12 const TString partic =
"mu-";
13 const float Bfield = 3.0;
14 bool use_widths =
true;
15 bool update_tab =
true;
18 float eta_bin[] = {0.,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0};
const int size_eta_bin =
sizeof(eta_bin)/
sizeof(*eta_bin);
19 float mom_bin[] = {0.,1.,2.,3.,4.,5.,10.,15.,20.,25.,30.};
const int size_mom_bin =
sizeof(mom_bin)/
sizeof(*mom_bin);
21 string Bfield_str = Form(
"%.1f",Bfield);
22 Bfield_str.replace(Bfield_str.find(
"."),
sizeof(
".") - 1,
"_");
23 TString tab_name = Form(
"sigma_eta_%i_p_%i_",size_eta_bin-1,size_mom_bin-1) + partic + Form(
"_B%.1fT.txt",Bfield);
26 TH1::SetDefaultSumw2();
27 TH2::SetDefaultSumw2();
31 TFile *
F =
new TFile(
"../data/files_"+Bfield_str+
"_T/total_"+partic+
"_B_"+Form(
"%.1f",Bfield)+
"T_FastTrackingEval.root");
32 TTree *
T = (TTree*) F -> Get(
"tracks");
33 float gpx, gpy, gpz, px, py, pz;
40 int nEntries = T -> GetEntries();
43 float approx_sig_dpp[size_eta_bin-1][size_mom_bin-1] = {{0}};
44 float approx_sig_dth[size_eta_bin-1][size_mom_bin-1] = {{0}};
45 float approx_sig_dph[size_eta_bin-1][size_mom_bin-1] = {{0}};
48 tab.open(
"tables/"+tab_name);
49 if(!tab){cout <<
"Could not find file '" << tab_name <<
"'" << endl; use_widths =
false; update_tab =
true;}
51 cout <<
"Loading parameters from file '" << tab_name <<
"'" << endl;
52 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){tab >> approx_sig_dpp[et][
p];}}
53 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){tab >> approx_sig_dth[et][
p];}}
54 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){tab >> approx_sig_dph[et][
p];}}
59 float approx_sig_dpp_3_0[size_eta_bin-1][size_mom_bin-1] = {0};
float approx_sig_dpp_1_2[size_eta_bin-1][size_mom_bin-1] = {0};
60 float approx_sig_dth_3_0[size_eta_bin-1][size_mom_bin-1] = {0};
float approx_sig_dth_1_2[size_eta_bin-1][size_mom_bin-1] = {0};
61 float approx_sig_dph_3_0[size_eta_bin-1][size_mom_bin-1] = {0};
float approx_sig_dph_1_2[size_eta_bin-1][size_mom_bin-1] = {0};
63 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
64 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
65 approx_sig_dpp_3_0[et][
p] = 3.0*approx_sig_dpp[et][
p]; approx_sig_dpp_1_2[et][
p] = 1.2*approx_sig_dpp[et][
p];
66 approx_sig_dth_3_0[et][
p] = 3.0*approx_sig_dth[et][
p]; approx_sig_dth_1_2[et][
p] = 1.2*approx_sig_dth[et][
p];
67 approx_sig_dph_3_0[et][
p] = 3.0*approx_sig_dph[et][
p]; approx_sig_dph_1_2[et][
p] = 1.2*approx_sig_dph[et][
p];
72 TH1F *** h1_dpp_p_et_bins =
new TH1F**[size_eta_bin-1];
73 TH1F *** h1_dth_p_et_bins =
new TH1F**[size_eta_bin-1];
74 TH1F *** h1_dph_p_et_bins =
new TH1F**[size_eta_bin-1];
75 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
76 h1_dpp_p_et_bins[et] =
new TH1F*[size_mom_bin-1];
77 h1_dth_p_et_bins[et] =
new TH1F*[size_mom_bin-1];
78 h1_dph_p_et_bins[et] =
new TH1F*[size_mom_bin-1];
79 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
81 h1_dpp_p_et_bins[et][
p] =
new TH1F(Form(
"h1_dpp_p_et_bins_%i_%i",et,
p),
";dp/p;Counts" ,100,-approx_sig_dpp_3_0[et][
p],approx_sig_dpp_3_0[et][p]);
82 h1_dth_p_et_bins[et][
p] =
new TH1F(Form(
"h1_dth_p_et_bins_%i_%i",et,p),
";d#theta [rad];Counts",100,-approx_sig_dth_3_0[et][p],approx_sig_dth_3_0[et][p]);
83 h1_dph_p_et_bins[et][
p] =
new TH1F(Form(
"h1_dph_p_et_bins_%i_%i",et,p),
";d#phi [rad];Counts" ,100,-approx_sig_dph_3_0[et][p],approx_sig_dph_3_0[et][p]);
86 h1_dpp_p_et_bins[et][
p] =
new TH1F(Form(
"h1_dpp_p_et_bins_%i_%i",et,
p),
";dp/p;Counts" ,100,-0.08 ,0.08 );
87 h1_dth_p_et_bins[et][
p] =
new TH1F(Form(
"h1_dth_p_et_bins_%i_%i",et,
p),
";d#theta [rad];Counts",100,-0.0014,0.0014);
88 h1_dph_p_et_bins[et][
p] =
new TH1F(Form(
"h1_dph_p_et_bins_%i_%i",et,
p),
";d#phi [rad];Counts" ,100,-0.04 ,0.04 );
91 h1_dpp_p_et_bins[et][
p] -> SetTitle(Form(
"%.1f < |#eta| < %.1f, %.1f < p < %.1f GeV/c",eta_bin[et],eta_bin[et],mom_bin[
p],mom_bin[p]));
92 h1_dth_p_et_bins[et][
p] -> SetTitle(Form(
"%.1f < |#eta| < %.1f, %.1f < p < %.1f GeV/c",eta_bin[et],eta_bin[et],mom_bin[p],mom_bin[p]));
93 h1_dph_p_et_bins[et][
p] -> SetTitle(Form(
"%.1f < |#eta| < %.1f, %.1f < p < %.1f GeV/c",eta_bin[et],eta_bin[et],mom_bin[p],mom_bin[p]));
97 int color[] = {1,2,62,8,95,52,6,28,209,92,15};
98 int marker[] = {20,21,23,24,25,26,27,28,29,30};
100 TH1F ** h1_dpp_v_p_et_bins =
new TH1F*[size_eta_bin-1];
101 TH1F ** h1_dth_v_p_et_bins =
new TH1F*[size_eta_bin-1];
102 TH1F ** h1_dph_v_p_et_bins =
new TH1F*[size_eta_bin-1];
104 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
105 h1_dpp_v_p_et_bins[et] =
new TH1F(Form(
"h1_dpp_v_p_et_bins_%i",et),
";p [GeV/c];dp/p [%]" ,size_mom_bin-1,mom_bin);
prettyTH1F( h1_dpp_v_p_et_bins[et] , color[et] , marker[et] , 0. , 10. );
106 h1_dth_v_p_et_bins[et] =
new TH1F(Form(
"h1_dth_v_p_et_bins_%i",et),
";p [GeV/c];d#theta [mrad]",size_mom_bin-1,mom_bin);
prettyTH1F( h1_dth_v_p_et_bins[et] , color[et] , marker[et] , 0. , 1. );
107 h1_dph_v_p_et_bins[et] =
new TH1F(Form(
"h1_dph_v_p_et_bins_%i",et),
";p [GeV/c];d#phi [mrad]" ,size_mom_bin-1,mom_bin);
prettyTH1F( h1_dph_v_p_et_bins[et] , color[et] , marker[et] , 0. , 25. );
110 TH1F ** h1_dpp_v_et_p_bins =
new TH1F*[size_mom_bin-1];
111 TH1F ** h1_dth_v_et_p_bins =
new TH1F*[size_mom_bin-1];
112 TH1F ** h1_dph_v_et_p_bins =
new TH1F*[size_mom_bin-1];
114 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
115 h1_dpp_v_et_p_bins[
p] =
new TH1F(Form(
"h1_dpp_v_et_p_bins_%i",
p),
";#eta;dp/p [%]" ,size_eta_bin-1,eta_bin);
prettyTH1F( h1_dpp_v_et_p_bins[
p] , color[p] , marker[p] , 0. , 10. );
116 h1_dth_v_et_p_bins[
p] =
new TH1F(Form(
"h1_dth_v_et_p_bins_%i",p),
";#eta;d#theta [mrad]",size_eta_bin-1,eta_bin);
prettyTH1F( h1_dth_v_et_p_bins[p] , color[p] , marker[p] , 0. , 1. );
117 h1_dph_v_et_p_bins[
p] =
new TH1F(Form(
"h1_dph_v_et_p_bins_%i",p),
";#eta;d#phi [mrad]" ,size_eta_bin-1,eta_bin);
prettyTH1F( h1_dph_v_et_p_bins[p] , color[p] , marker[p] , 0. , 25. );
122 float width_dpp[size_eta_bin-1][size_mom_bin-1] = {{0}};
123 float error_dpp[size_eta_bin-1][size_mom_bin-1] = {{0}};
124 float width_dth[size_eta_bin-1][size_mom_bin-1] = {{0}};
125 float error_dth[size_eta_bin-1][size_mom_bin-1] = {{0}};
126 float width_dph[size_eta_bin-1][size_mom_bin-1] = {{0}};
127 float error_dph[size_eta_bin-1][size_mom_bin-1] = {{0}};
129 TF1 *** f_gaus_dpp =
new TF1**[size_eta_bin-1];
130 TF1 *** f_gaus_dth =
new TF1**[size_eta_bin-1];
131 TF1 *** f_gaus_dph =
new TF1**[size_eta_bin-1];
133 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
134 f_gaus_dpp[et] =
new TF1*[size_mom_bin-1];
135 f_gaus_dth[et] =
new TF1*[size_mom_bin-1];
136 f_gaus_dph[et] =
new TF1*[size_mom_bin-1];
138 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
140 f_gaus_dpp[et][
p] =
new TF1(Form(
"f_gaus_dpp_%i_%i",et,
p),
"gaus",-approx_sig_dpp_1_2[et][
p],approx_sig_dpp_1_2[et][p]);
141 f_gaus_dth[et][
p] =
new TF1(Form(
"f_gaus_dth_%i_%i",et,p),
"gaus",-approx_sig_dth_1_2[et][p],approx_sig_dth_1_2[et][p]);
142 f_gaus_dph[et][
p] =
new TF1(Form(
"f_gaus_dph_%i_%i",et,p),
"gaus",-approx_sig_dph_1_2[et][p],approx_sig_dph_1_2[et][p]);
145 f_gaus_dpp[et][
p] =
new TF1(Form(
"f_gaus_dpp_%i_%i",et,
p),
"gaus",-0.007 ,0.007 );
146 f_gaus_dth[et][
p] =
new TF1(Form(
"f_gaus_dth_%i_%i",et,
p),
"gaus",-0.0007,0.0007);
147 f_gaus_dph[et][
p] =
new TF1(Form(
"f_gaus_dph_%i_%i",et,
p),
"gaus",-0.02 ,0.02 );
153 for(
int ev = 0 ; ev < nEntries ; ev++){
155 if(ev%1000000==0) cout <<
"Looping over entry " << ev <<
" out of " << nEntries << endl;
158 float gtheta = TMath::ACos(gpz/sqrt(gpx*gpx+gpy*gpy+gpz*gpz));
159 float theta = TMath::ACos(pz/sqrt(px*px+py*py+pz*pz));
160 float dth = theta - gtheta;
162 float geta = -TMath::Log(TMath::Tan(gtheta/2.));
164 float p_reco = sqrt(px*px+py*py+pz*pz);
165 float p_truth = sqrt(gpx*gpx+gpy*gpy+gpz*gpz);
166 float dp_p = (p_reco-p_truth)/p_truth;
168 float gphi = TMath::ATan(gpy/gpx);
169 float phi = TMath::ATan(py/px);
170 float dph = phi - gphi;
173 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
174 if(
abs(geta) > eta_bin[et] &&
abs(geta) <= eta_bin[et+1] ){
175 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
176 if( p_truth > mom_bin[
p] && p_truth <= mom_bin[
p+1] ){
177 h1_dpp_p_et_bins[et][
p] ->
Fill( dp_p );
178 h1_dth_p_et_bins[et][
p] ->
Fill( dth );
179 h1_dph_p_et_bins[et][
p] ->
Fill( dph );
187 TCanvas ** c_fits_p =
new TCanvas*[size_eta_bin-1];
188 TCanvas ** c_fits_th =
new TCanvas*[size_eta_bin-1];
189 TCanvas ** c_fits_ph =
new TCanvas*[size_eta_bin-1];
191 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
192 c_fits_p [et] =
new TCanvas(Form(
"c_fits_p_%i" ,et),Form(
"dp/p , %.1f<eta<%.1f",eta_bin[et],eta_bin[et+1]),1000,800); c_fits_p [et] -> Divide(3,2);
193 c_fits_th[et] =
new TCanvas(Form(
"c_fits_th_%i",et),Form(
"dtheta, %.1f<eta<%.1f",eta_bin[et],eta_bin[et+1]),1000,800); c_fits_th[et] -> Divide(3,2);
194 c_fits_ph[et] =
new TCanvas(Form(
"c_fits_ph_%i",et),Form(
"dphi , %.1f<eta<%.1f",eta_bin[et],eta_bin[et+1]),1000,800); c_fits_ph[et] -> Divide(3,2);
196 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
198 c_fits_p [et] -> cd(
p+1);
199 h1_dpp_p_et_bins[et][
p] ->
Draw(); h1_dpp_p_et_bins[et][
p] -> Fit(Form(
"f_gaus_dpp_%i_%i",et,
p),
"R");
200 width_dpp[et][
p] = f_gaus_dpp[et][
p] -> GetParameter(2);
201 error_dpp[et][
p] = (f_gaus_dpp[et][
p] -> GetParError(2))*(f_gaus_dpp[et][
p] -> GetChisquare())/(f_gaus_dpp[et][
p] -> GetNDF());
204 c_fits_th[et] -> cd(
p+1);
205 h1_dth_p_et_bins[et][
p] ->
Draw(); h1_dth_p_et_bins[et][
p] -> Fit(Form(
"f_gaus_dth_%i_%i",et,
p),
"R");
206 width_dth[et][
p] = f_gaus_dth[et][
p] -> GetParameter(2);
207 error_dth[et][
p] = (f_gaus_dth[et][
p] -> GetParError(2))*(f_gaus_dth[et][
p] -> GetChisquare())/(f_gaus_dth[et][
p] -> GetNDF());
210 c_fits_ph[et] -> cd(
p+1);
211 h1_dph_p_et_bins[et][
p] ->
Draw(); h1_dph_p_et_bins[et][
p] -> Fit(Form(
"f_gaus_dph_%i_%i",et,
p),
"R");
212 width_dph[et][
p] = f_gaus_dph[et][
p] -> GetParameter(2);
213 error_dph[et][
p] = (f_gaus_dph[et][
p] -> GetParError(2))*(f_gaus_dph[et][
p] -> GetChisquare())/(f_gaus_dph[et][
p] -> GetNDF());
217 h1_dpp_v_p_et_bins[et] -> SetBinContent(
p +1,width_dpp[et][
p]*100. );
218 h1_dth_v_p_et_bins[et] -> SetBinContent(p +1,width_dth[et][p]*1000.);
219 h1_dph_v_p_et_bins[et] -> SetBinContent(p +1,width_dph[et][p]*1000.);
220 h1_dpp_v_et_p_bins[
p] -> SetBinContent(et+1,width_dpp[et][p]*100. );
221 h1_dth_v_et_p_bins[
p] -> SetBinContent(et+1,width_dth[et][p]*1000.);
222 h1_dph_v_et_p_bins[
p] -> SetBinContent(et+1,width_dph[et][p]*1000.);
224 h1_dpp_v_p_et_bins[et] -> SetBinError (p +1,error_dpp[et][p]*100. );
225 h1_dth_v_p_et_bins[et] -> SetBinError (p +1,error_dth[et][p]*1000.);
226 h1_dph_v_p_et_bins[et] -> SetBinError (p +1,error_dph[et][p]*1000.);
227 h1_dpp_v_et_p_bins[
p] -> SetBinError (et+1,error_dpp[et][p]*100. );
228 h1_dth_v_et_p_bins[
p] -> SetBinError (et+1,error_dth[et][p]*1000.);
229 h1_dph_v_et_p_bins[
p] -> SetBinError (et+1,error_dph[et][p]*1000.);
235 ofstream updated_tab;
237 updated_tab.open(
"tables/"+tab_name);
238 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
239 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
240 updated_tab << width_dpp[et][
p];
241 if(
p == size_mom_bin-2) updated_tab <<
"\n";
242 else updated_tab <<
"\t";
246 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
247 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
248 updated_tab << width_dth[et][
p];
249 if(
p == size_mom_bin-2) updated_tab <<
"\n";
250 else updated_tab <<
"\t";
254 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
255 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++){
256 updated_tab << width_dph[et][
p];
257 if(
p == size_mom_bin-2) updated_tab <<
"\n";
258 else updated_tab <<
"\t";
266 TCanvas *
c1 =
new TCanvas(
"c1",
"c1",1300,900);
270 h1_dpp_v_p_et_bins[0] ->
Draw();
271 for(
int et = 0 ; et < size_eta_bin-1 ; et++) h1_dpp_v_p_et_bins[et] ->
Draw(
"same");
273 h1_dth_v_p_et_bins[0] ->
Draw();
274 for(
int et = 0 ; et < size_eta_bin-1 ; et++) h1_dth_v_p_et_bins[et] ->
Draw(
"same");
276 h1_dph_v_p_et_bins[0] ->
Draw();
277 for(
int et = 0 ; et < size_eta_bin-1 ; et++) h1_dph_v_p_et_bins[et] ->
Draw(
"same");
279 h1_dpp_v_et_p_bins[0] ->
Draw();
280 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++) h1_dpp_v_et_p_bins[
p] ->
Draw(
"same");
282 h1_dth_v_et_p_bins[0] ->
Draw();
283 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++) h1_dth_v_et_p_bins[
p] ->
Draw(
"same");
285 h1_dph_v_et_p_bins[0] ->
Draw();
286 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++) h1_dph_v_et_p_bins[
p] ->
Draw(
"same");
287 TLegend * leg1 =
new TLegend(0.50,0.6,0.70,0.85);
289 for(
int et = 0 ; et < size_eta_bin-1 ; et++) leg1 ->
AddEntry(h1_dph_v_p_et_bins[et],Form(
"%.1f < |#eta| < %.1f",eta_bin[et],eta_bin[et+1]));
291 leg1 ->
Draw(
"same");
292 TLegend * leg2 =
new TLegend(0.20,0.6,0.40,0.85);
294 for(
int p = 0 ;
p < size_mom_bin-1 ;
p++) leg2 ->
AddEntry(h1_dph_v_et_p_bins[
p],Form(
"%.1f < p < %.1f GeV/c",mom_bin[p],mom_bin[p+1]));
296 leg2 ->
Draw(
"same");
300 TString out_pdf_name =
"fits_AllS_"+partic+
"_B_"+Form(
"%.1f",Bfield)+
"T.pdf";
302 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
303 TString fname = out_pdf_name;
304 if(et == 0) fname+=
"(";
305 else if(et == size_eta_bin-2) fname+=
")";
306 c_fits_p[et] ->
Print(fname);
311 TFile * Fout =
new TFile(
"histos_"+partic+
"_B_"+Form(
"%.1f",Bfield)+
"T.root",
"recreate");
312 for(
int et = 0 ; et < size_eta_bin-1 ; et++){
313 h1_dpp_v_p_et_bins[et] -> Write(Form(
"h1_dpp_v_p_et_bins_%i",et));
314 h1_dth_v_p_et_bins[et] -> Write(Form(
"h1_dth_v_p_et_bins_%i",et));
315 h1_dph_v_p_et_bins[et] -> Write(Form(
"h1_dph_v_p_et_bins_%i",et));
317 for(
int p = 0 ; p < size_mom_bin-1 ; p++){
318 h1_dpp_v_et_p_bins[
p] -> Write(Form(
"h1_dpp_v_et_p_bins_%i",p));
319 h1_dth_v_et_p_bins[
p] -> Write(Form(
"h1_dth_v_et_p_bins_%i",p));
320 h1_dph_v_et_p_bins[
p] -> Write(Form(
"h1_dph_v_et_p_bins_%i",p));
330 h1 -> SetMarkerStyle(marker);
331 h1 -> SetMarkerColor(color);
334 h1 -> SetMaximum(max);
337 h1 ->
GetXaxis() -> SetNdivisions(107);
339 h1 ->
GetYaxis() -> SetNdivisions(107);