DESY Hbb Analysis Framework
AnalysisMuonsExample.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 
11 
12 using namespace std;
13 using namespace analysis;
14 using namespace analysis::tools;
15 
16 
17 // =============================================================================================
18 int main(int argc, char * argv[])
19 {
20 // bool isMC = false;
21  TH1::SetDefaultSumw2(); // proper treatment of errors when scaling histograms
22 
23  // Input files list
24  std::string inputList = "rootFileList.txt";
25  Analysis analysis(inputList);
26 
27  // Physics Objects Collections
28  analysis.addTree<Muon> ("Muons","MssmHbb/Events/slimmedMuons");
29 
30  TFile hout("histograms_muons.root","recreate");
31 
32  std::map<std::string, TH1F*> h1;
33  h1["n"] = new TH1F("n" , "" , 30, 0, 30);
34  h1["pt"] = new TH1F("pt" , "" , 100, 0, 770);
35  h1["eta"] = new TH1F("eta" , "" , 100, -5.30, 3.30);
36  h1["phi"] = new TH1F("phi" , "" , 100, -3.7, 3.7);
37  h1["q"] = new TH1F("q", "", 4, -2, 2);
38  h1["isPF"] = new TH1F("isPF","",2,0,2);
39  h1["isGlobal"] = new TH1F("isGlobal","",2,0,2);
40  h1["isTracker"] = new TH1F("isTracker","",2,0,2);
41  h1["isLoose"] = new TH1F("isLoose","",2,0,2);
42  h1["isMedium"] = new TH1F("isMedium","",2,0,2);
43 
44 
45  // Analysis of events
46  std::cout << "This analysis has " << analysis.size() << " events" << std::endl;
47  int nevents = analysis.size();
48 
49 // int nFired = 0;
50  for ( int i = 0 ; i < nevents ; ++i )
51  {
52  if ( i > 0 && i%100000 == 0 ) std::cout << i << " events processed..." << std::endl;
53 
54  analysis.event(i);
55 
56  // Muons
57  auto muons = analysis.collection<Muon>("Muons");
58  int nmuons = 0;
59  for ( int m = 0 ; m < muons->size() ; ++m )
60  {
61  Muon muon = muons->at(m);
62  h1["pt"] -> Fill(muon.pt());
63  h1["eta"] -> Fill(muon.eta());
64  h1["phi"] -> Fill(muon.phi());
65  h1["q"] -> Fill(muon.q());
66  h1["isPF"] -> Fill(muon.isPFMuon() );
67  h1["isGlobal"] -> Fill(muon.isGlobalMuon() );
68  h1["isTracker"] -> Fill(muon.isTrackerMuon());
69  h1["isLoose"] -> Fill(muon.isLooseMuon() );
70  h1["isMedium"] -> Fill(muon.isMediumMuon() );
71  ++nmuons;
72 
73  }
74  h1["n"] -> Fill(nmuons);
75 
76  }
77 
78  for (auto & ih1 : h1)
79  {
80  ih1.second -> Write();
81  }
82 
83 //
84 }
85 
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
float phi() const
returns the azimuthal angle
Definition: Candidate.cc:135
int main(int argc, char *argv[])
bool isPFMuon() const
Definition: Muon.cc:42
float pt() const
returns the transverse momentum
Definition: Candidate.cc:133
bool isGlobalMuon() const
Definition: Muon.cc:43
bool isLooseMuon() const
Definition: Muon.cc:45
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 q() const
returns the charge
Definition: Candidate.cc:139
bool isMediumMuon() const
Definition: Muon.cc:46
bool isTrackerMuon() const
Definition: Muon.cc:44