CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TagProbeFitTreeAnalyzer.cc
Go to the documentation of this file.
8 
10 
11 using namespace std;
12 using namespace edm;
13 
15  public:
18  virtual void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override {};
19  virtual void endRun(const edm::Run &run, const edm::EventSetup &setup) override{};
20  void calculateEfficiency(string name, const edm::ParameterSet& pset);
21  private:
23 };
24 
26  fitter( pset.getParameter<vector<string> >("InputFileNames"),
27  pset.getParameter<string>("InputDirectoryName"),
28  pset.getParameter<string>("InputTreeName"),
29  pset.getParameter<string>("OutputFileName"),
30  pset.existsAs<unsigned int>("NumCPU")?pset.getParameter<unsigned int>("NumCPU"):1,
31  pset.existsAs<bool>("SaveWorkspace")?pset.getParameter<bool>("SaveWorkspace"):false,
32  pset.existsAs<bool>("floatShapeParameters")?pset.getParameter<bool>("floatShapeParameters"):true,
33  pset.existsAs<vector<string> >("fixVars")?pset.getParameter<vector<string> >("fixVars"):vector<string>()
34  )
35 {
36  fitter.setQuiet(pset.getUntrackedParameter("Quiet",false));
37 
38  if (pset.existsAs<bool>("binnedFit")) {
39  bool binned = pset.getParameter<bool>("binnedFit");
40  fitter.setBinnedFit(binned, binned ? pset.getParameter<uint32_t>("binsForFit") : 0);
41  } else if (pset.existsAs<uint32_t>("binsForMassPlots")) {
42  fitter.setBinsForMassPlots(pset.getParameter<uint32_t>("binsForMassPlots"));
43  }
44 
45  if (pset.existsAs<bool>("saveDistributionsPlot")) {
46  fitter.setSaveDistributionsPlot(pset.getParameter<bool>("saveDistributionsPlot"));
47  }
48  if (pset.existsAs<std::string>("WeightVariable")) {
49  fitter.setWeightVar(pset.getParameter<std::string>("WeightVariable"));
50  }
51  const ParameterSet variables = pset.getParameter<ParameterSet>("Variables");
52  vector<string> variableNames = variables.getParameterNamesForType<vector<string> >();
53  for (vector<string>::const_iterator name = variableNames.begin(); name != variableNames.end(); name++) {
54  vector<string> var = variables.getParameter<vector<string> >(*name);
55  double lo, hi;
56  if(var.size()>=4 && !(istringstream(var[1])>>lo).fail() && !(istringstream(var[2])>>hi).fail()){
57  fitter.addVariable(*name, var[0], lo, hi, var[3]);
58  }else{
59  LogError("TagProbeFitTreeAnalyzer")<<"Could not create variable: "<<*name<<
60  ". Example: pt = cms.vstring(\"Probe pT\", \"1.0\", \"100.0\", \"GeV/c\") ";
61  }
62  }
63 
64  const ParameterSet categories = pset.getParameter<ParameterSet>("Categories");
65  vector<string> categoryNames = categories.getParameterNamesForType<vector<string> >();
66  for (vector<string>::const_iterator name = categoryNames.begin(); name != categoryNames.end(); name++) {
67  vector<string> cat = categories.getParameter<vector<string> >(*name);
68  if(cat.size()==2){
69  fitter.addCategory(*name, cat[0], cat[1]);
70  }else{
71  LogError("TagProbeFitTreeAnalyzer")<<"Could not create category: "<<*name<<
72  ". Example: mcTrue = cms.vstring(\"MC True\", \"dummy[true=1,false=0]\") ";
73  }
74  }
75 
76  if (pset.existsAs<ParameterSet>("Expressions")) {
77  const ParameterSet exprs = pset.getParameter<ParameterSet>("Expressions");
78  vector<string> exprNames = exprs.getParameterNamesForType<vector<string> >();
79  for (vector<string>::const_iterator name = exprNames.begin(); name != exprNames.end(); name++) {
80  vector<string> expr = exprs.getParameter<vector<string> >(*name);
81  if(expr.size()>=2){
82  vector<string> args(expr.begin()+2,expr.end());
83  fitter.addExpression(*name, expr[0], expr[1], args);
84  }else{
85  LogError("TagProbeFitTreeAnalyzer")<<"Could not create expr: "<<*name<<
86  ". Example: qop = cms.vstring(\"qOverP\", \"charge/p\", \"charge\", \"p\") ";
87  }
88  }
89  }
90 
91 
92  if (pset.existsAs<ParameterSet>("Cuts")) {
93  const ParameterSet cuts = pset.getParameter<ParameterSet>("Cuts");
94  vector<string> cutNames = cuts.getParameterNamesForType<vector<string> >();
95  for (vector<string>::const_iterator name = cutNames.begin(); name != cutNames.end(); name++) {
96  vector<string> cat = cuts.getParameter<vector<string> >(*name);
97  if(cat.size()==3){
98  fitter.addThresholdCategory(*name, cat[0], cat[1], atof(cat[2].c_str()));
99  }else{
100  LogError("TagProbeFitTreeAnalyzer")<<"Could not create cut: "<<*name<<
101  ". Example: matched = cms.vstring(\"Matched\", \"deltaR\", \"0.5\") ";
102  }
103  }
104  }
105 
106  if(pset.existsAs<ParameterSet>("PDFs")){
107  const ParameterSet pdfs = pset.getParameter<ParameterSet>("PDFs");
108  vector<string> pdfNames = pdfs.getParameterNamesForType<vector<string> >();
109  for (vector<string>::const_iterator name = pdfNames.begin(); name != pdfNames.end(); name++) {
110  vector<string> pdf = pdfs.getParameter<vector<string> >(*name);
111  fitter.addPdf(*name, pdf);
112  }
113  }
114 
115  const ParameterSet efficiencies = pset.getParameter<ParameterSet>("Efficiencies");
116  vector<string> efficiencyNames = efficiencies.getParameterNamesForType<ParameterSet>();
117  for (vector<string>::const_iterator name = efficiencyNames.begin(); name != efficiencyNames.end(); name++) {
118  try {
120  } catch (std::exception &ex) {
121  throw cms::Exception("Error", ex.what());
122  }
123  }
124 }
125 
127  vector<string> effCatState = pset.getParameter<vector<string> >("EfficiencyCategoryAndState");
128  if(effCatState.empty() || (effCatState.size() % 2 == 1)){
129  cout<<"EfficiencyCategoryAndState must be a even-sized list of category names and states of that category (cat1, state1, cat2, state2, ...)."<<endl;
130  exit(1);
131  }
132 
133  vector<string> unbinnedVariables;
134  if(pset.existsAs<vector<string> >("UnbinnedVariables")){
135  unbinnedVariables = pset.getParameter<vector<string> >("UnbinnedVariables");
136  }
137 
138  const ParameterSet binVars = pset.getParameter<ParameterSet>("BinnedVariables");
139  map<string, vector<double> >binnedVariables;
140  vector<string> variableNames = binVars.getParameterNamesForType<vector<double> >();
141  for (vector<string>::const_iterator var = variableNames.begin(); var != variableNames.end(); var++) {
142  vector<double> binning = binVars.getParameter<vector<double> >(*var);
143  binnedVariables[*var] = binning;
144  }
145  map<string, vector<string> >mappedCategories;
146  vector<string> categoryNames = binVars.getParameterNamesForType<vector<string> >();
147  for (vector<string>::const_iterator var = categoryNames.begin(); var != categoryNames.end(); var++) {
148  vector<string> map = binVars.getParameter<vector<string> >(*var);
149  mappedCategories[*var] = map;
150  }
151 
152  vector<string> binToPDFmap;
153  if(pset.existsAs<vector<string> >("BinToPDFmap")){
154  binToPDFmap = pset.getParameter<vector<string> >("BinToPDFmap");
155  }
156  if((binToPDFmap.size() > 0) && (binToPDFmap.size()%2 == 0)){
157  cout<<"BinToPDFmap must have odd size, first string is the default, followed by binRegExp - PDFname pairs!"<<endl;
158  exit(2);
159  }
160 
161  vector<string> effCats, effStates;
162  for (size_t i = 0, n = effCatState.size()/2; i < n; ++i) {
163  effCats.push_back(effCatState[2*i]);
164  effStates.push_back(effCatState[2*i+1]);
165  }
166 
167  fitter.calculateEfficiency(name, effCats, effStates, unbinnedVariables, binnedVariables, mappedCategories, binToPDFmap);
168 }
169 
170 //define this as a plug-in
172 
void setSaveDistributionsPlot(bool saveDistributionsPlot_)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
void addPdf(std::string pdfName, std::vector< std::string > &pdfCommands)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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;...
void calculateEfficiency(string name, const edm::ParameterSet &pset)
bool addThresholdCategory(std::string categoryName, std::string title, std::string varName, double cutValue)
adds a new category based on a cut
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
void setQuiet(bool quiet_=true)
suppress most of the output from RooFit and Minuit
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
TagProbeFitTreeAnalyzer(const edm::ParameterSet &pset)
def cat
Definition: eostools.py:400
virtual void endRun(const edm::Run &run, const edm::EventSetup &setup) override
void setBinnedFit(bool binned, int bins=0)
set if to do a binned fit
virtual void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void setBinsForMassPlots(int bins)
set number of bins to use when making the plots; 0 = automatic
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
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 setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:43