Belle II Software  release-05-01-25
PXDRawDQMChipsModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Klemens Lautenbach, Bjoern Spruck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <pxd/modules/pxdDQM/PXDRawDQMChipsModule.h>
12 #include <vxd/geometry/GeoCache.h>
13 
14 #include <TDirectory.h>
15 #include <boost/format.hpp>
16 #include <string>
17 
18 using namespace std;
19 using namespace Belle2;
20 using namespace Belle2::PXD;
21 using namespace Belle2::VXD;
22 
23 using boost::format;
24 
25 //-----------------------------------------------------------------
26 // Register the Module
27 //-----------------------------------------------------------------
28 REG_MODULE(PXDRawDQMChips)
29 
30 //-----------------------------------------------------------------
31 // Implementation
32 //-----------------------------------------------------------------
33 
35 {
36  //Set module properties
37  setDescription("Monitor raw PXD");
38  setPropertyFlags(c_ParallelProcessingCertified);
39  addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where histograms will be placed",
40  std::string("pxdraw"));
41 
42  addParam("PXDRawHitsName", m_storeRawHitsName, "The name of the StoreArray of PXDRawHits to be processed", string(""));
43 }
44 
45 void PXDRawDQMChipsModule::defineHisto()
46 {
47  // Create a separate histogram directory and cd into it.
48  TDirectory* oldDir = gDirectory;
49  if (m_histogramDirectoryName != "") {
50  oldDir->mkdir(m_histogramDirectoryName.c_str());
51  oldDir->cd(m_histogramDirectoryName.c_str());
52  }
53 
54 
55  for (auto i = 0; i < 64; i++) {
56  auto layer = (((i >> 5) & 0x1) + 1);
57  auto ladder = ((i >> 1) & 0xF);
58  auto sensor = ((i & 0x1) + 1);
59 
60  // Check if sensor exist
61  if (Belle2::VXD::GeoCache::getInstance().validSensorID(Belle2::VxdID(layer, ladder, sensor))) {
62  for (auto j = 0; j < eNumSwitcher; j++) {
63  for (auto k = 0; k < eNumDCD; k++) {
64  string s = str(format("Sensor %d:%d:%d (DHH ID %02Xh) Switcher %d DCD %d") % layer % ladder % sensor % i % j % k);
65  string s2 = str(format("_%d.%d.%d_%d_%d") % layer % ladder % sensor % j % k);
66 
67  hrawPxdHitsCount[i][j][k] = new TH1F(("hrawPxdCount" + s2).c_str(), ("Pxd Raw Count " + s + ";Nr per Event").c_str(), 8192, 0,
68  8192);
69  hrawPxdHitsCharge[i][j][k] = new TH1F(("hrawPxdHitsCharge" + s2).c_str(),
70  ("Pxd Raw Hit Charge, " + s + ";Charge").c_str(), 256, 0, 256);
71  }
72  }
73  } else {
74  for (auto j = 0; j < eNumSwitcher; j++) {
75  for (auto k = 0; k < eNumDCD; k++) {
76  hrawPxdHitsCount[i][j][k] = NULL;
77  hrawPxdHitsCharge[i][j][k] = NULL;
78  }
79  }
80  }
81  }
82 
83  // cd back to root directory
84  oldDir->cd();
85 }
86 
87 void PXDRawDQMChipsModule::initialize()
88 {
89  REG_HISTOGRAM
90  m_storeRawHits.isRequired(m_storeRawHitsName);
91 }
92 
93 void PXDRawDQMChipsModule::beginRun()
94 {
95  // Just to make sure, reset all the histograms.
96  for (auto i = 0; i < eNumSensors; i++) {
97  for (auto j = 0; j < eNumSwitcher; j++) {
98  for (auto k = 0; k < eNumDCD; k++) {
99  if (hrawPxdHitsCount[i][j][k]) hrawPxdHitsCount[i][j][k]->Reset();
100  if (hrawPxdHitsCharge[i][j][k]) hrawPxdHitsCharge[i][j][k]->Reset();
101  }
102  }
103  }
104 }
105 
106 void PXDRawDQMChipsModule::event()
107 {
108  uint nhits[eNumSensors][eNumSwitcher][eNumDCD] = {};
109 
110  for (auto& it : m_storeRawHits) {
111  int dhh_id;
112  // calculate DHH id from Vxd Id
113  unsigned int layer, ladder, sensor;//, segment;
114  VxdID currentVxdId;
115  currentVxdId = it.getSensorID();
116  layer = currentVxdId.getLayerNumber();
117  ladder = currentVxdId.getLadderNumber();
118  sensor = currentVxdId.getSensorNumber();
119  // segment = currentVxdId.getSegmentNumber();// Frame nr? ... ignore
120  dhh_id = ((layer - 1) << 5) | ((ladder) << 1) | (sensor - 1);
121  if (dhh_id <= 0 || dhh_id >= 64) {
122  B2ERROR("SensorId (DHH ID) out of range: " << dhh_id);
123  continue;
124  }
125  int switcher = it.getRow() / 128; // TODO here must be: function for REAL inverse mapping
126  int dcd = it.getColumn() / 64; // TODO here must be: function for REAL inverse mapping
127  // TODO check switcher 0-6? DCD 0-4?
128  nhits[dhh_id][switcher][dcd]++;
129  if (hrawPxdHitsCharge[dhh_id][switcher][dcd]) hrawPxdHitsCharge[dhh_id][switcher][dcd]->Fill(it.getCharge());
130  }
131  for (auto i = 0; i < eNumSensors; i++) {
132  for (auto j = 0; j < eNumSwitcher; j++) {
133  for (auto k = 0; k < eNumDCD; k++) {
134  if (hrawPxdHitsCount[i][j][k]) hrawPxdHitsCount[i][j][k]->Fill(nhits[i][j][k]);
135  }
136  }
137  }
138 }
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::VxdID::getLadderNumber
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:108
Belle2::VXD::GeoCache::validSensorID
bool validSensorID(Belle2::VxdID id) const
Check that id is a valid sensor number.
Definition: GeoCache.cc:53
Belle2::VXD
Namespace to provide code needed by both Vertex Detectors, PXD and SVD, and also testbeam telescopes.
Definition: GeoCache.h:36
Belle2::PXD
Namespace to encapsulate code needed for simulation and reconstrucion of the PXD.
Definition: PXDCalibrationUtilities.h:28
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::PXDRawDQMChipsModule
The raw PXD DQM module.
Definition: PXDRawDQMChipsModule.h:43
Belle2::VxdID::getSensorNumber
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:110
Belle2::VxdID::getLayerNumber
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:106
Belle2::HistoModule
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29