Belle II Software development
CRYInputModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <generators/modules/cryinput/CRYInputModule.h>
10
11#include <framework/datastore/StoreArray.h>
12#include <framework/gearbox/Unit.h>
13#include <framework/utilities/FileSystem.h>
14
15#include <string>
16#include <vector>
17#include <fstream>
18#include <stdlib.h> // For Ubuntu Linux
19
20using namespace std;
21using namespace Belle2;
22
23//-----------------------------------------------------------------
24// Register the Module
25//-----------------------------------------------------------------
26REG_MODULE(CRYInput);
27
28//-----------------------------------------------------------------
29// Implementation
30//-----------------------------------------------------------------
31
33{
34 //Set module properties
35 setDescription(R"DOC(Generates cosmic showers with CRY.
36
37The showers will be generated in the xz plane in a square plane of n bt n meters
38centered at the IP (n can be choosen with the boxLength parameter). Then the
39cosmics will be propagated from there to the boundary of the detector world volume.
40
41Finally, if the track would intersect with the acceptance volume the track is
42kept. The acceptance volume can be either a sphere, a cylinder or a box centered
43at the IP. This depends on how many values are given to the acceptance parameter.
44)DOC");
45 addParam("CosmicDataDir", m_cosmicdatadir, R"DOC(Directory that holds the cosmic
46data for CRY. Empty string will look in the default location)DOC", std::string(""));
47 addParam("acceptance", m_acceptance, R"DOC(Size of the acceptance volume.
48This can be either be:
49
501. one value being the radius of a sphere
512. two values for the radius (in xy) and the half-length (in z) of a cylinder
523. three values for x,y,z half-length of a box
53
54All volumes are centered around the IP. All values are in cm)DOC", m_acceptance);
55 addParam("maxTrials", m_maxTrials, "Maximum number of trials per event", m_maxTrials);
56 addParam("kineticEnergyThreshold", m_kineticEnergyThreshold,
57 "Energy threshold [GeV]", m_kineticEnergyThreshold);
58 addParam("timeOffset", m_timeOffset, "Time offset [s]", m_timeOffset);
59 addParam("boxLength", m_boxLength, R"DOC(Length of the side of the square in
60the xz plane in which CRY will generate cosmics in cm. Will be rounded down to
61meters. According to the CRY documentation good values are 1, 3, 10, 30, 100 and
62300m but anything in between should work as well. The default is 100m and should
63be fine for almost all use cases.)DOC", m_boxLength);
64 addParam("date", m_date, R"DOC(Date used for the generation: a string in the form of
65'month-date-year'. The cosmic-ray distribution is adjusted to account for the eleven
66year, sunspot cycle (the default solar minimum date is January 1, 2008).)DOC", m_date);
67 addParam("returnGammas", m_returnGammas,
68 "Whether or not CRY should return gammas", m_returnGammas);
69 addParam("returnKaons", m_returnKaons,
70 "Whether or not CRY should return kaons", m_returnKaons);
71 addParam("returnPions", m_returnPions,
72 "Whether or not CRY should return pions", m_returnPions);
73 addParam("returnProtons", m_returnProtons,
74 "Whether or not CRY should return protons", m_returnProtons);
75 addParam("returnNeutrons", m_returnNeutrons,
76 "Whether or not CRY should return neutrons", m_returnNeutrons);
77 addParam("returnElectrons", m_returnElectrons,
78 "Whether or not CRY should return electrons", m_returnElectrons);
79 addParam("returnMuons", m_returnMuons,
80 "Whether or not CRY should return muons", m_returnMuons);
81}
82
84{
85 if (m_cosmicdatadir.empty()) {
86 m_cosmicdatadir = FileSystem::findFile("data/generators/modules/cryinput/");
87 }
88
89 if (m_boxLength < 100 or m_boxLength > 30000) {
90 B2FATAL("Box length should be between 100 and 30000 cm (1 to 300 m)");
91 }
92
93 StoreArray<MCParticle> mcparticle;
94 mcparticle.registerInDataStore();
95
111}
112
114{
118}
119
121{
123}
bool m_returnElectrons
Whether or not CRY should return electrons.
std::string m_cosmicdatadir
cosmic data (used by CRY for interpolation).
virtual void initialize() override
Initializes the module.
virtual void event() override
Method is called for each event.
double m_boxLength
length of the sides of the square plane in which to generate cosmics
bool m_returnKaons
Whether or not CRY should return kaons.
virtual void terminate() override
Method is called at the end of the event processing.
bool m_returnMuons
Whether or not CRY should return muons.
bool m_returnGammas
Whether or not CRY should return gammas.
CRY m_generator
The CRY generator.
std::string m_date
date used for generation.
std::vector< double > m_acceptance
Shape parameters for the acceptance box.
MCParticleGraph m_mcGraph
The MCParticle graph object.
double m_kineticEnergyThreshold
kinetic energy threshold.
double m_timeOffset
time offset.
CRYInputModule()
Constructor.
bool m_returnProtons
Whether or not CRY should return protons.
bool m_returnNeutrons
Whether or not CRY should return neutrons.
bool m_returnPions
Whether or not CRY should return pions.
int m_maxTrials
maximum number of trials.
void setReturnKaons(bool kaons)
Set whether or not CRY should return kaons.
Definition: CRY.h:102
void setDate(const std::string &date)
Sets the date used for generation (the cosmic-ray distribution is adjusted to account for the eleven ...
Definition: CRY.h:74
void setTimeOffset(double timeoffset)
Sets the time offset.
Definition: CRY.h:64
void setMaxTrials(int maxtrials)
Sets the maximum number of trials.
Definition: CRY.h:79
void setReturnProtons(bool protons)
Set whether or not CRY should return protons.
Definition: CRY.h:114
void setBoxLength(double length)
Set the size of the square nxn plane where CRY generates cosmics.
Definition: CRY.h:90
void setReturnGammas(bool gammas)
Set whether or not CRY should return gammas.
Definition: CRY.h:96
void setReturnElectrons(bool electrons)
Set whether or not CRY should return electrons.
Definition: CRY.h:126
void setCosmicDataDir(const std::string &cosmicdatadir)
Sets the directory that holds cosmic data.
Definition: CRY.h:52
void setReturnMuons(bool muons)
Set whether or not CRY should return muons.
Definition: CRY.h:132
void setReturnNeutrons(bool neutrons)
Set whether or not CRY should return neutrons.
Definition: CRY.h:120
void setKineticEnergyThreshold(double kineticenergythreshold)
Sets the kinetic energy threshold, particles below that value will be ignored.
Definition: CRY.h:69
void setReturnPions(bool pions)
Set whether or not CRY should return pions.
Definition: CRY.h:108
void setAcceptance(const std::vector< double > &size)
Sets the size of the acceptance volume.
Definition: CRY.h:59
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:151
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
void init()
Initializes the generator.
Definition: CRY.cc:37
void generateEvent(MCParticleGraph &mcGraph)
Generates one single event.
Definition: CRY.cc:105
void term()
Terminates the generator.
Definition: CRY.cc:200
void clear()
Reset particles and decay information to make the class reusable.
Abstract base class for different kinds of events.
STL namespace.