Belle II Software  release-06-02-00
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 //This module
9 #include <ecl/modules/eclTrackCalDigitMatch/ECLTrackCalDigitMatchModule.h>
10 
11 //Framework
12 #include <framework/logging/Logger.h>
13 #include <framework/dataobjects/Helix.h>
14 #include <framework/gearbox/Const.h>
15 
16 //MDST
17 #include <mdst/dataobjects/TrackFitResult.h>
18 #include <mdst/dataobjects/Track.h>
19 
20 //ECL
21 #include <ecl/geometry/ECLGeometryPar.h>
22 #include <ecl/dataobjects/ECLCalDigit.h>
23 
24 //Analysis
25 #include <analysis/dataobjects/ECLEnergyCloseToTrack.h>
26 
27 using namespace Belle2;
28 using namespace std;
29 
30 #define TWOPI 6.28318530718
31 
32 //-----------------------------------------------------------------
33 // Register the Module
34 //-----------------------------------------------------------------
35 REG_MODULE(ECLTrackCalDigitMatch)
36 
37 //-----------------------------------------------------------------
38 // Implementation
39 //-----------------------------------------------------------------
40 
42 {
43  // Set module properties
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);
50 }
51 
53 {
54 
56  m_eclCalDigits.isRequired();
57  m_tracks.isRequired();
58 
60  m_anaEnergyCloseToTrack.registerInDataStore();
61 
63  m_tracks.registerRelationTo(m_anaEnergyCloseToTrack);
64 
65  // ECL geometry
67 
68  // based on the (fix) endcap gap positions, get the fwd and bwd z positions
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);
72 
73  // fill maps that related phi id to list of cell ids (ECLGeometryPar returns IDs from 0..)
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
80  };
81 
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
85  };
86 
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
92  };
93 
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
97  };
98  }
99 
100  m_eclCalDigitsArray.resize(8736 + 1);
101 }
102 
104 {
105 
106  // Fill a vector that can be used to map cellid -> store array position for eclCalDigits.
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;
110  }
111 
112  for (const Track& track : m_tracks) {
113 
114  const auto anainfo = m_anaEnergyCloseToTrack.appendNew();
115  track.addRelationTo(anainfo);
116 
117  // get the trackfit results for this track
118  Const::ChargedStable chargedStable(abs(m_trackHypothesis));
119  auto closestMassFitResult = track.getTrackFitResultWithClosestMass(chargedStable);
120  if (closestMassFitResult == nullptr) continue;
121 
122  // get the track parameters
123  const double z0 = closestMassFitResult->getZ0();
124  const double tanlambda = closestMassFitResult->getTanLambda();
125 
126  // use the helix class
127  Helix h = closestMassFitResult->getHelix();
128 
129  // extrapolate to radius
130  const double lHelixRadius = h.getArcLength2DAtCylindricalR(m_extRadius) > 0 ? h.getArcLength2DAtCylindricalR(m_extRadius) : 999999.;
131 
132  // extrapolate to FWD z
133  const double lFWD = (m_extZFWD - z0) / tanlambda > 0 ? (m_extZFWD - z0) / tanlambda : 999999.;
134 
135  // extrapolate to backward z
136  const double lBWD = (m_extZBWD - z0) / tanlambda > 0 ? (m_extZBWD - z0) / tanlambda : 999999.;
137 
138  // pick smalles arclength
139  const double l = std::min(std::min(lHelixRadius, lFWD), lBWD);
140 
141  B2DEBUG(50, lHelixRadius << " " << lFWD << " " << lBWD << " -> " << l);
142 
143  TVector3 posHelix = h.getPositionAtArcLength2D(l);
144  const double exttheta = atan2(posHelix.Perp(), posHelix.Z());
145  const double extphi = atan2(posHelix.Y(), posHelix.X());
146 
147  // check if the extrapolation reaches the requested radius
148  if (!isnan(exttheta)) {
149  // get the correct phi bin for this track (phi: -PI..PI, but phi-ids in ECL from 0..144)
150  double extphitwopi = extphi;
151  if (extphi < 0) extphitwopi = TWOPI + extphi;
152  const int phiid = extphitwopi / (TWOPI / 144);
153 
154  // get the energy sums
155  double sum3FWDBarrel = 0.0;
156  double sum3FWDEndcap = 0.0;
157  double sum3BWDBarrel = 0.0;
158  double sum3BWDEndcap = 0.0;
159 
160  for (int i = 0; i < 3; ++i) {
161  int pos = m_eclCalDigitsArray[m_FWD3Barrel[phiid][i]];
162  if (pos >= 0) {
163  sum3FWDBarrel += m_eclCalDigits[pos]->getEnergy();
164  }
165  B2DEBUG(50, phiid << " " << i << " " << m_FWD3Barrel[phiid][i] << " " << sum3FWDBarrel);
166 
167  pos = m_eclCalDigitsArray[m_FWD3Endcap[phiid][i]];
168  if (pos >= 0) {
169  sum3FWDEndcap += m_eclCalDigits[pos]->getEnergy();
170  }
171  B2DEBUG(50, phiid << " " << i << " " << m_FWD3Endcap[phiid][i] << " " << sum3FWDEndcap);
172 
173  pos = m_eclCalDigitsArray[m_BWD3Barrel[phiid][i]];
174  if (pos >= 0) {
175  sum3BWDBarrel += m_eclCalDigits[pos]->getEnergy();
176  }
177  B2DEBUG(50, phiid << " " << i << " " << m_BWD3Barrel[phiid][i] << " " << sum3BWDBarrel);
178 
179  pos = m_eclCalDigitsArray[m_BWD3Endcap[phiid][i]];
180  if (pos >= 0) {
181  sum3BWDEndcap += m_eclCalDigits[pos]->getEnergy();
182  }
183  B2DEBUG(50, phiid << " " << i << " " << m_BWD3Endcap[phiid][i] << " " << sum3BWDEndcap);
184  }
185 
186  anainfo->setEnergy3FWDBarrel(sum3FWDBarrel);
187  anainfo->setEnergy3FWDEndcap(sum3FWDEndcap);
188  anainfo->setEnergy3BWDBarrel(sum3BWDBarrel);
189  anainfo->setEnergy3BWDEndcap(sum3BWDEndcap);
190 
191  anainfo->setExtTheta(exttheta);
192  anainfo->setExtPhi(extphi);
193  anainfo->setExtPhiId(phiid);
194 
195  }
196 
197  }
198 }
Helix parameter class.
Definition: Helix.h:48
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:470
static const ChargedStable electron
electron particle
Definition: Const.h:540
Module to find the closest ECLCalDigits to an extrapolated track.
virtual void initialize() override
initialize
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
Base class for Modules.
Definition: Module.h:72
Class that bundles various TrackFitResults.
Definition: Track.h:25
#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.