ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/MCParticle.h
Revision: 1.7
Committed: Fri Nov 21 20:15:02 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.6: +43 -5 lines
Log Message:
Include daughter in prinout if "l" is given. Add a couple of useful functions.

File Contents

# User Rev Content
1 bendavid 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.7 // $Id: MCParticle.h,v 1.6 2008/11/05 12:15:39 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     fPdgId(id), fStatus(s),
27 bendavid 1.6 fFourVector(FourVector(px,py,pz,e)), fDecayVertex(0,0,0),
28 bendavid 1.1 fIsGenerated(kFALSE), fIsSimulated(kFALSE) {}
29     ~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     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.7 Bool_t Is(Int_t pid, Bool_t checkCharge=kFALSE) const;
41 loizides 1.3 Bool_t IsGenerated() const { return fIsGenerated; }
42 loizides 1.7 Bool_t IsNeutrino() const;
43     Bool_t IsQuark() const { return (AbsPdgId()>0 && AbsPdgId()<7); }
44 loizides 1.3 Bool_t IsSimulated() const { return fIsSimulated; }
45     const MCParticle *Mother() const;
46 bendavid 1.6 FourVector Mom() const { return FourVector(fFourVector); }
47 bendavid 1.1 void SetIsGenerated(Bool_t t=kTRUE) { fIsGenerated = t; }
48     void SetIsSimulated(Bool_t t=kTRUE) { fIsSimulated = t; }
49 loizides 1.3 TParticlePDG *PdgEntry() const;
50     Int_t PdgId() const { return fPdgId; }
51 bendavid 1.1 void SetMom(Double_t px, Double_t py, Double_t pz, Double_t e);
52 loizides 1.3 void SetMother(MCParticle *p) { fMother = p; }
53     void SetStatus(Int_t s) { fStatus = s; }
54 bendavid 1.2 void SetVertex(Double_t x, Double_t y, Double_t z);
55 ceballos 1.5 void SetPdgId(Int_t s) { fPdgId = s; }
56 loizides 1.3 Int_t Status() const { return fStatus; }
57     void Print(Option_t *opt="") const;
58 bendavid 1.1
59     enum EPartType {
60 loizides 1.7 kUnknown=0,
61     kUp=1, kDown=2, kStrange=3, kCharm=4, kBottom=5, kTop=6,
62     kEl=11, kMu=13, kTau=15,
63 bendavid 1.1 kElNu=12, kMuNu=14, kTauNu=16,
64 loizides 1.7 kGlu=21, kGamma=22, kZ=23, kW=24, kH=25
65 bendavid 1.1 };
66    
67     protected:
68     Int_t fPdgId; //pdg identifier
69     Int_t fStatus; //status flag of generator or simulation
70 bendavid 1.6 FourVectorM32 fFourVector; //four momentum vector
71     ThreeVector32 fDecayVertex; //gen decay vertex
72 bendavid 1.1 TRef fMother; //reference to mother
73 loizides 1.3 Bool_t fIsGenerated; //=true if generated particle
74     Bool_t fIsSimulated; //=true if simulated particle
75 bendavid 1.1
76 bendavid 1.6 ClassDef(MCParticle,3) // Generated particle class
77 bendavid 1.1 };
78     }
79    
80     //--------------------------------------------------------------------------------------------------
81 loizides 1.7 inline Bool_t mithep::MCParticle::HasDaughter(Int_t pid, Bool_t checkCharge) const
82     {
83     // Return true if a particle with given pdg code is found amoung daughters.
84     // If checkCharge is false then just the type of particle is checked
85     // (ie particle and anti-particle).
86    
87     if (checkCharge) {
88     for (UInt_t i=0; i<NDaughters(); ++i)
89     if (Daughter(i)->PdgId()==pid)
90     return kTRUE;
91     } else {
92     Int_t apid = pid>0?pid:-pid;
93     for (UInt_t i=0; i<NDaughters(); ++i)
94     if (Daughter(i)->AbsPdgId()==apid)
95     return kTRUE;
96     }
97     return kFALSE;
98     }
99    
100     //--------------------------------------------------------------------------------------------------
101 bendavid 1.1 inline const mithep::MCParticle *mithep::MCParticle::Daughter(UInt_t i) const
102     {
103     // Return daughter corresponding to given index.
104    
105     return static_cast<const MCParticle*>(fDaughters.At(i));
106     }
107    
108     //--------------------------------------------------------------------------------------------------
109 bendavid 1.4 inline const mithep::MCParticle *mithep::MCParticle::DistinctMother() const
110     {
111     // Return mother, walking up the tree until a particle with a different pdg from this one
112     // is found.
113    
114     const mithep::MCParticle *mother = Mother();
115    
116     if (!mother) return 0;
117    
118     while (mother->PdgId()==fPdgId)
119     mother = mother->Mother();
120    
121     return mother;
122     }
123    
124     //--------------------------------------------------------------------------------------------------
125 bendavid 1.1 inline const mithep::MCParticle *mithep::MCParticle::Mother() const
126     {
127     // Return mother.
128    
129     return static_cast<const MCParticle*>(fMother.GetObject());
130     }
131    
132     //--------------------------------------------------------------------------------------------------
133 loizides 1.7 inline Bool_t mithep::MCParticle::Is(Int_t pid, Bool_t checkCharge) const
134     {
135     // Return true if particle is of given type. If checkCharge is false then just the type of
136     // particle is checked (ie particle and anti-particle).
137    
138     if (checkCharge)
139     return (PdgId() == pid);
140    
141     Int_t apid = pid>0?pid:-pid;
142     return (AbsPdgId() == apid);
143     }
144    
145     //--------------------------------------------------------------------------------------------------
146 bendavid 1.1 inline Bool_t mithep::MCParticle::IsNeutrino() const
147     {
148     // Return true if particle is neutrino.
149    
150     Int_t ap = AbsPdgId();
151     if ((ap==kElNu) ||
152     (ap==kMuNu) ||
153     (ap==kTauNu))
154     return kTRUE;
155    
156     return kFALSE;
157     }
158    
159     //--------------------------------------------------------------------------------------------------
160     inline TParticlePDG *mithep::MCParticle::PdgEntry() const
161     {
162     // Return entry to pdg database.
163    
164     return TDatabasePDG::Instance()->GetParticle(fPdgId);
165     }
166    
167     //--------------------------------------------------------------------------------------------------
168     inline void mithep::MCParticle::SetMom(Double_t px, Double_t py, Double_t pz, Double_t e)
169     {
170     // Set four vector.
171    
172     fFourVector.SetXYZT(px, py, pz, e);
173     }
174    
175     //--------------------------------------------------------------------------------------------------
176     inline void mithep::MCParticle::SetVertex(Double_t x, Double_t y, Double_t z)
177     {
178     // Set decay vertex.
179    
180     fDecayVertex.SetXYZ(x,y,z);
181     }
182     #endif