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