Fork me on GitHub

source: svn/trunk/src/TriggerUtil.cc@ 248

Last change on this file since 248 was 243, checked in by Xavier Rouby, 16 years ago

copy-constructors ; operator=

File size: 11.4 KB
Line 
1/*
2 * ---- Delphes ----
3 * A Fast Simulator for general purpose LHC detector
4 * S. Ovyn ~~~~ severine.ovyn@uclouvain.be
5 *
6 * Center for Particle Physics and Phenomenology (CP3)
7 * Universite Catholique de Louvain (UCL)
8 * Louvain-la-Neuve, Belgium
9 * */
10
11// \brief Trigger class, and some generic definitions
12
13#include "TriggerUtil.h"
14
15#include <iostream>
16#include <iomanip>
17#include <sstream>
18#include <fstream>
19#include <string>
20
21using namespace std;
22
23TriggerTable::TriggerTable() {
24 has_been_evaluated=false;
25}
26
27TriggerTable& TriggerTable::operator=(TriggerTable&tt) {
28 if (this == &tt) return *this;
29 event_i = tt.event_i;
30 has_been_evaluated = tt.has_been_evaluated;
31 GlobalResult = tt.GlobalResult;
32 for (unsigned int i=0; i<tt.list_of_trigger_bits.size(); i++)
33 list_of_trigger_bits.push_back(tt.list_of_trigger_bits[i]);
34 return *this;
35}
36
37TriggerTable::TriggerTable(const TriggerTable& tt) {
38 event_i = tt.event_i;
39 has_been_evaluated = tt.has_been_evaluated;
40 GlobalResult = tt.GlobalResult;
41 for (unsigned int i=0; i<tt.list_of_trigger_bits.size(); i++)
42 list_of_trigger_bits.push_back(tt.list_of_trigger_bits[i]);
43}
44
45
46void TriggerTable::TriggerCardReader(const string& filename){
47 ifstream trigger_file(filename.c_str());
48 if( !trigger_file.good() ) {
49 cout << "ERROR: Trigger input file "<< filename << " not found. Exiting.\n";
50 return;
51 }
52
53 TriggerBit mybit;
54 string temp_string, temp_string_no_comment, trigger_name, trigger_algorithm;
55 while ( getline(trigger_file,temp_string) ) {
56 string temp_string_no_comment = temp_string.substr(0,temp_string.find("#")); //remove comments
57 if(temp_string_no_comment.size()<2) continue; // avoid empty lines
58 istringstream temp_stream(temp_string_no_comment);
59
60 temp_stream >> trigger_name;
61 trigger_algorithm = temp_string_no_comment.substr( temp_string_no_comment.find(">>")+2) ;
62
63 mybit.TriggerBit::GetTrigCondition(trigger_algorithm);
64 list_of_trigger_bits.push_back(mybit);
65 }
66}
67
68
69void TriggerTable::PrintTriggerTable(const string& LogName) {
70
71 ofstream f_out(LogName.c_str(),ios::app);
72 f_out<<"* *"<<"\n";
73 f_out<<"#*********************************************** *"<<"\n";
74 f_out<<"# Trigger conditions defined in the trigger card *"<<"\n";
75 f_out<<"#*********************************************** *"<<"\n";
76 f_out<<"* *"<<"\n";
77
78 f_out.close();
79
80 for(unsigned int i=0; i < list_of_trigger_bits.size(); i++) {
81 list_of_trigger_bits[i].PrintTrigCondition(LogName,i+1);
82 }
83 f_out<<"* *"<<"\n";
84 f_out<<"#*********************************************************************"<<"\n";
85
86}
87
88bool TriggerTable::GetGlobalResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
89 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
90 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig, ExRootTreeBranch *branchTrigger) {
91
92 TRootTrigger *elementTrigger;
93 GlobalResult=false;
94 for(unsigned int i=0; i < list_of_trigger_bits.size(); i++) {
95 if(list_of_trigger_bits[i].GetResult(branchElecTrig, branchMuonTrig, branchJetTrig, branchTauJetTrig, branchPhotonTrig, branchETmisTrig))
96 {
97 GlobalResult=true;
98 int flag=i+1;
99 elementTrigger = (TRootTrigger*) branchTrigger->NewEntry();
100 elementTrigger->Accepted=flag;
101 }
102 }
103 if(GlobalResult)
104 {
105 elementTrigger = (TRootTrigger*) branchTrigger->NewEntry();
106 elementTrigger->Accepted=0;
107 }
108 return GlobalResult;
109
110}
111
112//*************************************************************************
113TriggerBit::TriggerBit() {
114}
115
116TriggerBit::~TriggerBit() {
117 ElecValues.clear();
118 MuonValues.clear();
119 JetValues.clear();
120 TauJetValues.clear();
121 EtmisValues.clear();
122 GammaValues.clear();
123}
124
125TriggerBit::TriggerBit(const TriggerBit& tb) {
126 for(unsigned int i=0; i<tb.ElecValues.size(); i++)
127 ElecValues.push_back(tb.ElecValues[i]);
128
129 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
130 MuonValues.push_back(tb.MuonValues[i]);
131
132 for(unsigned int i=0; i<tb.JetValues.size(); i++)
133 JetValues.push_back(tb.JetValues[i]);
134
135 for(unsigned int i=0; i<tb.TauJetValues.size(); i++)
136 TauJetValues.push_back(tb.TauJetValues[i]);
137
138 for(unsigned int i=0; i<tb.EtmisValues.size(); i++)
139 EtmisValues.push_back(tb.EtmisValues[i]);
140
141 for(unsigned int i=0; i<tb.GammaValues.size(); i++)
142 GammaValues.push_back(tb.GammaValues[i]);
143
144 Result = tb.Result;
145}
146
147TriggerBit& TriggerBit::operator=(const TriggerBit& tb) {
148 if (this==&tb) return *this;
149 for(unsigned int i=0; i<tb.ElecValues.size(); i++)
150 ElecValues.push_back(tb.ElecValues[i]);
151
152 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
153 MuonValues.push_back(tb.MuonValues[i]);
154
155 for(unsigned int i=0; i<tb.JetValues.size(); i++)
156 JetValues.push_back(tb.JetValues[i]);
157
158 for(unsigned int i=0; i<tb.TauJetValues.size(); i++)
159 TauJetValues.push_back(tb.TauJetValues[i]);
160
161 for(unsigned int i=0; i<tb.EtmisValues.size(); i++)
162 EtmisValues.push_back(tb.EtmisValues[i]);
163
164 for(unsigned int i=0; i<tb.GammaValues.size(); i++)
165 GammaValues.push_back(tb.GammaValues[i]);
166 Result = tb.Result;
167
168 return *this;
169}
170
171
172
173bool TriggerBit::GetResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
174 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
175 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig)
176{
177 int elec_size = ElecValues.size();
178 int muon_size = MuonValues.size();
179 int jet_size = JetValues.size();
180 int taujet_size = TauJetValues.size();
181 int gamma_size = GammaValues.size();
182 int etmis_size = EtmisValues.size();
183
184 Result=false;
185 if(
186 (branchElecTrig->GetEntries() >= elec_size )
187 && (branchMuonTrig->GetEntries() >= muon_size )
188 && (branchJetTrig->GetEntries() >= jet_size )
189 && (branchTauJetTrig->GetEntries() >= taujet_size )
190 && (branchPhotonTrig->GetEntries() >= gamma_size )
191 )
192 {
193 Result=true;
194 if(elec_size!=0){
195 TRootElectron *electron;
196 for(int i=0;i<elec_size;i++){
197 electron = (TRootElectron*)branchElecTrig->At(i);
198 if(electron->PT < ElecValues[i])Result=false;}}
199
200 if(muon_size!=0){
201 TRootMuon *muon;
202 for(int i=0;i<muon_size;i++){
203 muon = (TRootMuon*)branchMuonTrig->At(i);
204 if(muon->PT < MuonValues[i])Result=false;}}
205
206 if(jet_size!=0){
207 TRootJet *jet;
208 for(int i=0;i<jet_size;i++){
209 jet = (TRootJet*)branchJetTrig->At(i);
210 if(jet->PT < JetValues[i])Result=false;}}
211
212 if(taujet_size!=0){
213 TRootTauJet *taujet;
214 for(int i=0;i<taujet_size;i++){
215 taujet = (TRootTauJet*)branchTauJetTrig->At(i);
216 if(taujet->PT < TauJetValues[i])Result=false;}}
217
218 if(gamma_size!=0){
219 TRootPhoton *gamma;
220 for(int i=0;i<gamma_size;i++){
221 gamma = (TRootPhoton*)branchPhotonTrig->At(i);
222 if(gamma->PT < GammaValues[i])Result=false;}}
223
224
225 if(etmis_size!=0){
226 TRootETmis *etmis = (TRootETmis*)branchETmisTrig->At(0);
227 if(etmis->ET < EtmisValues[0])Result=false;}
228
229 }
230 return Result;
231}
232
233void TriggerBit::GetTrigCondition(const string& trigger_algorithm) {
234
235 vector<string> ElecSequences;
236 vector<string> MuonSequences;
237 vector<string> JetSequences;
238 vector<string> TauJetSequences;
239 vector<string> EtmisSequences;
240 vector<string> GammaSequences;
241
242 char *result = NULL;
243 result = strtok( (char*) trigger_algorithm.c_str(),"&");
244 while( result != NULL )
245 {
246 if(strstr (result,"ELEC"))ElecSequences.push_back(result);
247 if(strstr (result,"MUON"))MuonSequences.push_back(result);
248 if(strstr (result,"JET"))JetSequences.push_back(result);
249 if(strstr (result,"TAUJET"))TauJetSequences.push_back(result);
250 if(strstr (result,"ETMIS"))EtmisSequences.push_back(result);
251 if(strstr (result,"GAMMA"))GammaSequences.push_back(result);
252 result = strtok( NULL,"&");
253 }
254
255 ElecValues = GetCuts(ElecSequences);
256 MuonValues = GetCuts(MuonSequences);
257 JetValues = GetCuts(JetSequences);
258 TauJetValues = GetCuts(TauJetSequences);
259 EtmisValues = GetCuts(EtmisSequences);
260 GammaValues = GetCuts(GammaSequences);
261
262}
263
264
265void TriggerBit::PrintTrigCondition(const string& LogName,const int i)
266{
267 int elec_size = TriggerBit::ElecValues.size();
268 int muon_size = TriggerBit::MuonValues.size();
269 int jet_size = TriggerBit::JetValues.size();
270 int taujet_size = TriggerBit::TauJetValues.size();
271 int gamma_size = TriggerBit::GammaValues.size();
272 int etmis_size = TriggerBit::EtmisValues.size();
273
274 ofstream f_out(LogName.c_str(),ios::app);
275
276 f_out <<"* *"<<"\n";
277 f_out << left << setw(25) <<"# Trigger bit number "<<""
278 << left << setw(35) <<i <<""<< right << setw(10)<<"*"<<"\n";
279 f_out <<"#*************************"<<"\n";
280 f_out << left << setw(45) <<"* # Number of reconstructed objects required:"<<""<<right << setw(23)<<"*"<<"\n";
281 f_out << left << setw(1) <<"*"
282 << internal << setw(10) << "Electron"<< ""<< internal << setw(10) << "Muon" << ""
283 << internal << setw(10) << "Jets" << ""<< internal << setw(10) << "Tau-jets "<< ""
284 << internal << setw(10) << "Photons" << ""<< internal << setw(10) << "ETmis "<< ""<< right << setw(9) <<"*"<<"\n";
285 f_out << left << setw(1) <<"*"
286 << internal << setw(10) << elec_size << ""<< internal << setw(10) << muon_size << ""
287 << internal << setw(10) << jet_size << ""<< internal << setw(10) << taujet_size << ""
288 << internal << setw(10) << gamma_size<< ""<< internal << setw(10) << etmis_size << ""<< right << setw(9)<<"*"<<"\n";
289 f_out << left << setw(45) <<"* # Values of the related thresholds: "<<""<<right << setw(25)<<"*"<<"\n";
290 if(elec_size!=0){
291 f_out << left << setw(20) <<"* - Electrons: "<<"";
292 for(int i=0;i<elec_size;i++){f_out << left << setw(5) << TriggerBit::ElecValues[i]<<"";}f_out <<"\n";}
293
294 if(muon_size!=0){
295 f_out << left << setw(20) <<"* - Muons: "<<"";
296 for(int i=0;i<muon_size;i++){f_out << left << setw(5) << TriggerBit::MuonValues[i]<<"";}f_out <<"\n";}
297
298 if(jet_size!=0){
299 f_out << left << setw(20) <<"* - Jets: "<<"";
300 for(int i=0;i<jet_size;i++){f_out << left << setw(5) << TriggerBit::JetValues[i]<<"";}f_out <<"\n";}
301
302 if(taujet_size!=0){
303 f_out << left << setw(20) <<"* - Tau-jets: "<<"";
304 for(int i=0;i<taujet_size;i++){f_out << left << setw(5) << TriggerBit::TauJetValues[i]<<"";}f_out <<"\n";}
305
306 if(gamma_size!=0){
307 f_out << left << setw(20) <<"* - Photons: "<<"";
308 for(int i=0;i<gamma_size;i++){f_out << left << setw(5) << TriggerBit::GammaValues[i]<<"";}f_out <<"\n";}
309
310 if(etmis_size!=0){
311 f_out << left << setw(20) <<"* - ETMIS: "<<"";
312 for(int i=0;i<etmis_size;i++){f_out << left << setw(5) << TriggerBit::EtmisValues[i]<<"";}f_out <<"\n";}
313 f_out <<"* *"<<"\n";
314
315
316
317}
318
319vector<float> TriggerBit::GetCuts(const vector<string> &Sequences)
320{
321 vector<float> OrderedValue;
322 string ptVal;
323 Int_t PtVal=0;
324 for(unsigned int i=0; i < Sequences.size(); i++) {
325 ptVal = Sequences[i].substr( Sequences[i].find("'")+1) ;
326 PtVal = atoi( ptVal.c_str() );
327 OrderedValue.push_back(PtVal);
328 }
329 return OrderedValue;
330
331}
332
333
Note: See TracBrowser for help on using the repository browser.