ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.16
Committed: Tue Mar 3 17:04:10 2009 UTC (16 years, 2 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre1
Changes since 1.15: +25 -24 lines
Log Message:
Cleanup and double32.

File Contents

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