Belle II Software  release-05-01-25
PXDGatedModeDQMModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Bjoern Spruck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <pxd/modules/pxdDQM/PXDGatedModeDQMModule.h>
12 #include "TDirectory.h"
13 
14 using namespace std;
15 using namespace Belle2;
16 using namespace Belle2::PXD;
17 using namespace Belle2::VXD;
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(PXDGatedModeDQM)
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
28 PXDGatedModeDQMModule::PXDGatedModeDQMModule() : HistoModule() , m_vxdGeometry(VXD::GeoCache::getInstance())
29 {
30  //Set module properties
31  setDescription("Monitor GatedMode");
32  setPropertyFlags(c_ParallelProcessingCertified);
33  addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where histograms will be placed",
34  std::string("PXDINJ"));
35  addParam("PXDRawHitsName", m_PXDRawHitsName, "Name of PXD raw hits", std::string(""));
36  addParam("perGate", m_perGate, "Make plots per GM Start Gate", true);
37  addParam("minTimeCutLER", m_minTimeCutLER, "minimum time cut in us after LER kick", 20);
38  addParam("maxTimeCutLER", m_maxTimeCutLER, "maximum time cut in us after LER kick", 4980);
39  addParam("minTimeCutHER", m_minTimeCutHER, "minimum time cut in us after HER kick", 20);
40  addParam("maxTimeCutHER", m_maxTimeCutHER, "maximum time cut in us after HER kick", 4980);
41  addParam("outsideTimeCut", m_outsideTimeCut, "outside GM time cut in us after kick", 20000);
42  addParam("chargeCut", m_chargeCut, "minimum pixel ADU charge cut", 5);
43  addParam("chargeCutHigh", m_chargeCutHigh, "minimum pixel ADU charge cut for second set of histograms", 20);
44 }
45 
46 void PXDGatedModeDQMModule::defineHisto()
47 {
48  TDirectory* oldDir = gDirectory;
49  oldDir->mkdir(m_histogramDirectoryName.c_str());// do not rely on return value, might be ZERO
50  oldDir->cd(m_histogramDirectoryName.c_str());//changing to the right directory
51 
52  hBunchInjHER = new TH1F("hBunchInjHER", "Last Inj Bunch HER;Counts;BunchNr/4", 1280, 0, 1280);
53  hBunchInjLER = new TH1F("hBunchInjLER", "Last Inj Bunch LER;Counts;BunchNr/4", 1280, 0, 1280);
54  hBunchTrg = new TH1F("hBunchTrg", "Triggered Bunch;Counts;BunchNr/4", 1280, 0, 1280);
55 
56 
57  std::vector<VxdID> sensors = m_vxdGeometry.getListOfSensors();
58  for (VxdID& avxdid : sensors) {
59  VXD::SensorInfoBase info = m_vxdGeometry.getSensorInfo(avxdid);
60  if (info.getType() != VXD::SensorInfoBase::PXD) continue;
61  // Only interested in PXD sensors
62 
63  TString buff = (std::string)avxdid;
64  TString bufful = buff;
65  bufful.ReplaceAll(".", "_");
66 
67  for (int rgate = m_perGate ? 0 : 96; rgate <= 96; rgate++) { // 96 is no gating
68  hGatedModeMapLER[std::make_pair(avxdid, rgate)] = new TH2F(Form("PXDGatedModeMapLER_%d_", rgate) + bufful,
69  Form("PXDGatedModeMapLER %d ", rgate) + buff + ";U;V", 25, 0, 250, 192, 0, 768);
70  hGatedModeMapHER[std::make_pair(avxdid, rgate)] = new TH2F(Form("PXDGatedModeMapHER_%d_", rgate) + bufful,
71  Form("PXDGatedModeMapHER %d ", rgate) + buff + ";U;V", 25, 0, 250, 192, 0, 768);
72  hGatedModeMapCutLER[std::make_pair(avxdid, rgate)] = new TH2F(Form("PXDGatedModeMapCutLER_%d_", rgate) + bufful,
73  Form("PXDGatedModeMapCutLER %d ", rgate) + buff + ";U;V", 25, 0, 250, 192, 0, 768);
74  hGatedModeMapCutHER[std::make_pair(avxdid, rgate)] = new TH2F(Form("PXDGatedModeMapCutHER_%d_", rgate) + bufful,
75  Form("PXDGatedModeMapCutHER %d ", rgate) + buff + ";U;V", 25, 0, 250, 192, 0, 768);
76 
77  hGatedModeMapADCLER[std::make_pair(avxdid, rgate)] = new TH2F(Form("PXDGatedModeMapADCLER_%d_", rgate) + bufful,
78  Form("PXDGatedModeMapADCLER %d ", rgate) + buff + ";U;V", 25, 0, 250, 192, 0, 768);
79  hGatedModeMapADCHER[std::make_pair(avxdid, rgate)] = new TH2F(Form("PXDGatedModeMapADCHER_%d_", rgate) + bufful,
80  Form("PXDGatedModeMapADCHER %d ", rgate) + buff + ";U;V", 25, 0, 250, 192, 0, 768);
81  hGatedModeMapCutADCLER[std::make_pair(avxdid, rgate)] = new TH2F(Form("PXDGatedModeMapCutADCLER_%d_", rgate) + bufful,
82  Form("PXDGatedModeMapCutADCLER %d ", rgate) + buff + ";U;V", 25, 0, 250, 192, 0, 768);
83  hGatedModeMapCutADCHER[std::make_pair(avxdid, rgate)] = new TH2F(Form("PXDGatedModeMapCutADCHER_%d_", rgate) + bufful,
84  Form("PXDGatedModeMapCutADCHER %d ", rgate) + buff + ";U;V", 25, 0, 250, 192, 0, 768);
85  }
86  hGatedModeProjLER[avxdid] = new TH2F("PXDGatedModeProjLER_" + bufful,
87  "PXDGatedModeProjLER " + buff + ";Gate;V", 96, 0, 96, 192, 0, 768);
88  hGatedModeProjHER[avxdid] = new TH2F("PXDGatedModeProjHER_" + bufful,
89  "PXDGatedModeProjHER " + buff + ";Gate;V", 96, 0, 96, 192, 0, 768);
90 
91  hGatedModeMapSubLER[avxdid] = new TH2F("PXDGatedModeMapSubLER_" + bufful,
92  "PXDGatedModeMapSubLER " + buff + ";U;V-G", 25, 0, 250, 192, 0, 768);
93  hGatedModeMapSubHER[avxdid] = new TH2F("PXDGatedModeMapSubHER_" + bufful,
94  "PXDGatedModeMapSubHER " + buff + ";U;V-G", 25, 0, 250, 192, 0, 768);
95  hGatedModeMapAddLER[avxdid] = new TH2F("PXDGatedModeMapAddLER_" + bufful,
96  "PXDGatedModeMapAddLER " + buff + ";U;V+G", 25, 0, 250, 192, 0, 768);
97  hGatedModeMapAddHER[avxdid] = new TH2F("PXDGatedModeMapAddHER_" + bufful,
98  "PXDGatedModeMapAddHER " + buff + ";U;V+G", 25, 0, 250, 192, 0, 768);
99 
100  hGatedModeProjADCLER[avxdid] = new TH2F("PXDGatedModeProjADCLER_" + bufful,
101  "PXDGatedModeProjADCLER " + buff + ";Gate;V", 96, 0, 96, 192, 0, 768);
102  hGatedModeProjADCHER[avxdid] = new TH2F("PXDGatedModeProjADCHER_" + bufful,
103  "PXDGatedModeProjADCHER " + buff + ";Gate;V", 96, 0, 96, 192, 0, 768);
104 
105  hGatedModeMapSubADCLER[avxdid] = new TH2F("PXDGatedModeMapSubADCLER_" + bufful,
106  "PXDGatedModeMapSubADCLER " + buff + ";U;V-G", 25, 0, 250, 192, 0, 768);
107  hGatedModeMapSubADCHER[avxdid] = new TH2F("PXDGatedModeMapSubADCHER_" + bufful,
108  "PXDGatedModeMapSubADCHER " + buff + ";U;V-G", 25, 0, 250, 192, 0, 768);
109  hGatedModeMapAddADCLER[avxdid] = new TH2F("PXDGatedModeMapAddADCLER_" + bufful,
110  "PXDGatedModeMapAddADCLER " + buff + ";U;V+G", 25, 0, 250, 192, 0, 768);
111  hGatedModeMapAddADCHER[avxdid] = new TH2F("PXDGatedModeMapAddADCHER_" + bufful,
112  "PXDGatedModeMapAddADCHER " + buff + ";U;V+G", 25, 0, 250, 192, 0, 768);
113 
114  }
115  // cd back to root directory
116  oldDir->cd();
117 }
118 
119 void PXDGatedModeDQMModule::initialize()
120 {
121  REG_HISTOGRAM
122  m_rawTTD.isOptional();
123  m_storeRawHits.isRequired(m_PXDRawHitsName);
124 }
125 
126 void PXDGatedModeDQMModule::beginRun()
127 {
128  // reset all histograms
129  hBunchInjHER->Reset();
130  hBunchInjLER->Reset();
131  hBunchTrg->Reset();
132 
133  for (auto& it : hGatedModeMapLER) if (it.second) it.second->Reset();
134  for (auto& it : hGatedModeMapHER) if (it.second) it.second->Reset();
135  for (auto& it : hGatedModeMapCutLER) if (it.second) it.second->Reset();
136  for (auto& it : hGatedModeMapCutHER) if (it.second) it.second->Reset();
137  for (auto& it : hGatedModeMapADCLER) if (it.second) it.second->Reset();
138  for (auto& it : hGatedModeMapADCHER) if (it.second) it.second->Reset();
139  for (auto& it : hGatedModeMapCutADCLER) if (it.second) it.second->Reset();
140  for (auto& it : hGatedModeMapCutADCHER) if (it.second) it.second->Reset();
141 
142  for (auto& it : hGatedModeProjLER) if (it.second) it.second->Reset();
143  for (auto& it : hGatedModeProjHER) if (it.second) it.second->Reset();
144  for (auto& it : hGatedModeMapSubLER) if (it.second) it.second->Reset();
145  for (auto& it : hGatedModeMapSubHER) if (it.second) it.second->Reset();
146  for (auto& it : hGatedModeMapAddLER) if (it.second) it.second->Reset();
147  for (auto& it : hGatedModeMapAddHER) if (it.second) it.second->Reset();
148  for (auto& it : hGatedModeProjADCLER) if (it.second) it.second->Reset();
149  for (auto& it : hGatedModeProjADCHER) if (it.second) it.second->Reset();
150  for (auto& it : hGatedModeMapSubADCLER) if (it.second) it.second->Reset();
151  for (auto& it : hGatedModeMapSubADCHER) if (it.second) it.second->Reset();
152  for (auto& it : hGatedModeMapAddADCLER) if (it.second) it.second->Reset();
153  for (auto& it : hGatedModeMapAddADCHER) if (it.second) it.second->Reset();
154 }
155 
156 void PXDGatedModeDQMModule::event()
157 {
158 
159  for (auto& it : m_rawTTD) {
160  B2DEBUG(29, "TTD FTSW : " << hex << it.GetTTUtime(0) << " " << it.GetTTCtime(0) << " EvtNr " << it.GetEveNo(0) << " Type " <<
161  (it.GetTTCtimeTRGType(0) & 0xF) << " TimeSincePrev " << it.GetTimeSincePrevTrigger(0) << " TimeSinceInj " <<
162  it.GetTimeSinceLastInjection(0) << " IsHER " << it.GetIsHER(0) << " Bunch " << it.GetBunchNumber(0));
163 
164  // get last injection time
165  auto difference = it.GetTimeSinceLastInjection(0);
166  // check time overflow, too long ago
167  if (difference != 0x7FFFFFFF) {
168  auto isher = it.GetIsHER(0);
169  float diff2 = difference / (508.877 / 4.); // 127MHz clock ticks to us, inexact rounding
170  int bunch_trg = it.GetBunchNumber(0);
171  int time_inj = it.GetTimeSinceLastInjection(0);
172  int bunch_inj = (bunch_trg - time_inj) % 1280;
173  if (bunch_inj < 0) bunch_inj += 1280;
174  int rgate = bunch_inj / (1280. / 96.); // 0-96 ?
175  if ((isher && diff2 >= m_minTimeCutHER && diff2 <= m_maxTimeCutHER) ||
176  (!isher && diff2 >= m_minTimeCutLER && diff2 <= m_maxTimeCutLER)
177  ) { // be sure that we fill only in gating region
178  hBunchTrg->Fill(it.GetBunchNumber(0) & 0x7FF);
179  if (isher) hBunchInjHER->Fill(bunch_inj);
180  else hBunchInjLER->Fill(bunch_inj);
181  for (auto& p : m_storeRawHits) {
182  auto charge = p.getCharge();
183  if (charge > m_chargeCut) {
184  int v = int(p.getVCellID()) - rgate * 4;
185  if (v < 0) v += 768;
186  int v2 = int(p.getVCellID()) + rgate * 4;
187  if (v2 >= 768) v2 -= 768;
188  if (isher) {
189  auto h = hGatedModeMapHER[std::make_pair(p.getSensorID(), rgate)];
190  if (h) {
191  h->Fill(p.getUCellID(), p.getVCellID());
192  }
193  auto h2 = hGatedModeProjHER[p.getSensorID()];
194  if (h2) {
195  h2->Fill(rgate, p.getVCellID());
196  }
197  auto h3 = hGatedModeMapSubHER[p.getSensorID()];
198  if (h3) {
199  h3->Fill(p.getUCellID(), v);
200  }
201  auto h4 = hGatedModeMapAddHER[p.getSensorID()];
202  if (h4) {
203  h4->Fill(p.getUCellID(), v2);
204  }
205  auto h5 = hGatedModeMapADCHER[std::make_pair(p.getSensorID(), rgate)];
206  if (h5) {
207  h5->Fill(p.getUCellID(), p.getVCellID(), p.getCharge());
208  }
209  auto h6 = hGatedModeProjADCHER[p.getSensorID()];
210  if (h6) {
211  h6->Fill(rgate, p.getVCellID(), p.getCharge());
212  }
213  auto h7 = hGatedModeMapSubADCHER[p.getSensorID()];
214  if (h7) {
215  h7->Fill(p.getUCellID(), v, p.getCharge());
216  }
217  auto h8 = hGatedModeMapAddADCHER[p.getSensorID()];
218  if (h8) {
219  h8->Fill(p.getUCellID(), v2, p.getCharge());
220  }
221  } else {
222  auto h = hGatedModeMapLER[std::make_pair(p.getSensorID(), rgate)];
223  if (h) {
224  h->Fill(p.getUCellID(), p.getVCellID());
225  }
226  auto h2 = hGatedModeProjLER[p.getSensorID()];
227  if (h2) {
228  h2->Fill(rgate, p.getVCellID());
229  }
230  auto h3 = hGatedModeMapSubLER[p.getSensorID()];
231  if (h3) {
232  h3->Fill(p.getUCellID(), v);
233  }
234  auto h4 = hGatedModeMapAddLER[p.getSensorID()];
235  if (h4) {
236  h4->Fill(p.getUCellID(), v2);
237  }
238  auto h5 = hGatedModeMapADCLER[std::make_pair(p.getSensorID(), rgate)];
239  if (h5) {
240  h5->Fill(p.getUCellID(), p.getVCellID(), p.getCharge());
241  }
242  auto h6 = hGatedModeProjADCLER[p.getSensorID()];
243  if (h6) {
244  h6->Fill(rgate, p.getVCellID(), p.getCharge());
245  }
246  auto h7 = hGatedModeMapSubADCLER[p.getSensorID()];
247  if (h7) {
248  h7->Fill(p.getUCellID(), v, p.getCharge());
249  }
250  auto h8 = hGatedModeMapAddADCLER[p.getSensorID()];
251  if (h8) {
252  h8->Fill(p.getUCellID(), v2, p.getCharge());
253  }
254  }
255  }
256  if (m_chargeCutHigh > 30) {
257 
258  if (isher) {
259  auto h = hGatedModeMapCutHER[std::make_pair(p.getSensorID(), rgate)];
260  if (h) {
261  h->Fill(p.getUCellID(), p.getVCellID());
262  }
263  auto h2 = hGatedModeMapCutADCHER[std::make_pair(p.getSensorID(), rgate)];
264  if (h2) {
265  h2->Fill(p.getUCellID(), p.getVCellID(), p.getCharge());
266  }
267  } else {
268  auto h = hGatedModeMapCutLER[std::make_pair(p.getSensorID(), rgate)];
269  if (h) {
270  h->Fill(p.getUCellID(), p.getVCellID());
271  }
272  auto h2 = hGatedModeMapCutADCLER[std::make_pair(p.getSensorID(), rgate)];
273  if (h2) {
274  h2->Fill(p.getUCellID(), p.getVCellID(), p.getCharge());
275  }
276  }
277  }
278  }
279  } else if (diff2 > m_outsideTimeCut) {
280  rgate = 96;
281  for (auto& p : m_storeRawHits) {
282  if (isher) {
283  auto h = hGatedModeMapHER[std::make_pair(p.getSensorID(), rgate)];
284  if (h) {
285  h->Fill(p.getUCellID(), p.getVCellID());
286  }
287  auto h2 = hGatedModeMapADCHER[std::make_pair(p.getSensorID(), rgate)];
288  if (h2) {
289  h2->Fill(p.getUCellID(), p.getVCellID(), p.getCharge());
290  }
291  } else {
292  auto h = hGatedModeMapLER[std::make_pair(p.getSensorID(), rgate)];
293  if (h) {
294  h->Fill(p.getUCellID(), p.getVCellID());
295  }
296  auto h2 = hGatedModeMapADCLER[std::make_pair(p.getSensorID(), rgate)];
297  if (h2) {
298  h2->Fill(p.getUCellID(), p.getVCellID(), p.getCharge());
299  }
300  }
301  }
302  }
303  }
304  break;
305  }
306 }
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::VXD::SensorInfoBase
Base class to provide Sensor Information for PXD and SVD.
Definition: SensorInfoBase.h:40
Belle2::PXD::PXDGatedModeDQMModule
The PXD for GatedMode DQM module.
Definition: PXDGatedModeDQMModule.h:46
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
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXD::GeoCache
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:41
Belle2::HistoModule
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29