CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
TagProbeFitter Class Reference

#include <TagProbeFitter.h>

Public Member Functions

bool addCategory (std::string categoryName, std::string title, std::string expression)
 adds a new category variable to the set of variables describing the data in the tree; "expression" is parsed by factory() More...
 
bool addExpression (std::string expressionName, std::string title, std::string expression, const std::vector< std::string > &arguments)
 adds a new category based on a cut More...
 
void addFixedVariavles (const std::vector< std::string > &)
 set a list of variables to fix during first fit iteration. If the list is empty, do one iteration. More...
 
void addPdf (std::string pdfName, std::vector< std::string > &pdfCommands)
 
bool addThresholdCategory (std::string categoryName, std::string title, std::string varName, double cutValue)
 adds a new category based on a cut More...
 
bool addVariable (std::string variableName, std::string title, double low, double hi, std::string units)
 adds a new real variable to the set of variables describing the data in the tree More...
 
std::string calculateEfficiency (std::string dirName, std::string efficiencyCategory, std::string efficiencyState, std::vector< std::string > &unbinnedVariables, std::map< std::string, std::vector< double > > &binnedReals, std::map< std::string, std::vector< std::string > > &binnedCategories, std::vector< std::string > &binToPDFmap)
 calculate the efficiency for a particular binning of the data; it saves everything in the directory "dirName", uses the previously defined PDF with name "pdfName" More...
 
std::string calculateEfficiency (std::string dirName, const std::vector< std::string > &efficiencyCategories, const std::vector< std::string > &efficiencyStates, std::vector< std::string > &unbinnedVariables, std::map< std::string, std::vector< double > > &binnedReals, std::map< std::string, std::vector< std::string > > &binnedCategories, std::vector< std::string > &binToPDFmap)
 
void setBinnedFit (bool binned, int bins=0)
 set if to do a binned fit More...
 
void setBinsForMassPlots (int bins)
 set number of bins to use when making the plots; 0 = automatic More...
 
void setQuiet (bool quiet_=true)
 suppress most of the output from RooFit and Minuit More...
 
void setSaveDistributionsPlot (bool saveDistributionsPlot_)
 
void setSplitMode (unsigned int nevents)
 
void setWeightVar (const std::string &weight)
 set a variable to be used as weight for a dataset. empty string means no weights. More...
 
 TagProbeFitter (const std::vector< std::string > &inputFileNames, std::string inputDirectoryName, std::string inputTreeName, std::string outputFileName, int numCPU=1, bool saveWorkspace_=false, bool floatShapeParameters=true, const std::vector< std::string > &fixVars_=std::vector< std::string >())
 construct the fitter with the inputFileName, inputDirectoryName, inputTreeName, outputFileName and specify wether to save the workspace with data for each bin More...
 
 ~TagProbeFitter ()
 destructor closes the files More...
 

Protected Member Functions

void createPdf (RooWorkspace *w, std::vector< std::string > &pdfCommands)
 creates the simultaneous PDF in the workspace according to the "pdfCommands" More...
 
void doCntEfficiency (RooWorkspace *w, RooRealVar &efficiency)
 calculate the efficiecny by counting in the dataset found in the workspace More...
 
void doFitEfficiency (RooWorkspace *w, std::string pdfName, RooRealVar &efficiency)
 calculate the efficiecny with a simulataneous maximum likelihood fit in the dataset found in the workspace with PDF pdfName More...
 
void doSBSEfficiency (RooWorkspace *w, RooRealVar &efficiency)
 calculate the efficiecny with side band substraction in the dataset found in the workspace More...
 
void makeEfficiencyPlot1D (RooDataSet &eff, RooRealVar &v, const TString &plotName, const TString &plotTitle, const TString &effName, const char *catName=nullptr, int catIndex=-1)
 makes the 1D plot More...
 
void makeEfficiencyPlot2D (RooDataSet &eff, RooRealVar &v1, RooRealVar &v2, const TString &plotName, const TString &plotTitle, const TString &effName, const char *catName=nullptr, int catIndex=-1)
 makes the 2D plot More...
 
void saveDistributionsPlot (RooWorkspace *w)
 saves the distributions canvas More...
 
void saveEfficiencyPlots (RooDataSet &eff, const TString &effName, RooArgSet &binnedVariables, RooArgSet &mappedCategories)
 saves the efficiency plots More...
 
void saveFitPlot (RooWorkspace *w)
 saves the fit canvas More...
 
void setInitialValues (RooWorkspace *w)
 sets initial values of the PDF parameters based on the data available in the workspace More...
 
void varFixer (RooWorkspace *w, bool fix)
 fix or release variables selected by user More...
 
void varRestorer (RooWorkspace *w)
 restore variables's values for fit starting point More...
 
void varSaver (RooWorkspace *w)
 store values in the vector More...
 

Protected Attributes

int binnedFit
 do binned fit; 0 = automatic, 1 = yes, -1 = no. d More...
 
bool doSaveDistributionsPlot
 save distribution plots More...
 
std::vector< std::pair< std::pair< std::string, std::string >, std::pair< std::string, std::vector< std::string > > > > expressionVars
 expressions computed almost on the fly More...
 
std::vector< std::string > fixVars
 list of variables fo fix (see below) More...
 
std::vector< double > fixVarValues
 
bool floatShapeParameters
 
TChain * inputTree
 pointer to the input TTree Chain of data More...
 
int massBins
 number of bins to use in mass shape plots; 0 = automatic More...
 
int numCPU
 number of CPUs to use for the fit More...
 
TDirectory * outputDirectory
 pointer to the TDirectory in the output file that is the root directory for this fitter More...
 
TFile * outputFile
 pointer to the output file More...
 
RooWorkspace parameterParser
 a RooWorkspace object to parse input parameters with ".factory()" More...
 
std::map< std::string, std::vector< std::string > > pdfs
 the map of pdf names to the vector of commands to build the pdf More...
 
bool quiet
 suppress most printout More...
 
bool saveWorkspace
 the default option wether to save the workspace for each bin More...
 
unsigned int split_mode
 
std::vector< std::pair< std::pair< std::string, std::string >, std::pair< std::string, double > > > thresholdCategories
 
RooArgSet variables
 the set of variables describing the data in the input TTree More...
 
std::string weightVar
 weight variable (or empy string for no weights) More...
 

Detailed Description

Definition at line 11 of file TagProbeFitter.h.

Constructor & Destructor Documentation

TagProbeFitter::TagProbeFitter ( const std::vector< std::string > &  inputFileNames,
std::string  inputDirectoryName,
std::string  inputTreeName,
std::string  outputFileName,
int  numCPU = 1,
bool  saveWorkspace_ = false,
bool  floatShapeParameters = true,
const std::vector< std::string > &  fixVars_ = std::vector<std::string>() 
)

construct the fitter with the inputFileName, inputDirectoryName, inputTreeName, outputFileName and specify wether to save the workspace with data for each bin

Definition at line 52 of file TagProbeFitter.cc.

References gather_cfg::cout, MillePedeFileConverter_cfg::e, mps_fire::i, and download_sqlite_cfg::outputFile.

52  {
53  inputTree = new TChain((inputDirectoryName+"/"+inputTreeName).c_str());
54  for(size_t i=0; i<inputFileNames.size(); i++){
55  inputTree->Add(inputFileNames[i].c_str());
56  }
57  outputFile = new TFile(outputFileName.c_str(),"recreate");
58  outputDirectory = outputFile->mkdir(inputDirectoryName.c_str());
59  numCPU = numCPU_;
60  saveWorkspace = saveWorkspace_;
61  massBins = 0; // automatic default
62  floatShapeParameters = floatShapeParameters_;
63  fixVars = fixVars_;
64  weightVar = "";
65  if(!floatShapeParameters && fixVars.empty()) std::cout << "TagProbeFitter: " << "You wnat to fix some variables but do not specify them!";
66 
67  gROOT->SetStyle("Plain");
68  gStyle->SetTitleFillColor(0);
69  gStyle->SetPalette(1);
70  gStyle->SetOptStat(0);
71  gStyle->SetPaintTextFormat(".2f");
72 
73  quiet = false;
74 
75  binnedFit = false;
76 
78 
79  // make integration very precise
80  RooAbsReal::defaultIntegratorConfig()->setEpsAbs(1e-13);
81  RooAbsReal::defaultIntegratorConfig()->setEpsRel(1e-13);
82 
83  split_mode = 0;
84 }
std::string weightVar
weight variable (or empy string for no weights)
std::vector< std::string > fixVars
list of variables fo fix (see below)
TChain * inputTree
pointer to the input TTree Chain of data
unsigned int split_mode
bool saveWorkspace
the default option wether to save the workspace for each bin
bool doSaveDistributionsPlot
save distribution plots
int numCPU
number of CPUs to use for the fit
int massBins
number of bins to use in mass shape plots; 0 = automatic
bool quiet
suppress most printout
int binnedFit
do binned fit; 0 = automatic, 1 = yes, -1 = no. d
TFile * outputFile
pointer to the output file
TDirectory * outputDirectory
pointer to the TDirectory in the output file that is the root directory for this fitter ...
TagProbeFitter::~TagProbeFitter ( )

destructor closes the files

Definition at line 86 of file TagProbeFitter.cc.

References download_sqlite_cfg::outputFile.

86  {
87  if(inputTree)
88  delete inputTree;
89  if(outputFile)
90  outputFile->Close();
91 }
TChain * inputTree
pointer to the input TTree Chain of data
TFile * outputFile
pointer to the output file

Member Function Documentation

bool TagProbeFitter::addCategory ( std::string  categoryName,
std::string  title,
std::string  expression 
)

adds a new category variable to the set of variables describing the data in the tree; "expression" is parsed by factory()

Definition at line 113 of file TagProbeFitter.cc.

References EnergyCorrector::c, and objects.autophobj::variables.

Referenced by TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

113  {
114  RooCategory* c = (RooCategory*) parameterParser.factory(expression.c_str());
115  if(!c)
116  return false;
117  //set the name of the category to the passed name instead of the one in the expression
118  c->SetName(name.c_str());
119  c->SetTitle(title.c_str());
120  variables.addClone(*c);
121  return true;
122 }
RooWorkspace parameterParser
a RooWorkspace object to parse input parameters with ".factory()"
RooArgSet variables
the set of variables describing the data in the input TTree
bool TagProbeFitter::addExpression ( std::string  expressionName,
std::string  title,
std::string  expression,
const std::vector< std::string > &  arguments 
)

adds a new category based on a cut

Definition at line 124 of file TagProbeFitter.cc.

Referenced by TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

124  {
125  expressionVars.push_back(make_pair(make_pair(expressionName,title), make_pair(expression,arguments)));
126  return true;
127 }
std::vector< std::pair< std::pair< std::string, std::string >, std::pair< std::string, std::vector< std::string > > > > expressionVars
expressions computed almost on the fly
void TagProbeFitter::addFixedVariavles ( const std::vector< std::string > &  )

set a list of variables to fix during first fit iteration. If the list is empty, do one iteration.

void TagProbeFitter::addPdf ( std::string  pdfName,
std::vector< std::string > &  pdfCommands 
)

add a new PDF to the list of available PDFs; "pdfCommands" are parsed by factory(). the user needs to define efficiency[0.9,0,1] for the initial value, "signal" PDF, "backgroundPass" PDF and "backgroundFail" PDF

Definition at line 136 of file TagProbeFitter.cc.

References dataset::name.

Referenced by TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

136  {
137  pdfs[name] = pdfCommands;
138 }
std::map< std::string, std::vector< std::string > > pdfs
the map of pdf names to the vector of commands to build the pdf
bool TagProbeFitter::addThresholdCategory ( std::string  categoryName,
std::string  title,
std::string  varName,
double  cutValue 
)

adds a new category based on a cut

Definition at line 130 of file TagProbeFitter.cc.

Referenced by TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

130  {
131  thresholdCategories.push_back(make_pair(make_pair(categoryName,title), make_pair(varName,cutValue)));
132  return true;
133 }
std::vector< std::pair< std::pair< std::string, std::string >, std::pair< std::string, double > > > thresholdCategories
bool TagProbeFitter::addVariable ( std::string  variableName,
std::string  title,
double  low,
double  hi,
std::string  units 
)

adds a new real variable to the set of variables describing the data in the tree

Definition at line 106 of file TagProbeFitter.cc.

References groupFilesInBlocks::temp, and objects.autophobj::variables.

Referenced by TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

106  {
107  RooRealVar temp(name.c_str(), title.c_str(), low, hi, units.c_str());
108  temp.setBins(5000,"cache");
109  variables.addClone(temp);
110  return true;
111 }
TString units(TString variable, Char_t axis)
RooArgSet variables
the set of variables describing the data in the input TTree
std::string TagProbeFitter::calculateEfficiency ( std::string  dirName,
std::string  efficiencyCategory,
std::string  efficiencyState,
std::vector< std::string > &  unbinnedVariables,
std::map< std::string, std::vector< double > > &  binnedReals,
std::map< std::string, std::vector< std::string > > &  binnedCategories,
std::vector< std::string > &  binToPDFmap 
)
inline

calculate the efficiency for a particular binning of the data; it saves everything in the directory "dirName", uses the previously defined PDF with name "pdfName"

Definition at line 39 of file TagProbeFitter.h.

References TrackerOfflineValidation_Dqm_cff::dirName, genParticles_cff::map, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by TagProbeFitTreeAnalyzer::calculateEfficiency(), and setWeightVar().

39  {
40  std::vector<std::string> efficiencyCategories(1,efficiencyCategory);
41  std::vector<std::string> efficiencyStates(1,efficiencyState);
42  return calculateEfficiency(dirName, efficiencyCategories, efficiencyStates, unbinnedVariables, binnedReals, binnedCategories, binToPDFmap);
43  }
std::string calculateEfficiency(std::string dirName, std::string efficiencyCategory, std::string efficiencyState, std::vector< std::string > &unbinnedVariables, std::map< std::string, std::vector< double > > &binnedReals, std::map< std::string, std::vector< std::string > > &binnedCategories, std::vector< std::string > &binToPDFmap)
calculate the efficiency for a particular binning of the data; it saves everything in the directory "...
std::string TagProbeFitter::calculateEfficiency ( std::string  dirName,
const std::vector< std::string > &  efficiencyCategories,
const std::vector< std::string > &  efficiencyStates,
std::vector< std::string > &  unbinnedVariables,
std::map< std::string, std::vector< double > > &  binnedReals,
std::map< std::string, std::vector< std::string > > &  binnedCategories,
std::vector< std::string > &  binToPDFmap 
)
void TagProbeFitter::createPdf ( RooWorkspace *  w,
std::vector< std::string > &  pdfCommands 
)
protected

creates the simultaneous PDF in the workspace according to the "pdfCommands"

Definition at line 644 of file TagProbeFitter.cc.

References mps_check::command, mps_fire::i, and AlCaHLTBitMon_QueryRunRegistry::string.

644  {
645  // create the signal and background pdfs defined by the user
646  for(unsigned int i=0; i<pdfCommands.size(); i++){
647  const std::string & command = pdfCommands[i];
648  if (command.find("#import ") == 0) {
649  TDirectory *here = gDirectory;
650  w->import(command.substr(8).c_str());
651  here->cd();
652  } else {
653  TDirectory *here = gDirectory;
654  w->factory(command.c_str());
655  here->cd();
656  }
657  }
658  // setup the simultaneous extended pdf
659 
660  w->factory("expr::nSignalPass('efficiency*fSigAll*numTot', efficiency, fSigAll[.9,0,1],numTot[1,0,1e10])");
661  w->factory("expr::nSignalFail('(1-efficiency)*fSigAll*numTot', efficiency, fSigAll,numTot)");
662  w->factory("expr::nBkgPass('effBkg*(1-fSigAll)*numTot', effBkg[.9,0,1],fSigAll,numTot)");
663  w->factory("expr::nBkgFail('(1-effBkg)*(1-fSigAll)*numTot', effBkg,fSigAll,numTot)");
664  TString sPass = "signal", sFail = "signal";
665  if (w->pdf("signalPass") != nullptr && w->pdf("signalFail") != nullptr) {
666  if (w->pdf("signal") != nullptr) throw std::logic_error("You must either define one 'signal' PDF or two PDFs ('signalPass', 'signalFail'), not both!");
667  sPass = "signalPass"; sFail = "signalFail";
668  } else if (w->pdf("signal") != nullptr) {
669  if (w->pdf("signalPass") != nullptr || w->pdf("signalFail") != nullptr) {
670  throw std::logic_error("You must either define one 'signal' PDF or two PDFs ('signalPass', 'signalFail'), not both!");
671  }
672  } else {
673  throw std::logic_error("You must either define one 'signal' PDF or two PDFs ('signalPass', 'signalFail')");
674  }
675  w->factory("SUM::pdfPass(nSignalPass*"+sPass+", nBkgPass*backgroundPass)"); //fBkgPass*
676  w->factory("SUM::pdfFail(nSignalFail*"+sFail+", nBkgFail*backgroundFail)"); //fBkgFail*
677 
678  w->factory("SIMUL::simPdf(_efficiencyCategory_, Passed=pdfPass, Failed=pdfFail)");
679  // signalFractionInPassing is not used in the fit just to set the initial values
680  if (w->pdf("simPdf") == nullptr) throw std::runtime_error("Could not create simultaneous fit pdf.");
681  if(w->var("signalFractionInPassing") == nullptr)
682  w->factory("signalFractionInPassing[0.9]");
683 }
const double w
Definition: UKUtility.cc:23
list command
Definition: mps_check.py:25
void TagProbeFitter::doCntEfficiency ( RooWorkspace *  w,
RooRealVar &  efficiency 
)
protected

calculate the efficiecny by counting in the dataset found in the workspace

Definition at line 937 of file TagProbeFitter.cc.

References alpha, MillePedeFileConverter_cfg::e, and cmsPerfPublish::fail().

937  {
938  int pass = w->data("data")->sumEntries("_efficiencyCategory_==_efficiencyCategory_::Passed");
939  int fail = w->data("data")->sumEntries("_efficiencyCategory_==_efficiencyCategory_::Failed");
940  double e = (pass+fail == 0) ? 0 : pass/double(pass+fail);
941  // Use Clopper-Pearson
942  double alpha = (1.0 - .68540158589942957)/2;
943  double lo = (pass == 0) ? 0.0 : ROOT::Math::beta_quantile( alpha, pass, fail+1 );
944  double hi = (fail == 0) ? 1.0 : ROOT::Math::beta_quantile( 1-alpha, pass+1, fail );
946  //double lob, hib;
947  //Efficiency( pass, pass+fail, .68540158589942957, e, lob, hib );
948  //std::cerr << "CNT " << pass << "/" << fail << ": Clopper Pearson [" << lo << ", " << hi << "], Bayes [" << lob << ", " << hib << "]" << std::endl;
949  efficiency.setVal(e);
950  efficiency.setAsymError(lo-e, hi-e);
951 }
float alpha
Definition: AMPTWrapper.h:95
const double w
Definition: UKUtility.cc:23
def fail(errstr="")
void TagProbeFitter::doFitEfficiency ( RooWorkspace *  w,
std::string  pdfName,
RooRealVar &  efficiency 
)
protected

calculate the efficiecny with a simulataneous maximum likelihood fit in the dataset found in the workspace with PDF pdfName

—> if "floatShapeParameters==false" && "fixVars is NOT empty" : Perform a global fit to the whole sample, save the fitted values of the user specified parameters, and fix them for bin-by-bin fit.

Definition at line 484 of file TagProbeFitter.cc.

References MessageLogger_cfi::cerr, data, MillePedeFileConverter_cfg::e, and TagProbeFitTreeAnalyzer_cfi::NumCPU.

484  {
485  //if pdfName is empty skip the fit
486  if(pdfName == "all"){
487  return;
488  }
489  //create the simultaneous pdf of name pdfName
490  createPdf(w, pdfs[pdfName]);
491  //set the initial values for the yields of signal and background
493  std::unique_ptr<RooFitResult> res;
494 
495  RooAbsData *data = w->data("data");
496  std::unique_ptr<RooDataHist> bdata;
497  if (binnedFit) {
498  // get variables from data, which contain also other binning or expression variables
499  const RooArgSet *dataObs = data->get(0);
500  // remove everything which is not a dependency of the pdf
501  RooArgSet *obs = w->pdf("simPdf")->getObservables(dataObs);
502  bdata.reset(new RooDataHist("data_binned", "data_binned", *obs, *data));
503  w->import(*bdata);
504  data = w->data("data_binned");
505  delete obs;
506  }
507 
508  double totPassing = data->sumEntries("_efficiencyCategory_==_efficiencyCategory_::Passed");
509  double totFailing = data->sumEntries("_efficiencyCategory_==_efficiencyCategory_::Failed");
510 
511  RooAbsReal* simNLL = w->pdf("simPdf")->createNLL(*data,Extended(true),NumCPU(numCPU));
512 
513  RooMinimizer minimizer(*simNLL); // we are going to use this for 'scan'
514  RooMinuit minuit(*simNLL);
515  minuit.setStrategy(1);
516  minuit.setProfile(true);
517  RooProfileLL profileLL("simPdfNLL","",*simNLL,*w->var("efficiency"));
518 
519 
520  //******* The block of code below is to make the fit converge faster.
521  // ****** This part is OPTIONAL, i.e., off be default. User can activate this
522  // ****** by setting the following parameters: "fixVars" and "floatShapeParameters"
523  // ****** Here is the full logic:
534 
535 
536  if(!fixVars.empty()){
537  // calculate initial values for parameters user want to fix
538  if(!floatShapeParameters && fixVarValues.empty()){
539  // we want to fix these parameters for each bin.
540  // the following sequence fixes them, fits, releases and fits again
541  // to get reasonable values.
542  // ----------------------------------------------------------------------
543  // This procedure works only once with a whole dataset (without binning)
544  // ----------------------------------------------------------------------
545 
546  // fix them
547  varFixer(w,true);
548  //do fit
549  minimizer.minimize("Minuit2","Scan");
550  minuit.migrad();
551  minuit.hesse();
552  //minuit.minos();
553  //w->pdf("simPdf")->fitTo(*data, Save(true), Extended(true), NumCPU(numCPU), Strategy(2),
554  //PrintLevel(quiet?-1:1), PrintEvalErrors(quiet?-1:1), Warnings(!quiet));
555  //release vars
556  varFixer(w,false);
557  //do fit
558  minimizer.minimize("Minuit2","Scan");
559  minuit.migrad();
560  minuit.hesse();
561  //minuit.minos();
562  //w->pdf("simPdf")->fitTo(*data, Save(true), Extended(true), NumCPU(numCPU), Strategy(2),
563  //PrintLevel(quiet?-1:1), PrintEvalErrors(quiet?-1:1), Warnings(!quiet));
564  //save vars
565  varSaver(w);
566  // now we have a starting point. Fit will converge faster.
567  }
568 
569  // here we can use initial values if we want (this works for each bin)
570  if(!floatShapeParameters) varRestorer(w); //restore vars
571 
572  //do fit
573  minimizer.minimize("Minuit2","Scan");
574  minuit.migrad();
575  minuit.hesse();
576  // initialize the profile likelihood
577  profileLL.getVal();
578  RooMinimizer* profMinuit = profileLL.minimizer();
579  profMinuit->setProfile(true);
580  profMinuit->setStrategy(2);
581  profMinuit->setPrintLevel(1);
582  profMinuit->minos(*w->var("efficiency"));
583  res.reset( profMinuit->save() );
584  //res = w->pdf("simPdf")->fitTo(*data, Save(true), Extended(true), NumCPU(numCPU), Strategy(2),
585  //Minos(*w->var("efficiency")), PrintLevel(quiet?-1:1),
586  //PrintEvalErrors(quiet?-1:1), Warnings(!quiet));
587  }//if(!fixVars.empty())
588 
589  // (default = true) if we don't want to fix any parameters or want to fit each bin with all parameters floating
591  //release vars
592  varFixer(w,false);
593 
594  //do fit
595  minimizer.minimize("Minuit2","Scan");
596  minuit.migrad();
597  minuit.hesse();
598  res.reset( w->pdf("simPdf")->fitTo(*data, Save(true), Extended(true), NumCPU(numCPU), Strategy(2),
599  Minos(*w->var("efficiency")), PrintLevel(quiet?-1:1),
600  PrintEvalErrors(quiet?-1:1), Warnings(!quiet)) );
601  }
602 
603 
604 
605  // save everything
606  res->Write("fitresults");
607  w->saveSnapshot("finalState",w->components());
608  saveFitPlot(w);
609  //extract the efficiency parameter from the results
610  RooRealVar* e = (RooRealVar*) res->floatParsFinal().find("efficiency");
611  //What's wrong with this? and why don't they copy the errors!
612  //efficiency = *e;
613  efficiency.setVal(e->getVal());
614  Double_t errLo = e->getErrorLo(), errHi = e->getErrorHi();
615  if (errLo == 0 && e->getVal() < 0.5) errLo = e->getMin()-e->getVal();
616  if (errHi == 0 && e->getVal() > 0.5) errHi = e->getMax()-e->getVal();
617  efficiency.setAsymError(errLo, errHi);
618 
619  if (totPassing * totFailing == 0) {
620  RooRealVar* nTot = (RooRealVar*) res->floatParsFinal().find("numTot");
621  RooRealVar* fSig = (RooRealVar*) res->floatParsFinal().find("fSigAll");
622  double cerr = ROOT::Math::beta_quantile( 1-(1.0-.68540158589942957)/2, 1, nTot->getVal() * fSig->getVal() );
623  /*
624  std::cout << "======================================================================================" << std::endl;
625  std::cout << "======= totPassing " << totPassing << ", totFailing " << totFailing << std::endl;
626  std::cout << "======= FIT: e " << e->getVal() << ", e Lo " << e->getErrorLo() << ", e Hi " << e->getErrorHi() << std::endl;
627  std::cout << "======= FIT:nS " << nS->getVal() << ", nS Lo " << nS->getErrorLo() << ", nS Hi " << nS->getErrorHi() << std::endl;
628  std::cout << "======= FIT:nB " << nB->getVal() << ", nB Lo " << nB->getErrorLo() << ", nB Hi " << nB->getErrorHi() << std::endl;
629  std::cout << "======= CNT: " << cerr << std::endl;
630  std::cout << "======================================================================================" << std::endl;
631  */
632  if (totPassing == 0) {
633  efficiency.setVal(0);
634  efficiency.setAsymError(0,cerr);
635  } else {
636  efficiency.setVal(1);
637  efficiency.setAsymError(-cerr,0);
638  }
639  }
640 
641  delete simNLL;
642 }
const double w
Definition: UKUtility.cc:23
std::vector< std::string > fixVars
list of variables fo fix (see below)
Definition: Electron.h:6
std::map< std::string, std::vector< std::string > > pdfs
the map of pdf names to the vector of commands to build the pdf
void varSaver(RooWorkspace *w)
store values in the vector
void varRestorer(RooWorkspace *w)
restore variables&#39;s values for fit starting point
void saveFitPlot(RooWorkspace *w)
saves the fit canvas
void setInitialValues(RooWorkspace *w)
sets initial values of the PDF parameters based on the data available in the workspace ...
int numCPU
number of CPUs to use for the fit
bool quiet
suppress most printout
int binnedFit
do binned fit; 0 = automatic, 1 = yes, -1 = no. d
void varFixer(RooWorkspace *w, bool fix)
fix or release variables selected by user
std::vector< double > fixVarValues
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void createPdf(RooWorkspace *w, std::vector< std::string > &pdfCommands)
creates the simultaneous PDF in the workspace according to the "pdfCommands"
void TagProbeFitter::doSBSEfficiency ( RooWorkspace *  w,
RooRealVar &  efficiency 
)
protected

calculate the efficiecny with side band substraction in the dataset found in the workspace

Definition at line 934 of file TagProbeFitter.cc.

934  {
935 }
void TagProbeFitter::makeEfficiencyPlot1D ( RooDataSet &  eff,
RooRealVar &  v,
const TString &  plotName,
const TString &  plotTitle,
const TString &  effName,
const char *  catName = nullptr,
int  catIndex = -1 
)
protected

makes the 1D plot

Definition at line 880 of file TagProbeFitter.cc.

References svgfig::canvas(), mps_splice::entry, mps_fire::i, gen::n, and AlCaHLTBitMon_ParallelJobs::p.

880  {
881  TGraphAsymmErrors *p = new TGraphAsymmErrors();
882  const RooArgSet *entry = eff.get();
883  const RooRealVar &vi = dynamic_cast<const RooRealVar &>(*entry->find(v.GetName()));
884  const RooRealVar &ei = dynamic_cast<const RooRealVar &>(*entry->find("efficiency"));
885  for (unsigned int i = 0, n = eff.numEntries(); i < n; ++i) {
886  entry = eff.get(i);
887  if (catName != nullptr && entry->getCatIndex(catName) != catIndex) continue;
888  int j = p->GetN(); p->Set(j+1);
889  p->SetPoint(j, vi.getVal(), ei.getVal() );
890  p->SetPointError(j, -vi.getAsymErrorLo(), vi.getAsymErrorHi(), -ei.getAsymErrorLo(), ei.getAsymErrorHi() );
891  }
892  TCanvas canvas(plotName);
893  TH1F *frame = new TH1F("frame", "Efficiency of "+effName, 1, v.getMin(), v.getMax()); frame->SetDirectory(nullptr);
894  p->SetNameTitle(Form("hxy_%s", eff.GetName()), "Efficiency of "+effName);
895  p->GetXaxis()->SetTitle(strlen(v.getUnit()) ? Form("%s (%s)", v.GetName(), v.getUnit()) : v.GetName());
896  p->GetYaxis()->SetTitle("Efficiency of "+effName);
897  frame->GetXaxis()->SetTitle(strlen(v.getUnit()) ? Form("%s (%s)", v.GetName(), v.getUnit()) : v.GetName());
898  frame->GetYaxis()->SetTitle("Efficiency of "+effName);
899  frame->GetYaxis()->SetRangeUser(0,1);
900  frame->Draw();
901  p->SetLineWidth(2); p->SetMarkerStyle(kFullCircle); p->SetMarkerSize(1.2);
902  p->Draw("P SAME");
903  canvas.Write();
904  delete frame;
905  delete p;
906 }
def canvas(sub, attr)
Definition: svgfig.py:482
void TagProbeFitter::makeEfficiencyPlot2D ( RooDataSet &  eff,
RooRealVar &  v1,
RooRealVar &  v2,
const TString &  plotName,
const TString &  plotTitle,
const TString &  effName,
const char *  catName = nullptr,
int  catIndex = -1 
)
protected

makes the 2D plot

Definition at line 908 of file TagProbeFitter.cc.

References svgfig::canvas(), MillePedeFileConverter_cfg::e, mps_splice::entry, h, and mps_fire::i.

908  {
909  TCanvas canvas(plotName);
910  canvas.SetRightMargin(0.15);
911  TH2F* h = new TH2F(plotName, plotName, v1.getBinning().numBins(), v1.getBinning().array(), v2.getBinning().numBins(), v2.getBinning().array());
912  const RooArgSet* set = eff.get();
913  RooRealVar* e = (RooRealVar*) set->find("efficiency");
914  RooRealVar* v1_ = (RooRealVar*) set->find(v1.GetName());
915  RooRealVar* v2_ = (RooRealVar*) set->find(v2.GetName());
916  h->SetTitle(TString::Format("%s;%s%s;%s%s;Efficiency of %s", plotTitle.Data(),
917  v1.GetTitle(), TString(v1.getUnit()).Length()==0?"":TString::Format(" (%s)", v1.getUnit()).Data(),
918  v2.GetTitle(), TString(v2.getUnit()).Length()==0?"":TString::Format(" (%s)", v2.getUnit()).Data(), effName.Data()));
919  h->SetOption("colztexte");
920  h->GetZaxis()->SetRangeUser(-0.001,1.001);
921  h->SetStats(kFALSE);
922  for(int i=0; i<eff.numEntries(); i++){
923  const RooArgSet *entry = eff.get(i);
924  if (catName != nullptr && entry->getCatIndex(catName) != catIndex) continue;
925  h->SetBinContent(h->FindBin(v1_->getVal(), v2_->getVal()), e->getVal());
926  h->SetBinError(h->FindBin(v1_->getVal(), v2_->getVal()), (e->getErrorHi()-e->getErrorLo())/2.);
927  }
928  h->Draw();
929  canvas.Draw();
930  canvas.Write();
931  delete h;
932 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
def canvas(sub, attr)
Definition: svgfig.py:482
void TagProbeFitter::saveDistributionsPlot ( RooWorkspace *  w)
protected

saves the distributions canvas

Definition at line 785 of file TagProbeFitter.cc.

References svgfig::canvas(), mps_fire::i, globaldigis_analyze_cfi::Name, and findQualityFiles::v.

785  {
786  // save pointers to datasets to manage memory
787  RooAbsData* dataAll = w->data("data");
788  RooAbsData* dataPass = dataAll->reduce(Cut("_efficiencyCategory_==_efficiencyCategory_::Passed"));
789  RooAbsData* dataFail = dataAll->reduce(Cut("_efficiencyCategory_==_efficiencyCategory_::Failed"));
790 
791  const RooArgSet* vars = dataAll->get();
792  vector<RooRealVar*> reals;
793  RooLinkedListIter it = vars->iterator();
794  for(RooAbsArg* v = (RooAbsArg*)it.Next(); v!=nullptr; v = (RooAbsArg*)it.Next() ){
795  if(!v->InheritsFrom("RooRealVar")) continue;
796  reals.push_back((RooRealVar*)v);
797  }
798  TCanvas canvas("distributions_canvas");
799  canvas.Divide(3,reals.size());
800  vector<RooPlot*> frames;
801  for(unsigned int i=0; i<reals.size(); i++){
802  // plot the Passing Probes
803  canvas.cd(3*i+1);
804  frames.push_back(reals[i]->frame(Name("Passing"), Title("Passing Probes"), Bins(100)));
805  dataPass->plotOn(frames.back(), LineColor(kGreen));
806  dataPass->statOn(frames.back());
807  frames.back()->Draw();
808  // plot the Failing Probes
809  canvas.cd(3*i+2);
810  frames.push_back(reals[i]->frame(Name("Failing"), Title("Failing Probes"), Bins(100)));
811  dataFail->plotOn(frames.back(), LineColor(kRed));
812  dataFail->statOn(frames.back());
813  frames.back()->Draw();
814  // plot the All Probes
815  canvas.cd(3*i+3);
816  frames.push_back(reals[i]->frame(Name("All"), Title("All Probes"), Bins(100)));
817  dataAll->plotOn(frames.back(), LineColor(kBlue));
818  dataAll->statOn(frames.back());
819  frames.back()->Draw();
820  }
821  canvas.Draw();
822  canvas.Write();
823  for (size_t i=0; i<frames.size(); i++) {
824  delete frames[i];
825  }
826  delete dataPass;
827  delete dataFail;
828 }
const double w
Definition: UKUtility.cc:23
def canvas(sub, attr)
Definition: svgfig.py:482
vars
Definition: DeepTauId.cc:77
void TagProbeFitter::saveEfficiencyPlots ( RooDataSet &  eff,
const TString &  effName,
RooArgSet &  binnedVariables,
RooArgSet &  mappedCategories 
)
protected

saves the efficiency plots

Definition at line 830 of file TagProbeFitter.cc.

References protons_cff::t.

830  {
831  RooLinkedListIter v1it = binnedVariables.iterator();
832  bool isOnePoint = (eff.numEntries() == 1); // for datasets with > 1 entry, we don't make plots for variables with just one bin
833  for(RooRealVar* v1 = (RooRealVar*)v1it.Next(); v1!=nullptr; v1 = (RooRealVar*)v1it.Next() ){
834  RooArgSet binCategories1D;
835  if (v1->numBins() == 1 && !isOnePoint) continue;
836  RooLinkedListIter v2it = binnedVariables.iterator();
837  for(RooRealVar* v2 = (RooRealVar*)v2it.Next(); v2!=nullptr; v2 = (RooRealVar*)v2it.Next() ){
838  if(v2 == v1) continue;
839  if (v2->numBins() == 1 && !isOnePoint) continue;
840  binCategories1D.addClone( RooBinningCategory(TString(v2->GetName())+"_bins", TString(v2->GetName())+"_bins", *v2) );
841 
842  RooArgSet binCategories2D;
843  RooLinkedListIter v3it = binnedVariables.iterator();
844  for(RooRealVar* v3 = (RooRealVar*)v3it.Next(); v3!=nullptr; v3 = (RooRealVar*)v3it.Next() ){
845  if(v3 == v1 || v3 == v2) continue;
846  binCategories2D.addClone( RooBinningCategory(TString(v3->GetName())+"_bins", TString(v3->GetName())+"_bins", *v3) );
847  }
848  RooMultiCategory allCats2D("allCats2D", "allCats2D", RooArgSet(binCategories2D, mappedCategories));
849  if(allCats2D.numTypes()==0){
850  makeEfficiencyPlot2D(eff, *v1, *v2, TString::Format("%s_%s_PLOT", v1->GetName(), v2->GetName()), "", effName);
851  }else{
852  RooDataSet myEff(eff);
853  myEff.addColumn(allCats2D);
854  std::unique_ptr<TIterator> catIt(allCats2D.typeIterator());
855  for(RooCatType* t = (RooCatType*)catIt->Next(); t!=nullptr; t = (RooCatType*)catIt->Next() ){
856  TString catName = t->GetName();
857  if(catName.Contains("NotMapped")) continue;
858  catName.ReplaceAll("{","").ReplaceAll("}","").ReplaceAll(";","_&_");
859  makeEfficiencyPlot2D(myEff, *v1, *v2, TString::Format("%s_%s_PLOT_%s",v1->GetName(), v2->GetName(), catName.Data()), catName, effName, "allCats2D", t->getVal());
860  }
861  }
862  }
863  RooMultiCategory allCats1D("allCats1D", "allCats1D", RooArgSet(binCategories1D, mappedCategories));
864  if(allCats1D.numTypes()==0){
865  makeEfficiencyPlot1D(eff, *v1, TString::Format("%s_PLOT", v1->GetName()), "", effName);
866  }else{
867  RooDataSet myEff(eff);
868  myEff.addColumn(allCats1D);
869  std::unique_ptr<TIterator> catIt(allCats1D.typeIterator());
870  for(RooCatType* t = (RooCatType*)catIt->Next(); t!=nullptr; t = (RooCatType*)catIt->Next() ){
871  TString catName = t->GetName();
872  if(catName.Contains("NotMapped")) continue;
873  catName.ReplaceAll("{","").ReplaceAll("}","").ReplaceAll(";","_&_");
874  makeEfficiencyPlot1D(myEff, *v1, TString::Format("%s_PLOT_%s", v1->GetName(), catName.Data()), catName, effName, "allCats1D", t->getVal());
875  }
876  }
877  }
878 }
void makeEfficiencyPlot1D(RooDataSet &eff, RooRealVar &v, const TString &plotName, const TString &plotTitle, const TString &effName, const char *catName=nullptr, int catIndex=-1)
makes the 1D plot
void makeEfficiencyPlot2D(RooDataSet &eff, RooRealVar &v1, RooRealVar &v2, const TString &plotName, const TString &plotTitle, const TString &effName, const char *catName=nullptr, int catIndex=-1)
makes the 2D plot
void TagProbeFitter::saveFitPlot ( RooWorkspace *  w)
protected

saves the fit canvas

Definition at line 722 of file TagProbeFitter.cc.

References svgfig::canvas(), mps_fire::i, ResonanceBuilder::mass, globaldigis_analyze_cfi::Name, and findQualityFiles::v.

722  {
723  // save refferences for convenience
724  RooCategory& efficiencyCategory = *w->cat("_efficiencyCategory_");
725  RooAbsData* dataAll = (binnedFit ? w->data("data_binned") : w->data("data") );
726  RooAbsData* dataPass = dataAll->reduce(Cut("_efficiencyCategory_==_efficiencyCategory_::Passed"));
727  RooAbsData* dataFail = dataAll->reduce(Cut("_efficiencyCategory_==_efficiencyCategory_::Failed"));
728  RooAbsPdf& pdf = *w->pdf("simPdf");
729  std::unique_ptr<RooArgSet> obs(pdf.getObservables(*dataAll));
730  RooRealVar* mass = nullptr;
731  RooLinkedListIter it = obs->iterator();
732  for(RooAbsArg* v = (RooAbsArg*)it.Next(); v!=nullptr; v = (RooAbsArg*)it.Next() ){
733  if(!v->InheritsFrom("RooRealVar")) continue;
734  mass = (RooRealVar*)v;
735  break;
736  }
737  if(!mass) return;
738  // make a 2x2 canvas
739  TCanvas canvas("fit_canvas");
740  canvas.Divide(2,2);
741  vector<RooPlot*> frames;
742  // plot the Passing Probes
743  canvas.cd(1);
744  if (massBins == 0) {
745  frames.push_back(mass->frame(Name("Passing"), Title("Passing Probes")));
746  frames.push_back(mass->frame(Name("Failing"), Title("Failing Probes")));
747  frames.push_back(mass->frame(Name("All"), Title("All Probes")));
748  } else {
749  frames.push_back(mass->frame(Name("Passing"), Title("Passing Probes"), Bins(massBins)));
750  frames.push_back(mass->frame(Name("Failing"), Title("Failing Probes"), Bins(massBins)));
751  frames.push_back(mass->frame(Name("All"), Title("All Probes"), Bins(massBins)));
752  }
753  dataPass->plotOn(frames[0]);
754  pdf.plotOn(frames[0], Slice(efficiencyCategory, "Passed"), ProjWData(*dataPass), LineColor(kGreen));
755  pdf.plotOn(frames[0], Slice(efficiencyCategory, "Passed"), ProjWData(*dataPass), LineColor(kGreen), Components("backgroundPass"), LineStyle(kDashed));
756  frames[0]->Draw();
757  // plot the Failing Probes
758  canvas.cd(2);
759  dataFail->plotOn(frames[1]);
760  pdf.plotOn(frames[1], Slice(efficiencyCategory, "Failed"), ProjWData(*dataFail), LineColor(kRed));
761  pdf.plotOn(frames[1], Slice(efficiencyCategory, "Failed"), ProjWData(*dataFail), LineColor(kRed), Components("backgroundFail"), LineStyle(kDashed));
762  frames[1]->Draw();
763  // plot the All Probes
764  canvas.cd(3);
765  dataAll->plotOn(frames.back());
766  pdf.plotOn(frames.back(), ProjWData(*dataAll), LineColor(kBlue));
767  pdf.plotOn(frames.back(), ProjWData(*dataAll), LineColor(kBlue), Components("backgroundPass,backgroundFail"), LineStyle(kDashed));
768  frames.back()->Draw();
769  // plot the Fit Results
770  canvas.cd(4);
771  frames.push_back(mass->frame(Name("Fit Results"), Title("Fit Results")));
772  pdf.paramOn(frames.back(), dataAll, "", 0, "NELU", 0.1, 0.9, 0.9);
773  // draw only the parameter box not the whole frame
774  frames.back()->findObject(Form("%s_paramBox",pdf.GetName()))->Draw();
775  //save and clean up
776  canvas.Draw();
777  canvas.Write();
778  for (size_t i=0; i<frames.size(); i++) {
779  delete frames[i];
780  }
781  delete dataPass;
782  delete dataFail;
783 }
const double w
Definition: UKUtility.cc:23
int massBins
number of bins to use in mass shape plots; 0 = automatic
int binnedFit
do binned fit; 0 = automatic, 1 = yes, -1 = no. d
def canvas(sub, attr)
Definition: svgfig.py:482
void TagProbeFitter::setBinnedFit ( bool  binned,
int  bins = 0 
)
inline

set if to do a binned fit

Definition at line 48 of file TagProbeFitter.h.

References binnedFit, create_public_pileup_plots::bins, massBins, and setBinsForMassPlots().

Referenced by TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

48 { binnedFit = binned; massBins = bins; }
int massBins
number of bins to use in mass shape plots; 0 = automatic
int binnedFit
do binned fit; 0 = automatic, 1 = yes, -1 = no. d
void TagProbeFitter::setBinsForMassPlots ( int  bins)

set number of bins to use when making the plots; 0 = automatic

Definition at line 140 of file TagProbeFitter.cc.

References create_public_pileup_plots::bins.

Referenced by setBinnedFit(), and TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

140  {
141  massBins = bins;
142 }
int massBins
number of bins to use in mass shape plots; 0 = automatic
void TagProbeFitter::setInitialValues ( RooWorkspace *  w)
protected

sets initial values of the PDF parameters based on the data available in the workspace

Definition at line 685 of file TagProbeFitter.cc.

685  {
686  // calculate initial values
687  double signalEfficiency = w->var("efficiency")->getVal();
688  double signalFractionInPassing = w->var("signalFractionInPassing")->getVal();
689  double totPassing = w->data("data")->sumEntries("_efficiencyCategory_==_efficiencyCategory_::Passed");
690  double totFailinging = w->data("data")->sumEntries("_efficiencyCategory_==_efficiencyCategory_::Failed");
691  double numSignalAll = totPassing*signalFractionInPassing/signalEfficiency;
692 
693  //std::cout << "Number of probes: " << totPassing+totFailinging << std::endl;
694 
695  // check if this value is inconsistent on the failing side
696  if(numSignalAll*(1-signalEfficiency) > totFailinging)
697  numSignalAll = totFailinging;
698  // now set the values
699  w->var("numTot")->setVal(totPassing+totFailinging);
700  w->var("numTot")->setMax(2.0*(totPassing+totFailinging)+10); //wiggle room in case of 0 events in bin
701 
702  if (totPassing == 0) {
703  w->var("efficiency")->setVal(0.0);
704  w->var("efficiency")->setAsymError(0,1);
705  w->var("efficiency")->setConstant(false);
706  } else if (totFailinging == 0) {
707  w->var("efficiency")->setVal(1.0);
708  w->var("efficiency")->setAsymError(-1,0);
709  w->var("efficiency")->setConstant(false);
710  } else {
711  w->var("efficiency")->setConstant(false);
712  }
713 
714  // if signal fraction is 1 then set the number of background events to 0.
715  //RooRealVar* fBkgPass = w->var("numBackgroundPass");
716  //if(signalFractionInPassing==1.0) { fBkgPass->setVal(0.0); fBkgPass->setConstant(true); }
717 
718  // save initial state for reference
719  w->saveSnapshot("initialState",w->components());
720 }
const double w
Definition: UKUtility.cc:23
void TagProbeFitter::setQuiet ( bool  quiet_ = true)

suppress most of the output from RooFit and Minuit

Definition at line 93 of file TagProbeFitter.cc.

References dqm::qstatus::ERROR, instance, and dqm::qstatus::WARNING.

Referenced by setSaveDistributionsPlot(), and TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

93  {
94  quiet = quiet_;
95  if (quiet) {
96  RooMsgService::instance().setGlobalKillBelow(RooFit::ERROR);
97  } else {
98  RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING);
99  }
100 }
static PFTauRenderPlugin instance
static const int WARNING
bool quiet
suppress most printout
static const int ERROR
void TagProbeFitter::setSaveDistributionsPlot ( bool  saveDistributionsPlot_)
inline

Definition at line 54 of file TagProbeFitter.h.

References doSaveDistributionsPlot, setQuiet(), setSplitMode(), setWeightVar(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

54 { doSaveDistributionsPlot = saveDistributionsPlot_; }
bool doSaveDistributionsPlot
save distribution plots
void TagProbeFitter::setSplitMode ( unsigned int  nevents)

split mode - use it for very large input files (slower that non-split mode, which is the default) 0 - import input TTree as a whole (non-split mode) non-zero value - use split reading mode and read specified number of events for each iteration

Definition at line 102 of file TagProbeFitter.cc.

Referenced by setSaveDistributionsPlot(), and TagProbeFitTreeAnalyzer::TagProbeFitTreeAnalyzer().

102  {
103  split_mode = nevents;
104 }
unsigned int split_mode
void TagProbeFitter::setWeightVar ( const std::string &  weight)
void TagProbeFitter::varFixer ( RooWorkspace *  w,
bool  fix 
)
protected

fix or release variables selected by user

Definition at line 953 of file TagProbeFitter.cc.

References gather_cfg::cout.

953  {
954  std::vector<std::string>::const_iterator it;
955  for(it=fixVars.begin(); it<fixVars.end(); it++){
956  if(w->var((*it).c_str()))
957  w->var((*it).c_str())->setAttribute("Constant",fix);
958  else{
959  std::cout << "TagProbeFitter: " << "Can't find a variable to fix: " << *it;
960  }
961  }
962 }
const double w
Definition: UKUtility.cc:23
std::vector< std::string > fixVars
list of variables fo fix (see below)
void TagProbeFitter::varRestorer ( RooWorkspace *  w)
protected

restore variables's values for fit starting point

Definition at line 976 of file TagProbeFitter.cc.

References gather_cfg::cout, and mps_fire::i.

976  {
977  if(fixVarValues.size()==fixVars.size())
978  for(unsigned int i=0; i< fixVars.size(); i++){
979  std::cout << "setting variable " << fixVars[i].c_str() << std::endl;
980  w->var(fixVars[i].c_str())->setVal(fixVarValues[i]);
981  }
982  else{
983  std::cout << "fixVars and fixVarValues are not of the same size!" << std::endl;
984  }
985 }
const double w
Definition: UKUtility.cc:23
std::vector< std::string > fixVars
list of variables fo fix (see below)
std::vector< double > fixVarValues
void TagProbeFitter::varSaver ( RooWorkspace *  w)
protected

store values in the vector

Definition at line 964 of file TagProbeFitter.cc.

References gather_cfg::cout.

964  {
965  if(!fixVarValues.empty()){
966  std::cout << "attempt to save variables more than once!" << std::endl;
967  return;
968  }
969  std::vector<std::string>::const_iterator it;
970  for(it=fixVars.begin(); it<fixVars.end(); it++){
971  fixVarValues.push_back(w->var((*it).c_str())->getVal());
972  }
973 
974 }
const double w
Definition: UKUtility.cc:23
std::vector< std::string > fixVars
list of variables fo fix (see below)
std::vector< double > fixVarValues

Member Data Documentation

int TagProbeFitter::binnedFit
protected

do binned fit; 0 = automatic, 1 = yes, -1 = no. d

Definition at line 87 of file TagProbeFitter.h.

Referenced by setBinnedFit().

bool TagProbeFitter::doSaveDistributionsPlot
protected

save distribution plots

Definition at line 81 of file TagProbeFitter.h.

Referenced by setSaveDistributionsPlot().

std::vector<std::pair<std::pair<std::string,std::string>, std::pair<std::string, std::vector<std::string> > > > TagProbeFitter::expressionVars
protected

expressions computed almost on the fly

Definition at line 103 of file TagProbeFitter.h.

std::vector<std::string> TagProbeFitter::fixVars
protected

list of variables fo fix (see below)

Definition at line 110 of file TagProbeFitter.h.

std::vector<double> TagProbeFitter::fixVarValues
protected

Definition at line 111 of file TagProbeFitter.h.

bool TagProbeFitter::floatShapeParameters
protected

release some variables before the fit in each bin if set to "false" will fit all dataset to get values of specified variables and then fit all bins having them fixed if set to "true" (default) will not fit all dataset, just each bin with fixed and then released variables

Definition at line 116 of file TagProbeFitter.h.

TChain* TagProbeFitter::inputTree
protected

pointer to the input TTree Chain of data

Definition at line 69 of file TagProbeFitter.h.

int TagProbeFitter::massBins
protected

number of bins to use in mass shape plots; 0 = automatic

Definition at line 90 of file TagProbeFitter.h.

Referenced by setBinnedFit().

int TagProbeFitter::numCPU
protected

number of CPUs to use for the fit

Definition at line 78 of file TagProbeFitter.h.

TDirectory* TagProbeFitter::outputDirectory
protected

pointer to the TDirectory in the output file that is the root directory for this fitter

Definition at line 75 of file TagProbeFitter.h.

TFile* TagProbeFitter::outputFile
protected

pointer to the output file

Definition at line 72 of file TagProbeFitter.h.

RooWorkspace TagProbeFitter::parameterParser
protected

a RooWorkspace object to parse input parameters with ".factory()"

Definition at line 119 of file TagProbeFitter.h.

std::map<std::string, std::vector<std::string> > TagProbeFitter::pdfs
protected

the map of pdf names to the vector of commands to build the pdf

Definition at line 93 of file TagProbeFitter.h.

bool TagProbeFitter::quiet
protected

suppress most printout

Definition at line 122 of file TagProbeFitter.h.

bool TagProbeFitter::saveWorkspace
protected

the default option wether to save the workspace for each bin

Definition at line 84 of file TagProbeFitter.h.

unsigned int TagProbeFitter::split_mode
protected

split mode - use it for very large input files (slower that non-split mode, which is the default) 0 - import input TTree as a whole (non-split mode) non-zero value - use split reading mode and read specified number of events for each iteration

Definition at line 127 of file TagProbeFitter.h.

std::vector<std::pair<std::pair<std::string,std::string>, std::pair<std::string, double> > > TagProbeFitter::thresholdCategories
protected

Definition at line 107 of file TagProbeFitter.h.

RooArgSet TagProbeFitter::variables
protected

the set of variables describing the data in the input TTree

Definition at line 96 of file TagProbeFitter.h.

std::string TagProbeFitter::weightVar
protected

weight variable (or empy string for no weights)

Definition at line 99 of file TagProbeFitter.h.