Belle II Software development
CDCTrigger2DFinderModule.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 CDCTrigger2DFinderModule_H
10#define CDCTrigger2DFinderModule_H
11
12#include <framework/core/Module.h>
13
14#include <utility>
15#include <unordered_map>
16#include <vector>
17#include <fstream>
18
19
20#include <framework/datastore/StoreArray.h>
21#include <framework/datastore/StoreObjPtr.h>
22#include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
23#include <trg/cdc/dataobjects/CDCTriggerTrack.h>
24#include <trg/cdc/dataobjects/CDCTriggerHoughCluster.h>
25#include <trg/cdc/dbobjects/CDCTrigger2DConfig.h>
26
27#include <TMatrix.h>
28#include <Math/Vector2D.h>
29
30
31namespace Belle2 {
37 typedef std::pair<unsigned short, ROOT::Math::XYVector> CDCPair;
39 typedef std::unordered_map<int, CDCPair> CDCHitMap;
41 typedef std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> Coord2dPair;
42
50 public:
52 CDCTriggerHoughCand(std::vector<unsigned>& _list, Coord2dPair _coord,
53 unsigned short _slcount, unsigned _id):
54 m_hitList(_list), m_coord(_coord), m_SLcount(_slcount), m_id(_id) {}
55
57
59 std::vector<unsigned> getIdList() const { return m_hitList; }
61 Coord2dPair getCoord() const { return m_coord; }
63 unsigned short getSLcount() const { return m_SLcount; }
65 unsigned getID() const { return m_id; }
66
67 private:
69 std::vector<unsigned> m_hitList;
73 unsigned short m_SLcount = 0;
75 unsigned m_id = 0;
76 };
77
79 inline bool operator==(const CDCTriggerHoughCand& a, const CDCTriggerHoughCand& b)
80 {
81 return (a.getCoord().first.X() == b.getCoord().first.X() &&
82 a.getCoord().first.Y() == b.getCoord().first.Y());
83 }
84
85
87 public:
90
92 virtual void initialize() override;
94 virtual void beginRun() override;
96 virtual void event() override;
98 virtual void terminate() override;
99
107 double x1_s, double x2_s, double y1_s, double y2_s,
108 unsigned iterations,
109 unsigned ix_s, unsigned iy_s);
110
114 bool shortTrack(std::bitset<45>& superLayers);
115
118 void connectedRegions();
130 void addNeighbors(const CDCTriggerHoughCand& center,
131 const std::vector<CDCTriggerHoughCand>& candidates,
132 std::vector<CDCTriggerHoughCand>& merged,
133 std::vector<CDCTriggerHoughCand>& rejected,
134 unsigned short nSLmax) const;
136 bool inList(const CDCTriggerHoughCand& a, const std::vector<CDCTriggerHoughCand>& list) const;
138 bool connected(const CDCTriggerHoughCand& a, const CDCTriggerHoughCand& b) const;
140 void mergeIdList(std::vector<unsigned>& merged, std::vector<unsigned>& a, std::vector<unsigned>& b);
141
144 void patternClustering(const CDCHitMap& inputMap);
146 bool connectedLR(unsigned patternL, unsigned patternR);
148 bool connectedUD(unsigned patternD, unsigned patternU);
150 bool connectedDiag(unsigned patternLD, unsigned patternRU);
154 unsigned topRightSquare(std::vector<unsigned>& pattern);
160 unsigned topRightCorner(unsigned pattern);
166 unsigned bottomLeftCorner(unsigned pattern);
167
170 void findAllCrossingHits(std::vector<unsigned>& list,
171 double x1, double x2, double y1, double y2,
172 const CDCHitMap& inputMap);
177 void selectHits(std::vector<unsigned>& list, std::vector<unsigned>& selected,
178 std::vector<unsigned>& unselected);
179
180 protected:
181
189 unsigned m_nCellsPhi;
191 unsigned m_nCellsR;
193 double m_minPt;
200 double m_maxR = 0.;
202 double m_shiftR = 0.;
205 unsigned m_maxIterations = 0;
207 unsigned m_nCells = 0;
208
210 double m_rectX = 0;
212 double m_rectY = 0;
213
216 unsigned m_minHits;
221 unsigned m_minCells;
227 unsigned m_connect;
234
237
240
243
246
249 unsigned m_storePlane;
263
265 std::string m_testFilename;
267 std::ofstream m_testFile;
268
276 std::vector<CDCTriggerHoughCand> m_houghCand;
277
279 double m_radius[9][5] = {{0.}};
281 unsigned m_TSoffset[10] = {0};
282
291
294
295 };//end class declaration
296
297} // end namespace Belle2
298
299#endif // CDCTrigger2DFinderModule_H
void findAllCrossingHits(std::vector< unsigned > &list, double x1, double x2, double y1, double y2, const CDCHitMap &inputMap)
Find all hits in inputMap whose Hough curve crosses the rectangle with corners (x1,...
unsigned m_maxIterations
number of iterations for the fast peak finder, smallest n such that 2^(n+1) > max(nCellsPhi,...
bool shortTrack(std::bitset< 45 > &superLayers)
check the short track condition (= hits in the inner super layers rather than any super layers)
bool connectedLR(unsigned patternL, unsigned patternR)
Check for left/right connection of patterns in 2 x 2 squares.
unsigned topRightCorner(unsigned pattern)
Find the top right corner within 2 x 2 square.
bool m_usehitpattern
switch to use hit pattern inside TSF
std::string m_testFilename
filename for test output for firmware debugging
unsigned m_minCells
minimum number of cells in a cluster to form a track
bool connectedUD(unsigned patternD, unsigned patternU)
Check for up/down connection of patterns in 2 x 2 squares.
double m_radius[9][5]
Radius of the CDC layers with priority wires (2 per super layer).
bool m_useadc
switch to use hit pattern inside TSF with ADC cut
unsigned m_minHitsShort
short tracks require hits in the first minHitsShort super layers to form a candidate
virtual void initialize() override
Initialize the module and check module parameters.
unsigned m_nCellsR
number of Hough cells in 1/r
int m_shiftPt
shift the Hough plane in 1/r to avoid curvature 0 tracks < 0: shift in negative direction (negative h...
double m_shiftR
Hough plane shift in 1/r [1/cm].
virtual void event() override
Run tracking.
void patternClustering(const CDCHitMap &inputMap)
Combine Hough candidates to tracks by a fixed pattern algorithm.
StoreArray< CDCTriggerSegmentHit > m_segmentHits
list of track segment hits
std::string m_outputCollectionName
Name of the StoreArray containing the tracks found by the Hough tracking.
unsigned m_nCellsPhi
number of Hough cells in phi
bool m_usePriority
switch between priority position and center position of track segment
bool m_clusterPattern
switch for clustering algorithm (if true use nested patterns)
virtual void terminate() override
Clean up.
bool m_hitRelationsFromCorners
switch for creating relations to hits in the pattern clustering algorithm.
StoreObjPtr< TMatrix > m_houghPlane
matrix containing the Hough plane
unsigned m_storePlane
switch to save the Hough plane in DataStore (0: don't save, 1: save only peaks, 2: save full plane)
bool m_ignore2nd
switch to skip second priority hits
bool inList(const CDCTriggerHoughCand &a, const std::vector< CDCTriggerHoughCand > &list) const
Check if candidate is in list.
unsigned m_connect
number of neighbors to check for connection (4: direct, 6: direct + upper right and lower left corner...
std::vector< CDCTriggerHoughCand > m_houghCand
Hough Candidates.
void selectHits(std::vector< unsigned > &list, std::vector< unsigned > &selected, std::vector< unsigned > &unselected)
Select one hit per super layer.
bool m_suppressClone
switch to send only the first found track and suppress the subsequent clones
std::ofstream m_testFile
filestream for test output for firmware debugging
unsigned m_nCells
number of cells for the fast peak finder: 2^(maxIterations + 1).
virtual void beginRun() override
Register run-dependent DataStore arrays.
StoreArray< CDCTriggerTrack > m_tracks
list of found tracks
unsigned m_clusterSizeX
maximum cluster size for pattern algorithm
double m_minPt
Hough plane limit in Pt [GeV].
void mergeIdList(std::vector< unsigned > &merged, std::vector< unsigned > &a, std::vector< unsigned > &b)
Merge lists a and b and put the result in merged.
bool connected(const CDCTriggerHoughCand &a, const CDCTriggerHoughCand &b) const
Check if candidates are connected.
unsigned bottomLeftCorner(unsigned pattern)
Find the bottom left corner within 2 x 2 square.
bool m_requireSL0
switch to check separately for a hit in the innermost super layer
unsigned m_TSoffset[10]
Number of track segments up to super layer.
unsigned m_minHits
minimum number of hits from different super layers in a Hough cell to form a candidate
StoreArray< CDCTriggerHoughCluster > m_clusters
list of clusters in the Hough map
void addNeighbors(const CDCTriggerHoughCand &center, const std::vector< CDCTriggerHoughCand > &candidates, std::vector< CDCTriggerHoughCand > &merged, std::vector< CDCTriggerHoughCand > &rejected, unsigned short nSLmax) const
Recursive function to add combine connected cells.
int fastInterceptFinder(CDCHitMap &hits, double x1_s, double x2_s, double y1_s, double y2_s, unsigned iterations, unsigned ix_s, unsigned iy_s)
Fast intercept finder Divide Hough plane recursively to find cells with enough crossing lines.
double m_rectX
Store the rectangle size in x.
bool connectedDiag(unsigned patternLD, unsigned patternRU)
Check for diagonal connected of patterns in 2 x 2 squares.
double m_maxR
Hough plane limit in 1/r [1/cm].
unsigned topRightSquare(std::vector< unsigned > &pattern)
Find the top right square within a cluster of 2 x 2 squares In case of ambiguity, top is favored over...
std::string m_clusterCollectionName
Name of the StoreArray containing the clusters formed in the Hough plane.
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
double m_rectY
Store the rectangle size in y.
bool m_onlyLocalMax
switch to ignore candidates connected to cells with higher super layer count
bool m_useDB
switch to use database to load run dependent parameter
DBObjPtr< CDCTrigger2DConfig > m_cdctrg2d_DB
run dependent parameter database of 2D
unsigned m_clusterSizeY
maximum cluster size for pattern algorithm
CDCHitMap m_hitMap
map of TS hits containing <iHit, <iSL, (x, y)>> with iHit: hit index in StoreArray iSL: super layer i...
void connectedRegions()
Combine Hough candidates to tracks by merging connected cells.
std::vector< unsigned > m_hitList
list of hit indices contained in the Hough cell
unsigned getID() const
Get candidate number.
Coord2dPair m_coord
Coordinate of rectangle for this candidate.
std::vector< unsigned > getIdList() const
Get Index list.
CDCTriggerHoughCand(std::vector< unsigned > &_list, Coord2dPair _coord, unsigned short _slcount, unsigned _id)
Constructor for hough candidates.
unsigned short m_SLcount
Super layer count (number of hits from different super layers).
Coord2dPair getCoord() const
Get rectangle coordinates.
unsigned short getSLcount() const
Get super layer count.
unsigned m_id
candidate number, for debugging.
Class for accessing objects in the database.
Definition DBObjPtr.h:21
Module()
Constructor.
Definition Module.cc:30
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
bool operator==(const DecayNode &node1, const DecayNode &node2)
Compare two Decay Nodes: They are equal if All daughter decay nodes are equal or one of the daughter ...
Definition DecayNode.cc:47
std::pair< unsigned short, ROOT::Math::XYVector > CDCPair
Pair of <iSuperLayer, (x, y)>, for hits in conformal space.
std::unordered_map< int, CDCPair > CDCHitMap
Map of <counter, CDCPair>, for hits with indices.
std::pair< ROOT::Math::XYVector, ROOT::Math::XYVector > Coord2dPair
Hough Tuples.
Abstract base class for different kinds of events.