CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
SimplerLikelihoodRatioTestStatOpt Class Reference

#include <SimplerLikelihoodRatioTestStatExt.h>

Inheritance diagram for SimplerLikelihoodRatioTestStatOpt:

Public Member Functions

virtual Double_t Evaluate (RooAbsData &data, RooArgSet &nullPOI)
 
virtual const TString GetVarName () const
 
 SimplerLikelihoodRatioTestStatOpt (const RooArgSet &obs, RooAbsPdf &pdfNull, RooAbsPdf &pdfAlt, const RooArgSet &paramsNull=RooArgSet(), const RooArgSet &paramsAlt=RooArgSet(), bool factorize=true)
 
virtual ~SimplerLikelihoodRatioTestStatOpt ()
 

Private Member Functions

double evalSimNLL (RooAbsData &data, RooSimultaneous *pdf, std::vector< RooAbsPdf * > &components)
 
double evalSimpleNLL (RooAbsData &data, RooAbsPdf *pdf)
 
void unrollSimPdf (RooSimultaneous *pdf, std::vector< RooAbsPdf * > &out)
 

Private Attributes

const RooArgSet * obs_
 observables (global argset) More...
 
std::auto_ptr< RooArgSet > paramsAlt_
 
std::auto_ptr< RooArgSet > paramsNull_
 parameter sets to apply snapshots to More...
 
RooAbsPdf * pdfAlt_
 
std::auto_ptr< RooAbsPdf > pdfAltOwned_
 
RooArgSet pdfCompAlt_
 
RooArgSet pdfCompNull_
 snapshot with all branch nodes of the pdfs before factorization More...
 
RooArgList pdfDepObs_
 nodes which depend directly on observables, on which one has to do redirectServers More...
 
RooAbsPdf * pdfNull_
 pdfs (cloned, and with constraints factorized away) More...
 
std::auto_ptr< RooAbsPdf > pdfNullOwned_
 owned copy of the pdfs after factorizing More...
 
RooSimultaneous * simPdfAlt_
 
std::vector< RooAbsPdf * > simPdfComponentsAlt_
 
std::vector< RooAbsPdf * > simPdfComponentsNull_
 components of the sim pdfs after factorization, for each bin in sim. category. can contain nulls More...
 
RooSimultaneous * simPdfNull_
 pdfNull, pdfAlt cast to sympdf (may be null) after factorization More...
 
RooArgSet snapAlt_
 
RooArgSet snapNull_
 snapshots of parameters for the two pdfs More...
 

Detailed Description

BEGIN_HTML

SimplerLikelihoodRatioTestStatOpt: an optimized implementaion of the simple likelihood ratio test statistics Q = - ln( L(data|null) / L(data|alt) )

Optimization is obtained through the following methods:

Author: Giovanni Petrucciani (UCSD/CMS/CERN), May 2011

END_HTML

Definition at line 34 of file SimplerLikelihoodRatioTestStatExt.h.

Constructor & Destructor Documentation

SimplerLikelihoodRatioTestStatOpt::SimplerLikelihoodRatioTestStatOpt ( const RooArgSet &  obs,
RooAbsPdf &  pdfNull,
RooAbsPdf &  pdfAlt,
const RooArgSet &  paramsNull = RooArgSet(),
const RooArgSet &  paramsAlt = RooArgSet(),
bool  factorize = true 
)

Create a SimplerLikelihoodRatioTestStatOpt. obs = the observables on which the two pdfs depend pdfNull, pdfAlt = pdfs of the two models paramsNull, paramsAlt = values of the parameters that should be set before evaluating the pdfs factorize: if set to true, the constraint terms not depending on the observables will be removed

Definition at line 4 of file SimplerLikelihoodRatioTestStatExt.cc.

References createBeamHaloJobs::constraints, utils::factorizePdf(), utils::fullClonePdf(), utils::getClients(), obs_, pdfAlt_, pdfAltOwned_, pdfCompAlt_, pdfCompNull_, pdfDepObs_, pdfNull_, pdfNullOwned_, simPdfAlt_, simPdfComponentsAlt_, simPdfComponentsNull_, simPdfNull_, snapAlt_, snapNull_, and unrollSimPdf().

8  :
9  obs_(&obs)
10 {
11  // take a snapshot of the pdf so we can modify it at will
12  RooAbsPdf *cloneNull = utils::fullClonePdf(&pdfNull, pdfCompNull_);
13  RooAbsPdf *cloneAlt = utils::fullClonePdf(&pdfAlt, pdfCompAlt_);
14 
15  // factorize away constraints
16  RooArgList constraints;
17  pdfNull_ = factorize ? utils::factorizePdf(obs, *cloneNull, constraints) : cloneNull;
18  if (pdfNull_ == 0) throw std::invalid_argument("SimplerLikelihoodRatioTestStatOpt:: pdf does not depend on observables");
19  if (pdfNull_ != cloneNull) pdfNullOwned_.reset(pdfNull_); // if new, then take ownership of it
20  if (cloneNull == cloneAlt) {
21  pdfAlt_ = pdfNull_;
22  } else {
23  pdfAlt_ = factorize ? utils::factorizePdf(obs, *cloneAlt, constraints) : cloneAlt;
24  if (pdfAlt_ == 0) throw std::invalid_argument("SimplerLikelihoodRatioTestStatOpt:: pdf does not depend on observables");
25  if (pdfAlt_ != cloneAlt) pdfAltOwned_.reset(pdfAlt_); // if new, then take ownership of it
26  }
27 
28  // take snapshot of parameters
29  snapNull_.addClone(paramsNull);
30  snapAlt_.addClone(paramsAlt);
31 
32  // if the pdf is a RooSimultaneous, unroll it
33  simPdfNull_ = dynamic_cast<RooSimultaneous *>(pdfNull_);
34  simPdfAlt_ = dynamic_cast<RooSimultaneous *>(pdfAlt_);
37 
38  // optimize caching
39  pdfNull_->optimizeCacheMode(*obs_);
40  pdfAlt_->optimizeCacheMode(*obs_);
41 
42  // find nodes that directly depend on observables
45 }
RooArgList pdfDepObs_
nodes which depend directly on observables, on which one has to do redirectServers ...
std::vector< RooAbsPdf * > simPdfComponentsNull_
components of the sim pdfs after factorization, for each bin in sim. category. can contain nulls ...
std::auto_ptr< RooAbsPdf > pdfNullOwned_
owned copy of the pdfs after factorizing
void getClients(const RooAbsCollection &values, const RooAbsCollection &allObjects, RooAbsCollection &clients)
add to &#39;clients&#39; all object within allObjects that directly depend on values
Definition: utils.cc:236
RooAbsPdf * pdfNull_
pdfs (cloned, and with constraints factorized away)
RooArgSet snapNull_
snapshots of parameters for the two pdfs
RooSimultaneous * simPdfNull_
pdfNull, pdfAlt cast to sympdf (may be null) after factorization
RooAbsPdf * fullClonePdf(const RooAbsPdf *pdf, RooArgSet &holder, bool cloneLeafNodes=false)
Definition: utils.cc:218
const RooArgSet * obs_
observables (global argset)
RooArgSet pdfCompNull_
snapshot with all branch nodes of the pdfs before factorization
RooAbsPdf * factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &constraints)
Definition: utils.cc:80
void unrollSimPdf(RooSimultaneous *pdf, std::vector< RooAbsPdf * > &out)
SimplerLikelihoodRatioTestStatOpt::~SimplerLikelihoodRatioTestStatOpt ( )
virtual

Definition at line 47 of file SimplerLikelihoodRatioTestStatExt.cc.

48 {
49 }

Member Function Documentation

double SimplerLikelihoodRatioTestStatOpt::evalSimNLL ( RooAbsData &  data,
RooSimultaneous *  pdf,
std::vector< RooAbsPdf * > &  components 
)
private

Definition at line 106 of file SimplerLikelihoodRatioTestStatExt.cc.

References newFWLiteAna::bin, i, n, obs_, and w().

Referenced by Evaluate().

106  {
107  data.setDirtyProp(false);
108 
109  double sum = 0.0;
110  int i, n = data.numEntries();
111 
112  // must fetch the category, from the dataset first, if it's not empty
113  RooAbsCategoryLValue *cat = 0;
114  if (n) {
115  const RooArgSet *entry = data.get(0);
116  cat = dynamic_cast<RooAbsCategoryLValue *>(entry->find(pdf->indexCat().GetName()));
117  assert(cat != 0 && "Didn't find category in dataset");
118  }
119 
120  // now loop on the dataset, and dispatch the request to the appropriate pdf
121  std::vector<double> sumw(components.size(), 0);
122  for (i = 0; i < n; ++i) {
123  data.get(i);
124  double w = data.weight(); if (w == 0) continue;
125  int bin = cat->getBin();
126  assert(bin < int(components.size()) && "Bin outside range");
127  if (components[bin] == 0) continue;
128  sum += -w*components[bin]->getLogVal(obs_);
129  sumw[bin] += w;
130  }
131 
132  // then compute extended term
133  for (i = 0, n = components.size(); i < n; ++i) {
134  if (components[i]) sum += components[i]->extendedTerm(UInt_t(sumw[i]), obs_);
135  }
136  return sum;
137 }
int i
Definition: DBlmapReader.cc:9
const RooArgSet * obs_
observables (global argset)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
unsigned int UInt_t
Definition: FUTypes.h:12
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
T w() const
double SimplerLikelihoodRatioTestStatOpt::evalSimpleNLL ( RooAbsData &  data,
RooAbsPdf *  pdf 
)
private

Definition at line 139 of file SimplerLikelihoodRatioTestStatExt.cc.

References i, n, obs_, and w().

Referenced by Evaluate().

139  {
140  data.setDirtyProp(false);
141  double sum = 0.0, sumw = 0.0;
142  int i, n = data.numEntries();
143  for (i = 0; i < n; ++i) {
144  data.get(i);
145  double w = data.weight(); if (w == 0) continue;
146  sum += -w*pdf->getLogVal(obs_);
147  sumw += w;
148  }
149  sum += pdf->extendedTerm(UInt_t(sumw), obs_);
150  return sum;
151 }
int i
Definition: DBlmapReader.cc:9
const RooArgSet * obs_
observables (global argset)
unsigned int UInt_t
Definition: FUTypes.h:12
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
T w() const
Double_t SimplerLikelihoodRatioTestStatOpt::Evaluate ( RooAbsData &  data,
RooArgSet &  nullPOI 
)
virtual

Definition at line 52 of file SimplerLikelihoodRatioTestStatExt.cc.

References a, evalSimNLL(), evalSimpleNLL(), obs_, paramsAlt_, paramsNull_, pdfAlt_, pdfDepObs_, pdfNull_, simPdfAlt_, simPdfComponentsAlt_, simPdfComponentsNull_, simPdfNull_, snapAlt_, and snapNull_.

53 {
54  // get parameters, if not there already
55  if (paramsNull_.get() == 0) paramsNull_.reset(pdfNull_->getParameters(data));
56  if (paramsAlt_.get() == 0) paramsAlt_.reset(pdfAlt_->getParameters(data));
57 
58  // if the dataset is not empty, redirect pdf nodes to the dataset
59  std::auto_ptr<TIterator> iterDepObs(pdfDepObs_.createIterator());
60  bool nonEmpty = data.numEntries() > 0;
61  if (nonEmpty) {
62  const RooArgSet *entry = data.get(0);
63  for (RooAbsArg *a = (RooAbsArg *) iterDepObs->Next(); a != 0; a = (RooAbsArg *) iterDepObs->Next()) {
64  a->redirectServers(*entry);
65  }
66  }
67 
68  // evaluate null pdf
70  *paramsNull_ = nullPOI;
72 
73  // evaluate alt pdf
76 
77  // put back links in pdf nodes, otherwise if the dataset goes out of scope they have dangling pointers
78  if (nonEmpty) {
79  iterDepObs->Reset();
80  for (RooAbsArg *a = (RooAbsArg *) iterDepObs->Next(); a != 0; a = (RooAbsArg *) iterDepObs->Next()) {
81  a->redirectServers(*obs_);
82  }
83  }
84 
85  return nullNLL-altNLL;
86 }
RooArgList pdfDepObs_
nodes which depend directly on observables, on which one has to do redirectServers ...
double evalSimNLL(RooAbsData &data, RooSimultaneous *pdf, std::vector< RooAbsPdf * > &components)
std::vector< RooAbsPdf * > simPdfComponentsNull_
components of the sim pdfs after factorization, for each bin in sim. category. can contain nulls ...
RooAbsPdf * pdfNull_
pdfs (cloned, and with constraints factorized away)
RooArgSet snapNull_
snapshots of parameters for the two pdfs
RooSimultaneous * simPdfNull_
pdfNull, pdfAlt cast to sympdf (may be null) after factorization
const RooArgSet * obs_
observables (global argset)
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
std::auto_ptr< RooArgSet > paramsNull_
parameter sets to apply snapshots to
double evalSimpleNLL(RooAbsData &data, RooAbsPdf *pdf)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double a
Definition: hdecay.h:121
virtual const TString SimplerLikelihoodRatioTestStatOpt::GetVarName ( ) const
inlinevirtual

Definition at line 47 of file SimplerLikelihoodRatioTestStatExt.h.

References pdfAlt_, and pdfNull_.

47  {
48  return TString::Format("-log(%s/%s)", pdfNull_->GetName(), pdfAlt_->GetName());
49  }
RooAbsPdf * pdfNull_
pdfs (cloned, and with constraints factorized away)
void SimplerLikelihoodRatioTestStatOpt::unrollSimPdf ( RooSimultaneous *  pdf,
std::vector< RooAbsPdf * > &  out 
)
private

Definition at line 88 of file SimplerLikelihoodRatioTestStatExt.cc.

References NULL, and obs_.

Referenced by SimplerLikelihoodRatioTestStatOpt().

88  {
89  // get a clone of the pdf category, so that I can use it to enumerate the pdf states
90  std::auto_ptr<RooAbsCategoryLValue> catClone((RooAbsCategoryLValue*) simpdf->indexCat().Clone());
91  out.resize(catClone->numBins(NULL), 0);
92  //std::cout << "Pdf " << pdf->GetName() <<" is a SimPdf over category " << catClone->GetName() << ", with " << out.size() << " bins" << std::endl;
93 
94  // loop on the category state and fetch the pdfs
95  for (int ib = 0, nb = out.size(); ib < nb; ++ib) {
96  catClone->setBin(ib);
97  RooAbsPdf *pdfi = simpdf->getPdf(catClone->getLabel());
98  pdfi->optimizeCacheMode(*obs_);
99  if (pdfi != 0) {
100  //std::cout << " bin " << ib << " (label " << catClone->getLabel() << ") has pdf " << pdfi->GetName() << " of type " << pdfi->ClassName() << std::endl;
101  out[ib] = pdfi;
102  }
103  }
104 }
#define NULL
Definition: scimark2.h:8
const RooArgSet * obs_
observables (global argset)
tuple out
Definition: dbtoconf.py:99

Member Data Documentation

const RooArgSet* SimplerLikelihoodRatioTestStatOpt::obs_
private

observables (global argset)

Definition at line 52 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by evalSimNLL(), evalSimpleNLL(), Evaluate(), SimplerLikelihoodRatioTestStatOpt(), and unrollSimPdf().

std::auto_ptr<RooArgSet> SimplerLikelihoodRatioTestStatOpt::paramsAlt_
private

Definition at line 62 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by Evaluate().

std::auto_ptr<RooArgSet> SimplerLikelihoodRatioTestStatOpt::paramsNull_
private

parameter sets to apply snapshots to

Definition at line 62 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by Evaluate().

RooAbsPdf * SimplerLikelihoodRatioTestStatOpt::pdfAlt_
private
std::auto_ptr<RooAbsPdf> SimplerLikelihoodRatioTestStatOpt::pdfAltOwned_
private
RooArgSet SimplerLikelihoodRatioTestStatOpt::pdfCompAlt_
private
RooArgSet SimplerLikelihoodRatioTestStatOpt::pdfCompNull_
private

snapshot with all branch nodes of the pdfs before factorization

Definition at line 56 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by SimplerLikelihoodRatioTestStatOpt().

RooArgList SimplerLikelihoodRatioTestStatOpt::pdfDepObs_
private

nodes which depend directly on observables, on which one has to do redirectServers

Definition at line 58 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by Evaluate(), and SimplerLikelihoodRatioTestStatOpt().

RooAbsPdf* SimplerLikelihoodRatioTestStatOpt::pdfNull_
private

pdfs (cloned, and with constraints factorized away)

Definition at line 54 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by Evaluate(), GetVarName(), and SimplerLikelihoodRatioTestStatOpt().

std::auto_ptr<RooAbsPdf> SimplerLikelihoodRatioTestStatOpt::pdfNullOwned_
private

owned copy of the pdfs after factorizing

Definition at line 64 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by SimplerLikelihoodRatioTestStatOpt().

RooSimultaneous * SimplerLikelihoodRatioTestStatOpt::simPdfAlt_
private
std::vector<RooAbsPdf *> SimplerLikelihoodRatioTestStatOpt::simPdfComponentsAlt_
private
std::vector<RooAbsPdf *> SimplerLikelihoodRatioTestStatOpt::simPdfComponentsNull_
private

components of the sim pdfs after factorization, for each bin in sim. category. can contain nulls

Definition at line 68 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by Evaluate(), and SimplerLikelihoodRatioTestStatOpt().

RooSimultaneous* SimplerLikelihoodRatioTestStatOpt::simPdfNull_
private

pdfNull, pdfAlt cast to sympdf (may be null) after factorization

Definition at line 66 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by Evaluate(), and SimplerLikelihoodRatioTestStatOpt().

RooArgSet SimplerLikelihoodRatioTestStatOpt::snapAlt_
private
RooArgSet SimplerLikelihoodRatioTestStatOpt::snapNull_
private

snapshots of parameters for the two pdfs

Definition at line 60 of file SimplerLikelihoodRatioTestStatExt.h.

Referenced by Evaluate(), and SimplerLikelihoodRatioTestStatOpt().