Fork me on GitHub

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

Last change on this file since 513 was 443, checked in by Xavier Rouby, 15 years ago

new header in all files

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