CGEM BOSS
6.6.5.i
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,
[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
21
template
<
class
Generator,
class
Predicate>
22
class
EvtPredGen
{
23
24
public
:
25
26
typedef
typename
Generator::result_type
result_type
;
27
28
EvtPredGen
()
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
),
38
itsTried
(other.
itsTried
),
itsPassed
(other.
itsPassed
)
39
{}
40
41
~EvtPredGen
()
42
{}
43
44
result_type
operator()
() {
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
67
protected
:
68
69
Generator
itsGen
;
70
Predicate
itsPred
;
71
int
itsTried
;
72
int
itsPassed
;
73
74
};
75
76
#endif
77
EvtPredGen
Definition
EvtPredGen.hh:22
EvtPredGen::itsPassed
int itsPassed
Definition
EvtPredGen.hh:72
EvtPredGen::EvtPredGen
EvtPredGen()
Definition
EvtPredGen.hh:28
EvtPredGen::getPassed
int getPassed() const
Definition
EvtPredGen.hh:65
EvtPredGen::operator()
result_type operator()()
Definition
EvtPredGen.hh:44
EvtPredGen::EvtPredGen
EvtPredGen(Generator gen, Predicate pred)
Definition
EvtPredGen.hh:32
EvtPredGen::getTried
int getTried() const
Definition
EvtPredGen.hh:64
EvtPredGen::itsPred
Predicate itsPred
Definition
EvtPredGen.hh:70
EvtPredGen::EvtPredGen
EvtPredGen(const EvtPredGen &other)
Definition
EvtPredGen.hh:36
EvtPredGen::itsTried
int itsTried
Definition
EvtPredGen.hh:71
EvtPredGen::~EvtPredGen
~EvtPredGen()
Definition
EvtPredGen.hh:41
EvtPredGen::itsGen
Generator itsGen
Definition
EvtPredGen.hh:69
EvtPredGen::result_type
Generator::result_type result_type
Definition
EvtPredGen.hh:26
6.6.5.i
Generator
BesEvtGen
BesEvtGen-00-01-96-slc6tag
src
EvtGen
EvtGenBase
EvtPredGen.hh
Generated by
1.12.0