Fork me on GitHub

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

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

new header in all files

File size: 17.3 KB
RevLine 
[260]1/***********************************************************************
2** **
3** /----------------------------------------------\ **
4** | Delphes, a framework for the fast simulation | **
5** | of a generic collider experiment | **
[443]6** \------------- arXiv:0903.2225v1 ------------/ **
[260]7** **
8** **
9** This package uses: **
10** ------------------ **
[443]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] **
[260]14** FROG: [hep-ex/0901.2718v1] **
[443]15** HepMC: Comput. Phys. Commun.134 (2001) 41 **
[260]16** **
17** ------------------------------------------------------------------ **
18** **
19** Main authors: **
20** ------------- **
21** **
[443]22** Severine Ovyn Xavier Rouby **
23** severine.ovyn@uclouvain.be xavier.rouby@cern **
[260]24** **
[443]25** Center for Particle Physics and Phenomenology (CP3) **
26** Universite catholique de Louvain (UCL) **
27** Louvain-la-Neuve, Belgium **
28** **
[260]29** Copyright (C) 2008-2009, **
[443]30** All rights reserved. **
[260]31** **
32***********************************************************************/
[52]33
[443]34
[52]35// \brief Trigger class, and some generic definitions
36
[219]37#include "TriggerUtil.h"
[52]38
39#include <iostream>
[219]40#include <iomanip>
[52]41#include <sstream>
42#include <fstream>
[219]43#include <string>
[52]44
45using namespace std;
46
[63]47TriggerTable::TriggerTable() {
48 has_been_evaluated=false;
49}
[52]50
[243]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
[219]68void TriggerTable::TriggerCardReader(const string& filename){
[63]69 ifstream trigger_file(filename.c_str());
70 if( !trigger_file.good() ) {
[250]71 cerr << left << setw(30) <<"** ERROR: Trigger input file "<<""
72 << right << setw(15) <<filename<<""
73 << right << setw(24) <<"not found. Exiting... **"<<endl;
[63]74 return;
[52]75 }
76
[63]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 }
[52]90}
91
[63]92
[219]93void TriggerTable::PrintTriggerTable(const string& LogName) {
[63]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 }
[74]107 f_out<<"* *"<<"\n";
108 f_out<<"#*********************************************************************"<<"\n";
109
[63]110}
111
[72]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
[63]136//*************************************************************************
[264]137TriggerBit::TriggerBit() {
138}
[63]139
[243]140TriggerBit::~TriggerBit() {
141 ElecValues.clear();
[250]142 IElecValues.clear();
[243]143 MuonValues.clear();
[250]144 IMuonValues.clear();
[243]145 JetValues.clear();
[250]146 BjetValues.clear();
[243]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
[250]156 for(unsigned int i=0; i<tb.IElecValues.size(); i++)
157 IElecValues.push_back(tb.IElecValues[i]);
158
[243]159 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
160 MuonValues.push_back(tb.MuonValues[i]);
161
[250]162 for(unsigned int i=0; i<tb.IMuonValues.size(); i++)
163 IMuonValues.push_back(tb.IMuonValues[i]);
164
[243]165 for(unsigned int i=0; i<tb.JetValues.size(); i++)
166 JetValues.push_back(tb.JetValues[i]);
167
[250]168 for(unsigned int i=0; i<tb.BjetValues.size(); i++)
169 BjetValues.push_back(tb.BjetValues[i]);
170
[243]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
[250]188 for(unsigned int i=0; i<tb.IElecValues.size(); i++)
189 IElecValues.push_back(tb.IElecValues[i]);
190
[243]191 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
192 MuonValues.push_back(tb.MuonValues[i]);
193
[250]194 for(unsigned int i=0; i<tb.IMuonValues.size(); i++)
195 IMuonValues.push_back(tb.IMuonValues[i]);
196
[243]197 for(unsigned int i=0; i<tb.JetValues.size(); i++)
198 JetValues.push_back(tb.JetValues[i]);
199
[250]200 for(unsigned int i=0; i<tb.BjetValues.size(); i++)
201 BjetValues.push_back(tb.BjetValues[i]);
202
[243]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
[72]218bool TriggerBit::GetResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
219 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
220 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig)
221{
[250]222 TSimpleArray<TRootJet> bjets=SubArrayBjets(branchJetTrig);
223 TSimpleArray<TRootElectron> Ielectron=SubArrayIElec(branchElecTrig);
224 TSimpleArray<TRootMuon> Imuon=SubArrayIMuon(branchMuonTrig);
[264]225
[72]226 int elec_size = ElecValues.size();
[250]227 int Ielec_size = IElecValues.size();
[72]228 int muon_size = MuonValues.size();
[250]229 int Imuon_size = IMuonValues.size();
[72]230 int jet_size = JetValues.size();
[250]231 int bjet_size = BjetValues.size();
[72]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 )
[250]239 && (Ielectron.GetEntries() >= Ielec_size )
[72]240 && (branchMuonTrig->GetEntries() >= muon_size )
[250]241 && (Imuon.GetEntries() >= Imuon_size )
[72]242 && (branchJetTrig->GetEntries() >= jet_size )
[250]243 && (bjets.GetEntries() >= bjet_size )
[72]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
[250]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
[72]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
[250]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
[72]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
[250]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
[72]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
[63]321void TriggerBit::GetTrigCondition(const string& trigger_algorithm) {
322
[52]323 vector<string> ElecSequences;
[250]324 vector<string> IElecSequences;
[52]325 vector<string> MuonSequences;
[250]326 vector<string> IMuonSequences;
[52]327 vector<string> JetSequences;
328 vector<string> TauJetSequences;
329 vector<string> EtmisSequences;
330 vector<string> GammaSequences;
[250]331 vector<string> BjetSequences;
[63]332
[250]333 char * result = new char[256];
[52]334 result = strtok( (char*) trigger_algorithm.c_str(),"&");
[63]335 while( result != NULL )
[52]336 {
337 if(strstr (result,"ELEC"))ElecSequences.push_back(result);
[250]338 if(strstr (result,"IElec"))IElecSequences.push_back(result);
[52]339 if(strstr (result,"MUON"))MuonSequences.push_back(result);
[250]340 if(strstr (result,"IMuon"))IMuonSequences.push_back(result);
[52]341 if(strstr (result,"JET"))JetSequences.push_back(result);
[250]342 if(strstr (result,"TAU"))TauJetSequences.push_back(result);
[52]343 if(strstr (result,"ETMIS"))EtmisSequences.push_back(result);
344 if(strstr (result,"GAMMA"))GammaSequences.push_back(result);
[250]345 if(strstr (result,"Bjet"))BjetSequences.push_back(result);
[52]346 result = strtok( NULL,"&");
[63]347 }
[264]348 delete [] result;
[52]349
[63]350 ElecValues = GetCuts(ElecSequences);
[250]351 IElecValues = GetCuts(IElecSequences);
[63]352 MuonValues = GetCuts(MuonSequences);
[250]353 IMuonValues = GetCuts(IMuonSequences);
[63]354 JetValues = GetCuts(JetSequences);
355 TauJetValues = GetCuts(TauJetSequences);
356 EtmisValues = GetCuts(EtmisSequences);
357 GammaValues = GetCuts(GammaSequences);
[250]358 BjetValues = GetCuts(BjetSequences);
[63]359
[52]360}
[219]361
[264]362
[219]363void TriggerBit::PrintTrigCondition(const string& LogName,const int i)
[63]364{
365 int elec_size = TriggerBit::ElecValues.size();
[250]366 int Ielec_size = TriggerBit::IElecValues.size();
[63]367 int muon_size = TriggerBit::MuonValues.size();
[250]368 int Imuon_size = TriggerBit::IMuonValues.size();
[63]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();
[250]373 int bjets_size = TriggerBit::BjetValues.size();
[264]374
[63]375 ofstream f_out(LogName.c_str(),ios::app);
[52]376
[63]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";
[250]382
[63]383 if(elec_size!=0){
[250]384 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << elec_size <<""<< left << setw(20)<<"Electron(s) with p_T: "<<"";
[63]385 for(int i=0;i<elec_size;i++){f_out << left << setw(5) << TriggerBit::ElecValues[i]<<"";}f_out <<"\n";}
[52]386
[250]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
[63]391 if(muon_size!=0){
[250]392 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << muon_size <<""<< left << setw(20)<<"Muon(s) with p_T: "<<"";
[63]393 for(int i=0;i<muon_size;i++){f_out << left << setw(5) << TriggerBit::MuonValues[i]<<"";}f_out <<"\n";}
[52]394
[250]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
[63]399 if(jet_size!=0){
[250]400 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << jet_size <<""<< left << setw(20)<<"Jet(s) with p_T: "<<"";
[63]401 for(int i=0;i<jet_size;i++){f_out << left << setw(5) << TriggerBit::JetValues[i]<<"";}f_out <<"\n";}
[52]402
[63]403 if(taujet_size!=0){
[250]404 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << taujet_size <<""<< left << setw(20)<<"Tau-jet(s) with p_T: "<<"";
[63]405 for(int i=0;i<taujet_size;i++){f_out << left << setw(5) << TriggerBit::TauJetValues[i]<<"";}f_out <<"\n";}
[250]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
[63]411 if(gamma_size!=0){
[250]412 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << gamma_size <<""<< left << setw(20)<<"Photon(s) with p_T: "<<"";
[63]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){
[250]416 f_out << left << setw(5) <<"** -"<<""<< left << setw(20)<<"Transverse missing energy with p_T: "<<"";
[63]417 for(int i=0;i<etmis_size;i++){f_out << left << setw(5) << TriggerBit::EtmisValues[i]<<"";}f_out <<"\n";}
418 f_out <<"* *"<<"\n";
[260]419 f_out <<"**********************************************************************"<<"\n";
[63]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);
[52]432 }
[63]433 return OrderedValue;
[264]434
[250]435}
[63]436
[250]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;
[52]448}
449
[250]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}
[63]462
[250]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.