11 #include <ecl/modules/eclTrackCalDigitMatch/ECLTrackCalDigitMatchModule.h>
14 #include <framework/logging/Logger.h>
15 #include <framework/dataobjects/Helix.h>
18 #include <mdst/dataobjects/TrackFitResult.h>
19 #include <mdst/dataobjects/Track.h>
22 #include <ecl/geometry/ECLGeometryPar.h>
23 #include <ecl/dataobjects/ECLCalDigit.h>
26 #include <analysis/dataobjects/ECLEnergyCloseToTrack.h>
31 #define TWOPI 6.28318530718
45 setDescription(
"Find ECLCalDigits closest to a track (this is *not* a track to cluster matcher)");
46 addParam(
"extRadius", m_extRadius,
"radius to which tracks are extrapolated [cm]", 130.00);
47 addParam(
"angleFWDGap", m_angleFWDGap,
"FWD gap angle [deg]", 31.80);
48 addParam(
"angleBWDGap", m_angleBWDGap,
"BWD gap angle [deg]", 129.70);
49 addParam(
"trackHypothesis", m_trackHypothesis,
"Track hypothesis (PDG code) used in extrapolation", 11);
50 setPropertyFlags(c_ParallelProcessingCertified);
57 m_eclCalDigits.isRequired();
58 m_tracks.isRequired();
61 m_anaEnergyCloseToTrack.registerInDataStore();
64 m_tracks.registerRelationTo(m_anaEnergyCloseToTrack);
70 m_extZFWD = m_extRadius / std::tan(m_angleFWDGap * 0.0174533);
71 m_extZBWD = m_extRadius / std::tan(m_angleBWDGap * 0.0174533);
72 B2DEBUG(50,
"m_extZFWD: " << m_extZFWD <<
", m_extZBWD: " << m_extZBWD);
75 for (
unsigned int i = 0; i < 144; ++i) {
76 const unsigned thetaFWDEndcap = 12;
77 const unsigned thetaFWDBarrel = 13;
78 m_FWD3Barrel[i] = { geom->GetCellID(thetaFWDBarrel, (i == 0) ? 143 : i - 1) + 1,
79 geom->GetCellID(thetaFWDBarrel, i) + 1,
80 geom->GetCellID(thetaFWDBarrel, (i == 143) ? 0 : i + 1) + 1
83 m_FWD3Endcap[i] = { geom->GetCellID(thetaFWDEndcap, (i == 0) ? 143 : i - 1) + 1,
84 geom->GetCellID(thetaFWDEndcap, i) + 1,
85 geom->GetCellID(thetaFWDEndcap, (i == 143) ? 0 : i + 1) + 1
88 const unsigned thetaBWDEndcap = 59;
89 const unsigned thetaBWDBarrel = 58;
90 m_BWD3Barrel[i] = { geom->GetCellID(thetaBWDBarrel, (i == 0) ? 143 : i - 1) + 1,
91 geom->GetCellID(thetaBWDBarrel, i) + 1,
92 geom->GetCellID(thetaBWDBarrel, (i == 143) ? 0 : i + 1) + 1
95 m_BWD3Endcap[i] = { geom->GetCellID(thetaBWDEndcap, (i == 0) ? 143 : i - 1) + 1,
96 geom->GetCellID(thetaBWDEndcap, i) + 1,
97 geom->GetCellID(thetaBWDEndcap, (i == 143) ? 0 : i + 1) + 1
101 m_eclCalDigitsArray.resize(8736 + 1);
108 memset(&m_eclCalDigitsArray[0], -1, m_eclCalDigitsArray.size() *
sizeof m_eclCalDigitsArray[0]);
109 for (
int i = 0; i < m_eclCalDigits.getEntries(); i++) {
110 m_eclCalDigitsArray[m_eclCalDigits[i]->getCellId()] = i;
113 for (
const Track& track : m_tracks) {
115 const auto anainfo = m_anaEnergyCloseToTrack.appendNew();
116 track.addRelationTo(anainfo);
120 auto closestMassFitResult = track.getTrackFitResultWithClosestMass(chargedStable);
121 if (closestMassFitResult ==
nullptr)
continue;
124 const double z0 = closestMassFitResult->getZ0();
125 const double tanlambda = closestMassFitResult->getTanLambda();
128 Helix h = closestMassFitResult->getHelix();
131 const double lHelixRadius = h.getArcLength2DAtCylindricalR(m_extRadius) > 0 ? h.getArcLength2DAtCylindricalR(m_extRadius) : 999999.;
134 const double lFWD = (m_extZFWD - z0) / tanlambda > 0 ? (m_extZFWD - z0) / tanlambda : 999999.;
137 const double lBWD = (m_extZBWD - z0) / tanlambda > 0 ? (m_extZBWD - z0) / tanlambda : 999999.;
140 const double l = std::min(std::min(lHelixRadius, lFWD), lBWD);
142 B2DEBUG(50, lHelixRadius <<
" " << lFWD <<
" " << lBWD <<
" -> " << l);
144 TVector3 posHelix = h.getPositionAtArcLength2D(l);
145 const double exttheta = atan2(posHelix.Perp(), posHelix.Z());
146 const double extphi = atan2(posHelix.Y(), posHelix.X());
149 if (!isnan(exttheta)) {
151 double extphitwopi = extphi;
152 if (extphi < 0) extphitwopi = TWOPI + extphi;
153 const int phiid = extphitwopi / (TWOPI / 144);
156 double sum3FWDBarrel = 0.0;
157 double sum3FWDEndcap = 0.0;
158 double sum3BWDBarrel = 0.0;
159 double sum3BWDEndcap = 0.0;
161 for (
int i = 0; i < 3; ++i) {
162 int pos = m_eclCalDigitsArray[m_FWD3Barrel[phiid][i]];
164 sum3FWDBarrel += m_eclCalDigits[pos]->getEnergy();
166 B2DEBUG(50, phiid <<
" " << i <<
" " << m_FWD3Barrel[phiid][i] <<
" " << sum3FWDBarrel);
168 pos = m_eclCalDigitsArray[m_FWD3Endcap[phiid][i]];
170 sum3FWDEndcap += m_eclCalDigits[pos]->getEnergy();
172 B2DEBUG(50, phiid <<
" " << i <<
" " << m_FWD3Endcap[phiid][i] <<
" " << sum3FWDEndcap);
174 pos = m_eclCalDigitsArray[m_BWD3Barrel[phiid][i]];
176 sum3BWDBarrel += m_eclCalDigits[pos]->getEnergy();
178 B2DEBUG(50, phiid <<
" " << i <<
" " << m_BWD3Barrel[phiid][i] <<
" " << sum3BWDBarrel);
180 pos = m_eclCalDigitsArray[m_BWD3Endcap[phiid][i]];
182 sum3BWDEndcap += m_eclCalDigits[pos]->getEnergy();
184 B2DEBUG(50, phiid <<
" " << i <<
" " << m_BWD3Endcap[phiid][i] <<
" " << sum3BWDEndcap);
187 anainfo->setEnergy3FWDBarrel(sum3FWDBarrel);
188 anainfo->setEnergy3FWDEndcap(sum3FWDEndcap);
189 anainfo->setEnergy3BWDBarrel(sum3BWDBarrel);
190 anainfo->setEnergy3BWDEndcap(sum3BWDEndcap);
192 anainfo->setExtTheta(exttheta);
193 anainfo->setExtPhi(extphi);
194 anainfo->setExtPhiId(phiid);