hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MCAnaHistos.cxx
Go to the documentation of this file.
1#include "MCAnaHistos.h"
2#include <math.h>
3
5 std::string h_name = "";
6 for (auto hist : _h_configs.items()) {
7 if (hist.key() == "pos_pxpy_hh")
8 {
9 for (int pxz = hist.value().at("lowPxz");
10 pxz < hist.value().at("highPxz");
11 pxz += (int) hist.value().at("stepPxz"))
12 {
13 h_name = m_name + "_pos_pxpy_" + std::to_string(pxz) + "_hh";
14 histos2d[h_name] = plot2D(h_name, hist.value().at("xtitle"),
15 hist.value().at("binsX"), hist.value().at("minX"),
16 hist.value().at("maxX"), hist.value().at("ytitle"),
17 hist.value().at("binsY"), hist.value().at("minY"),
18 hist.value().at("maxY"));
19 }
20 }
21 if (hist.key() == "ele_pxpy_hh")
22 {
23 for (int pxz = hist.value().at("lowPxz");
24 pxz < hist.value().at("highPxz");
25 pxz += (int) hist.value().at("stepPxz"))
26 {
27 h_name = m_name + "_ele_pxpy_" + std::to_string(pxz) + "_hh";
28 histos2d[h_name] = plot2D(h_name, hist.value().at("xtitle"),
29 hist.value().at("binsX"), hist.value().at("minX"),
30 hist.value().at("maxX"), hist.value().at("ytitle"),
31 hist.value().at("binsY"), hist.value().at("minY"),
32 hist.value().at("maxY"));
33 }
34 }
35 }
36}
37
38void MCAnaHistos::FillMCParticles(std::vector<MCParticle*> *mcParts, std::string analysis, float weight) {
39 if(mcParts == nullptr)
40 std::cout << "MCPARTS IS NULL" << std::endl;
41 int nParts = mcParts->size();
42 Fill1DHisto("numMCparts_h", (float)nParts, weight);
43 int nMuons = 0;
44 int nElec = 0;
45 int nPos = 0;
46 int nGamma = 0;
47 double minMuonE = -99.9;
48
49 TLorentzVector ele;
50 TLorentzVector pos;
51
52 for (int i = 0; i < nParts; i++)
53 {
54 MCParticle *part = mcParts->at(i);
55 int pdg = part->getPDG();
56 int momPdg = part->getMomPDG();
57 // if ( pdg > 600)
58 // std::cout<<"Found particle with momPDG = "<<momPdg<<" part = " << pdg << " mass " << part->getMass() << std::endl;
59
60 double energy = part->getEnergy();
61 double massMeV = 1000.0*part->getMass();
62 double zPos = part->getVertexPosition().at(2);
63 std::vector<double> partP = part->getMomentum();
64 TLorentzVector part4P(partP.at(0), partP.at(1), partP.at(2), energy);
65 part4P.RotateY(-0.0305);
66 double momentum = part4P.P();
67
68 if (momPdg == 623)
69 {
70 Fill1DHisto("recoil_ele_p_h",momentum, weight);
71 Fill1DHisto("recoil_ele_px_h",part4P.X(), weight);
72 Fill1DHisto("recoil_ele_py_h",part4P.Y(), weight);
73 Fill1DHisto("recoil_ele_pz_h",part4P.Z(), weight);
74 }
75
76 if (pdg == 622)
77 {
78 Fill1DHisto("mc622Mass_h", massMeV, weight);
79 Fill1DHisto("mc622Z_h", zPos, weight);
80 Fill1DHisto("mc622Energy_h", energy, weight);
81 Fill1DHisto("mc622P_h", momentum, weight);
82 }
83
84 if (pdg == 625)
85 {
86 Fill1DHisto("mc625Mass_h", massMeV, weight);
87 Fill1DHisto("mc625Z_h", zPos, weight);
88 Fill1DHisto("mc625Energy_h", energy, weight);
89 Fill1DHisto("mc625P_h", momentum, weight);
90 }
91
92 if (pdg == 624)
93 {
94 Fill1DHisto("mc624Mass_h", massMeV, weight);
95 Fill1DHisto("mc624Z_h", zPos, weight);
96 Fill1DHisto("mc625Energy_h", energy, weight);
97 Fill1DHisto("mc625P_h", momentum, weight);
98 }
99
100
101 if (fabs(pdg) == 13)
102 {
103 nMuons++;
104 if (energy < minMuonE || minMuonE < 0.0)
105 {
106 minMuonE = energy;
107 }
108 }
109
110 bool partOfInt = false;
111 // std::cout<<analysis<<std::endl;
112 if (analysis == "simps"){
113 if (fabs(pdg) == 11 && momPdg == 625)
114 partOfInt = true;
115 } else {
116 if ((momPdg == 623 || momPdg == 622) && (fabs(pdg) == 11))
117 partOfInt = true;
118 }
119
120 if (partOfInt == true)
121 {
122 double PperpB = 1000.0*sqrt( (part4P.Px()*part4P.Px()) + (part4P.Pz()*part4P.Pz()) );
123 int Pxz = int(floor(PperpB));
124 int round = Pxz%100;
125 Pxz = Pxz - round;
126 if (pdg == 11)
127 {
128 Fill1DHisto("ele_pxz_h", PperpB, weight);
129 Fill2DHisto("ele_pxpy_" + std::to_string(Pxz) + "_hh", part4P.Px(), part4P.Py(), weight);
130
131 Fill1DHisto("truthRadElecE_h", energy, weight);
132 Fill1DHisto("truthRadEleczPos_h", zPos, weight);
133 Fill1DHisto("truthRadElecPt_h", part4P.Pt(), weight);
134 Fill1DHisto("truthRadElecPz_h", part4P.Pz(), weight);
135
136 ele = part4P;
137 }
138 if (pdg == -11)
139 {
140 Fill1DHisto("pos_pxz_h", PperpB, weight);
141 Fill2DHisto("pos_pxpy_" + std::to_string(Pxz) + "_hh", part4P.Px(), part4P.Py(), weight);
142
143 Fill1DHisto("truthRadPosE_h", energy, weight);
144 Fill1DHisto("truthRadPoszPos_h", zPos, weight);
145 Fill1DHisto("truthRadPosPt_h", part4P.Pt(), weight);
146 Fill1DHisto("truthRadPosPz_h", part4P.Pz(), weight);
147
148 pos = part4P;
149 }
150 }
151
152 if (analysis == "beam") {
153 if (pdg == 11) {
154 nElec++;
155 Fill1DHisto("truthElecE_h", energy, weight);
156 Fill1DHisto("truthElecPt_h", part4P.Pt(), weight);
157 Fill1DHisto("truthElecPz_h", part4P.Pz(), weight);
158 }
159
160 if (pdg == -11) {
161 nPos++;
162 Fill1DHisto("truthPosE_h", energy, weight);
163
164 }
165
166 if (pdg == 22) {
167 nGamma++;
168 Fill1DHisto("truthGammaE_h", energy, weight);
169 Fill1DHisto("truthGammaELow_h", energy*1000.0, weight);// Scaled to MeV
170 }
171 }
172
173 Fill1DHisto("MCpartsEnergy_h", energy, weight);
174 Fill1DHisto("MCpartsEnergyLow_h", energy*1000.0, weight);// Scaled to MeV
175 }
176
177 //TLorentzVector res = ele + pos;
178 //std::cout<<" My resonance mass is "<< res.M()<< std::endl;
179
180 Fill1DHisto("numMuons_h", nMuons, weight);
181 Fill1DHisto("minMuonE_h", minMuonE, weight);
182 Fill1DHisto("minMuonEhigh_h", minMuonE, weight);
183
184 Fill1DHisto("numElectrons_h", nElec, weight);
185 Fill1DHisto("numPositrons_h", nPos, weight);
186 Fill1DHisto("numGammas_h", nGamma, weight);
187}
188
189void MCAnaHistos::FillMCTrackerHits(std::vector<MCTrackerHit*> *mcTrkrHits, float weight ) {
190 int nHits = mcTrkrHits->size();
191 Fill1DHisto("numMCTrkrHit_h", nHits, weight);
192 for (int i=0; i < nHits; i++)
193 {
194 MCTrackerHit *hit = mcTrkrHits->at(i);
195 int pdg = hit->getPDG();
196 Fill1DHisto("mcTrkrHitEdep_h", hit->getEdep()*1000.0, weight); // Scaled to MeV
197 Fill1DHisto("mcTrkrHitPdgId_h", (float)hit->getPDG(), weight);
198 }
199}
200
201void MCAnaHistos::FillMCEcalHits(std::vector<MCEcalHit*> *mcEcalHits, float weight ) {
202 int nHits = mcEcalHits->size();
203 Fill1DHisto("numMCEcalHit_h", nHits, weight);
204 for (int i=0; i < nHits; i++)
205 {
206 MCEcalHit *hit = mcEcalHits->at(i);
207 Fill1DHisto("mcEcalHitEnergy_h", hit->getEnergy()*1000.0, weight); // Scaled to MeV
208 }
209}
210
211void MCAnaHistos::FillMCParticleHistos(MCParticle* mcpart, std::string label, double weight){
212 double px=mcpart->getMomentum().at(0);
213 double py=mcpart->getMomentum().at(1);
214 double pz=mcpart->getMomentum().at(2);
215
216 double p=sqrt(px*px+py*py+pz*pz);
217
218 Fill1DHisto(label+"_px_h",px,weight);
219 Fill1DHisto(label+"_py_h",py,weight);
220 Fill1DHisto(label+"_pz_h",pz,weight);
221 Fill1DHisto(label+"_p_h",p,weight);
222
223 double thetaX=px/p;
224 double thetaY=py/p;
225 Fill1DHisto(label+"_thetax_h",thetaX,weight);
226 Fill1DHisto(label+"_thetay_h",thetaY,weight);
227
228 return;
229}
230
231void MCAnaHistos::FillMCPairHistos(MCParticle* ele,MCParticle* pos,std::string label, double weight){
232 double px1=ele->getMomentum().at(0);
233 double py1=ele->getMomentum().at(1);
234 double pz1=ele->getMomentum().at(2);
235 double px2=pos->getMomentum().at(0);
236 double py2=pos->getMomentum().at(1);
237 double pz2=pos->getMomentum().at(2);
238
239 double E1=sqrt(px1*px1+py1*py1+pz1*pz1);
240 double E2=sqrt(px2*px2+py2*py2+pz2*pz2);
241
242 double pxTot=px1+px2;
243 double pyTot=py1+py2;
244 double pzTot=pz1+pz2;
245 double pTotSq=pxTot*pxTot+pyTot*pyTot+pzTot*pzTot;
246 double Etot=E1+E2;
247
248 double mass=sqrt(Etot*Etot-pTotSq);
249
250 Fill1DHisto(label+"_pxV0_h",pxTot,weight);
251 Fill1DHisto(label+"_pyV0_h",pyTot,weight);
252 Fill1DHisto(label+"_pzV0_h",pzTot,weight);
253 Fill1DHisto(label+"_pV0_h",sqrt(pTotSq),weight);
254 Fill1DHisto(label+"_mass_h",mass,weight);
255
256 double thetaX=pxTot/sqrt(pTotSq);
257 double thetaY=pyTot/sqrt(pTotSq);
258 Fill1DHisto(label+"_thetaxV0_h",thetaX,weight);
259 Fill1DHisto(label+"_thetayV0_h",thetaY,weight);
260
261}
void Fill2DHisto(const std::string &histoName, float valuex, float valuey, float weight=1.)
description
std::map< std::string, TH2F * > histos2d
description
TH2F * plot2D(std::string name, std::string xtitle, int nbinsX, float xmin, float xmax, std::string ytitle, int nbinsY, float ymin, float ymax)
description
void Fill1DHisto(const std::string &histoName, float value, float weight=1.)
description
json _h_configs
description
std::string m_name
description
void FillMCParticles(std::vector< MCParticle * > *mcParts, std::string analysis, float weight=1.)
description
void FillMCParticleHistos(MCParticle *mcpart, std::string label, double weight)
void FillMCPairHistos(MCParticle *ele, MCParticle *pos, std::string label, double weight)
void FillMCTrackerHits(std::vector< MCTrackerHit * > *mcTrkrHits, float weight=1.)
description
void FillMCEcalHits(std::vector< MCEcalHit * > *mcEcalHits, float weight=1.)
description
virtual void Define2DHistos()
description
double getEnergy() const
Definition MCEcalHit.h:62
std::vector< double > getMomentum() const
std::vector< double > getVertexPosition() const
double getEnergy() const
Definition MCParticle.h:162
int getMomPDG() const
Definition MCParticle.h:153
int getPDG() const
Definition MCParticle.h:147
double getMass() const
Definition MCParticle.h:165
double getEdep() const
int getPDG() const