ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.20
Committed: Tue Apr 7 15:56:02 2009 UTC (16 years ago) by phedex
Content type: text/plain
Branch: MAIN
Changes since 1.19: +30 -2 lines
Log Message:
add IsNeutral accessor

File Contents

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