Belle II Software  release-08-01-10
PXDRawHitSorterModule.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 <pxd/modules/pxdReconstruction/PXDRawHitSorterModule.h>
10 
11 #include <framework/logging/Logger.h>
12 
13 #include <vxd/geometry/GeoCache.h>
14 
15 #include <pxd/reconstruction/Pixel.h>
16 #include <pxd/reconstruction/PXDPixelMasker.h>
17 
18 #include <set>
19 #include <algorithm>
20 
21 using namespace std;
22 using namespace Belle2;
23 using namespace Belle2::PXD;
24 
25 //-----------------------------------------------------------------
26 // Register the Module
27 //-----------------------------------------------------------------
28 REG_MODULE(PXDRawHitSorter);
29 
30 //-----------------------------------------------------------------
31 // Implementation
32 //-----------------------------------------------------------------
33 
34 PXDRawHitSorterModule::PXDRawHitSorterModule() : Module()
35 {
36  //Set module properties
37  setDescription("This module converts the input collection of PXDRawHits into "
38  "a collection of PXDDigits sorted, for each half-ladder, by frame, row,"
39  "and column.");
41 
42  addParam("mergeDuplicates", m_mergeDuplicates,
43  "If true, take maximum charge of multiple instances of the same fired pixel. Otherwise only keep the first.", true);
44  addParam("zeroSuppressionCut", m_0cut, "Minimum charge for a digit to carry", 0);
45  addParam("trimOutOfRange", m_trimOutOfRange, "Discard rawhits whith out-of-range coordinates", true);
46  addParam("rawHits", m_storeRawHitsName, "PXDRawHit collection name", string(""));
47  addParam("digits", m_storeDigitsName, "PXDDigit collection name", string(""));
48 }
49 
50 
52 {
53  //Register collections
55  m_storeDaqStatus.isRequired();
56  //m_storeDigits.registerInDataStore(m_storeDigitsName, DataStore::c_ErrorIfAlreadyRegistered);
57  m_storeDigits.registerInDataStore(m_storeDigitsName);
58 
59 }
60 
62 {
63  // if no input, nothing to do
64  if (!m_storeRawHits || !m_storeRawHits.getEntries()) return;
65 
67 
68  //Mapping of Pixel information to sort according to VxdID, row, column
69  std::map<VxdID, std::multiset<Pixel>> sensors;
70  // Get Map of (un)usable modules
71  auto usability = m_storeDaqStatus->getUsable();
72 
73  // Fill sensor information to get sorted Pixel indices
74  const int nPixels = m_storeRawHits.getEntries();
75  for (int i = 0; i < nPixels; i++) {
76  const PXDRawHit* const rawhit = m_storeRawHits[i];
77  // If malformed object, drop it.
78  VxdID sensorID = rawhit->getSensorID();
79  if (!geo.validSensorID(sensorID)) {
80  B2WARNING("Malformed PXDRawHit, VxdID $" << hex << sensorID.getID() << ", dropping. (" << sensorID << ")");
81  continue;
82  }
83  if (!usability[sensorID]) continue;// masked as bad sensor data
84  if (m_trimOutOfRange && !goodHit(rawhit))
85  continue;
86  // Zero-suppression cut
87  if (rawhit->getCharge() < m_0cut) continue;
88  // FIXME: The index of the temporary Pixel object seems not needed here.
89  // Set this index always to zero
90  Pixel px(rawhit, 0);
91  // We need some protection against bad data
92  if (sensorID.getLayerNumber() && sensorID.getLadderNumber() && sensorID.getSensorNumber()) {
93  if (PXDPixelMasker::getInstance().pixelOK(sensorID, px.getU(), px.getV())) {
94  sensors[sensorID].insert(px);
95  }
96  }
97  }
98 
99  unsigned int index(0);
100  // And just loop over the sensors and create the digits.
101  for (auto& sensor : sensors) {
102  const PXD::Pixel* lastpx(0);
103  VxdID sensorID = sensor.first;
104  for (const PXD::Pixel& px : sensor.second) {
105  //Normal case: pixel has different address
106  if (!lastpx || px > *lastpx) {
107  //Write the digit
108  m_storeDigits.appendNew(sensorID, px.getU(), px.getV(), px.getCharge());
109  ++index;
110  } else {
111  //We already have a pixel at this address, see if we merge or drop the new one
112  if (m_mergeDuplicates) {
113  //Merge the two pixels. As the PXDDigit does not have setters we have to create a new object.
114  //The charge of the new PXDDigit is the maximum of the duplicates.
115  const PXDDigit& old = *m_storeDigits[index - 1];
116  *m_storeDigits[index - 1] = PXDDigit(old.getSensorID(), old.getUCellID(),
117  old.getVCellID(), std::max(old.getCharge(), static_cast<unsigned short>(px.getCharge())));
118  } //Otherwise delete the second pixel by forgetting about it.
119  }
120  lastpx = &px;
121  }
122  }
123 }
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
The PXD digit class.
Definition: PXDDigit.h:27
unsigned short getVCellID() const
Get cell ID in v.
Definition: PXDDigit.h:74
unsigned short getUCellID() const
Get cell ID in u.
Definition: PXDDigit.h:69
unsigned short getCharge() const
Get collected charge.
Definition: PXDDigit.h:79
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDDigit.h:64
The PXD Raw Hit class This class stores information about PXD Pixel hits and makes them available in ...
Definition: PXDRawHit.h:24
short getCharge() const
Get collected charge.
Definition: PXDRawHit.h:92
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDRawHit.h:52
static PXDPixelMasker & getInstance()
Main (and only) way to access the PXDPixelMasker.
int m_0cut
Minimum charge for a digit to carry.
bool m_trimOutOfRange
Discard out-of-range hits.
virtual void initialize() override
Initialize the module.
bool m_mergeDuplicates
Mode: if true, merge duplicate pixels, otherwise only keep the first.
virtual void event() override
do the sorting
StoreObjPtr< PXDDAQStatus > m_storeDaqStatus
Required input for PXD Daq Status.
std::string m_storeRawHitsName
Name of the collection to use for PXDRawHits.
bool goodHit(const PXDRawHit *const rawhit) const
Utility function to check pixel coordinates.
std::string m_storeDigitsName
Name of the collection to use for the PXDDigits.
StoreArray< PXDRawHit > m_storeRawHits
Required input for PXDRawHit.
StoreArray< PXDDigit > m_storeDigits
Output array for PXDDigits.
Class to represent one pixel, used in clustering for fast access.
Definition: Pixel.h:36
unsigned short getU() const
Return the CellID in u.
Definition: Pixel.h:66
float getCharge() const
Return the Charge of the Pixel.
Definition: Pixel.h:70
unsigned short getV() const
Return the CellID in v.
Definition: Pixel.h:68
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
bool validSensorID(Belle2::VxdID id) const
Check that id is a valid sensor number.
Definition: GeoCache.cc:52
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getID() const
Get the unique id.
Definition: VxdID.h:94
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:100
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:98
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
Abstract base class for different kinds of events.