Belle II Software development
CDCTriggerHoughETFModule.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 CDCTriggerHoughETFModule_H
10#define CDCTriggerHoughETFModule_H
11
12#include <framework/core/Module.h>
13
14#include <utility>
15#include <map>
16#include <vector>
17#include <fstream>
18
19#include <framework/datastore/StoreArray.h>
20#include <framework/datastore/StoreObjPtr.h>
21#include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
22#include <trg/cdc/dataobjects/CDCTriggerTrack.h>
23#include <trg/cdc/dataobjects/CDCTriggerHoughCluster.h>
24#include <framework/dataobjects/BinnedEventT0.h>
25
26#include <TMatrix.h>
27#include <Math/Vector2D.h>
28
29namespace Belle2 {
35 typedef std::pair<unsigned short, ROOT::Math::XYVector> cdcPair;
37 typedef std::map<int, cdcPair> cdcMap;
39 typedef std::pair<ROOT::Math::XYVector, ROOT::Math::XYVector> coord2dPair;
40
48 public:
50 CDCTriggerHoughCand(std::vector<unsigned>& _list, coord2dPair _coord,
51 unsigned short _slcount, unsigned _id):
52 hitList(_list), coord(_coord), SLcount(_slcount), id(_id) {}
53
55
57 std::vector<unsigned> getIdList() const { return hitList; }
59 coord2dPair getCoord() const { return coord; }
61 unsigned short getSLcount() const { return SLcount; }
63 unsigned getID() const { return id; }
64
65 private:
67 std::vector<unsigned> hitList;
71 unsigned short SLcount = 0;
73 unsigned id = 0;
74 };
75
77 inline bool operator==(const CDCTriggerHoughCand& a, const CDCTriggerHoughCand& b)
78 {
79 return (a.getCoord().first.X() == b.getCoord().first.X() &&
80 a.getCoord().first.Y() == b.getCoord().first.Y());
81 }
82
83
85 public:
88
90 virtual void initialize() override;
92 virtual void event() override;
94 virtual void terminate() override;
95
102 int fastInterceptFinder(cdcMap& hits,
103 double x1_s, double x2_s, double y1_s, double y2_s,
104 unsigned iterations,
105 unsigned ix_s, unsigned iy_s);
106
109 unsigned short countSL(bool* superLayers);
113 bool shortTrack(bool* superLayers);
114
117 void connectedRegions();
129 void addNeighbors(const CDCTriggerHoughCand& center,
130 const std::vector<CDCTriggerHoughCand>& candidates,
131 std::vector<CDCTriggerHoughCand>& merged,
132 std::vector<CDCTriggerHoughCand>& rejected,
133 unsigned short nSLmax) const;
135 bool inList(const CDCTriggerHoughCand& a, const std::vector<CDCTriggerHoughCand>& list) const;
137 bool connected(const CDCTriggerHoughCand& a, const CDCTriggerHoughCand& b) const;
139 void mergeIdList(std::vector<unsigned>& merged, std::vector<unsigned>& a, std::vector<unsigned>& b);
140
143 bool patternClustering(const cdcMap& inputMap);
145 bool connectedLR(unsigned patternL, unsigned patternR);
147 bool connectedUD(unsigned patternD, unsigned patternU);
149 bool connectedDiag(unsigned patternLD, unsigned patternRU);
153 unsigned topRightSquare(std::vector<unsigned>& pattern);
159 unsigned topRightCorner(unsigned pattern);
165 unsigned bottomLeftCorner(unsigned pattern);
166
169 void findAllCrossingHits(std::vector<unsigned>& list,
170 double x1, double x2, double y1, double y2,
171 const cdcMap& inputMap);
176 void selectHits(std::vector<unsigned>& list, std::vector<unsigned>& selected,
177 std::vector<unsigned>& unselected);
178
179 int getSector(int id, int sl);
180 std::vector<int> sectorTimingList();
181 std::vector<int> highPassTimingList();
182 int calcEventTiming();
183 int median(std::vector<int> v);
184 int medianInTimeWindow(std::vector<int> v);
185
186
187
188 protected:
189
193 std::string m_EventTimeName;
199 std::vector<std::vector<CDCTriggerSegmentHit*>> associatedTSHitsList;
215
216
224 unsigned m_nCellsPhi;
226 unsigned m_nCellsR;
228 double m_minPt;
235 double maxR = 0.;
237 double shiftR = 0.;
240 unsigned maxIterations = 0;
242 unsigned nCells = 0;
243
246 unsigned m_minHits;
251 unsigned m_minCells;
257 unsigned m_connect;
264
267
270 unsigned m_storePlane;
284
286 int m_offset = 0;
287
289 std::string m_testFilename;
291 std::ofstream testFile;
292
300 std::vector<CDCTriggerHoughCand> houghCand;
301
303 double radius[9][2] = {{0.}};
305 unsigned TSoffset[10] = {0};
307 const int NTS [9] = {160, 160, 192, 224, 256, 288, 320, 352, 384};
309 const int NSEC [9] = {16, 0, 16, 0, 16, 0, 8, 0, 8};
311 int NSecOffset [9] = {0};
312
321 };//end class declaration
323} // end namespace Belle2
324
325#endif // CDCTrigger2DFinderModule_H
coord2dPair coord
Coordinate of rectangle for this candidate.
unsigned short SLcount
Super layer count (number of hits from different super layers).
coord2dPair getCoord() const
Get rectangle coordinates.
unsigned getID() const
Get candidate number.
std::vector< unsigned > hitList
list of hit indices contained in the Hough cell
unsigned id
candidate number, for debugging.
std::vector< unsigned > getIdList() const
Get Index list.
unsigned short getSLcount() const
Get super layer count.
CDCTriggerHoughCand(std::vector< unsigned > &_list, coord2dPair _coord, unsigned short _slcount, unsigned _id)
Constructor for hough candidates.
std::string m_EventTimeName
Name of the StoreObject containing the trigger event time.
int NSecOffset[9]
Number of sector offset of each super layer.
std::vector< CDCTriggerHoughCand > houghCand
Hough Candidates.
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.
std::string m_testFilename
filename for test output for firmware debugging
int fastInterceptFinder(cdcMap &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.
bool m_useHighPassTimingList
Use associated fastest timings track-by-track.
unsigned m_minCells
minimum number of cells in a cluster to form a track
std::ofstream testFile
filestream for test output for firmware debugging
bool connectedUD(unsigned patternD, unsigned patternU)
Check for up/down connection of patterns in 2 x 2 squares.
unsigned maxIterations
number of iterations for the fast peak finder, smallest n such that 2^(n+1) > max(nCellsPhi,...
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...
virtual void event() override
Run tracking.
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
StoreArray< CDCTriggerSegmentHit > m_hits
list of input track segment hits
bool m_usePriority
switch between priority position and center position of track segment
short m_timeWindowEnd
End time of time window relative to median.
bool m_clusterPattern
switch for clustering algorithm (if true use nested patterns)
unsigned short countSL(bool *superLayers)
count the number of super layers with hits
double maxR
Hough plane limit in 1/r [1/cm].
virtual void terminate() override
Clean up.
bool m_hitRelationsFromCorners
switch for creating relations to hits in the pattern clustering algorithm.
std::vector< std::vector< CDCTriggerSegmentHit * > > associatedTSHitsList
list of fastest timing of TS associated with Track
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...
double shiftR
Hough plane shift in 1/r [1/cm].
void findAllCrossingHits(std::vector< unsigned > &list, double x1, double x2, double y1, double y2, const cdcMap &inputMap)
Find all hits in inputMap whose Hough curve crosses the rectangle with corners (x1,...
unsigned nCells
number of cells for the fast peak finder: 2^(maxIterations + 1).
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
unsigned m_t0CalcMethod
Switch method to determine the event timing.
double radius[9][2]
Radius of the CDC layers with priority wires (2 per super layer).
StoreArray< CDCTriggerTrack > m_tracks
list of found tracks
cdcMap hitMap
map of TS hits containing <iHit, <iSL, (x, y)>> with iHit: hit index in StoreArray iSL: super layer i...
int m_offset
offset for ETF simulation
unsigned m_arrivalOrder
arrival order of fastest timing used as t0 (effective when t0CalcMEthod == 0)
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.
const int NSEC[9]
Number of sector in each super layer.
bool m_requireSL0
switch to check separately for a hit in the innermost super layer
short m_timeWindowBegin
Start time of time window relative to median.
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.
const int NTS[9]
Number of track segments in each super layers.
StoreObjPtr< BinnedEventT0 > m_eventTime
StoreObjPtr holding the event time.
bool shortTrack(bool *superLayers)
check the short track condition (= hits in the inner super layers rather than any super layers)
bool connectedDiag(unsigned patternLD, unsigned patternRU)
Check for diagonal connected of patterns in 2 x 2 squares.
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...
unsigned TSoffset[10]
Number of track segments up to super layer.
std::string m_clusterCollectionName
Name of the StoreArray containing the clusters formed in the Hough plane.
bool m_storeTracks
Switch to save the 2D Hough track reconstructed in this module.
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
bool patternClustering(const cdcMap &inputMap)
Combine Hough candidates to tracks by a fixed pattern algorithm.
bool m_onlyLocalMax
switch to ignore candidates connected to cells with higher super layer count
bool m_usePriorityTiming
Switch to use priority timing instead of fastest timing.
unsigned m_clusterSizeY
maximum cluster size for pattern algorithm
void connectedRegions()
Combine Hough candidates to tracks by merging connected cells.
Base class for Modules.
Definition: Module.h:72
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:48
std::map< int, cdcPair > cdcMap
Map of <counter, cdcPair>, for hits with indices.
std::pair< ROOT::Math::XYVector, ROOT::Math::XYVector > coord2dPair
Hough Tuples.
std::pair< unsigned short, ROOT::Math::XYVector > cdcPair
Pair of <iSuperLayer, (x, y)>, for hits in conformal space.
Abstract base class for different kinds of events.