ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.19
Committed: Mon Apr 6 13:38:47 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.18: +17 -2 lines
Log Message:
Add few more accessors

File Contents

# User Rev Content
1 bendavid 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.19 // $Id: MCParticle.h,v 1.18 2009/03/11 10:08:09 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 loizides 1.7 Bool_t IsNeutrino() const;
50 loizides 1.16 Bool_t IsParton() const { return (IsGluon() || IsQuark()); }
51 loizides 1.7 Bool_t IsQuark() const { return (AbsPdgId()>0 && AbsPdgId()<7); }
52 loizides 1.16 Bool_t IsSimulated() const { return fIsSimulated; }
53 bendavid 1.13 const MCParticle *Mother() const { return fMother.Obj(); }
54 loizides 1.16 EObjType ObjType() const { return kMCParticle; }
55     void SetIsGenerated(Bool_t t=kTRUE) { fIsGenerated = t; }
56     void SetIsSimulated(Bool_t t=kTRUE) { fIsSimulated = t; }
57 loizides 1.3 TParticlePDG *PdgEntry() const;
58 loizides 1.16 Int_t PdgId() const { return fPdgId; }
59 loizides 1.18 Double_t PdgMass() const;
60 bendavid 1.1 void SetMom(Double_t px, Double_t py, Double_t pz, Double_t e);
61 loizides 1.16 void SetMother(const MCParticle *p) { fMother = p; }
62     void SetStatus(Int_t s) { fStatus = s; }
63 bendavid 1.2 void SetVertex(Double_t x, Double_t y, Double_t z);
64 loizides 1.16 void SetPdgId(Int_t s) { fPdgId = s; }
65 loizides 1.3 Int_t Status() const { return fStatus; }
66     void Print(Option_t *opt="") const;
67 bendavid 1.1
68     enum EPartType {
69 loizides 1.7 kUnknown=0,
70     kUp=1, kDown=2, kStrange=3, kCharm=4, kBottom=5, kTop=6,
71     kEl=11, kMu=13, kTau=15,
72 bendavid 1.1 kElNu=12, kMuNu=14, kTauNu=16,
73 loizides 1.8 kGlu=21, kGamma=22, kZ=23, kW=24, kH=25,
74     kZp=32, kZpp=33, kWp=34, kH0=35, kA0=36, kHp=37,
75     kPi0=111, kEta=221
76 bendavid 1.1 };
77    
78     protected:
79 loizides 1.14 Double_t GetCharge() const;
80     void GetMom() const;
81    
82 bendavid 1.1 Int_t fPdgId; //pdg identifier
83 loizides 1.16 Short_t fStatus; //status flag of generator or simulation
84     Vect4M fMom; //four momentum vector
85     Vect3 fDecayVertex; //gen decay vertex
86 bendavid 1.13 Ref<MCParticle> fMother; //reference to mother
87 loizides 1.3 Bool_t fIsGenerated; //=true if generated particle
88     Bool_t fIsSimulated; //=true if simulated particle
89 bendavid 1.1
90 loizides 1.14 ClassDef(MCParticle,1) // Generated particle class
91 bendavid 1.1 };
92     }
93    
94     //--------------------------------------------------------------------------------------------------
95 loizides 1.8 inline const mithep::MCParticle *mithep::MCParticle::Daughter(UInt_t i) const
96     {
97     // Return daughter corresponding to given index.
98    
99     return static_cast<const MCParticle*>(fDaughters.At(i));
100     }
101    
102     //--------------------------------------------------------------------------------------------------
103     inline const mithep::MCParticle *mithep::MCParticle::DistinctMother() const
104     {
105     // Return mother, walking up the tree until a particle with a different pdg from this one
106     // is found.
107    
108     const mithep::MCParticle *mother = Mother();
109    
110     if (!mother)
111     return 0;
112    
113     while (mother->PdgId()==fPdgId)
114     mother = mother->Mother();
115    
116     return mother;
117     }
118    
119     //--------------------------------------------------------------------------------------------------
120 loizides 1.14 inline Double_t mithep::MCParticle::GetCharge() const
121     {
122     // Get charge from pdg lookup.
123    
124     TParticlePDG *pdgEntry = PdgEntry();
125     if (pdgEntry)
126     return pdgEntry->Charge()/3.0;
127     else {
128     Error("Charge", "Pdg code for %i not found in table, returning charge=-99.0", fPdgId);
129     return -99.0;
130     }
131     }
132    
133     //--------------------------------------------------------------------------------------------------
134     inline void mithep::MCParticle::GetMom() const
135     {
136     // Get momentum values from stored values.
137    
138 loizides 1.16 fCachedMom.SetCoordinates(fMom.Pt(), fMom.Eta(), fMom.Phi(), fMom.M());
139 loizides 1.14 }
140    
141     //--------------------------------------------------------------------------------------------------
142 loizides 1.7 inline Bool_t mithep::MCParticle::HasDaughter(Int_t pid, Bool_t checkCharge) const
143     {
144     // Return true if a particle with given pdg code is found amoung daughters.
145     // If checkCharge is false then just the type of particle is checked
146     // (ie particle and anti-particle).
147    
148     if (checkCharge) {
149     for (UInt_t i=0; i<NDaughters(); ++i)
150     if (Daughter(i)->PdgId()==pid)
151     return kTRUE;
152     } else {
153     Int_t apid = pid>0?pid:-pid;
154     for (UInt_t i=0; i<NDaughters(); ++i)
155     if (Daughter(i)->AbsPdgId()==apid)
156     return kTRUE;
157     }
158     return kFALSE;
159     }
160    
161     //--------------------------------------------------------------------------------------------------
162 loizides 1.9 inline Bool_t mithep::MCParticle::HasMother(const MCParticle *m) const
163     {
164     // Return true if the given particle is among mothers. (Note the comparison
165     // is made on pointers and therefore will fail if you work on copies.)
166    
167     if (!m)
168     return kFALSE;
169    
170     const mithep::MCParticle *mother = Mother();
171     while (mother && mother!=m)
172     mother = mother->Mother();
173    
174     if (mother)
175     return kTRUE;
176     return kFALSE;
177     }
178    
179     //--------------------------------------------------------------------------------------------------
180 loizides 1.8 inline Bool_t mithep::MCParticle::HasMother(Int_t pid, Bool_t checkCharge) const
181     {
182     // Return true if a particle with given pdg code is found amoung mothers.
183     // If checkCharge is false then just the type of particle is checked
184     // (ie particle and anti-particle).
185 bendavid 1.4
186     const mithep::MCParticle *mother = Mother();
187    
188 loizides 1.8 if (checkCharge) {
189 loizides 1.9 while (mother && mother->PdgId()!=pid)
190 loizides 1.8 mother = mother->Mother();
191     } else {
192     Int_t apid = pid>0?pid:-pid;
193 loizides 1.9 while (mother && mother->AbsPdgId()!=apid)
194 loizides 1.8 mother = mother->Mother();
195     }
196 bendavid 1.4
197 loizides 1.8 if (mother)
198     return kTRUE;
199     return kFALSE;
200 bendavid 1.1 }
201    
202     //--------------------------------------------------------------------------------------------------
203 loizides 1.7 inline Bool_t mithep::MCParticle::Is(Int_t pid, Bool_t checkCharge) const
204     {
205     // Return true if particle is of given type. If checkCharge is false then just the type of
206     // particle is checked (ie particle and anti-particle).
207    
208     if (checkCharge)
209     return (PdgId() == pid);
210    
211     Int_t apid = pid>0?pid:-pid;
212     return (AbsPdgId() == apid);
213     }
214    
215     //--------------------------------------------------------------------------------------------------
216 loizides 1.11 inline Bool_t mithep::MCParticle::IsNot(Int_t pid, Bool_t checkCharge) const
217     {
218     // Return true if particle is not of given type. If checkCharge is false then just the type of
219     // particle is checked (ie particle and anti-particle).
220    
221     return !Is(pid, checkCharge);
222     }
223    
224     //--------------------------------------------------------------------------------------------------
225 loizides 1.19 inline Bool_t mithep::MCParticle::IsLepton() const
226     {
227     // Return true if particle is a lepton.
228    
229     Int_t ap = AbsPdgId();
230     if ((ap==kEl) ||
231     (ap==kMu) ||
232     (ap==kTau))
233     return kTRUE;
234    
235     return kFALSE;
236     }
237    
238     //--------------------------------------------------------------------------------------------------
239 bendavid 1.1 inline Bool_t mithep::MCParticle::IsNeutrino() const
240     {
241 loizides 1.19 // Return true if particle is a neutrino.
242 bendavid 1.1
243     Int_t ap = AbsPdgId();
244     if ((ap==kElNu) ||
245     (ap==kMuNu) ||
246     (ap==kTauNu))
247     return kTRUE;
248    
249     return kFALSE;
250     }
251    
252     //--------------------------------------------------------------------------------------------------
253     inline TParticlePDG *mithep::MCParticle::PdgEntry() const
254     {
255     // Return entry to pdg database.
256    
257     return TDatabasePDG::Instance()->GetParticle(fPdgId);
258     }
259    
260     //--------------------------------------------------------------------------------------------------
261 loizides 1.18 inline Double_t mithep::MCParticle::PdgMass() const
262     {
263     // Return mass obtained from pdg database.
264    
265     TParticlePDG *pdg = PdgEntry();
266     if (pdg)
267     return pdg->Mass();
268     return 0;
269     }
270    
271     //--------------------------------------------------------------------------------------------------
272 bendavid 1.1 inline void mithep::MCParticle::SetMom(Double_t px, Double_t py, Double_t pz, Double_t e)
273     {
274     // Set four vector.
275    
276 loizides 1.16 fMom.SetXYZT(px, py, pz, e);
277 bendavid 1.15 ClearMom();
278 bendavid 1.1 }
279    
280     //--------------------------------------------------------------------------------------------------
281     inline void mithep::MCParticle::SetVertex(Double_t x, Double_t y, Double_t z)
282     {
283     // Set decay vertex.
284    
285     fDecayVertex.SetXYZ(x,y,z);
286     }
287     #endif