CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TagProbeFitter.h
Go to the documentation of this file.
1 #ifndef TagProbeFitter_h
2 #define TagProbeFitter_h
3 
4 #include "TFile.h"
5 #include "TChain.h"
6 #include "TGraphAsymmErrors.h"
7 #include "RooWorkspace.h"
8 #include "RooFitResult.h"
9 #include "RooDataSet.h"
10 
12  public:
14  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>() );
15 
18 
20  bool addVariable(std::string variableName, std::string title, double low, double hi, std::string units);
21 
23  bool addCategory(std::string categoryName, std::string title, std::string expression);
24 
26  bool addExpression(std::string expressionName, std::string title, std::string expression, const std::vector<std::string>& arguments);
27 
29  bool addThresholdCategory(std::string categoryName, std::string title, std::string varName, double cutValue);
30 
33  void addPdf(std::string pdfName, std::vector<std::string>& pdfCommands);
34 
36  void addFixedVariavles(const std::vector<std::string>&);
37 
39  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) {
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  }
44 
45  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);
46 
48  void setBinnedFit(bool binned, int bins=0) { binnedFit = binned; massBins = bins; }
49 
51  void setBinsForMassPlots(int bins) ;
52 
54  void setSaveDistributionsPlot(bool saveDistributionsPlot_) { doSaveDistributionsPlot = saveDistributionsPlot_; }
55 
57  void setWeightVar(const std::string &weight);
58 
60  void setQuiet(bool quiet_=true);
61 
62  protected:
64  TChain* inputTree;
65 
67  TFile* outputFile;
68 
70  TDirectory* outputDirectory;
71 
73  int numCPU;
74 
77 
80 
82  int binnedFit;
83 
85  int massBins;
86 
88  std::map<std::string, std::vector<std::string> > pdfs;
89 
91  RooArgSet variables;
92 
95 
97  //RooArgSet expressionVars;
98  std::vector<std::pair<std::pair<std::string,std::string>, std::pair<std::string, std::vector<std::string> > > > expressionVars;
99 
100  // Threshold categories have to be created at the last minute
101  // so we store just the info about them
102  std::vector<std::pair<std::pair<std::string,std::string>, std::pair<std::string, double> > > thresholdCategories;
103 
105  std::vector<std::string> fixVars;
106  std::vector<double> fixVarValues;
107 
112 
114  RooWorkspace parameterParser;
115 
117  bool quiet;
118 
120  void varFixer(RooWorkspace* w, bool fix);
122  void varSaver(RooWorkspace* w);
124  void varRestorer(RooWorkspace* w);
125 
127  void doFitEfficiency(RooWorkspace* w, std::string pdfName, RooRealVar& efficiency);
128 
130  void doSBSEfficiency(RooWorkspace* w, RooRealVar& efficiency);
131 
133  void doCntEfficiency(RooWorkspace* w, RooRealVar& efficiency);
134 
136  void createPdf(RooWorkspace* w, std::vector<std::string>& pdfCommands);
137 
139  void setInitialValues(RooWorkspace* w);
140 
142  void saveFitPlot(RooWorkspace* w);
143 
145  void saveDistributionsPlot(RooWorkspace* w);
146 
148  void saveEfficiencyPlots(RooDataSet& eff, const TString& effName, RooArgSet& binnedVariables, RooArgSet& mappedCategories);
149 
151  void makeEfficiencyPlot1D(RooDataSet& eff, RooRealVar& v, const TString& plotName, const TString& plotTitle, const TString& effName, const char *catName = 0, int catIndex = -1);
152 
154  void makeEfficiencyPlot2D(RooDataSet& eff, RooRealVar& v1, RooRealVar& v2, const TString& plotName, const TString& plotTitle, const TString& effName, const char *catName = 0, int catIndex = -1);
155 
156 };
157 
158 #endif //TagProbeFitter_h
void setSaveDistributionsPlot(bool saveDistributionsPlot_)
void doCntEfficiency(RooWorkspace *w, RooRealVar &efficiency)
calculate the efficiecny by counting in the dataset found in the workspace
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
tuple inputFileNames
Definition: mvaPFMET_cff.py:73
const double w
Definition: UKUtility.cc:23
void addPdf(std::string pdfName, std::vector< std::string > &pdfCommands)
void setWeightVar(const std::string &weight)
set a variable to be used as weight for a dataset. empty string means no weights. ...
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 &quot;...
bool addThresholdCategory(std::string categoryName, std::string title, std::string varName, double cutValue)
adds a new category based on a cut
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
void setQuiet(bool quiet_=true)
suppress most of the output from RooFit and Minuit
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 sp...
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
void saveEfficiencyPlots(RooDataSet &eff, const TString &effName, RooArgSet &binnedVariables, RooArgSet &mappedCategories)
saves the efficiency plots
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 makeEfficiencyPlot2D(RooDataSet &eff, RooRealVar &v1, RooRealVar &v2, const TString &plotName, const TString &plotTitle, const TString &effName, const char *catName=0, int catIndex=-1)
makes the 2D plot
void setBinnedFit(bool binned, int bins=0)
set if to do a binned fit
void varRestorer(RooWorkspace *w)
restore variables&#39;s values for fit starting point
void saveFitPlot(RooWorkspace *w)
saves the fit canvas
~TagProbeFitter()
destructor closes the files
bool saveWorkspace
the default option wether to save the workspace for each bin
bool doSaveDistributionsPlot
save distribution plots
RooWorkspace parameterParser
a RooWorkspace object to parse input parameters with &quot;.factory()&quot;
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
int massBins
number of bins to use in mass shape plots; 0 = automatic
void saveDistributionsPlot(RooWorkspace *w)
saves the distributions canvas
bool quiet
suppress most printout
std::vector< std::pair< std::pair< std::string, std::string >, std::pair< std::string, double > > > thresholdCategories
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
TString units(TString variable, Char_t axis)
TFile * outputFile
pointer to the output file
void setBinsForMassPlots(int bins)
set number of bins to use when making the plots; 0 = automatic
void doSBSEfficiency(RooWorkspace *w, RooRealVar &efficiency)
calculate the efficiecny with side band substraction in the dataset found in the workspace ...
void createPdf(RooWorkspace *w, std::vector< std::string > &pdfCommands)
creates the simultaneous PDF in the workspace according to the &quot;pdfCommands&quot;
void doFitEfficiency(RooWorkspace *w, std::string pdfName, RooRealVar &efficiency)
calculate the efficiecny with a simulataneous maximum likelihood fit in the dataset found in the work...
TDirectory * outputDirectory
pointer to the TDirectory in the output file that is the root directory for this fitter ...
RooArgSet variables
the set of variables describing the data in the input TTree
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; &quot;expression&quot; is...
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
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...
void makeEfficiencyPlot1D(RooDataSet &eff, RooRealVar &v, const TString &plotName, const TString &plotTitle, const TString &effName, const char *catName=0, int catIndex=-1)
makes the 1D plot