RooEffGenContext.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooEffGenContext.cxx 26044 2008-10-31 16:45:22Z wouter $
00005  * Authors:                                                                  *
00006  *   GR, Gerhard Raven, NIKHEF/VU, Gerhard.Raven@nikhf.nl                    *
00007  *                                                                           *
00008  * Copyright (c) 2005, NIKHEF.  All rights reserved.                         *
00009  *                                                                           *
00010  * Redistribution and use in source and binary forms,                        *
00011  * with or without modification, are permitted according to the terms        *
00012  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00013  *****************************************************************************/
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////////
00017 // 
00018 // BEGIN_HTML
00019 // RooEffGenContext is a specialized generator context for p.d.fs represented
00020 // by class RooEffProd, which are p.d.fs multiplied with an efficiency function.
00021 // This generator context generates events from such products by first
00022 // generating events from a dedicated generator context of the input p.d.f.
00023 // and applying an extra rejection step based on the efficiency function.
00024 // END_HTML
00025 //
00026                                                                                                                       
00027                                                                                                                       
00028 #include "RooFit.h"
00029 #include "RooEffGenContext.h"
00030 #include "RooAbsPdf.h"
00031 #include "RooRandom.h"
00032 using namespace std;
00033 
00034 ClassImp(RooEffGenContext)
00035   ;
00036 
00037 
00038 //_____________________________________________________________________________
00039 RooEffGenContext::RooEffGenContext(const RooAbsPdf &model, 
00040                  const RooAbsPdf& pdf, const RooAbsReal& eff,
00041                  const RooArgSet &vars,
00042                  const RooDataSet *prototype, const RooArgSet* auxProto,
00043                  Bool_t verbose, const RooArgSet* /*forceDirect*/) :
00044   RooAbsGenContext(model,vars,prototype,auxProto,verbose)
00045 {
00046   // Constructor of generator context for RooEffProd products
00047 
00048     RooArgSet x(eff,eff.GetName());
00049    _cloneSet = (RooArgSet*) x.snapshot(kTRUE);
00050    _eff = dynamic_cast<RooAbsReal*>(_cloneSet->find(eff.GetName()));
00051    _generator=pdf.genContext(vars,prototype,auxProto,verbose);
00052 }
00053 
00054 
00055 
00056 //_____________________________________________________________________________
00057 RooEffGenContext::~RooEffGenContext()
00058 {
00059   // Destructor
00060   delete _generator ;
00061   delete _cloneSet ;
00062 }
00063 
00064 
00065 //_____________________________________________________________________________
00066 void RooEffGenContext::initGenerator(const RooArgSet &theEvent)
00067 {
00068   // One-time initialization of generator.
00069 
00070     _eff->recursiveRedirectServers(theEvent);
00071     _generator->initGenerator(theEvent);
00072 }
00073 
00074 
00075 //_____________________________________________________________________________
00076 void RooEffGenContext::generateEvent(RooArgSet &theEvent, Int_t remaining)
00077 {
00078   // Generate one event. Generate an event from the p.d.f and
00079   // then perform an accept/reject sampling based on the efficiency
00080   // function
00081 
00082     Double_t maxEff=1; // for now -- later check max val of _eff...
00083     do {
00084         _generator->generateEvent(theEvent,remaining);
00085     } while (_eff->getVal() < RooRandom::uniform()*maxEff);
00086 }

Generated on Tue Jul 5 15:06:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1