MINT2
SumPdf.h
Go to the documentation of this file.
1 #ifndef SUM_PDF_sums_two_normalised_pdfs_HH
2 #define SUM_PDF_sums_two_normalised_pdfs_HH
3 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
4 // status: Mon 9 Feb 2009 19:17:56 GMT
5 
6 #include "Mint/IPdf.h"
7 #include "Mint/PdfBase.h"
8 #include "Mint/FitParameter.h"
9 #include "Mint/IReturnReal.h"
10 
11 #include <iostream>
12 #include <vector>
13 
14 namespace MINT{
15 
16 template<typename EVENT_TYPE>
17 class SumPdf : public PdfBase<EVENT_TYPE>{
18  protected:
22 
23  public:
25  , IPdf<EVENT_TYPE>& pdf_1
26  , IPdf<EVENT_TYPE>& pdf_2)
27  : PdfBase<EVENT_TYPE>()
28  , _f1(f1), _pdf_1(pdf_1), _pdf_2(pdf_2)
29  {
30  }
31 
32  SumPdf(const SumPdf& other)
33  : IReturnRealForEvent<EVENT_TYPE>()
34  , IPdf<EVENT_TYPE>()
35  , PdfBase<EVENT_TYPE>()
36  , _f1(other._f1), _pdf_1(other._pdf_1), _pdf_2(other._pdf_2)
37  {
38  }
39 
40  virtual double getVal(EVENT_TYPE & evt){
41  bool dbThis=false;
42  if(dbThis) std::cout << "SumPdf::getVal(): you called?" << std::endl;
43  double f = (double) _f1;
44  double returnVal = f * _pdf_1.getVal(evt) + (1.0 - f) * _pdf_2.getVal(evt);
45  if(dbThis) std::cout << "SumPdf::getVal(): returning " << returnVal
46  << std::endl;
47  return returnVal;
48  }
49 
50  virtual void beginFit(){
51  bool dbThis=false;
52  if(dbThis) std::cout << "SumPdf::beginFit(): you called?" << std::endl;
53  if(dbThis) std::cout << "... calling beginFit PDF 1" << std::endl;
54  _pdf_1.beginFit();
55  if(dbThis) std::cout << "... calling beginFit PDF 2" << std::endl;
56  _pdf_2.beginFit();
57  if(dbThis) std::cout << "SumPdf::beginFit(): returning" << std::endl;
58  }
59  virtual void parametersChanged(){
60  bool dbThis=false;
61  if(dbThis) std::cout << "SumPdf::parametersChanged you called?"
62  << std::endl;
63  if(dbThis) std::cout << "... parametersChanged pdf 1" << std::endl;
65  if(dbThis) std::cout << "... parametersChanged pdf 2" << std::endl;
67  if(dbThis) std::cout << "SumPdf::parametersChanged: done."
68  << std::endl;
69  }
70  virtual void endFit(){
71  _pdf_1.endFit();
72  _pdf_2.endFit();
73  }
74 
75  virtual void Gradient(EVENT_TYPE & evt, std::vector<double>& grad, MINT::MinuitParameterSet* mps){
76  std::vector<double> grad_1(mps->size());
77  std::vector<double> grad_2(mps->size());
78 
79  if(grad.size() != mps->size()){
80  std::cout << "size-mismatch in SumPdf::Gradient" << std::endl;
81  throw "bugger";
82  }
83  for(unsigned int j=0; j < grad_1.size(); j++) grad_1[j]=0;
84  for(unsigned int j=0; j < grad_2.size(); j++) grad_2[j]=0;
85 
86  _pdf_1.Gradient(evt, grad_1,mps);
87  _pdf_2.Gradient(evt, grad_2,mps);
88 
89  for(unsigned int j=0; j < grad.size(); j++){
90  grad.at(j)= _f1 * grad_1.at(j) + (1.0 - _f1) * grad_2.at(j);
91  }
92 
93  }
94 
95  virtual bool useAnalyticGradient(){
97  }
98 
99  virtual ~SumPdf(){}
100 };
101 
102 }//namespace MINT
103 #endif
104 //
virtual bool useAnalyticGradient()
Definition: SumPdf.h:95
virtual ~SumPdf()
Definition: SumPdf.h:99
SumPdf(FitParameter &f1, IPdf< EVENT_TYPE > &pdf_1, IPdf< EVENT_TYPE > &pdf_2)
Definition: SumPdf.h:24
virtual void parametersChanged()=0
virtual void Gradient(EVENT_TYPE &evt, std::vector< double > &grad, MINT::MinuitParameterSet *mps)
Definition: SumPdf.h:75
unsigned int size() const
virtual double getVal(EVENT &EVT)=0
virtual double getVal(EVENT_TYPE &evt)
Definition: SumPdf.h:40
SumPdf(const SumPdf &other)
Definition: SumPdf.h:32
IPdf< EVENT_TYPE > & _pdf_1
Definition: SumPdf.h:20
virtual void beginFit()
Definition: SumPdf.h:50
virtual bool useAnalyticGradient()
Definition: IPdf.h:30
virtual void parametersChanged()
Definition: SumPdf.h:59
FitParameter & _f1
Definition: SumPdf.h:19
virtual void endFit()=0
virtual void Gradient(EVENT &evt, std::vector< double > &grad, MINT::MinuitParameterSet *mps)
Definition: IPdf.h:23
virtual void endFit()
Definition: SumPdf.h:70
virtual void beginFit()=0
IPdf< EVENT_TYPE > & _pdf_2
Definition: SumPdf.h:21