ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/SelMods/interface/GenericSelMod.h
Revision: 1.4
Committed: Mon Mar 23 22:17:03 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009a, Mit_009, Mit_008
Changes since 1.3: +1 -2 lines
Log Message:
Cleanup

File Contents

# User Rev Content
1 loizides 1.1 //--------------------------------------------------------------------------------------------------
2 loizides 1.4 // $Id: GenericSelMod.h,v 1.3 2009/01/26 13:19:24 loizides Exp $
3 loizides 1.1 //
4     // GenericSelMod
5     //
6     // This module allows trivial event selection based on counting the number of
7     // particles found in the given kinematic range.
8     //
9     // Authors: C.Loizides
10     //--------------------------------------------------------------------------------------------------
11    
12     #ifndef MITPHYSICS_SELMODS_GENERICSELMOD_H
13     #define MITPHYSICS_SELMODS_GENERICSELMOD_H
14    
15     #include "MitAna/TreeMod/interface/BaseSelMod.h"
16 loizides 1.3 #include <TH1D.h>
17 loizides 1.1
18     namespace mithep
19     {
20     template<class T>
21     class GenericSelMod : public BaseSelMod
22     {
23     public:
24     GenericSelMod(const char *name="GenericSelMod",
25     const char *title="Generic selection 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     UInt_t GetMinCounts() const { return fMinCounts; }
32 loizides 1.2 Double_t GetMinPtMax() const { return fMinMaxPt; }
33 loizides 1.1 Double_t GetPtMin() const { return fPtMin; }
34     Double_t GetPtMax() const { return fPtMax; }
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 loizides 1.2 void SetMinMaxPt(Double_t pt) { fMinMaxPt= pt; }
40     void SetMinCounts(UInt_t c) { fMinCounts = c; }
41 loizides 1.1 void SetPtMin(Double_t pt) { fPtMin = pt; }
42     void SetPtMax(Double_t pt) { fPtMax = pt; }
43    
44     protected:
45     void Process();
46 loizides 1.3 void SlaveBegin();
47 loizides 1.1
48 loizides 1.3 TString fColName; //name of input collection
49     Double_t fPtMin; //minimum pt required (def = 0 GeV)
50     Double_t fPtMax; //maximum pt required (def = 5000 GeV)
51     Double_t fEtaMin; //minimum eta required (def = -10)
52     Double_t fEtaMax; //maximum eta required (def = +10)
53     Double_t fMinMaxPt; //min pt required for max pt (def = 0GeV)
54     UInt_t fMinCounts; //min number of particles required (def = 1)
55     const Collection<T> *fCol; //!pointer to collection
56     TH1D *fNAccCounters; //!acceptance histogram
57 loizides 1.1
58     ClassDefT(GenericSelMod,1) // Generic selection module
59     };
60     }
61    
62     //--------------------------------------------------------------------------------------------------
63     template<class T>
64     mithep::GenericSelMod<T>::GenericSelMod(const char *name, const char *title) :
65     BaseSelMod(name,title),
66     fColName("SetMe"),
67     fPtMin(0),
68     fPtMax(5000),
69     fEtaMin(-10),
70     fEtaMax(10),
71 loizides 1.3 fMinMaxPt(0),
72 loizides 1.1 fMinCounts(1),
73     fCol(0)
74     {
75     // Constructor.
76     }
77    
78     //--------------------------------------------------------------------------------------------------
79     template<class T>
80     void mithep::GenericSelMod<T>::Process()
81     {
82 loizides 1.3 // Process entries of the tree.
83    
84     fNAccCounters->Fill(0);
85 loizides 1.1
86     fCol = GetObjThisEvt<Collection<T> >(GetColName());
87     if (!fCol) {
88     this->SendError(kAbortModule, "Process",
89     "Could not obtain collection with name %s!", GetColName());
90     return;
91     }
92    
93 loizides 1.3 fNAccCounters->Fill(1);
94    
95 loizides 1.1 UInt_t counter = 0;
96     UInt_t ents=this->fCol->GetEntries();
97     for(UInt_t i=0;i<ents;++i) {
98     const T *p = this->fCol->At(i);
99     Double_t pt = p->Pt();
100     if (pt<this->fPtMin)
101     continue;
102     if (pt>this->fPtMax)
103     continue;
104     Double_t eta = p->Eta();
105     if (eta<this->fEtaMin)
106     continue;
107     if (eta>this->fEtaMax)
108     continue;
109    
110 loizides 1.3 if (i==0) { // check particle with largest pt
111     if (pt<fMinMaxPt) {
112     this->SkipEvent();
113     return;
114     }
115     }
116 loizides 1.1 ++counter;
117     }
118    
119 loizides 1.3 fNAccCounters->Fill(2);
120    
121 loizides 1.1 // skip event if not enough particles are found in kinematic region
122 loizides 1.3 if (counter<GetMinCounts()) {
123 loizides 1.1 this->SkipEvent();
124 loizides 1.3 return;
125     }
126    
127     fNAccCounters->Fill(3);
128     }
129    
130     //--------------------------------------------------------------------------------------------------
131     template<class T>
132     void mithep::GenericSelMod<T>::SlaveBegin()
133     {
134     // Setup acceptence histogram.
135    
136     AddTH1(fNAccCounters,"hNAccCounters",";cut;#",25,-0.5,24.5);
137     if (1) {
138     TAxis *xa = fNAccCounters->GetXaxis();
139     for(Int_t i=1;i<=fNAccCounters->GetNbinsX();++i)
140     xa->SetBinLabel(i,"unused");
141     xa->SetBinLabel(1,"Enter");
142     xa->SetBinLabel(2,"Objs");
143     xa->SetBinLabel(3,"MinMax");
144     xa->SetBinLabel(4,"Counts");
145     xa->SetRangeUser(0,3);
146     }
147 loizides 1.1 }
148     #endif