DAS  3.0
Das Analysis System
DistVariation

Description

Generic structure to hold the histograms and indices corresponding to one variation, for any observable using TUnfoldBinning.

This class is intended to be used in getUnfHist only.

#include <DistVariation.h>

+ Inheritance diagram for DistVariation:
+ Collaboration diagram for DistVariation:

Public Member Functions

 ~DistVariation ()
 
 DistVariation (const TString &group, const TString &name, size_t index=0, int bit=0)
 
 DistVariation (const DistVariation &v)
 
 DistVariation (DistVariation &&v)
 
void Write (TDirectory *d)
 
- Public Member Functions inherited from Variation
 ~Variation ()=default
 
 Variation (const TString &group, const TString &name, size_t index=0, int bit=0)
 
 Variation (const Variation &v)
 
 Variation (Variation &&v)
 

Public Attributes

std::unique_ptr< TH1 > rec
 
std::unique_ptr< TH1 > tmp
 
std::unique_ptr< TH1 > gen
 
std::unique_ptr< TH1 > missNoMatch
 
std::unique_ptr< TH1 > missOut
 
std::unique_ptr< TH1 > fakeNoMatch
 
std::unique_ptr< TH1 > fakeOut
 
std::unique_ptr< TH2 > cov
 
std::unique_ptr< TH2 > RM
 
- Public Attributes inherited from Variation
const TString group
 
const TString name
 
const std::size_t index
 
const int bit
 

Static Public Attributes

static bool isMC = false
 
static TUnfoldBinning * genBinning = nullptr
 
static TUnfoldBinning * recBinning = nullptr
 

Constructor & Destructor Documentation

◆ ~DistVariation()

Destructor.

108 {
109  auto apply_to_all = [](auto&& f, auto&& ... x) { (f(x),...); };
110 
111  // 1D histograms
112  auto check_bin_contents_1D = [](auto&& h) {
113  if (!h) return;
114  if (h->GetEntries() == 0) // TODO: fix move constructor (otherwise this is prompted when copying, which is misleading)
115  cerr << orange << h->GetName() << " is empty" << def << '\n';
116  if (h->GetBinContent(0) > 0)
117  cerr << orange << h->GetName() << "'s underflow is not empty\n" << def;
118  if (h->GetBinContent(h->GetNbinsX()+1) > 0)
119  cerr << orange << h->GetName() << "'s overflow is not empty\n" << def;
120  };
121  apply_to_all(check_bin_contents_1D,
123 
124  // 2D histograms
125  auto check_bin_contents_2D = [](auto&& h) {
126  if (!h) return;
127 
128  int nBinsX = h->GetNbinsX();
129  int nBinsY = h->GetNbinsY();
130 
131  bool underflowFilled = false,
132  overflowFilled = false;
133  for (int i = 1; i <= nBinsX; ++i) {
134  underflowFilled |= h->GetBinContent(i,0) > 0;
135  overflowFilled |= h->GetBinContent(i,nBinsY+1) > 0;
136  }
137  if (underflowFilled)
138  cerr << orange << h->GetName() << "'s underflow on horizontal axis is not empty\n" << def;
139  if (overflowFilled)
140  cerr << orange << h->GetName() << "'s overflow on horizontal axis is not empty\n" << def;
141 
142  underflowFilled = false;
143  overflowFilled = false;
144  for (int i = 1; i <= nBinsX; ++i) {
145  underflowFilled |= h->GetBinContent(0,i) > 0;
146  overflowFilled |= h->GetBinContent(nBinsX+1,0) > 0;
147  }
148  if (underflowFilled)
149  cerr << orange << h->GetName() << "'s underflow on vertical axis is not empty\n" << def;
150  if (overflowFilled)
151  cerr << orange << h->GetName() << "'s overflow on vertical axis is not empty\n" << def;
152  };
153  apply_to_all(check_bin_contents_2D, RM, cov);
154 
155  if (!RM) return;
156 
157  bool genClosure = true, recClosure = true;
158  auto checkbin = [](const unique_ptr<TH1>& h, int i) {
159  auto content = h->GetBinContent(i);
160  bool ok = std::abs(content - 1) < feps || std::abs(content) < feps;
161  if (!ok) cerr << orange << "| " << i << " " << content << "\n" << def;
162  return ok;
163  };
164 
165  auto RMx = unique_ptr<TH1>(RM->ProjectionX());
166  RMx->Add(missNoMatch.get());
167  RMx->Add(missOut.get());
168  RMx->Divide(gen.get());
169  for (int i = 1; i <= RMx->GetNbinsX(); ++i)
170  genClosure &= checkbin(RMx, i);
171 
172  auto RMy = unique_ptr<TH1>(RM->ProjectionY());
173  RMy->Add(fakeNoMatch.get());
174  RMy->Add(fakeOut.get());
175  RMy->Divide(rec.get());
176  for (int i = 1; i <= RMy->GetNbinsX(); ++i)
177  recClosure &= checkbin(RMy, i);
178 
179  if (!recClosure)
180  cerr << red << name << " is not closing at rec level" << '\n' << def;
181  if (!genClosure)
182  cerr << red << name << " is not closing at gen level" << '\n' << def;
183 }

◆ DistVariation() [1/3]

DistVariation ( const TString &  group,
const TString &  name,
size_t  index = 0,
int  bit = 0 
)

Normal constructor.

21  :
23 {
24  cout << "|- Setting up " << __func__ << " `" << name << "`." << endl;
25 
26  if (!genBinning)
27  BOOST_THROW_EXCEPTION( runtime_error("Particle-level binning has not been defined") );
28  if (!recBinning)
29  BOOST_THROW_EXCEPTION( runtime_error("Detector-level binning has not been defined") );
30 
31  // TH1 * TUnfoldBinning::CreateHistogram
32  // (const char * histogramName,
33  // Bool_t originalAxisBinning = kFALSE, // no physical axis
34  // Int_t ** binMap = nullptr, // mapping from global bins to hist bins (unused here)
35  // const char * histogramTitle = nullptr,
36  // const char * axisSteering = nullptr // needed for underflow and overflow (not done here)
37  // )
38  auto makeRec = [this,name](TString subname, TString title) {
39  auto h = unique_ptr<TH1>(recBinning->CreateHistogram(name + subname,
40  false, nullptr, title + " (detector level)"));
41  h->GetXaxis()->SetTitle("rec");
42  return h;
43  };
44  rec = makeRec("rec", "all");
45  tmp = makeRec("tmp", "temporary object to calculate covariance");
46 
47  // TH2D * TUnfoldBinning::CreateErrorMatrixHistogram
48  // (const char * histogramName,
49  // Bool_t originalAxisBinning,
50  // Int_t ** binMap = nullptr,
51  // const char * histogramTitle = nullptr,
52  // const char * axisSteering = nullptr
53  // )
54  cov = unique_ptr<TH2>(recBinning->CreateErrorMatrixHistogram(name + "cov",
55  false, nullptr, "covariance matrix (detector level)"));
56  cov->GetXaxis()->SetTitle("rec");
57  cov->GetYaxis()->SetTitle("rec");
58 
59  if (!isMC) return;
60  auto makeGen = [this,name](TString subname, TString title) {
61  auto h = unique_ptr<TH1>(genBinning->CreateHistogram(name + subname,
62  false, nullptr, title + " (particle level)"));
63  h->GetXaxis()->SetTitle("gen");
64  return h;
65  };
66  gen = makeGen("gen" , "all");
67  missNoMatch = makeGen("missNoMatch", "truly unmatched");
68  missOut = makeGen("missOut" , "matched out of the phase space");
69  fakeNoMatch = makeRec("fakeNoMatch", "truly unmatched");
70  fakeOut = makeRec("fakeOut" , "matched out of the phase space");
71 
72  // TH2D * TUnfoldBinning::CreateHistogramOfMigrations (TUnfoldBinning const * xAxis,
73  // TUnfoldBinning const * yAxis,
74  // char const * histogramName,
75  // Bool_t originalXAxisBinning = kFALSE,
76  // Bool_t originalYAxisBinning = kFALSE,
77  // char const * histogramTitle = nullptr
78  // )
79  RM = unique_ptr<TH2>(TUnfoldBinning::CreateHistogramOfMigrations(genBinning, recBinning,
80  name + "RM", false, false, "response matrix"));
81  RM->GetXaxis()->SetTitle("gen");
82  RM->GetYaxis()->SetTitle("rec");
83 }

◆ DistVariation() [2/3]

DistVariation ( const DistVariation v)
inline

copy constructor

54  :
56  rec (std::unique_ptr<TH1>(dynamic_cast<TH1*>(v.rec ->Clone()))),
57  tmp (std::unique_ptr<TH1>(dynamic_cast<TH1*>(v.tmp ->Clone()))),
58  gen (std::unique_ptr<TH1>(dynamic_cast<TH1*>(v.gen ->Clone()))),
59  missNoMatch(std::unique_ptr<TH1>(dynamic_cast<TH1*>(v.missNoMatch->Clone()))),
60  missOut (std::unique_ptr<TH1>(dynamic_cast<TH1*>(v.missOut ->Clone()))),
61  fakeNoMatch(std::unique_ptr<TH1>(dynamic_cast<TH1*>(v.fakeNoMatch->Clone()))),
62  fakeOut (std::unique_ptr<TH1>(dynamic_cast<TH1*>(v.fakeOut ->Clone()))),
63  cov (std::unique_ptr<TH2>(dynamic_cast<TH2*>(v.cov ->Clone()))),
64  RM (std::unique_ptr<TH2>(dynamic_cast<TH2*>(v.RM ->Clone())))
65  { }

◆ DistVariation() [3/3]

DistVariation ( DistVariation &&  v)
inline

move constructor

69  :
71  rec(std::move(v.rec)), tmp(std::move(v.tmp)), gen(std::move(v.gen)),
72  missNoMatch(std::move(v.missNoMatch)), missOut(std::move(v.missOut)),
73  fakeNoMatch(std::move(v.fakeNoMatch)), fakeOut(std::move(v.fakeOut)),
74  cov(std::move(v.cov)), RM(std::move(v.RM))
75  { }

Member Function Documentation

◆ Write()

void Write ( TDirectory *  d)

Create a subdirectory to the directory given in argument where all histograms are written.

86 {
87  cout << "Writing " << name << endl;
88  d->cd();
89  TDirectory * dd = d->mkdir(name);
90  dd->cd();
91  auto write = [this,dd](auto&& h) {
92  if (!h) return;
93  TString n = h->GetName();
94  n.ReplaceAll(name,"");
95  h->SetDirectory(dd);
96  h->Write(n);
97  };
98  auto apply_to_all = [](auto&& f, auto&& ... x) { (f(x),...); };
99  apply_to_all(write,
101 }

Member Data Documentation

◆ cov

std::unique_ptr<TH2> cov

covariance matrix

◆ fakeNoMatch

std::unique_ptr<TH1> fakeNoMatch

background (unmatched entries)

◆ fakeOut

std::unique_ptr<TH1> fakeOut

background (migration out of phase space)

◆ gen

std::unique_ptr<TH1> gen

generated-level distribution

◆ genBinning

TUnfoldBinning * genBinning = nullptr
static

full binning at particle level

◆ isMC

bool isMC = false
static

flag from metainfo

◆ missNoMatch

std::unique_ptr<TH1> missNoMatch

losses (unmatched entries)

◆ missOut

std::unique_ptr<TH1> missOut

losses (migration out of phase space)

◆ rec

std::unique_ptr<TH1> rec

reconstructed-level distribution

◆ recBinning

TUnfoldBinning * recBinning = nullptr
static

full binning at detector level

◆ RM

std::unique_ptr<TH2> RM

response matrix

◆ tmp

std::unique_ptr<TH1> tmp

temporary histogram help fill the covariance matrix


The documentation for this struct was generated from the following files:
DAS::Unfolding::DistVariation::isMC
static bool isMC
flag from metainfo
Definition: DistVariation.h:27
Ntupliser_cfg.cerr
cerr
Definition: Ntupliser_cfg.py:93
DAS::Unfolding::DistVariation::rec
std::unique_ptr< TH1 > rec
reconstructed-level distribution
Definition: DistVariation.h:32
Step::def
static const char * def
Definition: Step.h:36
DAS::Uncertainties::Variation::name
const TString name
variation name (including "Up" or "Down")
Definition: Variation.h:25
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:256
DAS::Unfolding::DistVariation::recBinning
static TUnfoldBinning * recBinning
full binning at detector level
Definition: DistVariation.h:30
Step::red
static const char * red
Definition: Step.h:34
feps
static const auto feps
Definition: DistVariation.cc:17
DAS::Uncertainties::Variation::bit
const int bit
correlation bit
Definition: Variation.h:28
orange
static const char * orange
Definition: colours.h:6
DAS::Unfolding::DistVariation::cov
std::unique_ptr< TH2 > cov
covariance matrix
Definition: DistVariation.h:41
DAS::Unfolding::DistVariation::gen
std::unique_ptr< TH1 > gen
generated-level distribution
Definition: DistVariation.h:34
DAS::Unfolding::DistVariation::tmp
std::unique_ptr< TH1 > tmp
temporary histogram help fill the covariance matrix
Definition: DistVariation.h:33
DAS::Unfolding::DistVariation::missNoMatch
std::unique_ptr< TH1 > missNoMatch
losses (unmatched entries)
Definition: DistVariation.h:35
DAS::Uncertainties::Variation::group
const TString group
e.g. event, recjet
Definition: Variation.h:24
DAS::Unfolding::DistVariation::RM
std::unique_ptr< TH2 > RM
response matrix
Definition: DistVariation.h:42
DAS::Unfolding::DistVariation::missOut
std::unique_ptr< TH1 > missOut
losses (migration out of phase space)
Definition: DistVariation.h:36
DAS::Unfolding::DistVariation::fakeNoMatch
std::unique_ptr< TH1 > fakeNoMatch
background (unmatched entries)
Definition: DistVariation.h:37
DAS::Unfolding::DistVariation::genBinning
static TUnfoldBinning * genBinning
full binning at particle level
Definition: DistVariation.h:29
DAS::Uncertainties::Variation
Definition: Variation.h:22
DAS::Uncertainties::Variation::index
const std::size_t index
index in the vector where the variation factor is stored
Definition: Variation.h:27
DAS::Unfolding::DistVariation::fakeOut
std::unique_ptr< TH1 > fakeOut
background (migration out of phase space)
Definition: DistVariation.h:38