Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
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\file RooEffGenContext.cxx
17\class RooEffGenContext
18\ingroup Roofitcore
19
20RooEffGenContext is a specialized generator context for p.d.fs represented
21by class RooEffProd, which are p.d.fs multiplied with an efficiency function.
22This generator context generates events from such products by first
23generating events from a dedicated generator context of the input p.d.f.
24and applying an extra rejection step based on the efficiency function.
25**/
26
27#include <memory>
28
29#include "RooEffGenContext.h"
30#include "RooAbsPdf.h"
31#include "RooRandom.h"
32
33using namespace std;
34
36
37////////////////////////////////////////////////////////////////////////////////
38/// Constructor of generator context for RooEffProd products
39
41 const RooArgSet &vars, const RooDataSet *prototype, const RooArgSet *auxProto,
42 bool verbose, const RooArgSet * /*forceDirect*/)
43 : RooAbsGenContext(model, vars, prototype, auxProto, verbose), _maxEff(0.)
44{
45 RooArgSet x(eff, eff.GetName());
46 _cloneSet = static_cast<RooArgSet*>(x.snapshot(true));
47 _eff = dynamic_cast<RooAbsReal *>(_cloneSet->find(eff.GetName()));
48 _generator = pdf.genContext(vars, prototype, auxProto, verbose);
49 _vars = static_cast<RooArgSet*>(vars.snapshot(true));
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Destructor
54
56{
57 delete _generator;
58 delete _cloneSet;
59 delete _vars;
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// One-time initialization of generator.
64
66{
68 _generator->initGenerator(theEvent);
69
70 // Check if PDF supports maximum finding
71 Int_t code = _eff->getMaxVal(*_vars);
72 if (!code) {
73 _maxEff = 1.;
74 } else {
75 _maxEff = _eff->maxVal(code);
76 }
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Generate one event. Generate an event from the p.d.f and
81/// then perform an accept/reject sampling based on the efficiency
82/// function
83
85{
86 while (true) {
87 _generator->generateEvent(theEvent, remaining);
88 double val = _eff->getVal();
89 if (val > _maxEff && !_eff->getMaxVal(*_vars)) {
90 coutE(Generation) << ClassName() << "::" << GetName()
91 << ":generateEvent: value of efficiency is larger than assumed maximum of 1." << std::endl;
92 continue;
93 }
94 if (val > RooRandom::uniform() * _maxEff) {
95 break;
96 }
97 }
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Detailed printing interface
102
103void RooEffGenContext::printMultiline(ostream &os, Int_t content, bool verbose, TString indent) const
104{
105 RooAbsGenContext::printMultiline(os, content, verbose, indent);
106 os << indent << "--- RooEffGenContext ---" << endl;
107 os << indent << "Using EFF ";
109 os << indent << "PDF generator" << endl;
110
111 TString indent2(indent);
112 indent2.Append(" ");
113
114 _generator->printMultiline(os, content, verbose, indent2);
115}
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
static void indent(ostringstream &buf, int indent_level)
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
virtual void initGenerator(const RooArgSet &theEvent)
Interface function to initialize context for generation for given set of observables.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Interface for multi-line printing.
virtual void generateEvent(RooArgSet &theEvent, Int_t remaining)=0
virtual RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const
Interface function to create a generator context from a p.d.f.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
virtual double maxVal(Int_t code) const
Return maximum value for set of observables identified by code assigned in getMaxVal.
virtual Int_t getMaxVal(const RooArgSet &vars) const
Advertise capability to determine maximum value of function for given set of observables.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
RooEffGenContext is a specialized generator context for p.d.fs represented by class RooEffProd,...
void generateEvent(RooArgSet &theEvent, Int_t remaining) override
Generate one event.
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Detailed printing interface.
RooArgSet * _cloneSet
Internal clone of p.d.f.
RooEffGenContext(const RooAbsPdf &model, const RooAbsPdf &pdf, const RooAbsReal &eff, const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false, const RooArgSet *forceDirect=nullptr)
Constructor of generator context for RooEffProd products.
void initGenerator(const RooArgSet &theEvent) override
One-time initialization of generator.
RooArgSet * _vars
Vars to generate.
RooAbsGenContext * _generator
Generator context for p.d.f.
~RooEffGenContext() override
Destructor.
double _maxEff
Maximum of efficiency in vars.
RooAbsReal * _eff
Pointer to efficiency function.
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
static double uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Definition RooRandom.cxx:81
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
Basic string class.
Definition TString.h:139
TString & Append(const char *cs)
Definition TString.h:576
Double_t x[n]
Definition legend1.C:17