CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LikelihoodPdfProduct.cc
Go to the documentation of this file.
3 #include <iostream>
4 
5 
6 
8  int ecalsubdet, int ptbin)
9 {
10  _name=std::string(name);
11  _ecalsubdet = ecalsubdet;
12  _ptbin = ptbin;
13 }
14 
15 
16 
18 {
19  // do the delete's
20  std::vector<LikelihoodSpecies*>::iterator specItr;
21  for(specItr=_specList.begin(); specItr!=_specList.end(); specItr++) {
22  delete *specItr;
23  }
24 }
25 
26 
27 
28 void
30 {
31  _calibration=calibration;
32 }
33 
34 
35 
36 void
37 LikelihoodPdfProduct::addSpecies(const char* name, float priorWeight)
38 {
39  LikelihoodSpecies* species = new LikelihoodSpecies(name,priorWeight);
40  _specList.push_back(species);
41 }
42 
43 
44 
45 void
46 LikelihoodPdfProduct::addPdf(const char* specname,
47  const char* name,
48  bool splitPdf)
49 {
50  std::vector<LikelihoodSpecies*>::const_iterator specItr;
51  for(specItr=_specList.begin();specItr!=_specList.end();specItr++) {
52  LikelihoodSpecies* species = *specItr;
53  if(strcmp(species->getName(),specname)==0) {
54  LikelihoodPdf *pdf = new LikelihoodPdf(name,species->getName(),_ecalsubdet,_ptbin);
55  pdf->split(species->getSplitFractions(),splitPdf);
57  species->addPdf(pdf);
58  }
59  }
60 }
61 
62 
63 
64 void
65 LikelihoodPdfProduct::setSplitFrac(const char* specname,
66  const char* catName, float frac) {
67  std::vector<LikelihoodSpecies*>::const_iterator specItr;
68  for(specItr=_specList.begin();specItr!=_specList.end();specItr++) {
69  LikelihoodSpecies* species = *specItr;
70  if(strcmp(species->getName(),specname)==0) {
71  species->setSplitFraction( make_pair(std::string(catName), frac) );
72  break;
73  }
74  }
75 }
76 
77 
78 
79 float
80 LikelihoodPdfProduct::getRatio(const char* specname,
81  const std::vector<float>& measurements,
82  std::string gsfClass)
83 {
84  float sigProb=0, bkgProb=0;
85  std::vector<LikelihoodSpecies*>::const_iterator specItr;
86  for(specItr=_specList.begin();specItr!=_specList.end();specItr++) {
87  LikelihoodSpecies* species = *specItr;
88  std::map<std::string,float> splitFractions = species->getSplitFractions();
89  std::map<std::string,float>::iterator iter = splitFractions.find(gsfClass);
91  float splitFr= (splitFractions.size()==0) ? 1. : iter->second;
92  if(strcmp(species->getName(),specname)==0) {
93  sigProb=splitFr*getSpeciesProb(specname,measurements,gsfClass);
94  }
95  else {
96  bkgProb+=splitFr*getSpeciesProb(species->getName(),measurements,gsfClass);
97  }
98  }
99  if(sigProb+bkgProb>0)
100  return sigProb/(sigProb+bkgProb);
101  else
102  return -1.;
103 }
104 
105 
106 
107 float
109  const std::vector<float>& measurements,
110  std::string gsfClass)
111 {
112  float bareProb=1.;
113  float priorWeight=1.;
114  std::vector<LikelihoodSpecies*>::const_iterator specItr;
115  for(specItr=_specList.begin();specItr!=_specList.end();specItr++) {
116  LikelihoodSpecies* species = *specItr;
117  if(strcmp(species->getName(),specName)==0) {
118  for(unsigned int ipdf=0; ipdf< species->getListOfPdfs().size(); ipdf++) {
119  bareProb*=species->getListOfPdfs().at(ipdf)->getVal(measurements.at(ipdf),gsfClass);
120  }
121  priorWeight=species->getPrior();
122  break;
123  }
124  }
125  edm::LogInfo("LikelihoodPdfProduct") << "Species: " << specName
126  << " bare probability = " << bareProb
127  << " with a priori probability = " << priorWeight;
128  return priorWeight*bareProb;
129 }
void initFromDB(const ElectronLikelihoodCalibration *calibration)
initialize the PDFs from CondDB
void addPdf(LikelihoodPdf *pdf)
void setSplitFraction(std::pair< std::string, float > splitfrac)
void setSplitFrac(const char *specname, const char *catName, float frac=1.0)
set the fraction of one category for a given species
void addSpecies(const char *name, float priorWeight=1.)
add a species (hypothesis) to the likelihood, with a priori probability
LikelihoodPdfProduct(const char *name, int ecalsubdet, int ptbin)
void initFromDB(const ElectronLikelihoodCalibration *calibration)
initialize PDFs from CondDB
float getSpeciesProb(const char *specName, const std::vector< float > &measurements, std::string gsfClass)
std::vector< LikelihoodSpecies * > _specList
void split(const std::map< std::string, float > &splitFractions, bool splitPdf=false)
std::map< std::string, float > getSplitFractions()
void addPdf(const char *specname, const char *name, bool splitPdf=false)
add a pdf for a species, splitted or not
const char * getName()
float getRatio(const char *specName, const std::vector< float > &measurements, std::string)
get the likelihood ratio p(a priori) * L(specName) / L_tot
std::vector< LikelihoodPdf * > getListOfPdfs()
const ElectronLikelihoodCalibration * _calibration