ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.10
Committed: Wed Dec 3 16:58:17 2008 UTC (16 years, 5 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.9: +3 -3 lines
Log Message:
Make add and set functions for referencing objects accept const pointers

File Contents

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