ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.22
Committed: Fri Nov 18 00:02:02 2011 UTC (13 years, 5 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025d
Changes since 1.21: +15 -3 lines
Log Message:
Photon vertex probability and partial hlt wildcard support

File Contents

# User Rev Content
1 bendavid 1.22 // $Id: HLTMod.cc,v 1.21 2011/05/15 20:40:30 bendavid Exp $
2 loizides 1.1
3     #include "MitAna/TreeMod/interface/HLTMod.h"
4     #include <TFile.h>
5     #include <TTree.h>
6     #include "MitAna/DataTree/interface/Names.h"
7     #include "MitAna/DataTree/interface/TriggerName.h"
8 loizides 1.11 #include "MitAna/DataTree/interface/TriggerMask.h"
9 loizides 1.1 #include "MitAna/DataTree/interface/TriggerObject.h"
10 loizides 1.11 #include "MitAna/DataTree/interface/TriggerObjectCol.h"
11 loizides 1.12 #include "MitAna/DataTree/interface/TriggerObjectsTable.h"
12 loizides 1.1
13     using namespace mithep;
14    
15     ClassImp(mithep::HLTMod)
16    
17     //--------------------------------------------------------------------------------------------------
18     HLTMod::HLTMod(const char *name, const char *title) :
19     BaseMod(name,title),
20     fAbort(kTRUE),
21 loizides 1.8 fPrintTable(kFALSE),
22 loizides 1.13 fIgnoreBits(kFALSE),
23     fObjMode(kHlt),
24 loizides 1.1 fBitsName(Names::gkHltBitBrn),
25 loizides 1.8 fMyObjsNamePub(Form("%sTrigObjs", name)),
26 loizides 1.1 fBits(0),
27     fMyTrgObjs(0),
28     fTriggers(0),
29     fTrigObjs(0),
30     fNEvents(0),
31 paus 1.20 fNAccepted(0),
32 loizides 1.1 fNFailed(0)
33     {
34     // Constructor.
35     }
36    
37     //--------------------------------------------------------------------------------------------------
38     HLTMod::~HLTMod()
39     {
40     // Destructor.
41     }
42    
43     //--------------------------------------------------------------------------------------------------
44 bendavid 1.19 void HLTMod::AddTrigger(const char *expr, UInt_t firstRun, UInt_t lastRun)
45 loizides 1.1 {
46     // Add trigger search pattern to the list of patters. Each element of the list is logically
47     // "ored". The given expression can contain several trigger names logically "anded" (using "&").
48     // A "!" infront of a trigger name negates the bit. For example, valid expressions are:
49     // "A", "!A", "A&B", "A&!B" or "A&B&C"
50    
51     string tname(expr);
52 bendavid 1.19 std::pair<std::string,std::pair<UInt_t,UInt_t> > element(tname,std::pair<UInt_t,UInt_t>(firstRun,lastRun));
53     fTrigNames.push_back(element);
54 loizides 1.1 }
55    
56     //--------------------------------------------------------------------------------------------------
57     void HLTMod::AddTrigObjs(UInt_t tid)
58     {
59     // Add trigger objects corresponding to trigger id.
60    
61 bendavid 1.21 const BitMask1024 &ba = fTrigBitsAnd.at(tid);
62     const BitMask1024 &bm = fTrigBitsCmp.at(tid);
63 loizides 1.1 for (UInt_t i=0; i<bm.Size(); ++i) {
64 loizides 1.13 if (ba.TestBit(i)==0 && !fIgnoreBits)
65 loizides 1.1 continue; // not an active trigger bit
66     if (fBitsDone.TestBit(i))
67     continue; // objects for this bit are already obtained
68     if (bm.TestBit(i)==0)
69     continue; // excluded trigger bit (ie a !trgname)
70    
71     const TList *list = fTrigObjs->GetList(i);
72 loizides 1.15 if (list) {
73     TIter iter(list->MakeIterator());
74     const TriggerObject *to = dynamic_cast<const TriggerObject*>(iter.Next());
75     while (to) {
76     if ( (fObjMode == kAll) ||
77     ((fObjMode==kHlt) && (to->IsHLT())) ||
78     ((fObjMode==kL1) && (to->IsL1())) )
79     fMyTrgObjs->Add(to);
80     to = dynamic_cast<const TriggerObject*>(iter.Next());
81     }
82 loizides 1.13 }
83 loizides 1.1 fBitsDone.SetBit(i);
84     }
85     }
86    
87     //--------------------------------------------------------------------------------------------------
88     void HLTMod::BeginRun()
89     {
90     // Get HLT tree and set branches. Compute bitmasks to be used when comparing to the HLT bits.
91    
92 loizides 1.6 fTrigBitsAnd.clear();
93     fTrigBitsCmp.clear();
94 loizides 1.1
95 loizides 1.18 if (fPrintTable) {
96     Info("BeginRun", "Get trigger table for run %d", GetEventHeader()->RunNum());
97 loizides 1.2 fTriggers->Print();
98 loizides 1.18 }
99 bendavid 1.19
100     UInt_t runNumber = GetEventHeader()->RunNum();
101 loizides 1.2
102 loizides 1.5 for (UInt_t i=0; i<fTrigNames.size(); ++i) {
103 bendavid 1.19
104     UInt_t firstRun = fTrigNames.at(i).second.first;
105 paus 1.20 UInt_t lastRun = fTrigNames.at(i).second.second;
106 bendavid 1.19
107 paus 1.20 // implement run dependence of the triggers
108     if ( (!(firstRun==0 && lastRun==0)) &&
109     ( runNumber<firstRun || runNumber>lastRun ) )
110     continue;
111 bendavid 1.19
112 bendavid 1.21 BitMask1024 tmask; //trigger mask
113     BitMask1024 amask; //bitand mask
114 bendavid 1.19 TString names(fTrigNames.at(i).first.c_str());
115 loizides 1.7
116 loizides 1.1 TObjArray *arr = names.Tokenize("&");
117     if (arr) {
118     for(Int_t j=0; j<arr->GetEntries(); j++){
119     TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
120     if (!s)
121     continue;
122 bendavid 1.22 TString st = s->GetString();
123     bool wildcard = false;
124     if (st.EndsWith("*")) {
125     st.ReplaceAll("*","");
126     wildcard = true;
127     }
128     const char *sptr = st.Data();
129 loizides 1.1 Bool_t invert = kFALSE;
130     if (sptr[0] == '!') {
131     invert = kTRUE; //inverted bit set
132     ++sptr;
133     }
134 bendavid 1.22 const TriggerName *tn = 0;
135     if (wildcard) {
136     tn = fTriggers->GetWildcard(sptr);
137     }
138     else {
139     tn = fTriggers->Get(sptr);
140     }
141 loizides 1.1 if (!tn) {
142 loizides 1.7 Warning("BeginRun", "Trigger %s not found.", sptr);
143 loizides 1.1 continue;
144     }
145 loizides 1.16
146 loizides 1.1 UShort_t bit = tn->Id();
147 loizides 1.16 if (amask.TestBit(bit)) {
148     if (tmask.TestBit(bit)==invert) {
149     amask.ClearBit(bit);
150     tmask.ClearBit(bit);
151 loizides 1.17 Warning("BeginRun", "Trigger expression %s always false.", names.Data());
152 loizides 1.16 break;
153     }
154     } else { //always set and-mask bit
155     amask.SetBit(bit);
156     if (!invert)
157     tmask.SetBit(bit); //set trigger bit
158     }
159 loizides 1.1 }
160     delete arr;
161     }
162 loizides 1.16 if (amask.NBitsSet()) {
163 loizides 1.14 fTrigBitsAnd.push_back(amask);
164     fTrigBitsCmp.push_back(tmask);
165     }
166 loizides 1.1 }
167     }
168    
169     //--------------------------------------------------------------------------------------------------
170     void HLTMod::Process()
171     {
172     // Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
173     // and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
174     // in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
175    
176     ++fNEvents;
177 loizides 1.4 LoadBranch(fBitsName);
178 loizides 1.1
179     // match trigger bits to trigger mask and obtain trigger objects
180     fMyTrgObjs = new TriggerObjectOArr(0,fMyObjsNamePub);
181     fMyTrgObjs->SetOwner(kFALSE); // the objects are owned by the object table
182     fBitsDone.Clear();
183     Bool_t accept = kFALSE;
184 loizides 1.6 for (UInt_t i = 0; i<fTrigBitsAnd.size(); ++i) {
185 bendavid 1.21 BitMask1024 bitmask(fBits->Get());
186 loizides 1.6 bitmask &= fTrigBitsAnd.at(i);
187     if (bitmask==fTrigBitsCmp.at(i)) {
188 loizides 1.1 accept = kTRUE;
189     AddTrigObjs(i);
190     }
191     }
192    
193     // take action if failed
194     if (!accept) {
195     ++fNFailed;
196     OnFailed();
197     delete fMyTrgObjs;
198     if (fAbort) {
199     SkipEvent(); // abort processing of this event by sub-modules
200     }
201     return;
202     }
203    
204     // take action if accepted
205 paus 1.20 ++fNAccepted;
206 loizides 1.9 IncNEventsProcessed();
207 loizides 1.1 OnAccepted();
208     if (!AddObjThisEvt(fMyTrgObjs)) {
209     SendError(kAbortAnalysis, "Process",
210     "Could not add my trigger objects with name %s to event.",
211     fMyTrgObjs->GetName());
212     return;
213     }
214     fMyTrgObjs = 0;
215     }
216    
217     //--------------------------------------------------------------------------------------------------
218     void HLTMod::SlaveBegin()
219     {
220     // Request trigger bit branch and obtain trigger table and objects.
221    
222 loizides 1.4 ReqBranch(fBitsName, fBits);
223 loizides 1.1
224     fTriggers = GetHLTTable();
225     if (!fTriggers) {
226     SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger table.");
227     return;
228     }
229     fTrigObjs = GetHLTObjectsTable();
230     if (!fTrigObjs) {
231     SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger objects table.");
232     return;
233     }
234     }
235 loizides 1.9
236     //--------------------------------------------------------------------------------------------------
237     void HLTMod::SlaveTerminate()
238     {
239     // Save number of accepted events.
240    
241 paus 1.20 printf(" %s - Accepted events: %d (/%d)\n",GetName(),fNAccepted,fNEvents);
242 ceballos 1.10 SaveNEventsProcessed("hDHLTEvents");
243 loizides 1.9 }