8#ifndef SERVICES_GENERATORSERVICE_H_
9#define SERVICES_GENERATORSERVICE_H_
11#include <ElementaryUtils/logger/CustomException.h>
12#include <ElementaryUtils/string_utils/Formatter.h>
13#include <ElementaryUtils/string_utils/StringUtils.h>
14#include <partons/beans/automation/BaseObjectData.h>
23#include "../automation/MonteCarloTask.h"
24#include "../beans/containers/ExperimentalConditions.h"
25#include "../beans/containers/GeneralConfiguration.h"
26#include "../beans/containers/GenerationInformation.h"
27#include "../beans/other/EventGeneratorInterface.h"
29#include "../EpicVersion.h"
30#include "../managers/ModuleObjectFactory.h"
31#include "../modules/event_generator/EventGeneratorModule.h"
32#include "../modules/writer/WriterModule.h"
33#include "../modules/random_generator/RandomNumberGSL.h"
44template<
class kinRange,
class procModule,
class kinModule,
85 *(std::static_pointer_cast<RandomNumberGSL>(
93 "RECREATE",
"EpIC debugging histograms");
141 ElemUtils::Formatter() << EPIC_VERSION_MAJOR <<
"."
142 << EPIC_VERSION_MINOR <<
"." << EPIC_VERSION_PATCH);
154 * std::chrono::duration_cast<std::chrono::microseconds>(
159 * std::chrono::duration_cast<std::chrono::microseconds>(
168 ElemUtils::Formatter() <<
"Generation information:\n"
169 << generationInformation.toString() <<
'\n');
178 std::stringstream ss;
182 std::make_pair(
"lepton_polarisation", ss.str()));
191 std::make_pair(
"hadron_polarisation", ss.str()));
268 const std::shared_ptr<EventGeneratorModule> &pEventGeneratorModule) {
283 const std::shared_ptr<kinModule> &pKinematicModule) {
353 ElemUtils::Formatter() <<
"General configuration:\n"
371 ElemUtils::Formatter() <<
"Experimental conditions:\n"
391 if (ElemUtils::StringUtils::equals(
406 throw ElemUtils::CustomException(getClassName(), __func__,
407 ElemUtils::Formatter() <<
"You have not provided any "
412 ElemUtils::Formatter() <<
"Event generator module: "
432 if (ElemUtils::StringUtils::equals(
447 throw ElemUtils::CustomException(getClassName(), __func__,
448 ElemUtils::Formatter() <<
"You have not provided any "
453 ElemUtils::Formatter() <<
"Writer module: "
463 throw ElemUtils::CustomException(getClassName(), __func__,
464 "Pointer to process module in null");
468 throw ElemUtils::CustomException(getClassName(), __func__,
469 "Pointer to kineamtic module in null");
473 throw ElemUtils::CustomException(getClassName(), __func__,
474 "Pointer to radiative correction module in null");
478 throw ElemUtils::CustomException(getClassName(), __func__,
479 "Pointer to event generator module in null");
483 throw ElemUtils::CustomException(getClassName(), __func__,
484 "Pointer to writer module in null");
488 throw ElemUtils::CustomException(getClassName(), __func__,
489 "Number of events to be generated is: 0");
498 time_t now = time(0);
499 return std::string(ctime(&now));
509 const NumA::Vector3D& currentHadronPolarisation =
513 if (fabs(currentHadronPolarisation.getX()) == 1.
514 || fabs(currentHadronPolarisation.getY()) == 1.
515 || fabs(currentHadronPolarisation.getZ()) == 1.)
520 double thetaPol = acos(cosThetaPol);
525 NumA::Vector3D(sin(thetaPol) * cos(phiPol),
526 sin(thetaPol) * sin(phiPol), cos(thetaPol)));
542 virtual double getJacobian(
const std::vector<double>& variables)
const = 0;
551 "RECREATE",
"EpIC debugging histograms");
555 ElemUtils::Formatter()
556 <<
"Histogram file created successfully: "
562 ElemUtils::Formatter()
563 <<
"Failed to create histogram file: "
581 std::vector<TH1*>::const_iterator it;
583 for (it = m_histograms.begin(); it != m_histograms.end(); it++) {
590 ElemUtils::Formatter() <<
"Histogram file closed after saving "
591 << m_histograms.size() <<
" histograms");
608 std::pair<std::chrono::steady_clock::time_point,
610 std::pair<std::chrono::steady_clock::time_point,
616 std::vector<TH1*> m_histograms;
ModuleObjectFactory * getModuleObjectFactory() const
static Epic * getInstance()
Interface to EventGeneratorModule.
Definition: EventGeneratorInterface.h:22
static const std::string EVENT_GENERATOR_MODULE_CLASS_NAME
Class name used in parsing XML.
Definition: EventGeneratorModule.h:38
Container to store experimental conditions.
Definition: ExperimentalConditions.h:29
void setHadronPolarisation(const NumA::Vector3D &hadronPolarisation)
int getLeptonHelicity() const
static ExperimentalConditions fromTask(const MonteCarloTask &task)
const NumA::Vector3D & getHadronPolarisation() const
Container to store general configuration of generator.
Definition: GeneralConfiguration.h:29
static GeneralConfiguration fromTask(const MonteCarloTask &task)
const std::string & getHistogramFilePath() const
size_t getNEvents() const
Template for services handling generation of MC events.
Definition: GeneratorService.h:47
virtual void addAdditionalGenerationConfiguration(GenerationInformation &generationInformation)
Definition: GeneratorService.h:175
const std::shared_ptr< rcModule > & getRCModule() const
Definition: GeneratorService.h:290
std::pair< std::chrono::steady_clock::time_point, std::chrono::steady_clock::time_point > m_debugTimeGeneration
Timer spent for generation.
Definition: GeneratorService.h:611
const std::shared_ptr< kinModule > & getKinematicModule() const
Definition: GeneratorService.h:275
void setProcessModule(procModule *processModule)
Definition: GeneratorService.h:253
GeneralConfiguration m_generalConfiguration
General configuration.
Definition: GeneratorService.h:600
virtual void transformRanges(std::vector< KinematicRange > &ranges) const =0
void setScenarioDate(const std::string &scenarioDate)
Definition: GeneratorService.h:339
virtual void bookHistograms()
Definition: GeneratorService.h:571
void setRCModule(const std::shared_ptr< rcModule > &pRCModule)
Definition: GeneratorService.h:297
GeneratorService(const GeneratorService &other)
Definition: GeneratorService.h:66
const std::string & getScenarioDate() const
Definition: GeneratorService.h:332
virtual ~GeneratorService()
Definition: GeneratorService.h:102
GeneratorService(const std::string &className)
Definition: GeneratorService.h:53
std::shared_ptr< WriterModule > m_pWriterModule
Writer module.
Definition: GeneratorService.h:603
void getWriterModuleFromTask(const MonteCarloTask &task)
Definition: GeneratorService.h:429
void openHistogramFile()
Definition: GeneratorService.h:547
void getGeneralConfigurationFromTask(const MonteCarloTask &task)
Definition: GeneratorService.h:348
procModule * getProcessModule() const
Definition: GeneratorService.h:246
const std::shared_ptr< WriterModule > & getWriterModule() const
Definition: GeneratorService.h:304
TFile * m_histogramFile
File containing histograms.
Definition: GeneratorService.h:615
void computeTask(const MonteCarloTask &task)
Definition: GeneratorService.h:108
kinRange m_kinematicRanges
Kinematic ranges.
Definition: GeneratorService.h:595
virtual void isServiceWellConfigured() const
Definition: GeneratorService.h:460
void setGeneralConfiguration(const GeneralConfiguration &generalConfiguration)
Definition: GeneratorService.h:208
const std::shared_ptr< EventGeneratorModule > & getEventGeneratorModule() const
Definition: GeneratorService.h:260
void getExperimentalConditionsFromTask(const MonteCarloTask &task)
Definition: GeneratorService.h:366
std::string getCurrentDate() const
Definition: GeneratorService.h:496
virtual void getProcessModuleFromTask(const MonteCarloTask &task)=0
std::string m_scenarioDescription
Scenario description.
Definition: GeneratorService.h:606
std::shared_ptr< EventGeneratorModule > m_pEventGeneratorModule
Event generator module.
Definition: GeneratorService.h:602
procModule * m_pProcessModule
Process module.
Definition: GeneratorService.h:596
void setScenarioDescription(const std::string &scenarioDescription)
Definition: GeneratorService.h:325
virtual void getKinematicRangesFromTask(const MonteCarloTask &task)=0
virtual double getJacobian(const std::vector< double > &variables) const =0
void setKinematicRanges(const kinRange &kinematicRanges)
Definition: GeneratorService.h:223
std::shared_ptr< rcModule > m_pRCModule
Radiative correction module.
Definition: GeneratorService.h:598
void printAndSaveGenerationConfiguration()
Definition: GeneratorService.h:135
ExperimentalConditions m_experimentalConditions
Experimental conditions.
Definition: GeneratorService.h:601
std::shared_ptr< kinModule > m_pKinematicModule
Kinematic module.
Definition: GeneratorService.h:597
virtual void getKinematicModuleFromTask(const MonteCarloTask &task)=0
void setExperimentalConditions(const ExperimentalConditions &experimentalConditions)
Definition: GeneratorService.h:237
virtual void getRCModuleFromTask(const MonteCarloTask &task)=0
void setKinematicModule(const std::shared_ptr< kinModule > &pKinematicModule)
Definition: GeneratorService.h:282
std::pair< std::chrono::steady_clock::time_point, std::chrono::steady_clock::time_point > m_debugTimeInitialization
Timer spent for initialization.
Definition: GeneratorService.h:609
void setWriterModule(const std::shared_ptr< WriterModule > &pWriterModule)
Definition: GeneratorService.h:311
virtual void getAdditionalGeneralConfigurationFromTask(const MonteCarloTask &task)=0
void getEventGeneratorModuleFromTask(const MonteCarloTask &task)
Definition: GeneratorService.h:388
std::string m_scenarioDate
Scenario date.
Definition: GeneratorService.h:605
const ExperimentalConditions & getExperimentalConditions() const
Definition: GeneratorService.h:230
const GeneralConfiguration & getGeneralConfiguration() const
Definition: GeneratorService.h:201
void setEventGeneratorModule(const std::shared_ptr< EventGeneratorModule > &pEventGeneratorModule)
Definition: GeneratorService.h:267
const std::string & getScenarioDescription() const
Definition: GeneratorService.h:318
void checkTargetPolarisation(ExperimentalConditions &experimentalConditions) const
Definition: GeneratorService.h:505
std::shared_ptr< RandomNumberModule > m_randomNumberModule
Random number module.
Definition: GeneratorService.h:613
const kinRange & getKinematicRanges() const
Definition: GeneratorService.h:216
virtual void transformVariables(std::vector< double > &variables) const =0
void closeHistogramFile()
Definition: GeneratorService.h:577
std::shared_ptr< RandomNumberModule > newRandomNumberModule(unsigned int classId)
std::shared_ptr< WriterModule > newWriterModule(unsigned int classId)
std::shared_ptr< EventGeneratorModule > newEventGeneratorModule(unsigned int classId)
Container to store information from xml scenario for a single task.
Definition: MonteCarloTask.h:23
const PARTONS::BaseObjectData & getWriterConfiguration() const
const PARTONS::BaseObjectData & getGeneratorConfiguration() const
Generation of random numbers based on GSL.
Definition: RandomNumberGSL.h:27
static const unsigned int classId
Definition: RandomNumberGSL.h:34
static const std::string WRITER_MODULE_CLASS_NAME
Class name used in parsing XML.
Definition: WriterModule.h:35