Belle II Software  release-06-02-00
cdcDQM7.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 "cdc/modules/cdcDQM/cdcDQM7.h"
10 
11 #include <framework/core/HistoModule.h>
12 
13 // framework aux
14 #include <framework/gearbox/Unit.h>
15 #include <framework/gearbox/Const.h>
16 #include <framework/logging/Logger.h>
17 
18 #include <TDirectory.h>
19 
20 using namespace std;
21 using namespace Belle2;
22 
23 //-----------------------------------------------------------------
24 // Register the Module
25 //-----------------------------------------------------------------
26 REG_MODULE(cdcDQM7)
27 
28 //-----------------------------------------------------------------
29 // Implementation
30 //-----------------------------------------------------------------
31 
33 {
34  //Set module properties
35  setDescription("CDC DQM module");
36  setPropertyFlags(c_ParallelProcessingCertified);
37 }
38 
39 cdcDQM7Module::~cdcDQM7Module()
40 {
41 }
42 
43 //------------------------------------------------------------------
44 // Function to define histograms
45 //-----------------------------------------------------------------
46 
47 TH1D* h_nhits_L[56] = {0}; // hit in each layer
48 
49 TH1D* h_tdc_sL[9] = {0}; // tdc each super layer
50 TH1D* h_adc_sL[9] = {0}; // adc each super layer
51 
52 TH1D* h_fast_tdc; // fastest TDC in each event
53 TH1D* h_board_out_tdc; // out of range TDC
54 TH2D* bmap_2; // board(copper-finess) status map 2D
55 
56 // add 20190205
57 TH1D* h_occ; // occupancy
58 TH1D* h_occ_L[56]; // occupancy layer dependent
59 TH1D* h_hit_cell; // hit vs cell id
60 
61 TH1D* h_EoccAfterInjLER; /*<nhits after LER injection>*/
62 TH1D* h_EoccAfterInjHER; /*<nhits after HER injection>*/
63 TH1D* h_occAfterInjLER; /*<occupancy after LER injection>*/
64 TH1D* h_occAfterInjHER; /*<occupancy after HER injection>*/
65 
66 
67 void cdcDQM7Module::defineHisto()
68 {
69 
70  TDirectory* oldDir = gDirectory;
71  TDirectory* dirDAQ = oldDir->mkdir("CDC");
72 
73  dirDAQ->cd();
74 
75  int bmin = 0;
76  int bmax;
77  int ndiv[9] = {160, 160, 192, 224, 256, 288, 320, 352, 384};
78 
79  for (int b = 0; b < 56; b++) {
80 
81  if (b < 8) {
82  bmax = ndiv[0];
83  } else if (b < 14) {
84  bmax = ndiv[1];
85  } else if (b < 20) {
86  bmax = ndiv[2];
87  } else if (b < 26) {
88  bmax = ndiv[3];
89  } else if (b < 32) {
90  bmax = ndiv[4];
91  } else if (b < 38) {
92  bmax = ndiv[5];
93  } else if (b < 44) {
94  bmax = ndiv[6];
95  } else if (b < 50) {
96  bmax = ndiv[7];
97  } else {
98  bmax = ndiv[8];
99  }
100 
101  // nhits_L
102  h_nhits_L[b] = new TH1D(Form("nhits_L%d", b), Form("nhits Layer %d", b), bmax - bmin, bmin, bmax);
103  h_nhits_L[b]->SetMinimum(0);
104  h_nhits_L[b]->SetFillColor(7);
105 
106  h_occ_L[b] = new TH1D(Form("h_occ_L%d", b), "occ. each layer", 100, 0, 1); //
107  h_occ_L[b]->SetFillColor(96);
108  h_occ_L[b]->SetMinimum(0);
109  h_occ_L[b]->SetStats(0);
110 
111  }
112 
113  for (int s = 0; s < 9; s++) {
114  h_tdc_sL[s] = new TH1D(Form("tdc_sL%d", s), Form("tdc sLayer %d", s), 250, 4200, 5200);
115  h_tdc_sL[s]->SetMinimum(0);
116  h_tdc_sL[s]->SetFillColor(6);
117 
118  h_adc_sL[s] = new TH1D(Form("adc_sL%d", s), Form("adc sLayer %d", s), 100, 0, 500);
119  h_adc_sL[s]->SetMinimum(0);
120  h_adc_sL[s]->SetFillColor(8);
121  }
122 
123  h_fast_tdc = new TH1D("fast_tdc", "fastest TDC", 50, 4800, 5000);
124  h_fast_tdc->SetFillColor(6);
125 
126  h_board_out_tdc = new TH1D("h_board_out_tdc", "out of range TDC", 300, 0, 300);
127  h_board_out_tdc->SetFillColor(95);
128 
129  // 20190205
130  h_occ = new TH1D("occ", "occ. total", 100, 0, 1.);
131  h_occ->SetFillColor(95);
132 
133  // 20191108
134  h_hit_cell = new TH1D("h_hit_cell", "Hit of each cell", 14336, 0, 14335);
135  h_hit_cell->SetFillColor(20);
136  //
137  bmap_2 = new TH2D("bmap_2", "", 75, 0, 75, 4, 0, 4);
138 
139  // LIVE
140  h_tdc_sL[6]->SetOption("LIVE");
141  h_tdc_sL[6]->SetOption("hist");
142 
143  h_board_out_tdc->SetOption("LIVE");
144  h_board_out_tdc->SetOption("hist");
145 
146  // set
147  h_fast_tdc->SetStats(1);
148  bmap_2->SetOption("zcol"); //
149  bmap_2->SetStats(0);
150 
151  h_EoccAfterInjLER = new TH1D("EoccAfterInjLer", "Eocc after LER injection", 4000, 0, 20000);
152  h_EoccAfterInjLER->SetMinimum(0);
153  h_EoccAfterInjLER->SetFillColor(7);
154 
155  h_EoccAfterInjHER = new TH1D("EoccAfterInjHer", "Eocc after HER injection", 4000, 0, 20000);
156  h_EoccAfterInjHER->SetMinimum(0);
157  h_EoccAfterInjHER->SetFillColor(7);
158 
159  h_occAfterInjLER = new TH1D("occAfterInjLer", "occupancy after LER injection", 4000, 0, 20000);
160  h_occAfterInjLER->SetMinimum(0);
161  h_occAfterInjLER->SetFillColor(7);
162 
163  h_occAfterInjHER = new TH1D("occAfterInjHer", "occupancy after HER injection", 4000, 0, 20000);
164  h_occAfterInjHER->SetMinimum(0);
165  h_occAfterInjHER->SetFillColor(7);
166 
167  oldDir->cd();//
168 
169 }
170 
171 void cdcDQM7Module::initialize()
172 {
173  REG_HISTOGRAM // required to register histograms to HistoManager
174  // register dataobjects
175  m_rawFTSW.isOptional();
176  m_CDCRawHits.isRequired();
177  m_CDCHits.isRequired();
178 }
179 
180 void cdcDQM7Module::beginRun()
181 {
182  for (int i = 0; i < 56; i++) {
183  h_nhits_L[i]->Reset();
184  h_occ_L[i]->Reset();
185 
186  }
187 
188  for (int j = 0; j < 9; j++) {
189  h_tdc_sL[j]->Reset();
190  h_adc_sL[j]->Reset();
191  }
192 
193  h_fast_tdc->Reset();
194  h_board_out_tdc->Reset();
195  bmap_2->Reset();
196  h_occ->Reset();
197  h_hit_cell->Reset();
198 
199  h_EoccAfterInjLER->Reset();
200  h_EoccAfterInjHER->Reset();
201  h_occAfterInjLER->Reset();
202  h_occAfterInjHER->Reset();
203 
204 }
205 
206 void cdcDQM7Module::event()
207 {
208  int nent = m_CDCHits.getEntries();
209  int ftdc = 0;
210 
211  // occ total
212  double occ_total = nent / 14336.;
213  h_occ->Fill(occ_total);
214 
215  // for layer dependent occupancy
216  int whits_L[56] = {}; // wire hits
217  double occ_L[56] = {}; // occupancy
218 
219  int ndiv[9] = {160, 160, 192, 224, 256, 288, 320, 352, 384};
220 
221  for (int i = 0; i < nent; i++) {
222  CDCHit* cdchit = static_cast<CDCHit*>(m_CDCHits[i]);
223 
224  int sL = cdchit->getISuperLayer();
225  int iL = cdchit->getILayer();
226  int wid = cdchit->getIWire();
227  int adcsum = cdchit->getADCCount();
228  int vtdc = cdchit->getTDCCount();
229 
230  if (sL > 8) continue; // error
231  if (iL > 8) continue; // error
232 
233  int num = sL * 6 + iL + 2;
234  if (num > 55) continue; // error
235 
236  // wire hits
237  if (sL == 0) {
238  whits_L[iL]++;
239  } else {
240  whits_L[num]++;
241  }
242 
243  if (adcsum > -1) {
244 
245  if (sL == 0) {
246  h_nhits_L[iL]->Fill(wid);
247  } else {
248  h_nhits_L[num]->Fill(wid);
249  }
250 
251  //
252  if (vtdc > ftdc && adcsum > 20) {
253  ftdc = vtdc;
254  }// fastest
255 
256  }// adc
257 
258  // add by J.H. Yin
259  if (adcsum > 25) {
260  int cid(0);
261  if (sL == 0) {
262  cid = iL * ndiv[sL] + wid;
263  } else {
264  for (int isl = 0; isl < sL; isl ++) {
265  cid += 6 * ndiv[isl];
266  }
267  cid += 2 * ndiv[0] + iL * ndiv[sL] + wid;
268  }
269  h_hit_cell -> Fill(cid);
270  }
271  }// cdchit
272 
273  h_fast_tdc->Fill(ftdc);
274 
275  // each layer
276  for (int b = 0; b < 56; b++) {
277  int n_wire = 0;
278  if (b < 8) {
279  n_wire = ndiv[0];
280  } else if (b < 14) {
281  n_wire = ndiv[1];
282  } else if (b < 20) {
283  n_wire = ndiv[2];
284  } else if (b < 26) {
285  n_wire = ndiv[3];
286  } else if (b < 32) {
287  n_wire = ndiv[4];
288  } else if (b < 38) {
289  n_wire = ndiv[5];
290  } else if (b < 44) {
291  n_wire = ndiv[6];
292  } else if (b < 50) {
293  n_wire = ndiv[7];
294  } else {
295  n_wire = ndiv[8];
296  }
297 
298  // cal. occupancy
299  occ_L[b] = (double)whits_L[b] / n_wire;
300  h_occ_L[b]->Fill(occ_L[b]);
301  }
302 
303 
304  //
305  int r_nent = m_CDCRawHits.getEntries();
306 
307  // new
308  for (int j = 0; j < r_nent; j++) {
309  CDCRawHit* cdcrawhit = static_cast<CDCRawHit*>(m_CDCRawHits[j]);
310 
311  int brd = cdcrawhit->getBoardId();
312  int v_adc = cdcrawhit->getFADC();
313  int v_tdc = cdcrawhit->getTDC();
314  int n_tot = cdcrawhit->getTOT();
315  int n_node = cdcrawhit->getNode();
316  int n_fns = cdcrawhit->getFiness();
317 
318  bmap_2->Fill(n_node, n_fns);
319 
320  if (v_tdc > 5200 || v_tdc < 4200) {
321  h_board_out_tdc->Fill(brd);
322  }
323 
324  // printf("%d, %d:\n", j, board);
325  if (brd > 299) continue;
326  if (n_tot < 4) continue;
327  if (v_adc < 35) continue;
328 
329  // each sL
330  if (brd < 28) {
331  h_tdc_sL[0]->Fill(v_tdc);
332  h_adc_sL[0]->Fill(v_adc);
333  } else if (brd < 48) {
334  h_tdc_sL[1]->Fill(v_tdc);
335  h_adc_sL[1]->Fill(v_adc);
336  } else if (brd < 72) {
337  h_tdc_sL[2]->Fill(v_tdc);
338  h_adc_sL[2]->Fill(v_adc);
339  } else if (brd < 100) {
340  h_tdc_sL[3]->Fill(v_tdc);
341  h_adc_sL[3]->Fill(v_adc);
342  } else if (brd < 132) {
343  h_tdc_sL[4]->Fill(v_tdc);
344  h_adc_sL[4]->Fill(v_adc);
345  } else if (brd < 168) {
346  h_tdc_sL[5]->Fill(v_tdc);
347  h_adc_sL[5]->Fill(v_adc);
348  } else if (brd < 208) {
349  h_tdc_sL[6]->Fill(v_tdc);
350  h_adc_sL[6]->Fill(v_adc);
351  } else if (brd < 252) {
352  h_tdc_sL[7]->Fill(v_tdc);
353  h_adc_sL[7]->Fill(v_adc);
354  } else {
355  h_tdc_sL[8]->Fill(v_tdc);
356  h_adc_sL[8]->Fill(v_adc);
357  }
358 
359 
360  }// cdcrawhits
361 
362  for (auto& it : m_rawFTSW) {
363  B2DEBUG(29, "TTD FTSW : " << hex << it.GetTTUtime(0) << " " << it.GetTTCtime(0) << " EvtNr " << it.GetEveNo(0) << " Type " <<
364  (it.GetTTCtimeTRGType(0) & 0xF) << " TimeSincePrev " << it.GetTimeSincePrevTrigger(0) << " TimeSinceInj " <<
365  it.GetTimeSinceLastInjection(0) << " IsHER " << it.GetIsHER(0) << " Bunch " << it.GetBunchNumber(0));
366  auto difference = it.GetTimeSinceLastInjection(0);
367  if (difference != 0x7FFFFFFF) {
368  //unsigned int nentries = m_digits.getEntries();
369  float diff2 = difference / 127.; // 127MHz clock ticks to us, inexact rounding
370  if (it.GetIsHER(0)) {
371  h_occAfterInjHER->Fill(diff2, occ_total);
372  h_EoccAfterInjHER->Fill(diff2);
373  } else {
374  h_occAfterInjLER->Fill(diff2, occ_total);
375  h_EoccAfterInjLER->Fill(diff2);
376  }
377  }
378  }
379 
380 
381 
382 
383 }
384 
385 
386 void cdcDQM7Module::endRun()
387 {
388  //
389 }
390 
391 
392 void cdcDQM7Module::terminate()
393 {
394  //
395 }
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
unsigned short getIWire() const
Getter for iWire.
Definition: CDCHit.h:166
short getTDCCount() const
Getter for TDC count.
Definition: CDCHit.h:219
unsigned short getADCCount() const
Getter for integrated charge.
Definition: CDCHit.h:230
unsigned short getISuperLayer() const
Getter for iSuperLayer.
Definition: CDCHit.h:184
unsigned short getILayer() const
Getter for iLayer.
Definition: CDCHit.h:172
The CDCRawHit (suppressed mode) class.
Definition: CDCRawHit.h:25
unsigned short getTOT(void) const
Getter for TOT value.
Definition: CDCRawHit.h:116
unsigned short getBoardId(void) const
Getter for boar ID.
Definition: CDCRawHit.h:92
unsigned short getTDC(void) const
Getter for TDC value.
Definition: CDCRawHit.h:108
unsigned short getNode(void) const
Getter for Node ID.
Definition: CDCRawHit.h:59
unsigned short getFiness(void) const
Getter fot Finess ID.
Definition: CDCRawHit.h:68
unsigned short getFADC(void) const
Getter for FADC value.
Definition: CDCRawHit.h:100
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
The module for Data Quality Monitor.
Definition: cdcDQM7.h:33
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.