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