DESY Hbb Analysis Framework
MssmHbbAnalyser.cc
Go to the documentation of this file.
1 
8 //
9 // Original Author: Roberval Walsh
10 // Created: Mon, 20 Oct 2014 14:24:08 GMT
11 //
12 //
13 
14 // system include files
15 #include <iostream>
16 //
17 // user include files
20 
21 
22 //
23 // class declaration
24 //
25 
26 using namespace analysis;
27 using namespace analysis::tools;
28 using namespace analysis::mssmhbb;
29 
30 //
31 // constructors and destructor
32 //
33 MssmHbbAnalyser::MssmHbbAnalyser()
34 {
35 }
36 
37 MssmHbbAnalyser::MssmHbbAnalyser(int argc, char ** argv) : BaseAnalyser(argc,argv), Analyser(argc,argv)
38 {
39 // histograms("cutflow");
40 // histograms("jet",config_->nJetsMin());
41  do_tree_ = config_->doTree();
42  if ( do_tree_ ) this -> mssmHbbTree();
43  mbb_ = -1.;
44  this->jetHistograms(config_->nJetsMin(),"final_selection");
45  h1_["mssmhbb_mbb"] = std::make_shared<TH1F>("mbb","MSSM Hbb mbb", 30000,0,3000);
46 }
47 
49 {
50  // do anything here that needs to be done at desctruction time
51  // (e.g. close files, deallocate resources etc.)
52 
53  if ( do_tree_ ) mssmhbb_tree_ -> Write();
54 }
55 
56 
57 //
58 // member functions
59 //
60 // ------------ method called for each event ------------
61 bool MssmHbbAnalyser::event(const int & i)
62 {
63  // parent function checks only json and run range validity
64  if ( ! Analyser::event(i) ) return false;
65 
66 // PILEUP RE-WEIGHT
67 // this->actionApplyPileupWeight();
68 
69  return true;
70 }
72 {
73  if ( ! this->selectionNJets() ) return false;
74  for ( int i = 1; i <= config_->nJetsMin(); ++i )
75  {
76  // kinematics selection
77  if ( ! this->selectionJet(i) ) return false;
78  if ( i <= 2 && (! this->onlineJetMatching(i)) ) return false;
79  // delta R selection
80  for ( int j = i+1; j <= config_->nJetsMin(); ++j )
81  if ( ! this->selectionJetDr(i,j) ) return false;
82  }
83  // delta eta jet selection
84  if ( ! this->selectionJetDeta(1,2) ) return false;
85 
86  return true;
87 
88 }
90 {
91  for ( int i = 1; i <= config_->nBJetsMin(); ++i )
92  {
93  if ( ! this->selectionBJet(i) ) return false;
94  this->actionApplyBtagSF(i);
95  if ( i<= 2 && ! this->onlineBJetMatching(i) ) return false;
96  }
97 
98  return true;
99 
100 }
102 {
103  if ( ! this->selectionNMuons() ) return false;
104  if ( ! this->selectionMuons() ) return false;
105  if ( ! this->onlineMuonMatching() ) return false;
106  return true;
107 
108 }
110 {
111  this->fillJetHistograms("final_selection");
112  this->fillMssmHbbHistograms();
113  this->fillMssmHbbTree();
114  return true;
115 
116 }
117 
118 bool MssmHbbAnalyser::muonJet(const bool & swap)
119 {
120  // jet 1 is the muon jet, swap with jet 2 in case jet1 does not have a muon
121  // Muon jet association, a muon can be in either of the two leading jets.
122  // If argument is false(default, the jet label follows the jet ranking, regardless of where the muon is
123  // If argument is true, the jet label 1 refers to the muon-jet: *** the order of the workflow may matter!!! ***
124  if ( ! muonsanalysis_ || ! jetsanalysis_ ) return true; // will skip this selection
125 
126  int r1 = 1;
127  int r2 = 2;
128  int j1 = r1-1;
129  int j2 = r2-1;
130  ++ cutflow_;
131  if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" )
132  {
133  if ( swap ) h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"MSSMHbb Semileptonic: Jet-muon association -> Muon-Jet index 1");
134  else h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"MSSMHbb Semileptonic: Jet-muon association");
135  }
136 
137  if ( selectedJets_.size() < 2 || selectedMuons_.size() < 1 ) return false;
138 
139  auto jet1 = selectedJets_[j1];
140  jet1 -> addMuon(selectedMuons_);
141  auto jet2 = selectedJets_[j2];
142  jet2 -> addMuon(selectedMuons_);
143 
144  if ( ! (jet1 -> muon() || jet2 -> muon()) ) return false;
145  if ( ! jet1 -> muon() && swap ) this->jetSwap(r1,r2);
146 
147  h1_["cutflow"] -> Fill(cutflow_,weight_);
148  return true;
149 
150 }
151 
153 {
154  if ( ! do_tree_ ) return;
155  ++ cutflow_;
156  if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" )
157  h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"Fill MssmHbb tree");
158 
160  if ( config_->isMC() || !config_->signalRegion() ) mbb_ = c_12.m();
161 
162  mbbw_ = weight_;
163 
164  mssmhbb_tree_ -> Fill();
165  h1_["cutflow"] -> Fill(cutflow_,weight_);
166 
167 }
168 
170 {
171 // do_tree_ = true;
172  this->output()->cd();
173  mssmhbb_tree_ = std::make_shared<TTree>("mssmhbb","TTree with mbb and weight for FitModel");
174  mssmhbb_tree_ -> Branch("mbb",&mbb_,"mbb/D");
175  mssmhbb_tree_ -> Branch("weight",&mbbw_,"weight/D");
176 }
177 
179 {
180  ++ cutflow_;
181  if ( std::string(h1_["cutflow"] -> GetXaxis()-> GetBinLabel(cutflow_+1)) == "" )
182  h1_["cutflow"] -> GetXaxis()-> SetBinLabel(cutflow_+1,"Fill MssmHbb Histograms");
183 
185  float mbb = 0.;
186  if ( config_->isMC() || !config_->signalRegion() ) mbb = c_12.m();
187 
188  h1_["mssmhbb_mbb"] -> Fill(mbb,weight_);
189  h1_["cutflow"] -> Fill(cutflow_,weight_);
190 
191 }
192 
193 
virtual void jetSwap(const int &, const int &)
virtual bool muonJet(const bool &swap=false)
std::shared_ptr< TFile > output()
returns pointer to output root file
float m() const
returns the mass
Definition: Candidate.cc:137
virtual bool selectionJet(const int &r)
Given the ranking &#39;r&#39; of a jet, it returns whether the jet passes the pt_min and |eta_max|, optionally pt_max, where the values of the thresholds pt_min and |eta_max|, pt_max are passed by configuration file.
Definition: JetAnalyser.cc:378
virtual void fillJetHistograms(const std::string &label="x")
Fill the pre-defined histograms created by the jetHistograms() method.
Definition: JetAnalyser.cc:795
virtual bool onlineJetMatching(const int &)
Definition: JetAnalyser.cc:746
std::shared_ptr< Config > config_
Config objects.
Definition: BaseAnalyser.h:63
virtual bool onlineBJetMatching(const int &)
Definition: JetAnalyser.cc:778
float weight_
event weight
Definition: BaseAnalyser.h:72
virtual bool selectionBJet(const int &)
Definition: JetAnalyser.cc:708
std::vector< std::shared_ptr< Muon > > selectedMuons_
Definition: MuonAnalyser.h:47
virtual void jetHistograms(const int &n, const std::string &label="x")
Creates pre-defined histograms in directory &#39;label&#39; for analysis with &#39;n&#39; jets.
Definition: JetAnalyser.cc:172
virtual bool selectionJetDeta(const int &r1, const int &r2)
Given the rankings r1 and r2 of two jets, it returns whether the jets passes the delta_eta selection;...
Definition: JetAnalyser.cc:445
std::vector< std::shared_ptr< Jet > > selectedJets_
Definition: JetAnalyser.h:47
std::map< std::string, std::shared_ptr< TH1F > > h1_
1D histograms mapping
Definition: BaseAnalyser.h:80
int cutflow_
Cutflow index.
Definition: BaseAnalyser.h:66
virtual bool event(const int &i)
Read event and perform basic selections and actions.
std::shared_ptr< TTree > mssmhbb_tree_
virtual bool selectionJetDr(const int &r1, const int &r2)
Given the rankings r1 and r2 of two jets, it returns whether the jets passes the delta_R selection; t...
Definition: JetAnalyser.cc:541
virtual float actionApplyBtagSF(const int &, const bool &global_weight=true)