ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/TreeMod/src/HLTMod.cc
Revision: 1.19
Committed: Tue Sep 14 22:51:28 2010 UTC (14 years, 7 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e
Changes since 1.18: +13 -4 lines
Log Message:
Run based trigger selection

File Contents

# Content
1 // $Id: HLTMod.cc,v 1.18 2009/12/01 15:14:11 loizides Exp $
2
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 #include "MitAna/DataTree/interface/TriggerMask.h"
9 #include "MitAna/DataTree/interface/TriggerObject.h"
10 #include "MitAna/DataTree/interface/TriggerObjectCol.h"
11 #include "MitAna/DataTree/interface/TriggerObjectsTable.h"
12
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 fPrintTable(kFALSE),
22 fIgnoreBits(kFALSE),
23 fObjMode(kHlt),
24 fBitsName(Names::gkHltBitBrn),
25 fMyObjsNamePub(Form("%sTrigObjs", name)),
26 fBits(0),
27 fMyTrgObjs(0),
28 fTriggers(0),
29 fTrigObjs(0),
30 fNEvents(0),
31 fNAcceped(0),
32 fNFailed(0)
33 {
34 // Constructor.
35 }
36
37 //--------------------------------------------------------------------------------------------------
38 HLTMod::~HLTMod()
39 {
40 // Destructor.
41 }
42
43 //--------------------------------------------------------------------------------------------------
44 void HLTMod::AddTrigger(const char *expr, UInt_t firstRun, UInt_t lastRun)
45 {
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 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 }
55
56 //--------------------------------------------------------------------------------------------------
57 void HLTMod::AddTrigObjs(UInt_t tid)
58 {
59 // Add trigger objects corresponding to trigger id.
60
61 const BitMask256 &ba = fTrigBitsAnd.at(tid);
62 const BitMask256 &bm = fTrigBitsCmp.at(tid);
63 for (UInt_t i=0; i<bm.Size(); ++i) {
64 if (ba.TestBit(i)==0 && !fIgnoreBits)
65 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 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 }
83 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 fTrigBitsAnd.clear();
93 fTrigBitsCmp.clear();
94
95 if (fPrintTable) {
96 Info("BeginRun", "Get trigger table for run %d", GetEventHeader()->RunNum());
97 fTriggers->Print();
98 }
99
100 UInt_t runNumber = GetEventHeader()->RunNum();
101
102 for (UInt_t i=0; i<fTrigNames.size(); ++i) {
103
104 UInt_t firstRun = fTrigNames.at(i).second.first;
105 UInt_t lastRun = fTrigNames.at(i).second.second;
106
107 if ( (!(firstRun==0 && lastRun==0)) && ( runNumber<firstRun || runNumber>lastRun ) ) continue;
108
109 BitMask256 tmask; //trigger mask
110 BitMask256 amask; //bitand mask
111 TString names(fTrigNames.at(i).first.c_str());
112
113 TObjArray *arr = names.Tokenize("&");
114 if (arr) {
115 for(Int_t j=0; j<arr->GetEntries(); j++){
116 TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
117 if (!s)
118 continue;
119 const char *sptr = s->GetString().Data();
120 Bool_t invert = kFALSE;
121 if (sptr[0] == '!') {
122 invert = kTRUE; //inverted bit set
123 ++sptr;
124 }
125 const TriggerName *tn = fTriggers->Get(sptr);
126 if (!tn) {
127 Warning("BeginRun", "Trigger %s not found.", sptr);
128 continue;
129 }
130
131 UShort_t bit = tn->Id();
132 if (amask.TestBit(bit)) {
133 if (tmask.TestBit(bit)==invert) {
134 amask.ClearBit(bit);
135 tmask.ClearBit(bit);
136 Warning("BeginRun", "Trigger expression %s always false.", names.Data());
137 break;
138 }
139 } else { //always set and-mask bit
140 amask.SetBit(bit);
141 if (!invert)
142 tmask.SetBit(bit); //set trigger bit
143 }
144 }
145 delete arr;
146 }
147 if (amask.NBitsSet()) {
148 fTrigBitsAnd.push_back(amask);
149 fTrigBitsCmp.push_back(tmask);
150 }
151 }
152 }
153
154 //--------------------------------------------------------------------------------------------------
155 void HLTMod::Process()
156 {
157 // Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
158 // and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
159 // in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
160
161 ++fNEvents;
162 LoadBranch(fBitsName);
163
164 // match trigger bits to trigger mask and obtain trigger objects
165 fMyTrgObjs = new TriggerObjectOArr(0,fMyObjsNamePub);
166 fMyTrgObjs->SetOwner(kFALSE); // the objects are owned by the object table
167 fBitsDone.Clear();
168 Bool_t accept = kFALSE;
169 for (UInt_t i = 0; i<fTrigBitsAnd.size(); ++i) {
170 BitMask256 bitmask(fBits->Get());
171 bitmask &= fTrigBitsAnd.at(i);
172 if (bitmask==fTrigBitsCmp.at(i)) {
173 accept = kTRUE;
174 AddTrigObjs(i);
175 }
176 }
177
178 // take action if failed
179 if (!accept) {
180 ++fNFailed;
181 OnFailed();
182 delete fMyTrgObjs;
183 if (fAbort) {
184 SkipEvent(); // abort processing of this event by sub-modules
185 }
186 return;
187 }
188
189 // take action if accepted
190 ++fNAcceped;
191 IncNEventsProcessed();
192 OnAccepted();
193 if (!AddObjThisEvt(fMyTrgObjs)) {
194 SendError(kAbortAnalysis, "Process",
195 "Could not add my trigger objects with name %s to event.",
196 fMyTrgObjs->GetName());
197 return;
198 }
199 fMyTrgObjs = 0;
200 }
201
202 //--------------------------------------------------------------------------------------------------
203 void HLTMod::SlaveBegin()
204 {
205 // Request trigger bit branch and obtain trigger table and objects.
206
207 ReqBranch(fBitsName, fBits);
208
209 fTriggers = GetHLTTable();
210 if (!fTriggers) {
211 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger table.");
212 return;
213 }
214 fTrigObjs = GetHLTObjectsTable();
215 if (!fTrigObjs) {
216 SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger objects table.");
217 return;
218 }
219 }
220
221 //--------------------------------------------------------------------------------------------------
222 void HLTMod::SlaveTerminate()
223 {
224 // Save number of accepted events.
225
226 SaveNEventsProcessed("hDHLTEvents");
227 }