Belle II Software  release-06-02-00
TRGECLDQMModule.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/TRGECLDQMModule.h>
10 #include <trg/ecl/TrgEclMapping.h>
11 #include <trg/ecl/TrgEclCluster.h>
12 #include <trg/ecl/TrgEclDataBase.h>
13 
14 #include <framework/datastore/StoreArray.h>
15 
16 #include <TDirectory.h>
17 
18 using namespace Belle2;
19 
20 REG_MODULE(TRGECLDQM);
21 
22 
24 {
25 
26 
27  setDescription("DQM for ECL Trigger system");
29 
30  TCId.clear();
31  TCEnergy.clear();
32  TCTiming.clear();
33  RevoFAM.clear();
34  RevoTrg.clear();
35  FineTiming.clear();
36 
37 }
38 
39 
41 {
42 
43 }
44 
45 
47 {
48  TDirectory* oldDir = gDirectory;
49  TDirectory* dirDQM = (TDirectory*)gDirectory->Get("TRG");
50  if (!dirDQM) {
51  dirDQM = oldDir->mkdir("TRG");
52  }
53  dirDQM->cd();
54 
55  h_TCId = new TH1D("h_TCId", "[TRGECL] Hit TC ID", 578, 0, 578);
56  h_TCthetaId = new TH1D("h_TCthetaId", "[TRGECL] Hit TC #theta ID", 19, 0, 19);
57  h_TCphiId_FWD = new TH1D("h_TCphiId_FWD", "[TRGECL] Hit TC #phi ID in FWD", 34, 0, 34);
58  h_TCphiId_BR = new TH1D("h_TCphiId_BR", "[TRGECL] Hit TC #phi ID in BR", 38, 0, 38);
59  h_TCphiId_BWD = new TH1D("h_TCphiId_BWD", "[TRGECL] Hit TC #phi ID in BWD", 34, 0, 34);
60  h_TotalEnergy = new TH1D("h_TotalEnergy", "[TRGECL] Total TC Energy (ADC)", 100, 0, 3000);
61  h_TCEnergy = new TH1D("h_TCEnergy", "[TRGECL] TC Energy (ADC)", 100, 0, 1500);
62  h_Narrow_TotalEnergy = new TH1D("h_Narrow_TotalEnergy", "[TRGECL] Total TC Energy (ADC)", 100, 0, 500);
63  h_Narrow_TCEnergy = new TH1D("h_Narrow_TCEnergy", "[TRGECL] TC Energy (ADC)", 100, 0, 100);
64  h_n_TChit_event = new TH1D("h_n_TChit_event", "[TRGECL] N(TC) ", 40, 0, 40);
65  h_Cluster = new TH1D("h_Cluster", "[TRGECL] N(Cluster) ", 20, 0, 20);
66  h_TCTiming = new TH1D("h_TCTiming", "[TRGECL] TC Timing (ns)", 100, 3010, 3210);
67  h_TRGTiming = new TH1D("h_TRGTiming", "[TRGECL] TRG Timing (ns)", 100, 3010, 3210);
68  h_Cal_TCTiming = new TH1D("h_Cal_TCTiming", "[TRGECL] Cal TC Timing (ns)", 100, -400, 400);
69  h_Cal_TRGTiming = new TH1D("h_Cal_TRGTiming", "[TRGECL] TRG Timing (ns)", 100, -400, 400);
70  h_ECL_TriggerBit = new TH1D("h_ECL_TriggerBit", "[TRGECL] ECL Trigger Bit", 29, 0, 29);
71  h_Cluster_Energy_Sum = new TH1D("h_Cluster_Energy_Sum", "[TRGECL] Energy Sum of 2 Clusters (ADC)", 300, 0, 3000);
72 
73 
74 
75  const char* label[44] = {"Hit", "Timing Source(FWD)", "Timing Source(BR)", "Timing Source(BWD)", "physics Trigger", "2D Bhabha Veto", "3D Bhabha veto", "3D Bhabha Selection", "E Low", "E High", "E LOM", "Cluster Overflow", "Low multi bit 0", "Low multi bit 1", "Low multi bit 2", "Low multi bit 3", "Low multi bit 4", "Low multi bit 5", "Low multi bit 6", "Low multi bit 7", "Low multi bit 8", "Low multi bit 9", "Low multi bit 10", "Low multi bit 11", "Low multi bit 12", "Low multi bit 13", "mumu bit", "prescale bit", "ECL burst bit" , "2D Bhabha bit 1", "2D Bhabha bit 2" , "2D Bhabha bit 3", "2D Bhabha bit 4", "2D Bhabha bit 5", "2D Bhabha bit 6", "2D Bhabha bit 7", "2D Bhabha bit 8", "2D Bhabha bit 9", "2D Bhabha bit 10", "2D Bhabha bit 11", "2D Bhabha bit 12", "2D Bhabha bit 13", "2D Bhabha bit 14"};
76 
77 
78  for (int j = 0; j < 29; j++) {
79  h_ECL_TriggerBit->GetXaxis()-> SetBinLabel(j + 1, label[j]);
80  }
81  h_ECL_TriggerBit->SetStats(0);
82 
83  oldDir->cd();
84 }
85 
86 
88 {
89 
90  // calls back the defineHisto() function, but the HistoManager module has to be in the path
91  REG_HISTOGRAM
92 
93  trgeclHitArray.registerInDataStore();
94  trgeclEvtArray.registerInDataStore();
95  trgeclCluster.registerInDataStore();
96  trgeclSumArray.registerInDataStore();
97 
98 }
99 
100 
102 {
103 }
104 
106 {
107  // delete h_TCId;
108 }
109 
111 {
112  TCId.clear();
113  TCEnergy.clear();
114  TCTiming.clear();
115  RevoFAM.clear();
116  RevoTrg.clear();
117  FineTiming.clear();
118 
119  // StoreArray<TRGECLUnpackerStore> trgeclHitArray;
120  /* cppcheck-suppress variableScope */
121  double HitTiming;
122  /* cppcheck-suppress variableScope */
123  double HitEnergy;
124  double HitRevoFam = 0;
125  double HitRevoTrg = 0;
126  double HitFineTiming = 0;
127  double HitRevoEvtTiming = 0;
128  double HitCalTiming = 0;
129  int CheckSum = 0;
130 
131  for (int iii = 0; iii < trgeclEvtArray.getEntries(); iii++) {
132  TRGECLUnpackerEvtStore* aTRGECLUnpackerEvtStore = trgeclEvtArray[iii];
133 
134  HitFineTiming = aTRGECLUnpackerEvtStore -> getEvtTime();
135  HitRevoTrg = aTRGECLUnpackerEvtStore -> getL1Revo();
136  HitRevoEvtTiming = aTRGECLUnpackerEvtStore -> getEvtRevo();
137  CheckSum = aTRGECLUnpackerEvtStore -> getEvtExist() ;
138 
139 
140  RevoTrg.push_back(HitRevoTrg);
141 
142 
143 
144  }
145  if (CheckSum == 0) {return;}
146 
147 
148 
149  for (int ii = 0; ii < trgeclHitArray.getEntries(); ii++) {
150  TRGECLUnpackerStore* aTRGECLUnpackerStore = trgeclHitArray[ii];
151  int TCID = (aTRGECLUnpackerStore->getTCId());
152  int hit_win = aTRGECLUnpackerStore -> getHitWin();
153  HitEnergy = aTRGECLUnpackerStore -> getTCEnergy();
154  HitTiming = aTRGECLUnpackerStore ->getTCTime();
155 
156  if (TCID < 1 || TCID > 576 || HitEnergy == 0) {continue;}
157  if (!(hit_win == 3 || hit_win == 4)) {continue;}
158  HitCalTiming = aTRGECLUnpackerStore ->getTCCALTime() ;
159  HitRevoFam = aTRGECLUnpackerStore-> getRevoFAM() ;
160 
161  TCId.push_back(TCID);
162  TCEnergy.push_back(HitEnergy);
163  TCTiming.push_back(HitTiming);
164  RevoFAM.push_back(HitRevoFam);
165  FineTiming.push_back(HitCalTiming);
166  }
167  //
168  //
169  if (TCId.size() == 0) {return;}
170 
171  /* cppcheck-suppress variableScope */
172  int phy;
173  /* cppcheck-suppress variableScope */
174  int b1;
175  /* cppcheck-suppress variableScope */
176  int b2v;
177  /* cppcheck-suppress variableScope */
178  int b2s;
179  /* cppcheck-suppress variableScope */
180  int mu;
181  /* cppcheck-suppress variableScope */
182  int pre;
183  /* cppcheck-suppress variableScope */
184  int clover;
185  /* cppcheck-suppress variableScope */
186  int tsource;
187  /* cppcheck-suppress variableScope */
188  int b1type;
189  /* cppcheck-suppress variableScope */
190  int etot;
191  /* cppcheck-suppress variableScope */
192  int vlm;
193  /* cppcheck-suppress variableScope */
194  int eclburst;
195  // int s_hit_win= 0;
196  std::vector<int> trgbit ;
197  trgbit.resize(44, 0);
198  for (int iii = 0; iii < trgeclSumArray.getEntries(); iii++) {
199  TRGECLUnpackerSumStore* aTRGECLUnpackerSumStore = trgeclSumArray[iii];
200 
201  tsource = aTRGECLUnpackerSumStore ->getTimeType();
202  phy = aTRGECLUnpackerSumStore ->getPhysics();
203  b1 = aTRGECLUnpackerSumStore ->get2DBhabha();
204  b1type = aTRGECLUnpackerSumStore -> getBhabhaType();
205  b2v = aTRGECLUnpackerSumStore -> get3DBhabhaV();
206  b2s = aTRGECLUnpackerSumStore -> get3DBhabhaS() ;
207  etot = aTRGECLUnpackerSumStore -> getEtotType();
208  clover = aTRGECLUnpackerSumStore -> getICNOver();
209  vlm = aTRGECLUnpackerSumStore -> getLowMulti();
210  mu = aTRGECLUnpackerSumStore -> getMumu();
211  pre = aTRGECLUnpackerSumStore -> getPrescale();
212  eclburst = aTRGECLUnpackerSumStore -> getECLBST();
213 
214  //
215  trgbit[0] = 1;
216  trgbit[1] = tsource & 0x1;
217  trgbit[2] = (tsource >> 1) & 0x1;
218  trgbit[3] = (tsource >> 2) & 0x1;
219  trgbit[4] = phy;
220  trgbit[5] = b1;
221  trgbit[6] = b2v;
222  trgbit[7] = b2s;
223  trgbit[8] = etot & 0x1;
224  trgbit[9] = (etot >> 1) & 0x1;
225  trgbit[10] = (etot >> 2) & 0x1;
226  trgbit[11] = clover;
227 
228  for (int j = 0; j < 14; j++) {
229  trgbit[12 + j] = (vlm >> j) & 0x1;
230  }
231 
232  trgbit[26] = mu;
233  trgbit[27] = pre;
234  trgbit[28] = eclburst;
235 
236  trgbit[29] = b1type & 0x1;
237  trgbit[30] = (b1type >> 1) & 0x1;
238  trgbit[31] = (b1type >> 2) & 0x1;
239  trgbit[32] = (b1type >> 3) & 0x1;
240  trgbit[33] = (b1type >> 4) & 0x1;
241  trgbit[34] = (b1type >> 5) & 0x1;
242  trgbit[35] = (b1type >> 6) & 0x1;
243  trgbit[36] = (b1type >> 7) & 0x1;
244  trgbit[37] = (b1type >> 8) & 0x1;
245  trgbit[38] = (b1type >> 9) & 0x1;
246  trgbit[39] = (b1type >> 10) & 0x1;
247  trgbit[40] = (b1type >> 11) & 0x1;
248  trgbit[41] = (b1type >> 12) & 0x1;
249  trgbit[42] = (b1type >> 13) & 0x1;
250  trgbit[43] = (b1type >> 14) & 0x1;
251 
252 
253  }
254 
255  for (int j = 0; j < 29; j++) {
256  if (trgbit[j] == 0x1) {h_ECL_TriggerBit->Fill(j, 1);}
257  }
258 
259 
260  //----------------------
261  //Clustering
262  //----------------------
263  //
264 
265  TrgEclCluster _TCCluster ;
266  _TCCluster.setICN(TCId, TCEnergy, TCTiming);
267 
268  int c = _TCCluster.getNofCluster();
269  h_Cluster->Fill(c);
270  std::vector<double> ClusterTiming;
271  std::vector<double> ClusterEnergy;
272  std::vector<int> MaxTCId;
273  ClusterTiming.clear();
274  ClusterEnergy.clear();
275  MaxTCId.clear();
276 
277  for (int iii = 0; iii < trgeclCluster.getEntries(); iii++) {
278  TRGECLCluster* aTRGECLCluster = trgeclCluster[iii];
279  int maxTCId = aTRGECLCluster ->getMaxTCId();
280  double clusterenergy = aTRGECLCluster ->getEnergyDep();
281  double clustertiming = aTRGECLCluster -> getTimeAve();
282  ClusterTiming.push_back(clustertiming);
283  ClusterEnergy.push_back(clusterenergy);
284  MaxTCId.push_back(maxTCId);
285  }
286 
287 
288  std::vector<double> maxClusterEnergy;
289  std::vector<double> maxClusterTiming;
290  std::vector<int> maxCenterTCId;
291  maxClusterTiming.clear();
292  maxClusterEnergy.clear();
293  maxCenterTCId.clear();
294 
295  maxClusterEnergy.resize(2, 0.0);
296  maxClusterTiming.resize(2, 0.0);
297  maxCenterTCId.resize(2, 0.0);
298  const int cl_size = ClusterEnergy.size();
299  for (int icl = 0; icl < cl_size; icl++) {
300  if (maxClusterEnergy[0] < ClusterEnergy[icl]) {
301  maxClusterEnergy[0] = ClusterEnergy[icl];
302  maxClusterTiming[0] = ClusterTiming[icl];
303  maxCenterTCId[0] = MaxTCId[icl];
304  } else if (maxClusterEnergy[1] < ClusterEnergy[icl]) {
305  maxClusterEnergy[1] = ClusterEnergy[icl];
306  maxClusterTiming[1] = ClusterTiming[icl];
307  maxCenterTCId[1] = MaxTCId[icl];
308 
309  }
310 
311  }
312  TrgEclDataBase _database;
313 
314  std::vector<double> _3DBhabhaThreshold;
315  _3DBhabhaThreshold = {30, 45}; // /10 MeV
316 
317 
318  bool BtoBFlag = false;
319  bool BhabhaFlag = false;
320  int lut1 = _database.Get3DBhabhaLUT(maxCenterTCId[0]);
321  int lut2 = _database.Get3DBhabhaLUT(maxCenterTCId[1]);
322  int energy1 = 15 & lut1;
323  int energy2 = 15 & lut2;
324  lut1 >>= 4;
325  lut2 >>= 4;
326  int phi1 = 511 & lut1;
327  int phi2 = 511 & lut2;
328  lut1 >>= 9;
329  lut2 >>= 9;
330  int theta1 = lut1;
331  int theta2 = lut2;
332  int dphi = abs(phi1 - phi2);
333  if (dphi > 180) {dphi = 360 - dphi;}
334  int thetaSum = theta1 + theta2;
335  if (dphi > 160 && thetaSum > 165 && thetaSum < 190) {BtoBFlag = true;}
336 
337  if ((maxClusterEnergy[0] * 0.1) > _3DBhabhaThreshold[0] * energy1
338  && (maxClusterEnergy[1] * 0.1) > _3DBhabhaThreshold[0] * (energy2)
339  && ((maxClusterEnergy[0] * 0.1) > _3DBhabhaThreshold[1] * energy1
340  || (maxClusterEnergy[1] * 0.1) > _3DBhabhaThreshold[1] * (energy2))) {
341  if (BtoBFlag) {BhabhaFlag = true;}
342  }
343 
344 
345  if (BhabhaFlag) {
346  h_Cluster_Energy_Sum -> Fill((maxClusterEnergy[0] + maxClusterEnergy[1]) / 5.25);
347  }
348 
349 
350  const int NofTCHit = TCId.size();
351 
352  double totalEnergy = 0;
353  TrgEclMapping* a = new TrgEclMapping();
354  double max = 0;
355  double caltrgtiming = 0;
356 
357  for (int ihit = 0; ihit < NofTCHit ; ihit ++) {
358  h_TCId -> Fill(TCId[ihit]);
359  h_TCthetaId -> Fill(a -> getTCThetaIdFromTCId(TCId[ihit]));
360  {
361  if (a->getTCThetaIdFromTCId(TCId[ihit]) < 4) {
362  h_TCphiId_FWD -> Fill(a->getTCPhiIdFromTCId(TCId[ihit]));
363  } else if (a->getTCThetaIdFromTCId(TCId[ihit]) > 3 && a->getTCThetaIdFromTCId(TCId[ihit]) < 16) {
364  h_TCphiId_BR -> Fill(a->getTCPhiIdFromTCId(TCId[ihit]));
365  } else {
366  h_TCphiId_BWD -> Fill(a->getTCPhiIdFromTCId(TCId[ihit]));
367 
368  }
369  }
370  h_TCEnergy -> Fill(TCEnergy[ihit]);
371  h_Narrow_TCEnergy -> Fill(TCEnergy[ihit]);
372  h_Cal_TCTiming -> Fill(FineTiming[ihit]);
373 
374  if (max < TCEnergy[ihit]) {
375  max = TCEnergy[ihit];
376  caltrgtiming = FineTiming[ihit];
377  }
378 
379  totalEnergy += TCEnergy[ihit];
380  h_n_TChit_event -> Fill(NofTCHit);
381  double timing = 8 * HitRevoTrg - (128 * RevoFAM[ihit] + TCTiming[ihit]);
382  if (timing < 0) {timing = timing + 10240;}
383  h_TCTiming->Fill(timing);
384  }
385  double trgtiming = 8 * HitRevoTrg - (128 * HitRevoEvtTiming + HitFineTiming);
386 
387  if (trgtiming < 0) {trgtiming = trgtiming + 10240;}
388  h_TRGTiming -> Fill(trgtiming);
389  h_Cal_TRGTiming -> Fill(caltrgtiming);
390  h_TotalEnergy -> Fill(totalEnergy);
391  h_Narrow_TotalEnergy -> Fill(totalEnergy);
392 
393  // usleep(100);
394 }
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
Example Detector.
Definition: TRGECLCluster.h:24
double getEnergyDep() const
The method to get deposited energy.
int getMaxTCId() const
The method to get the Maximum(center) TC id.
std::vector< double > TCEnergy
Hit TC Energy.
TH1 * h_TCId
TCId histogram.
TH1 * h_TCphiId_BWD
TCphiId histogram.
TH1 * h_Narrow_TotalEnergy
Total Energy on narrow range.
TH1 * h_TotalEnergy
Total Energy.
TH1 * h_Cluster
N of Cluster / event.
virtual void initialize() override
initialize
StoreArray< TRGECLUnpackerStore > trgeclHitArray
Trg ECL Unpakcer TC output.
virtual void event() override
Event.
TH1 * h_Cal_TRGTiming
Event Timing / event.
TH1 * h_Narrow_TCEnergy
TC Energy histogram on narrow range.
virtual void endRun() override
End Run.
TH1 * h_Cluster_Energy_Sum
Energy sum of 2 Top energetic clusters when 3D bhabnha bit on.
virtual void terminate() override
terminate
virtual ~TRGECLDQMModule()
Destrunctor.
TH1 * h_TCphiId_FWD
TCphiId histogram.
TH1 * h_TRGTiming
Event Timing / event.
TH1 * h_ECL_TriggerBit
ECL Trigger Bit.
std::vector< double > TCTiming
Hit TC Timing.
StoreArray< TRGECLUnpackerEvtStore > trgeclEvtArray
Trg ECL Unpakcer Event output.
TH1 * h_TCthetaId
TCthetaId histogram.
virtual void beginRun() override
begin Run
StoreArray< TRGECLUnpackerSumStore > trgeclSumArray
Trg Ecl Unpacker Summary output.
TH1 * h_TCphiId_BR
TCphiId histogram.
TH1 * h_Cal_TCTiming
TC Timing / event.
TH1 * h_TCEnergy
TC Energy.
std::vector< double > FineTiming
Event Timing.
std::vector< double > RevoTrg
GDL Revolution Clk.
TH1 * h_TCTiming
TC Timing / event.
TH1 * h_n_TChit_event
N of TC Hit / event.
std::vector< double > RevoFAM
FAM Revolution Clk.
StoreArray< TRGECLCluster > trgeclCluster
Trg ECL Cluster output.
std::vector< int > TCId
Hit TCId.
virtual void defineHisto() override
Define Histogram.
int getTCCALTime() const
The method to get cal timing.
int getTCId() const
The method to get cell id.
int getTCTime() const
The method to get hit average time.
int get2DBhabha() const
The mothod to get 2D Bhabha bit.
int getPhysics() const
The mothod to get Physics bit.
int getTimeType() const
The mothod to get Timing Type.
A Class of ECL Trigger clustering
Definition: TrgEclCluster.h:30
void setICN(const std::vector< int > &)
set ICN for each part(Fw,Br,Bw)
int getNofCluster()
0 : center , 1; upper , 2: right , 3: lower , 4: lower right
Definition: TrgEclCluster.h:92
class TrgEclDataBase;
int Get3DBhabhaLUT(int)
TC CM Phi
A class of TC Mapping.
Definition: TrgEclMapping.h:26
#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.