eic-smear  1.0.3
A collection of ROOT classes for Monte Carlo events and a fast-smearing code simulating detector effects for the Electron-Ion Collider task force
EventMC.cxx
Go to the documentation of this file.
1 
10 #include "eicsmear/erhic/EventMC.h"
11 
12 #include <iostream>
13 #include <list>
14 #include <string>
15 #include <vector>
16 
17 #include <TCollection.h>
18 #include <TDatabasePDG.h>
19 #include <TDirectory.h>
20 #include <TParticlePDG.h>
21 #include <TTree.h>
22 
25 
26 namespace erhic {
27 
28 // We use these vectors/iterators a lot, so define
29 // some typedefs for convenience.
30 typedef std::vector<const VirtualParticle*> TrackVector;
31 typedef TrackVector::iterator TrackVectorIter;
32 typedef TrackVector::const_iterator TrackVectorCIter;
33 
35 : number(-1)
36 , process(-1)
37 , nTracks(-1)
38 , ELeptonInNucl(NAN)
39 , ELeptonOutNucl(NAN)
40 , particles("erhic::ParticleMC", 100) {
41 }
42 
44  // No memory to clear. The TClonesArray takes care of the
45  // particles when it is destroyed.
46 }
47 
48 TrackVector EventMC::GetTracks() const {
49  TrackVector tracks;
50  TObject* object(NULL);
51  TIter next(&particles);
52  while ((object = next())) {
53  tracks.push_back(static_cast<ParticleMC*>(object));
54  } // while
55  return tracks;
56 }
57 
58 void EventMC::HadronicFinalState(TrackVector& final_) const {
59  // This is simple but not very efficient.
60  // Copy vector to a list and use list::remove to get rid
61  // of the scattered lepton. Then copy this list back to
62  // the vector.
63  FinalState(final_);
64  std::list<const VirtualParticle*> plist(final_.begin(),
65  final_.end());
66  plist.remove(ScatteredLepton());
67  final_ = TrackVector(plist.begin(), plist.end());
68 }
69 
70 // Get the particles that belong to the hadronic final state.
71 // The stored Particle* are pointers to the original particles in the event
72 // so don't delete them!
73 void EventMC::FinalState(TrackVector& final_) const {
74  final_.clear();
75  TIter next(&particles);
76  ParticleMC* p(NULL);
77  while ((p = static_cast<ParticleMC*>(next()))) {
78  if (1 == p->GetStatus()) {
79  final_.push_back(p);
80  } // if
81  } // while
82 }
83 
84 TLorentzVector EventMC::FinalStateMomentum() const {
85  TrackVector final_;
86  FinalState(final_);
87  TLorentzVector mom;
88  for (TrackVectorCIter i = final_.begin(); i != final_.end(); ++i) {
89  mom += (*i)->Get4Vector();
90  } // for
91 
92  return mom;
93 }
94 
95 TLorentzVector EventMC::HadronicFinalStateMomentum() const {
96  TrackVector final_;
97  HadronicFinalState(final_);
98  TLorentzVector mom;
99  for (TrackVectorCIter i = final_.begin(); i != final_.end(); ++i) {
100  mom += (*i)->Get4Vector();
101  } // for
102 
103  return mom;
104 }
105 
106 Double_t EventMC::FinalStateCharge() const {
107  TrackVector final_;
108  FinalState(final_);
109  Double_t charge(0);
110  TDatabasePDG* pdg = TDatabasePDG::Instance();
111  for (TrackVectorCIter i = final_.begin(); i != final_.end(); ++i) {
112  TParticlePDG* part = pdg->GetParticle((*i)->Id());
113  if (part) {
114  charge += part->Charge() / 3.;
115  } else {
116  std::cout << "Unknown particle: " << (*i)->Id() << std::endl;
117  } // if
118  } // for
119  return charge;
120 }
121 
123  return GetTrack(0);
124 }
125 
127  return GetTrack(1);
128 }
129 
131  return GetTrack(3);
132 }
133 
135  return GetTrack(2);
136 }
137 
139  number = -1;
140  process = -1;
141  nTracks = -1;
142  x = QSquared = y = WSquared = nu = ELeptonInNucl = ELeptonOutNucl = NAN;
143 }
144 
145 void EventMC::Clear(Option_t* /*option*/) {
146  Reset();
147  particles.Clear();
148 }
149 
151  new(particles[particles.GetEntries()]) ParticleMC(*track);
152  nTracks = particles.GetEntries();
153 }
154 
155 //
156 // class Reader
157 //
158 
159 Reader::Reader(const std::string& treeName)
160 : mEvent(NULL)
161 , mTree(NULL) {
162  if (gDirectory) gDirectory->GetObject(treeName.c_str(), mTree);
163  if (mTree) mTree->SetBranchAddress("event", &mEvent);
164 }
165 
166 EventMC* Reader::Read(Long64_t i) {
167  EventMC* event(NULL);
168  if (mTree) {
169  mTree->GetEntry(i);
170  event = mEvent;
171  } // if
172  return event;
173 }
174 
175 } // namespace erhic
virtual const ParticleMC * ScatteredLepton() const
Definition: EventMC.cxx:134
virtual void Clear(Option_t *="")
Definition: EventMC.cxx:145
Double32_t QSquared
Q2 calculated from scattered electron.
Definition: EventDis.h:182
Double32_t nu
Energy transfer from the electron.
Definition: EventDis.h:185
Double_t FinalStateCharge() const
Definition: EventMC.cxx:106
Double32_t y
Inelasticity.
Definition: EventDis.h:183
Int_t nTracks
Number of Particles in the event (intermediate + final)
Definition: EventMC.h:203
virtual void Reset()
Definition: EventMC.cxx:138
virtual UShort_t GetStatus() const
Definition: ParticleMC.h:416
Int_t number
Event number.
Definition: EventMC.h:201
TClonesArray particles
Particle list.
Definition: EventMC.h:208
EventMC * mEvent
The last event read.
Definition: EventMC.h:295
Int_t process
PYTHIA code for the physics process producing the event.
Definition: EventMC.h:202
void HadronicFinalState(ParticlePtrList &) const
Definition: EventMC.cxx:58
Reader(const std::string &treeName="EICTree")
Definition: EventMC.cxx:159
Double32_t WSquared
Invariant mass of the hadronic system.
Definition: EventDis.h:184
virtual void AddLast(ParticleMC *track)
Definition: EventMC.cxx:150
virtual const ParticleMC * ExchangeBoson() const
Definition: EventMC.cxx:130
virtual const ParticleMC * GetTrack(UInt_t) const
Definition: EventMC.h:225
EventMC * Read(Long64_t number)
Definition: EventMC.cxx:166
TTree * mTree
The tree being read.
Definition: EventMC.h:296
virtual const ParticleMC * BeamLepton() const
Definition: EventMC.cxx:122
TLorentzVector HadronicFinalStateMomentum() const
Definition: EventMC.cxx:95
virtual const ParticleMC * BeamHadron() const
Definition: EventMC.cxx:126
TLorentzVector FinalStateMomentum() const
Definition: EventMC.cxx:84
void FinalState(ParticlePtrList &particles) const
Definition: EventMC.cxx:73
Double32_t x
Bjorken scaling variable.
Definition: EventDis.h:181
Double32_t ELeptonOutNucl
Definition: EventMC.h:206
virtual ~EventMC()
Definition: EventMC.cxx:43
std::vector< const VirtualParticle * > GetTracks() const
Definition: EventMC.cxx:48
Double32_t ELeptonInNucl
Definition: EventMC.h:204