CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

LikelihoodPdf Class Reference

#include <LikelihoodPdf.h>

List of all members.

Public Member Functions

std::string getName ()
 get PDF name
std::string getSpecies ()
 get PDF species
float getVal (float x, std::string catName="NOSPLIT", bool normalized=true)
 get Value of pdf at point x for class catName
void initFromDB (const ElectronLikelihoodCalibration *calibration)
 initialize PDFs from CondDB
 LikelihoodPdf ()
 LikelihoodPdf (const LikelihoodPdf &pdf)
 LikelihoodPdf (const char *name, const char *species, int ecalsubdet, int ptbin)
void split (std::map< std::string, float > splitFractions, bool splitPdf=false)
virtual ~LikelihoodPdf ()

Private Member Functions

float normalization (const PhysicsTools::Calibration::HistogramF *thePdf)

Private Attributes

int _ecalsubdet
std::string _name
int _ptbin
std::string _species
std::map< std::string, const
PhysicsTools::Calibration::HistogramF * > 
_splitPdf
std::map< std::string,
std::string > 
_splitRule

Detailed Description

Definition at line 12 of file LikelihoodPdf.h.


Constructor & Destructor Documentation

LikelihoodPdf::LikelihoodPdf ( ) [inline]

Definition at line 15 of file LikelihoodPdf.h.

{};
LikelihoodPdf::LikelihoodPdf ( const LikelihoodPdf pdf) [inline]

Definition at line 16 of file LikelihoodPdf.h.

{}; 
LikelihoodPdf::LikelihoodPdf ( const char *  name,
const char *  species,
int  ecalsubdet,
int  ptbin 
)

Definition at line 9 of file LikelihoodPdf.cc.

References _ecalsubdet, _name, _ptbin, and _species.

                                                                                             {
  _name = std::string(name);
  _species = std::string(species);
  _ecalsubdet = ecalsubdet;
  _ptbin = ptbin;
}
LikelihoodPdf::~LikelihoodPdf ( ) [virtual]

Definition at line 18 of file LikelihoodPdf.cc.

                              {
}

Member Function Documentation

std::string LikelihoodPdf::getName ( void  ) [inline]

get PDF name

Definition at line 31 of file LikelihoodPdf.h.

References _name.

{ return _name; }
std::string LikelihoodPdf::getSpecies ( ) [inline]

get PDF species

Definition at line 34 of file LikelihoodPdf.h.

References _species.

{ return _species; }
float LikelihoodPdf::getVal ( float  x,
std::string  catName = "NOSPLIT",
bool  normalized = true 
)

get Value of pdf at point x for class catName

Definition at line 85 of file LikelihoodPdf.cc.

References _ecalsubdet, _name, _ptbin, _species, _splitPdf, PhysicsTools::Calibration::Histogram< Value_t, Axis_t >::binContent(), PhysicsTools::Calibration::Histogram< Value_t, Axis_t >::findBin(), normalization(), PhysicsTools::Calibration::Histogram< Value_t, Axis_t >::normalization(), and PhysicsTools::Calibration::Histogram< Value_t, Axis_t >::value().

                                       {
  const PhysicsTools::Calibration::HistogramF *thePdf=0;
  if(_splitPdf.size()>1) {
    edm::LogInfo("LikelihoodPdf") << "The PDF " << _name
                                  << " is SPLITTED by category " << gsfClass;
    thePdf=_splitPdf.find(gsfClass)->second;
  }
  else {
    edm::LogInfo("LikelihoodPdf") << "The PDF " << _name
                                  << " is UNSPLITTED";
    thePdf=_splitPdf.find("NOSPLIT")->second;
  }
  
  float prob=-1;

  if(normalized)
    // using thePdf->normalization() neglects the overflows... calculating it manually.
    // prob=thePdf->value(x)/thePdf->normalization();
    prob=thePdf->value(x)/normalization(thePdf);
  else
    prob=thePdf->value(x);

  edm::LogInfo("LikelihoodPdf") << "sanity check: PDF name = " << _name
                                << " for species = " << _species
                                << " for class = " << gsfClass 
                                << " bin content = " << thePdf->binContent(thePdf->findBin(x))
                                << " normalization (std) = " << thePdf->normalization()
                                << " normalization (manual) = " << normalization(thePdf)
                                << " prob = " << prob;
  edm::LogInfo("LikelihoodPdf") << "From likelihood with ecalsubdet = " << _ecalsubdet
                                << " ptbin = " << _ptbin;
 

  return prob;
}
void LikelihoodPdf::initFromDB ( const ElectronLikelihoodCalibration calibration)

initialize PDFs from CondDB

Definition at line 60 of file LikelihoodPdf.cc.

References _name, _species, _splitPdf, _splitRule, ElectronLikelihoodCalibration::data, Exception, and timingPdfMaker::histo.

Referenced by LikelihoodPdfProduct::addPdf().

                                                                          {

  std::map<std::string,std::string>::const_iterator ruleItr;
  for(ruleItr=_splitRule.begin();ruleItr!=_splitRule.end();ruleItr++) {
    // look for the requested PDF in the CondDB
    std::vector<ElectronLikelihoodCalibration::Entry>::const_iterator entryItr;
    bool foundPdf=false;
    for(entryItr=calibration->data.begin(); entryItr!=calibration->data.end(); entryItr++) {
      if(entryItr->category.label.compare(ruleItr->second)==0) { 
        const PhysicsTools::Calibration::HistogramF *histo = &(entryItr->histogram);
        _splitPdf.insert( std::make_pair(ruleItr->first,histo) );
        foundPdf=true;
      }
    }
    if(!foundPdf) {
      throw cms::Exception("LikelihoodPdf") << "The pdf requested: " << _name
                                            << " for species: " << _species
                                            << " is not present in the Conditions DB!";
    }
  }
}
float LikelihoodPdf::normalization ( const PhysicsTools::Calibration::HistogramF thePdf) [private]

Definition at line 124 of file LikelihoodPdf.cc.

References PhysicsTools::Calibration::Histogram< Value_t, Axis_t >::binContent(), i, and PhysicsTools::Calibration::Histogram< Value_t, Axis_t >::numberOfBins().

Referenced by getVal().

                                                                            {
  int nBins = thePdf->numberOfBins();
  float sum=0.;
  for(int i=0; i<=nBins+1; i++) {
    sum += thePdf->binContent(i);
  }
  return sum;
}
void LikelihoodPdf::split ( std::map< std::string, float >  splitFractions,
bool  splitPdf = false 
)

split the pdf by category if splitPdf is true. split map is: <"class",classFraction> if splitPdf is false, pdf is splitted, but they are all equal (but allowing different priors)

use different a-priori probabilities and different PDFs depending by category

use different a-priori, but same PDFs for all categories

do not split at all (same PDF's, same a-priori for all categories)

Definition at line 24 of file LikelihoodPdf.cc.

References _ecalsubdet, _name, _ptbin, _species, and _splitRule.

Referenced by LikelihoodPdfProduct::addPdf().

                                    {

  char buffer[100];
  if(splitFractions.size()>0 && splitPdf) {
    std::map<std::string,float>::const_iterator splitCatItr;
    for(splitCatItr=splitFractions.begin();splitCatItr!=splitFractions.end();splitCatItr++) {
      sprintf(buffer,"%s_%s_subdet%d_ptbin%d_%s",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin,splitCatItr->first.c_str());
      std::string totPdfName = std::string(buffer);
      _splitRule.insert( std::make_pair(splitCatItr->first,totPdfName) );
    }
  }

  else if(splitFractions.size()>0) {
    std::map<std::string,float>::const_iterator splitCatItr;
    for(splitCatItr=splitFractions.begin();splitCatItr!=splitFractions.end();splitCatItr++) {
      sprintf(buffer,"%s_%s_subdet%d_ptbin%d",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin);
      std::string totPdfName = std::string(buffer);
      _splitRule.insert( std::make_pair(splitCatItr->first,totPdfName) );
    }
  }

  else {
      sprintf(buffer,"%s_%s_subdet%d_ptbin%d",_name.c_str(),_species.c_str(),_ecalsubdet,_ptbin);
      std::string totPdfName = std::string(buffer);
      _splitRule.insert( std::make_pair("NOSPLIT",totPdfName) );
  }
}

Member Data Documentation

Definition at line 44 of file LikelihoodPdf.h.

Referenced by getVal(), LikelihoodPdf(), and split().

std::string LikelihoodPdf::_name [private]

Definition at line 42 of file LikelihoodPdf.h.

Referenced by getName(), getVal(), initFromDB(), LikelihoodPdf(), and split().

int LikelihoodPdf::_ptbin [private]

Definition at line 45 of file LikelihoodPdf.h.

Referenced by getVal(), LikelihoodPdf(), and split().

std::string LikelihoodPdf::_species [private]

Definition at line 43 of file LikelihoodPdf.h.

Referenced by getSpecies(), getVal(), initFromDB(), LikelihoodPdf(), and split().

std::map<std::string,const PhysicsTools::Calibration::HistogramF*> LikelihoodPdf::_splitPdf [private]

Definition at line 47 of file LikelihoodPdf.h.

Referenced by getVal(), and initFromDB().

std::map<std::string,std::string> LikelihoodPdf::_splitRule [private]

Definition at line 48 of file LikelihoodPdf.h.

Referenced by initFromDB(), and split().