Belle II Software development
NDFinder.h
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#pragma once
10
11#include <string>
12#include <vector>
13#include <array>
14#include <utility>
15#include <Math/Vector3D.h>
16#include "trg/cdc/NDFinderDefs.h"
17#include "trg/cdc/Clusterizend.h"
18
19namespace Belle2 {
24
28 unsigned short minSuperAxial;
30 unsigned short minSuperStereo;
32 unsigned short iterations;
34 unsigned short omegaTrim;
36 unsigned short phiTrim;
40 std::string axialFile;
41 std::string stereoFile;
42 };
43
45 struct HitInfo {
46 unsigned short hitID;
47 unsigned short hitSLID;
48 unsigned short hitPrioPos;
49 short hitPrioTime;
50 };
51
54 public:
56 NDFinderTrack(std::array<double, 3> estimatedParameters,
57 SimpleCluster&& cluster,
58 std::vector<ROOT::Math::XYZVector>&& readoutHoughSpace,
59 std::vector<ROOT::Math::XYZVector>&& readoutCluster)
60 : m_cluster(std::move(cluster)),
61 m_houghSpace(std::move(readoutHoughSpace)),
62 m_readoutCluster(std::move(readoutCluster))
63 {
64 m_omega = estimatedParameters[0];
65 m_phi = estimatedParameters[1];
66 m_cot = estimatedParameters[2];
67 }
68
70 double getOmega() const { return m_omega; }
72 double getPhi0() const { return m_phi; }
74 double getCot() const { return m_cot; }
76 std::vector<unsigned short> getRelatedHits() const { return m_cluster.getClusterHits(); }
78 std::vector<ROOT::Math::XYZVector> getHoughSpace() const { return m_houghSpace; }
80 std::vector<ROOT::Math::XYZVector> getClusterReadout() const { return m_readoutCluster; }
81
82 private:
84 double m_omega;
86 double m_phi;
88 double m_cot;
92 std::vector<ROOT::Math::XYZVector> m_houghSpace;
94 std::vector<ROOT::Math::XYZVector> m_readoutCluster;
95 };
96
97
99 class NDFinder {
100 public:
103 unsigned short omega;
104 unsigned short phi;
105 unsigned short cot;
106 unsigned short nHitIDs;
107 unsigned short nPriorityWires;
108 };
109
111 struct WireInfo {
112 unsigned short relativeWireID;
113 unsigned short phiSectorStart;
114 unsigned short priorityWire;
115 };
116
119 unsigned short hitIndex;
120 unsigned short contribution;
121 unsigned short superLayer;
122 short priorityTime;
123 };
124
125 // Default constructor
126 NDFinder() = default;
127
128 // Destructor
129 virtual ~NDFinder()
130 {
131 delete m_hitToSectorIDs;
132 delete m_compAxialHitReps;
133 delete m_compStereoHitReps;
134 delete m_expAxialHitReps;
135 delete m_expStereoHitReps;
136 delete m_houghSpace;
137 }
138
140 void init(const NDFinderParameters& ndFinderParameters);
142 void reset();
144 void addHit(const HitInfo& hitInfo);
146 void findTracks();
148 std::vector<NDFinderTrack>* getFinderTracks() { return &m_ndFinderTracks; }
149
150 // NDFinder: Internal functions for track finding
151 protected:
153 void initLookUpArrays();
155 void initHitToSectorMap();
157 void loadCompressedHitReps(const std::string& fileName, const SectorBinning& compBins, c5array& compHitsToWeights);
159 void fillExpandedHitReps(const SectorBinning& compBins, const c5array& compHitsToWeights, c5array& expHitsToWeights);
161 void processHitForHoughSpace(const unsigned short hitIdx);
163 void writeHitToHoughSpace(const WireInfo& hitInfo, const c5array& expHitsToWeights);
165 void runTrackFinding();
167 std::vector<SimpleCluster> relateHitsToClusters(std::vector<SimpleCluster>& clusters);
169 std::vector<std::vector<unsigned short>> getHitsVsClustersTable(const std::vector<SimpleCluster>& clusters);
171 unsigned short getHitContribution(const cell_index& peakCell, const unsigned short hitIdx);
173 std::vector<ContributionInfo> extractContributionInfos(const std::vector<unsigned short>& clusterHits);
175 int getMaximumHitInSuperLayer(const std::vector<ContributionInfo>& contributionInfos, unsigned short superLayer);
177 bool checkHitSuperLayers(const SimpleCluster& cluster);
179 std::array<double, 3> calculateCenterOfGravity(const SimpleCluster& cluster);
181 std::array<double, 3> getTrackParameterEstimate(const std::array<double, 3>& centerOfGravity);
183 std::array<double, 3> transformTrackParameters(const std::array<double, 3>& estimatedParameters);
185 static inline double getTrackRadius(double transverseMomentum) { return transverseMomentum * 1e11 / (3e8 * 1.5); }
186
187 // NDFinder: Member data stores
188 private:
190 std::vector<NDFinderTrack> m_ndFinderTracks;
192 std::vector<unsigned short> m_hitIDs;
194 std::vector<unsigned short> m_hitSLIDs;
196 std::vector<unsigned short> m_priorityWirePos;
198 std::vector<short> m_priorityWireTime;
200 unsigned short m_nHits{0};
205
206 /*
207 Since the CDC wire pattern is repeated 32 times, the hit IDs are stored for 1/32 of the CDC only.
208 The total number of 2336 TS corresponds to (41 axial + 32 stereo) * 32.
209 The number of track bins is (for example): (omega, phi, cot) = (40, 384, 9)
210 Note: The omega dimension here represents just sign(q)/(p_T[GeV/c]) (0.25 -> inf -> -inf -> -0.25 for 0 -> 19.5 -> 39)
211 */
212
213 // Track segments
214 static constexpr unsigned short m_nTS = 2336;
215 static constexpr unsigned short m_nSL = 9;
216 static constexpr unsigned short m_nAxial = 41;
217 static constexpr unsigned short m_nStereo = 32;
218 static constexpr unsigned short m_nPrio = 3;
219
220 // Full Hough space bins
221 static constexpr unsigned short m_nOmega = 40;
222 static constexpr unsigned short m_nPhi = 384;
223 static constexpr unsigned short m_nCot = 9;
224
225 // CDC symmetry in phi
226 static constexpr unsigned short m_phiGeo = 32;
227
228 // Phi sectors in the CDC
229 static constexpr unsigned short m_nPhiSector = m_nPhi / m_phiGeo;
230
231 // Data structure/binning of the compressed hit pattern files (.txt.gz files)
232 static constexpr unsigned short m_nPhiComp = 15;
235
236 // Acceptance ranges + slot sizes to convert bins to track parameters (for getBinToVal method)
237 static constexpr std::array<double, 2> m_omegaRange = {-4., 4.};
238 static constexpr std::array<double, 2> m_phiRange = {0., 11.25};
239 // These are optimized for minSuperAxial = 3 and minSuperStereo = 2
240 static constexpr std::array<double, 2> m_cotRange = {2.3849627654510415, -1.0061730449796316};
241 static constexpr double m_binSizeOmega = (m_omegaRange[1] - m_omegaRange[0]) / m_nOmega;
242 static constexpr double m_binSizePhi = (m_phiRange[1] - m_phiRange[0]) / m_nPhiSector;
243 static constexpr double m_binSizeCot = (m_cotRange[1] - m_cotRange[0]) / m_nCot;
244 static constexpr std::array<std::array<double, 2>, 3> m_acceptanceRanges = {m_omegaRange, m_phiRange, m_cotRange};
245 static constexpr std::array<double, 3> m_binSizes = {m_binSizeOmega, m_binSizePhi, m_binSizeCot};
246
247 // Array pointers to the hit representations and Hough space
268 c5array* m_compStereoHitReps = nullptr;
281 c5array* m_expStereoHitReps = nullptr;
284 };
285
286}
Clustering module.
std::vector< ROOT::Math::XYZVector > getClusterReadout() const
Cluster readout (if storeAdditionalReadout true)
Definition NDFinder.h:80
double m_cot
3D polar angle
Definition NDFinder.h:88
SimpleCluster m_cluster
The found cluster of the track, including the track segment hits.
Definition NDFinder.h:90
double getCot() const
Get the track parameter cot (z always 0)
Definition NDFinder.h:74
double getOmega() const
Get the track parameter omega (z always 0)
Definition NDFinder.h:70
double m_phi
2D azimuthal angle
Definition NDFinder.h:86
NDFinderTrack(std::array< double, 3 > estimatedParameters, SimpleCluster &&cluster, std::vector< ROOT::Math::XYZVector > &&readoutHoughSpace, std::vector< ROOT::Math::XYZVector > &&readoutCluster)
Constructor.
Definition NDFinder.h:56
std::vector< unsigned short > getRelatedHits() const
Get the number of related Hits.
Definition NDFinder.h:76
std::vector< ROOT::Math::XYZVector > m_houghSpace
Vector storing the complete Hough space for analysis.
Definition NDFinder.h:92
std::vector< ROOT::Math::XYZVector > getHoughSpace() const
Hough space readout (if storeAdditionalReadout true)
Definition NDFinder.h:78
double m_omega
2D track curvature (This is the "real" omega (curvature), i.e., sign(q)/(r_2d[cm]))
Definition NDFinder.h:84
std::vector< ROOT::Math::XYZVector > m_readoutCluster
Vector storing cluster informations for analysis.
Definition NDFinder.h:94
double getPhi0() const
Get the track parameter phi0 (z always 0)
Definition NDFinder.h:72
static constexpr unsigned short m_nPhi
Bins in the omega dimension.
Definition NDFinder.h:222
static constexpr double m_binSizeOmega
0.2
Definition NDFinder.h:241
std::vector< short > m_priorityWireTime
Drift time of the priority wire.
Definition NDFinder.h:198
std::vector< NDFinderTrack > * getFinderTracks()
Retreive the results.
Definition NDFinder.h:148
static constexpr unsigned short m_nPhiComp
Bins of compressed phi: phi_start, phi_width, phi_0, ..., phi_12.
Definition NDFinder.h:232
c5array * m_compAxialHitReps
m_compAxialHitReps/m_compStereoHitReps (~ Compressed in phi (width, start, values)) 5D array mapping:
Definition NDFinder.h:267
std::vector< std::vector< unsigned short > > getHitsVsClustersTable(const std::vector< SimpleCluster > &clusters)
Create hits to clusters confusion matrix.
Definition NDFinder.cc:318
static constexpr unsigned short m_nSL
Number of super layers.
Definition NDFinder.h:215
std::vector< unsigned short > m_hitIDs
TS-IDs of the hits in the current event: Elements = [0,2335] for 2336 TS in total.
Definition NDFinder.h:192
std::array< double, 3 > transformTrackParameters(const std::array< double, 3 > &estimatedParameters)
Transform to physical units.
Definition NDFinder.cc:476
void initLookUpArrays()
Initialize the arrays LUT arrays.
Definition NDFinder.cc:72
std::vector< unsigned short > m_priorityWirePos
Priority positon within the TS. Elements basf2: [0,3] first, left, right, no hit.
Definition NDFinder.h:196
void loadCompressedHitReps(const std::string &fileName, const SectorBinning &compBins, c5array &compHitsToWeights)
Fills the m_compAxialHitReps/m_compStereoHitReps (see below) arrays with the hit representations (hit...
Definition NDFinder.cc:126
static constexpr std::array< double, 2 > m_cotRange
=> theta in [22.75, 135.18]
Definition NDFinder.h:240
static constexpr std::array< double, 2 > m_omegaRange
1/4 = 0.25 GeV (minimum transverse momentum)
Definition NDFinder.h:237
static constexpr std::array< double, 2 > m_phiRange
One phi sector (360/32)
Definition NDFinder.h:238
std::vector< NDFinderTrack > m_ndFinderTracks
Result: Vector of the found tracks.
Definition NDFinder.h:190
static constexpr double m_binSizePhi
0.9375
Definition NDFinder.h:242
static constexpr unsigned short m_nOmega
Bins in the phi dimension.
Definition NDFinder.h:221
Clusterizend m_clusterer
Clustering module.
Definition NDFinder.h:204
int getMaximumHitInSuperLayer(const std::vector< ContributionInfo > &contributionInfos, unsigned short superLayer)
Find the hit with the maximum contribution in a given super layer.
Definition NDFinder.cc:382
void init(const NDFinderParameters &ndFinderParameters)
Initialization of the NDFinder (parameters and lookup tables)
Definition NDFinder.cc:27
void initHitToSectorMap()
Fills the m_hitToSectorIDs (see below) array with the hit to orientation/sectorWire/sectorID relation...
Definition NDFinder.cc:91
bool checkHitSuperLayers(const SimpleCluster &cluster)
Cut on the number of hit axial/stereo super layers.
Definition NDFinder.cc:410
static constexpr unsigned short m_nTS
Number of track segments.
Definition NDFinder.h:214
unsigned short m_nHits
Counter for the number of hits in the current event.
Definition NDFinder.h:200
c3array * m_houghSpace
The complete Hough space with the size [m_nOmega, m_nPhi, m_nCot].
Definition NDFinder.h:283
static constexpr unsigned short m_phiGeo
Repetition of the wire pattern.
Definition NDFinder.h:226
void fillExpandedHitReps(const SectorBinning &compBins, const c5array &compHitsToWeights, c5array &expHitsToWeights)
Fills the m_expAxialHitReps/m_expStereoHitReps (see below) arrays with the expanded hit representatio...
Definition NDFinder.cc:159
static double getTrackRadius(double transverseMomentum)
Transverse momentum (which is 1/omega, in GeV/c) to radius (in cm)
Definition NDFinder.h:185
static constexpr unsigned short m_nStereo
Number of unique stereo track segments.
Definition NDFinder.h:217
NDFinderParameters m_ndFinderParams
Configuration parameters of the 3DFinder.
Definition NDFinder.h:202
static constexpr unsigned short m_nPrio
Number of priority wires.
Definition NDFinder.h:218
static constexpr unsigned short m_nAxial
Number of unique axial track segments.
Definition NDFinder.h:216
c2array * m_hitToSectorIDs
m_hitToSectorIDs: 2D array mapping TS-ID ([0, 2335]) to:
Definition NDFinder.h:255
void processHitForHoughSpace(const unsigned short hitIdx)
Process a single axial or stereo hit for the Hough space.
Definition NDFinder.cc:214
static constexpr unsigned short m_nPhiSector
Bins of one phi sector (12)
Definition NDFinder.h:229
std::array< double, 3 > calculateCenterOfGravity(const SimpleCluster &cluster)
Calculate the center of gravity (weighted mean) for the track parameters.
Definition NDFinder.cc:430
static constexpr double m_binSizeCot
-0.377
Definition NDFinder.h:243
std::vector< SimpleCluster > relateHitsToClusters(std::vector< SimpleCluster > &clusters)
Relate the hits in the peak of the cluster to the cluster. Applies a cut on the clusters.
Definition NDFinder.cc:296
std::vector< unsigned short > m_hitSLIDs
SL-IDs of the hits in the current event: Elements = Super layer number in [0,1,......
Definition NDFinder.h:194
static constexpr SectorBinning m_compAxialBins
40, 15, 1, 41, 3
Definition NDFinder.h:233
void reset()
Reset the NDFinder data structure to process next event.
Definition NDFinder.cc:185
void findTracks()
Main function for track finding.
Definition NDFinder.cc:204
void addHit(const HitInfo &hitInfo)
Add the hit info of a single track segment to the NDFinder.
Definition NDFinder.cc:59
static constexpr SectorBinning m_compStereoBins
40, 15, 9, 32, 3
Definition NDFinder.h:234
static constexpr unsigned short m_nCot
Bins in the cot dimension.
Definition NDFinder.h:223
c5array * m_expAxialHitReps
m_expAxialHitReps/m_expStereoHitReps (~ expansion of the compressed representations) 5D array mapping...
Definition NDFinder.h:280
unsigned short getHitContribution(const cell_index &peakCell, const unsigned short hitIdx)
Returns the hit contribution of a TS at a certain cluster cell (= peak/maximum cell)
Definition NDFinder.cc:336
std::vector< ContributionInfo > extractContributionInfos(const std::vector< unsigned short > &clusterHits)
Extract relevant hit information (hitIdx, contribution, super layer, drift time)
Definition NDFinder.cc:363
std::array< double, 3 > getTrackParameterEstimate(const std::array< double, 3 > &centerOfGravity)
Transform the center of gravity (cells) into the estimated track parameters.
Definition NDFinder.cc:465
void writeHitToHoughSpace(const WireInfo &hitInfo, const c5array &expHitsToWeights)
Write (add) a single hit (Hough curve) to the Hough space.
Definition NDFinder.cc:232
void runTrackFinding()
Core track finding logic in the constructed Hough space.
Definition NDFinder.cc:247
Type for found clusters.
boost::multi_array< unsigned short, 2 > c2array
TS-ID to 1/32 phi-sector mapping is stored in a 2D array.
boost::multi_array< unsigned short, 5 > c5array
Store hit patterns in a 5D array (hitid, prio, omega, phi, cot)
boost::multi_array< unsigned short, 3 > c3array
The Hough space is a 3D array (omega, phi, cot)
std::array< c3index, 3 > cell_index
The cell index of one Hough space bin.
Abstract base class for different kinds of events.
STL namespace.
Struct containing the track segment (hit) information from the Track Segment Finder (TSF)
Definition NDFinder.h:45
Struct of NDFinder parameters.
Definition NDFinder.h:26
std::string axialFile
Axial and stereo hit representations that should be used.
Definition NDFinder.h:40
unsigned short minSuperStereo
Required number of stereo super layers.
Definition NDFinder.h:30
bool storeAdditionalReadout
Switch for writing the full Hough space and the cluster information to the 3DFinderInfo class.
Definition NDFinder.h:38
unsigned short phiTrim
Clustering: Number of deleted cells in each phi direction from the maximum.
Definition NDFinder.h:36
unsigned short minSuperAxial
Required number of axial super layers.
Definition NDFinder.h:28
unsigned short omegaTrim
Clustering: Number of deleted cells in each omega direction from the maximum.
Definition NDFinder.h:34
unsigned short iterations
Clustering: Number of iterations for the cluster search in each Hough space quadrant.
Definition NDFinder.h:32
Collection of the hit contribution information needed for the hit to cluster relations.
Definition NDFinder.h:118
Data type to collect a binning.
Definition NDFinder.h:102
Collection of the hit information needed for the hit representations.
Definition NDFinder.h:111