Fork me on GitHub

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

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

first test 2.0

File size: 17.2 KB
RevLine 
[260]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***********************************************************************/
[52]31
32// \brief Trigger class, and some generic definitions
33
[219]34#include "TriggerUtil.h"
[52]35
36#include <iostream>
[219]37#include <iomanip>
[52]38#include <sstream>
39#include <fstream>
[219]40#include <string>
[52]41
42using namespace std;
43
[63]44TriggerTable::TriggerTable() {
45 has_been_evaluated=false;
46}
[52]47
[243]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
[219]65void TriggerTable::TriggerCardReader(const string& filename){
[63]66 ifstream trigger_file(filename.c_str());
67 if( !trigger_file.good() ) {
[250]68 cerr << left << setw(30) <<"** ERROR: Trigger input file "<<""
69 << right << setw(15) <<filename<<""
70 << right << setw(24) <<"not found. Exiting... **"<<endl;
[63]71 return;
[52]72 }
73
[63]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 }
[52]87}
88
[63]89
[219]90void TriggerTable::PrintTriggerTable(const string& LogName) {
[63]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 }
[74]104 f_out<<"* *"<<"\n";
105 f_out<<"#*********************************************************************"<<"\n";
106
[63]107}
108
[72]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
[63]133//*************************************************************************
[264]134TriggerBit::TriggerBit() {
135}
[63]136
[243]137TriggerBit::~TriggerBit() {
138 ElecValues.clear();
[250]139 IElecValues.clear();
[243]140 MuonValues.clear();
[250]141 IMuonValues.clear();
[243]142 JetValues.clear();
[250]143 BjetValues.clear();
[243]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
[250]153 for(unsigned int i=0; i<tb.IElecValues.size(); i++)
154 IElecValues.push_back(tb.IElecValues[i]);
155
[243]156 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
157 MuonValues.push_back(tb.MuonValues[i]);
158
[250]159 for(unsigned int i=0; i<tb.IMuonValues.size(); i++)
160 IMuonValues.push_back(tb.IMuonValues[i]);
161
[243]162 for(unsigned int i=0; i<tb.JetValues.size(); i++)
163 JetValues.push_back(tb.JetValues[i]);
164
[250]165 for(unsigned int i=0; i<tb.BjetValues.size(); i++)
166 BjetValues.push_back(tb.BjetValues[i]);
167
[243]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
[250]185 for(unsigned int i=0; i<tb.IElecValues.size(); i++)
186 IElecValues.push_back(tb.IElecValues[i]);
187
[243]188 for(unsigned int i=0; i<tb.MuonValues.size(); i++)
189 MuonValues.push_back(tb.MuonValues[i]);
190
[250]191 for(unsigned int i=0; i<tb.IMuonValues.size(); i++)
192 IMuonValues.push_back(tb.IMuonValues[i]);
193
[243]194 for(unsigned int i=0; i<tb.JetValues.size(); i++)
195 JetValues.push_back(tb.JetValues[i]);
196
[250]197 for(unsigned int i=0; i<tb.BjetValues.size(); i++)
198 BjetValues.push_back(tb.BjetValues[i]);
199
[243]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
[72]215bool TriggerBit::GetResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
216 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
217 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig)
218{
[250]219 TSimpleArray<TRootJet> bjets=SubArrayBjets(branchJetTrig);
220 TSimpleArray<TRootElectron> Ielectron=SubArrayIElec(branchElecTrig);
221 TSimpleArray<TRootMuon> Imuon=SubArrayIMuon(branchMuonTrig);
[264]222
[72]223 int elec_size = ElecValues.size();
[250]224 int Ielec_size = IElecValues.size();
[72]225 int muon_size = MuonValues.size();
[250]226 int Imuon_size = IMuonValues.size();
[72]227 int jet_size = JetValues.size();
[250]228 int bjet_size = BjetValues.size();
[72]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 )
[250]236 && (Ielectron.GetEntries() >= Ielec_size )
[72]237 && (branchMuonTrig->GetEntries() >= muon_size )
[250]238 && (Imuon.GetEntries() >= Imuon_size )
[72]239 && (branchJetTrig->GetEntries() >= jet_size )
[250]240 && (bjets.GetEntries() >= bjet_size )
[72]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
[250]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
[72]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
[250]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
[72]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
[250]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
[72]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
[63]318void TriggerBit::GetTrigCondition(const string& trigger_algorithm) {
319
[52]320 vector<string> ElecSequences;
[250]321 vector<string> IElecSequences;
[52]322 vector<string> MuonSequences;
[250]323 vector<string> IMuonSequences;
[52]324 vector<string> JetSequences;
325 vector<string> TauJetSequences;
326 vector<string> EtmisSequences;
327 vector<string> GammaSequences;
[250]328 vector<string> BjetSequences;
[63]329
[250]330 char * result = new char[256];
[52]331 result = strtok( (char*) trigger_algorithm.c_str(),"&");
[63]332 while( result != NULL )
[52]333 {
334 if(strstr (result,"ELEC"))ElecSequences.push_back(result);
[250]335 if(strstr (result,"IElec"))IElecSequences.push_back(result);
[52]336 if(strstr (result,"MUON"))MuonSequences.push_back(result);
[250]337 if(strstr (result,"IMuon"))IMuonSequences.push_back(result);
[52]338 if(strstr (result,"JET"))JetSequences.push_back(result);
[250]339 if(strstr (result,"TAU"))TauJetSequences.push_back(result);
[52]340 if(strstr (result,"ETMIS"))EtmisSequences.push_back(result);
341 if(strstr (result,"GAMMA"))GammaSequences.push_back(result);
[250]342 if(strstr (result,"Bjet"))BjetSequences.push_back(result);
[52]343 result = strtok( NULL,"&");
[63]344 }
[264]345 delete [] result;
[52]346
[63]347 ElecValues = GetCuts(ElecSequences);
[250]348 IElecValues = GetCuts(IElecSequences);
[63]349 MuonValues = GetCuts(MuonSequences);
[250]350 IMuonValues = GetCuts(IMuonSequences);
[63]351 JetValues = GetCuts(JetSequences);
352 TauJetValues = GetCuts(TauJetSequences);
353 EtmisValues = GetCuts(EtmisSequences);
354 GammaValues = GetCuts(GammaSequences);
[250]355 BjetValues = GetCuts(BjetSequences);
[63]356
[52]357}
[219]358
[264]359
[219]360void TriggerBit::PrintTrigCondition(const string& LogName,const int i)
[63]361{
362 int elec_size = TriggerBit::ElecValues.size();
[250]363 int Ielec_size = TriggerBit::IElecValues.size();
[63]364 int muon_size = TriggerBit::MuonValues.size();
[250]365 int Imuon_size = TriggerBit::IMuonValues.size();
[63]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();
[250]370 int bjets_size = TriggerBit::BjetValues.size();
[264]371
[63]372 ofstream f_out(LogName.c_str(),ios::app);
[52]373
[63]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";
[250]379
[63]380 if(elec_size!=0){
[250]381 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << elec_size <<""<< left << setw(20)<<"Electron(s) with p_T: "<<"";
[63]382 for(int i=0;i<elec_size;i++){f_out << left << setw(5) << TriggerBit::ElecValues[i]<<"";}f_out <<"\n";}
[52]383
[250]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
[63]388 if(muon_size!=0){
[250]389 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << muon_size <<""<< left << setw(20)<<"Muon(s) with p_T: "<<"";
[63]390 for(int i=0;i<muon_size;i++){f_out << left << setw(5) << TriggerBit::MuonValues[i]<<"";}f_out <<"\n";}
[52]391
[250]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
[63]396 if(jet_size!=0){
[250]397 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << jet_size <<""<< left << setw(20)<<"Jet(s) with p_T: "<<"";
[63]398 for(int i=0;i<jet_size;i++){f_out << left << setw(5) << TriggerBit::JetValues[i]<<"";}f_out <<"\n";}
[52]399
[63]400 if(taujet_size!=0){
[250]401 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << taujet_size <<""<< left << setw(20)<<"Tau-jet(s) with p_T: "<<"";
[63]402 for(int i=0;i<taujet_size;i++){f_out << left << setw(5) << TriggerBit::TauJetValues[i]<<"";}f_out <<"\n";}
[250]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
[63]408 if(gamma_size!=0){
[250]409 f_out << left << setw(5) <<"** -"<<""<< left << setw(2) << gamma_size <<""<< left << setw(20)<<"Photon(s) with p_T: "<<"";
[63]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){
[250]413 f_out << left << setw(5) <<"** -"<<""<< left << setw(20)<<"Transverse missing energy with p_T: "<<"";
[63]414 for(int i=0;i<etmis_size;i++){f_out << left << setw(5) << TriggerBit::EtmisValues[i]<<"";}f_out <<"\n";}
415 f_out <<"* *"<<"\n";
[260]416 f_out <<"**********************************************************************"<<"\n";
[63]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);
[52]429 }
[63]430 return OrderedValue;
[264]431
[250]432}
[63]433
[250]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;
[52]445}
446
[250]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}
[63]459
[250]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.