1 |
loizides |
1.1 |
// $Id: L1Mod.cc,v 1.17 2009/10/01 12:43:53 loizides Exp $
|
2 |
|
|
|
3 |
|
|
#include "MitAna/TreeMod/interface/L1Mod.h"
|
4 |
|
|
#include <TFile.h>
|
5 |
|
|
#include <TTree.h>
|
6 |
|
|
#include "MitAna/DataTree/interface/Names.h"
|
7 |
|
|
#include "MitAna/DataTree/interface/L1TriggerMask.h"
|
8 |
|
|
#include "MitAna/DataTree/interface/TriggerName.h"
|
9 |
|
|
#include "MitAna/DataTree/interface/TriggerTable.h"
|
10 |
|
|
|
11 |
|
|
using namespace mithep;
|
12 |
|
|
|
13 |
|
|
ClassImp(mithep::L1Mod)
|
14 |
|
|
|
15 |
|
|
//--------------------------------------------------------------------------------------------------
|
16 |
|
|
L1Mod::L1Mod(const char *name, const char *title) :
|
17 |
|
|
BaseMod(name,title),
|
18 |
|
|
fAbort(kTRUE),
|
19 |
|
|
fAlgo(kFALSE),
|
20 |
|
|
fPrintTable(kFALSE),
|
21 |
|
|
fIgnoreBits(kFALSE),
|
22 |
|
|
fBitsName(Names::gkL1TechBitsBrn), //Names::gkL1AlgoBitsBrn
|
23 |
|
|
fBits(0),
|
24 |
|
|
fTriggers(0),
|
25 |
|
|
fNEvents(0),
|
26 |
|
|
fNAcceped(0),
|
27 |
|
|
fNFailed(0)
|
28 |
|
|
{
|
29 |
|
|
// Constructor.
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
//--------------------------------------------------------------------------------------------------
|
33 |
|
|
L1Mod::~L1Mod()
|
34 |
|
|
{
|
35 |
|
|
// Destructor.
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
//--------------------------------------------------------------------------------------------------
|
39 |
|
|
void L1Mod::AddTrigger(const char *expr)
|
40 |
|
|
{
|
41 |
|
|
// Add trigger search pattern to the list of patters. Each element of the list is logically
|
42 |
|
|
// "ored". The given expression can contain several trigger names logically "anded" (using "&").
|
43 |
|
|
// A "!" infront of a trigger name negates the bit. For example, valid expressions are:
|
44 |
|
|
// "A", "!A", "A&B", "A&!B" or "A&B&C"
|
45 |
|
|
|
46 |
|
|
string tname(expr);
|
47 |
|
|
fTrigNames.push_back(tname);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
//--------------------------------------------------------------------------------------------------
|
51 |
|
|
void L1Mod::BeginRun()
|
52 |
|
|
{
|
53 |
|
|
// Get L1 tree and set branches. Compute bitmasks to be used when comparing to the L1 bits.
|
54 |
|
|
|
55 |
|
|
fTrigBitsAnd.clear();
|
56 |
|
|
fTrigBitsCmp.clear();
|
57 |
|
|
|
58 |
|
|
if (fPrintTable)
|
59 |
|
|
fTriggers->Print();
|
60 |
|
|
|
61 |
|
|
for (UInt_t i=0; i<fTrigNames.size(); ++i) {
|
62 |
|
|
BitMask64 tmask; //trigger mask
|
63 |
|
|
BitMask64 amask; //bitand mask
|
64 |
|
|
TString names(fTrigNames.at(i).c_str());
|
65 |
|
|
|
66 |
|
|
TObjArray *arr = names.Tokenize("&");
|
67 |
|
|
if (arr) {
|
68 |
|
|
for(Int_t j=0; j<arr->GetEntries(); j++){
|
69 |
|
|
TObjString *s = dynamic_cast<TObjString*>(arr->At(j));
|
70 |
|
|
if (!s)
|
71 |
|
|
continue;
|
72 |
|
|
const char *sptr = s->GetString().Data();
|
73 |
|
|
Bool_t invert = kFALSE;
|
74 |
|
|
if (sptr[0] == '!') {
|
75 |
|
|
invert = kTRUE; //inverted bit set
|
76 |
|
|
++sptr;
|
77 |
|
|
}
|
78 |
|
|
const TriggerName *tn = fTriggers->Get(sptr);
|
79 |
|
|
if (!tn) {
|
80 |
|
|
Warning("BeginRun", "Trigger %s not found.", sptr);
|
81 |
|
|
continue;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
UShort_t bit = tn->Id();
|
85 |
|
|
if (amask.TestBit(bit)) {
|
86 |
|
|
if (tmask.TestBit(bit)==invert) {
|
87 |
|
|
amask.ClearBit(bit);
|
88 |
|
|
tmask.ClearBit(bit);
|
89 |
|
|
Warning("BeginRun", "Trigger expression %s always false.", names.Data());
|
90 |
|
|
break;
|
91 |
|
|
}
|
92 |
|
|
} else { //always set and-mask bit
|
93 |
|
|
amask.SetBit(bit);
|
94 |
|
|
if (!invert)
|
95 |
|
|
tmask.SetBit(bit); //set trigger bit
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
delete arr;
|
99 |
|
|
}
|
100 |
|
|
if (amask.NBitsSet()) {
|
101 |
|
|
fTrigBitsAnd.push_back(amask);
|
102 |
|
|
fTrigBitsCmp.push_back(tmask);
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
//--------------------------------------------------------------------------------------------------
|
108 |
|
|
void L1Mod::Process()
|
109 |
|
|
{
|
110 |
|
|
// Process trigger bits for this event. If trigger bits pass the given bit mask, then obtain
|
111 |
|
|
// and publish the corresponding trigger objects. If OnAccepted or OnFailed is implemented
|
112 |
|
|
// in a derived class, call it. Do not stop processing this event, if fAbort is kFALSE.
|
113 |
|
|
|
114 |
|
|
++fNEvents;
|
115 |
|
|
LoadBranch(fBitsName);
|
116 |
|
|
|
117 |
|
|
// match trigger bits to trigger mask
|
118 |
|
|
fBitsDone.Clear();
|
119 |
|
|
Bool_t accept = kFALSE;
|
120 |
|
|
for (UInt_t i = 0; i<fTrigBitsAnd.size(); ++i) {
|
121 |
|
|
BitMask64 bitmask(fBits->Get());
|
122 |
|
|
bitmask &= fTrigBitsAnd.at(i);
|
123 |
|
|
if (bitmask==fTrigBitsCmp.at(i)) {
|
124 |
|
|
accept = kTRUE;
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
// take action if failed
|
129 |
|
|
if (!accept) {
|
130 |
|
|
++fNFailed;
|
131 |
|
|
OnFailed();
|
132 |
|
|
if (fAbort) {
|
133 |
|
|
SkipEvent(); // abort processing of this event by sub-modules
|
134 |
|
|
}
|
135 |
|
|
return;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
// take action if accepted
|
139 |
|
|
++fNAcceped;
|
140 |
|
|
IncNEventsProcessed();
|
141 |
|
|
OnAccepted();
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
//--------------------------------------------------------------------------------------------------
|
145 |
|
|
void L1Mod::SlaveBegin()
|
146 |
|
|
{
|
147 |
|
|
// Request trigger bit branch and obtain trigger table and objects.
|
148 |
|
|
|
149 |
|
|
ReqBranch(fBitsName, fBits);
|
150 |
|
|
|
151 |
|
|
if (fAlgo)
|
152 |
|
|
fTriggers = GetL1AlgoTable();
|
153 |
|
|
else
|
154 |
|
|
fTriggers = GetL1TechTable();
|
155 |
|
|
|
156 |
|
|
if (!fTriggers) {
|
157 |
|
|
SendError(kAbortAnalysis, "SlaveBegin", "Could not get HLT trigger table.");
|
158 |
|
|
return;
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
//--------------------------------------------------------------------------------------------------
|
163 |
|
|
void L1Mod::SlaveTerminate()
|
164 |
|
|
{
|
165 |
|
|
// Save number of accepted events.
|
166 |
|
|
|
167 |
|
|
SaveNEventsProcessed("hDL1Events");
|
168 |
|
|
}
|