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