ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/src/MCParticle.cc
Revision: 1.3
Committed: Mon Nov 24 11:51:21 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.2: +52 -2 lines
Log Message:
Added FindMother and FindDaughter methods.

File Contents

# User Rev Content
1 loizides 1.3 // $Id: MCParticle.cc,v 1.2 2008/11/21 20:15:02 loizides Exp $
2 bendavid 1.1
3     #include "MitAna/DataTree/interface/MCParticle.h"
4    
5     ClassImp(mithep::MCParticle)
6    
7     using namespace mithep;
8    
9     //--------------------------------------------------------------------------------------------------
10     Double_t MCParticle::Charge() const
11     {
12 loizides 1.3 // Get charge from pdg lookup.
13 bendavid 1.1
14     TParticlePDG* pdgEntry = PdgEntry();
15     if (pdgEntry)
16     return pdgEntry->Charge()/3.0;
17     else {
18 loizides 1.2 Error("Charge", "Pdg code %i not found in table, returning charge=-99.0", fPdgId);
19 bendavid 1.1 return -99.0;
20     }
21     }
22    
23     //--------------------------------------------------------------------------------------------------
24 loizides 1.3 const MCParticle *MCParticle::FindDaughter(Int_t pid,
25     Bool_t checkCharge, const MCParticle *start) const
26     {
27     // Return daughter with given pid. If checkCharge is false then just the type of particle is
28     // checked (ie particle and anti-particle). If start is not null, start searching from
29     // this daughter.
30    
31     UInt_t i = 0;
32     if (start) {
33     for (; i<NDaughters(); ++i) {
34     if (Daughter(i)==start) {
35     ++i;
36     break;
37     }
38     }
39     return 0;
40     }
41    
42     for (UInt_t j=i; j<NDaughters(); ++j) {
43     if (Daughter(j)->Is(pid,checkCharge))
44     return Daughter(j);
45     }
46    
47     return 0;
48     }
49    
50     //--------------------------------------------------------------------------------------------------
51     const MCParticle *MCParticle::FindMother(Int_t pid, Bool_t checkCharge) const
52     {
53     // Return mother with given pid. If checkCharge is false then just the type of particle is
54     // checked (ie particle and anti-particle).
55    
56     const MCParticle *mother = Mother();
57     if (!mother)
58     return 0;
59    
60     if (checkCharge) {
61     while (mother->PdgId()==fPdgId)
62     mother = mother->Mother();
63     return mother;
64     }
65    
66     Int_t apid = pid>0?pid:-pid;
67     while (mother->AbsPdgId()==apid)
68     mother = mother->Mother();
69    
70     return mother;
71     }
72    
73     //--------------------------------------------------------------------------------------------------
74 loizides 1.2 void MCParticle::Print(Option_t *opt) const
75 bendavid 1.1 {
76 loizides 1.2 // Print particle kinematics. In case option "l" is given then also print info about daughters.
77    
78     printf("id=%5d st=%2d nd=%3d gen=%d px=%.3f py=%.3f pz=%.3f e=%.3f\n",
79     PdgId(), Status(), NDaughters(), IsGenerated(), Px(), Py(), Pz(), E());
80    
81     if (opt && opt[0]=='l') {
82     for (UInt_t i=0; i<NDaughters(); ++i) {
83     printf(" %2d -> id=%5d st=%2d gen=%d px=%.3f py=%.3f pz=%.3f e=%.3f\n",
84     i, Daughter(i)->PdgId(), Daughter(i)->Status(), Daughter(i)->IsGenerated(),
85     Daughter(i)->Px(), Daughter(i)->Py(), Daughter(i)->Pz(), Daughter(i)->E());
86     }
87     }
88 bendavid 1.1 }