BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
BesEvtGen-00-04-08/src/EvtGen/EvtGenBase/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, [email protected], 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>
22class EvtPredGen {
23
24public:
25
26 typedef typename Generator::result_type result_type;
27
29 : itsTried(0), itsPassed(0)
30 {}
31
32 EvtPredGen(Generator gen, Predicate pred)
33 : itsGen(gen), itsPred(pred), itsTried(0), itsPassed(0)
34 {}
35
36 EvtPredGen(const EvtPredGen& other)
37 : itsGen(other.itsGen), itsPred(other.itsPred),
39 {}
40
42 {}
43
45
46 int i = 0;
47 int MAX = 10000;
48 while(i++ < MAX) {
49
50 itsTried++;
51 result_type point = itsGen();
52 if(itsPred(point)) {
53 itsPassed++;
54 return point;
55 }
56 }
57
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");
61 return itsGen();
62 }
63
64 inline int getTried() const { return itsTried; }
65 inline int getPassed() const { return itsPassed; }
66
67protected:
68
69 Generator itsGen;
70 Predicate itsPred;
71 int itsTried;
72 int itsPassed;
73
74};
75
76#endif
77
EvtPredGen(Generator gen, Predicate pred)