Belle II Software development
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#include <pxd/dataobjects/PXDDAQStatus.h>
11#include <pxd/dataobjects/PXDDigit.h>
12
13#include <framework/logging/Logger.h>
14
15#include <vxd/geometry/GeoCache.h>
16
17#include <pxd/reconstruction/Pixel.h>
18#include <pxd/reconstruction/PXDPixelMasker.h>
19
20#include <set>
21#include <algorithm>
22
23using namespace std;
24using namespace Belle2;
25using namespace Belle2::PXD;
26
27//-----------------------------------------------------------------
28// Register the Module
29//-----------------------------------------------------------------
30REG_MODULE(PXDRawHitSorter);
31
32//-----------------------------------------------------------------
33// Implementation
34//-----------------------------------------------------------------
35
37{
38 //Set module properties
39 setDescription("This module converts the input collection of PXDRawHits into "
40 "a collection of PXDDigits sorted, for each half-ladder, by frame, row,"
41 "and column.");
43
44 addParam("mergeDuplicates", m_mergeDuplicates,
45 "If true, take maximum charge of multiple instances of the same fired pixel. Otherwise only keep the first.", true);
46 addParam("zeroSuppressionCut", m_0cut, "Minimum charge for a digit to carry", 0);
47 addParam("trimOutOfRange", m_trimOutOfRange, "Discard rawhits with out-of-range coordinates", true);
48 addParam("rawHits", m_storeRawHitsName, "PXDRawHit collection name", string(""));
49 addParam("digits", m_storeDigitsName, "PXDDigit collection name", string(""));
50}
51
52
54{
55 //Register collections
57 m_storeDaqStatus.isRequired();
58 //m_storeDigits.registerInDataStore(m_storeDigitsName, DataStore::c_ErrorIfAlreadyRegistered);
59 m_storeDigits.registerInDataStore(m_storeDigitsName);
60
61}
62
64{
65 // if no input, nothing to do
66 if (!m_storeRawHits || !m_storeRawHits.getEntries()) return;
67
69
70 //Mapping of Pixel information to sort according to VxdID, row, column
71 std::map<VxdID, std::multiset<Pixel>> sensors;
72 // Get Map of (un)usable modules
73 auto usability = m_storeDaqStatus->getUsable();
74
75 // Fill sensor information to get sorted Pixel indices
76 const int nPixels = m_storeRawHits.getEntries();
77 for (int i = 0; i < nPixels; i++) {
78 const PXDRawHit* const rawhit = m_storeRawHits[i];
79 // If malformed object, drop it.
80 VxdID sensorID = rawhit->getSensorID();
81 if (!geo.validSensorID(sensorID)) {
82 B2WARNING("Malformed PXDRawHit, VxdID $" << hex << sensorID.getID() << ", dropping. (" << sensorID << ")");
83 continue;
84 }
85 if (!usability[sensorID]) continue;// masked as bad sensor data
86 if (m_trimOutOfRange && !goodHit(rawhit))
87 continue;
88 // Zero-suppression cut
89 if (rawhit->getCharge() < m_0cut) continue;
90 // FIXME: The index of the temporary Pixel object seems not needed here.
91 // Set this index always to zero
92 Pixel px(rawhit, 0);
93 // We need some protection against bad data
94 if (sensorID.getLayerNumber() && sensorID.getLadderNumber() && sensorID.getSensorNumber()) {
95 if (PXDPixelMasker::getInstance().pixelOK(sensorID, px.getU(), px.getV())) {
96 sensors[sensorID].insert(px);
97 }
98 }
99 }
100
101 unsigned int index(0);
102 // And just loop over the sensors and create the digits.
103 for (auto& sensor : sensors) {
104 const PXD::Pixel* lastpx(0);
105 VxdID sensorID = sensor.first;
106 for (const PXD::Pixel& px : sensor.second) {
107 //Normal case: pixel has different address
108 if (!lastpx || px > *lastpx) {
109 //Write the digit
110 m_storeDigits.appendNew(sensorID, px.getU(), px.getV(), px.getCharge());
111 ++index;
112 } else {
113 //We already have a pixel at this address, see if we merge or drop the new one
114 if (m_mergeDuplicates) {
115 //Merge the two pixels. As the PXDDigit does not have setters we have to create a new object.
116 //The charge of the new PXDDigit is the maximum of the duplicates.
117 const PXDDigit& old = *m_storeDigits[index - 1];
118 *m_storeDigits[index - 1] = PXDDigit(old.getSensorID(), old.getUCellID(),
119 old.getVCellID(), std::max(old.getCharge(), static_cast<unsigned short>(px.getCharge())));
120 } //Otherwise delete the second pixel by forgetting about it.
121 }
122 lastpx = &px;
123 }
124 }
125}
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
Module()
Constructor.
Definition Module.cc:30
@ 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:88
unsigned short getUCellID() const
Get cell ID in u.
Definition PXDDigit.h:83
unsigned short getCharge() const
Get collected charge.
Definition PXDDigit.h:93
VxdID getSensorID() const
Get the sensor ID.
Definition PXDDigit.h:78
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.
PXDRawHitSorterModule()
Constructor defining the parameters.
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:68
float getCharge() const
Return the Charge of the Pixel.
Definition Pixel.h:72
unsigned short getV() const
Return the CellID in v.
Definition Pixel.h:70
Class to facilitate easy access to sensor information of the VXD like coordinate transformations or p...
Definition GeoCache.h:38
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:32
baseType getID() const
Get the unique id.
Definition VxdID.h:93
baseType getSensorNumber() const
Get the sensor id.
Definition VxdID.h:99
baseType getLadderNumber() const
Get the ladder id.
Definition VxdID.h:97
baseType getLayerNumber() const
Get the layer id.
Definition VxdID.h:95
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
Abstract base class for different kinds of events.
STL namespace.