cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
SpringGeneratorWorker.cpp
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 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
26#include "CepGen/Utils/String.h"
29
30namespace cepgen {
32 public:
33 explicit SpringGeneratorWorker(const ParametersList& params)
34 : GeneratorWorker(params), max_trials_(steer<int>("maxTrials")) {
35 bscntl_.ipnt = steer<int>("verbose");
36 }
38 int lu = 6;
39 spinfo_(lu);
40 }
41
42 void initialise() override {
43 gIntegrand = dynamic_cast<Integrand*>(integrand_.get());
44 sprng2_.mxtryp = max_trials_;
45 sprng2_.nevent = 0;
46 }
47 bool next() override {
48 if (!integrator_)
49 throw CG_FATAL("SpringGeneratorWorker:next") << "No integrator object handled!";
50 if (integrator_->name() != "bases")
51 throw CG_FATAL("SpringGeneratorWorker:next") << "Spring generator is only compatible with Bases integrator.";
52
53 CG_TICKER(const_cast<RunParameters*>(params_)->timeKeeper());
54
55 sprng2_.ntrial = 0;
56 sprng2_.miss = 0;
57 int mxtry = max_trials_;
58 spring_(integrand_call, mxtry);
59 if (sprng2_.miss)
60 return false;
61
62 // return with an accepted event
63 return storeEvent();
64 }
65
67 auto desc = GeneratorWorker::description();
68 desc.setDescription("Spring/Bases worker");
69 desc.add<int>("maxTrials", 50).setDescription("maximum number of trials per generation");
70 desc.add<int>("verbose", 0);
71 return desc;
72 }
73
74 private:
75 static Integrand* gIntegrand;
76 static double integrand_call(double in[]) {
77 if (!gIntegrand)
78 throw CG_FATAL("SpringGeneratorWorker") << "Integrand was not specified before event generation.";
79 return gIntegrand->eval(std::vector<double>(in, in + gIntegrand->size()));
80 }
81
82 const int max_trials_;
83 };
84 Integrand* SpringGeneratorWorker::gIntegrand = nullptr;
85} // namespace cepgen
86REGISTER_GENERATOR_WORKER("spring", SpringGeneratorWorker);
void spinfo_(int &)
void spring_(double(*func)(double *), int &mxtry)
struct @4 bscntl_
struct @5 sprng2_
#define CG_FATAL(mod)
Definition Exception.h:61
#define REGISTER_GENERATOR_WORKER(name, obj)
Add a generator worker to the list of handled modules.
#define CG_TICKER(tmr)
Definition TimeKeeper.h:30
Event generator worker instance.
std::unique_ptr< ProcessIntegrand > integrand_
Local event weight evaluator.
const RunParameters * params_
Steering parameters for the event generation.
bool storeEvent()
Store the event in the output file.
static ParametersDescription description()
const Integrator * integrator_
Pointer to the mother-handled integrator instance.
An integrand wrapper placeholder.
Definition Integrand.h:27
virtual double eval(const std::vector< double > &)=0
Compute the integrand for a given coordinates set.
virtual size_t size() const =0
Phase space dimension.
const std::string & name() const
Module unique indexing name.
Definition NamedModule.h:42
A description object for parameters collection.
List of parameters used to start and run the simulation job.
SpringGeneratorWorker(const ParametersList &params)
static ParametersDescription description()
void initialise() override
Initialise the generation parameters.
bool next() override
Generate a single event.
T steer(const std::string &key) const
Retrieve a parameters as previously steered.
Definition Steerable.h:39
Common namespace for this Monte Carlo generator.