DAS  3.0
Das Analysis System
DAS::Unfolding::Checks Namespace Reference

Functions

void NegativeBins (const unique_ptr< TH1 > &unf)
 
unique_ptr< TH2 > GetPM (const unique_ptr< TH2 > &RM)
 
void folding (const unique_ptr< TH1 > &genIn, const unique_ptr< TH1 > &recIn, const unique_ptr< TH2 > &PMin, const map< TString, unique_ptr< TH1 >> &miss, const map< TString, unique_ptr< TH1 >> &fake)
 
void BLT (const unique_ptr< TH1 > &dataDist, const unique_ptr< TH2 > &dataCov, const unique_ptr< TH1 > &MC, int rebin=1)
 
void CovMargin (unique_ptr< TH1 > &h, unique_ptr< TH2 > &cov, TString name, int ibin)
 

Function Documentation

◆ BLT()

void DAS::Unfolding::Checks::BLT ( const unique_ptr< TH1 > &  dataDist,
const unique_ptr< TH2 > &  dataCov,
const unique_ptr< TH1 > &  MC,
int  rebin = 1 
)

Bottom Line Test

Checks the agreement of data and MC before and after unfolding

Todo:
current implementation is insufficient for complex binning schemes
211 {
212  cout << __LINE__ << '\t' << __func__ << endl;
213  cerr << __LINE__ << '\t' << orange << "Warning: the BLT only gives reasonable "
214  "results for simples rebinning schemes "
215  "(e.g. 2 rec bins for 1 gen bins)\n" << def;
216  auto reb_dataDist = Clone<TH1>(dataDist, "reb_dataDist");
217  auto reb_dataCov = Clone<TH2>(dataCov, "reb_dataCov" );
218  auto reb_MC = Clone<TH1>(MC, "reb_MC" );
219 
220  reb_dataDist->Rebin(rebin);
221  reb_dataCov->Rebin2D(rebin, rebin);
222  reb_MC->Rebin(rebin);
223  vector<int> indices;
224  for (int i = 1; i <= dataCov->GetNbinsX(); ++i)
225  if (dataCov->GetBinContent(i,i) > 0) indices.push_back(i);
226  int ndf = indices.size();
227 
228  TVectorD v(ndf);
229  TMatrixD M(ndf,ndf);
230  M.SetTol(1e-100);
231  for (int i = 0; i < ndf; ++i) {
232  int index = indices.at(i);
233  double iData = dataDist->GetBinContent(index),
234  iMC = MC ->GetBinContent(index);
235  v(i) = iData-iMC;
236  for (int j = 0; j < ndf; ++j) {
237  int jndex = indices.at(j);
238  M(i,j) = dataCov->GetBinContent(index,jndex);
239  }
240  }
241  M.Invert();
242 
243  double chi2 = v*(M*v);
244 
245  cout << "chi2/ndf = " << chi2 << " / " << ndf << " = " << (chi2/ndf) << endl;
246 }

◆ CovMargin()

void DAS::Unfolding::Checks::CovMargin ( unique_ptr< TH1 > &  h,
unique_ptr< TH2 > &  cov,
TString  name,
int  ibin 
)

Set underflow/overflow to 0.

251 {
252  if ( h->GetBinContent(ibin) == 0
253  && h->GetBinError(ibin) == 0
254  && cov->GetBinContent(ibin,ibin) == 0) return;
255 
256  cerr << __LINE__ << orange << "\tWarning: " << name << " is not empty! "
257  "It will be set to zero, but no guarantee it works...\n" << def;
258 
259  h->SetBinContent(ibin,0);
260  h->SetBinError (ibin,0);
261  for (int i = 0; i <= h->GetNbinsX(); ++i) {
262  cov->SetBinContent(ibin,i,0);
263  cov->SetBinContent(i,ibin,0);
264  }
265 }

◆ folding()

void DAS::Unfolding::Checks::folding ( const unique_ptr< TH1 > &  genIn,
const unique_ptr< TH1 > &  recIn,
const unique_ptr< TH2 > &  PMin,
const map< TString, unique_ptr< TH1 >> &  miss,
const map< TString, unique_ptr< TH1 >> &  fake 
)

Folding test

Check that the MC closes: (gen - sum of misses) * PM = (rec - sum of fakes)

Parameters
genIninput gen-level spectrum
recIninput rec-level spectrum
PMininput probability matrix
missmiss counts
fakefake counts
166 {
167  cout << __LINE__ << '\t' << __func__ << endl;
168 
169  unique_ptr<TH1> gen = Clone<TH1>(genIn, "gen_folding");
170  unique_ptr<TH1> rec = Clone<TH1>(recIn, "rec_folding");
171  unique_ptr<TH2> PM = Clone<TH2>(PMin , "PM_folding");
172 
173  for (auto& m: miss) gen->Add(m.second.get(), -1);
174  for (auto& f: fake) rec->Add(f.second.get(), -1);
175 
176  const int Nx = PM->GetNbinsX(),
177  Ny = PM->GetNbinsY();
178 
179  // check folding
180  bool Fail = false;
181  for (int j = 1; j <= Ny; ++j) {
182  double error = rec->GetBinError(j);
183  if (::abs(error) < deps) continue;
184 
185  double content = rec->GetBinContent(j);
186  Fail |= isnan(content);
187 
188  for (int i = 1; i <= Nx; ++i)
189  content -= gen->GetBinContent(i) * PM->GetBinContent(i,j);
190 
191  if (::abs(content) < error / 100) continue;
192  Fail = true;
193  cerr << __LINE__ << orange << "\tWarning: Folding test is failing in bin "
194  << j << " with (gen - miss) x PM - (rec - fake) = " << content
195  << " > error / 100 = " << (error / 100) << def << '\n';
196  }
197 
198  if (Fail) /*BOOST_THROW_EXCEPTION( std::runtime_error(*/ cerr << red << "Failure: folding test has failed\n" << def /*) )*/;
199 }

◆ GetPM()

unique_ptr<TH2> DAS::Unfolding::Checks::GetPM ( const unique_ptr< TH2 > &  RM)

Calculate probability matrix.

137 {
138  unique_ptr<TH2> PM = Clone<TH2>(RM, "PM");
139 
140  const int Nx = RM->GetNbinsX(),
141  Ny = RM->GetNbinsY();
142 
143  // normalisation
144  for (int i = 1; i <= Nx; ++i) {
145  double normalisation = RM->Integral(i, i, 1, Ny);
146  if (normalisation > 0)
147  for (int j = 1; j <= Ny; ++j) {
148  double content = RM->GetBinContent(i,j);
149  content /= normalisation;
150  PM->SetBinContent(i,j, content);
151  }
152  }
153 
154  return PM;
155 }

◆ NegativeBins()

void DAS::Unfolding::Checks::NegativeBins ( const unique_ptr< TH1 > &  unf)

Check negative entries

Note: you should not necessarily worry if you get a value compatible with zero BUT you should not trust the result if the value is not at all compatible with zero

123 {
124  cout << __LINE__ << '\t' << __func__ << endl;
125  for (int i = 1; i <= unf->GetNbinsX(); ++i) {
126  double content = unf->GetBinContent(i);
127  if (content >= 0) continue;
128  double error = unf->GetBinError(i);
129  cerr << __LINE__ << orange << "\tWarning: bin " << i
130  << " has negative content: " << content << " +/- " << error << '\n' << def;
131  }
132 }
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.name
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
Ntupliser_cfg.cerr
cerr
Definition: Ntupliser_cfg.py:93
Step::def
static const char * def
Definition: Step.h:36
deps
static const auto deps
Definition: unfold.cc:28
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:256
Step::red
static const char * red
Definition: Step.h:34
orange
static const char * orange
Definition: colours.h:6