StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StJetCandidate.h
1 // -*- mode: c++ -*-
2 
3 //
4 // Pibero Djawotho <pibero@tamu.edu>
5 // Texas A&M University
6 // 31 August 2009
7 //
8 
9 #ifndef ST_JET_CANDIDATE_H
10 #define ST_JET_CANDIDATE_H
11 
12 #include <map>
13 #include <string>
14 using namespace std;
15 
16 #include "TLorentzVector.h"
17 #include "TRef.h"
18 #include "TRefArray.h"
19 
20 class StJetVertex;
21 class StJetElement;
22 class StJetTrack;
23 class StJetTower;
24 class StJetParticle;
25 
26 class StJetCandidate : public TObject {
27 public:
29  : mPt(0)
30  , mEta(0)
31  , mPhi(0)
32  , mE(0)
33  , mDetEta(0)
34  , mRt(0)
35  , mArea(0)
36  , mAreaError(0)
37  {
38  }
39 
40  StJetCandidate(const TVector3& vertex, const TLorentzVector& fourMomentum, float area = 0, float area_error = 0);
41 
42  TLorentzVector fourMomentum() const;
43  TVector3 momentum() const;
44 
45  float pt () const { return mPt ; }
46  float eta() const { return mEta; }
47  float phi() const { return mPhi; }
48  float E () const { return mE ; }
49  float area() const{ return mArea; }
50  float areaError() const{ return mAreaError; }
51  float px () const { return momentum().Px(); }
52  float py () const { return momentum().Py(); }
53  float pz () const { return momentum().Pz(); }
54  float detEta() const { return mDetEta; }
55  float detEta(const TVector3& vertex) const;
56  bool getBarrelDetectorEta(const TVector3& vertex, float& detEta) const;
57  bool getEndcapDetectorEta(const TVector3& vertex, float& detEta) const;
58  float sumTrackPt() const;
59  float sumTrackPt(float radius) const;
60  float sumTowerPt() const;
61  float sumTowerPt(float radius) const;
62  float sumPt() const { return sumTrackPt() + sumTowerPt(); }
63  float sumPt(float radius) const { return sumTrackPt(radius)+sumTowerPt(radius); }
64  float profile(float radius) const { return sumPt(radius)/sumPt(); }
65  float psi(float radius) const { return profile(radius); }
66  float rt() const { return mRt; }
67  float neutralFraction() const { return rt(); }
68  float chargedFraction() const { return 1 - neutralFraction(); }
69  StJetTrack* leadingChargedParticle() const;
70  float deltaPhi(const StJetCandidate* jet) const { return momentum().DeltaPhi(jet->momentum()); }
71  float deltaR(const StJetCandidate* jet) const { return momentum().DeltaR(jet->momentum()); }
72  float deltaR(const StJetElement* element) const;
73 
74  int numberOfTracks() const { return mTracks.GetEntriesFast(); }
75  int numberOfTowers() const { return mTowers.GetEntriesFast(); }
76  int numberOfParticles() const { return mParticles.GetEntriesFast(); }
77 
78  StJetVertex* vertex() const { return (StJetVertex*)mVertex.GetObject(); }
79  StJetTrack* track(int i) const { return (StJetTrack*)mTracks.At(i); }
80  StJetTower* tower(int i) const { return (StJetTower*)mTowers.At(i); }
81  StJetParticle* particle(int i) const { return (StJetParticle*)mParticles.At(i); }
82 
83  StJetTrack* getTrackById(int id) const;
84  StJetTower* getTowerById(int id) const;
85 
86  const TRefArray& tracks() const { return mTracks; }
87  const TRefArray& towers() const { return mTowers; }
88  const TRefArray& particles() const { return mParticles; }
89 
90  // Utility functions to get jet patch eta and phi from jet patch id and vice-versa
91  static float getJetPatchPhi(int jetPatch);
92  static bool getBarrelJetPatchEtaPhi(int id, float& eta, float& phi);
93  static bool getEndcapJetPatchEtaPhi(int id, float& eta, float& phi);
94  static bool getOverlapJetPatchEtaPhi(int id, float& eta, float& phi);
95 
96  static bool getBarrelJetPatchId(float eta, float phi, int& id);
97  static bool getEndcapJetPatchId(float eta, float phi, int& id);
98  static bool getOverlapJetPatchId(float eta, float phi, int& id);
99 
100  void setPtEtaPhiE(float pt, float eta, float phi, float E);
101  void setPxPyPzE(float px, float py, float pz, float E);
102  void setVertex(const StJetVertex* vertex) { mVertex = (TObject*)vertex; }
103 
104  void setUeDensity(const char* name, float density){ string str(name); mUeDensity[str] = density; }
105  map<string, float> ueDensity() const { return mUeDensity; }
106  StJetTrack* addTrack(StJetTrack* track) { mTracks.Add((TObject*)track); return (StJetTrack*)mTracks.Last(); }
107  StJetTower* addTower(StJetTower* tower) { mTowers.Add((TObject*)tower); return (StJetTower*)mTowers.Last(); }
108  StJetParticle* addParticle(StJetParticle* particle) { mParticles.Add((TObject*)particle); return (StJetParticle*)mParticles.Last(); }
109 
110 private:
111  friend class StjeJetEventTreeWriter;
112  friend class StJetMaker2009;
113 
114  float mPt;
115  float mEta;
116  float mPhi;
117  float mE;
118  float mDetEta;
119  float mRt;
120  float mArea;
121  float mAreaError;
122 
123  map<string, float> mUeDensity;
124 
125  TRef mVertex;
126  TRefArray mTracks;
127  TRefArray mTowers;
128  TRefArray mParticles;
129 
130  ClassDef(StJetCandidate,5);
131 };
132 
133 inline TLorentzVector StJetCandidate::fourMomentum() const
134 {
135  TLorentzVector fourMom;
136  fourMom.SetPtEtaPhiE(mPt, mEta, mPhi, mE);
137  return fourMom;
138 }
139 
140 inline TVector3 StJetCandidate::momentum() const
141 {
142  TVector3 mom;
143  mom.SetPtEtaPhi(mPt, mEta, mPhi);
144  return mom;
145 }
146 
147 inline void StJetCandidate::setPtEtaPhiE(float pt, float eta, float phi, float E)
148 {
149  mPt = pt;
150  mEta = eta;
151  mPhi = phi;
152  mE = E;
153 }
154 
155 inline void StJetCandidate::setPxPyPzE(float px, float py, float pz, float E)
156 {
157  TVector3 mom(px, py, pz);
158  mPt = mom.Pt();
159  mEta = mom.Eta();
160  mPhi = mom.Phi();
161  mE = E;
162 }
163 
164 #endif // ST_JET_CANDIDATE_H