ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.23
Committed: Fri Sep 25 08:38:18 2009 UTC (15 years, 7 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013, Mit_013pre1, Mit_012i, Mit_012h, Mit_012g, Mit_012f, Mit_012e, Mit_012d, Mit_012c, Mit_012b, Mit_012a, Mit_012, Mit_011a
Branch point for: Mit_025c_branch
Changes since 1.22: +14 -14 lines
Log Message:
Cosmetics

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: MCParticle.h,v 1.22 2009/06/02 11:12:10 bendavid Exp $
3 //
4 // MCParticle
5 //
6 // Stores MC information for both generated and simulated particles.
7 //
8 // Authors: C.Loizides, J.Bendavid
9 //--------------------------------------------------------------------------------------------------
10
11 #ifndef MITANA_DATATREE_MCPARTICLE_H
12 #define MITANA_DATATREE_MCPARTICLE_H
13
14 #include <TDatabasePDG.h>
15 #include <TParticlePDG.h>
16 #include "MitCommon/DataFormats/interface/Vect3.h"
17 #include "MitCommon/DataFormats/interface/Vect4M.h"
18 #include "MitAna/DataCont/interface/Ref.h"
19 #include "MitAna/DataTree/interface/CompositeParticle.h"
20
21 namespace mithep
22 {
23 class MCParticle : public CompositeParticle
24 {
25 public:
26 enum EPartType {
27 kUnknown=0,
28 kUp=1, kDown=2, kStrange=3, kCharm=4, kBottom=5, kTop=6,
29 kEl=11, kMu=13, kTau=15,
30 kElNu=12, kMuNu=14, kTauNu=16,
31 kGlu=21, kGamma=22, kZ=23, kW=24, kH=25,
32 kZp=32, kZpp=33, kWp=34, kH0=35, kA0=36, kHp=37,
33 kPi0=111, kEta=221, kKLong=130, kKShort=310, kK0=311,
34 kD0=413, kB0=511, kB0Bar=513, kJPsi=443, kUpsilon=553,
35 kProton=2122, kNeutron=2122, kDeltaPlusPlus = 2224,
36 kDeltaPlus = 2214, kDelta0 = 2114, kDeltaMinus=1114
37 };
38
39 MCParticle() : fPdgId(0), fStatus(0), fIsGenerated(kFALSE), fIsSimulated(kFALSE) {}
40 MCParticle(Double_t px, Double_t py, Double_t pz, Double_t e, Int_t id, Int_t s) :
41 fPdgId(id), fStatus(s), fMom(FourVector(px,py,pz,e)),
42 fIsGenerated(kFALSE), fIsSimulated(kFALSE) {}
43
44 Int_t AbsPdgId() const { return (fPdgId<0 ? -fPdgId:fPdgId); }
45 void AddDaughter(const MCParticle *p) { fDaughters.Add(p); }
46 const ThreeVector DecayVertex() const { return fDecayVertex.V(); }
47 const MCParticle *Daughter(UInt_t i) const;
48 const MCParticle *DistinctMother() const;
49 using CompositeParticle::HasDaughter;
50 const MCParticle *FindDaughter(Int_t pid,
51 Bool_t checkCharge=kFALSE, const MCParticle *start=0) const;
52 const MCParticle *FindMother(Int_t pid, Bool_t checkCharge=kFALSE) const;
53 Bool_t HasDaughter(Int_t pid, Bool_t checkCharge=kFALSE) const;
54 Bool_t HasMother() const { return fMother.IsValid(); }
55 Bool_t HasMother(const MCParticle *m) const;
56 Bool_t HasMother(Int_t pid, Bool_t checkCharge=kFALSE) const;
57 Bool_t Is(Int_t pid, Bool_t checkCharge=kFALSE) const;
58 Bool_t IsCharged() const { return !IsNeutral(); }
59 Bool_t IsGenerated() const { return fIsGenerated; }
60 Bool_t IsGluon() const { return fPdgId == kGlu; }
61 Bool_t IsLepton() const;
62 Bool_t IsNeutral() const;
63 Bool_t IsNeutrino() const;
64 Bool_t IsNot(Int_t pid, Bool_t checkCharge=kFALSE) const;
65 Bool_t IsParton() const { return (IsGluon() || IsQuark()); }
66 Bool_t IsQuark() const { return (AbsPdgId()>0 && AbsPdgId()<7); }
67 Bool_t IsSimulated() const { return fIsSimulated; }
68 const MCParticle *Mother() const { return fMother.Obj(); }
69 EObjType ObjType() const { return kMCParticle; }
70 void SetIsGenerated(Bool_t t=kTRUE) { fIsGenerated = t; }
71 void SetIsSimulated(Bool_t t=kTRUE) { fIsSimulated = t; }
72 TParticlePDG *PdgEntry() const;
73 Int_t PdgId() const { return fPdgId; }
74 Double_t PdgMass() const;
75 void SetMom(Double_t px, Double_t py, Double_t pz, Double_t e);
76 void SetMother(const MCParticle *p) { fMother = p; }
77 void SetStatus(Int_t s) { fStatus = s; }
78 void SetVertex(Double_t x, Double_t y, Double_t z);
79 void SetPdgId(Int_t s) { fPdgId = s; }
80 Int_t Status() const { return fStatus; }
81 void Print(Option_t *opt="") const;
82
83 protected:
84 Double_t GetCharge() const;
85 void GetMom() const;
86
87 Int_t fPdgId; //pdg identifier
88 Short_t fStatus; //status flag of generator or simulation
89 Vect4M fMom; //four momentum vector
90 Vect3 fDecayVertex; //gen decay vertex
91 Ref<MCParticle> fMother; //reference to mother
92 Bool_t fIsGenerated; //=true if generated particle
93 Bool_t fIsSimulated; //=true if simulated particle
94
95 ClassDef(MCParticle,1) // Generated particle class
96 };
97 }
98
99 //--------------------------------------------------------------------------------------------------
100 inline const mithep::MCParticle *mithep::MCParticle::Daughter(UInt_t i) const
101 {
102 // Return daughter corresponding to given index.
103
104 return static_cast<const MCParticle*>(fDaughters.At(i));
105 }
106
107 //--------------------------------------------------------------------------------------------------
108 inline const mithep::MCParticle *mithep::MCParticle::DistinctMother() const
109 {
110 // Return mother, walking up the tree until a particle with a different pdg from this one
111 // is found.
112
113 const mithep::MCParticle *mother = Mother();
114
115 if (!mother)
116 return 0;
117
118 while (mother && mother->PdgId()==fPdgId)
119 mother = mother->Mother();
120
121 return mother;
122 }
123
124 //--------------------------------------------------------------------------------------------------
125 inline Double_t mithep::MCParticle::GetCharge() const
126 {
127 // Get charge from pdg lookup.
128
129 TParticlePDG *pdgEntry = PdgEntry();
130 if (pdgEntry)
131 return pdgEntry->Charge()/3.0;
132 else {
133 Error("Charge", "Pdg code for %i not found in table, returning charge=-99.0", fPdgId);
134 return -99.0;
135 }
136 }
137
138 //--------------------------------------------------------------------------------------------------
139 inline void mithep::MCParticle::GetMom() const
140 {
141 // Get momentum values from stored values.
142
143 fCachedMom.SetCoordinates(fMom.Pt(), fMom.Eta(), fMom.Phi(), fMom.M());
144 }
145
146 //--------------------------------------------------------------------------------------------------
147 inline Bool_t mithep::MCParticle::HasDaughter(Int_t pid, Bool_t checkCharge) const
148 {
149 // Return true if a particle with given pdg code is found amoung daughters.
150 // If checkCharge is false then just the type of particle is checked
151 // (ie particle and anti-particle).
152
153 if (checkCharge) {
154 for (UInt_t i=0; i<NDaughters(); ++i)
155 if (Daughter(i)->PdgId()==pid)
156 return kTRUE;
157 } else {
158 Int_t apid = pid>0?pid:-pid;
159 for (UInt_t i=0; i<NDaughters(); ++i)
160 if (Daughter(i)->AbsPdgId()==apid)
161 return kTRUE;
162 }
163 return kFALSE;
164 }
165
166 //--------------------------------------------------------------------------------------------------
167 inline Bool_t mithep::MCParticle::HasMother(const MCParticle *m) const
168 {
169 // Return true if the given particle is among mothers. (Note the comparison
170 // is made on pointers and therefore will fail if you work on copies.)
171
172 if (!m)
173 return kFALSE;
174
175 const mithep::MCParticle *mother = Mother();
176 while (mother && mother!=m)
177 mother = mother->Mother();
178
179 if (mother)
180 return kTRUE;
181 return kFALSE;
182 }
183
184 //--------------------------------------------------------------------------------------------------
185 inline Bool_t mithep::MCParticle::HasMother(Int_t pid, Bool_t checkCharge) const
186 {
187 // Return true if a particle with given pdg code is found amoung mothers.
188 // If checkCharge is false then just the type of particle is checked
189 // (ie particle and anti-particle).
190
191 const mithep::MCParticle *mother = Mother();
192
193 if (checkCharge) {
194 while (mother && mother->PdgId()!=pid)
195 mother = mother->Mother();
196 } else {
197 Int_t apid = pid>0?pid:-pid;
198 while (mother && mother->AbsPdgId()!=apid)
199 mother = mother->Mother();
200 }
201
202 if (mother)
203 return kTRUE;
204 return kFALSE;
205 }
206
207 //--------------------------------------------------------------------------------------------------
208 inline Bool_t mithep::MCParticle::Is(Int_t pid, Bool_t checkCharge) const
209 {
210 // Return true if particle is of given type. If checkCharge is false then just the type of
211 // particle is checked (ie particle and anti-particle).
212
213 if (checkCharge)
214 return (PdgId() == pid);
215
216 Int_t apid = pid>0?pid:-pid;
217 return (AbsPdgId() == apid);
218 }
219
220 //--------------------------------------------------------------------------------------------------
221 inline Bool_t mithep::MCParticle::IsNot(Int_t pid, Bool_t checkCharge) const
222 {
223 // Return true if particle is not of given type. If checkCharge is false then just the type of
224 // particle is checked (ie particle and anti-particle).
225
226 return !Is(pid, checkCharge);
227 }
228
229 //--------------------------------------------------------------------------------------------------
230 inline Bool_t mithep::MCParticle::IsLepton() const
231 {
232 // Return true if particle is a lepton.
233
234 Int_t ap = AbsPdgId();
235 if ((ap==kEl) ||
236 (ap==kMu) ||
237 (ap==kTau))
238 return kTRUE;
239
240 return kFALSE;
241 }
242
243 //--------------------------------------------------------------------------------------------------
244 inline Bool_t mithep::MCParticle::IsNeutral() const
245 {
246 // Return true if particle is a neutral.
247
248 return (Charge()!=0);
249 }
250
251 //--------------------------------------------------------------------------------------------------
252 inline Bool_t mithep::MCParticle::IsNeutrino() const
253 {
254 // Return true if particle is a neutrino.
255
256 Int_t ap = AbsPdgId();
257 if ((ap==kElNu) ||
258 (ap==kMuNu) ||
259 (ap==kTauNu))
260 return kTRUE;
261
262 return kFALSE;
263 }
264
265 //--------------------------------------------------------------------------------------------------
266 inline TParticlePDG *mithep::MCParticle::PdgEntry() const
267 {
268 // Return entry to pdg database.
269
270 return TDatabasePDG::Instance()->GetParticle(fPdgId);
271 }
272
273 //--------------------------------------------------------------------------------------------------
274 inline Double_t mithep::MCParticle::PdgMass() const
275 {
276 // Return mass obtained from pdg database.
277
278 TParticlePDG *pdg = PdgEntry();
279 if (pdg)
280 return pdg->Mass();
281 return 0;
282 }
283
284 //--------------------------------------------------------------------------------------------------
285 inline void mithep::MCParticle::SetMom(Double_t px, Double_t py, Double_t pz, Double_t e)
286 {
287 // Set four vector.
288
289 fMom.SetXYZT(px, py, pz, e);
290 ClearMom();
291 }
292
293 //--------------------------------------------------------------------------------------------------
294 inline void mithep::MCParticle::SetVertex(Double_t x, Double_t y, Double_t z)
295 {
296 // Set decay vertex.
297
298 fDecayVertex.SetXYZ(x,y,z);
299 }
300 #endif