11 #include <THnSparse.h>
14 #include <eicsmear/smear/EventSmear.h>
15 #include <eicsmear/erhic/EventPythia.h>
16 #include <eicsmear/erhic/ParticleMC.h>
23 TString filename_mc_smeared,
31 double electron_pmin = 0.01;
34 double electron_emin = 3.0;
37 TFile *file_mc =
new TFile(filename_mc,
"OPEN");
38 TFile *file_mc_smeared =
new TFile(filename_mc_smeared,
"OPEN");
41 TTree *
tree = (TTree*)file_mc->Get(
"EICTree");
42 TTree *tree_smeared = (TTree*)file_mc_smeared->Get(
"Smeared");
51 TIter
next(file_mc->GetListOfKeys());
53 while ((key = (TKey*)
next()))
55 if ( TString(key->GetName()) ==
"crossSection" )
57 xsec += (TString(((TObjString*)key->ReadObj())->GetName())).Atof();
62 if ( TString(key->GetName()) ==
"nEvents" )
64 nevent += (TString(((TObjString*)key->ReadObj())->GetName())).Atof();
73 TObjString* gen_crossSection = (TObjString*)file_mc->Get(
"crossSection");
74 TObjString* gen_nEvents = (TObjString*)file_mc->Get(
"nEvents");
77 gen_crossSection->SetString( TString::Format(
"%f", xsec) );
78 gen_nEvents->SetString( TString::Format(
"%d", nevent) );
81 float xsec_fb = xsec * 1e9;
84 float lumi_ifb = (float)nevent / (
float)xsec_fb;
87 TObjString* gen_lumi_ifb =
new TObjString();
88 gen_lumi_ifb->SetString( TString::Format(
"%f", lumi_ifb) );
91 cout <<
"crossSection: " << gen_crossSection->GetName() << endl;
92 cout <<
"nEvents: " << gen_nEvents->GetName() << endl;
93 cout <<
"luminosity: " << gen_lumi_ifb->GetName() << endl;
96 TFile *file_out =
new TFile(filename_output,
"RECREATE");
99 tree->AddFriend(tree_smeared);
101 erhic::EventPythia *
event = NULL;
102 Smear::Event *eventS = NULL;
104 tree->SetBranchAddress(
"event", &
event);
105 tree->SetBranchAddress(
"eventS", &eventS);
108 TH1F* h_eta =
new TH1F(
"h_eta",
";#eta;dN/d#eta", 100, -5, 5);
109 TH1F* h_eta_accept = (TH1F*)h_eta->Clone(
"h_eta_accept");
110 h_eta_accept->SetLineColor(kGreen);
126 const int nbins_x = 25;
130 double width_x = (max_x - min_x) / nbins_x;
131 double bins_x[nbins_x+1];
132 for(
int i =0;
i <= nbins_x;
i++)
135 bins_x[
i] = TMath::Power( 10, min_x +
i*width_x);
139 const int nbins_Q2 = 20;
143 double width_Q2 = (max_Q2 - min_Q2) / nbins_Q2;
144 double bins_Q2[nbins_Q2+1];
145 for(
int i =0;
i <= nbins_Q2;
i++)
146 bins_Q2[
i] = TMath::Power( 10, min_Q2 +
i*width_Q2);
149 const int nbins_z = 20;
153 double width_z = (max_z -
min_z) / nbins_z;
154 double bins_z[nbins_z+1];
155 for(
int i =0;
i <= nbins_z;
i++)
158 bins_z[
i] = min_z +
i*width_z;
162 const int nbins_pT1 = 5;
163 const int nbins_pT2 = 4;
164 const int nbins_pT = nbins_pT1 + nbins_pT2;
167 double width_pT1 = 0.2;
168 double width_pT2 = 1.0;
170 double bins_pT[nbins_pT+1];
171 for(
int i =0;
i <= nbins_pT1;
i++)
174 bins_pT[
i] = min_pT +
i*width_pT1;
176 for(
int i =1;
i <= nbins_pT2;
i++)
179 bins_pT[nbins_pT1 +
i] = min_pT + nbins_pT1*width_pT1 +
i*width_pT2;
184 const int hn_dis_ndim = 2;
185 int hn_dis_nbins[] = { nbins_x,
187 double hn_dis_xmin[] = {0., 0. };
188 double hn_dis_xmax[] = {0., 0. };
190 THnSparse* hn_dis =
new THnSparseF(
"hn_dis_electron",
191 "DIS Kinematis Per Event (Electron); x; Q2;",
197 hn_dis->GetAxis(0)->SetName(
"x");
198 hn_dis->GetAxis(1)->SetName(
"Q2");
200 hn_dis->SetBinEdges(0,bins_x);
201 hn_dis->SetBinEdges(1,bins_Q2);
204 THnSparse* hn_dis_accept = (THnSparse*)hn_dis->Clone(
"hn_dis_electron_accept");
205 hn_dis_accept->SetTitle(
"DIS Kinematis Per Event (Accepted)");
208 const int hn_sidis_ndim = 4;
209 int hn_sidis_nbins[] = { nbins_x,
213 double hn_sidis_xmin[] = {0., 0., 0., 0. };
214 double hn_sidis_xmax[] = {0., 0., 0., 0. };
216 THnSparse* hn_sidis_pion_plus =
new THnSparseF(
"hn_sidis_pion_plus",
217 "SIDIS Kinematis Per Particle (Postitively Charged Pion);x;Q2;z;pT;",
223 hn_sidis_pion_plus->GetAxis(0)->SetName(
"x");
224 hn_sidis_pion_plus->GetAxis(1)->SetName(
"Q2");
225 hn_sidis_pion_plus->GetAxis(2)->SetName(
"z");
226 hn_sidis_pion_plus->GetAxis(3)->SetName(
"pT");
229 hn_sidis_pion_plus->SetBinEdges(0,bins_x);
230 hn_sidis_pion_plus->SetBinEdges(1,bins_Q2);
231 hn_sidis_pion_plus->SetBinEdges(2,bins_z);
232 hn_sidis_pion_plus->SetBinEdges(3,bins_pT);
235 THnSparse* hn_sidis_pion_minus = (THnSparseF*)hn_sidis_pion_plus->Clone(
"hn_sidis_pion_minus");
236 hn_sidis_pion_minus->SetTitle(
"SIDIS Kinematis Per Particle (Negatively Charged Pion)");
238 THnSparse* hn_sidis_kaon_plus = (THnSparseF*)hn_sidis_pion_plus->Clone(
"hn_sidis_kaon_plus");
239 hn_sidis_kaon_plus->SetTitle(
"SIDIS Kinematis Per Particle (Positively Charged Kaon)");
241 THnSparse* hn_sidis_kaon_minus = (THnSparseF*)hn_sidis_pion_plus->Clone(
"hn_sidis_kaon_minus");
242 hn_sidis_kaon_minus->SetTitle(
"SIDIS Kinematis Per Particle (Negatively Charged Kaon)");
245 THnSparse* hn_sidis_pion_plus_accept = (THnSparse*)hn_sidis_pion_plus->Clone(
"hn_sidis_pion_plus_accept");
246 hn_sidis_pion_plus_accept->SetTitle(
"SIDIS Kinematis Per Particle (Positively Charged Pion, Accepted)");
248 THnSparse* hn_sidis_pion_minus_accept = (THnSparseF*)hn_sidis_pion_plus->Clone(
"hn_sidis_pion_minus_accept");
249 hn_sidis_pion_minus_accept->SetTitle(
"SIDIS Kinematis Per Particle (Negatively Charged Pion, Accepted)");
251 THnSparse* hn_sidis_kaon_plus_accept = (THnSparseF*)hn_sidis_pion_plus->Clone(
"hn_sidis_kaon_plus_accept");
252 hn_sidis_kaon_plus_accept->SetTitle(
"SIDIS Kinematis Per Particle (Positively Charged Kaon, Accepted)");
254 THnSparse* hn_sidis_kaon_minus_accept = (THnSparseF*)hn_sidis_pion_plus->Clone(
"hn_sidis_kaon_minus_accept");
255 hn_sidis_kaon_minus_accept->SetTitle(
"SIDIS Kinematis Per Particle (Negatively Charged Kaon, Accepted)");
258 TH2F* hxQ2 = (TH2F*)hn_dis->Projection(1,0);
271 for (
int bin_x = 1; bin_x <= hxQ2->GetNbinsX(); bin_x++ )
274 TMath::Power(10, 0.5 * ( ( TMath::Log10( hxQ2->GetXaxis()->GetBinLowEdge(bin_x) ) )
275 + ( TMath::Log10( hxQ2->GetXaxis()->GetBinLowEdge(bin_x) + hxQ2->GetXaxis()->GetBinWidth(bin_x) ) ) ) ) );
282 for (
int bin_Q2 = 1; bin_Q2 <= hxQ2->GetNbinsY(); bin_Q2++ )
286 TMath::Power(10, 0.5 * ( ( TMath::Log10( hxQ2->GetYaxis()->GetBinLowEdge(bin_Q2) ) )
287 + ( TMath::Log10( hxQ2->GetYaxis()->GetBinLowEdge(bin_Q2) + hxQ2->GetYaxis()->GetBinWidth(bin_Q2) ) ) ) ) );
292 unsigned max_event = tree->GetEntries();
297 for (
unsigned ievent = 0; ievent < max_event; ievent++ )
299 if ( ievent%1000 == 0 )
300 cout <<
"Processing event " << ievent << endl;
303 tree->GetEntry(ievent);
306 float y =
event->GetTrueY();
307 if ( y > 0.95 || y < 0.01 )
310 float x =
event->GetTrueX();
311 float Q2 =
event->GetTrueQ2();
313 double fill_hn_dis[] = {
x, Q2};
314 hn_dis->Fill( fill_hn_dis );
317 bool electron_detected =
false;
318 if ( eventS->ScatteredLepton() && eventS->ScatteredLepton()->GetP() > electron_pmin && eventS->ScatteredLepton()->GetE() > electron_emin )
319 electron_detected =
true;
322 if ( !electron_detected )
326 hn_dis_accept->Fill( fill_hn_dis );
330 unsigned ntracks =
event->GetNTracks();
332 for (
unsigned itrack = 0; itrack <
ntracks; itrack++ )
334 erhic::ParticleMC * iparticle =
event->GetTrack( itrack );
335 Smear::ParticleMCS * ismeared = eventS->GetTrack( itrack );
338 if ( iparticle->GetStatus() != 1 )
342 float z = iparticle->GetZ();
349 if ( iparticle->GetEta() < -4 || iparticle->GetEta() > 4 )
353 float pT = iparticle->GetPtVsGamma();
356 double fill_hn_sidis[] = {
x, Q2,
z, pT};
359 int pid = iparticle->Id().Code();
366 hn_sidis_pion_plus->Fill( fill_hn_sidis );
368 if ( ismeared->GetP() > 0.1 && ismeared->Id().Code() == 211 )
369 hn_sidis_pion_plus_accept->Fill( fill_hn_sidis );
373 else if ( pid == -211 )
375 hn_sidis_pion_minus->Fill( fill_hn_sidis );
377 if ( ismeared->GetP() > 0.1 && ismeared->Id().Code() == -211 )
378 hn_sidis_pion_minus_accept->Fill( fill_hn_sidis );
382 else if ( pid == 321 )
384 hn_sidis_kaon_plus->Fill( fill_hn_sidis );
386 if ( ismeared->GetP() > 0.1 && ismeared->Id().Code() == 321 )
387 hn_sidis_kaon_plus_accept->Fill( fill_hn_sidis );
391 else if ( pid == -321 )
393 hn_sidis_kaon_minus->Fill( fill_hn_sidis );
395 if ( ismeared->GetP() > 0.1 && ismeared->Id().Code() == -321 )
396 hn_sidis_kaon_minus_accept->Fill( fill_hn_sidis );
405 hn_dis_accept->Write();
407 hn_sidis_pion_plus->Write();
408 hn_sidis_pion_minus->Write();
409 hn_sidis_kaon_plus->Write();
410 hn_sidis_kaon_minus->Write();
412 hn_sidis_pion_plus_accept->Write();
413 hn_sidis_pion_minus_accept->Write();
414 hn_sidis_kaon_plus_accept->Write();
415 hn_sidis_kaon_minus_accept->Write();
418 h_eta_accept->Write();
420 gen_crossSection->Write(
"crossSection");
421 gen_nEvents->Write(
"nEvents");
423 gen_lumi_ifb->Write(
"luminosity");
433 int main(
int argc ,
char* argv[] )
435 if ( argc < 4 || argc > 5 )
437 cout <<
"Usage: " << argv[0] <<
" <filename_output> <filename_EICTree> <filename_EICTree_smeared> <optional: 'debug' for debug mode" << endl;
441 cout <<
"Running eic_sphenix_fill_xq2 with: \n" << endl;
442 cout <<
" - Output file: " << argv[1] << endl;
443 cout <<
" - EICTree input file: " << argv[2] << endl;
447 cout <<
" - EICTree (smeared) file: " << argv[3] << endl;
450 else if ( argc == 5 )
452 cout <<
" - EICTree (smeared) file: " << argv[3] << endl;
453 cout <<
" ==== DEBUG MODE ==== " << endl;