Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SCorrelatorJetTree.evt.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SCorrelatorJetTree.evt.h
1 // ----------------------------------------------------------------------------
2 // 'SCorrelatorJetTree.evt.h'
3 // Derek Anderson
4 // 03.28.2023
5 //
6 // A module to produce a tree of jets for the sPHENIX
7 // Cold QCD Energy-Energy Correlator analysis.
8 //
9 // Derived from code by Antonio Silva (thanks!!)
10 // ----------------------------------------------------------------------------
11 
12 #pragma once
13 
14 using namespace std;
15 using namespace findNode;
16 
17 
18 
19 namespace SColdQcdCorrelatorAnalysis {
20 
21  // event methods ------------------------------------------------------------
22 
23  bool SCorrelatorJetTree::IsGoodVertex(const CLHEP::Hep3Vector vtx) {
24 
25  // print debug statement
26  if (m_doDebug) {
27  cout << "SCorrelatorJetTree::IsGoodVertex(CLHEP::Hep3Vector) Checking if event is good..." << endl;
28  }
29 
30  // calculate vr
31  const double vr = sqrt((vtx.x() * vtx.x()) + (vtx.y() * vtx.y()));
32 
33  // check if event is good
34  const bool isInEvtVzRange = ((vtx.z() > m_evtVzRange[0]) && (vtx.z() < m_evtVzRange[1]));
35  const bool isInEvtVrRange = ((abs(vr) > m_evtVrRange[0]) && (abs(vr) < m_evtVrRange[1]));
36  const bool isGoodVertex = (isInEvtVzRange && isInEvtVrRange);
37  return isGoodVertex;
38 
39  } // end 'IsGoodVertex(CLHEP::Hep3Vector)'
40 
41 
42 
43  void SCorrelatorJetTree::GetEventVariables(PHCompositeNode* topNode) {
44 
45  // print debug statement
46  if (m_doDebug) {
47  cout << "SCorrelatorJetTree::GetEventVariables(PHCompositeNode*) Grabbing event info..." << endl;
48  }
49 
50  m_recoVtx = GetRecoVtx(topNode);
51  m_recoNumTrks = GetNumTrks(topNode);
52  m_recoSumECal = GetSumECalEne(topNode);
53  m_recoSumHCal = GetSumHCalEne(topNode);
54  if (m_isMC) {
55  m_trueNumChrgPars = GetNumChrgPars(topNode);
56  m_trueSumPar = GetSumParEne(topNode);
57  }
58  return;
59 
60  } // end 'GetEventVariables(PHCompositeNode*)'
61 
62 
63 
65 
66  // print debug statement
67  if (m_doDebug) {
68  cout << "SCorrelatorJetTree::GetPartonInfo(PHCompositeNode*) Grabbing parton info..." << endl;
69  }
70 
71  // pick out relevant sub-sevent to grab
72  int iPartonEvt = 1;
73  if (m_isEmbed) {
74  iPartonEvt = 2;
75  }
76 
77  // loop over particles
78  unsigned int iOutPart = 0;
79  HepMC::GenEvent* mcEvt = GetMcEvent(topNode, iPartonEvt);
80  for (HepMC::GenEvent::particle_const_iterator itPar = mcEvt -> particles_begin(); itPar != mcEvt -> particles_end(); ++itPar) {
81 
82  // check if outputing parton
83  const bool isOutParton = IsOutgoingParton(*itPar);
84  const bool foundBothPartons = (iOutPart == 2);
85  if (!isOutParton || foundBothPartons) continue;
86 
87  // grab parton info
88  const double parPx = (*itPar) -> momentum().px();
89  const double parPy = (*itPar) -> momentum().py();
90  const double parPz = (*itPar) -> momentum().pz();
91  const double parVx = (*itPar) -> production_vertex() -> position().x();
92  const double parVy = (*itPar) -> production_vertex() -> position().y();
93  const double parVz = (*itPar) -> production_vertex() -> position().z();
94 
95  // record ids, momentum, and vtx
96  m_partonID[iOutPart] = (*itPar) -> pdg_id();
97  m_partonMom[iOutPart] = CLHEP::Hep3Vector(parPx, parPy, parPz);
98  m_trueVtx = CLHEP::Hep3Vector(parVx, parVy, parVz);
99  ++iOutPart;
100  } // end particle loop
101  return;
102 
103  } // end 'GetPartonInfo(PHCompositeNode*)'
104 
105 
106 
108 
109  // print debug statement
110  if (m_doDebug) {
111  cout << "SCorrelatorJetTree::GetNumTrks(PHCompositeNode*) Calculating no. of tracks..." << endl;
112  }
113 
114  // loop over tracks
115  long nTrk = 0;
116  SvtxTrack* track = NULL;
117  SvtxTrackMap* mapTrks = GetTrackMap(topNode);
118  for (SvtxTrackMap::Iter itTrk = mapTrks -> begin(); itTrk != mapTrks -> end(); ++itTrk) {
119 
120  // get track
121  track = itTrk -> second;
122  if (!track) continue;
123 
124  // if good, add to count
125  const bool isGoodTrack = IsGoodTrack(track, topNode);
126  if (isGoodTrack) ++nTrk;
127 
128  } // end track loop
129  return nTrk;
130 
131  } // end 'GetNumTrks(PHCompositeNode*)'
132 
133 
134 
135  long SCorrelatorJetTree::GetNumChrgPars(PHCompositeNode* topNode) {
136 
137  // print debug statement
138  if (m_doDebug) {
139  cout << "SCorrelatorJetTree::GetNumChrgPars(PHCompositeNode*) Calculating no. of charged particles..." << endl;
140  }
141 
142  // loop over subevents
143  long nPar = 0;
144  for (const int evtToGrab : m_vecEvtsToGrab) {
145 
146  // loop over particles
147  HepMC::GenEvent* mcEvt = GetMcEvent(topNode, evtToGrab);
148  for (HepMC::GenEvent::particle_const_iterator itPar = mcEvt -> particles_begin(); itPar != mcEvt -> particles_end(); ++itPar) {
149 
150  // check if particle is final state
151  const bool isFinalState = ((*itPar) -> status() == 1);
152  if (!isFinalState) continue;
153 
154  // if good, add to count
155  const bool isGoodPar = IsGoodParticle(*itPar);
156  if (isGoodPar) ++nPar;
157 
158  } // end particle loop
159  } // end subevent loop
160  return nPar;
161 
162  } // end 'GetNumChrgPars(PHCompositeNode*)'
163 
164 
165 
166  double SCorrelatorJetTree::GetSumECalEne(PHCompositeNode* topNode) {
167 
168  // print debug statement
169  if (m_doDebug) {
170  cout << "SCorrelatorJetTree::GetSumECalEne(PHCompositeNode*) Getting sum of ECal energy..." << endl;
171  }
172 
173  // grab vertex and clusters
174  GlobalVertex* vtx = GetGlobalVertex(topNode);
175  RawClusterContainer* emClustStore = GetClusterStore(topNode, "CLUSTER_CEMC");
176 
177  // loop over emcal clusters
178  double eneECalSum = 0.;
179  RawClusterContainer::ConstRange emClustRange = emClustStore -> getClusters();
181  for (itEMClust = emClustRange.first; itEMClust != emClustRange.second; itEMClust++) {
182 
183  // grab cluster
184  const RawCluster* emClust = itEMClust -> second;
185  if (!emClust) continue;
186 
187  // construct vertex and get 4-momentum
188  const double vX = vtx -> get_x();
189  const double vY = vtx -> get_y();
190  const double vZ = vtx -> get_z();
191 
192  CLHEP::Hep3Vector hepVecVtx = CLHEP::Hep3Vector(vX, vY, vZ);
193  CLHEP::Hep3Vector hepVecEMClust = RawClusterUtility::GetECoreVec(*emClust, hepVecVtx);
194 
195  // if good, add to sum
196  const bool isGoodECal = IsGoodECal(hepVecEMClust);
197  if (isGoodECal) eneECalSum += hepVecEMClust.mag();
198 
199  } // end emcal loop
200  return eneECalSum;
201 
202  } // end 'GetSumECalEne(PHCompositeNode*)'
203 
204 
205 
206  double SCorrelatorJetTree::GetSumHCalEne(PHCompositeNode* topNode) {
207 
208  // print debug statement
209  if (m_doDebug) {
210  cout << "SCorrelatorJetTree::GetSumHCalEne(PHCompositeNode*) Getting sum of HCal energy..." << endl;
211  }
212 
213  // grab vertex and clusters
214  GlobalVertex* vtx = GetGlobalVertex(topNode);
215  RawClusterContainer* ihClustStore = GetClusterStore(topNode, "CLUSTER_HCALIN");
216  RawClusterContainer* ohClustStore = GetClusterStore(topNode, "CLUSTER_HCALOUT");
217 
218  // loop over ihcal clusters
219  double eneIHCalSum = 0.;
220  RawClusterContainer::ConstRange ihClustRange = ihClustStore -> getClusters();
222  for (itIHClust = ihClustRange.first; itIHClust != ihClustRange.second; itIHClust++) {
223 
224  // grab cluster
225  const RawCluster* ihClust = itIHClust -> second;
226  if (!ihClust) continue;
227 
228  // construct vertex and get 4-momentum
229  const double vX = vtx -> get_x();
230  const double vY = vtx -> get_y();
231  const double vZ = vtx -> get_z();
232 
233  CLHEP::Hep3Vector hepVecVtx = CLHEP::Hep3Vector(vX, vY, vZ);
234  CLHEP::Hep3Vector hepVecIHClust = RawClusterUtility::GetECoreVec(*ihClust, hepVecVtx);
235 
236  // if good, add to sum
237  const bool isGoodHCal = IsGoodECal(hepVecIHClust);
238  if (isGoodHCal) eneIHCalSum += hepVecIHClust.mag();
239  } // end ihcal loop
240 
241  // loop over ohcal clusters
242  double eneOHCalSum = 0.;
243  RawClusterContainer::ConstRange ohClustRange = ohClustStore -> getClusters();
245  for (itOHClust = ohClustRange.first; itOHClust != ohClustRange.second; itOHClust++) {
246 
247  // grab cluster
248  const RawCluster* ohClust = itOHClust -> second;
249  if (!ohClust) continue;
250 
251  // construct vertex and get 4-momentum
252  const double vX = vtx -> get_x();
253  const double vY = vtx -> get_y();
254  const double vZ = vtx -> get_z();
255 
256  CLHEP::Hep3Vector hepVecVtx = CLHEP::Hep3Vector(vX, vY, vZ);
257  CLHEP::Hep3Vector hepVecOHClust = RawClusterUtility::GetECoreVec(*ohClust, hepVecVtx);
258 
259  // if good, add to sum
260  const bool isGoodHCal = IsGoodECal(hepVecOHClust);
261  if (isGoodHCal) eneOHCalSum += hepVecOHClust.mag();
262  } // end ohcal loop
263 
264  const double eneHCalSum = eneIHCalSum + eneOHCalSum;
265  return eneHCalSum;
266 
267  } // end 'GetSumHCalEne(PHCompositeNode*)'
268 
269 
270 
271  double SCorrelatorJetTree::GetSumParEne(PHCompositeNode* topNode) {
272 
273  // print debug statement
274  if (m_doDebug) {
275  cout << "SCorrelatorJetTree::GetSumParEne(PHComposite*) Calculating sum of particle energy..." << endl;
276  }
277 
278  // loop over subevents
279  double eSumPar = 0.;
280  for (const int evtToGrab : m_vecEvtsToGrab) {
281 
282  HepMC::GenEvent* mcEvt = GetMcEvent(topNode, evtToGrab);
283  for (HepMC::GenEvent::particle_const_iterator itPar = mcEvt -> particles_begin(); itPar != mcEvt -> particles_end(); ++itPar) {
284 
285  // check if particle is final state
286  const bool isFinalState = ((*itPar) -> status() == 1);
287  if (!isFinalState) continue;
288 
289  // if good, add to count
290  const bool isGoodPar = IsGoodParticle(*itPar, true);
291  if (isGoodPar) eSumPar += (*itPar) -> momentum().e();
292 
293  } // end particle loop
294  } // end subevent loop
295  return eSumPar;
296 
297  } // end 'GetSumParEne(PHCompositeNode*)'
298 
299 
300 
301  CLHEP::Hep3Vector SCorrelatorJetTree::GetRecoVtx(PHCompositeNode* topNode) {
302 
303  // print debug statement
304  if (m_doDebug) {
305  cout << "SCorrelatorJetTree::GetRecoVtx(PHComposite*) Getting reconstructed vertex..." << endl;
306  }
307 
308  const GlobalVertex* vtx = GetGlobalVertex(topNode);
309  const double vtxX = vtx -> get_x();
310  const double vtxY = vtx -> get_y();
311  const double vtxZ = vtx -> get_z();
312  const CLHEP::Hep3Vector recoVtx = CLHEP::Hep3Vector(vtxX, vtxY, vtxZ);
313  return recoVtx;
314 
315  } // end 'GetRecoVtx(PHCompositeNode*)'
316 
317 } // end SColdQcdCorrelatorAnalysis namespace
318 
319 // end ------------------------------------------------------------------------