9 #include <ecl/modules/eclTrackCalDigitMatch/ECLTrackCalDigitMatchModule.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/dataobjects/Helix.h>
14 #include <framework/gearbox/Const.h>
17 #include <mdst/dataobjects/TrackFitResult.h>
18 #include <mdst/dataobjects/Track.h>
21 #include <ecl/geometry/ECLGeometryPar.h>
22 #include <ecl/dataobjects/ECLCalDigit.h>
25 #include <analysis/dataobjects/ECLEnergyCloseToTrack.h>
30 #define TWOPI 6.28318530718
44 setDescription(
"Find ECLCalDigits closest to a track (this is *not* a track to cluster matcher)");
45 addParam(
"extRadius", m_extRadius,
"radius to which tracks are extrapolated [cm]", 130.00);
46 addParam(
"angleFWDGap", m_angleFWDGap,
"FWD gap angle [deg]", 31.80);
47 addParam(
"angleBWDGap", m_angleBWDGap,
"BWD gap angle [deg]", 129.70);
48 addParam(
"trackHypothesis", m_trackHypothesis,
"Track hypothesis (PDG code) used in extrapolation",
Const::electron.getPDGCode());
49 setPropertyFlags(c_ParallelProcessingCertified);
56 m_eclCalDigits.isRequired();
57 m_tracks.isRequired();
60 m_anaEnergyCloseToTrack.registerInDataStore();
63 m_tracks.registerRelationTo(m_anaEnergyCloseToTrack);
69 m_extZFWD = m_extRadius / std::tan(m_angleFWDGap * 0.0174533);
70 m_extZBWD = m_extRadius / std::tan(m_angleBWDGap * 0.0174533);
71 B2DEBUG(50,
"m_extZFWD: " << m_extZFWD <<
", m_extZBWD: " << m_extZBWD);
74 for (
unsigned int i = 0; i < 144; ++i) {
75 const unsigned thetaFWDEndcap = 12;
76 const unsigned thetaFWDBarrel = 13;
77 m_FWD3Barrel[i] = { geom->GetCellID(thetaFWDBarrel, (i == 0) ? 143 : i - 1) + 1,
78 geom->GetCellID(thetaFWDBarrel, i) + 1,
79 geom->GetCellID(thetaFWDBarrel, (i == 143) ? 0 : i + 1) + 1
82 m_FWD3Endcap[i] = { geom->GetCellID(thetaFWDEndcap, (i == 0) ? 143 : i - 1) + 1,
83 geom->GetCellID(thetaFWDEndcap, i) + 1,
84 geom->GetCellID(thetaFWDEndcap, (i == 143) ? 0 : i + 1) + 1
87 const unsigned thetaBWDEndcap = 59;
88 const unsigned thetaBWDBarrel = 58;
89 m_BWD3Barrel[i] = { geom->GetCellID(thetaBWDBarrel, (i == 0) ? 143 : i - 1) + 1,
90 geom->GetCellID(thetaBWDBarrel, i) + 1,
91 geom->GetCellID(thetaBWDBarrel, (i == 143) ? 0 : i + 1) + 1
94 m_BWD3Endcap[i] = { geom->GetCellID(thetaBWDEndcap, (i == 0) ? 143 : i - 1) + 1,
95 geom->GetCellID(thetaBWDEndcap, i) + 1,
96 geom->GetCellID(thetaBWDEndcap, (i == 143) ? 0 : i + 1) + 1
100 m_eclCalDigitsArray.resize(8736 + 1);
107 memset(&m_eclCalDigitsArray[0], -1, m_eclCalDigitsArray.size() *
sizeof m_eclCalDigitsArray[0]);
108 for (
int i = 0; i < m_eclCalDigits.getEntries(); i++) {
109 m_eclCalDigitsArray[m_eclCalDigits[i]->getCellId()] = i;
112 for (
const Track& track : m_tracks) {
114 const auto anainfo = m_anaEnergyCloseToTrack.appendNew();
115 track.addRelationTo(anainfo);
119 auto closestMassFitResult = track.getTrackFitResultWithClosestMass(chargedStable);
120 if (closestMassFitResult ==
nullptr)
continue;
123 const double z0 = closestMassFitResult->getZ0();
124 const double tanlambda = closestMassFitResult->getTanLambda();
127 Helix h = closestMassFitResult->getHelix();
130 const double lHelixRadius = h.getArcLength2DAtCylindricalR(m_extRadius) > 0 ? h.getArcLength2DAtCylindricalR(m_extRadius) : 999999.;
133 const double lFWD = (m_extZFWD - z0) / tanlambda > 0 ? (m_extZFWD - z0) / tanlambda : 999999.;
136 const double lBWD = (m_extZBWD - z0) / tanlambda > 0 ? (m_extZBWD - z0) / tanlambda : 999999.;
139 const double l = std::min(std::min(lHelixRadius, lFWD), lBWD);
141 B2DEBUG(50, lHelixRadius <<
" " << lFWD <<
" " << lBWD <<
" -> " << l);
143 TVector3 posHelix = h.getPositionAtArcLength2D(l);
144 const double exttheta = atan2(posHelix.Perp(), posHelix.Z());
145 const double extphi = atan2(posHelix.Y(), posHelix.X());
148 if (!isnan(exttheta)) {
150 double extphitwopi = extphi;
151 if (extphi < 0) extphitwopi = TWOPI + extphi;
152 const int phiid = extphitwopi / (TWOPI / 144);
155 double sum3FWDBarrel = 0.0;
156 double sum3FWDEndcap = 0.0;
157 double sum3BWDBarrel = 0.0;
158 double sum3BWDEndcap = 0.0;
160 for (
int i = 0; i < 3; ++i) {
161 int pos = m_eclCalDigitsArray[m_FWD3Barrel[phiid][i]];
163 sum3FWDBarrel += m_eclCalDigits[pos]->getEnergy();
165 B2DEBUG(50, phiid <<
" " << i <<
" " << m_FWD3Barrel[phiid][i] <<
" " << sum3FWDBarrel);
167 pos = m_eclCalDigitsArray[m_FWD3Endcap[phiid][i]];
169 sum3FWDEndcap += m_eclCalDigits[pos]->getEnergy();
171 B2DEBUG(50, phiid <<
" " << i <<
" " << m_FWD3Endcap[phiid][i] <<
" " << sum3FWDEndcap);
173 pos = m_eclCalDigitsArray[m_BWD3Barrel[phiid][i]];
175 sum3BWDBarrel += m_eclCalDigits[pos]->getEnergy();
177 B2DEBUG(50, phiid <<
" " << i <<
" " << m_BWD3Barrel[phiid][i] <<
" " << sum3BWDBarrel);
179 pos = m_eclCalDigitsArray[m_BWD3Endcap[phiid][i]];
181 sum3BWDEndcap += m_eclCalDigits[pos]->getEnergy();
183 B2DEBUG(50, phiid <<
" " << i <<
" " << m_BWD3Endcap[phiid][i] <<
" " << sum3BWDEndcap);
186 anainfo->setEnergy3FWDBarrel(sum3FWDBarrel);
187 anainfo->setEnergy3FWDEndcap(sum3FWDEndcap);
188 anainfo->setEnergy3BWDBarrel(sum3BWDBarrel);
189 anainfo->setEnergy3BWDEndcap(sum3BWDEndcap);
191 anainfo->setExtTheta(exttheta);
192 anainfo->setExtPhi(extphi);
193 anainfo->setExtPhiId(phiid);
Provides a type-safe way to pass members of the chargedStableSet set.
static const ChargedStable electron
electron particle
Module to find the closest ECLCalDigits to an extrapolated track.
virtual void initialize() override
initialize
virtual void event() override
event
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
Class that bundles various TrackFitResults.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.