ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/PhysicsMod/interface/PlotKineMod.h
Revision: 1.4
Committed: Wed Dec 10 16:29:30 2008 UTC (16 years, 4 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.3: +3 -5 lines
Log Message:
Cleanup

File Contents

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