ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.11
Committed: Mon Dec 8 14:56:09 2008 UTC (16 years, 4 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.10: +13 -1 lines
Log Message:
Added IsParton, IsNot and IsGluon.

File Contents

# User Rev Content
1 bendavid 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.11 // $Id: MCParticle.h,v 1.10 2008/12/03 16:58:17 bendavid Exp $
3 bendavid 1.1 //
4     // MCParticle
5     //
6     // Stores MC information for both gen and sim level
7     //
8     // Authors: C.Loizides, J.Bendavid...
9     //--------------------------------------------------------------------------------------------------
10    
11 loizides 1.3 #ifndef MITANA_DATATREE_MCPARTICLE_H
12     #define MITANA_DATATREE_MCPARTICLE_H
13 bendavid 1.1
14     #include <TRef.h>
15     #include <TDatabasePDG.h>
16     #include <TParticlePDG.h>
17     #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     ~MCParticle() {}
29    
30 loizides 1.3 Int_t AbsPdgId() const { return (fPdgId<0 ? -fPdgId:fPdgId); }
31 bendavid 1.10 void AddDaughter(const MCParticle *p) { fDaughters.Add(p); }
32 loizides 1.3 Double_t Charge() const;
33     const ThreeVector &DecayVertex() const { return fDecayVertex; }
34     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     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.3 Bool_t IsGenerated() const { return fIsGenerated; }
47 loizides 1.11 Bool_t IsGluon() const { return fPdgId == kGlu; }
48 loizides 1.7 Bool_t IsNeutrino() const;
49 loizides 1.11 Bool_t IsParton() const { return (IsGluon() || IsQuark()); }
50 loizides 1.7 Bool_t IsQuark() const { return (AbsPdgId()>0 && AbsPdgId()<7); }
51 loizides 1.3 Bool_t IsSimulated() const { return fIsSimulated; }
52     const MCParticle *Mother() const;
53 bendavid 1.6 FourVector Mom() const { return FourVector(fFourVector); }
54 bendavid 1.1 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     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 bendavid 1.10 void SetMother(const MCParticle *p) { fMother = const_cast<MCParticle*>(p); }
60 loizides 1.3 void SetStatus(Int_t s) { fStatus = s; }
61 bendavid 1.2 void SetVertex(Double_t x, Double_t y, Double_t z);
62 ceballos 1.5 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     Int_t fPdgId; //pdg identifier
78     Int_t fStatus; //status flag of generator or simulation
79 bendavid 1.6 FourVectorM32 fFourVector; //four momentum vector
80     ThreeVector32 fDecayVertex; //gen decay vertex
81 bendavid 1.1 TRef fMother; //reference to mother
82 loizides 1.3 Bool_t fIsGenerated; //=true if generated particle
83     Bool_t fIsSimulated; //=true if simulated particle
84 bendavid 1.1
85 bendavid 1.6 ClassDef(MCParticle,3) // Generated particle class
86 bendavid 1.1 };
87     }
88    
89     //--------------------------------------------------------------------------------------------------
90 loizides 1.8 inline const mithep::MCParticle *mithep::MCParticle::Daughter(UInt_t i) const
91     {
92     // Return daughter corresponding to given index.
93    
94     return static_cast<const MCParticle*>(fDaughters.At(i));
95     }
96    
97     //--------------------------------------------------------------------------------------------------
98     inline const mithep::MCParticle *mithep::MCParticle::DistinctMother() const
99     {
100     // Return mother, walking up the tree until a particle with a different pdg from this one
101     // is found.
102    
103     const mithep::MCParticle *mother = Mother();
104    
105     if (!mother)
106     return 0;
107    
108     while (mother->PdgId()==fPdgId)
109     mother = mother->Mother();
110    
111     return mother;
112     }
113    
114     //--------------------------------------------------------------------------------------------------
115 loizides 1.7 inline Bool_t mithep::MCParticle::HasDaughter(Int_t pid, Bool_t checkCharge) const
116     {
117     // Return true if a particle with given pdg code is found amoung daughters.
118     // If checkCharge is false then just the type of particle is checked
119     // (ie particle and anti-particle).
120    
121     if (checkCharge) {
122     for (UInt_t i=0; i<NDaughters(); ++i)
123     if (Daughter(i)->PdgId()==pid)
124     return kTRUE;
125     } else {
126     Int_t apid = pid>0?pid:-pid;
127     for (UInt_t i=0; i<NDaughters(); ++i)
128     if (Daughter(i)->AbsPdgId()==apid)
129     return kTRUE;
130     }
131     return kFALSE;
132     }
133    
134     //--------------------------------------------------------------------------------------------------
135 loizides 1.9 inline Bool_t mithep::MCParticle::HasMother(const MCParticle *m) const
136     {
137     // Return true if the given particle is among mothers. (Note the comparison
138     // is made on pointers and therefore will fail if you work on copies.)
139    
140     if (!m)
141     return kFALSE;
142    
143     const mithep::MCParticle *mother = Mother();
144     while (mother && mother!=m)
145     mother = mother->Mother();
146    
147     if (mother)
148     return kTRUE;
149     return kFALSE;
150     }
151    
152     //--------------------------------------------------------------------------------------------------
153 loizides 1.8 inline Bool_t mithep::MCParticle::HasMother(Int_t pid, Bool_t checkCharge) const
154     {
155     // Return true if a particle with given pdg code is found amoung mothers.
156     // If checkCharge is false then just the type of particle is checked
157     // (ie particle and anti-particle).
158 bendavid 1.4
159     const mithep::MCParticle *mother = Mother();
160    
161 loizides 1.8 if (checkCharge) {
162 loizides 1.9 while (mother && mother->PdgId()!=pid)
163 loizides 1.8 mother = mother->Mother();
164     } else {
165     Int_t apid = pid>0?pid:-pid;
166 loizides 1.9 while (mother && mother->AbsPdgId()!=apid)
167 loizides 1.8 mother = mother->Mother();
168     }
169 bendavid 1.4
170 loizides 1.8 if (mother)
171     return kTRUE;
172     return kFALSE;
173 bendavid 1.1 }
174    
175     //--------------------------------------------------------------------------------------------------
176 loizides 1.7 inline Bool_t mithep::MCParticle::Is(Int_t pid, Bool_t checkCharge) const
177     {
178     // Return true if particle is of given type. If checkCharge is false then just the type of
179     // particle is checked (ie particle and anti-particle).
180    
181     if (checkCharge)
182     return (PdgId() == pid);
183    
184     Int_t apid = pid>0?pid:-pid;
185     return (AbsPdgId() == apid);
186     }
187    
188     //--------------------------------------------------------------------------------------------------
189 loizides 1.11 inline Bool_t mithep::MCParticle::IsNot(Int_t pid, Bool_t checkCharge) const
190     {
191     // Return true if particle is not of given type. If checkCharge is false then just the type of
192     // particle is checked (ie particle and anti-particle).
193    
194     return !Is(pid, checkCharge);
195     }
196    
197     //--------------------------------------------------------------------------------------------------
198 bendavid 1.1 inline Bool_t mithep::MCParticle::IsNeutrino() const
199     {
200     // Return true if particle is neutrino.
201    
202     Int_t ap = AbsPdgId();
203     if ((ap==kElNu) ||
204     (ap==kMuNu) ||
205     (ap==kTauNu))
206     return kTRUE;
207    
208     return kFALSE;
209     }
210    
211     //--------------------------------------------------------------------------------------------------
212 loizides 1.8 inline const mithep::MCParticle *mithep::MCParticle::Mother() const
213     {
214     // Return mother.
215    
216     return static_cast<const MCParticle*>(fMother.GetObject());
217     }
218    
219     //--------------------------------------------------------------------------------------------------
220 bendavid 1.1 inline TParticlePDG *mithep::MCParticle::PdgEntry() const
221     {
222     // Return entry to pdg database.
223    
224     return TDatabasePDG::Instance()->GetParticle(fPdgId);
225     }
226    
227     //--------------------------------------------------------------------------------------------------
228     inline void mithep::MCParticle::SetMom(Double_t px, Double_t py, Double_t pz, Double_t e)
229     {
230     // Set four vector.
231    
232     fFourVector.SetXYZT(px, py, pz, e);
233     }
234    
235     //--------------------------------------------------------------------------------------------------
236     inline void mithep::MCParticle::SetVertex(Double_t x, Double_t y, Double_t z)
237     {
238     // Set decay vertex.
239    
240     fDecayVertex.SetXYZ(x,y,z);
241     }
242     #endif