Fork me on GitHub

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

Last change on this file since 261 was 260, checked in by severine ovyn, 16 years ago

add header

File size: 17.3 KB
Line 
1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
6** \----------------------------------------------/ **
7** **
8** **
9** This package uses: **
10** ------------------ **
11** FastJet algorithm: Phys. Lett. B641 (2006) [hep-ph/0512210] **
12** Hector: JINST 2:P09005 (2007) [physics.acc-ph:0707.1198v2] **
13** FROG: [hep-ex/0901.2718v1] **
14** **
15** ------------------------------------------------------------------ **
16** **
17** Main authors: **
18** ------------- **
19** **
20** Severine Ovyn Xavier Rouby **
21** severine.ovyn@uclouvain.be xavier.rouby@cern **
22** **
23** Center for Particle Physics and Phenomenology (CP3) **
24** Universite catholique de Louvain (UCL) **
25** Louvain-la-Neuve, Belgium **
26** **
27** Copyright (C) 2008-2009, **
28** All rights reserved. **
29** **
30***********************************************************************/
31
32// \brief Trigger class, and some generic definitions
33
34#include "TriggerUtil.h"
35
36#include <iostream>
37#include <iomanip>
38#include <sstream>
39#include <fstream>
40#include <string>
41
42using namespace std;
43
44TriggerTable::TriggerTable() {
45 has_been_evaluated=false;
46}
47
48TriggerTable& TriggerTable::operator=(TriggerTable&tt) {
49 if (this == &tt) return *this;
50 has_been_evaluated = tt.has_been_evaluated;
51 GlobalResult = tt.GlobalResult;
52 for (unsigned int i=0; i<tt.list_of_trigger_bits.size(); i++)
53 list_of_trigger_bits.push_back(tt.list_of_trigger_bits[i]);
54 return *this;
55}
56
57TriggerTable::TriggerTable(const TriggerTable& tt) {
58 has_been_evaluated = tt.has_been_evaluated;
59 GlobalResult = tt.GlobalResult;
60 for (unsigned int i=0; i<tt.list_of_trigger_bits.size(); i++)
61 list_of_trigger_bits.push_back(tt.list_of_trigger_bits[i]);
62}
63
64
65void TriggerTable::TriggerCardReader(const string& filename){
66 ifstream trigger_file(filename.c_str());
67 if( !trigger_file.good() ) {
68 cerr << left << setw(30) <<"** ERROR: Trigger input file "<<""
69 << right << setw(15) <<filename<<""
70 << right << setw(24) <<"not found. Exiting... **"<<endl;
71 return;
72 }
73
74 TriggerBit mybit;
75 string temp_string, temp_string_no_comment, trigger_name, trigger_algorithm;
76 while ( getline(trigger_file,temp_string) ) {
77 string temp_string_no_comment = temp_string.substr(0,temp_string.find("#")); //remove comments
78 if(temp_string_no_comment.size()<2) continue; // avoid empty lines
79 istringstream temp_stream(temp_string_no_comment);
80
81 temp_stream >> trigger_name;
82 trigger_algorithm = temp_string_no_comment.substr( temp_string_no_comment.find(">>")+2) ;
83
84 mybit.TriggerBit::GetTrigCondition(trigger_algorithm);
85 list_of_trigger_bits.push_back(mybit);
86 }
87}
88
89
90void TriggerTable::PrintTriggerTable(const string& LogName) {
91
92 ofstream f_out(LogName.c_str(),ios::app);
93 f_out<<"* *"<<"\n";
94 f_out<<"#*********************************************** *"<<"\n";
95 f_out<<"# Trigger conditions defined in the trigger card *"<<"\n";
96 f_out<<"#*********************************************** *"<<"\n";
97 f_out<<"* *"<<"\n";
98
99 f_out.close();
100
101 for(unsigned int i=0; i < list_of_trigger_bits.size(); i++) {
102 list_of_trigger_bits[i].PrintTrigCondition(LogName,i+1);
103 }
104 f_out<<"* *"<<"\n";
105 f_out<<"#*********************************************************************"<<"\n";
106
107}
108
109bool TriggerTable::GetGlobalResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
110 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
111 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig, ExRootTreeBranch *branchTrigger) {
112
113 TRootTrigger *elementTrigger;
114 GlobalResult=false;
115 for(unsigned int i=0; i < list_of_trigger_bits.size(); i++) {
116 if(list_of_trigger_bits[i].GetResult(branchElecTrig, branchMuonTrig, branchJetTrig, branchTauJetTrig, branchPhotonTrig, branchETmisTrig))
117 {
118 GlobalResult=true;
119 int flag=i+1;
120 elementTrigger = (TRootTrigger*) branchTrigger->NewEntry();
121 elementTrigger->Accepted=flag;
122 }
123 }
124 if(GlobalResult)
125 {
126 elementTrigger = (TRootTrigger*) branchTrigger->NewEntry();
127 elementTrigger->Accepted=0;
128 }
129 return GlobalResult;
130
131}
132
133//*************************************************************************
134
135TriggerBit::~TriggerBit() {
136 ElecValues.clear();
137 IElecValues.clear();
138 MuonValues.clear();
139 IMuonValues.clear();
140 JetValues.clear();
141 BjetValues.clear();
142 TauJetValues.clear();
143 EtmisValues.clear();
144 GammaValues.clear();
145
146}
147
148TriggerBit::TriggerBit(const TriggerBit& tb) {
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.IElecValues.size(); i++)
153 IElecValues.push_back(tb.IElecValues[i]);
154
155
156 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
157 MuonValues.push_back(tb.MuonValues[i]);
158
159 for(unsigned int i=0; i<tb.IMuonValues.size(); i++)
160 IMuonValues.push_back(tb.IMuonValues[i]);
161
162 for(unsigned int i=0; i<tb.JetValues.size(); i++)
163 JetValues.push_back(tb.JetValues[i]);
164
165 for(unsigned int i=0; i<tb.BjetValues.size(); i++)
166 BjetValues.push_back(tb.BjetValues[i]);
167
168
169 for(unsigned int i=0; i<tb.TauJetValues.size(); i++)
170 TauJetValues.push_back(tb.TauJetValues[i]);
171
172 for(unsigned int i=0; i<tb.EtmisValues.size(); i++)
173 EtmisValues.push_back(tb.EtmisValues[i]);
174
175 for(unsigned int i=0; i<tb.GammaValues.size(); i++)
176 GammaValues.push_back(tb.GammaValues[i]);
177
178 Result = tb.Result;
179}
180
181TriggerBit& TriggerBit::operator=(const TriggerBit& tb) {
182 if (this==&tb) return *this;
183 for(unsigned int i=0; i<tb.ElecValues.size(); i++)
184 ElecValues.push_back(tb.ElecValues[i]);
185
186 for(unsigned int i=0; i<tb.IElecValues.size(); i++)
187 IElecValues.push_back(tb.IElecValues[i]);
188
189 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
190 MuonValues.push_back(tb.MuonValues[i]);
191
192 for(unsigned int i=0; i<tb.IMuonValues.size(); i++)
193 IMuonValues.push_back(tb.IMuonValues[i]);
194
195 for(unsigned int i=0; i<tb.JetValues.size(); i++)
196 JetValues.push_back(tb.JetValues[i]);
197
198 for(unsigned int i=0; i<tb.BjetValues.size(); i++)
199 BjetValues.push_back(tb.BjetValues[i]);
200
201 for(unsigned int i=0; i<tb.TauJetValues.size(); i++)
202 TauJetValues.push_back(tb.TauJetValues[i]);
203
204 for(unsigned int i=0; i<tb.EtmisValues.size(); i++)
205 EtmisValues.push_back(tb.EtmisValues[i]);
206
207 for(unsigned int i=0; i<tb.GammaValues.size(); i++)
208 GammaValues.push_back(tb.GammaValues[i]);
209 Result = tb.Result;
210
211 return *this;
212}
213
214
215
216bool TriggerBit::GetResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
217 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
218 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig)
219{
220
221 TSimpleArray<TRootJet> bjets=SubArrayBjets(branchJetTrig);
222 TSimpleArray<TRootElectron> Ielectron=SubArrayIElec(branchElecTrig);
223 TSimpleArray<TRootMuon> Imuon=SubArrayIMuon(branchMuonTrig);
224
225 int elec_size = ElecValues.size();
226 int Ielec_size = IElecValues.size();
227 int muon_size = MuonValues.size();
228 int Imuon_size = IMuonValues.size();
229 int jet_size = JetValues.size();
230 int bjet_size = BjetValues.size();
231 int taujet_size = TauJetValues.size();
232 int gamma_size = GammaValues.size();
233 int etmis_size = EtmisValues.size();
234
235 Result=false;
236 if(
237 (branchElecTrig->GetEntries() >= elec_size )
238 && (Ielectron.GetEntries() >= Ielec_size )
239 && (branchMuonTrig->GetEntries() >= muon_size )
240 && (Imuon.GetEntries() >= Imuon_size )
241 && (branchJetTrig->GetEntries() >= jet_size )
242 && (bjets.GetEntries() >= bjet_size )
243 && (branchTauJetTrig->GetEntries() >= taujet_size )
244 && (branchPhotonTrig->GetEntries() >= gamma_size )
245 )
246 {
247 Result=true;
248 if(elec_size!=0){
249 TRootElectron *electron;
250 for(int i=0;i<elec_size;i++){
251 electron = (TRootElectron*)branchElecTrig->At(i);
252 if(electron->PT < ElecValues[i])Result=false;}}
253
254 if(Ielec_size!=0)
255 {
256 TRootElectron *i_elec; Ielectron.Reset();
257 int i=0;
258 while((i_elec = Ielectron.Next()))
259 {
260 if(i_elec->PT < IElecValues[i])Result=false;
261 i++;
262 }
263 }
264
265
266 if(muon_size!=0){
267 TRootMuon *muon;
268 for(int i=0;i<muon_size;i++){
269 muon = (TRootMuon*)branchMuonTrig->At(i);
270 if(muon->PT < MuonValues[i])Result=false;}}
271
272 if(Imuon_size!=0)
273 {
274 TRootMuon *i_muon; Imuon.Reset();
275 int i=0;
276 while((i_muon = Imuon.Next()))
277 {
278 if(i_muon->PT < IMuonValues[i])Result=false;
279 i++;
280 }
281 }
282
283 if(jet_size!=0){
284 TRootJet *jet;
285 for(int i=0;i<jet_size;i++){
286 jet = (TRootJet*)branchJetTrig->At(i);
287 if(jet->PT < JetValues[i])Result=false;}}
288
289 if(jet_size!=0){
290 TRootJet *jet;
291 for(int i=0;i<jet_size;i++){
292 jet = (TRootJet*)branchJetTrig->At(i);
293 if(jet->PT < JetValues[i])Result=false;}}
294
295 if(bjet_size!=0)
296 {
297 TRootJet *i_bjets; bjets.Reset();
298 int i=0;
299 while((i_bjets = bjets.Next()))
300 {
301 if(i_bjets->PT < BjetValues[i])Result=false;
302 i++;
303 }
304 }
305
306
307 if(taujet_size!=0){
308 TRootTauJet *taujet;
309 for(int i=0;i<taujet_size;i++){
310 taujet = (TRootTauJet*)branchTauJetTrig->At(i);
311 if(taujet->PT < TauJetValues[i])Result=false;}}
312
313 if(gamma_size!=0){
314 TRootPhoton *gamma;
315 for(int i=0;i<gamma_size;i++){
316 gamma = (TRootPhoton*)branchPhotonTrig->At(i);
317 if(gamma->PT < GammaValues[i])Result=false;}}
318
319
320 if(etmis_size!=0){
321 TRootETmis *etmis = (TRootETmis*)branchETmisTrig->At(0);
322 if(etmis->ET < EtmisValues[0])Result=false;}
323
324 }
325 return Result;
326}
327
328void TriggerBit::GetTrigCondition(const string& trigger_algorithm) {
329
330 vector<string> ElecSequences;
331 vector<string> IElecSequences;
332 vector<string> MuonSequences;
333 vector<string> IMuonSequences;
334 vector<string> JetSequences;
335 vector<string> TauJetSequences;
336 vector<string> EtmisSequences;
337 vector<string> GammaSequences;
338 vector<string> BjetSequences;
339
340/// char *result =NULL;
341 char * result = new char[256];
342 result = strtok( (char*) trigger_algorithm.c_str(),"&");
343 while( result != NULL )
344 {
345 if(strstr (result,"ELEC"))ElecSequences.push_back(result);
346 if(strstr (result,"IElec"))IElecSequences.push_back(result);
347 if(strstr (result,"MUON"))MuonSequences.push_back(result);
348 if(strstr (result,"IMuon"))IMuonSequences.push_back(result);
349 if(strstr (result,"JET"))JetSequences.push_back(result);
350 if(strstr (result,"TAU"))TauJetSequences.push_back(result);
351 if(strstr (result,"ETMIS"))EtmisSequences.push_back(result);
352 if(strstr (result,"GAMMA"))GammaSequences.push_back(result);
353 if(strstr (result,"Bjet"))BjetSequences.push_back(result);
354 result = strtok( NULL,"&");
355 }
356 delete result;
357
358 ElecValues = GetCuts(ElecSequences);
359 IElecValues = GetCuts(IElecSequences);
360 MuonValues = GetCuts(MuonSequences);
361 IMuonValues = GetCuts(IMuonSequences);
362 JetValues = GetCuts(JetSequences);
363 TauJetValues = GetCuts(TauJetSequences);
364 EtmisValues = GetCuts(EtmisSequences);
365 GammaValues = GetCuts(GammaSequences);
366 BjetValues = GetCuts(BjetSequences);
367
368}
369
370void TriggerBit::PrintTrigCondition(const string& LogName,const int i)
371{
372 int elec_size = TriggerBit::ElecValues.size();
373 int Ielec_size = TriggerBit::IElecValues.size();
374 int muon_size = TriggerBit::MuonValues.size();
375 int Imuon_size = TriggerBit::IMuonValues.size();
376 int jet_size = TriggerBit::JetValues.size();
377 int taujet_size = TriggerBit::TauJetValues.size();
378 int gamma_size = TriggerBit::GammaValues.size();
379 int etmis_size = TriggerBit::EtmisValues.size();
380 int bjets_size = TriggerBit::BjetValues.size();
381
382 ofstream f_out(LogName.c_str(),ios::app);
383
384 f_out <<"* *"<<"\n";
385 f_out << left << setw(25) <<"# Trigger bit number "<<""
386 << left << setw(35) <<i <<""<< right << setw(10)<<"*"<<"\n";
387 f_out <<"#*************************"<<"\n";
388 f_out << left << setw(45) <<"* # Number of reconstructed objects required:"<<""<<right << setw(23)<<"*"<<"\n";
389
390 if(elec_size!=0){
391 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << elec_size <<""<< left << setw(20)<<"Electron(s) with p_T: "<<"";
392 for(int i=0;i<elec_size;i++){f_out << left << setw(5) << TriggerBit::ElecValues[i]<<"";}f_out <<"\n";}
393
394 if(Ielec_size!=0){
395 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << Ielec_size <<""<< left << setw(20)<<"Isolated electron(s) with p_T: "<<"";
396 for(int i=0;i<Ielec_size;i++){f_out << left << setw(5) << TriggerBit::IElecValues[i]<<"";}f_out <<"\n";}
397
398 if(muon_size!=0){
399 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << muon_size <<""<< left << setw(20)<<"Muon(s) with p_T: "<<"";
400 for(int i=0;i<muon_size;i++){f_out << left << setw(5) << TriggerBit::MuonValues[i]<<"";}f_out <<"\n";}
401
402 if(Imuon_size!=0){
403 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << Imuon_size <<""<< left << setw(20)<<"Isolated muon(s) with p_T: "<<"";
404 for(int i=0;i<Imuon_size;i++){f_out << left << setw(5) << TriggerBit::IMuonValues[i]<<"";}f_out <<"\n";}
405
406 if(jet_size!=0){
407 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << jet_size <<""<< left << setw(20)<<"Jet(s) with p_T: "<<"";
408 for(int i=0;i<jet_size;i++){f_out << left << setw(5) << TriggerBit::JetValues[i]<<"";}f_out <<"\n";}
409
410 if(taujet_size!=0){
411 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << taujet_size <<""<< left << setw(20)<<"Tau-jet(s) with p_T: "<<"";
412 for(int i=0;i<taujet_size;i++){f_out << left << setw(5) << TriggerBit::TauJetValues[i]<<"";}f_out <<"\n";}
413
414 if(bjets_size!=0){
415 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << bjets_size <<""<< left << setw(20)<<"B-jet(s) with p_T: "<<"";
416 for(int i=0;i<bjets_size;i++){f_out << left << setw(5) << TriggerBit::BjetValues[i]<<"";}f_out <<"\n";}
417
418 if(gamma_size!=0){
419 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << gamma_size <<""<< left << setw(20)<<"Photon(s) with p_T: "<<"";
420 for(int i=0;i<gamma_size;i++){f_out << left << setw(5) << TriggerBit::GammaValues[i]<<"";}f_out <<"\n";}
421
422 if(etmis_size!=0){
423 f_out << left << setw(5) <<"** -"<<""<< left << setw(20)<<"Transverse missing energy with p_T: "<<"";
424 for(int i=0;i<etmis_size;i++){f_out << left << setw(5) << TriggerBit::EtmisValues[i]<<"";}f_out <<"\n";}
425 f_out <<"* *"<<"\n";
426 f_out <<"**********************************************************************"<<"\n";
427
428}
429
430vector<float> TriggerBit::GetCuts(const vector<string> &Sequences)
431{
432 vector<float> OrderedValue;
433 string ptVal;
434 Int_t PtVal=0;
435 for(unsigned int i=0; i < Sequences.size(); i++) {
436 ptVal = Sequences[i].substr( Sequences[i].find("'")+1) ;
437 PtVal = atoi( ptVal.c_str() );
438 OrderedValue.push_back(PtVal);
439 }
440 return OrderedValue;
441}
442
443TSimpleArray<TRootJet> TriggerBit::SubArrayBjets(TClonesArray *JET)
444{
445 TIter itJet((TCollection*)JET);
446 TRootJet *jet;
447 itJet.Reset();
448 TSimpleArray<TRootJet> array;
449 while( (jet = (TRootJet*) itJet.Next()) )
450 {
451 if(jet->Btag==1)array.Add(jet);
452 }
453 return array;
454}
455
456TSimpleArray<TRootElectron> TriggerBit::SubArrayIElec(TClonesArray *ELEC)
457{
458 TIter itElec((TCollection*)ELEC);
459 TRootElectron *electron;
460 itElec.Reset();
461 TSimpleArray<TRootElectron> array;
462 while( (electron = (TRootElectron*) itElec.Next()) )
463 {
464 if(electron->IsolFlag==1)array.Add(electron);
465 }
466 return array;
467}
468
469TSimpleArray<TRootMuon> TriggerBit::SubArrayIMuon(TClonesArray *MUON)
470{
471 TIter itMuon((TCollection*)MUON);
472 TRootMuon *muon;
473 itMuon.Reset();
474 TSimpleArray<TRootMuon> array;
475 while( (muon = (TRootMuon*) itMuon.Next()) )
476 {
477 if(muon->IsolFlag==1)array.Add(muon);
478 }
479 return array;
480}
481
482
Note: See TracBrowser for help on using the repository browser.