Belle II Software  release-05-02-19
CRYInputModule.cc
1 /************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2015 Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Torben Ferber *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 
11 #include <generators/modules/cryinput/CRYInputModule.h>
12 
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/gearbox/Unit.h>
15 #include <framework/utilities/FileSystem.h>
16 
17 #include <string>
18 #include <vector>
19 #include <fstream>
20 #include <stdlib.h> // For Ubuntu Linux
21 
22 using namespace std;
23 using namespace Belle2;
24 
25 //-----------------------------------------------------------------
26 // Register the Module
27 //-----------------------------------------------------------------
28 REG_MODULE(CRYInput)
29 
30 //-----------------------------------------------------------------
31 // Implementation
32 //-----------------------------------------------------------------
33 
35 {
36  //Set module properties
37  setDescription(R"DOC(Generates cosmic showers with CRY.
38 
39 The showers will be generated in the xz plane in a square plane of n bt n meters
40 centered at the IP (n can be choosen with the boxLength parameter). Then the
41 cosmics will be propagated from there to the corner of of a n times n times n
42 cube centered around the IP.
43 
44 Finally, if the track would intersect with the acceptance volume the track is
45 kept. The acceptance volume can be either a sphere, a cylinder or a box centered
46 at the IP. This depends on how many values are given to the acceptance parameter.
47 )DOC");
48  addParam("CosmicDataDir", m_cosmicdatadir, R"DOC(Directory that holds the cosmic
49 data for CRY. Empty string will look in the default location)DOC", std::string(""));
50  addParam("acceptance", m_acceptance, R"DOC(Size of the acceptance volume.
51 This can be either be:
52 
53 1. one value being the radius of a sphere
54 2. two values for the radius (in xy) and the half-length (in z) of a cylinder
55 3. three values for x,y,z half-length of a box
56 
57 All volumes are centered around the IP. All values are in cm)DOC", m_acceptance);
58  addParam("maxTrials", m_maxTrials, "Maximum number of trials per event", m_maxTrials);
59  addParam("kineticEnergyThreshold", m_kineticEnergyThreshold,
60  "Energy threshold [GeV]", m_kineticEnergyThreshold);
61  addParam("timeOffset", m_timeOffset, "Time offset [s]", m_timeOffset);
62  addParam("boxLength", m_boxLength, R"DOC(Length of the side of the square in
63 the xz plane in which CRY will generate cosmics in cm. Will be rounded down to
64 meters. According to the CRY documentation good values are 1, 3, 10, 30, 100 and
65 300m but anything in between should work as well. The default is 100m and should
66 be fine for almost all use cases.)DOC", m_boxLength);
67  addParam("date", m_date, R"DOC(Date used for the generation: a string in the form of
68 'month-date-year'. The cosmic-ray distribution is adjusted to account for the eleven
69 year, sunspot cycle (the default solar minimum date is January 1, 2008).)DOC", m_date);
70  addParam("returnGammas", m_returnGammas,
71  "Whether or not CRY should return gammas", m_returnGammas);
72  addParam("returnKaons", m_returnKaons,
73  "Whether or not CRY should return kaons", m_returnKaons);
74  addParam("returnPions", m_returnPions,
75  "Whether or not CRY should return pions", m_returnPions);
76  addParam("returnProtons", m_returnProtons,
77  "Whether or not CRY should return protons", m_returnProtons);
78  addParam("returnNeutrons", m_returnNeutrons,
79  "Whether or not CRY should return neutrons", m_returnNeutrons);
80  addParam("returnElectrons", m_returnElectrons,
81  "Whether or not CRY should return electrons", m_returnElectrons);
82  addParam("returnMuons", m_returnMuons,
83  "Whether or not CRY should return muons", m_returnMuons);
84 }
85 
86 void CRYInputModule::initialize()
87 {
88  if (m_cosmicdatadir.empty()) {
89  m_cosmicdatadir = FileSystem::findFile("data/generators/modules/cryinput/");
90  }
91 
92  if (m_boxLength < 100 or m_boxLength > 30000) {
93  B2FATAL("Box length should be between 100 and 30000 cm (1 to 300 m)");
94  }
95 
96  StoreArray<MCParticle> mcparticle;
97  mcparticle.registerInDataStore();
98 
99  m_generator.setCosmicDataDir(m_cosmicdatadir);
100  m_generator.setAcceptance(m_acceptance);
101  m_generator.setMaxTrials(m_maxTrials);
102  m_generator.setKineticEnergyThreshold(m_kineticEnergyThreshold);
103  m_generator.setTimeOffset(m_timeOffset);
104  m_generator.setBoxLength(m_boxLength);
105  m_generator.setDate(m_date);
106  m_generator.setReturnGammas(m_returnGammas);
107  m_generator.setReturnKaons(m_returnKaons);
108  m_generator.setReturnPions(m_returnPions);
109  m_generator.setReturnProtons(m_returnProtons);
110  m_generator.setReturnNeutrons(m_returnNeutrons);
111  m_generator.setReturnElectrons(m_returnElectrons);
112  m_generator.setReturnMuons(m_returnMuons);
113  m_generator.init();
114 }
115 
116 void CRYInputModule::event()
117 {
118  m_mcGraph.clear();
119  m_generator.generateEvent(m_mcGraph);
120  m_mcGraph.generateList();
121 }
122 
123 void CRYInputModule::terminate()
124 {
125  m_generator.term();
126 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::CRYInputModule
The CRY Generator module.
Definition: CRYInputModule.h:37
Belle2::StoreArray::clear
void clear() override
Delete all entries in this array.
Definition: StoreArray.h:217
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreArray< MCParticle >