Skip to content

Commit 39a37aa

Browse files
committed
included hepmc rad analysis example
1 parent d5c62ed commit 39a37aa

1 file changed

Lines changed: 300 additions & 0 deletions

File tree

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
#include "HepMCElectro.h"
2+
#include "ParticleCreator.h"
3+
#include "ParticleGenerator.h"
4+
#include "ParticleModifier.h"
5+
#include "Indicing.h"
6+
#include "Histogrammer.h"
7+
#include "BasicKinematicsRDF.h"
8+
#include "ReactionKinematicsRDF.h"
9+
#include "ElectronScatterKinematicsRDF.h"
10+
#include "gammaN_2_Spin0Spin0SpinHalfRDF.h"
11+
#include <TBenchmark.h>
12+
#include <TCanvas.h>
13+
14+
void ProcessHepMCKLambda(const std::string infile="/w/work5/home/garyp/eic/Farm/data/KLambda_18x275/rootfiles/KLambda_18x275.root", const std::string outfile="/w/work5/home/garyp/rad_trees/HepMC_KLambda_18x275.root"){
15+
// Enable implicit multi-threading
16+
ROOT::EnableImplicitMT(4);
17+
18+
using namespace rad::names::data_type; //for MC()
19+
20+
gBenchmark->Start("df");
21+
22+
//create reaction dataframe
23+
rad::config::HepMCElectro hepmc{"hepmc3_tree", infile };
24+
25+
hepmc.AliasMomentumComponents();
26+
27+
//Assign particles names and indices
28+
//indicing comes from ordering in hepmc file
29+
hepmc.setBeamIonIndex(1);
30+
hepmc.setBeamElectronIndex(0);
31+
hepmc.setScatElectronIndex(2);
32+
33+
hepmc.setParticleIndex("Lambda",3);
34+
hepmc.setParticleIndex("K",4);
35+
36+
//rad::ParticleCreator particles{hepmc};
37+
hepmc.Particles().Miss("missX",{rad::names::ScatEle().data(),"Lambda"});
38+
39+
hepmc.setBaryonParticles({"Lambda"});
40+
hepmc.setMesonParticles({"missX"});
41+
42+
//must call this after all particles are configured
43+
hepmc.makeParticleMap();
44+
//rad::rdf::PrintParticles(hepmc,MC());
45+
46+
//////////////////////////////////////////////////////////
47+
// Now define calculated variables
48+
// Note reconstructed variables will have rec_ prepended
49+
// truth variables will have tru_ prepended
50+
//////////////////////////////////////////////////////////
51+
52+
//masses column name, {+ve particles}, {-ve particles}
53+
rad::rdf::MissMass(hepmc,"W","{scat_ele}");
54+
rad::rdf::Mass(hepmc,"Whad","{missX,Lambda}");
55+
56+
//dis kinematics
57+
rad::rdf::Q2(hepmc,"Q2");
58+
rad::rdf::nu(hepmc,"nu");
59+
rad::rdf::y(hepmc,"y");
60+
rad::rdf::xbj(hepmc,"xbj");
61+
62+
//q2prime tau
63+
rad::rdf::TauPrime(hepmc,"tau");
64+
65+
//t distribution, column name
66+
rad::rdf::TTop(hepmc,"t_top");
67+
rad::rdf::TBot(hepmc,"t_bot");
68+
rad::rdf::TPrimeBot(hepmc,"tp_bot");
69+
rad::rdf::TPrimeTop(hepmc,"tp_top");
70+
71+
//CM production angles
72+
rad::rdf::CMAngles(hepmc,"CM");
73+
//Proton Rest production angles
74+
rad::rdf::PRAngles(hepmc,"PR");
75+
76+
//semi-inclusive missing X
77+
rad::rdf::MissMass(hepmc,"MissMassX","{scat_ele,Lambda}");
78+
rad::rdf::MissP(hepmc,"MissP","{scat_ele,Lambda}");
79+
rad::rdf::MissPt(hepmc,"MissPt","{scat_ele,Lambda}");
80+
rad::rdf::MissPz(hepmc,"MissPz","{scat_ele,Lambda}");
81+
rad::rdf::MissTheta(hepmc,"MissTheta","{scat_ele,Lambda}");
82+
83+
//decay angles
84+
rad::rdf::gn2s0s0s12::HelicityAngles(hepmc,"Heli");
85+
//photon polarisation
86+
rad::rdf::PolGammaStar(hepmc,"GammaPol");
87+
rad::rdf::CircPolGammaStar(hepmc,"GammaPolCirc");
88+
rad::rdf::EGammaStar(hepmc,"GammaE");
89+
90+
///////////////////////////////////////////////////////////////
91+
//Define subsets of particles and corresponing variables to plot
92+
///////////////////////////////////////////////////////////////
93+
// hepmc.Define("electrons","rad::helpers::PositionsWhere(mc_pid==11)");
94+
// hepmc.Define(MC()+"elsP",Form("Take(%spmag,electrons)",MC().data()));
95+
96+
///////////////////////////////////////////////////////////
97+
//Define histograms
98+
///////////////////////////////////////////////////////////
99+
rad::histo::Histogrammer histo{"set1",hepmc};
100+
// we can create many histograms by splitting events into
101+
// bins, where the same histogram is produced for the given bin
102+
// e.g. create 10 bins in mc_W between 4 and 54 GeV
103+
//histo.Splitter().AddRegularDimension(MC()+"W", rad::histo::RegularSplits(10,4,54) );
104+
//can add as many split dimensions as we like
105+
//histo.Splitter().AddRegularDimension("xxx", rad::histo::RegularSplits(nbins,low,high) );
106+
histo.Init({MC()});//will create histograms for mc
107+
108+
//Kinematics
109+
histo.Create<TH1D,double>({"Q2","Q2",100,0,500.},{"Q2"});
110+
histo.Create<TH1D,double>({"nu","nu",100,0,10000.},{"nu"});
111+
histo.Create<TH1D,double>({"xbj","xbj",100,0,1.},{"xbj"});
112+
histo.Create<TH1D,double>({"y","y",100,0,1.},{"y"});
113+
114+
histo.Create<TH1D,double>({"W","W",100,0,200.},{"W"});
115+
histo.Create<TH1D,double>({"Whad","Whad",100,0,200.},{"Whad"});
116+
117+
histo.Create<TH1D,double>({"MissMassX","M(X) [GeV]",100,0,50.},{"MissMassX"});
118+
119+
histo.Create<TH1D,double>({"ttop","t(p,p^{'}) [GeV^{2}]",100,0,2.0},{"t_top"});
120+
histo.Create<TH1D,double>({"tbot","t(p,p^{'}) [GeV^{2}]",100,0,2.0},{"t_bot"});
121+
histo.Create<TH1D,double>({"tptop","t' top [GeV^{2}]",100,0,2.0},{"tp_top"});
122+
histo.Create<TH1D,double>({"tpbot","t' bot [GeV^{2}]",100,0,2.0},{"tp_bot"});
123+
124+
histo.Create<TH2D,double,double>({"tbot_MissMassX","tbot vs M_{X,miss}",100,0.0,2.0,100,0.0,50.},{"t_bot","MissMassX"});
125+
histo.Create<TH2D,double,double>({"tpbot_MissMassX","t'bot vs M_{X,miss}",100,0.0,2.0,100,0.0,50.},{"tp_bot","MissMassX"});
126+
histo.Create<TH2D,double,double>({"tbot_W","tbot vs W",100,0.0,2.0,100,0.,200.},{"t_bot","W"});
127+
histo.Create<TH2D,double,double>({"tpbot_W","t'bot vs W",100,0.0,2.0,100,0.,200.},{"tp_bot","W"});
128+
129+
//histo.Create<TH2D,double,double>({"W_MissMassX","W vs M_{X,miss}",100,0.0,50.,100,0.,200.},{"MissMassX","W"});
130+
131+
//CM and PR Decay Angles
132+
histo.Create<TH1D,double>({"cthCM","cos(#theta_{CM})",100,-1,1},{"CM_CosTheta"});
133+
histo.Create<TH1D,double>({"phCM","#phi_{CM}",100,-TMath::Pi(),TMath::Pi()},{"CM_Phi"});
134+
histo.Create<TH1D,double>({"cthPR","cos(#theta_{PR})",100,-1,1},{"PR_CosTheta"});
135+
histo.Create<TH1D,double>({"phPR","#phi_{PR}",100,-TMath::Pi(),TMath::Pi()},{"PR_Phi"});
136+
137+
//exclusivity
138+
histo.Create<TH1D,double>({"MissMassX","M_{X,miss} [GeV]",100,-10,10},{"MissMassX"});
139+
histo.Create<TH1D,double>({"missP","p_{X,miss}(e',#Lambda)",100,0,100},{"MissP"});
140+
histo.Create<TH1D,double>({"missPt","p_{t,X,miss}(e',#Lambda)",100,0,100},{"MissPt"});
141+
histo.Create<TH1D,double>({"missPz","p_{z,X,miss}(e',#Lambda)",100,0,100},{"MissPz"});
142+
histo.Create<TH1D,double>({"missTheta","#theta_{X,miss}(e',#Lambda)",100,0,1},{"MissTheta"});
143+
144+
//histo.Create<TH1D,ROOT::RVecD>({"allP","momentum of all particles",100,0,100},{"pmag"});
145+
// histo.Create<TH1D,ROOT::RVecD>({"eleP","momentum of electrons",100,0,100},{"elsP"});
146+
147+
//check recoil proton azimuthal distribution
148+
// histo.Create<TH1D,double>({"scatele_phi","Azimuthal Angle of Scattered Electron",250,-TMath::Pi(),TMath::Pi()},{"phi[scat_ele]"});
149+
// histo.Create<TH1D,double>({"pprime_phi","Azimuthal Angle of Recoil Proton",250,-TMath::Pi(),TMath::Pi()},{"phi[pprime]"});
150+
151+
//for brufit need
152+
//CM_Phi Heli_theta Heli_phi GammaPolCirc=sqrt(1-epsilon)*Pol t GammaE
153+
histo.Create<TH1D,double>({"GammaPol","Polarisation of Virtual Photon",100,0,1},{"GammaPol"});
154+
histo.Create<TH1D,double>({"GammaE","Energy of Virtual Photon",100,0,18},{"GammaE"});
155+
histo.Create<TH1D,double>({"Heli_CosTheta","#theta decay angle",100,-TMath::Pi(),TMath::Pi()},{"Heli_CosTheta"});
156+
histo.Create<TH1D,double>({"Heli_Phi","#phi decay angle",100,-TMath::Pi()-1,TMath::Pi()+1},{"Heli_Phi"});
157+
158+
//Polarisation and kinematic limits for cicular
159+
histo.Create<TH2D,double,double>({"y_W","W{ele missmass} vs y",100,0,1,100,0,200},{"y","W"});
160+
histo.Create<TH2D,double,double>({"y_Escatele","E_{e'} vs y",100,0,1,100,0,18},{"y","pmag[scat_ele]"});
161+
histo.Create<TH2D,double,double>({"y_CircPol","Circular Polarisation vs y",100,0,1,100,0,1},{"y","GammaPolCirc"});
162+
histo.Create<TH2D,double,double>({"W_CircPol","Circular Polarisation vs W{ele missmiass}",100,0,200,100,0,1},{"W","GammaPolCirc"});
163+
164+
165+
gBenchmark->Start("snapshot");
166+
hepmc.BookLazySnapshot(outfile);
167+
gBenchmark->Stop("snapshot");
168+
gBenchmark->Print("snapshot");
169+
170+
gBenchmark->Start("processing");
171+
///////////////////////////////////////////////////////////
172+
//Draw histograms
173+
///////////////////////////////////////////////////////////
174+
175+
TCanvas *c00 = new TCanvas("c00","Kinematics");
176+
c00->Divide(4,2);
177+
c00->cd(1);
178+
histo.DrawSame("Q2",gPad);
179+
c00->cd(2);
180+
histo.DrawSame("W",gPad);
181+
c00->cd(3);
182+
histo.DrawSame("Whad",gPad);
183+
c00->cd(4);
184+
histo.DrawSame("MissMassX",gPad);
185+
c00->cd(5);
186+
histo.DrawSame("ttop",gPad);
187+
c00->cd(6);
188+
histo.DrawSame("tbot",gPad);
189+
c00->cd(7);
190+
histo.DrawSame("tptop",gPad);
191+
c00->cd(8);
192+
histo.DrawSame("tpbot",gPad);
193+
c00->Print("temp00.pdf");
194+
195+
TCanvas *c001 = new TCanvas("c001","Kinematics Reduced");
196+
c001->Divide(2,2);
197+
c001->cd(1)->SetLogy();
198+
histo.DrawSame("Q2",gPad);
199+
c001->cd(2);
200+
histo.DrawSame("W",gPad);
201+
c001->cd(3);
202+
histo.DrawSame("MissMassX",gPad);
203+
c001->cd(4);
204+
histo.DrawSame("tbot",gPad);
205+
c001->Print("temp001.pdf");
206+
207+
//histo.DrawSame("ttop",gPad);
208+
209+
TCanvas *c01 = new TCanvas("c01","Semi-Inclusive Missing X");
210+
c01->Divide(3,2);
211+
c01->cd(1);
212+
histo.DrawSame("MissMassX",gPad);
213+
c01->cd(2);
214+
histo.DrawSame("missP",gPad);
215+
c01->cd(3);
216+
histo.DrawSame("missPt",gPad);
217+
c01->cd(4);
218+
histo.DrawSame("missPz",gPad);
219+
c01->cd(5);
220+
histo.DrawSame("missTheta",gPad);
221+
c01->cd(6);
222+
//histo.DrawSame("MissMassX",gPad);
223+
c01->Print("temp01.pdf");
224+
225+
TCanvas *c02 = new TCanvas("c02","2D t Distributions");
226+
c02->Divide(2,2);
227+
c02->cd(1);
228+
histo.Draw2DMC("tbot_MissMassX","colz",gPad);
229+
c02->cd(2);
230+
histo.Draw2DMC("tpbot_MissMassX","colz",gPad);
231+
c02->cd(3);
232+
histo.Draw2DMC("tbot_W","colz",gPad);
233+
c02->cd(4);
234+
histo.Draw2DMC("tpbot_W","colz",gPad);
235+
c02->Print("temp02.pdf");
236+
237+
TCanvas *c03 = new TCanvas("c03","CM and PR Frame Angles");
238+
c03->Divide(2,2);
239+
c03->cd(1);
240+
histo.DrawSame("cthCM",gPad);
241+
c03->cd(2);
242+
histo.DrawSame("phCM",gPad);
243+
c03->cd(3);
244+
histo.DrawSame("cthPR",gPad);
245+
c03->cd(4);
246+
histo.DrawSame("phPR",gPad);
247+
c03->Print("temp03.pdf");
248+
249+
TCanvas *c04 = new TCanvas("c04","Helicity and Polarisation");
250+
c04->Divide(2,2);
251+
c04->cd(1);
252+
histo.DrawSame("Heli_CosTheta",gPad);
253+
c04->cd(2);
254+
histo.DrawSame("Heli_Phi",gPad);
255+
c04->cd(3);
256+
histo.DrawSame("GammaPol",gPad);
257+
c04->cd(4);
258+
histo.DrawSame("GammaE",gPad);
259+
c04->Print("temp04.pdf");
260+
261+
TCanvas *c05 = new TCanvas("c05","DIS Kinematics");
262+
c05->Divide(2,2);
263+
c05->cd(1);
264+
histo.DrawSame("Q2",gPad);
265+
c05->cd(2);
266+
histo.DrawSame("nu",gPad);
267+
c05->cd(3);
268+
histo.DrawSame("xbj",gPad);
269+
c05->cd(4);
270+
histo.DrawSame("y",gPad);
271+
c05->Print("temp05.pdf");
272+
273+
TCanvas *c06 = new TCanvas("c06","Kin Lim CircPol Correlations");
274+
c06->Divide(2,2);
275+
c06->cd(1);
276+
histo.Draw2DMC("y_W","colz",gPad);
277+
c06->cd(2);
278+
histo.Draw2DMC("y_Escatele","colz",gPad);
279+
c06->cd(3);
280+
histo.Draw2DMC("y_CircPol","colz",gPad);
281+
c06->cd(4);
282+
histo.Draw2DMC("W_CircPol","colz",gPad);
283+
c06->Print("temp06.pdf");
284+
285+
TString pdfoutfile = outfile;
286+
pdfoutfile = gSystem->BaseName(pdfoutfile);
287+
pdfoutfile.ReplaceAll(".root",".pdf");
288+
289+
gSystem->Exec(Form("pdfunite temp*.pdf %s",pdfoutfile.Data()));
290+
gSystem->Exec("rm temp*.pdf");
291+
gBenchmark->Stop("processing");
292+
gBenchmark->Print("processing");
293+
294+
//save all histograms to file
295+
//histo.File("HepMCDDVCS_hists.root");
296+
297+
gBenchmark->Stop("df");
298+
gBenchmark->Print("df");
299+
300+
}

0 commit comments

Comments
 (0)