CMS 3D CMS Logo

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(const std::map<std::string,float>& splitFractions,
25  bool splitPdf) {
26 // std::map<std::string,float>splitFractions = _splitFractions;
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  snprintf(buffer, 100, "%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  snprintf(buffer, 100, "%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  snprintf(buffer, 100, "%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==ruleItr->second) {
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 const& gsfClass,
86  bool normalized) const {
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  // using thePdf->normalization() neglects the overflows... calculating it manually.
103  // prob=thePdf->value(x)/thePdf->normalization();
104  prob=thePdf->value(x)/normalization(thePdf);
105  else
106  prob=thePdf->value(x);
107 
108  edm::LogInfo("LikelihoodPdf") << "sanity check: PDF name = " << _name
109  << " for species = " << _species
110  << " for class = " << gsfClass
111  << " bin content = " << thePdf->binContent(thePdf->findBin(x))
112  << " normalization (std) = " << thePdf->normalization()
113  << " normalization (manual) = " << normalization(thePdf)
114  << " prob = " << prob;
115  edm::LogInfo("LikelihoodPdf") << "From likelihood with ecalsubdet = " << _ecalsubdet
116  << " ptbin = " << _ptbin;
117 
118 
119  return prob;
120 }
121 
122 // Histogram::normalization() gives the integral excluding the over-underflow...
123 float
125  int nBins = thePdf->numberOfBins();
126  float sum=0.;
127  for(int i=0; i<=nBins+1; i++) {
128  sum += thePdf->binContent(i);
129  }
130  return sum;
131 }
std::map< std::string, const PhysicsTools::Calibration::HistogramF * > _splitPdf
Definition: LikelihoodPdf.h:47
virtual ~LikelihoodPdf()
std::string _species
Definition: LikelihoodPdf.h:43
Value_t binContent(int bin) const
Definition: Histogram.h:69
void initFromDB(const ElectronLikelihoodCalibration *calibration)
initialize PDFs from CondDB
void split(const std::map< std::string, float > &splitFractions, bool splitPdf=false)
std::string _name
Definition: LikelihoodPdf.h:42
float normalization(const PhysicsTools::Calibration::HistogramF *thePdf) const
Value_t value(Axis_t x) const
Definition: Histogram.h:70
float getVal(float x, std::string const &catName="NOSPLIT", bool normalized=true) const
get Value of pdf at point x for class catName
std::map< std::string, std::string > _splitRule
Definition: LikelihoodPdf.h:48