1 |
loizides |
1.6 |
//--------------------------------------------------------------------------------------------------
|
2 |
loizides |
1.19 |
// $Id: BaseMod.h,v 1.18 2009/04/29 08:43:33 loizides Exp $
|
3 |
loizides |
1.2 |
//
|
4 |
|
|
// BaseMod
|
5 |
|
|
//
|
6 |
loizides |
1.8 |
// This TAM module is the base module for all our TAM modules. It defines a couple of useful
|
7 |
|
|
// getters to retrieve information from the underlying framework code, such as the EventHeader,
|
8 |
|
|
// RunInfo or Trigger information.
|
9 |
loizides |
1.2 |
//
|
10 |
|
|
// Authors: C.Loizides
|
11 |
loizides |
1.6 |
//--------------------------------------------------------------------------------------------------
|
12 |
loizides |
1.2 |
|
13 |
loizides |
1.7 |
#ifndef MITANA_TREEMOD_BASEMOD_H
|
14 |
|
|
#define MITANA_TREEMOD_BASEMOD_H
|
15 |
loizides |
1.1 |
|
16 |
loizides |
1.19 |
#include <TObjString.h>
|
17 |
loizides |
1.1 |
#include "MitAna/TAM/interface/TAModule.h"
|
18 |
loizides |
1.8 |
#include "MitAna/TreeMod/interface/Selector.h"
|
19 |
|
|
#include "MitAna/DataTree/interface/Collections.h"
|
20 |
|
|
#include "MitAna/DataTree/interface/TriggerName.h"
|
21 |
|
|
#include "MitAna/DataTree/interface/TriggerObject.h"
|
22 |
loizides |
1.1 |
|
23 |
|
|
namespace mithep
|
24 |
|
|
{
|
25 |
loizides |
1.5 |
class Selector;
|
26 |
loizides |
1.12 |
class HLTFwkMod;
|
27 |
loizides |
1.5 |
|
28 |
loizides |
1.1 |
class BaseMod : public TAModule {
|
29 |
|
|
public:
|
30 |
loizides |
1.12 |
BaseMod(const char *name="BaseMod", const char *title="Base analysis module");
|
31 |
loizides |
1.4 |
|
32 |
loizides |
1.19 |
private:
|
33 |
|
|
class ObjType : public TObjString {
|
34 |
|
|
public:
|
35 |
|
|
ObjType(const char *name="", Bool_t br=kTRUE) : TObjString(name), fBr(br) {}
|
36 |
|
|
~ObjType() {}
|
37 |
|
|
Bool_t IsBranch() const { return fBr; }
|
38 |
|
|
protected:
|
39 |
|
|
Bool_t fBr; //=true then object is from branch
|
40 |
|
|
};
|
41 |
|
|
|
42 |
loizides |
1.4 |
protected:
|
43 |
loizides |
1.19 |
void AddEventObject(const char *name, Bool_t fromBr=kTRUE);
|
44 |
loizides |
1.14 |
template <class T> void AddTH1(T *&ptr, const char *name, const char *title,
|
45 |
|
|
Int_t nbins, Double_t xmin, Double_t xmax);
|
46 |
|
|
template <class T> void AddTH2(T *&ptr, const char *name, const char *title,
|
47 |
|
|
Int_t nbinsx, Double_t xmin, Double_t xmax,
|
48 |
|
|
Int_t nbinsy, Double_t ymin, Double_t ymax);
|
49 |
phedex |
1.17 |
template <class T> void AddTH3(T *&ptr, const char *name, const char *title,
|
50 |
|
|
Int_t nbinsx, Double_t xmin, Double_t xmax,
|
51 |
|
|
Int_t nbinsy, Double_t ymin, Double_t ymax,
|
52 |
|
|
Int_t nbinsz, Double_t zmin, Double_t zmax);
|
53 |
loizides |
1.9 |
const EventHeader *GetEventHeader() const { return GetSel()->GetEventHeader(); }
|
54 |
loizides |
1.19 |
Bool_t GetFillHist() const { return fFillHist; }
|
55 |
|
|
const HLTFwkMod *GetHltFwkMod() const { return fHltFwkMod; }
|
56 |
loizides |
1.12 |
const TriggerObjectCol *GetHLTObjects(const char *name) const;
|
57 |
|
|
const TriggerObjectsTable *GetHLTObjectsTable() const;
|
58 |
|
|
const TriggerTable *GetHLTTable() const;
|
59 |
loizides |
1.19 |
Int_t GetNEventsProcessed() const { return fNEventsProc; }
|
60 |
loizides |
1.18 |
template <class T> const T *GetObjThisEvt(const char *name, Bool_t warn=1) const;
|
61 |
|
|
template <class T> T *GetObjThisEvt(const char *name, Bool_t warn=1);
|
62 |
|
|
template <class T> const T *GetPublicObj(const char *name, Bool_t warn=1) const;
|
63 |
|
|
template <class T> T *GetPublicObj(const char *name, Bool_t warn=1);
|
64 |
loizides |
1.19 |
const RunInfo *GetRunInfo() const { return GetSel()->GetRunInfo(); }
|
65 |
loizides |
1.9 |
const Selector *GetSel() const;
|
66 |
loizides |
1.12 |
Bool_t HasHLTInfo() const;
|
67 |
loizides |
1.19 |
void IncNEventsProcessed() { ++fNEventsProc; }
|
68 |
|
|
template <class T> Bool_t LoadEventObject(const char *name, const T *&addr, Bool_t warn=1);
|
69 |
|
|
template <class T> void ReqBranch(const char *bname, const T *&addr);
|
70 |
|
|
template <class T> void ReqEventObject(const char *name, const T *&addr);
|
71 |
|
|
template <class T> void ReqEventObject(const char *name, const T *&addr, Bool_t fromBr);
|
72 |
loizides |
1.9 |
void SaveNEventsProcessed(const char *name="hDEvents");
|
73 |
loizides |
1.19 |
void SetFillHist(Bool_t b) { fFillHist = b; }
|
74 |
|
|
Bool_t ValidRunInfo() const { return GetSel()->ValidRunInfo(); }
|
75 |
loizides |
1.9 |
|
76 |
|
|
private:
|
77 |
loizides |
1.14 |
Bool_t fFillHist; //=true then fill histos (def=0)
|
78 |
loizides |
1.19 |
THashTable fEvtObjBrNames; //names of per-event objects
|
79 |
loizides |
1.12 |
mutable const HLTFwkMod *fHltFwkMod; //!pointer to HLTFwdMod
|
80 |
|
|
const TString fHltFwkModName; //!name of HLTFwkMod
|
81 |
loizides |
1.14 |
Int_t fNEventsProc; //!number of events
|
82 |
loizides |
1.1 |
|
83 |
loizides |
1.15 |
ClassDef(BaseMod, 1) // Base TAM module
|
84 |
loizides |
1.1 |
};
|
85 |
loizides |
1.6 |
}
|
86 |
loizides |
1.4 |
|
87 |
loizides |
1.6 |
//--------------------------------------------------------------------------------------------------
|
88 |
loizides |
1.19 |
inline void mithep::BaseMod::AddEventObject(const char *name, Bool_t fromBr)
|
89 |
|
|
{
|
90 |
|
|
// Add event object to list of objects that should be retrieved from a branch rather
|
91 |
|
|
// than from a pointer given by the event.
|
92 |
|
|
|
93 |
|
|
if (fEvtObjBrNames.FindObject(name)) {
|
94 |
|
|
SendError(kWarning, "AddEventObject",
|
95 |
|
|
"Can not add event object with name %s and type %d",
|
96 |
|
|
name, fromBr);
|
97 |
|
|
return;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
fEvtObjBrNames.Add(new ObjType(name,fromBr));
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
//--------------------------------------------------------------------------------------------------
|
104 |
loizides |
1.14 |
template <class T>
|
105 |
|
|
inline void mithep::BaseMod::AddTH1(T *&ptr, const char *name, const char *title,
|
106 |
|
|
Int_t nbins, Double_t xmin, Double_t xmax)
|
107 |
|
|
{
|
108 |
|
|
// Create ROOT histogram and add it to the output list.
|
109 |
|
|
|
110 |
|
|
ptr = new T(name, title, nbins, xmin, xmax);
|
111 |
|
|
ptr->Sumw2();
|
112 |
|
|
AddOutput(ptr);
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
//--------------------------------------------------------------------------------------------------
|
116 |
|
|
template <class T>
|
117 |
|
|
inline void mithep::BaseMod::AddTH2(T *&ptr, const char *name, const char *title,
|
118 |
|
|
Int_t nbinsx, Double_t xmin, Double_t xmax,
|
119 |
|
|
Int_t nbinsy, Double_t ymin, Double_t ymax)
|
120 |
|
|
{
|
121 |
|
|
// Create ROOT histogram and add it to the output list.
|
122 |
|
|
|
123 |
|
|
ptr = new T(name, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
|
124 |
|
|
ptr->Sumw2();
|
125 |
|
|
AddOutput(ptr);
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
//--------------------------------------------------------------------------------------------------
|
129 |
phedex |
1.17 |
template <class T>
|
130 |
|
|
inline void mithep::BaseMod::AddTH3(T *&ptr, const char *name, const char *title,
|
131 |
|
|
Int_t nbinsx, Double_t xmin, Double_t xmax,
|
132 |
|
|
Int_t nbinsy, Double_t ymin, Double_t ymax,
|
133 |
|
|
Int_t nbinsz, Double_t zmin, Double_t zmax)
|
134 |
|
|
{
|
135 |
|
|
// Create ROOT histogram and add it to the output list.
|
136 |
|
|
|
137 |
|
|
ptr = new T(name, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax, nbinsz, zmin, zmax);
|
138 |
|
|
ptr->Sumw2();
|
139 |
|
|
AddOutput(ptr);
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
//--------------------------------------------------------------------------------------------------
|
143 |
loizides |
1.8 |
inline const mithep::TriggerObjectCol *mithep::BaseMod::GetHLTObjects(const char *name) const
|
144 |
|
|
{
|
145 |
|
|
// Get pointer to HLT TriggerObjects collection with given name for the current event.
|
146 |
|
|
|
147 |
|
|
return (dynamic_cast<const TriggerObjectCol *>(FindObjThisEvt(name)));
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
//--------------------------------------------------------------------------------------------------
|
151 |
loizides |
1.10 |
template <class T>
|
152 |
loizides |
1.18 |
inline const T *mithep::BaseMod::GetObjThisEvt(const char *name, Bool_t warn) const
|
153 |
loizides |
1.13 |
{
|
154 |
|
|
// Get published object for the current event.
|
155 |
|
|
|
156 |
|
|
T *ret = dynamic_cast<T*>(FindObjThisEvt(name));
|
157 |
loizides |
1.18 |
if (!ret && warn) {
|
158 |
loizides |
1.13 |
SendError(kWarning, "GetObjThisEvent",
|
159 |
|
|
"Could not obtain object with name %s and type %s for current event!",
|
160 |
|
|
name, T::Class_Name());
|
161 |
|
|
}
|
162 |
|
|
return ret;
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
//--------------------------------------------------------------------------------------------------
|
166 |
|
|
template <class T>
|
167 |
loizides |
1.18 |
inline T *mithep::BaseMod::GetObjThisEvt(const char *name, Bool_t warn)
|
168 |
loizides |
1.10 |
{
|
169 |
|
|
// Get published object for the current event.
|
170 |
|
|
|
171 |
|
|
T *ret = dynamic_cast<T*>(FindObjThisEvt(name));
|
172 |
loizides |
1.18 |
if (!ret && warn) {
|
173 |
loizides |
1.10 |
SendError(kWarning, "GetObjThisEvent",
|
174 |
|
|
"Could not obtain object with name %s and type %s for current event!",
|
175 |
|
|
name, T::Class_Name());
|
176 |
|
|
}
|
177 |
|
|
return ret;
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
//--------------------------------------------------------------------------------------------------
|
181 |
|
|
template <class T>
|
182 |
loizides |
1.18 |
inline const T *mithep::BaseMod::GetPublicObj(const char *name, Bool_t warn) const
|
183 |
loizides |
1.13 |
{
|
184 |
|
|
// Get public object.
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
T *ret = dynamic_cast<T*>(FindPublicObj(name));
|
188 |
loizides |
1.18 |
if (!ret && warn) {
|
189 |
loizides |
1.13 |
SendError(kWarning, "GetPublicObject",
|
190 |
|
|
"Could not obtain public object with name %s and type %s!",
|
191 |
|
|
name, T::Class_Name());
|
192 |
|
|
}
|
193 |
|
|
return ret;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
//--------------------------------------------------------------------------------------------------
|
197 |
|
|
template <class T>
|
198 |
loizides |
1.18 |
inline T *mithep::BaseMod::GetPublicObj(const char *name, Bool_t warn)
|
199 |
loizides |
1.10 |
{
|
200 |
|
|
// Get public object.
|
201 |
|
|
|
202 |
|
|
T *ret = dynamic_cast<T*>(FindPublicObj(name));
|
203 |
loizides |
1.18 |
if (!ret && warn) {
|
204 |
loizides |
1.10 |
SendError(kWarning, "GetPublicObject",
|
205 |
|
|
"Could not obtain public object with name %s and type %s!",
|
206 |
|
|
name, T::Class_Name());
|
207 |
|
|
}
|
208 |
|
|
return ret;
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
//--------------------------------------------------------------------------------------------------
|
212 |
loizides |
1.6 |
inline const mithep::Selector *mithep::BaseMod::GetSel() const
|
213 |
|
|
{
|
214 |
loizides |
1.8 |
// Get pointer to selector.
|
215 |
|
|
|
216 |
loizides |
1.6 |
return static_cast<const Selector*>(GetSelector());
|
217 |
loizides |
1.1 |
}
|
218 |
loizides |
1.13 |
|
219 |
|
|
//--------------------------------------------------------------------------------------------------
|
220 |
|
|
template <class T>
|
221 |
loizides |
1.19 |
inline Bool_t mithep::BaseMod::LoadEventObject(const char *name, const T *&addr, Bool_t warn)
|
222 |
loizides |
1.13 |
{
|
223 |
loizides |
1.19 |
// Obtain the object with the specified name that has been requested during processing.
|
224 |
|
|
// In case name is found in fEvtObjBrNames it will be read from a branch to the
|
225 |
|
|
// address specified in ReqEventObject.
|
226 |
|
|
|
227 |
|
|
TString type("event");
|
228 |
|
|
ObjType *o = static_cast<ObjType*>(fEvtObjBrNames.FindObject(name));
|
229 |
|
|
if (o && o->IsBranch()) {
|
230 |
|
|
type = "branch";
|
231 |
|
|
LoadBranch(name);
|
232 |
|
|
} else {
|
233 |
|
|
addr = GetObjThisEvt<T>(name);
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
Bool_t ret = (addr!=0);
|
237 |
|
|
if (!ret && warn) {
|
238 |
|
|
SendError(kWarning, "LoadEventObject",
|
239 |
|
|
"Could not obtain object with name %s and type %s from %s!",
|
240 |
|
|
name, T::Class_Name(), type.Data());
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
return ret;
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
//--------------------------------------------------------------------------------------------------
|
247 |
|
|
template <class T>
|
248 |
|
|
inline void mithep::BaseMod::ReqBranch(const char *bname, const T *&addr)
|
249 |
|
|
{
|
250 |
|
|
// Requests that the branch with the specified name is made available
|
251 |
loizides |
1.13 |
// during processing and that it be read in to the address specified.
|
252 |
|
|
|
253 |
loizides |
1.19 |
TAModule::ReqBranch(bname, const_cast<T*&>(addr));
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
//--------------------------------------------------------------------------------------------------
|
257 |
|
|
template <class T>
|
258 |
|
|
inline void mithep::BaseMod::ReqEventObject(const char *name, const T *&addr)
|
259 |
|
|
{
|
260 |
|
|
// Requests that the object with the specified name is made available
|
261 |
|
|
// during processing. In case name is found in fEvtObjBrNames it
|
262 |
|
|
// will be read from a branch to the address specified.
|
263 |
|
|
|
264 |
|
|
ObjType *o = static_cast<ObjType*>(fEvtObjBrNames.FindObject(name));
|
265 |
|
|
if (!o || !o->IsBranch())
|
266 |
|
|
return;
|
267 |
|
|
|
268 |
|
|
ReqBranch(name, addr);
|
269 |
|
|
}
|
270 |
|
|
|
271 |
|
|
//--------------------------------------------------------------------------------------------------
|
272 |
|
|
template <class T>
|
273 |
|
|
inline void mithep::BaseMod::ReqEventObject(const char *name, const T *&addr, Bool_t fromBr)
|
274 |
|
|
{
|
275 |
|
|
// Requests that the object with the specified name is made available
|
276 |
|
|
// during processing. In case name is found in fEvtObjBrNames it
|
277 |
|
|
// will be read from a branch to the address specified.
|
278 |
|
|
|
279 |
|
|
ObjType *o = static_cast<ObjType*>(fEvtObjBrNames.FindObject(name));
|
280 |
|
|
if (!o && fromBr)
|
281 |
|
|
AddEventObject(name, fromBr);
|
282 |
|
|
|
283 |
|
|
ReqEventObject(name, addr);
|
284 |
loizides |
1.13 |
}
|
285 |
loizides |
1.1 |
#endif
|