BCMTF.h
1 #ifndef __BCMTF__H
2 #define __BCMTF__H
3 
18 /*
19  * Copyright (C) 2007-2018, the BAT core developer team
20  * All rights reserved.
21  *
22  * For the licensing terms see doc/COPYING.
23  * For documentation see http://mpp.mpg.de/bat
24  */
25 
26 // ---------------------------------------------------------
27 
28 #include "../../BAT/BCModel.h"
29 
30 #include <TH1D.h>
31 
32 class BCMTFChannel;
33 class BCMTFProcess;
34 class BCMTFSystematic;
35 class TF1;
36 
37 // ---------------------------------------------------------
38 class BCMTF : public BCModel
39 {
40 
41 public:
42 
49  BCMTF(const std::string& name = "multi_template_fitter");
50 
53  ~BCMTF();
54 
61  int GetNChannels() const
62  { return fNChannels; };
63 
66  int GetNProcesses() const
67  { return fNProcesses; };
68 
71  int GetNSystematics() const
72  { return fNSystematics; };
73 
77  int GetChannelIndex(const std::string& name) const;
78 
82  int GetProcessIndex(const std::string& name) const;
83 
87  int GetSystematicIndex(const std::string& name) const;
88 
92  int GetParIndexProcess(int index) const
93  { return fProcessParIndexContainer.at(index); };
94 
98  int GetParIndexSystematic(int index) const
99  { return fSystematicParIndexContainer.at(index); };
100 
105  { return fChannelContainer.at(index); };
106 
107  double GetPValue() const
108  { return fPValue; }
109 
114  { return fProcessContainer.at(index); };
115 
120  { return fSystematicContainer.at(index); };
121 
133  void SetData(const std::string& channelname, TH1D hist, double minimum = -1, double maximum = -1);
134 
142  void SetTemplate(const std::string& channelname, const std::string& processname, TH1D hist, double efficiency = 1., double norm = 1.);
143 
158  void SetTemplate(const std::string& channelname, const std::string& processname, std::vector<TF1*>* funccont, int nbins, double efficiency = 1.);
159 
165  void SetExpectationFunction(int parindex, TF1* func)
166  { fExpectationFunctionContainer[parindex] = func; };
167 
181  void SetSystematicVariation(const std::string& channelname, const std::string& processname, const std::string& systematicname, double variation_up, double variation_down);
182 
195  void SetSystematicVariation(const std::string& channelname, const std::string& processname, const std::string& systematicname, TH1D hist_up, TH1D hist_down);
196 
211  void SetSystematicVariation(const std::string& channelname, const std::string& processname, const std::string& systematicname, TH1D hist, TH1D hist_up, TH1D hist_down);
212 
220  { fFlagEfficiencyConstraint = flag; };
221 
230  void AddChannel(const std::string& name);
231 
240  void AddProcess(const std::string& name, double nmin = 0., double nmax = 1., int color = -1, int fillstyle = -1, int linestyle = -1);
241 
247  void AddSystematic(const std::string& name, double min = -5., double max = 5.);
248 
255  double Expectation(int channelindex, int binindex, const std::vector<double>& parameters);
256 
265  double ExpectationFunction(int parindex, int channelindex, int processindex, const std::vector<double>& parameters);
266 
274  double Efficiency(int channelindex, int processindex, int binindex, const std::vector<double>& parameters);
275 
276  // avoid accidental hiding
277  using BCModel::Probability;
278 
288  double Probability(int channelindex, int processindex, int binindex, const std::vector<double>& parameters);
289 
296  double CalculateChi2(int channelindex, const std::vector<double>& parameters);
297 
303  double CalculateChi2(const std::vector<double>& parameters);
304 
311  double CalculateCash(int channelindex, const std::vector<double>& parameters);
312 
318  double CalculateCash(const std::vector<double>& parameters);
319 
327  double CalculatePValue(int channelindex, const std::vector<double>& parameters);
328 
338  double CalculatePValue(const std::vector<double>& parameters);
339 
347  void PrintFitSummary();
348 
365  void PrintStack(int channelindex, const std::vector<double>& parameters, const std::string& filename = "stack.pdf", const std::string& options = "e1b0stack");
366 
375  void PrintStack(const std::string& channelname, const std::vector<double>& parameters, const std::string& filename = "stack.pdf", const std::string& options = "e1b0stack")
376  {
377  return PrintStack(GetChannelIndex(channelname), parameters, filename, options);
378  }
379 
390  double LogLikelihood(const std::vector<double>& parameters);
391 
396 
399 private:
400 
403  std::vector<BCMTFChannel*> fChannelContainer;
404 
407  std::vector<BCMTFProcess*> fProcessContainer;
408 
411  std::vector<BCMTFSystematic*> fSystematicContainer;
412 
415  int fNChannels;
416 
419  int fNProcesses;
420 
423  int fNSystematics;
424 
428  std::vector<int> fProcessParIndexContainer;
429 
432  std::vector<int> fSystematicParIndexContainer;
433 
437  bool fFlagEfficiencyConstraint;
438 
441  std::vector<TF1*> fExpectationFunctionContainer;
442 
445  double fPValue;
446 
449  BCMTF(const BCMTF&);
450 
453  BCMTF& operator=(const BCMTF&);
454 
455 };
456 // ---------------------------------------------------------
457 
458 #endif
void SetTemplate(const std::string &channelname, const std::string &processname, TH1D hist, double efficiency=1., double norm=1.)
Set the template for a specific process in a particular channel.
Definition: BCMTF.cxx:92
double CalculatePValue(int channelindex, const std::vector< double > &parameters)
Calculates and returns the fast p-value for the total likelihood as test statistic.
Definition: BCMTF.cxx:1033
int GetNChannels() const
Definition: BCMTF.h:61
void PrintStack(const std::string &channelname, const std::vector< double > &parameters, const std::string &filename="stack.pdf", const std::string &options="e1b0stack")
Print the stack of templates together with the data in a particular channel.
Definition: BCMTF.h:375
int GetNProcesses() const
Definition: BCMTF.h:66
void SetSystematicVariation(const std::string &channelname, const std::string &processname, const std::string &systematicname, double variation_up, double variation_down)
Set the impact of a source of systematic uncertainty for a particular source of systematic uncertaint...
Definition: BCMTF.cxx:386
double ExpectationFunction(int parindex, int channelindex, int processindex, const std::vector< double > &parameters)
Return the function value of the expectation function for a parameter, channel and process...
Definition: BCMTF.cxx:557
The base class for all user-defined models.
Definition: BCModel.h:39
~BCMTF()
The default destructor.
Definition: BCMTF.cxx:44
int GetParIndexProcess(int index) const
Definition: BCMTF.h:92
void MCMCUserIterationInterface()
Method executed for every iteration of the MCMC.
Definition: BCMTF.cxx:1159
double Expectation(int channelindex, int binindex, const std::vector< double > &parameters)
Return the expected number of events for a channel and bin.
Definition: BCMTF.cxx:528
double Efficiency(int channelindex, int processindex, int binindex, const std::vector< double > &parameters)
Return the efficiency for a process in a channel and for a particular bin.
Definition: BCMTF.cxx:575
A class describing a process.
Definition: BCMTFProcess.h:29
double Probability(int channelindex, int processindex, int binindex, const std::vector< double > &parameters)
Return the probability for a process in a channel and for a particular bin.
Definition: BCMTF.cxx:623
double CalculateCash(int channelindex, const std::vector< double > &parameters)
Calculate the Cash statistic for a single channel.
Definition: BCMTF.cxx:969
void AddProcess(const std::string &name, double nmin=0., double nmax=1., int color=-1, int fillstyle=-1, int linestyle=-1)
Add a process and the associated BAT parameter.
Definition: BCMTF.cxx:289
void PrintStack(int channelindex, const std::vector< double > &parameters, const std::string &filename="stack.pdf", const std::string &options="e1b0stack")
Print the stack of templates together with the data in a particular channel.
Definition: BCMTF.cxx:644
int GetNSystematics() const
Definition: BCMTF.h:71
int GetParIndexSystematic(int index) const
Definition: BCMTF.h:98
int GetChannelIndex(const std::string &name) const
Definition: BCMTF.cxx:52
void SetFlagEfficiencyConstraint(bool flag)
Set a flag for the efficiency: if true then the total efficiency including all systematic uncertainti...
Definition: BCMTF.h:219
A class describing a physics channel.
Definition: BCMTFChannel.h:36
int GetProcessIndex(const std::string &name) const
Definition: BCMTF.cxx:65
void SetData(const std::string &channelname, TH1D hist, double minimum=-1, double maximum=-1)
Set the data histogram in a particular channel.
Definition: BCMTF.cxx:177
BCMTFSystematic * GetSystematic(int index)
Definition: BCMTF.h:119
void PrintFitSummary()
Print a summary of the fit to the log.
Definition: BCMTF.cxx:495
void SetExpectationFunction(int parindex, TF1 *func)
Set an expectation function.
Definition: BCMTF.h:165
BCMTFChannel * GetChannel(int index)
Definition: BCMTF.h:104
BCMTF(const std::string &name="multi_template_fitter")
A constructor.
Definition: BCMTF.cxx:35
BCMTFProcess * GetProcess(int index)
Definition: BCMTF.h:113
int GetSystematicIndex(const std::string &name) const
Definition: BCMTF.cxx:78
void AddChannel(const std::string &name)
Add a channel.
Definition: BCMTF.cxx:245
double CalculateChi2(int channelindex, const std::vector< double > &parameters)
Calculate a chi2 for a single channel given a set of parameters.
Definition: BCMTF.cxx:910
void AddSystematic(const std::string &name, double min=-5., double max=5.)
Add a source of systematic uncertainty and the associated BAT (nuisance) parameter.
Definition: BCMTF.cxx:343
virtual double Probability(const std::vector< double > &parameters)
Returns the a posteriori probability given a set of parameter values.
Definition: BCModel.h:213
double LogLikelihood(const std::vector< double > &parameters)
Calculate natural logarithm of the likelihood.
Definition: BCMTF.cxx:1114
A class for fitting several templates to a data set.
Definition: BCMTF.h:38
A class desribing a systematic uncertainty.