Logo ROOT  
Reference Guide
RooEffGenContext.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * GR, Gerhard Raven, NIKHEF/VU, Gerhard.Raven@nikhf.nl *
7  * *
8  * Copyright (c) 2005, NIKHEF. All rights reserved. *
9  * *
10  * Redistribution and use in source and binary forms, *
11  * with or without modification, are permitted according to the terms *
12  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
13  *****************************************************************************/
14 
15 
16 /**
17 \file RooEffGenContext.cxx
18 \class RooEffGenContext
19 \ingroup Roofitcore
20 
21 RooEffGenContext is a specialized generator context for p.d.fs represented
22 by class RooEffProd, which are p.d.fs multiplied with an efficiency function.
23 This generator context generates events from such products by first
24 generating events from a dedicated generator context of the input p.d.f.
25 and applying an extra rejection step based on the efficiency function.
26 **/
27 
28 #include <memory>
29 
30 #include "RooFit.h"
31 #include "RooEffGenContext.h"
32 #include "RooAbsPdf.h"
33 #include "RooRandom.h"
34 
35 using namespace std;
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Constructor of generator context for RooEffProd products
41 
43  const RooAbsPdf& pdf, const RooAbsReal& eff,
44  const RooArgSet &vars,
45  const RooDataSet *prototype, const RooArgSet* auxProto,
46  Bool_t verbose, const RooArgSet* /*forceDirect*/) :
47  RooAbsGenContext(model, vars, prototype, auxProto, verbose), _maxEff(0.)
48 {
49  RooArgSet x(eff,eff.GetName());
50  _cloneSet = static_cast<RooArgSet*>(x.snapshot(kTRUE));
51  _eff = dynamic_cast<RooAbsReal*>(_cloneSet->find(eff.GetName()));
52  _generator = pdf.genContext(vars, prototype, auxProto, verbose);
53  _vars = static_cast<RooArgSet*>(vars.snapshot(kTRUE));
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Destructor
58 
60 {
61  delete _generator;
62  delete _cloneSet;
63  delete _vars;
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// One-time initialization of generator.
68 
70 {
71  _eff->recursiveRedirectServers(theEvent);
72  _generator->initGenerator(theEvent);
73 
74  // Check if PDF supports maximum finding
75  Int_t code = _eff->getMaxVal(*_vars);
76  if (!code) {
77  _maxEff = 1.;
78  } else {
79  _maxEff = _eff->maxVal(code);
80  }
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Generate one event. Generate an event from the p.d.f and
85 /// then perform an accept/reject sampling based on the efficiency
86 /// function
87 
89 {
90  while (true) {
91  _generator->generateEvent(theEvent, remaining);
92  double val = _eff->getVal();
93  if (val > _maxEff && !_eff->getMaxVal(*_vars)) {
94  coutE(Generation) << ClassName() << "::" << GetName()
95  << ":generateEvent: value of efficiency is larger than assumed maximum of 1." << std::endl;
96  continue;
97  }
98  if (val > RooRandom::uniform() * _maxEff) {
99  break;
100  }
101  }
102 }
RooAbsPdf::genContext
virtual RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, Bool_t verbose=kFALSE) const
Interface function to create a generator context from a p.d.f.
Definition: RooAbsPdf.cxx:2005
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooFit.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooEffGenContext::generateEvent
void generateEvent(RooArgSet &theEvent, Int_t remaining)
Generate one event.
Definition: RooEffGenContext.cxx:88
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooAbsReal::getVal
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:91
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
x
Double_t x[n]
Definition: legend1.C:17
RooAbsReal
Definition: RooAbsReal.h:61
RooAbsArg::recursiveRedirectServers
Bool_t recursiveRedirectServers(const RooAbsCollection &newServerList, Bool_t mustReplaceAll=kFALSE, Bool_t nameChange=kFALSE, Bool_t recurseInNewSet=kTRUE)
Definition: RooAbsArg.cxx:1066
RooEffGenContext::_generator
RooAbsGenContext * _generator
Definition: RooEffGenContext.h:38
RooEffGenContext.h
bool
RooAbsGenContext::initGenerator
virtual void initGenerator(const RooArgSet &theEvent)
Interface function to initialize context for generation for given set of observables.
Definition: RooAbsGenContext.cxx:273
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:134
RooAbsPdf.h
RooFit::Generation
@ Generation
Definition: RooGlobalFunc.h:67
RooRandom.h
RooAbsReal::getMaxVal
virtual Int_t getMaxVal(const RooArgSet &vars) const
Advertise capability to determine maximum value of function for given set of observables.
Definition: RooAbsReal.cxx:3651
RooAbsGenContext
Definition: RooAbsGenContext.h:26
RooEffGenContext::_cloneSet
RooArgSet * _cloneSet
Definition: RooEffGenContext.h:36
RooEffGenContext::initGenerator
void initGenerator(const RooArgSet &theEvent)
One-time initialization of generator.
Definition: RooEffGenContext.cxx:69
RooAbsReal::maxVal
virtual Double_t maxVal(Int_t code) const
Return maximum value for set of observables identified by code assigned in getMaxVal.
Definition: RooAbsReal.cxx:3662
RooEffGenContext::_vars
RooArgSet * _vars
Definition: RooEffGenContext.h:39
RooEffGenContext::_eff
RooAbsReal * _eff
Definition: RooEffGenContext.h:37
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooEffGenContext::~RooEffGenContext
virtual ~RooEffGenContext()
Destructor.
Definition: RooEffGenContext.cxx:59
RooDataSet
Definition: RooDataSet.h:33
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooAbsPdf
Definition: RooAbsPdf.h:40
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooEffGenContext::_maxEff
double _maxEff
Definition: RooEffGenContext.h:40
RooRandom::uniform
static Double_t uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Definition: RooRandom.cxx:83
TObject::ClassName
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:130
RooEffGenContext::RooEffGenContext
RooEffGenContext(const RooAbsPdf &model, const RooAbsPdf &pdf, const RooAbsReal &eff, const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, Bool_t verbose=kFALSE, const RooArgSet *forceDirect=0)
Constructor of generator context for RooEffProd products.
Definition: RooEffGenContext.cxx:42
RooEffGenContext
Definition: RooEffGenContext.h:23
RooAbsGenContext::generateEvent
virtual void generateEvent(RooArgSet &theEvent, Int_t remaining)=0
RooArgSet
Definition: RooArgSet.h:28
int