Belle II Software development
He3tubeModule.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 <beast/he3tube/modules/He3tubeModule.h>
10#include <beast/he3tube/dataobjects/He3tubeSimHit.h>
11#include <mdst/dataobjects/MCParticle.h>
12#include <framework/datastore/StoreArray.h>
13#include <framework/datastore/RelationArray.h>
14#include <framework/datastore/RelationIndex.h>
15#include <framework/logging/Logger.h>
16
17using namespace std;
18using namespace Belle2;
19using namespace Belle2::he3tube;
20
21//We have to register the module to the Framework. The "Module" part of the
22//class name will be appended automatically so every module hast to be named
23//XxxModule
24REG_MODULE(He3tube);
25
26
27He3tubeModule::He3tubeModule() : Module(), m_intParameter(0), m_doubleParameter(0), m_stringParameter("")
28{
29 setDescription("Creates Helium-3 tube - sub-detector of BEASTII");
30
31 //We can define parameters which can be set from the steering file. The arguments are:
32 // name, reference to the variable where the value will be stored, description, default value
33 //If the default value is omitted the user has to specify this parameter, otherwise an error is produced
34 addParam("intParameter", m_intParameter,
35 "Useless parameter of type integer", 0);
36 addParam("doubleParameter", m_doubleParameter,
37 "Useless parameter of type double", 0.0);
38 addParam("stringParameter", m_stringParameter,
39 "Useless parameter of type string", string(""));
40 addParam("doubleListParameter", m_doubleListParameter,
41 "Useless parameter of type vector<double>", vector<double>(3, 0));
42
43 //Valid parameter types are int, double, string, bool and vectors of any of those
44}
45
47{
48 B2INFO("He3tube: Initialize");
49 //Here you can do some stuff before processing starts. If you want to
50 //write to some collections of the DataStore you have to register these
51 //here by using StoreArray<T>::registerPersistent() for collections which
52 //should be written to the output file by default or
53 //StoreArray<T>::registerTransient() for collections which will not be
54 //saved by default. If one just wants to access collections one should
55 //check if they were registered by using the isRequired member
56
57 StoreArray<MCParticle> mcParticles;
59 RelationArray relMCSimHit(mcParticles, simHits);
60 if (!(mcParticles.isRequired() && simHits.isRequired() && relMCSimHit.isRequired())) {
61 //Fatal is not necessary here as the storeArrays should just look
62 //empty if not registered but let's make sure everything is present
63 B2FATAL("Not all collections found, exiting processing");
64 }
65}
66
68{
69 B2INFO("He3tube: Begin of new run");
70 //Here comes the initialisation specific to each run
71}
72
74{
75 B2INFO("He3tube: Event is being processed");
76 //Here comes the actual event processing
77
78 StoreArray<MCParticle> mcParticles;
80
81 //RelationIndex is a readonly, bidirectional index for a Relation so that one
82 //can easily use the RelationArray without looping over it manually.
83 RelationIndex<MCParticle, He3tubeSimHit> relMCSimHit(mcParticles, simHits);
84
85 //Lets loop over all created He3tubeSimHits:
86 //int nSimHits = simHits.getEntries();
87 //for (int i = 0; i < nSimHits; ++i) {
88 //He3tubeSimHit& hit = *simHits[i];
89 //Find all MCParticles which point to that SimHit and the corresponding weight
90 //RelationIndex<MCParticle, He3tubeSimHit>::range_to range = relMCSimHit.getElementsTo(hit);
91 //for (; range.first != range.second; ++range.first) {
92 //And Print something about the relation
93 //const RelationIndex<MCParticle, He3tubeSimHit>::Element& relation = *range.first;
94 //B2INFO("He3tubeSimHit #" << i << " has an energy deposition of " << hit.getEnergyDep()
95 //<< " and is related to MCParticle #" << relation.indexFrom
96 //<< " which has an PDG code of " << relation.from->getPDG());
97 //}
98 //}
99
100 //Now let's do it the other way round:
101 int nMCParticles = mcParticles.getEntries();
102 for (int i = 0; i < nMCParticles; ++i) {
103 MCParticle& mcp = *mcParticles[i];
104 // Find all He3tubeSimHits which point from that MCParticle.
105 typedef RelationIndex<MCParticle, He3tubeSimHit>::Element relMCSimHit_Element;
106 for (const relMCSimHit_Element& relation : relMCSimHit.getElementsFrom(mcp)) {
107 B2INFO("MCParticle #" << i << " created the AwesomSimHit #" << relation.indexTo
108 << " which has an energy deposition of " << relation.to->getEnergyDep());
109 }
110 }
111}
112
114{
115 B2INFO("He3tube: End of run");
116 //Here cleanup after each run
117}
118
119
121{
122 B2INFO("He3tube: Terminate");
123 //Here final cleanup
124}
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
Definition: RelationIndex.h:76
range_from getElementsFrom(const FROM *from) const
Return a range of all elements pointing from the given object.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
virtual void event()
Called for every end run.
virtual void initialize()
Init the module.
std::string m_stringParameter
Useless variable showing how to create string parameters.
Definition: He3tubeModule.h:60
virtual void beginRun()
Called for every begin run.
virtual void terminate()
Called on termination.
virtual void endRun()
Called for every end run.
double m_doubleParameter
Useless variable showing how to create double parameters.
Definition: He3tubeModule.h:57
int m_intParameter
Useless variable showing how to create integer parameters.
Definition: He3tubeModule.h:54
std::vector< double > m_doubleListParameter
Useless variable showing how to create array parameters.
Definition: He3tubeModule.h:63
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Namespace to encapsulate code needed for the HE3TUBE detector.
Abstract base class for different kinds of events.
STL namespace.