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