Belle II Software  release-08-01-09
TRGECLEventTimingDQMModule.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 <trg/ecl/modules/trgeclDQM/TRGECLEventTimingDQMModule.h>
10 #include <framework/core/HistoModule.h>
11 #include <framework/datastore/StoreArray.h>
12 #include <iostream>
13 #include <string>
14 using namespace Belle2;
15 
16 REG_MODULE(TRGECLEventTimingDQM);
17 
18 
20 {
22  setDescription("ECL trigger event timing histograms");
23  trgecl_map = new TrgEclMapping();
24 }
25 
26 
28 {
29  delete trgecl_map;
30 }
31 
33 {
34 
35  TDirectory* oldDir = gDirectory;
36  oldDir->mkdir("TRGECLEventTiming")->cd();
37 
38  m_histMaxTCE =
39  new TH1F("h_MaxTCE",
40  "[TRGECL] Most Energetic TC Energy ; max TC Energy (ADC) ; Entries / 10 ADC",
41  140, 0, 1400);
43  new TH1F("h_MaxTCId",
44  "[TRGECL] Most Energetic TC ID ; max TC ID ; Entries",
45  578, 0, 578);
47  new TH1F("h_MaxTCThetaId",
48  "[TRGECL] Most Energetic TC Theta ID ; max TC #theta ID ; Entries",
49  19, 0, 19);
51  new TH1F("h_EventTimingQuality",
52  "[TRGECL] Event timing quality ; Event timing quality ; Entries",
53  4, 0, 4);
55  new TH1F("h_EventT0Coarse",
56  "[TRGECL] EventT0 with coarse event timing ; EventT0 (ns) ; Entries / 2 ns",
57  150, -150, 150);
59  new TH1F("h_EventT0Fine",
60  "[TRGECL] EventT0 with fine event timing ; EventT0 (ns) ; Entries / 2 ns",
61  150, -150, 150);
62 
63  // set label for h_EventTimingQuality
64  m_histEventTimingQuality->GetXaxis()->SetBinLabel(1, "None");
65  m_histEventTimingQuality->GetXaxis()->SetBinLabel(2, "Coarse");
66  m_histEventTimingQuality->GetXaxis()->SetBinLabel(3, "Fine");
67  m_histEventTimingQuality->GetXaxis()->SetBinLabel(4, "Super fine");
68 
69  // EventT0 histograms for different TC energy region
70  int nBins;
71  double minT0;
72  double maxT0;
73  for (int energyBin = 0; energyBin < NBinEventT0; energyBin++) {
74 
75  if (energyBin <= 1) {
76  nBins = 200;
77  minT0 = -200;
78  maxT0 = 200;
79  } else if (energyBin <= 5) {
80  nBins = 100;
81  minT0 = -100;
82  maxT0 = 100;
83  } else {
84  nBins = 50;
85  minT0 = -50;
86  maxT0 = 50;
87  }
88 
89  // set TC energy(ADC) ranges for each histogram
90  std::stringstream ss1, ss2;
91  ss1 << std::setfill('0') << std::setw(3) << std::to_string(10 + 20 * energyBin);
92  ss2 << std::setfill('0') << std::setw(3) << std::to_string(10 + 20 * (energyBin + 1));
93  TString ECUT1 = ss1.str() + "to" + ss2.str();
94  TString ECUT2 = ss1.str() + "-" + ss2.str();
95 
96  // EventT0
97  m_histEventT0[energyBin] =
98  new TH1F("h_EventT0_MaxTCE_" + ECUT1 + "",
99  "[TRGECL] EventT0 MaxTCE (" + ECUT2 + " ADC) ; EventT0 (ns); Entries / 2 ns",
100  nBins, minT0, maxT0);
101  }
102  oldDir->cd();
103 }
104 
106 {
107  m_eventT0.isOptional();
108  REG_HISTOGRAM
109 }
110 
112 {
113 
114  if (!m_eventT0.isValid()) {
115  B2DEBUG(20, "No EventT0 is found.");
116  return;
117  }
118 
119  if (!m_objTrgSummary.isValid()) {
120  B2DEBUG(20, "No TRGSummary is found.");
121  return;
122  }
123 
124  m_histMaxTCE->Reset();
125  m_histMaxTCId->Reset();
126  m_histMaxTCThetaId->Reset();
127  m_histEventTimingQuality->Reset();
128  m_histEventT0Coarse->Reset();
129  m_histEventT0Fine->Reset();
130 
131  for (int energyBin = 0; energyBin < NBinEventT0; energyBin++) {
132  m_histEventT0[energyBin]->Reset();
133  }
134 
135 }
136 
138 {
139 
140  // check TRGSummary object
141  if (!m_objTrgSummary.isValid()) {
142  B2DEBUG(20, "TRGSummary object not available");
143  return;
144  }
148  int m_L1TimingSrc = m_objTrgSummary->getTimType();
149  // accept only event that L1 timing is from ECL trigger
150  if (m_L1TimingSrc != 0) {
151  B2DEBUG(20, "This event is not deternied by ECL trigger.");
152  return ;
153  }
154 
155  // Skip this event if there is no EventT0, to avoid crashing other DQM
156  if (!m_eventT0.isOptional()) {
157  B2DEBUG(20, "No EventT0 is found.");
158  return;
159  }
160 
161  // Determine if there is a valid EventT0 to use and then extract the information about it
162  if (!m_eventT0.isValid()) {
163  B2DEBUG(20, "No valid EventT0 is found.");
164  return ;
165  }
166 
167  // get event timing window of ecl trigger
168  int evt_win = -1000;
169  int evt_time_win = -1000;
171  evt_win = iii.getEvtWin();
172  evt_time_win = iii.getEvtTimeWin();
173  }
174  int flag_win_a = -1;
175  int flag_win_b = -1;
176  if (evt_win == 3) {
177  if (evt_time_win == -1) {
178  flag_win_a = 2;
179  flag_win_b = 3;
180  } else {
181  flag_win_a = 3;
182  flag_win_b = 4;
183  }
184  } else if (evt_win == 4) {
185  if (evt_time_win == -1) {
186  flag_win_a = 3;
187  flag_win_b = 4;
188  } else {
189  flag_win_a = 4;
190  flag_win_b = 5;
191  }
192  } else {
193  B2DEBUG(20, "L1 timing is out of ETM hit window");
194  return;
195  }
196 
197  // TC information
198  int MaxTCEnergy = 0;
199  int MaxTCId = -1000;
200  int MaxTCThetaId = 0;
201  for (const TRGECLUnpackerStore& iii : m_trgeclUnpackerStores) {
202  // L1 window selection
203  int hit_win = iii.getHitWin();
204  if (!(hit_win == flag_win_a ||
205  hit_win == flag_win_b)) { continue; }
206  int TCId = iii.getTCId();
207  int TCEnergy = iii.getTCEnergy();
208  if (TCId < 1 || TCId > 576 || TCEnergy == 0) { continue; }
209  // select most energetic TC
210  if (TCEnergy > MaxTCEnergy) {
211  MaxTCEnergy = TCEnergy;
212  MaxTCId = TCId;
213  MaxTCThetaId = trgecl_map->getTCThetaIdFromTCId(TCId);
214  }
215  }
216  if (MaxTCId == -1000) {
217  B2DEBUG(20, "No max TC is found.");
218  return;
219  }
220  m_histMaxTCE->Fill(MaxTCEnergy);
221  m_histMaxTCId->Fill(MaxTCId);
222  m_histMaxTCThetaId->Fill(MaxTCThetaId);
223 
224  // Event timing quality from TRGSummary
225  // 0=none, 1=coarse, 2=fine, 3=super fine
226  int gdlTimQuality = m_objTrgSummary->getTimQuality();
227  m_histEventTimingQuality->Fill(gdlTimQuality);
228 
229  // get EventT0
230  const double eventT0 =
231  m_eventT0->hasEventT0() ?
232  m_eventT0->getEventT0() : -1000;
233 
234  // EventT0 with coarse or fine event timing
235  if (gdlTimQuality == 1) {
236  // coarse
237  m_histEventT0Coarse->Fill(eventT0);
238  } else if (gdlTimQuality >= 2) {
239  // fine or super fine
240  m_histEventT0Fine->Fill(eventT0);
241  }
242 
243  // set TC energy region for EventT0
244  bool IsMaxTCEnergy[NBinEventT0] = {false};
245  int EnergyBinWidth = 20;
246  for (int idx = 0; idx < NBinEventT0; idx++) {
247  if (MaxTCEnergy >= 10 + EnergyBinWidth * idx &&
248  MaxTCEnergy <= 10 + EnergyBinWidth * (idx + 1)) {
249  IsMaxTCEnergy[idx] = true;
250  }
251  }
252 
253  // fill EventT0 for different TC energy region
254  for (int binADC = 0 ; binADC < NBinEventT0; binADC++) {
255  if (IsMaxTCEnergy[binADC] == true) {
256  m_histEventT0[binADC]->Fill(eventT0);
257  }
258  }
259 
260 }
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
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
StoreObjPtr< EventT0 > m_eventT0
EventT0 data object.
TH1F * m_histEventTimingQuality
Event Timing Quality from TRGSummary.
virtual void initialize() override
Initialize the module.
static const int NBinEventT0
The number of EventT0 histogram for different max TC E region.
virtual void event() override
This method is called for each event.
StoreArray< TRGECLUnpackerStore > m_trgeclUnpackerStores
Trg ECL UnpakcerStore.
TH1F * m_histEventT0Coarse
EventT0 with coarse event timing.
TrgEclMapping * trgecl_map
ecl trigger map
StoreObjPtr< TRGSummary > m_objTrgSummary
Trigger Summary data object.
virtual void beginRun() override
This method is called for each run.
TH1F * m_histEventT0Fine
EventT0 with fine event timing.
StoreArray< TRGECLUnpackerEvtStore > m_trgeclUnpackerEvtStores
Trg ECL UnpakcerEvtStore.
TH1F * m_histEventT0[NBinEventT0]
EventT0 for different max TC E region.
virtual void defineHisto() override
Defination of histograms.
A class of TC Mapping.
Definition: TrgEclMapping.h:26
int getTCThetaIdFromTCId(int)
get [TC Theta ID] from [TC ID]
REG_MODULE(arichBtest)
Register the Module.
Abstract base class for different kinds of events.