Belle II Software  release-08-01-10
trgeclUnpackerModule.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/trgeclUnpacker/trgeclUnpackerModule.h>
10 
11 #include "trg/ecl/TrgEclDataBase.h"
12 #include "trg/ecl/TrgEclMapping.h"
13 
14 using namespace std;
15 using namespace Belle2;
16 
18 REG_MODULE(TRGECLUnpacker);
19 
20 string TRGECLUnpackerModule::version() const
21 {
22  return string("4.02");
23 }
24 
25 TRGECLUnpackerModule::TRGECLUnpackerModule()
26  : Module::Module(), n_basf2evt(0)
27 {
28 
29  string desc = "TRGECLUnpackerModule(" + version() + ")";
30  setDescription(desc);
32 
33  B2DEBUG(20, "trgeclunpacker: Constructor done.");
34 }
35 
37 
39 {
40 }
41 
43 {
44  m_TRGECLSumArray.registerInDataStore();
45  m_TRGECLTCArray.registerInDataStore();
46  m_TRGECLEvtArray.registerInDataStore();
47  m_TRGECLClusterArray.registerInDataStore();
48  m_eventLevelClusteringInfo.registerInDataStore();
49 
50 }
51 
55 {
56 
57  StoreArray<RawTRG> raw_trgarray;
58 
59  for (int i = 0; i < raw_trgarray.getEntries(); i++) { // # of readout boards
60  iFiness = i;
61  for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) { // Basically 1 entry
62  nodeid = ((raw_trgarray[i]->GetNodeID(j)) >> 24) & 0x1F;
63  trgtype = raw_trgarray[i]->GetTRGType(j);
64  n_basf2evt = raw_trgarray[i]->GetEveNo(j);
65  if (nodeid == 0x13) {
66  for (int ch = 0; ch < raw_trgarray[i]->GetMaxNumOfCh(j); ch++) { // ch in a readout board
67  nwords = raw_trgarray[i]->GetDetectorNwords(j, ch);
68  if (nwords == 0) {
69  continue; // This channel might be masked.
70  } else if (nwords < 9) {
71  B2ERROR("Consistecy error in unpacker.");
72  B2ERROR("data length " << nwords << " nWord " << nwords);
73  B2ERROR("Node ID " << nodeid << ", Finness ID " << iFiness);
74  continue;
75  }
76  readCOPPEREvent(raw_trgarray[i], j, nwords, ch);
77  }
78  }
79  }
80  }
81 
82  // Count number of trigger cells in each ECL region for EventLevelClusteringInfo
83  uint16_t nTCsPerRegion[3] = {};
84  const int firstBarrelId = 81; // First TCId in the barrel
85  const int lastBarrelId = 512; // Last TCId in the barrel
86  for (auto& trgeclhit : m_TRGECLTCArray) {
87  const int tcId = trgeclhit.getTCId();
88  if (tcId < firstBarrelId) {
89  nTCsPerRegion[0]++;
90  } else if (tcId > lastBarrelId) {
91  nTCsPerRegion[2]++;
92  } else {
93  nTCsPerRegion[1]++;
94  }
95  }
96 
97  // Store
99  m_eventLevelClusteringInfo->setNECLTriggerCellsFWD(nTCsPerRegion[0]);
100  m_eventLevelClusteringInfo->setNECLTriggerCellsBarrel(nTCsPerRegion[1]);
101  m_eventLevelClusteringInfo->setNECLTriggerCellsBWD(nTCsPerRegion[2]);
102 
103 }
104 
105 void TRGECLUnpackerModule::readCOPPEREvent(RawTRG* raw_copper, int i, int nnn, int ch)
106 {
107  /* cppcheck-suppress variableScope */
108  int* rdat;
109  if (raw_copper->GetDetectorNwords(i, ch) > 0) {
110  rdat = raw_copper->GetDetectorBuffer(i, ch);
111  etm_version = ((rdat[0] >> 16) & 0xffff);
112  if (etm_version > 136) {
113  checkBuffer(rdat, nnn);
114  } else {
115  checkBuffer_v136(rdat, nnn);
116  }
117  }
118 }
119 
120 void TRGECLUnpackerModule::checkBuffer(int* rdat, int nnn)
121 {
122 
123  int version_check = (rdat[0] >> 12) & 0xf;
124  if (version_check != 15) return;
125 
126  // Checksum variable
127  unsigned char check_sum = (rdat[nnn - 1] >> 24) & 0xFF;
128  unsigned char data_sum = 0;
129  unsigned char kdat[4] = {0};
130  for (int j = nnn - 2; j > -1; j--) {
131  kdat[0] = rdat[j] & 0xff;
132  kdat[1] = (rdat[j] >> 8) & 0xff;
133  kdat[2] = (rdat[j] >> 16) & 0xff;
134  kdat[3] = (rdat[j] >> 24) & 0xff;
135  for (int k = 0; k < 4; k++) {
136  data_sum = data_sum + kdat[k];
137  }
138  }
139 
140  int flag_checksum = 0;
141 
142  if (check_sum == data_sum) {
143  flag_checksum = 0;
144  } else {
145  flag_checksum = 1;
146  }
147 
148  // Information
149  int l1_revo = rdat[0] & 0x7ff;
150  int i = 0;
151  int window_num = 0;
152 
153  // Summary
154  /* cppcheck-suppress variableScope */
155  int summary_data = 0;
156  int summary_recon = 0;
157  /* cppcheck-suppress variableScope */
158  int summary_revo = 0;
159  /* cppcheck-suppress variableScope */
160  bool summary_trg = false;
161  /* cppcheck-suppress variableScope */
162  int data_win = 0;
163 
164  // TC
165  /* cppcheck-suppress variableScope */
166  int ntc_win = 0;
167  bool tc_trg = false;
168  // TC info
169  int tc_id = 0;
170  int tc_t = 0;
171  int tc_e = 0;
172  int conv_tc_t = 0;
173  int win3_revo = -9999;
174 
175  vector<unsigned> sum_data;
176  vector<vector<unsigned>> sum_info;
177 
178  vector<int> tc_data;
179  vector<vector<int>> tc_info;
180  vector<vector<int>> tc_info_FE1;
181  vector<vector<int>> tc_info_FE2;
182  vector<vector<int>> tc_info_BE1;
183  vector<vector<int>> tc_info_BE2;
184 
185  // Unpacking ---->
186  while (i < nnn - 2) {
187  summary_data = rdat[i + 1];
188  summary_trg = (summary_data >> 23) & 0x1;
189  summary_revo = (summary_data >> 16) & 0x7f;
190  ntc_win = summary_data & 0x3ff;
191  if (ntc_win == 0) {
192  tc_trg = false;
193  } else {
194  tc_trg = true;
195  }
196  data_win = window_num;
197  if (window_num == 3) win3_revo = summary_revo;
198 
199  if (summary_trg == true) { // Summary on
200  sum_data.push_back(data_win);
201  sum_data.push_back(summary_revo);
202  for (int j = 0; j < 12; j++) {
203  summary_recon =
204  (((rdat[i + j + 2] >> 0) & 0xFF) << 24) +
205  (((rdat[i + j + 2] >> 8) & 0xFF) << 16) +
206  (((rdat[i + j + 2] >> 16) & 0xFF) << 8) +
207  (((rdat[i + j + 2] >> 24) & 0xFF) << 0);
208  sum_data.push_back(summary_recon);
209  }
210  sum_info.push_back(sum_data);
211  sum_data.clear();
212  i = i + 14;
213 
214  if (tc_trg == true) { // summary on & TC on
215  for (int j = 0; j < ntc_win; j++) {
216  tc_id = (rdat[i + j] >> 20) & 0x3FF;
217  tc_t = (rdat[i + j] >> 12) & 0x7F;
218  tc_e = rdat[i + j] & 0xFFF;
219  conv_tc_t = (data_win - 3) * 128 + tc_t;
220 
221  // TC vector
222  tc_data.push_back(tc_id);
223  tc_data.push_back(conv_tc_t);
224  tc_data.push_back(tc_e);
225  tc_data.push_back(data_win);
226  if (tc_id < 81) {
227  if (tc_id > 75) {
228  tc_info_FE1.push_back(tc_data);
229  } else {
230  tc_info_FE2.push_back(tc_data);
231  }
232  } else if (tc_id > 512) {
233  if (tc_id > 572) {
234  tc_info_BE1.push_back(tc_data);
235  } else {
236  tc_info_BE2.push_back(tc_data);
237  }
238  } else {
239  tc_info.push_back(tc_data);
240  }
241  tc_data.clear();
242  }
243  i = i + ntc_win - 1;
244  }
245 
246  } else { // Summary off
247  if (tc_trg == true) { // summary off & TC on
248  for (int j = 0; j < ntc_win; j++) {
249  tc_id = (rdat[i + j + 2] >> 20) & 0x3FF;
250  tc_t = (rdat[i + j + 2] >> 12) & 0x7F;
251  conv_tc_t = (data_win - 3) * 128 + tc_t;
252  tc_e = rdat[i + j + 2] & 0xFFF;
253 
254  // TC vector
255  tc_data.push_back(tc_id);
256  tc_data.push_back(conv_tc_t);
257  tc_data.push_back(tc_e);
258  tc_data.push_back(data_win);
259  if (tc_id < 81) {
260  if (tc_id > 75) {
261  tc_info_FE1.push_back(tc_data);
262  } else {
263  tc_info_FE2.push_back(tc_data);
264  }
265  } else if (tc_id > 512) {
266  if (tc_id > 572) {
267  tc_info_BE1.push_back(tc_data);
268  } else {
269  tc_info_BE2.push_back(tc_data);
270  }
271  } else {
272  tc_info.push_back(tc_data);
273  }
274  tc_data.clear();
275  }
276  i = i + ntc_win + 1;
277  } else { // Summary off & TC off
278  i = i + 1;
279  }
280  }
281  window_num++;
282  }
283 
284  // <---- Unpacking
285 
286  // Summary
287  /* cppcheck-suppress variableScope */
288  int sum_num_ord = 0;
289  /* cppcheck-suppress variableScope */
290  int sum_num = 0;
291  /* cppcheck-suppress variableScope */
292  int sum_revo = 0;
293  int cl_theta[6] = {0};
294  int cl_phi[6] = {0};
295  int cl_time[6] = { -9999};
296  int cl_energy[6] = {0};
297  int cl_1gev[6] = {0};
298  int cl_2gev[6] = {0};
299  int cl_bha[6] = {0};
300  int ncl = 0;
301  int low_multi = 0;
302  int b2bhabha_v = 0;
303  int b2bhabha_s = 0;
304  int mumu = 0;
305  int prescale = 0;
306  int icn_over = 0;
307  int bg_veto = 0;
308  int icn = 0;
309  int etot_type = 0;
310  int etot = 0;
311  int b1_type = 0;
312  int b1bhabha = 0;
313  int physics = 0;
314  int time_type = 0;
315  int time = 0;
316  int ecl_bst = 0;
317 
318  int m_sumNum = 0;
319 
320  TrgEclDataBase database;
321  TrgEclMapping mapping;
322 
323  vector<int> cl_1d;
324  vector<vector<int>> cl_2d;
325 
326  vector<int> evt_1d_vector;
327  vector<vector<int>> evt_2d_vector;
328 
329  // Store Summary
330  int sum_size = sum_info.size();
331  if (sum_size != 0) {
332  for (int j = 0; j < sum_size; j++) {
333  sum_num = sum_info[j][0];
334  sum_revo = sum_info[j][1];
335  // TRG
336  time = (sum_info[j][2]) & 0x7F;
337  time_type = (sum_info[j][2] >> 7) & 0x7;
338  physics = (sum_info[j][2] >> 10) & 0x1;
339  b1bhabha = (sum_info[j][2] >> 11) & 0x1;
340  b1_type = (sum_info[j][2] >> 12) & 0x3FFF;
341  etot = ((sum_info[j][3] & 0x7F) << 6) + ((sum_info[j][2] >> 26) & 0x3F);
342  etot_type = (sum_info[j][3] >> 7) & 0x7;
343  icn = (sum_info[j][3] >> 10) & 0x7F;
344  bg_veto = (sum_info[j][3] >> 17) & 0x7;
345  icn_over = (sum_info[j][3] >> 20) & 0x1;
346  b2bhabha_v = (sum_info[j][3] >> 21) & 0x1;
347  low_multi = (((sum_info[j][4] >> 6) & 0x3) << 12) + ((sum_info[j][4] & 0x3) << 10) + ((sum_info[j][3] >> 22) & 0x3FF);
348  b2bhabha_s = (sum_info[j][4] >> 2) & 0x1;
349  mumu = (sum_info[j][4] >> 3) & 0x1;
350  prescale = (sum_info[j][4] >> 4) & 0x1;
351  ecl_bst = (sum_info[j][4] >> 5) & 0x1;
352  // CL
353  cl_energy[0] = (sum_info[j][5]) & 0xFFF;
354  cl_time[0] = (sum_info[j][5] >> 12) & 0xFF;
355  cl_phi[0] = (sum_info[j][5] >> 20) & 0xFF;
356  cl_theta[0] = ((sum_info[j][6] & 0x7) << 4) + ((sum_info[j][5] >> 28) & 0xF);
357 
358  cl_energy[1] = (sum_info[j][6] >> 3) & 0xFFF;
359  cl_time[1] = (sum_info[j][6] >> 15) & 0xFF;
360  cl_phi[1] = (sum_info[j][6] >> 23) & 0xFF;
361  cl_theta[1] = ((sum_info[j][7] & 0x3F) << 1) + ((sum_info[j][6] >> 31) & 0x1);
362 
363  cl_energy[2] = (sum_info[j][7] >> 6) & 0xFFF;
364  cl_time[2] = (sum_info[j][7] >> 18) & 0xFF;
365  cl_phi[2] = ((sum_info[j][8] & 0x3) << 6) + ((sum_info[j][7] >> 26) & 0x3F);
366  cl_theta[2] = (sum_info[j][8] >> 2) & 0x7F;
367 
368  cl_energy[3] = (sum_info[j][8] >> 9) & 0xFFF;
369  cl_time[3] = (sum_info[j][8] >> 21) & 0xFF;
370  cl_phi[3] = ((sum_info[j][9] & 0x1F) << 3) + ((sum_info[j][8] >> 29) & 0x7);
371  cl_theta[3] = (sum_info[j][9] >> 5) & 0x7F;
372 
373  cl_energy[4] = (sum_info[j][ 9] >> 12) & 0xFFF;
374  cl_time[4] = (sum_info[j][ 9] >> 24) & 0xFF;
375  cl_phi[4] = (sum_info[j][10]) & 0xFF;
376  cl_theta[4] = (sum_info[j][10] >> 8) & 0x7F;
377 
378  cl_energy[5] = (sum_info[j][10] >> 15) & 0xFFF;
379  cl_time[5] = ((sum_info[j][11] & 0x7) << 5) + ((sum_info[j][10] >> 27) & 0x1F);
380  cl_phi[5] = (sum_info[j][11] >> 3) & 0xFF;
381  cl_theta[5] = (sum_info[j][11] >> 11) & 0x7F;
382  // CL others
383  for (int k = 0; k < 6; k++) {
384  cl_1gev[k] = (sum_info[j][12] >> k) & 0x1;
385  cl_2gev[k] = (sum_info[j][12] >> (k + 6)) & 0x1;
386  cl_bha[k] = (sum_info[j][12] >> (k + 12)) & 0x1;
387  }
388  ncl = (sum_info[j][13]) & 0x7;
389 
390  m_TRGECLSumArray.appendNew();
391  m_sumNum = m_TRGECLSumArray.getEntries() - 1;
392  m_TRGECLSumArray[m_sumNum]->setEventId(n_basf2evt);
393  m_TRGECLSumArray[m_sumNum]->setSumNum(sum_num);
394  m_TRGECLSumArray[m_sumNum]->setSumRevo(sum_revo);
395  m_TRGECLSumArray[m_sumNum]->setCLTheta(cl_theta);
396  m_TRGECLSumArray[m_sumNum]->setCLPhi(cl_phi);
397  m_TRGECLSumArray[m_sumNum]->setCLTime(cl_time);
398  m_TRGECLSumArray[m_sumNum]->setCLEnergy(cl_energy);
399  m_TRGECLSumArray[m_sumNum]->setCLF1GeV(cl_1gev);
400  m_TRGECLSumArray[m_sumNum]->setCLF2GeV(cl_2gev);
401  m_TRGECLSumArray[m_sumNum]->setCLFBha(cl_bha);
402  m_TRGECLSumArray[m_sumNum]->setNCL(ncl);
403  m_TRGECLSumArray[m_sumNum]->setICN(icn);
404  m_TRGECLSumArray[m_sumNum]->setICNOver(icn_over);
405  m_TRGECLSumArray[m_sumNum]->setLowMulti(low_multi);
406  m_TRGECLSumArray[m_sumNum]->set3DBhabhaV(b2bhabha_v);
407  m_TRGECLSumArray[m_sumNum]->set3DBhabhaS(b2bhabha_s);
408  m_TRGECLSumArray[m_sumNum]->setMumu(mumu);
409  m_TRGECLSumArray[m_sumNum]->setPrescale(prescale);
410  m_TRGECLSumArray[m_sumNum]->set2DBhabha(b1bhabha);
411  m_TRGECLSumArray[m_sumNum]->setBhabhaType(b1_type);
412  m_TRGECLSumArray[m_sumNum]->setPhysics(physics);
413  m_TRGECLSumArray[m_sumNum]->setBG(bg_veto);
414  m_TRGECLSumArray[m_sumNum]->setEtot(etot);
415  m_TRGECLSumArray[m_sumNum]->setEtotType(etot_type);
416  m_TRGECLSumArray[m_sumNum]->setECLBST(ecl_bst);
417  m_TRGECLSumArray[m_sumNum]->setTime(time);
418  m_TRGECLSumArray[m_sumNum]->setTimeType(time_type);
419 
420  for (int k = 0; k < 6; k++) {
421  cl_1d.push_back(cl_theta[k]);
422  cl_1d.push_back(cl_phi[k]);
423  cl_1d.push_back(cl_time[k]);
424  cl_1d.push_back(cl_energy[k]);
425  cl_1d.push_back(cl_1gev[k]);
426  cl_1d.push_back(cl_2gev[k]);
427  cl_1d.push_back(cl_bha[k]);
428  cl_2d.push_back(cl_1d);
429  cl_1d.clear();
430  }
431  sort(cl_2d.begin(), cl_2d.end(),
432  [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[3] > aa2[3];});
433 
434  if (sum_num == -9999) {
435  sum_num_ord = -9999;
436  } else if (sum_num <= 3) {
437  sum_num_ord = 2 * abs(sum_num - 3);
438  } else {
439  sum_num_ord = (sum_num * 2) - 7;
440  }
441  evt_1d_vector.push_back(sum_num_ord);
442  evt_1d_vector.push_back(sum_revo);
443  evt_1d_vector.push_back(sum_num);
444  evt_1d_vector.push_back(time);
445  for (int k = 0; k < 6; k++) {
446  for (int l = 0; l < 7; l++) {
447  evt_1d_vector.push_back(cl_2d[k][l]);
448  }
449  }
450  evt_1d_vector.push_back(ncl);
451  evt_1d_vector.push_back(low_multi);
452  evt_1d_vector.push_back(b2bhabha_v);
453  evt_1d_vector.push_back(b2bhabha_s);
454  evt_1d_vector.push_back(mumu);
455  evt_1d_vector.push_back(prescale);
456  evt_1d_vector.push_back(icn);
457  evt_1d_vector.push_back(icn_over);
458  evt_1d_vector.push_back(etot_type);
459  evt_1d_vector.push_back(etot);
460  evt_1d_vector.push_back(ecl_bst);
461  evt_1d_vector.push_back(b1_type);
462  evt_1d_vector.push_back(b1bhabha);
463  evt_1d_vector.push_back(physics);
464  evt_1d_vector.push_back(time_type);
465  evt_2d_vector.push_back(evt_1d_vector);
466  evt_1d_vector.clear();
467  }
468  } else {
469  for (int k = 0; k < 6; k++) {
470  cl_theta[k] = 0;
471  cl_phi[k] = 0;
472  cl_time[k] = -9999;
473  cl_energy[k] = 0;
474  cl_1gev[k] = 0;
475  cl_2gev[k] = 0;
476  cl_bha[k] = 0;
477  }
478  ncl = 0;
479  low_multi = 0;
480  b2bhabha_v = 0;
481  b2bhabha_s = 0;
482  mumu = 0;
483  prescale = 0;
484  icn_over = 0;
485  bg_veto = 0;
486  icn = 0;
487  etot_type = 0;
488  etot = 0;
489  ecl_bst = 0;
490  b1_type = 0;
491  b1bhabha = 0;
492  physics = 0;
493  time_type = 0;
494  time = -9999;
495 
496  m_TRGECLSumArray.appendNew();
497  m_sumNum = m_TRGECLSumArray.getEntries() - 1;
498  m_TRGECLSumArray[m_sumNum]->setEventId(n_basf2evt);
499  m_TRGECLSumArray[m_sumNum]->setSumNum(0);
500  m_TRGECLSumArray[m_sumNum]->setCLTheta(cl_theta);
501  m_TRGECLSumArray[m_sumNum]->setCLPhi(cl_phi);
502  m_TRGECLSumArray[m_sumNum]->setCLTime(cl_time);
503  m_TRGECLSumArray[m_sumNum]->setCLEnergy(cl_energy);
504  m_TRGECLSumArray[m_sumNum]->setCLF1GeV(cl_1gev);
505  m_TRGECLSumArray[m_sumNum]->setCLF2GeV(cl_2gev);
506  m_TRGECLSumArray[m_sumNum]->setCLFBha(cl_bha);
507  m_TRGECLSumArray[m_sumNum]->setNCL(ncl);
508  m_TRGECLSumArray[m_sumNum]->setICN(icn);
509  m_TRGECLSumArray[m_sumNum]->setICNOver(icn_over);
510  m_TRGECLSumArray[m_sumNum]->setLowMulti(low_multi);
511  m_TRGECLSumArray[m_sumNum]->set3DBhabhaV(b2bhabha_v);
512  m_TRGECLSumArray[m_sumNum]->set3DBhabhaS(b2bhabha_s);
513  m_TRGECLSumArray[m_sumNum]->setMumu(mumu);
514  m_TRGECLSumArray[m_sumNum]->setPrescale(prescale);
515  m_TRGECLSumArray[m_sumNum]->set2DBhabha(b1bhabha);
516  m_TRGECLSumArray[m_sumNum]->setBhabhaType(b1_type);
517  m_TRGECLSumArray[m_sumNum]->setPhysics(physics);
518  m_TRGECLSumArray[m_sumNum]->setBG(bg_veto);
519  m_TRGECLSumArray[m_sumNum]->setEtot(etot);
520  m_TRGECLSumArray[m_sumNum]->setEtotType(etot_type);
521  m_TRGECLSumArray[m_sumNum]->setECLBST(ecl_bst);
522  m_TRGECLSumArray[m_sumNum]->setTime(time);
523  m_TRGECLSumArray[m_sumNum]->setTimeType(time_type);
524  }
525 
526  // TC & TRG
527  tc_info.insert(tc_info.end(), tc_info_FE1.begin(), tc_info_FE1.end());
528  tc_info.insert(tc_info.end(), tc_info_FE2.begin(), tc_info_FE2.end());
529  tc_info.insert(tc_info.end(), tc_info_BE1.begin(), tc_info_BE1.end());
530  tc_info.insert(tc_info.end(), tc_info_BE2.begin(), tc_info_BE2.end());
531 
532  int m_evtNum = 0;
533 
534  int m_tcNum = 0;
535  /* cppcheck-suppress variableScope */
536  int m_tcid = 0;
537  /* cppcheck-suppress variableScope */
538  int m_time = -9999;
539  /* cppcheck-suppress variableScope */
540  int m_energy = 0;
541  /* cppcheck-suppress variableScope */
542  int m_win = 0;
543  /* cppcheck-suppress variableScope */
544  int m_revo = 0;
545  /* cppcheck-suppress variableScope */
546  int m_caltime = -9999;
547 
548  int tot_ntc = tc_info.size();
549  /* cppcheck-suppress variableScope */
550  int evt_ntc = 0;
551  /* cppcheck-suppress variableScope */
552  int evt_revo = -9999;
553  /* cppcheck-suppress variableScope */
554  int evt_win = 0;
555  /* cppcheck-suppress variableScope */
556  int evt_timing = -9999; // most energetic
557  int evt_cl_theta[6] = {0};
558  int evt_cl_phi[6] = {0};
559  int evt_cl_time[6] = { -9999};
560  int evt_cl_energy[6] = {0};
561  int evt_cl_1gev[6] = {0};
562  int evt_cl_2gev[6] = {0};
563  int evt_cl_bha[6] = {0};
564  /* cppcheck-suppress variableScope */
565  int evt_ncl = 0;
566  /* cppcheck-suppress variableScope */
567  int evt_low_multi = 0;
568  /* cppcheck-suppress variableScope */
569  int evt_b2bhabha_v = 0;
570  /* cppcheck-suppress variableScope */
571  int evt_b2bhabha_s = 0;
572  /* cppcheck-suppress variableScope */
573  int evt_mumu = 0;
574  /* cppcheck-suppress variableScope */
575  int evt_prescale = 0;
576  /* cppcheck-suppress variableScope */
577  int evt_icn = 0;
578  /* cppcheck-suppress variableScope */
579  int evt_icn_over = 0;
580  /* cppcheck-suppress variableScope */
581  int evt_etot_type = 0;
582  /* cppcheck-suppress variableScope */
583  int evt_etot = 0;
584  /* cppcheck-suppress variableScope */
585  int evt_ecl_bst = 0;
586  /* cppcheck-suppress variableScope */
587  int evt_b1_type = 0;
588  /* cppcheck-suppress variableScope */
589  int evt_b1bhabha = 0;
590  /* cppcheck-suppress variableScope */
591  int evt_physics = 0;
592  /* cppcheck-suppress variableScope */
593  int evt_time_type = 0;
594  /* cppcheck-suppress variableScope */
595  int evt_etot_all = 0;
596  /* cppcheck-suppress variableScope */
597  int evt_time_min = 0;
598  /* cppcheck-suppress variableScope */
599  int evt_time_max = 0;
600  /* cppcheck-suppress variableScope */
601  int evt_time_win = 0;
602  /* cppcheck-suppress variableScope */
603  int etot_i = 0;
604  /* cppcheck-suppress variableScope */
605  int etot_c = 0;
606  /* cppcheck-suppress variableScope */
607  int etot_f = 0;
608  /* cppcheck-suppress variableScope */
609  int cl_tcid = 0;
610  /* cppcheck-suppress variableScope */
611  int cl_thetaid = 0;
612  /* cppcheck-suppress variableScope */
613  int cl_phiid = 0;
614  /* cppcheck-suppress variableScope */
615  int m_clNum = 0;
616 
617 
618  int evt_v_size = evt_2d_vector.size();
619  if (evt_v_size != 0) {
620  // Sort window : 3 => 4 => 2 => 5 => 1 => 6 => 7
621  sort(evt_2d_vector.begin(), evt_2d_vector.end(),
622  [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[0] < aa2[0];});
623  }
624 
625  if (tot_ntc != 0 && flag_checksum == 0 && nnn > 7) {
626  if (evt_v_size == 0) {
627  // Find most energetic TC timing
628  sort(tc_info.begin(), tc_info.end(),
629  [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[2] > aa2[2];});
630  evt_revo = win3_revo;
631  evt_win = tc_info[0][3];
632  evt_timing = tc_info[0][1];
633  for (int k = 0; k < 6; k++) {
634  evt_cl_theta[k] = 0;
635  evt_cl_phi[k] = 0;
636  evt_cl_time[k] = 0;
637  evt_cl_energy[k] = 0;
638  evt_cl_1gev[k] = 0;
639  evt_cl_2gev[k] = 0;
640  evt_cl_bha[k] = 0;
641  }
642  evt_ncl = 0;
643  evt_low_multi = 0;
644  evt_b2bhabha_v = 0;
645  evt_b2bhabha_s = 0;
646  evt_mumu = 0;
647  evt_prescale = 0;
648  evt_icn = 0;
649  evt_icn_over = 0;
650  evt_etot_type = 0;
651  evt_etot = 0;
652  evt_ecl_bst = 0;
653  evt_b1_type = 0;
654  evt_b1bhabha = 0;
655  evt_physics = 0;
656  evt_time_type = 0;
657  } else {
658  evt_revo = evt_2d_vector[0][1];
659  evt_win = evt_2d_vector[0][2];
660  evt_timing = evt_2d_vector[0][3];
661  for (int k = 0; k < 6; k++) {
662  evt_cl_theta[k] = evt_2d_vector[0][ 4 + k * 7];
663  evt_cl_phi[k] = evt_2d_vector[0][ 5 + k * 7];
664  evt_cl_time[k] = evt_2d_vector[0][ 6 + k * 7];
665  evt_cl_energy[k] = evt_2d_vector[0][ 7 + k * 7];
666  evt_cl_1gev[k] = evt_2d_vector[0][ 8 + k * 7];
667  evt_cl_2gev[k] = evt_2d_vector[0][ 9 + k * 7];
668  evt_cl_bha[k] = evt_2d_vector[0][10 + k * 7];
669  }
670  evt_ncl = evt_2d_vector[0][46];
671  evt_low_multi = evt_2d_vector[0][47];
672  evt_b2bhabha_v = evt_2d_vector[0][48];
673  evt_b2bhabha_s = evt_2d_vector[0][49];
674  evt_mumu = evt_2d_vector[0][50];
675  evt_prescale = evt_2d_vector[0][51];
676  evt_icn = evt_2d_vector[0][52];
677  evt_icn_over = evt_2d_vector[0][53];
678  evt_etot_type = evt_2d_vector[0][54];
679  evt_etot = evt_2d_vector[0][55];
680  evt_ecl_bst = evt_2d_vector[0][56];
681  evt_b1_type = evt_2d_vector[0][57];
682  evt_b1bhabha = evt_2d_vector[0][58];
683  evt_physics = evt_2d_vector[0][59];
684  evt_time_type = evt_2d_vector[0][60];
685  }
686  // Sort by TC number
687  sort(tc_info.begin(), tc_info.end(),
688  [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[0] < aa2[0];});
689 
690  for (int ii = 0; ii < tot_ntc; ii++) {
691  m_tcid = tc_info[ii][0];
692  m_time = tc_info[ii][1];
693  m_energy = tc_info[ii][2];
694  m_win = tc_info[ii][3];
695  m_revo = win3_revo;
696  m_caltime = m_time - ((evt_win - 3) * 128 + evt_timing);
697  m_TRGECLTCArray.appendNew();
698  m_tcNum = m_TRGECLTCArray.getEntries() - 1;
699  m_TRGECLTCArray[m_tcNum]->setEventId(n_basf2evt);
700  m_TRGECLTCArray[m_tcNum]->setTCId(m_tcid);
701  m_TRGECLTCArray[m_tcNum]->setTCTime(m_time);
702  m_TRGECLTCArray[m_tcNum]->setTCCALTime(m_caltime);
703  m_TRGECLTCArray[m_tcNum]->setHitWin(m_win);
704  m_TRGECLTCArray[m_tcNum]->setRevoFAM(m_revo);
705  m_TRGECLTCArray[m_tcNum]->setTCEnergy(m_energy);
706  m_TRGECLTCArray[m_tcNum]->setChecksum(flag_checksum);
707 
708  if (m_win == evt_win || m_win == evt_win + 1) evt_ntc++;
709  if (m_win == evt_win - 1) {
710  etot_i += m_energy;
711  }
712  if (m_win == evt_win) {
713  etot_c += m_energy;
714  }
715  if (m_win == evt_win + 1) {
716  etot_f += m_energy;
717  }
718  }
719 
720  if (etot_i == 0 && etot_f == 0) {
721  evt_etot_all = etot_c;
722  evt_time_min = - evt_timing;
723  evt_time_max = 256 - evt_timing;
724  evt_time_win = 1;
725  } else if (etot_i >= etot_f) {
726  evt_etot_all = etot_c + etot_i;
727  evt_time_min = -128 - evt_timing;
728  evt_time_max = 128 - evt_timing;
729  evt_time_win = -1;
730  } else {
731  evt_etot_all = etot_c + etot_f;
732  evt_time_min = - evt_timing;
733  evt_time_max = 256 - evt_timing;
734  evt_time_win = 1;
735  }
736 
737  for (int icluster = 0; icluster < 6; icluster++) {
738  if (evt_cl_energy[icluster] == 0 || evt_cl_theta[icluster] == 0 || evt_cl_phi[icluster] == 0) {continue;}
739  cl_tcid = mapping.getTCIdFromPosition(evt_cl_theta[icluster], evt_cl_phi[icluster]);
740  if (cl_tcid == 0) {continue;}
741  cl_thetaid = mapping.getTCThetaIdFromTCId(cl_tcid);
742  cl_phiid = mapping.getTCPhiIdFromTCId(cl_tcid);
743 
744  m_TRGECLClusterArray.appendNew();
745  m_clNum = m_TRGECLClusterArray.getEntries() - 1;
746  m_TRGECLClusterArray[m_clNum]->setEventId(n_basf2evt);
747  m_TRGECLClusterArray[m_clNum]->setClusterId(icluster);
748  m_TRGECLClusterArray[m_clNum]->setEventRevo(evt_revo);
749 
750  m_TRGECLClusterArray[m_clNum]->setMaxTCId(cl_tcid); // center of Cluster
751  m_TRGECLClusterArray[m_clNum]->setMaxThetaId(cl_thetaid);
752  m_TRGECLClusterArray[m_clNum]->setMaxPhiId(cl_phiid);
753  m_TRGECLClusterArray[m_clNum]->setClusterId(icluster);
754  m_TRGECLClusterArray[m_clNum]->setEnergyDep((double)evt_cl_energy[icluster] * 5.25); // MeV
755  m_TRGECLClusterArray[m_clNum]->setTimeAve((double)evt_cl_time[icluster]);
756  m_TRGECLClusterArray[m_clNum]->setPositionX(mapping.getTCPosition(cl_tcid).X());
757  m_TRGECLClusterArray[m_clNum]->setPositionY(mapping.getTCPosition(cl_tcid).Y());
758  m_TRGECLClusterArray[m_clNum]->setPositionZ(mapping.getTCPosition(cl_tcid).Z());
759  }
760  m_TRGECLEvtArray.appendNew();
761  m_evtNum = m_TRGECLEvtArray.getEntries() - 1;
762  m_TRGECLEvtArray[m_evtNum]->setEventId(n_basf2evt);
763  m_TRGECLEvtArray[m_evtNum]->setETM(etm_version);
764  m_TRGECLEvtArray[m_evtNum]->setL1Revo(l1_revo);
765  m_TRGECLEvtArray[m_evtNum]->setEvtRevo(evt_revo);
766  m_TRGECLEvtArray[m_evtNum]->setEvtWin(evt_win);
767  m_TRGECLEvtArray[m_evtNum]->setEvtTime(evt_timing);
768  m_TRGECLEvtArray[m_evtNum]->setNTC(evt_ntc);
769  m_TRGECLEvtArray[m_evtNum]->setCLTheta(evt_cl_theta);
770  m_TRGECLEvtArray[m_evtNum]->setCLPhi(evt_cl_phi);
771  m_TRGECLEvtArray[m_evtNum]->setCLTime(evt_cl_time);
772  m_TRGECLEvtArray[m_evtNum]->setCLEnergy(evt_cl_energy);
773  m_TRGECLEvtArray[m_evtNum]->setCLF1GeV(evt_cl_1gev);
774  m_TRGECLEvtArray[m_evtNum]->setCLF2GeV(evt_cl_2gev);
775  m_TRGECLEvtArray[m_evtNum]->setCLFBha(evt_cl_bha);
776  m_TRGECLEvtArray[m_evtNum]->setNCL(evt_ncl);
777  m_TRGECLEvtArray[m_evtNum]->setLowMulti(evt_low_multi);
778  m_TRGECLEvtArray[m_evtNum]->set3DBhabhaV(evt_b2bhabha_v);
779  m_TRGECLEvtArray[m_evtNum]->set3DBhabhaS(evt_b2bhabha_s);
780  m_TRGECLEvtArray[m_evtNum]->setMumu(evt_mumu);
781  m_TRGECLEvtArray[m_evtNum]->setPrescale(evt_prescale);
782  m_TRGECLEvtArray[m_evtNum]->setICN(evt_icn);
783  m_TRGECLEvtArray[m_evtNum]->setICNOver(evt_icn_over);
784  m_TRGECLEvtArray[m_evtNum]->setEtotType(evt_etot_type);
785  m_TRGECLEvtArray[m_evtNum]->setEtot(evt_etot);
786  m_TRGECLEvtArray[m_evtNum]->setECLBST(evt_ecl_bst);
787  m_TRGECLEvtArray[m_evtNum]->set2DBhabha(evt_b1bhabha);
788  m_TRGECLEvtArray[m_evtNum]->setBhabhaType(evt_b1_type);
789  m_TRGECLEvtArray[m_evtNum]->setPhysics(evt_physics);
790  m_TRGECLEvtArray[m_evtNum]->setTimeType(evt_time_type);
791  m_TRGECLEvtArray[m_evtNum]->setCheckSum(flag_checksum);
792  m_TRGECLEvtArray[m_evtNum]->setEvtExist(1);
793  m_TRGECLEvtArray[m_evtNum]->setTRGTYPE(trgtype);
794  m_TRGECLEvtArray[m_evtNum]->setEtotAll(evt_etot_all);
795  m_TRGECLEvtArray[m_evtNum]->setEvtTimeMin(evt_time_min);
796  m_TRGECLEvtArray[m_evtNum]->setEvtTimeMax(evt_time_max);
797  m_TRGECLEvtArray[m_evtNum]->setEvtTimeWin(evt_time_win);
798  } else {
799  m_TRGECLTCArray.appendNew();
800  m_tcNum = m_TRGECLTCArray.getEntries() - 1;
801  m_TRGECLTCArray[m_tcNum]->setEventId(n_basf2evt);
802  m_TRGECLTCArray[m_tcNum]->setTCId(0);
803  m_TRGECLTCArray[m_tcNum]->setTCTime(-9999);
804  m_TRGECLTCArray[m_tcNum]->setTCCALTime(-9999);
805  m_TRGECLTCArray[m_tcNum]->setHitWin(-9999);
806  m_TRGECLTCArray[m_tcNum]->setRevoFAM(-9999);
807  m_TRGECLTCArray[m_tcNum]->setTCEnergy(0);
808  m_TRGECLTCArray[m_tcNum]->setChecksum(flag_checksum);
809 
810  m_TRGECLEvtArray.appendNew();
811  m_evtNum = m_TRGECLEvtArray.getEntries() - 1;
812  m_TRGECLEvtArray[m_evtNum]->setEventId(n_basf2evt);
813  m_TRGECLEvtArray[m_evtNum]->setETM(etm_version);
814  m_TRGECLEvtArray[m_evtNum]->setL1Revo(-9999);
815  m_TRGECLEvtArray[m_evtNum]->setEvtTime(-9999);
816  m_TRGECLEvtArray[m_evtNum]->setEvtRevo(-9999);
817  m_TRGECLEvtArray[m_evtNum]->setEvtWin(-9999);
818  m_TRGECLEvtArray[m_evtNum]->setNTC(0);
819  for (int k = 0; k < 6; k++) {
820  evt_cl_theta[k] = 0;
821  evt_cl_phi[k] = 0;
822  evt_cl_time[k] = -9999;
823  evt_cl_energy[k] = 0;
824  evt_cl_1gev[k] = 0;
825  evt_cl_2gev[k] = 0;
826  evt_cl_bha[k] = 0;
827  }
828  m_TRGECLEvtArray[m_evtNum]->setCLTheta(evt_cl_theta);
829  m_TRGECLEvtArray[m_evtNum]->setCLPhi(evt_cl_phi);
830  m_TRGECLEvtArray[m_evtNum]->setCLTime(evt_cl_time);
831  m_TRGECLEvtArray[m_evtNum]->setCLEnergy(evt_cl_energy);
832  m_TRGECLEvtArray[m_evtNum]->setCLF1GeV(evt_cl_1gev);
833  m_TRGECLEvtArray[m_evtNum]->setCLF2GeV(evt_cl_2gev);
834  m_TRGECLEvtArray[m_evtNum]->setCLFBha(evt_cl_bha);
835  m_TRGECLEvtArray[m_evtNum]->setNCL(0);
836  m_TRGECLEvtArray[m_evtNum]->setLowMulti(0);
837  m_TRGECLEvtArray[m_evtNum]->set3DBhabhaV(0);
838  m_TRGECLEvtArray[m_evtNum]->set3DBhabhaS(0);
839  m_TRGECLEvtArray[m_evtNum]->setMumu(0);
840  m_TRGECLEvtArray[m_evtNum]->setPrescale(0);
841  m_TRGECLEvtArray[m_evtNum]->setICN(0);
842  m_TRGECLEvtArray[m_evtNum]->setICNOver(0);
843  m_TRGECLEvtArray[m_evtNum]->setEtotType(0);
844  m_TRGECLEvtArray[m_evtNum]->setEtot(0);
845  m_TRGECLEvtArray[m_evtNum]->setECLBST(0);
846  m_TRGECLEvtArray[m_evtNum]->set2DBhabha(0);
847  m_TRGECLEvtArray[m_evtNum]->setBhabhaType(0);
848  m_TRGECLEvtArray[m_evtNum]->setPhysics(0);
849  m_TRGECLEvtArray[m_evtNum]->setTimeType(0);
850  m_TRGECLEvtArray[m_evtNum]->setCheckSum(flag_checksum);
851  m_TRGECLEvtArray[m_evtNum]->setEvtExist(0);
852  m_TRGECLEvtArray[m_evtNum]->setTRGTYPE(trgtype);
853  m_TRGECLEvtArray[m_evtNum]->setEtotAll(0);
854  m_TRGECLEvtArray[m_evtNum]->setEvtTimeMin(-9999);
855  m_TRGECLEvtArray[m_evtNum]->setEvtTimeMax(-9999);
856  m_TRGECLEvtArray[m_evtNum]->setEvtTimeWin(0);
857  }
858 
859  return;
860 }
861 
863 {
864 
865  int version_check = (rdat[0] >> 12) & 0xf;
866  if (version_check != 15) return;
867 
868  // Checksum variable
869  unsigned char check_sum = (rdat[nnn - 1] >> 24) & 0xFF;
870  unsigned char data_sum = 0;
871  unsigned char kdat[4] = {0};
872  for (int j = nnn - 2; j > -1; j--) {
873  kdat[0] = rdat[j] & 0xff;
874  kdat[1] = (rdat[j] >> 8) & 0xff;
875  kdat[2] = (rdat[j] >> 16) & 0xff;
876  kdat[3] = (rdat[j] >> 24) & 0xff;
877  for (int k = 0; k < 4; k++) {
878  data_sum = data_sum + kdat[k];
879  }
880  }
881 
882  int flag_checksum = 0;
883 
884  if (check_sum == data_sum) {
885  flag_checksum = 0;
886  } else {
887  flag_checksum = 1;
888  }
889 
890  // Information
891  int l1_revo = rdat[0] & 0x7ff;
892  int i = 0;
893  int window_num = 0;
894 
895  // Summary
896  /* cppcheck-suppress variableScope */
897  int summary_data = 0;
898  /* cppcheck-suppress variableScope */
899  int summary_revo = 0;
900  /* cppcheck-suppress variableScope */
901  bool summary_trg = false;
902  /* cppcheck-suppress variableScope */
903  int data_win = 0;
904 
905  // TC
906  /* cppcheck-suppress variableScope */
907  int ntc_win = 0;
908  bool tc_trg = false;
909  // TC info
910  int tc_id = 0;
911  int tc_t = 0;
912  int tc_e = 0;
913  int conv_tc_t = 0;
914  int win3_revo = -9999;
915 
916  vector<unsigned> sum_data;
917  vector<vector<unsigned>> sum_info; //TODO can these be unsigned? (required for bit shifts shifts)
918 
919  vector<int> tc_data;
920  vector<vector<int>> tc_info;
921  vector<vector<int>> tc_info_FE1;
922  vector<vector<int>> tc_info_FE2;
923  vector<vector<int>> tc_info_BE1;
924  vector<vector<int>> tc_info_BE2;
925 
926  // Unpacking ---->
927  while (i < nnn - 2) {
928  summary_data = rdat[i + 1];
929  summary_trg = (summary_data >> 23) & 0x1;
930  summary_revo = (summary_data >> 16) & 0x7f;
931  ntc_win = summary_data & 0x3ff;
932  if (ntc_win == 0) {
933  tc_trg = false;
934  } else {
935  tc_trg = true;
936  }
937  data_win = window_num;
938  if (window_num == 3) win3_revo = summary_revo;
939 
940  if (summary_trg == true) { // Summary on
941  sum_data.push_back(data_win);
942  sum_data.push_back(summary_revo);
943  for (int j = 0; j < 9; j++) {
944  sum_data.push_back(rdat[i + j + 2]);
945  }
946  sum_info.push_back(sum_data);
947  sum_data.clear();
948  i = i + 11;
949 
950  if (tc_trg == true) { // summary on & TC on
951  for (int j = 0; j < ntc_win; j++) {
952  tc_id = (rdat[i + j] >> 20) & 0x3FF;
953  tc_t = (rdat[i + j] >> 12) & 0x7F;
954  tc_e = rdat[i + j] & 0xFFF;
955  conv_tc_t = (data_win - 3) * 128 + tc_t;
956 
957  // TC vector
958  tc_data.push_back(tc_id);
959  tc_data.push_back(conv_tc_t);
960  tc_data.push_back(tc_e);
961  tc_data.push_back(data_win);
962  if (tc_id < 81) {
963  if (tc_id > 75) {
964  tc_info_FE1.push_back(tc_data);
965  } else {
966  tc_info_FE2.push_back(tc_data);
967  }
968  } else if (tc_id > 512) {
969  if (tc_id > 572) {
970  tc_info_BE1.push_back(tc_data);
971  } else {
972  tc_info_BE2.push_back(tc_data);
973  }
974  } else {
975  tc_info.push_back(tc_data);
976  }
977  tc_data.clear();
978  }
979  i = i + ntc_win - 1;
980  }
981 
982  } else { // Summary off
983  if (tc_trg == true) { // summary off & TC on
984  for (int j = 0; j < ntc_win; j++) {
985  tc_id = (rdat[i + j + 2] >> 20) & 0x3FF;
986  tc_t = (rdat[i + j + 2] >> 12) & 0x7F;
987  conv_tc_t = (data_win - 3) * 128 + tc_t;
988  tc_e = rdat[i + j + 2] & 0xFFF;
989 
990  // TC vector
991  tc_data.push_back(tc_id);
992  tc_data.push_back(conv_tc_t);
993  tc_data.push_back(tc_e);
994  tc_data.push_back(data_win);
995  if (tc_id < 81) {
996  if (tc_id > 75) {
997  tc_info_FE1.push_back(tc_data);
998  } else {
999  tc_info_FE2.push_back(tc_data);
1000  }
1001  } else if (tc_id > 512) {
1002  if (tc_id > 572) {
1003  tc_info_BE1.push_back(tc_data);
1004  } else {
1005  tc_info_BE2.push_back(tc_data);
1006  }
1007  } else {
1008  tc_info.push_back(tc_data);
1009  }
1010  tc_data.clear();
1011  }
1012  i = i + ntc_win + 1;
1013  } else { // Summary off & TC off
1014  i = i + 1;
1015  }
1016  }
1017  window_num++;
1018  }
1019 
1020  // <---- Unpacking
1021 
1022  // Summary
1023  /* cppcheck-suppress variableScope */
1024  int sum_num = 0;
1025  /* cppcheck-suppress variableScope */
1026  int sum_revo = 0;
1027  int cl_theta[6] = {0};
1028  int cl_phi[6] = {0};
1029  int cl_time[6] = { -9999};
1030  int cl_energy[6] = {0};
1031  int ncl = 0;
1032  int low_multi = 0;
1033  int b2bhabha_v = 0;
1034  int b2bhabha_s = 0;
1035  int mumu = 0;
1036  int prescale = 0;
1037  int icn_over = 0;
1038  int bg_veto = 0;
1039  int icn = 0;
1040  int etot_type = 0;
1041  int etot = 0;
1042  int b1_type = 0;
1043  int b1bhabha = 0;
1044  int physics = 0;
1045  int time_type = 0;
1046  int time = 0;
1047  int ecl_bst = 0;
1048 
1049  int m_sumNum = 0;
1050 
1051  TrgEclDataBase database;
1052  TrgEclMapping mapping;
1053 
1054  vector<int> cl_1d;
1055  vector<vector<int>> cl_2d;
1056 
1057  vector<int> evt_1d_vector;
1058  vector<vector<int>> evt_2d_vector;
1059 
1060  // Store Summary
1061  int sum_size = sum_info.size();
1062  if (sum_size != 0) {
1063  for (int j = 0; j < sum_size; j++) {
1064  sum_num = sum_info[j][0];
1065  sum_revo = sum_info[j][1];
1066  if (etm_version >= 128) {
1067  ecl_bst = (sum_info[j][2] >> 26) & 0x1;
1068  }
1069  if (etm_version > 119) {
1070  cl_theta[5] = (sum_info[j][2] >> 19) & 0x7f;
1071  cl_phi[5] = (sum_info[j][2] >> 11) & 0xff;
1072  cl_time[5] = (sum_info[j][2] >> 3) & 0xff;
1073  cl_energy[5] = ((sum_info[j][2] & 0x7) << 9) + ((sum_info[j][3] >> 23) & 0x1ff);
1074 
1075  cl_theta[4] = (sum_info[j][3] >> 16) & 0x7f;
1076  cl_phi[4] = (sum_info[j][3] >> 8) & 0xff;
1077  cl_time[4] = (sum_info[j][3]) & 0xff;
1078  cl_energy[4] = (sum_info[j][4] >> 20) & 0xfff;
1079 
1080  cl_theta[3] = (sum_info[j][4] >> 13) & 0x7f;
1081  cl_phi[3] = (sum_info[j][4] >> 5) & 0xff;
1082  cl_time[3] = ((sum_info[j][4] & 0x1f) << 3) + ((sum_info[j][5] >> 29) & 0x7);
1083  cl_energy[3] = (sum_info[j][5] >> 17) & 0xfff;
1084 
1085  cl_theta[2] = (sum_info[j][5] >> 10) & 0x7f;
1086  cl_phi[2] = (sum_info[j][5] >> 2) & 0xff;
1087  cl_time[2] = ((sum_info[j][5] & 0x3) << 6) + ((sum_info[j][6] >> 26) & 0x3f);
1088  cl_energy[2] = (sum_info[j][6] >> 14) & 0xfff;
1089 
1090  cl_theta[1] = (sum_info[j][6] >> 7) & 0x7f;
1091  cl_phi[1] = ((sum_info[j][6] & 0x7f) << 1) + ((sum_info[j][7] >> 31) & 0x1);
1092  cl_time[1] = (sum_info[j][7] >> 23) & 0xff;
1093  cl_energy[1] = (sum_info[j][7] >> 11) & 0xfff;
1094 
1095  cl_theta[0] = (sum_info[j][7] >> 4) & 0x7f;
1096  cl_phi[0] = ((sum_info[j][7] & 0xf) << 4) + ((sum_info[j][8] >> 28) & 0xf);
1097  cl_time[0] = (sum_info[j][8] >> 20) & 0xff;
1098  cl_energy[0] = (sum_info[j][8] >> 8) & 0xfff;
1099 
1100  ncl = (sum_info[j][8] >> 5) & 0x7;
1101 
1102  prescale = (sum_info[j][8] >> 4) & 0x1;
1103  mumu = (sum_info[j][8] >> 3) & 0x1;
1104  b2bhabha_s = (sum_info[j][8] >> 2) & 0x1;
1105  if (etm_version >= 135) {
1106  low_multi = (((sum_info[j][2] >> 27) & 0x3) << 12) + ((sum_info[j][8] & 0x3) << 10) + ((sum_info[j][9] >> 22) & 0x3ff);
1107  } else {
1108  low_multi = ((sum_info[j][8] & 0x3) << 10) + ((sum_info[j][9] >> 22) & 0x3ff);
1109  }
1110  b2bhabha_v = (sum_info[j][9] >> 21) & 0x1;
1111  icn_over = (sum_info[j][9] >> 20) & 0x1;
1112  bg_veto = (sum_info[j][9] >> 17) & 0x7;
1113  icn = (sum_info[j][9] >> 10) & 0x7f;
1114  etot_type = (sum_info[j][9] >> 7) & 0x7;
1115  etot = ((sum_info[j][9] & 0x7f) << 6) + ((sum_info[j][10] >> 26) & 0x3f);
1116  b1_type = (sum_info[j][10] >> 12) & 0x3fff;
1117  b1bhabha = (sum_info[j][10] >> 11) & 0x1;
1118  physics = (sum_info[j][10] >> 10) & 0x1;
1119  time_type = (sum_info[j][10] >> 7) & 0x7;
1120  time = (sum_info[j][10]) & 0x7f;
1121  } else {
1122  cl_theta[5] = (sum_info[j][2] >> 24) & 0x7f;
1123  cl_phi[5] = (sum_info[j][2] >> 16) & 0xff;
1124  cl_time[5] = (sum_info[j][2] >> 8) & 0xff;
1125  cl_energy[5] = ((sum_info[j][2] & 0xff) << 4) + ((sum_info[j][3] >> 28) & 0xf);
1126 
1127  cl_theta[4] = (sum_info[j][3] >> 21) & 0x7f;
1128  cl_phi[4] = (sum_info[j][3] >> 13) & 0xff;
1129  cl_time[4] = (sum_info[j][3] >> 5) & 0xff;
1130  cl_energy[4] = ((sum_info[j][3] & 0x1f) << 7) + ((sum_info[j][4] >> 25) & 0x7f);
1131 
1132  cl_theta[3] = (sum_info[j][4] >> 18) & 0x7f;
1133  cl_phi[3] = (sum_info[j][4] >> 10) & 0xff;
1134  cl_time[3] = (sum_info[j][4] >> 2) & 0xff;
1135  cl_energy[3] = ((sum_info[j][4] & 0x3) << 10) + ((sum_info[j][5] >> 22) & 0x3ff);
1136 
1137  cl_theta[2] = (sum_info[j][5] >> 15) & 0x7f;
1138  cl_phi[2] = (sum_info[j][5] >> 7) & 0xff;
1139  cl_time[2] = ((sum_info[j][5] & 0x7f) << 1) + ((sum_info[j][6] >> 31) & 0x1);
1140  cl_energy[2] = (sum_info[j][6] >> 19) & 0xfff;
1141 
1142  cl_theta[1] = (sum_info[j][6] >> 12) & 0x7f;
1143  cl_phi[1] = (sum_info[j][6] >> 4) & 0xff;
1144  cl_time[1] = ((sum_info[j][6] & 0xf) << 4) + ((sum_info[j][7] >> 28) & 0xf);
1145  cl_energy[1] = (sum_info[j][7] >> 16) & 0xfff;
1146 
1147  cl_theta[0] = (sum_info[j][7] >> 9) & 0x7f;
1148  cl_phi[0] = (sum_info[j][7] >> 1) & 0xff;
1149  cl_time[0] = ((sum_info[j][7] & 0x1) << 7) + ((sum_info[j][8] >> 25) & 0x7f);
1150  cl_energy[0] = (sum_info[j][8] >> 13) & 0xfff;
1151 
1152  ncl = (sum_info[j][8] >> 10) & 0x7;
1153 
1154  low_multi = ((sum_info[j][8] & 0x3ff) << 2) + ((sum_info[j][9] >> 30) & 0x3);
1155  b2bhabha_v = (sum_info[j][9] >> 29) & 0x1;
1156  icn_over = (sum_info[j][9] >> 28) & 0x1;
1157  bg_veto = (sum_info[j][9] >> 25) & 0x7;
1158  icn = (sum_info[j][9] >> 18) & 0x7f;
1159  etot_type = (sum_info[j][9] >> 15) & 0x7;
1160  etot = (sum_info[j][9] >> 2) & 0x1fff;
1161 
1162  b1_type = ((sum_info[j][9] & 0x3) << 12) + ((sum_info[j][10] >> 20) & 0xfff);
1163  b1bhabha = (sum_info[j][10] >> 19) & 0x1;
1164  physics = (sum_info[j][10] >> 18) & 0x1;
1165  time_type = (sum_info[j][10] >> 15) & 0x7;
1166  time = (sum_info[j][10] >> 8) & 0x7f;
1167 
1168  b2bhabha_s = 0;
1169  mumu = 0;
1170  prescale = 0;
1171  }
1172 
1173  m_TRGECLSumArray.appendNew();
1174  m_sumNum = m_TRGECLSumArray.getEntries() - 1;
1175  m_TRGECLSumArray[m_sumNum]->setEventId(n_basf2evt);
1176  m_TRGECLSumArray[m_sumNum]->setSumNum(sum_num);
1177  m_TRGECLSumArray[m_sumNum]->setSumRevo(sum_revo);
1178  m_TRGECLSumArray[m_sumNum]->setCLTheta(cl_theta);
1179  m_TRGECLSumArray[m_sumNum]->setCLPhi(cl_phi);
1180  m_TRGECLSumArray[m_sumNum]->setCLTime(cl_time);
1181  m_TRGECLSumArray[m_sumNum]->setCLEnergy(cl_energy);
1182  m_TRGECLSumArray[m_sumNum]->setNCL(ncl);
1183  m_TRGECLSumArray[m_sumNum]->setICN(icn);
1184  m_TRGECLSumArray[m_sumNum]->setICNOver(icn_over);
1185  m_TRGECLSumArray[m_sumNum]->setLowMulti(low_multi);
1186  m_TRGECLSumArray[m_sumNum]->set3DBhabhaV(b2bhabha_v);
1187  m_TRGECLSumArray[m_sumNum]->set3DBhabhaS(b2bhabha_s);
1188  m_TRGECLSumArray[m_sumNum]->setMumu(mumu);
1189  m_TRGECLSumArray[m_sumNum]->setPrescale(prescale);
1190  m_TRGECLSumArray[m_sumNum]->set2DBhabha(b1bhabha);
1191  m_TRGECLSumArray[m_sumNum]->setBhabhaType(b1_type);
1192  m_TRGECLSumArray[m_sumNum]->setPhysics(physics);
1193  m_TRGECLSumArray[m_sumNum]->setBG(bg_veto);
1194  m_TRGECLSumArray[m_sumNum]->setEtot(etot);
1195  m_TRGECLSumArray[m_sumNum]->setEtotType(etot_type);
1196  m_TRGECLSumArray[m_sumNum]->setECLBST(ecl_bst);
1197  m_TRGECLSumArray[m_sumNum]->setTime(time);
1198  m_TRGECLSumArray[m_sumNum]->setTimeType(time_type);
1199 
1200  for (int k = 0; k < 6; k++) {
1201  cl_1d.push_back(cl_theta[k]);
1202  cl_1d.push_back(cl_phi[k]);
1203  cl_1d.push_back(cl_time[k]);
1204  cl_1d.push_back(cl_energy[k]);
1205  cl_2d.push_back(cl_1d);
1206  cl_1d.clear();
1207  }
1208  sort(cl_2d.begin(), cl_2d.end(),
1209  [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[3] > aa2[3];});
1210 
1211  evt_1d_vector.push_back(abs(sum_num - 3));
1212  evt_1d_vector.push_back(sum_revo);
1213  evt_1d_vector.push_back(sum_num);
1214  evt_1d_vector.push_back(time);
1215  for (int k = 0; k < 6; k++) {
1216  evt_1d_vector.push_back(cl_2d[k][0]);
1217  evt_1d_vector.push_back(cl_2d[k][1]);
1218  evt_1d_vector.push_back(cl_2d[k][2]);
1219  evt_1d_vector.push_back(cl_2d[k][3]);
1220  }
1221  evt_1d_vector.push_back(ncl);
1222  evt_1d_vector.push_back(low_multi);
1223  evt_1d_vector.push_back(b2bhabha_v);
1224  evt_1d_vector.push_back(b2bhabha_s);
1225  evt_1d_vector.push_back(mumu);
1226  evt_1d_vector.push_back(prescale);
1227  evt_1d_vector.push_back(icn);
1228  evt_1d_vector.push_back(icn_over);
1229  evt_1d_vector.push_back(etot_type);
1230  evt_1d_vector.push_back(etot);
1231  evt_1d_vector.push_back(ecl_bst);
1232  evt_1d_vector.push_back(b1_type);
1233  evt_1d_vector.push_back(b1bhabha);
1234  evt_1d_vector.push_back(physics);
1235  evt_1d_vector.push_back(time_type);
1236  evt_2d_vector.push_back(evt_1d_vector);
1237  evt_1d_vector.clear();
1238  }
1239  } else {
1240 
1241  for (int k = 0; k < 6; k++) {
1242  cl_theta[k] = 0;
1243  cl_phi[k] = 0;
1244  cl_time[k] = -9999;
1245  cl_energy[k] = 0;
1246  }
1247  ncl = 0;
1248  low_multi = 0;
1249  b2bhabha_v = 0;
1250  b2bhabha_s = 0;
1251  mumu = 0;
1252  prescale = 0;
1253  icn_over = 0;
1254  bg_veto = 0;
1255  icn = 0;
1256  etot_type = 0;
1257  etot = 0;
1258  ecl_bst = 0;
1259  b1_type = 0;
1260  b1bhabha = 0;
1261  physics = 0;
1262  time_type = 0;
1263  time = -9999;
1264 
1265  m_TRGECLSumArray.appendNew();
1266  m_sumNum = m_TRGECLSumArray.getEntries() - 1;
1267  m_TRGECLSumArray[m_sumNum]->setEventId(n_basf2evt);
1268  m_TRGECLSumArray[m_sumNum]->setSumNum(0);
1269  m_TRGECLSumArray[m_sumNum]->setCLTheta(cl_theta);
1270  m_TRGECLSumArray[m_sumNum]->setCLPhi(cl_phi);
1271  m_TRGECLSumArray[m_sumNum]->setCLTime(cl_time);
1272  m_TRGECLSumArray[m_sumNum]->setCLEnergy(cl_energy);
1273  m_TRGECLSumArray[m_sumNum]->setNCL(ncl);
1274  m_TRGECLSumArray[m_sumNum]->setICN(icn);
1275  m_TRGECLSumArray[m_sumNum]->setICNOver(icn_over);
1276  m_TRGECLSumArray[m_sumNum]->setLowMulti(low_multi);
1277  m_TRGECLSumArray[m_sumNum]->set3DBhabhaV(b2bhabha_v);
1278  m_TRGECLSumArray[m_sumNum]->set3DBhabhaS(b2bhabha_s);
1279  m_TRGECLSumArray[m_sumNum]->setMumu(mumu);
1280  m_TRGECLSumArray[m_sumNum]->setPrescale(prescale);
1281  m_TRGECLSumArray[m_sumNum]->set2DBhabha(b1bhabha);
1282  m_TRGECLSumArray[m_sumNum]->setBhabhaType(b1_type);
1283  m_TRGECLSumArray[m_sumNum]->setPhysics(physics);
1284  m_TRGECLSumArray[m_sumNum]->setBG(bg_veto);
1285  m_TRGECLSumArray[m_sumNum]->setEtot(etot);
1286  m_TRGECLSumArray[m_sumNum]->setEtotType(etot_type);
1287  m_TRGECLSumArray[m_sumNum]->setECLBST(ecl_bst);
1288  m_TRGECLSumArray[m_sumNum]->setTime(time);
1289  m_TRGECLSumArray[m_sumNum]->setTimeType(time_type);
1290  }
1291 
1292  // TC & TRG
1293  tc_info.insert(tc_info.end(), tc_info_FE1.begin(), tc_info_FE1.end());
1294  tc_info.insert(tc_info.end(), tc_info_FE2.begin(), tc_info_FE2.end());
1295  tc_info.insert(tc_info.end(), tc_info_BE1.begin(), tc_info_BE1.end());
1296  tc_info.insert(tc_info.end(), tc_info_BE2.begin(), tc_info_BE2.end());
1297 
1298  int m_evtNum = 0;
1299 
1300  int m_tcNum = 0;
1301  /* cppcheck-suppress variableScope */
1302  int m_tcid = 0;
1303  /* cppcheck-suppress variableScope */
1304  int m_time = -9999;
1305  /* cppcheck-suppress variableScope */
1306  int m_energy = 0;
1307  /* cppcheck-suppress variableScope */
1308  int m_win = 0;
1309  /* cppcheck-suppress variableScope */
1310  int m_revo = 0;
1311  /* cppcheck-suppress variableScope */
1312  int m_caltime = -9999;
1313 
1314  int tot_ntc = tc_info.size();
1315  /* cppcheck-suppress variableScope */
1316  int evt_ntc = 0;
1317  /* cppcheck-suppress variableScope */
1318  int evt_revo = -9999;
1319  /* cppcheck-suppress variableScope */
1320  int evt_win = 0;
1321  /* cppcheck-suppress variableScope */
1322  int evt_timing = -9999;
1323  int evt_cl_theta[6] = {0};
1324  int evt_cl_phi[6] = {0};
1325  int evt_cl_time[6] = { -9999};
1326  int evt_cl_energy[6] = {0};
1327  /* cppcheck-suppress variableScope */
1328  int evt_ncl = 0;
1329  /* cppcheck-suppress variableScope */
1330  int evt_low_multi = 0;
1331  /* cppcheck-suppress variableScope */
1332  int evt_b2bhabha_v = 0;
1333  /* cppcheck-suppress variableScope */
1334  int evt_b2bhabha_s = 0;
1335  /* cppcheck-suppress variableScope */
1336  int evt_mumu = 0;
1337  /* cppcheck-suppress variableScope */
1338  int evt_prescale = 0;
1339  /* cppcheck-suppress variableScope */
1340  int evt_icn = 0;
1341  /* cppcheck-suppress variableScope */
1342  int evt_icn_over = 0;
1343  /* cppcheck-suppress variableScope */
1344  int evt_etot_type = 0;
1345  /* cppcheck-suppress variableScope */
1346  int evt_etot = 0;
1347  /* cppcheck-suppress variableScope */
1348  int evt_ecl_bst = 0;
1349  /* cppcheck-suppress variableScope */
1350  int evt_b1_type = 0;
1351  /* cppcheck-suppress variableScope */
1352  int evt_b1bhabha = 0;
1353  /* cppcheck-suppress variableScope */
1354  int evt_physics = 0;
1355  /* cppcheck-suppress variableScope */
1356  int evt_time_type = 0;
1357  /* cppcheck-suppress variableScope */
1358  int evt_etot_all = 0;
1359  /* cppcheck-suppress variableScope */
1360  int evt_time_min = 0;
1361  /* cppcheck-suppress variableScope */
1362  int evt_time_max = 0;
1363  /* cppcheck-suppress variableScope */
1364  int evt_time_win = 0;
1365  /* cppcheck-suppress variableScope */
1366  int etot_i = 0;
1367  /* cppcheck-suppress variableScope */
1368  int etot_c = 0;
1369  /* cppcheck-suppress variableScope */
1370  int etot_f = 0;
1371  /* cppcheck-suppress variableScope */
1372  int cl_tcid = 0;
1373  /* cppcheck-suppress variableScope */
1374  int cl_thetaid = 0;
1375  /* cppcheck-suppress variableScope */
1376  int cl_phiid = 0;
1377  /* cppcheck-suppress variableScope */
1378  int m_clNum = 0;
1379 
1380 
1381  int evt_v_size = evt_2d_vector.size();
1382  if (evt_v_size != 0) {
1383  // Sort window : 3 => 4 => 2 => 5 => 1 => 6 => 7
1384  sort(evt_2d_vector.begin(), evt_2d_vector.end(),
1385  [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[0] < aa2[0];});
1386  }
1387 
1388  if (tot_ntc != 0 && flag_checksum == 0 && nnn > 7) {
1389  if (evt_v_size == 0) {
1390  // Find most energetic TC timing
1391  sort(tc_info.begin(), tc_info.end(),
1392  [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[2] > aa2[2];});
1393  evt_revo = win3_revo;
1394  evt_win = tc_info[0][3];
1395  evt_timing = tc_info[0][1];
1396  for (int k = 0; k < 6; k++) {
1397  evt_cl_theta[k] = 0;
1398  evt_cl_phi[k] = 0;
1399  evt_cl_time[k] = 0;
1400  evt_cl_energy[k] = 0;
1401  }
1402  evt_ncl = 0;
1403  evt_low_multi = 0;
1404  evt_b2bhabha_v = 0;
1405  evt_b2bhabha_s = 0;
1406  evt_mumu = 0;
1407  evt_prescale = 0;
1408  evt_icn = 0;
1409  evt_icn_over = 0;
1410  evt_etot_type = 0;
1411  evt_etot = 0;
1412  evt_ecl_bst = 0;
1413  evt_b1_type = 0;
1414  evt_b1bhabha = 0;
1415  evt_physics = 0;
1416  evt_time_type = 0;
1417  } else {
1418  evt_revo = evt_2d_vector[0][1];
1419  evt_win = evt_2d_vector[0][2];
1420  evt_timing = evt_2d_vector[0][3];
1421  for (int k = 0; k < 6; k++) {
1422  evt_cl_theta[k] = evt_2d_vector[0][4 + k * 4];
1423  evt_cl_phi[k] = evt_2d_vector[0][5 + k * 4];
1424  evt_cl_time[k] = evt_2d_vector[0][6 + k * 4];
1425  evt_cl_energy[k] = evt_2d_vector[0][7 + k * 4];
1426  }
1427  evt_ncl = evt_2d_vector[0][28];
1428  evt_low_multi = evt_2d_vector[0][29];
1429  evt_b2bhabha_v = evt_2d_vector[0][30];
1430  evt_b2bhabha_s = evt_2d_vector[0][31];
1431  evt_mumu = evt_2d_vector[0][32];
1432  evt_prescale = evt_2d_vector[0][33];
1433  evt_icn = evt_2d_vector[0][34];
1434  evt_icn_over = evt_2d_vector[0][35];
1435  evt_etot_type = evt_2d_vector[0][36];
1436  evt_etot = evt_2d_vector[0][37];
1437  evt_ecl_bst = evt_2d_vector[0][38];
1438  evt_b1_type = evt_2d_vector[0][39];
1439  evt_b1bhabha = evt_2d_vector[0][40];
1440  evt_physics = evt_2d_vector[0][41];
1441  evt_time_type = evt_2d_vector[0][42];
1442  }
1443  // Sort by TC number
1444  sort(tc_info.begin(), tc_info.end(),
1445  [](const vector<int>& aa1, const vector<int>& aa2) {return aa1[0] < aa2[0];});
1446 
1447  for (int ii = 0; ii < tot_ntc; ii++) {
1448  m_tcid = tc_info[ii][0];
1449  m_time = tc_info[ii][1];
1450  m_energy = tc_info[ii][2];
1451  m_win = tc_info[ii][3];
1452  m_revo = win3_revo;
1453  m_caltime = m_time - ((evt_win - 3) * 128 + evt_timing);
1454  m_TRGECLTCArray.appendNew();
1455  m_tcNum = m_TRGECLTCArray.getEntries() - 1;
1456  m_TRGECLTCArray[m_tcNum]->setEventId(n_basf2evt);
1457  m_TRGECLTCArray[m_tcNum]->setTCId(m_tcid);
1458  m_TRGECLTCArray[m_tcNum]->setTCTime(m_time);
1459  m_TRGECLTCArray[m_tcNum]->setTCCALTime(m_caltime);
1460  m_TRGECLTCArray[m_tcNum]->setHitWin(m_win);
1461  m_TRGECLTCArray[m_tcNum]->setRevoFAM(m_revo);
1462  m_TRGECLTCArray[m_tcNum]->setTCEnergy(m_energy);
1463  m_TRGECLTCArray[m_tcNum]->setChecksum(flag_checksum);
1464 
1465  if (m_win == evt_win || m_win == evt_win + 1) evt_ntc++;
1466  if (m_win == evt_win - 1) {
1467  etot_i += m_energy;
1468  }
1469  if (m_win == evt_win) {
1470  etot_c += m_energy;
1471  }
1472  if (m_win == evt_win + 1) {
1473  etot_f += m_energy;
1474  }
1475  }
1476 
1477  if (etot_i == 0 && etot_f == 0) {
1478  evt_etot_all = etot_c;
1479  evt_time_min = - evt_timing;
1480  evt_time_max = 256 - evt_timing;
1481  evt_time_win = 1;
1482  } else if (etot_i >= etot_f) {
1483  evt_etot_all = etot_c + etot_i;
1484  evt_time_min = -128 - evt_timing;
1485  evt_time_max = 128 - evt_timing;
1486  evt_time_win = -1;
1487  } else {
1488  evt_etot_all = etot_c + etot_f;
1489  evt_time_min = - evt_timing;
1490  evt_time_max = 256 - evt_timing;
1491  evt_time_win = 1;
1492  }
1493 
1494  for (int icluster = 0; icluster < 6; icluster++) {
1495  if (evt_cl_energy[icluster] == 0 || evt_cl_theta[icluster] == 0 || evt_cl_phi[icluster] == 0) {continue;}
1496  cl_tcid = mapping.getTCIdFromPosition(evt_cl_theta[icluster], evt_cl_phi[icluster]);
1497  if (cl_tcid == 0) {continue;}
1498  cl_thetaid = mapping.getTCThetaIdFromTCId(cl_tcid);
1499  cl_phiid = mapping.getTCPhiIdFromTCId(cl_tcid);
1500 
1501  m_TRGECLClusterArray.appendNew();
1502  m_clNum = m_TRGECLClusterArray.getEntries() - 1;
1503  m_TRGECLClusterArray[m_clNum]->setEventId(n_basf2evt);
1504  m_TRGECLClusterArray[m_clNum]->setClusterId(icluster);
1505  m_TRGECLClusterArray[m_clNum]->setEventRevo(evt_revo);
1506 
1507  m_TRGECLClusterArray[m_clNum]->setMaxTCId(cl_tcid); // center of Cluster
1508  m_TRGECLClusterArray[m_clNum]->setMaxThetaId(cl_thetaid);
1509  m_TRGECLClusterArray[m_clNum]->setMaxPhiId(cl_phiid);
1510  m_TRGECLClusterArray[m_clNum]->setClusterId(icluster);
1511  m_TRGECLClusterArray[m_clNum]->setEnergyDep((double)evt_cl_energy[icluster] * 5.25); // MeV
1512  m_TRGECLClusterArray[m_clNum]->setTimeAve((double)evt_cl_time[icluster]);
1513  m_TRGECLClusterArray[m_clNum]->setPositionX(mapping.getTCPosition(cl_tcid).X());
1514  m_TRGECLClusterArray[m_clNum]->setPositionY(mapping.getTCPosition(cl_tcid).Y());
1515  m_TRGECLClusterArray[m_clNum]->setPositionZ(mapping.getTCPosition(cl_tcid).Z());
1516  }
1517  m_TRGECLEvtArray.appendNew();
1518  m_evtNum = m_TRGECLEvtArray.getEntries() - 1;
1519  m_TRGECLEvtArray[m_evtNum]->setEventId(n_basf2evt);
1520  m_TRGECLEvtArray[m_evtNum]->setETM(etm_version);
1521  m_TRGECLEvtArray[m_evtNum]->setL1Revo(l1_revo);
1522  m_TRGECLEvtArray[m_evtNum]->setEvtRevo(evt_revo);
1523  m_TRGECLEvtArray[m_evtNum]->setEvtWin(evt_win);
1524  m_TRGECLEvtArray[m_evtNum]->setEvtTime(evt_timing);
1525  m_TRGECLEvtArray[m_evtNum]->setNTC(evt_ntc);
1526  m_TRGECLEvtArray[m_evtNum]->setCLTheta(evt_cl_theta);
1527  m_TRGECLEvtArray[m_evtNum]->setCLPhi(evt_cl_phi);
1528  m_TRGECLEvtArray[m_evtNum]->setCLTime(evt_cl_time);
1529  m_TRGECLEvtArray[m_evtNum]->setCLEnergy(evt_cl_energy);
1530  m_TRGECLEvtArray[m_evtNum]->setNCL(evt_ncl);
1531  m_TRGECLEvtArray[m_evtNum]->setLowMulti(evt_low_multi);
1532  m_TRGECLEvtArray[m_evtNum]->set3DBhabhaV(evt_b2bhabha_v);
1533  m_TRGECLEvtArray[m_evtNum]->set3DBhabhaS(evt_b2bhabha_s);
1534  m_TRGECLEvtArray[m_evtNum]->setMumu(evt_mumu);
1535  m_TRGECLEvtArray[m_evtNum]->setPrescale(evt_prescale);
1536  m_TRGECLEvtArray[m_evtNum]->setICN(evt_icn);
1537  m_TRGECLEvtArray[m_evtNum]->setICNOver(evt_icn_over);
1538  m_TRGECLEvtArray[m_evtNum]->setEtotType(evt_etot_type);
1539  m_TRGECLEvtArray[m_evtNum]->setEtot(evt_etot);
1540  m_TRGECLEvtArray[m_evtNum]->setECLBST(evt_ecl_bst);
1541  m_TRGECLEvtArray[m_evtNum]->set2DBhabha(evt_b1bhabha);
1542  m_TRGECLEvtArray[m_evtNum]->setBhabhaType(evt_b1_type);
1543  m_TRGECLEvtArray[m_evtNum]->setPhysics(evt_physics);
1544  m_TRGECLEvtArray[m_evtNum]->setTimeType(evt_time_type);
1545  m_TRGECLEvtArray[m_evtNum]->setCheckSum(flag_checksum);
1546  m_TRGECLEvtArray[m_evtNum]->setEvtExist(1);
1547  m_TRGECLEvtArray[m_evtNum]->setTRGTYPE(trgtype);
1548  m_TRGECLEvtArray[m_evtNum]->setEtotAll(evt_etot_all);
1549  m_TRGECLEvtArray[m_evtNum]->setEvtTimeMin(evt_time_min);
1550  m_TRGECLEvtArray[m_evtNum]->setEvtTimeMax(evt_time_max);
1551  m_TRGECLEvtArray[m_evtNum]->setEvtTimeWin(evt_time_win);
1552  } else {
1553  m_TRGECLTCArray.appendNew();
1554  m_tcNum = m_TRGECLTCArray.getEntries() - 1;
1555  m_TRGECLTCArray[m_tcNum]->setEventId(n_basf2evt);
1556  m_TRGECLTCArray[m_tcNum]->setTCId(0);
1557  m_TRGECLTCArray[m_tcNum]->setTCTime(-9999);
1558  m_TRGECLTCArray[m_tcNum]->setTCCALTime(-9999);
1559  m_TRGECLTCArray[m_tcNum]->setHitWin(-9999);
1560  m_TRGECLTCArray[m_tcNum]->setRevoFAM(-9999);
1561  m_TRGECLTCArray[m_tcNum]->setTCEnergy(0);
1562  m_TRGECLTCArray[m_tcNum]->setChecksum(flag_checksum);
1563 
1564  m_TRGECLEvtArray.appendNew();
1565  m_evtNum = m_TRGECLEvtArray.getEntries() - 1;
1566  m_TRGECLEvtArray[m_evtNum]->setEventId(n_basf2evt);
1567  m_TRGECLEvtArray[m_evtNum]->setETM(etm_version);
1568  m_TRGECLEvtArray[m_evtNum]->setL1Revo(-9999);
1569  m_TRGECLEvtArray[m_evtNum]->setEvtTime(-9999);
1570  m_TRGECLEvtArray[m_evtNum]->setEvtRevo(-9999);
1571  m_TRGECLEvtArray[m_evtNum]->setEvtWin(-9999);
1572  m_TRGECLEvtArray[m_evtNum]->setNTC(0);
1573  for (int k = 0; k < 6; k++) {
1574  evt_cl_theta[k] = 0;
1575  evt_cl_phi[k] = 0;
1576  evt_cl_time[k] = -9999;
1577  evt_cl_energy[k] = 0;
1578  }
1579  m_TRGECLEvtArray[m_evtNum]->setCLTheta(evt_cl_theta);
1580  m_TRGECLEvtArray[m_evtNum]->setCLPhi(evt_cl_phi);
1581  m_TRGECLEvtArray[m_evtNum]->setCLTime(evt_cl_time);
1582  m_TRGECLEvtArray[m_evtNum]->setCLEnergy(evt_cl_energy);
1583  m_TRGECLEvtArray[m_evtNum]->setNCL(0);
1584  m_TRGECLEvtArray[m_evtNum]->setLowMulti(0);
1585  m_TRGECLEvtArray[m_evtNum]->set3DBhabhaV(0);
1586  m_TRGECLEvtArray[m_evtNum]->set3DBhabhaS(0);
1587  m_TRGECLEvtArray[m_evtNum]->setMumu(0);
1588  m_TRGECLEvtArray[m_evtNum]->setPrescale(0);
1589  m_TRGECLEvtArray[m_evtNum]->setICN(0);
1590  m_TRGECLEvtArray[m_evtNum]->setICNOver(0);
1591  m_TRGECLEvtArray[m_evtNum]->setEtotType(0);
1592  m_TRGECLEvtArray[m_evtNum]->setEtot(0);
1593  m_TRGECLEvtArray[m_evtNum]->setECLBST(0);
1594  m_TRGECLEvtArray[m_evtNum]->set2DBhabha(0);
1595  m_TRGECLEvtArray[m_evtNum]->setBhabhaType(0);
1596  m_TRGECLEvtArray[m_evtNum]->setPhysics(0);
1597  m_TRGECLEvtArray[m_evtNum]->setTimeType(0);
1598  m_TRGECLEvtArray[m_evtNum]->setCheckSum(flag_checksum);
1599  m_TRGECLEvtArray[m_evtNum]->setEvtExist(0);
1600  m_TRGECLEvtArray[m_evtNum]->setTRGTYPE(trgtype);
1601  m_TRGECLEvtArray[m_evtNum]->setEtotAll(0);
1602  m_TRGECLEvtArray[m_evtNum]->setEvtTimeMin(-9999);
1603  m_TRGECLEvtArray[m_evtNum]->setEvtTimeMax(-9999);
1604  m_TRGECLEvtArray[m_evtNum]->setEvtTimeWin(0);
1605  }
1606 
1607  return;
1608 }
1609 
Base class for Modules.
Definition: Module.h:72
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
The Raw TOP class Class for RawCOPPER class data taken by TOP Currently, this class is almost same as...
Definition: RawTRG.h:27
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
virtual ~TRGECLUnpackerModule()
Destructor.
void initialize() override
Initilizes TRGECLUnpackerModuel.
void event() override
Called event by event.
virtual void readCOPPEREvent(RawTRG *, int, int, int)
Read data from TRG copper.
void endRun() override
Called when run ended.
StoreArray< TRGECLUnpackerSumStore > m_TRGECLSumArray
ECL Trigger Unpacker Summary output.
void terminate() override
Called when processing ended.
StoreArray< TRGECLUnpackerStore > m_TRGECLTCArray
ECL Trigger Unpacker TC output.
void beginRun() override
Called when new run started.
StoreArray< TRGECLUnpackerEvtStore > m_TRGECLEvtArray
ECL Trigger Unpacker Event output.
std::string version() const
returns version of TRGECLUnpackerModule.
virtual void checkBuffer_v136(int *, int)
Unpacker main function for upto version 136.
StoreObjPtr< EventLevelClusteringInfo > m_eventLevelClusteringInfo
EventLevelClusteringInfo.
virtual void checkBuffer(int *, int)
Unpacker main function.
StoreArray< TRGECLCluster > m_TRGECLClusterArray
ECL Trigger Cluster output.
class TrgEclDataBase;
A class of TC Mapping.
Definition: TrgEclMapping.h:26
int getTCThetaIdFromTCId(int)
get [TC Theta ID] from [TC ID]
int getTCIdFromPosition(int, int)
get TCId from phi and theta position(LSB = 1.4)
TVector3 getTCPosition(int)
TC position (cm)
int getTCPhiIdFromTCId(int)
get [TC Phi ID] from [TC ID]
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
int GetDetectorNwords(int n, int finesse_num)
get Detector buffer length
Definition: RawCOPPER.h:657
int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
Definition: RawCOPPER.h:681
Abstract base class for different kinds of events.