Belle II Software development
PXDRawHotPixelMaskCollectorModue.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/pxdHotPixelMaskCollector/PXDRawHotPixelMaskCollectorModule.h>
10#include <vxd/geometry/GeoCache.h>
11
12#include <boost/format.hpp>
13
14#include <TH1I.h>
15
16using namespace std;
17using boost::format;
18using namespace Belle2;
19
20
21//-----------------------------------------------------------------
22// Register the Module
23//-----------------------------------------------------------------
24REG_MODULE(PXDRawHotPixelMaskCollector);
25
26//-----------------------------------------------------------------
27// Implementation
28//-----------------------------------------------------------------
29
31{
32 // Set module properties
33 setDescription("Calibration Collector Module for PXD hot pixel masking from rawhits");
35
36 addParam("zeroSuppressionCut", m_0cut, "Minimum charge (in ADU) for detecting a hit", 0);
37 addParam("rawHits", m_storeRawHitsName, "PXDRawHit collection name", string(""));
38}
39
40void PXDRawHotPixelMaskCollectorModule::prepare() // Do your initialise() stuff here
41{
42 m_pxdRawHit.isRequired();
43 m_storeDaqStatus.isRequired();
44
46
47 if (gTools->getNumberOfPXDLayers() == 0) {
48 B2WARNING("Missing geometry for PXD, PXD-masking is skiped.");
49 }
50
51 //-------------------------------------------------------------------------------------------------
52 // PXDHits: Histogram the number of PXDRawHits per event (assuming Belle 2 PXD with < 2% occupancy)
53 //-------------------------------------------------------------------------------------------------
54 auto hPXDHits = new TH1I("hPXDHits",
55 "Number of hits in PXD per events used for masking, distribution parameters found by PXDRawHotPixelMaskCollectorModule", 200000, 0,
56 200000);
57 hPXDHits->GetXaxis()->SetTitle("Number of hits");
58 hPXDHits->GetYaxis()->SetTitle("Events");
59 registerObject<TH1I>("PXDHits", hPXDHits);
60
61 //--------------------------------------------------------
62 // PXDHitCounts: Count the number of PXDRawHits per sensor
63 //--------------------------------------------------------
64 int nPXDSensors = gTools->getNumberOfPXDSensors();
65 auto hPXDHitCounts = new TH1I("hPXDHitCounts",
66 "Number of hits in PXD sensors for masking, distribution parameters found by PXDRawHotPixelMaskCollectorModule", nPXDSensors, 0,
67 nPXDSensors);
68
69 hPXDHitCounts->GetXaxis()->SetTitle("SensorID");
70 hPXDHitCounts->GetYaxis()->SetTitle("Number of hits");
71 for (int i = 0; i < nPXDSensors; i++) {
72 VxdID id = gTools->getSensorIDFromPXDIndex(i);
73 string sensorDescr = id;
74 hPXDHitCounts->GetXaxis()->SetBinLabel(i + 1, str(format("%1%") % sensorDescr).c_str());
75 }
76 registerObject<TH1I>("PXDHitCounts", hPXDHitCounts);
77
78 // Fill PXDHitMap with empty histos for all sensors
79 for (int i = 0; i < nPXDSensors; i++) {
80 VxdID id = gTools->getSensorIDFromPXDIndex(i);
81 string sensorDescr = id;
82
83 //----------------------------------------------------------------
84 // Hitmaps: Number of hits per sensor and pixel
85 //----------------------------------------------------------------
86 string name = str(format("PXD_%1%_PixelHitmap") % id.getID());
87 string title = str(format("PXD Sensor %1% Pixel Hitmap from PXDRawHotPixelMaskCollector") % sensorDescr);
88
89 // Data object creation --------------------------------------------------
90 auto hsensorhitmap = new TH1I(name.c_str(), title.c_str(), 250 * 768, 0, 250 * 768);
91 registerObject<TH1I>(name.c_str(), hsensorhitmap);
92 }
93}
94
95void PXDRawHotPixelMaskCollectorModule::collect() // Do your event() stuff here
96{
97 // Histogram pxd hits per event
98 TH1I* collector_hits = getObjectPtr<TH1I>("PXDHits");
99
100 // Even if there is no input StoreArray, we still want to fill zero hits
101 if (!m_pxdRawHit)
102 collector_hits->Fill(0);
103 else
104 collector_hits->Fill(m_pxdRawHit.getEntries());
105
106 auto& geo = VXD::GeoCache::getInstance();
107 auto gTools = geo.getGeoTools();
108
109 // Get Map of (un)usable modules
110 auto usability = m_storeDaqStatus->getUsable();
111 // Count hits per sensor
112 TH1I* collector_pxdhitcounts = getObjectPtr<TH1I>("PXDHitCounts");
113
114 for (auto& rawhit : m_pxdRawHit) {
115 VxdID sensorID = rawhit.getSensorID();
116 if (!geo.validSensorID(sensorID)) {
117 B2WARNING("Malformed PXDRawHit, VxdID $" << hex << sensorID.getID() << ", dropping. (" << sensorID << ")");
118 continue;
119 }
120 if (!usability[sensorID]) continue;// masked as bad sensor data
121
122 // We need some protection against hot data
123 if (!goodHit(rawhit)) continue;
124
125 // Zero-suppression cut
126 if (rawhit.getCharge() < m_0cut) continue;
127
128 // Increment counter for hit pixel
129 if (sensorID.getLayerNumber() && sensorID.getLadderNumber() && sensorID.getSensorNumber()) {
130 string name = str(format("PXD_%1%_PixelHitmap") % sensorID.getID());
131 TH1I* collector_sensorhitmap = getObjectPtr<TH1I>(name.c_str());
132 collector_sensorhitmap->Fill(rawhit.getColumn() * 768 + rawhit.getRow());
133 collector_pxdhitcounts->Fill(gTools->getPXDSensorIndex(sensorID));
134 }
135 }
136}
Calibration collector module base class.
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
PXDRawHotPixelMaskCollectorModule()
Constructor: Sets the description, the properties and the parameters of the module.
int m_0cut
Minimum charge (ADU) for detecting a hit.
StoreArray< PXDRawHit > m_pxdRawHit
Required input for PXDRawHit.
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 &rawhit) const
Utility function to check pixel coordinates.
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
const GeoTools * getGeoTools()
Return a raw pointer to a GeoTools object.
Definition: GeoCache.h:142
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
int getID(const std::vector< double > &breaks, double t)
get id of the time point t
Definition: calibTools.h:60
Abstract base class for different kinds of events.
STL namespace.