1 /*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
4 * File: $Id: EvtPredGen.hh,v 1.2 2009-03-16 16:40:16 robbep Exp $
5 * Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
7 * Copyright (C) 2002 Caltech
8 *******************************************************************************/
10 // A predicate is applied to a generator to get another generator.
11 // Accept-reject can be implemented in this way.
14 // Generator -> Generator
16 #ifndef EVT_PRED_GEN_HH
17 #define EVT_PRED_GEN_HH
21 template <class Generator, class Predicate>
26 typedef typename Generator::result_type result_type;
29 : itsTried(0), itsPassed(0)
32 EvtPredGen(Generator gen, Predicate pred)
33 : itsGen(gen), itsPred(pred), itsTried(0), itsPassed(0)
36 EvtPredGen(const EvtPredGen& other)
37 : itsGen(other.itsGen), itsPred(other.itsPred),
38 itsTried(other.itsTried), itsPassed(other.itsPassed)
44 result_type operator()() {
51 result_type point = itsGen();
58 printf("No random point generated after %d attempts\n",MAX);
59 printf("Sharp peak? Consider using pole compensation.\n");
60 printf("I will now pick a point at random to return.\n");
64 inline int getTried() const { return itsTried; }
65 inline int getPassed() const { return itsPassed; }