DAS  3.0
Das Analysis System
Correlator< FunctionalForm >

Description

template<typename FunctionalForm>
struct Step::Correlator< FunctionalForm >

A class to account for the correlations when fitting.

#include <Step.h>

+ Collaboration diagram for Correlator< FunctionalForm >:

Public Member Functions

 Correlator (TH1 *h, TH2 *hcov, int im, int iM, FunctionalForm &ff, std::ostream &Stream=std::cout)
 
double operator() (const double *p)
 
void SetReplica (UInt_t seed)
 
void UnsetReplica ()
 

Public Attributes

const int n
 
TVectorD c
 
TVectorD e
 
TVectorD v
 
TVectorD w
 
TVectorD s
 
TMatrixD cov
 
TMatrixD rot
 
TMatrixD invcov
 
FunctionalFormf
 
std::ostream & stream
 

Constructor & Destructor Documentation

◆ Correlator()

Correlator ( TH1 *  h,
TH2 *  hcov,
int  im,
int  iM,
FunctionalForm ff,
std::ostream &  Stream = std::cout 
)
inline

Constructor

Performs first sanity checks, then converts histograms to vector/matrix.

Parameters
hinput histogram (normalised to bin width if appropriate)
hcovcovariance histogram
imfirst bin where to start the fit
iMlast bin where to stop the fit
fffit function
Streamstream (e.g. `cout`)
304  :
305  n(iM-im+1), c(n), e(n+1), v(n), w(n), s(n), cov(n,n), rot(n,n), invcov(n,n), f(ff), stream(Stream)
306  {
307  using namespace std;
308 
309  // sanity checks
310 
311  if (verbose)
312  stream << "n = " << n << '\n';
313 
314  if (verbose)
315  stream << "Checking histogram\n";
316  for (int i = im; i <= iM; ++i) {
317  auto content = h->GetBinContent(i);
318  if (verbose)
319  stream << setw(3) << i
320  << setw(12) << h->GetBinCenter(i)
321  << setw(12) << content << '\n';
322  assert(isnormal(content));
323  }
324 
325  if (hcov != nullptr) {
326  if (verbose)
327  stream << "Checking covariance\n";
328  for (int i = im; i <= iM; ++i)
329  for (int j = im; j <= iM; ++j) {
330  auto content = hcov->GetBinContent(i,j);
331  if (verbose) {
332  stream << setw(12) << content;
333  if (j == iM) stream << '\n';
334  }
335  assert(isfinite(content));
336  }
337  }
338 
339  // conversion for matrix algebra
340 
341  int shift = im;
342  if (verbose)
343  stream << "Converting from histograms to vector and matrix (shift = " << shift << "):";
344  for (int i = 0; i < n; ++i) {
345  e(i) = h->GetBinLowEdge(i+shift);
346  c(i) = h->GetBinCenter (i+shift);
347  v(i) = h->GetBinContent(i+shift);
348  if (verbose)
349  stream << '\n' << setw(5) << i << setw(10) << c(i) << setw(15) << v(i) << setw(15);
350  assert(abs(v(i)) > 0);
351  for (int j = 0; j < n; ++j) {
352  cov(i,j) = hcov != nullptr ? hcov->GetBinContent(i+shift,j+shift)
353  : i == j ? pow(h->GetBinError(i+shift),2) : 0;
354  if (i == j && verbose) stream << (100*sqrt(cov(i,j))/v(i)) << '%';
355  }
356  }
357  e(n) = h->GetBinLowEdge(n+shift);
358  if (verbose)
359  stream << '\n';
360 
361  if (!cov.IsSymmetric()) {
362  if (verbose)
363  stream << "Forcing to be symmetric\n";
364 
365  auto cov2 = cov;
366  cov2.T();
367  cov += cov2;
368  cov *= 0.5;
369  assert(cov.IsSymmetric());
370  }
371 
372  // preparing variables for replicas
373  w = v;
374  rot = cov.EigenVectors(s); // `s` will be modified here, but will be overwritten later
375  if (verbose)
376  stream << "Getting eigenvalues, expect different columns only in case of non-zero bin-to-bin correlations:";
377  for (int k = 0; k < n; ++k) {
378  if (verbose)
379  stream << '\n' << setw(5) << k << setw(15) << s[k] << setw(15) << cov(k,k);
380  s(k) = sqrt(s(k)); // to be used as input of `TRandom3::Gaus()`
381  assert(s[k] > 0);
382  }
383  if (verbose)
384  stream << '\n';
385 
386  // inverting
387  if (verbose)
388  stream << "Inverting...\n";
389  TDecompSVD svd(cov);
390  svd.SetTol(eps);
391  bool status = false;
392  invcov = svd.Invert(status);
393  assert(status);
394 
395  if (verbose)
396  stream << "Ready to fit\n";
397  }

Member Function Documentation

◆ operator()()

double operator() ( const double *  p)
inline

operator overloading for the functor to be used with ROOT::Math::Minimizer

402  {
403  auto r = w;
404  for (int i = 0; i < n; ++i) {
405  auto y0 = f(&e(i), p),
406  y1 = f(&c(i), p),
407  y2 = f(&e(i+1), p);
408  r(i) -= (y0+4*y1+y2)/6;
409  }
410  return r * (invcov * r);
411  }

◆ SetReplica()

void SetReplica ( UInt_t  seed)
inline
414  {
415  TRandom3 r(seed);
416 
417  TVectorD d(n);
418  for (int k = 0; k < n; ++k)
419  d(k) = r.Gaus(0, s(k));
420 
421  w = v + rot*d;
422  }

◆ UnsetReplica()

void UnsetReplica ( )
inline
425  {
426  w = v;
427  }

Member Data Documentation

◆ c

TVectorD c

bin center

◆ cov

TMatrixD cov

covariance matrix

◆ e

TVectorD e

bin edge

◆ f

fit function

◆ invcov

TMatrixD invcov

inverse of covariance matrix

◆ n

const int n

#bins

◆ rot

TMatrixD rot

rotation matrix

◆ s

TVectorD s

sqrt(eigenvalues)

◆ stream

std::ostream& stream

stream (e.g. cout or file)

◆ v

TVectorD v

xsection value

◆ w

TVectorD w

replica


The documentation for this struct was generated from the following file:
Step::eps
static const auto eps
Definition: Step.h:38
Step::verbose
static bool verbose
Definition: Step.h:40
Ntupliser_cfg.p
p
Definition: Ntupliser_cfg.py:358
Step::Correlator::c
TVectorD c
bin center
Definition: Step.h:281
Step::Correlator::v
TVectorD v
xsection value
Definition: Step.h:283
Step::Correlator::f
FunctionalForm & f
fit function
Definition: Step.h:290
Step::Correlator::e
TVectorD e
bin edge
Definition: Step.h:282
Step::Correlator::rot
TMatrixD rot
rotation matrix
Definition: Step.h:287
Step::Correlator::n
const int n
#bins
Definition: Step.h:280
Step::Correlator::cov
TMatrixD cov
covariance matrix
Definition: Step.h:286
Step::Correlator::s
TVectorD s
sqrt(eigenvalues)
Definition: Step.h:285
Step::Correlator::invcov
TMatrixD invcov
inverse of covariance matrix
Definition: Step.h:288
Step::Correlator::stream
std::ostream & stream
stream (e.g. cout or file)
Definition: Step.h:291
Step::Correlator::w
TVectorD w
replica
Definition: Step.h:284