17 #include "TProfile2D.h"
18 #include "TProfile3D.h"
28 #include "TPaveStats.h"
32 #include "TVirtualFitter.h"
34 #define BohrR 1963.6885 // Bohr Radius for pions
35 #define FmToGeV 0.19733 // conversion to fm
37 #define masspiC 0.1395702 // pi+ mass (GeV/c^2)
42 int CollisionType_def=0;// PbPb, pPb, pp
43 int FitType=0;// (0)Edgeworth, (1)Laguerre, (2)Levy
45 int Mbin=0;// 0-9: centrality bin in widths of 5%
46 int CHARGE=-1;// -1 or +1: + or - pions for same-charge case, --+ or -++, ---+ or -+++
48 int EDbin=0;// 0 or 1: Kt3 bin
49 double G_def = 0.;// coherent %
50 double Rcoh_def = 1.;// Radius of Gaussian coherent component in fm
52 bool MRC=1;// Momentum Resolution Corrections?
53 bool MuonCorrection=1;// correct for Muons?
55 int f_choice=0;// 0(Core/Halo), 1(40fm), 2(70fm), 3(100fm)
60 bool SaveToFile_def=0;
62 float TwoFrac;// Lambda parameter
63 float OneFrac;// Lambda^{1/2}
64 float ThreeFrac;// Lambda^{3/2}
65 double Qcut_pp = 0.6;// 0.6
66 double Qcut_PbPb = 0.1;
67 double NormQcutLow_pp = 1.0;
68 double NormQcutHigh_pp = 1.5;
69 double NormQcutLow_PbPb = .15;
70 double NormQcutHigh_PbPb = .2;// was .175
73 const int BINRANGE_3=60;// q12,q13,q23
75 double A_3[BINRANGE_3][BINRANGE_3][BINRANGE_3];// q12,q13,q23
76 double A_3_e[BINRANGE_3][BINRANGE_3][BINRANGE_3];// q12,q13,q23
77 double B_3[BINRANGE_3][BINRANGE_3][BINRANGE_3];// q12,q13,q23
78 double BinCenters[400];
83 void fcn_c3(int&, double*, double&, double[], int);
90 void SetFSICorrelations();
91 void SetFSIindex(Float_t);
92 Float_t FSICorrelation(Int_t, Int_t, Float_t);
93 void SetMuonCorrections();
94 void SetMomResCorrections();
95 double Gamov(int, double);
103 TH1D *C3muonCorrectionSC[2];
105 double AvgQinvSS[30];
106 double AvgQinvOS[30];
107 double BinCentersQ4[20];
111 void Fit_c3(bool SaveToFile=SaveToFile_def, int CollisionType=CollisionType_def, double G=G_def, double Rcoh=Rcoh_def){
113 SaveToFile_def=SaveToFile;
114 CollisionType_def=CollisionType;
120 if(CollisionType==0){// PbPb
121 //_file0 = new TFile("Results/PDC_11h_3Dhistos.root","READ");
122 //_file0 = new TFile("Results/PDC_11h_c3FitBuild.root","READ");
123 _file0 = new TFile("Results/PDC_11h_LowNorm_HighNorm.root","READ");
124 }else if(CollisionType==1){// pPb
125 //_file0 = new TFile("Results/PDC_13bc_kINT7_LowNorm.root","READ");
126 _file0 = new TFile("Results/PDC_13bc_kINT7_LowNorm_HighNorm.root","READ");
128 _file0 = new TFile("Results/PDC_10bcde_kMB_3Dhisto_LowNorm_HighNorm.root","READ");
132 TDirectoryFile *tdir = (TDirectoryFile*)_file0->Get("PWGCF.outputFourPionAnalysis.root");
133 if(CollisionType==0) MyList=(TList*)tdir->Get("FourPionOutput_1");
134 else MyList=(TList*)tdir->Get("FourPionOutput_2");
135 //MyList=(TList*)_file0->Get("MyList");
140 if(CollisionType==0) {Q3LimitLow = 0.01; Q3LimitHigh = 0.08;}// 0.01 and 0.08
141 else {Q3LimitLow = 0.01; Q3LimitHigh = 0.25;}// 0.01 and 0.25
146 OneFrac = sqrt(TwoFrac);
147 ThreeFrac = pow(TwoFrac, 1.5);
149 //// Core/Halo, 40fm, 70fm, 100fm
150 float ThermShift_f33[4]={0., 0.06933, 0.01637, 0.006326};
151 float ThermShift_f32[4]={0., -0.0185, -0.005301, -0.002286};
152 float ThermShift_f31[4]={0., -0.01382, -0.0004682, 0.0005337};
153 float f33prime = ThreeFrac;
154 float f32prime = TwoFrac*(1-OneFrac);
155 float f31prime = pow(1-OneFrac,3) + 3*OneFrac*pow(1-OneFrac,2);
156 f33prime += ThermShift_f33[f_choice];
157 f32prime += ThermShift_f32[f_choice];
158 f31prime += ThermShift_f31[f_choice];
159 float f33 = f33prime;
160 float f32 = f32prime/TwoFrac;
161 float f31 = f31prime - 3*((1-TwoFrac)*(1-OneFrac) + ThermShift_f32[f_choice]*(1-TwoFrac)/TwoFrac);
162 //cout<<f33 + 3*f32 + f31<<endl;
165 cout<<"Mbin = "<<Mbin<<" KT3 = "<<EDbin<<endl;
167 if(CollisionType==0){
168 if(Mbin==0) {RbinMRC=10;}
169 else if(Mbin==1) {RbinMRC=9;}
170 else if(Mbin<=3) {RbinMRC=8;}
171 else if(Mbin<=5) {RbinMRC=7;}
178 if(CollisionType==0) BINLIMIT_3=20;
181 // bin centers from QS+FSI
182 double BinCenterPbPbCentral[40]={0.00206385, 0.00818515, 0.0129022, 0.0177584, 0.0226881, 0.027647, 0.032622, 0.0376015, 0.042588, 0.0475767, 0.0525692, 0.0575625, 0.0625569, 0.0675511, 0.0725471, 0.0775436, 0.0825399, 0.0875364, 0.0925339, 0.0975321, 0.102529, 0.107527, 0.112525, 0.117523, 0.122522, 0.12752, 0.132519, 0.137518, 0.142516, 0.147515, 0.152514, 0.157513, 0.162513, 0.167512, 0.172511, 0.177511, 0.18251, 0.187509, 0.192509, 0.197509};
183 double BinCenterpPbAndpp[40]={0.00359275, 0.016357, 0.0257109, 0.035445, 0.045297, 0.0552251, 0.0651888, 0.0751397, 0.0851088, 0.0951108, 0.105084, 0.115079, 0.12507, 0.135059, 0.145053, 0.155049, 0.16505, 0.175038, 0.185039, 0.195034, 0.205023, 0.215027, 0.225024, 0.235023, 0.245011, 0.255017, 0.265017, 0.275021, 0.285021, 0.295017, 0.305018, 0.315018, 0.325013, 0.335011, 0.345016, 0.355019, 0.365012, 0.375016, 0.385017, 0.395016};
184 if(CollisionType==0){
185 for(int i=0; i<40; i++) BinCenters[i] = BinCenterPbPbCentral[i];
187 for(int i=0; i<40; i++) BinCenters[i] = BinCenterpPbAndpp[i];
190 // extend BinCenters for high q
191 for(int index=40; index<400; index++){
192 if(CollisionType==0) BinCenters[index] = (index+0.5)*(0.005);
193 else BinCenters[index] = (index+0.5)*(0.010);
195 // Set 0's to 3-particle fit arrays
196 for(int i=1; i<=BINLIMIT_3; i++){// bin number
197 for(int j=1; j<=BINLIMIT_3; j++){// bin number
198 for(int k=1; k<=BINLIMIT_3; k++){// bin number
199 A_3[i-1][j-1][k-1]=0;
200 A_3_e[i-1][j-1][k-1]=0;
201 B_3[i-1][j-1][k-1]=0;
208 TH3D *ThreeParticle[2][2][2][5];// ch1,ch2,ch3,term
209 TProfile3D *K3avg[2][2][2][4];
210 double norm_3[5]={0};
213 gStyle->SetOptStat(0);
214 gStyle->SetOptDate(0);
215 gStyle->SetOptFit(0111);
220 SetFSICorrelations();
221 SetMomResCorrections();
222 SetMuonCorrections();
224 /////////////////////////////////////////////////////////
228 TH1D *Events = (TH1D*)MyList->FindObject("fEvents2");
231 cout<<"#Events = "<<Events->Integral(Mbin+1,Mbin+1)<<endl;
235 ///////////////////////////////////
238 for(int term=0; term<5; term++){
240 TString *name3 = new TString("ThreeParticle_Charge1_");
242 name3->Append("_Charge2_");
244 name3->Append("_Charge3_");
246 name3->Append("_M_");
248 name3->Append("_ED_");
250 name3->Append("_Term_");
253 TString *nameNorm3=new TString(name3->Data());
254 nameNorm3->Append("_Norm");
256 TString *nameK3=new TString(name3->Data());
257 nameK3->Append("_Kfactor3D");
259 name3->Append("_3D");
263 norm_3[term] = ((TH1D*)MyList->FindObject(nameNorm3->Data()))->Integral();
264 ThreeParticle[0][0][0][term] = (TH3D*)MyList->FindObject(name3->Data());
265 ThreeParticle[0][0][0][term]->Sumw2();
266 //if(0==0 && 0==0) cout<<"3-pion norms "<<norm_3[term]<<endl;
267 ThreeParticle[0][0][0][term]->Scale(norm_3[0]/norm_3[term]);
268 ThreeParticle[0][0][0][term]->SetMarkerStyle(20);
269 ThreeParticle[0][0][0][term]->SetTitle("");
274 K3avg[0][0][0][term] = (TProfile3D*)MyList->FindObject(nameK3->Data());
283 cout<<"Done getting Histograms"<<endl;
285 TF1 *Unity=new TF1("Unity","1",0,100);
286 Unity->SetLineStyle(2);
289 int ch1=0,ch2=0,ch3=0;
293 ///////////////////////////////////////////////////////////
295 cout<<"3-pion section"<<endl;
297 TCanvas *can2 = new TCanvas("can2", "can2",600,53,700,500);
298 can2->SetHighLightColor(2);
299 can2->Range(-0.7838115,-1.033258,0.7838115,1.033258);
300 gStyle->SetOptFit(0111);
301 can2->SetFillColor(10);
302 can2->SetBorderMode(0);
303 can2->SetBorderSize(2);
306 can2->SetFrameFillColor(0);
307 can2->SetFrameBorderMode(0);
308 can2->SetFrameBorderMode(0);
309 gPad->SetRightMargin(0.02); gPad->SetTopMargin(0.02);
312 float Q3HistoLimit=0.12;
313 if(CollisionType!=0){ Q3BINS=60; Q3HistoLimit=0.6;}
315 TH1D *c3_hist = new TH1D("c3_hist","",Q3BINS,0,Q3HistoLimit);
316 TH1D *Combinatorics_1d = new TH1D("Combinatorics_1d","",Q3BINS,0,Q3HistoLimit);
317 TH1D *GenSignalExpected_num=new TH1D("GenSignalExpected_num","",Q3BINS,0,Q3HistoLimit);
318 TH1D *GenSignalExpected_den=new TH1D("GenSignalExpected_den","",Q3BINS,0,Q3HistoLimit);
319 double c3_e[100]={0};
327 for(int i=2; i<=ThreeParticle[0][0][0][0]->GetNbinsX(); i++){// bin number
328 double Q12 = BinCenters[i-1];// true center
329 //int Q12bin = int(Q12/0.01)+1;
331 for(int j=2; j<=ThreeParticle[0][0][0][0]->GetNbinsY(); j++){// bin number
332 double Q13 = BinCenters[j-1];// true center
333 //int Q13bin = int(Q13/0.01)+1;
335 for(int k=2; k<=ThreeParticle[0][0][0][0]->GetNbinsZ(); k++){// bin number
336 double Q23 = BinCenters[k-1];// true center
337 //int Q23bin = int(Q23/0.01)+1;
340 if(Q12 < sqrt(pow(Q13,2)+pow(Q23,2) - 2*Q13*Q23)) continue;// not all configurations are possible
341 if(Q12 > sqrt(pow(Q13,2)+pow(Q23,2) + 2*Q13*Q23)) continue;// not all configurations are possible
343 double Q3 = sqrt(pow(Q12,2) + pow(Q13,2) + pow(Q23,2));
344 int Q3bin = c3_hist->GetXaxis()->FindBin(Q3);
347 double K3 = K3avg[0][0][0][0]->GetBinContent(i,j,k);
348 double K2_12 = K3avg[0][0][0][1]->GetBinContent(i,j,k);
349 double K2_13 = K3avg[0][0][0][2]->GetBinContent(i,j,k);
350 double K2_23 = K3avg[0][0][0][3]->GetBinContent(i,j,k);
355 double TERM1=ThreeParticle[ch1][ch2][ch3][0]->GetBinContent(i,j,k);// N3 (3-pion yield per q12,q13,q23 cell). 3-pions from same-event
356 double TERM2=ThreeParticle[ch1][ch2][ch3][1]->GetBinContent(i,j,k);// N2*N1. 1 and 2 from same-event
357 double TERM3=ThreeParticle[ch1][ch2][ch3][2]->GetBinContent(i,j,k);// N2*N1. 1 and 3 from same-event
358 double TERM4=ThreeParticle[ch1][ch2][ch3][3]->GetBinContent(i,j,k);// N2*N1. 2 and 3 from same-event
359 double TERM5=ThreeParticle[ch1][ch2][ch3][4]->GetBinContent(i,j,k);// N1*N1*N1. All from different events (pure combinatorics)
362 if(TERM1==0 && TERM2==0 && TERM3==0 && TERM4==0 && TERM5==0) continue;
363 if(TERM1==0 || TERM2==0 || TERM3==0 || TERM4==0 || TERM5==0) continue;
367 TERM1 *= MRC_SC_3[0]->GetBinContent(MRC_SC_3[0]->GetXaxis()->FindBin(Q3));
368 TERM2 *= MRC_SC_3[1]->GetBinContent(MRC_SC_3[1]->GetXaxis()->FindBin(Q3));
369 TERM3 *= MRC_SC_3[1]->GetBinContent(MRC_SC_3[1]->GetXaxis()->FindBin(Q3));
370 TERM4 *= MRC_SC_3[1]->GetBinContent(MRC_SC_3[1]->GetXaxis()->FindBin(Q3));
371 TERM5 *= MRC_SC_3[2]->GetBinContent(MRC_SC_3[2]->GetXaxis()->FindBin(Q3));
373 double MuonCorr1=1, MuonCorr2=1, MuonCorr3=1, MuonCorr4=1;
375 MuonCorr1 = C3muonCorrectionSC[0]->GetBinContent(C3muonCorrectionSC[0]->GetXaxis()->FindBin(Q3));
376 MuonCorr2 = C3muonCorrectionSC[1]->GetBinContent(C3muonCorrectionSC[0]->GetXaxis()->FindBin(Q3));
377 MuonCorr3 = MuonCorr2;
378 MuonCorr4 = MuonCorr2;
383 // Purify. Isolate pure 3-pion QS correlations using Lambda and K3 (removes lower order correlations)
385 N3_QS -= ( pow(1-OneFrac,3) + 3*OneFrac*pow(1-OneFrac,2) )*TERM5;
386 N3_QS -= (1-OneFrac)*(TERM2 + TERM3 + TERM4 - 3*(1-TwoFrac)*TERM5);
392 // Isolate 3-pion cumulant
394 value_num -= (TERM2 - (1-TwoFrac)*TERM5)*K2_12/TwoFrac * MuonCorr2;
395 value_num -= (TERM3 - (1-TwoFrac)*TERM5)*K2_13/TwoFrac * MuonCorr3;
396 value_num -= (TERM4 - (1-TwoFrac)*TERM5)*K2_23/TwoFrac * MuonCorr4;
397 value_num += 2*TERM5;
404 N3_QS_e += pow(( pow(1-OneFrac,3) +3*OneFrac*pow(1-OneFrac,2) )*sqrt(TERM5),2);
405 N3_QS_e += (pow((1-OneFrac),2)*(TERM2 + TERM3 + TERM4) + pow((1-OneFrac)*3*(1-TwoFrac)*sqrt(TERM5),2));
406 N3_QS_e /= pow(ThreeFrac,2);
407 N3_QS_e *= pow(K3,2);
409 value_num_e = N3_QS_e;
410 value_num_e += (pow(K2_12/TwoFrac*sqrt(TERM2),2) + pow((1-TwoFrac)*K2_12/TwoFrac*sqrt(TERM5),2));
411 value_num_e += (pow(K2_13/TwoFrac*sqrt(TERM3),2) + pow((1-TwoFrac)*K2_13/TwoFrac*sqrt(TERM5),2));
412 value_num_e += (pow(K2_23/TwoFrac*sqrt(TERM4),2) + pow((1-TwoFrac)*K2_23/TwoFrac*sqrt(TERM5),2));
413 value_num_e += pow(2*sqrt(TERM5),2);
415 c3_e[Q3bin-1] += value_num_e + TERM5;// add baseline stat error
419 c3_hist->Fill(Q3, value_num + TERM5);// for cumulant correlation function
420 Combinatorics_1d->Fill(Q3, TERM5);
423 A_3[i-1][j-1][k-1] = value_num + TERM5;
424 B_3[i-1][j-1][k-1] = TERM5;
425 A_3_e[i-1][j-1][k-1] = sqrt(value_num_e + TERM5);
426 //if(i==j && i==k && i==4) cout<<A_3[i-1][j-1][k-1]<<" "<<B_3[i-1][j-1][k-1]<<" "<<A_3_e[i-1][j-1][k-1]<<endl;
427 ///////////////////////////////////////////////////////////
435 ////////////////////////////
437 // Intermediate steps
438 for(int i=0; i<Q3BINS; i++) {c3_hist->SetBinError(i+1, sqrt(c3_e[i]));}
440 c3_hist->Divide(Combinatorics_1d);
442 ///////////////////////////////////////////////////////////////////////////////////////////////////
446 c3_hist->GetXaxis()->SetTitle("#font[12]{Q}_{3} (GeV/#font[12]{c})");
447 c3_hist->GetYaxis()->SetTitle("#font[12]{#bf{c}}_{3}");
448 c3_hist->GetYaxis()->SetTitleSize(0.045); c3_hist->GetXaxis()->SetTitleSize(0.045);
449 c3_hist->GetYaxis()->SetTitleOffset(1.1);
450 c3_hist->GetXaxis()->SetRangeUser(0,Q3LimitHigh);
451 c3_hist->GetYaxis()->SetRangeUser(0.9,4);
452 c3_hist->SetMarkerStyle(25);
453 c3_hist->SetMarkerColor(2);
454 c3_hist->SetLineColor(2);
455 c3_hist->SetMaximum(3);
456 c3_hist->SetMinimum(.7);
458 //legend2->AddEntry(c3_hist,"#font[12]{#bf{c}}_{3} (cumulant correlation)","p");
463 TMinuit MyMinuit_c3(npar_c3);
464 MyMinuit_c3.SetFCN(fcn_c3);
466 double arglist_c3 = 0;
467 MyMinuit_c3.mnexcm("SET NOWarnings",&arglist_c3,1, ierflg_c3);
469 MyMinuit_c3.mnexcm("SET PRint",&arglist_c3,1, ierflg_c3);
470 //arglist_c3=2;// improve Minimization Strategy (1 is default)
471 //MyMinuit_c3.mnexcm("SET STR",&arglist_c3,1,ierflg_c3);
473 //MyMinuit_c3.mnexcm("SCAN", &arglist_c3,1,ierflg_c3);
475 MyMinuit_c3.mnexcm("MIGRAD", &arglist_c3 ,1,ierflg_c3);
480 c3Fit1D_Expan=new TF1("c3Fit1D_Expan","[0]*(1+[1]*exp(-pow([2]*x/0.19733,2)/2.) * pow(1 + ([3]/(6.*pow(2.,1.5))*(8.*pow([2]*x/sqrt(3.)/0.19733,3) - 12.*pow([2]*x/sqrt(3.)/0.19733,1))) + ([4]/(24.*pow(2.,2))*(16.*pow([2]*x/sqrt(3.)/0.19733,4) -48.*pow([2]*x/sqrt(3.)/0.19733,2) + 12)) + [5]/(120.*pow(2.,2.5))*(32.*pow(x/sqrt(3.)*[2]/0.19733,5) - 160.*pow(x/sqrt(3.)*[2]/0.19733,3) + 120*x/sqrt(3.)*[2]/0.19733) ,3))",0,1);
481 }else if(FitType==1){
482 c3Fit1D_Expan=new TF1("c3Fit1D_Expan","[0]*(1+[1]*exp(-[2]*x/0.19733 * sqrt(3.)/2.) * pow(1 + [3]*([2]*x/sqrt(3.)/0.19733 - 1) + [4]/2*(pow([2]*x/sqrt(3.)/0.19733,2) - 4*[2]*x/sqrt(3.)/0.19733 + 2) + [5]/6.*(-pow(x/sqrt(3.)*[1]/0.19733,3) + 9*pow(x/sqrt(3.)*[1]/0.19733,2) - 18*x/sqrt(3.)*[1]/0.19733 + 6),3))",0,1);
484 c3Fit1D_Expan=new TF1("c3Fit1D_Expan","[0]*(1+[1]*exp(-pow([2]*x/0.19733, [3])))",0,1);
488 double OutputPar_c3[npar_c3]={0};
489 double OutputPar_c3_e[npar_c3]={0};
491 double par_c3[npar_c3]; // the start values
492 double stepSize_c3[npar_c3]; // step sizes
493 double minVal_c3[npar_c3]; // minimum bound on parameter
494 double maxVal_c3[npar_c3]; // maximum bound on parameter
495 string parName_c3[npar_c3];
496 // 1.0 1.0 10. 0. 0. 0. 1.5
497 par_c3[0] = 1.0; par_c3[1] = 1.0; par_c3[2] = 10.; par_c3[3] = 0.; par_c3[4] = 0.; par_c3[5] = 0; par_c3[6] = 1.5;
498 stepSize_c3[0] = 0.01; stepSize_c3[1] = 0.1; stepSize_c3[2] = 0.1; stepSize_c3[3] = 0.01; stepSize_c3[4] = 0.01; stepSize_c3[5] = 0.01; stepSize_c3[6] = 0.1;
499 minVal_c3[0] = 0.8; minVal_c3[1] = 0.2; minVal_c3[2] = 4.; minVal_c3[3] = -2; minVal_c3[4] = -1; minVal_c3[5] = -1; minVal_c3[6] = 0.5;
500 maxVal_c3[0] = 1.1; maxVal_c3[1] = 1000.; maxVal_c3[2] = 100.; maxVal_c3[3] = +2; maxVal_c3[4] = +1; maxVal_c3[5] = +1; maxVal_c3[6] = 2.5;
501 parName_c3[0] = "N"; parName_c3[1] = "#lambda_{3}"; parName_c3[2] = "R_{inv}"; parName_c3[3] = "coeff_{3}"; parName_c3[4] = "coeff_{4}"; parName_c3[5] = "coeff_{5}"; parName_c3[6] = "#alpha";
503 if(CollisionType==0){
505 par_c3[2]=15.; minVal_c3[2] = 8.;
508 if(FitType==0) {par_c3[2] = 2.0; minVal_c3[2] = 1.0;}
510 par_c3[1] = 4.0; minVal_c3[1] = 1.0;
512 par_c3[2] = 1.3; minVal_c3[2] = .9; maxVal_c3[2] = 10.;
516 if(FitType==0) {par_c3[6] = 2.;}
517 if(FitType==1) {par_c3[6] = 1.;}
518 if(FitType==2) {par_c3[3] = 0; par_c3[4] = 0; par_c3[5] = 0;}
520 if(FitType==2) {maxVal_c3[1] = 10.;}
522 for (int i=0; i<npar_c3; i++){
523 MyMinuit_c3.DefineParameter(i, parName_c3[i].c_str(), par_c3[i], stepSize_c3[i], minVal_c3[i], maxVal_c3[i]);
525 if(FitType==0 || FitType==1) { MyMinuit_c3.FixParameter(6);}
527 MyMinuit_c3.FixParameter(3);
528 MyMinuit_c3.FixParameter(4);
529 MyMinuit_c3.FixParameter(5);
531 MyMinuit_c3.FixParameter(0);
532 //MyMinuit_c3.FixParameter(1);
533 //MyMinuit_c3.FixParameter(2);
534 //MyMinuit_c3.FixParameter(3);
535 //MyMinuit_c3.FixParameter(4);
536 MyMinuit_c3.FixParameter(5);
538 /////////////////////////////////////////////////////////////
539 // Do the minimization!
540 cout<<"Start Three-d fit"<<endl;
541 MyMinuit_c3.Migrad();// Minuit's best minimization algorithm
542 cout<<"End Three-d fit"<<endl;
543 /////////////////////////////////////////////////////////////
544 MyMinuit_c3.mnexcm("SHOw PARameters", &arglist_c3, 1, ierflg_c3);
545 cout<<"c3 Fit: Chi2 = "<<Chi2_c3<<" NDF = "<<(NFitPoints_c3-MyMinuit_c3.GetNumFreePars())<<endl;
546 cout<<" Chi2/NDF = "<<Chi2_c3 / (NFitPoints_c3-MyMinuit_c3.GetNumFreePars())<<endl;
548 for(int i=0; i<npar_c3; i++){
549 MyMinuit_c3.GetParameter(i,OutputPar_c3[i],OutputPar_c3_e[i]);
552 cout<<"Tij Norm = "<<pow(OutputPar_c3[1], 1/3.)<<endl;
555 c3Fit1D_Expan->FixParameter(0,OutputPar_c3[0]);
556 c3Fit1D_Expan->FixParameter(1,OutputPar_c3[1]);
557 c3Fit1D_Expan->FixParameter(2,OutputPar_c3[2]);
558 c3Fit1D_Expan->FixParameter(3,OutputPar_c3[3]);
559 c3Fit1D_Expan->FixParameter(4,OutputPar_c3[4]);
560 c3Fit1D_Expan->FixParameter(5,OutputPar_c3[5]);
562 c3Fit1D_Expan->FixParameter(0,OutputPar_c3[0]);
563 c3Fit1D_Expan->FixParameter(1,OutputPar_c3[1]);
564 c3Fit1D_Expan->FixParameter(2,OutputPar_c3[2]);
565 c3Fit1D_Expan->FixParameter(3,OutputPar_c3[6]);
567 c3Fit1D_Expan->SetLineStyle(1);
568 //c3Fit1D_Expan->Draw("same");
571 // project 3D EW fit onto 1D histogram
572 for(int i=2; i<=BINLIMIT_3; i++){// bin number
573 double Q12 = BinCenters[i-1];// true center
574 for(int j=2; j<=BINLIMIT_3; j++){// bin number
575 double Q13 = BinCenters[j-1];// true center
576 for(int k=2; k<=BINLIMIT_3; k++){// bin number
577 double Q23 = BinCenters[k-1];// true center
579 double Q3 = sqrt(pow(Q12,2) + pow(Q13,2) + pow(Q23,2));
581 if(Q12 < sqrt(pow(Q13,2)+pow(Q23,2) - 2*Q13*Q23)) continue;// not all configurations are possible
582 if(Q12 > sqrt(pow(Q13,2)+pow(Q23,2) + 2*Q13*Q23)) continue;// not all configurations are possible
584 double TERM5=ThreeParticle[ch1][ch2][ch3][4]->GetBinContent(i,j,k);// N1*N1*N1. All from different events (pure combinatorics)
585 if(TERM5==0) continue;
588 if(MRC) TERM5 *= MRC_SC_3[2]->GetBinContent(MRC_SC_3[2]->GetXaxis()->FindBin(Q3));
590 double radius = OutputPar_c3[2]/FmToGeV;
591 double arg12 = Q12*radius;
592 double arg13 = Q13*radius;
593 double arg23 = Q23*radius;
594 double Expan12=1, Expan13=1, Expan23=1;
596 Expan12 += OutputPar_c3[3]/pow(2.,3/2.)/(6.)*(8*pow(arg12,3) - 12*pow(arg12,1));
597 Expan12 += OutputPar_c3[4]/pow(2.,4/2.)/(24.)*(16*pow(arg12,4) -48*pow(arg12,2) + 12);
598 Expan12 += OutputPar_c3[5]/pow(2.,5/2.)/(120.)*(32.*pow(arg12,5) - 160.*pow(arg12,3) + 120*arg12);
600 Expan13 += OutputPar_c3[3]/pow(2.,3/2.)/(6.)*(8*pow(arg13,3) - 12*pow(arg13,1));
601 Expan13 += OutputPar_c3[4]/pow(2.,4/2.)/(24.)*(16*pow(arg13,4) -48*pow(arg13,2) + 12);
602 Expan13 += OutputPar_c3[5]/pow(2.,5/2.)/(120.)*(32.*pow(arg13,5) - 160.*pow(arg13,3) + 120*arg13);
604 Expan23 += OutputPar_c3[3]/pow(2.,3/2.)/(6.)*(8*pow(arg23,3) - 12*pow(arg23,1));
605 Expan23 += OutputPar_c3[4]/pow(2.,4/2.)/(24.)*(16*pow(arg23,4) -48*pow(arg23,2) + 12);
606 Expan23 += OutputPar_c3[5]/pow(2.,5/2.)/(120.)*(32.*pow(arg23,5) - 160.*pow(arg23,3) + 120*arg23);
607 }else if(FitType==1){
608 Expan12 += OutputPar_c3[3]*(arg12 - 1);
609 Expan12 += OutputPar_c3[4]/2.*(pow(arg12,2) - 4*arg12 + 2);
610 Expan12 += OutputPar_c3[5]/6.*(-pow(arg12,3) + 9*pow(arg12,2) - 18*arg12 + 6);
612 Expan13 += OutputPar_c3[3]*(arg13 - 1);
613 Expan13 += OutputPar_c3[4]/2.*(pow(arg13,2) - 4*arg13 + 2);
614 Expan13 += OutputPar_c3[5]/6.*(-pow(arg13,3) + 9*pow(arg13,2) - 18*arg13 + 6);
616 Expan23 += OutputPar_c3[3]*(arg23 - 1);
617 Expan23 += OutputPar_c3[4]/2.*(pow(arg23,2) - 4*arg23 + 2);
618 Expan23 += OutputPar_c3[5]/6.*(-pow(arg23,3) + 9*pow(arg23,2) - 18*arg23 + 6);
622 double t12_coh = exp(-pow(Rcoh/FmToGeV * Q12,2)/2.);
623 double t23_coh = exp(-pow(Rcoh/FmToGeV * Q23,2)/2.);
624 double t13_coh = exp(-pow(Rcoh/FmToGeV * Q13,2)/2.);
625 double C = 2*OutputPar_c3[1] * pow(1-G,3)*exp(-(pow(arg12,OutputPar_c3[6])+pow(arg13,OutputPar_c3[6])+pow(arg23,OutputPar_c3[6]))/2.)*Expan12*Expan13*Expan23;
626 C += 2*pow(OutputPar_c3[1], 2/3.) * G*pow(1-G,2)*exp(-(pow(arg12,OutputPar_c3[6])+pow(arg13,OutputPar_c3[6]))/2.)*Expan12*Expan13*t23_coh;
627 C += 2*pow(OutputPar_c3[1], 2/3.) * G*pow(1-G,2)*exp(-(pow(arg12,OutputPar_c3[6])+pow(arg23,OutputPar_c3[6]))/2.)*Expan12*Expan23*t13_coh;
628 C += 2*pow(OutputPar_c3[1], 2/3.) * G*pow(1-G,2)*exp(-(pow(arg13,OutputPar_c3[6])+pow(arg23,OutputPar_c3[6]))/2.)*Expan13*Expan23*t12_coh;
631 C *= OutputPar_c3[0];
632 //if(Q3<0.018) continue;
633 GenSignalExpected_num->Fill(Q3, C);
634 GenSignalExpected_den->Fill(Q3, TERM5);
635 //if(Q3<0.02) cout<<Q3<<" "<<TERM5<<endl;
636 ///////////////////////////////////////////////////////////
645 GenSignalExpected_num->Sumw2();
646 GenSignalExpected_num->Divide(GenSignalExpected_den);
648 TSpline3 *c3Fit1D_ExpanSpline = new TSpline3(GenSignalExpected_num);
649 c3Fit1D_ExpanSpline->SetLineWidth(2);
650 double xpoints[1000], ypoints[1000];
651 bool splineOnly=kFALSE;
652 for(int iii=0; iii<1000; iii++){
653 xpoints[iii] = 0 + (iii+0.5)*0.001;
654 //ypoints[iii] = c3Fit1D_ExpanSpline->Eval(xpoints[iii]);// to skip spline
655 splineOnly=kTRUE;// to skip 1D approximation
656 if(CollisionType==0) splineOnly=kTRUE;
657 if(CollisionType!=0 && xpoints[iii] > 0.06) splineOnly=kTRUE;
659 ypoints[iii] = c3Fit1D_Expan->Eval(xpoints[iii]);
660 if(c3Fit1D_Expan->Eval(xpoints[iii])<2. && fabs(c3Fit1D_Expan->Eval(xpoints[iii])-c3Fit1D_ExpanSpline->Eval(xpoints[iii])) < 0.01) splineOnly=kTRUE;
662 else {ypoints[iii] = c3Fit1D_ExpanSpline->Eval(xpoints[iii]); splineOnly=kTRUE;}
664 TGraph *gr_c3Spline = new TGraph(1000,xpoints,ypoints);
665 gr_c3Spline->SetLineWidth(2);
666 if(CollisionType==0) gr_c3Spline->SetLineColor(1);
667 if(CollisionType==1) gr_c3Spline->SetLineColor(2);
668 if(CollisionType==2) gr_c3Spline->SetLineColor(4);
670 gr_c3Spline->Draw("c same");
673 double ChiSqSum_1D=0, SumNDF_1D=0;
674 for(int bin=1; bin<=300; bin++){
675 double binCenter = c3_hist->GetXaxis()->GetBinCenter(bin);
676 if(binCenter > Q3Limit) continue;
677 if(c3_hist->GetBinError(bin)==0) continue;
678 if(binCenter < 0.01) continue;
680 for(int gr=0; gr<999; gr++){
681 if(binCenter > xpoints[gr] && (binCenter < xpoints[gr+1])) {grIndex=gr; break;}
684 ChiSqSum_1D += pow((c3_hist->GetBinContent(bin)-ypoints[grIndex]) / c3_hist->GetBinError(bin),2);
685 //cout<<c3_hist->GetBinContent(bin)<<" "<<ypoints[grIndex]<<" "<<c3_hist->GetBinError(bin)<<endl;
686 cout<<pow((c3_hist->GetBinContent(bin)-ypoints[grIndex]) / c3_hist->GetBinError(bin),2)<<endl;
689 cout<<"1D Chi2/NDF = "<<ChiSqSum_1D / (SumNDF_1D-5.)<<endl;
696 TString *savefilename = new TString("FitFiles/FitFile_CT");
697 *savefilename += CollisionType;
698 savefilename->Append("_FT");
699 *savefilename += FitType;
700 savefilename->Append("_R");
701 *savefilename += Rcoh;
702 savefilename->Append("_G");
703 *savefilename += int((G+0.001)/0.02);
704 savefilename->Append(".root");
705 TFile *savefile = new TFile(savefilename->Data(),"RECREATE");
706 MyMinuit_c3.Write("MyMinuit_c3");
714 //________________________________________________________________________
715 void SetFSICorrelations(){
716 // read in 2-particle and 3-particle FSI correlations = K2 & K3
717 // 2-particle input histo from file is binned in qinv. 3-particle in qinv of each pair
718 TFile *fsifile = new TFile("KFile.root","READ");
719 if(!fsifile->IsOpen()) {
720 cout<<"No FSI file found!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
723 TH1D *temphistoSS[12];
724 TH1D *temphistoOS[12];
725 for(Int_t MB=0; MB<12; MB++) {
726 TString *nameK2SS = new TString("K2ss_");
728 temphistoSS[MB] = (TH1D*)fsifile->Get(nameK2SS->Data());
730 TString *nameK2OS = new TString("K2os_");
732 temphistoOS[MB] = (TH1D*)fsifile->Get(nameK2OS->Data());
734 fFSIss[MB] = (TH1D*)temphistoSS[MB]->Clone();
735 fFSIos[MB] = (TH1D*)temphistoOS[MB]->Clone();
736 fFSIss[MB]->SetDirectory(0);
737 fFSIos[MB]->SetDirectory(0);
745 double Gamov(int chargeProduct, double qinv){
747 double arg = chargeProduct*2.*PI/(BohrR*qinv/2.);
749 return arg/(exp(arg)-1);
752 void SetMomResCorrections(){
754 TString *momresfilename = new TString("MomResFile");
755 if(CollisionType_def!=0) momresfilename->Append("_ppAndpPb");
756 momresfilename->Append(".root");
758 TFile *MomResFile = new TFile(momresfilename->Data(),"READ");
760 TString *proName[28];
761 for(int ii=0; ii<28; ii++){
762 proName[ii] = new TString("MRC_pro_");
768 MRC_SC_3[0] = (TH1D*)(((TH2D*)MomResFile->Get("MRC_3_SC_term1"))->ProjectionY(proName[4]->Data(), RbinMRC, RbinMRC));
769 MRC_SC_3[1] = (TH1D*)(((TH2D*)MomResFile->Get("MRC_3_SC_term2"))->ProjectionY(proName[5]->Data(), RbinMRC, RbinMRC));
770 MRC_SC_3[2] = (TH1D*)(((TH2D*)MomResFile->Get("MRC_3_SC_term3"))->ProjectionY(proName[6]->Data(), RbinMRC, RbinMRC));
771 MRC_SC_3[0]->SetDirectory(0); MRC_SC_3[1]->SetDirectory(0); MRC_SC_3[2]->SetDirectory(0);
775 for(int bin=1; bin<=MRC_SC_3[0]->GetNbinsX(); bin++){
776 MRC_SC_3[0]->SetBinContent(bin, 1.0); MRC_SC_3[1]->SetBinContent(bin, 1.0); MRC_SC_3[2]->SetBinContent(bin, 1.0);
786 return (n < 1.00001) ? 1 : fact(n - 1) * n;
788 //________________________________________________________________________________________
789 void SetMuonCorrections(){
790 TString *name = new TString("MuonCorrection");
791 if(CollisionType_def!=0) name->Append("_ppAndpPb");
793 name->Append(".root");
794 TFile *MuonFile=new TFile(name->Data(),"READ");
795 TString *proName[22];
796 for(int ii=0; ii<22; ii++){
797 proName[ii] = new TString("MuonCorr_pro_");
802 C3muonCorrectionSC[0] = (TH1D*)(((TH2D*)MuonFile->Get("C3muonCorrection_SC_term1"))->ProjectionY(proName[3]->Data(), RbinMRC, RbinMRC));
803 C3muonCorrectionSC[1] = (TH1D*)(((TH2D*)MuonFile->Get("C3muonCorrection_SC_term2"))->ProjectionY(proName[4]->Data(), RbinMRC, RbinMRC));
805 C3muonCorrectionSC[0]->SetDirectory(0); C3muonCorrectionSC[1]->SetDirectory(0);
809 for(int bin=1; bin<=C3muonCorrectionSC[0]->GetNbinsX(); bin++){
810 C3muonCorrectionSC[0]->SetBinContent(bin, 1.0); C3muonCorrectionSC[1]->SetBinContent(bin, 1.0);
816 //________________________________________________________________________
817 void SetFSIindex(Float_t R){
818 if(CollisionType_def==0){
819 if(Mbin==0) fFSIindex = 0;//0-5%
820 else if(Mbin==1) fFSIindex = 1;//5-10%
821 else if(Mbin<=3) fFSIindex = 2;//10-20%
822 else if(Mbin<=5) fFSIindex = 3;//20-30%
823 else if(Mbin<=7) fFSIindex = 4;//30-40%
824 else if(Mbin<=9) fFSIindex = 5;//40-50%
825 else if(Mbin<=12) fFSIindex = 6;//40-50%
826 else if(Mbin<=15) fFSIindex = 7;//40-50%
827 else if(Mbin<=18) fFSIindex = 8;//40-50%
828 else fFSIindex = 8;//90-100%
829 }else fFSIindex = 9;// pp and pPb
832 //________________________________________________________________________
833 Float_t FSICorrelation(Int_t charge1, Int_t charge2, Float_t qinv){
834 // returns 2-particle Coulomb correlations = K2
835 Int_t qbinL = fFSIss[fFSIindex]->GetXaxis()->FindBin(qinv-fFSIss[fFSIindex]->GetXaxis()->GetBinWidth(1)/2.);
836 Int_t qbinH = qbinL+1;
837 if(qbinL <= 0) return 1.0;
838 if(qbinH > fFSIss[fFSIindex]->GetNbinsX()) {// Scaled Gamov approximation
839 int chargeproduct = 1;
840 if(charge1!=charge2) {
842 Float_t ScaleFac = (fFSIos[fFSIindex]->GetBinContent(fFSIos[fFSIindex]->GetNbinsX()-1) - 1);
843 ScaleFac /= (Gamov(chargeproduct, fFSIos[fFSIindex]->GetXaxis()->GetBinCenter(fFSIos[fFSIindex]->GetNbinsX()-1)) - 1);
844 return ( (Gamov(chargeproduct, qinv)-1)*ScaleFac + 1);
846 Float_t ScaleFac = (fFSIss[fFSIindex]->GetBinContent(fFSIss[fFSIindex]->GetNbinsX()-1) - 1);
847 ScaleFac /= (Gamov(chargeproduct, fFSIss[fFSIindex]->GetXaxis()->GetBinCenter(fFSIss[fFSIindex]->GetNbinsX()-1)) - 1);
848 return ( (Gamov(chargeproduct, qinv)-1)*ScaleFac + 1);
853 if(charge1==charge2){
854 slope = fFSIss[fFSIindex]->GetBinContent(qbinL) - fFSIss[fFSIindex]->GetBinContent(qbinH);
855 slope /= fFSIss[fFSIindex]->GetXaxis()->GetBinCenter(qbinL) - fFSIss[fFSIindex]->GetXaxis()->GetBinCenter(qbinH);
856 return (slope*(qinv - fFSIss[fFSIindex]->GetXaxis()->GetBinCenter(qbinL)) + fFSIss[fFSIindex]->GetBinContent(qbinL));
858 slope = fFSIos[fFSIindex]->GetBinContent(qbinL) - fFSIos[fFSIindex]->GetBinContent(qbinH);
859 slope /= fFSIos[fFSIindex]->GetXaxis()->GetBinCenter(qbinL) - fFSIos[fFSIindex]->GetXaxis()->GetBinCenter(qbinH);
860 return (slope*(qinv - fFSIos[fFSIindex]->GetXaxis()->GetBinCenter(qbinL)) + fFSIos[fFSIindex]->GetBinContent(qbinL));
863 //__________________________________________________________________________
864 void fcn_c3(int& npar, double* deriv, double& f, double par[], int flag){
866 double q12=0, q13=0, q23=0;
867 double Expan12=0, Expan13=0, Expan23=0;
869 double Rch=par[2]/FmToGeV;
871 //double lnL=0, term1=0, term2=0;
873 //double SumChi2_test=0;
875 for(int i=0; i<=BINLIMIT_3; i++){// q12
876 for(int j=0; j<=BINLIMIT_3; j++){// q13
877 for(int k=0; k<=BINLIMIT_3; k++){// q23
879 if(B_3[i][j][k] == 0) continue;
880 if(A_3[i][j][k] == 0) continue;
881 if(A_3_e[i][j][k] == 0) continue;
886 double q3 = sqrt(pow(q12,2)+pow(q13,2)+pow(q23,2));
887 if(q3 > Q3LimitHigh) continue;
888 if(q3 < Q3LimitLow) continue;
890 double arg12 = q12*Rch;
891 double arg13 = q13*Rch;
892 double arg23 = q23*Rch;
893 if(FitType==0){// Edgeworth expansion
895 Expan12 += par[3]/pow(2.,3/2.)/(6.)*(8*pow(arg12,3) - 12*pow(arg12,1));
896 Expan12 += par[4]/pow(2.,4/2.)/(24.)*(16*pow(arg12,4) -48*pow(arg12,2) + 12);
897 Expan12 += par[5]/pow(2.,5/2.)/(120.)*(32.*pow(arg12,5) - 160.*pow(arg12,3) + 120*arg12);
900 Expan13 += par[3]/pow(2.,3/2.)/(6.)*(8*pow(arg13,3) - 12*pow(arg13,1));
901 Expan13 += par[4]/pow(2.,4/2.)/(24.)*(16*pow(arg13,4) -48*pow(arg13,2) + 12);
902 Expan13 += par[5]/pow(2.,5/2.)/(120.)*(32.*pow(arg13,5) - 160.*pow(arg13,3) + 120*arg13);
905 Expan23 += par[3]/pow(2.,3/2.)/(6.)*(8*pow(arg23,3) - 12*pow(arg23,1));
906 Expan23 += par[4]/pow(2.,4/2.)/(24.)*(16*pow(arg23,4) -48*pow(arg23,2) + 12);
907 Expan23 += par[5]/pow(2.,5/2.)/(120.)*(32.*pow(arg23,5) - 160.*pow(arg23,3) + 120*arg23);
908 }else if(FitType==1){// Laguerre expansion
910 Expan12 += par[3]*(arg12 - 1);
911 Expan12 += par[4]/2.*(pow(arg12,2) - 4*arg12 + 2);
912 Expan12 += par[5]/6.*(-pow(arg12,3) + 9*pow(arg12,2) - 18*arg12 + 6);
915 Expan13 += par[3]*(arg13 - 1);
916 Expan13 += par[4]/2.*(pow(arg13,2) - 4*arg13 + 2);
917 Expan13 += par[5]/6.*(-pow(arg13,3) + 9*pow(arg13,2) - 18*arg13 + 6);
920 Expan23 += par[3]*(arg23 - 1);
921 Expan23 += par[4]/2.*(pow(arg23,2) - 4*arg23 + 2);
922 Expan23 += par[5]/6.*(-pow(arg23,3) + 9*pow(arg23,2) - 18*arg23 + 6);
923 }else{Expan12=1.0; Expan13=1.0; Expan23=1.0;}
925 double t12_coh = exp(-pow(Rcoh_def/FmToGeV * q12,2)/2.);
926 double t23_coh = exp(-pow(Rcoh_def/FmToGeV * q23,2)/2.);
927 double t13_coh = exp(-pow(Rcoh_def/FmToGeV * q13,2)/2.);
928 C = 2*par[1] * pow(1-G_def,3)*exp(-(pow(arg12,par[6])+pow(arg13,par[6])+pow(arg23,par[6]))/2.)*Expan12*Expan13*Expan23;
929 C += 2*pow(par[1],2/3.) * G_def*pow(1-G_def,2)*exp(-(pow(arg12,par[6])+pow(arg13,par[6]))/2.)*Expan12*Expan13*t23_coh;
930 C += 2*pow(par[1],2/3.) * G_def*pow(1-G_def,2)*exp(-(pow(arg12,par[6])+pow(arg23,par[6]))/2.)*Expan12*Expan23*t13_coh;
931 C += 2*pow(par[1],2/3.) * G_def*pow(1-G_def,2)*exp(-(pow(arg13,par[6])+pow(arg23,par[6]))/2.)*Expan13*Expan23*t12_coh;
936 double error = pow(A_3_e[i][j][k]/B_3[i][j][k],2);
937 error += pow(sqrt(B_3[i][j][k])*A_3[i][j][k]/pow(B_3[i][j][k],2),2);
939 SumChi2 += pow( (C - A_3[i][j][k]/B_3[i][j][k])/error,2);
941 //if(q3<0.05) SumChi2_test += pow( (C - A_3[i][j][k]/B_3[i][j][k])/error,2);
943 /*if(A_3[i][j][k] >= 1) term1 = C*(A_3[i][j][k]+B_3[i][j][k])/(A_3[i][j][k]*(C+1));
945 term2 = (A_3[i][j][k]+B_3[i][j][k])/(B_3[i][j][k]*(C+1));
947 if(term1 > 0.0 && term2 > 0.0){
948 lnL += A_3[i][j][k]*log(term1) + B_3[i][j][k]*log(term2);
949 }else if(term1==0 && term2 > 0.0){
950 lnL += B_3[i][j][k]*log(term2);
951 }else {cout<<"WARNING -- term1 and term2 are negative"<<endl;}
959 //f = -2.0*lnL;// log-liklihood minimization
960 f = SumChi2;// Chi2 minimization
962 //Chi2_c3 = SumChi2_test;