13 #include "PIDFitter.h"
26 #include "TGraphErrors.h"
29 #include "BetheBlochFunction.hh"
36 Double_t sigmaNSampleFitFcn(Double_t* x, Double_t *par);
39 PIDFitter::PIDFitter(){
43 void PIDFitter::Process( Char_t* sigmaOfSigmTrialInputName,
44 Char_t* sigmaOfSigmTrialOutputName,
45 Char_t* phaseSpaceCalibInputName,
46 Char_t* phaseSpaceCalibOutputName,
47 Char_t* gausFitInputName,
48 Char_t* gausFitOutputName,
49 Char_t* ampFitOutputName ){
51 GetSigmaOfSingleTrail(sigmaOfSigmTrialInputName,sigmaOfSigmTrialOutputName);
52 DoPhaseSpaceCalibration(phaseSpaceCalibInputName,phaseSpaceCalibOutputName);
53 FitMultiGaus(gausFitInputName,gausFitOutputName);
54 ExtrapAmp(gausFitOutputName,ampFitOutputName);
58 void PIDFitter::GetSigmaOfSingleTrail(Char_t* fileName4SigmaOfSingleTrail,Char_t* sigmaFileName){
60 cout<<
" getting sigma of single trail..."<<endl;
63 if (mWriteSigmaNSampleGraph) {
64 fitResoFile =
new TFile(
"sigmaNSample.root",
"UPDATE");
68 ofstream SigmaFileOut;
69 SigmaFileOut.open(sigmaFileName);
71 float pionPosition4Calib=0.4;
73 int i = int((pionPosition4Calib-mPStart)*mNPBins/(mPEnd-mPStart) );
77 TFile histo4CalibFile(fileName4SigmaOfSingleTrail,
"READ");
79 TH1F* theDummyHisto = (TH1F *)histo4CalibFile.Get(
"h2000");
82 for (
int j=0; j<mNEtaBins; j++) {
85 TGraphErrors* sigmaNSampleGraph =
new TGraphErrors();
88 grName.Append(fileName4SigmaOfSingleTrail);
89 grName.Append(
"SigmaNSample");
90 grName.Append((i<10) ?
"0" :
"");
93 grName.ReplaceAll(
".root",
"");
95 sigmaNSampleGraph->SetTitle(grName.Data());
96 sigmaNSampleGraph->SetName(grName.Data());
99 for (
int k=0; k<mNNHitsBins;k++){
101 TH1F* tempHisto =
new TH1F(*theDummyHisto);
104 char *theName =
new char[80];
106 sprintf(theName,
"h0%d%d%d",i,j,k);
107 else sprintf(theName,
"h%d%d%d",i,j,k);
109 theHist= (TH1F *)histo4CalibFile.Get(theName);
113 for (
int mm=0; mm<tempHisto->GetNbinsX(); mm++)
114 tempHisto->SetBinContent(mm,(theHist->GetBinContent(mm)));
119 Float_t theFitGausHalfRange = 0.03e-05*0.95;
121 Float_t mean=FitResoGaus(tempHisto,theFitGausHalfRange,theError,
122 0.005e-4,0.04e-4,1,j,k,pionPosition4Calib);
123 Float_t sigma=FitResoGaus(tempHisto,theFitGausHalfRange,theError,
124 0.005e-4,0.04e-4,2,j,k,pionPosition4Calib);
126 sigmaNSampleGraph->SetPoint(sigmaNSampleGraph->GetN(),(k*mNNHitsBins+(5./2.)),sigma/mean);
127 sigmaNSampleGraph->SetPointError((sigmaNSampleGraph->GetN()-1),0,theError);
129 if (tempHisto)
delete tempHisto;
134 TF1* f1 =
new TF1(
"f1",sigmaNSampleFitFcn,12.,40.,1);
135 sigmaNSampleGraph->Fit(
"f1",
"R");
137 cout<<
"sigNSamplePion1Graph fit parameter: "<<f1->GetParameter(0);
138 double theSigmaOfSingleTrail= f1->GetParameter(0);
139 double theErrorOfSigmaOfSingleTrail = f1->GetParError(0);
140 if(theErrorOfSigmaOfSingleTrail) {}
141 if (mWriteSigmaNSampleGraph) {
143 sigmaNSampleGraph->SetMarkerColor(2);
144 sigmaNSampleGraph->SetMarkerStyle(20);
145 sigmaNSampleGraph->Write(grName.Data(),TObject::kOverwrite | TObject::kSingleKey);
146 fitResoFile->Write();
151 if (sigmaNSampleGraph)
delete sigmaNSampleGraph;
152 mSigmaOfSingleTrail[j]=theSigmaOfSingleTrail;
156 SigmaFileOut<<j<<endl;
157 SigmaFileOut<<theSigmaOfSingleTrail<<endl;
161 if (mWriteSigmaNSampleGraph) fitResoFile->Close();
162 SigmaFileOut.close();
165 cout<<
" end of getting sigma of single trail..."<<endl;
170 float PIDFitter::FitResoGaus(TH1F* resoHist,
float fitRange,
float& er,
float theStart,
float theEnd,
int ParIndex,
int j,
int k,
float thePPosition){
175 if (mWriteGaus4SigmaNSampleHist) {
176 fitResoFile =
new TFile(
"Gaus4SigmaNSample.root",
"UPDATE");
179 Double_t tempSigmaOfSingleTrial =0.42;
181 RefreshPresettings(resoHist, tempSigmaOfSingleTrial, k, thePPosition);
185 Double_t ECenterVary=0.3;
186 Double_t EWidthVary=0.4;
188 Double_t PiCenterVary=0.3;
189 Double_t PiHeightVary=0.2;
190 Double_t PiWidthVary=0.4;
192 Double_t KCenterVary=0.3;
193 Double_t KWidthVary=0.4;
196 =
new TF1(
"sumGs",
"gaus(0)+gaus(3)+gaus(6)", 0., 0.08e-4);
198 Double_t pars_b[9] = {mPiGausHeight, mPiGausCenter, mPiSigma,
199 mEGausHeight, mEGausCenter, mESigma,
200 mKGausHeight, mKGausCenter, mKSigma };
202 sumGs->SetParameters(&pars_b[0]);
204 sumGs->SetParLimits( 0, mPiGausHeight*(1.-PiHeightVary),
205 mPiGausHeight*(1.+PiHeightVary) );
206 sumGs->SetParLimits( 1, mPiGausCenter*(1.-PiCenterVary),
207 mPiGausCenter*(1.+PiCenterVary) );
208 sumGs->SetParLimits( 2, mPiSigma*(1.-PiWidthVary),
209 mPiSigma*(1.+PiWidthVary) );
211 sumGs->SetParLimits( 3, 0.,mEGausHeight);
212 sumGs->SetParLimits( 4, mEGausCenter*(1.-ECenterVary),
213 mEGausCenter*(1.+ECenterVary) );
214 sumGs->SetParLimits( 5, mESigma*(1.-EWidthVary),
215 mESigma*(1.+EWidthVary) );
217 sumGs->SetParLimits( 6, 0.,mKGausHeight);
218 sumGs->SetParLimits( 7, mKGausCenter*(1.-KCenterVary),
219 mKGausCenter*(1.+KCenterVary) );
220 sumGs->SetParLimits( 8, mKSigma*(1.-KWidthVary),
221 mKSigma*(1.+KWidthVary) );
224 resoHist->Fit(
"sumGs",
"R");
226 if (mWriteGaus4SigmaNSampleHist){
231 if (mWriteGaus4SigmaNSampleHist) fitResoFile->Close();
232 float thePar=sumGs->GetParameter(ParIndex);
233 if (mWriteGaus4SigmaNSampleHist) {
delete fitResoFile; fitResoFile=0;}
234 if (sumGs) {
delete sumGs; }
240 void PIDFitter::RefreshPresettings(TH1F* resoHist,
double tempSigmaOfSingleTrial,
int k,
float thePPosition){
242 mEGausHeight =0; mESigma=0.;
243 mPiGausHeight =0; mPiSigma=0.;
244 mKGausHeight =0; mKSigma=0.;
245 mPGausHeight =0; mPSigma=0.;
247 mEGausCenter = electronBandCenter ->Eval(thePPosition,0,0);
248 mPiGausCenter = pionBandCenter ->Eval(thePPosition,0,0);
249 mKGausCenter = kaonBandCenter ->Eval(thePPosition,0,0);
250 mPGausCenter = antiprotonBandCenter->Eval(thePPosition,0,0);
252 PresetHeightAndSigma(mEGausCenter, mEGausHeight, mESigma,
253 resoHist, tempSigmaOfSingleTrial, k);
254 PresetHeightAndSigma(mPiGausCenter, mPiGausHeight, mPiSigma,
255 resoHist, tempSigmaOfSingleTrial, k);
256 PresetHeightAndSigma(mKGausCenter, mKGausHeight, mKSigma,
257 resoHist, tempSigmaOfSingleTrial, k);
258 PresetHeightAndSigma(mPGausCenter, mPGausHeight, mPSigma,
259 resoHist, tempSigmaOfSingleTrial, k);
264 void PIDFitter::PresetHeightAndSigma(
double center,
double& height,
double& sigma, TH1F* resoHist,
double tempSigmaOfSingleTrial,
int k){
266 int nbins = resoHist->GetNbinsX();
268 int((center-mDedxStart)*
float(nbins)/((mDedxEnd-mDedxStart)));
270 height = (centBin<nbins) ? resoHist->GetBinContent(centBin) : 0.;
271 sigma = tempSigmaOfSingleTrial*center/TMath::Sqrt((k+0.5)*((
double(mNNHitsEnd)-
double(mNNHitsStart))/
double(mNNHitsBins)));
277 void PIDFitter::DoPhaseSpaceCalibration(Char_t* fileName4Calibration,Char_t* phaseSpaceCalibFileName){
279 cout<<
" doing phase space calibration.......... "<<endl;
281 double protonRef[mNEtaBins][mNNHitsBins];
282 double pionRef[mNEtaBins][mNNHitsBins];
284 double fitEnd = mDedxEnd;
285 double fitStart = mDedxStart;
287 TFile histo4CalibFile(fileName4Calibration,
"READ");
292 int pionPosition4Calib =int((0.5-mPStart)*mNPBins/(mPEnd-mPStart) );
293 int protonPosition4Calib =int((0.7-mPStart)*mNPBins/(mPEnd-mPStart) );
297 for (
int j=0; j<mNEtaBins; j++)
298 for (
int k=2; k<mNNHitsBins;k++){
300 int i = protonPosition4Calib;
307 char *theName =
new char[80];
309 sprintf(theName,
"h0%d%d%d",i,jname,kname);
310 else sprintf(theName,
"h%d%d%d",i,jname,kname);
312 theHist= (TH1F *)histo4CalibFile.Get(theName);
316 float(i)*((mPEnd-mPStart)/
float(mNPBins)) +
317 (((mPEnd-mPStart)/mNPBins)/2.);
320 RefreshPresettings(theHist, mSigmaOfSingleTrail[j] , k, pPosition);
323 Double_t KCenterVary=0.15;
324 Double_t KWidthVary=0.03;
326 Double_t PiCenterVary=0.1;
327 Double_t PiHeightVary=0.1;
328 Double_t PiWidthVary=0.05;
330 Double_t PCenterVary=0.1;
331 Double_t PWidthVary=0.03;
335 =
new TF1(
"sumGs",
"gaus(0)+gaus(3)+gaus(6)", fitStart, fitEnd);
337 Double_t pars_c[9] = { mPiGausHeight, mPiGausCenter, mPiSigma,
338 mKGausHeight, mKGausCenter, mKSigma,
339 mPGausHeight, mPGausCenter, mPSigma };
341 sumGs->SetParLimits( 0, mPiGausHeight*(1.-PiHeightVary),
342 mPiGausHeight*(1.+PiHeightVary) );
343 sumGs->SetParLimits( 1, mPiGausCenter*(1.-PiCenterVary),
344 mPiGausCenter*(1.+PiCenterVary) );
345 sumGs->SetParLimits( 2, mPiSigma*(1.-PiWidthVary),
346 mPiSigma*(1.+PiWidthVary) );
349 sumGs->SetParLimits( 3, 0.,mKGausHeight);
350 sumGs->SetParLimits( 4, mKGausCenter*(1.-KCenterVary),
351 mKGausCenter*(1.+KCenterVary) );
352 sumGs->SetParLimits( 5, mKSigma*(1.-KWidthVary),
353 mKSigma*(1.+KWidthVary) );
356 sumGs->SetParLimits( 6, 0.,mPGausHeight);
357 sumGs->SetParLimits( 7, mPGausCenter*(1.-PCenterVary),
358 mPGausCenter*(1.+PCenterVary) );
359 sumGs->SetParLimits( 8, mPSigma*(1.-PWidthVary),
360 mPSigma*(1.+PWidthVary) );
362 sumGs->SetParameters(&pars_c[0]);
364 theHist->Fit(
"sumGs",
"NR");
366 protonRef[j][k]=sumGs->GetParameter(7);
368 if (sumGs) {
delete sumGs;}
373 for (
int j=0; j<mNEtaBins; j++)
374 for (
int k=2; k<mNNHitsBins;k++){
376 int i = pionPosition4Calib;
383 char *theName =
new char[80];
385 sprintf(theName,
"h0%d%d%d",i,jname,kname);
386 else sprintf(theName,
"h%d%d%d",i,jname,kname);
388 theHist= (TH1F *)histo4CalibFile.Get(theName);
391 float(i)*((mPEnd-mPStart)/
float(mNPBins)) +
392 (((mPEnd-mPStart)/mNPBins)/2.);
395 RefreshPresettings(theHist, mSigmaOfSingleTrail[j] , k, pPosition);
398 Double_t KCenterVary=0.15;
399 Double_t KWidthVary=0.03;
401 Double_t PiCenterVary=0.1;
402 Double_t PiHeightVary=0.1;
403 Double_t PiWidthVary=0.05;
405 Double_t PCenterVary=0.1;
406 Double_t PWidthVary=0.03;
409 =
new TF1(
"sumGs",
"gaus(0)+gaus(3)+gaus(6)", fitStart, fitEnd);
411 Double_t pars_c[9] = { mPiGausHeight, mPiGausCenter, mPiSigma,
412 mKGausHeight, mKGausCenter, mKSigma,
413 mPGausHeight, mPGausCenter, mPSigma };
415 sumGs->SetParLimits( 0, mPiGausHeight*(1.-PiHeightVary),
416 mPiGausHeight*(1.+PiHeightVary) );
417 sumGs->SetParLimits( 1, mPiGausCenter*(1.-PiCenterVary),
418 mPiGausCenter*(1.+PiCenterVary) );
419 sumGs->SetParLimits( 2, mPiSigma*(1.-PiWidthVary),
420 mPiSigma*(1.+PiWidthVary) );
423 sumGs->SetParLimits( 3, 0.,mKGausHeight );
424 sumGs->SetParLimits( 4, mKGausCenter*(1.-KCenterVary),
425 mKGausCenter*(1.+KCenterVary) );
426 sumGs->SetParLimits( 5, mKSigma*(1.-KWidthVary),
427 mKSigma*(1.+KWidthVary) );
430 sumGs->SetParLimits( 6, 0.,mPGausHeight );
431 sumGs->SetParLimits( 7, mPGausCenter*(1.-PCenterVary),
432 mPGausCenter*(1.+PCenterVary) );
433 sumGs->SetParLimits( 8, mPSigma*(1.-PWidthVary),
434 mPSigma*(1.+PWidthVary) );
436 sumGs->SetParameters(&pars_c[0]);
438 theHist->Fit(
"sumGs",
"NR");
440 pionRef[j][k]=sumGs->GetParameter(1);
443 if (sumGs) {
delete sumGs; }
446 for (
int j=0; j<mNEtaBins; j++)
447 for (
int k=2; k<mNNHitsBins;k++){
448 double theCalib=4.68971e-07;
449 double theOffSet=3.01022e-07;
450 double deltaReference=protonRef[j][k]-pionRef[j][k];
451 double mimimumIonizingPionPosition=
452 float(pionPosition4Calib)*((mPEnd-mPStart)/
float(mNPBins)) +
453 (((mPEnd-mPStart)/mNPBins)/2.);
454 double protonTestPosition=
455 float(protonPosition4Calib)*((mPEnd-mPStart)/
float(mNPBins)) +
456 (((mPEnd-mPStart)/mNPBins)/2.);
458 BBScalePar[j][k]=look4MinDeltaDiff(theCalib*0.7, theCalib*1.3, 100,mimimumIonizingPionPosition ,protonTestPosition , deltaReference);
459 BBOffSetPar[j][k]= theOffSet+minimumIonizingdEdx(BBScalePar[j][k],mimimumIonizingPionPosition )-pionRef[j][k];
461 cout<<
" j "<<j<<
" k "<<k<<
" BBScalePar["<<j<<
"]["<<k<<
"]="<<BBScalePar[j][k]<<
"; BBOffSetPar["<<j<<
"]["<<k<<
"]="<<
BBOffSetPar[j][k]<<
"; "<<endl;
466 for (
int j=0; j<mNEtaBins; j++)
467 for (
int k=0; k<2; k++) {
468 BBScalePar[j][k]=BBScalePar[j][2];
473 ofstream PhaseSpaceFileOut;
474 PhaseSpaceFileOut.open(phaseSpaceCalibFileName);
476 for (
int j=0; j<mNEtaBins; j++)
477 for (
int k=0; k<mNNHitsBins; k++) {
478 PhaseSpaceFileOut<<j<<endl<<k<<endl;
479 PhaseSpaceFileOut<<electronBandCenter->GetParameter(0)<<endl;
480 PhaseSpaceFileOut<<electronBandCenter->GetParameter(1)<<endl;
482 PhaseSpaceFileOut<<BBScalePar[j][k]<<endl;
483 PhaseSpaceFileOut<<electronBandCenter->GetParameter(6)<<endl;
487 PhaseSpaceFileOut.close();
489 cout<<
" phase space calibration finished .......... "<<endl;
495 void PIDFitter::Init(){
497 mWriteGaus4SigmaNSampleHist=kFALSE;
500 if (mWriteGaus4SigmaNSampleHist){
501 TFile* fitResoFile =
new TFile(
"Gaus4SigmaNSample.root",
"RECREATE");
502 fitResoFile->Write();
503 fitResoFile->Close();
507 mWriteSigmaNSampleGraph=kFALSE;
509 if (mWriteSigmaNSampleGraph) {
510 TFile* fitResoFile =
new TFile(
"sigmaNSample.root",
"RECREATE");
516 mSigmaOfSingleTrail =
new double[mNEtaBins];
519 BBScalePar =
new double*[mNEtaBins];
521 for (
int ii=0; ii<mNEtaBins; ii++) {
523 BBScalePar[ii] =
new double[mNNHitsBins];
530 =
new TF1(
"electronBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
532 =
new TF1(
"pionBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
534 =
new TF1(
"kaonBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
536 =
new TF1(
"antiprotonBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
539 =
new TF1(
"pionKaonBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
541 =
new TF1(
"kaonAntiprotonBandCenter",BetheBlochFunction, mPStart,mPEnd, NParameters);
547 Double_t electronPars[7]
548 ={ 1.09344, 0.0199, 3.01022e-07, 1, 0.511e-3, 4.68971e-07, 0.0005 };
550 ={ 1.09344, 0.0199, 3.01022e-07, 1, 0.13957, 4.68971e-07, 0.0005 };
552 ={ 1.09344, 0.0199, 3.01022e-07, 1, 0.49368, 4.68971e-07, 0.0005 };
553 Double_t antiprotonPars[7]
554 ={ 1.09344, 0.0199, 3.01022e-07, 1, 0.93827, 4.68971e-07, 0.0005 };
556 Double_t pionKaonPars[7]
557 ={ 1.09344, 0.0199, 3.01022e-07, 1, 0.387447*1.1, 4.68971e-07, 0.0005 };
559 Double_t kaonAntiprotonPars[7]
560 ={ 1.09344, 0.0199, 3.01022e-07, 1, 0.804893*1.05, 4.68971e-07, 0.0005 };
562 electronBandCenter->SetParameters(&electronPars[0]);
563 pionBandCenter->SetParameters(&pionPars[0]);
564 kaonBandCenter->SetParameters(&kaonPars[0]);
565 antiprotonBandCenter->SetParameters(&antiprotonPars[0]);
566 pionKaonBandCenter->SetParameters(&pionKaonPars[0]);
575 double PIDFitter::delta(
double calib,
double pionPosition,
double protonPosition){
577 pionBandCenter->SetParameter(5,calib);
578 antiprotonBandCenter->SetParameter(5,calib);
580 return (antiprotonBandCenter->Eval(protonPosition,0,0)-
581 pionBandCenter->Eval(pionPosition,0,0));
585 double PIDFitter::look4MinDeltaDiff(
double calibStart,
double calibEnd,
int calibSteps,
double pionPosition,
double protonPosition,
double DeltaRef){
587 double calibSeg=(calibEnd-calibStart)/
double(calibSteps);
588 double thisCalib=calibStart;
589 double minDeltaDiffCalib=5000;
590 double minDeltaDiff=5000;
594 double myDelta=delta(thisCalib,pionPosition,protonPosition);
595 double diff=TMath::Abs(myDelta-DeltaRef);
596 if (diff<minDeltaDiff) {
598 minDeltaDiffCalib=thisCalib;
601 thisCalib=thisCalib+calibSeg;
602 }
while(thisCalib<calibEnd);
604 return minDeltaDiffCalib;
608 double PIDFitter::minimumIonizingdEdx(
double calib,
double pionPosition){
609 pionBandCenter->SetParameter(5,calib);
611 return pionBandCenter->Eval(pionPosition,0,0);
616 void PIDFitter::FitMultiGaus(Char_t* fileNameOfInput, Char_t* fileNameOfOutput){
620 TFile histoFile(fileNameOfInput,
"READ");
622 TFile fittedHistoFile(fileNameOfOutput,
"RECREATE");
628 for (
int i=0; i<mNPBins; i++)
629 for (
int j=0; j<mNEtaBins; j++)
630 for (
int k=0; k<mNNHitsBins;k++){
632 cout<<
" p bin # "<<i<<
", eta bin # "<<j<<
", ndedx bin # "<<k<<endl;
634 char *theName =
new char[80];
636 sprintf(theName,
"h0%d%d%d",i,j,k);
637 else sprintf(theName,
"h%d%d%d",i,j,k);
639 theHist= (TH1F *)histoFile.Get(theName);
642 float(i)*((mPEnd-mPStart)/
float(mNPBins)) +
643 (((mPEnd-mPStart)/mNPBins)/2.);
647 electronBandCenter->SetParameter(5,BBScalePar[j][k]);
648 pionBandCenter->SetParameter(5,BBScalePar[j][k]);
649 kaonBandCenter->SetParameter(5,BBScalePar[j][k]);
650 antiprotonBandCenter->SetParameter(5,BBScalePar[j][k]);
651 pionKaonBandCenter->SetParameter(5,BBScalePar[j][k]);
654 electronBandCenter->SetParameter(2,
BBOffSetPar[j][k]);
657 antiprotonBandCenter->SetParameter(2,
BBOffSetPar[j][k]);
658 pionKaonBandCenter->SetParameter(2,
BBOffSetPar[j][k]);
662 RefreshPresettings(theHist, mSigmaOfSingleTrail[j] , k, pPosition);
665 Double_t KCenterVary=0.1;
666 Double_t KWidthVary=0.1;
668 Double_t PiCenterVary=0.1;
669 Double_t PiHeightVary=0.1;
670 Double_t PiWidthVary=0.1;
672 Double_t PCenterVary=0.1;
673 Double_t PWidthVary=0.1;
675 Double_t ECenterVary=0.;
676 Double_t EWidthVary=0.1;
680 if (pPosition<0.13) {
698 if (pPosition<junction1){
700 Double_t kaonBandLowEdge=pionKaonBandCenter->Eval(pPosition,0.,0.);
701 fitEnd = TMath::Min(kaonBandLowEdge,mDedxEnd);
704 =
new TF1(
"sumGs",
"gaus(0)+gaus(3)", fitStart, fitEnd);
706 Double_t pars_a[6] = { mPiGausHeight, mPiGausCenter, mPiSigma,
707 mEGausHeight, mEGausCenter, mESigma };
709 sumGs->SetParameters(&pars_a[0]);
711 sumGs->SetParLimits( 0, mPiGausHeight*(1.-PiHeightVary),
712 mPiGausHeight*(1.+PiHeightVary) );
713 sumGs->SetParLimits( 1, mPiGausCenter*(1.-PiCenterVary),
714 mPiGausCenter*(1.+PiCenterVary) );
715 sumGs->SetParLimits( 2, mPiSigma*(1.-PiWidthVary),
716 mPiSigma*(1.+PiWidthVary) );
718 sumGs->SetParLimits( 3, 0., mEGausHeight );
719 sumGs->SetParLimits( 4, mEGausCenter*(1.-ECenterVary),
720 mEGausCenter*(1.+ECenterVary));
721 sumGs->SetParLimits( 5, mESigma*(1.-EWidthVary),
722 mESigma*(1.+EWidthVary) );
725 if (theHist->GetEntries()>1.) theHist->Fit(
"sumGs",
"R");
727 fittedHistoFile.cd();
729 if (sumGs)
delete sumGs;
735 if (pPosition>=junction1 && pPosition<junction2){
738 fitEnd = TMath::Min(antiprotonBandLowEdge,mDedxEnd);
741 =
new TF1(
"sumGs",
"gaus(0)+gaus(3)+gaus(6)", fitStart, fitEnd);
743 Double_t pars_b[9] = { mPiGausHeight, mPiGausCenter, mPiSigma,
744 mEGausHeight, mEGausCenter, mESigma,
745 mKGausHeight, mKGausCenter, mKSigma };
747 sumGs->SetParameters(&pars_b[0]);
750 sumGs->SetParLimits( 0, mPiGausHeight*(1.-PiHeightVary),
751 mPiGausHeight*(1.+PiHeightVary));
752 sumGs->SetParLimits( 1, mPiGausCenter*(1.-PiCenterVary),
753 mPiGausCenter*(1.+PiCenterVary) );
754 sumGs->SetParLimits( 2, mPiSigma*(1.-PiWidthVary),
755 mPiSigma*(1.+PiWidthVary) );
757 sumGs->SetParLimits( 3, 0., mEGausHeight );
758 sumGs->SetParLimits( 4, mEGausCenter*(1.-ECenterVary),
759 mEGausCenter*(1.+ECenterVary) );
760 sumGs->SetParLimits( 5, mESigma*(1.-EWidthVary),
761 mESigma*(1.+EWidthVary) );
763 sumGs->SetParLimits( 6, 0., mKGausHeight );
764 sumGs->SetParLimits( 7, mKGausCenter*(1.-KCenterVary),
765 mKGausCenter*(1.+KCenterVary) );
766 sumGs->SetParLimits( 8, mKSigma*(1.-KWidthVary),
767 mKSigma*(1.+KWidthVary) );
770 theHist->Fit(
"sumGs",
"R");
772 fittedHistoFile.cd();
774 if (sumGs)
delete sumGs;
779 if (pPosition>=junction2 && pPosition<junction3){
784 =
new TF1(
"sumGs",
"gaus(0)+gaus(3)+gaus(6)+gaus(9)", fitStart, fitEnd);
786 Double_t pars_c[12] = { mPiGausHeight, mPiGausCenter, mPiSigma,
787 mEGausHeight, mEGausCenter, mESigma,
788 mKGausHeight, mKGausCenter, mKSigma,
789 mPGausHeight, mPGausCenter, mPSigma };
791 sumGs->SetParLimits( 0, mPiGausHeight*(1.-PiHeightVary),
792 mPiGausHeight*(1.+PiHeightVary) );
793 sumGs->SetParLimits( 1, mPiGausCenter*(1.-PiCenterVary),
794 mPiGausCenter*(1.+PiCenterVary) );
795 sumGs->SetParLimits( 2, mPiSigma*(1.-PiWidthVary),
796 mPiSigma*(1.+PiWidthVary) );
799 sumGs->SetParLimits( 3, 0., mEGausHeight );
800 sumGs->SetParLimits( 4, mEGausCenter*(1.-ECenterVary),
801 mEGausCenter*(1.+ECenterVary) );
802 sumGs->SetParLimits( 5, mESigma*(1.-EWidthVary),
803 mESigma*(1.+EWidthVary) );
806 sumGs->SetParLimits( 6, 0., mKGausHeight );
807 sumGs->SetParLimits( 7, mKGausCenter*(1.-KCenterVary),
808 mKGausCenter*(1.+KCenterVary) );
809 sumGs->SetParLimits( 8, mKSigma*(1.-KWidthVary),
810 mKSigma*(1.+KWidthVary) );
813 sumGs->SetParLimits( 9, 0., mPGausHeight );
814 sumGs->SetParLimits(10, mPGausCenter*(1.-PCenterVary),
815 mPGausCenter*(1.+PCenterVary) );
816 sumGs->SetParLimits(11, mPSigma*(1.-PWidthVary),
817 mPSigma*(1.+PWidthVary) );
819 sumGs->SetParameters(&pars_c[0]);
821 theHist->Fit(
"sumGs",
"R");
823 fittedHistoFile.cd();
825 if (sumGs)
delete sumGs;
829 if (pPosition>=junction3 && pPosition<2.){
834 =
new TF1(
"sumGs",
"gaus(0)+gaus(3)+gaus(6)", fitStart, fitEnd);
836 Double_t pars_d[9] = { mPiGausHeight, mPiGausCenter, mPiSigma,
837 mKGausHeight, mKGausCenter, mKSigma,
838 mPGausHeight, mPGausCenter, mPSigma };
840 sumGs->SetParLimits( 0, mPiGausHeight*(1.-PiHeightVary),
841 mPiGausHeight*(1.+PiHeightVary));
842 sumGs->SetParLimits( 1, mPiGausCenter*(1.-PiCenterVary),
843 mPiGausCenter*(1.+PiCenterVary));
844 sumGs->SetParLimits( 2, mPiSigma*(1.-PiWidthVary),
845 mPiSigma*(1.+PiWidthVary));
849 sumGs->SetParLimits( 3, 0., mKGausHeight );
850 sumGs->SetParLimits( 4, mKGausCenter*(1.-KCenterVary),
851 mKGausCenter*(1.+KCenterVary));
852 sumGs->SetParLimits( 5, mKSigma*(1.-KWidthVary),
853 mKSigma*(1.+KWidthVary));
856 sumGs->SetParLimits( 6, 0., mPGausHeight );
857 sumGs->SetParLimits( 7, mPGausCenter*(1.-PCenterVary),
858 mPGausCenter*(1.+PCenterVary));
859 sumGs->SetParLimits( 8, mPSigma*(1.-PWidthVary),
860 mPSigma*(1.+PWidthVary));
862 sumGs->SetParameters(&pars_d[0]);
864 theHist->Fit(
"sumGs",
"R");
866 fittedHistoFile.cd();
868 if (sumGs)
delete sumGs;
875 fittedHistoFile.Write();
876 fittedHistoFile.Close();
880 void PIDFitter::ExtrapAmp(Char_t* fileNameOfInput, Char_t* fileNameOfOutput){
882 cout<<
" **********extraping pion amp. begin********* "<<endl;
884 Double_t pBegin = mPStart;
885 Double_t pEnd = mPEnd;
887 TFile* gausHistFile =
new TFile(fileNameOfInput,
"READ");
889 TFile* ampHistFile =
new TFile(fileNameOfOutput,
"RECREATE");
892 for (
int j=0; j<mNEtaBins; j++)
893 for (
int k=0; k<mNNHitsBins;k++){
895 char *PiAmpName =
new char[80];
896 sprintf(PiAmpName,
"PiAmp%d%d",j,k);
897 char *EAmpName =
new char[80];
898 sprintf(EAmpName,
"EAmp%d%d",j,k);
899 char *KAmpName =
new char[80];
900 sprintf(KAmpName,
"KAmp%d%d",j,k);
901 char *PAmpName =
new char[80];
902 sprintf(PAmpName,
"PAmp%d%d",j,k);
904 TH1F* PiAmpHisto =
new TH1F(PiAmpName, PiAmpName, mNPBins,mPStart,mPEnd);
905 TH1F* EAmpHisto =
new TH1F(EAmpName, EAmpName, mNPBins,mPStart,mPEnd);
906 TH1F* KAmpHisto =
new TH1F(KAmpName, KAmpName, mNPBins,mPStart,mPEnd);
907 TH1F* PAmpHisto =
new TH1F(PAmpName, PAmpName, mNPBins,mPStart,mPEnd);
909 PiAmpHisto->SetLineColor(4);
910 EAmpHisto->SetLineColor(6);
911 KAmpHisto->SetLineColor(2);
912 PAmpHisto->SetLineColor(3);
916 double nhitsPosition=double((k+0.5)*(
float(mNNHitsEnd-mNNHitsStart)/
float(mNNHitsBins)));
919 for (
int i=0; i<mNPBins; i++){
922 float(i)*((pEnd-pBegin)/
float(mNPBins)) +
923 (((pEnd-pBegin)/mNPBins)/2.);
925 char *theHistName =
new char[80];
927 sprintf(theHistName,
"h0%d%d%d",i,j,k);
928 else sprintf(theHistName,
"h%d%d%d",i,j,k);
930 TH1F* theHist= (TH1F *)gausHistFile->Get(theHistName);
933 TF1* sumGs=theHist->GetFunction(
"sumGs");
935 if (!sumGs)
continue;
937 if (pPosition<junction1){
938 PiAmpHisto->SetBinContent(i+1,sumGs->GetParameter(0));
939 PiAmpHisto->SetBinError(i+1, sumGs->GetParError(0));
940 EAmpHisto->SetBinContent(i+1,sumGs->GetParameter(3));
941 EAmpHisto->SetBinError(i+1, sumGs->GetParError(3));
944 if (pPosition>=junction1 && pPosition<junction2){
945 PiAmpHisto->SetBinContent(i+1,sumGs->GetParameter(0));
946 PiAmpHisto->SetBinError(i+1, sumGs->GetParError(0));
947 EAmpHisto->SetBinContent(i+1,sumGs->GetParameter(3));
948 EAmpHisto->SetBinError(i+1, sumGs->GetParError(3));
949 KAmpHisto->SetBinContent(i+1,sumGs->GetParameter(6));
950 KAmpHisto->SetBinError(i+1, sumGs->GetParError(6));
952 if (pPosition>=junction2 && pPosition<junction3 ){
953 PiAmpHisto->SetBinContent(i+1,sumGs->GetParameter(0));
954 PiAmpHisto->SetBinError(i+1, sumGs->GetParError(0));
955 EAmpHisto->SetBinContent(i+1,sumGs->GetParameter(3));
956 EAmpHisto->SetBinError(i+1, sumGs->GetParError(3));
957 KAmpHisto->SetBinContent(i+1,sumGs->GetParameter(6));
958 KAmpHisto->SetBinError(i+1, sumGs->GetParError(6));
959 PAmpHisto->SetBinContent(i+1,sumGs->GetParameter(9));
960 PAmpHisto->SetBinError(i+1, sumGs->GetParError(9));
963 if (pPosition>=junction3 && pPosition<2.){
964 PiAmpHisto->SetBinContent(i+1,sumGs->GetParameter(0));
965 PiAmpHisto->SetBinError(i+1, sumGs->GetParError(0));
966 KAmpHisto->SetBinContent(i+1,sumGs->GetParameter(3));
967 KAmpHisto->SetBinError(i+1, sumGs->GetParError(3));
968 PAmpHisto->SetBinContent(i+1,sumGs->GetParameter(6));
969 PAmpHisto->SetBinError(i+1, sumGs->GetParError(6));
978 double ampPeakPos = 0.45;
982 for (
int t=0; t<4; t++){
983 TF1* gs =
new TF1(
"gs",
"gaus",low,high);
984 PiAmpHisto->Fit(
"gs",
"NWR");
985 low = gs->GetParameter(1)-0.13;
986 high = gs->GetParameter(1)+0.13;
987 ampPeakPos= gs->GetParameter(1);
996 TF1* PiFcnCenter =
new TF1(
"PiFcnCenter",
"pol3",0.4,0.7);
998 TF1* PiFcnLeft =
new TF1(
"PiFcnLeft",
"pol3",0.1,ampPeakPos-0.05);
999 PiFcnLeft->SetLineColor(4);
1001 TF1* PiFcnRight =
new TF1(
"PiFcnRight",
"expo",0.7,1.4);
1002 PiFcnRight->SetLineColor(3);
1004 PiAmpHisto->Fit(
"PiFcnCenter",
"WR+");
1009 float crossBandBegin = 0.8;
1010 float brossBandEnd = 1.2;
1013 TGraphErrors* PiAmpGraphRight =
new TGraphErrors();
1015 for (
int ampbin = 0; ampbin<PiAmpHisto->GetNbinsX(); ampbin++){
1016 if (PiAmpHisto->GetBinCenter(ampbin) < crossBandBegin ||
1017 PiAmpHisto->GetBinCenter(ampbin) > brossBandEnd){
1018 PiAmpGraphRight->SetPoint(PiAmpGraphRight->GetN(), PiAmpHisto->GetBinCenter(ampbin), PiAmpHisto->GetBinContent(ampbin));
1019 PiAmpGraphRight->SetPointError(PiAmpGraphRight->GetN()-1, PiAmpHisto->GetBinCenter(ampbin), PiAmpHisto->GetBinContent(ampbin));
1024 PiAmpGraphRight->Fit(
"PiFcnRight",
"WR+");
1026 PiAmpHisto->GetListOfFunctions()->Add(PiAmpGraphRight->GetFunction(
"PiFcnRight"));
1029 if (PiFcnCenter)
delete PiFcnCenter;
1030 if (PiFcnLeft)
delete PiFcnLeft;
1031 if (PiFcnRight)
delete PiFcnRight;
1034 float EAmpFitBegin = EAmpHisto->GetBinCenter(EAmpHisto->GetMaximumBin())+0.03;
1037 if (nhitsPosition <= 15. && nhitsPosition >10) EAmpFitBegin +=0.05;
1038 if (nhitsPosition <= 10. && nhitsPosition >5) EAmpFitBegin +=0.09;
1041 TF1* EFcnLeft =
new TF1(
"EFcnLeft",
"expo",EAmpFitBegin,EAmpFitBegin+0.22);
1042 EFcnLeft->SetLineColor(2);
1043 TF1* EFcnRight =
new TF1(
"EFcnRight",
"expo",0.35,0.8);
1044 EFcnRight->SetLineColor(4);
1048 crossBandBegin = 0.45;
1051 TGraphErrors* EAmpGraphRight =
new TGraphErrors();
1053 for (
int ampbin = 0; ampbin<EAmpHisto->GetNbinsX(); ampbin++){
1054 if (EAmpHisto->GetBinCenter(ampbin) < crossBandBegin ||
1055 EAmpHisto->GetBinCenter(ampbin) > brossBandEnd){
1056 EAmpGraphRight->SetPoint(EAmpGraphRight->GetN(), EAmpHisto->GetBinCenter(ampbin), EAmpHisto->GetBinContent(ampbin));
1057 EAmpGraphRight->SetPointError(EAmpGraphRight->GetN()-1, EAmpHisto->GetBinCenter(ampbin), EAmpHisto->GetBinContent(ampbin));
1062 EAmpGraphRight->Fit(
"EFcnRight",
"WR+");
1064 EAmpHisto->GetListOfFunctions()->Add(EAmpGraphRight->GetFunction(
"EFcnRight"));
1070 if (EFcnLeft)
delete EFcnLeft;
1071 if (EFcnRight)
delete EFcnRight;
1093 TF1* KFcnCenter =
new TF1(
"KFcnCenter",
"gaus",low,high);
1095 TF1* KFcnLeft =
new TF1(
"KFcnLeft",
"pol3", (nhitsPosition <= 25.) ? 0.28 : 0.35, 0.65);
1096 KFcnLeft->SetLineColor(4);
1098 TF1* KFcnRight =
new TF1(
"KFcnRight",
"expo",0.8,2.);
1099 KFcnRight->SetLineColor(3);
1102 crossBandBegin = 0.48;
1103 brossBandEnd = 0.58;
1106 TGraphErrors* KAmpGraphLeft =
new TGraphErrors();
1108 for (
int ampbin = 0; ampbin<KAmpHisto->GetNbinsX(); ampbin++){
1109 if (KAmpHisto->GetBinCenter(ampbin) < crossBandBegin ||
1110 KAmpHisto->GetBinCenter(ampbin) > brossBandEnd){
1111 KAmpGraphLeft->SetPoint(KAmpGraphLeft->GetN(), KAmpHisto->GetBinCenter(ampbin), KAmpHisto->GetBinContent(ampbin));
1112 KAmpGraphLeft->SetPointError(KAmpGraphLeft->GetN()-1, KAmpHisto->GetBinCenter(ampbin), KAmpHisto->GetBinContent(ampbin));
1116 KAmpGraphLeft->Fit(
"KFcnLeft",
"WR+");
1117 KAmpHisto->GetListOfFunctions()->Add(KAmpGraphLeft->GetFunction(
"KFcnLeft"));
1118 crossBandBegin = 0.9;
1122 TGraphErrors* KAmpGraphRight =
new TGraphErrors();
1124 for (
int ampbin = 0; ampbin<KAmpHisto->GetNbinsX(); ampbin++){
1125 if (KAmpHisto->GetBinCenter(ampbin) < crossBandBegin ||
1126 KAmpHisto->GetBinCenter(ampbin) > brossBandEnd){
1127 KAmpGraphRight->SetPoint(KAmpGraphRight->GetN(), KAmpHisto->GetBinCenter(ampbin), KAmpHisto->GetBinContent(ampbin));
1128 KAmpGraphRight->SetPointError(KAmpGraphRight->GetN()-1, KAmpHisto->GetBinCenter(ampbin), KAmpHisto->GetBinContent(ampbin));
1133 KAmpGraphRight->Fit(
"KFcnRight",
"WR+");
1135 KAmpHisto->GetListOfFunctions()->Add(KAmpGraphRight->GetFunction(
"KFcnRight"));
1137 KAmpHisto->Fit(
"KFcnCenter",
"WR+");
1140 if ( KFcnCenter->GetXmin()<KFcnLeft->GetXmax() && KFcnLeft->GetXmax() < KFcnCenter->GetXmax() )
1141 KAmpHisto->GetFunction(
"KFcnCenter")->SetRange(KFcnLeft->GetXmax()-0.05, KFcnCenter->GetXmax());
1145 if (KFcnCenter)
delete KFcnCenter;
1146 if (KFcnLeft)
delete KFcnLeft;
1147 if (KFcnRight)
delete KFcnRight;
1152 TF1* PFcnLeft =
new TF1(
"PFcnLeft",
"pol4",0.6,1.4);
1153 TF1* PFcnRight =
new TF1(
"PFcnRight",
"expo",1.4,2.);
1155 crossBandBegin = 1.5;
1159 TGraphErrors* PAmpGraphRight =
new TGraphErrors();
1161 for (
int ampbin = 0; ampbin<PAmpHisto->GetNbinsX(); ampbin++){
1162 if (PAmpHisto->GetBinCenter(ampbin) < crossBandBegin ||
1163 PAmpHisto->GetBinCenter(ampbin) > brossBandEnd){
1164 PAmpGraphRight->SetPoint(PAmpGraphRight->GetN(), PAmpHisto->GetBinCenter(ampbin), PAmpHisto->GetBinContent(ampbin));
1165 PAmpGraphRight->SetPointError(PAmpGraphRight->GetN()-1, PAmpHisto->GetBinCenter(ampbin), PAmpHisto->GetBinContent(ampbin));
1170 PAmpGraphRight->Fit(
"PFcnRight",
"WR+");
1172 PAmpHisto->GetListOfFunctions()->Add(PAmpGraphRight->GetFunction(
"PFcnRight"));
1175 PAmpHisto->Fit(
"PFcnLeft",
"RW+");
1177 if (PFcnRight)
delete PFcnRight;
1178 if (PFcnLeft)
delete PFcnLeft;
1183 PiAmpHisto->Write(PiAmpHisto->GetName(),TObject::kOverwrite | TObject::kSingleKey);
1184 EAmpHisto->Write(EAmpHisto->GetName(),TObject::kOverwrite | TObject::kSingleKey);
1185 KAmpHisto->Write(KAmpHisto->GetName(),TObject::kOverwrite | TObject::kSingleKey);
1186 PAmpHisto->Write(PAmpHisto->GetName(),TObject::kOverwrite | TObject::kSingleKey);
1191 ampHistFile->Write();
1192 ampHistFile->Close();
1193 gausHistFile->Close();
1194 cout<<
" **********extraping pion amp. end********* "<<endl;
1198 Double_t sigmaNSampleFitFcn(Double_t* x, Double_t *par){
1200 if (x[0])
return par[0]/::sqrt(x[0]);
TF1 * kaonAntiprotonBandCenter
//for drawing line between pion and kaon bands
double ** BBOffSetPar
//for drawing line between kaon and antiproton bands