DESY Hbb Analysis Framework
Functions
SimpleAnalysis.cc File Reference
#include <string>
#include <iostream>
#include <vector>
#include "TFile.h"
#include "TFileCollection.h"
#include "TChain.h"
#include "TH1.h"
#include "Analysis/Tools/interface/Analysis.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 18 of file SimpleAnalysis.cc.

References analysis::tools::Analysis::addTree(), analysis::tools::Jet::btag(), analysis::tools::Analysis::collection(), analysis::tools::Candidate::deltaR(), analysis::tools::Candidate::eta(), analysis::tools::Analysis::event(), analysis::tools::Analysis::fileName(), naf_mult_submit::int, ReHLT_L1Trepack_HLTUser_DataNtuple::isMC, naf_mult_submit::json, analysis::tools::Candidate::phi(), analysis::tools::Analysis::processJsonFile(), analysis::tools::Candidate::pt(), analysis::tools::Analysis::run(), analysis::tools::Analysis::selectJson(), and analysis::tools::Analysis::size().

19 {
20  bool isMC = true;
21  bool isbbb = true;
22  std::string inputList = "rootFileList.txt";
23  std::string outputRoot = "histograms.root";
24  std::string json = "json_2016g.txt";
25  int bWP = 1;
26  float btagcut[3] = {0.46,0.84,0.92};
27  // Cuts // <<<<===== CMSDAS
28  float ptmin[3] = { 100.0, 100.0, 40.0 };
29  float etamax[3] = { 2.2, 2.2 , 2.2 };
30  float btagmin[3] = { btagcut[bWP], btagcut[bWP], btagcut[bWP]};
31 // float nonbtag = 0.46;
32  float dRmin = 1.;
33  float detamax = 1.55;
34 
35 
36  TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms
37 
38  // Input files list
39  Analysis analysis(inputList);
40 
41  analysis.addTree<Jet> ("Jets","MssmHbb/Events/slimmedJetsPuppiReapplyJEC");
42 
43  std::vector<std::string> triggerObjects;
44  triggerObjects.push_back("hltL1sDoubleJetC100");
45  triggerObjects.push_back("hltDoubleJetsC100");
46  triggerObjects.push_back("hltBTagCaloCSVp014DoubleWithMatching");
47  triggerObjects.push_back("hltDoublePFJetsC100");
48  triggerObjects.push_back("hltDoublePFJetsC100MaxDeta1p6");
49 
50 // for ( auto & obj : triggerObjects )
51 // analysis.addTree<TriggerObject> (obj,Form("MssmHbb/Events/selectedPatTrigger/%s",obj.c_str()));
52 
53 // analysis.triggerResults("MssmHbb/Events/TriggerResults");
54 // std::string hltPath = "HLT_DoubleJetsC100_DoubleBTagCSV_p014_DoublePFJetsC100MaxDeta1p6_v";
55 
56 
57  if( !isMC ) analysis.processJsonFile(json);
58 
59  TFile hout(outputRoot.c_str(),"recreate");
60 
61  std::map<std::string, TH1F*> h1;
62  h1["n"] = new TH1F("n" , "" , 30, 0, 30);
63  h1["n_csv"] = new TH1F("n_csv" , "" , 30, 0, 30);
64  h1["n_ptmin20"]= new TH1F("n_ptmin20" , "" , 30, 0, 30);
65  h1["n_ptmin20_csv"] = new TH1F("n_ptmin20_csv" , "" , 30, 0, 30);
66  for ( int i = 0 ; i < 3 ; ++i )
67  {
68  h1[Form("pt_%i",i)] = new TH1F(Form("pt_%i",i) , "" , 100, 0, 1000);
69  h1[Form("eta_%i",i)] = new TH1F(Form("eta_%i",i) , "" , 100, -5, 5);
70  h1[Form("phi_%i",i)] = new TH1F(Form("phi_%i",i) , "" , 100, -4, 4);
71  h1[Form("btag_%i",i)] = new TH1F(Form("btag_%i",i) , "" , 100, 0, 1);
72 
73  h1[Form("pt_%i_csv",i)] = new TH1F(Form("pt_%i_csv",i) , "" , 100, 0, 1000);
74  h1[Form("eta_%i_csv",i)] = new TH1F(Form("eta_%i_csv",i) , "" , 100, -5, 5);
75  h1[Form("phi_%i_csv",i)] = new TH1F(Form("phi_%i_csv",i) , "" , 100, -4, 4);
76  h1[Form("btag_%i_csv",i)] = new TH1F(Form("btag_%i_csv",i) , "" , 100, 0, 1);
77  }
78  h1["m12"] = new TH1F("m12" , "" , 50, 0, 1000);
79  h1["m12_csv"] = new TH1F("m12_csv" , "" , 50, 0, 1000);
80 
81 
82  // Analysis of events
83  std::cout << "This analysis has " << analysis.size() << " events" << std::endl;
84 
85  // Cut flow
86  // 0: triggered events
87  // 1: 3+ idloose jets
88  // 2: kinematics
89  // 3: matched to online
90  // 4: delta R
91  // 5: delta eta
92  // 6: btag (bbnb)
93  int nsel[10] = { };
94 
95  std::string prevFile = "";
96  for ( int i = 0 ; i < analysis.size() ; ++i )
97  {
98  int njets = 0;
99 // int njets_csv = 0;
100  bool goodEvent = true;
101 
102  if ( i > 0 && i%100000==0 ) std::cout << i << " events processed! " << std::endl;
103 
104  analysis.event(i);
105  if (! isMC )
106  {
107  if ( analysis.run() == 279975)
108  {
109  if ( prevFile == "" || prevFile != analysis.fileName() )
110  {
111  prevFile = analysis.fileName();
112  std::cout << prevFile << std::endl;
113  }
114  }
115  if (!analysis.selectJson() ) continue; // To use only goodJSonFiles
116  }
117 
118 // int triggerFired = analysis.triggerResult(hltPath);
119 // if ( !triggerFired ) continue;
120 
121  ++nsel[0];
122 
123  // match offline to online
124 // analysis.match<Jet,TriggerObject>("Jets",triggerObjects,0.5);
125 
126  // Jets - std::shared_ptr< Collection<Jet> >
127  auto slimmedJets = analysis.collection<Jet>("Jets");
128  std::vector<Jet *> selectedJets;
129  for ( int j = 0 ; j < slimmedJets->size() ; ++j )
130  {
131  if ( slimmedJets->at(j).idLoose() ) selectedJets.push_back(&slimmedJets->at(j));
132  }
133  if ( selectedJets.size() < 2 ) continue;
134 
135  ++nsel[1];
136 
137  // Kinematic selection - 2 leading jets
138  for ( int j = 0; j < 2; ++j )
139  {
140  Jet * jet = selectedJets[j];
141  if ( jet->pt() < ptmin[j] || fabs(jet->eta()) > etamax[j] )
142  {
143  goodEvent = false;
144  break;
145  }
146  }
147 
148  if ( ! goodEvent ) continue;
149 
150  ++nsel[2];
151 
152  for ( int j1 = 0; j1 < 1; ++j1 )
153  {
154  const Jet & jet1 = *selectedJets[j1];
155  for ( int j2 = j1+1; j2 < 2; ++j2 )
156  {
157  const Jet & jet2 = *selectedJets[j2];
158  if ( jet1.deltaR(jet2) < dRmin ) goodEvent = false;
159  }
160  }
161 
162  if ( ! goodEvent ) continue;
163 
164  ++nsel[3];
165 
166  if ( fabs(selectedJets[0]->eta() - selectedJets[1]->eta()) > detamax ) continue;
167 
168  ++nsel[4];
169 
170 
171  // Fill histograms of kinematic passed events
172  for ( int j = 0 ; j < (int)selectedJets.size() ; ++j )
173  {
174  if ( selectedJets[j]->pt() < 20. ) continue;
175  ++njets;
176  }
177 
178  h1["n"] -> Fill(selectedJets.size());
179  h1["n_ptmin20"] -> Fill(njets);
180  for ( int j = 0; j < 2; ++j )
181  {
182  Jet * jet = selectedJets[j];
183  h1[Form("pt_%i",j)] -> Fill(jet->pt());
184  h1[Form("eta_%i",j)] -> Fill(jet->eta());
185  h1[Form("phi_%i",j)] -> Fill(jet->phi());
186  h1[Form("btag_%i",j)] -> Fill(jet->btag("btag_csvivf"));
187 
188  if ( j < 2 && jet->btag("btag_csvivf") < btagmin[j] ) goodEvent = false;
189 // if ( ! isbbb )
190 // {
191 // if ( j == 2 && jet->btag("btag_csvivf") > nonbtag ) goodEvent = false;
192 // }
193 // else
194 // {
195 // if ( j == 2 && jet->btag("btag_csvivf") < btagmin[j] ) goodEvent = false;
196 // }
197  }
198 
199  h1["m12"] -> Fill((selectedJets[0]->p4() + selectedJets[1]->p4()).M());
200 
201  if ( ! goodEvent ) continue;
202 
203  ++nsel[5];
204 
205 // std::cout << "oioi" << std::endl;
206 
207 
208  // Is matched?
209 // bool matched[10] = {true,true,true,true,true,true,true,true,true,true};
210 // for ( int j = 0; j < 2; ++j )
211 // {
212 // Jet * jet = selectedJets[j];
213 // // for ( auto & obj : triggerObjects ) matched = (matched && jet->matched(obj));
214 // for ( size_t io = 0; io < triggerObjects.size() ; ++io )
215 // {
216 // if ( ! jet->matched(triggerObjects[io]) ) matched[io] = false;
217 // }
218 // }
219 //
220 // for ( size_t io = 0; io < triggerObjects.size() ; ++io )
221 // {
222 // if ( matched[io] ) ++nmatch[io];
223 // goodEvent = ( goodEvent && matched[io] );
224 // }
225 //
226 // if ( ! goodEvent ) continue;
227 
228  ++nsel[6];
229 
230  // Fill histograms of passed bbnb btagging selection
231 // for ( int j = 0 ; j < (int)selectedJets.size() ; ++j )
232 // {
233 // if ( selectedJets[j]->pt() < 20. ) continue;
234 // ++njets_csv;
235 // }
236 // h1["n_csv"] -> Fill(selectedJets.size());
237 // h1["n_ptmin20_csv"] -> Fill(njets_csv);
238 // for ( int j = 0; j < 3; ++j )
239 // {
240 // Jet * jet = selectedJets[j];
241 // h1[Form("pt_%i_csv",j)] -> Fill(jet->pt());
242 // h1[Form("eta_%i_csv",j)] -> Fill(jet->eta());
243 // h1[Form("phi_%i_csv",j)] -> Fill(jet->phi());
244 // h1[Form("btag_%i_csv",j)] -> Fill(jet->btag("btag_csvivf"));
245 // }
246 // if ( !isbbb ) h1["m12_csv"] -> Fill((selectedJets[0]->p4() + selectedJets[1]->p4()).M());
247 
248  }
249 
250  for (auto & ih1 : h1)
251  {
252  ih1.second -> Write();
253  }
254 
255 // PRINT OUTS
256 
257  // Cut flow
258  // 0: triggered events
259  // 1: 3+ idloose jets
260  // 2: matched to online
261  // 3: kinematics
262  // 4: delta R
263  // 5: delta eta
264  // 6: btag (bbnb)
265 
266  double fracAbs[10];
267  double fracRel[10];
268  std::string cuts[10];
269  cuts[0] = "Triggered";
270  cuts[1] = "Triple idloose-jet";
271  cuts[2] = "Triple jet kinematics";
272  cuts[3] = "Delta R(i;j)";
273  cuts[4] = "Delta eta(j1;j2)";
274  cuts[5] = "btagged (bbnb)";
275  if ( isbbb ) cuts[5] = "btagged (bbb)";
276  cuts[6] = "Matched to online j1;j2";
277 
278  printf ("%-23s %10s %10s %10s \n", std::string("Cut flow").c_str(), std::string("# events").c_str(), std::string("absolute").c_str(), std::string("relative").c_str() );
279  for ( int i = 0; i < 7; ++i )
280  {
281  fracAbs[i] = double(nsel[i])/nsel[0];
282  if ( i>0 )
283  fracRel[i] = double(nsel[i])/nsel[i-1];
284  else
285  fracRel[i] = fracAbs[i];
286  printf ("%-23s %10d %10.3f %10.3f \n", cuts[i].c_str(), nsel[i], fracAbs[i], fracRel[i] );
287  }
288  // CSV output
289  printf ("%-23s , %10s , %10s , %10s \n", std::string("Cut flow").c_str(), std::string("# events").c_str(), std::string("absolute").c_str(), std::string("relative").c_str() );
290  for ( int i = 0; i < 7; ++i )
291  printf ("%-23s , %10d , %10.3f , %10.3f \n", cuts[i].c_str(), nsel[i], fracAbs[i], fracRel[i] );
292 
293  // Trigger objects counts
294  std::cout << std::endl;
295  printf ("%-40s %10s \n", std::string("Trigger object").c_str(), std::string("# events").c_str() );
296 // for ( size_t io = 0; io < triggerObjects.size() ; ++io )
297 // {
298 // printf ("%-40s %10d \n", triggerObjects[io].c_str(), nmatch[io] );
299 // }
300 
301 
302 
303 
304 
305 //
306 }
float eta() const
returns the pseudorapidity
Definition: Candidate.cc:134
float phi() const
returns the azimuthal angle
Definition: Candidate.cc:135
float pt() const
returns the transverse momentum
Definition: Candidate.cc:133
float deltaR(const Candidate &) const
returns the deltaR between this and another candidate
Definition: Candidate.cc:140
float btag(const std::string &) const
returns the btag value of btag_csvivf
Definition: Jet.cc:57