ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.8
Committed: Mon Nov 24 11:51:20 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.7: +61 -29 lines
Log Message:
Added FindMother and FindDaughter methods.

File Contents

# User Rev Content
1 bendavid 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.8 // $Id: MCParticle.h,v 1.7 2008/11/21 20:15:02 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 loizides 1.8 // MCParticle(const MCParticle *p)
29 bendavid 1.1 ~MCParticle() {}
30    
31 loizides 1.3 Int_t AbsPdgId() const { return (fPdgId<0 ? -fPdgId:fPdgId); }
32     void AddDaughter(MCParticle *p) { fDaughters.Add(p); }
33     Double_t Charge() const;
34     const ThreeVector &DecayVertex() const { return fDecayVertex; }
35     const MCParticle *Daughter(UInt_t i) const;
36 bendavid 1.4 const MCParticle *DistinctMother() const;
37 loizides 1.7 using CompositeParticle::HasDaughter;
38 loizides 1.8 const MCParticle *FindDaughter(Int_t pid,
39     Bool_t checkCharge=kFALSE, const MCParticle *start=0) const;
40     const MCParticle *FindMother(Int_t pid, Bool_t checkCharge=kFALSE) const;
41 loizides 1.7 Bool_t HasDaughter(Int_t pid, Bool_t checkCharge=kFALSE) const;
42 loizides 1.3 Bool_t HasMother() const { return fMother.IsValid(); }
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 loizides 1.3 void SetMother(MCParticle *p) { fMother = p; }
57     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.8 inline Bool_t mithep::MCParticle::HasMother(Int_t pid, Bool_t checkCharge) const
133     {
134     // Return true if a particle with given pdg code is found amoung mothers.
135     // If checkCharge is false then just the type of particle is checked
136     // (ie particle and anti-particle).
137 bendavid 1.4
138     const mithep::MCParticle *mother = Mother();
139 loizides 1.8 if (!mother)
140     return kFALSE;
141 bendavid 1.4
142 loizides 1.8 if (checkCharge) {
143     while (mother->PdgId()==fPdgId)
144     mother = mother->Mother();
145     } else {
146     Int_t apid = pid>0?pid:-pid;
147     while (mother->AbsPdgId()==apid)
148     mother = mother->Mother();
149     }
150 bendavid 1.4
151 loizides 1.8 if (mother)
152     return kTRUE;
153     return kFALSE;
154 bendavid 1.1 }
155    
156     //--------------------------------------------------------------------------------------------------
157 loizides 1.7 inline Bool_t mithep::MCParticle::Is(Int_t pid, Bool_t checkCharge) const
158     {
159     // Return true if particle is of given type. If checkCharge is false then just the type of
160     // particle is checked (ie particle and anti-particle).
161    
162     if (checkCharge)
163     return (PdgId() == pid);
164    
165     Int_t apid = pid>0?pid:-pid;
166     return (AbsPdgId() == apid);
167     }
168    
169     //--------------------------------------------------------------------------------------------------
170 bendavid 1.1 inline Bool_t mithep::MCParticle::IsNeutrino() const
171     {
172     // Return true if particle is neutrino.
173    
174     Int_t ap = AbsPdgId();
175     if ((ap==kElNu) ||
176     (ap==kMuNu) ||
177     (ap==kTauNu))
178     return kTRUE;
179    
180     return kFALSE;
181     }
182    
183     //--------------------------------------------------------------------------------------------------
184 loizides 1.8 inline const mithep::MCParticle *mithep::MCParticle::Mother() const
185     {
186     // Return mother.
187    
188     return static_cast<const MCParticle*>(fMother.GetObject());
189     }
190    
191     //--------------------------------------------------------------------------------------------------
192 bendavid 1.1 inline TParticlePDG *mithep::MCParticle::PdgEntry() const
193     {
194     // Return entry to pdg database.
195    
196     return TDatabasePDG::Instance()->GetParticle(fPdgId);
197     }
198    
199     //--------------------------------------------------------------------------------------------------
200     inline void mithep::MCParticle::SetMom(Double_t px, Double_t py, Double_t pz, Double_t e)
201     {
202     // Set four vector.
203    
204     fFourVector.SetXYZT(px, py, pz, e);
205     }
206    
207     //--------------------------------------------------------------------------------------------------
208     inline void mithep::MCParticle::SetVertex(Double_t x, Double_t y, Double_t z)
209     {
210     // Set decay vertex.
211    
212     fDecayVertex.SetXYZ(x,y,z);
213     }
214     #endif