ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/PhysicsMod/interface/PlotKineMod.h
Revision: 1.9
Committed: Mon May 18 06:30:38 2009 UTC (15 years, 11 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.8: +12 -5 lines
Log Message:
Added FilterMod to filter out particles from collection based on eta/pt cuts.

File Contents

# Content
1 //--------------------------------------------------------------------------------------------------
2 // $Id: PlotKineMod.h,v 1.8 2009/05/12 18:41:40 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 SetEntriesMax(Int_t e) { fEntriesMax = e; }
36 void SetEtaMin(Double_t e) { fEtaMin = e; }
37 void SetEtaMax(Double_t e) { fEtaMax = e; }
38 void SetInputName(const char *n) { SetColName(n); }
39 void SetLoadBranch(Bool_t b) { fLoadBr = b; }
40 void SetPtMin(Double_t pt) { fPtMin = pt; }
41 void SetPtMax(Double_t pt) { fPtMax = pt; }
42
43 protected:
44 Bool_t Load();
45 void Process();
46 void SlaveBegin();
47
48 TString fColName; //name of collection
49 Bool_t fLoadBr; //=true then load branch (def=1)
50 Double_t fPtMin; //minimum pt
51 Double_t fPtMax; //maximum pt
52 Double_t fEtaMin; //minimum eta
53 Double_t fEtaMax; //maximum eta
54 Int_t fEntriesMax; //maximum number of entries
55 const Collection<T> *fCol; //!pointer to collection
56 TH1D *fPtHist; //!pt histogram
57 TH1D *fEtaHist; //!eta histogram
58 TH1D *fEntHist; //!entries histogram
59
60 ClassDefT(PlotKineMod, 1) // Plot kinematics module
61 };
62 }
63
64 //--------------------------------------------------------------------------------------------------
65 template<class T>
66 mithep::PlotKineMod<T>::PlotKineMod(const char *name, const char *title) :
67 BaseMod(name,title),
68 fColName("SetMe"),
69 fLoadBr(kTRUE),
70 fPtMin(1),
71 fPtMax(5000),
72 fEtaMin(-10),
73 fEtaMax(10),
74 fEntriesMax(250),
75 fCol(0),
76 fPtHist(0),
77 fEtaHist(0),
78 fEntHist(0)
79 {
80 // Constructor.
81
82 SetFillHist(kTRUE);
83 }
84
85 //--------------------------------------------------------------------------------------------------
86 template<class T>
87 Bool_t mithep::PlotKineMod<T>::Load()
88 {
89 // Load data from branch or get pointer from event.
90
91 if (GetLoadBranch())
92 LoadBranch(GetColName());
93 else
94 fCol = GetObjThisEvt<Collection<T> >(GetColName());
95
96 return (fCol!=0);
97 }
98
99 //--------------------------------------------------------------------------------------------------
100 template<class T>
101 void mithep::PlotKineMod<T>::Process()
102 {
103 // Process entries of the tree: Just load the branch and fill the histograms.
104
105 if (!Load()) {
106 SendError(kAbortModule, "Process", "Could not load data!");
107 return;
108 }
109
110 if (!GetFillHist())
111 return;
112
113 UInt_t ents=fCol->GetEntries();
114 fEntHist->Fill(ents);
115 for(UInt_t i=0;i<ents;++i) {
116 const T *p = fCol->At(i);
117 Double_t pt = p->Pt();
118 if (pt<fPtMin)
119 continue;
120 if (pt>fPtMax)
121 continue;
122 Double_t eta = p->Eta();
123 if (eta<fEtaMin)
124 continue;
125 if (eta>fEtaMax)
126 continue;
127 fPtHist->Fill(pt);
128 fEtaHist->Fill(eta);
129 }
130 }
131
132 //--------------------------------------------------------------------------------------------------
133 template<class T>
134 void mithep::PlotKineMod<T>::SlaveBegin()
135 {
136 // Request a branch and create the histograms.
137
138 if (GetLoadBranch())
139 ReqBranch(GetColName(), fCol);
140
141 if (GetFillHist()) {
142 Int_t ptbins = (Int_t)((fPtMax-fPtMin)/2.5);
143 AddTH1(fPtHist,"hPtHist",";p_{t} [GeV];#",ptbins,fPtMin,fPtMax);
144 Int_t etabins = (Int_t)((fEtaMax-fEtaMin)/0.1);
145 AddTH1(fEtaHist,"hEtaHist",";#eta;#",etabins,fEtaMin,fEtaMax);
146 AddTH1(fEntHist,"hEntriesHist",";#entries;#",fEntriesMax,-0.5,fEntriesMax-0.5);
147 }
148 }
149 #endif