DESY Hbb Analysis Framework
AnalysisTriggerExample.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <vector>
4 
5 #include "TFile.h"
6 #include "TFileCollection.h"
7 #include "TChain.h"
8 #include "TH1.h"
9 
12 
13 using namespace std;
14 using namespace analysis;
15 using namespace analysis::tools;
16 
17 
18 // =============================================================================================
19 int main(int argc, char * argv[])
20 {
21  TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms
22 
23  if ( macro_config(argc, argv) != 0 ) return -1;
24 
25  // Input files list
27 
28  // Trigger
29  analysis.triggerResults(triggerCol_);
30 
31  // Trigger objects
32  for ( auto & obj : triggerObjectsJets_ )
33  analysis.addTree<TriggerObject>(obj,triggerObjDir_+"/"+obj);
34 
35  // Analysis of events
36  std::cout << "This analysis has " << analysis.size() << " events" << std::endl;
37  int nevts = analysis.size();
38  if ( nevts > 0 ) nevts = nevtmax_;
39  for ( int i = 0 ; i < nevts ; ++i )
40  {
41  analysis.event(i);
42 
43  std::cout << "++++++ ENTRY " << i << std::endl;
44 
45  // Trigger results: fired and prescales
46  // hltPath
47  int trg_fired = analysis.triggerResult(hltPath_);
48  // prescales
49  int l1ps = analysis.triggerPrescale(l1Seed_);
50  int hltps = analysis.triggerPrescale(hltPath_);
51  std::string s_accept = " fired ";
52 
53  // printing info
54  if ( ! trg_fired )
55  {
56  std::cout << "The path " << hltPath_ << " did not fire " << std::endl;
57  continue;
58  }
59 
60  std::cout << "The path " << hltPath_ << " fired and has HLT PS = " << hltps << std::endl;
61  std::cout << "and its L1 seed " << l1Seed_ << " has the following prescale: " << l1ps << endl;
62 
63  // dealing with trigger objects
64  // *** WARNING! *** the order you enter the trigger object in the config file matter!
65  auto l1jets = analysis.collection<TriggerObject>(triggerObjectsJets_[0]);
66  for ( int j = 0 ; j < l1jets->size() ; ++j )
67  {
68  TriggerObject l1jet = l1jets->at(j);
69  std::cout << "L1 Jet: pT = " << l1jet.pt() << ", " << l1jet.eta() << ", " << l1jet.phi() << std::endl;
70  }
71 
72  }
73 
74 
75 }
76 
std::shared_ptr< Collection< Object > > collection(const std::string &unique_name)
Definition: Analysis.h:336
float eta() const
returns the pseudorapidity
Definition: Candidate.cc:134
int macro_config(int argc, char *argv[])
Definition: macro_config.h:145
int triggerPrescale(const std::string &trig)
Definition: Analysis.cc:197
float phi() const
returns the azimuthal angle
Definition: Candidate.cc:135
std::string triggerObjDir_
Definition: macro_config.h:139
bool triggerResult(const std::string &trig)
Definition: Analysis.cc:190
std::vector< std::string > triggerObjectsJets_
Definition: macro_config.h:127
std::string l1Seed_
Definition: macro_config.h:116
std::string inputlist_
Definition: macro_config.h:21
float pt() const
returns the transverse momentum
Definition: Candidate.cc:133
bool triggerResults(const std::string &path)
Definition: Analysis.cc:162
std::string hltPath_
Definition: macro_config.h:115
void event(const int &event, const bool &addCollections=true)
Definition: Analysis.cc:94
std::shared_ptr< PhysicsObjectTree< Object > > addTree(const std::string &unique_name, const std::string &path)
Definition: Analysis.h:273
int nevtmax_
Definition: macro_config.h:15
int main(int argc, char *argv[])
std::string triggerCol_
Definition: macro_config.h:136