Fork me on GitHub

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

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

final trigger

File size: 9.0 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}
66
67bool TriggerTable::GetGlobalResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
68 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
69 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig, ExRootTreeBranch *branchTrigger) {
70
71 TRootTrigger *elementTrigger;
72 GlobalResult=false;
73 for(unsigned int i=0; i < list_of_trigger_bits.size(); i++) {
74 if(list_of_trigger_bits[i].GetResult(branchElecTrig, branchMuonTrig, branchJetTrig, branchTauJetTrig, branchPhotonTrig, branchETmisTrig))
75 {
76 GlobalResult=true;
77 int flag=i+1;
78 elementTrigger = (TRootTrigger*) branchTrigger->NewEntry();
79 elementTrigger->Accepted=flag;
80 }
81 }
82 if(GlobalResult)
83 {
84 elementTrigger = (TRootTrigger*) branchTrigger->NewEntry();
85 elementTrigger->Accepted=0;
86 }
87 return GlobalResult;
88
89}
90
91//*************************************************************************
92TriggerBit::TriggerBit() {
93}
94
95bool TriggerBit::GetResult(TClonesArray *branchElecTrig, TClonesArray *branchMuonTrig,
96 TClonesArray *branchJetTrig, TClonesArray *branchTauJetTrig,
97 TClonesArray *branchPhotonTrig, TClonesArray *branchETmisTrig)
98{
99 int elec_size = ElecValues.size();
100 int muon_size = MuonValues.size();
101 int jet_size = JetValues.size();
102 int taujet_size = TauJetValues.size();
103 int gamma_size = GammaValues.size();
104 int etmis_size = EtmisValues.size();
105
106 Result=false;
107 if(
108 (branchElecTrig->GetEntries() >= elec_size )
109 && (branchMuonTrig->GetEntries() >= muon_size )
110 && (branchJetTrig->GetEntries() >= jet_size )
111 && (branchTauJetTrig->GetEntries() >= taujet_size )
112 && (branchPhotonTrig->GetEntries() >= gamma_size )
113 )
114 {
115 Result=true;
116 if(elec_size!=0){
117 TRootElectron *electron;
118 for(int i=0;i<elec_size;i++){
119 electron = (TRootElectron*)branchElecTrig->At(i);
120 if(electron->PT < ElecValues[i])Result=false;}}
121
122 if(muon_size!=0){
123 TRootMuon *muon;
124 for(int i=0;i<muon_size;i++){
125 muon = (TRootMuon*)branchMuonTrig->At(i);
126 if(muon->PT < MuonValues[i])Result=false;}}
127
128 if(jet_size!=0){
129 TRootJet *jet;
130 for(int i=0;i<jet_size;i++){
131 jet = (TRootJet*)branchJetTrig->At(i);
132 if(jet->PT < JetValues[i])Result=false;}}
133
134 if(taujet_size!=0){
135 TRootTauJet *taujet;
136 for(int i=0;i<taujet_size;i++){
137 taujet = (TRootTauJet*)branchTauJetTrig->At(i);
138 if(taujet->PT < TauJetValues[i])Result=false;}}
139
140 if(gamma_size!=0){
141 TRootPhoton *gamma;
142 for(int i=0;i<gamma_size;i++){
143 gamma = (TRootPhoton*)branchPhotonTrig->At(i);
144 if(gamma->PT < GammaValues[i])Result=false;}}
145
146
147 if(etmis_size!=0){
148 TRootETmis *etmis = (TRootETmis*)branchETmisTrig->At(0);
149 if(etmis->ET < EtmisValues[0])Result=false;}
150
151 }
152 return Result;
153}
154
155void TriggerBit::GetTrigCondition(const string& trigger_algorithm) {
156
157 vector<string> ElecSequences;
158 vector<string> MuonSequences;
159 vector<string> JetSequences;
160 vector<string> TauJetSequences;
161 vector<string> EtmisSequences;
162 vector<string> GammaSequences;
163
164 char *result = NULL;
165 result = strtok( (char*) trigger_algorithm.c_str(),"&");
166 while( result != NULL )
167 {
168 if(strstr (result,"ELEC"))ElecSequences.push_back(result);
169 if(strstr (result,"MUON"))MuonSequences.push_back(result);
170 if(strstr (result,"JET"))JetSequences.push_back(result);
171 if(strstr (result,"TAUJET"))TauJetSequences.push_back(result);
172 if(strstr (result,"ETMIS"))EtmisSequences.push_back(result);
173 if(strstr (result,"GAMMA"))GammaSequences.push_back(result);
174 result = strtok( NULL,"&");
175 }
176
177 ElecValues = GetCuts(ElecSequences);
178 MuonValues = GetCuts(MuonSequences);
179 JetValues = GetCuts(JetSequences);
180 TauJetValues = GetCuts(TauJetSequences);
181 EtmisValues = GetCuts(EtmisSequences);
182 GammaValues = GetCuts(GammaSequences);
183
184}
185void TriggerBit::PrintTrigCondition(string LogName,int i)
186{
187 int elec_size = TriggerBit::ElecValues.size();
188 int muon_size = TriggerBit::MuonValues.size();
189 int jet_size = TriggerBit::JetValues.size();
190 int taujet_size = TriggerBit::TauJetValues.size();
191 int gamma_size = TriggerBit::GammaValues.size();
192 int etmis_size = TriggerBit::EtmisValues.size();
193
194 ofstream f_out(LogName.c_str(),ios::app);
195
196 f_out <<"* *"<<"\n";
197 f_out << left << setw(25) <<"# Trigger bit number "<<""
198 << left << setw(35) <<i <<""<< right << setw(10)<<"*"<<"\n";
199 f_out <<"#*************************"<<"\n";
200 f_out << left << setw(45) <<"* # Number of reconstructed objects required:"<<""<<right << setw(23)<<"*"<<"\n";
201 f_out << left << setw(1) <<"*"
202 << internal << setw(10) << "Electron"<< ""<< internal << setw(10) << "Muon" << ""
203 << internal << setw(10) << "Jets" << ""<< internal << setw(10) << "Tau-jets "<< ""
204 << internal << setw(10) << "Photons" << ""<< internal << setw(10) << "ETmis "<< ""<< right << setw(9) <<"*"<<"\n";
205 f_out << left << setw(1) <<"*"
206 << internal << setw(10) << elec_size << ""<< internal << setw(10) << muon_size << ""
207 << internal << setw(10) << jet_size << ""<< internal << setw(10) << taujet_size << ""
208 << internal << setw(10) << gamma_size<< ""<< internal << setw(10) << etmis_size << ""<< right << setw(9)<<"*"<<"\n";
209 f_out << left << setw(45) <<"* # Values of the related thresholds: "<<""<<right << setw(25)<<"*"<<"\n";
210 if(elec_size!=0){
211 f_out << left << setw(20) <<"* - Electrons: "<<"";
212 for(int i=0;i<elec_size;i++){f_out << left << setw(5) << TriggerBit::ElecValues[i]<<"";}f_out <<"\n";}
213
214 if(muon_size!=0){
215 f_out << left << setw(20) <<"* - Muons: "<<"";
216 for(int i=0;i<muon_size;i++){f_out << left << setw(5) << TriggerBit::MuonValues[i]<<"";}f_out <<"\n";}
217
218 if(jet_size!=0){
219 f_out << left << setw(20) <<"* - Jets: "<<"";
220 for(int i=0;i<jet_size;i++){f_out << left << setw(5) << TriggerBit::JetValues[i]<<"";}f_out <<"\n";}
221
222 if(taujet_size!=0){
223 f_out << left << setw(20) <<"* - Tau-jets: "<<"";
224 for(int i=0;i<taujet_size;i++){f_out << left << setw(5) << TriggerBit::TauJetValues[i]<<"";}f_out <<"\n";}
225
226 if(gamma_size!=0){
227 f_out << left << setw(20) <<"* - Photons: "<<"";
228 for(int i=0;i<gamma_size;i++){f_out << left << setw(5) << TriggerBit::GammaValues[i]<<"";}f_out <<"\n";}
229
230 if(etmis_size!=0){
231 f_out << left << setw(20) <<"* - ETMIS: "<<"";
232 for(int i=0;i<etmis_size;i++){f_out << left << setw(5) << TriggerBit::EtmisValues[i]<<"";}f_out <<"\n";}
233 f_out <<"* *"<<"\n";
234
235
236
237}
238
239vector<float> TriggerBit::GetCuts(const vector<string> &Sequences)
240{
241 vector<float> OrderedValue;
242 string ptVal;
243 Int_t PtVal=0;
244 for(unsigned int i=0; i < Sequences.size(); i++) {
245 ptVal = Sequences[i].substr( Sequences[i].find("'")+1) ;
246 PtVal = atoi( ptVal.c_str() );
247 OrderedValue.push_back(PtVal);
248 }
249 return OrderedValue;
250
251}
252
253
Note: See TracBrowser for help on using the repository browser.