8 #include <tracking/vxdHoughTracking/findlets/ROIFinder.h>
9 #include <tracking/vxdHoughTracking/findlets/RawTrackCandCleaner.icc.h>
10 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
11 #include <framework/logging/Logger.h>
12 #include <framework/core/ModuleParamList.h>
13 #include <framework/geometry/BFieldManager.h>
14 #include <framework/geometry/B2Vector3.h>
15 #include <framework/database/DBObjPtr.h>
16 #include <mdst/dbobjects/BeamSpot.h>
17 #include <pxd/geometry/SensorInfo.h>
18 #include <vxd/geometry/GeoCache.h>
21 using namespace TrackFindingCDC;
22 using namespace vxdHoughTracking;
24 ROIFinder::~ROIFinder() =
default;
26 ROIFinder::ROIFinder()
30 void ROIFinder::exposeParameters(
ModuleParamList* moduleParamList,
const std::string& prefix)
32 Super::exposeParameters(moduleParamList, prefix);
34 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"calculateROI"), m_param_calculateROI,
35 "Calculate PXDIntercepts and ROIs in this findlet based on a simple circle extrapolation (r-phi) and straigh line extrapolation (z, theta)?",
36 m_param_calculateROI);
38 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"storePXDInterceptsName"), m_param_storePXDInterceptsName,
39 "Name of the PXDIntercepts StoreArray produced by DATCON using a simple circle extrapolation in r-phi and a straight line extrapolation in theta.",
40 m_param_storePXDInterceptsName);
42 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"storeROIsName"), m_param_storeROIsName,
43 "Name of the ROIs StoreArray produced by DATCON using a simple circle extrapolation in r-phi and a straight line extrapolation in theta.",
44 m_param_storeROIsName);
46 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"tolerancePhi"), m_param_tolerancePhi,
47 "Allowed tolerance in phi (in radians) (for ROI calculation in u direction). If the intercept is within this range of the active region, an intercept is created.",
48 m_param_tolerancePhi);
49 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"toleranceZ"), m_param_toleranceZ,
50 "Allowed tolerance in z (in cm) (for ROI calculation in v direction). If the intercept is within this range of the active region of a sensor, an intercept is created.",
53 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"radiusCorrectionFactor"), m_param_radiusCorrectionFactor,
54 "Correct charge-dependent bias of the extrapolated hit with radiusCorrectionFactor * trackCharge / trackRadius.",
55 m_param_radiusCorrectionFactor);
56 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"sinPhiCorrectionFactor"), m_param_sinPhiCorrectionFactor,
57 "Correct sin(trackPhi) dependent bias with sinPhiCorrectionFactor * sin(trackPhi).",
58 m_param_sinPhiCorrectionFactor);
59 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"cosPhiCorrectionFactor"), m_param_cosPhiCorrectionFactor,
60 "Correct cos(trackPhi) dependent bias with cosPhiCorrectionFactor * cos(trackPhi).",
61 m_param_cosPhiCorrectionFactor);
63 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"minimumROISizeUL1"), m_param_minimumROISizeUL1,
64 "Minimum ROI size (in pixel) in u direction on L1.", m_param_minimumROISizeUL1);
65 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"minimumROISizeVL1"), m_param_minimumROISizeVL1,
66 "Minimum ROI size (in pixel) in v direction on L1.", m_param_minimumROISizeVL1);
67 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"minimumROISizeUL2"), m_param_minimumROISizeUL2,
68 "Minimum ROI size (in pixel) in u direction on L2.", m_param_minimumROISizeUL2);
69 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"minimumROISizeVL2"), m_param_minimumROISizeVL2,
70 "Minimum ROI size (in pixel) in v direction on L2.", m_param_minimumROISizeVL2);
72 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"multiplierUL1"), m_param_multiplierUL1,
73 "Multiplier term for ROI size estimation for L1 u direction. Usage: multiplierUL1 * 1/R + minimumROISizeUL1, with R in cm.",
74 m_param_multiplierUL1);
75 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"multiplierUL2"), m_param_multiplierUL2,
76 "Multiplier term for ROI size estimation for L2 u direction. Usage: multiplierUL2 * 1/R + minimumROISizeUL2, with R in cm.",
77 m_param_multiplierUL2);
78 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"multiplierVL1"), m_param_multiplierVL1,
79 "Multiplier term for ROI size estimation for L1 v direction. Usage: (1 + abs(tan(lambda)) * multiplierVL1) + minimumROISizeVL1.",
80 m_param_multiplierVL1);
81 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"multiplierVL2"), m_param_multiplierVL2,
82 "Multiplier term for ROI size estimation for L2 v direction. Usage: (1 + abs(tan(lambda)) * multiplierVL2) + minimumROISizeVL2.",
83 m_param_multiplierVL2);
85 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"maximumROISizeU"), m_param_maximumROISizeU,
86 "Maximum ROI size in u.", m_param_maximumROISizeU);
87 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"maximumROISizeV"), m_param_maximumROISizeV,
88 "Maximum ROI size in v.", m_param_maximumROISizeV);
93 void ROIFinder::initialize()
96 if (not m_param_calculateROI) {
102 m_storePXDIntercepts.registerInDataStore(m_param_storePXDInterceptsName);
103 m_storeROIs.registerInDataStore(m_param_storeROIsName);
105 if (m_param_minimumROISizeUL1 < 0 or m_param_minimumROISizeUL2 < 0 or
106 m_param_minimumROISizeVL1 < 0 or m_param_minimumROISizeVL2 < 0 or
107 m_param_multiplierUL1 < 0 or m_param_multiplierUL2 < 0 or
108 m_param_multiplierVL1 < 0 or m_param_multiplierVL2 < 0 or
109 m_param_tolerancePhi < 0 or m_param_toleranceZ < 0) {
110 B2ERROR(
"Please check the ROI size parameters. "
111 "None of minimumROISizeUL1, minimumROISizeUL2, minimumROISizeVL1, minimumROISizeVL2, "
112 "multiplierUL1, multiplierUL2, multiplierVL1, multiplierVL2, overlapU, overlapV must be < 0!");
116 void ROIFinder::beginRun()
119 if (not m_param_calculateROI) {
129 m_BeamSpotPosition = (*beamSpotDB).getIPPosition();
131 m_BeamSpotPosition.SetXYZ(0., 0., 0.);
136 void ROIFinder::beginEvent()
139 if (not m_param_calculateROI) {
146 void ROIFinder::apply(
const std::vector<SpacePointTrackCand>& finalTracks)
149 if (not m_param_calculateROI) {
153 for (
auto& track : finalTracks) {
159 std::vector<PXDIntercept> thisTracksIntercepts;
160 thisTracksIntercepts.reserve(8);
162 const B2Vector3D& momentumEstimate = track.getMomSeed();
164 const double trackPhi = momentumEstimate.
Phi();
165 const double trackTheta = momentumEstimate.
Theta();
166 const double tanTrackLambda = tan(M_PI_2 - trackTheta);
167 const double trackRadius = momentumEstimate.
Perp() / (0.00299792458 * m_bFieldZ) ;
168 const double trackCharge = track.getChargeSeed();
171 for (
int layer = 1; layer <= 2; layer++) {
172 const double sensorPerpRadius = m_const_layerRadius[layer - 1];
175 for (
int ladder = 1; ladder <= (layer == 1 ? 8 : 12); ladder++) {
176 const double sensorPhi = (layer == 1) ? m_const_ladderPhiL1[ladder - 1] : m_const_ladderPhiL2[ladder - 1];
177 const double rotatedBeamSpotX = m_BeamSpotPosition.X() * cos(sensorPhi) + m_BeamSpotPosition.Y() * sin(sensorPhi);
178 const double rotatedBeamSpotY = -m_BeamSpotPosition.X() * sin(sensorPhi) + m_BeamSpotPosition.Y() * cos(sensorPhi);
181 const double sensorLocalX = sensorPerpRadius - rotatedBeamSpotX;
183 double phiDiff = trackPhi - sensorPhi;
184 if (phiDiff < -M_PI) {
185 phiDiff += 2. * M_PI;
187 if (phiDiff > M_PI) {
188 phiDiff -= 2. * M_PI;
194 if (fabs(phiDiff) > 0.3 * M_PI ) {
201 double relTrackCenterPhi = 0;
202 if (trackCharge < 0) {
203 relTrackCenterPhi = trackPhi - M_PI_2 - sensorPhi;
204 }
else if (trackCharge > 0) {
205 relTrackCenterPhi = trackPhi + M_PI_2 - sensorPhi;
207 const double xCenter = trackRadius * cos(relTrackCenterPhi);
208 const double yCenter = trackRadius * sin(relTrackCenterPhi);
211 if ((trackRadius * trackRadius - (sensorLocalX - xCenter) * (sensorLocalX - xCenter)) < 0) {
214 const double ytmp = sqrt(trackRadius * trackRadius - (sensorLocalX - xCenter) * (sensorLocalX - xCenter));
215 const double yplus = yCenter + ytmp + rotatedBeamSpotY;
216 const double yminus = yCenter - ytmp + rotatedBeamSpotY;
218 const double correctionterm = (m_param_radiusCorrectionFactor * trackCharge / trackRadius) +
219 m_param_sinPhiCorrectionFactor * sin(trackPhi) +
220 m_param_cosPhiCorrectionFactor * cos(trackPhi);
222 const double localUPositionPlus = yplus - m_const_shiftY + correctionterm;
223 const double localUPositionMinus = yminus - m_const_shiftY + correctionterm;
224 const double toleranceRPhi = m_param_tolerancePhi * sensorLocalX;
227 if (not(yplus >= m_const_sensorMinY - toleranceRPhi and yplus <= m_const_sensorMaxY + toleranceRPhi) and
228 not(yminus >= m_const_sensorMinY - toleranceRPhi and yminus <= m_const_sensorMaxY + toleranceRPhi)) {
233 const double z = sensorLocalX * tanTrackLambda - m_BeamSpotPosition.Z();
236 for (
int sensor = 1; sensor <= 2; sensor++) {
238 const double shiftZ = (layer == 1) ? m_const_centerZShiftLayer1[sensor - 1] : m_const_centerZShiftLayer2[sensor - 1];
240 double localVPosition = z - shiftZ;
242 if (localVPosition >= ((-m_const_activeSensorLength[layer - 1] / 2.0) - m_param_toleranceZ) and
243 localVPosition <= ((m_const_activeSensorLength[layer - 1] / 2.0) + m_param_toleranceZ)) {
245 const VxdID sensorID =
VxdID(layer, ladder, sensor);
249 if (localUPositionPlus >= -m_const_activeSensorWidth / 2.0 - toleranceRPhi and
250 localUPositionPlus <= m_const_activeSensorWidth / 2.0 + toleranceRPhi) {
252 intercept.
setCoorU(localUPositionPlus);
255 m_storePXDIntercepts.appendNew(intercept);
256 thisTracksIntercepts.push_back(intercept);
259 if (localUPositionMinus >= -m_const_activeSensorWidth / 2.0 - toleranceRPhi and
260 localUPositionMinus <= m_const_activeSensorWidth / 2.0 + toleranceRPhi) {
262 intercept.
setCoorU(localUPositionMinus);
265 m_storePXDIntercepts.appendNew(intercept);
266 thisTracksIntercepts.push_back(intercept);
273 const double omega = 1. / trackRadius;
274 unsigned short uSizeL1 = (
unsigned short)(m_param_multiplierUL1 * omega + m_param_minimumROISizeUL1);
275 unsigned short uSizeL2 = (
unsigned short)(m_param_multiplierUL2 * omega + m_param_minimumROISizeUL2);
276 unsigned short vSizeL1 = (
unsigned short)((1. + fabs(tanTrackLambda) * m_param_multiplierVL1) * m_param_minimumROISizeVL1);
277 unsigned short vSizeL2 = (
unsigned short)((1. + fabs(tanTrackLambda) * m_param_multiplierVL2) * m_param_minimumROISizeVL2);
278 for (
auto& intercept : thisTracksIntercepts) {
279 const VxdID& interceptSensorID = intercept.getSensorID();
281 double uCoordinate = intercept.getCoorU();
282 double vCoordinate = intercept.getCoorV();
286 int interceptUCell = currentSensor->
getUCellID(uCoordinate, vCoordinate,
false);
287 int interceptVCell = currentSensor->
getVCellID(vCoordinate,
false);
288 int nUCells = currentSensor->
getUCells();
289 int nVCells = currentSensor->
getVCells();
291 unsigned short uSize = (interceptSensorID.
getLayerNumber() == 1 ? uSizeL1 : uSizeL2);
292 unsigned short vSize = (interceptSensorID.
getLayerNumber() == 1 ? vSizeL1 : vSizeL2);
293 if (uSize > m_param_maximumROISizeU) {
294 uSize = m_param_maximumROISizeU;
296 if (vSize > m_param_maximumROISizeV) {
297 vSize = m_param_maximumROISizeV;
301 short uCellDownLeft = interceptUCell - uSize / 2;
302 short vCellDownLeft = interceptVCell - vSize / 2;
305 short uCellUpRight = interceptUCell + uSize / 2;
306 short vCellUpRight = interceptVCell + vSize / 2;
308 if (uCellDownLeft >= nUCells or vCellDownLeft >= nVCells or uCellUpRight < 0 or vCellUpRight < 0) {
312 if (uCellDownLeft < 0) {
315 if (vCellDownLeft < 0) {
320 if (uCellUpRight >= nUCells) {
321 uCellUpRight = nUCells - 1;
323 if (vCellUpRight >= nVCells) {
324 vCellUpRight = nVCells - 1;
327 m_storeROIs.appendNew(
ROIid(uCellDownLeft, uCellUpRight, vCellDownLeft, vCellUpRight, interceptSensorID));
DataType Phi() const
The azimuth angle.
DataType Theta() const
The polar angle.
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing objects in the database.
The Module parameter list class.
PXDIntercept stores the U,V coordinates and uncertainties of the intersection of a track with an PXD ...
Specific implementation of SensorInfo for PXD Sensors which provides additional pixel specific inform...
ROIid stores the U and V ids and the sensor id of the Region Of Interest.
@ c_isActive
bit 11: SPTC is active (i.e.
static const double T
[tesla]
void setVxdID(VxdID::baseType user_vxdID)
set the sensor ID
void setCoorU(double user_coorU)
set the U coordinate of the intercept
void setCoorV(double user_coorV)
set the V coordinate of the intercept
static const SensorInfoBase & get(Belle2::VxdID id)
Return a reference to the SensorInfo of a given SensorID.
int getVCells() const
Return number of pixel/strips in v direction.
int getUCells() const
Return number of pixel/strips in u direction.
int getVCellID(double v, bool clamp=false) const
Return the corresponding pixel/strip ID of a given v coordinate.
int getUCellID(double u, double v=0, bool clamp=false) const
Return the corresponding pixel/strip ID of a given u coordinate.
Class to uniquely identify a any structure of the PXD and SVD.
baseType getLayerNumber() const
Get the layer id.
void addParameter(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Abstract base class for different kinds of events.