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(std::vector<std::string> inputFileNames, std::string inputDirectoryName, std::string inputTreeName, std::string outputFileName, int numCPU = 1, bool saveWorkspace_ = false, bool floatShapeParameters = true, 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, 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(std::vector<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, std::vector<std::string> efficiencyCategories, 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 setWeightVar(const std::string &weight);
55 
57  void setQuiet(bool quiet_=true);
58 
59  protected:
61  TChain* inputTree;
62 
64  TFile* outputFile;
65 
67  TDirectory* outputDirectory;
68 
70  int numCPU;
71 
74 
76  int binnedFit;
77 
79  int massBins;
80 
82  std::map<std::string, std::vector<std::string> > pdfs;
83 
85  RooArgSet variables;
86 
88  std::string weightVar;
89 
91  //RooArgSet expressionVars;
92  std::vector<std::pair<std::pair<std::string,std::string>, std::pair<std::string, std::vector<std::string> > > > expressionVars;
93 
94  // Threshold categories have to be created at the last minute
95  // so we store just the info about them
96  std::vector<std::pair<std::pair<std::string,std::string>, std::pair<std::string, double> > > thresholdCategories;
97 
99  std::vector<std::string> fixVars;
100  std::vector<double> fixVarValues;
101 
106 
108  RooWorkspace parameterParser;
109 
111  bool quiet;
112 
114  void varFixer(RooWorkspace* w, bool fix);
116  void varSaver(RooWorkspace* w);
118  void varRestorer(RooWorkspace* w);
119 
121  void doFitEfficiency(RooWorkspace* w, std::string pdfName, RooRealVar& efficiency);
122 
124  void doSBSEfficiency(RooWorkspace* w, RooRealVar& efficiency);
125 
127  void doCntEfficiency(RooWorkspace* w, RooRealVar& efficiency);
128 
130  void createPdf(RooWorkspace* w, std::vector<std::string>& pdfCommands);
131 
133  void setInitialValues(RooWorkspace* w);
134 
136  void saveFitPlot(RooWorkspace* w);
137 
139  void saveDistributionsPlot(RooWorkspace* w);
140 
142  void saveEfficiencyPlots(RooDataSet& eff, TString effName, RooArgSet& binnedVariables, RooArgSet& mappedCategories);
143 
145  void makeEfficiencyPlot1D(RooDataSet& eff, RooRealVar& v, TString plotName, TString plotTitle, TString effName);
146 
148  void makeEfficiencyPlot2D(RooDataSet& eff, RooRealVar& v1, RooRealVar& v2, TString plotName, TString plotTitle, TString effName);
149 
150 };
151 
152 #endif //TagProbeFitter_h
void doCntEfficiency(RooWorkspace *w, RooRealVar &efficiency)
calculate the efficiecny by counting in the dataset found in the workspace
bool addExpression(std::string expressionName, std::string title, std::string expression, std::vector< std::string > arguments)
adds a new category based on a cut
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 makeEfficiencyPlot1D(RooDataSet &eff, RooRealVar &v, TString plotName, TString plotTitle, TString effName)
makes the 1D plot
void addPdf(std::string pdfName, std::vector< std::string > &pdfCommands)
TagProbeFitter(std::vector< std::string > inputFileNames, std::string inputDirectoryName, std::string inputTreeName, std::string outputFileName, int numCPU=1, bool saveWorkspace_=false, bool floatShapeParameters=true, std::vector< std::string > fixVars_=std::vector< std::string >())
construct the fitter with the inputFileName, inputDirectoryName, inputTreeName, outputFileName and sp...
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)
void addFixedVariavles(std::vector< string >)
set a list of variables to fix during first fit iteration. If the list is empty, do one iteration...
TChain * inputTree
pointer to the input TTree Chain of data
void setQuiet(bool quiet_=true)
suppress most of the output from RooFit and Minuit
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 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
void saveEfficiencyPlots(RooDataSet &eff, TString effName, RooArgSet &binnedVariables, RooArgSet &mappedCategories)
saves the efficiency 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 makeEfficiencyPlot2D(RooDataSet &eff, RooRealVar &v1, RooRealVar &v2, TString plotName, TString plotTitle, TString effName)
makes the 2D plot
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
mathSSE::Vec4< T > v
T w() const