ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/interface/BaseMod.h
Revision: 1.14
Committed: Tue Dec 9 10:16:24 2008 UTC (16 years, 4 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.13: +37 -4 lines
Log Message:
Added function to add histograms to output.

File Contents

# User Rev Content
1 loizides 1.6 //--------------------------------------------------------------------------------------------------
2 loizides 1.14 // $Id: BaseMod.h,v 1.13 2008/12/04 13:48:34 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     #include "MitAna/TAM/interface/TAModule.h"
17 loizides 1.8 #include "MitAna/TreeMod/interface/Selector.h"
18     #include "MitAna/DataTree/interface/Collections.h"
19     #include "MitAna/DataTree/interface/TriggerName.h"
20     #include "MitAna/DataTree/interface/TriggerObject.h"
21 loizides 1.1
22     namespace mithep
23     {
24 loizides 1.5 class Selector;
25 loizides 1.12 class HLTFwkMod;
26 loizides 1.5
27 loizides 1.1 class BaseMod : public TAModule {
28     public:
29 loizides 1.12 BaseMod(const char *name="BaseMod", const char *title="Base analysis module");
30 loizides 1.4 ~BaseMod() {}
31    
32     protected:
33 loizides 1.14 template <class T> void AddTH1(T *&ptr, const char *name, const char *title,
34     Int_t nbins, Double_t xmin, Double_t xmax);
35     template <class T> void AddTH2(T *&ptr, const char *name, const char *title,
36     Int_t nbinsx, Double_t xmin, Double_t xmax,
37     Int_t nbinsy, Double_t ymin, Double_t ymax);
38     void IncNEventsProcessed() { ++fNEventsProc; }
39 loizides 1.9 const EventHeader *GetEventHeader() const { return GetSel()->GetEventHeader(); }
40 loizides 1.14 Bool_t GetFillHist() const { return fFillHist; }
41 loizides 1.12 const HLTFwkMod *GetHltFwkMod() const { return fHltFwkMod; }
42     const TriggerObjectCol *GetHLTObjects(const char *name) const;
43     const TriggerObjectsTable *GetHLTObjectsTable() const;
44     const TriggerTable *GetHLTTable() const;
45 loizides 1.14 Int_t GetNEventsProcessed() const { return fNEventsProc; }
46 loizides 1.13 template <class T> const T *GetObjThisEvt(const char *name) const;
47 loizides 1.10 template <class T> T *GetObjThisEvt(const char *name);
48 loizides 1.13 template <class T> const T *GetPublicObj(const char *name) const;
49 loizides 1.10 template <class T> T *GetPublicObj(const char *name);
50 loizides 1.9 const RunInfo *GetRunInfo() const { return GetSel()->GetRunInfo(); }
51     const Selector *GetSel() const;
52 loizides 1.12 Bool_t HasHLTInfo() const;
53 loizides 1.13 template <class T> void ReqBranch(const char *bname, const T *&address);
54 loizides 1.9 Bool_t ValidRunInfo() const { return GetSel()->ValidRunInfo(); }
55     void SaveNEventsProcessed(const char *name="hDEvents");
56 loizides 1.14 void SetFillHist(Bool_t b) { fFillHist = b; }
57 loizides 1.9
58     private:
59 loizides 1.14 Bool_t fFillHist; //=true then fill histos (def=0)
60 loizides 1.12 mutable const HLTFwkMod *fHltFwkMod; //!pointer to HLTFwdMod
61     const TString fHltFwkModName; //!name of HLTFwkMod
62 loizides 1.14 Int_t fNEventsProc; //!number of events
63 loizides 1.1
64 loizides 1.4 ClassDef(BaseMod,1) // Base TAM module
65 loizides 1.1 };
66 loizides 1.6 }
67 loizides 1.4
68 loizides 1.6 //--------------------------------------------------------------------------------------------------
69 loizides 1.14 template <class T>
70     inline void mithep::BaseMod::AddTH1(T *&ptr, const char *name, const char *title,
71     Int_t nbins, Double_t xmin, Double_t xmax)
72     {
73     // Create ROOT histogram and add it to the output list.
74    
75     ptr = new T(name, title, nbins, xmin, xmax);
76     ptr->Sumw2();
77     AddOutput(ptr);
78     }
79    
80     //--------------------------------------------------------------------------------------------------
81     template <class T>
82     inline void mithep::BaseMod::AddTH2(T *&ptr, const char *name, const char *title,
83     Int_t nbinsx, Double_t xmin, Double_t xmax,
84     Int_t nbinsy, Double_t ymin, Double_t ymax)
85     {
86     // Create ROOT histogram and add it to the output list.
87    
88     ptr = new T(name, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
89     ptr->Sumw2();
90     AddOutput(ptr);
91     }
92    
93     //--------------------------------------------------------------------------------------------------
94 loizides 1.8 inline const mithep::TriggerObjectCol *mithep::BaseMod::GetHLTObjects(const char *name) const
95     {
96     // Get pointer to HLT TriggerObjects collection with given name for the current event.
97    
98     return (dynamic_cast<const TriggerObjectCol *>(FindObjThisEvt(name)));
99     }
100    
101     //--------------------------------------------------------------------------------------------------
102 loizides 1.10 template <class T>
103 loizides 1.13 inline const T *mithep::BaseMod::GetObjThisEvt(const char *name) const
104     {
105     // Get published object for the current event.
106    
107     T *ret = dynamic_cast<T*>(FindObjThisEvt(name));
108     if (!ret) {
109     SendError(kWarning, "GetObjThisEvent",
110     "Could not obtain object with name %s and type %s for current event!",
111     name, T::Class_Name());
112     }
113     return ret;
114     }
115    
116     //--------------------------------------------------------------------------------------------------
117     template <class T>
118 loizides 1.10 inline T *mithep::BaseMod::GetObjThisEvt(const char *name)
119     {
120     // Get published object for the current event.
121    
122     T *ret = dynamic_cast<T*>(FindObjThisEvt(name));
123     if (!ret) {
124     SendError(kWarning, "GetObjThisEvent",
125     "Could not obtain object with name %s and type %s for current event!",
126     name, T::Class_Name());
127     }
128     return ret;
129     }
130    
131     //--------------------------------------------------------------------------------------------------
132     template <class T>
133 loizides 1.13 inline const T *mithep::BaseMod::GetPublicObj(const char *name) const
134     {
135     // Get public object.
136    
137    
138     T *ret = dynamic_cast<T*>(FindPublicObj(name));
139     if (!ret) {
140     SendError(kWarning, "GetPublicObject",
141     "Could not obtain public object with name %s and type %s!",
142     name, T::Class_Name());
143     }
144     return ret;
145     }
146    
147     //--------------------------------------------------------------------------------------------------
148     template <class T>
149 loizides 1.10 inline T *mithep::BaseMod::GetPublicObj(const char *name)
150     {
151     // Get public object.
152    
153 loizides 1.11
154 loizides 1.10 T *ret = dynamic_cast<T*>(FindPublicObj(name));
155     if (!ret) {
156     SendError(kWarning, "GetPublicObject",
157     "Could not obtain public object with name %s and type %s!",
158     name, T::Class_Name());
159     }
160     return ret;
161     }
162    
163     //--------------------------------------------------------------------------------------------------
164 loizides 1.6 inline const mithep::Selector *mithep::BaseMod::GetSel() const
165     {
166 loizides 1.8 // Get pointer to selector.
167    
168 loizides 1.6 return static_cast<const Selector*>(GetSelector());
169 loizides 1.1 }
170 loizides 1.13
171     //--------------------------------------------------------------------------------------------------
172     template <class T>
173     inline void mithep::BaseMod::ReqBranch(const char *bname, const T *&address)
174     {
175     // Requests that the branch with the specified name be made available
176     // during processing and that it be read in to the address specified.
177    
178     TAModule::ReqBranch(bname, const_cast<T*&>(address));
179     }
180 loizides 1.1 #endif