ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.13
Committed: Wed Feb 18 08:17:03 2009 UTC (16 years, 2 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.12: +5 -13 lines
Log Message:
Switched to new Ref class

File Contents

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