Belle II Software  release-06-00-14
CLAWSModule.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/claws/modules/CLAWSModule.h>
10 #include <beast/claws/dataobjects/CLAWSSimHit.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 #include <boost/foreach.hpp>
17 
18 using namespace std;
19 
20 namespace Belle2 {
26  namespace claws {
27 
28  //We have to register the module to the Framework. The "Module" part of the
29  //class name will be appended automatically so every module hast to be named
30  //XxxModule
31  REG_MODULE(CLAWS)
32 
33 
34  CLAWSModule::CLAWSModule() : Module(), m_intParameter(0), m_doubleParameter(0), m_stringParameter("")
35  {
36  setDescription("Creates CLAWS crystals - sub-detector of BEASTII");
37 
38  //We can define parameters which can be set from the steering file. The arguments are:
39  // name, reference to the veriable where the value will be stored, description, default value
40  //If the default value is ommited the user has to specify this parameter, otherwise an error is produced
41  addParam("intParameter", m_intParameter,
42  "Useless parameter of type integer", 0);
43  addParam("doubleParameter", m_doubleParameter,
44  "Useless parameter of type double", 0.0);
45  addParam("stringParameter", m_stringParameter,
46  "Useless parameter of type string", string(""));
47  addParam("doubleListParameter", m_doubleListParameter,
48  "Useless parameter of type vector<double>", vector<double>(3, 0));
49 
50 
51  //Valid parameter types are int, double, string, bool and vectors of any of those
52  }
53 
54  void CLAWSModule::initialize()
55  {
56  B2INFO("CLAWS: Initialize");
57  //Here you can do some stuff before processing starts. If you want to
58  //write to some collections of the DataStore you have to register these
59  //here by using StoreArray<T>::registerPersistent() for collections which
60  //should be written to the output file by default or
61  //StoreArray<T>::registerTransient() for collections which will not be
62  //saved by default. If one just wants to access collections one should
63  //check if they were registered by using the isRequired member
64 
65  StoreArray<MCParticle> mcParticles;
67  RelationArray relMCSimHit(mcParticles, simHits);
68  if (!(mcParticles.isRequired() && simHits.isRequired() && relMCSimHit.isRequired())) {
69  //Fatal is not neccessary here as the storeArrays should just look
70  //empty if not registered but let's make sure everything is present
71  B2FATAL("Not all collections found, exiting processing");
72  }
73  }
74 
75  void CLAWSModule::beginRun()
76  {
77  B2INFO("CLAWS: Begin of new run");
78  //Here comes the initialisation specific to each run
79  }
80 
81  void CLAWSModule::event()
82  {
83  B2INFO("CLAWS: Event is being processed");
84  //Here comes the actual event processing
85 
86  StoreArray<MCParticle> mcParticles;
88 
89  //RelationIndex is a readonly, bidirectional index for a Relation so that one
90  //can easily use the RelationArray without looping over it manually.
91  RelationIndex<MCParticle, CLAWSSimHit> relMCSimHit(mcParticles, simHits);
92 
93  //Lets loop over all created CLAWSSimHits:
94  //int nSimHits = simHits.getEntries();
95  //for (int i = 0; i < nSimHits; ++i) {
96  //CLAWSSimHit& hit = *simHits[i];
97  //Find all MCParticles which point to that SimHit and the corresponding weight
98  //RelationIndex<MCParticle, CLAWSSimHit>::range_to range = relMCSimHit.getElementsTo(hit);
99  //for (; range.first != range.second; ++range.first) {
100  //And Print something about the relation
101  //const RelationIndex<MCParticle, CLAWSSimHit>::Element& relation = *range.to;
102  //B2INFO("CLAWSSimHit #" << i << " has an energy deposition of " << hit.getEnergyDep()
103  // << " and is related to MCParticle #" << relation.indexFrom
104  // << " which has an PDG code of " << relation.from->getPDG());
105  //}
106  //}
107 
108  //Now let's do it the other way round:
109  int nMCParticles = mcParticles.getEntries();
110  for (int i = 0; i < nMCParticles; ++i) {
111  MCParticle& mcp = *mcParticles[i];
112  //Find all CLAWSSimHits which point from that MCParticle using a typedef and BOOST_FOREACH
113  //The typedef is needed as BOOST_FOREACH is a macro and cannot handle anything including a comma
114  typedef RelationIndex<MCParticle, CLAWSSimHit>::Element relMCSimHit_Element;
115  BOOST_FOREACH(const relMCSimHit_Element & relation, relMCSimHit.getElementsFrom(mcp)) {
116  B2INFO("MCParticle #" << i << " created the AwesomSimHit #" << relation.indexTo
117  << " which has an energy deposition of " << relation.to->getEnergyDep());
118  }
119  }
120  }
121 
122  void CLAWSModule::endRun()
123  {
124  B2INFO("CLAWS: End of run");
125  //Here cleanup after each run
126  }
127 
128 
129  void CLAWSModule::terminate()
130  {
131  B2INFO("CLAWS: Terminate");
132  //Here final cleanup
133  }
134 
135  } //claws namespace
137 } //Belle2 namespace
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
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.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
The CLAWS module.
Definition: CLAWSModule.h:30
#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.