ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.24
Committed: Wed Mar 28 12:15:34 2012 UTC (13 years, 1 month ago) by paus
Content type: text/plain
Branch: MAIN
Changes since 1.23: +15 -2 lines
Log Message:
Enable skimming.

File Contents

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