source: trunk/src/ExRootCandidate.cc@ 18

Last change on this file since 18 was 2, checked in by Pavel Demin, 16 years ago

first commit

File size: 9.4 KB
RevLine 
[2]1
2/** \class ExRootCandidate
3 *
4 * Class implementing particle candidate model.
5 *
6 * $Date: 2008-06-04 13:57:54 $
7 * $Revision: 1.1 $
8 *
9 *
10 * \author P. Demin - UCL, Louvain-la-Neuve
11 *
12 */
13
14#include "ExRootAnalysis/ExRootCandidate.h"
15#include "ExRootAnalysis/ExRootFactory.h"
16
17#include "TDatabasePDG.h"
18#include "TBrowser.h"
19#include "TClass.h"
20
21#include <map>
22#include <iostream>
23
24using namespace std;
25
26ExRootCompare *ExRootCandidate::fgCompare = 0;
27
28ExRootCandidate::ExRootCandidate() :
29 fIsResonance(kFALSE),
30 fCharge(0),
31 fLorentzVector(0.0, 0.0, 0.0, 0.0),
32 fMother(0)
33{
34}
35
36//------------------------------------------------------------------------------
37
38ExRootCandidate::ExRootCandidate(const ExRootCandidate &object) :
39 fIsResonance(kFALSE),
40 fCharge(0),
41 fLorentzVector(0.0, 0.0, 0.0, 0.0),
42 fMother(0)
43{
44 object.Copy(*this);
45}
46
47//------------------------------------------------------------------------------
48
49Bool_t ExRootCandidate::IsCloneOf(const ExRootCandidate *object, Bool_t checkType) const
50{
51 // Original behaviour of ExRootCandidate::IsCloneOf()
52 if(object->GetUniqueID() == GetUniqueID() && !checkType) return kTRUE;
53
54 if((IsComposite() && !object->IsComposite()) ||
55 (!IsComposite() && object->IsComposite())) return kFALSE;
56
57 // forsingle tracks and clusters, it is enough to compare
58 // UIDs and PDT types
59 if(!IsComposite() && !object->IsComposite())
60 {
61 return (object->GetUniqueID() == GetUniqueID() &&
62 (!checkType || GetType() == object->GetType()));
63 }
64
65 // if we got here, must be true
66 return kTRUE;
67}
68
69//------------------------------------------------------------------------------
70
71const ExRootCandidate *ExRootCandidate::FindCloneInTree(const ExRootCandidate *object) const
72{
73 if(IsCloneOf(object)) return this;
74 const ExRootCandidate *daughter;
75 ExRootCandConstIter itDaughters(Iterator());
76 while((daughter = itDaughters.Next()))
77 {
78 daughter = daughter->FindCloneInTree(object);
79 if(daughter) return daughter;
80 }
81 return 0;
82}
83
84//------------------------------------------------------------------------------
85
86Bool_t ExRootCandidate::Overlaps(const ExRootCandidate *object) const
87{
88 if(object->GetUniqueID() == GetUniqueID()) return kTRUE;
89
90 const ExRootCandidate *daughter;
91
92 ExRootCandConstIter itDaughters(Iterator());
93 while((daughter = itDaughters.Next()))
94 {
95 if(daughter->Overlaps(object)) return kTRUE;
96 }
97
98 itDaughters = object->Iterator();
99 while((daughter = itDaughters.Next()))
100 {
101 if(daughter->Overlaps(this)) return kTRUE;
102 }
103
104 return kFALSE;
105}
106
107//------------------------------------------------------------------------------
108
109Bool_t ExRootCandidate::Equals(const ExRootCandidate *object) const
110{
111 if(object->GetUniqueID() != GetUniqueID()) return kFALSE;
112
113 const ExRootCandidate *daughter;
114
115 ExRootCandConstIter itDaughters(Iterator());
116 while((daughter = itDaughters.Next()))
117 {
118 if(!daughter->Equals(object)) return kFALSE;
119 }
120
121 itDaughters = object->Iterator();
122 while((daughter = itDaughters.Next()))
123 {
124 if(!daughter->Equals(this)) return kFALSE;
125 }
126
127 return kTRUE;
128}
129
130//------------------------------------------------------------------------------
131
132void ExRootCandidate::SetMass(Double_t mass)
133{
134 fLorentzVector.SetVectM(fLorentzVector.Vect(), mass);
135}
136
137//------------------------------------------------------------------------------
138
139void ExRootCandidate::SetP4(const TLorentzVector &p4)
140{
141 fLorentzVector = p4;
142}
143
144//------------------------------------------------------------------------------
145
146void ExRootCandidate::SetMomentum(Double_t momentum)
147{
148 // this implementation leaves mass unchanged; subclasses may differ
149 Double_t scale = 0.0;
150 Double_t p = fLorentzVector.P();
151 if(p != 0.0) scale = momentum / p;
152 fLorentzVector.SetVect(scale*fLorentzVector.Vect());
153}
154
155//------------------------------------------------------------------------------
156
157void ExRootCandidate::SetType(TParticlePDG *particle)
158{
159 const TParticlePDG *pdg = GetType();
160
161 if(pdg == particle || particle == 0) return;
162
163 SetInfo(particle);
164 SetName(particle->GetName());
165
166 //
167 // by default:
168 // if the proper lifetime multiplied by light velocity is less
169 // than a nanometer, the object is considered a resonance
170 // (a state that does not fly)
171 //
172 fIsResonance = kFALSE;
173 if(particle->Width() > 1.0e-15) fIsResonance = kTRUE; // Lifetime() < 1.0e-08
174
175 if(!IsComposite())
176 {
177 // the mass has changed since the type has changed
178 SetMass(GetMass());
179
180 // set the charge
181 SetCharge(particle->Charge());
182 }
183 else
184 {
185 if(GetCharge() != particle->Charge())
186 {
187 cout
188 << "** ERROR: attempt to call ExRootCandidate::SetType(\""
189 << particle->ParticleClass() << "\") for a composite" << endl
190 << " ExRootCandidate whose daughters have total charge "
191 << GetCharge() << endl;
192 }
193 }
194}
195
196//------------------------------------------------------------------------------
197
198void ExRootCandidate::SetType(const char *name)
199{
200 TDatabasePDG *pdg = TDatabasePDG::Instance();
201 TParticlePDG *particle;
202 if((particle = pdg->GetParticle(name))) SetType(particle);
203}
204
205//------------------------------------------------------------------------------
206
207void ExRootCandidate::SetType(Int_t pdgCode)
208{
209 TDatabasePDG *pdg = TDatabasePDG::Instance();
210 TParticlePDG *particle;
211 if((particle = pdg->GetParticle(pdgCode))) SetType(particle);
212}
213
214//------------------------------------------------------------------------------
215// Geneology functions, no longer in a separate class
216//------------------------------------------------------------------------------
217
218void ExRootCandidate::AddDaughter(const ExRootCandidate *object)
219{
220 Add(object);
221}
222
223//------------------------------------------------------------------------------
224
225void ExRootCandidate::AddDaughter(ExRootCandidate *object)
226{
227 Add(object);
228}
229
230//------------------------------------------------------------------------------
231
232void ExRootCandidate::Add(const ExRootCandidate *object)
233{
234 Add(static_cast<ExRootCandidate *>(object->Clone()));
235}
236
237//------------------------------------------------------------------------------
238
239void ExRootCandidate::Add(ExRootCandidate *object)
240{
241 ExRootCandList::Add(object);
242
243 // as soon as there are daughters, the charge is
244 // given by the sum of the daughter charges
245 if(Size() == 0) fCharge = 0;
246
247 fCharge += object->fCharge;
248 fLorentzVector += object->fLorentzVector;
249
250 // set the daughter's mother link
251 object->fMother = this;
252}
253
254//------------------------------------------------------------------------------
255// Access functions
256//------------------------------------------------------------------------------
257
258Double_t ExRootCandidate::GetMass() const
259{
260 const TParticlePDG *pdg = GetType();
261 if(!IsComposite() && pdg)
262 return pdg->Mass();
263 else
264 return fLorentzVector.M();
265}
266
267//------------------------------------------------------------------------------
268
269TObject *ExRootCandidate::Clone(const char *newname) const
270{
271 ExRootCandidate *object = fFactory->NewCandidate();
272 Copy(*object);
273 return object;
274}
275
276//------------------------------------------------------------------------------
277
278void ExRootCandidate::Copy(TObject &obj) const
279{
280 ExRootCandidate &object = (ExRootCandidate &) obj;
281
282 ExRootCandList::Copy(obj);
283
284 object.fIsResonance = fIsResonance;
285 object.fCharge = fCharge;
286 object.fLorentzVector = fLorentzVector;
287
288 object.fMother = 0;
289
290 const ExRootCandidate *daughterOld;
291 ExRootCandidate *daughterNew;
292 ExRootCandConstIter itDaughters(Iterator());
293 while((daughterOld = itDaughters.Next()))
294 {
295 daughterNew = static_cast<ExRootCandidate *>(daughterOld->Clone());
296 object.ExRootCandList::Add(daughterNew);
297 daughterNew->fMother = static_cast<ExRootCandidate *>(&object);
298 }
299
300 map<const TClass *, TObject *>::const_iterator it;
301 for(it = fInfo.begin(); it != fInfo.end(); ++it)
302 {
303 object.SetInfo(it->second->Clone());
304 }
305}
306
307//------------------------------------------------------------------------------
308
309void ExRootCandidate::Clear()
310{
311 SetUniqueID(0);
312 fCharge = 0;
313 fLorentzVector.SetXYZT(0.0, 0.0, 0.0, 0.0);
314 fInfo.clear();
315 ExRootCandList::Clear();
316}
317
318//------------------------------------------------------------------------------
319
320const TObject *ExRootCandidate::GetInfo(const TClass *cl) const
321{
322 map<const TClass *, TObject *>::const_iterator it = fInfo.find(cl);
323
324 return (it != fInfo.end() ? it->second : 0);
325}
326
327//------------------------------------------------------------------------------
328
329TObject *ExRootCandidate::GetInfo(const TClass *cl)
330{
331 map<const TClass *, TObject *>::const_iterator it = fInfo.find(cl);
332
333 return (it != fInfo.end() ? it->second : 0);
334}
335
336//------------------------------------------------------------------------------
337
338void ExRootCandidate::SetInfo(TObject *info)
339{
340 fInfo[info->IsA()] = info;
341}
342
343//------------------------------------------------------------------------------
344
345void ExRootCandidate::Browse(TBrowser *b)
346{
347/*
348 map<const TClass *, TObject *>::const_iterator it = fInfo.find(ExRootDSTInfo::Class());
349
350 if(it != fInfo.end()) b->Add(it->second);
351*/
352 ExRootCandList::Browse(b);
353}
354
355//------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.