Belle II Software  release-06-02-00
ROIGeneratorModule.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 <tracking/modules/pxdDataReduction/ROIGeneratorModule.h>
10 #include <framework/datastore/StoreObjPtr.h>
11 #include <framework/dataobjects/EventMetaData.h>
12 #include <framework/datastore/StoreArray.h>
13 #include <tracking/dataobjects/ROIid.h>
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 //-----------------------------------------------------------------
19 // Register the Module
20 //-----------------------------------------------------------------
21 
22 REG_MODULE(ROIGenerator)
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
29 {
30  //Set module properties
31  setDescription("This module is used to generate a certain number of ROIs");
32  setPropertyFlags(c_ParallelProcessingCertified);
33 
34  addParam("ROIListName", m_ROIListName, "name of the list of ROIs", std::string(""));
35  addParam("nROIs", m_nROIs, "number of generated ROIs", 1);
36 
37  addParam("TrigDivider", m_divider, "Generates one ROI every TrigDivider events", 2);
38  addParam("Layer" , m_layer , "on layer", 1);
39  addParam("Ladder" , m_ladder , " ladder " , 1);
40  addParam("Sensor" , m_sensor , " sensor " , 1);
41 
42  addParam("MinU" , m_minU , " min U (pixel column hopefully) ", 0);
43  addParam("MaxU" , m_maxU , " max U (pixel column hopefully) ", 250 - 1);
44 
45 
46  addParam("MinV" , m_minV , " min V (pixel column hopefully) ", 0);
47  addParam("MaxV" , m_maxV , " max v (pixel column hopefully) ", 768 - 1);
48 
49  addParam("Random" , m_random , "dont use fix position, move pseudo randomly", false);
50 }
51 
52 void ROIGeneratorModule::initialize()
53 {
54  StoreObjPtr<EventMetaData> eventMetaData;
55  eventMetaData.isRequired();
56 
57  StoreArray<ROIid> roiIDs;
58  roiIDs.registerInDataStore(m_ROIListName); // does not report error if ROIid exists
59 }
60 
61 void ROIGeneratorModule::event()
62 {
63 
64  StoreArray<ROIid> ROIList(m_ROIListName);
65 
66  StoreObjPtr<EventMetaData> eventMetaDataPtr;
67  int tNr = eventMetaDataPtr->getEvent(); // trigger number
68 
69  // Only if divider tells us to...
70  if (m_divider != 0 && (tNr % m_divider) != 0)
71  return ;
72 
73  // ROIList.create(true);
74 
75  ROIid tmp_ROIid;
76 
77  VxdID sensorID;
78  sensorID.setLayerNumber(m_layer);
79  sensorID.setLadderNumber(m_ladder);
80  sensorID.setSensorNumber(m_sensor);
81 
82  // Always create one FULL size ROI
83  int minU = m_minU, maxU = m_maxU, minV = m_minV, maxV = m_maxV;
84  int w = maxU - minU;
85  int h = maxV - minV;
86  if (m_nROIs == 1 && m_random) {
87  switch (tNr % 9) {
88  case 0:
89  minU = 0;
90  maxU = w;
91  minV = 0;
92  maxV = h;
93  break;
94  case 1:
95  minU = 0;
96  maxU = w;
97  break;
98  case 2:
99  minU = 0;
100  maxU = w;
101  minV = 768 - 1 - h;
102  maxV = 768 - 1;
103  break;
104  case 3:
105  minV = 0;
106  maxV = h;
107  break;
108  case 4:
109  break;
110  case 5:
111  minV = 768 - 1 - h;
112  maxV = 768 - 1;
113  break;
114  case 6:
115  minU = 250 - 1 - w;
116  maxU = 250 - 1;
117  minV = 0;
118  maxV = h;
119  break;
120  case 7:
121  minU = 250 - 1 - w;
122  maxU = 250 - 1;
123  break;
124  case 8:
125  minU = 250 - 1 - w;
126  maxU = 250 - 1;
127  minV = 768 - 1 - h;
128  maxV = 768 - 1;
129  break;
130  default:
131  break;
132  }
133  }
134  tmp_ROIid.setMinUid(minU);
135  tmp_ROIid.setMinVid(minV);
136  tmp_ROIid.setMaxUid(maxU);
137  tmp_ROIid.setMaxVid(maxV);
138  tmp_ROIid.setSensorID(sensorID);
139 
140  ROIList.appendNew(tmp_ROIid);
141 
142  if (m_nROIs > 1) {
143  // ... plus additional ones for debugging.
144  // maybe we should do it depending on the triggernr lateron...
145  int dU = (m_maxU - m_minU) / (m_nROIs + 1);
146  int dV = (m_maxV - m_minV) / (m_nROIs + 1);
147  for (int iROI = 1; iROI < m_nROIs; iROI++) {
148  // Create a chain of ROIs from top left to bottom right
149  minU = m_minU + dU * iROI;
150  maxU = minU + dU;
151  minV = m_minV + dV * iROI;
152  maxV = minV + dV;
153 
154  tmp_ROIid.setMinUid(minU);
155  tmp_ROIid.setMinVid(minV);
156  tmp_ROIid.setMaxUid(maxU);
157  tmp_ROIid.setMaxVid(maxV);
158  tmp_ROIid.setSensorID(sensorID);
159 
160  ROIList.appendNew(tmp_ROIid);
161  }
162  }
163 }
Base class for Modules.
Definition: Module.h:72
The ROI generator Module.
ROIid stores the U and V ids and the sensor id of the Region Of Interest.
Definition: ROIid.h:25
void setMaxUid(double user_maxUid)
set the maximum U id of the ROI
Definition: ROIid.h:50
void setSensorID(VxdID user_sensorID)
set the sensor ID of the ROI
Definition: ROIid.h:53
void setMinUid(double user_minUid)
set the minimum U id of the ROI
Definition: ROIid.h:49
void setMaxVid(double user_maxVid)
set the maximum V id of the ROI
Definition: ROIid.h:52
void setMinVid(double user_minVid)
set the minimum V id of the ROI
Definition: ROIid.h:51
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.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
void setSensorNumber(baseType sensor)
Set the sensor id.
Definition: VxdID.h:111
void setLadderNumber(baseType ladder)
Set the ladder id.
Definition: VxdID.h:109
void setLayerNumber(baseType layer)
Set the layer id.
Definition: VxdID.h:107
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.