Fork me on GitHub

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

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

sorted vector

File size: 9.2 KB
Line 
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
13#include "interface/TriggerUtil.h"
14#include "TRandom.h"
15
16#include <iostream>
17#include <sstream>
18#include <fstream>
19#include <iomanip>
20#include <cstring>
21
22using namespace std;
23
24TriggerTable::TriggerTable() {
25 has_been_evaluated=false;
26}
27
28void TriggerTable::TriggerCardReader(const string filename){
29 ifstream trigger_file(filename.c_str());
30 if( !trigger_file.good() ) {
31 cout << "ERROR: Trigger input file "<< filename << " not found. Exiting.\n";
32 return;
33 }
34
35 TriggerBit mybit;
36 string temp_string, temp_string_no_comment, trigger_name, trigger_algorithm;
37 while ( getline(trigger_file,temp_string) ) {
38 string temp_string_no_comment = temp_string.substr(0,temp_string.find("#")); //remove comments
39 if(temp_string_no_comment.size()<2) continue; // avoid empty lines
40 istringstream temp_stream(temp_string_no_comment);
41
42 temp_stream >> trigger_name;
43 trigger_algorithm = temp_string_no_comment.substr( temp_string_no_comment.find(">>")+2) ;
44
45 mybit.TriggerBit::GetTrigCondition(trigger_algorithm);
46 list_of_trigger_bits.push_back(mybit);
47 }
48}
49
50
51void TriggerTable::PrintTriggerTable(string LogName) {
52
53 ofstream f_out(LogName.c_str(),ios::app);
54 f_out<<"* *"<<"\n";
55 f_out<<"#*********************************************** *"<<"\n";
56 f_out<<"# Trigger conditions defined in the trigger card *"<<"\n";
57 f_out<<"#*********************************************** *"<<"\n";
58 f_out<<"* *"<<"\n";
59
60 f_out.close();
61
62 for(unsigned int i=0; i < list_of_trigger_bits.size(); i++) {
63 list_of_trigger_bits[i].PrintTrigCondition(LogName,i+1);
64 }
65 f_out<<"* *"<<"\n";
66 f_out<<"#*********************************************************************"<<"\n";
67
68}
69
70bool TriggerTable::GetGlobalResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
71 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
72 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig, ExRootTreeBranch *branchTrigger) {
73
74 TRootTrigger *elementTrigger;
75 GlobalResult=false;
76 for(unsigned int i=0; i < list_of_trigger_bits.size(); i++) {
77 if(list_of_trigger_bits[i].GetResult(branchElecTrig, branchMuonTrig, branchJetTrig, branchTauJetTrig, branchPhotonTrig, branchETmisTrig))
78 {
79 GlobalResult=true;
80 int flag=i+1;
81 elementTrigger = (TRootTrigger*) branchTrigger->NewEntry();
82 elementTrigger->Accepted=flag;
83 }
84 }
85 if(GlobalResult)
86 {
87 elementTrigger = (TRootTrigger*) branchTrigger->NewEntry();
88 elementTrigger->Accepted=0;
89 }
90 return GlobalResult;
91
92}
93
94//*************************************************************************
95TriggerBit::TriggerBit() {
96}
97
98bool TriggerBit::GetResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
99 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
100 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig)
101{
102 int elec_size = ElecValues.size();
103 int muon_size = MuonValues.size();
104 int jet_size = JetValues.size();
105 int taujet_size = TauJetValues.size();
106 int gamma_size = GammaValues.size();
107 int etmis_size = EtmisValues.size();
108
109 Result=false;
110 if(
111 (branchElecTrig->GetEntries() >= elec_size )
112 && (branchMuonTrig->GetEntries() >= muon_size )
113 && (branchJetTrig->GetEntries() >= jet_size )
114 && (branchTauJetTrig->GetEntries() >= taujet_size )
115 && (branchPhotonTrig->GetEntries() >= gamma_size )
116 )
117 {
118 Result=true;
119 if(elec_size!=0){
120 TRootElectron *electron;
121 for(int i=0;i<elec_size;i++){
122 electron = (TRootElectron*)branchElecTrig->At(i);
123 if(electron->PT < ElecValues[i])Result=false;}}
124
125 if(muon_size!=0){
126 TRootMuon *muon;
127 for(int i=0;i<muon_size;i++){
128 muon = (TRootMuon*)branchMuonTrig->At(i);
129 if(muon->PT < MuonValues[i])Result=false;}}
130
131 if(jet_size!=0){
132 TRootJet *jet;
133 for(int i=0;i<jet_size;i++){
134 jet = (TRootJet*)branchJetTrig->At(i);
135 if(jet->PT < JetValues[i])Result=false;}}
136
137 if(taujet_size!=0){
138 TRootTauJet *taujet;
139 for(int i=0;i<taujet_size;i++){
140 taujet = (TRootTauJet*)branchTauJetTrig->At(i);
141 if(taujet->PT < TauJetValues[i])Result=false;}}
142
143 if(gamma_size!=0){
144 TRootPhoton *gamma;
145 for(int i=0;i<gamma_size;i++){
146 gamma = (TRootPhoton*)branchPhotonTrig->At(i);
147 if(gamma->PT < GammaValues[i])Result=false;}}
148
149
150 if(etmis_size!=0){
151 TRootETmis *etmis = (TRootETmis*)branchETmisTrig->At(0);
152 if(etmis->ET < EtmisValues[0])Result=false;}
153
154 }
155 return Result;
156}
157
158void TriggerBit::GetTrigCondition(const string& trigger_algorithm) {
159
160 vector<string> ElecSequences;
161 vector<string> MuonSequences;
162 vector<string> JetSequences;
163 vector<string> TauJetSequences;
164 vector<string> EtmisSequences;
165 vector<string> GammaSequences;
166
167 char *result = NULL;
168 result = strtok( (char*) trigger_algorithm.c_str(),"&");
169 while( result != NULL )
170 {
171 if(strstr (result,"ELEC"))ElecSequences.push_back(result);
172 if(strstr (result,"MUON"))MuonSequences.push_back(result);
173 if(strstr (result,"JET"))JetSequences.push_back(result);
174 if(strstr (result,"TAUJET"))TauJetSequences.push_back(result);
175 if(strstr (result,"ETMIS"))EtmisSequences.push_back(result);
176 if(strstr (result,"GAMMA"))GammaSequences.push_back(result);
177 result = strtok( NULL,"&");
178 }
179
180 ElecValues = GetCuts(ElecSequences);
181 MuonValues = GetCuts(MuonSequences);
182 JetValues = GetCuts(JetSequences);
183 TauJetValues = GetCuts(TauJetSequences);
184 EtmisValues = GetCuts(EtmisSequences);
185 GammaValues = GetCuts(GammaSequences);
186
187}
188void TriggerBit::PrintTrigCondition(string LogName,int i)
189{
190 int elec_size = TriggerBit::ElecValues.size();
191 int muon_size = TriggerBit::MuonValues.size();
192 int jet_size = TriggerBit::JetValues.size();
193 int taujet_size = TriggerBit::TauJetValues.size();
194 int gamma_size = TriggerBit::GammaValues.size();
195 int etmis_size = TriggerBit::EtmisValues.size();
196
197 ofstream f_out(LogName.c_str(),ios::app);
198
199 f_out <<"* *"<<"\n";
200 f_out << left << setw(25) <<"# Trigger bit number "<<""
201 << left << setw(35) <<i <<""<< right << setw(10)<<"*"<<"\n";
202 f_out <<"#*************************"<<"\n";
203 f_out << left << setw(45) <<"* # Number of reconstructed objects required:"<<""<<right << setw(23)<<"*"<<"\n";
204 f_out << left << setw(1) <<"*"
205 << internal << setw(10) << "Electron"<< ""<< internal << setw(10) << "Muon" << ""
206 << internal << setw(10) << "Jets" << ""<< internal << setw(10) << "Tau-jets "<< ""
207 << internal << setw(10) << "Photons" << ""<< internal << setw(10) << "ETmis "<< ""<< right << setw(9) <<"*"<<"\n";
208 f_out << left << setw(1) <<"*"
209 << internal << setw(10) << elec_size << ""<< internal << setw(10) << muon_size << ""
210 << internal << setw(10) << jet_size << ""<< internal << setw(10) << taujet_size << ""
211 << internal << setw(10) << gamma_size<< ""<< internal << setw(10) << etmis_size << ""<< right << setw(9)<<"*"<<"\n";
212 f_out << left << setw(45) <<"* # Values of the related thresholds: "<<""<<right << setw(25)<<"*"<<"\n";
213 if(elec_size!=0){
214 f_out << left << setw(20) <<"* - Electrons: "<<"";
215 for(int i=0;i<elec_size;i++){f_out << left << setw(5) << TriggerBit::ElecValues[i]<<"";}f_out <<"\n";}
216
217 if(muon_size!=0){
218 f_out << left << setw(20) <<"* - Muons: "<<"";
219 for(int i=0;i<muon_size;i++){f_out << left << setw(5) << TriggerBit::MuonValues[i]<<"";}f_out <<"\n";}
220
221 if(jet_size!=0){
222 f_out << left << setw(20) <<"* - Jets: "<<"";
223 for(int i=0;i<jet_size;i++){f_out << left << setw(5) << TriggerBit::JetValues[i]<<"";}f_out <<"\n";}
224
225 if(taujet_size!=0){
226 f_out << left << setw(20) <<"* - Tau-jets: "<<"";
227 for(int i=0;i<taujet_size;i++){f_out << left << setw(5) << TriggerBit::TauJetValues[i]<<"";}f_out <<"\n";}
228
229 if(gamma_size!=0){
230 f_out << left << setw(20) <<"* - Photons: "<<"";
231 for(int i=0;i<gamma_size;i++){f_out << left << setw(5) << TriggerBit::GammaValues[i]<<"";}f_out <<"\n";}
232
233 if(etmis_size!=0){
234 f_out << left << setw(20) <<"* - ETMIS: "<<"";
235 for(int i=0;i<etmis_size;i++){f_out << left << setw(5) << TriggerBit::EtmisValues[i]<<"";}f_out <<"\n";}
236 f_out <<"* *"<<"\n";
237
238
239
240}
241
242vector<float> TriggerBit::GetCuts(const vector<string> &Sequences)
243{
244 vector<float> OrderedValue;
245 string ptVal;
246 Int_t PtVal=0;
247 for(unsigned int i=0; i < Sequences.size(); i++) {
248 ptVal = Sequences[i].substr( Sequences[i].find("'")+1) ;
249 PtVal = atoi( ptVal.c_str() );
250 OrderedValue.push_back(PtVal);
251 }
252 return OrderedValue;
253
254}
255
256
Note: See TracBrowser for help on using the repository browser.