Belle II Software  release-08-01-10
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 #ifndef NDFINDER_H
10 #define NDFINDER_H
11 
12 #include <cmath>
13 #include "trg/cdc/NDFinderDefs.h"
14 #include "trg/cdc/Clusterizend.h"
15 
16 namespace Belle2 {
22  struct cellweight {
23  cell_index index;
24  ushort weight;
25  };
26 
28  class NDFinderTrack {
29  public:
30  NDFinderTrack(std::vector<double> values, const SimpleCluster& cluster):
31  m_cluster(cluster)
32  {
33  m_omega = values[0];
34  m_phi = values[1];
35  m_cotTheta = values[2];
36  }
37 
39  virtual ~NDFinderTrack() {}
40  double getOmega()
41  {
42  return m_omega;
43  }
44  double getPhi0()
45  {
46  return m_phi;
47  }
48  double getCot()
49  {
50  return m_cotTheta;
51  }
52  double get_nRelHits()
53  {
54  return m_cluster.get_hits().size();
55  }
56  std::vector<unsigned short> get_relHits()
57  {
58  return m_cluster.get_hits();
59  }
60  std::vector<unsigned short> get_relHitsWeights()
61  {
62  return m_cluster.get_weights();
63  }
64  void reset()
65  {
66  m_omega = 0.;
67  m_phi = 0.;
68  m_cotTheta = 0.;
69  }
70 
71  private:
73  double m_omega;
75  double m_phi;
77  double m_cotTheta;
80  std::vector<unsigned short> m_relHits;
82  std::vector<double> m_hitWeights;
83  SimpleCluster m_cluster;
84  };
85 
86 
90  class NDFinder {
91  public:
92 
94  struct ndparameters {
96  std::string axialFile = "data/trg/cdc/ndFinderArrayAxialComp.txt.gz";
97  std::string stereoFile = "data/trg/cdc/ndFinderArrayStereoComp.txt.gz";
98 
101  long unsigned int minhits = 4;
103  long unsigned int minhits_axial = 0;
105  float thresh = 0.85;
106 
108  float minassign = 0.2;
109 
111  long unsigned int mincells = 5;
112 
114  unsigned short phigeo = 32;
116  unsigned short parcels = 7;
118  unsigned short parcelsExp = 11;
119  };
120  std::vector<std::vector<float>> m_acceptRanges;
121  std::vector<float> m_slotsizes;
122 
123 
124 
126  NDFinder() {}
127 
129  virtual ~NDFinder()
130  {
131  delete m_parrayAxial;
132  delete m_parrayStereo;
133  delete m_phoughPlane;
134  delete m_parrayHitMod;
135  delete m_pcompAxial;
136  delete m_pcompStereo;
137  delete m_parrayAxialExp;
138  delete m_parrayStereoExp;
139  }
140 
141 
157  void init(int minweight, int minpts, bool diagonal,
158  int minhits, int minhits_axial, double thresh, double minassign,
159  int mincells, bool verbose, std::string& axialFile, std::string& stereoFile);
160 
162  void initBins();
163 
167  void loadArray(const std::string& filename, ndbinning bins, c5array& hitsToTracks);
170  void restoreZeros(ndbinning zerobins, ndbinning compbins, c5array& expArray, const c5array& compArray);
171 
175  void squeezeOne(c5array& writeArray, c5array& readArray, int outparcels, int inparcels, c5index ihit, c5index iprio, c5index itheta,
176  c5elem nomega);
177 
180  void squeezeAll(ndbinning writebins, c5array& writeArray, c5array& readArray, int outparcels, int inparcels);
181 
183  void initHitModAxSt(c2array& hitMod);
184 
186  void reset()
187  {
188  m_NDFinderTracks.clear();
189  m_hitIds.clear();
190  m_prioPos.clear();
191  m_nHits = 0;
192  m_vecDstart.clear();
193  m_hitOrients.clear();
194  delete m_phoughPlane;
195  m_phoughPlane = new c3array(m_pc3shape);
196  }
197 
199  void printParams();
200 
202  void addHit(unsigned short hitId, unsigned short hitPrioPos)
203  {
204  if (hitPrioPos > 0) { // skip "no hit"
205  m_hitIds.push_back(hitId);
206  m_prioPos.push_back(3 - hitPrioPos);
207  m_nHits++;
208  }
209  }
210 
212  void findTracks();
213 
215  std::vector<NDFinderTrack>* getFinderTracks()
216  {
217  return &m_NDFinderTracks;
218  }
219 
221  void printArray3D(c3array& hitsToTracks, ndbinning bins, ushort, ushort, ushort, ushort);
222 
224  protected:
225 
227  void getCM();
228 
233  void addLookup(unsigned short ihit);
234 
236  void addC3Comp(ushort hitr, ushort prio, const c5array& hitsToTracks,
237  short Dstart, ndbinning bins);
238 
240  std::vector<std::vector<unsigned short>> getHitsVsClusters(
241  std::vector<SimpleCluster>& clusters);
242 
244  cell_index getMax(const std::vector<cell_index>&);
245 
248  ushort hitContrib(cell_index peak, ushort ihit);
249 
252  std::vector<SimpleCluster> relateHitsToClusters(
253  std::vector<std::vector<unsigned short>>& hitsVsClusters,
254  std::vector<SimpleCluster>& clusters);
255 
258  int hitToCluster(std::vector<std::vector<unsigned short>>& hitsVsClusters,
259  unsigned short hit);
260 
263  std::vector<cellweight> getHighWeight(std::vector<cell_index> entries, float cutoff);
264 
266  std::vector<double> getWeightedMean(std::vector<cellweight>);
267 
269  std::vector<double> getBinToVal(std::vector<double>);
270 
272  double cdc_track_radius(double pt)
273  {
274  return pt * 1e11 / (3e8 * 1.5); // div (c * B)
275  }
276 
278  float transformVar(float estVal, int idx);
279  std::vector<double> transform(std::vector<double> estimate);
280 
282  private:
283 
285  boost::array<c5index, 5> m_pc5shapeax;
286  boost::array<c5index, 5> m_pc5shapest;
287  boost::array<c3index, 3> m_pc3shape;
288  boost::array<c2index, 2> m_pc2shapeHitMod;
289  boost::array<c5index, 5> m_pc5shapeCompAx;
290  boost::array<c5index, 5> m_pc5shapeCompSt;
291  boost::array<c5index, 5> m_pc5shapeExpAx;
292  boost::array<c5index, 5> m_pc5shapeExpSt;
293 
295  c5array* m_parrayAxial = nullptr;
296  c5array* m_parrayStereo = nullptr;
297  c3array* m_phoughPlane = nullptr;
298  c2array* m_parrayHitMod = nullptr;
299  c5array* m_pcompAxial = nullptr;
300  c5array* m_pcompStereo = nullptr;
301  c5array* m_parrayAxialExp = nullptr;
302  c5array* m_parrayStereoExp = nullptr;
303 
305  std::vector<int> m_nWires;
306 
308  std::vector<NDFinderTrack> m_NDFinderTracks;
309 
312  std::vector<unsigned short> m_hitIds;
313 
317  std::vector<unsigned short> m_prioPos;
318 
322  std::vector<unsigned short> m_hitOrients;
323 
326  std::vector<short> m_vecDstart;
327 
329  unsigned short m_nHits{0};
330 
333 
336  ndbinning m_stbins;
337  ndbinning m_fullbins;
338  ndbinning m_compaxbins;
339  ndbinning m_compstbins;
340  ndbinning m_expaxbins;
341  ndbinning m_expstbins;
342 
345  std::vector<ushort> m_planeShape;
346 
348  unsigned short m_nPhiFull{0};
349  unsigned short m_nPhiOne{0};
350  unsigned short m_nPhiComp{0};
351  unsigned short m_nPhiExp{0};
352  unsigned short m_nPhiUse{0};
353  unsigned short m_nOmega{0};
354  unsigned short m_nTheta{0};
355 
356  unsigned short m_nSL{0};
357  unsigned short m_nTS{0};
358  unsigned short m_nAx{0};
359  unsigned short m_nSt{0};
360  unsigned short m_nPrio{0};
361 
364 
366  bool m_verbose{false};
367  };
369 }
370 #endif
371 
Clustering module.
Definition: Clusterizend.h:114
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:80
double m_phi
2D azimuthal angle
Definition: NDFinder.h:75
virtual ~NDFinderTrack()
Default destructor.
Definition: NDFinder.h:39
std::vector< double > m_hitWeights
vector of the weights for each related hit.
Definition: NDFinder.h:82
double m_omega
2D track curvature
Definition: NDFinder.h:73
double m_cotTheta
3D polar angle
Definition: NDFinder.h:77
Class to represent the CDC NDFinder.
Definition: NDFinder.h:90
std::vector< NDFinderTrack > * getFinderTracks()
retreive the results
Definition: NDFinder.h:215
std::vector< cellweight > getHighWeight(std::vector< cell_index > entries, float cutoff)
Candidate cells as seed for the clustering.
Definition: NDFinder.cc:624
ndbinning m_axbins
Binnings in different hit pattern arrays.
Definition: NDFinder.h:335
virtual ~NDFinder()
Default destructor.
Definition: NDFinder.h:129
std::vector< SimpleCluster > relateHitsToClusters(std::vector< std::vector< unsigned short >> &hitsVsClusters, std::vector< SimpleCluster > &clusters)
Use confusion matrix to related hits to clusters.
Definition: NDFinder.cc:422
Belle2::Clusterizend m_clusterer
Clustering module.
Definition: NDFinder.h:363
void initBins()
Initialize the binnings and reserve the arrays.
Definition: NDFinder.cc:72
void initHitModAxSt(c2array &hitMod)
Initialize hit modulo mappings.
Definition: NDFinder.cc:192
c5array * m_parrayAxial
Array pointers to the hit patterns.
Definition: NDFinder.h:295
void getCM()
NDFinder internal functions for track finding.
Definition: NDFinder.cc:485
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:246
std::vector< unsigned short > m_prioPos
Priority positon within the TS in the current event elements basf2: [0,3] first, left,...
Definition: NDFinder.h:317
void loadArray(const std::string &filename, ndbinning bins, c5array &hitsToTracks)
Load an NDFinder array of hit representations in track phase space.
Definition: NDFinder.cc:159
void restoreZeros(ndbinning zerobins, ndbinning compbins, c5array &expArray, const c5array &compArray)
Restore non-zero suppressed hit curves.
Definition: NDFinder.cc:258
std::vector< short > m_vecDstart
Phi-start of 7/32 hit representation in full track parameter space.
Definition: NDFinder.h:326
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:322
ushort hitContrib(cell_index peak, ushort ihit)
Determine weight contribution of a single hit to a single cell.
Definition: NDFinder.cc:641
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:223
std::vector< double > getBinToVal(std::vector< double >)
Scale the weighted center to track parameter values.
Definition: NDFinder.cc:548
unsigned short m_nHits
Counter for the number of hits in the current event.
Definition: NDFinder.h:329
boost::array< c5index, 5 > m_pc5shapeax
NDFinder.
Definition: NDFinder.h:285
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:362
std::vector< int > m_nWires
Number of first priority wires in each super layer (TS per SL)
Definition: NDFinder.h:305
double cdc_track_radius(double pt)
Transverse momentum to radius.
Definition: NDFinder.h:272
void printParams()
Debug: print configured parameters.
Definition: NDFinder.cc:672
ndparameters m_params
Configuration parameters of the 3DFinder.
Definition: NDFinder.h:332
clusterer_params m_clusterer_params
Configuration of the clustering module.
Definition: NDFinder.h:344
std::vector< NDFinderTrack > m_NDFinderTracks
Result: vector of the found tracks.
Definition: NDFinder.h:308
void addLookup(unsigned short ihit)
Add a single axial or stereo hit to the houghmap.
Definition: NDFinder.cc:331
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:312
int hitToCluster(std::vector< std::vector< unsigned short >> &hitsVsClusters, unsigned short hit)
Determine the best cluster for a single hit, given hitsVsClusters confusion matrix.
Definition: NDFinder.cc:578
unsigned short m_nPhiFull
Default bins.
Definition: NDFinder.h:348
NDFinder()
Default constructor.
Definition: NDFinder.h:126
void reset()
NDFinder reset data structure to process next event.
Definition: NDFinder.h:186
void findTracks()
main function for track finding
Definition: NDFinder.cc:388
std::vector< std::vector< unsigned short > > getHitsVsClusters(std::vector< SimpleCluster > &clusters)
Create hits to clusters confusion matrix.
Definition: NDFinder.cc:402
std::vector< double > getWeightedMean(std::vector< cellweight >)
Calculate the weighted center of a cluster.
Definition: NDFinder.cc:558
float transformVar(float estVal, int idx)
Calculate physical units.
Definition: NDFinder.cc:519
void printArray3D(c3array &hitsToTracks, ndbinning bins, ushort, ushort, ushort, ushort)
Debug Tool: Print part of the houghmap.
Definition: NDFinder.cc:283
cell_index getMax(const std::vector< cell_index > &)
Peak cell in cluster.
Definition: NDFinder.cc:608
void addHit(unsigned short hitId, unsigned short hitPrioPos)
fill hit info of the event
Definition: NDFinder.h:202
bool m_verbose
Print Hough planes and verbose output.
Definition: NDFinder.h:366
void init(int minweight, int minpts, bool diagonal, int minhits, int minhits_axial, double thresh, double minassign, int mincells, bool verbose, std::string &axialFile, std::string &stereoFile)
initialization
Definition: NDFinder.cc:25
Type for found clusters.
Definition: Clusterizend.h:34
std::vector< unsigned short > get_weights()
Get weight contribution of each related hit to the cluster.
Definition: Clusterizend.h:94
std::vector< unsigned short > get_hits()
Get ids of related hits (indices of the TS StoreArray)
Definition: Clusterizend.h:89
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:94
long unsigned int minhits
Clustering options.
Definition: NDFinder.h:101
long unsigned int mincells
Minimum numeber of cells in the track parameter space.
Definition: NDFinder.h:111
long unsigned int minhits_axial
Required number of axial hits per track.
Definition: NDFinder.h:103
std::string axialFile
Zero-Suppressed trained hit data.
Definition: NDFinder.h:96
unsigned short phigeo
CDC symmetry: repeat wire pattern 32 times in phi.
Definition: NDFinder.h:114
float minassign
Required relative weight contribution to assign a hit to a cluster.
Definition: NDFinder.h:108
float thresh
Members must have thresh x maxweight of cluster.
Definition: NDFinder.h:105
unsigned short parcelsExp
CDC symmetry: phi range covered by expanded hit data [0 .
Definition: NDFinder.h:118
unsigned short parcels
‍** CDC symmetry: phi range covered by hit data [0 .. phigeo] *‍/
Definition: NDFinder.h:116
Default binning in a (7/32) phi-sector.
Definition: NDFinderDefs.h:41