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

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.9 // $Id: PlotKineMod.h,v 1.8 2009/05/12 18:41:40 loizides Exp $
3 loizides 1.1 //
4     // PlotKineMod
5     //
6 loizides 1.3 // This module allows one to quickly plot eta and pt distribution of a given particle.
7 loizides 1.1 //
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 loizides 1.5 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 loizides 1.9 void SetEntriesMax(Int_t e) { fEntriesMax = e; }
36 loizides 1.5 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 loizides 1.1
43     protected:
44 loizides 1.3 Bool_t Load();
45     void Process();
46     void SlaveBegin();
47    
48 loizides 1.1 TString fColName; //name of collection
49 loizides 1.9 Bool_t fLoadBr; //=true then load branch (def=1)
50 loizides 1.1 Double_t fPtMin; //minimum pt
51     Double_t fPtMax; //maximum pt
52     Double_t fEtaMin; //minimum eta
53     Double_t fEtaMax; //maximum eta
54 loizides 1.9 Int_t fEntriesMax; //maximum number of entries
55 loizides 1.2 const Collection<T> *fCol; //!pointer to collection
56 loizides 1.1 TH1D *fPtHist; //!pt histogram
57     TH1D *fEtaHist; //!eta histogram
58 loizides 1.9 TH1D *fEntHist; //!entries histogram
59 loizides 1.1
60 loizides 1.6 ClassDefT(PlotKineMod, 1) // Plot kinematics module
61 loizides 1.1 };
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 loizides 1.9 fLoadBr(kTRUE),
70 loizides 1.1 fPtMin(1),
71     fPtMax(5000),
72     fEtaMin(-10),
73     fEtaMax(10),
74 loizides 1.9 fEntriesMax(250),
75 loizides 1.1 fCol(0),
76     fPtHist(0),
77 loizides 1.9 fEtaHist(0),
78     fEntHist(0)
79 loizides 1.1 {
80     // Constructor.
81 loizides 1.3
82 loizides 1.9 SetFillHist(kTRUE);
83 loizides 1.3 }
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 loizides 1.1 }
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 loizides 1.3 if (!Load()) {
106 loizides 1.4 SendError(kAbortModule, "Process", "Could not load data!");
107 loizides 1.3 return;
108     }
109    
110     if (!GetFillHist())
111     return;
112 loizides 1.2
113 loizides 1.3 UInt_t ents=fCol->GetEntries();
114 loizides 1.9 fEntHist->Fill(ents);
115 loizides 1.3 for(UInt_t i=0;i<ents;++i) {
116 loizides 1.2 const T *p = fCol->At(i);
117 loizides 1.1 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 loizides 1.6
138 loizides 1.3 if (GetLoadBranch())
139 loizides 1.2 ReqBranch(GetColName(), fCol);
140 loizides 1.1
141 loizides 1.3 if (GetFillHist()) {
142 loizides 1.7 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 loizides 1.9 AddTH1(fEntHist,"hEntriesHist",";#entries;#",fEntriesMax,-0.5,fEntriesMax-0.5);
147 loizides 1.3 }
148 loizides 1.1 }
149     #endif