Belle II Software  release-06-01-15
AWESOMEBasicModule.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 /* Own header. */
10 #include <online_book/awesome/modules/AWESOMEBasic/AWESOMEBasicModule.h>
11 
12 /* Belle2 headers. */
13 #include <framework/logging/Logger.h>
14 
15 /* --------- WARNING ------------------------------------------------------
16  * If you have more complex parameter types in your class then simple int,
17  * double or std::vector of those you might need to uncomment the following
18  * include directive to avoid an undefined reference on compilation.
19  * --------------------------------------------------------------------- */
20 // #include <framework/core/ModuleParam.templateDetails.h>
21 
22 using namespace Belle2;
23 using namespace Belle2::AWESOME;
24 
30 REG_MODULE(AWESOMEBasic)
31 
33  Module(),
34  m_intParameter{0},
35  m_doubleParameter{0},
36  m_stringParameter{""}
37 {
38  setDescription("Here you can enter a description of the module which can be displayed during runtime.");
39  /* We can define parameters which can be set from the steering file. The arguments are:
40  * name, reference to the veriable where the value will be stored, description, default value.
41  * If the default value is ommited the user has to specify this parameter, otherwise an error is produced. */
42  addParam("intParameter", m_intParameter,
43  "Useless parameter of type integer", 0);
44  addParam("doubleParameter", m_doubleParameter,
45  "Useless parameter of type double", 0.0);
46  addParam("stringParameter", m_stringParameter,
47  "Useless parameter of type string", std::string{""});
48  addParam("doubleListParameter", m_doubleListParameter,
49  "Useless parameter of type vector<double>", std::vector<double> {3, 0});
50 
51  //Valid parameter types are int, double, string, bool and vectors of any of those
52 }
53 
55 {
56  B2INFO("AWESOMEBasic: initialize.");
67  m_SimHits.isRequired();
69 }
70 
72 {
73  B2INFO("AWESOMEBasic: begin of new run.");
78 }
79 
81 {
82  B2INFO("AWESOMEBasic: event is being processed.");
83  /* Let's try a simple loop over the simulated hits. */
84  for (const AWESOMESimHit& hit : m_SimHits) {
89  int mcArrayIndex = -1;
90  int pdgCode = 0;
91  /* We assume there is only a single MCParticle related to the hit. */
92  MCParticle* mcParticle = hit.getRelated<MCParticle>();
93  if (mcParticle) {
94  mcArrayIndex = mcParticle->getArrayIndex();
95  pdgCode = mcParticle->getPDG();
96  }
97  B2INFO("AWESOMESimHit #" << hit.getArrayIndex()
98  << " has an energy deposition of " << hit.getEnergyDep()
99  << " and is related to MCParticle #" << mcArrayIndex
100  << " which has a PDG code " << pdgCode);
101  }
102  /* Now let's do it the other way round. */
103  for (const MCParticle& mcParticle : m_MCParticles) {
109  for (const AWESOMESimHit& hit : mcParticle.getRelationsWith<AWESOMESimHit>())
110  B2INFO("MCParticle #" << mcParticle.getArrayIndex()
111  << " which has a PDG code " << mcParticle.getPDG()
112  << " created the AWESOMESimHit #" << hit.getArrayIndex()
113  << " which has an energy deposition of " << hit.getEnergyDep());
114  }
115 }
116 
118 {
119  B2INFO("AWESOMEBasic: end of run.");
120  /* Here you can do some cleanup after each run. */
121 }
122 
123 
125 {
126  B2INFO("AWESOMEBasic: terminate.");
127  /* Here you can do some final cleanup. */
128 }
A Geant4 simulated hit for the AWESOME detector.
Definition: AWESOMESimHit.h:33
void initialize() override
Initialize the module.
void event() override
Called for each event.
void endRun() override
Called for each end of run.
void terminate() override
Called on termination.
StoreArray< AWESOMESimHit > m_SimHits
AWESOME simulated hits.
void beginRun() override
Called for each begin of run.
StoreArray< MCParticle > m_MCParticles
MC particles.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
int getArrayIndex() const
Get 0-based index of the particle in the corresponding MCParticle list.
Definition: MCParticle.h:244
int getPDG() const
Return PDG code of particle.
Definition: MCParticle.h:112
Base class for Modules.
Definition: Module.h:72
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool requireRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const
Produce error if no relation from this array to 'toArray' has been registered.
Definition: StoreArray.h:155
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.