DESY Hbb Analysis Framework
MuonIdWeight.cc
Go to the documentation of this file.
1 // system include files
2 // user include files
4 #include "TFile.h"
5 
6 //
7 // class declaration
8 //
9 
10 using namespace analysis;
11 using namespace analysis::tools;
12 
13 //
14 // constructors and destructor
16 {
17 }
18 
19 // Main constructor
20 MuonIdWeight::MuonIdWeight(const std::string & fname )
21 {
22  TH2D * tmp;
23  std::shared_ptr<TFile> f = std::make_shared<TFile>(fname.c_str(),"old");
24  tmp = (TH2D*) f->Get("weight_2down");
25  if ( tmp ) histos_[-2] = std::make_shared<TH2D>(*tmp);
26 
27  tmp = (TH2D*) f->Get("weight_1down");
28  if ( tmp ) histos_[-1] = std::make_shared<TH2D>(*tmp);
29 
30  tmp = (TH2D*) f->Get("weight");
31  if ( tmp ) histos_[0] = std::make_shared<TH2D>(*tmp);
32 
33  tmp = (TH2D*) f->Get("weight_1up");
34  if ( tmp ) histos_[1] = std::make_shared<TH2D>(*tmp);
35 
36  tmp = (TH2D*) f->Get("weight_2up");
37  if ( tmp ) histos_[2] = std::make_shared<TH2D>(*tmp);
38 
39  if ( ! histos_[-2] )
40  std::cout << "WARNING - MuonIdWeight::MuonIdWeight | Histogram weight_2down not found. Weight = 1" << std::endl;
41  if ( ! histos_[-1] )
42  std::cout << "WARNING - MuonIdWeight::MuonIdWeight | Histogram weight_1down not found. Weight = 1" << std::endl;
43  if ( ! histos_[0] )
44  std::cout << "WARNING - MuonIdWeight::MuonIdWeight | Histogram weight not found. Weight = 1" << std::endl;
45  if ( ! histos_[1] )
46  std::cout << "WARNING - MuonIdWeight::MuonIdWeight | Histogram weight_1up not found. Weight = 1" << std::endl;
47  if ( ! histos_[2] )
48  std::cout << "WARNING - MuonIdWeight::MuonIdWeight | Histogram weight_2up not found. Weight = 1" << std::endl;
49 }
50 
52 {
53  // do anything here that needs to be done at desctruction time
54  // (e.g. close files, deallocate resources etc.)
55 }
56 
57 
58 //
59 // member functions
60 //
61 // ------------ method called for each event ------------
62 
63 // output tree
64 float MuonIdWeight::weight(const float & pt, const float & eta , const int & var)
65 {
66  float weight = 1.;
67  if ( ! histos_[0] ) return weight;
68  if ( ! histos_[var] ) return weight;
69  int binx = histos_[var] -> GetXaxis()->FindBin(pt);
70  int biny = histos_[var] -> GetYaxis()->FindBin(eta);
71  weight = histos_[var] -> GetBinContent(binx, biny);
72  return weight;
73 }
74 
float weight(const float &pt, const float &eta, const int &var=0)
Definition: MuonIdWeight.cc:64
std::map< int, std::shared_ptr< TH2D > > histos_
Definition: MuonIdWeight.h:50
TFile * f[10]
Definition: PlotsCompare.cc:24