Belle II Software development
ECLTrackCalDigitMatchModule.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/eclTrackCalDigitMatch/ECLTrackCalDigitMatchModule.h>
11
12/* ECL headers. */
13#include <ecl/dataobjects/ECLCalDigit.h>
14#include <ecl/dataobjects/ECLElementNumbers.h>
15#include <ecl/geometry/ECLGeometryPar.h>
16
17/* Basf2 headers. */
18#include <analysis/dataobjects/ECLEnergyCloseToTrack.h>
19#include <framework/dataobjects/Helix.h>
20#include <framework/gearbox/Const.h>
21#include <framework/logging/Logger.h>
22#include <mdst/dataobjects/Track.h>
23#include <mdst/dataobjects/TrackFitResult.h>
24
25using namespace Belle2;
26using namespace std;
27
28//-----------------------------------------------------------------
29// Register the Module
30//-----------------------------------------------------------------
31REG_MODULE(ECLTrackCalDigitMatch);
32
33//-----------------------------------------------------------------
34// Implementation
35//-----------------------------------------------------------------
36
38{
39 // Set module properties
40 setDescription("Find ECLCalDigits closest to a track (this is *not* a track to cluster matcher)");
41 addParam("extRadius", m_extRadius, "radius to which tracks are extrapolated [cm]", 130.00);
42 addParam("angleFWDGap", m_angleFWDGap, "FWD gap angle [deg]", 31.80);
43 addParam("angleBWDGap", m_angleBWDGap, "BWD gap angle [deg]", 129.70);
44 addParam("trackHypothesis", m_trackHypothesis, "Track hypothesis (PDG code) used in extrapolation", Const::electron.getPDGCode());
46}
47
49{
50
52 m_eclCalDigits.isRequired();
53 m_tracks.isRequired();
54
56 m_anaEnergyCloseToTrack.registerInDataStore();
57
59 m_tracks.registerRelationTo(m_anaEnergyCloseToTrack);
60
61 // ECL geometry
63
64 // based on the (fix) endcap gap positions, get the fwd and bwd z positions
65 m_extZFWD = m_extRadius / std::tan(m_angleFWDGap * 0.0174533);
66 m_extZBWD = m_extRadius / std::tan(m_angleBWDGap * 0.0174533);
67 B2DEBUG(50, "m_extZFWD: " << m_extZFWD << ", m_extZBWD: " << m_extZBWD);
68
69 // fill maps that related phi id to list of cell ids (ECLGeometryPar returns IDs from 0..)
70 for (unsigned int i = 0; i < 144; ++i) {
71 const unsigned thetaFWDEndcap = 12;
72 const unsigned thetaFWDBarrel = 13;
73 m_FWD3Barrel[i] = { geom->GetCellID(thetaFWDBarrel, (i == 0) ? 143 : i - 1) + 1,
74 geom->GetCellID(thetaFWDBarrel, i) + 1,
75 geom->GetCellID(thetaFWDBarrel, (i == 143) ? 0 : i + 1) + 1
76 };
77
78 m_FWD3Endcap[i] = { geom->GetCellID(thetaFWDEndcap, (i == 0) ? 143 : i - 1) + 1,
79 geom->GetCellID(thetaFWDEndcap, i) + 1,
80 geom->GetCellID(thetaFWDEndcap, (i == 143) ? 0 : i + 1) + 1
81 };
82
83 const unsigned thetaBWDEndcap = 59;
84 const unsigned thetaBWDBarrel = 58;
85 m_BWD3Barrel[i] = { geom->GetCellID(thetaBWDBarrel, (i == 0) ? 143 : i - 1) + 1,
86 geom->GetCellID(thetaBWDBarrel, i) + 1,
87 geom->GetCellID(thetaBWDBarrel, (i == 143) ? 0 : i + 1) + 1
88 };
89
90 m_BWD3Endcap[i] = { geom->GetCellID(thetaBWDEndcap, (i == 0) ? 143 : i - 1) + 1,
91 geom->GetCellID(thetaBWDEndcap, i) + 1,
92 geom->GetCellID(thetaBWDEndcap, (i == 143) ? 0 : i + 1) + 1
93 };
94 }
95
97}
98
100{
101
102 // Fill a vector that can be used to map cellid -> store array position for eclCalDigits.
103 memset(&m_eclCalDigitsArray[0], -1, m_eclCalDigitsArray.size() * sizeof m_eclCalDigitsArray[0]);
104 for (int i = 0; i < m_eclCalDigits.getEntries(); i++) {
105 m_eclCalDigitsArray[m_eclCalDigits[i]->getCellId()] = i;
106 }
107
108 for (const Track& track : m_tracks) {
109
110 const auto anainfo = m_anaEnergyCloseToTrack.appendNew();
111 track.addRelationTo(anainfo);
112
113 // get the trackfit results for this track
114 Const::ChargedStable chargedStable(abs(m_trackHypothesis));
115 auto closestMassFitResult = track.getTrackFitResultWithClosestMass(chargedStable);
116 if (closestMassFitResult == nullptr) continue;
117
118 // get the track parameters
119 const double z0 = closestMassFitResult->getZ0();
120 const double tanlambda = closestMassFitResult->getTanLambda();
121
122 // use the helix class
123 Helix h = closestMassFitResult->getHelix();
124
125 // extrapolate to radius
126 const double lHelixRadius = h.getArcLength2DAtCylindricalR(m_extRadius) > 0 ? h.getArcLength2DAtCylindricalR(m_extRadius) : 999999.;
127
128 // extrapolate to FWD z
129 const double lFWD = (m_extZFWD - z0) / tanlambda > 0 ? (m_extZFWD - z0) / tanlambda : 999999.;
130
131 // extrapolate to backward z
132 const double lBWD = (m_extZBWD - z0) / tanlambda > 0 ? (m_extZBWD - z0) / tanlambda : 999999.;
133
134 // pick smallest arclength
135 const double l = std::min(std::min(lHelixRadius, lFWD), lBWD);
136
137 B2DEBUG(50, lHelixRadius << " " << lFWD << " " << lBWD << " -> " << l);
138
139 ROOT::Math::XYZVector posHelix = h.getPositionAtArcLength2D(l);
140 const double exttheta = atan2(posHelix.Rho(), posHelix.Z());
141 const double extphi = atan2(posHelix.Y(), posHelix.X());
142
143 // check if the extrapolation reaches the requested radius
144 if (!isnan(exttheta)) {
145 // get the correct phi bin for this track (phi: -PI..PI, but phi-ids in ECL from 0..144)
146 double extphitwopi = extphi;
147 if (extphi < 0) extphitwopi = 2.0 * M_PI + extphi;
148 const int phiid = extphitwopi / (2.0 * M_PI / 144);
149
150 // get the energy sums
151 double sum3FWDBarrel = 0.0;
152 double sum3FWDEndcap = 0.0;
153 double sum3BWDBarrel = 0.0;
154 double sum3BWDEndcap = 0.0;
155
156 for (int i = 0; i < 3; ++i) {
157 int pos = m_eclCalDigitsArray[m_FWD3Barrel[phiid][i]];
158 if (pos >= 0) {
159 sum3FWDBarrel += m_eclCalDigits[pos]->getEnergy();
160 }
161 B2DEBUG(50, phiid << " " << i << " " << m_FWD3Barrel[phiid][i] << " " << sum3FWDBarrel);
162
163 pos = m_eclCalDigitsArray[m_FWD3Endcap[phiid][i]];
164 if (pos >= 0) {
165 sum3FWDEndcap += m_eclCalDigits[pos]->getEnergy();
166 }
167 B2DEBUG(50, phiid << " " << i << " " << m_FWD3Endcap[phiid][i] << " " << sum3FWDEndcap);
168
169 pos = m_eclCalDigitsArray[m_BWD3Barrel[phiid][i]];
170 if (pos >= 0) {
171 sum3BWDBarrel += m_eclCalDigits[pos]->getEnergy();
172 }
173 B2DEBUG(50, phiid << " " << i << " " << m_BWD3Barrel[phiid][i] << " " << sum3BWDBarrel);
174
175 pos = m_eclCalDigitsArray[m_BWD3Endcap[phiid][i]];
176 if (pos >= 0) {
177 sum3BWDEndcap += m_eclCalDigits[pos]->getEnergy();
178 }
179 B2DEBUG(50, phiid << " " << i << " " << m_BWD3Endcap[phiid][i] << " " << sum3BWDEndcap);
180 }
181
182 anainfo->setEnergy3FWDBarrel(sum3FWDBarrel);
183 anainfo->setEnergy3FWDEndcap(sum3FWDEndcap);
184 anainfo->setEnergy3BWDBarrel(sum3BWDBarrel);
185 anainfo->setEnergy3BWDEndcap(sum3BWDEndcap);
186
187 anainfo->setExtTheta(exttheta);
188 anainfo->setExtPhi(extphi);
189 anainfo->setExtPhiId(phiid);
190
191 }
192
193 }
194}
Helix parameter class.
Definition: Helix.h:48
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:589
static const ChargedStable electron
electron particle
Definition: Const.h:659
double m_extZFWD
z position (FWD) to which track is extrapolated
std::map< int, std::vector< int > > m_FWD3Endcap
map between phi id and FWD3 cell ids on the endcap side
virtual void initialize() override
initialize
int m_trackHypothesis
Track hypothesis to be used (will use closest one)
StoreArray< ECLEnergyCloseToTrack > m_anaEnergyCloseToTrack
Analysis level information attached to a track.
std::map< int, std::vector< int > > m_BWD3Barrel
map between phi id and BWD3 cell ids on the barrel side
double m_extZBWD
z position (BWD) to which track is extrapolated
double m_extRadius
radius to which track is extrapolated (using track parameters, not GEANT)
std::map< int, std::vector< int > > m_FWD3Barrel
map between phi id and FWD3 cell ids on the barrel side
StoreArray< Track > m_tracks
Required input array of Tracks.
ECL::ECLGeometryPar * geom
ECL geometry.
ECLTrackCalDigitMatchModule()
Constructor: Sets the description, the properties and the parameters of the module.
std::map< int, std::vector< int > > m_BWD3Endcap
map between phi id and BWD3 cell ids on the endcap side
StoreArray< ECLCalDigit > m_eclCalDigits
Required input array of ECLCalDigits
std::vector< int > m_eclCalDigitsArray
eclCalDigits in array
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
int GetCellID(int ThetaId, int PhiId)
Get Cell Id.
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
Class that bundles various TrackFitResults.
Definition: Track.h:25
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
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.
STL namespace.