3 Double_t energyIntervalsBarrelLow[]= {0,0.03, 0.05, 0.07, 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0};
4 Double_t thetaIntervalsBarrelLow[]= {22.,23.,24.,25.,30.,35.,40.,45.,50.,55.,60.,65.,70.,75.,80.,85.,90.,95.,100.,105.,110.,115.,120.,125.,130.,135.,137., 139., 140., 141.};
7 Double_t energyIntervalsBarrelHigh[]= {1.0,1.1,1.2,1.5,2.0,2.5,3.0,3.5,4.0,5.0,6.0,7.0,8.0,9.0,10.0};
8 Double_t thetaIntervalsBarrelHigh[]= {22.,23.,24.,25.,30.,35.,40.,45.,50.,55.,60.,65.,70.,75.,80.,85.,90.,95.,100.,105.,110.,115.,120.,125.,130.,135.,137., 139., 140., 141.};
11 Double_t energyIntervalsFwd[]= {0,0.03, 0.05, 0.07, 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.5,2.0,2.5,3.0,3.5,4.0,5.0,6.0,7.0,8.0,9.0,10.0};
12 Double_t thetaIntervalsFwd[]= {5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,20.,21.,22.};
15 Double_t energyIntervalsBwd[]= {0,0.03,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.5,2.0};
16 Double_t thetaIntervalsBwd[]= {147.,148.,149.,150.,151.,152.,153.,154.,155.,156.,157.,158.,159.,160.,161.,162.,163.,164.,166.,168.,170.,172.};
19 Double_t energyIntervalsShashlyk[]= {0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.5,2.0,2.5,3.0,3.5,4.0,5.0,6.0,7.0,8.0,9.0,10.0};
37 f_histos=
new TFile(
"correction_histos_fit.root");
38 if (f_histos->IsZombie())
45 TH2F *hisEnergyRatioBarrelLow, *hisEnergyRatioBarrelHigh;
46 TH2F *hisEnergyRatioFwd, *hisEnergyRatioBwd;
47 TH1F *hisEnergyRatioShashlyk;
49 TString OutputFile=
"emc_correction_par_";
50 OutputFile = OutputFile +
particle+
"_";
52 OutputFile +=
".root";
55 if (!useStoredHistos||storeHistos)
57 TChain *
c=
new TChain(
"pndsim");
58 if (InputFile1.Contains(
".root"))
60 TFile *
f1=
new TFile(InputFile1);
63 std::cout<<
"Input file "<<InputFile1<<
" does not exists"<<std::endl;
68 else if (InputFile1.Contains(
".txt"))
71 ifstream
infile(InputFile1.Data(), ios::in);
73 while (getline(
infile,file_name,
'\n'))
75 if (std::string::npos != file_name.find(
".root"))
77 TFile *
f2=
new TFile(file_name.c_str());
80 std::cout<<
"Input file "<<file_name<<
" does not exists"<<std::endl;
83 c->Add(file_name.c_str());
89 std::cout<<
"Wrong input file: "<<InputFile1<<std::endl;
105 hisEnergyRatioBarrelLow->GetXaxis()->SetTitle(
"Cluster Reconstructed Photon Energy (GeV)");
106 hisEnergyRatioBarrelLow->GetYaxis()->SetTitle(
"Cluster Reconstructed #theta Photon Angle (#circ)");
109 hisEnergyRatioBarrelHigh->GetXaxis()->SetTitle(
"Cluster Reconstructed Photon Energy (GeV)");
110 hisEnergyRatioBarrelHigh->GetYaxis()->SetTitle(
"Cluster Reconstructed #theta Photon Angle (#circ)");
113 hisEnergyRatioFwd->GetXaxis()->SetTitle(
"Cluster Reconstructed Photon Energy (GeV)");
114 hisEnergyRatioFwd->GetYaxis()->SetTitle(
"Cluster Reconstructed #theta Photon Angle (#circ)");
117 hisEnergyRatioBwd->GetXaxis()->SetTitle(
"Cluster Reconstructed Photon Energy (GeV)");
118 hisEnergyRatioBwd->GetYaxis()->SetTitle(
"Cluster Reconstructed #theta Photon Angle (#circ)");
121 hisEnergyRatioShashlyk->GetXaxis()->SetTitle(
"Cluster Reconstructed Photon Energy (GeV)");
124 TH1F hisEnergyRatio1[50][50];
125 TH1F hisEnergyRatio2[50][50];
126 TH1F hisEnergyRatio3[50][50];
127 TH1F hisEnergyRatio4[50][50];
128 TH1F hisEnergyRatio5[50];
134 hisEnergyRatio1[
i][j].SetBins(100,0.,2.);
135 hisEnergyRatioBarrelLow->SetBinContent(
i+1,j+1,1.);
143 hisEnergyRatio2[
i][j].SetBins(100,0.,2.);
144 hisEnergyRatioBarrelHigh->SetBinContent(
i+1,j+1,1.);
152 hisEnergyRatio3[
i][j].SetBins(100,0.,2.);
153 hisEnergyRatioFwd->SetBinContent(
i+1,j+1,1.);
161 hisEnergyRatio4[
i][j].SetBins(100,0.,2.);
162 hisEnergyRatioBwd->SetBinContent(
i+1,j+1,1.);
168 hisEnergyRatio5[
i].SetBins(100,0.,2.);
169 hisEnergyRatioShashlyk->SetBinContent(
i+1,j+1,1.);
172 TClonesArray*
track_array=
new TClonesArray(
"PndMCTrack");
173 c->SetBranchAddress(
"MCTrack",&track_array);
174 TClonesArray*
cluster_array=
new TClonesArray(
"PndEmcCluster");
175 c->SetBranchAddress(
"EmcCluster",&cluster_array);
184 printf(
"Intitialization done RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
186 cout<<
"c->GetEntries()="<<c->GetEntries()<<endl;
187 for (Int_t j=0; j< c->GetEntries(); j++)
192 cout<<
"Event "<<j<<endl;
197 if (cluster_array->GetEntriesFast()>0)
203 thMC = mc_momentum.Theta()*(180./
TMath::Pi());
204 phiMC = mc_momentum.Phi()*(180./
TMath::Pi());
208 Int_t idWithHighestEnergy = 0;
211 for (Int_t
i=0;
i<cluster_array->GetEntriesFast();
i++)
215 cluster_energy=cluster->
energy();
217 if (cluster_energy>highestEnergy)
219 idWithHighestEnergy =
i;
226 TVector3 cluster_pos=cluster->
where();
227 cluster_theta=cluster_pos.Theta()*180./
TMath::Pi();
228 cluster_phi=cluster_pos.Phi()*180./
TMath::Pi();
229 cluster_energy=highestEnergy;
233 if (((module==1)||(module==2))&&(cluster_energy<=1.0))
237 else if (((module==1)||(module==2))&&(cluster_energy>1.0))
246 Int_t thetaBin=
GetThetaBin(cluster_theta, range_set);
247 Int_t energyBin=
GetEnergyBin(cluster_energy, range_set);
249 if (cluster_theta >= 141. && cluster_theta < 147.)
continue;
252 if ((thetaBin<0&&range_set!=5) || energyBin<0)
254 cout<<
"!!!!!!!!!!!!!!!!!!!!!!"<<endl;
255 cout<<
"Module="<<module<<
" range_set="<<range_set<<endl;
256 cout <<
"theta_reco =" << cluster_theta <<
"/ energy_reco =" << cluster_energy << endl;
257 cout <<
"thetaBin= "<<thetaBin<<
" & energyBin= "<<energyBin<<endl;
261 if (cluster_theta > (thMC-5) && cluster_theta <=(thMC+5) ){
266 if (
fabs(phi_diff)<2.5 ||
fabs(phi_diff+360)<2.5 ||
fabs(phi_diff-360)<2.5)
272 if ((
fabs(phiMC) <5.)||
fabs(phiMC-180.)<5.||
fabs(phiMC-360.)<5.)
break;
273 if (en_div > 0.7 && en_div <1.3){
274 hisEnergyRatio1[energyBin][thetaBin].Fill(en_div);
280 if ((
fabs(phiMC) <5.)||
fabs(phiMC-180.)<5.||
fabs(phiMC-360.)<5.)
break;
281 if (en_div > 0.7 && en_div <1.3){
282 hisEnergyRatio2[energyBin][thetaBin].Fill(en_div);
288 if (cluster_theta <11.)
break;
289 if (en_div > 0.7 && en_div <1.3){
290 hisEnergyRatio3[energyBin][thetaBin].Fill(en_div);
296 if (en_div > 0.7 && en_div <1.3){
297 hisEnergyRatio4[energyBin][thetaBin].Fill(en_div);
303 if ((en_div > 0.7 && en_div <1.3)&&(thMC>1.)){
304 hisEnergyRatio5[energyBin].Fill(en_div);
319 std::cout<<
"Array of histogram is filled"<<std::endl;
324 printf(
"RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
335 mean_en_ratio = hisEnergyRatio1[
i][j].GetMean();
337 hisEnergyRatioBarrelLow->SetBinContent(
i+1,j+1,mean_en_ratio);
348 mean_en_ratio = hisEnergyRatio2[
i][j].GetMean();
350 hisEnergyRatioBarrelHigh->SetBinContent(
i+1,j+1,mean_en_ratio);
361 mean_en_ratio = hisEnergyRatio3[
i][j].GetMean();
363 hisEnergyRatioFwd->SetBinContent(
i+1,j+1,mean_en_ratio);
374 mean_en_ratio = hisEnergyRatio4[
i][j].GetMean();
376 hisEnergyRatioBwd->SetBinContent(
i+1,j+1,mean_en_ratio);
385 mean_en_ratio = hisEnergyRatio5[
i].GetMean();
387 hisEnergyRatioShashlyk->SetBinContent(
i+1,mean_en_ratio);
392 f_histos=
new TFile(
"correction_histos_fit.root",
"RECREATE");
393 hisEnergyRatioBarrelLow->Write();
394 hisEnergyRatioBarrelHigh->Write();
395 hisEnergyRatioFwd->Write();
396 hisEnergyRatioBwd->Write();
397 hisEnergyRatioShashlyk->Write();
400 std::cout<<
"Histograms are filled with mean values"<<std::endl;
403 if (useStoredHistos&&(!storeHistos))
405 f_histos=
new TFile(
"correction_histos_fit.root");
406 hisEnergyRatioBarrelLow=(TH2F*)f_histos->Get(
"hisEnergyRatioBarrelLow");
407 hisEnergyRatioBarrelHigh=(TH2F*)f_histos->Get(
"hisEnergyRatioBarrelHigh");
408 hisEnergyRatioFwd=(TH2F*)f_histos->Get(
"hisEnergyRatioFwd");
409 hisEnergyRatioBwd=(TH2F*)f_histos->Get(
"hisEnergyRatioBwd");
410 hisEnergyRatioShashlyk=(TH1F*)f_histos->Get(
"hisEnergyRatioShashlyk");
413 TF2 * func1 =
new TF2(
"func1",
FitFunction1,0.03,1.0,25.,135., 10);
414 double iniParams1[10] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 };
415 func1->SetParameters(iniParams1);
416 TCanvas *
c1=
new TCanvas(
"c1");
417 hisEnergyRatioBarrelLow->Fit(func1,
"RN");
418 func1->Draw(
"SURF1");
420 TF2 * func2 =
new TF2(
"func2",
FitFunction1,1.0,8.0,25.,135., 10);
421 double iniParams2[10] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 };
422 func2->SetParameters(iniParams2);
423 TCanvas *
c2=
new TCanvas(
"c2");
424 hisEnergyRatioBarrelHigh->Fit(func2,
"RN");
425 func2->Draw(
"SURF1");
427 TF2 * func3 =
new TF2(
"func3",
FitFunction1,0.03,8.0,11.,22., 10);
428 double iniParams3[10] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 };
429 func3->SetParameters(iniParams3);
430 TCanvas *
c3=
new TCanvas(
"c3");
431 hisEnergyRatioFwd->Fit(func3,
"RN");
432 func3->Draw(
"SURF1");
434 TF2 * func4 =
new TF2(
"func4",
FitFunction1,0.03,2.0,150.,163., 10);
435 double iniParams4[10] = { 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01 };
436 func4->SetParameters(iniParams4);
437 TCanvas *
c4=
new TCanvas(
"c4");
438 hisEnergyRatioBwd->Fit(func4,
"RN");
439 func4->Draw(
"SURF1");
441 TF1 * func5 =
new TF1(
"func5",
FitFunction2,0.0,10.0, 5);
442 double iniParams5[10] = { 0.01, 0.01, 0.01, 0.01, 0.01};
443 func5->SetParameters(iniParams5);
444 TCanvas *
c5=
new TCanvas(
"c5");
445 hisEnergyRatioShashlyk->Fit(func5,
"R");
450 c1->SaveAs(
"c1.root");
451 c2->SaveAs(
"c2.root");
452 c3->SaveAs(
"c3.root");
453 c4->SaveAs(
"c4.root");
454 c5->SaveAs(
"c5.root");
456 TFile fout(OutputFile,
"recreate");
459 enum {barrel_low=1, barrel_high=2, fwcap=3, bwcap=4, fsc=5};
460 Double_t pars1[10], pars2[10], pars3[10], pars4[10], pars5[5];
463 for (
int i=0;
i<10;
i++)
466 for (
int i=0;
i<10;
i++)
468 Double_t *p3=func3->GetParameters();
469 for (
int i=0;
i<10;
i++)
471 Double_t *p4=func4->GetParameters();
472 for (
int i=0;
i<10;
i++)
474 Double_t *p5=func5->GetParameters();
475 for (
int i=0;
i<5;
i++)
490 printf(
"RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
500 double theta=x[1]*TMath::DegToRad();
502 double factor1= par[0]
507 +par[5]*
cos(theta)*
cos(theta)
511 +par[9]*
log(e)*
cos(theta);
522 double res=(par[0]-par[1]/
sqrt(e)+par[2]/e+par[3]/(e*e)-par[4]/(e*
sqrt(e)));
551 std::cout<<
"Wrong EMC module: "<<range_set<<std::endl;
555 for (Int_t
i=0;
i<(nrThetaInt-1);
i++)
557 if (val>=thetaIntervals[
i] && val<thetaIntervals[
i+1])
592 std::cout<<
"Wrong EMC module: "<<range_set<<std::endl;
596 for (Int_t
i=0;
i<(nrEnergyInt-1);
i++)
598 if (val>=energyIntervals[
i] && val<energyIntervals[
i+1])
Double_t energyIntervalsFwd[]
Double_t thetaIntervalsBwd[]
Double_t FitFunction1(Double_t *x, Double_t *par)
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
friend F32vec4 cos(const F32vec4 &a)
friend F32vec4 exp(const F32vec4 &a)
Short_t GetModule() const
friend F32vec4 sqrt(const F32vec4 &a)
Double_t val[nBoxes][nFEBox]
int emc_correction_parametrization(Int_t version, TString InputFile1, TString particle="gamma", Bool_t debug=false, Bool_t useStoredHistos=true)
Double_t energyIntervalsBarrelLow[]
friend F32vec4 log(const F32vec4 &a)
TVector3 GetMomentum() const
Double_t FitFunction2(Double_t *x, Double_t *par)
TLorentzVector Get4Momentum() const
Double_t thetaIntervalsBarrelLow[]
TClonesArray * cluster_array
Double_t energyIntervalsBarrelHigh[]
Double_t energyIntervalsBwd[]
Double_t energyIntervalsShashlyk[]
Int_t nrThetaIntervals[4]
friend F32vec4 fabs(const F32vec4 &a)
a cluster (group of neighboring crystals) of hit emc crystals
Double_t energyIntervals[]
void SetCalibrationPar(Int_t iParSet, Double_t *pars)
Int_t GetEnergyBin(Double_t val, Int_t module)
cout<<"will loop over "<< t-> GetEntries()
virtual Double_t energy() const
Double_t thetaIntervalsBarrelHigh[]
TClonesArray * track_array
TFile infile("dedx_out.root","READ")
Double_t thetaIntervalsFwd[]
Int_t GetThetaBin(Double_t val, Int_t module)