9#include <trg/cdc/modules/houghtracking/CDCTrigger2DFinderModule.h>
11#include <cdc/geometry/CDCGeometryPar.h>
12#include <framework/logging/Logger.h>
13#include <framework/gearbox/Const.h>
20#define CDC_SUPER_LAYERS 9
43 "Name of the input StoreArray of CDCTriggerSegmentHits.",
46 "Name of the StoreArray holding the tracks found in the Hough tracking.",
47 string(
"TRGCDC2DFinderTracks"));
49 "Name of the StoreArray holding the clusters formed in the Hough plane.",
52 "Number of Hough cells in phi (limits: [-180, 180]). Must be an even number.",
55 "Number of Hough cells in 1/r. Must be an even number.",
59 "Hough plane limits in 1/r are [-1/r(minPt), 1/r(minPt)]", (
double)(0.3));
61 "Shift the Hough plane by 1/4 cell size in 1/r to avoid "
62 "curvature 0 tracks (<0: shift in negative direction, "
63 "0: no shift, >0: shift in positive direction).", 0);
66 "Minimum hits from different super layers required in a peak cell.",
69 "Minimum hits required required in a peak cell for a short track"
70 " (must be in the first minHitsShort super layers).",
73 "Peaks with less than minCells connected cells are ignored.",
76 "Switch to remove cells connected to a cell with higher super layer count.",
79 "Definition for connected cells. 4: direct (left/right/top/bottom), "
80 "6: direct + 2 diagonal (top right/bottom left), "
81 "8: direct + all diagonal (top right/top left/bottom right/bottom left)",
84 "Switch to skip second priority hits.",
false);
86 "If true, use wire position of priority cell in track segment, "
87 "otherwise use wire position of center cell.",
true);
89 "Switch to check separately for a hit in the innermost superlayer.",
false);
91 "Switch for saving Hough plane as TMatrix in DataStore. "
92 "0: don't store anything, 1: store only peaks, 2: store full plane "
93 "(will increase runtime).", (
unsigned)(0));
95 "use nested pattern algorithm to find clusters",
true);
97 "maximum number of 2 x 2 squares in cluster for pattern algorithm",
100 "maximum number of 2 x 2 squares in cluster for pattern algorithm",
103 "Switch for creating relations to hits in the pattern algorithm. "
104 "If true, create relations from cluster corners, otherwise "
105 "from estimated cluster center (might not have relations).",
false);
108 "If not empty, a file with input (hits) and output (tracks) "
109 "for each event is written (for firmware debugging).",
string(
""));
112 "Switch to send only the first found track and suppress the "
113 "subsequent clones.",
false);
116 "Switch to use hit pattern inside TSF ",
false);
119 "Switch to use ADC. Can be used with usehitpattern enabled. ",
false);
137 for (
int iSL = 0; iSL < 9; ++iSL) {
139 nTS += cdc.nWiresInLayer(layerId);
142 for (
int priority = 0; priority < 2; ++ priority) {
143 radius[iSL][priority] = cdc.senseWireR(layerId + priority);
146 for (
int priority = 0; priority < 5; ++ priority) {
147 if (iSL == 0)
radius[iSL][priority] = cdc.senseWireR(layerId + priority);
148 else radius[iSL][priority] = cdc.senseWireR(layerId + priority - 2);
151 layerId += (iSL > 0 ? 6 : 7);
159 B2INFO(
"2D finder will exit with the first track candidate in time.");
174 testFile << StoreObjPtr<EventMetaData>()->getEvent() <<
" "
190 if (iSL % 2)
continue;
198 if (iSL == 0)nhitpattern = 15;
199 else nhitpattern = 11;
200 for (
int i = 0; i < nhitpattern; i++) {
201 if ((hitpattern & (1 << i)) != 0) {
203 if (iSL != 0 && i == 0) phi = phi - 1;
204 else if (iSL != 0 && i == 1) phi = phi + 0;
205 else if (iSL != 0 && i == 2) phi = phi + 1;
206 else if (iSL != 0 && i == 3) phi = phi - 0.5;
207 else if (iSL != 0 && i == 4) phi = phi + 0.5;
208 else if (iSL != 0 && i == 5) phi = phi + 0;
209 else if (iSL != 0 && i == 6) phi = phi - 0.5;
210 else if (iSL != 0 && i == 7) phi = phi + 0.5;
211 else if (iSL != 0 && i == 8) phi = phi - 1;
212 else if (iSL != 0 && i == 9) phi = phi + 0;
213 else if (iSL != 0 && i == 10) phi = phi + 1;
214 else if (iSL == 0 && i == 0) phi = phi + 0;
215 else if (iSL == 0 && i == 1) phi = phi - 0.5;
216 else if (iSL == 0 && i == 2) phi = phi + 0.5;
217 else if (iSL == 0 && i == 3) phi = phi - 1;
218 else if (iSL == 0 && i == 4) phi = phi + 0;
219 else if (iSL == 0 && i == 5) phi = phi + 1;
220 else if (iSL == 0 && i == 6) phi = phi - 1.5;
221 else if (iSL == 0 && i == 7) phi = phi - 0.5;
222 else if (iSL == 0 && i == 8) phi = phi + 0.5;
223 else if (iSL == 0 && i == 9) phi = phi + 1.5;
224 else if (iSL == 0 && i == 10) phi = phi - 2;
225 else if (iSL == 0 && i == 11) phi = phi - 1;
226 else if (iSL == 0 && i == 12) phi = phi + 0;
227 else if (iSL == 0 && i == 13) phi = phi + 1;
228 else if (iSL == 0 && i == 14) phi = phi + 2;
231 if (iSL != 0 && i == 0) iLayer = 0;
232 else if (iSL != 0 && i == 1) iLayer = 0;
233 else if (iSL != 0 && i == 2) iLayer = 0;
234 else if (iSL != 0 && i == 3) iLayer = 1;
235 else if (iSL != 0 && i == 4) iLayer = 1;
236 else if (iSL != 0 && i == 5) iLayer = 2;
237 else if (iSL != 0 && i == 6) iLayer = 3;
238 else if (iSL != 0 && i == 7) iLayer = 3;
239 else if (iSL != 0 && i == 8) iLayer = 4;
240 else if (iSL != 0 && i == 9) iLayer = 4;
241 else if (iSL != 0 && i == 10) iLayer = 4;
242 else if (iSL == 0 && i == 0) iLayer = 0;
243 else if (iSL == 0 && i == 1) iLayer = 1;
244 else if (iSL == 0 && i == 2) iLayer = 1;
245 else if (iSL == 0 && i == 3) iLayer = 2;
246 else if (iSL == 0 && i == 4) iLayer = 2;
247 else if (iSL == 0 && i == 5) iLayer = 2;
248 else if (iSL == 0 && i == 6) iLayer = 3;
249 else if (iSL == 0 && i == 7) iLayer = 3;
250 else if (iSL == 0 && i == 8) iLayer = 3;
251 else if (iSL == 0 && i == 9) iLayer = 3;
252 else if (iSL == 0 && i == 10) iLayer = 4;
253 else if (iSL == 0 && i == 11) iLayer = 4;
254 else if (iSL == 0 && i == 12) iLayer = 4;
255 else if (iSL == 0 && i == 13) iLayer = 4;
256 else if (iSL == 0 && i == 14) iLayer = 4;
258 double r =
radius[iSL][iLayer];
259 ROOT::Math::XYVector pos(cos(phi) / r, sin(phi) / r);
260 hitMap.insert(std::make_pair(iHit * 15 + i, std::make_pair(iSL * 5 + iLayer, pos)));
266 phi += 0.5 * (((
m_segmentHits[iHit]->getPriorityPosition() >> 1) & 1)
272 ROOT::Math::XYVector pos(cos(phi) / r, sin(phi) / r);
273 hitMap.insert(std::make_pair(iHit, std::make_pair(iSL, pos)));
294 B2DEBUG(50,
"extending Hough plane to " <<
maxIterations <<
" iterations, "
295 <<
nCells <<
" cells: phi in ["
296 << -rectX * 180. / M_PI <<
", " << rectX * 180. / M_PI
297 <<
"] deg, 1/r in [" << -rectY +
shiftR <<
", " << rectY +
shiftR <<
"] /cm");
314 typedef pair<int, cdcPair> cdcHitPair;
316 typedef vector<cdcHitPair> cdcSeqMap;
320 seqHitMap.push_back(hit);
322 sort(seqHitMap.begin(), seqHitMap.end(), [
this](cdcHitPair i, cdcHitPair j) {
323 return m_segmentHits[i.first]->foundTime() < m_segmentHits[j.first]->foundTime();
325 auto seqHitItr = seqHitMap.begin();
327 vector<bool> layerHit(CDC_SUPER_LAYERS,
false);
330 short firstTick =
m_segmentHits[(*seqHitMap.begin()).first]->foundTime() / period + 1;
331 short lastTick =
m_segmentHits[(*(seqHitMap.end() - 1)).first]->foundTime() / period + 1;
333 for (
auto tick = firstTick * period; tick < lastTick * period; tick += period) {
335 for (
auto itr = seqHitItr; itr < seqHitMap.end(); ++itr) {
336 cdcHitPair currentHit = *itr;
338 if (count(layerHit.begin(), layerHit.end(),
true) >=
m_minHits &&
343 layerHit[
m_segmentHits[currentHit.first]->getISuperLayer()] =
true;
345 copy_n(seqHitItr, nHitInCycle, inserter(fastHitMap, fastHitMap.end()));
347 B2DEBUG(20,
"at tick " << tick <<
", number of candidates: " <<
houghCand.size());
349 B2DEBUG(10,
"found a track at clock " << tick <<
" with "
350 << fastHitMap.size() <<
"hits");
353 advance(seqHitItr, nHitInCycle);
359 B2DEBUG(10,
"found a track with " <<
hitMap.size() <<
"hits");
374 testFile << round(2 * ix) / 2. <<
" " << round(2 * iy) / 2. <<
" "
375 <<
m_tracks[i]->getChargeSign() << endl;
379 for (
unsigned ihit = 0; ihit < hits.size(); ++ihit) {
380 unsigned short iSL = hits[ihit]->getISuperLayer();
382 << hits[ihit]->getPriorityPosition() <<
" "
383 << hits.weight(ihit) << endl;
CDCTrigger2DFinderModule()
Constructor.
std::vector< CDCTriggerHoughCand > houghCand
Hough Candidates.
bool m_usehitpattern
switch to use hit pattern inside TSF
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.
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 m_useadc
switch to use hit pattern inside TSF with ADC cut
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
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)
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.
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
void patternClustering(const cdcMap &inputMap)
Combine Hough candidates to tracks by a fixed pattern algorithm.
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].
unsigned nCells
number of cells for the fast peak finder: 2^(maxIterations + 1).
bool m_suppressClone
switch to send only the first found track and suppress the subsequent clones
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...
unsigned m_clusterSizeX
maximum cluster size for pattern algorithm
double m_minPt
Hough plane limit in Pt [GeV].
bool m_requireSL0
switch to check separately for a hit in the innermost 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
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.
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
double radius[9][5]
Radius of the CDC layers with priority wires (2 per super layer).
bool m_onlyLocalMax
switch to ignore candidates connected to cells with higher super layer count
unsigned m_clusterSizeY
maximum cluster size for pattern algorithm
void connectedRegions()
Combine Hough candidates to tracks by merging connected cells.
Combination of several CDCHits to a track segment hit for the trigger.
The Class for CDC Geometry Parameters.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
static const double speedOfLight
[cm/ns]
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
void setReturnValue(int value)
Sets the return value for this module as integer.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class for type safe access to objects that are referred to in relations.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
int getEntries() const
Get the number of objects in the array.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
std::map< int, cdcPair > cdcMap
Map of <counter, cdcPair>, for hits with indices.
Abstract base class for different kinds of events.