cepgen
is hosted by
Hepforge
,
IPPP Durham
CepGen
1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
ProcessIntegrand.cpp
Go to the documentation of this file.
1
/*
2
* CepGen: a central exclusive processes event generator
3
* Copyright (C) 2013-2024 Laurent Forthomme
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include <numeric>
20
21
#include "
CepGen/Core/Exception.h
"
22
#include "
CepGen/Core/RunParameters.h
"
23
#include "
CepGen/Event/Event.h
"
24
#include "
CepGen/EventFilter/EventBrowser.h
"
25
#include "
CepGen/EventFilter/EventModifier.h
"
26
#include "
CepGen/Integration/ProcessIntegrand.h
"
27
#include "
CepGen/Process/Process.h
"
28
#include "
CepGen/Utils/Functional.h
"
29
#include "
CepGen/Utils/Math.h
"
30
#include "
CepGen/Utils/TimeKeeper.h
"
31
32
namespace
cepgen
{
33
ProcessIntegrand::ProcessIntegrand
(
const
proc::Process
& proc) : params_(new
RunParameters
), tmr_(new utils::Timer) {
34
setProcess(proc);
35
}
36
37
ProcessIntegrand::ProcessIntegrand
(
const
RunParameters
* params) : params_(params), tmr_(new utils::Timer) {
38
if
(!params_)
39
throw
CG_FATAL
(
"ProcessIntegrand"
) <<
"Invalid runtime parameters specified."
;
40
if
(!params_->
hasProcess
())
41
throw
CG_FATAL
(
"ProcessIntegrand"
) <<
"No process defined in runtime parameters."
;
42
setProcess(params_->
process
());
43
}
44
45
size_t
ProcessIntegrand::size
()
const
{
return
process
().
ndim
(); }
46
47
void
ProcessIntegrand::setProcess(
const
proc::Process
& proc) {
48
//--- each integrand object has its own clone of the process
49
process_ = proc.
clone
();
// note: kinematics is already set by the process copy constructor
50
51
CG_DEBUG
(
"ProcessIntegrand:setProcess"
)
52
<<
"New '"
<<
process
().
name
() <<
"' process cloned from '"
<< proc.
name
() <<
"' process."
;
53
process
().
kinematics
().
setParameters
(proc.
kinematics
().
parameters
());
54
55
//--- first-run preparation
56
CG_DEBUG
(
"ProcessIntegrand:setProcess"
).log([
this
](
auto
& dbg) {
57
dbg <<
"Run started for "
<<
process
().
name
() <<
" process "
<< std::hex << (
void
*)process_.get() << std::dec
58
<<
".\n\t"
;
59
const
auto
& beams =
process
().
kinematics
().
incomingBeams
();
60
dbg <<
"Process mode considered: "
<< beams.
mode
() <<
"\n\t"
61
<<
" positive-z beam: "
<< beams.positive() <<
"\n\t"
62
<<
" negative-z beam: "
<< beams.negative();
63
if
(!beams.structureFunctions().empty())
64
dbg <<
"\n\t structure functions: "
<< beams.structureFunctions();
65
process
().
dumpVariables
(&dbg.stream());
66
});
67
process
().
initialise
();
68
69
CG_DEBUG
(
"ProcessIntegrand:setProcess"
)
70
<<
"Process integrand defined for dimension-"
<<
size
() <<
" process '"
<<
process
().
name
() <<
"'."
;
71
}
72
73
proc::Process
&
ProcessIntegrand::process
() {
74
if
(!process_)
75
throw
CG_FATAL
(
"ProcessIntegrand:process"
) <<
"Process was not properly cloned!"
;
76
return
*process_;
77
}
78
79
const
proc::Process
&
ProcessIntegrand::process
()
const
{
80
if
(!process_)
81
throw
CG_FATAL
(
"ProcessIntegrand:process"
) <<
"Process was not properly cloned!"
;
82
return
*process_;
83
}
84
85
double
ProcessIntegrand::eval
(
const
std::vector<double>& x) {
86
CG_TICKER
(
const_cast<
RunParameters
*
>
(params_)->timeKeeper());
87
88
//--- start the timer
89
tmr_->reset();
90
process
().
clearEvent
();
91
92
//--- specify the phase space point to probe and calculate weight
93
auto
weight =
process
().
weight
(x);
94
95
//--- invalidate any unphysical behaviour
96
if
(!
utils::positive
(weight))
97
return
0.;
98
99
//--- speed up the integration process if no event is to be generated
100
if
(!process_->hasEvent())
101
return
weight;
102
103
process_->setKinematics();
// fill in the process' Event object
104
auto
*
event
= process_->eventPtr();
// prepare the event content
105
106
// once kinematics variables computed, can apply taming functions
107
for
(
const
auto
& tam : params_->
tamingFunctions
())
108
if
(
const
auto
val = (*tam)(bws_.
get
(*event, tam->variables().at(0))) != 0.)
109
weight *= val;
110
else
111
return
0.;
112
113
if
(storage_)
114
event
->metadata[
"time:generation"
] = tmr_->elapsed();
// pure CepGen part of the event generation
115
116
{
// trigger all event modification algorithms
117
double
br = -1.;
118
const
auto
fast_mode = !storage_;
119
for
(
auto
& mod : params_->
eventModifiersSequence
()) {
120
if
(!mod->run(*event, br, fast_mode) || br == 0.)
121
return
0.;
122
weight *= br;
// branching fraction for all decays
123
}
124
}
125
{
// apply cuts on final state system (after event modification algorithms)
126
const
auto
& kin = process_->kinematics();
127
// (polish your cuts, as this might be very time-consuming...)
128
if
(!kin.cuts().central.contain((*event)(
Particle::Role::CentralSystem
)))
129
return
0.;
130
if
(!kin.cuts().central_particles.empty())
131
for
(
const
auto
& part : (*event)(
Particle::Role::CentralSystem
)) {
132
// retrieve all cuts associated to this final state particle in the central system
133
if
(kin.cuts().central_particles.count(part.pdgId()) > 0 &&
134
!kin.cuts().central_particles.at(part.pdgId()).contain({part}))
135
return
0.;
136
}
137
if
(!kin.incomingBeams().positive().elastic() &&
138
!kin.cuts().remnants.contain((*event)(
Particle::Role::OutgoingBeam1
), event))
139
return
0.;
140
if
(!kin.incomingBeams().negative().elastic() &&
141
!kin.cuts().remnants.contain((*event)(
Particle::Role::OutgoingBeam2
), event))
142
return
0.;
143
144
if
(storage_) {
145
// add generation metadata to the event
146
event
->metadata[
"weight"
] = weight;
147
event
->metadata[
"time:total"
] = tmr_->elapsed();
148
}
149
150
CG_DEBUG_LOOP
(
"ProcessIntegrand"
) <<
"[process "
<< std::hex << (
void
*)process_.get() << std::dec <<
"]\n\t"
151
<<
"Generation time: "
<<
event
->metadata(
"time:generation"
) * 1.e3 <<
" ms\n\t"
152
<<
"Total time (gen+hadr+cuts): "
<<
event
->metadata(
"time:total"
) * 1.e3
153
<<
" ms"
;
154
155
// a bit of debugging information
156
CG_DEBUG_LOOP
(
"ProcessIntegrand"
) <<
"f value for dim-"
<< x.size() <<
" point "
<< x <<
": "
<< weight <<
"."
;
157
}
158
return
weight;
159
}
160
}
// namespace cepgen
EventBrowser.h
EventModifier.h
Event.h
Exception.h
CG_FATAL
#define CG_FATAL(mod)
Definition
Exception.h:61
Functional.h
Math.h
CG_DEBUG_LOOP
#define CG_DEBUG_LOOP(mod)
Definition
Message.h:224
CG_DEBUG
#define CG_DEBUG(mod)
Definition
Message.h:220
ProcessIntegrand.h
Process.h
RunParameters.h
TimeKeeper.h
CG_TICKER
#define CG_TICKER(tmr)
Definition
TimeKeeper.h:30
cepgen::IncomingBeams::mode
mode::Kinematics mode() const
Type of kinematics to consider for the phase space.
Definition
IncomingBeams.cpp:204
cepgen::Kinematics::setParameters
void setParameters(const ParametersList &) override
Set module parameters.
Definition
Kinematics.cpp:26
cepgen::Kinematics::incomingBeams
IncomingBeams & incomingBeams()
Beam/primary particle kinematics.
Definition
Kinematics.h:36
cepgen::Kinematics::parameters
const ParametersList & parameters() const override
List containing all parameters handled.
Definition
Kinematics.cpp:41
cepgen::NamedModule::name
const std::string & name() const
Module unique indexing name.
Definition
NamedModule.h:42
cepgen::Particle::OutgoingBeam1
@ OutgoingBeam1
outgoing beam state/particle
Definition
Particle.h:54
cepgen::Particle::OutgoingBeam2
@ OutgoingBeam2
outgoing beam state/particle
Definition
Particle.h:55
cepgen::Particle::CentralSystem
@ CentralSystem
Central particles system.
Definition
Particle.h:56
cepgen::ProcessIntegrand::process
proc::Process & process()
Thread-local physics process.
Definition
ProcessIntegrand.cpp:73
cepgen::ProcessIntegrand::ProcessIntegrand
ProcessIntegrand(const proc::Process &)
Definition
ProcessIntegrand.cpp:33
cepgen::ProcessIntegrand::eval
double eval(const std::vector< double > &x) override
Compute the integrand for a given phase space point (or "event")
Definition
ProcessIntegrand.cpp:85
cepgen::ProcessIntegrand::size
size_t size() const override
Phase space dimension.
Definition
ProcessIntegrand.cpp:45
cepgen::RunParameters
List of parameters used to start and run the simulation job.
Definition
RunParameters.h:41
cepgen::RunParameters::process
proc::Process & process()
Process object for cross-section computation/events generation.
Definition
RunParameters.cpp:105
cepgen::RunParameters::tamingFunctions
const TamingFunctionsSequence & tamingFunctions() const
List of all taming functions definitions.
Definition
RunParameters.h:133
cepgen::RunParameters::hasProcess
bool hasProcess() const
Is this parameters collection holding any physics process?
Definition
RunParameters.h:65
cepgen::RunParameters::eventModifiersSequence
EventModifiersSequence & eventModifiersSequence()
List of event modification algos List of event modification algos.
Definition
RunParameters.h:114
cepgen::proc::Process
Class template to define any process to compute using this MC integrator/events generator.
Definition
Process.h:34
cepgen::proc::Process::clearEvent
void clearEvent()
Restore the event object to its initial state.
Definition
Process.cpp:262
cepgen::proc::Process::kinematics
const Kinematics & kinematics() const
Constant reference to the process kinematics.
Definition
Process.h:50
cepgen::proc::Process::initialise
void initialise()
Initialise the process once the kinematics has been set.
Definition
Process.cpp:285
cepgen::proc::Process::clone
virtual std::unique_ptr< Process > clone() const
Copy all process attributes into a new object.
Definition
Process.cpp:85
cepgen::proc::Process::dumpVariables
void dumpVariables(std::ostream *=nullptr) const
List all variables handled by this generic process.
Definition
Process.cpp:137
cepgen::proc::Process::weight
double weight(const std::vector< double > &)
Compute the weight for a phase-space point.
Definition
Process.cpp:234
cepgen::proc::Process::ndim
size_t ndim() const
Number of dimensions on which the integration is performed.
Definition
Process.h:60
cepgen::utils::EventBrowser::get
double get(const Event &ev, const std::string &var) const
Get/compute a variable value.
Definition
EventBrowser.cpp:34
cepgen::utils::positive
bool positive(const T &val)
Check if a number is positive and finite.
Definition
Math.cpp:26
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
CepGen
Integration
ProcessIntegrand.cpp
Generated on Mon Jul 29 2024 for CepGen by
1.9.7