Belle II Software  release-05-01-25
PXDRawHitSorterModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <pxd/modules/pxdReconstruction/PXDRawHitSorterModule.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 
23 using namespace std;
24 using namespace Belle2;
25 using namespace Belle2::PXD;
26 
27 //-----------------------------------------------------------------
28 // Register the Module
29 //-----------------------------------------------------------------
30 REG_MODULE(PXDRawHitSorter);
31 
32 //-----------------------------------------------------------------
33 // Implementation
34 //-----------------------------------------------------------------
35 
36 PXDRawHitSorterModule::PXDRawHitSorterModule() : Module()
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 whith 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 crap 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 }
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::PXD::Pixel::getCharge
float getCharge() const
Return the Charge of the Pixel.
Definition: Pixel.h:81
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::PXD::PXDRawHitSorterModule::m_storeDigitsName
std::string m_storeDigitsName
Name of the collection to use for the PXDDigits.
Definition: PXDRawHitSorterModule.h:78
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module::c_ParallelProcessingCertified
@ 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:82
Belle2::PXD::Pixel
Class to represent one pixel, used in clustering for fast access.
Definition: Pixel.h:47
Belle2::VxdID::getID
baseType getID() const
Get the unique id.
Definition: VxdID.h:104
Belle2::PXD::PXDRawHitSorterModule::initialize
virtual void initialize() override
Initialize the module.
Definition: PXDRawHitSorterModule.cc:53
Belle2::PXD::PXDRawHitSorterModule::m_mergeDuplicates
bool m_mergeDuplicates
Mode: if true, merge duplicate pixels, otherwise only keep the first.
Definition: PXDRawHitSorterModule.h:80
Belle2::PXDDigit
The PXD digit class.
Definition: PXDDigit.h:38
Belle2::PXD::PXDRawHitSorterModule::m_trimOutOfRange
bool m_trimOutOfRange
Discard out-of-range hits.
Definition: PXDRawHitSorterModule.h:84
Belle2::VXD::GeoCache::validSensorID
bool validSensorID(Belle2::VxdID id) const
Check that id is a valid sensor number.
Definition: GeoCache.cc:53
Belle2::PXDRawHit
The PXD Raw Hit class This class stores information about PXD Pixel hits and makes them available in ...
Definition: PXDRawHit.h:36
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2::PXDRawHit::getSensorID
VxdID getSensorID() const
Get the sensor ID.
Definition: PXDRawHit.h:64
Belle2::PXD
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
Definition: PXDCalibrationUtilities.h:28
Belle2::PXD::PXDRawHitSorterModule::event
virtual void event() override
do the sorting
Definition: PXDRawHitSorterModule.cc:63
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PXD::PXDRawHitSorterModule::m_storeRawHits
StoreArray< PXDRawHit > m_storeRawHits
Required input for PXDRawHit.
Definition: PXDRawHitSorterModule.h:60
Belle2::PXD::PXDRawHitSorterModule::m_storeDigits
StoreArray< PXDDigit > m_storeDigits
Output array for PXDDigits.
Definition: PXDRawHitSorterModule.h:64
Belle2::PXDRawHit::getCharge
short getCharge() const
Get collected charge.
Definition: PXDRawHit.h:104
Belle2::PXD::Pixel::getV
unsigned short getV() const
Return the CellID in v.
Definition: Pixel.h:79
Belle2::PXD::PXDRawHitSorterModule::m_storeRawHitsName
std::string m_storeRawHitsName
Name of the collection to use for PXDRawHits.
Definition: PXDRawHitSorterModule.h:76
Belle2::Module::addParam
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:562
Belle2::VXD::GeoCache
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:41
Belle2::PXD::Pixel::getU
unsigned short getU() const
Return the CellID in u.
Definition: Pixel.h:77
Belle2::PXD::PXDRawHitSorterModule::m_0cut
int m_0cut
Minimum charge for a digit to carry.
Definition: PXDRawHitSorterModule.h:82
Belle2::PXD::PXDRawHitSorterModule::goodHit
bool goodHit(const PXDRawHit *const rawhit) const
Utility function to check pixel coordinates.
Definition: PXDRawHitSorterModule.h:67
Belle2::PXD::PXDPixelMasker::getInstance
static PXDPixelMasker & getInstance()
Main (and only) way to access the PXDPixelMasker.
Definition: PXDPixelMasker.cc:37
Belle2::PXD::PXDRawHitSorterModule::m_storeDaqStatus
StoreObjPtr< PXDDAQStatus > m_storeDaqStatus
Required input for PXD Daq Status.
Definition: PXDRawHitSorterModule.h:62