Belle II Software  release-05-02-19
CDCTrigger2DFinderModule.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012-2014 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Michael Schnell, Sara Neuhaus *
7  * *
8  **************************************************************************/
9 
10 #ifndef CDCTrigger2DFinderModule_H
11 #define CDCTrigger2DFinderModule_H
12 
13 #include <framework/core/Module.h>
14 
15 #include <utility>
16 #include <map>
17 #include <vector>
18 #include <fstream>
19 
20 #include <root/TVector2.h>
21 
22 #include <framework/datastore/StoreArray.h>
23 #include <framework/datastore/StoreObjPtr.h>
24 #include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
25 #include <trg/cdc/dataobjects/CDCTriggerTrack.h>
26 #include <trg/cdc/dataobjects/CDCTriggerHoughCluster.h>
27 
28 namespace Belle2 {
34  typedef std::pair<unsigned short, TVector2> cdcPair;
36  typedef std::map<int, cdcPair> cdcMap;
38  typedef std::pair<TVector2, TVector2> coord2dPair;
39 
46  class CDCTriggerHoughCand {
47  public:
49  CDCTriggerHoughCand(std::vector<unsigned>& _list, coord2dPair _coord,
50  unsigned short _slcount, unsigned _id):
51  hitList(_list), coord(_coord), SLcount(_slcount), id(_id) {}
52 
54 
56  std::vector<unsigned> getIdList() const { return hitList; }
58  coord2dPair getCoord() const { return coord; }
60  unsigned short getSLcount() const { return SLcount; }
62  unsigned getID() const { return id; }
63 
64  private:
66  std::vector<unsigned> hitList;
70  unsigned short SLcount = 0;
72  unsigned id = 0;
73  };
74 
76  inline bool operator==(const CDCTriggerHoughCand& a, const CDCTriggerHoughCand& b)
77  {
78  return (a.getCoord().first.X() == b.getCoord().first.X() &&
79  a.getCoord().first.Y() == b.getCoord().first.Y());
80  }
81 
82 
86  class CDCTrigger2DFinderModule : public Module {
87  public:
90 
92  virtual void initialize() override;
94  virtual void event() override;
96  virtual void terminate() override;
97 
104  int fastInterceptFinder(cdcMap& hits,
105  double x1_s, double x2_s, double y1_s, double y2_s,
106  unsigned iterations,
107  unsigned ix_s, unsigned iy_s);
108 
111  unsigned short countSL(bool*);
115  bool shortTrack(bool*);
116 
119  void connectedRegions();
131  void addNeighbors(const CDCTriggerHoughCand& center,
132  const std::vector<CDCTriggerHoughCand>& candidates,
133  std::vector<CDCTriggerHoughCand>& merged,
134  std::vector<CDCTriggerHoughCand>& rejected,
135  unsigned short nSLmax) const;
137  bool inList(const CDCTriggerHoughCand& a, const std::vector<CDCTriggerHoughCand>& list) const;
139  bool connected(const CDCTriggerHoughCand& a, const CDCTriggerHoughCand& b) const;
141  void mergeIdList(std::vector<unsigned>& merged, std::vector<unsigned>& a, std::vector<unsigned>& b);
142 
145  void patternClustering(const cdcMap& inputMap);
147  bool connectedLR(unsigned patternL, unsigned patternR);
149  bool connectedUD(unsigned patternD, unsigned patternU);
151  bool connectedDiag(unsigned patternLD, unsigned patternRU);
155  unsigned topRightSquare(std::vector<unsigned>& pattern);
161  unsigned topRightCorner(unsigned pattern);
167  unsigned bottomLeftCorner(unsigned pattern);
168 
171  void findAllCrossingHits(std::vector<unsigned>& list,
172  double x1, double x2, double y1, double y2,
173  const cdcMap& inputMap);
178  void selectHits(std::vector<unsigned>& list, std::vector<unsigned>& selected,
179  std::vector<unsigned>& unselected);
180 
181  protected:
182 
184  std::string m_hitCollectionName;
186  std::string m_outputCollectionName;
188  std::string m_clusterCollectionName;
190  unsigned m_nCellsPhi;
192  unsigned m_nCellsR;
194  double m_minPt;
201  double maxR = 0.;
203  double shiftR = 0.;
206  unsigned maxIterations = 0;
208  unsigned nCells = 0;
209 
212  unsigned m_minHits;
215  unsigned m_minHitsShort;
217  unsigned m_minCells;
223  unsigned m_connect;
225  bool m_ignore2nd;
227  bool m_usePriority;
229  bool m_requireSL0;
230 
233 
236  unsigned m_storePlane;
238  bool m_clusterPattern;
240  unsigned m_clusterSizeX;
242  unsigned m_clusterSizeY;
250 
252  std::string m_testFilename;
254  std::ofstream testFile;
255 
263  std::vector<CDCTriggerHoughCand> houghCand;
264 
266  double radius[9][2] = {{0.}};
268  unsigned TSoffset[10] = {0};
269 
278  };//end class declaration
280 } // end namespace Belle2
281 
282 #endif // CDCTrigger2DFinderModule_H
Belle2::CDCTrigger2DFinderModule::m_suppressClone
bool m_suppressClone
switch to send only the first found track and suppress the subsequent clones
Definition: CDCTrigger2DFinderModule.h:239
Belle2::CDCTrigger2DFinderModule::houghCand
std::vector< CDCTriggerHoughCand > houghCand
Hough Candidates.
Definition: CDCTrigger2DFinderModule.h:270
Belle2::CDCTrigger2DFinderModule::hitMap
cdcMap hitMap
map of TS hits containing <iHit, <iSL, (x, y)>> with iHit: hit index in StoreArray iSL: super layer i...
Definition: CDCTrigger2DFinderModule.h:268
Belle2::CDCTriggerHoughCand::hitList
std::vector< unsigned > hitList
list of hit indices contained in the Hough cell
Definition: CDCTriggerHoughETFModule.h:74
Belle2::CDCTrigger2DFinderModule::connectedLR
bool connectedLR(unsigned patternL, unsigned patternR)
Check for left/right connection of patterns in 2 x 2 squares.
Definition: CDCTriggerHoughtrafo.cc:658
Belle2::CDCTrigger2DFinderModule::maxIterations
unsigned maxIterations
number of iterations for the fast peak finder, smallest n such that 2^(n+1) > max(nCellsPhi,...
Definition: CDCTrigger2DFinderModule.h:213
Belle2::CDCTrigger2DFinderModule::m_shiftPt
int m_shiftPt
shift the Hough plane in 1/r to avoid curvature 0 tracks < 0: shift in negative direction (negative h...
Definition: CDCTrigger2DFinderModule.h:206
Belle2::CDCTrigger2DFinderModule::m_houghPlane
StoreObjPtr< TMatrix > m_houghPlane
matrix containing the Hough plane
Definition: CDCTrigger2DFinderModule.h:284
Belle2::CDCTrigger2DFinderModule::m_hitCollectionName
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
Definition: CDCTrigger2DFinderModule.h:191
Belle2::CDCTrigger2DFinderModule::CDCTrigger2DFinderModule
CDCTrigger2DFinderModule()
Constructor.
Definition: CDCTrigger2DFinderModule.cc:36
Belle2::CDCTrigger2DFinderModule::m_minPt
double m_minPt
Hough plane limit in Pt [GeV].
Definition: CDCTrigger2DFinderModule.h:201
Belle2::operator==
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:50
Belle2::CDCTriggerHoughCand::getID
unsigned getID() const
Get candidate number.
Definition: CDCTriggerHoughETFModule.h:70
Belle2::CDCTrigger2DFinderModule::topRightCorner
unsigned topRightCorner(unsigned pattern)
Find the top right corner within 2 x 2 square.
Definition: CDCTriggerHoughtrafo.cc:758
Belle2::CDCTrigger2DFinderModule::m_nCellsR
unsigned m_nCellsR
number of Hough cells in 1/r
Definition: CDCTrigger2DFinderModule.h:199
Belle2::CDCTrigger2DFinderModule::m_testFilename
std::string m_testFilename
filename for test output for firmware debugging
Definition: CDCTrigger2DFinderModule.h:259
Belle2::CDCTrigger2DFinderModule::topRightSquare
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...
Definition: CDCTriggerHoughtrafo.cc:728
Belle2::CDCTrigger2DFinderModule::m_ignore2nd
bool m_ignore2nd
switch to skip second priority hits
Definition: CDCTrigger2DFinderModule.h:232
Belle2::CDCTrigger2DFinderModule::shortTrack
bool shortTrack(bool *)
check the short track condition (= hits in the inner super layers rather than any super layers)
Definition: CDCTriggerHoughtrafo.cc:36
Belle2::CDCTrigger2DFinderModule::m_minHitsShort
unsigned m_minHitsShort
short tracks require hits in the first minHitsShort super layers to form a candidate
Definition: CDCTrigger2DFinderModule.h:222
Belle2::cdcMap
std::map< int, cdcPair > cdcMap
Map of <counter, cdcPair>, for hits with indices.
Definition: CDCTriggerHoughETFModule.h:44
Belle2::CDCTrigger2DFinderModule::bottomLeftCorner
unsigned bottomLeftCorner(unsigned pattern)
Find the bottom left corner within 2 x 2 square.
Definition: CDCTriggerHoughtrafo.cc:776
Belle2::CDCTrigger2DFinderModule::m_onlyLocalMax
bool m_onlyLocalMax
switch to ignore candidates connected to cells with higher super layer count
Definition: CDCTrigger2DFinderModule.h:226
Belle2::CDCTriggerHoughCand::CDCTriggerHoughCand
CDCTriggerHoughCand(std::vector< unsigned > &_list, coord2dPair _coord, unsigned short _slcount, unsigned _id)
Constructor for hough candidates.
Definition: CDCTriggerHoughETFModule.h:57
Belle2::CDCTrigger2DFinderModule::fastInterceptFinder
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.
Definition: CDCTriggerHoughtrafo.cc:58
Belle2::CDCTrigger2DFinderModule::m_connect
unsigned m_connect
number of neighbors to check for connection (4: direct, 6: direct + upper right and lower left corner...
Definition: CDCTrigger2DFinderModule.h:230
Belle2::CDCTriggerHoughCand::id
unsigned id
candidate number, for debugging.
Definition: CDCTriggerHoughETFModule.h:80
Belle2::CDCTrigger2DFinderModule::m_requireSL0
bool m_requireSL0
switch to check separately for a hit in the innermost super layer
Definition: CDCTrigger2DFinderModule.h:236
Belle2::CDCTrigger2DFinderModule::connectedUD
bool connectedUD(unsigned patternD, unsigned patternU)
Check for up/down connection of patterns in 2 x 2 squares.
Definition: CDCTriggerHoughtrafo.cc:682
Belle2::CDCTriggerHoughCand::coord
coord2dPair coord
Coordinate of rectangle for this candidate.
Definition: CDCTriggerHoughETFModule.h:76
Belle2::CDCTrigger2DFinderModule::inList
bool inList(const CDCTriggerHoughCand &a, const std::vector< CDCTriggerHoughCand > &list) const
Check if candidate is in list.
Definition: CDCTriggerHoughtrafo.cc:330
Belle2::CDCTrigger2DFinderModule::m_clusters
StoreArray< CDCTriggerHoughCluster > m_clusters
list of clusters in the Hough map
Definition: CDCTrigger2DFinderModule.h:282
Belle2::CDCTrigger2DFinderModule::connectedDiag
bool connectedDiag(unsigned patternLD, unsigned patternRU)
Check for diagonal connected of patterns in 2 x 2 squares.
Definition: CDCTriggerHoughtrafo.cc:715
Belle2::CDCTrigger2DFinderModule::terminate
virtual void terminate() override
Clean up.
Definition: CDCTrigger2DFinderModule.cc:305
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCTrigger2DFinderModule::event
virtual void event() override
Run tracking.
Definition: CDCTrigger2DFinderModule.cc:152
Belle2::StoreObjPtr< TMatrix >
Belle2::CDCTrigger2DFinderModule::m_outputCollectionName
std::string m_outputCollectionName
Name of the StoreArray containing the tracks found by the Hough tracking.
Definition: CDCTrigger2DFinderModule.h:193
Belle2::CDCTrigger2DFinderModule::m_minHits
unsigned m_minHits
minimum number of hits from different super layers in a Hough cell to form a candidate
Definition: CDCTrigger2DFinderModule.h:219
Belle2::coord2dPair
std::pair< TVector2, TVector2 > coord2dPair
Typedef for the coord2dPair, which represents the DATCONHoughCand.
Definition: DATCONHoughCand.h:32
Belle2::CDCTrigger2DFinderModule::testFile
std::ofstream testFile
filestream for test output for firmware debugging
Definition: CDCTrigger2DFinderModule.h:261
Belle2::CDCTriggerHoughCand
Hough Candidates class.
Definition: CDCTriggerHoughETFModule.h:54
Belle2::CDCTrigger2DFinderModule::patternClustering
void patternClustering(const cdcMap &inputMap)
Combine Hough candidates to tracks by a fixed pattern algorithm.
Definition: CDCTriggerHoughtrafo.cc:484
Belle2::CDCTriggerHoughCand::getSLcount
unsigned short getSLcount() const
Get super layer count.
Definition: CDCTriggerHoughETFModule.h:68
Belle2::CDCTrigger2DFinderModule::addNeighbors
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.
Definition: CDCTriggerHoughtrafo.cc:286
Belle2::CDCTrigger2DFinderModule::initialize
virtual void initialize() override
Initialize the module and check module parameters.
Definition: CDCTrigger2DFinderModule.cc:118
Belle2::CDCTrigger2DFinderModule::m_clusterSizeX
unsigned m_clusterSizeX
maximum cluster size for pattern algorithm
Definition: CDCTrigger2DFinderModule.h:247
Belle2::CDCTrigger2DFinderModule::m_clusterPattern
bool m_clusterPattern
switch for clustering algorithm (if true use nested patterns)
Definition: CDCTrigger2DFinderModule.h:245
Belle2::CDCTriggerHoughCand::getIdList
std::vector< unsigned > getIdList() const
Get Index list.
Definition: CDCTriggerHoughETFModule.h:64
Belle2::CDCTrigger2DFinderModule::maxR
double maxR
Hough plane limit in 1/r [1/cm].
Definition: CDCTrigger2DFinderModule.h:208
Belle2::CDCTriggerHoughCand::SLcount
unsigned short SLcount
Super layer count (number of hits from different super layers).
Definition: CDCTriggerHoughETFModule.h:78
Belle2::CDCTrigger2DFinderModule::shiftR
double shiftR
Hough plane shift in 1/r [1/cm].
Definition: CDCTrigger2DFinderModule.h:210
Belle2::CDCTrigger2DFinderModule::connected
bool connected(const CDCTriggerHoughCand &a, const CDCTriggerHoughCand &b) const
Check if candidates are connected.
Definition: CDCTriggerHoughtrafo.cc:340
Belle2::cdcPair
std::pair< unsigned short, TVector2 > cdcPair
Pair of <iSuperLayer, (x, y)>, for hits in conformal space.
Definition: CDCTriggerHoughETFModule.h:42
Belle2::CDCTrigger2DFinderModule::m_storePlane
unsigned m_storePlane
switch to save the Hough plane in DataStore (0: don't save, 1: save only peaks, 2: save full plane)
Definition: CDCTrigger2DFinderModule.h:243
Belle2::CDCTrigger2DFinderModule::radius
double radius[9][2]
Radius of the CDC layers with priority wires (2 per super layer).
Definition: CDCTrigger2DFinderModule.h:273
Belle2::CDCTrigger2DFinderModule::nCells
unsigned nCells
number of cells for the fast peak finder: 2^(maxIterations + 1).
Definition: CDCTrigger2DFinderModule.h:215
Belle2::CDCTrigger2DFinderModule::m_hitRelationsFromCorners
bool m_hitRelationsFromCorners
switch for creating relations to hits in the pattern clustering algorithm.
Definition: CDCTrigger2DFinderModule.h:256
Belle2::CDCTrigger2DFinderModule::mergeIdList
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.
Definition: CDCTriggerHoughtrafo.cc:378
Belle2::CDCTrigger2DFinderModule::connectedRegions
void connectedRegions()
Combine Hough candidates to tracks by merging connected cells.
Definition: CDCTriggerHoughtrafo.cc:175
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::CDCTrigger2DFinderModule::m_tracks
StoreArray< CDCTriggerTrack > m_tracks
list of found tracks
Definition: CDCTrigger2DFinderModule.h:280
Belle2::CDCTrigger2DFinderModule::selectHits
void selectHits(std::vector< unsigned > &list, std::vector< unsigned > &selected, std::vector< unsigned > &unselected)
Select one hit per super layer.
Definition: CDCTriggerHoughtrafo.cc:450
Belle2::CDCTrigger2DFinderModule::findAllCrossingHits
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,...
Definition: CDCTriggerHoughtrafo.cc:412
Belle2::CDCTrigger2DFinderModule::m_clusterSizeY
unsigned m_clusterSizeY
maximum cluster size for pattern algorithm
Definition: CDCTrigger2DFinderModule.h:249
Belle2::CDCTrigger2DFinderModule::m_usePriority
bool m_usePriority
switch between priority position and center position of track segment
Definition: CDCTrigger2DFinderModule.h:234
Belle2::CDCTrigger2DFinderModule::countSL
unsigned short countSL(bool *)
count the number of super layers with hits
Definition: CDCTriggerHoughtrafo.cc:25
Belle2::CDCTrigger2DFinderModule::TSoffset
unsigned TSoffset[10]
Number of track segments up to super layer.
Definition: CDCTrigger2DFinderModule.h:275
Belle2::CDCTrigger2DFinderModule::m_segmentHits
StoreArray< CDCTriggerSegmentHit > m_segmentHits
list of track segment hits
Definition: CDCTrigger2DFinderModule.h:278
Belle2::CDCTrigger2DFinderModule::m_clusterCollectionName
std::string m_clusterCollectionName
Name of the StoreArray containing the clusters formed in the Hough plane.
Definition: CDCTrigger2DFinderModule.h:195
Belle2::CDCTriggerHoughCand::getCoord
coord2dPair getCoord() const
Get rectangle coordinates.
Definition: CDCTriggerHoughETFModule.h:66
Belle2::CDCTrigger2DFinderModule::m_nCellsPhi
unsigned m_nCellsPhi
number of Hough cells in phi
Definition: CDCTrigger2DFinderModule.h:197
Belle2::CDCTrigger2DFinderModule::m_minCells
unsigned m_minCells
minimum number of cells in a cluster to form a track
Definition: CDCTrigger2DFinderModule.h:224