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

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.8 // $Id: PlotKineMod.h,v 1.7 2008/12/12 16:03:12 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     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 loizides 1.1
42     protected:
43 loizides 1.3 Bool_t Load();
44     void Process();
45     void SlaveBegin();
46    
47 loizides 1.1 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 loizides 1.2 Bool_t fLoadBr; //=true then load branch (def=1)
53     const Collection<T> *fCol; //!pointer to collection
54 loizides 1.1 TH1D *fPtHist; //!pt histogram
55     TH1D *fEtaHist; //!eta histogram
56    
57 loizides 1.6 ClassDefT(PlotKineMod, 1) // Plot kinematics module
58 loizides 1.1 };
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 loizides 1.2 fLoadBr(kTRUE),
71 loizides 1.1 fCol(0),
72     fPtHist(0),
73     fEtaHist(0)
74     {
75     // Constructor.
76 loizides 1.3
77 loizides 1.4 SetFillHist(1);
78 loizides 1.3 }
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 loizides 1.1 }
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 loizides 1.3 if (!Load()) {
101 loizides 1.4 SendError(kAbortModule, "Process", "Could not load data!");
102 loizides 1.3 return;
103     }
104    
105     if (!GetFillHist())
106     return;
107 loizides 1.2
108 loizides 1.3 UInt_t ents=fCol->GetEntries();
109     for(UInt_t i=0;i<ents;++i) {
110 loizides 1.2 const T *p = fCol->At(i);
111 loizides 1.1 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 loizides 1.6
132 loizides 1.3 if (GetLoadBranch())
133 loizides 1.2 ReqBranch(GetColName(), fCol);
134 loizides 1.1
135 loizides 1.3 if (GetFillHist()) {
136 loizides 1.7 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 loizides 1.3 }
141 loizides 1.1 }
142     #endif