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