Belle II Software development
ECLSplitterN2Module.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 <ecl/modules/eclSplitterN2/ECLSplitterN2Module.h>
11
12/* ECL headers. */
13#include <ecl/utility/Position.h>
14#include <ecl/dataobjects/ECLCalDigit.h>
15#include <ecl/dataobjects/ECLConnectedRegion.h>
16#include <ecl/dataobjects/ECLLocalMaximum.h>
17#include <ecl/dataobjects/ECLShower.h>
18
19/* Basf2 headers. */
20#include <framework/logging/Logger.h>
21
22/* C++ headers. */
23#include <string>
24
25// NAMESPACES
26using namespace Belle2;
27using namespace ECL;
28
29//-----------------------------------------------------------------
30// Register the Module(s)
31//-----------------------------------------------------------------
32REG_MODULE(ECLSplitterN2);
33REG_MODULE(ECLSplitterN2PureCsI);
34
35//-----------------------------------------------------------------
36// Implementation
37//-----------------------------------------------------------------
38
39ECLSplitterN2Module::ECLSplitterN2Module() : Module(), m_eclCalDigits(eclCalDigitArrayName()),
40 m_eclConnectedRegions(eclConnectedRegionArrayName()),
41 m_eclLocalMaximums(eclLocalMaximumArrayName()),
42 m_eclShowers(eclShowerArrayName())
43{
44 // Set description.
45 setDescription("ECLSplitterN2Module: Baseline reconstruction splitter code for the neutral hadron hypothesis.");
46
47 // Set module parameters.
48 addParam("positionMethod", m_positionMethod, "Position determination method.", std::string("lilo"));
49 addParam("liloParameterA", m_liloParameterA, "Position determination linear-log. parameter A.", 4.0);
50 addParam("liloParameterB", m_liloParameterB, "Position determination linear-log. parameter B.", 0.0);
51 addParam("liloParameterC", m_liloParameterC, "Position determination linear-log. parameter C.", 0.0);
52
53 // Set parallel processing flag.
55}
56
58{
59 // do not delete objects here, do it in terminate()!
60}
61
63{
64 // Check user input.
65 m_liloParameters.resize(3);
69
70 // ECL dataobjects.
73 m_eclShowers.isRequired(eclShowerArrayName());
74
75 // All the relations are already registered by ECLSplitterN1
76 m_eclShowers.requireRelationTo(m_eclConnectedRegions);
77 m_eclShowers.requireRelationTo(m_eclCalDigits);
78 m_eclShowers.requireRelationTo(m_eclLocalMaximums);
79
80}
81
83{
84 ;
85}
86
88{
89 B2DEBUG(175, "ECLCRSplitterN2Module::event()");
90
91 // Loop over all connected regions (CR_.
92 for (auto& aCR : m_eclConnectedRegions) {
93 unsigned int iShower = 1;
94
95 const auto aECLShower = m_eclShowers.appendNew();
96
97 // Add relation to the CR.
98 aECLShower->addRelationTo(&aCR);
99
100 // Loop over all local maximums (LM).
101 for (auto& aLM : aCR.getRelationsWith<ECLLocalMaximum>(eclLocalMaximumArrayName())) {
102 // Add relation to the CR.
103 aECLShower->addRelationTo(&aLM);
104 }
105
106 // Prepare shower variables.
107 double highestEnergy = 0.0;
108 double highestEnergyTime = 0.;
109 double highestEnergyTimeResolution = 0.;
110 double weightSum = 0.0;
111 double energySum = 0.0;
112 unsigned int highestEnergyID = 0;
113 std::vector< ECLCalDigit > digits;
114 std::vector< double > weights;
115
116 // Loop over all digits that are related to the CR, they can be weighted (in the future?).
117 auto relatedDigitsPairs = aCR.getRelationsTo<ECLCalDigit>(eclCalDigitArrayName());
118 for (unsigned int iRel = 0; iRel < relatedDigitsPairs.size(); iRel++) {
119 const auto aECLCalDigit = relatedDigitsPairs.object(iRel);
120 const auto weight = relatedDigitsPairs.weight(iRel);
121
122 // Add Relation to ECLCalDigits.
123 aECLShower->addRelationTo(aECLCalDigit, weight);
124
125 // Find highest energetic crystal, its time, and its time resolution. This is not neceessarily the LM!
126 const double energyDigit = aECLCalDigit->getEnergy();
127 if (energyDigit > highestEnergy) {
128 highestEnergy = energyDigit * weight;
129 highestEnergyID = aECLCalDigit->getCellId();
130 highestEnergyTime = aECLCalDigit->getTime();
131 highestEnergyTimeResolution = aECLCalDigit->getTimeResolution();
132 }
133
134 digits.push_back(*aECLCalDigit);
135 weights.push_back(weight);
136
137 weightSum += weight;
138 energySum += energyDigit * weight;
139
140 }
141
142 const ROOT::Math::XYZVector& showerposition = Belle2::ECL::computePositionLiLo(digits, weights, m_liloParameters);
143 aECLShower->setTheta(showerposition.Theta());
144 aECLShower->setPhi(showerposition.Phi());
145 aECLShower->setR(showerposition.R());
146
147 aECLShower->setEnergy(energySum);
148 aECLShower->setEnergyRaw(energySum);
149 aECLShower->setEnergyHighestCrystal(highestEnergy);
150 aECLShower->setCentralCellId(highestEnergyID);
151 aECLShower->setTime(highestEnergyTime);
152 aECLShower->setDeltaTime99(highestEnergyTimeResolution);
153 aECLShower->setNumberOfCrystals(weightSum);
154
155 aECLShower->setShowerId(iShower);
156 aECLShower->setHypothesisId(Belle2::ECLShower::c_neutralHadron);
157 aECLShower->setConnectedRegionId(aCR.getCRId());
158
159 B2DEBUG(175, "N2 shower " << iShower);
160 B2DEBUG(175, " theta = " << aECLShower->getTheta());
161 B2DEBUG(175, " phi = " << aECLShower->getPhi());
162 B2DEBUG(175, " R = " << aECLShower->getR());
163 B2DEBUG(175, " energy = " << aECLShower->getEnergy());
164 B2DEBUG(175, " time = " << aECLShower->getTime());
165 B2DEBUG(175, " time resolution = " << aECLShower->getDeltaTime99());
166
167 } // end auto& aCR
168
169}
170
171
173{
174 ;
175}
176
177
179{
180 ;
181}
Class to store calibrated ECLDigits: ECLCalDigits.
Definition: ECLCalDigit.h:23
Class to store local maxima (LM)
@ c_neutralHadron
CR is reconstructed as a neutral hadron (N2)
Definition: ECLShower.h:44
virtual const char * eclShowerArrayName() const
Default name ECLShowers.
double m_liloParameterB
lin-log parameter B
StoreArray< ECLShower > m_eclShowers
Store array: ECLShower.
StoreArray< ECLConnectedRegion > m_eclConnectedRegions
Store array: ECLConnectedRegion.
std::string m_positionMethod
Position calculation: lilo or linear.
virtual void initialize() override
Initialize.
StoreArray< ECLLocalMaximum > m_eclLocalMaximums
Store array: ECLLocalMaximum.
virtual void event() override
Event.
virtual const char * eclLocalMaximumArrayName() const
Default name ECLLocalMaximums.
virtual void endRun() override
End run.
virtual void terminate() override
Terminate.
virtual void beginRun() override
Begin run.
std::vector< double > m_liloParameters
lin-log parameters A, B, and C
virtual const char * eclConnectedRegionArrayName() const
Default name ECLConnectedRegions.
virtual const char * eclCalDigitArrayName() const
Default name ECLCalDigits.
double m_liloParameterA
lin-log parameter A
StoreArray< ECLCalDigit > m_eclCalDigits
Store array: ECLCalDigit.
double m_liloParameterC
lin-log parameter C
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
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:560
#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.