UnfoldMaxEnt.cxx
Go to the documentation of this file.
2 
3 #include "TH1.h"
4 
5 #include <cmath>
6 #include <iostream>
7 
8 namespace ana
9 {
10  //----------------------------------------------------------------------
12  double reg)
13  : UnfoldTikhonov(rt, 0)
14  {
15  // Parent can't do it because virtual function call won't work yet
16  fReg = reg;
17  if(fReg < 0){
19  std::cout << "UnfoldMaxEnt: Automatic regularization strength = " << fReg << std::endl;
20  }
21  }
22 
23  //----------------------------------------------------------------------
25  {
26  }
27 
28  //----------------------------------------------------------------------
29  double UnfoldMaxEnt::PenaltyTerm(const std::vector<double>& pred) const
30  {
31  double tot = 0;
32  for(double x: pred) tot += x;
33 
34  // Maximum possible entropy, with all bins having equal content
35  const double maxent = log(pred.size());
36 
37  double ent = 0;
38  for(double x: pred){
39  if(x) ent -= x/tot*log(x/tot);
40  }
41 
42  // When maximum entropy is reached, penalty is zero. For maximal order (all
43  // entries in one bin), penalty is "maxent".
44  return maxent - ent;
45  }
46 
47 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
virtual ~UnfoldMaxEnt()
Spectrum with the value of a second variable, allowing for reweighting
virtual double PenaltyTerm(const std::vector< double > &pred) const override
Only difference from Tikhonov is the regularization term.
double fReg
Regularization strength.
OStream cout
Definition: OStream.cxx:6
double DeriveCrudeRegStrength() const
UnfoldMaxEnt(const ReweightableSpectrum &rt, double reg=-1)