00001 #include <float.h>
00002
00003 #include <fstream.h>
00004
00005 #include "/afs/rhic.bnl.gov/star/replicas/DEV/StRoot/StEventUtilities/BetheBlochFunction.hh"
00006
00007 #include "/star/data05/scratch/aihong/pidamp_dAu/StRoot/StPidAmpMaker/StPidProbabilityConst.hh"
00008
00009
00010 void WriteOutPIDTableMacro( char* myOutputName){
00011
00013
00014 char* mInputAmpFileName[mMultiplicityBins][mNDcaBins][mNChargeBins];
00015
00016 char* mInputSigmaFileName[mMultiplicityBins][mNDcaBins][mNChargeBins];
00017 char* mInputCalibFileName[mMultiplicityBins][mNDcaBins][mNChargeBins];
00018
00019 char* mOutputFileName;
00020
00021 double* mSigmaOfSingleTrail;
00022 mSigmaOfSingleTrail = new double[mNEtaBins];
00023
00024 TF1* EBandCenter;
00025 TF1* PiBandCenter;
00026 TF1* KBandCenter;
00027 TF1* PBandCenter;
00028
00029 TF1* BandCenterPtr;
00030
00031
00032 double **BBPrePar;
00033 double **BBTurnOver;
00034 double **BBOffSetPar;
00035 double **BBScalePar;
00036 double **BBSaturate;
00037
00038
00039 BBPrePar = new double*[mNEtaBins];
00040 BBTurnOver = new double*[mNEtaBins];
00041 BBOffSetPar = new double*[mNEtaBins];
00042 BBScalePar = new double*[mNEtaBins];
00043 BBSaturate = new double*[mNEtaBins];
00044
00045
00046
00047 for (int ii=0; ii<mNEtaBins; ii++) {
00048 BBPrePar[ii] = new double[mNNHitsBins];
00049 BBTurnOver[ii] = new double[mNNHitsBins];
00050 BBOffSetPar[ii] = new double[mNNHitsBins];
00051 BBScalePar[ii] = new double[mNNHitsBins];
00052 BBSaturate[ii] = new double[mNNHitsBins];
00053 }
00054
00055
00056
00057 EBandCenter
00058 =new TF1("EBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
00059 PiBandCenter
00060 =new TF1("PiBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
00061 KBandCenter
00062 =new TF1("KBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
00063 PBandCenter
00064 =new TF1("PBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
00065
00066
00067
00068 Double_t electronPars[7]
00069 ={ 1.072, 0.3199, 1.66032e-07, 1, 0.511e-3, 2.71172e-07, 0.0005 };
00070 Double_t pionPars[7]
00071 ={ 1.072, 0.3199, 1.66032e-07, 1, 0.13957, 2.71172e-07, 0.0005 };
00072 Double_t kaonPars[7]
00073 ={ 1.072, 0.3199, 1.66032e-07, 1, 0.49368, 2.71172e-07, 0.0005 };
00074 Double_t antiprotonPars[7]
00075 ={ 1.072, 0.3199, 1.66032e-07, 1, 0.93827, 2.71172e-07, 0.0005 };
00076
00077
00078 EBandCenter->SetParameters(&electronPars[0]);
00079 PiBandCenter->SetParameters(&pionPars[0]);
00080 KBandCenter->SetParameters(&kaonPars[0]);
00081 PBandCenter->SetParameters(&antiprotonPars[0]);
00082
00083
00085
00086
00087
00088 TString OutPutName(myOutputName);
00089
00090 char* PidTag;
00091
00092 if (OutPutName.Contains("PiPIDTable"))
00093 {PidTag="Pi"; BandCenterPtr=PiBandCenter;}
00094 else if (OutPutName.Contains("EPIDTable"))
00095 {PidTag="E"; BandCenterPtr=EBandCenter;}
00096 else if (OutPutName.Contains("KPIDTable"))
00097 {PidTag="K"; BandCenterPtr=KBandCenter;}
00098 else if (OutPutName.Contains("PPIDTable"))
00099 {PidTag="P"; BandCenterPtr=PBandCenter;}
00100
00101
00102 for (int i=0; i<mMultiplicityBins; i++)
00103 for (int j=0; j<mNDcaBins; j++)
00104 for (int k=0; k<mNChargeBins; k++) {
00105
00106
00107
00108
00109 mInputAmpFileName[i][j][k]= new char[80];
00110 sprintf(mInputAmpFileName[i][j][k],"./PidHistoAmp_%d%d%d.root",i,j,k);
00111
00112
00113 mInputSigmaFileName[i][j][k]= new char[80];
00114 sprintf(mInputSigmaFileName[i][j][k],"PidSigmaOfSingleTrail_%d%d%d_basedOn_%d00.txt",i,j,k,i);
00115
00116
00117 mInputCalibFileName[i][j][k]= new char[80];
00118 sprintf(mInputCalibFileName[i][j][k], "./PhaseSpaceCalib%d%d%dButItisbasedOn_%d01.txt",i,j,k,i);
00119
00120
00121 mOutputFileName=myOutputName;
00122 }
00123
00124
00126 TFile outFile(mOutputFileName,"RECREATE");
00127
00128 outFile.cd();
00129
00130
00131 int thisMultBins=mMultiplicityBins;
00132 int thisDcaBins=mNDcaBins;
00133 int thisChargeBins=mNChargeBins;
00134
00135 int thisDedxBins=200;
00136 int thisPBins=200;
00137 int thisEtaBins=mNEtaBins;
00138 int thisNHitsBins=mNNHitsBins;
00139
00141
00142 double thisDedxStart=0.;
00143 double thisDedxEnd=0.53e-5;
00144 double thisPStart=1e-12;
00145 double thisPEnd=2.0;
00146 double thisEtaStart=mEtaStart;
00147 double thisEtaEnd=mEtaEnd;
00148 double thisNHitsStart=mNNHitsStart;
00149 double thisNHitsEnd=mNNHitsEnd;
00150
00152
00153
00154 TVectorD* EqualyDividableRangeStartSet = new TVectorD(20);
00155
00156 (*EqualyDividableRangeStartSet)(0)=thisDedxStart;
00157 (*EqualyDividableRangeStartSet)(1)=thisPStart;
00158 (*EqualyDividableRangeStartSet)(2)=thisEtaStart;
00159 (*EqualyDividableRangeStartSet)(3)=thisNHitsStart;
00160
00161 EqualyDividableRangeStartSet->Write("EqualyDividableRangeStartSet",TObject::kOverwrite | TObject::kSingleKey);
00162
00163 TVectorD* EqualyDividableRangeEndSet = new TVectorD(20);
00164
00165 (*EqualyDividableRangeEndSet)(0)=thisDedxEnd;
00166 (*EqualyDividableRangeEndSet)(1)=thisPEnd;
00167 (*EqualyDividableRangeEndSet)(2)=thisEtaEnd;
00168 (*EqualyDividableRangeEndSet)(3)=thisNHitsEnd;
00169
00170 EqualyDividableRangeEndSet->Write("EqualyDividableRangeEndSet",TObject::kOverwrite | TObject::kSingleKey);
00171
00172
00173
00174 TVectorD* EqualyDividableRangeNBinsSet = new TVectorD(20);
00175
00176 (*EqualyDividableRangeNBinsSet)(0)=thisDedxBins;
00177 (*EqualyDividableRangeNBinsSet)(1)=thisPBins;
00178 (*EqualyDividableRangeNBinsSet)(2)=thisEtaBins;
00179 (*EqualyDividableRangeNBinsSet)(3)=thisNHitsBins;
00180
00181 EqualyDividableRangeNBinsSet->Write("EqualyDividableRangeNBinsSet",TObject::kOverwrite | TObject::kSingleKey);
00182
00184
00185
00186 TVectorD* NoEqualyDividableRangeNBinsSet = new TVectorD(20);
00187
00188 (*NoEqualyDividableRangeNBinsSet)(0)=thisMultBins;
00189 (*NoEqualyDividableRangeNBinsSet)(1)=thisDcaBins;
00190 (*NoEqualyDividableRangeNBinsSet)(2)=thisChargeBins;
00191
00192 NoEqualyDividableRangeNBinsSet->Write("NoEqualyDividableRangeNBinsSet",TObject::kOverwrite | TObject::kSingleKey);
00193
00194
00195 TVectorD* MultiBinEdgeSet = new TVectorD(20);
00196
00197 (*MultiBinEdgeSet)(0) = 1.;
00198 (*MultiBinEdgeSet)(1) =.4;
00199 (*MultiBinEdgeSet)(2) =.2;
00200
00201 MultiBinEdgeSet->Write("MultiBinEdgeSet",TObject::kOverwrite | TObject::kSingleKey);
00202
00203 TVectorD* DcaBinEdgeSet = new TVectorD(20);
00204
00205 (*DcaBinEdgeSet)(0) = 0.0000;
00206 (*DcaBinEdgeSet)(1) = 3.0;
00207
00208 DcaBinEdgeSet->Write("DcaBinEdgeSet",TObject::kOverwrite | TObject::kSingleKey);
00209
00210
00211
00212
00213 outFile.Write();
00214
00215
00216 int objAryIdx=0;
00217
00218 TVectorD* theAmpTable;
00219 TVectorD* theCenterTable;
00220 TVectorD* theSigmaTable;
00221
00222
00223 TVectorD* theBBPreParTable;
00224 TVectorD* theBBTurnOverTable;
00225 TVectorD* theBBScaleTable;
00226 TVectorD* theBBOffSetTable;
00227 TVectorD* theBBSaturateTable;
00228
00229
00230
00233
00234
00235
00236 objAryIdx=0;
00237 theAmpTable = new TVectorD(thisMultBins*thisDcaBins*thisChargeBins*thisPBins*thisEtaBins*thisNHitsBins);
00238 theCenterTable = new TVectorD(thisMultBins*thisDcaBins*thisChargeBins*thisPBins*thisEtaBins*thisNHitsBins);
00239 theSigmaTable = new TVectorD(thisMultBins*thisDcaBins*thisChargeBins*thisPBins*thisEtaBins*thisNHitsBins);
00240
00241
00242
00243 theBBPreParTable = new TVectorD(thisEtaBins*thisNHitsBins);
00244 theBBTurnOverTable = new TVectorD(thisEtaBins*thisNHitsBins);
00245 theBBScaleTable = new TVectorD(thisEtaBins*thisNHitsBins);
00246 theBBOffSetTable = new TVectorD(thisEtaBins*thisNHitsBins);
00247 theBBSaturateTable = new TVectorD(thisEtaBins*thisNHitsBins);
00248
00249
00250 for (int multIdx=0; multIdx<thisMultBins; multIdx++)
00251 for (int dcaIdx=0; dcaIdx<thisDcaBins; dcaIdx++)
00252 for (int chargeIdx=0; chargeIdx<thisChargeBins; chargeIdx++){
00253
00254 TFile AmpFile(mInputAmpFileName[multIdx][dcaIdx][chargeIdx],"READ");
00255
00256 ifstream sigmaFile(mInputSigmaFileName[multIdx][dcaIdx][chargeIdx]);
00257 ifstream calibFile(mInputCalibFileName[multIdx][dcaIdx][chargeIdx]);
00258
00259
00260 cout<<mInputSigmaFileName[multIdx][dcaIdx][chargeIdx]<<endl;
00261
00262 int ie,in;
00263
00264 for (int h=0; h<thisEtaBins*thisNHitsBins;h++){
00265 calibFile>>ie; calibFile>>in;
00266
00267
00268 calibFile>>BBPrePar[ie][in];
00269 calibFile>>BBTurnOver[ie][in];
00270 calibFile>>BBOffSetPar[ie][in];
00271 calibFile>>BBScalePar[ie][in];
00272 calibFile>>BBSaturate[ie][in];
00273
00274
00275 (*theBBPreParTable)(h)=BBPrePar[ie][in];
00276 (*theBBTurnOverTable)(h)=BBTurnOver[ie][in];
00277 (*theBBOffSetTable)(h)=BBOffSetPar[ie][in];
00278 (*theBBScaleTable)(h)=BBScalePar[ie][in];
00279 (*theBBSaturateTable)(h)=BBSaturate[ie][in];
00280
00281 }
00282
00283 calibFile.close();
00284
00285 for (int h=0; h<thisEtaBins; h++){
00286 sigmaFile>>ie; sigmaFile>>mSigmaOfSingleTrail[h];
00287 }
00288
00289 sigmaFile.close();
00290
00291
00292 for (int pIdx=0; pIdx<thisPBins; pIdx++)
00293 for (int etaIdx=0; etaIdx<thisEtaBins; etaIdx++)
00294 for (int nhitsIdx=0; nhitsIdx<thisNHitsBins; nhitsIdx++){
00295
00296
00297 double pPosition= (pIdx+0.5)*(thisPEnd-thisPStart)/float(thisPBins);
00298 double etaPosition= (etaIdx+0.5)*(thisEtaEnd-thisEtaStart)/float(thisEtaBins);
00299 double nhitsPosition=double((nhitsIdx+0.5)*(float(thisNHitsEnd-thisNHitsStart)/float(thisNHitsBins)));
00300
00301 BandCenterPtr->SetParameter(0,BBPrePar[etaIdx][nhitsIdx]);
00302 BandCenterPtr->SetParameter(1,BBTurnOver[etaIdx][nhitsIdx]);
00303 BandCenterPtr->SetParameter(2,BBOffSetPar[etaIdx][nhitsIdx]);
00304 BandCenterPtr->SetParameter(5,BBScalePar[etaIdx][nhitsIdx]);
00305 BandCenterPtr->SetParameter(6,BBSaturate[etaIdx][nhitsIdx]);
00306
00307 double theAmp;
00308 double theCenter;
00309 double theSigma;
00310
00311 char *theAmpName = new char[80];
00312 sprintf(theAmpName,"%sAmp%d%d",PidTag,etaIdx,nhitsIdx);
00313
00314 TH1F* theAmpHist=(TH1F *)AmpFile.Get(theAmpName);
00315
00316 if (theAmpName) delete theAmpName;
00317
00318 if (theAmpHist) {
00319
00320
00321
00322 if (OutPutName.Contains("PiPIDTable"))
00323 {PidTag="Pi"; BandCenterPtr=PiBandCenter;}
00324 if (OutPutName.Contains("EPIDTable"))
00325 {PidTag="E"; BandCenterPtr=EBandCenter;}
00326 if (OutPutName.Contains("KPIDTable"))
00327 {PidTag="K"; BandCenterPtr=KBandCenter;}
00328 if (OutPutName.Contains("PPIDTable"))
00329 {PidTag="P"; BandCenterPtr=PBandCenter;}
00330
00331
00332
00333 if (OutPutName.Contains("PiPIDTable")){
00334
00335 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
00336 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
00337
00338 TF1* PiFcnCenter = theAmpHist->GetFunction("PiFcnCenter");
00339 TF1* PiFcnLeft = theAmpHist->GetFunction("PiFcnLeft");
00340 TF1* PiFcnRight = theAmpHist->GetFunction("PiFcnRight");
00341
00342 if (PiFcnRight){
00343 PiFcnRight->SetRange(PiFcnRight->GetXmin(),mPEnd);
00344 if ( pPosition<=PiFcnRight->GetXmax()
00345 && pPosition >PiFcnRight->GetXmin()&& PiFcnRight->GetParameter(1)<0 )
00346 theAmp = PiFcnRight->Eval(pPosition,0.,0.);
00347 }
00348
00349 if (PiFcnCenter){
00350 if ( pPosition<=PiFcnCenter->GetXmax()
00351 && pPosition >PiFcnCenter->GetXmin() )
00352 theAmp = PiFcnCenter->Eval(pPosition,0.,0.);
00353 }
00354
00355 if (PiFcnLeft){
00356 if ( pPosition <= PiFcnLeft->GetXmax()
00357 && pPosition > PiFcnLeft->GetXmin() )
00358 theAmp = PiFcnLeft->Eval(pPosition,0.,0.);
00359 }
00360
00361
00362 } else if (OutPutName.Contains("EPIDTable")) {
00363
00364 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
00365 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
00366
00367 TF1* EFcnLeft = theAmpHist->GetFunction("EFcnLeft");
00368 if (EFcnLeft){
00369 if ( pPosition<=EFcnLeft->GetXmax()
00370 && pPosition >EFcnLeft->GetXmin() && EFcnLeft->GetParameter(1)<0 )
00371 theAmp = EFcnLeft->Eval(pPosition,0.,0.);
00372 }
00373
00374 TF1* EFcnRight = theAmpHist->GetFunction("EFcnRight");
00375 if (EFcnRight){
00376
00377 EFcnRight->SetRange(0.15, mPEnd);
00378 if ( pPosition<=EFcnRight->GetXmax()
00379 && pPosition >EFcnRight->GetXmin() && EFcnRight->GetParameter(1)<0 )
00380 theAmp = EFcnRight->Eval(pPosition,0.,0.);
00381 }
00382
00383 if (nhitsPosition<=5)
00384 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
00385 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
00386
00387 } else if (OutPutName.Contains("KPIDTable")) {
00388
00389 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
00390 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
00391
00392
00393 TF1* KFcnCenter = theAmpHist->GetFunction("KFcnCenter");
00394 TF1* KFcnLeft = theAmpHist->GetFunction("KFcnLeft");
00395 TF1* KFcnRight = theAmpHist->GetFunction("KFcnRight");
00396
00397 if (KFcnRight){
00398 if ( pPosition<=KFcnRight->GetXmax()
00399 && pPosition >KFcnRight->GetXmin() )
00400 theAmp = KFcnRight->Eval(pPosition,0.,0.);
00401 }
00402
00403 if (KFcnCenter){
00404 if ( pPosition<=KFcnCenter->GetXmax()
00405 && pPosition >KFcnCenter->GetXmin() )
00406 theAmp = KFcnCenter->Eval(pPosition,0.,0.);
00407 }
00408
00409 if (KFcnLeft){
00410 if ( pPosition<=KFcnLeft->GetXmax()
00411 && pPosition >KFcnLeft->GetXmin() )
00412 theAmp = KFcnLeft->Eval(pPosition,0.,0.);
00413 }
00414
00415 if (nhitsPosition<=5)
00416 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
00417 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
00418
00419 } else if (OutPutName.Contains("PPIDTable")) {
00420
00421 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
00422 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
00423
00424 TF1* PFcnRight = theAmpHist->GetFunction("PFcnRight");
00425 TF1* PFcnLeft = theAmpHist->GetFunction("PFcnLeft");
00426
00427 if (PFcnRight){
00428 if ( pPosition<=PFcnRight->GetXmax()
00429 && pPosition >PFcnRight->GetXmin() )
00430 theAmp = PFcnRight->Eval(pPosition,0.,0.);
00431 }
00432
00433 if (PFcnLeft){
00434 if ( pPosition<=PFcnLeft->GetXmax()
00435 && pPosition >PFcnLeft->GetXmin() )
00436 theAmp = PFcnLeft->Eval(pPosition,0.,0.);
00437 }
00438
00439 }
00440
00441
00442 } else theAmp=0;
00443
00444
00445 theCenter=BandCenterPtr->Eval(pPosition);
00446 theSigma=
00447 mSigmaOfSingleTrail[etaIdx]*theCenter/TMath::Sqrt(nhitsPosition);
00448
00449
00450
00451 theAmp= (theAmp<FLT_MAX && theAmp>0.) ? theAmp : 0.;
00452 theCenter = (theCenter<FLT_MAX && theCenter>0.) ? theCenter : 0.;
00453 theSigma = (theSigma<FLT_MAX && theSigma>0. ) ? theSigma : 0.;
00454
00455 (*theAmpTable)(objAryIdx)=(theAmp);
00456 (*theCenterTable)(objAryIdx)=(theCenter);
00457 (*theSigmaTable)(objAryIdx)=(theSigma);
00458
00459
00460
00461 objAryIdx++;
00462
00463
00464
00465 }
00466
00467 AmpFile.Close();
00468
00469 }
00470
00471 outFile.cd();
00472
00473
00474 char *ampNm = new char[80];
00475 sprintf(ampNm,"%sAmp",PidTag);
00476 char *ctrNm = new char[80];
00477 sprintf(ctrNm,"%sCenter",PidTag);
00478 char *sigmaNm = new char[80];
00479 sprintf(sigmaNm,"%sSigma",PidTag);
00480
00481 theAmpTable->Write(ampNm,TObject::kOverwrite | TObject::kSingleKey);
00482 theCenterTable->Write(ctrNm,TObject::kOverwrite | TObject::kSingleKey);
00483 theSigmaTable->Write(sigmaNm,TObject::kOverwrite | TObject::kSingleKey);
00484
00485 theBBPreParTable->Write("BBPrePar",TObject::kOverwrite | TObject::kSingleKey);
00486 theBBTurnOverTable->Write("BBTurnOver",TObject::kOverwrite | TObject::kSingleKey);
00487 theBBOffSetTable->Write("BBOffSet",TObject::kOverwrite | TObject::kSingleKey);
00488 theBBScaleTable->Write("BBScale",TObject::kOverwrite | TObject::kSingleKey);
00489 theBBSaturateTable->Write("BBSaturate",TObject::kOverwrite | TObject::kSingleKey);
00490
00491
00492 outFile.Write();
00493
00494 if (theAmpTable) delete theAmpTable;
00495 if (theCenterTable) delete theCenterTable;
00496 if (theSigmaTable) delete theSigmaTable;
00497
00498 if (theBBScaleTable) delete theBBScaleTable;
00499 if (theBBOffSetTable) delete theBBOffSetTable;
00500
00501 if (ampNm) delete ampNm;
00502 if (ctrNm) delete ctrNm;
00503 if (sigmaNm) delete sigmaNm;
00504
00505 outFile.Close();
00506 }
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537