ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/PhysicsMod/interface/PlotKineMod.h
Revision: 1.8
Committed: Tue May 12 18:41:40 2009 UTC (15 years, 11 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.7: +1 -2 lines
Log Message:
Save number of triggered events.

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: PlotKineMod.h,v 1.7 2008/12/12 16:03:12 loizides Exp $
3 //
4 // PlotKineMod
5 //
6 // This module allows one to quickly plot eta and pt distribution of a given particle.
7 //
8 // Authors: C.Loizides
9 //--------------------------------------------------------------------------------------------------
10
11 #ifndef MITANA_PHYSICSMOD_PLOTKINEMOD_H
12 #define MITANA_PHYSICSMOD_PLOTKINEMOD_H
13
14 #include "MitAna/TreeMod/interface/BaseMod.h"
15 #include "MitAna/DataTree/interface/Collections.h"
16 #include <TH1D.h>
17
18 namespace mithep
19 {
20 template<class T>
21 class PlotKineMod : public BaseMod
22 {
23 public:
24 PlotKineMod(const char *name="PlotKineMod",
25 const char *title="Plot kinematics module");
26
27 const char *GetColName() const { return fColName; }
28 Double_t GetEtaMin() const { return fEtaMin; }
29 Double_t GetEtaMax() const { return fEtaMax; }
30 const char *GetInputName() const { return GetColName(); }
31 Double_t GetPtMin() const { return fPtMin; }
32 Double_t GetPtMax() const { return fPtMax; }
33 Bool_t GetLoadBranch() const { return fLoadBr; }
34 void SetColName(const char *n) { fColName=n; }
35 void SetEtaMin(Double_t e) { fEtaMin = e; }
36 void SetEtaMax(Double_t e) { fEtaMax = e; }
37 void SetInputName(const char *n) { SetColName(n); }
38 void SetLoadBranch(Bool_t b) { fLoadBr = b; }
39 void SetPtMin(Double_t pt) { fPtMin = pt; }
40 void SetPtMax(Double_t pt) { fPtMax = pt; }
41
42 protected:
43 Bool_t Load();
44 void Process();
45 void SlaveBegin();
46
47 TString fColName; //name of collection
48 Double_t fPtMin; //minimum pt
49 Double_t fPtMax; //maximum pt
50 Double_t fEtaMin; //minimum eta
51 Double_t fEtaMax; //maximum eta
52 Bool_t fLoadBr; //=true then load branch (def=1)
53 const Collection<T> *fCol; //!pointer to collection
54 TH1D *fPtHist; //!pt histogram
55 TH1D *fEtaHist; //!eta histogram
56
57 ClassDefT(PlotKineMod, 1) // Plot kinematics module
58 };
59 }
60
61 //--------------------------------------------------------------------------------------------------
62 template<class T>
63 mithep::PlotKineMod<T>::PlotKineMod(const char *name, const char *title) :
64 BaseMod(name,title),
65 fColName("SetMe"),
66 fPtMin(1),
67 fPtMax(5000),
68 fEtaMin(-10),
69 fEtaMax(10),
70 fLoadBr(kTRUE),
71 fCol(0),
72 fPtHist(0),
73 fEtaHist(0)
74 {
75 // Constructor.
76
77 SetFillHist(1);
78 }
79
80 //--------------------------------------------------------------------------------------------------
81 template<class T>
82 Bool_t mithep::PlotKineMod<T>::Load()
83 {
84 // Load data from branch or get pointer from event.
85
86 if (GetLoadBranch())
87 LoadBranch(GetColName());
88 else
89 fCol = GetObjThisEvt<Collection<T> >(GetColName());
90
91 return (fCol!=0);
92 }
93
94 //--------------------------------------------------------------------------------------------------
95 template<class T>
96 void mithep::PlotKineMod<T>::Process()
97 {
98 // Process entries of the tree: Just load the branch and fill the histograms.
99
100 if (!Load()) {
101 SendError(kAbortModule, "Process", "Could not load data!");
102 return;
103 }
104
105 if (!GetFillHist())
106 return;
107
108 UInt_t ents=fCol->GetEntries();
109 for(UInt_t i=0;i<ents;++i) {
110 const T *p = fCol->At(i);
111 Double_t pt = p->Pt();
112 if (pt<fPtMin)
113 continue;
114 if (pt>fPtMax)
115 continue;
116 Double_t eta = p->Eta();
117 if (eta<fEtaMin)
118 continue;
119 if (eta>fEtaMax)
120 continue;
121 fPtHist->Fill(pt);
122 fEtaHist->Fill(eta);
123 }
124 }
125
126 //--------------------------------------------------------------------------------------------------
127 template<class T>
128 void mithep::PlotKineMod<T>::SlaveBegin()
129 {
130 // Request a branch and create the histograms.
131
132 if (GetLoadBranch())
133 ReqBranch(GetColName(), fCol);
134
135 if (GetFillHist()) {
136 Int_t ptbins = (Int_t)((fPtMax-fPtMin)/2.5);
137 AddTH1(fPtHist,"hPtHist",";p_{t} [GeV];#",ptbins,fPtMin,fPtMax);
138 Int_t etabins = (Int_t)((fEtaMax-fEtaMin)/0.1);
139 AddTH1(fEtaHist,"hEtaHist",";#eta;#",etabins,fEtaMin,fEtaMax);
140 }
141 }
142 #endif