Belle II Software  release-08-01-10
TRGCDCT3DConverterModule.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 // $Id$
10 //---------------------------------------------------------------
11 // Filename : TRGCDCT3DConverterModule.cc
12 // Section :
13 // Owner :
14 // Email :
15 //---------------------------------------------------------------
16 // Description : TRGCDCT3DConverter Module
17 //---------------------------------------------------------------
18 // $Log$
19 //---------------------------------------------------------------
20 
21 
22 #include <trg/cdc/modules/trgcdct3dConverter/TRGCDCT3DConverterModule.h>
23 #include <bitset>
24 #include "trg/cdc/Fitter3D.h"
25 #include "trg/cdc/Fitter3DUtility.h"
26 #include "trg/cdc/JSignal.h"
27 #include "trg/cdc/JSignalData.h"
28 #include "boost/multi_array.hpp"
29 
30 using namespace boost;
31 using namespace std;
32 using namespace Belle2;
33 using namespace TRGCDCT3DCONVERTERSPACE;
35 REG_MODULE(TRGCDCT3DConverter);
36 
37 string TRGCDCT3DConverterModule::version() const
38 {
39  return string("1.00");
40 }
41 
42 TRGCDCT3DConverterModule::TRGCDCT3DConverterModule()
43  : Module::Module()
44 {
46  string desc = "TRGCDCT3DConverterModule(" + version() + ")";
47  setDescription(desc);
48  addParam("hitCollectionName", m_hitCollectionName,
49  "Name of the input StoreArray of CDCTriggerSegmentHits.",
50  string("CDCTriggerSegmentHits0"));
51  addParam("addTSToDatastore", m_addTSToDatastore,
52  "If true, adds TS to datastore",
53  true);
54  addParam("EventTimeName", m_EventTimeName,
55  "Name of the event time object.",
56  string("BinnedEventT00"));
57  addParam("addEventTimeToDatastore", m_addEventTimeToDatastore,
58  "If true, adds event time to datastore",
59  true);
60  addParam("inputCollectionName", m_inputCollectionName,
61  "Name of the StoreArray holding the input tracks from the 2D finder.",
62  string("TRGCDC2DFinderTracks0"));
63  addParam("add2DFinderToDatastore", m_add2DFinderToDatastore,
64  "If true, adds 2D Finder results to datastore",
65  true);
66  addParam("outputCollectionName", m_outputCollectionName,
67  "Name of the StoreArray holding the 3D output tracks.",
68  string("TRGCDC3DFitterTracks0"));
69  addParam("add3DToDatastore", m_add3DToDatastore,
70  "If true, adds 3D results to datastore",
71  true);
72  addParam("fit3DWithTSIM", m_fit3DWithTSIM,
73  "0: use firmware results. 1: Fits with fast TSIM. 2: Fits with firm TSIM",
74  unsigned(0));
75  addParam("firmwareResultCollectionName", m_firmwareResultCollectionName,
76  "Name of the StoreArray holding the firmware results.",
77  string("TRGCDCT3DUnpackerStores0"));
78  addParam("isVerbose", m_isVerbose,
79  "If not zero, prints detail information.",
80  unsigned(0));
81  B2INFO("TRGCDCT3DConverter: Constructor done.");
82 }
83 
85 {
86 }
87 
89 {
90 }
91 
93 {
99 
102 
104 }
105 
107 {
108 }
109 
111 {
112 }
113 
115 {
116  //cout<<"Event"<<endl;
117 
118  if (m_addTSToDatastore) {
119  // Process firmware stereo TS
120  // stTsfFirmwareInfo[stSL][tsIndex][iClk][id, rt, lr, pr, foundTime]
121  multi_array<double, 4> stTsfFirmwareInfo{extents[4][15][48][5]};
122  storeTSFirmwareData(stTsfFirmwareInfo);
123 
124  // stTsfInfo[stSL][iTS][id, rt, lr, pr, foundTime]
125  multi_array<double, 3> stTsfInfo{extents[4][0][5]};
126 
127  filterTSData(stTsfFirmwareInfo, stTsfInfo);
128  // Add to TS datastore
129  addTSDatastore(stTsfInfo, 1);
130  }
131 
133  // Process firmware 2D
134 
135  // t2DFirmwareInfo[tIndex][iClk][valid, isOld, charge, rho, phi0]
136  multi_array<double, 3> t2DFirmwareInfo{extents[4][48][5]};
137  // t2DTsfFirmwareInfo[tIndex][iClk][axSL][id, rt, lr, pr]
138  multi_array<double, 4> t2DTsfFirmwareInfo{extents[4][48][5][4]};
139  store2DFirmwareData(t2DFirmwareInfo, t2DTsfFirmwareInfo);
140 
141  // t2DInfo[tIndex][charge, rho, phi0]
142  multi_array<double, 2> t2DInfo{extents[0][3]};
143  // t2DTsfInfo[tIndex][axSL][id, rt, lr, pr, -9999]
144  multi_array<double, 3> t2DTsfInfo{extents[0][5][5]};
145 
146  filter2DData(t2DFirmwareInfo, t2DTsfFirmwareInfo, t2DInfo, t2DTsfInfo);
147  add2DDatastore(t2DInfo, t2DTsfInfo);
148  }
149 
152  // add eventTime
153  bool validEventTime = 0;
154  int eventTime = 0;
155  for (int iClk = 0; iClk < m_firmwareResults.getEntries() - 17 - 1; iClk++) {
157  if (result->m_t3dtrk0_evtTimeValid_delay) {
158  validEventTime = 1;
159  eventTime = result->m_t3dtrk0_evtTime_delay;
160  }
161  }
162  if (validEventTime) {
163  m_eventTime->addBinnedEventT0(eventTime, Const::CDC);
164  }
165  if (m_isVerbose) {
166  if (validEventTime) cout << "[ET] valid: 1 eventTime:" << eventTime << endl;
167  else cout << "[ET] valid: 0" << endl;
168  }
169  }
170 
171  if (m_add3DToDatastore) {
172  // t3DFirmwareInfo[tIndex][iClk][2DValid, 2DisOld, TSFValid, EventTimeValid, eventTime, charge, rho, phi0, z0, cot, zchi]
173  multi_array<double, 3> t3DFirmwareInfo{extents[4][48][11]};
174 
175  // m_fit3DWithTSIM 0:firmware 1:fastSim 2:firmSim
176  // Use Firmware results
177  if (m_fit3DWithTSIM == 0) store3DFirmwareData(t3DFirmwareInfo);
178  // Use fast sim with debug
179  if (m_fit3DWithTSIM == 1) store3DFastSimData(t3DFirmwareInfo);
180  // Use firm sim with debug
181  if (m_fit3DWithTSIM == 2) store3DFirmSimData(t3DFirmwareInfo);
182 
183  // t3DInfo[eventTime, charge, rho, phi0, z0, cot, zchi]
184  multi_array<double, 2> t3DInfo{extents[0][7]};
185 
186 
187  filter3DData(t3DFirmwareInfo, t3DInfo);
188 
189  if (m_fit3DWithTSIM == 0) add3DDatastore(t3DInfo);
190  else add3DDatastore(t3DInfo, 0);
191  }
192 
193  if (m_isVerbose > 1) {
194  debug3DFirmware();
195  }
196 
197 
198 
199  //vector<int> t2DClks;
200  //vector<int> t2DTrackId;
201  //filter2DData(t2DFirmwareInfo, t2DTsfFirmwareInfo, t2DInfo, t2DTsfInfo, t2DClks, t2DTrackId);
202 
205  //for(unsigned iTrack = 0; iTrack < t2DInfo.size(); iTrack++)
206  //{
207  // cout<<"[2D] iClk: "<<t2DClks[iTrack]<<" trackid: "<<t2DTrackId[iTrack]<<" charge:"<<t2DInfo[iTrack][0]<<endl;
208  // int rho_s = t2DInfo[iTrack][1];
209  // int rho_2Dint = toSigned(rho_s, 7);
210  // double rho = 0.3*34/30/1.5e-4/abs(rho_2Dint);
211  // int rho_3Dint = rho*(pow(2,11)-0.5)/2500;
212  // cout<<" rho_s "<<rho_s<<" rho_int: "<<rho_2Dint<<" rho: "<<rho<<" rho_3Dint: "<<rho_3Dint<<endl;;
213  // //cout<<" phi0: "<<t2DInfo[iTrack][2]<<" s: "<<toSigned(t2DInfo[iTrack][2],13)<<" convert: "<<endl;
214  // //for(unsigned iAx = 0; iAx < t2DTsfInfo[iTrack].size(); iAx++)
215  // //{
216  // // cout<<" iAx: "<<iAx<<" id: "<<t2DTsfInfo[iTrack][iAx][0]<<" lr: "<<t2DTsfInfo[iTrack][iAx][2]<<endl;
217  // //}
218  //}
220  //for (unsigned iTrack = 0; iTrack < t3DInfo.size(); iTrack++)
221  //{
222  // cout<<"iClk: "<<t3DClks[iTrack]<<" trackid: "<<t3DTrackId[iTrack]<<" validTS: "<<bitset<4>(t3DInfo[iTrack][0])<<" z0: "<<t3DInfo[iTrack][1]<<" cot: "<<t3DInfo[iTrack][2]<<" zchi: "<<t3DInfo[iTrack][3]<<endl;
223  //}
224 
225 
226 }
227 
228 int TRGCDCT3DConverterModule::toTSID(int iSL, int iWire)
229 {
230  vector<int> nWires = {160, 160, 192, 224, 256, 288, 320, 352, 384};
231  int id = 0;
232  for (int i = 0; i < (int)iSL; i++) {
233  id += nWires[i];
234  }
235 
236 //Correct the segmentID. The zero points of raw segmentID for four boards are different.
237  if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore0") {
238  id = id + iWire + nWires[(int)iSL] / 4.0 * 0;
239  if (iWire + nWires[(int)iSL] / 4.0 * 0 > nWires[(int)iSL]) {
240  id = id - nWires[(int)iSL];
241  }
242  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore1") {
243  id = id + iWire + nWires[(int)iSL] / 4.0 * 1;
244  if (iWire + nWires[(int)iSL] / 4.0 * 1 > nWires[(int)iSL]) {
245  id = id - nWires[(int)iSL];
246  }
247  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore2") {
248  id = id + iWire + nWires[(int)iSL] / 4.0 * 2;
249  if (iWire + nWires[(int)iSL] / 4.0 * 2 > nWires[(int)iSL]) {
250  id = id - nWires[(int)iSL];
251  }
252  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore3") {
253  id = id + iWire + nWires[(int)iSL] / 4.0 * 3;
254  if (iWire + nWires[(int)iSL] / 4.0 * 3 > nWires[(int)iSL]) {
255  id = id - nWires[(int)iSL];
256  }
257  }
258  //cout<<"toID: iSL"<<iSL<<" iWire:"<<iWire<<" id:"<<id<<endl;
259  return id;
260 }
261 
262 int TRGCDCT3DConverterModule::toSigned(int value, int nBits)
263 {
264  int signMask = 1 << (nBits - 1);
265  if (value & signMask) {
266  int mask = (1 << nBits) - 1;
267  value |= ~mask;
268  }
269  return value;
270 }
271 
273 //int TRGCDCT3DConverterModule::t2DRhoTot3DRho(int value, bool isSigned)
274 //{
275 // if (value == 0) return 2047;
276 // if (value == 125) {
277 // B2WARNING("Bug in 2D parser.");
278 // return 451;
279 // }
280 // if (isSigned) return int(0.3 * 34 / 30 / 1.5e-4 / abs(toSigned(value, 7)) * (pow(2, 11) - 0.5) / 2500);
281 // else return int(0.3 * 34 / 30 / 1.5e-4 / abs(value) * (pow(2, 11) - 0.5) / 2500);
282 //}
283 //
284 
286 {
287  double phiReal = 45 + 90. / 80 * (1 + phi);
288  if (toSigned(rho, 7) >= 0) phiReal -= 90;
289  else phiReal += 90;
290 
291  while (phiReal > 180) {
292  phiReal -= 360;
293  }
294  while (phiReal < -180) {
295  phiReal += 360;
296  }
297 
298  int phiInt = phiReal * (pow(2, 12) - 0.5) / 180;
299  return phiInt;
300 }
301 
302 void TRGCDCT3DConverterModule::filterTSData(multi_array<double, 4>& tsfFirmwareInfo,
303  multi_array<double, 3>& tsfInfo)
304 {
305  // iSl is stereo SL index
306  for (unsigned iSL = 0; iSL < tsfFirmwareInfo.shape()[0]; iSL++) {
307  unsigned iTS_filter = 0;
308  for (unsigned iTS = 0; iTS < tsfFirmwareInfo.shape()[1]; iTS++) {
309  for (unsigned iClk = 0; iClk < tsfFirmwareInfo.shape()[2]; iClk++) {
310  double id = tsfFirmwareInfo[iSL][iTS][iClk][0];
311  double rt = tsfFirmwareInfo[iSL][iTS][iClk][1];
312  double lr = tsfFirmwareInfo[iSL][iTS][iClk][2];
313  double pr = tsfFirmwareInfo[iSL][iTS][iClk][3];
314  double ft = tsfFirmwareInfo[iSL][iTS][iClk][4];
315 
316  if (pr != 0) {
317  double ts_ref[5] = {id, rt, lr, pr, ft};
318  multi_array_ref<double, 1> ts((double*)ts_ref, extents[5]);
319  tsfInfo.resize(extents[4][tsfInfo.shape()[1] + 1][5]);
320  tsfInfo[iSL][iTS_filter++] = ts;
321  }
322 
323  }
324  }
325  }
326 }
327 
330 //void TRGCDCT3DConverterModule::filter3DData(std::vector<std::vector<std::vector<double> > > & t3DFirmwareInfo, std::vector<std::vector<double> > & t3DInfo, std::vector<int> & t3DClks, std::vector<int> & t3DTrackId)
331 //{
332 // for (unsigned iTrack = 0; iTrack < t3DFirmwareInfo.size(); iTrack++)
333 // {
334 // for (unsigned iClk = 0; iClk < t3DFirmwareInfo[iTrack].size(); iClk++)
335 // {
336 // double valid2D = t3DFirmwareInfo[iTrack][iClk][0];
337 // double validTS = t3DFirmwareInfo[iTrack][iClk][1];
338 // bitset<4> tsf_fnf(validTS);
339 // int nStHits = int(tsf_fnf[0]) + int(tsf_fnf[1]) + int(tsf_fnf[2]) + int(tsf_fnf[3]);
340 // if (valid2D != 1 || nStHits < 2) continue;
341 // double z0 = t3DFirmwareInfo[iTrack][iClk][2];
342 // double cot = t3DFirmwareInfo[iTrack][iClk][3];
343 // double zchi = t3DFirmwareInfo[iTrack][iClk][4];
344 // //cout<<"valid2D:"<<valid2D<<" tsf_fnf: "<<tsf_fnf<<" nSt: "<<nStHits<<endl;
345 // vector<double> track = {validTS, z0, cot, zchi};
346 // t3DInfo.push_back(track);
347 // t3DClks.push_back(iClk);
348 // t3DTrackId.push_back(iTrack);
349 // }
350 // }
351 //}
352 
353 
354 // t2DFirmwareInfo[tIndex][iClk][valid, isOld, charge, rho, phi0]
355 // t2DTsfFirmwareInfo[tIndex][iClk][axSL][id, rt, lr, pr]
356 // t2DInfo[tIndex][charge, rho, phi0]
357 // t2DTsfInfo[tIndex][axSL][id, rt, lr, pr, -9999]
358 void TRGCDCT3DConverterModule::filter2DData(multi_array<double, 3>& t2DFirmwareInfo,
359  multi_array<double, 4>& t2DTsfFirmwareInfo, multi_array<double, 2>& t2DInfo,
360  multi_array<double, 3>& t2DTsfInfo)
361 {
362 
363  for (unsigned iTrack = 0; iTrack < t2DFirmwareInfo.shape()[0]; iTrack++) {
364  for (unsigned iClk = 0; iClk < t2DFirmwareInfo.shape()[1]; iClk++) {
365  if (t2DFirmwareInfo[iTrack][iClk][0] == 0) continue;
366  // TODO make an algorithm to follow the track.
367 
368  //choose new tracks
369  //if (t2DInfo.shape()[0] != 0 && t2DFirmwareInfo[iTrack][iClk][1] == 1) continue;
370 
371  double track_ref[3] = {t2DFirmwareInfo[iTrack][iClk][2], t2DFirmwareInfo[iTrack][iClk][3], t2DFirmwareInfo[iTrack][iClk][4]};
372  multi_array_ref<double, 1> track((double*)track_ref, extents[3]);
373  t2DInfo.resize(extents[t2DInfo.shape()[0] + 1][3]);
374  t2DInfo[t2DInfo.shape()[0] - 1] = track;
375 
376 
377  multi_array<double, 2> axTSInfo{extents[5][5]};
378  for (unsigned iAx = 0; iAx < t2DTsfFirmwareInfo.shape()[2]; iAx++) {
379  double id = t2DTsfFirmwareInfo[iTrack][iClk][iAx][0];
380  double rt = t2DTsfFirmwareInfo[iTrack][iClk][iAx][1];
381  double lr = t2DTsfFirmwareInfo[iTrack][iClk][iAx][2];
382  double pr = t2DTsfFirmwareInfo[iTrack][iClk][iAx][3];
383 
384  axTSInfo[iAx][0] = id;
385  axTSInfo[iAx][1] = rt;
386  axTSInfo[iAx][2] = lr;
387  axTSInfo[iAx][3] = pr;
388  axTSInfo[iAx][4] = -9999;
389  }
390  t2DTsfInfo.resize(extents[t2DTsfInfo.shape()[0] + 1][5][5]);
391  t2DTsfInfo[t2DTsfInfo.shape()[0] - 1] = axTSInfo;
392  }
393  }
394  //for(unsigned iTrack = 0; iTrack < t2DInfo.size(); iTrack++)
395  //{
396  // cout<<"iTrack: "<<iTrack<<" charge:"<<t2DInfo[iTrack][0]<<" rho: "<<t2DInfo[iTrack][1]<<" phi0: "<<t2DInfo[iTrack][2]<<endl;
397  // for(unsigned iAx = 0; iAx < t2DTsfInfo[iTrack].size(); iAx++)
398  // {
399  // cout<<" iAx: "<<iAx<<" id: "<<t2DTsfInfo[iTrack][iAx][0]<<" lr: "<<t2DTsfInfo[iTrack][iAx][2]<<endl;
400  // }
401  //}
402 }
403 
408 //void TRGCDCT3DConverterModule::filter2DData(std::vector<std::vector<std::vector<double> > > & t2DFirmwareInfo, std::vector<std::vector<std::vector<std::vector<double> > > > & t2DTsfFirmwareInfo, std::vector<std::vector<double> > & t2DInfo, std::vector<std::vector<std::vector<double> > > & t2DTsfInfo, std::vector<int> & t2DClks, std::vector<int> & t2DTrackId)
409 //{
410 // for (unsigned iTrack = 0; iTrack < t2DFirmwareInfo.size(); iTrack++)
411 // {
412 // for (unsigned iClk = 0; iClk < t2DFirmwareInfo[iTrack].size(); iClk++)
413 // {
414 // if (t2DFirmwareInfo[iTrack][iClk][0] == 0) continue;
415 //
416 // vector<double> track = {t2DFirmwareInfo[iTrack][iClk][1], t2DFirmwareInfo[iTrack][iClk][2], t2DFirmwareInfo[iTrack][iClk][3]};
417 // t2DInfo.push_back(track);
418 //
419 // vector<vector< double> > axTSInfo (5, vector<double> (5));
420 // for (unsigned iAx = 0; iAx < t2DTsfFirmwareInfo[iTrack][iClk].size(); iAx++)
421 // {
422 // double id = t2DTsfFirmwareInfo[iTrack][iClk][iAx][0];
423 // double rt = t2DTsfFirmwareInfo[iTrack][iClk][iAx][1];
424 // double lr = t2DTsfFirmwareInfo[iTrack][iClk][iAx][2];
425 // double pr = t2DTsfFirmwareInfo[iTrack][iClk][iAx][3];
426 //
427 // axTSInfo[iAx][0] = id;
428 // axTSInfo[iAx][1] = rt;
429 // axTSInfo[iAx][2] = lr;
430 // axTSInfo[iAx][3] = pr;
431 // axTSInfo[iAx][4] = -9999;
432 // }
433 // t2DTsfInfo.push_back(axTSInfo);
434 //
435 // t2DClks.push_back(iClk);
436 // t2DTrackId.push_back(iTrack);
437 // }
438 // }
439 // //for(unsigned iTrack = 0; iTrack < t2DInfo.size(); iTrack++)
440 // //{
441 // // cout<<"iTrack: "<<iTrack<<" charge:"<<t2DInfo[iTrack][0]<<" rho: "<<t2DInfo[iTrack][1]<<" phi0: "<<t2DInfo[iTrack][2]<<endl;
442 // // for(unsigned iAx = 0; iAx < t2DTsfInfo[iTrack].size(); iAx++)
443 // // {
444 // // cout<<" iAx: "<<iAx<<" id: "<<t2DTsfInfo[iTrack][iAx][0]<<" lr: "<<t2DTsfInfo[iTrack][iAx][2]<<endl;
445 // // }
446 // // cout<<" iClk: "<<t2DClks[iTrack]<<" trackid: "<<t2DTrackId[iTrack]<<endl;
447 // //}
448 //}
449 
452 // t3DInfo[eventTime, charge, rho, phi0, z0, cot, zchi]
453 void TRGCDCT3DConverterModule::add2DDatastore(multi_array<double, 2>& t2DInfo,
454  multi_array<double, 3>& t2DTsfInfo)
455 {
456  // Add 2D track
457  for (unsigned iTrack = 0; iTrack < t2DInfo.shape()[0]; ++iTrack) {
458  double charge = 0, phi0_i = 0, omega = 0, chi2D = 0;
459  //double phi0_c = 0;
460  //Convert
461  charge = t2DInfo[iTrack][0] == 2 ? -1 : 1;
462  //phi0_c = t2DPhiTot3DPhi(t2DInfo[iTrack][2], t2DInfo[iTrack][1]) / (pow(2, 12) - 0.5) * M_PI;
463  //phi0_i = phi0_c + charge * M_PI_2;
464  //cout<<phi0_i<<" "<<(45 + 90./80 * (1+ t2DInfo[iTrack][2]))/180*M_PI<<endl;
465  phi0_i = (45 + 90. / 80 * (1 + t2DInfo[iTrack][2])) / 180 * M_PI;
466 
467  //Correct phi0_i. The zero points of raw phi0_i for four boards are different.
468  if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore0") {
469  phi0_i = phi0_i + (M_PI / 2.0) * 0;
470  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore1") {
471  phi0_i = phi0_i + (M_PI / 2.0) * 1;
472  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore2") {
473  phi0_i = phi0_i + (M_PI / 2.0) * 2;
474  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore3") {
475  phi0_i = phi0_i + (M_PI / 2.0) * 3;
476  }
477 
478  // Confine the range of the angle to -pi ~ pi
479  while (phi0_i > M_PI) {
480  phi0_i -= 2 * M_PI;
481  }
482  while (phi0_i < -M_PI) {
483  phi0_i += 2 * M_PI;
484  }
485 
486  //omega = charge / t2DRhoTot3DRho(t2DInfo[iTrack][1])/(pow(2,11)-0.5)*2500;
487  //cout<<omega<<" "<<toSigned(t2DInfo[iTrack][1],7)*1.5e-4*30/0.3/34<<endl;
488  //omega = toSigned(t2DInfo[iTrack][1], 7) * 1.5e-4 * 30 / 0.3 / 34;
489  omega = toSigned(t2DInfo[iTrack][1], 7) / 33.0 * 3.2;
490  //cout<<"iTrack: "<<iTrack<<" charge:"<<t2DInfo[iTrack][0]<<" "<<charge<<" rho: "<<t2DInfo[iTrack][1]<<" "<<omega<<" phi0_i: "<<t2DInfo[iTrack][2]<<" "<<phi0_i<<endl;
491 
492  CDCTriggerTrack* track = m_tracks2D.appendNew(phi0_i, omega, chi2D, 0, 0, 0);
493 
494  if (m_isVerbose) cout << "[2D] iTrack:" << iTrack << " charge:" << charge << " phi0_i:" << phi0_i << " " << phi0_i * 180 / M_PI <<
495  " omega:" << omega << " pt:" << charge / omega * 0.3 * 1.5 * 0.01 << endl;
496 
497  for (unsigned iAx = 0; iAx < t2DTsfInfo.shape()[1]; ++iAx) {
498  double rawId = t2DTsfInfo[iTrack][iAx][0];
499  double id = -1;
500  if (iAx != 4) id = rawId;
501  else {
502  id = rawId - 16;
503  if (id < 0) id += 384;
504  }
505  double rt = t2DTsfInfo[iTrack][iAx][1];
506  double lr = t2DTsfInfo[iTrack][iAx][2];
507  double pr = t2DTsfInfo[iTrack][iAx][3];
508  double ft = t2DTsfInfo[iTrack][iAx][4];
509  if (pr == 0) continue;
510  CDCHit prHit(rt, 0, iAx * 2, pr == 3 ? 2 : 3, id);
511  m_hits.appendNew(prHit, toTSID(int(iAx * 2), id), pr, lr, rt, 0, ft);
512  track->addRelationTo(m_hits[m_hits.getEntries() - 1]);
513  if (m_isVerbose) cout << "[2D] iTrack: " << iTrack << " iAx:" << iAx << " id:" << id << " rt:" << rt << " lr:" << lr << " pr:" << pr
514  << " ft:" << ft << endl;
515  }
516 
517 
518  }
519 }
520 
521 void TRGCDCT3DConverterModule::addTSDatastore(multi_array<double, 3>& tsfInfo, int isSt)
522 {
523  for (unsigned iSL = 0; iSL < tsfInfo.shape()[0]; iSL++) {
524  for (unsigned iTS = 0; iTS < tsfInfo.shape()[1]; iTS++) {
525  double id = tsfInfo[iSL][iTS][0];
526  double rt = tsfInfo[iSL][iTS][1];
527  double lr = tsfInfo[iSL][iTS][2];
528  double pr = tsfInfo[iSL][iTS][3];
529  double ft = tsfInfo[iSL][iTS][4];
530  if (m_isVerbose) cout << "[TSF] iSL:" << iSL << " iTS:" << iTS << " id:" << id << " rt:" << rt << " lr:" << lr << " pr:" << pr <<
531  " ft:" << ft << endl;
532  if (pr != 0) {
533  CDCHit prHit(rt, 0, iSL * 2 + isSt, pr == 3 ? 2 : 3, id);
534  m_hits.appendNew(prHit, toTSID(int(iSL * 2 + isSt), id), pr, lr, rt, 0, ft);
535  }
536  }
537  }
538 }
539 
540 void TRGCDCT3DConverterModule::storeTSFirmwareData(multi_array<double, 4>& tsfInfo)
541 {
542  for (int iClk = 0; iClk < m_firmwareResults.getEntries(); iClk++) {
544  //cout<<"iClk:"<<iClk<<" tsf1_cc:"<<result->m_tsf1_cc<<" tsf1ts0_id:"<<result->m_tsf1ts0_id<<" tsf1ts0_rt:"<<result->m_tsf1ts0_rt<<" tsf1ts0_lr:"<<result->m_tsf1ts0_lr<<" tsf1ts0_pr:"<<result->m_tsf1ts0_pr<<endl;
545  tsfInfo[0][0][iClk][0] = result->m_tsf1ts0_id;
546  tsfInfo[0][0][iClk][1] = result->m_tsf1ts0_rt;
547  tsfInfo[0][0][iClk][2] = result->m_tsf1ts0_lr;
548  tsfInfo[0][0][iClk][3] = result->m_tsf1ts0_pr;
549  tsfInfo[0][0][iClk][4] = result->m_tsf1_cc;
550  tsfInfo[0][1][iClk][0] = result->m_tsf1ts1_id;
551  tsfInfo[0][1][iClk][1] = result->m_tsf1ts1_rt;
552  tsfInfo[0][1][iClk][2] = result->m_tsf1ts1_lr;
553  tsfInfo[0][1][iClk][3] = result->m_tsf1ts1_pr;
554  tsfInfo[0][1][iClk][4] = result->m_tsf1_cc;
555  tsfInfo[0][2][iClk][0] = result->m_tsf1ts2_id;
556  tsfInfo[0][2][iClk][1] = result->m_tsf1ts2_rt;
557  tsfInfo[0][2][iClk][2] = result->m_tsf1ts2_lr;
558  tsfInfo[0][2][iClk][3] = result->m_tsf1ts2_pr;
559  tsfInfo[0][2][iClk][4] = result->m_tsf1_cc;
560  tsfInfo[0][3][iClk][0] = result->m_tsf1ts3_id;
561  tsfInfo[0][3][iClk][1] = result->m_tsf1ts3_rt;
562  tsfInfo[0][3][iClk][2] = result->m_tsf1ts3_lr;
563  tsfInfo[0][3][iClk][3] = result->m_tsf1ts3_pr;
564  tsfInfo[0][3][iClk][4] = result->m_tsf1_cc;
565  tsfInfo[0][4][iClk][0] = result->m_tsf1ts4_id;
566  tsfInfo[0][4][iClk][1] = result->m_tsf1ts4_rt;
567  tsfInfo[0][4][iClk][2] = result->m_tsf1ts4_lr;
568  tsfInfo[0][4][iClk][3] = result->m_tsf1ts4_pr;
569  tsfInfo[0][4][iClk][4] = result->m_tsf1_cc;
570  tsfInfo[0][5][iClk][0] = result->m_tsf1ts5_id;
571  tsfInfo[0][5][iClk][1] = result->m_tsf1ts5_rt;
572  tsfInfo[0][5][iClk][2] = result->m_tsf1ts5_lr;
573  tsfInfo[0][5][iClk][3] = result->m_tsf1ts5_pr;
574  tsfInfo[0][5][iClk][4] = result->m_tsf1_cc;
575  tsfInfo[0][6][iClk][0] = result->m_tsf1ts6_id;
576  tsfInfo[0][6][iClk][1] = result->m_tsf1ts6_rt;
577  tsfInfo[0][6][iClk][2] = result->m_tsf1ts6_lr;
578  tsfInfo[0][6][iClk][3] = result->m_tsf1ts6_pr;
579  tsfInfo[0][6][iClk][4] = result->m_tsf1_cc;
580  tsfInfo[0][7][iClk][0] = result->m_tsf1ts7_id;
581  tsfInfo[0][7][iClk][1] = result->m_tsf1ts7_rt;
582  tsfInfo[0][7][iClk][2] = result->m_tsf1ts7_lr;
583  tsfInfo[0][7][iClk][3] = result->m_tsf1ts7_pr;
584  tsfInfo[0][7][iClk][4] = result->m_tsf1_cc;
585  tsfInfo[0][8][iClk][0] = result->m_tsf1ts8_id;
586  tsfInfo[0][8][iClk][1] = result->m_tsf1ts8_rt;
587  tsfInfo[0][8][iClk][2] = result->m_tsf1ts8_lr;
588  tsfInfo[0][8][iClk][3] = result->m_tsf1ts8_pr;
589  tsfInfo[0][8][iClk][4] = result->m_tsf1_cc;
590  tsfInfo[0][9][iClk][0] = result->m_tsf1ts9_id;
591  tsfInfo[0][9][iClk][1] = result->m_tsf1ts9_rt;
592  tsfInfo[0][9][iClk][2] = result->m_tsf1ts9_lr;
593  tsfInfo[0][9][iClk][3] = result->m_tsf1ts9_pr;
594  tsfInfo[0][9][iClk][4] = result->m_tsf1_cc;
595  tsfInfo[0][10][iClk][0] = result->m_tsf1ts10_id;
596  tsfInfo[0][10][iClk][1] = result->m_tsf1ts10_rt;
597  tsfInfo[0][10][iClk][2] = result->m_tsf1ts10_lr;
598  tsfInfo[0][10][iClk][3] = result->m_tsf1ts10_pr;
599  tsfInfo[0][10][iClk][4] = result->m_tsf1_cc;
600  tsfInfo[0][11][iClk][0] = result->m_tsf1ts11_id;
601  tsfInfo[0][11][iClk][1] = result->m_tsf1ts11_rt;
602  tsfInfo[0][11][iClk][2] = result->m_tsf1ts11_lr;
603  tsfInfo[0][11][iClk][3] = result->m_tsf1ts11_pr;
604  tsfInfo[0][11][iClk][4] = result->m_tsf1_cc;
605  tsfInfo[0][12][iClk][0] = result->m_tsf1ts12_id;
606  tsfInfo[0][12][iClk][1] = result->m_tsf1ts12_rt;
607  tsfInfo[0][12][iClk][2] = result->m_tsf1ts12_lr;
608  tsfInfo[0][12][iClk][3] = result->m_tsf1ts12_pr;
609  tsfInfo[0][12][iClk][4] = result->m_tsf1_cc;
610  tsfInfo[0][13][iClk][0] = result->m_tsf1ts13_id;
611  tsfInfo[0][13][iClk][1] = result->m_tsf1ts13_rt;
612  tsfInfo[0][13][iClk][2] = result->m_tsf1ts13_lr;
613  tsfInfo[0][13][iClk][3] = result->m_tsf1ts13_pr;
614  tsfInfo[0][13][iClk][4] = result->m_tsf1_cc;
615  tsfInfo[0][14][iClk][0] = result->m_tsf1ts14_id;
616  tsfInfo[0][14][iClk][1] = result->m_tsf1ts14_rt;
617  tsfInfo[0][14][iClk][2] = result->m_tsf1ts14_lr;
618  tsfInfo[0][14][iClk][3] = result->m_tsf1ts14_pr;
619  tsfInfo[0][14][iClk][4] = result->m_tsf1_cc;
620 
621  tsfInfo[1][0][iClk][0] = result->m_tsf3ts0_id;
622  tsfInfo[1][0][iClk][1] = result->m_tsf3ts0_rt;
623  tsfInfo[1][0][iClk][2] = result->m_tsf3ts0_lr;
624  tsfInfo[1][0][iClk][3] = result->m_tsf3ts0_pr;
625  tsfInfo[1][0][iClk][4] = result->m_tsf3_cc;
626  tsfInfo[1][1][iClk][0] = result->m_tsf3ts1_id;
627  tsfInfo[1][1][iClk][1] = result->m_tsf3ts1_rt;
628  tsfInfo[1][1][iClk][2] = result->m_tsf3ts1_lr;
629  tsfInfo[1][1][iClk][3] = result->m_tsf3ts1_pr;
630  tsfInfo[1][1][iClk][4] = result->m_tsf3_cc;
631  tsfInfo[1][2][iClk][0] = result->m_tsf3ts2_id;
632  tsfInfo[1][2][iClk][1] = result->m_tsf3ts2_rt;
633  tsfInfo[1][2][iClk][2] = result->m_tsf3ts2_lr;
634  tsfInfo[1][2][iClk][3] = result->m_tsf3ts2_pr;
635  tsfInfo[1][2][iClk][4] = result->m_tsf3_cc;
636  tsfInfo[1][3][iClk][0] = result->m_tsf3ts3_id;
637  tsfInfo[1][3][iClk][1] = result->m_tsf3ts3_rt;
638  tsfInfo[1][3][iClk][2] = result->m_tsf3ts3_lr;
639  tsfInfo[1][3][iClk][3] = result->m_tsf3ts3_pr;
640  tsfInfo[1][3][iClk][4] = result->m_tsf3_cc;
641  tsfInfo[1][4][iClk][0] = result->m_tsf3ts4_id;
642  tsfInfo[1][4][iClk][1] = result->m_tsf3ts4_rt;
643  tsfInfo[1][4][iClk][2] = result->m_tsf3ts4_lr;
644  tsfInfo[1][4][iClk][3] = result->m_tsf3ts4_pr;
645  tsfInfo[1][4][iClk][4] = result->m_tsf3_cc;
646  tsfInfo[1][5][iClk][0] = result->m_tsf3ts5_id;
647  tsfInfo[1][5][iClk][1] = result->m_tsf3ts5_rt;
648  tsfInfo[1][5][iClk][2] = result->m_tsf3ts5_lr;
649  tsfInfo[1][5][iClk][3] = result->m_tsf3ts5_pr;
650  tsfInfo[1][5][iClk][4] = result->m_tsf3_cc;
651  tsfInfo[1][6][iClk][0] = result->m_tsf3ts6_id;
652  tsfInfo[1][6][iClk][1] = result->m_tsf3ts6_rt;
653  tsfInfo[1][6][iClk][2] = result->m_tsf3ts6_lr;
654  tsfInfo[1][6][iClk][3] = result->m_tsf3ts6_pr;
655  tsfInfo[1][6][iClk][4] = result->m_tsf3_cc;
656  tsfInfo[1][7][iClk][0] = result->m_tsf3ts7_id;
657  tsfInfo[1][7][iClk][1] = result->m_tsf3ts7_rt;
658  tsfInfo[1][7][iClk][2] = result->m_tsf3ts7_lr;
659  tsfInfo[1][7][iClk][3] = result->m_tsf3ts7_pr;
660  tsfInfo[1][7][iClk][4] = result->m_tsf3_cc;
661  tsfInfo[1][8][iClk][0] = result->m_tsf3ts8_id;
662  tsfInfo[1][8][iClk][1] = result->m_tsf3ts8_rt;
663  tsfInfo[1][8][iClk][2] = result->m_tsf3ts8_lr;
664  tsfInfo[1][8][iClk][3] = result->m_tsf3ts8_pr;
665  tsfInfo[1][8][iClk][4] = result->m_tsf3_cc;
666  tsfInfo[1][9][iClk][0] = result->m_tsf3ts9_id;
667  tsfInfo[1][9][iClk][1] = result->m_tsf3ts9_rt;
668  tsfInfo[1][9][iClk][2] = result->m_tsf3ts9_lr;
669  tsfInfo[1][9][iClk][3] = result->m_tsf3ts9_pr;
670  tsfInfo[1][9][iClk][4] = result->m_tsf3_cc;
671  tsfInfo[1][10][iClk][0] = result->m_tsf3ts10_id;
672  tsfInfo[1][10][iClk][1] = result->m_tsf3ts10_rt;
673  tsfInfo[1][10][iClk][2] = result->m_tsf3ts10_lr;
674  tsfInfo[1][10][iClk][3] = result->m_tsf3ts10_pr;
675  tsfInfo[1][10][iClk][4] = result->m_tsf3_cc;
676  tsfInfo[1][11][iClk][0] = result->m_tsf3ts11_id;
677  tsfInfo[1][11][iClk][1] = result->m_tsf3ts11_rt;
678  tsfInfo[1][11][iClk][2] = result->m_tsf3ts11_lr;
679  tsfInfo[1][11][iClk][3] = result->m_tsf3ts11_pr;
680  tsfInfo[1][11][iClk][4] = result->m_tsf3_cc;
681  tsfInfo[1][12][iClk][0] = result->m_tsf3ts12_id;
682  tsfInfo[1][12][iClk][1] = result->m_tsf3ts12_rt;
683  tsfInfo[1][12][iClk][2] = result->m_tsf3ts12_lr;
684  tsfInfo[1][12][iClk][3] = result->m_tsf3ts12_pr;
685  tsfInfo[1][12][iClk][4] = result->m_tsf3_cc;
686  tsfInfo[1][13][iClk][0] = result->m_tsf3ts13_id;
687  tsfInfo[1][13][iClk][1] = result->m_tsf3ts13_rt;
688  tsfInfo[1][13][iClk][2] = result->m_tsf3ts13_lr;
689  tsfInfo[1][13][iClk][3] = result->m_tsf3ts13_pr;
690  tsfInfo[1][13][iClk][4] = result->m_tsf3_cc;
691  tsfInfo[1][14][iClk][0] = result->m_tsf3ts14_id;
692  tsfInfo[1][14][iClk][1] = result->m_tsf3ts14_rt;
693  tsfInfo[1][14][iClk][2] = result->m_tsf3ts14_lr;
694  tsfInfo[1][14][iClk][3] = result->m_tsf3ts14_pr;
695  tsfInfo[1][14][iClk][4] = result->m_tsf3_cc;
696 
697  tsfInfo[2][0][iClk][0] = result->m_tsf5ts0_id;
698  tsfInfo[2][0][iClk][1] = result->m_tsf5ts0_rt;
699  tsfInfo[2][0][iClk][2] = result->m_tsf5ts0_lr;
700  tsfInfo[2][0][iClk][3] = result->m_tsf5ts0_pr;
701  tsfInfo[2][0][iClk][4] = result->m_tsf5_cc;
702  tsfInfo[2][1][iClk][0] = result->m_tsf5ts1_id;
703  tsfInfo[2][1][iClk][1] = result->m_tsf5ts1_rt;
704  tsfInfo[2][1][iClk][2] = result->m_tsf5ts1_lr;
705  tsfInfo[2][1][iClk][3] = result->m_tsf5ts1_pr;
706  tsfInfo[2][1][iClk][4] = result->m_tsf5_cc;
707  tsfInfo[2][2][iClk][0] = result->m_tsf5ts2_id;
708  tsfInfo[2][2][iClk][1] = result->m_tsf5ts2_rt;
709  tsfInfo[2][2][iClk][2] = result->m_tsf5ts2_lr;
710  tsfInfo[2][2][iClk][3] = result->m_tsf5ts2_pr;
711  tsfInfo[2][2][iClk][4] = result->m_tsf5_cc;
712  tsfInfo[2][3][iClk][0] = result->m_tsf5ts3_id;
713  tsfInfo[2][3][iClk][1] = result->m_tsf5ts3_rt;
714  tsfInfo[2][3][iClk][2] = result->m_tsf5ts3_lr;
715  tsfInfo[2][3][iClk][3] = result->m_tsf5ts3_pr;
716  tsfInfo[2][3][iClk][4] = result->m_tsf5_cc;
717  tsfInfo[2][4][iClk][0] = result->m_tsf5ts4_id;
718  tsfInfo[2][4][iClk][1] = result->m_tsf5ts4_rt;
719  tsfInfo[2][4][iClk][2] = result->m_tsf5ts4_lr;
720  tsfInfo[2][4][iClk][3] = result->m_tsf5ts4_pr;
721  tsfInfo[2][4][iClk][4] = result->m_tsf5_cc;
722  tsfInfo[2][5][iClk][0] = result->m_tsf5ts5_id;
723  tsfInfo[2][5][iClk][1] = result->m_tsf5ts5_rt;
724  tsfInfo[2][5][iClk][2] = result->m_tsf5ts5_lr;
725  tsfInfo[2][5][iClk][3] = result->m_tsf5ts5_pr;
726  tsfInfo[2][5][iClk][4] = result->m_tsf5_cc;
727  tsfInfo[2][6][iClk][0] = result->m_tsf5ts6_id;
728  tsfInfo[2][6][iClk][1] = result->m_tsf5ts6_rt;
729  tsfInfo[2][6][iClk][2] = result->m_tsf5ts6_lr;
730  tsfInfo[2][6][iClk][3] = result->m_tsf5ts6_pr;
731  tsfInfo[2][6][iClk][4] = result->m_tsf5_cc;
732  tsfInfo[2][7][iClk][0] = result->m_tsf5ts7_id;
733  tsfInfo[2][7][iClk][1] = result->m_tsf5ts7_rt;
734  tsfInfo[2][7][iClk][2] = result->m_tsf5ts7_lr;
735  tsfInfo[2][7][iClk][3] = result->m_tsf5ts7_pr;
736  tsfInfo[2][7][iClk][4] = result->m_tsf5_cc;
737  tsfInfo[2][8][iClk][0] = result->m_tsf5ts8_id;
738  tsfInfo[2][8][iClk][1] = result->m_tsf5ts8_rt;
739  tsfInfo[2][8][iClk][2] = result->m_tsf5ts8_lr;
740  tsfInfo[2][8][iClk][3] = result->m_tsf5ts8_pr;
741  tsfInfo[2][8][iClk][4] = result->m_tsf5_cc;
742  tsfInfo[2][9][iClk][0] = result->m_tsf5ts9_id;
743  tsfInfo[2][9][iClk][1] = result->m_tsf5ts9_rt;
744  tsfInfo[2][9][iClk][2] = result->m_tsf5ts9_lr;
745  tsfInfo[2][9][iClk][3] = result->m_tsf5ts9_pr;
746  tsfInfo[2][9][iClk][4] = result->m_tsf5_cc;
747  tsfInfo[2][10][iClk][0] = result->m_tsf5ts10_id;
748  tsfInfo[2][10][iClk][1] = result->m_tsf5ts10_rt;
749  tsfInfo[2][10][iClk][2] = result->m_tsf5ts10_lr;
750  tsfInfo[2][10][iClk][3] = result->m_tsf5ts10_pr;
751  tsfInfo[2][10][iClk][4] = result->m_tsf5_cc;
752  tsfInfo[2][11][iClk][0] = result->m_tsf5ts11_id;
753  tsfInfo[2][11][iClk][1] = result->m_tsf5ts11_rt;
754  tsfInfo[2][11][iClk][2] = result->m_tsf5ts11_lr;
755  tsfInfo[2][11][iClk][3] = result->m_tsf5ts11_pr;
756  tsfInfo[2][11][iClk][4] = result->m_tsf5_cc;
757  tsfInfo[2][12][iClk][0] = result->m_tsf5ts12_id;
758  tsfInfo[2][12][iClk][1] = result->m_tsf5ts12_rt;
759  tsfInfo[2][12][iClk][2] = result->m_tsf5ts12_lr;
760  tsfInfo[2][12][iClk][3] = result->m_tsf5ts12_pr;
761  tsfInfo[2][12][iClk][4] = result->m_tsf5_cc;
762  tsfInfo[2][13][iClk][0] = result->m_tsf5ts13_id;
763  tsfInfo[2][13][iClk][1] = result->m_tsf5ts13_rt;
764  tsfInfo[2][13][iClk][2] = result->m_tsf5ts13_lr;
765  tsfInfo[2][13][iClk][3] = result->m_tsf5ts13_pr;
766  tsfInfo[2][13][iClk][4] = result->m_tsf5_cc;
767  tsfInfo[2][14][iClk][0] = result->m_tsf5ts14_id;
768  tsfInfo[2][14][iClk][1] = result->m_tsf5ts14_rt;
769  tsfInfo[2][14][iClk][2] = result->m_tsf5ts14_lr;
770  tsfInfo[2][14][iClk][3] = result->m_tsf5ts14_pr;
771  tsfInfo[2][14][iClk][4] = result->m_tsf5_cc;
772 
773  tsfInfo[3][0][iClk][0] = result->m_tsf7ts0_id;
774  tsfInfo[3][0][iClk][1] = result->m_tsf7ts0_rt;
775  tsfInfo[3][0][iClk][2] = result->m_tsf7ts0_lr;
776  tsfInfo[3][0][iClk][3] = result->m_tsf7ts0_pr;
777  tsfInfo[3][0][iClk][4] = result->m_tsf7_cc;
778  tsfInfo[3][1][iClk][0] = result->m_tsf7ts1_id;
779  tsfInfo[3][1][iClk][1] = result->m_tsf7ts1_rt;
780  tsfInfo[3][1][iClk][2] = result->m_tsf7ts1_lr;
781  tsfInfo[3][1][iClk][3] = result->m_tsf7ts1_pr;
782  tsfInfo[3][1][iClk][4] = result->m_tsf7_cc;
783  tsfInfo[3][2][iClk][0] = result->m_tsf7ts2_id;
784  tsfInfo[3][2][iClk][1] = result->m_tsf7ts2_rt;
785  tsfInfo[3][2][iClk][2] = result->m_tsf7ts2_lr;
786  tsfInfo[3][2][iClk][3] = result->m_tsf7ts2_pr;
787  tsfInfo[3][2][iClk][4] = result->m_tsf7_cc;
788  tsfInfo[3][3][iClk][0] = result->m_tsf7ts3_id;
789  tsfInfo[3][3][iClk][1] = result->m_tsf7ts3_rt;
790  tsfInfo[3][3][iClk][2] = result->m_tsf7ts3_lr;
791  tsfInfo[3][3][iClk][3] = result->m_tsf7ts3_pr;
792  tsfInfo[3][3][iClk][4] = result->m_tsf7_cc;
793  tsfInfo[3][4][iClk][0] = result->m_tsf7ts4_id;
794  tsfInfo[3][4][iClk][1] = result->m_tsf7ts4_rt;
795  tsfInfo[3][4][iClk][2] = result->m_tsf7ts4_lr;
796  tsfInfo[3][4][iClk][3] = result->m_tsf7ts4_pr;
797  tsfInfo[3][4][iClk][4] = result->m_tsf7_cc;
798  tsfInfo[3][5][iClk][0] = result->m_tsf7ts5_id;
799  tsfInfo[3][5][iClk][1] = result->m_tsf7ts5_rt;
800  tsfInfo[3][5][iClk][2] = result->m_tsf7ts5_lr;
801  tsfInfo[3][5][iClk][3] = result->m_tsf7ts5_pr;
802  tsfInfo[3][5][iClk][4] = result->m_tsf7_cc;
803  tsfInfo[3][6][iClk][0] = result->m_tsf7ts6_id;
804  tsfInfo[3][6][iClk][1] = result->m_tsf7ts6_rt;
805  tsfInfo[3][6][iClk][2] = result->m_tsf7ts6_lr;
806  tsfInfo[3][6][iClk][3] = result->m_tsf7ts6_pr;
807  tsfInfo[3][6][iClk][4] = result->m_tsf7_cc;
808  tsfInfo[3][7][iClk][0] = result->m_tsf7ts7_id;
809  tsfInfo[3][7][iClk][1] = result->m_tsf7ts7_rt;
810  tsfInfo[3][7][iClk][2] = result->m_tsf7ts7_lr;
811  tsfInfo[3][7][iClk][3] = result->m_tsf7ts7_pr;
812  tsfInfo[3][7][iClk][4] = result->m_tsf7_cc;
813  tsfInfo[3][8][iClk][0] = result->m_tsf7ts8_id;
814  tsfInfo[3][8][iClk][1] = result->m_tsf7ts8_rt;
815  tsfInfo[3][8][iClk][2] = result->m_tsf7ts8_lr;
816  tsfInfo[3][8][iClk][3] = result->m_tsf7ts8_pr;
817  tsfInfo[3][8][iClk][4] = result->m_tsf7_cc;
818  tsfInfo[3][9][iClk][0] = result->m_tsf7ts9_id;
819  tsfInfo[3][9][iClk][1] = result->m_tsf7ts9_rt;
820  tsfInfo[3][9][iClk][2] = result->m_tsf7ts9_lr;
821  tsfInfo[3][9][iClk][3] = result->m_tsf7ts9_pr;
822  tsfInfo[3][9][iClk][4] = result->m_tsf7_cc;
823  tsfInfo[3][10][iClk][0] = result->m_tsf7ts10_id;
824  tsfInfo[3][10][iClk][1] = result->m_tsf7ts10_rt;
825  tsfInfo[3][10][iClk][2] = result->m_tsf7ts10_lr;
826  tsfInfo[3][10][iClk][3] = result->m_tsf7ts10_pr;
827  tsfInfo[3][10][iClk][4] = result->m_tsf7_cc;
828  tsfInfo[3][11][iClk][0] = result->m_tsf7ts11_id;
829  tsfInfo[3][11][iClk][1] = result->m_tsf7ts11_rt;
830  tsfInfo[3][11][iClk][2] = result->m_tsf7ts11_lr;
831  tsfInfo[3][11][iClk][3] = result->m_tsf7ts11_pr;
832  tsfInfo[3][11][iClk][4] = result->m_tsf7_cc;
833  tsfInfo[3][12][iClk][0] = result->m_tsf7ts12_id;
834  tsfInfo[3][12][iClk][1] = result->m_tsf7ts12_rt;
835  tsfInfo[3][12][iClk][2] = result->m_tsf7ts12_lr;
836  tsfInfo[3][12][iClk][3] = result->m_tsf7ts12_pr;
837  tsfInfo[3][12][iClk][4] = result->m_tsf7_cc;
838  tsfInfo[3][13][iClk][0] = result->m_tsf7ts13_id;
839  tsfInfo[3][13][iClk][1] = result->m_tsf7ts13_rt;
840  tsfInfo[3][13][iClk][2] = result->m_tsf7ts13_lr;
841  tsfInfo[3][13][iClk][3] = result->m_tsf7ts13_pr;
842  tsfInfo[3][13][iClk][4] = result->m_tsf7_cc;
843  tsfInfo[3][14][iClk][0] = result->m_tsf7ts14_id;
844  tsfInfo[3][14][iClk][1] = result->m_tsf7ts14_rt;
845  tsfInfo[3][14][iClk][2] = result->m_tsf7ts14_lr;
846  tsfInfo[3][14][iClk][3] = result->m_tsf7ts14_pr;
847  tsfInfo[3][14][iClk][4] = result->m_tsf7_cc;
848 
849  }
850 }
851 
852 // t2DFirmwareInfo[tIndex][iClk][valid, isOld charge, rho, phi0]
853 // t2DTsfFirmwareInfo[tIndex][iClk][axSL][id, rt, lr, pr]
854 void TRGCDCT3DConverterModule::store2DFirmwareData(multi_array<double, 3>& t2DFirmwareInfo,
855  multi_array<double, 4>& t2DTsfFirmwareInfo)
856 {
857 
858  for (int iClk = 0; iClk < m_firmwareResults.getEntries(); iClk++) {
860  bitset<6> t2d_fnf(int(result->m_t2d_fnf));
861  bitset<6> t2d_oldfnf(int(result->m_t3d_2doldtrk));
862  //cout<<"iclk:"<<iClk<<" fnf:"<<result->m_t2d_fnf<<" "<<t2d_fnf<<" "<<t2d_fnf[5]<<endl;
863  //cout<<"iClk:"<<iClk<<" t2d_fnf:"<<m_firmwareResults[iClk]->m_t2d_fnf<<endl;
864 
865  t2DFirmwareInfo[0][iClk][0] = t2d_fnf[5];
866  t2DFirmwareInfo[0][iClk][1] = t2d_oldfnf[5];;
867  t2DFirmwareInfo[0][iClk][2] = result->m_t2d0_charge;
868  t2DFirmwareInfo[0][iClk][3] = result->m_t2d0_rho_s;
869  t2DFirmwareInfo[0][iClk][4] = result->m_t2d0_phi;
870 
871  t2DFirmwareInfo[1][iClk][0] = t2d_fnf[4];
872  t2DFirmwareInfo[1][iClk][1] = t2d_oldfnf[4];;
873  t2DFirmwareInfo[1][iClk][2] = result->m_t2d1_charge;
874  t2DFirmwareInfo[1][iClk][3] = result->m_t2d1_rho_s;
875  t2DFirmwareInfo[1][iClk][4] = result->m_t2d1_phi;
876 
877  t2DFirmwareInfo[2][iClk][0] = t2d_fnf[3];
878  t2DFirmwareInfo[2][iClk][1] = t2d_oldfnf[3];;
879  t2DFirmwareInfo[2][iClk][2] = result->m_t2d2_charge;
880  t2DFirmwareInfo[2][iClk][3] = result->m_t2d2_rho_s;
881  t2DFirmwareInfo[2][iClk][4] = result->m_t2d2_phi;
882 
883  t2DFirmwareInfo[3][iClk][0] = t2d_fnf[2];
884  t2DFirmwareInfo[3][iClk][1] = t2d_oldfnf[2];;
885  t2DFirmwareInfo[3][iClk][2] = result->m_t2d3_charge;
886  t2DFirmwareInfo[3][iClk][3] = result->m_t2d3_rho_s;
887  t2DFirmwareInfo[3][iClk][4] = result->m_t2d3_phi;
888 
889  t2DTsfFirmwareInfo[0][iClk][0][0] = result->m_t2d0ts0_id;
890  t2DTsfFirmwareInfo[0][iClk][0][1] = result->m_t2d0ts0_rt;
891  t2DTsfFirmwareInfo[0][iClk][0][2] = result->m_t2d0ts0_lr;
892  t2DTsfFirmwareInfo[0][iClk][0][3] = result->m_t2d0ts0_pr;
893  t2DTsfFirmwareInfo[0][iClk][1][0] = result->m_t2d0ts2_id;
894  t2DTsfFirmwareInfo[0][iClk][1][1] = result->m_t2d0ts2_rt;
895  t2DTsfFirmwareInfo[0][iClk][1][2] = result->m_t2d0ts2_lr;
896  t2DTsfFirmwareInfo[0][iClk][1][3] = result->m_t2d0ts2_pr;
897  t2DTsfFirmwareInfo[0][iClk][2][0] = result->m_t2d0ts4_id;
898  t2DTsfFirmwareInfo[0][iClk][2][1] = result->m_t2d0ts4_rt;
899  t2DTsfFirmwareInfo[0][iClk][2][2] = result->m_t2d0ts4_lr;
900  t2DTsfFirmwareInfo[0][iClk][2][3] = result->m_t2d0ts4_pr;
901  t2DTsfFirmwareInfo[0][iClk][3][0] = result->m_t2d0ts6_id;
902  t2DTsfFirmwareInfo[0][iClk][3][1] = result->m_t2d0ts6_rt;
903  t2DTsfFirmwareInfo[0][iClk][3][2] = result->m_t2d0ts6_lr;
904  t2DTsfFirmwareInfo[0][iClk][3][3] = result->m_t2d0ts6_pr;
905  t2DTsfFirmwareInfo[0][iClk][4][0] = result->m_t2d0ts8_id;
906  t2DTsfFirmwareInfo[0][iClk][4][1] = result->m_t2d0ts8_rt;
907  t2DTsfFirmwareInfo[0][iClk][4][2] = result->m_t2d0ts8_lr;
908  t2DTsfFirmwareInfo[0][iClk][4][3] = result->m_t2d0ts8_pr;
909 
910  t2DTsfFirmwareInfo[1][iClk][0][0] = result->m_t2d1ts0_id;
911  t2DTsfFirmwareInfo[1][iClk][0][1] = result->m_t2d1ts0_rt;
912  t2DTsfFirmwareInfo[1][iClk][0][2] = result->m_t2d1ts0_lr;
913  t2DTsfFirmwareInfo[1][iClk][0][3] = result->m_t2d1ts0_pr;
914  t2DTsfFirmwareInfo[1][iClk][1][0] = result->m_t2d1ts2_id;
915  t2DTsfFirmwareInfo[1][iClk][1][1] = result->m_t2d1ts2_rt;
916  t2DTsfFirmwareInfo[1][iClk][1][2] = result->m_t2d1ts2_lr;
917  t2DTsfFirmwareInfo[1][iClk][1][3] = result->m_t2d1ts2_pr;
918  t2DTsfFirmwareInfo[1][iClk][2][0] = result->m_t2d1ts4_id;
919  t2DTsfFirmwareInfo[1][iClk][2][1] = result->m_t2d1ts4_rt;
920  t2DTsfFirmwareInfo[1][iClk][2][2] = result->m_t2d1ts4_lr;
921  t2DTsfFirmwareInfo[1][iClk][2][3] = result->m_t2d1ts4_pr;
922  t2DTsfFirmwareInfo[1][iClk][3][0] = result->m_t2d1ts6_id;
923  t2DTsfFirmwareInfo[1][iClk][3][1] = result->m_t2d1ts6_rt;
924  t2DTsfFirmwareInfo[1][iClk][3][2] = result->m_t2d1ts6_lr;
925  t2DTsfFirmwareInfo[1][iClk][3][3] = result->m_t2d1ts6_pr;
926  t2DTsfFirmwareInfo[1][iClk][4][0] = result->m_t2d1ts8_id;
927  t2DTsfFirmwareInfo[1][iClk][4][1] = result->m_t2d1ts8_rt;
928  t2DTsfFirmwareInfo[1][iClk][4][2] = result->m_t2d1ts8_lr;
929  t2DTsfFirmwareInfo[1][iClk][4][3] = result->m_t2d1ts8_pr;
930 
931  t2DTsfFirmwareInfo[2][iClk][0][0] = result->m_t2d2ts0_id;
932  t2DTsfFirmwareInfo[2][iClk][0][1] = result->m_t2d2ts0_rt;
933  t2DTsfFirmwareInfo[2][iClk][0][2] = result->m_t2d2ts0_lr;
934  t2DTsfFirmwareInfo[2][iClk][0][3] = result->m_t2d2ts0_pr;
935  t2DTsfFirmwareInfo[2][iClk][1][0] = result->m_t2d2ts2_id;
936  t2DTsfFirmwareInfo[2][iClk][1][1] = result->m_t2d2ts2_rt;
937  t2DTsfFirmwareInfo[2][iClk][1][2] = result->m_t2d2ts2_lr;
938  t2DTsfFirmwareInfo[2][iClk][1][3] = result->m_t2d2ts2_pr;
939  t2DTsfFirmwareInfo[2][iClk][2][0] = result->m_t2d2ts4_id;
940  t2DTsfFirmwareInfo[2][iClk][2][1] = result->m_t2d2ts4_rt;
941  t2DTsfFirmwareInfo[2][iClk][2][2] = result->m_t2d2ts4_lr;
942  t2DTsfFirmwareInfo[2][iClk][2][3] = result->m_t2d2ts4_pr;
943  t2DTsfFirmwareInfo[2][iClk][3][0] = result->m_t2d2ts6_id;
944  t2DTsfFirmwareInfo[2][iClk][3][1] = result->m_t2d2ts6_rt;
945  t2DTsfFirmwareInfo[2][iClk][3][2] = result->m_t2d2ts6_lr;
946  t2DTsfFirmwareInfo[2][iClk][3][3] = result->m_t2d2ts6_pr;
947  t2DTsfFirmwareInfo[2][iClk][4][0] = result->m_t2d2ts8_id;
948  t2DTsfFirmwareInfo[2][iClk][4][1] = result->m_t2d2ts8_rt;
949  t2DTsfFirmwareInfo[2][iClk][4][2] = result->m_t2d2ts8_lr;
950  t2DTsfFirmwareInfo[2][iClk][4][3] = result->m_t2d2ts8_pr;
951 
952  t2DTsfFirmwareInfo[3][iClk][0][0] = result->m_t2d3ts0_id;
953  t2DTsfFirmwareInfo[3][iClk][0][1] = result->m_t2d3ts0_rt;
954  t2DTsfFirmwareInfo[3][iClk][0][2] = result->m_t2d3ts0_lr;
955  t2DTsfFirmwareInfo[3][iClk][0][3] = result->m_t2d3ts0_pr;
956  t2DTsfFirmwareInfo[3][iClk][1][0] = result->m_t2d3ts2_id;
957  t2DTsfFirmwareInfo[3][iClk][1][1] = result->m_t2d3ts2_rt;
958  t2DTsfFirmwareInfo[3][iClk][1][2] = result->m_t2d3ts2_lr;
959  t2DTsfFirmwareInfo[3][iClk][1][3] = result->m_t2d3ts2_pr;
960  t2DTsfFirmwareInfo[3][iClk][2][0] = result->m_t2d3ts4_id;
961  t2DTsfFirmwareInfo[3][iClk][2][1] = result->m_t2d3ts4_rt;
962  t2DTsfFirmwareInfo[3][iClk][2][2] = result->m_t2d3ts4_lr;
963  t2DTsfFirmwareInfo[3][iClk][2][3] = result->m_t2d3ts4_pr;
964  t2DTsfFirmwareInfo[3][iClk][3][0] = result->m_t2d3ts6_id;
965  t2DTsfFirmwareInfo[3][iClk][3][1] = result->m_t2d3ts6_rt;
966  t2DTsfFirmwareInfo[3][iClk][3][2] = result->m_t2d3ts6_lr;
967  t2DTsfFirmwareInfo[3][iClk][3][3] = result->m_t2d3ts6_pr;
968  t2DTsfFirmwareInfo[3][iClk][4][0] = result->m_t2d3ts8_id;
969  t2DTsfFirmwareInfo[3][iClk][4][1] = result->m_t2d3ts8_rt;
970  t2DTsfFirmwareInfo[3][iClk][4][2] = result->m_t2d3ts8_lr;
971  t2DTsfFirmwareInfo[3][iClk][4][3] = result->m_t2d3ts8_pr;
972  }
973 }
974 
975 
976 // t3DFirmwareInfo[tIndex][iClk][2DValid, 2DisOld, TSFValid, EventTimeValid, eventTime, charge, rho, phi0, z0, cot, zchi]
977 void TRGCDCT3DConverterModule::store3DFirmwareData(multi_array<double, 3>& t3DFirmwareInfo)
978 {
979 
980  for (int iClk = 0; iClk < m_firmwareResults.getEntries() - 17 - 1; iClk++) {
982  TRGCDCT3DUnpackerStore* result3D = m_firmwareResults[iClk + 17];
983 
984  bitset<6> t3d_fnf(int(result3D->m_t3d_2dfnf));
985  bitset<4> tsf_fnf(int(result3D->m_t3d_validTS));
986  bitset<6> t3d_oldfnf(int(result->m_t3d_2doldtrk));
987 
988  //cout<<iClk<<" "<<t3d_fnf<<" "<<t3d_oldfnf<<endl;
989 
990 //The evtTime information was for debugging, but the currnet firmware doese not output the evtTime information corresponding to every track.
991 
992  t3DFirmwareInfo[0][iClk][0] = t3d_fnf[5];
993  t3DFirmwareInfo[0][iClk][1] = t3d_oldfnf[5];
994  t3DFirmwareInfo[0][iClk][2] = tsf_fnf[0];
995 // t3DFirmwareInfo[0][iClk][3] = result3D->m_t3dtrk0_evtTimeValid_delay;
996 // t3DFirmwareInfo[0][iClk][4] = result3D->m_t3dtrk0_evtTime_delay;
997  t3DFirmwareInfo[0][iClk][5] = result->m_t2d0_charge;
998  t3DFirmwareInfo[0][iClk][6] = result->m_t2d0_rho_s;
999  t3DFirmwareInfo[0][iClk][7] = result->m_t2d0_phi;
1000  t3DFirmwareInfo[0][iClk][8] = result3D->m_t3dtrk0_z0_s;
1001  t3DFirmwareInfo[0][iClk][9] = result3D->m_t3dtrk0_cot_s;
1002  t3DFirmwareInfo[0][iClk][10] = result3D->m_t3dtrk0_zchisq;
1003 
1004  t3DFirmwareInfo[1][iClk][0] = t3d_fnf[4];
1005  t3DFirmwareInfo[1][iClk][1] = t3d_oldfnf[4];
1006  t3DFirmwareInfo[1][iClk][2] = tsf_fnf[1];
1007 // t3DFirmwareInfo[1][iClk][3] = result3D->m_t3dtrk1_evtTimeValid_delay;
1008 // t3DFirmwareInfo[1][iClk][4] = result3D->m_t3dtrk1_evtTime_delay;
1009  t3DFirmwareInfo[1][iClk][5] = result->m_t2d1_charge;
1010  t3DFirmwareInfo[1][iClk][6] = result->m_t2d1_rho_s;
1011  t3DFirmwareInfo[1][iClk][7] = result->m_t2d1_phi;
1012  t3DFirmwareInfo[1][iClk][8] = result3D->m_t3dtrk1_z0_s;
1013  t3DFirmwareInfo[1][iClk][9] = result3D->m_t3dtrk1_cot_s;
1014  t3DFirmwareInfo[1][iClk][10] = result3D->m_t3dtrk1_zchisq;
1015 
1016  t3DFirmwareInfo[2][iClk][0] = t3d_fnf[3];
1017  t3DFirmwareInfo[2][iClk][1] = t3d_oldfnf[3];
1018  t3DFirmwareInfo[2][iClk][2] = tsf_fnf[2];
1019 // t3DFirmwareInfo[2][iClk][3] = result3D->m_t3dtrk2_evtTimeValid_delay;
1020 // t3DFirmwareInfo[2][iClk][4] = result3D->m_t3dtrk2_evtTime_delay;
1021  t3DFirmwareInfo[2][iClk][5] = result->m_t2d2_charge;
1022  t3DFirmwareInfo[2][iClk][6] = result->m_t2d2_rho_s;
1023  t3DFirmwareInfo[2][iClk][7] = result->m_t2d2_phi;
1024  t3DFirmwareInfo[2][iClk][8] = result3D->m_t3dtrk2_z0_s;
1025  t3DFirmwareInfo[2][iClk][9] = result3D->m_t3dtrk2_cot_s;
1026  t3DFirmwareInfo[2][iClk][10] = result3D->m_t3dtrk2_zchisq;
1027 
1028  t3DFirmwareInfo[3][iClk][0] = t3d_fnf[2];
1029  t3DFirmwareInfo[3][iClk][1] = t3d_oldfnf[2];
1030  t3DFirmwareInfo[3][iClk][2] = tsf_fnf[3];
1031 // t3DFirmwareInfo[3][iClk][3] = result3D->m_t3dtrk3_evtTimeValid_delay;
1032 // t3DFirmwareInfo[3][iClk][4] = result3D->m_t3dtrk3_evtTime_delay;
1033  t3DFirmwareInfo[3][iClk][5] = result->m_t2d3_charge;
1034  t3DFirmwareInfo[3][iClk][6] = result->m_t2d3_rho_s;
1035  t3DFirmwareInfo[3][iClk][7] = result->m_t2d3_phi;
1036  t3DFirmwareInfo[3][iClk][8] = result3D->m_t3dtrk3_z0_s;
1037  t3DFirmwareInfo[3][iClk][9] = result3D->m_t3dtrk3_cot_s;
1038  t3DFirmwareInfo[3][iClk][10] = result3D->m_t3dtrk3_zchisq;
1039 
1040  }
1041 
1042 }
1043 
1044 // t3DFirmwareInfo[tIndex][iClk][2DValid, 2DisOld, TSFValid, EventTimeValid, eventTime, charge, rho, phi0, z0, cot, zchi]
1045 void TRGCDCT3DConverterModule::store3DFastSimData(multi_array<double, 3>& t3DFirmwareInfo)
1046 {
1047 
1048  for (int iClk = 0; iClk < m_firmwareResults.getEntries() - 17 - 1; iClk++) {
1049 
1050  TRGCDCT3DUnpackerStore* result = m_firmwareResults[iClk];
1051  TRGCDCT3DUnpackerStore* result3D = m_firmwareResults[iClk + 17];
1052  TRGCDCT3DUnpackerStore* resultDebug = m_firmwareResults[iClk + 4];
1053 
1054  if (bitset<6> (result->m_t2d_fnf)[5] == 0) continue;
1055 
1056  // Store information(charge, radius(cm), phi_c(rad), eventTime, eventTimeValid, [TS ID, TS LR, TS driftTime])
1057  // [TODO] Is evtTime clock correct?
1058  int charge = resultDebug->m_t3dtrk0_charge == 2 ? -1 : 1;
1059  double radius = resultDebug->m_t3dtrk0_rho * 2500 / (pow(2, 11) - 0.5);
1060  double phi_c = toSigned(resultDebug->m_t3dtrk0_phi0, 13) * M_PI / (pow(2, 12) - 0.5);
1061  int eventTime = result3D->m_t3dtrk0_evtTime_delay;
1062  int eventTimeValid = result3D->m_t3dtrk0_evtTimeValid_delay;
1063  // rawStTSs[iSt] = [TS ID, TS LR, TS driftTime]
1064  vector<vector<int> > rawStTSs(4, vector<int> (3));
1065  rawStTSs[0][0] = resultDebug->m_t3dtrk0ts0_id;
1066  rawStTSs[0][1] = resultDebug->m_t3dtrk0ts0_lr;
1067  rawStTSs[0][2] = resultDebug->m_t3dtrk0ts0_rt;
1068  rawStTSs[1][0] = resultDebug->m_t3dtrk0ts1_id;
1069  rawStTSs[1][1] = resultDebug->m_t3dtrk0ts1_lr;
1070  rawStTSs[1][2] = resultDebug->m_t3dtrk0ts1_rt;
1071  rawStTSs[2][0] = resultDebug->m_t3dtrk0ts2_id;
1072  rawStTSs[2][1] = resultDebug->m_t3dtrk0ts2_lr;
1073  rawStTSs[2][2] = resultDebug->m_t3dtrk0ts2_rt;
1074  rawStTSs[3][0] = resultDebug->m_t3dtrk0ts3_id;
1075  rawStTSs[3][1] = resultDebug->m_t3dtrk0ts3_lr;
1076  rawStTSs[3][2] = resultDebug->m_t3dtrk0ts3_rt;
1077 
1078  // Get geometry
1079  map<string, vector<double> > stGeometry;
1080  vector<vector<double> > stXts;
1082  TRGCDCFitter3D::getStereoXt(stGeometry["priorityLayer"], stXts);
1083 
1084  double z0 = 0, cot = 0, chi2 = 0;
1085  Fitter3DUtility::fitter3D(stGeometry, stXts, eventTimeValid, eventTime, rawStTSs, charge, radius, phi_c, z0, cot, chi2);
1086 
1087  bitset<6> t2d_fnf(int(result3D->m_t3d_2dfnf));
1088  bitset<4> tsf_fnf(int(result3D->m_t3d_validTS));
1089  bitset<6> t2d_oldfnf(int(result->m_t3d_2doldtrk));
1090 
1091  //cout<<iClk<<" "<<t2d_fnf<<" "<<t2d_oldfnf<<endl;
1092 
1093  t3DFirmwareInfo[0][iClk][0] = t2d_fnf[5];
1094  t3DFirmwareInfo[0][iClk][1] = t2d_oldfnf[5];
1095  t3DFirmwareInfo[0][iClk][2] = tsf_fnf[3];
1096 
1097  t3DFirmwareInfo[0][iClk][3] = result3D->m_t3dtrk0_evtTimeValid_delay;
1098  t3DFirmwareInfo[0][iClk][4] = result3D->m_t3dtrk0_evtTime_delay;
1099  t3DFirmwareInfo[0][iClk][5] = charge;
1100  t3DFirmwareInfo[0][iClk][6] = radius;
1101  t3DFirmwareInfo[0][iClk][7] = phi_c;
1102  t3DFirmwareInfo[0][iClk][8] = z0;
1103  t3DFirmwareInfo[0][iClk][9] = cot;
1104  t3DFirmwareInfo[0][iClk][10] = chi2;
1105  }
1106 }
1107 
1108 // t3DFirmwareInfo[tIndex][iClk][2DValid, 2DisOld, TSFValid, EventTimeValid, eventTime, charge, rho, phi0, z0, cot, zchi]
1109 void TRGCDCT3DConverterModule::store3DFirmSimData(multi_array<double, 3>& t3DFirmwareInfo)
1110 {
1111  for (int iClk = 0; iClk < m_firmwareResults.getEntries() - 17 - 1; iClk++) {
1112 
1113  TRGCDCT3DUnpackerStore* result = m_firmwareResults[iClk];
1114  TRGCDCT3DUnpackerStore* result3D = m_firmwareResults[iClk + 17];
1115  TRGCDCT3DUnpackerStore* resultDebug = m_firmwareResults[iClk + 4];
1116 
1117  if (bitset<6> (result->m_t2d_fnf)[5] == 0) continue;
1118 
1119  // Store information(charge, radius(cm), phi_c(rad), eventTime, eventTimeValid, [TS ID, TS LR, TS driftTime])
1120  // [TODO] Is evtTime clock correct?
1121  int charge = resultDebug->m_t3dtrk0_charge == 2 ? -1 : 1;
1122  double radius = resultDebug->m_t3dtrk0_rho * 2500 / (pow(2, 11) - 0.5);
1123  double phi_c = toSigned(resultDebug->m_t3dtrk0_phi0, 13) * M_PI / (pow(2, 12) - 0.5);
1124  int eventTime = result3D->m_t3dtrk0_evtTime_delay;
1125  int eventTimeValid = result3D->m_t3dtrk0_evtTimeValid_delay;
1126  // rawStTSs[iSt] = [TS ID, TS LR, TS driftTime]
1127  vector<vector<int> > rawStTSs(4, vector<int> (3));
1128  rawStTSs[0][0] = resultDebug->m_t3dtrk0ts0_id;
1129  rawStTSs[0][1] = resultDebug->m_t3dtrk0ts0_lr;
1130  rawStTSs[0][2] = resultDebug->m_t3dtrk0ts0_rt;
1131  rawStTSs[1][0] = resultDebug->m_t3dtrk0ts1_id;
1132  rawStTSs[1][1] = resultDebug->m_t3dtrk0ts1_lr;
1133  rawStTSs[1][2] = resultDebug->m_t3dtrk0ts1_rt;
1134  rawStTSs[2][0] = resultDebug->m_t3dtrk0ts2_id;
1135  rawStTSs[2][1] = resultDebug->m_t3dtrk0ts2_lr;
1136  rawStTSs[2][2] = resultDebug->m_t3dtrk0ts2_rt;
1137  rawStTSs[3][0] = resultDebug->m_t3dtrk0ts3_id;
1138  rawStTSs[3][1] = resultDebug->m_t3dtrk0ts3_lr;
1139  rawStTSs[3][2] = resultDebug->m_t3dtrk0ts3_rt;
1140 
1141  // Get geometry
1142  map<string, vector<double> > stGeometry;
1143  vector<vector<double> > stXts;
1145  TRGCDCFitter3D::getStereoXt(stGeometry["priorityLayer"], stXts);
1146 
1147  // Prepare complex fit3D
1148  map<string, vector<double> > mConstV;
1149  map<string, double> mConstD;
1150  TRGCDCFitter3D::getConstants(mConstD, mConstV);
1151  Fitter3DUtility::fitter3DFirm(mConstD, mConstV, eventTimeValid, eventTime, rawStTSs, charge, radius, phi_c, m_commonData,
1153  double z0 = m_mSignalStorage["z0_r"].getRealInt();
1154  double cot = m_mSignalStorage["cot_r"].getRealInt();
1155  double chi2 = m_mSignalStorage["zChi2_r"].getRealInt();
1156 
1157  bitset<6> t2d_fnf(int(result3D->m_t3d_2dfnf));
1158  bitset<4> tsf_fnf(int(result3D->m_t3d_validTS));
1159  bitset<6> t2d_oldfnf(int(result->m_t3d_2doldtrk));
1160 
1161  //cout<<iClk<<" "<<t2d_fnf<<" "<<t2d_oldfnf<<endl;
1162 
1163  t3DFirmwareInfo[0][iClk][0] = t2d_fnf[5];
1164  t3DFirmwareInfo[0][iClk][1] = t2d_oldfnf[5];
1165  t3DFirmwareInfo[0][iClk][2] = tsf_fnf[3];
1166 
1167  t3DFirmwareInfo[0][iClk][3] = result3D->m_t3dtrk0_evtTimeValid_delay;
1168  t3DFirmwareInfo[0][iClk][4] = result3D->m_t3dtrk0_evtTime_delay;
1169  t3DFirmwareInfo[0][iClk][5] = charge;
1170  t3DFirmwareInfo[0][iClk][6] = radius;
1171  t3DFirmwareInfo[0][iClk][7] = phi_c;
1172  t3DFirmwareInfo[0][iClk][8] = z0;
1173  t3DFirmwareInfo[0][iClk][9] = cot;
1174  t3DFirmwareInfo[0][iClk][10] = chi2;
1175  }
1176 }
1177 
1179 {
1180  bool doPrint = (m_isVerbose > 1);
1181 
1182  for (int iClk = 0; iClk < m_firmwareResults.getEntries(); iClk++) {
1183  TRGCDCT3DUnpackerStore* result = m_firmwareResults[iClk];
1184  //bitset<6> t2d_fnf (int(result->m_t3d_2dfnf));
1185  //bitset<4> tsf_fnf (int(result->m_t3d_validTS));
1186 
1187  //cout<<"iClk:"<<iClk<<endl;
1188  //cout<<" [2D] fnf:"<<result->m_t2d_fnf<<" "<<bitset<6> (result->m_t2d_fnf)<<endl;
1189  //cout<<" [0] rho: "<<result->m_t2d0_rho_s<<" "<<toSigned(result->m_t2d0_rho_s, 7)<<" "<<int(0.3*34/30/1.5e-4/abs(toSigned(result->m_t2d0_rho_s, 7))*(pow(2,11)-0.5)/2500)<<" phi0: "<<result->m_t2d0_phi<<endl;
1190  //cout<<" [1] rho: "<<result->m_t2d1_rho_s<<" "<<toSigned(result->m_t2d1_rho_s, 7)<<" "<<int(0.3*34/30/1.5e-4/abs(toSigned(result->m_t2d1_rho_s, 7))*(pow(2,11)-0.5)/2500)<<" phi0: "<<result->m_t2d1_phi<<endl;
1191  //cout<<" [2] rho: "<<result->m_t2d2_rho_s<<" "<<toSigned(result->m_t2d2_rho_s, 7)<<" "<<int(0.3*34/30/1.5e-4/abs(toSigned(result->m_t2d2_rho_s, 7))*(pow(2,11)-0.5)/2500)<<" phi0: "<<result->m_t2d2_phi<<endl;
1192  //cout<<" [3] rho: "<<result->m_t2d3_rho_s<<" "<<toSigned(result->m_t2d3_rho_s, 7)<<" "<<int(0.3*34/30/1.5e-4/abs(toSigned(result->m_t2d3_rho_s, 7))*(pow(2,11)-0.5)/2500)<<" phi0: "<<result->m_t2d3_phi<<endl;
1193  //cout<<" [3D] fnf:"<<result->m_t3d_2dfnf<<" "<<t2d_fnf<<" "<<t2d_fnf[5]<<" tsValid: "<<result->m_t3d_validTS<<" "<<tsf_fnf<<endl;;
1194  //cout<<" [0] z0: "<<result->m_t3dtrk0_z0_s<<" cot: "<<result->m_t3dtrk0_cot_s<<" chi2: "<<result->m_t3dtrk0_zchisq<<endl;
1195  //cout<<" [1] z0: "<<result->m_t3dtrk1_z0_s<<" cot: "<<result->m_t3dtrk1_cot_s<<" chi2: "<<result->m_t3dtrk1_zchisq<<endl;
1196  //cout<<" [2] z0: "<<result->m_t3dtrk2_z0_s<<" cot: "<<result->m_t3dtrk2_cot_s<<" chi2: "<<result->m_t3dtrk2_zchisq<<endl;
1197  //cout<<" [3] z0: "<<result->m_t3dtrk3_z0_s<<" cot: "<<result->m_t3dtrk3_cot_s<<" chi2: "<<result->m_t3dtrk3_zchisq<<endl;
1198  //cout<<" [debug] MSB"<<endl;
1199  //cout<<" evtTime: "<<result->m_t3dtrk0_evtTime_delay<<" evtTimeValid: "<<result->m_t3dtrk0_evtTimeValid_delay<<endl;
1200  //cout<<" charge: "<<result->m_t3dtrk0_charge<<" rho: "<<result->m_t3dtrk0_rho<<" phi0: "<<result->m_t3dtrk0_phi0<<endl;;
1201  //cout<<" ts0 id: "<<result->m_t3dtrk0ts0_id<<" lr: "<<result->m_t3dtrk0ts0_lr<<" rt: "<<result->m_t3dtrk0ts0_rt<<endl;
1202  //cout<<" ts1 id: "<<result->m_t3dtrk0ts1_id<<" lr: "<<result->m_t3dtrk0ts1_lr<<" rt: "<<result->m_t3dtrk0ts1_rt<<endl;
1203  //cout<<" ts2 id: "<<result->m_t3dtrk0ts2_id<<" lr: "<<result->m_t3dtrk0ts2_lr<<" rt: "<<result->m_t3dtrk0ts2_rt<<endl;
1204  //cout<<" ts3 id: "<<result->m_t3dtrk0ts3_id<<" lr: "<<result->m_t3dtrk0ts3_lr<<" rt: "<<result->m_t3dtrk0ts3_rt<<endl;
1205  //cout<<" [debug] LSB"<<endl;
1206  //cout<<" evtTime: "<<result->m_t3dtrk1_evtTime_delay<<" evtTimeValid: "<<result->m_t3dtrk1_evtTimeValid_delay<<endl;
1207  //cout<<" charge: "<<result->m_t3dtrk1_charge<<" rho: "<<result->m_t3dtrk1_rho<<" phi0: "<<result->m_t3dtrk1_phi0<<endl;;
1208  //cout<<" ts0 id: "<<result->m_t3dtrk1ts0_id<<" lr: "<<result->m_t3dtrk1ts0_lr<<" rt: "<<result->m_t3dtrk1ts0_rt<<endl;
1209  //cout<<" ts1 id: "<<result->m_t3dtrk1ts1_id<<" lr: "<<result->m_t3dtrk1ts1_lr<<" rt: "<<result->m_t3dtrk1ts1_rt<<endl;
1210  //cout<<" ts2 id: "<<result->m_t3dtrk1ts2_id<<" lr: "<<result->m_t3dtrk1ts2_lr<<" rt: "<<result->m_t3dtrk1ts2_rt<<endl;
1211  //cout<<" ts3 id: "<<result->m_t3dtrk1ts3_id<<" lr: "<<result->m_t3dtrk1ts3_lr<<" rt: "<<result->m_t3dtrk1ts3_rt<<endl;
1212 
1214  //if (result->m_t2d_fnf && iClk < 48-4-1 && bitset<6> (result->m_t2d_fnf)[5])
1215  //{
1216  // TRGCDCT3DUnpackerStore * resultDebug = m_firmwareResults[iClk+4];
1217  // if(t2DRhoTot3DRho(result->m_t2d0_rho_s) == resultDebug->m_t3dtrk0_rho)
1218  // {
1219  // cout<<"Matched 2D0 and debug0"<<endl;
1220  // } else {
1221  // cout<<"iClk:"<<iClk<<endl;
1222  // cout<<" [2D] fnf:"<<result->m_t2d_fnf<<" "<<bitset<6> (result->m_t2d_fnf)<<endl;
1223  // cout<<" [0] rho: "<<result->m_t2d0_rho_s<<" "<<toSigned(result->m_t2d0_rho_s, 7)<<" "<<t2DRhoTot3DRho(result->m_t2d0_rho_s)<<" phi0: "<<result->m_t2d0_phi<<endl;
1224  // cout<<" [1] rho: "<<result->m_t2d1_rho_s<<" "<<toSigned(result->m_t2d1_rho_s, 7)<<" "<<t2DRhoTot3DRho(result->m_t2d1_rho_s)<<" phi0: "<<result->m_t2d1_phi<<endl;
1225  // cout<<" [2] rho: "<<result->m_t2d2_rho_s<<" "<<toSigned(result->m_t2d2_rho_s, 7)<<" "<<t2DRhoTot3DRho(result->m_t2d2_rho_s)<<" phi0: "<<result->m_t2d2_phi<<endl;
1226  // cout<<" [3] rho: "<<result->m_t2d3_rho_s<<" "<<toSigned(result->m_t2d3_rho_s, 7)<<" "<<t2DRhoTot3DRho(result->m_t2d3_rho_s)<<" phi0: "<<result->m_t2d3_phi<<endl;
1227  // cout<<" [3DDebug] MSB"<<endl;
1228  // cout<<" charge: "<<resultDebug->m_t3dtrk0_charge<<" rho: "<<resultDebug->m_t3dtrk0_rho<<" phi0: "<<resultDebug->m_t3dtrk0_phi0<<endl;;
1229  // cout<<" ts0 id: "<<resultDebug->m_t3dtrk0ts0_id<<" lr: "<<resultDebug->m_t3dtrk0ts0_lr<<" rt: "<<resultDebug->m_t3dtrk0ts0_rt<<endl;
1230  // cout<<" ts1 id: "<<resultDebug->m_t3dtrk0ts1_id<<" lr: "<<resultDebug->m_t3dtrk0ts1_lr<<" rt: "<<resultDebug->m_t3dtrk0ts1_rt<<endl;
1231  // cout<<" ts2 id: "<<resultDebug->m_t3dtrk0ts2_id<<" lr: "<<resultDebug->m_t3dtrk0ts2_lr<<" rt: "<<resultDebug->m_t3dtrk0ts2_rt<<endl;
1232  // cout<<" ts3 id: "<<resultDebug->m_t3dtrk0ts3_id<<" lr: "<<resultDebug->m_t3dtrk0ts3_lr<<" rt: "<<resultDebug->m_t3dtrk0ts3_rt<<endl;
1233  // }
1234  //}
1235 
1237  //if (iClk < 48-4-1 && bitset<6> (result->m_t2d_fnf)[2])
1238  //{
1239  // TRGCDCT3DUnpackerStore * resultDebug = m_firmwareResults[iClk+4];
1240  // if(t2DRhoTot3DRho(result->m_t2d3_rho_s) == resultDebug->m_t3dtrk1_rho)
1241  // {
1242  // cout<<"Matched 2D3 and debug1"<<endl;
1243  // } else {
1244  // cout<<"iClk:"<<iClk<<endl;
1245  // cout<<" [2D] fnf:"<<result->m_t2d_fnf<<" "<<bitset<6> (result->m_t2d_fnf)<<endl;
1246  // cout<<" [0] rho: "<<result->m_t2d0_rho_s<<" "<<toSigned(result->m_t2d0_rho_s, 7)<<" "<<t2DRhoTot3DRho(result->m_t2d0_rho_s)<<" phi0: "<<result->m_t2d0_phi<<endl;
1247  // cout<<" [1] rho: "<<result->m_t2d1_rho_s<<" "<<toSigned(result->m_t2d1_rho_s, 7)<<" "<<t2DRhoTot3DRho(result->m_t2d1_rho_s)<<" phi0: "<<result->m_t2d1_phi<<endl;
1248  // cout<<" [2] rho: "<<result->m_t2d2_rho_s<<" "<<toSigned(result->m_t2d2_rho_s, 7)<<" "<<t2DRhoTot3DRho(result->m_t2d2_rho_s)<<" phi0: "<<result->m_t2d2_phi<<endl;
1249  // cout<<" [3] rho: "<<result->m_t2d3_rho_s<<" "<<toSigned(result->m_t2d3_rho_s, 7)<<" "<<t2DRhoTot3DRho(result->m_t2d3_rho_s)<<" phi0: "<<result->m_t2d3_phi<<endl;
1250  // cout<<" [3DDebug] LSB"<<endl;
1251  // cout<<" evtTime: "<<resultDebug->m_t3dtrk1_evtTime_delay<<" evtTimeValid: "<<resultDebug->m_t3dtrk1_evtTimeValid_delay<<endl;
1252  // cout<<" charge: "<<resultDebug->m_t3dtrk1_charge<<" rho: "<<resultDebug->m_t3dtrk1_rho<<" phi0: "<<resultDebug->m_t3dtrk1_phi0<<endl;;
1253  // cout<<" ts0 id: "<<resultDebug->m_t3dtrk1ts0_id<<" lr: "<<resultDebug->m_t3dtrk1ts0_lr<<" rt: "<<resultDebug->m_t3dtrk1ts0_rt<<endl;
1254  // cout<<" ts1 id: "<<resultDebug->m_t3dtrk1ts1_id<<" lr: "<<resultDebug->m_t3dtrk1ts1_lr<<" rt: "<<resultDebug->m_t3dtrk1ts1_rt<<endl;
1255  // cout<<" ts2 id: "<<resultDebug->m_t3dtrk1ts2_id<<" lr: "<<resultDebug->m_t3dtrk1ts2_lr<<" rt: "<<resultDebug->m_t3dtrk1ts2_rt<<endl;
1256  // cout<<" ts3 id: "<<resultDebug->m_t3dtrk1ts3_id<<" lr: "<<resultDebug->m_t3dtrk1ts3_lr<<" rt: "<<resultDebug->m_t3dtrk1ts3_rt<<endl;
1257  // }
1258  //}
1259 
1261  //int countTrk0 = int(result->m_t3dtrk0ts0_lr!=0)+int(result->m_t3dtrk0ts1_lr!=0)+int(result->m_t3dtrk0ts2_lr!=0)+int(result->m_t3dtrk0ts3_lr!=0);
1262  //if ( iClk < 48 - 7 - 1)
1263  //{
1264  // TRGCDCT3DUnpackerStore * resultDebug = m_firmwareResults[iClk];
1265  // TRGCDCT3DUnpackerStore * result = m_firmwareResults[iClk+7];
1266 
1267  // if (int(countTrk0 > 1) == bitset<4> (int(result->m_t3d_validTS))[3])
1268  // {
1269  // cout<<"debug TSF matches with TSFValid0"<<endl;
1270  // } else {
1271  // cout<<"iClk:"<<iClk+7<<endl;
1272  // cout<<" [3D] fnf:"<<result->m_t3d_2dfnf<<" "<<bitset<6> (int(result->m_t3d_2dfnf))<<" tsValid: "<<result->m_t3d_validTS<<" "<<bitset<4> (int(result->m_t3d_validTS))<<endl;;
1273  // cout<<" [3DDebug] MSB"<<endl;
1274  // cout<<" charge: "<<resultDebug->m_t3dtrk0_charge<<" rho: "<<resultDebug->m_t3dtrk0_rho<<" phi0: "<<resultDebug->m_t3dtrk0_phi0<<endl;;
1275  // cout<<" ts0 id: "<<resultDebug->m_t3dtrk0ts0_id<<" lr: "<<resultDebug->m_t3dtrk0ts0_lr<<" rt: "<<resultDebug->m_t3dtrk0ts0_rt<<endl;
1276  // cout<<" ts1 id: "<<resultDebug->m_t3dtrk0ts1_id<<" lr: "<<resultDebug->m_t3dtrk0ts1_lr<<" rt: "<<resultDebug->m_t3dtrk0ts1_rt<<endl;
1277  // cout<<" ts2 id: "<<resultDebug->m_t3dtrk0ts2_id<<" lr: "<<resultDebug->m_t3dtrk0ts2_lr<<" rt: "<<resultDebug->m_t3dtrk0ts2_rt<<endl;
1278  // cout<<" ts3 id: "<<resultDebug->m_t3dtrk0ts3_id<<" lr: "<<resultDebug->m_t3dtrk0ts3_lr<<" rt: "<<resultDebug->m_t3dtrk0ts3_rt<<endl;
1279  // cout<<" count: "<<countTrk0<<endl;
1280  // }
1281  //}
1282 
1284  //int countTrk3 = int(result->m_t3dtrk1ts0_lr!=0)+int(result->m_t3dtrk1ts1_lr!=0)+int(result->m_t3dtrk1ts2_lr!=0)+int(result->m_t3dtrk1ts3_lr!=0);
1285  //if ( iClk < 48 - 7 - 1)
1286  //{
1287  // TRGCDCT3DUnpackerStore * resultDebug = m_firmwareResults[iClk];
1288  // TRGCDCT3DUnpackerStore * result = m_firmwareResults[iClk+7];
1289 
1290  // if (int(countTrk3 > 1) == bitset<4> (int(result->m_t3d_validTS))[2])
1291  // {
1292  // cout<<"debug TSF matches with TSFValid3"<<endl;
1293  // } else {
1294  // cout<<"iClk:"<<iClk+7<<endl;
1295  // cout<<" [3D] fnf:"<<result->m_t3d_2dfnf<<" "<<bitset<6> (int(result->m_t3d_2dfnf))<<" tsValid: "<<result->m_t3d_validTS<<" "<<bitset<4> (int(result->m_t3d_validTS))<<endl;;
1296  // cout<<" [3DDebug] LSB"<<endl;
1297  // cout<<" charge: "<<resultDebug->m_t3dtrk1_charge<<" rho: "<<resultDebug->m_t3dtrk1_rho<<" phi0: "<<resultDebug->m_t3dtrk1_phi0<<endl;;
1298  // cout<<" ts0 id: "<<resultDebug->m_t3dtrk1ts0_id<<" lr: "<<resultDebug->m_t3dtrk1ts0_lr<<" rt: "<<resultDebug->m_t3dtrk1ts0_rt<<endl;
1299  // cout<<" ts1 id: "<<resultDebug->m_t3dtrk1ts1_id<<" lr: "<<resultDebug->m_t3dtrk1ts1_lr<<" rt: "<<resultDebug->m_t3dtrk1ts1_rt<<endl;
1300  // cout<<" ts2 id: "<<resultDebug->m_t3dtrk1ts2_id<<" lr: "<<resultDebug->m_t3dtrk1ts2_lr<<" rt: "<<resultDebug->m_t3dtrk1ts2_rt<<endl;
1301  // cout<<" ts3 id: "<<resultDebug->m_t3dtrk1ts3_id<<" lr: "<<resultDebug->m_t3dtrk1ts3_lr<<" rt: "<<resultDebug->m_t3dtrk1ts3_rt<<endl;
1302  // cout<<" count: "<<countTrk3<<endl;
1303  // }
1304  //}
1305 
1306  // Compare 2D with debug and 3D after 4 clks and 11 clks
1307  if (result->m_t2d_fnf && iClk < 48 - 17 - 1 && bitset<6> (result->m_t2d_fnf)[5]) {
1308  TRGCDCT3DUnpackerStore* resultDebug = m_firmwareResults[iClk + 4];
1309  TRGCDCT3DUnpackerStore* result3D = m_firmwareResults[iClk + 17];
1310 
1311  // Store information(charge, radius(cm), phi_c(rad), eventTime, eventTimeValid, [TS ID, TS LR, TS driftTime])
1312  // [TODO] Is evtTime clock correct?
1313  int charge = resultDebug->m_t3dtrk0_charge;
1314  double radius = resultDebug->m_t3dtrk0_rho * 2500 / (pow(2, 11) - 0.5);
1315  double phi_c = toSigned(resultDebug->m_t3dtrk0_phi0, 13) * M_PI / (pow(2, 12) - 0.5);
1316  int eventTime = result3D->m_t3dtrk0_evtTime_delay;
1317  int eventTimeValid = result3D->m_t3dtrk0_evtTimeValid_delay;
1318  // rawStTSs[iSt] = [TS ID, TS LR, TS driftTime]
1319  vector<vector<int> > rawStTSs(4, vector<int> (3));
1320  rawStTSs[0][0] = resultDebug->m_t3dtrk0ts0_id;
1321  rawStTSs[0][1] = resultDebug->m_t3dtrk0ts0_lr;
1322  rawStTSs[0][2] = resultDebug->m_t3dtrk0ts0_rt;
1323  rawStTSs[1][0] = resultDebug->m_t3dtrk0ts1_id;
1324  rawStTSs[1][1] = resultDebug->m_t3dtrk0ts1_lr;
1325  rawStTSs[1][2] = resultDebug->m_t3dtrk0ts1_rt;
1326  rawStTSs[2][0] = resultDebug->m_t3dtrk0ts2_id;
1327  rawStTSs[2][1] = resultDebug->m_t3dtrk0ts2_lr;
1328  rawStTSs[2][2] = resultDebug->m_t3dtrk0ts2_rt;
1329  rawStTSs[3][0] = resultDebug->m_t3dtrk0ts3_id;
1330  rawStTSs[3][1] = resultDebug->m_t3dtrk0ts3_lr;
1331  rawStTSs[3][2] = resultDebug->m_t3dtrk0ts3_rt;
1332 
1333  // Get geometry
1334  map<string, vector<double> > stGeometry;
1335  vector<vector<double> > stXts;
1337  TRGCDCFitter3D::getStereoXt(stGeometry["priorityLayer"], stXts);
1338  //Fitter3DUtility::loadStereoXt("TODOdata/stereoXt",4,stXts);
1339 
1341  //vector<double> stTSs(4);
1342  //Fitter3DUtility::calPhiFast(stGeometry, stXts, eventTimeValid, eventTime, rawStTSs, stTSs);
1343  //cout<<" [calPhi] "<<stTSs[0]<<" "<<stTSs[1]<<" "<<stTSs[2]<<" "<<stTSs[3]<<endl;
1345  //vector<double> invZError2;
1346  //Fitter3DUtility::setErrorFast(rawStTSs, eventTimeValid, invZError2);
1347  //cout<<" [invZError2] "<<invZError2[0]<<" "<<invZError2[1]<<" "<<invZError2[2]<<" "<<invZError2[3]<<endl;
1350  //vector<double> zz(4, 0);
1351  //vector<double> arcS(4, 0);
1352  //for (unsigned iSt = 0; iSt < 4; iSt++) {
1353  // if (rawStTSs[iSt][1] != 0) {
1354  // zz[iSt] = Fitter3DUtility::calZ(charge, stGeometry["angleSt"][iSt], stGeometry["zToStraw"][iSt],
1355  // stGeometry["cdcRadius"][iSt], stTSs[iSt], radius, phi_c);
1356  // arcS[iSt] = Fitter3DUtility::calS(radius, stGeometry["cdcRadius"][iSt]);
1357  // }
1358  //}
1359  //cout<<" [zz] "<<zz[0]<<" "<<zz[1]<<" "<<zz[2]<<" "<<zz[3]<<endl;
1360  //cout<<" [arcS] "<<arcS[0]<<" "<<arcS[1]<<" "<<arcS[2]<<" "<<arcS[3]<<endl;
1362  //double z0 = 0;
1363  //double cot = 0;
1364  //double chi2 = 0;
1365  //Fitter3DUtility::rSFit(&invZError2[0], &arcS[0], &zz[0], z0, cot, chi2);
1366  double z0 = 0;
1367  double cot = 0;
1368  double chi2 = 0;
1369  Fitter3DUtility::fitter3D(stGeometry, stXts, eventTimeValid, eventTime, rawStTSs, charge, radius, phi_c, z0, cot, chi2);
1370 
1371  // Prepare complex fit3D
1372  map<string, vector<double> > mConstV;
1373  map<string, double> mConstD;
1374  TRGCDCFitter3D::getConstants(mConstD, mConstV);
1375  //Belle2::TRGCDCJSignalData commonData;
1376  //map<string, TRGCDCJSignal> mSignalStorage;
1377  //map<string, TRGCDCJLUT*> mLutStorage;
1378  Fitter3DUtility::fitter3DFirm(mConstD, mConstV, eventTimeValid, eventTime, rawStTSs, charge, radius, phi_c, m_commonData,
1380 
1383  //vector<tuple<string, double, int, double, double, int> > t_values = {
1384  // make_tuple("phi0", phi_c, mConstD["phiBitSize"], mConstD["phiMin"], mConstD["phiMax"], 0),
1385  // make_tuple("rho", radius, mConstD["rhoBitSize"], mConstD["rhoMin"], mConstD["rhoMax"], 0),
1386  // //make_tuple("charge",(int) (m_mDouble["charge"]==1 ? 1 : 0), 1, 0, 1.5, 0),
1387  // make_tuple("charge", (int)(charge == 1 ? 1 : 0), 1, 0, 1.5, 0),
1388  // make_tuple("lr_0", rawStTSs[0][1], 2, 0, 3.5, 0),
1389  // make_tuple("lr_1", rawStTSs[1][1], 2, 0, 3.5, 0),
1390  // make_tuple("lr_2", rawStTSs[2][1], 2, 0, 3.5, 0),
1391  // make_tuple("lr_3", rawStTSs[3][1], 2, 0, 3.5, 0),
1392  // make_tuple("tsId_0", rawStTSs[0][0], ceil(log(mConstV["nTSs"][1]) / log(2)), 0, pow(2, ceil(log(mConstV["nTSs"][1]) / log(2))) - 0.5, 0),
1393  // make_tuple("tsId_1", rawStTSs[1][0], ceil(log(mConstV["nTSs"][3]) / log(2)), 0, pow(2, ceil(log(mConstV["nTSs"][3]) / log(2))) - 0.5, 0),
1394  // make_tuple("tsId_2", rawStTSs[2][0], ceil(log(mConstV["nTSs"][5]) / log(2)), 0, pow(2, ceil(log(mConstV["nTSs"][5]) / log(2))) - 0.5, 0),
1395  // make_tuple("tsId_3", rawStTSs[3][0], ceil(log(mConstV["nTSs"][7]) / log(2)), 0, pow(2, ceil(log(mConstV["nTSs"][7]) / log(2))) - 0.5, 0),
1396  // make_tuple("tdc_0", rawStTSs[0][2], mConstD["tdcBitSize"], 0, pow(2, mConstD["tdcBitSize"]) - 0.5, 0),
1397  // make_tuple("tdc_1", rawStTSs[1][2], mConstD["tdcBitSize"], 0, pow(2, mConstD["tdcBitSize"]) - 0.5, 0),
1398  // make_tuple("tdc_2", rawStTSs[2][2], mConstD["tdcBitSize"], 0, pow(2, mConstD["tdcBitSize"]) - 0.5, 0),
1399  // make_tuple("tdc_3", rawStTSs[3][2], mConstD["tdcBitSize"], 0, pow(2, mConstD["tdcBitSize"]) - 0.5, 0),
1400  // make_tuple("eventTime", eventTime, mConstD["tdcBitSize"], 0, pow(2, mConstD["tdcBitSize"]) - 0.5, 0),
1401  // make_tuple("eventTimeValid", eventTimeValid, 1, 0, 1.5, 0),
1402  //};
1403  //TRGCDCJSignal::valuesToMapSignals(t_values, m_commonData, m_mSignalStorage);
1405  //Fitter3DUtility::setError(mConstD, mConstV, m_mSignalStorage);
1406  //Fitter3DUtility::calPhi(mConstD, mConstV, m_mSignalStorage, m_mLutStorage);
1407  //Fitter3DUtility::constrainRPerStSl(mConstV, m_mSignalStorage);
1408  //Fitter3DUtility::calZ(mConstD, mConstV, m_mSignalStorage, m_mLutStorage);
1409  //Fitter3DUtility::calS(mConstD, mConstV, m_mSignalStorage, m_mLutStorage);
1410  //Fitter3DUtility::rSFit(mConstD, mConstV, m_mSignalStorage, m_mLutStorage);
1413  //if ((*m_mSignalStorage.begin()).second.getName() == "") {
1414  // for (auto it = m_mSignalStorage.begin(); it != m_mSignalStorage.end(); ++it) {
1415  // (*it).second.setName((*it).first);
1416  // }
1417  //}
1418 
1419  if (toSigned(result3D->m_t3dtrk0_z0_s, 11) != m_mSignalStorage["z0_r"].getInt()
1420  || toSigned(result3D->m_t3dtrk0_cot_s, 11) != m_mSignalStorage["cot_r"].getInt()) {
1421  bitset<6> t2d_oldfnf(int(result->m_t3d_2doldtrk));
1422  cout << "iClk:" << iClk << endl;
1423  cout << " [2D] fnf:" << result->m_t2d_fnf << " " << bitset<6> (result->m_t2d_fnf) << " oldfnf: " << t2d_oldfnf << endl;
1424 // cout << " [0] rho: " << result->m_t2d0_rho_s << " " << t2DRhoTot3DRho(result->m_t2d0_rho_s) << " phi0: " << result->m_t2d0_phi <<
1425 // " " << t2DPhiTot3DPhi(result->m_t2d0_phi, result->m_t2d0_rho_s) << endl;
1426  cout << " [debug] MSB" << endl;
1427  cout << " charge: " << resultDebug->m_t3dtrk0_charge << " rho: " << resultDebug->m_t3dtrk0_rho << " phi0: " << toSigned(
1428  resultDebug->m_t3dtrk0_phi0, 13) << endl;;
1429  cout << " ts0 id: " << resultDebug->m_t3dtrk0ts0_id << " lr: " << resultDebug->m_t3dtrk0ts0_lr << " rt: " <<
1430  resultDebug->m_t3dtrk0ts0_rt << endl;
1431  cout << " ts1 id: " << resultDebug->m_t3dtrk0ts1_id << " lr: " << resultDebug->m_t3dtrk0ts1_lr << " rt: " <<
1432  resultDebug->m_t3dtrk0ts1_rt << endl;
1433  cout << " ts2 id: " << resultDebug->m_t3dtrk0ts2_id << " lr: " << resultDebug->m_t3dtrk0ts2_lr << " rt: " <<
1434  resultDebug->m_t3dtrk0ts2_rt << endl;
1435  cout << " ts3 id: " << resultDebug->m_t3dtrk0ts3_id << " lr: " << resultDebug->m_t3dtrk0ts3_lr << " rt: " <<
1436  resultDebug->m_t3dtrk0ts3_rt << endl;
1437  cout << " [3D] fnf:" << result3D->m_t3d_2dfnf << " " << bitset<6> (result3D->m_t3d_2dfnf) << " tsValid: " <<
1438  result3D->m_t3d_validTS << " " << bitset<4> (result3D->m_t3d_validTS) << endl;;
1439  cout << " [0] z0: " << result3D->m_t3dtrk0_z0_s << " " << toSigned(result3D->m_t3dtrk0_z0_s,
1440  11) << " " << toSigned(result3D->m_t3dtrk0_z0_s,
1441  11) * 0.0382 << " cot: " << result3D->m_t3dtrk0_cot_s << " " << toSigned(result3D->m_t3dtrk0_cot_s,
1442  11) << " " << toSigned(result3D->m_t3dtrk0_cot_s, 11) * 0.00195 << " chi2: " << result3D->m_t3dtrk0_zchisq << endl;
1443  cout << " [1] z0: " << result3D->m_t3dtrk1_z0_s << " " << toSigned(result3D->m_t3dtrk1_z0_s,
1444  11) << " " << toSigned(result3D->m_t3dtrk1_z0_s,
1445  11) * 0.0382 << " cot: " << result3D->m_t3dtrk1_cot_s << " " << toSigned(result3D->m_t3dtrk1_cot_s,
1446  11) << " " << toSigned(result3D->m_t3dtrk1_cot_s, 11) * 0.00195 << " chi2: " << result3D->m_t3dtrk1_zchisq << endl;
1447  cout << " [2] z0: " << result3D->m_t3dtrk2_z0_s << " " << toSigned(result3D->m_t3dtrk2_z0_s,
1448  11) << " " << toSigned(result3D->m_t3dtrk2_z0_s,
1449  11) * 0.0382 << " cot: " << result3D->m_t3dtrk2_cot_s << " " << toSigned(result3D->m_t3dtrk2_cot_s,
1450  11) << " " << toSigned(result3D->m_t3dtrk2_cot_s, 11) * 0.00195 << " chi2: " << result3D->m_t3dtrk2_zchisq << endl;
1451  cout << " [3] z0: " << result3D->m_t3dtrk3_z0_s << " " << toSigned(result3D->m_t3dtrk3_z0_s,
1452  11) << " " << toSigned(result3D->m_t3dtrk3_z0_s,
1453  11) * 0.0382 << " cot: " << result3D->m_t3dtrk3_cot_s << " " << toSigned(result3D->m_t3dtrk3_cot_s,
1454  11) << " " << toSigned(result3D->m_t3dtrk3_cot_s, 11) * 0.00195 << " chi2: " << result3D->m_t3dtrk3_zchisq << endl;
1455  cout << " evtTime: " << result3D->m_t3dtrk0_evtTime_delay << " evtTimeValid: " << result3D->m_t3dtrk0_evtTimeValid_delay << endl;
1456 
1457  cout << " [Store information]" << endl;
1458  cout << " charge: " << charge << " radius(cm): " << radius << " phi_c(rad): " << phi_c << endl;
1459  cout << " eventTime: " << eventTime << " valid: " << eventTimeValid << endl;
1460  cout << " rawStTSs[0] id:" << rawStTSs[0][0] << " lr: " << rawStTSs[0][1] << " rt: " << rawStTSs[0][2] << endl;
1461  cout << " rawStTSs[1] id:" << rawStTSs[1][0] << " lr: " << rawStTSs[1][1] << " rt: " << rawStTSs[1][2] << endl;
1462  cout << " rawStTSs[2] id:" << rawStTSs[2][0] << " lr: " << rawStTSs[2][1] << " rt: " << rawStTSs[2][2] << endl;
1463  cout << " rawStTSs[3] id:" << rawStTSs[3][0] << " lr: " << rawStTSs[3][1] << " rt: " << rawStTSs[3][2] << endl;
1464 
1465  cout << " [Calculate fast]" << endl;
1466  cout << " [z0] " << z0 << " [cot] " << cot << " [chi2] " << chi2 << endl;
1467 
1468  cout << " [Calculate firm]" << endl;
1469  cout << " z0: " << m_mSignalStorage["z0_r"].getInt() << " " << m_mSignalStorage["z0_r"].getRealInt() << " " <<
1470  m_mSignalStorage["z0_r"].getToReal() << " cot: " << m_mSignalStorage["cot_r"].getInt() << " " <<
1471  m_mSignalStorage["cot_r"].getRealInt() << " " << m_mSignalStorage["cot_r"].getToReal() << " zchi: " <<
1472  m_mSignalStorage["zChi2_r"].getInt() << " " << m_mSignalStorage["zChi2_r"].getRealInt() << " " <<
1473  m_mSignalStorage["zChi2_r"].getToReal() << endl;
1474  //doPrint = 1;
1475  }
1476  //else
1477  //{
1478  // cout<<"same"<<endl;
1479  //}
1480 
1481  }
1482 
1483  }
1484 
1485  if (doPrint) {
1486  for (int iClk = 0; iClk < m_firmwareResults.getEntries(); iClk++) {
1487  TRGCDCT3DUnpackerStore* result = m_firmwareResults[iClk];
1488  bitset<6> t2d_fnf(int(result->m_t3d_2dfnf));
1489  bitset<4> tsf_fnf(int(result->m_t3d_validTS));
1490  bitset<6> t2d_oldfnf(int(result->m_t3d_2doldtrk));
1491  cout << "iClk:" << iClk << endl;
1492  cout << " [2D] fnf:" << result->m_t2d_fnf << " " << bitset<6> (result->m_t2d_fnf) << " oldfnf: " << t2d_oldfnf << endl;
1493  cout << " [0] rho: " << result->m_t2d0_rho_s << " " << toSigned(result->m_t2d0_rho_s,
1494  7) << " " << int(0.3 * 34 / 30 / 1.5e-4 / abs(toSigned(result->m_t2d0_rho_s, 7)) * (pow(2,
1495  11) - 0.5) / 2500) << " phi0: " << result->m_t2d0_phi << endl;
1496  cout << " [1] rho: " << result->m_t2d1_rho_s << " " << toSigned(result->m_t2d1_rho_s,
1497  7) << " " << int(0.3 * 34 / 30 / 1.5e-4 / abs(toSigned(result->m_t2d1_rho_s, 7)) * (pow(2,
1498  11) - 0.5) / 2500) << " phi0: " << result->m_t2d1_phi << endl;
1499  cout << " [2] rho: " << result->m_t2d2_rho_s << " " << toSigned(result->m_t2d2_rho_s,
1500  7) << " " << int(0.3 * 34 / 30 / 1.5e-4 / abs(toSigned(result->m_t2d2_rho_s, 7)) * (pow(2,
1501  11) - 0.5) / 2500) << " phi0: " << result->m_t2d2_phi << endl;
1502  cout << " [3] rho: " << result->m_t2d3_rho_s << " " << toSigned(result->m_t2d3_rho_s,
1503  7) << " " << int(0.3 * 34 / 30 / 1.5e-4 / abs(toSigned(result->m_t2d3_rho_s, 7)) * (pow(2,
1504  11) - 0.5) / 2500) << " phi0: " << result->m_t2d3_phi << endl;
1505  cout << " [3D] fnf:" << result->m_t3d_2dfnf << " " << t2d_fnf << " " << t2d_fnf[5] << " tsValid: " << result->m_t3d_validTS << " "
1506  << tsf_fnf << endl;;
1507  cout << " [0] z0: " << result->m_t3dtrk0_z0_s << " cot: " << result->m_t3dtrk0_cot_s << " chi2: " << result->m_t3dtrk0_zchisq
1508  << endl;
1509  cout << " [1] z0: " << result->m_t3dtrk1_z0_s << " cot: " << result->m_t3dtrk1_cot_s << " chi2: " << result->m_t3dtrk1_zchisq
1510  << endl;
1511  cout << " [2] z0: " << result->m_t3dtrk2_z0_s << " cot: " << result->m_t3dtrk2_cot_s << " chi2: " << result->m_t3dtrk2_zchisq
1512  << endl;
1513  cout << " [3] z0: " << result->m_t3dtrk3_z0_s << " cot: " << result->m_t3dtrk3_cot_s << " chi2: " << result->m_t3dtrk3_zchisq
1514  << endl;
1515  cout << " [debug] MSB" << endl;
1516  cout << " evtTime: " << result->m_t3dtrk0_evtTime_delay << " evtTimeValid: " << result->m_t3dtrk0_evtTimeValid_delay <<
1517  endl;
1518  cout << " charge: " << result->m_t3dtrk0_charge << " rho: " << result->m_t3dtrk0_rho << " phi0: " << result->m_t3dtrk0_phi0
1519  << endl;;
1520  cout << " ts0 id: " << result->m_t3dtrk0ts0_id << " lr: " << result->m_t3dtrk0ts0_lr << " rt: " << result->m_t3dtrk0ts0_rt
1521  << endl;
1522  cout << " ts1 id: " << result->m_t3dtrk0ts1_id << " lr: " << result->m_t3dtrk0ts1_lr << " rt: " << result->m_t3dtrk0ts1_rt
1523  << endl;
1524  cout << " ts2 id: " << result->m_t3dtrk0ts2_id << " lr: " << result->m_t3dtrk0ts2_lr << " rt: " << result->m_t3dtrk0ts2_rt
1525  << endl;
1526  cout << " ts3 id: " << result->m_t3dtrk0ts3_id << " lr: " << result->m_t3dtrk0ts3_lr << " rt: " << result->m_t3dtrk0ts3_rt
1527  << endl;
1528  cout << " [debug] LSB" << endl;
1529  cout << " evtTime: " << result->m_t3dtrk1_evtTime_delay << " evtTimeValid: " << result->m_t3dtrk1_evtTimeValid_delay <<
1530  endl;
1531  cout << " charge: " << result->m_t3dtrk1_charge << " rho: " << result->m_t3dtrk1_rho << " phi0: " << result->m_t3dtrk1_phi0
1532  << endl;;
1533  cout << " ts0 id: " << result->m_t3dtrk1ts0_id << " lr: " << result->m_t3dtrk1ts0_lr << " rt: " << result->m_t3dtrk1ts0_rt
1534  << endl;
1535  cout << " ts1 id: " << result->m_t3dtrk1ts1_id << " lr: " << result->m_t3dtrk1ts1_lr << " rt: " << result->m_t3dtrk1ts1_rt
1536  << endl;
1537  cout << " ts2 id: " << result->m_t3dtrk1ts2_id << " lr: " << result->m_t3dtrk1ts2_lr << " rt: " << result->m_t3dtrk1ts2_rt
1538  << endl;
1539  cout << " ts3 id: " << result->m_t3dtrk1ts3_id << " lr: " << result->m_t3dtrk1ts3_lr << " rt: " << result->m_t3dtrk1ts3_rt
1540  << endl;
1541  }
1542  }
1543 }
1544 
1545 
1546 // t3DFirmwareInfo[tIndex][iClk][2DValid, 2DisOld, TSFValid, EventTimeValid, eventTime, charge, rho, phi0, z0, cot, zchi]
1547 // t3DInfo[eventTime, charge, rho, phi0, z0, cot, zchi]
1548 void TRGCDCT3DConverterModule::filter3DData(multi_array<double, 3>& t3DFirmwareInfo,
1549  multi_array<double, 2>& t3DInfo)
1550 {
1551  for (unsigned iTrack = 0; iTrack < t3DFirmwareInfo.shape()[0]; iTrack++) {
1552  for (unsigned iClk = 0; iClk < t3DFirmwareInfo.shape()[1]; iClk++) {
1553  //cout<<iClk<<" 2d: "<<t3DFirmwareInfo[iTrack][iClk][0]<<" tsf: "<<t3DFirmwareInfo[iTrack][iClk][2]<<" evt: "<<t3DFirmwareInfo[iTrack][iClk][3]<<" isOld: "<<t3DFirmwareInfo[iTrack][iClk][1]<<endl;
1554  // 2DValid
1555  if (t3DFirmwareInfo[iTrack][iClk][0] == 0) continue;
1556  //cout<<iClk<<" 2d: "<<t3DFirmwareInfo[iTrack][iClk][0]<<" tsf: "<<t3DFirmwareInfo[iTrack][iClk][2]<<" evt: "<<t3DFirmwareInfo[iTrack][iClk][3]<<" isOld: "<<t3DFirmwareInfo[iTrack][iClk][1]<<endl;
1557  // TSFValid
1558 //t3DFirmwareInfo[iTrack][iClk][0] (t3d_fnf) := t2d_fnf & TSFValid, so using t3d_fnf is alreay sufficient
1559 // if (t3DFirmwareInfo[iTrack][iClk][2] == 0) continue;
1560  // EventTimeValid
1561 // if (t3DFirmwareInfo[iTrack][iClk][3] == 0) continue;
1562  // TODO make an algorithm to follow the track.
1563  // Start follow status of track.
1564  //choose new tracks
1565 // if (t3DInfo.size() != 0 && t3DFirmwareInfo[iTrack][iClk][1] == 1) continue;
1566  //if (t3DFirmwareInfo[iTrack][iClk][1] == 1) continue;
1567  double track3D_ref[7] = {t3DFirmwareInfo[iTrack][iClk][4], t3DFirmwareInfo[iTrack][iClk][5], t3DFirmwareInfo[iTrack][iClk][6], t3DFirmwareInfo[iTrack][iClk][7], t3DFirmwareInfo[iTrack][iClk][8], t3DFirmwareInfo[iTrack][iClk][9], t3DFirmwareInfo[iTrack][iClk][10]};
1568 
1569  multi_array_ref<double, 1> track3D((double*)track3D_ref, extents[7]);
1570 
1571  t3DInfo.resize(extents[t3DInfo.shape()[0] + 1][7]);
1572  t3DInfo[t3DInfo.shape()[0] - 1] = track3D;
1573 
1574  }
1575  }
1576 }
1577 
1578 // t3DInfo[eventTime, charge, rho, phi0, z0, cot, zchi]
1579 void TRGCDCT3DConverterModule::add3DDatastore(multi_array<double, 2>& t3DInfo, bool doConvert)
1580 {
1581  for (unsigned iTrack = 0; iTrack < t3DInfo.shape()[0]; ++iTrack) {
1582  double charge = 0, phi0_i = 0, omega = 0, chi2D = 0, z0 = 0, cot = 0, zchi2 = 0;
1583  double phi0_c = 0;
1584  if (doConvert) {
1585  charge = t3DInfo[iTrack][1] == 2 ? -1 : 1;
1586  phi0_c = t2DPhiTot3DPhi(t3DInfo[iTrack][3], t3DInfo[iTrack][2]) / (pow(2, 12) - 0.5) * M_PI;
1587  //phi0_i = phi0_c + charge * M_PI_2;
1588  phi0_i = (45 + 90. / 80 * (1 + t3DInfo[iTrack][3])) / 180 * M_PI;
1589  //omega = charge / t2DRhoTot3DRho(t3DInfo[iTrack][2]) / (pow(2, 11) - 0.5) * 2500;
1590  omega = toSigned(t3DInfo[iTrack][2], 7) / 33.0 * 3.2;
1591  z0 = toSigned(t3DInfo[iTrack][4], 11) * 0.0382;
1592  cot = toSigned(t3DInfo[iTrack][5], 11) * 0.00195;
1593  zchi2 = t3DInfo[iTrack][6];
1594  } else {
1595  charge = t3DInfo[iTrack][1] == 1 ? 1 : -1;
1596  phi0_c = t2DPhiTot3DPhi((t3DInfo[iTrack][3] - 34 / 90.*80 - 1), t3DInfo[iTrack][2]) / (pow(2, 12) - 0.5) * M_PI;
1597  phi0_i = t3DInfo[iTrack][3];
1598  omega = t3DInfo[iTrack][2];
1599  z0 = t3DInfo[iTrack][4];
1600  cot = t3DInfo[iTrack][5];
1601  zchi2 = t3DInfo[iTrack][6];
1602  }
1603 
1604  //Correct phi0_i. The zero points of raw phi0_i for four boards are different.
1605  if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore0") {
1606  phi0_c = phi0_c + (M_PI / 2.0) * 0;
1607  phi0_i = phi0_i + (M_PI / 2.0) * 0;
1608  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore1") {
1609  phi0_c = phi0_c + (M_PI / 2.0) * 1;
1610  phi0_i = phi0_i + (M_PI / 2.0) * 1;
1611  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore2") {
1612  phi0_c = phi0_c + (M_PI / 2.0) * 2;
1613  phi0_i = phi0_i + (M_PI / 2.0) * 2;
1614  } else if (m_firmwareResultCollectionName == "TRGCDCT3DUnpackerStore3") {
1615  phi0_c = phi0_c + (M_PI / 2.0) * 3;
1616  phi0_i = phi0_i + (M_PI / 2.0) * 3;
1617  }
1618  // Confine the range of the angle to -pi ~ pi
1619  while (phi0_c > M_PI) {
1620  phi0_c -= 2 * M_PI;
1621  }
1622  while (phi0_i < -M_PI) {
1623  phi0_c += 2 * M_PI;
1624  }
1625  while (phi0_i > M_PI) {
1626  phi0_i -= 2 * M_PI;
1627  }
1628  while (phi0_i < -M_PI) {
1629  phi0_i += 2 * M_PI;
1630  }
1631 
1632  //cout<<"iTrack: "<<iTrack<<" eventTime:"<<t3DInfo[iTrack][0]<<" charge:"<<charge<<" omega: "<<omega<<" rho: "<<charge/omega<<" pt: "<<charge/omega*0.3*1.5*0.01<<" phi0_i: "<<phi0_i<<" "<<phi0_i*180/M_PI<<" phi0_c: "<<phi0_c<<" "<<phi0_c*180/M_PI<<" z0:"<<z0<<" cot:"<<cot<<" theta: "<<M_PI/2-atan(cot)<<" zchi:"<<zchi2<<endl;
1633  if (m_isVerbose) cout << "[3D] iTrack:" << iTrack << " charge: " << charge << " phi0_i:" << phi0_i << " " << phi0_i * 180 / M_PI <<
1634  " omega:" << omega << " pt:" << charge / omega * 0.3 * 1.5 * 0.01 << " z0:" << z0 << " cot:" << cot << " zchi2:" << zchi2 << endl;
1635  m_tracks3D.appendNew(phi0_i, omega, chi2D, z0, cot, zchi2);
1636  }
1637 }
void addBinnedEventT0(int eventT0, Const::EDetector detector)
Store a binned event t0 for the given detector replacing any other hypothesis for this detector.
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
Track created by the CDC trigger.
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
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
A class to hold common data for JSignals.
Definition: JSignalData.h:33
std::string m_EventTimeName
name of the event time StoreObjPtr
StoreArray< CDCTriggerTrack > m_tracks2D
list of 2D input tracks
void addTSDatastore(boost::multi_array< double, 3 > &tsfInfo, int isSt=1)
adds tsfInfo to TS data store
bool m_add2DFinderToDatastore
Flag for adding 2D finder to datastore.
void store3DFirmSimData(boost::multi_array< double, 3 > &t3DFirmwareInfo)
uses firm sim with debug
Belle2::TRGCDCJSignalData * m_commonData
TRGCDCJSignalData for VHDL generation (jbkim's class)
int toSigned(int value, int nBits)
converts to signed value
void store3DFastSimData(boost::multi_array< double, 3 > &t3DFirmwareInfo)
uses fast sim with debug
virtual void initialize() override
Initilizes TRGCDCT3DConverterModule.
std::string m_outputCollectionName
Name of the StoreArray containing the resulting 3D tracks.
StoreArray< CDCTriggerSegmentHit > m_hits
list of track segment hits
void filterTSData(boost::multi_array< double, 4 > &tsfFirmwareInfo, boost::multi_array< double, 3 > &tsfInfo)
filters tsfFirmwareInfo to tsfInfo
virtual void endRun() override
Called when run ended.
std::map< std::string, TRGCDCJLUT * > m_mLutStorage
TRGCDCJLUT for VHDL generation (jbkim's class)
virtual void terminate() override
Called when processing ended.
void add3DDatastore(boost::multi_array< double, 2 > &t3DInfo, bool doConvert=1)
adds t3DInfo to track data store
std::map< std::string, TRGCDCJSignal > m_mSignalStorage
TRGCDCJSignal for VHDL generation (jbkim's class)
void store2DFirmwareData(boost::multi_array< double, 3 > &t2DFirmwareInfo, boost::multi_array< double, 4 > &axTsfFirmwareInfo)
converts firmwareResults of 2D to a vector
std::string m_inputCollectionName
Name of the StoreArray containing the input tracks from the 2D fitter.
unsigned m_isVerbose
Switch printing detail information.
void store3DFirmwareData(boost::multi_array< double, 3 > &t3DFirmwareInfo)
converts firmwareResults of 3D to a vector
virtual void beginRun() override
Called when new run started.
void storeTSFirmwareData(boost::multi_array< double, 4 > &tsfInfo)
converts firmwareResults of TS to a vector
bool m_addEventTimeToDatastore
Flag for adding event time to datastore.
StoreArray< CDCTriggerTrack > m_tracks3D
list of 3D output tracks
StoreObjPtr< BinnedEventT0 > m_eventTime
StoreObjPtr containing the event time.
void filter3DData(boost::multi_array< double, 3 > &t3DFirmwareInfo, boost::multi_array< double, 2 > &t3DInfo)
filters t3DFirmwareInfo to t3DInfo
std::string version() const
returns version of TRGCDCT3DConverterModule.
void filter2DData(boost::multi_array< double, 3 > &t2DFirmwareInfo, boost::multi_array< double, 4 > &t2DTsfFirmwareInfo, boost::multi_array< double, 2 > &t2DInfo, boost::multi_array< double, 3 > &t2DTsfInfo)
‍** filters t2DFirmwareInfo to t2DInfo*‍/
int toTSID(int iSL, int iWire)
converts sl, iWire to continuous TS ID [0,2335]
std::string m_hitCollectionName
Name of the StoreArray containing the input track segment hits.
std::string m_firmwareResultCollectionName
Name of the StoreArray containing the input firmware results.
void add2DDatastore(boost::multi_array< double, 2 > &t2DInfo, boost::multi_array< double, 3 > &t2DTsfInfo)
adds t2DInfo to track data store
int t2DPhiTot3DPhi(int phi, int rho)
converts to 2D rho to 3D rho value, obselete
StoreArray< TRGCDCT3DUnpackerStore > m_firmwareResults
list of firmware results
int m_t3dtrk3_cot_s
m_t3dtrk3_cot_s leaf
int m_t3dtrk3_zchisq
m_t3dtrk3_zchisq leaf
int m_t3dtrk0_evtTimeValid_delay
m_t3dtrk0_evtTimeValid_delay leaf
int m_t3dtrk0ts2_id
m_t3dtrk0ts2_id leaf
int m_t3dtrk0ts0_rt
m_t3dtrk0ts0_rt leaf
int m_t3dtrk0ts3_lr
m_t3dtrk0ts3_lr leaf
int m_t3dtrk0ts1_id
m_t3dtrk0ts1_id leaf
int m_t3dtrk2_zchisq
m_t3dtrk2_zchisq leaf
int m_t3dtrk2_cot_s
m_t3dtrk2_cot_s leaf
int m_t3dtrk0ts3_id
m_t3dtrk0ts3_id leaf
int m_t3dtrk0ts0_lr
m_t3dtrk0ts0_lr leaf
int m_t3dtrk0_zchisq
m_t3dtrk0_zchisq leaf
int m_t3dtrk1_cot_s
m_t3dtrk1_cot_s leaf
int m_t3dtrk0ts0_id
m_t3dtrk0ts0_id leaf
int m_t3dtrk0_cot_s
m_t3dtrk0_cot_s leaf
int m_t3dtrk0_evtTime_delay
m_t3dtrk0_evtTime_delay leaf
int m_t3dtrk0ts2_lr
m_t3dtrk0ts2_lr leaf
int m_t3dtrk0ts1_rt
m_t3dtrk0ts1_rt leaf
int m_t3dtrk0_phi0
m_t3dtrk0_phi0 leaf
int m_t3dtrk0ts3_rt
m_t3dtrk0ts3_rt leaf
int m_t3dtrk0_charge
m_t3dtrk0_charge leaf
int m_t3dtrk0ts1_lr
m_t3dtrk0ts1_lr leaf
int m_t3dtrk0ts2_rt
m_t3dtrk0ts2_rt leaf
int m_t3dtrk1_zchisq
m_t3dtrk1_zchisq leaf
static void fitter3DFirm(std::map< std::string, double > &mConstD, const std::map< std::string, std::vector< double > > &mConstV, int eventTimeValid, int eventTime, std::vector< std::vector< int > > const &rawStTSs, int charge, double radius, double phi_c, Belle2::TRGCDCJSignalData *commonData, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage, std::map< std::string, Belle2::TRGCDCJLUT * > &mLutStorage)
Combines several functions for fitter3D firmware.
static void fitter3D(std::map< std::string, std::vector< double > > &stGeometry, std::vector< std::vector< double > > const &stXts, int eventTimeValid, int eventTime, std::vector< std::vector< int > > const &rawStTSs, int charge, double radius, double phi_c, double &z0, double &cot, double &chi2)
Combines several functions for fitter3D.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
static void getStereoGeometry(std::map< std::string, std::vector< double > > &stGeometry)
Get stereo geometry.
Definition: Fitter3D.cc:1558
static void getStereoXt(std::vector< double > const &stPriorityLayer, std::vector< std::vector< double > > &stXts, bool isSimple=0)
Get stereo Xt.
Definition: Fitter3D.cc:1578
static void getConstants(std::map< std::string, double > &mConstD, std::map< std::string, std::vector< double > > &mConstV, bool isXtSimple=0)
Get constants for firmwareFit.
Definition: Fitter3D.cc:1596
Abstract base class for different kinds of events.