BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtPredGen.hh
Go to the documentation of this file.
1/*******************************************************************************
2 * Project: BaBar detector at the SLAC PEP-II B-factory
3 * Package: EvtGenBase
4 * File: $Id: EvtPredGen.hh,v 1.1.1.2 2007/10/26 05:03:14 pingrg Exp $
5 * Author: Alexei Dvoretskii, dvoretsk@slac.stanford.edu, 2001-2002
6 *
7 * Copyright (C) 2002 Caltech
8 *******************************************************************************/
9
10// A predicate is applied to a generator to get another generator.
11// Accept-reject can be implemented in this way.
12//
13// Predicate
14// Generator -> Generator
15
16#ifndef EVT_PRED_GEN_HH
17#define EVT_PRED_GEN_HH
18
19#include <stdio.h>
20
21template <class Generator, class Predicate> class EvtPredGen {
22
23public:
24 typedef typename Generator::result_type result_type;
25
26 EvtPredGen() : itsTried( 0 ), itsPassed( 0 ) {}
27
28 EvtPredGen( Generator gen, Predicate pred )
29 : itsGen( gen ), itsPred( pred ), itsTried( 0 ), itsPassed( 0 ) {}
30
31 EvtPredGen( const EvtPredGen& other )
32 : itsGen( other.itsGen )
33 , itsPred( other.itsPred )
34 , itsTried( other.itsTried )
35 , itsPassed( other.itsPassed ) {}
36
38
40
41 int i = 0;
42 int MAX = 10000;
43 while ( i++ < MAX )
44 {
45
46 itsTried++;
47 result_type point = itsGen();
48 if ( itsPred( point ) )
49 {
50 itsPassed++;
51 return point;
52 }
53 }
54
55 printf( "No random point generated after %d attempts\n", MAX );
56 printf( "Sharp peak? Consider using pole compensation.\n" );
57 printf( "I will now pick a point at random to return.\n" );
58 return itsGen();
59 }
60
61 inline int getTried() const { return itsTried; }
62 inline int getPassed() const { return itsPassed; }
63
64protected:
65 Generator itsGen;
66 Predicate itsPred;
69};
70
71#endif
int getPassed() const
Definition EvtPredGen.hh:62
result_type operator()()
Definition EvtPredGen.hh:39
EvtPredGen(Generator gen, Predicate pred)
Definition EvtPredGen.hh:28
Generator::result_type result_type
Definition EvtPredGen.hh:24
int getTried() const
Definition EvtPredGen.hh:61
Predicate itsPred
Definition EvtPredGen.hh:66
EvtPredGen(const EvtPredGen &other)
Definition EvtPredGen.hh:31
Generator itsGen
Definition EvtPredGen.hh:65