laura is hosted by Hepforge, IPPP Durham
Laura++  v3r3
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauAbsFitModel.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2004 - 2014.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Authors:
7 // Thomas Latham
8 // John Back
9 // Paul Harrison
10 
15 #include <iostream>
16 #include <limits>
17 #include <vector>
18 
19 #include "TMessage.h"
20 #include "TMonitor.h"
21 #include "TServerSocket.h"
22 #include "TSocket.h"
23 #include "TSystem.h"
24 #include "TVirtualFitter.h"
25 
26 #include "LauAbsFitModel.hh"
27 #include "LauAbsFitter.hh"
28 #include "LauAbsPdf.hh"
29 #include "LauComplex.hh"
30 #include "LauFitter.hh"
31 #include "LauFitDataTree.hh"
32 #include "LauGenNtuple.hh"
33 #include "LauParameter.hh"
34 #include "LauParamFixed.hh"
35 #include "LauPrint.hh"
36 #include "LauSPlot.hh"
37 
39 
40 
42  compareFitData_(kFALSE),
43  savePDF_(kFALSE),
44  writeLatexTable_(kFALSE),
45  writeSPlotData_(kFALSE),
46  storeDPEff_(kFALSE),
47  randomFit_(kFALSE),
48  emlFit_(kFALSE),
49  poissonSmear_(kFALSE),
50  enableEmbedding_(kFALSE),
51  usingDP_(kTRUE),
52  pdfsDependOnDP_(kFALSE),
53  inputFitData_(0),
54  genNtuple_(0),
55  sPlotNtuple_(0),
56  nullString_(""),
57  doSFit_(kFALSE),
58  sWeightBranchName_(""),
59  sWeightScaleFactor_(1.0),
60  outputTableName_(""),
61  fitToyMCFileName_("fitToyMC.root"),
62  fitToyMCTableName_("fitToyMCTable"),
63  fitToyMCScale_(10),
64  fitToyMCPoissonSmear_(kFALSE),
65  sPlotFileName_(""),
66  sPlotTreeName_(""),
67  sPlotVerbosity_("")
68 {
69 }
70 
71 
73 {
74  delete inputFitData_; inputFitData_ = 0;
75  delete genNtuple_; genNtuple_ = 0;
76  delete sPlotNtuple_; sPlotNtuple_ = 0;
77 
78  // Remove the components created to apply constraints to fit parameters
79  for (std::vector<LauAbsRValue*>::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){
80  if ( !(*iter)->isLValue() ){
81  delete (*iter);
82  (*iter) = 0;
83  }
84  }
85 }
86 
87 void LauAbsFitModel::run(const TString& applicationCode, const TString& dataFileName, const TString& dataTreeName,
88  const TString& histFileName, const TString& tableFileName)
89 {
90  // Chose whether you want to generate or fit events in the Dalitz plot.
91  // To generate events choose applicationCode = "gen", to fit events choose
92  // applicationCode = "fit".
93 
94  TString runCode(applicationCode);
95  runCode.ToLower();
96 
97  TString histFileNameCopy(histFileName);
98  TString tableFileNameCopy(tableFileName);
99  TString dataFileNameCopy(dataFileName);
100  TString dataTreeNameCopy(dataTreeName);
101 
102  // Initialise the fit par vectors. Each class that inherits from this one
103  // must implement this sensibly for all vectors specified in clearFitParVectors,
104  // i.e. specify parameter names, initial, min, max and fixed values
105  this->initialise();
106 
107  // Add variables to Gaussian constrain to a list
108  this->addConParameters();
109 
110  if (dataFileNameCopy == "") {dataFileNameCopy = "data.root";}
111  if (dataTreeNameCopy == "") {dataTreeNameCopy = "genResults";}
112 
113  if (runCode.Contains("gen")) {
114 
115  if (histFileNameCopy == "") {histFileNameCopy = "parInfo.root";}
116  if (tableFileNameCopy == "") {tableFileNameCopy = "genResults";}
117 
118  this->setGenValues();
119  this->generate(dataFileNameCopy, dataTreeNameCopy, histFileNameCopy, tableFileNameCopy);
120 
121  } else if (runCode.Contains("fit")) {
122 
123  if (histFileNameCopy == "") {histFileNameCopy = "parInfo.root";}
124  if (tableFileNameCopy == "") {tableFileNameCopy = "fitResults";}
125 
126  this->fit(dataFileNameCopy, dataTreeNameCopy, histFileNameCopy, tableFileNameCopy);
127 
128  } else if (runCode.Contains("plot")) {
129 
130  this->savePDFPlots("plot");
131 
132  } else if (runCode.Contains("weight")) {
133 
134  this->weightEvents(dataFileNameCopy, dataTreeNameCopy);
135  }
136 }
137 
138 void LauAbsFitModel::doSFit( const TString& sWeightBranchName, Double_t scaleFactor )
139 {
140  if ( sWeightBranchName == "" ) {
141  std::cerr << "WARNING in LauAbsFitModel::doSFit : sWeight branch name is empty string, not setting-up sFit." << std::endl;
142  return;
143  }
144 
145  doSFit_ = kTRUE;
146  sWeightBranchName_ = sWeightBranchName;
147  sWeightScaleFactor_ = scaleFactor;
148 }
149 
150 void LauAbsFitModel::setBkgndClassNames( const std::vector<TString>& names )
151 {
152  if ( !bkgndClassNames_.empty() ) {
153  std::cerr << "WARNING in LauAbsFitModel::setBkgndClassNames : Names already stored, not changing them." << std::endl;
154  return;
155  }
156 
157  UInt_t nBkgnds = names.size();
158  for ( UInt_t i(0); i < nBkgnds; ++i ) {
159  bkgndClassNames_.insert( std::make_pair( i, names[i] ) );
160  }
161 
162  this->setupBkgndVectors();
163 }
164 
165 Bool_t LauAbsFitModel::validBkgndClass( const TString& className ) const
166 {
167  if ( bkgndClassNames_.empty() ) {
168  return kFALSE;
169  }
170 
171  Bool_t found(kFALSE);
172  for ( LauBkgndClassMap::const_iterator iter = bkgndClassNames_.begin(); iter != bkgndClassNames_.end(); ++iter ) {
173  if ( iter->second == className ) {
174  found = kTRUE;
175  break;
176  }
177  }
178 
179  return found;
180 }
181 
182 UInt_t LauAbsFitModel::bkgndClassID( const TString& className ) const
183 {
184  if ( ! this->validBkgndClass( className ) ) {
185  std::cerr << "ERROR in LauAbsFitModel::bkgndClassID : Request for ID for invalid background class \"" << className << "\"." << std::endl;
186  return (bkgndClassNames_.size() + 1);
187  }
188 
189  UInt_t bgID(0);
190  for ( LauBkgndClassMap::const_iterator iter = bkgndClassNames_.begin(); iter != bkgndClassNames_.end(); ++iter ) {
191  if ( iter->second == className ) {
192  bgID = iter->first;
193  break;
194  }
195  }
196 
197  return bgID;
198 }
199 
200 const TString& LauAbsFitModel::bkgndClassName( UInt_t classID ) const
201 {
202  LauBkgndClassMap::const_iterator iter = bkgndClassNames_.find( classID );
203 
204  if ( iter == bkgndClassNames_.end() ) {
205  std::cerr << "ERROR in LauAbsFitModel::bkgndClassName : Request for name of invalid background class ID " << classID << "." << std::endl;
206  return nullString_;
207  }
208 
209  return iter->second;
210 }
211 
213 {
214  std::cout << "INFO in LauAbsFitModel::clearFitParVectors : Clearing fit variable vectors" << std::endl;
215 
216  // Remove the components created to apply constraints to fit parameters
217  for (std::vector<LauAbsRValue*>::iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter){
218  if ( !(*iter)->isLValue() ){
219  delete (*iter);
220  (*iter) = 0;
221  }
222  }
223  conVars_.clear();
224  fitVars_.clear();
225 }
226 
228 {
229  std::cout << "INFO in LauAbsFitModel::clearExtraVarVectors : Clearing extra ntuple variable vectors" << std::endl;
230  extraVars_.clear();
231 }
232 
234 {
235  // makes sure each parameter holds its genValue as its current value
236  for (LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter) {
237  (*iter)->value((*iter)->genValue());
238  }
239  this->propagateParUpdates();
240 }
241 
242 void LauAbsFitModel::writeSPlotData(const TString& fileName, const TString& treeName, Bool_t storeDPEfficiency, const TString& verbosity)
243 {
244  if (this->writeSPlotData()) {
245  std::cerr << "ERROR in LauAbsFitModel::writeSPlotData : Already have an sPlot ntuple setup, not doing it again." << std::endl;
246  return;
247  }
248  writeSPlotData_ = kTRUE;
249  sPlotFileName_ = fileName;
250  sPlotTreeName_ = treeName;
251  sPlotVerbosity_ = verbosity;
252  storeDPEff_ = storeDPEfficiency;
253 }
254 
255 // TODO : histFileName isn't used here at the moment but could be used for
256 // storing the values of the parameters used in the generation.
257 // These could then be read and used for setting the "true" values
258 // in a subsequent fit.
259 void LauAbsFitModel::generate(const TString& dataFileName, const TString& dataTreeName, const TString& /*histFileName*/, const TString& tableFileNameBase)
260 {
261  // Create the ntuple for storing the results
262  std::cout << "INFO in LauAbsFitModel::generate : Creating generation ntuple." << std::endl;
263  if (genNtuple_ != 0) {delete genNtuple_; genNtuple_ = 0;}
264  genNtuple_ = new LauGenNtuple(dataFileName,dataTreeName);
265 
266  // add branches for storing the experiment number and the number of
267  // the event within the current experiment
268  this->addGenNtupleIntegerBranch("iExpt");
269  this->addGenNtupleIntegerBranch("iEvtWithinExpt");
270  this->setupGenNtupleBranches();
271 
272  // Start the cumulative timer
273  cumulTimer_.Start();
274 
275  const UInt_t firstExp = this->firstExpt();
276  const UInt_t nExp = this->nExpt();
277 
278  Bool_t genOK(kTRUE);
279  do {
280  // Loop over the number of experiments
281  for (UInt_t iExp = firstExp; iExp < (firstExp+nExp); ++iExp) {
282 
283  // Start the timer to see how long each experiment takes to generate
284  timer_.Start();
285 
286  // Store the experiment number in the ntuple
287  this->setGenNtupleIntegerBranchValue("iExpt",iExp);
288 
289  // Do the generation for this experiment
290  std::cout << "INFO in LauAbsFitModel::generate : Generating experiment number " << iExp << std::endl;
291  genOK = this->genExpt();
292 
293  // Stop the timer and see how long the program took so far
294  timer_.Stop();
295  timer_.Print();
296 
297  if (!genOK) {
298  // delete and recreate an empty tree
300 
301  // then break out of the experiment loop
302  std::cerr << "WARNING in LauAbsFitModel::generate : Problem in toy MC generation. Starting again with updated parameters..." << std::endl;
303  break;
304  }
305 
306  if (this->writeLatexTable()) {
307  TString tableFileName(tableFileNameBase);
308  tableFileName += "_";
309  tableFileName += iExp;
310  tableFileName += ".tex";
311  this->writeOutTable(tableFileName);
312  }
313 
314  } // Loop over number of experiments
315  } while (!genOK);
316 
317  // Print out total timing info.
318  cumulTimer_.Stop();
319  std::cout << "INFO in LauAbsFitModel::generate : Finished generating all experiments." << std::endl;
320  std::cout << "INFO in LauAbsFitModel::generate : Cumulative timing:" << std::endl;
321  cumulTimer_.Print();
322 
323  // Build the event index
324  std::cout << "INFO in LauAbsFitModel::generate : Building experiment:event index." << std::endl;
325  // TODO - can test this return value?
326  //Int_t nIndexEntries =
327  genNtuple_->buildIndex("iExpt","iEvtWithinExpt");
328 
329  // Write out toy MC ntuple
330  std::cout << "INFO in LauAbsFitModel::generate : Writing data to file " << dataFileName << "." << std::endl;
332 }
333 
335 {
337 }
338 
340 {
342 }
343 
345 {
346  genNtuple_->setIntegerBranchValue(name,value);
347 }
348 
350 {
351  genNtuple_->setDoubleBranchValue(name,value);
352 }
353 
355 {
356  return genNtuple_->getIntegerBranchValue(name);
357 }
358 
360 {
361  return genNtuple_->getDoubleBranchValue(name);
362 }
363 
365 {
367 }
368 
370 {
372 }
373 
375 {
377 }
378 
380 {
381  sPlotNtuple_->setIntegerBranchValue(name,value);
382 }
383 
385 {
386  sPlotNtuple_->setDoubleBranchValue(name,value);
387 }
388 
390 {
392 }
393 
394 void LauAbsFitModel::fit(const TString& dataFileName, const TString& dataTreeName, const TString& histFileName, const TString& tableFileNameBase)
395 {
396  // Routine to perform the total fit.
397 
398  const UInt_t firstExp = this->firstExpt();
399  const UInt_t nExp = this->nExpt();
400 
401  std::cout << "INFO in LauAbsFitModel::fit : First experiment = " << firstExp << std::endl;
402  std::cout << "INFO in LauAbsFitModel::fit : Number of experiments = " << nExp << std::endl;
403 
404  // Start the cumulative timer
405  cumulTimer_.Start();
406 
407  this->resetFitCounters();
408 
409  // Create and setup the fit results ntuple
410  this->setupResultsOutputs( histFileName, tableFileNameBase );
411 
412  // Create and setup the sPlot ntuple
413  if (this->writeSPlotData()) {
414  std::cout << "INFO in LauAbsFitModel::fit : Creating sPlot ntuple." << std::endl;
415  if (sPlotNtuple_ != 0) {delete sPlotNtuple_; sPlotNtuple_ = 0;}
417  this->setupSPlotNtupleBranches();
418  }
419 
420  // This reads in the given dataFile and creates an input
421  // fit data tree that stores them for all events and experiments.
422  Bool_t dataOK = this->verifyFitData(dataFileName,dataTreeName);
423  if (!dataOK) {
424  std::cerr << "ERROR in LauAbsFitModel::fit : Problem caching the fit data." << std::endl;
425  gSystem->Exit(EXIT_FAILURE);
426  }
427 
428  // Loop over the number of experiments
429  for (UInt_t iExp = firstExp; iExp < (firstExp+nExp); ++iExp) {
430 
431  // Start the timer to see how long each fit takes
432  timer_.Start();
433 
434  this->setCurrentExperiment( iExp );
435 
436  UInt_t nEvents = this->readExperimentData();
437  if (nEvents < 1) {
438  std::cerr << "WARNING in LauAbsFitModel::fit : Zero events in experiment " << iExp << ", skipping..." << std::endl;
439  timer_.Stop();
440  continue;
441  }
442 
443  // Now the sub-classes must implement whatever they need to do
444  // to cache any more input fit data they need in order to
445  // calculate the likelihoods during the fit.
446  // They need to use the inputFitData_ tree as input. For example,
447  // inputFitData_ contains m13Sq and m23Sq. The appropriate fit model
448  // then caches the resonance dynamics for the signal model, as
449  // well as the background likelihood values in the Dalitz plot
450  this->cacheInputFitVars();
451  if ( this->doSFit() ) {
452  this->cacheInputSWeights();
453  }
454 
455  // Do the fit for this experiment
456  this->fitExpt();
457 
458  // Write the results into the ntuple
460 
461  // Stop the timer and see how long the program took so far
462  timer_.Stop();
463  timer_.Print();
464 
465  // Store the per-event likelihood values
466  if ( this->writeSPlotData() ) {
467  this->storePerEvtLlhds();
468  }
469 
470  // Create a toy MC sample using the fitted parameters so that
471  // the user can compare the fit to the data.
472  if (compareFitData_ == kTRUE && this->statusCode() == 3) {
474  }
475 
476  } // Loop over number of experiments
477 
478  // Print out total timing info.
479  cumulTimer_.Stop();
480  std::cout << "INFO in LauAbsFitModel::fit : Cumulative timing:" << std::endl;
481  cumulTimer_.Print();
482 
483  // Print out stats on OK fits.
484  const UInt_t nOKFits = this->numberOKFits();
485  const UInt_t nBadFits = this->numberBadFits();
486  std::cout << "INFO in LauAbsFitModel::fit : Number of OK Fits = " << nOKFits << std::endl;
487  std::cout << "INFO in LauAbsFitModel::fit : Number of Failed Fits = " << nBadFits << std::endl;
488  Double_t fitEff(0.0);
489  if (nExp != 0) {fitEff = nOKFits/(1.0*nExp);}
490  std::cout << "INFO in LauAbsFitModel::fit : Fit efficiency = " << fitEff*100.0 << "%." << std::endl;
491 
492  // Write out any fit results (ntuples etc...).
493  this->writeOutAllFitResults();
494  if ( this->writeSPlotData() ) {
495  this->calculateSPlotData();
496  }
497 }
498 
499 void LauAbsFitModel::setupResultsOutputs( const TString& histFileName, const TString& tableFileName )
500 {
501  this->LauSimFitSlave::setupResultsOutputs( histFileName, tableFileName );
502 
503  outputTableName_ = tableFileName;
504 }
505 
506 Bool_t LauAbsFitModel::verifyFitData(const TString& dataFileName, const TString& dataTreeName)
507 {
508  // From the input data stream, store the variables into the
509  // internal tree inputFitData_ that can be used by the sub-classes
510  // in calculating their likelihood functions for the fit
511  delete inputFitData_;
512  inputFitData_ = new LauFitDataTree(dataFileName,dataTreeName);
513  Bool_t dataOK = inputFitData_->findBranches();
514 
515  if (!dataOK) {
516  delete inputFitData_; inputFitData_ = 0;
517  }
518 
519  return dataOK;
520 }
521 
523 {
524  Bool_t hasBranch = inputFitData_->haveBranch( sWeightBranchName_ );
525  if ( ! hasBranch ) {
526  std::cerr << "ERROR in LauAbsFitModel::cacheInputSWeights : Input data does not contain variable \"" << sWeightBranchName_ << "\".\n";
527  std::cerr << " : Turning off sFit!" << std::endl;
528  doSFit_ = kFALSE;
529  return;
530  }
531 
532  UInt_t nEvents = this->eventsPerExpt();
533  sWeights_.clear();
534  sWeights_.reserve( nEvents );
535 
536  for (UInt_t iEvt = 0; iEvt < nEvents; ++iEvt) {
537 
538  const LauFitData& dataValues = inputFitData_->getData(iEvt);
539 
540  LauFitData::const_iterator iter = dataValues.find( sWeightBranchName_ );
541 
542  sWeights_.push_back( iter->second * sWeightScaleFactor_ );
543  }
544 }
545 
547 {
548  // Routine to perform the actual fit for the given experiment
549 
550  // Update initial fit parameters if required (e.g. if using random numbers).
551  this->checkInitFitParams();
552 
553  // Initialise the fitter
557 
558  this->startNewFit( LauFitter::fitter()->nParameters(), LauFitter::fitter()->nFreeParameters() );
559 
560  // Now ready for minimisation step
561  std::cout << "\nINFO in LauAbsFitModel::fitExpt : Start minimisation...\n";
563 
564  // If we're doing a two stage fit we can now release (i.e. float)
565  // the 2nd stage parameters and re-fit
566  if (this->twoStageFit()) {
567  if ( fitResult.status != 3 ) {
568  std::cerr << "WARNING in LauAbsFitModel:fitExpt : Not running second stage fit since first stage failed." << std::endl;
570  } else {
572  this->startNewFit( LauFitter::fitter()->nParameters(), LauFitter::fitter()->nFreeParameters() );
573  fitResult = LauFitter::fitter()->minimise();
574  }
575  }
576 
577  const TMatrixD& covMat = LauFitter::fitter()->covarianceMatrix();
578  this->storeFitStatus( fitResult, covMat );
579 
580  // Store the final fit results and errors into protected internal vectors that
581  // all sub-classes can use within their own finalFitResults implementation
582  // used below (e.g. putting them into an ntuple in a root file)
584 }
585 
587 {
588  if (sPlotNtuple_ != 0) {
591  LauSPlot splot(sPlotNtuple_->fileName(), sPlotNtuple_->treeName(), this->firstExpt(), this->nExpt(),
592  this->variableNames(), this->freeSpeciesNames(), this->fixdSpeciesNames(), this->twodimPDFs(),
593  this->splitSignal(), this->scfDPSmear());
595  splot.writeOutResults();
596  }
597 }
598 
599 void LauAbsFitModel::compareFitData(UInt_t toyMCScale, const TString& mcFileName, const TString& tableFileName, Bool_t poissonSmearing)
600 {
601  compareFitData_ = kTRUE;
602  fitToyMCScale_ = toyMCScale;
603  fitToyMCFileName_ = mcFileName;
604  fitToyMCTableName_ = tableFileName;
605  fitToyMCPoissonSmear_ = poissonSmearing;
606 }
607 
608 void LauAbsFitModel::createFitToyMC(const TString& mcFileName, const TString& tableFileName)
609 {
610  // Create a toy MC sample so that the user can compare the fitted
611  // result with the data.
612  // Generate more toy MC to reduce statistical fluctuations:
613  // - use the rescaling value fitToyMCScale_
614 
615  // Store the info on the number of experiments, first expt and current expt
616  const UInt_t oldNExpt(this->nExpt());
617  const UInt_t oldFirstExpt(this->firstExpt());
618  const UInt_t oldIExpt(this->iExpt());
619 
620  // Turn off Poisson smearing if required
621  const Bool_t poissonSmearing(this->doPoissonSmearing());
623 
624  // Turn off embedding, since we need toy MC, not reco'ed events
625  const Bool_t enableEmbeddingOrig(this->enableEmbedding());
626  this->enableEmbedding(kFALSE);
627 
628  // Need to make sure that the generation of the DP co-ordinates is
629  // switched on if any of our PDFs depend on it
630  const Bool_t origUseDP = this->useDP();
631  if ( !origUseDP && this->pdfsDependOnDP() ) {
632  this->useDP( kTRUE );
633  this->initialiseDPModels();
634  }
635 
636  // Construct a unique filename for this experiment
637  TString exptString("_expt");
638  exptString += oldIExpt;
639  TString fileName( mcFileName );
640  fileName.Insert( fileName.Last('.'), exptString );
641 
642  // Generate the toy MC
643  std::cout << "INFO in LauAbsFitModel::createFitToyMC : Generating toy MC in " << fileName << " to compare fit with data..." << std::endl;
644  std::cout << " : Number of experiments to generate = " << fitToyMCScale_ << "." << std::endl;
645  std::cout << " : This is to allow the toy MC to be made with reduced statistical fluctuations." << std::endl;
646 
647  // Set the genValue of each parameter to its current (fitted) value
648  // but first store the original genValues for restoring later
649  std::vector<Double_t> origGenValues; origGenValues.reserve(this->nTotParams());
650  Bool_t blind(kFALSE);
651  for (LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter) {
652  origGenValues.push_back((*iter)->genValue());
653  (*iter)->genValue((*iter)->unblindValue());
654  if ( (*iter)->blind() ) {
655  blind = kTRUE;
656  }
657  }
658  if ( blind ) {
659  std::cerr << "WARNING in LauAbsFitModel::createFitToyMC : One or more parameters are blind but the toy will be created using the unblind values - use with caution!!" << std::endl;
660  }
661 
662  // If we're asked to generate more than 100 experiments then split it
663  // up into multiple files since otherwise can run into memory issues
664  // when building the index
665 
666  UInt_t totalExpts = fitToyMCScale_;
667  if ( totalExpts > 100 ) {
668  UInt_t nFiles = totalExpts/100;
669  if ( totalExpts%100 ) {
670  nFiles += 1;
671  }
672  for ( UInt_t iFile(0); iFile < nFiles; ++iFile ) {
673 
674  UInt_t firstExp( iFile*100 );
675 
676  // Set number of experiments and first experiment to generate
677  UInt_t nExp = ((firstExp + 100)>totalExpts) ? totalExpts-firstExp : 100;
678  this->setNExpts(nExp, firstExp);
679 
680  // Create a unique filename and generate the events
681  TString extraname = "_file";
682  extraname += iFile;
683  fileName.Insert( fileName.Last('.'), extraname );
684  this->generate(fileName, "genResults", "dummy.root", tableFileName);
685  }
686  } else {
687  // Set number of experiments to new value
688  this->setNExpts(fitToyMCScale_, 0);
689  // Generate the toy
690  this->generate(fileName, "genResults", "dummy.root", tableFileName);
691  }
692 
693  // Reset number of experiments to original value
694  this->setNExpts(oldNExpt, oldFirstExpt);
695  this->setCurrentExperiment(oldIExpt);
696 
697  // Restore the Poisson smearing to its former value
698  this->doPoissonSmearing(poissonSmearing);
699 
700  // Restore the embedding status
701  this->enableEmbedding(enableEmbeddingOrig);
702 
703  // Restore "useDP" to its former status
704  this->useDP( origUseDP );
705 
706  // Restore the original genValue to each parameter
707  for (UInt_t i(0); i<this->nTotParams(); ++i) {
708  fitVars_[i]->genValue(origGenValues[i]);
709  }
710 
711  std::cout << "INFO in LauAbsFitModel::createFitToyMC : Finished in createFitToyMC." << std::endl;
712 }
713 
715 {
716  // Calculate the total negative log-likelihood over all events.
717  // This function assumes that the fit parameters and data tree have
718  // already been set-up correctly.
719 
720  // Loop over the data points to calculate the log likelihood
721  Double_t logLike = this->getLogLikelihood( 0, this->eventsPerExpt() );
722 
723  // Include the Poisson term in the extended likelihood if required
724  if (this->doEMLFit()) {
725  logLike -= this->getEventSum();
726  }
727 
728  // Calculate any penalty terms from Gaussian constrained variables
729  if ( ! conVars_.empty() ){
730  logLike -= this->getLogLikelihoodPenalty();
731  }
732 
733  Double_t totNegLogLike = -logLike;
734  return totNegLogLike;
735 }
736 
738 {
739  Double_t penalty(0.0);
740 
741  for ( LauAbsRValuePList::const_iterator iter = conVars_.begin(); iter != conVars_.end(); ++iter ) {
742  Double_t val = (*iter)->unblindValue();
743  Double_t mean = (*iter)->constraintMean();
744  Double_t width = (*iter)->constraintWidth();
745 
746  Double_t term = ( val - mean )*( val - mean );
747  penalty += term/( 2*width*width );
748  }
749 
750  return penalty;
751 }
752 
753 Double_t LauAbsFitModel::getLogLikelihood( UInt_t iStart, UInt_t iEnd )
754 {
755  // Calculate the total negative log-likelihood over all events.
756  // This function assumes that the fit parameters and data tree have
757  // already been set-up correctly.
758 
759  // Loop over the data points to calculate the log likelihood
760  Double_t logLike(0.0);
761  const Double_t worstLL = this->worstLogLike();
762 
763  // Loop over the number of events in this experiment
764  Bool_t ok(kTRUE);
765  for (UInt_t iEvt = iStart; iEvt < iEnd; ++iEvt) {
766 
767  Double_t likelihood = this->getTotEvtLikelihood(iEvt);
768 
769  if (likelihood > std::numeric_limits<Double_t>::min()) { // Is the likelihood zero?
770  Double_t evtLogLike = TMath::Log(likelihood);
771  if ( doSFit_ ) {
772  evtLogLike *= sWeights_[iEvt];
773  }
774  logLike += evtLogLike;
775  } else {
776  ok = kFALSE;
777  std::cerr << "WARNING in LauAbsFitModel::getLogLikelihood : Strange likelihood value for event " << iEvt << ": " << likelihood << "\n";
778  this->printEventInfo(iEvt);
779  this->printVarsInfo(); //Write the values of the floated variables for which the likelihood is zero
780  break;
781  }
782  }
783 
784  if (!ok) {
785  std::cerr << " : Returning worst NLL found so far to force MINUIT out of this region." << std::endl;
786  logLike = worstLL;
787  } else if (logLike < worstLL) {
788  this->worstLogLike( logLike );
789  }
790 
791  return logLike;
792 }
793 
794 void LauAbsFitModel::setParsFromMinuit(Double_t* par, Int_t npar)
795 {
796  // This function sets the internal parameters based on the values
797  // that Minuit is using when trying to minimise the total likelihood function.
798 
799  // MINOS reports different numbers of free parameters depending on the
800  // situation, so disable this check
801  if ( ! this->withinAsymErrorCalc() ) {
802  const UInt_t nFreePars = this->nFreeParams();
803  if (static_cast<UInt_t>(npar) != nFreePars) {
804  std::cerr << "ERROR in LauAbsFitModel::setParsFromMinuit : Unexpected number of free parameters: " << npar << ".\n";
805  std::cerr << " Expected: " << nFreePars << ".\n" << std::endl;
806  gSystem->Exit(EXIT_FAILURE);
807  }
808  }
809 
810  // Despite npar being the number of free parameters
811  // the par array actually contains all the parameters,
812  // free and floating...
813 
814  // Update all the floating ones with their new values
815  // Also check if we have any parameters on which the DP integrals depend
816  // and whether they have changed since the last iteration
817  Bool_t recalcNorm(kFALSE);
818  const LauParameterPSet::const_iterator resVarsEnd = resVars_.end();
819  for (UInt_t i(0); i<this->nTotParams(); ++i) {
820  if (!fitVars_[i]->fixed()) {
821  if ( resVars_.find( fitVars_[i] ) != resVarsEnd ) {
822  if ( fitVars_[i]->value() != par[i] ) {
823  recalcNorm = kTRUE;
824  }
825  }
826  fitVars_[i]->value(par[i]);
827  }
828  }
829 
830  // If so, then recalculate the normalisation
831  if (recalcNorm) {
832  this->recalculateNormalisation();
833  }
834 
835  this->propagateParUpdates();
836 }
837 
839 {
840  UInt_t nParsAdded(0);
841  for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) {
842  LauAbsPdf* pdf = (*pdf_iter);
843  if ( pdf->isDPDependent() ) {
844  this->pdfsDependOnDP( kTRUE );
845  }
846  LauAbsRValuePList& pars = pdf->getParameters();
847  for (LauAbsRValuePList::iterator pars_iter = pars.begin(); pars_iter != pars.end(); ++pars_iter) {
848  LauParameterPList params = (*pars_iter)->getPars();
849  for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) {
850  if ( !(*params_iter)->clone() && ( !(*params_iter)->fixed() || ( this->twoStageFit() && (*params_iter)->secondStage() ) ) ) {
851  fitVars_.push_back(*params_iter);
852  ++nParsAdded;
853  }
854  }
855  }
856  }
857  return nParsAdded;
858 }
859 
861 {
862  for ( LauParameterPList::const_iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) {
863  if ( (*iter)->gaussConstraint() ) {
864  conVars_.push_back( *iter );
865  std::cout << "INFO in LauAbsFitModel::addConParameters : Added Gaussian constraint to parameter "<< (*iter)->name() << std::endl;
866  }
867  }
868 
869  // Add penalties from the constraints to fit parameters
870  const std::vector<StoreConstraints>& storeCon = this->constraintsStore();
871  for ( std::vector<StoreConstraints>::const_iterator iter = storeCon.begin(); iter != storeCon.end(); ++iter ) {
872  const std::vector<TString>& names = (*iter).conPars_;
873  std::vector<LauParameter*> params;
874  for ( std::vector<TString>::const_iterator iternames = names.begin(); iternames != names.end(); ++iternames ) {
875  for ( LauParameterPList::const_iterator iterfit = fitVars_.begin(); iterfit != fitVars_.end(); ++iterfit ) {
876  if ( (*iternames) == (*iterfit)->name() ){
877  params.push_back(*iterfit);
878  }
879  }
880  }
881 
882  // If the parameters are not found, skip it
883  if ( params.size() != (*iter).conPars_.size() ) {
884  std::cerr << "WARNING in LauAbsFitModel::addConParameters: Could not find parameters to constrain in the formula... skipping" << std::endl;
885  continue;
886  }
887 
888  LauFormulaPar* formPar = new LauFormulaPar( (*iter).formula_, (*iter).formula_, params );
889  formPar->addGaussianConstraint( (*iter).mean_, (*iter).width_ );
890  conVars_.push_back(formPar);
891 
892  std::cout << "INFO in LauAbsFitModel::addConParameters : Added Gaussian constraint to formula\n";
893  std::cout << " : Formula: " << (*iter).formula_ << std::endl;
894  for ( std::vector<LauParameter*>::iterator iterparam = params.begin(); iterparam != params.end(); ++iterparam ) {
895  std::cout << " : Parameter: " << (*iterparam)->name() << std::endl;
896  }
897  }
898 
899 }
900 
902 {
903  for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) {
904  (*pdf_iter)->updatePulls();
905  }
906 }
907 
908 void LauAbsFitModel::printFitParameters(const LauPdfList& pdfList, std::ostream& fout) const
909 {
910  LauPrint print;
911  for (LauPdfList::const_iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) {
912  const LauAbsRValuePList& pars = (*pdf_iter)->getParameters();
913  for (LauAbsRValuePList::const_iterator pars_iter = pars.begin(); pars_iter != pars.end(); ++pars_iter) {
914  LauParameterPList params = (*pars_iter)->getPars();
915  for (LauParameterPList::iterator params_iter = params.begin(); params_iter != params.end(); ++params_iter) {
916  if (!(*params_iter)->clone()) {
917  fout << (*params_iter)->name() << " & $";
918  print.printFormat(fout, (*params_iter)->value());
919  if ((*params_iter)->fixed() == kTRUE) {
920  fout << "$ (fixed) \\\\";
921  } else {
922  fout << " \\pm ";
923  print.printFormat(fout, (*params_iter)->error());
924  fout << "$ \\\\" << std::endl;
925  }
926  }
927  }
928  }
929  }
930 }
931 
933 {
934  for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) {
935  (*pdf_iter)->cacheInfo(theData);
936  }
937 }
938 
939 Double_t LauAbsFitModel::prodPdfValue(LauPdfList& pdfList, UInt_t iEvt)
940 {
941  Double_t pdfVal = 1.0;
942  for (LauPdfList::iterator pdf_iter = pdfList.begin(); pdf_iter != pdfList.end(); ++pdf_iter) {
943  (*pdf_iter)->calcLikelihoodInfo(iEvt);
944  pdfVal *= (*pdf_iter)->getLikelihood();
945  }
946  return pdfVal;
947 }
948 
949 void LauAbsFitModel::printEventInfo(UInt_t iEvt) const
950 {
951  const LauFitData& data = inputFitData_->getData(iEvt);
952  std::cerr << " : Input data values for this event:" << std::endl;
953  for (LauFitData::const_iterator iter = data.begin(); iter != data.end(); ++iter) {
954  std::cerr << " " << iter->first << " = " << iter->second << std::endl;
955  }
956 }
957 
959 {
960  std::cerr << " : Current values of fit parameters:" << std::endl;
961  for (UInt_t i(0); i<this->nTotParams(); ++i) {
962  std::cerr << " " << (fitVars_[i]->name()).Data() << " = " << fitVars_[i]->value() << std::endl;
963  }
964 }
965 
967 {
968  // Update initial fit parameters if required (e.g. if using random numbers).
969  this->checkInitFitParams();
970 
971  // Store the total number of parameters and the number of free parameters
972  UInt_t nPars = fitVars_.size();
973  UInt_t nFreePars = 0;
974 
975  // Send the fit parameters
976  for ( LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) {
977  if ( ! (*iter)->fixed() ) {
978  ++nFreePars;
979  }
980  array.Add( *iter );
981  }
982 
983  this->startNewFit( nPars, nFreePars );
984 }
985 
986 void LauAbsFitModel::finaliseExperiment( const LauAbsFitter::FitStatus& fitStat, const TObjArray* parsFromMaster, const TMatrixD* covMat, TObjArray& parsToMaster )
987 {
988  // Copy the fit status information
989  this->storeFitStatus( fitStat, *covMat );
990 
991  // Now process the parameters
992  const UInt_t nPars = this->nTotParams();
993  UInt_t nParsFromMaster = parsFromMaster->GetEntries();
994  if ( nParsFromMaster != nPars ) {
995  std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Unexpected number of parameters received from master" << std::endl;
996  std::cerr << " : Received " << nParsFromMaster << " when expecting " << nPars << std::endl;
997  gSystem->Exit( EXIT_FAILURE );
998  }
999 
1000  for ( UInt_t iPar(0); iPar < nParsFromMaster; ++iPar ) {
1001  LauParameter* parameter = dynamic_cast<LauParameter*>( (*parsFromMaster)[iPar] );
1002  if ( ! parameter ) {
1003  std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Error reading parameter from master" << std::endl;
1004  gSystem->Exit( EXIT_FAILURE );
1005  }
1006 
1007  if ( parameter->name() != fitVars_[iPar]->name() ) {
1008  std::cerr << "ERROR in LauAbsFitModel::finaliseExperiment : Error reading parameter from master" << std::endl;
1009  gSystem->Exit( EXIT_FAILURE );
1010  }
1011 
1012  *(fitVars_[iPar]) = *parameter;
1013  }
1014 
1015  // Write the results into the ntuple
1017 
1018  // Store the per-event likelihood values
1019  if ( this->writeSPlotData() ) {
1020  this->storePerEvtLlhds();
1021  }
1022 
1023  // Create a toy MC sample using the fitted parameters so that
1024  // the user can compare the fit to the data.
1025  if (compareFitData_ == kTRUE && fitStat.status == 3) {
1027  }
1028 
1029  // Send the finalised fit parameters
1030  for ( LauParameterPList::iterator iter = fitVars_.begin(); iter != fitVars_.end(); ++iter ) {
1031  parsToMaster.Add( *iter );
1032  }
1033 }
1034 
1036 {
1037  // retrieve the data and find out how many events have been read
1038  const UInt_t exptIndex = this->iExpt();
1039  inputFitData_->readExperimentData( exptIndex );
1040  const UInt_t nEvent = inputFitData_->nEvents();
1041  this->eventsPerExpt( nEvent );
1042  return nEvent;
1043 }
1044 
Class for defining the SPlot technique.
Definition: LauSPlot.hh:55
UInt_t nTotParams() const
Access the total number of fit parameters.
virtual const FitStatus & minimise()=0
Perform the minimisation of the fit function.
Int_t statusCode() const
Access the fit status code.
TString fitToyMCTableName_
The output table name for Toy MC.
virtual void addSPlotNtupleIntegerBranch(const TString &name)
Add a branch to the sPlot tree for storing an integer.
Bool_t findBranches()
Find all of the branches in the tree.
virtual Bool_t genExpt()=0
The method that actually generates the toy MC events for the given experiment.
void createFitToyMC(const TString &mcFileName, const TString &tableFileName)
Create a toy MC sample from the fitted parameters.
File containing declaration of LauFitDataTree class.
virtual Double_t getEventSum() const =0
Returns the sum of the expected events over all hypotheses; used in the EML fit scenario.
Bool_t fixed() const
Check whether the parameter is fixed or floated.
virtual void updateParameters()=0
Update the values and errors of the parameters based on the fit minimum.
void setGenValues()
Make sure all parameters hold their genValue as the current value.
TString sPlotFileName_
The name of the sPlot file.
virtual void setupResultsOutputs(const TString &histFileName, const TString &tableFileName)
Setup saving of fit results to ntuple/LaTeX table etc.
virtual void writeOutTable(const TString &outputFile)=0
Write the latex table.
virtual UInt_t readExperimentData()
Read in the data for the current experiment.
Bool_t writeLatexTable() const
Determine whether writing out of the latex table is enabled.
Bool_t doSFit_
Option to perfom the sFit.
Bool_t writeSPlotData() const
Determine whether the sPlot data is to be written out.
TStopwatch timer_
The fit timer.
File containing declaration of LauParamFixed class.
Bool_t withinAsymErrorCalc() const
Query whether the fit is calculating the asymmetric errors.
Definition: LauFitObject.hh:74
virtual Double_t getTotNegLogLikelihood()
Calculates the total negative log-likelihood.
LauAbsRValuePList conVars_
Internal vectors of Gaussian parameters.
Bool_t storeDPEff_
Option to store DP efficiencies in the sPlot ntuple.
void cacheInfo(LauPdfList &pdfList, const LauFitDataTree &theData)
Have all PDFs in the list cache the data.
void runCalculations(const TString &option="q")
Method to calculate the sWeights and cN coeffs.
Definition: LauSPlot.cc:626
virtual void setGenNtupleIntegerBranchValue(const TString &name, Int_t value)
Set the value of an integer branch in the gen tree.
ClassImp(LauAbsCoeffSet)
virtual void setupBkgndVectors()=0
Method to set up the storage for background-related quantities called by setBkgndClassNames.
LauGenNtuple * genNtuple_
The generated ntuple.
File containing declaration of LauAbsFitModel class.
virtual Bool_t verifyFitData(const TString &dataFileName, const TString &dataTreeName)
Open the input file and verify that all required variables are present.
virtual void writeOutAllFitResults()
Write out any fit results.
const TString & name() const
The parameter name.
Class for defining combinations of fit parameter objects.
virtual void setupGenNtupleBranches()=0
Setup the generation ntuple branches.
UInt_t addFitParameters(LauPdfList &pdfList)
Add parameters of the PDFs in the list to the list of all fit parameters.
virtual void generate(const TString &dataFileName, const TString &dataTreeName, const TString &histFileName, const TString &tableFileNameBase)
Generate toy MC.
virtual void setBkgndClassNames(const std::vector< TString > &names)
Setup the background class names.
void setNExpts(UInt_t nExperiments, UInt_t firstExperiment=0)
Set the number of experiments and the first experiment.
Definition: LauFitObject.hh:81
Bool_t useDP() const
Is the Dalitz plot term in the likelihood.
Int_t buildIndex(const TString &majorName, const TString &minorName="0")
Create an index table using leaves of the tree.
Double_t worstLogLike() const
Access the worst log likelihood found so far.
void compareFitData(UInt_t toyMCScale=10, const TString &mcFileName="fitToyMC.root", const TString &tableFileName="fitToyMCTable.tex", Bool_t poissonSmearing=kTRUE)
Specify that a toy MC sample should be created for a successful fit to an experiment.
const TString & treeName() const
Ntuple tree name.
Definition: LauGenNtuple.hh:56
virtual void finaliseExperiment(const LauAbsFitter::FitStatus &fitStat, const TObjArray *parsFromMaster, const TMatrixD *covMat, TObjArray &parsToMaster)
Perform all finalisation actions.
Int_t getIntegerBranchValue(const TString &name) const
Get value of an integer branch.
virtual void cacheInputSWeights()
Cache the value of the sWeights to be used in the sFit.
virtual Bool_t twoStageFit() const =0
Determine whether the two-stage fit is enabled.
virtual void setGenNtupleDoubleBranchValue(const TString &name, Double_t value)
Set the value of a double branch in the gen tree.
void deleteAndRecreateTree()
Delete and recreate tree.
File containing declaration of LauAbsFitter class.
void storeFitStatus(const LauAbsFitter::FitStatus &status, const TMatrixD &covMatrix)
Store fit status information.
Definition: LauFitObject.cc:56
void addFriendTree(const TString &rootFileName, const TString &rootTreeName)
Add a friend tree.
virtual void storePerEvtLlhds()=0
Store the per-event likelihood values.
virtual void printEventInfo(UInt_t iEvt) const
Prints the values of all the fit variables for the specified event - useful for diagnostics.
Bool_t pdfsDependOnDP() const
Do any of the PDFs have a dependence on the DP?
virtual ~LauAbsFitModel()
Destructor.
Bool_t compareFitData_
Option to make toy from 1st successful experiment.
File containing declaration of LauPrint class.
Double_t prodPdfValue(LauPdfList &pdfList, UInt_t iEvt)
Calculate the product of the per-event likelihoods of the PDFs in the list.
Bool_t twoStageFit() const
Report whether the two-stage fit is enabled.
Definition: LauFitObject.hh:59
Double_t getDoubleBranchValue(const TString &name) const
Get value of a double branch.
std::vector< LauAbsPdf * > LauPdfList
List of Pdfs.
std::map< TString, Double_t > LauFitData
Type for holding event data.
void fillBranches()
Fill branches in the ntuple.
virtual Int_t getGenNtupleIntegerBranchValue(const TString &name) const
Get the value of an integer branch in the gen tree.
virtual LauSPlot::NumbMap fixdSpeciesNames() const =0
Returns the names and yields of species that are fixed in the fit.
LauBkgndClassMap bkgndClassNames_
The background class names.
Class to define various output print commands.
Definition: LauPrint.hh:29
virtual void setupSPlotNtupleBranches()=0
Setup the branches of the sPlot tuple.
virtual void fillGenNtupleBranches()
Fill the gen tuple branches.
virtual void setSPlotNtupleDoubleBranchValue(const TString &name, Double_t value)
Set the value of a double branch in the sPlot tree.
UInt_t nFreeParams() const
Access the total number of fit parameters.
void printFitParameters(const LauPdfList &pdfList, std::ostream &fout) const
Print the fit parameters for all PDFs in the list.
void addGaussianConstraint(Double_t newGaussMean, Double_t newGaussWidth)
Add a Gaussian constraint (or modify an existing one)
virtual void initialise(LauFitObject *fitObj, const std::vector< LauParameter * > &parameters)=0
Initialise the fitter, setting the information on the parameters.
void readExperimentData(UInt_t iExpt)
Read events only for the given experiment.
std::vector< LauAbsRValue * > LauAbsRValuePList
List of parameter pointers.
void resetFitCounters()
Reset the good/bad fit counters.
Definition: LauFitObject.cc:39
virtual Double_t getTotEvtLikelihood(UInt_t iEvt)=0
Calculates the likelihood for a given event.
TStopwatch cumulTimer_
The total fit timer.
File containing declaration of LauFitter class.
virtual void propagateParUpdates()=0
This function (specific to each model) calculates anything that depends on the fit parameter values...
void addConParameters()
Add parameters to the list of Gaussian constrained parameters.
virtual void recalculateNormalisation()=0
Recalculate normalisation the signal DP model(s)
LauFitDataTree * inputFitData_
The input data.
Bool_t doSFit() const
Return the flag to store the status of using an sFit or not.
void run(const TString &applicationCode, const TString &dataFileName, const TString &dataTreeName, const TString &histFileName, const TString &tableFileName="")
Start the toy generation / fitting.
std::vector< LauParameter * > LauParameterPList
List of parameter pointers.
const TString & treeName() const
Retrieve the tree name.
LauParameterList extraVars_
Extra variables that aren&#39;t in the fit but are stored in the ntuple.
Bool_t blind() const
The blinding state.
void addIntegerBranch(const TString &name)
Add integer branch to tree.
Definition: LauGenNtuple.cc:73
const TString & fileName() const
Ntuple file name.
Definition: LauGenNtuple.hh:50
UInt_t eventsPerExpt() const
Obtain the total number of events in the current experiment.
Definition: LauFitObject.hh:87
void setCurrentExperiment(const UInt_t curExpt)
Set the ID of the current experiment.
Abstract interface to the fitting and toy MC model.
const std::vector< StoreConstraints > & constraintsStore() const
Const access to the constraints store.
Int_t status
The status code of the fit.
Definition: LauAbsFitter.hh:43
virtual void addGenNtupleIntegerBranch(const TString &name)
Add a branch to the gen tree for storing an integer.
virtual void prepareInitialParArray(TObjArray &array)
Package the initial fit parameters for transmission to the master.
File containing declaration of LauParameter class.
Bool_t doPoissonSmearing() const
Determine whether Poisson smearing is enabled for the toy MC generation.
Struct to store fit status information.
Definition: LauAbsFitter.hh:41
virtual Double_t getGenNtupleDoubleBranchValue(const TString &name) const
Get the value of a double branch in the gen tree.
virtual void weightEvents(const TString &dataFileName, const TString &dataTreeName)=0
Weighting - allows e.g. MC events to be weighted by the DP model.
Bool_t doEMLFit() const
Determine whether an extended maximum likelihood fit it being performed.
File containing declaration of LauComplex class.
const TString & fileName() const
Retrieve the file name.
virtual Bool_t isDPDependent() const
Specifies whether or not the PDF is DP dependent.
Definition: LauAbsPdf.hh:111
virtual LauSPlot::NumbMap freeSpeciesNames() const =0
Returns the names and yields of species that are free in the fit.
Class to store the results from the toy MC generation into an ntuple.
Definition: LauGenNtuple.hh:32
File containing declaration of LauSPlot class.
virtual Bool_t splitSignal() const =0
Check if the signal is split into well-reconstructed and mis-reconstructed types. ...
virtual void releaseSecondStageParameters()=0
Release parameters marked as &quot;second stage&quot;.
TString sPlotTreeName_
The name of the sPlot tree.
virtual void initialiseDPModels()=0
Initialise the DP models.
LauGenNtuple * sPlotNtuple_
The sPlot ntuple.
UInt_t nExpt() const
Obtain the number of experiments.
Definition: LauFitObject.hh:90
TString sPlotVerbosity_
Control the verbosity of the sFit.
const TString nullString_
An empty string.
void clearFitParVectors()
Clear the vectors containing fit parameters.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:35
virtual void addSPlotNtupleDoubleBranch(const TString &name)
Add a branch to the sPlot tree for storing a double.
void clearExtraVarVectors()
Clear the vectors containing extra ntuple variables.
virtual void cacheInputFitVars()=0
Cache the input data values to calculate the likelihood during the fit.
void fitExpt()
Routine to perform the actual fit for a given experiment.
virtual const std::vector< LauAbsRValue * > & getParameters() const
Retrieve the parameters of the PDF, e.g. so that they can be loaded into a fit.
Definition: LauAbsPdf.hh:239
Double_t sWeightScaleFactor_
The sWeight scaling factor.
File containing declaration of LauAbsPdf class.
UInt_t bkgndClassID(const TString &className) const
The number assigned to a background class.
const LauFitData & getData(UInt_t iEvt) const
Retrieve the data for a given event.
virtual void finaliseFitResults(const TString &tableFileName)=0
Write the results of the fit into the ntuple.
static LauAbsFitter * fitter()
Method that provides access to the singleton fitter.
Definition: LauFitter.cc:34
void setIntegerBranchValue(const TString &name, Int_t value)
Set value of an integer branch.
Definition: LauGenNtuple.cc:91
virtual void checkInitFitParams()=0
Update initial fit parameters if required.
virtual void printVarsInfo() const
Same as printEventInfo, but printing out the values of the variables in the fit.
Bool_t writeSPlotData_
Option to write sPlot data.
Bool_t validBkgndClass(const TString &className) const
Check if the given background class is in the list.
Bool_t fitToyMCPoissonSmear_
Option to perform Poisson smearing.
TString sWeightBranchName_
The name of the sWeight branch.
LauParameterPList fitVars_
Internal vector of fit parameters.
Bool_t useAsymmFitErrors() const
Report whether or not calculation of asymmetric errors is enabled.
Definition: LauFitObject.hh:43
virtual Bool_t scfDPSmear() const =0
Check if the mis-reconstructed signal is to be smeared in the DP.
void fit(const TString &dataFileName, const TString &dataTreeName, const TString &histFileName, const TString &tableFileNameBase)
Perform the total fit.
UInt_t numberOKFits() const
Access the number of successful fits.
UInt_t numberBadFits() const
Access the number of failed fits.
virtual void setSPlotNtupleIntegerBranchValue(const TString &name, Int_t value)
Set the value of an integer branch in the sPlot tree.
UInt_t fitToyMCScale_
The scaling factor (toy vs data statistics)
virtual void fillSPlotNtupleBranches()
Fill the sPlot tuple.
TString fitToyMCFileName_
The output file name for Toy MC.
void writeOutGenResults()
Write out the results from the generation.
void printFormat(std::ostream &stream, Double_t value) const
Method to choose the printing format to a specified level of precision.
Definition: LauPrint.cc:32
virtual LauSPlot::TwoDMap twodimPDFs() const =0
Returns the species and variables for all 2D PDFs in the fit.
Double_t getLogLikelihoodPenalty()
Calculate the penalty terms to the log likelihood from Gaussian constraints.
Bool_t haveBranch(const TString &name) const
Check if the named branch is stored.
virtual void savePDFPlots(const TString &label)=0
Save the pdf Plots for all the resonances of experiment number fitExp.
const TString & bkgndClassName(UInt_t classID) const
Get the name of a background class from the number.
void startNewFit(const UInt_t nPars, const UInt_t nFreePars)
Indicate the start of a new fit.
Definition: LauFitObject.cc:46
LauParameterPSet resVars_
Internal set of fit parameters upon which the DP normalisation depends.
virtual Bool_t useAsymmFitErrors() const =0
Determine whether calculation of asymmetric errors is enabled.
Bool_t enableEmbedding() const
Determine whether embedding of events is enabled in the generation.
Class for defining the abstract interface for PDF classes.
Definition: LauAbsPdf.hh:41
Double_t getLogLikelihood(UInt_t iStart, UInt_t iEnd)
Calculate the sum of the log-likelihood over the specified events.
virtual LauSPlot::NameSet variableNames() const =0
Returns the names of all variables in the fit.
Double_t value() const
The value of the parameter.
UInt_t nEvents() const
Retrieve the number of events.
virtual void addGenNtupleDoubleBranch(const TString &name)
Add a branch to the gen tree for storing a double.
void updateFitParameters(LauPdfList &pdfList)
Update the fit parameters for all PDFs in the list.
void addDoubleBranch(const TString &name)
Add double branch to tree.
Definition: LauGenNtuple.cc:82
UInt_t iExpt() const
Obtain the number of the current experiment.
Definition: LauFitObject.hh:96
TString outputTableName_
The output table name.
virtual void setParsFromMinuit(Double_t *par, Int_t npar)
This function sets the parameter values from Minuit.
virtual void initialise()=0
Initialise the fit par vectors.
UInt_t firstExpt() const
Obtain the number of the first experiment.
Definition: LauFitObject.hh:93
Class to store the input fit variables.
virtual const TMatrixD & covarianceMatrix() const =0
Retrieve the fit covariance matrix.
virtual void setupResultsOutputs(const TString &histFileName, const TString &tableFileName)
Setup saving of fit results to ntuple/LaTeX table etc.
virtual void calculateSPlotData()
Calculate the sPlot data.
File containing declaration of LauGenNtuple class.
void setDoubleBranchValue(const TString &name, Double_t value)
Set value of a double branch.
Definition: LauGenNtuple.cc:96
std::vector< Double_t > sWeights_
The vector of sWeights.