ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.14
Committed: Wed Feb 18 15:38:54 2009 UTC (16 years, 2 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.13: +27 -4 lines
Log Message:
Reworked particle interface to cache FourVectorM

File Contents

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