Fork me on GitHub

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

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

add isolation and b-tag

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