1 |
bendavid |
1.1 |
//--------------------------------------------------------------------------------------------------
|
2 |
loizides |
1.18 |
// $Id: MCParticle.h,v 1.17 2009/03/08 12:09:59 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 |
loizides |
1.17 |
#include "MitCommon/DataFormats/interface/Vect3.h"
|
17 |
|
|
#include "MitCommon/DataFormats/interface/Vect4M.h"
|
18 |
bendavid |
1.13 |
#include "MitAna/DataCont/interface/Ref.h"
|
19 |
bendavid |
1.1 |
#include "MitAna/DataTree/interface/CompositeParticle.h"
|
20 |
|
|
|
21 |
|
|
namespace mithep
|
22 |
|
|
{
|
23 |
|
|
class MCParticle : public CompositeParticle
|
24 |
|
|
{
|
25 |
|
|
public:
|
26 |
loizides |
1.16 |
MCParticle() : fPdgId(0), fStatus(0), fIsGenerated(kFALSE), fIsSimulated(kFALSE) {}
|
27 |
bendavid |
1.1 |
MCParticle(Double_t px, Double_t py, Double_t pz, Double_t e, Int_t id, Int_t s) :
|
28 |
loizides |
1.18 |
fPdgId(id), fStatus(s), fMom(FourVector(px,py,pz,e)),
|
29 |
bendavid |
1.1 |
fIsGenerated(kFALSE), fIsSimulated(kFALSE) {}
|
30 |
|
|
|
31 |
loizides |
1.16 |
Int_t AbsPdgId() const { return (fPdgId<0 ? -fPdgId:fPdgId); }
|
32 |
|
|
void AddDaughter(const MCParticle *p) { fDaughters.Add(p); }
|
33 |
|
|
const ThreeVector DecayVertex() const { return fDecayVertex.V(); }
|
34 |
loizides |
1.3 |
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 |
loizides |
1.16 |
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.16 |
Bool_t IsGenerated() const { return fIsGenerated; }
|
47 |
|
|
Bool_t IsGluon() const { return fPdgId == kGlu; }
|
48 |
loizides |
1.7 |
Bool_t IsNeutrino() const;
|
49 |
loizides |
1.16 |
Bool_t IsParton() const { return (IsGluon() || IsQuark()); }
|
50 |
loizides |
1.7 |
Bool_t IsQuark() const { return (AbsPdgId()>0 && AbsPdgId()<7); }
|
51 |
loizides |
1.16 |
Bool_t IsSimulated() const { return fIsSimulated; }
|
52 |
bendavid |
1.13 |
const MCParticle *Mother() const { return fMother.Obj(); }
|
53 |
loizides |
1.16 |
EObjType ObjType() const { return kMCParticle; }
|
54 |
|
|
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 |
loizides |
1.16 |
Int_t PdgId() const { return fPdgId; }
|
58 |
loizides |
1.18 |
Double_t PdgMass() const;
|
59 |
bendavid |
1.1 |
void SetMom(Double_t px, Double_t py, Double_t pz, Double_t e);
|
60 |
loizides |
1.16 |
void SetMother(const MCParticle *p) { fMother = p; }
|
61 |
|
|
void SetStatus(Int_t s) { fStatus = s; }
|
62 |
bendavid |
1.2 |
void SetVertex(Double_t x, Double_t y, Double_t z);
|
63 |
loizides |
1.16 |
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 |
loizides |
1.14 |
Double_t GetCharge() const;
|
79 |
|
|
void GetMom() const;
|
80 |
|
|
|
81 |
bendavid |
1.1 |
Int_t fPdgId; //pdg identifier
|
82 |
loizides |
1.16 |
Short_t fStatus; //status flag of generator or simulation
|
83 |
|
|
Vect4M fMom; //four momentum vector
|
84 |
|
|
Vect3 fDecayVertex; //gen decay vertex
|
85 |
bendavid |
1.13 |
Ref<MCParticle> fMother; //reference to mother
|
86 |
loizides |
1.3 |
Bool_t fIsGenerated; //=true if generated particle
|
87 |
|
|
Bool_t fIsSimulated; //=true if simulated particle
|
88 |
bendavid |
1.1 |
|
89 |
loizides |
1.14 |
ClassDef(MCParticle,1) // Generated particle class
|
90 |
bendavid |
1.1 |
};
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
//--------------------------------------------------------------------------------------------------
|
94 |
loizides |
1.8 |
inline const mithep::MCParticle *mithep::MCParticle::Daughter(UInt_t i) const
|
95 |
|
|
{
|
96 |
|
|
// Return daughter corresponding to given index.
|
97 |
|
|
|
98 |
|
|
return static_cast<const MCParticle*>(fDaughters.At(i));
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
//--------------------------------------------------------------------------------------------------
|
102 |
|
|
inline const mithep::MCParticle *mithep::MCParticle::DistinctMother() const
|
103 |
|
|
{
|
104 |
|
|
// Return mother, walking up the tree until a particle with a different pdg from this one
|
105 |
|
|
// is found.
|
106 |
|
|
|
107 |
|
|
const mithep::MCParticle *mother = Mother();
|
108 |
|
|
|
109 |
|
|
if (!mother)
|
110 |
|
|
return 0;
|
111 |
|
|
|
112 |
|
|
while (mother->PdgId()==fPdgId)
|
113 |
|
|
mother = mother->Mother();
|
114 |
|
|
|
115 |
|
|
return mother;
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
//--------------------------------------------------------------------------------------------------
|
119 |
loizides |
1.14 |
inline Double_t mithep::MCParticle::GetCharge() const
|
120 |
|
|
{
|
121 |
|
|
// Get charge from pdg lookup.
|
122 |
|
|
|
123 |
|
|
TParticlePDG *pdgEntry = PdgEntry();
|
124 |
|
|
if (pdgEntry)
|
125 |
|
|
return pdgEntry->Charge()/3.0;
|
126 |
|
|
else {
|
127 |
|
|
Error("Charge", "Pdg code for %i not found in table, returning charge=-99.0", fPdgId);
|
128 |
|
|
return -99.0;
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
//--------------------------------------------------------------------------------------------------
|
133 |
|
|
inline void mithep::MCParticle::GetMom() const
|
134 |
|
|
{
|
135 |
|
|
// Get momentum values from stored values.
|
136 |
|
|
|
137 |
loizides |
1.16 |
fCachedMom.SetCoordinates(fMom.Pt(), fMom.Eta(), fMom.Phi(), fMom.M());
|
138 |
loizides |
1.14 |
}
|
139 |
|
|
|
140 |
|
|
//--------------------------------------------------------------------------------------------------
|
141 |
loizides |
1.7 |
inline Bool_t mithep::MCParticle::HasDaughter(Int_t pid, Bool_t checkCharge) const
|
142 |
|
|
{
|
143 |
|
|
// Return true if a particle with given pdg code is found amoung daughters.
|
144 |
|
|
// If checkCharge is false then just the type of particle is checked
|
145 |
|
|
// (ie particle and anti-particle).
|
146 |
|
|
|
147 |
|
|
if (checkCharge) {
|
148 |
|
|
for (UInt_t i=0; i<NDaughters(); ++i)
|
149 |
|
|
if (Daughter(i)->PdgId()==pid)
|
150 |
|
|
return kTRUE;
|
151 |
|
|
} else {
|
152 |
|
|
Int_t apid = pid>0?pid:-pid;
|
153 |
|
|
for (UInt_t i=0; i<NDaughters(); ++i)
|
154 |
|
|
if (Daughter(i)->AbsPdgId()==apid)
|
155 |
|
|
return kTRUE;
|
156 |
|
|
}
|
157 |
|
|
return kFALSE;
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
//--------------------------------------------------------------------------------------------------
|
161 |
loizides |
1.9 |
inline Bool_t mithep::MCParticle::HasMother(const MCParticle *m) const
|
162 |
|
|
{
|
163 |
|
|
// Return true if the given particle is among mothers. (Note the comparison
|
164 |
|
|
// is made on pointers and therefore will fail if you work on copies.)
|
165 |
|
|
|
166 |
|
|
if (!m)
|
167 |
|
|
return kFALSE;
|
168 |
|
|
|
169 |
|
|
const mithep::MCParticle *mother = Mother();
|
170 |
|
|
while (mother && mother!=m)
|
171 |
|
|
mother = mother->Mother();
|
172 |
|
|
|
173 |
|
|
if (mother)
|
174 |
|
|
return kTRUE;
|
175 |
|
|
return kFALSE;
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
//--------------------------------------------------------------------------------------------------
|
179 |
loizides |
1.8 |
inline Bool_t mithep::MCParticle::HasMother(Int_t pid, Bool_t checkCharge) const
|
180 |
|
|
{
|
181 |
|
|
// Return true if a particle with given pdg code is found amoung mothers.
|
182 |
|
|
// If checkCharge is false then just the type of particle is checked
|
183 |
|
|
// (ie particle and anti-particle).
|
184 |
bendavid |
1.4 |
|
185 |
|
|
const mithep::MCParticle *mother = Mother();
|
186 |
|
|
|
187 |
loizides |
1.8 |
if (checkCharge) {
|
188 |
loizides |
1.9 |
while (mother && mother->PdgId()!=pid)
|
189 |
loizides |
1.8 |
mother = mother->Mother();
|
190 |
|
|
} else {
|
191 |
|
|
Int_t apid = pid>0?pid:-pid;
|
192 |
loizides |
1.9 |
while (mother && mother->AbsPdgId()!=apid)
|
193 |
loizides |
1.8 |
mother = mother->Mother();
|
194 |
|
|
}
|
195 |
bendavid |
1.4 |
|
196 |
loizides |
1.8 |
if (mother)
|
197 |
|
|
return kTRUE;
|
198 |
|
|
return kFALSE;
|
199 |
bendavid |
1.1 |
}
|
200 |
|
|
|
201 |
|
|
//--------------------------------------------------------------------------------------------------
|
202 |
loizides |
1.7 |
inline Bool_t mithep::MCParticle::Is(Int_t pid, Bool_t checkCharge) const
|
203 |
|
|
{
|
204 |
|
|
// Return true if particle is of given type. If checkCharge is false then just the type of
|
205 |
|
|
// particle is checked (ie particle and anti-particle).
|
206 |
|
|
|
207 |
|
|
if (checkCharge)
|
208 |
|
|
return (PdgId() == pid);
|
209 |
|
|
|
210 |
|
|
Int_t apid = pid>0?pid:-pid;
|
211 |
|
|
return (AbsPdgId() == apid);
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
//--------------------------------------------------------------------------------------------------
|
215 |
loizides |
1.11 |
inline Bool_t mithep::MCParticle::IsNot(Int_t pid, Bool_t checkCharge) const
|
216 |
|
|
{
|
217 |
|
|
// Return true if particle is not of given type. If checkCharge is false then just the type of
|
218 |
|
|
// particle is checked (ie particle and anti-particle).
|
219 |
|
|
|
220 |
|
|
return !Is(pid, checkCharge);
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
//--------------------------------------------------------------------------------------------------
|
224 |
bendavid |
1.1 |
inline Bool_t mithep::MCParticle::IsNeutrino() const
|
225 |
|
|
{
|
226 |
|
|
// Return true if particle is neutrino.
|
227 |
|
|
|
228 |
|
|
Int_t ap = AbsPdgId();
|
229 |
|
|
if ((ap==kElNu) ||
|
230 |
|
|
(ap==kMuNu) ||
|
231 |
|
|
(ap==kTauNu))
|
232 |
|
|
return kTRUE;
|
233 |
|
|
|
234 |
|
|
return kFALSE;
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
//--------------------------------------------------------------------------------------------------
|
238 |
|
|
inline TParticlePDG *mithep::MCParticle::PdgEntry() const
|
239 |
|
|
{
|
240 |
|
|
// Return entry to pdg database.
|
241 |
|
|
|
242 |
|
|
return TDatabasePDG::Instance()->GetParticle(fPdgId);
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
//--------------------------------------------------------------------------------------------------
|
246 |
loizides |
1.18 |
inline Double_t mithep::MCParticle::PdgMass() const
|
247 |
|
|
{
|
248 |
|
|
// Return mass obtained from pdg database.
|
249 |
|
|
|
250 |
|
|
TParticlePDG *pdg = PdgEntry();
|
251 |
|
|
if (pdg)
|
252 |
|
|
return pdg->Mass();
|
253 |
|
|
return 0;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
//--------------------------------------------------------------------------------------------------
|
257 |
bendavid |
1.1 |
inline void mithep::MCParticle::SetMom(Double_t px, Double_t py, Double_t pz, Double_t e)
|
258 |
|
|
{
|
259 |
|
|
// Set four vector.
|
260 |
|
|
|
261 |
loizides |
1.16 |
fMom.SetXYZT(px, py, pz, e);
|
262 |
bendavid |
1.15 |
ClearMom();
|
263 |
bendavid |
1.1 |
}
|
264 |
|
|
|
265 |
|
|
//--------------------------------------------------------------------------------------------------
|
266 |
|
|
inline void mithep::MCParticle::SetVertex(Double_t x, Double_t y, Double_t z)
|
267 |
|
|
{
|
268 |
|
|
// Set decay vertex.
|
269 |
|
|
|
270 |
|
|
fDecayVertex.SetXYZ(x,y,z);
|
271 |
|
|
}
|
272 |
|
|
#endif
|