DESY Hbb Analysis Framework
Public Member Functions | Protected Attributes | List of all members
analysis::tools::PileupWeight Class Reference

#include <PileupWeight.h>

Public Member Functions

std::shared_ptr< TH1D > histogram (const int &var=0)
 
 PileupWeight ()
 constructors More...
 
 PileupWeight (const std::string &)
 
float weight (const float &truepu, const int &var=0)
 
 ~PileupWeight ()
 desctructor More...
 

Protected Attributes

std::map< int, std::shared_ptr< TH1D > > histos_
 

Detailed Description

Definition at line 41 of file PileupWeight.h.

Constructor & Destructor Documentation

PileupWeight::PileupWeight ( )

constructors

Definition at line 15 of file PileupWeight.cc.

16 {
17 }
PileupWeight::PileupWeight ( const std::string &  fname)

Definition at line 20 of file PileupWeight.cc.

References f, and histos_.

21 {
22  TH1D * tmp;
23  std::shared_ptr<TFile> f = std::make_shared<TFile>(fname.c_str(),"old");
24  tmp = (TH1D*) f->Get("weight_2down");
25  if ( tmp ) histos_[-2] = std::make_shared<TH1D>(*tmp);
26 
27  tmp = (TH1D*) f->Get("weight_1down");
28  if ( tmp ) histos_[-1] = std::make_shared<TH1D>(*tmp);
29 
30  tmp = (TH1D*) f->Get("weight");
31  if ( tmp ) histos_[0] = std::make_shared<TH1D>(*tmp);
32 
33  tmp = (TH1D*) f->Get("weight_1up");
34  if ( tmp ) histos_[1] = std::make_shared<TH1D>(*tmp);
35 
36  tmp = (TH1D*) f->Get("weight_2up");
37  if ( tmp ) histos_[2] = std::make_shared<TH1D>(*tmp);
38 
39  if ( ! histos_[-2] )
40  std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight_2down not found. Weight = 1" << std::endl;
41  if ( ! histos_[-1] )
42  std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight_1down not found. Weight = 1" << std::endl;
43  if ( ! histos_[0] )
44  std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight not found. Weight = 1" << std::endl;
45  if ( ! histos_[1] )
46  std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight_1up not found. Weight = 1" << std::endl;
47  if ( ! histos_[2] )
48  std::cout << "WARNING - PileupWeight::PileupWeight | Histogram weight_2up not found. Weight = 1" << std::endl;
49 }
TFile * f[10]
Definition: PlotsCompare.cc:24
std::map< int, std::shared_ptr< TH1D > > histos_
Definition: PileupWeight.h:51
PileupWeight::~PileupWeight ( )

desctructor

Definition at line 51 of file PileupWeight.cc.

52 {
53  // do anything here that needs to be done at desctruction time
54  // (e.g. close files, deallocate resources etc.)
55 }

Member Function Documentation

std::shared_ptr<TH1D> analysis::tools::PileupWeight::histogram ( const int &  var = 0)
float PileupWeight::weight ( const float &  truepu,
const int &  var = 0 
)

Definition at line 64 of file PileupWeight.cc.

References histos_.

65 {
66  float weight = 1.;
67  if ( ! histos_[0] ) return weight;
68  if ( ! histos_[var] ) return weight;
69  int bin = histos_[var] -> FindBin(truepu);
70  weight = histos_[var] -> GetBinContent(bin);
71  return weight;
72 }
float weight(const float &truepu, const int &var=0)
Definition: PileupWeight.cc:64
std::map< int, std::shared_ptr< TH1D > > histos_
Definition: PileupWeight.h:51

Member Data Documentation

std::map<int,std::shared_ptr<TH1D> > analysis::tools::PileupWeight::histos_
protected

Definition at line 51 of file PileupWeight.h.

Referenced by PileupWeight(), and weight().


The documentation for this class was generated from the following files: