ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/DataTree/interface/Particle.h
Revision: 1.27
Committed: Wed Feb 18 15:38:54 2009 UTC (16 years, 2 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.26: +55 -22 lines
Log Message:
Reworked particle interface to cache FourVectorM

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.27 // $Id: Particle.h,v 1.26 2009/02/17 15:52:51 bendavid Exp $
3 loizides 1.1 //
4     // Particle
5     //
6 loizides 1.27 // General particle class. It provides an abstract interface to kinematical quantities
7     // computed by derived classes.
8 loizides 1.1 //
9 paus 1.7 // Authors: C.Loizides
10 loizides 1.1 //--------------------------------------------------------------------------------------------------
11    
12 loizides 1.18 #ifndef MITANA_DATATREE_PARTICLE_H
13     #define MITANA_DATATREE_PARTICLE_H
14 loizides 1.9
15     #include <TMath.h>
16     #include "MitAna/DataTree/interface/DataObject.h"
17 bendavid 1.26 #include "MitAna/DataTree/interface/CacheFlag.h"
18 loizides 1.9
19 loizides 1.1 namespace mithep
20     {
21 loizides 1.3 class Particle : public DataObject
22 loizides 1.1 {
23     public:
24     Particle() {}
25 loizides 1.11
26 loizides 1.27 Double_t AbsEta() const { return TMath::Abs(Eta()); }
27     Double_t Charge() const;
28 loizides 1.24 Int_t Compare(const TObject *o) const;
29 loizides 1.27 Double_t E() const { return Mom().E(); }
30     Double_t Et() const;
31     Double_t Eta() const { return Mom().Eta(); }
32     Bool_t IsSortable() const { return kTRUE; }
33     Double_t Mass() const { return Mom().M(); }
34     Double_t Mt() const { return Mom().Mt(); }
35     FourVectorM &Mom() const;
36 loizides 1.24 EObjType ObjType() const { return kParticle; }
37 loizides 1.27 Double_t Phi() const { return Mom().Phi(); }
38 loizides 1.24 Double_t PhiDeg() const { return Phi() * 180 /TMath::Pi(); }
39 loizides 1.27 Double_t Pt() const { return Mom().Pt(); }
40     Double_t Px() const { return Mom().Px(); }
41     Double_t Py() const { return Mom().Py(); }
42     Double_t Pz() const { return Mom().Pz(); }
43     Double_t P() const { return Mom().P(); }
44     Double_t Theta() const { return Mom().Theta(); }
45     Double_t TMass() const;
46 loizides 1.24 void Print(Option_t *opt="") const;
47 loizides 1.11
48 bendavid 1.26 protected:
49 loizides 1.27 virtual Double_t GetCharge() const { return 0; }
50     virtual Double_t GetMass() const { return 0; }
51     virtual void GetMom() const = 0;
52    
53     mutable CacheFlag fCacheMomFlag; //||cache validity flag for momentum
54     mutable CacheFlag fCacheQFlag; //||cache validity flag for charge
55     mutable FourVectorM fCachedMom; //!cached momentum vector (filled by derived classes)
56     mutable Double_t fCachedQ; //!chached charge value (filled by derived classes)
57    
58 loizides 1.12 ClassDef(Particle, 1) // Generic particle class
59 loizides 1.1 };
60 loizides 1.8 }
61 loizides 1.24
62     //--------------------------------------------------------------------------------------------------
63 loizides 1.27 inline Double_t mithep::Particle::Charge() const
64     {
65     // Return cached charge value.
66    
67     if (!fCacheQFlag.IsValid()) {
68     fCachedQ = GetCharge();
69     fCacheQFlag.SetValid();
70     }
71    
72     return fCachedQ;
73     }
74    
75     //--------------------------------------------------------------------------------------------------
76 loizides 1.24 inline Int_t mithep::Particle::Compare(const TObject *o) const
77     {
78     // Default compare function for sorting according to transverse momentum.
79     // Returns -1 if this object is smaller than given object, 0 if objects are
80     // equal and 1 if this is larger than given object.
81    
82     const mithep::Particle *p = dynamic_cast<const mithep::Particle *>(o);
83     if (!p)
84     return 1;
85    
86     Double_t mypt = Pt();
87     Double_t pt = p->Pt();
88     if (mypt>pt)
89     return -1;
90     else if (pt>mypt)
91     return +1;
92     return 0;
93     }
94    
95     //--------------------------------------------------------------------------------------------------
96     inline Double_t mithep::Particle::Et() const
97     {
98     // Return transverse energy.
99    
100 loizides 1.25 return E()*Pt()/P();
101     }
102    
103     //--------------------------------------------------------------------------------------------------
104 loizides 1.27 inline mithep::FourVectorM &mithep::Particle::Mom() const
105     {
106     // Return cached momentum value.
107    
108     if (!fCacheMomFlag.IsValid()) {
109     GetMom();
110     fCacheMomFlag.SetValid();
111     }
112    
113     return fCachedMom;
114     }
115    
116     //--------------------------------------------------------------------------------------------------
117 loizides 1.25 inline Double_t mithep::Particle::TMass() const
118     {
119     // Return transverse mass.
120    
121     return Mass()*Pt()/P();
122 loizides 1.24 }
123 loizides 1.8 #endif