Belle II Software  release-08-00-10
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/datastore/RelationArray.h>
21 #include <framework/logging/Logger.h>
22 #include <mdst/dataobjects/ECLCluster.h>
23 
24 /* C++ headers. */
25 #include <string>
26 
27 // NAMESPACES
28 using namespace Belle2;
29 using namespace ECL;
30 
31 //-----------------------------------------------------------------
32 // Register the Module(s)
33 //-----------------------------------------------------------------
34 REG_MODULE(ECLSplitterN2);
35 REG_MODULE(ECLSplitterN2PureCsI);
36 
37 //-----------------------------------------------------------------
38 // Implementation
39 //-----------------------------------------------------------------
40 
41 ECLSplitterN2Module::ECLSplitterN2Module() : Module(), m_eclCalDigits(eclCalDigitArrayName()),
42  m_eclConnectedRegions(eclConnectedRegionArrayName()),
43  m_eclLocalMaximums(eclLocalMaximumArrayName()),
44  m_eclShowers(eclShowerArrayName())
45 {
46  // Set description.
47  setDescription("ECLSplitterN2Module: Baseline reconstruction splitter code for the neutral hadron hypothesis.");
48 
49  // Set module parameters.
50  addParam("positionMethod", m_positionMethod, "Position determination method.", std::string("lilo"));
51  addParam("liloParameterA", m_liloParameterA, "Position determination linear-log. parameter A.", 4.0);
52  addParam("liloParameterB", m_liloParameterB, "Position determination linear-log. parameter B.", 0.0);
53  addParam("liloParameterC", m_liloParameterC, "Position determination linear-log. parameter C.", 0.0);
54 
55  // Set parallel processing flag.
57 }
58 
60 {
61  // do not delete objects here, do it in terminate()!
62 }
63 
65 {
66  // Check user input.
67  m_liloParameters.resize(3);
71 
72  // ECL dataobjects.
73  m_eclCalDigits.registerInDataStore(eclCalDigitArrayName());
75  m_eclShowers.registerInDataStore(eclShowerArrayName());
76 
77  // Register relations (we probably dont need all, but keep them for now for debugging).
78  m_eclShowers.registerRelationTo(m_eclConnectedRegions);
79  m_eclShowers.registerRelationTo(m_eclCalDigits);
80  m_eclShowers.registerRelationTo(m_eclLocalMaximums);
81 
82 }
83 
85 {
86  ;
87 }
88 
90 {
91  B2DEBUG(175, "ECLCRSplitterN2Module::event()");
92 
93  // Loop over all connected regions (CR_.
94  for (auto& aCR : m_eclConnectedRegions) {
95  unsigned int iShower = 1;
96 
97  const auto aECLShower = m_eclShowers.appendNew();
98 
99  // Add relation to the CR.
100  aECLShower->addRelationTo(&aCR);
101 
102  // Loop over all local maximums (LM).
103  for (auto& aLM : aCR.getRelationsWith<ECLLocalMaximum>(eclLocalMaximumArrayName())) {
104  // Add relation to the CR.
105  aECLShower->addRelationTo(&aLM);
106  }
107 
108  // Prepare shower variables.
109  double highestEnergy = 0.0;
110  double highestEnergyTime = 0.;
111  double highestEnergyTimeResolution = 0.;
112  double weightSum = 0.0;
113  double energySum = 0.0;
114  unsigned int highestEnergyID = 0;
115  std::vector< ECLCalDigit > digits;
116  std::vector< double > weights;
117 
118  // Loop over all digits that are related to the CR, they can be weighted (in the future?).
119  auto relatedDigitsPairs = aCR.getRelationsTo<ECLCalDigit>(eclCalDigitArrayName());
120  for (unsigned int iRel = 0; iRel < relatedDigitsPairs.size(); iRel++) {
121  const auto aECLCalDigit = relatedDigitsPairs.object(iRel);
122  const auto weight = relatedDigitsPairs.weight(iRel);
123 
124  // Add Relation to ECLCalDigits.
125  aECLShower->addRelationTo(aECLCalDigit, weight);
126 
127  // Find highest energetic crystal, its time, and its time resolution. This is not neceessarily the LM!
128  const double energyDigit = aECLCalDigit->getEnergy();
129  if (energyDigit > highestEnergy) {
130  highestEnergy = energyDigit * weight;
131  highestEnergyID = aECLCalDigit->getCellId();
132  highestEnergyTime = aECLCalDigit->getTime();
133  highestEnergyTimeResolution = aECLCalDigit->getTimeResolution();
134  }
135 
136  digits.push_back(*aECLCalDigit);
137  weights.push_back(weight);
138 
139  weightSum += weight;
140  energySum += energyDigit * weight;
141 
142  }
143 
144  const ROOT::Math::XYZVector& showerposition = Belle2::ECL::computePositionLiLo(digits, weights, m_liloParameters);
145  aECLShower->setTheta(showerposition.Theta());
146  aECLShower->setPhi(showerposition.Phi());
147  aECLShower->setR(showerposition.R());
148 
149  aECLShower->setEnergy(energySum);
150  aECLShower->setEnergyRaw(energySum);
151  aECLShower->setEnergyHighestCrystal(highestEnergy);
152  aECLShower->setCentralCellId(highestEnergyID);
153  aECLShower->setTime(highestEnergyTime);
154  aECLShower->setDeltaTime99(highestEnergyTimeResolution);
155  aECLShower->setNumberOfCrystals(weightSum);
156 
157  aECLShower->setShowerId(iShower);
158  aECLShower->setHypothesisId(Belle2::ECLShower::c_neutralHadron);
159  aECLShower->setConnectedRegionId(aCR.getCRId());
160 
161  B2DEBUG(175, "N2 shower " << iShower);
162  B2DEBUG(175, " theta = " << aECLShower->getTheta());
163  B2DEBUG(175, " phi = " << aECLShower->getPhi());
164  B2DEBUG(175, " R = " << aECLShower->getR());
165  B2DEBUG(175, " energy = " << aECLShower->getEnergy());
166  B2DEBUG(175, " time = " << aECLShower->getTime());
167  B2DEBUG(175, " time resolution = " << aECLShower->getDeltaTime99());
168 
169  } // end auto& aCR
170 
171 }
172 
173 
175 {
176  ;
177 }
178 
179 
181 {
182  ;
183 }
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
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 * eclShowerArrayName() const
Default name ECLShowers.
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 * 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
virtual const char * eclConnectedRegionArrayName() const
Default name ECLConnectedRegions.
virtual const char * eclLocalMaximumArrayName() const
Default name ECLLocalMaximums.
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
REG_MODULE(arichBtest)
Register the Module.
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
Abstract base class for different kinds of events.