DESY Hbb Analysis Framework
Analyser.cc
Go to the documentation of this file.
1 // system include files
2 #include "boost/program_options.hpp"
3 #include "boost/algorithm/string.hpp"
4 #include <string>
5 #include <iostream>
6 #include <fstream>
7 #include <vector>
8 //
9 // user include files
11 
12 //
13 // class declaration
14 //
15 
16 using namespace analysis;
17 using namespace analysis::tools;
18 
20 {
21 }
22 
23 
24 Analyser::Analyser(int argc, char * argv[]) : BaseAnalyser(argc,argv), // not sure the BaseAnalyser should be called here
25  TriggerAnalyser(argc,argv),
26  JetAnalyser(argc,argv),
27  MuonAnalyser(argc,argv)
28 {
29  this -> pileupHistogram();
30 }
31 
33 {
34 }
35 
36 
37 //
38 // member functions
39 //
40 // ------------ method called for each event ------------
41 
42 bool Analyser::event(const int & i)
43 {
44  bool ok = true;
45  analysis_->event(i);
46  cutflow_ = -1;
47  weight_ = 1.; // reset weight at the beginning of the event analysis
48 
49  cutflow("Total events read");
50 
51  // Generator weight
52  if ( isMC_ )
53  {
54  this -> generatorWeight();
55  std::string genweight_type = "sign of weights";
56  if ( config_->fullGenWeight() ) genweight_type = "full weights";
57 
58  cutflow(Form("Generated weighted events (%s)",genweight_type.c_str()));
59  }
60 
61  if ( config_->runmin_ > 0 && analysis_->run() < config_->runmin_ ) return false;
62  if ( config_->runmax_ > 0 && analysis_->run() > config_->runmax_ ) return false;
63 
64  if (! config_->isMC() )
65  {
66  auto json = basename(config_->json());
67  ok = analysis_->selectJson();
68  cutflow(Form("Certified data: %s",json.c_str()),ok);
69  if ( ! ok ) return false;
70 
71  }
72 
73  if ( this->genParticlesAnalysis() )
74  cutflow(Form("Using GenParticles collection: %s",(config_->genParticlesCollection()).c_str()));
75 
76  if ( this->genJetsAnalysis() )
77  cutflow(Form("Using GenJets collection: %s",(config_->genJetsCollection()).c_str()));
78 
79  if ( this -> l1tJetsAnalysis() )
80  cutflow(Form("Using L1TJet collection: %s", (config_->l1tJetsCollection()).c_str()));
81 
82  if ( this -> l1tMuonsAnalysis() )
83  cutflow(Form("Using L1TMuon collection: %s", (config_->l1tMuonsCollection()).c_str()));
84 
87 
88  // PILEUP RE-WEIGHT
89  this->actionApplyPileupWeight();
90 
91  return ok;
92 
93 }
94 
95 bool Analyser::muonJet(const int & r)
96 {
97 
98  if ( ! muonsanalysis_ ) return true; // will skip this selection
99 
100  int j = r-1;
101  auto jet = selectedJets_[j];
102  jet -> addMuon(selectedMuons_);
103  bool isMuonJet = (jet -> muon() != nullptr);
104  cutflow(Form("Jet %d: Jet-muon association",r),isMuonJet);
105 
106  return isMuonJet;
107 
108 }
109 
111 {
112 // IDENTIFICATIONS
113  if ( ! this->selectionMuonId() ) return false;
114  if ( ! this->selectionJetId() ) return false;
115  if ( ! this->selectionJetPileupId() ) return false;
116  return true;
117 
118 }
int cutflow()
get cutflow index
void actionApplyPileupWeight(const int &var=0)
apply pileup weight given a systematic variation
void pileupHistogram()
creates pileup histogram
virtual bool analysisWithJets()
Definition: JetAnalyser.cc:72
bool genParticlesAnalysis() const
returns whether analysis of gen particles can be done
bool isMC_
flag for MC sample
Definition: BaseAnalyser.h:102
~Analyser()
desctructor
Definition: Analyser.cc:32
bool genJetsAnalysis() const
returns whether analysis of gen jets can be done
Analyser()
default constructor
Definition: Analyser.cc:19
std::string basename(const std::string &)
returns the basename of a path
std::shared_ptr< Config > config_
Config objects.
Definition: BaseAnalyser.h:63
void generatorWeight()
generator weight
std::shared_ptr< Analysis > analysis_
Analysis objects.
Definition: BaseAnalyser.h:61
float weight_
event weight
Definition: BaseAnalyser.h:72
std::vector< std::shared_ptr< Muon > > selectedMuons_
Definition: MuonAnalyser.h:47
std::vector< std::shared_ptr< Jet > > selectedJets_
Definition: JetAnalyser.h:47
virtual bool muonJet(const int &)
Assign muon to jet.
Definition: Analyser.cc:95
int cutflow_
Cutflow index.
Definition: BaseAnalyser.h:66
virtual bool event(const int &)
Read event and perform basic selections and actions.
Definition: Analyser.cc:42
virtual bool analysisWithMuons()
Definition: MuonAnalyser.cc:44
virtual bool preselection()
multiple actions: perform muon Id, jet Id and jet pileup Id selections
Definition: Analyser.cc:110
virtual bool selectionJetPileupId()
Definition: JetAnalyser.cc:646