MINT2
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends | List of all members
MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE > Class Template Reference

#include <Neg2LL.h>

Inheritance diagram for MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >:
MINT::Minimisable MINT::IMinimisable

Public Member Functions

virtual void beginFit ()
 
virtual void parametersChanged ()
 
virtual void endFit ()
 
bool init ()
 
virtual double getPdf (unsigned int evtNumber)
 
virtual double logPdf (unsigned int evtNumber)
 
virtual double eventWeight (unsigned int evtNumber)
 
void doGradient (unsigned int i, double pdfVal, double weight)
 
virtual double getVal ()
 
virtual void Gradient (std::vector< double > &grad)
 
virtual bool useAnalyticGradient ()
 
virtual void setUseAnalyticGradient (bool useAnalyticGradient)
 
virtual double getNewVal ()
 
virtual ~Neg2LLClass ()
 
- Public Member Functions inherited from MINT::Minimisable
 Minimisable (MinuitParameterSet *mps=0)
 
 Minimisable (const Minimisable &other)
 
virtual ~Minimisable ()
 
void setPset (MinuitParameterSet *mps)
 
MinuitParameterSetgetParSet ()
 
- Public Member Functions inherited from MINT::IMinimisable
virtual ~IMinimisable ()
 

Protected Member Functions

 Neg2LLClass (PDF_TYPE &pdf, EVENTLIST_TYPE &erptr, MinuitParameterSet *mps=0)
 
 Neg2LLClass (const Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE > &other)
 

Protected Attributes

PDF_TYPE & _pdf
 
EVENTLIST_TYPE & _eventList
 
bool _useAnalyticGradient
 
std::vector< double > _grad
 

Private Attributes

int _NCalls
 

Friends

class Neg2LL
 

Detailed Description

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
class MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >

Definition at line 54 of file Neg2LL.h.

Constructor & Destructor Documentation

◆ Neg2LLClass() [1/2]

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::Neg2LLClass ( PDF_TYPE &  pdf,
EVENTLIST_TYPE &  erptr,
MinuitParameterSet mps = 0 
)
inlineprotected

Definition at line 71 of file Neg2LL.h.

74  : Minimisable(mps)
75  , _NCalls(0)
76  , _pdf(pdf)
77  , _eventList(erptr)
78  , _useAnalyticGradient(pdf.useAnalyticGradient())
79  , _grad()
80  {
81  init();
82  }
std::vector< double > _grad
Definition: Neg2LL.h:64
bool _useAnalyticGradient
Definition: Neg2LL.h:63
PDF_TYPE & _pdf
Definition: Neg2LL.h:61
Minimisable(MinuitParameterSet *mps=0)
Definition: Minimisable.cpp:6
EVENTLIST_TYPE & _eventList
Definition: Neg2LL.h:62

◆ Neg2LLClass() [2/2]

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::Neg2LLClass ( const Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE > &  other)
inlineprotected

Definition at line 83 of file Neg2LL.h.

84  : Minimisable(other)
85  , _NCalls(other._NCalls)
86  , _pdf(other._pdf)
87  , _eventList(other.erptr)
88  , _useAnalyticGradient(other._pdf.useAnalyticGradient())
89  , _grad()
90  {
91  init();
92  }
std::vector< double > _grad
Definition: Neg2LL.h:64
bool _useAnalyticGradient
Definition: Neg2LL.h:63
PDF_TYPE & _pdf
Definition: Neg2LL.h:61
Minimisable(MinuitParameterSet *mps=0)
Definition: Minimisable.cpp:6
EVENTLIST_TYPE & _eventList
Definition: Neg2LL.h:62

◆ ~Neg2LLClass()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::~Neg2LLClass ( )
inlinevirtual

Definition at line 298 of file Neg2LL.h.

298 {}//if(0 != _grad) delete[] _grad;}

Member Function Documentation

◆ beginFit()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual void MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::beginFit ( )
inlinevirtual

Reimplemented from MINT::Minimisable.

Definition at line 108 of file Neg2LL.h.

108  {
109  _pdf.beginFit();
110  };
PDF_TYPE & _pdf
Definition: Neg2LL.h:61

◆ doGradient()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
void MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::doGradient ( unsigned int  i,
double  pdfVal,
double  weight 
)
inline

Definition at line 181 of file Neg2LL.h.

181  {
182  if(! _useAnalyticGradient) return;
183 
184  std::vector<double> gradPDF(this->getParSet()->size());
185  _pdf.Gradient(_eventList[i], gradPDF,this->getParSet());
186  for(unsigned int j=0; j < this->getParSet()->size(); j++){
187  _grad.at(j)+= weight*gradPDF.at(j)/pdfVal;
188  }
189  return;
190  }
std::vector< double > _grad
Definition: Neg2LL.h:64
unsigned int size() const
bool _useAnalyticGradient
Definition: Neg2LL.h:63
PDF_TYPE & _pdf
Definition: Neg2LL.h:61
MinuitParameterSet * getParSet()
Definition: Minimisable.cpp:25
EVENTLIST_TYPE & _eventList
Definition: Neg2LL.h:62

◆ endFit()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual void MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::endFit ( )
inlinevirtual

Reimplemented from MINT::Minimisable.

Definition at line 115 of file Neg2LL.h.

115  {
116  _pdf.endFit();
117  };
PDF_TYPE & _pdf
Definition: Neg2LL.h:61

◆ eventWeight()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual double MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::eventWeight ( unsigned int  evtNumber)
inlinevirtual

Definition at line 173 of file Neg2LL.h.

173  {
174  return MINT::getWeight(_eventList[evtNumber]);
175  // trick: this is a template that will return one
176  // for all event types, but evt.getWeight in case
177  // the event inherits from IWeightedEvent.
178  // This template is included in IWeightedEvent.h
179  }
double getWeight(const EVT_TYPE &)
EVENTLIST_TYPE & _eventList
Definition: Neg2LL.h:62

◆ getNewVal()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual double MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::getNewVal ( )
inlinevirtual

Reimplemented from MINT::Minimisable.

Definition at line 292 of file Neg2LL.h.

292  {
293  // forces re-calculation after parameter change
295  return getVal();
296  }
virtual double getVal()
Definition: Neg2LL.h:192
virtual void parametersChanged()
Definition: Neg2LL.h:111

◆ getPdf()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual double MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::getPdf ( unsigned int  evtNumber)
inlinevirtual

Definition at line 139 of file Neg2LL.h.

139  {
140  bool dbThis=false;
141  //if(dbThis) {
142  //std::cout << "about to call _pdf.getVal() "
143  //<< "for event:\n " << _eventList[evtNumber]
144  //<< std::endl;
145  //}
146  /*
147  if(_eventList.size() <= evtNumber){
148  std::cout << "getPdf called for non-existing event number "
149  << evtNumber
150  << "while _eventList.size() = " << _eventList.size()
151  << "."
152  << std::endl;
153  throw "rubbish";
154  }
155  */
156  double valPdf = _pdf.getVal(_eventList[evtNumber]);
157  if(dbThis) std::cout << " that worked! the value is "
158  << valPdf << std::endl;
159  if(valPdf <= 0){
160  if(dbThis) std::cout << "ERROR in Neg2LLClass::logPdf()"
161  << " the pdf is " << valPdf
162  << " which is <= 0."
163  << std::endl;
164  return -9999.e20 * (1.0 + fabs(valPdf));
165  }
166  return valPdf;
167  }
PDF_TYPE & _pdf
Definition: Neg2LL.h:61
EVENTLIST_TYPE & _eventList
Definition: Neg2LL.h:62

◆ getVal()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual double MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::getVal ( )
inlinevirtual

Implements MINT::Minimisable.

Definition at line 192 of file Neg2LL.h.

192  {
193  _NCalls ++;
194  bool verbose=false;
195  bool dbThis=false;
196  int printFreq = 100;
197  printFreq = 100;
198  if(_NCalls > 500) printFreq = 1000;
199  if(_NCalls > 10000) printFreq = 5000;
200 
201  bool printout = (0 == _NCalls%printFreq) || _NCalls <= 1;
202  printout |= dbThis;
203  verbose |= dbThis;
204 
205  double sum=0;
206 
207  if(verbose && printout){
208  std::cout << "Neg2LLClass::getVal after " << _NCalls << " calls."
209  << " pdf ptr is non zero - that's a start."
210  << std::endl;
211  }
212  double sumweights=0.0;
213  double sumsquareweights=0.0;
214 
215 
216 
217  for(unsigned int i=0; i < _grad.size(); i++) _grad[i]= 0.;
218 
219  // this little thing takes care of things that
220  // get initialised at the first call
221  // (which we should eliminate, but for now
222  // this it a workable work-around)
223  // (needed for multithreading, only)
224  //if(_eventList.empty()) return 0;
225  //eventWeight(0);
226  //getPdf(0);
227 
228  //#pragma omp parallel for reduction(+:sum, sumweights, sumsquareweights);
229  for(unsigned int i=0; i < _eventList.size(); ++i){
230 
231  //EVENT_TYPE & evt( (*_eventList)[i] );
232  // sum += logPdf((*_eventList)[i]);
233  double weight = _eventList[i].getWeight();//eventWeight(i);
234  double pdfVal = getPdf(i);
235  double logPdfVal = log(pdfVal);
236  if(TMath::IsNaN(weight*logPdfVal))continue;
237  sum += weight*logPdfVal;
238  sumweights += weight;
239  sumsquareweights += weight*weight;
240 
241  /*
242  //std::cout << sum << std::endl;
243  if(TMath::IsNaN(sum)){ std::cout << "ERROR for " << i << std::endl;
244  std::cout << weight << std::endl;
245  std::cout << pdfVal << std::endl;
246  std::cout << weight*logPdfVal << std::endl << std::endl;
247 
248  std::cout << _eventList[i].getValueFromVector(0) << std::endl;
249  std::cout << _eventList[i].getValueFromVector(1) << std::endl;
250  std::cout << _eventList[i].getValueFromVector(2) << std::endl;
251  std::cout << _eventList[i].getValueFromVector(3) << std::endl;
252  std::cout << _eventList[i].getValueFromVector(4) << std::endl;
253  std::cout << _eventList[i].getValueFromVector(5) << std::endl;
254  std::cout << _eventList[i].getValueFromVector(6) << std::endl;
255  throw ""; }
256  */
257 
258  if(_useAnalyticGradient) doGradient(i, pdfVal, weight);
259  /*
260  omp didn't cope with the below:
261  if(_useAnalyticGradient){
262  _pdf.Gradient(_eventList[i],gradPDF,this->getParSet());
263  for(unsigned int j=0; j < this->getParSet()->size(); j++){
264  _grad[j]+= weight*gradPDF[j]/pdfVal;
265  }
266  }
267  */
268 
269  }
270 
271  for(unsigned int i=0; i < _grad.size(); i++) _grad[i]=-2. * _grad[i] * fabs(sumweights/sumsquareweights);
272 
273 
274  if(printout){
275  std::cout << "Neg2LLClass::getVal after " << _NCalls << " calls."
276  << "for " << _eventList.size()
277  << " events, I'm about to return "
278  << -2.0*sum*fabs(sumweights/sumsquareweights) << std::endl;
279  std::cout << "Sum of weights = " << sumweights << std::endl;
280  }
281  return -2.* sum*fabs(sumweights/sumsquareweights);
282  }
std::vector< double > _grad
Definition: Neg2LL.h:64
bool _useAnalyticGradient
Definition: Neg2LL.h:63
virtual double getPdf(unsigned int evtNumber)
Definition: Neg2LL.h:139
void doGradient(unsigned int i, double pdfVal, double weight)
Definition: Neg2LL.h:181
EVENTLIST_TYPE & _eventList
Definition: Neg2LL.h:62

◆ Gradient()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual void MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::Gradient ( std::vector< double > &  grad)
inlinevirtual

Reimplemented from MINT::IMinimisable.

Definition at line 284 of file Neg2LL.h.

284  {
285  grad=_grad;
286  //for(unsigned int i=0; i < _grad.size(); i++) grad[i]=_grad[i];
287  }
std::vector< double > _grad
Definition: Neg2LL.h:64

◆ init()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
bool MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::init ( )
inline

Definition at line 119 of file Neg2LL.h.

119  {
120  // just a place holder
121  bool dbThis=true;
122  if(dbThis){
123  std::cout << "Neg2LLClass: I got initialised with an event list with "
124  << _eventList.size() << " events." << std::endl;
125  std::cout << "Neg2LLClass: with pointer: " << &_eventList << std::endl;
126  //if(_eventList.size() > 0){
127  // std::cout << "The first one is:\n"
128  // << _eventList[0]
129  // << std::endl;
130  //}
131 
132  }
133  //_grad= new Double_t[this->getParSet()->size()];
134  _grad.resize(this->getParSet()->size());
135  for(unsigned int i=0; i < _grad.size(); i++) _grad[i]= 0.;
136  return true;
137  }
std::vector< double > _grad
Definition: Neg2LL.h:64
MinuitParameterSet * getParSet()
Definition: Minimisable.cpp:25
EVENTLIST_TYPE & _eventList
Definition: Neg2LL.h:62

◆ logPdf()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual double MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::logPdf ( unsigned int  evtNumber)
inlinevirtual

Definition at line 169 of file Neg2LL.h.

169  {
170  return log(getPdf(evtNumber));
171  }
virtual double getPdf(unsigned int evtNumber)
Definition: Neg2LL.h:139

◆ parametersChanged()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual void MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::parametersChanged ( )
inlinevirtual

Reimplemented from MINT::Minimisable.

Definition at line 111 of file Neg2LL.h.

111  {
112  _pdf.parametersChanged();
113  };
PDF_TYPE & _pdf
Definition: Neg2LL.h:61

◆ setUseAnalyticGradient()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual void MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::setUseAnalyticGradient ( bool  useAnalyticGradient)
inlinevirtual

Reimplemented from MINT::IMinimisable.

Definition at line 290 of file Neg2LL.h.

bool _useAnalyticGradient
Definition: Neg2LL.h:63
virtual bool useAnalyticGradient()
Definition: Neg2LL.h:289

◆ useAnalyticGradient()

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
virtual bool MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::useAnalyticGradient ( )
inlinevirtual

Reimplemented from MINT::IMinimisable.

Definition at line 289 of file Neg2LL.h.

289 {return _useAnalyticGradient;}
bool _useAnalyticGradient
Definition: Neg2LL.h:63

Friends And Related Function Documentation

◆ Neg2LL

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
friend class Neg2LL
friend

Definition at line 55 of file Neg2LL.h.

Member Data Documentation

◆ _eventList

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
EVENTLIST_TYPE& MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::_eventList
protected

Definition at line 62 of file Neg2LL.h.

◆ _grad

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
std::vector<double> MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::_grad
protected

Definition at line 64 of file Neg2LL.h.

◆ _NCalls

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
int MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::_NCalls
private

Definition at line 57 of file Neg2LL.h.

◆ _pdf

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
PDF_TYPE& MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::_pdf
protected

Definition at line 61 of file Neg2LL.h.

◆ _useAnalyticGradient

template<typename PDF_TYPE, typename EVENTLIST_TYPE>
bool MINT::Neg2LLClass< PDF_TYPE, EVENTLIST_TYPE >::_useAnalyticGradient
protected

Definition at line 63 of file Neg2LL.h.


The documentation for this class was generated from the following file: