CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEgamma/ElectronIdentification/src/LikelihoodPdf.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/ElectronIdentification/interface/LikelihoodPdf.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 #include <iostream>
00005 
00006 
00007 
00008 
00009 LikelihoodPdf::LikelihoodPdf(const char* name, const char* species, int ecalsubdet, int ptbin) {
00010   _name = std::string(name);
00011   _species = std::string(species);
00012   _ecalsubdet = ecalsubdet;
00013   _ptbin = ptbin;
00014 }
00015 
00016 
00017 
00018 LikelihoodPdf::~LikelihoodPdf() {
00019 }
00020 
00021 
00022 
00023 void 
00024 LikelihoodPdf::split(std::map<std::string,float> splitFractions, 
00025                      bool splitPdf) {
00026 
00027   char buffer[100];
00030   if(splitFractions.size()>0 && splitPdf) {
00031     std::map<std::string,float>::const_iterator splitCatItr;
00032     for(splitCatItr=splitFractions.begin();splitCatItr!=splitFractions.end();splitCatItr++) {
00033       sprintf(buffer,"%s_%s_subdet%d_ptbin%d_%s",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin,splitCatItr->first.c_str());
00034       std::string totPdfName = std::string(buffer);
00035       _splitRule.insert( std::make_pair(splitCatItr->first,totPdfName) );
00036     }
00037   }
00038 
00040   else if(splitFractions.size()>0) {
00041     std::map<std::string,float>::const_iterator splitCatItr;
00042     for(splitCatItr=splitFractions.begin();splitCatItr!=splitFractions.end();splitCatItr++) {
00043       sprintf(buffer,"%s_%s_subdet%d_ptbin%d",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin);
00044       std::string totPdfName = std::string(buffer);
00045       _splitRule.insert( std::make_pair(splitCatItr->first,totPdfName) );
00046     }
00047   }
00048 
00050   else {
00051       sprintf(buffer,"%s_%s_subdet%d_ptbin%d",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin);
00052       std::string totPdfName = std::string(buffer);
00053       _splitRule.insert( std::make_pair("NOSPLIT",totPdfName) );
00054   }
00055 }
00056 
00057 
00058 
00059 void 
00060 LikelihoodPdf::initFromDB(const ElectronLikelihoodCalibration *calibration) {
00061 
00062   std::map<std::string,std::string>::const_iterator ruleItr;
00063   for(ruleItr=_splitRule.begin();ruleItr!=_splitRule.end();ruleItr++) {
00064     // look for the requested PDF in the CondDB
00065     std::vector<ElectronLikelihoodCalibration::Entry>::const_iterator entryItr;
00066     bool foundPdf=false;
00067     for(entryItr=calibration->data.begin(); entryItr!=calibration->data.end(); entryItr++) {
00068       if(entryItr->category.label.compare(ruleItr->second)==0) { 
00069         const PhysicsTools::Calibration::HistogramF *histo = &(entryItr->histogram);
00070         _splitPdf.insert( std::make_pair(ruleItr->first,histo) );
00071         foundPdf=true;
00072       }
00073     }
00074     if(!foundPdf) {
00075       throw cms::Exception("LikelihoodPdf") << "The pdf requested: " << _name
00076                                             << " for species: " << _species
00077                                             << " is not present in the Conditions DB!";
00078     }
00079   }
00080 }
00081 
00082 
00083 
00084 float 
00085 LikelihoodPdf::getVal(float x, std::string gsfClass, 
00086                       bool normalized) {
00087   const PhysicsTools::Calibration::HistogramF *thePdf=0;
00088   if(_splitPdf.size()>1) {
00089     edm::LogInfo("LikelihoodPdf") << "The PDF " << _name
00090                                   << " is SPLITTED by category " << gsfClass;
00091     thePdf=_splitPdf.find(gsfClass)->second;
00092   }
00093   else {
00094     edm::LogInfo("LikelihoodPdf") << "The PDF " << _name
00095                                   << " is UNSPLITTED";
00096     thePdf=_splitPdf.find("NOSPLIT")->second;
00097   }
00098   
00099   float prob=-1;
00100 
00101   if(normalized)
00102     prob=thePdf->value(x)/thePdf->normalization();
00103   else
00104     prob=thePdf->value(x);
00105 
00106   edm::LogInfo("LikelihoodPdf") << "sanity check: PDF name = " << _name
00107                                 << " for species = " << _species
00108                                 << " for class = " << gsfClass 
00109                                 << " bin content = " << thePdf->binContent(thePdf->findBin(x))
00110                                 << " normalization = " << thePdf->normalization()
00111                                 << " prob = " << prob;
00112   edm::LogInfo("LikelihoodPdf") << "From likelihood with ecalsubdet = " << _ecalsubdet
00113                                 << " ptbin = " << _ptbin;
00114  
00115 
00116   return prob;
00117 }