Belle II Software  release-05-02-19
CDCTriggerHoughETFModule.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 CDCTriggerHoughETFModule_H
11 #define CDCTriggerHoughETFModule_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 #include <framework/dataobjects/BinnedEventT0.h>
28 
29 namespace Belle2 {
35  typedef std::pair<unsigned short, TVector2> cdcPair;
37  typedef std::map<int, cdcPair> cdcMap;
39  typedef std::pair<TVector2, TVector2> coord2dPair;
40 
47  class CDCTriggerHoughCand {
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 
87  class CDCTriggerHoughETFModule : public Module {
88  public:
91 
93  virtual void initialize() override;
95  virtual void event() override;
97  virtual void terminate() override;
98 
105  int fastInterceptFinder(cdcMap& hits,
106  double x1_s, double x2_s, double y1_s, double y2_s,
107  unsigned iterations,
108  unsigned ix_s, unsigned iy_s);
109 
112  unsigned short countSL(bool*);
116  bool shortTrack(bool*);
117 
120  void connectedRegions();
132  void addNeighbors(const CDCTriggerHoughCand& center,
133  const std::vector<CDCTriggerHoughCand>& candidates,
134  std::vector<CDCTriggerHoughCand>& merged,
135  std::vector<CDCTriggerHoughCand>& rejected,
136  unsigned short nSLmax) const;
138  bool inList(const CDCTriggerHoughCand& a, const std::vector<CDCTriggerHoughCand>& list) const;
140  bool connected(const CDCTriggerHoughCand& a, const CDCTriggerHoughCand& b) const;
142  void mergeIdList(std::vector<unsigned>& merged, std::vector<unsigned>& a, std::vector<unsigned>& b);
143 
146  bool patternClustering(const cdcMap& inputMap);
148  bool connectedLR(unsigned patternL, unsigned patternR);
150  bool connectedUD(unsigned patternD, unsigned patternU);
152  bool connectedDiag(unsigned patternLD, unsigned patternRU);
156  unsigned topRightSquare(std::vector<unsigned>& pattern);
162  unsigned topRightCorner(unsigned pattern);
168  unsigned bottomLeftCorner(unsigned pattern);
169 
172  void findAllCrossingHits(std::vector<unsigned>& list,
173  double x1, double x2, double y1, double y2,
174  const cdcMap& inputMap);
179  void selectHits(std::vector<unsigned>& list, std::vector<unsigned>& selected,
180  std::vector<unsigned>& unselected);
181 
182  float calcEventTiming();
183  int median(std::vector<int> v);
184  int medianInTimeWindow(std::vector<int> v);
185 
186 
187  protected:
188 
192  std::string m_EventTimeName;
194  bool m_storeTracks;
198  std::vector<std::vector<CDCTriggerSegmentHit*>> associatedTSHitsList;
200  bool m_usePriorityTiming;
202  unsigned m_t0CalcMethod;
205  unsigned m_arrivalOrder;
208  short m_timeWindowStart;
211  short m_timeWindowEnd;
212 
213 
215  std::string m_hitCollectionName;
217  std::string m_outputCollectionName;
219  std::string m_clusterCollectionName;
221  unsigned m_nCellsPhi;
223  unsigned m_nCellsR;
225  double m_minPt;
232  double maxR = 0.;
234  double shiftR = 0.;
237  unsigned maxIterations = 0;
239  unsigned nCells = 0;
240 
243  unsigned m_minHits;
246  unsigned m_minHitsShort;
248  unsigned m_minCells;
254  unsigned m_connect;
256  bool m_ignore2nd;
258  bool m_usePriority;
260  bool m_requireSL0;
261 
264 
267  unsigned m_storePlane;
269  bool m_clusterPattern;
271  unsigned m_clusterSizeX;
273  unsigned m_clusterSizeY;
281 
283  std::string m_testFilename;
285  std::ofstream testFile;
286 
294  std::vector<CDCTriggerHoughCand> houghCand;
295 
297  double radius[9][2] = {{0.}};
299  unsigned TSoffset[10] = {0};
300 
309  };//end class declaration
311 } // end namespace Belle2
312 
313 #endif // CDCTrigger2DFinderModule_H
Belle2::CDCTriggerHoughETFModule::m_usePriorityTiming
bool m_usePriorityTiming
Switch to use priority timing instead of fastest timing.
Definition: CDCTriggerHoughETFModule.h:207
Belle2::CDCTriggerHoughETFModule::m_clusterCollectionName
std::string m_clusterCollectionName
Name of the StoreArray containing the clusters formed in the Hough plane.
Definition: CDCTriggerHoughETFModule.h:226
Belle2::CDCTriggerHoughETFModule::nCells
unsigned nCells
number of cells for the fast peak finder: 2^(maxIterations + 1).
Definition: CDCTriggerHoughETFModule.h:246
Belle2::CDCTriggerHoughETFModule::m_timeWindowEnd
short m_timeWindowEnd
End time of time window relative to median.
Definition: CDCTriggerHoughETFModule.h:218
Belle2::CDCTriggerHoughETFModule::connectedRegions
void connectedRegions()
Combine Hough candidates to tracks by merging connected cells.
Definition: CDCTriggerHoughtrafoForETF.cc:178
Belle2::CDCTriggerHoughETFModule::m_outputCollectionName
std::string m_outputCollectionName
Name of the StoreArray containing the tracks found by the Hough tracking.
Definition: CDCTriggerHoughETFModule.h:224
Belle2::CDCTriggerHoughETFModule::m_EventTimeName
std::string m_EventTimeName
Name of the StoreObject containing the trigger event time.
Definition: CDCTriggerHoughETFModule.h:199
Belle2::CDCTriggerHoughCand::hitList
std::vector< unsigned > hitList
list of hit indices contained in the Hough cell
Definition: CDCTriggerHoughETFModule.h:74
Belle2::CDCTriggerHoughETFModule::m_minCells
unsigned m_minCells
minimum number of cells in a cluster to form a track
Definition: CDCTriggerHoughETFModule.h:255
Belle2::CDCTriggerHoughETFModule::m_usePriority
bool m_usePriority
switch between priority position and center position of track segment
Definition: CDCTriggerHoughETFModule.h:265
Belle2::CDCTriggerHoughETFModule::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: CDCTriggerHoughETFModule.h:237
Belle2::CDCTriggerHoughETFModule::connectedUD
bool connectedUD(unsigned patternD, unsigned patternU)
Check for up/down connection of patterns in 2 x 2 squares.
Definition: CDCTriggerHoughtrafoForETF.cc:701
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::CDCTriggerHoughETFModule::m_clusterSizeY
unsigned m_clusterSizeY
maximum cluster size for pattern algorithm
Definition: CDCTriggerHoughETFModule.h:280
Belle2::CDCTriggerHoughETFModule::maxR
double maxR
Hough plane limit in 1/r [1/cm].
Definition: CDCTriggerHoughETFModule.h:239
Belle2::CDCTriggerHoughETFModule::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: CDCTriggerHoughtrafoForETF.cc:61
Belle2::CDCTriggerHoughETFModule::radius
double radius[9][2]
Radius of the CDC layers with priority wires (2 per super layer).
Definition: CDCTriggerHoughETFModule.h:304
Belle2::CDCTriggerHoughETFModule
Definition: CDCTriggerHoughETFModule.h:94
Belle2::CDCTriggerHoughETFModule::m_minPt
double m_minPt
Hough plane limit in Pt [GeV].
Definition: CDCTriggerHoughETFModule.h:232
Belle2::CDCTriggerHoughETFModule::shiftR
double shiftR
Hough plane shift in 1/r [1/cm].
Definition: CDCTriggerHoughETFModule.h:241
Belle2::CDCTriggerHoughETFModule::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: CDCTriggerHoughtrafoForETF.cc:289
Belle2::CDCTriggerHoughETFModule::m_hitRelationsFromCorners
bool m_hitRelationsFromCorners
switch for creating relations to hits in the pattern clustering algorithm.
Definition: CDCTriggerHoughETFModule.h:287
Belle2::CDCTriggerHoughETFModule::m_clusters
StoreArray< CDCTriggerHoughCluster > m_clusters
list of clusters in the Hough map
Definition: CDCTriggerHoughETFModule.h:313
Belle2::CDCTriggerHoughETFModule::shortTrack
bool shortTrack(bool *)
check the short track condition (= hits in the inner super layers rather than any super layers)
Definition: CDCTriggerHoughtrafoForETF.cc:39
Belle2::CDCTriggerHoughETFModule::m_nCellsPhi
unsigned m_nCellsPhi
number of Hough cells in phi
Definition: CDCTriggerHoughETFModule.h:228
Belle2::CDCTriggerHoughETFModule::m_testFilename
std::string m_testFilename
filename for test output for firmware debugging
Definition: CDCTriggerHoughETFModule.h:290
Belle2::cdcMap
std::map< int, cdcPair > cdcMap
Map of <counter, cdcPair>, for hits with indices.
Definition: CDCTriggerHoughETFModule.h:44
Belle2::CDCTriggerHoughETFModule::initialize
virtual void initialize() override
Initialize the module and check module parameters.
Definition: CDCTriggerHoughETFModule.cc:152
Belle2::CDCTriggerHoughETFModule::event
virtual void event() override
Run tracking.
Definition: CDCTriggerHoughETFModule.cc:193
Belle2::CDCTriggerHoughETFModule::m_minHits
unsigned m_minHits
minimum number of hits from different super layers in a Hough cell to form a candidate
Definition: CDCTriggerHoughETFModule.h:250
Belle2::CDCTriggerHoughETFModule::TSoffset
unsigned TSoffset[10]
Number of track segments up to super layer.
Definition: CDCTriggerHoughETFModule.h:306
Belle2::CDCTriggerHoughCand::CDCTriggerHoughCand
CDCTriggerHoughCand(std::vector< unsigned > &_list, coord2dPair _coord, unsigned short _slcount, unsigned _id)
Constructor for hough candidates.
Definition: CDCTriggerHoughETFModule.h:57
Belle2::CDCTriggerHoughETFModule::m_onlyLocalMax
bool m_onlyLocalMax
switch to ignore candidates connected to cells with higher super layer count
Definition: CDCTriggerHoughETFModule.h:257
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::CDCTriggerHoughETFModule::associatedTSHitsList
std::vector< std::vector< CDCTriggerSegmentHit * > > associatedTSHitsList
list of fastest timing of TS associated with Track
Definition: CDCTriggerHoughETFModule.h:205
Belle2::CDCTriggerHoughCand::id
unsigned id
candidate number, for debugging.
Definition: CDCTriggerHoughETFModule.h:80
Belle2::CDCTriggerHoughETFModule::connected
bool connected(const CDCTriggerHoughCand &a, const CDCTriggerHoughCand &b) const
Check if candidates are connected.
Definition: CDCTriggerHoughtrafoForETF.cc:343
Belle2::CDCTriggerHoughETFModule::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: CDCTriggerHoughETFModule.h:274
Belle2::CDCTriggerHoughETFModule::hitMap
cdcMap hitMap
map of TS hits containing <iHit, <iSL, (x, y)>> with iHit: hit index in StoreArray iSL: super layer i...
Definition: CDCTriggerHoughETFModule.h:299
Belle2::CDCTriggerHoughETFModule::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: CDCTriggerHoughtrafoForETF.cc:747
Belle2::CDCTriggerHoughETFModule::topRightCorner
unsigned topRightCorner(unsigned pattern)
Find the top right corner within 2 x 2 square.
Definition: CDCTriggerHoughtrafoForETF.cc:777
Belle2::CDCTriggerHoughETFModule::testFile
std::ofstream testFile
filestream for test output for firmware debugging
Definition: CDCTriggerHoughETFModule.h:292
Belle2::CDCTriggerHoughETFModule::m_requireSL0
bool m_requireSL0
switch to check separately for a hit in the innermost super layer
Definition: CDCTriggerHoughETFModule.h:267
Belle2::CDCTriggerHoughETFModule::m_tracks
StoreArray< CDCTriggerTrack > m_tracks
list of found tracks
Definition: CDCTriggerHoughETFModule.h:311
Belle2::CDCTriggerHoughETFModule::patternClustering
bool patternClustering(const cdcMap &inputMap)
Combine Hough candidates to tracks by a fixed pattern algorithm.
Definition: CDCTriggerHoughtrafoForETF.cc:488
Belle2::CDCTriggerHoughETFModule::m_t0CalcMethod
unsigned m_t0CalcMethod
Switch method to determine the event timing.
Definition: CDCTriggerHoughETFModule.h:209
Belle2::CDCTriggerHoughETFModule::terminate
virtual void terminate() override
Clean up.
Definition: CDCTriggerHoughETFModule.cc:350
Belle2::CDCTriggerHoughCand::coord
coord2dPair coord
Coordinate of rectangle for this candidate.
Definition: CDCTriggerHoughETFModule.h:76
Belle2::CDCTriggerHoughETFModule::countSL
unsigned short countSL(bool *)
count the number of super layers with hits
Definition: CDCTriggerHoughtrafoForETF.cc:28
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::CDCTriggerHoughETFModule::houghCand
std::vector< CDCTriggerHoughCand > houghCand
Hough Candidates.
Definition: CDCTriggerHoughETFModule.h:301
Belle2::CDCTriggerHoughETFModule::m_arrivalOrder
unsigned m_arrivalOrder
arrival order of fastest timing used as t0 (effective when t0CalcMEthod == 0)
Definition: CDCTriggerHoughETFModule.h:212
Belle2::coord2dPair
std::pair< TVector2, TVector2 > coord2dPair
Typedef for the coord2dPair, which represents the DATCONHoughCand.
Definition: DATCONHoughCand.h:32
Belle2::CDCTriggerHoughETFModule::m_clusterSizeX
unsigned m_clusterSizeX
maximum cluster size for pattern algorithm
Definition: CDCTriggerHoughETFModule.h:278
Belle2::CDCTriggerHoughETFModule::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: CDCTriggerHoughtrafoForETF.cc:415
Belle2::CDCTriggerHoughCand
Hough Candidates class.
Definition: CDCTriggerHoughETFModule.h:54
Belle2::CDCTriggerHoughETFModule::bottomLeftCorner
unsigned bottomLeftCorner(unsigned pattern)
Find the bottom left corner within 2 x 2 square.
Definition: CDCTriggerHoughtrafoForETF.cc:795
Belle2::CDCTriggerHoughETFModule::m_hits
StoreArray< CDCTriggerSegmentHit > m_hits
list of input track segment hits
Definition: CDCTriggerHoughETFModule.h:203
Belle2::CDCTriggerHoughETFModule::m_storeTracks
bool m_storeTracks
Switch to save the 2D Hough track reconstructed in this module.
Definition: CDCTriggerHoughETFModule.h:201
Belle2::CDCTriggerHoughCand::getSLcount
unsigned short getSLcount() const
Get super layer count.
Definition: CDCTriggerHoughETFModule.h:68
Belle2::CDCTriggerHoughETFModule::m_eventTime
StoreObjPtr< BinnedEventT0 > m_eventTime
StoreObjPtr holding the event time.
Definition: CDCTriggerHoughETFModule.h:197
Belle2::CDCTriggerHoughETFModule::m_segmentHits
StoreArray< CDCTriggerSegmentHit > m_segmentHits
list of track segment hits
Definition: CDCTriggerHoughETFModule.h:309
Belle2::CDCTriggerHoughCand::getIdList
std::vector< unsigned > getIdList() const
Get Index list.
Definition: CDCTriggerHoughETFModule.h:64
Belle2::CDCTriggerHoughETFModule::CDCTriggerHoughETFModule
CDCTriggerHoughETFModule()
Constructor.
Definition: CDCTriggerHoughETFModule.cc:38
Belle2::CDCTriggerHoughETFModule::connectedDiag
bool connectedDiag(unsigned patternLD, unsigned patternRU)
Check for diagonal connected of patterns in 2 x 2 squares.
Definition: CDCTriggerHoughtrafoForETF.cc:734
Belle2::CDCTriggerHoughETFModule::m_connect
unsigned m_connect
number of neighbors to check for connection (4: direct, 6: direct + upper right and lower left corner...
Definition: CDCTriggerHoughETFModule.h:261
Belle2::CDCTriggerHoughETFModule::m_timeWindowStart
short m_timeWindowStart
Start time of time window relative to median.
Definition: CDCTriggerHoughETFModule.h:215
Belle2::CDCTriggerHoughCand::SLcount
unsigned short SLcount
Super layer count (number of hits from different super layers).
Definition: CDCTriggerHoughETFModule.h:78
Belle2::CDCTriggerHoughETFModule::m_suppressClone
bool m_suppressClone
switch to send only the first found track and suppress the subsequent clones
Definition: CDCTriggerHoughETFModule.h:270
Belle2::cdcPair
std::pair< unsigned short, TVector2 > cdcPair
Pair of <iSuperLayer, (x, y)>, for hits in conformal space.
Definition: CDCTriggerHoughETFModule.h:42
Belle2::CDCTriggerHoughETFModule::selectHits
void selectHits(std::vector< unsigned > &list, std::vector< unsigned > &selected, std::vector< unsigned > &unselected)
Select one hit per super layer.
Definition: CDCTriggerHoughtrafoForETF.cc:453
Belle2::CDCTriggerHoughETFModule::m_minHitsShort
unsigned m_minHitsShort
short tracks require hits in the first minHitsShort super layers to form a candidate
Definition: CDCTriggerHoughETFModule.h:253
Belle2::CDCTriggerHoughETFModule::maxIterations
unsigned maxIterations
number of iterations for the fast peak finder, smallest n such that 2^(n+1) > max(nCellsPhi,...
Definition: CDCTriggerHoughETFModule.h:244
Belle2::CDCTriggerHoughETFModule::m_hitCollectionName
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
Definition: CDCTriggerHoughETFModule.h:222
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::CDCTriggerHoughETFModule::m_clusterPattern
bool m_clusterPattern
switch for clustering algorithm (if true use nested patterns)
Definition: CDCTriggerHoughETFModule.h:276
Belle2::CDCTriggerHoughETFModule::m_ignore2nd
bool m_ignore2nd
switch to skip second priority hits
Definition: CDCTriggerHoughETFModule.h:263
Belle2::CDCTriggerHoughETFModule::m_nCellsR
unsigned m_nCellsR
number of Hough cells in 1/r
Definition: CDCTriggerHoughETFModule.h:230
Belle2::CDCTriggerHoughETFModule::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: CDCTriggerHoughtrafoForETF.cc:381
Belle2::CDCTriggerHoughETFModule::connectedLR
bool connectedLR(unsigned patternL, unsigned patternR)
Check for left/right connection of patterns in 2 x 2 squares.
Definition: CDCTriggerHoughtrafoForETF.cc:677
Belle2::CDCTriggerHoughETFModule::m_houghPlane
StoreObjPtr< TMatrix > m_houghPlane
matrix containing the Hough plane
Definition: CDCTriggerHoughETFModule.h:315
Belle2::CDCTriggerHoughETFModule::inList
bool inList(const CDCTriggerHoughCand &a, const std::vector< CDCTriggerHoughCand > &list) const
Check if candidate is in list.
Definition: CDCTriggerHoughtrafoForETF.cc:333
Belle2::CDCTriggerHoughCand::getCoord
coord2dPair getCoord() const
Get rectangle coordinates.
Definition: CDCTriggerHoughETFModule.h:66