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