Belle II Software development
CDCTriggerNDFinderModule.cc
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#include "trg/cdc/modules/ndFinder/CDCTriggerNDFinderModule.h"
10
11#include <string>
12#include <vector>
13#include <array>
14#include <cmath>
15
16#include "trg/cdc/NDFinder.h"
17#include "trg/cdc/NDFinderPeakFinder.h"
18
19using namespace Belle2;
20
21REG_MODULE(CDCTriggerNDFinder);
22
23CDCTriggerNDFinderModule::CDCTriggerNDFinderModule() : Module()
24{
25 setDescription("CDC Trigger NDFinder Module.\n"
26 "Implements a 3D Hough transformation for \n"
27 "3D track finding in omega, phi, cot. \n"
28 "Uses numeric hit patterns for axial and \n"
29 "stereo TS.\n");
30 setPropertyFlags(c_ParallelProcessingCertified);
31 addParam("TrackSegmentHitsName", m_trackSegmentHitsName,
32 "The name of the StoreArray of the CDCTriggerSegmentHits.",
33 std::string("CDCTriggerSegmentHits"));
34 addParam("NDFinderTracksName", m_ndFinderTracksName,
35 "The name of the StoreArray where the tracks found by this NDFinder Module are stored.",
36 std::string("TRGCDCNDFinderTracks"));
37 addParam("minSuperAxial", m_minSuperAxial,
38 "Peak selection: Minimum number of axial super layer hits related to a peak "
39 "for the peak to be considered as a track.",
40 static_cast<unsigned short>(3));
41 addParam("minSuperStereo", m_minSuperStereo,
42 "Peak selection: Minimum number of stereo super layer hits related to a peak "
43 "for the peak to be considered as a track.",
44 static_cast<unsigned short>(2));
45 addParam("iterations", m_iterations,
46 "Peak finding: Number of iterations for the peak finding in one Hough space section.",
47 static_cast<unsigned short>(1));
48 addParam("omegaTrim", m_omegaTrim,
49 "Peak finding: Number of deleted cells in each omega direction of the maximum.",
50 static_cast<unsigned short>(5));
51 addParam("phiTrim", m_phiTrim,
52 "Peak finding: Number of deleted cells in each phi direction of the maximum.",
53 static_cast<unsigned short>(4));
54 addParam("storeHoughSpace", m_storeHoughSpace,
55 "Switch for saving the full Hough space.",
56 false);
57 addParam("axialFile", m_axialFile,
58 "File name of the axial hit representations.",
59 std::string(""));
60 addParam("stereoFile", m_stereoFile,
61 "File name of the stereo hit representations.",
62 std::string(""));
63}
64
65CDCTriggerNDFinderModule::~CDCTriggerNDFinderModule() {}
66
68{
69 m_trackSegmentHits.isRequired(m_trackSegmentHitsName);
70 m_ndFinderTracks.registerInDataStore(m_ndFinderTracksName);
71 m_ndFinderTracks.registerRelationTo(m_trackSegmentHits);
72 NDFinderParameters ndFinderParameters = {
73 m_minSuperAxial, m_minSuperStereo,
74 m_iterations, m_omegaTrim, m_phiTrim,
75 m_storeHoughSpace,
76 m_axialFile, m_stereoFile
77 };
78 m_NDFinder.init(ndFinderParameters);
79}
80
82
84{
85 m_NDFinder.reset();
86
87 for (CDCTriggerSegmentHit& hit : m_trackSegmentHits) {
88 if (hit.getPriorityPosition() == 0) continue; // no hit
89 HitInfo hitInfo = {
90 hit.getSegmentID(),
91 hit.getISuperLayer(),
92 hit.priorityTime()
93 };
94 m_NDFinder.addHit(hitInfo);
95 }
96
97 m_NDFinder.findTracks();
98
99 std::vector<RawFinderTrack>* rawFinderTracks = m_NDFinder.getFinderTracks();
100 for (RawFinderTrack& rawFinderTrack : *rawFinderTracks) {
101 // Set the Helix parameters of the 3DFinder rawFinderTrack
102 constexpr double z = 0.0;
103 CDCTrigger3DHTrack* ndFinderTrack = m_ndFinderTracks.appendNew(
104 rawFinderTrack.phi, rawFinderTrack.omega, z, rawFinderTrack.cot);
105
106 // Set the other parameters
107 ndFinderTrack->setQuadrant(getNDFinderQuadrant(*ndFinderTrack));
108 ndFinderTrack->setTotalMomentum(getNDFinderTotalMomentum(*ndFinderTrack));
109 ndFinderTrack->setValidTrackBit(true);
110
111 // Get the raw maximum and set it for HW comparison
112 const HoughPeak& peak = rawFinderTrack.peak;
113 unsigned int peakWeight = peak.weight;
114 cell_index peakCell = peak.cell;
115 std::array<int, 4> raw3DHMaximum = {
116 static_cast<int>(peakCell[0]),
117 static_cast<int>(peakCell[1]),
118 static_cast<int>(peakCell[2]),
119 static_cast<int>(peakWeight)
120 };
121 ndFinderTrack->setRaw3DHMaximum(raw3DHMaximum);
122
123 // Add the hough space
124 ndFinderTrack->setHoughSpace(std::move(rawFinderTrack.houghSpace));
125
126 // Add the relations to the rawFinderTrack segments
127 const std::vector<unsigned short>& relatedHits = peak.hits;
128 std::array<unsigned short, 9> tsVector{0};
129 for (unsigned short hitIdx = 0; hitIdx < relatedHits.size(); ++hitIdx) {
130 ndFinderTrack->addRelationTo(m_trackSegmentHits[relatedHits[hitIdx]]);
131 unsigned short superLayer = m_trackSegmentHits[relatedHits[hitIdx]]->getISuperLayer();
132 tsVector[superLayer] = m_trackSegmentHits[relatedHits[hitIdx]]->getLeftRight();
133 }
134 ndFinderTrack->setTSVector(tsVector);
135 }
136}
137
139
141
142short CDCTriggerNDFinderModule::getNDFinderQuadrant(const CDCTrigger3DHTrack& ndFinderTrack)
143{
144 short quadrant = -1;
145 const double phi = ndFinderTrack.getPhi0();
146 if (phi >= -1 * M_PI_4 && phi < 1 * M_PI_4) { quadrant = 3; }
147 else if (phi >= 1 * M_PI_4 && phi < 3 * M_PI_4) { quadrant = 0; }
148 else if (phi >= 3 * M_PI_4 || phi < -3 * M_PI_4) { quadrant = 1; }
149 else if (phi >= -3 * M_PI_4 && phi < -1 * M_PI_4) { quadrant = 2; }
150 return quadrant;
151}
152
153double CDCTriggerNDFinderModule::getNDFinderTotalMomentum(const CDCTrigger3DHTrack& ndFinderTrack)
154{
155 double theta = std::atan2(1.0, ndFinderTrack.getCotTheta());
156 if (theta < 0) theta += M_PI;
157 double totalMomentum = ndFinderTrack.getPt() / std::sin(theta);
158 return totalMomentum;
159}
virtual void initialize() override
Initialize the Module.
virtual void event() override
This method is the core of the module.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
virtual void beginRun() override
Called when entering a new run.
Combination of several CDCHits to a track segment hit for the trigger.
Base class for Modules.
Definition Module.h:72
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.