5 #include "/afs/rhic.bnl.gov/star/replicas/DEV/StRoot/StEventUtilities/BetheBlochFunction.hh"
7 #include "/star/data05/scratch/aihong/pidamp_dAu/StRoot/StPidAmpMaker/StPidProbabilityConst.hh"
10 void WriteOutPIDTableMacro(
char* myOutputName){
14 char* mInputAmpFileName[mMultiplicityBins][mNDcaBins][mNChargeBins];
16 char* mInputSigmaFileName[mMultiplicityBins][mNDcaBins][mNChargeBins];
17 char* mInputCalibFileName[mMultiplicityBins][mNDcaBins][mNChargeBins];
19 char* mOutputFileName;
21 double* mSigmaOfSingleTrail;
22 mSigmaOfSingleTrail =
new double[mNEtaBins];
39 BBPrePar =
new double*[mNEtaBins];
40 BBTurnOver =
new double*[mNEtaBins];
41 BBOffSetPar =
new double*[mNEtaBins];
42 BBScalePar =
new double*[mNEtaBins];
43 BBSaturate =
new double*[mNEtaBins];
47 for (
int ii=0; ii<mNEtaBins; ii++) {
48 BBPrePar[ii] =
new double[mNNHitsBins];
49 BBTurnOver[ii] =
new double[mNNHitsBins];
50 BBOffSetPar[ii] =
new double[mNNHitsBins];
51 BBScalePar[ii] =
new double[mNNHitsBins];
52 BBSaturate[ii] =
new double[mNNHitsBins];
58 =
new TF1(
"EBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
60 =
new TF1(
"PiBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
62 =
new TF1(
"KBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
64 =
new TF1(
"PBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
68 Double_t electronPars[7]
69 ={ 1.072, 0.3199, 1.66032e-07, 1, 0.511e-3, 2.71172e-07, 0.0005 };
71 ={ 1.072, 0.3199, 1.66032e-07, 1, 0.13957, 2.71172e-07, 0.0005 };
73 ={ 1.072, 0.3199, 1.66032e-07, 1, 0.49368, 2.71172e-07, 0.0005 };
74 Double_t antiprotonPars[7]
75 ={ 1.072, 0.3199, 1.66032e-07, 1, 0.93827, 2.71172e-07, 0.0005 };
78 EBandCenter->SetParameters(&electronPars[0]);
79 PiBandCenter->SetParameters(&pionPars[0]);
80 KBandCenter->SetParameters(&kaonPars[0]);
81 PBandCenter->SetParameters(&antiprotonPars[0]);
88 TString OutPutName(myOutputName);
92 if (OutPutName.Contains(
"PiPIDTable"))
93 {PidTag=
"Pi"; BandCenterPtr=PiBandCenter;}
94 else if (OutPutName.Contains(
"EPIDTable"))
95 {PidTag=
"E"; BandCenterPtr=EBandCenter;}
96 else if (OutPutName.Contains(
"KPIDTable"))
97 {PidTag=
"K"; BandCenterPtr=KBandCenter;}
98 else if (OutPutName.Contains(
"PPIDTable"))
99 {PidTag=
"P"; BandCenterPtr=PBandCenter;}
102 for (
int i=0; i<mMultiplicityBins; i++)
103 for (
int j=0; j<mNDcaBins; j++)
104 for (
int k=0; k<mNChargeBins; k++) {
109 mInputAmpFileName[i][j][k]=
new char[80];
110 sprintf(mInputAmpFileName[i][j][k],
"./PidHistoAmp_%d%d%d.root",i,j,k);
113 mInputSigmaFileName[i][j][k]=
new char[80];
114 sprintf(mInputSigmaFileName[i][j][k],
"PidSigmaOfSingleTrail_%d%d%d_basedOn_%d00.txt",i,j,k,i);
117 mInputCalibFileName[i][j][k]=
new char[80];
118 sprintf(mInputCalibFileName[i][j][k],
"./PhaseSpaceCalib%d%d%dButItisbasedOn_%d01.txt",i,j,k,i);
121 mOutputFileName=myOutputName;
126 TFile outFile(mOutputFileName,
"RECREATE");
131 int thisMultBins=mMultiplicityBins;
132 int thisDcaBins=mNDcaBins;
133 int thisChargeBins=mNChargeBins;
135 int thisDedxBins=200;
137 int thisEtaBins=mNEtaBins;
138 int thisNHitsBins=mNNHitsBins;
142 double thisDedxStart=0.;
143 double thisDedxEnd=0.53e-5;
144 double thisPStart=1e-12;
146 double thisEtaStart=mEtaStart;
147 double thisEtaEnd=mEtaEnd;
148 double thisNHitsStart=mNNHitsStart;
149 double thisNHitsEnd=mNNHitsEnd;
154 TVectorD* EqualyDividableRangeStartSet =
new TVectorD(20);
156 (*EqualyDividableRangeStartSet)(0)=thisDedxStart;
157 (*EqualyDividableRangeStartSet)(1)=thisPStart;
158 (*EqualyDividableRangeStartSet)(2)=thisEtaStart;
159 (*EqualyDividableRangeStartSet)(3)=thisNHitsStart;
161 EqualyDividableRangeStartSet->Write(
"EqualyDividableRangeStartSet",TObject::kOverwrite | TObject::kSingleKey);
163 TVectorD* EqualyDividableRangeEndSet =
new TVectorD(20);
165 (*EqualyDividableRangeEndSet)(0)=thisDedxEnd;
166 (*EqualyDividableRangeEndSet)(1)=thisPEnd;
167 (*EqualyDividableRangeEndSet)(2)=thisEtaEnd;
168 (*EqualyDividableRangeEndSet)(3)=thisNHitsEnd;
170 EqualyDividableRangeEndSet->Write(
"EqualyDividableRangeEndSet",TObject::kOverwrite | TObject::kSingleKey);
174 TVectorD* EqualyDividableRangeNBinsSet =
new TVectorD(20);
176 (*EqualyDividableRangeNBinsSet)(0)=thisDedxBins;
177 (*EqualyDividableRangeNBinsSet)(1)=thisPBins;
178 (*EqualyDividableRangeNBinsSet)(2)=thisEtaBins;
179 (*EqualyDividableRangeNBinsSet)(3)=thisNHitsBins;
181 EqualyDividableRangeNBinsSet->Write(
"EqualyDividableRangeNBinsSet",TObject::kOverwrite | TObject::kSingleKey);
186 TVectorD* NoEqualyDividableRangeNBinsSet =
new TVectorD(20);
188 (*NoEqualyDividableRangeNBinsSet)(0)=thisMultBins;
189 (*NoEqualyDividableRangeNBinsSet)(1)=thisDcaBins;
190 (*NoEqualyDividableRangeNBinsSet)(2)=thisChargeBins;
192 NoEqualyDividableRangeNBinsSet->Write(
"NoEqualyDividableRangeNBinsSet",TObject::kOverwrite | TObject::kSingleKey);
195 TVectorD* MultiBinEdgeSet =
new TVectorD(20);
197 (*MultiBinEdgeSet)(0) = 1.;
198 (*MultiBinEdgeSet)(1) =.4;
199 (*MultiBinEdgeSet)(2) =.2;
201 MultiBinEdgeSet->Write(
"MultiBinEdgeSet",TObject::kOverwrite | TObject::kSingleKey);
203 TVectorD* DcaBinEdgeSet =
new TVectorD(20);
205 (*DcaBinEdgeSet)(0) = 0.0000;
206 (*DcaBinEdgeSet)(1) = 3.0;
208 DcaBinEdgeSet->Write(
"DcaBinEdgeSet",TObject::kOverwrite | TObject::kSingleKey);
218 TVectorD* theAmpTable;
219 TVectorD* theCenterTable;
220 TVectorD* theSigmaTable;
223 TVectorD* theBBPreParTable;
224 TVectorD* theBBTurnOverTable;
225 TVectorD* theBBScaleTable;
226 TVectorD* theBBOffSetTable;
227 TVectorD* theBBSaturateTable;
237 theAmpTable =
new TVectorD(thisMultBins*thisDcaBins*thisChargeBins*thisPBins*thisEtaBins*thisNHitsBins);
238 theCenterTable =
new TVectorD(thisMultBins*thisDcaBins*thisChargeBins*thisPBins*thisEtaBins*thisNHitsBins);
239 theSigmaTable =
new TVectorD(thisMultBins*thisDcaBins*thisChargeBins*thisPBins*thisEtaBins*thisNHitsBins);
243 theBBPreParTable =
new TVectorD(thisEtaBins*thisNHitsBins);
244 theBBTurnOverTable =
new TVectorD(thisEtaBins*thisNHitsBins);
245 theBBScaleTable =
new TVectorD(thisEtaBins*thisNHitsBins);
246 theBBOffSetTable =
new TVectorD(thisEtaBins*thisNHitsBins);
247 theBBSaturateTable =
new TVectorD(thisEtaBins*thisNHitsBins);
250 for (
int multIdx=0; multIdx<thisMultBins; multIdx++)
251 for (
int dcaIdx=0; dcaIdx<thisDcaBins; dcaIdx++)
252 for (
int chargeIdx=0; chargeIdx<thisChargeBins; chargeIdx++){
254 TFile AmpFile(mInputAmpFileName[multIdx][dcaIdx][chargeIdx],
"READ");
256 ifstream sigmaFile(mInputSigmaFileName[multIdx][dcaIdx][chargeIdx]);
257 ifstream calibFile(mInputCalibFileName[multIdx][dcaIdx][chargeIdx]);
260 cout<<mInputSigmaFileName[multIdx][dcaIdx][chargeIdx]<<endl;
264 for (
int h=0; h<thisEtaBins*thisNHitsBins;h++){
265 calibFile>>ie; calibFile>>in;
268 calibFile>>BBPrePar[ie][in];
269 calibFile>>BBTurnOver[ie][in];
270 calibFile>>BBOffSetPar[ie][in];
271 calibFile>>BBScalePar[ie][in];
272 calibFile>>BBSaturate[ie][in];
275 (*theBBPreParTable)(h)=BBPrePar[ie][in];
276 (*theBBTurnOverTable)(h)=BBTurnOver[ie][in];
277 (*theBBOffSetTable)(h)=BBOffSetPar[ie][in];
278 (*theBBScaleTable)(h)=BBScalePar[ie][in];
279 (*theBBSaturateTable)(h)=BBSaturate[ie][in];
285 for (
int h=0; h<thisEtaBins; h++){
286 sigmaFile>>ie; sigmaFile>>mSigmaOfSingleTrail[h];
292 for (
int pIdx=0; pIdx<thisPBins; pIdx++)
293 for (
int etaIdx=0; etaIdx<thisEtaBins; etaIdx++)
294 for (
int nhitsIdx=0; nhitsIdx<thisNHitsBins; nhitsIdx++){
297 double pPosition= (pIdx+0.5)*(thisPEnd-thisPStart)/
float(thisPBins);
298 double etaPosition= (etaIdx+0.5)*(thisEtaEnd-thisEtaStart)/
float(thisEtaBins);
299 double nhitsPosition=double((nhitsIdx+0.5)*(
float(thisNHitsEnd-thisNHitsStart)/
float(thisNHitsBins)));
301 BandCenterPtr->SetParameter(0,BBPrePar[etaIdx][nhitsIdx]);
302 BandCenterPtr->SetParameter(1,BBTurnOver[etaIdx][nhitsIdx]);
303 BandCenterPtr->SetParameter(2,BBOffSetPar[etaIdx][nhitsIdx]);
304 BandCenterPtr->SetParameter(5,BBScalePar[etaIdx][nhitsIdx]);
305 BandCenterPtr->SetParameter(6,BBSaturate[etaIdx][nhitsIdx]);
311 char *theAmpName =
new char[80];
312 sprintf(theAmpName,
"%sAmp%d%d",PidTag,etaIdx,nhitsIdx);
314 TH1F* theAmpHist=(TH1F *)AmpFile.Get(theAmpName);
316 if (theAmpName)
delete theAmpName;
322 if (OutPutName.Contains(
"PiPIDTable"))
323 {PidTag=
"Pi"; BandCenterPtr=PiBandCenter;}
324 if (OutPutName.Contains(
"EPIDTable"))
325 {PidTag=
"E"; BandCenterPtr=EBandCenter;}
326 if (OutPutName.Contains(
"KPIDTable"))
327 {PidTag=
"K"; BandCenterPtr=KBandCenter;}
328 if (OutPutName.Contains(
"PPIDTable"))
329 {PidTag=
"P"; BandCenterPtr=PBandCenter;}
333 if (OutPutName.Contains(
"PiPIDTable")){
335 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
336 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
338 TF1* PiFcnCenter = theAmpHist->GetFunction(
"PiFcnCenter");
339 TF1* PiFcnLeft = theAmpHist->GetFunction(
"PiFcnLeft");
340 TF1* PiFcnRight = theAmpHist->GetFunction(
"PiFcnRight");
343 PiFcnRight->SetRange(PiFcnRight->GetXmin(),mPEnd);
344 if ( pPosition<=PiFcnRight->GetXmax()
345 && pPosition >PiFcnRight->GetXmin()&& PiFcnRight->GetParameter(1)<0 )
346 theAmp = PiFcnRight->Eval(pPosition,0.,0.);
350 if ( pPosition<=PiFcnCenter->GetXmax()
351 && pPosition >PiFcnCenter->GetXmin() )
352 theAmp = PiFcnCenter->Eval(pPosition,0.,0.);
356 if ( pPosition <= PiFcnLeft->GetXmax()
357 && pPosition > PiFcnLeft->GetXmin() )
358 theAmp = PiFcnLeft->Eval(pPosition,0.,0.);
362 }
else if (OutPutName.Contains(
"EPIDTable")) {
364 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
365 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
367 TF1* EFcnLeft = theAmpHist->GetFunction(
"EFcnLeft");
369 if ( pPosition<=EFcnLeft->GetXmax()
370 && pPosition >EFcnLeft->GetXmin() && EFcnLeft->GetParameter(1)<0 )
371 theAmp = EFcnLeft->Eval(pPosition,0.,0.);
374 TF1* EFcnRight = theAmpHist->GetFunction(
"EFcnRight");
377 EFcnRight->SetRange(0.15, mPEnd);
378 if ( pPosition<=EFcnRight->GetXmax()
379 && pPosition >EFcnRight->GetXmin() && EFcnRight->GetParameter(1)<0 )
380 theAmp = EFcnRight->Eval(pPosition,0.,0.);
383 if (nhitsPosition<=5)
384 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
385 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
387 }
else if (OutPutName.Contains(
"KPIDTable")) {
389 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
390 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
393 TF1* KFcnCenter = theAmpHist->GetFunction(
"KFcnCenter");
394 TF1* KFcnLeft = theAmpHist->GetFunction(
"KFcnLeft");
395 TF1* KFcnRight = theAmpHist->GetFunction(
"KFcnRight");
398 if ( pPosition<=KFcnRight->GetXmax()
399 && pPosition >KFcnRight->GetXmin() )
400 theAmp = KFcnRight->Eval(pPosition,0.,0.);
404 if ( pPosition<=KFcnCenter->GetXmax()
405 && pPosition >KFcnCenter->GetXmin() )
406 theAmp = KFcnCenter->Eval(pPosition,0.,0.);
410 if ( pPosition<=KFcnLeft->GetXmax()
411 && pPosition >KFcnLeft->GetXmin() )
412 theAmp = KFcnLeft->Eval(pPosition,0.,0.);
415 if (nhitsPosition<=5)
416 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
417 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
419 }
else if (OutPutName.Contains(
"PPIDTable")) {
421 theAmp = (theAmpHist->GetBinContent(pIdx+1)>0) ?
422 (theAmpHist->GetBinContent(pIdx+1)) : 0.;
424 TF1* PFcnRight = theAmpHist->GetFunction(
"PFcnRight");
425 TF1* PFcnLeft = theAmpHist->GetFunction(
"PFcnLeft");
428 if ( pPosition<=PFcnRight->GetXmax()
429 && pPosition >PFcnRight->GetXmin() )
430 theAmp = PFcnRight->Eval(pPosition,0.,0.);
434 if ( pPosition<=PFcnLeft->GetXmax()
435 && pPosition >PFcnLeft->GetXmin() )
436 theAmp = PFcnLeft->Eval(pPosition,0.,0.);
445 theCenter=BandCenterPtr->Eval(pPosition);
447 mSigmaOfSingleTrail[etaIdx]*theCenter/TMath::Sqrt(nhitsPosition);
451 theAmp= (theAmp<FLT_MAX && theAmp>0.) ? theAmp : 0.;
452 theCenter = (theCenter<FLT_MAX && theCenter>0.) ? theCenter : 0.;
453 theSigma = (theSigma<FLT_MAX && theSigma>0. ) ? theSigma : 0.;
455 (*theAmpTable)(objAryIdx)=(theAmp);
456 (*theCenterTable)(objAryIdx)=(theCenter);
457 (*theSigmaTable)(objAryIdx)=(theSigma);
474 char *ampNm =
new char[80];
475 sprintf(ampNm,
"%sAmp",PidTag);
476 char *ctrNm =
new char[80];
477 sprintf(ctrNm,
"%sCenter",PidTag);
478 char *sigmaNm =
new char[80];
479 sprintf(sigmaNm,
"%sSigma",PidTag);
481 theAmpTable->Write(ampNm,TObject::kOverwrite | TObject::kSingleKey);
482 theCenterTable->Write(ctrNm,TObject::kOverwrite | TObject::kSingleKey);
483 theSigmaTable->Write(sigmaNm,TObject::kOverwrite | TObject::kSingleKey);
485 theBBPreParTable->Write(
"BBPrePar",TObject::kOverwrite | TObject::kSingleKey);
486 theBBTurnOverTable->Write(
"BBTurnOver",TObject::kOverwrite | TObject::kSingleKey);
487 theBBOffSetTable->Write(
"BBOffSet",TObject::kOverwrite | TObject::kSingleKey);
488 theBBScaleTable->Write(
"BBScale",TObject::kOverwrite | TObject::kSingleKey);
489 theBBSaturateTable->Write(
"BBSaturate",TObject::kOverwrite | TObject::kSingleKey);
494 if (theAmpTable)
delete theAmpTable;
495 if (theCenterTable)
delete theCenterTable;
496 if (theSigmaTable)
delete theSigmaTable;
498 if (theBBScaleTable)
delete theBBScaleTable;
499 if (theBBOffSetTable)
delete theBBOffSetTable;
501 if (ampNm)
delete ampNm;
502 if (ctrNm)
delete ctrNm;
503 if (sigmaNm)
delete sigmaNm;