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