Belle II Software  release-05-02-19
CLAWSModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Susanne Koblitz *
7  * *
8  **************************************************************************/
9 
10 #include <beast/claws/modules/CLAWSModule.h>
11 #include <beast/claws/dataobjects/CLAWSSimHit.h>
12 #include <mdst/dataobjects/MCParticle.h>
13 #include <framework/datastore/StoreArray.h>
14 #include <framework/datastore/RelationArray.h>
15 #include <framework/datastore/RelationIndex.h>
16 #include <framework/logging/Logger.h>
17 #include <boost/foreach.hpp>
18 
19 using namespace std;
20 
21 namespace Belle2 {
27  namespace claws {
28 
29  //We have to register the module to the Framework. The "Module" part of the
30  //class name will be appended automatically so every module hast to be named
31  //XxxModule
32  REG_MODULE(CLAWS)
33 
34 
35  CLAWSModule::CLAWSModule() : Module(), m_intParameter(0), m_doubleParameter(0), m_stringParameter("")
36  {
37  setDescription("Creates CLAWS crystals - sub-detector of BEASTII");
38 
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", string(""));
48  addParam("doubleListParameter", m_doubleListParameter,
49  "Useless parameter of type vector<double>", vector<double>(3, 0));
50 
51 
52  //Valid parameter types are int, double, string, bool and vectors of any of those
53  }
54 
55  void CLAWSModule::initialize()
56  {
57  B2INFO("CLAWS: Initialize");
58  //Here you can do some stuff before processing starts. If you want to
59  //write to some collections of the DataStore you have to register these
60  //here by using StoreArray<T>::registerPersistent() for collections which
61  //should be written to the output file by default or
62  //StoreArray<T>::registerTransient() for collections which will not be
63  //saved by default. If one just wants to access collections one should
64  //check if they were registered by using the isRequired member
65 
66  StoreArray<MCParticle> mcParticles;
68  RelationArray relMCSimHit(mcParticles, simHits);
69  if (!(mcParticles.isRequired() && simHits.isRequired() && relMCSimHit.isRequired())) {
70  //Fatal is not neccessary here as the storeArrays should just look
71  //empty if not registered but let's make sure everything is present
72  B2FATAL("Not all collections found, exiting processing");
73  }
74  }
75 
76  void CLAWSModule::beginRun()
77  {
78  B2INFO("CLAWS: Begin of new run");
79  //Here comes the initialisation specific to each run
80  }
81 
82  void CLAWSModule::event()
83  {
84  B2INFO("CLAWS: Event is being processed");
85  //Here comes the actual event processing
86 
87  StoreArray<MCParticle> mcParticles;
89 
90  //RelationIndex is a readonly, bidirectional index for a Relation so that one
91  //can easily use the RelationArray without looping over it manually.
92  RelationIndex<MCParticle, CLAWSSimHit> relMCSimHit(mcParticles, simHits);
93 
94  //Lets loop over all created CLAWSSimHits:
95  //int nSimHits = simHits.getEntries();
96  //for (int i = 0; i < nSimHits; ++i) {
97  //CLAWSSimHit& hit = *simHits[i];
98  //Find all MCParticles which point to that SimHit and the corresponding weight
99  //RelationIndex<MCParticle, CLAWSSimHit>::range_to range = relMCSimHit.getElementsTo(hit);
100  //for (; range.first != range.second; ++range.first) {
101  //And Print something about the relation
102  //const RelationIndex<MCParticle, CLAWSSimHit>::Element& relation = *range.to;
103  //B2INFO("CLAWSSimHit #" << i << " has an energy deposition of " << hit.getEnergyDep()
104  // << " and is related to MCParticle #" << relation.indexFrom
105  // << " which has an PDG code of " << relation.from->getPDG());
106  //}
107  //}
108 
109  //Now let's do it the other way round:
110  int nMCParticles = mcParticles.getEntries();
111  for (int i = 0; i < nMCParticles; ++i) {
112  MCParticle& mcp = *mcParticles[i];
113  //Find all CLAWSSimHits which point from that MCParticle using a typedef and BOOST_FOREACH
114  //The typedef is needed as BOOST_FOREACH is a macro and cannot handle anything including a comma
115  typedef RelationIndex<MCParticle, CLAWSSimHit>::Element relMCSimHit_Element;
116  BOOST_FOREACH(const relMCSimHit_Element & relation, relMCSimHit.getElementsFrom(mcp)) {
117  B2INFO("MCParticle #" << i << " created the AwesomSimHit #" << relation.indexTo
118  << " which has an energy deposition of " << relation.to->getEnergyDep());
119  }
120  }
121  }
122 
123  void CLAWSModule::endRun()
124  {
125  B2INFO("CLAWS: End of run");
126  //Here cleanup after each run
127  }
128 
129 
130  void CLAWSModule::terminate()
131  {
132  B2INFO("CLAWS: Terminate");
133  //Here final cleanup
134  }
135 
136  } //claws namespace
138 } //Belle2 namespace
Belle2::RelationArray
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:72
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::RelationIndex
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
Definition: RelationIndex.h:84
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::RelationIndexContainer::Element
Element type for the index.
Definition: RelationIndexContainer.h:62
Belle2::StoreAccessorBase::isRequired
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Definition: StoreAccessorBase.h:80
Belle2::RelationIndex::getElementsFrom
range_from getElementsFrom(const FROM *from) const
Return a range of all elements pointing from the given object.
Definition: RelationIndex.h:157
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::StoreArray< MCParticle >
Belle2::claws::CLAWSModule
The CLAWS module.
Definition: CLAWSModule.h:38
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226