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 <cmath>
12#include "trg/cdc/NDFinderDefs.h"
13#include "trg/cdc/Clusterizend.h"
14#include <Math/Vector3D.h>
15
16namespace Belle2 {
22 struct cellweight {
23 cell_index index;
24 ushort weight;
25 };
26
29 public:
30 NDFinderTrack(std::vector<double> values, const SimpleCluster& cluster,
31 std::vector<ROOT::Math::XYZVector> houghspace, std::vector<ROOT::Math::XYZVector> ndreadout):
32 m_cluster(cluster)
33 {
34 m_omega = values[0];
35 m_phi = values[1];
36 m_cotTheta = values[2];
37 m_houghspace = houghspace;
38 m_ndreadout = ndreadout;
39 }
40
42 virtual ~NDFinderTrack() {}
43 double getOmega()
44 {
45 return m_omega;
46 }
47 double getPhi0()
48 {
49 return m_phi;
50 }
51 double getCot()
52 {
53 return m_cotTheta;
54 }
55 double getNRelHits()
56 {
57 return m_cluster.getHits().size();
58 }
59 std::vector<unsigned short> getRelHits()
60 {
61 return m_cluster.getHits();
62 }
63 std::vector<unsigned short> getRelHitsWeights()
64 {
65 return m_cluster.getWeights();
66 }
67 void reset()
68 {
69 m_omega = 0.;
70 m_phi = 0.;
71 m_cotTheta = 0.;
72 }
73 SimpleCluster getCluster()
74 {
75 return m_cluster;
76 }
77 std::vector<ROOT::Math::XYZVector> getHoughSpace()
78 {
79 return m_houghspace;
80 }
81 std::vector<ROOT::Math::XYZVector> getNDReadout()
82 {
83 return m_ndreadout;
84 }
85
86 private:
88 double m_omega;
90 double m_phi;
92 double m_cotTheta;
95 std::vector<unsigned short> m_relHits;
97 std::vector<double> m_hitWeights;
98 SimpleCluster m_cluster;
99 std::vector<ROOT::Math::XYZVector> m_houghspace;
100 std::vector<ROOT::Math::XYZVector> m_ndreadout;
101 };
102
103
107 class NDFinder {
108 public:
109
113 std::string axialFile = "data/trg/cdc/ndFinderArrayAxialComp.txt.gz";
114 std::string stereoFile = "data/trg/cdc/ndFinderArrayStereoComp.txt.gz";
115
118 unsigned char minSuperAxial = 4;
119
121 unsigned char minSuperStereo = 3;
122
124 float thresh = 0.85;
125
127 unsigned char minCells = 1;
128
130 bool dbscanning = false;
131
133 unsigned short minTotalWeight = 450;
134
136 unsigned short minPeakWeight = 32;
137
139 unsigned char iterations = 5;
140
142 unsigned char omegaTrim = 5;
143
145 unsigned char phiTrim = 4;
146
148 unsigned char thetaTrim = 4;
149
151 unsigned short phigeo = 32;
152
154 unsigned short parcels = 7;
155
157 unsigned short parcelsExp = 11;
158 };
159 std::vector<std::vector<float>> m_acceptRanges;
160 std::vector<float> m_slotSizes;
161
164
166 virtual ~NDFinder()
167 {
168 delete m_parrayAxial;
169 delete m_parrayStereo;
170 delete m_phoughPlane;
171 delete m_parrayHitMod;
172 delete m_pcompAxial;
173 delete m_pcompStereo;
174 delete m_parrayAxialExp;
175 delete m_parrayStereoExp;
176 }
177
178
200 void init(unsigned short minWeight, unsigned char minPts, bool diagonal,
201 unsigned char minSuperAxial, unsigned char minSuperStereo, float thresh,
202 unsigned char minCells, bool dbscanning, unsigned short minTotalWeight, unsigned short minPeakWeight, unsigned char iterations,
203 unsigned char omegaTrim, unsigned char phiTrim, unsigned char thetaTrim,
204 bool verbose, std::string& axialFile, std::string& stereoFile);
205
207 void initBins();
208
212 void loadArray(const std::string& filename, ndbinning bins, c5array& hitsToTracks);
215 void restoreZeros(ndbinning zerobins, ndbinning compbins, c5array& expArray, const c5array& compArray);
216
220 void squeezeOne(c5array& writeArray, c5array& readArray, int outparcels, int inparcels, c5index ihit, c5index iprio, c5index itheta,
221 c5elem nomega);
222
225 void squeezeAll(ndbinning writebins, c5array& writeArray, c5array& readArray, int outparcels, int inparcels);
226
228 void initHitModAxSt(c2array& hitMod);
229
231 void reset()
232 {
233 m_NDFinderTracks.clear();
234 m_hitIds.clear();
235 m_hitSLIds.clear();
236 m_prioPos.clear();
237 m_prioTime.clear();
238 m_nHits = 0;
239 m_vecDstart.clear();
240 m_hitOrients.clear();
241 delete m_phoughPlane;
242 m_phoughPlane = new c3array(m_pc3shape);
243 }
244
246 void printParams();
247
249 void addHit(unsigned short hitId, unsigned short hitSLId, unsigned short hitPrioPos, long hitPrioTime)
250 {
251 if (hitPrioPos > 0) { // skip "no hit"
252 m_hitIds.push_back(hitId);
253 m_hitSLIds.push_back(hitSLId);
254 m_prioPos.push_back(3 - hitPrioPos);
255 m_prioTime.push_back(hitPrioTime);
256 m_nHits++;
257 }
258 }
259
261 void findTracks();
262
264 std::vector<NDFinderTrack>* getFinderTracks()
265 {
266 return &m_NDFinderTracks;
267 }
268
270 void printArray3D(c3array& hitsToTracks, ndbinning bins, ushort, ushort, ushort, ushort);
271
273 protected:
274
276 void getCM();
277
282 void addLookup(unsigned short ihit);
283
285 void addC3Comp(ushort hitr, ushort prio, const c5array& hitsToTracks,
286 short Dstart, ndbinning bins);
287
289 std::vector<std::vector<unsigned short>> getHitsVsClusters(
290 std::vector<SimpleCluster>& clusters);
291
293 cell_index getMax(const std::vector<cell_index>&);
294
297 ushort hitContrib(cell_index peak, ushort ihit);
298
301 std::vector<SimpleCluster> allHitsToClusters(
302 std::vector<std::vector<unsigned short>>& hitsVsClusters,
303 std::vector<SimpleCluster>& clusters);
304
307 std::vector<cellweight> getHighWeight(std::vector<cell_index> entries, float cutoff);
308
310 std::vector<double> getWeightedMean(std::vector<cellweight>);
311
313 std::vector<double> getBinToVal(std::vector<double>);
314
316 double cdcTrackRadius(double pt)
317 {
318 return pt * 1e11 / (3e8 * 1.5); // div (c * B)
319 }
320
322 float transformVar(float estVal, int idx);
323 std::vector<double> transform(std::vector<double> estimate);
324
326 private:
327
329 boost::array<c5index, 5> m_pc5shapeax;
330 boost::array<c5index, 5> m_pc5shapest;
331 boost::array<c3index, 3> m_pc3shape;
332 boost::array<c2index, 2> m_pc2shapeHitMod;
333 boost::array<c5index, 5> m_pc5shapeCompAx;
334 boost::array<c5index, 5> m_pc5shapeCompSt;
335 boost::array<c5index, 5> m_pc5shapeExpAx;
336 boost::array<c5index, 5> m_pc5shapeExpSt;
337
339 c5array* m_parrayAxial = nullptr;
340 c5array* m_parrayStereo = nullptr;
341 c3array* m_phoughPlane = nullptr;
342 c2array* m_parrayHitMod = nullptr;
343 c5array* m_pcompAxial = nullptr;
344 c5array* m_pcompStereo = nullptr;
345 c5array* m_parrayAxialExp = nullptr;
346 c5array* m_parrayStereoExp = nullptr;
347
349 std::vector<int> m_nWires;
350
352 std::vector<NDFinderTrack> m_NDFinderTracks;
353
356 std::vector<unsigned short> m_hitIds;
357
360 std::vector<unsigned short> m_hitSLIds;
361
365 std::vector<unsigned short> m_prioPos;
366
368 std::vector<long> m_prioTime;
369
373 std::vector<unsigned short> m_hitOrients;
374
377 std::vector<short> m_vecDstart;
378
380 unsigned short m_nHits{0};
381
384
387 ndbinning m_stBins;
388 ndbinning m_fullBins;
389 ndbinning m_compAxBins;
390 ndbinning m_compStBins;
391 ndbinning m_expAxBins;
392 ndbinning m_expStBins;
393
396 std::vector<ushort> m_planeShape;
397
399 unsigned short m_nPhiFull{0};
400 unsigned short m_nPhiOne{0};
401 unsigned short m_nPhiComp{0};
402 unsigned short m_nPhiExp{0};
403 unsigned short m_nPhiUse{0};
404 unsigned short m_nOmega{0};
405 unsigned short m_nTheta{0};
406
407 unsigned short m_nSL{0};
408 unsigned short m_nTS{0};
409 unsigned short m_nAx{0};
410 unsigned short m_nSt{0};
411 unsigned short m_nPrio{0};
412
415 Belle2::Clusterizend m_clusterer2;
416
418 bool m_verbose{false};
419 };
421}
Clustering module.
Definition: Clusterizend.h:125
Store track parameters of found tracks.
Definition: NDFinder.h:28
std::vector< unsigned short > m_relHits
vector of the indices of the related hits in the list of CDC hits (StoreArray<CDCHits>)
Definition: NDFinder.h:95
double m_phi
2D azimuthal angle
Definition: NDFinder.h:90
virtual ~NDFinderTrack()
Default destructor.
Definition: NDFinder.h:42
std::vector< double > m_hitWeights
vector of the weights for each related hit.
Definition: NDFinder.h:97
double m_omega
2D track curvature
Definition: NDFinder.h:88
double m_cotTheta
3D polar angle
Definition: NDFinder.h:92
Class to represent the CDC NDFinder.
Definition: NDFinder.h:107
double cdcTrackRadius(double pt)
Transverse momentum to radius.
Definition: NDFinder.h:316
std::vector< NDFinderTrack > * getFinderTracks()
retreive the results
Definition: NDFinder.h:264
virtual ~NDFinder()
Default destructor.
Definition: NDFinder.h:166
Belle2::Clusterizend m_clusterer
Clustering module.
Definition: NDFinder.h:414
std::vector< SimpleCluster > allHitsToClusters(std::vector< std::vector< unsigned short > > &hitsVsClusters, std::vector< SimpleCluster > &clusters)
Relate all hits in a cluster to the cluster Remove small clusters with less than minsuper related hit...
Definition: NDFinder.cc:429
void initBins()
Initialize the binnings and reserve the arrays.
Definition: NDFinder.cc:78
void initHitModAxSt(c2array &hitMod)
Initialize hit modulo mappings.
Definition: NDFinder.cc:198
c5array * m_parrayAxial
Array pointers to the hit patterns.
Definition: NDFinder.h:339
void getCM()
NDFinder internal functions for track finding.
Definition: NDFinder.cc:494
void squeezeAll(ndbinning writebins, c5array &writeArray, c5array &readArray, int outparcels, int inparcels)
Loop over all hits and theta bins and squeeze all 2D (omega,phi) planes.
Definition: NDFinder.cc:252
std::vector< unsigned short > m_prioPos
Priority positon within the TS in the current event elements basf2: [0,3] first, left,...
Definition: NDFinder.h:365
void loadArray(const std::string &filename, ndbinning bins, c5array &hitsToTracks)
Load an NDFinder array of hit representations in track phase space.
Definition: NDFinder.cc:165
void restoreZeros(ndbinning zerobins, ndbinning compbins, c5array &expArray, const c5array &compArray)
Restore non-zero suppressed hit curves.
Definition: NDFinder.cc:264
std::vector< short > m_vecDstart
Phi-start of 7/32 hit representation in full track parameter space.
Definition: NDFinder.h:377
std::vector< unsigned short > m_hitOrients
Orients TS-Ids of the hits in the current event elements: [0,2335] for 2336 TS in total.
Definition: NDFinder.h:373
ushort hitContrib(cell_index peak, ushort ihit)
Determine weight contribution of a single hit to a single cell.
Definition: NDFinder.cc:672
void squeezeOne(c5array &writeArray, c5array &readArray, int outparcels, int inparcels, c5index ihit, c5index iprio, c5index itheta, c5elem nomega)
Squeeze phi-axis in a 2D (omega,phi) plane.
Definition: NDFinder.cc:229
std::vector< cellweight > getHighWeight(std::vector< cell_index > entries, float cutoff)
Candidate cells as seed for the clustering.
Definition: NDFinder.cc:655
void addHit(unsigned short hitId, unsigned short hitSLId, unsigned short hitPrioPos, long hitPrioTime)
fill hit info of the event
Definition: NDFinder.h:249
std::vector< double > getBinToVal(std::vector< double >)
Scale the weighted center to track parameter values.
Definition: NDFinder.cc:608
unsigned short m_nHits
Counter for the number of hits in the current event.
Definition: NDFinder.h:380
boost::array< c5index, 5 > m_pc5shapeax
NDFinder.
Definition: NDFinder.h:329
void addC3Comp(ushort hitr, ushort prio, const c5array &hitsToTracks, short Dstart, ndbinning bins)
In place array addition to houghmap Comp: A = A + B.
Definition: NDFinder.cc:368
std::vector< int > m_nWires
Number of first priority wires in each super layer (TS per SL)
Definition: NDFinder.h:349
ndbinning m_axBins
Binnings in different hit pattern arrays.
Definition: NDFinder.h:386
clustererParams m_clustererParams
Configuration of the clustering module.
Definition: NDFinder.h:395
void printParams()
Debug: print configured parameters.
Definition: NDFinder.cc:703
ndparameters m_params
Configuration parameters of the 3DFinder.
Definition: NDFinder.h:383
std::vector< NDFinderTrack > m_NDFinderTracks
Result: vector of the found tracks.
Definition: NDFinder.h:352
void addLookup(unsigned short ihit)
Add a single axial or stereo hit to the houghmap.
Definition: NDFinder.cc:337
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:356
unsigned short m_nPhiFull
Default bins.
Definition: NDFinder.h:399
NDFinder()
Default constructor.
Definition: NDFinder.h:163
void reset()
NDFinder reset data structure to process next event.
Definition: NDFinder.h:231
void findTracks()
main function for track finding
Definition: NDFinder.cc:394
std::vector< std::vector< unsigned short > > getHitsVsClusters(std::vector< SimpleCluster > &clusters)
Create hits to clusters confusion matrix.
Definition: NDFinder.cc:408
std::vector< double > getWeightedMean(std::vector< cellweight >)
Calculate the weighted center of a cluster.
Definition: NDFinder.cc:619
std::vector< long > m_prioTime
Drift time of the priority wire.
Definition: NDFinder.h:368
float transformVar(float estVal, int idx)
Calculate physical units.
Definition: NDFinder.cc:579
void printArray3D(c3array &hitsToTracks, ndbinning bins, ushort, ushort, ushort, ushort)
Debug Tool: Print part of the houghmap.
Definition: NDFinder.cc:289
cell_index getMax(const std::vector< cell_index > &)
Peak cell in cluster.
Definition: NDFinder.cc:639
bool m_verbose
Print Hough planes and verbose output.
Definition: NDFinder.h:418
std::vector< unsigned short > m_hitSLIds
SL-Ids of the hits in the current event elements: super layer number in [0,1,...,8].
Definition: NDFinder.h:360
Type for found clusters.
Definition: Clusterizend.h:45
std::vector< unsigned short > getHits()
Get ids of related hits (indices of the TS StoreArray)
Definition: Clusterizend.h:100
std::vector< unsigned short > getWeights()
Get weight contribution of each related hit to the cluster.
Definition: Clusterizend.h:105
unsigned short c5elem
Store hit patterns in a 5D array (hitid, prio, omega, phi, theta)
Definition: NDFinderDefs.h:23
Abstract base class for different kinds of events.
Struct of ndFinder parameters.
Definition: NDFinder.h:111
unsigned char iterations
Clustering: number of iterations for the cluster search in each Hough space.
Definition: NDFinder.h:139
std::string axialFile
Zero-Suppressed trained hit data.
Definition: NDFinder.h:113
unsigned short minTotalWeight
Clustering: minimum of the total weight in all cells of the 3d volume.
Definition: NDFinder.h:133
unsigned char minCells
Minimum number of cells in the track parameter space.
Definition: NDFinder.h:127
unsigned short phigeo
CDC symmetry: repeat wire pattern 32 times in phi.
Definition: NDFinder.h:151
unsigned char omegaTrim
Clustering: number of deleted cells in each omega direction from the maximum.
Definition: NDFinder.h:142
unsigned char minSuperAxial
Clustering options.
Definition: NDFinder.h:118
bool dbscanning
Clustering method: When true: dbscan, when false: fixed 3d volume.
Definition: NDFinder.h:130
float thresh
houghspace must have thresh x maxweight of cluster
Definition: NDFinder.h:124
unsigned short parcelsExp
CDC symmetry: phi range covered by expanded hit data [0 .
Definition: NDFinder.h:157
unsigned char thetaTrim
Clustering: number of deleted cells in each theta direction from the maximum.
Definition: NDFinder.h:148
unsigned char minSuperStereo
Required number of stereo super layers.
Definition: NDFinder.h:121
unsigned short minPeakWeight
Clustering: minimum peak cell weight.
Definition: NDFinder.h:136
unsigned short parcels
‍** CDC symmetry: phi range covered by hit data [0 .. phigeo] *‍/
Definition: NDFinder.h:154
unsigned char phiTrim
Clustering: number of deleted cells in each phi direction from the maximum.
Definition: NDFinder.h:145
Default binning in a (7/32) phi-sector.
Definition: NDFinderDefs.h:41