CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LikelihoodPdf.cc
Go to the documentation of this file.
4 #include <iostream>
5 
6 
7 
8 
9 LikelihoodPdf::LikelihoodPdf(const char* name, const char* species, int ecalsubdet, int ptbin) {
10  _name = std::string(name);
11  _species = std::string(species);
12  _ecalsubdet = ecalsubdet;
13  _ptbin = ptbin;
14 }
15 
16 
17 
19 }
20 
21 
22 
23 void
24 LikelihoodPdf::split(std::map<std::string,float> splitFractions,
25  bool splitPdf) {
26 
27  char buffer[100];
30  if(splitFractions.size()>0 && splitPdf) {
31  std::map<std::string,float>::const_iterator splitCatItr;
32  for(splitCatItr=splitFractions.begin();splitCatItr!=splitFractions.end();splitCatItr++) {
33  sprintf(buffer,"%s_%s_subdet%d_ptbin%d_%s",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin,splitCatItr->first.c_str());
34  std::string totPdfName = std::string(buffer);
35  _splitRule.insert( std::make_pair(splitCatItr->first,totPdfName) );
36  }
37  }
38 
40  else if(splitFractions.size()>0) {
41  std::map<std::string,float>::const_iterator splitCatItr;
42  for(splitCatItr=splitFractions.begin();splitCatItr!=splitFractions.end();splitCatItr++) {
43  sprintf(buffer,"%s_%s_subdet%d_ptbin%d",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin);
44  std::string totPdfName = std::string(buffer);
45  _splitRule.insert( std::make_pair(splitCatItr->first,totPdfName) );
46  }
47  }
48 
50  else {
51  sprintf(buffer,"%s_%s_subdet%d_ptbin%d",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin);
52  std::string totPdfName = std::string(buffer);
53  _splitRule.insert( std::make_pair("NOSPLIT",totPdfName) );
54  }
55 }
56 
57 
58 
59 void
61 
62  std::map<std::string,std::string>::const_iterator ruleItr;
63  for(ruleItr=_splitRule.begin();ruleItr!=_splitRule.end();ruleItr++) {
64  // look for the requested PDF in the CondDB
65  std::vector<ElectronLikelihoodCalibration::Entry>::const_iterator entryItr;
66  bool foundPdf=false;
67  for(entryItr=calibration->data.begin(); entryItr!=calibration->data.end(); entryItr++) {
68  if(entryItr->category.label.compare(ruleItr->second)==0) {
69  const PhysicsTools::Calibration::HistogramF *histo = &(entryItr->histogram);
70  _splitPdf.insert( std::make_pair(ruleItr->first,histo) );
71  foundPdf=true;
72  }
73  }
74  if(!foundPdf) {
75  throw cms::Exception("LikelihoodPdf") << "The pdf requested: " << _name
76  << " for species: " << _species
77  << " is not present in the Conditions DB!";
78  }
79  }
80 }
81 
82 
83 
84 float
85 LikelihoodPdf::getVal(float x, std::string gsfClass,
86  bool normalized) {
88  if(_splitPdf.size()>1) {
89  edm::LogInfo("LikelihoodPdf") << "The PDF " << _name
90  << " is SPLITTED by category " << gsfClass;
91  thePdf=_splitPdf.find(gsfClass)->second;
92  }
93  else {
94  edm::LogInfo("LikelihoodPdf") << "The PDF " << _name
95  << " is UNSPLITTED";
96  thePdf=_splitPdf.find("NOSPLIT")->second;
97  }
98 
99  float prob=-1;
100 
101  if(normalized)
102  prob=thePdf->value(x)/thePdf->normalization();
103  else
104  prob=thePdf->value(x);
105 
106  edm::LogInfo("LikelihoodPdf") << "sanity check: PDF name = " << _name
107  << " for species = " << _species
108  << " for class = " << gsfClass
109  << " bin content = " << thePdf->binContent(thePdf->findBin(x))
110  << " normalization = " << thePdf->normalization()
111  << " prob = " << prob;
112  edm::LogInfo("LikelihoodPdf") << "From likelihood with ecalsubdet = " << _ecalsubdet
113  << " ptbin = " << _ptbin;
114 
115 
116  return prob;
117 }
std::map< std::string, const PhysicsTools::Calibration::HistogramF * > _splitPdf
Definition: LikelihoodPdf.h:45
tuple histo
Definition: trackerHits.py:12
virtual ~LikelihoodPdf()
std::string _species
Definition: LikelihoodPdf.h:41
Value_t binContent(int bin) const
Definition: Histogram.h:61
void initFromDB(const ElectronLikelihoodCalibration *calibration)
initialize PDFs from CondDB
void split(std::map< std::string, float > splitFractions, bool splitPdf=false)
std::string _name
Definition: LikelihoodPdf.h:40
float getVal(float x, std::string catName="NOSPLIT", bool normalized=true)
get Value of pdf at point x for class catName
Value_t value(Axis_t x) const
Definition: Histogram.h:62
std::map< std::string, std::string > _splitRule
Definition: LikelihoodPdf.h:46