DESY Hbb Analysis Framework
TriggerAnalyser.cc
Go to the documentation of this file.
2 // system include files
3 #include "boost/program_options.hpp"
4 #include "boost/algorithm/string.hpp"
5 #include <string>
6 #include <iostream>
7 #include <fstream>
8 #include <vector>
9 //
10 // user include files
11 #include "TString.h"
12 
13 //
14 // class declaration
15 //
16 
17 using namespace analysis;
18 using namespace analysis::tools;
19 
21 {
22 }
23 
24 
25 TriggerAnalyser::TriggerAnalyser(int argc, char * argv[]) : BaseAnalyser(argc,argv)
26 {
27 
28  triggeranalysis_ = false;
29 
30  if ( config_->triggerResults() != "" )
31  triggeranalysis_ = analysis_->triggerResults(config_->triggerResults());
32 
33  if ( config_->triggerObjectsDir() != "" )
34  {
35  // online jets
36  if ( config_->triggerObjectsL1Jets() != "l1tJets")
37  analysis_->addTree<TriggerObject> (config_->triggerObjectsL1Jets() ,Form("%s/%s", config_->triggerObjectsDir().c_str(),config_->triggerObjectsL1Jets().c_str()));
38  analysis_->addTree<TriggerObject> (config_->triggerObjectsCaloJets(),Form("%s/%s", config_->triggerObjectsDir().c_str(),config_->triggerObjectsCaloJets().c_str()));
39  analysis_->addTree<TriggerObject> (config_->triggerObjectsPFJets() ,Form("%s/%s", config_->triggerObjectsDir().c_str(),config_->triggerObjectsPFJets().c_str()));
40  // online b jets
41  analysis_->addTree<TriggerObject> (config_->triggerObjectsBJets(),Form("%s/%s", config_->triggerObjectsDir().c_str(),config_->triggerObjectsBJets().c_str()));
42  // online muons
43  analysis_->addTree<TriggerObject> (config_->triggerObjectsL1Muons(),Form("%s/%s",config_->triggerObjectsDir().c_str(),config_->triggerObjectsL1Muons().c_str()));
44  analysis_->addTree<TriggerObject> (config_->triggerObjectsL3Muons(),Form("%s/%s",config_->triggerObjectsDir().c_str(),config_->triggerObjectsL3Muons().c_str()));
45  }
46  if ( config_ -> l1tJetsCollection() != "")
47  {
48  l1tjetsanalysis_ = ( analysis_ -> addTree<L1TJet> ("l1tJets",config_ -> l1tJetsCollection()) != nullptr );
49  }
50  if ( config_ -> l1tMuonsCollection() != "")
51  {
52  l1tmuonsanalysis_ = ( analysis_ -> addTree<L1TMuon> ("l1tMuons",config_ -> l1tMuonsCollection()) != nullptr );
53  }
54 
55 }
56 
58 {
59  // do anything here that needs to be done at desctruction time
60  // (e.g. close files, deallocate resources etc.)
61 }
62 
63 
64 //
65 // member functions
66 //
67 // ------------ method called for each event ------------
68 
69 
70 bool TriggerAnalyser::selectionTrigger() // Maybe not use this, use selectionHLT and selectionL1
71 {
72  bool hlt = selectionHLT();
73  bool l1 = selectionL1();
74 
76  // L1 muon trigger
77  bool l1muon = true;
78  if ( config_->triggerEmulateL1Muons() != "" && config_->triggerEmulateL1MuonsNMin() > 0 && config_->triggerObjectsL1Muons() != "" )
79  {
80  int nmin = config_->triggerEmulateL1MuonsNMin();
81  float ptmin = config_->triggerEmulateL1MuonsPtMin();
82  float etamax = config_->triggerEmulateL1MuonsEtaMax();
83  l1muon = selectionTriggerEmulated(l1,hlt,config_->triggerEmulateL1Muons(),nmin,ptmin,etamax);
84  }
85  // L3 muon trigger
86  bool l3muon = true;
87  if ( config_->triggerEmulateL3Muons() != "" && config_->triggerEmulateL3MuonsNMin() > 0 && config_->triggerObjectsL3Muons() != "" )
88  {
89  int nmin = config_->triggerEmulateL3MuonsNMin();
90  float ptmin = config_->triggerEmulateL3MuonsPtMin();
91  float etamax = config_->triggerEmulateL3MuonsEtaMax();
92  l3muon = selectionTriggerEmulated(l1,hlt,config_->triggerEmulateL3Muons(),nmin,ptmin,etamax);
93  }
94 
95  // L1 jet trigger
96  bool l1jet = true;
97  if ( config_->triggerEmulateL1Jets() != "" && config_->triggerEmulateL1JetsNMin() > 0 && config_->triggerObjectsL1Jets() != "" )
98  {
99  int nmin = config_->triggerEmulateL1JetsNMin();
100  float ptmin = config_->triggerEmulateL1JetsPtMin();
101  float etamax = config_->triggerEmulateL1JetsEtaMax();
102  l1jet = selectionTriggerEmulated(l1,hlt,config_->triggerEmulateL1Jets(),nmin,ptmin,etamax);
103  }
104 
105  // Calo jet trigger
106  bool calojet = true;
107  if ( config_->triggerEmulateCaloJets() != "" && config_->triggerEmulateCaloJetsNMin() > 0 && config_->triggerObjectsCaloJets() != "" )
108  {
109  int nmin = config_->triggerEmulateCaloJetsNMin();
110  float ptmin = config_->triggerEmulateCaloJetsPtMin();
111  float etamax = config_->triggerEmulateCaloJetsEtaMax();
112  calojet = selectionTriggerEmulated(l1,hlt,config_->triggerEmulateCaloJets(),nmin,ptmin,etamax);
113  }
114 
115 
116  // PF jet trigger
117  bool pfjet = true;
118  if ( config_->triggerEmulatePFJets() != "" && config_->triggerEmulatePFJetsNMin() > 0 && config_->triggerObjectsPFJets() != "" )
119  {
120  int nmin = config_->triggerEmulatePFJetsNMin();
121  float ptmin = config_->triggerEmulatePFJetsPtMin();
122  float etamax = config_->triggerEmulatePFJetsEtaMax();
123  pfjet = selectionTriggerEmulated(l1,hlt,config_->triggerEmulatePFJets(),nmin,ptmin,etamax);
124  }
125 
126 
127  bool emul = l1muon && l3muon && l1jet && calojet && pfjet;
128 
129  return (hlt && l1 && emul);
130 
131 }
132 
134 {
135  if ( config_->hltPath_ == "" ) return true;
136 
137  ++cutflow_;
138  if ( ! analysis_->triggerResult(config_->hltPath_) ) return false;
139 
140  if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" )
141  h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,(config_->hltPath_).c_str());
142 
143  h1_["cutflow"] -> Fill(cutflow_,weight_);
144 
145  return true;
146 }
147 
149 {
150  if ( config_->l1Seed_ == "" ) return true;
151 
152  ++cutflow_;
153  if ( ! analysis_->triggerResult(config_->l1Seed_) ) return false;
154 
155  if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" )
156  h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,(config_->l1Seed_).c_str());
157 
158  h1_["cutflow"] -> Fill(cutflow_,weight_);
159 
160  return true;
161 }
162 
163 bool TriggerAnalyser::selectionTriggerEmulated(const bool & l1, const bool & hlt, const std::string & name, const int & nmin, const float & ptmin, const float & etamax)
164 {
165 
166  ++cutflow_;
167 
168  if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" )
169  h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,Form("Emulated: %s (n >= %d, pT >= %4.1f GeV, |eta| <= %4.1f)",name.c_str(),nmin,ptmin,etamax));
170 
171 
172  if ( ! ( l1 && hlt ) ) return false;
173  if ( ! triggerEmulated(name) ) return false;
174 
175  h1_["cutflow"] -> Fill(cutflow_,weight_);
176 
177 
178  return true;
179 }
180 
181 
182 
183 
185 {
186  return triggeranalysis_;
187 }
188 
189 
190 std::vector< std::shared_ptr<TriggerObject> > TriggerAnalyser::triggerObjectsL1Jets()
191 {
192  auto collection = analysis_->collection<TriggerObject>(config_->triggerObjectsL1Jets());
193  std::vector< std::shared_ptr<TriggerObject> > objects;
194  for ( int j = 0 ; j < collection->size() ; ++j )
195  objects.push_back(std::make_shared<TriggerObject>(collection->at(j)));
196  return objects;
197 }
198 
199 std::vector< std::shared_ptr<TriggerObject> > TriggerAnalyser::triggerObjectsCaloJets()
200 {
201  auto collection = analysis_->collection<TriggerObject>(config_->triggerObjectsCaloJets());
202  std::vector< std::shared_ptr<TriggerObject> > objects;
203  for ( int j = 0 ; j < collection->size() ; ++j )
204  objects.push_back(std::make_shared<TriggerObject>(collection->at(j)));
205  return objects;
206 }
207 
208 std::vector< std::shared_ptr<TriggerObject> > TriggerAnalyser::triggerObjectsPFJets()
209 {
210  auto collection = analysis_->collection<TriggerObject>(config_->triggerObjectsPFJets());
211  std::vector< std::shared_ptr<TriggerObject> > objects;
212  for ( int j = 0 ; j < collection->size() ; ++j )
213  objects.push_back(std::make_shared<TriggerObject>(collection->at(j)));
214  return objects;
215 }
216 
217 std::vector< std::shared_ptr<TriggerObject> > TriggerAnalyser::triggerObjectsL1Muons()
218 {
219  auto collection = analysis_->collection<TriggerObject>(config_->triggerObjectsL1Muons());
220  std::vector< std::shared_ptr<TriggerObject> > objects;
221  for ( int j = 0 ; j < collection->size() ; ++j )
222  objects.push_back(std::make_shared<TriggerObject>(collection->at(j)));
223  return objects;
224 }
225 
226 std::vector< std::shared_ptr<TriggerObject> > TriggerAnalyser::triggerObjectsL3Muons()
227 {
228  auto collection = analysis_->collection<TriggerObject>(config_->triggerObjectsL3Muons());
229  std::vector< std::shared_ptr<TriggerObject> > objects;
230  for ( int j = 0 ; j < collection->size() ; ++j )
231  objects.push_back(std::make_shared<TriggerObject>(collection->at(j)));
232  return objects;
233 }
234 
236 {
237  return l1tjetsanalysis_;
238 }
239 
241 {
242  return l1tmuonsanalysis_;
243 }
std::shared_ptr< Config > config_
Config objects.
Definition: BaseAnalyser.h:63
std::vector< std::shared_ptr< TriggerObject > > triggerObjectsL3Muons()
std::vector< std::shared_ptr< TriggerObject > > triggerObjectsCaloJets()
std::shared_ptr< Analysis > analysis_
Analysis objects.
Definition: BaseAnalyser.h:61
float weight_
event weight
Definition: BaseAnalyser.h:72
std::vector< std::shared_ptr< TriggerObject > > triggerObjectsPFJets()
bool triggerEmulated(const std::string &)
return status of an emulated l1 trigger
std::map< std::string, std::shared_ptr< TH1F > > h1_
1D histograms mapping
Definition: BaseAnalyser.h:80
int cutflow_
Cutflow index.
Definition: BaseAnalyser.h:66
std::vector< std::shared_ptr< TriggerObject > > triggerObjectsL1Jets()
std::vector< std::shared_ptr< TriggerObject > > triggerObjectsL1Muons()
virtual bool selectionTriggerEmulated(const bool &, const bool &, const std::string &, const int &, const float &, const float &)