Fork me on GitHub

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

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

first test 2.0

File size: 17.2 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//*************************************************************************
134TriggerBit::TriggerBit() {
135}
136
137TriggerBit::~TriggerBit() {
138 ElecValues.clear();
139 IElecValues.clear();
140 MuonValues.clear();
141 IMuonValues.clear();
142 JetValues.clear();
143 BjetValues.clear();
144 TauJetValues.clear();
145 EtmisValues.clear();
146 GammaValues.clear();
147}
148
149TriggerBit::TriggerBit(const TriggerBit& tb) {
150 for(unsigned int i=0; i<tb.ElecValues.size(); i++)
151 ElecValues.push_back(tb.ElecValues[i]);
152
153 for(unsigned int i=0; i<tb.IElecValues.size(); i++)
154 IElecValues.push_back(tb.IElecValues[i]);
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 for(unsigned int i=0; i<tb.TauJetValues.size(); i++)
169 TauJetValues.push_back(tb.TauJetValues[i]);
170
171 for(unsigned int i=0; i<tb.EtmisValues.size(); i++)
172 EtmisValues.push_back(tb.EtmisValues[i]);
173
174 for(unsigned int i=0; i<tb.GammaValues.size(); i++)
175 GammaValues.push_back(tb.GammaValues[i]);
176
177 Result = tb.Result;
178}
179
180TriggerBit& TriggerBit::operator=(const TriggerBit& tb) {
181 if (this==&tb) return *this;
182 for(unsigned int i=0; i<tb.ElecValues.size(); i++)
183 ElecValues.push_back(tb.ElecValues[i]);
184
185 for(unsigned int i=0; i<tb.IElecValues.size(); i++)
186 IElecValues.push_back(tb.IElecValues[i]);
187
188 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
189 MuonValues.push_back(tb.MuonValues[i]);
190
191 for(unsigned int i=0; i<tb.IMuonValues.size(); i++)
192 IMuonValues.push_back(tb.IMuonValues[i]);
193
194 for(unsigned int i=0; i<tb.JetValues.size(); i++)
195 JetValues.push_back(tb.JetValues[i]);
196
197 for(unsigned int i=0; i<tb.BjetValues.size(); i++)
198 BjetValues.push_back(tb.BjetValues[i]);
199
200 for(unsigned int i=0; i<tb.TauJetValues.size(); i++)
201 TauJetValues.push_back(tb.TauJetValues[i]);
202
203 for(unsigned int i=0; i<tb.EtmisValues.size(); i++)
204 EtmisValues.push_back(tb.EtmisValues[i]);
205
206 for(unsigned int i=0; i<tb.GammaValues.size(); i++)
207 GammaValues.push_back(tb.GammaValues[i]);
208 Result = tb.Result;
209
210 return *this;
211}
212
213
214
215bool TriggerBit::GetResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
216 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
217 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig)
218{
219 TSimpleArray<TRootJet> bjets=SubArrayBjets(branchJetTrig);
220 TSimpleArray<TRootElectron> Ielectron=SubArrayIElec(branchElecTrig);
221 TSimpleArray<TRootMuon> Imuon=SubArrayIMuon(branchMuonTrig);
222
223 int elec_size = ElecValues.size();
224 int Ielec_size = IElecValues.size();
225 int muon_size = MuonValues.size();
226 int Imuon_size = IMuonValues.size();
227 int jet_size = JetValues.size();
228 int bjet_size = BjetValues.size();
229 int taujet_size = TauJetValues.size();
230 int gamma_size = GammaValues.size();
231 int etmis_size = EtmisValues.size();
232
233 Result=false;
234 if(
235 (branchElecTrig->GetEntries() >= elec_size )
236 && (Ielectron.GetEntries() >= Ielec_size )
237 && (branchMuonTrig->GetEntries() >= muon_size )
238 && (Imuon.GetEntries() >= Imuon_size )
239 && (branchJetTrig->GetEntries() >= jet_size )
240 && (bjets.GetEntries() >= bjet_size )
241 && (branchTauJetTrig->GetEntries() >= taujet_size )
242 && (branchPhotonTrig->GetEntries() >= gamma_size )
243 )
244 {
245 Result=true;
246 if(elec_size!=0){
247 TRootElectron *electron;
248 for(int i=0;i<elec_size;i++){
249 electron = (TRootElectron*)branchElecTrig->At(i);
250 if(electron->PT < ElecValues[i])Result=false;}}
251
252 if(Ielec_size!=0)
253 {
254 TRootElectron *i_elec; Ielectron.Reset();
255 int i=0;
256 while((i_elec = Ielectron.Next()))
257 {
258 if(i_elec->PT < IElecValues[i])Result=false;
259 i++;
260 }
261 }
262
263 if(muon_size!=0){
264 TRootMuon *muon;
265 for(int i=0;i<muon_size;i++){
266 muon = (TRootMuon*)branchMuonTrig->At(i);
267 if(muon->PT < MuonValues[i])Result=false;}}
268
269 if(Imuon_size!=0)
270 {
271 TRootMuon *i_muon; Imuon.Reset();
272 int i=0;
273 while((i_muon = Imuon.Next()))
274 {
275 if(i_muon->PT < IMuonValues[i])Result=false;
276 i++;
277 }
278 }
279
280 if(jet_size!=0){
281 TRootJet *jet;
282 for(int i=0;i<jet_size;i++){
283 jet = (TRootJet*)branchJetTrig->At(i);
284 if(jet->PT < JetValues[i])Result=false;}}
285
286 if(bjet_size!=0)
287 {
288 TRootJet *i_bjets; bjets.Reset();
289 int i=0;
290 while((i_bjets = bjets.Next()))
291 {
292 if(i_bjets->PT < BjetValues[i])Result=false;
293 i++;
294 }
295 }
296
297 if(taujet_size!=0){
298 TRootTauJet *taujet;
299 for(int i=0;i<taujet_size;i++){
300 taujet = (TRootTauJet*)branchTauJetTrig->At(i);
301 if(taujet->PT < TauJetValues[i])Result=false;}}
302
303 if(gamma_size!=0){
304 TRootPhoton *gamma;
305 for(int i=0;i<gamma_size;i++){
306 gamma = (TRootPhoton*)branchPhotonTrig->At(i);
307 if(gamma->PT < GammaValues[i])Result=false;}}
308
309
310 if(etmis_size!=0){
311 TRootETmis *etmis = (TRootETmis*)branchETmisTrig->At(0);
312 if(etmis->ET < EtmisValues[0])Result=false;}
313
314 }
315 return Result;
316}
317
318void TriggerBit::GetTrigCondition(const string& trigger_algorithm) {
319
320 vector<string> ElecSequences;
321 vector<string> IElecSequences;
322 vector<string> MuonSequences;
323 vector<string> IMuonSequences;
324 vector<string> JetSequences;
325 vector<string> TauJetSequences;
326 vector<string> EtmisSequences;
327 vector<string> GammaSequences;
328 vector<string> BjetSequences;
329
330 char * result = new char[256];
331 result = strtok( (char*) trigger_algorithm.c_str(),"&");
332 while( result != NULL )
333 {
334 if(strstr (result,"ELEC"))ElecSequences.push_back(result);
335 if(strstr (result,"IElec"))IElecSequences.push_back(result);
336 if(strstr (result,"MUON"))MuonSequences.push_back(result);
337 if(strstr (result,"IMuon"))IMuonSequences.push_back(result);
338 if(strstr (result,"JET"))JetSequences.push_back(result);
339 if(strstr (result,"TAU"))TauJetSequences.push_back(result);
340 if(strstr (result,"ETMIS"))EtmisSequences.push_back(result);
341 if(strstr (result,"GAMMA"))GammaSequences.push_back(result);
342 if(strstr (result,"Bjet"))BjetSequences.push_back(result);
343 result = strtok( NULL,"&");
344 }
345 delete [] result;
346
347 ElecValues = GetCuts(ElecSequences);
348 IElecValues = GetCuts(IElecSequences);
349 MuonValues = GetCuts(MuonSequences);
350 IMuonValues = GetCuts(IMuonSequences);
351 JetValues = GetCuts(JetSequences);
352 TauJetValues = GetCuts(TauJetSequences);
353 EtmisValues = GetCuts(EtmisSequences);
354 GammaValues = GetCuts(GammaSequences);
355 BjetValues = GetCuts(BjetSequences);
356
357}
358
359
360void TriggerBit::PrintTrigCondition(const string& LogName,const int i)
361{
362 int elec_size = TriggerBit::ElecValues.size();
363 int Ielec_size = TriggerBit::IElecValues.size();
364 int muon_size = TriggerBit::MuonValues.size();
365 int Imuon_size = TriggerBit::IMuonValues.size();
366 int jet_size = TriggerBit::JetValues.size();
367 int taujet_size = TriggerBit::TauJetValues.size();
368 int gamma_size = TriggerBit::GammaValues.size();
369 int etmis_size = TriggerBit::EtmisValues.size();
370 int bjets_size = TriggerBit::BjetValues.size();
371
372 ofstream f_out(LogName.c_str(),ios::app);
373
374 f_out <<"* *"<<"\n";
375 f_out << left << setw(25) <<"# Trigger bit number "<<""
376 << left << setw(35) <<i <<""<< right << setw(10)<<"*"<<"\n";
377 f_out <<"#*************************"<<"\n";
378 f_out << left << setw(45) <<"* # Number of reconstructed objects required:"<<""<<right << setw(23)<<"*"<<"\n";
379
380 if(elec_size!=0){
381 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << elec_size <<""<< left << setw(20)<<"Electron(s) with p_T: "<<"";
382 for(int i=0;i<elec_size;i++){f_out << left << setw(5) << TriggerBit::ElecValues[i]<<"";}f_out <<"\n";}
383
384 if(Ielec_size!=0){
385 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << Ielec_size <<""<< left << setw(20)<<"Isolated electron(s) with p_T: "<<"";
386 for(int i=0;i<Ielec_size;i++){f_out << left << setw(5) << TriggerBit::IElecValues[i]<<"";}f_out <<"\n";}
387
388 if(muon_size!=0){
389 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << muon_size <<""<< left << setw(20)<<"Muon(s) with p_T: "<<"";
390 for(int i=0;i<muon_size;i++){f_out << left << setw(5) << TriggerBit::MuonValues[i]<<"";}f_out <<"\n";}
391
392 if(Imuon_size!=0){
393 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << Imuon_size <<""<< left << setw(20)<<"Isolated muon(s) with p_T: "<<"";
394 for(int i=0;i<Imuon_size;i++){f_out << left << setw(5) << TriggerBit::IMuonValues[i]<<"";}f_out <<"\n";}
395
396 if(jet_size!=0){
397 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << jet_size <<""<< left << setw(20)<<"Jet(s) with p_T: "<<"";
398 for(int i=0;i<jet_size;i++){f_out << left << setw(5) << TriggerBit::JetValues[i]<<"";}f_out <<"\n";}
399
400 if(taujet_size!=0){
401 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << taujet_size <<""<< left << setw(20)<<"Tau-jet(s) with p_T: "<<"";
402 for(int i=0;i<taujet_size;i++){f_out << left << setw(5) << TriggerBit::TauJetValues[i]<<"";}f_out <<"\n";}
403
404 if(bjets_size!=0){
405 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << bjets_size <<""<< left << setw(20)<<"B-jet(s) with p_T: "<<"";
406 for(int i=0;i<bjets_size;i++){f_out << left << setw(5) << TriggerBit::BjetValues[i]<<"";}f_out <<"\n";}
407
408 if(gamma_size!=0){
409 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << gamma_size <<""<< left << setw(20)<<"Photon(s) with p_T: "<<"";
410 for(int i=0;i<gamma_size;i++){f_out << left << setw(5) << TriggerBit::GammaValues[i]<<"";}f_out <<"\n";}
411
412 if(etmis_size!=0){
413 f_out << left << setw(5) <<"** -"<<""<< left << setw(20)<<"Transverse missing energy with p_T: "<<"";
414 for(int i=0;i<etmis_size;i++){f_out << left << setw(5) << TriggerBit::EtmisValues[i]<<"";}f_out <<"\n";}
415 f_out <<"* *"<<"\n";
416 f_out <<"**********************************************************************"<<"\n";
417
418}
419
420vector<float> TriggerBit::GetCuts(const vector<string> &Sequences)
421{
422 vector<float> OrderedValue;
423 string ptVal;
424 Int_t PtVal=0;
425 for(unsigned int i=0; i < Sequences.size(); i++) {
426 ptVal = Sequences[i].substr( Sequences[i].find("'")+1) ;
427 PtVal = atoi( ptVal.c_str() );
428 OrderedValue.push_back(PtVal);
429 }
430 return OrderedValue;
431
432}
433
434TSimpleArray<TRootJet> TriggerBit::SubArrayBjets(TClonesArray *JET)
435{
436 TIter itJet((TCollection*)JET);
437 TRootJet *jet;
438 itJet.Reset();
439 TSimpleArray<TRootJet> array;
440 while( (jet = (TRootJet*) itJet.Next()) )
441 {
442 if(jet->Btag==1)array.Add(jet);
443 }
444 return array;
445}
446
447TSimpleArray<TRootElectron> TriggerBit::SubArrayIElec(TClonesArray *ELEC)
448{
449 TIter itElec((TCollection*)ELEC);
450 TRootElectron *electron;
451 itElec.Reset();
452 TSimpleArray<TRootElectron> array;
453 while( (electron = (TRootElectron*) itElec.Next()) )
454 {
455 if(electron->IsolFlag==1)array.Add(electron);
456 }
457 return array;
458}
459
460TSimpleArray<TRootMuon> TriggerBit::SubArrayIMuon(TClonesArray *MUON)
461{
462 TIter itMuon((TCollection*)MUON);
463 TRootMuon *muon;
464 itMuon.Reset();
465 TSimpleArray<TRootMuon> array;
466 while( (muon = (TRootMuon*) itMuon.Next()) )
467 {
468 if(muon->IsolFlag==1)array.Add(muon);
469 }
470 return array;
471}
472
Note: See TracBrowser for help on using the repository browser.