Belle II Software  release-05-02-19
DATCONROICalculationModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Michael Schnell, Christian Wessel *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/modules/DATCON/DATCONROICalculationModule.h>
12 
13 #include <pxd/geometry/SensorInfo.h>
14 #include <vxd/geometry/GeoCache.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(DATCONROICalculation)
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
29 {
30  //Set module properties
31  setDescription("DATCONROICalculationModule: Calculates ROI from the "
32  "extrapolated hits (MPH), one ROI for each MPH.");
33  setPropertyFlags(c_ParallelProcessingCertified);
34 
35  addParam("DATCONPXDIntercepts", m_storeDATCONPXDInterceptsName,
36  "Name of the DATCONPXDIntercepts StoreArray", string("DATCONPXDIntercepts"));
37  addParam("DATCONMPHs", m_storeDATCONMPHName,
38  "Name of the DATCONMPH StoreArray", string(""));
39  addParam("DATCONROIids", m_storeDATCONROIidName,
40  "Name of the ROIid StoreArray for ROI created by DATCON", string("DATCONROIs"));
41 
42  addParam("continueROIonNextSensor", m_ContinueROIonNextSensor,
43  "Continue the ROI on the next sensor when they are close to the edge?", bool(true));
44  addParam("fixedSizeUCells", m_fixedSizeUCells,
45  "Fixed size of the ROI in u-direction.", int(100));
46  addParam("fixedSizeVCells", m_fixedSizeVCells,
47  "Fixed size of the ROI in v-direction.", int(150));
48 
49 
50 }
51 
52 
53 void DATCONROICalculationModule::initialize()
54 {
55 
56  storeDATCONPXDIntercepts.isRequired(m_storeDATCONPXDInterceptsName);
57  m_storeDATCONPXDInterceptsName = storeDATCONPXDIntercepts.getName();
58 
59  storeDATCONMPHs.isRequired(m_storeDATCONMPHName);
60  m_storeDATCONMPHName = storeDATCONMPHs.getName();
61 
62  storeDATCONROIids.registerInDataStore(m_storeDATCONROIidName);
63  m_storeDATCONROIidName = storeDATCONROIids.getName();
64 
65 }
66 
67 /*
68 * Calculate Region of Interests (ROI).
69 */
70 void
71 DATCONROICalculationModule::event()
72 {
73  int uSize = m_fixedSizeUCells;
74  int vSize = m_fixedSizeVCells;
76  int sensorChange = 0, ladderChange = 0;
77  int uCellsRest = 0, vCellsRest = 0;
78  VxdID nextSensorID;
79 
80  ROIid DATCONROIid;
81 
82  for (auto& datconmph : storeDATCONMPHs) {
83  VxdID MPHSensorID = datconmph.getSensorID();
84  TVector2 localPosition = datconmph.getLocalCoordinate();
85 
86  double uCoordinate = localPosition.X();
87  double vCoordinate = localPosition.Y();
88 
89  const PXD::SensorInfo* currentSensor = dynamic_cast<const PXD::SensorInfo*>(&VXD::GeoCache::get(MPHSensorID));
90 
91  int uCell = currentSensor->getUCellID(uCoordinate, vCoordinate, false);
92  int vCell = currentSensor->getVCellID(vCoordinate, false);
93  int uCells = currentSensor->getUCells();
94  int vCells = currentSensor->getVCells();
95 
96  unsigned short sensorNumber = MPHSensorID.getSensorNumber();
97  unsigned short layerNumber = MPHSensorID.getLayerNumber();
98  unsigned short ladderNumber = MPHSensorID.getLadderNumber();
99 
101  int uCellDownLeft = uCell - uSize / 2;
102  int vCellDownLeft = vCell - vSize / 2;
103 
104  if (sensorNumber == 1) {
105  if (vCellDownLeft < 0) {
106  vCellDownLeft = 0;
107  }
108  } else if (sensorNumber == 2) {
109  if (vCellDownLeft < 0) {
110  vCellDownLeft = 0;
111  sensorChange = -1;
112  vCellsRest = vSize / 2 - (vCell - vCellDownLeft);
113  }
114  }
115 
116  if (uCellDownLeft < 0) {
117  uCellDownLeft = 0;
118  ladderChange = -1;
119  uCellsRest = uSize / 2 - (uCell - uCellDownLeft);
120  }
121 
123  int uCellUpRight = uCell + uSize / 2;
124  int vCellUpRight = vCell + vSize / 2;
125 
126  if (sensorNumber == 1) {
127  if (vCellUpRight > vCells - 1) {
128  vCellUpRight = vCells - 1;
129  sensorChange = +1;
130  vCellsRest = vSize / 2 - (vCellUpRight - vCell);
131  }
132  } else if (sensorNumber == 2) {
133  if (vCellUpRight >= vCells) {
134  vCellUpRight = vCells - 1;
135  }
136  }
137 
138  if (uCellUpRight >= uCells) {
139  uCellUpRight = uCells - 1;
140  ladderChange = +1;
141  uCellsRest = uSize / 2 - (uCellUpRight - uCell);
142  }
143 
144  storeDATCONROIids.appendNew(ROIid(uCellDownLeft, uCellUpRight, vCellDownLeft, vCellUpRight, MPHSensorID));
145 
146  if (m_ContinueROIonNextSensor) {
147  int uCellDownLeft_tmp, vCellDownLeft_tmp, uCellUpRight_tmp, vCellUpRight_tmp;
148 
150  if (ladderChange == -1 && sensorChange == 0) {
152  nextSensorID = MPHSensorID;
153  // Check for minimum ladderNumber, set to MaxLadder if required
154  if (ladderNumber > 1) {
155  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
156  } else {
157  if (layerNumber == 1) {
158  nextSensorID.setLadderNumber(8);
159  } else if (layerNumber == 2) {
160  nextSensorID.setLadderNumber(12);
161  }
162  }
163  uCellDownLeft_tmp = uCells - 1 - uCellsRest;
164  uCellUpRight_tmp = uCells - 1;
165  vCellDownLeft_tmp = vCellDownLeft;
166  vCellUpRight_tmp = vCellUpRight;
167 
168  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
169 
170  } else if (ladderChange == +1 && sensorChange == 0) {
172  nextSensorID = MPHSensorID;
173  if (layerNumber == 1) {
174  if (ladderNumber < 8) {
175  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
176  } else {
177  nextSensorID.setLadderNumber(1);
178  }
179  } else if (layerNumber == 2) {
180  if (ladderNumber < 12) {
181  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
182  } else {
183  nextSensorID.setLadderNumber(1);
184  }
185  }
186  uCellDownLeft_tmp = 0;
187  uCellUpRight_tmp = uCellsRest;
188  vCellDownLeft_tmp = vCellDownLeft;
189  vCellUpRight_tmp = vCellUpRight;
190 
191  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
192 
193  } else if (ladderChange == 0 && sensorChange == -1) {
195  nextSensorID = MPHSensorID;
196  nextSensorID.setSensorNumber(1);
197  vCellDownLeft_tmp = vCells - 1 - vCellsRest;
198  vCellUpRight_tmp = vCells - 1;
199  uCellDownLeft_tmp = uCellDownLeft;
200  uCellUpRight_tmp = uCellUpRight;
201 
202  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
203 
204  } else if (ladderChange == 0 && sensorChange == +1) {
206  nextSensorID = MPHSensorID;
207  nextSensorID.setSensorNumber(2);
208  vCellDownLeft_tmp = 0;
209  vCellUpRight_tmp = vCellsRest;
210  uCellDownLeft_tmp = uCellDownLeft;
211  uCellUpRight_tmp = uCellUpRight;
212 
213  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
214 
215  } else if (ladderChange == -1 && sensorChange == -1) {
217  nextSensorID = MPHSensorID;
218  // Check for minimum ladderNumber, set to MaxLadder if required
219  if (ladderNumber > 1) {
220  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
221  } else {
222  if (layerNumber == 1) {
223  nextSensorID.setLadderNumber(8);
224  } else if (layerNumber == 2) {
225  nextSensorID.setLadderNumber(12);
226  }
227  }
228  uCellDownLeft_tmp = uCells - 1 - uCellsRest;
229  uCellUpRight_tmp = uCells - 1;
230  vCellDownLeft_tmp = vCellDownLeft;
231  vCellUpRight_tmp = vCellUpRight;
232 
233  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
234 
235  nextSensorID = MPHSensorID;
236  nextSensorID.setSensorNumber(1);
237  vCellDownLeft_tmp = 0;
238  vCellUpRight_tmp = vCellsRest;
239  uCellDownLeft_tmp = uCellDownLeft;
240  uCellUpRight_tmp = uCellUpRight;
241 
242  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
243 
244  nextSensorID = MPHSensorID;
245  // Check for minimum ladderNumber, set to MaxLadder if required
246  if (ladderNumber > 1) {
247  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
248  } else {
249  if (layerNumber == 1) {
250  nextSensorID.setLadderNumber(8);
251  } else if (layerNumber == 2) {
252  nextSensorID.setLadderNumber(12);
253  }
254  }
255  nextSensorID.setSensorNumber(1);
256  vCellDownLeft_tmp = 0;
257  vCellUpRight_tmp = vCellsRest;
258  uCellDownLeft_tmp = uCells - 1 - uCellsRest;
259  uCellUpRight_tmp = uCells - 1;
260 
261  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
262 
263  } else if (ladderChange == -1 && sensorChange == +1) {
265  nextSensorID = MPHSensorID;
266  // Check for minimum ladderNumber, set to MaxLadder if required
267  if (ladderNumber > 1) {
268  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
269  } else {
270  if (layerNumber == 1) {
271  nextSensorID.setLadderNumber(8);
272  } else if (layerNumber == 2) {
273  nextSensorID.setLadderNumber(12);
274  }
275  }
276  uCellDownLeft_tmp = uCells - 1 - uCellsRest;
277  uCellUpRight_tmp = uCells - 1;
278  vCellDownLeft_tmp = vCellDownLeft;
279  vCellUpRight_tmp = vCellUpRight;
280 
281  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
282 
283  nextSensorID = MPHSensorID;
284  //nextSensorID.setSensorNumber(sensorNumber + sensorChange);
285  nextSensorID.setSensorNumber(2);
286  vCellDownLeft_tmp = 0;
287  vCellUpRight_tmp = vCellsRest;
288  uCellDownLeft_tmp = uCellDownLeft;
289  uCellUpRight_tmp = uCellUpRight;
290 
291  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
292 
293  nextSensorID = MPHSensorID;
294  // Check for minimum ladderNumber, set to MaxLadder if required
295  if (ladderNumber > 1) {
296  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
297  } else {
298  if (layerNumber == 1) {
299  nextSensorID.setLadderNumber(8);
300  } else if (layerNumber == 2) {
301  nextSensorID.setLadderNumber(12);
302  }
303  }
304  nextSensorID.setSensorNumber(2);
305  uCellDownLeft_tmp = uCells - 1 - uCellsRest;
306  uCellUpRight_tmp = uCells - 1;
307  vCellDownLeft_tmp = 0;
308  vCellUpRight_tmp = vCellsRest;
309 
310  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
311 
312  } else if (ladderChange == +1 && sensorChange == -1) {
314  nextSensorID = MPHSensorID;
315  if (layerNumber == 1) {
316  if (ladderNumber < 8) {
317  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
318  } else {
319  nextSensorID.setLadderNumber(1);
320  }
321  } else if (layerNumber == 2) {
322  if (ladderNumber < 12) {
323  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
324  } else {
325  nextSensorID.setLadderNumber(1);
326  }
327  }
328  uCellDownLeft_tmp = 0;
329  uCellUpRight_tmp = uCellsRest;
330  vCellDownLeft_tmp = vCellDownLeft;
331  vCellUpRight_tmp = vCellUpRight;
332 
333  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
334 
335  nextSensorID = MPHSensorID;
336  nextSensorID.setSensorNumber(1);
337  vCellDownLeft_tmp = vCells - 1 - vCellsRest;
338  vCellUpRight_tmp = vCells - 1;
339  uCellDownLeft_tmp = uCellDownLeft;
340  uCellUpRight_tmp = uCellUpRight;
341 
342  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
343 
344  nextSensorID = MPHSensorID;
345  if (layerNumber == 1) {
346  if (ladderNumber < 8) {
347  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
348  } else {
349  nextSensorID.setLadderNumber(1);
350  }
351  } else if (layerNumber == 2) {
352  if (ladderNumber < 12) {
353  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
354  } else {
355  nextSensorID.setLadderNumber(1);
356  }
357  }
358  nextSensorID.setSensorNumber(1);
359  uCellDownLeft_tmp = 0;
360  uCellUpRight_tmp = uCellsRest;
361  vCellDownLeft_tmp = vCells - 1 - vCellsRest;
362  vCellUpRight_tmp = vCells - 1;
363 
364  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
365 
366  } else if (ladderChange == +1 && sensorChange == +1) {
368  nextSensorID = MPHSensorID;
369  if (layerNumber == 1) {
370  if (ladderNumber < 8) {
371  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
372  } else {
373  nextSensorID.setLadderNumber(1);
374  }
375  } else if (layerNumber == 2) {
376  if (ladderNumber < 12) {
377  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
378  } else {
379  nextSensorID.setLadderNumber(1);
380  }
381  }
382  uCellDownLeft_tmp = 0;
383  uCellUpRight_tmp = uCellsRest;
384  vCellDownLeft_tmp = vCellDownLeft;
385  vCellUpRight_tmp = vCellUpRight;
386 
387  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
388 
389  nextSensorID = MPHSensorID;
390  nextSensorID.setSensorNumber(2);
391  vCellDownLeft_tmp = 0;
392  vCellUpRight_tmp = vCellsRest;
393  uCellDownLeft_tmp = uCellDownLeft;
394  uCellUpRight_tmp = uCellUpRight;
395 
396  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
397 
398  nextSensorID = MPHSensorID;
399  if (layerNumber == 1) {
400  if (ladderNumber < 8) {
401  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
402  } else {
403  nextSensorID.setLadderNumber(1);
404  }
405  } else if (layerNumber == 2) {
406  if (ladderNumber < 12) {
407  nextSensorID.setLadderNumber(ladderNumber + ladderChange);
408  } else {
409  nextSensorID.setLadderNumber(1);
410  }
411  }
412  nextSensorID.setSensorNumber(2);
413  uCellDownLeft_tmp = 0;
414  uCellUpRight_tmp = uCellsRest;
415  vCellDownLeft_tmp = 0;
416  vCellUpRight_tmp = vCellsRest;
417 
418  storeDATCONROIids.appendNew(ROIid(uCellDownLeft_tmp, uCellUpRight_tmp, vCellDownLeft_tmp, vCellUpRight_tmp, nextSensorID));
419 
420  }
421  }
422  }
423 }
424 
Belle2::VXD::SensorInfoBase::getUCells
int getUCells() const
Return number of pixel/strips in u direction.
Definition: SensorInfoBase.h:223
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::VXD::SensorInfoBase::getUCellID
int getUCellID(double u, double v=0, bool clamp=false) const
Return the corresponding pixel/strip ID of a given u coordinate.
Definition: SensorInfoBase.h:203
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::VxdID::getLadderNumber
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:108
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::PXD::SensorInfo
Specific implementation of SensorInfo for PXD Sensors which provides additional pixel specific inform...
Definition: SensorInfo.h:34
Belle2::VXD::SensorInfoBase::getVCellID
int getVCellID(double v, bool clamp=false) const
Return the corresponding pixel/strip ID of a given v coordinate.
Definition: SensorInfoBase.h:213
Belle2::ROIid
ROIid stores the U and V ids and the sensor id of the Region Of Interest.
Definition: ROIid.h:35
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXD::SensorInfoBase::getVCells
int getVCells() const
Return number of pixel/strips in v direction.
Definition: SensorInfoBase.h:225
Belle2::DATCONROICalculationModule
The DATCONROICalculationModule calculates ROI from the DATCONMostProbableHit / PXDIntercepts calculat...
Definition: DATCONROICalculationModule.h:43
Belle2::VxdID::setSensorNumber
void setSensorNumber(baseType sensor)
Set the sensor id.
Definition: VxdID.h:121
Belle2::VxdID::getSensorNumber
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:110
Belle2::VxdID::getLayerNumber
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:106
Belle2::VxdID::setLadderNumber
void setLadderNumber(baseType ladder)
Set the ladder id.
Definition: VxdID.h:119