EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventMC.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EventMC.cxx
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 
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 
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  // Note that the method is a bit of a misnomer - it will return ALL final
64  // particles other than the scattered lepton
65  // (intentionally, since you want to take decay products into account as well)
66  FinalState(final_);
67  std::list<const VirtualParticle*> plist(final_.begin(),
68  final_.end());
69  plist.remove(ScatteredLepton());
70  final_ = TrackVector(plist.begin(), plist.end());
71 }
72 
73 // Get the particles that belong to the hadronic final state.
74 // The stored Particle* are pointers to the original particles in the event
75 // so don't delete them!
76 void EventMC::FinalState(TrackVector& final_) const {
77  final_.clear();
78  TIter next(&particles);
79  ParticleMC* p(NULL);
80  while ((p = static_cast<ParticleMC*>(next()))) {
81  if (1 == p->GetStatus()) {
82  final_.push_back(p);
83  } // if
84  } // while
85 }
86 
87 TLorentzVector EventMC::FinalStateMomentum() const {
88  TrackVector final_;
89  FinalState(final_);
90  TLorentzVector mom;
91  for (TrackVectorCIter i = final_.begin(); i != final_.end(); ++i) {
92  mom += (*i)->Get4Vector();
93  } // for
94 
95  return mom;
96 }
97 
98 TLorentzVector EventMC::HadronicFinalStateMomentum() const {
99  TrackVector final_;
100  HadronicFinalState(final_);
101  TLorentzVector mom;
102  for (TrackVectorCIter i = final_.begin(); i != final_.end(); ++i) {
103  mom += (*i)->Get4Vector();
104  } // for
105 
106  return mom;
107 }
108 
109 Double_t EventMC::FinalStateCharge() const {
110  TrackVector final_;
111  FinalState(final_);
112  Double_t charge(0);
113  TDatabasePDG* pdg = TDatabasePDG::Instance();
114  for (TrackVectorCIter i = final_.begin(); i != final_.end(); ++i) {
115  TParticlePDG* part = pdg->GetParticle((*i)->Id());
116  if (part) {
117  charge += part->Charge() / 3.;
118  } else {
119  std::cout << "Unknown particle: " << (*i)->Id() << std::endl;
120  } // if
121  } // for
122  return charge;
123 }
124 
125  // See header!
127  return GetTrack(0);
128 }
129 
130  // See header!
132  return GetTrack(1);
133 }
134 
135  // See header!
137  return GetTrack(2);
138 }
139 
140  // See header!
142  return GetTrack(3);
143 }
144 
145 
147  number = -1;
148  process = -1;
149  nTracks = -1;
150  x = QSquared = y = WSquared = nu = ELeptonInNucl = ELeptonOutNucl = NAN;
151 }
152 
153 void EventMC::Clear(Option_t* /*option*/) {
154  Reset();
155  particles.Clear();
156 }
157 
159  new(particles[particles.GetEntries()]) ParticleMC(*track);
160  nTracks = particles.GetEntries();
161 }
162 
163 void EventMC::Print( const Option_t *option) const {
164  EventDis::Print();
165  std::cout << "I \t KS \t id \t orig\t daughter \t ldaughter \t "
166  << " px \t py \t pz \t E \t m \t xv \t yv \t zv"
167  << std::endl;
168 
169  for( unsigned int t=0; t<GetNTracks(); ++t) {
170  const Particle* inParticle = GetTrack(t);
171  inParticle->Print();
172  }
173 }
174 
175  //
176 // class Reader
177 //
178 
179 Reader::Reader(const std::string& treeName)
180 : mEvent(NULL)
181 , mTree(NULL) {
182  if (gDirectory) gDirectory->GetObject(treeName.c_str(), mTree);
183  if (mTree) mTree->SetBranchAddress("event", &mEvent);
184 }
185 
186 EventMC* Reader::Read(Long64_t i) {
187  EventMC* event(NULL);
188  if (mTree) {
189  mTree->GetEntry(i);
190  event = mEvent;
191  } // if
192  return event;
193 }
194 
195 } // namespace erhic