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

File Contents

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