Belle II Software  release-08-00-10
TrgEclDigitizer.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 <framework/datastore/StoreArray.h>
10 #include <framework/gearbox/Unit.h>
11 
12 #include <ecl/geometry/ECLGeometryPar.h>
13 #include <ecl/dataobjects/ECLSimHit.h>
14 #include <ecl/dataobjects/ECLHit.h>
15 
16 #include "trg/ecl/TrgEclDigitizer.h"
17 
18 
19 #include "trg//ecl/dataobjects/TRGECLDigi0.h"
20 #include "trg/ecl/dataobjects/TRGECLWaveform.h" // by shebalin
21 
22 #include <iostream>
23 #include <math.h>
24 #include <TRandom.h>
25 
26 using namespace std;
27 using namespace Belle2;
28 //using namespace TRG;
29 //
30 //
31 //
32 TrgEclDigitizer::TrgEclDigitizer():
33  TimeRange(0), _waveform(0), _FADC(1), _BeambkgTag(0)
34 {
35  MatrixParallel.clear();
36  MatrixSerial.clear();
37 
38  _TCMap = new TrgEclMapping();
39  _DataBase = new TrgEclDataBase();
40 
41  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
42  TCEnergy_tot[iTCIdm] = 0;
43  TCTiming_tot[iTCIdm] = 0;
44  for (int iTime = 0; iTime < 80; iTime++) {
45  TCEnergy[iTCIdm][iTime] = 0;
46  TCTiming[iTCIdm][iTime] = 0;
47  TCBkgContribution[iTCIdm][iTime] = 0;
48  TCSigContribution[iTCIdm][iTime] = 0;
49  TCBeambkgTag[iTCIdm][iTime] = 0;
50  }
51 
52  for (int iii = 0; iii < 60 ; iii++) {
53  TCRawEnergy[iTCIdm][iii] = 0;
54  TCRawTiming[iTCIdm][iii] = 0;
55  TCRawBkgTag[iTCIdm][iii] = 0;
56  }
57  for (int iii = 0; iii < 64 ; iii++) {
58  WaveForm[iTCIdm][iii] = 0;
59  }
60  }
61 }
62 //
63 //
64 //
66 {
67  delete _TCMap;
68  delete _DataBase;
69 }
70 //
71 //
72 //
73 
74 void
76 {
77  // prepare Matrix for Noise generation
78  //
79  _DataBase-> readNoiseLMatrix(MatrixParallel, MatrixSerial);
80  //
81  // 1=ECLHit, 2=ECLSimHit, 3=ECLHit+TRGECLBGTCHit
82  int TableFlag = 3;
83  // initialize parameters
84  getTCHit(TableFlag);
85  //
86  //
87  //
88  return;
89 }
90 //
91 //
92 //
93 void
95 {
96 
97  std::vector< std::vector<float> > E_cell(8736, std::vector<float>(80, 0.0));
98  std::vector< std::vector<float> > T_ave(8736, std::vector<float>(80, 0.0));
99  std::vector< std::vector<float> > Tof_ave(8736, std::vector<float>(80, 0.0));
100  std::vector< std::vector<float> > beambkg_tag(8736, std::vector<float>(80, 0.0));
101 
102  int nBinTime = 80;
103  TimeRange = 4000; // -4us ~ 4us
104  //-------------------------------------------------------------------
105  // read Xtal data
106  //---------------------------------------------------------------------
107  if (TableFlag == 1) { // read ECLHit table
108  StoreArray<ECLHit> eclHitArray("ECLHits");
109  int nHits_hit = eclHitArray.getEntries() - 1;
110  //
111  for (int iHits = 0; iHits < nHits_hit; iHits++) {
112  // Get a hit
113  ECLHit* aECLHit = eclHitArray[iHits];
114  int beambkg = aECLHit->getBackgroundTag();
115 
116  // Hit geom. info
117  int hitCellId = aECLHit->getCellId() - 1;
118  float hitE = aECLHit->getEnergyDep() / Unit::GeV;
119  float aveT = aECLHit->getTimeAve(); // ns :time from IP to PD
120  if (aveT < - TimeRange || aveT > TimeRange) {continue;} //Choose - TimeRange ~ TimeTange
121  int TimeIndex = (int)((aveT + TimeRange) / 100); //Binning : -4000 = 1st bin ~ 4000 80th bin.
122 
123  int iTCIdm = _TCMap->getTCIdFromXtalId(hitCellId + 1) - 1;
124  TCEnergy[iTCIdm][TimeIndex] += hitE;
125  TCTiming[iTCIdm][TimeIndex] += hitE * aveT;
126  if (beambkg > 0) {TCBkgContribution[iTCIdm][TimeIndex] += hitE ;}
127  else if (beambkg == 0) {TCSigContribution[iTCIdm][TimeIndex] += hitE;}
128 
129  }
130  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
131  for (int iTime = 0; iTime < nBinTime; iTime++) {
132  if (TCEnergy[iTCIdm][iTime] < 1e-9) {continue;}// 0.01MeV cut
133  /* cppcheck-suppress variableScope */
134  double maxbkgE = 0;
135  /* cppcheck-suppress variableScope */
136  int maxbkgtag = 0;
137  TCTiming[iTCIdm][iTime] /= TCEnergy[iTCIdm][iTime];
138  if (_BeambkgTag == 1) {
139  if (TCBkgContribution[iTCIdm][iTime] < TCSigContribution[iTCIdm][iTime]) {
140  TCBeambkgTag[iTCIdm][iTime] = 0; //signal Tag : 0
141  } else {
142  for (int iXtalIdm = 0; iXtalIdm < 8736; iXtalIdm++) {
143  int iTCId = _TCMap->getTCIdFromXtalId(iXtalIdm + 1) - 1;
144  if (iTCIdm != iTCId) {continue;}
145  if (maxbkgE < E_cell[iXtalIdm][iTime]) {
146  maxbkgE = E_cell[iXtalIdm][iTime];
147  maxbkgtag = beambkg_tag[iXtalIdm][iTime];
148  }
149  }
150  TCBeambkgTag[iTCIdm][iTime] = maxbkgtag;
151  }
152  }
153  }
154  }
155  }
156 
157 
158  if (TableFlag == 2) { // read ECLSimHit
160  //=====================
161  // Loop over all hits of steps
162  //=====================
163  StoreArray<ECLSimHit> eclArray("ECLSimHits");
164  int nHits = eclArray.getEntries();
165  //
166  for (int iHits = 0; iHits < nHits; iHits++) {
167  // Get a hit
168  ECLSimHit* aECLSimHit = eclArray[iHits];
169 
170  int hitCellId = aECLSimHit->getCellId() - 1;
171  float hitE = aECLSimHit->getEnergyDep() / Unit::GeV;
172  float hitTOF = aECLSimHit->getFlightTime() / Unit::ns;
173 
174  G4ThreeVector t = aECLSimHit->getPosIn(); // [cm], Hit position in Xtal (based on from IP)
175  ROOT::Math::XYZVector HitInPos(t.x(), t.y(), t.z()); // = aECLSimHit->getPosIn(); // [cm], Hit position in Xtal (based on from IP)
176  ROOT::Math::XYZVector PosCell = eclp->GetCrystalPos(hitCellId);// [cm], Xtal position (based on from IP)
177  ROOT::Math::XYZVector VecCell = eclp->GetCrystalVec(hitCellId);
178  float local_pos_r = 15.0 - (HitInPos - PosCell).Dot(VecCell);
179  if (hitTOF < - TimeRange || hitTOF > TimeRange) {continue;}
180  int TimeIndex = (int)((hitTOF + TimeRange) / 100);
181  E_cell[hitCellId][TimeIndex] = E_cell[hitCellId][TimeIndex] + hitE;
182  T_ave[hitCellId][TimeIndex] = T_ave[hitCellId][TimeIndex] + hitE * local_pos_r;
183  Tof_ave[hitCellId][TimeIndex] = Tof_ave[hitCellId][TimeIndex] + hitE * hitTOF;
184  }
185  //
186  //
187  //
188  //===============
189  // Xtal energy and timing (0-8us, 0.2us interval, 40 bins)
190  //===============
191  for (int iECLCell = 0; iECLCell < 8736; iECLCell++) {
192  for (int TimeIndex = 0; TimeIndex < nBinTime; TimeIndex++) {
193 
194  if (E_cell[iECLCell][TimeIndex] < 1e-9) {continue;} // 0.01MeV cut
195 
196  T_ave[iECLCell][TimeIndex] = T_ave[iECLCell][TimeIndex] / E_cell[iECLCell][TimeIndex];
197  T_ave[iECLCell][TimeIndex] =
198  6.05 +
199  0.0749 * T_ave[iECLCell][TimeIndex] -
200  0.00112 * T_ave[iECLCell][TimeIndex] * T_ave[iECLCell][TimeIndex];
201  Tof_ave[iECLCell][TimeIndex] = Tof_ave[iECLCell][TimeIndex] / E_cell[iECLCell][TimeIndex];
202 
203  } // 40bins, Time interval = 200ns
204  }
205  //
206  //
207  //
208  for (int iXtalIdm = 0; iXtalIdm < 8736; iXtalIdm++) {
209  int iTCIdm = _TCMap->getTCIdFromXtalId(iXtalIdm + 1) - 1;
210  for (int iTime = 0; iTime < nBinTime; iTime++) {
211  if (E_cell[iXtalIdm][iTime] < 1e-9) {continue;} // 0.01MeV cut
212  TCEnergy[iTCIdm][iTime] += E_cell[iXtalIdm][iTime];
213  TCTiming[iTCIdm][iTime] += E_cell[iXtalIdm][iTime] * (T_ave[iXtalIdm][iTime]);
214  if (beambkg_tag[iXtalIdm][iTime] > 0) {TCBkgContribution[iTCIdm][iTime] += E_cell[iXtalIdm][iTime];}
215  if (beambkg_tag[iXtalIdm][iTime] == 0) {TCSigContribution[iTCIdm][iTime] += E_cell[iXtalIdm][iTime];}
216 
217  }
218  }
219  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
220  for (int iTime = 0; iTime < nBinTime; iTime++) {
221  /* cppcheck-suppress variableScope */
222  double maxbkgE = 0;
223  /* cppcheck-suppress variableScope */
224  int maxbkgtag = 0;
225  if (TCEnergy[iTCIdm][iTime] < 1e-9) {continue;} // 0.01MeV cut
226  TCTiming[iTCIdm][iTime] /= TCEnergy[iTCIdm][iTime];
227  if (_BeambkgTag == 1) {
228  if (TCBkgContribution[iTCIdm][iTime] < TCSigContribution[iTCIdm][iTime]) {
229  TCBeambkgTag[iTCIdm][iTime] = 0; //signal Tag : 0
230  } else {
231  for (int iXtalIdm = 0; iXtalIdm < 8736; iXtalIdm++) {
232  int iTCId = _TCMap->getTCIdFromXtalId(iXtalIdm + 1) - 1;
233  if (iTCIdm != iTCId) {continue;}
234  if (maxbkgE < E_cell[iXtalIdm][iTime]) {
235  maxbkgE = E_cell[iXtalIdm][iTime];
236  maxbkgtag = beambkg_tag[iXtalIdm][iTime];
237  }
238  }
239  TCBeambkgTag[iTCIdm][iTime] = maxbkgtag;
240  }
241  }
242  }
243 
244  }
245 
246  }
247  //--------------------------------------------------------
248  //
249  //--------------------------------------------------------
250  if (TableFlag == 3) {
251  StoreArray<ECLHit> eclHitArray("ECLHits");
252  int nHits_hit = eclHitArray.getEntries() - 1;
253  // signal hit
254  for (int iHits = 0; iHits < nHits_hit; iHits++) {
255  // Get a hit
256  ECLHit* aECLHit = eclHitArray[iHits];
257  // Hit geom. info
258  int hitCellId = aECLHit->getCellId() - 1;
259  float hitE = aECLHit->getEnergyDep() / Unit::GeV;
260  float aveT = aECLHit->getTimeAve(); // ns :time from IP to PD
261  // Choose - TimeRange ~ TimeTange
262  if (aveT < - TimeRange || aveT > TimeRange) {continue;}
263  // Binning : -4000 = 1st bin ~ 4000 80th bin.
264  int TimeIndex = (int)((aveT + TimeRange) / 100);
265 
266  int iTCIdm = _TCMap->getTCIdFromXtalId(hitCellId + 1) - 1;
267  TCEnergy[iTCIdm][TimeIndex] += hitE;
268  TCTiming[iTCIdm][TimeIndex] += hitE * aveT;
269  }
270  // background hit
271  StoreArray<TRGECLBGTCHit> m_trgeclBGTCHits("TRGECLBGTCHits_beamBG");
272  for (const TRGECLBGTCHit& ttt : m_trgeclBGTCHits) {
273  // TC timing
274  double tcbg_t = ttt.getTimeAve();
275  // Timing cut
276  if (abs(tcbg_t) > TimeRange) continue;
277  //Binning : -4000 = 1st bin ~ 4000 80th bin.
278  int TimeIndex = (int)((tcbg_t + TimeRange) / 100);
279  // TC energy
280  double tcbg_e = ttt.getEnergyDep();
281  // TC ID index
282  int iTCIdm = ttt.getTCId() - 1;
283  // TC energy and timing
284  double tc_e = TCEnergy[iTCIdm][TimeIndex];
285  double tc_t = TCTiming[iTCIdm][TimeIndex];
286  TCEnergy[iTCIdm][TimeIndex] += tcbg_e;
287  TCTiming[iTCIdm][TimeIndex] += (tcbg_e * tcbg_t + tc_e * tc_t) / TCEnergy[iTCIdm][TimeIndex];
288  }
289  }
290  //--------------------------
291  // TC energy and timing in t=0-1us as true values.
292  //--------------------------
293  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
294  for (int iTime = 40; iTime < 50; iTime++) {
295  TCEnergy_tot[iTCIdm] += TCEnergy[iTCIdm][iTime];
296  TCTiming_tot[iTCIdm] += TCTiming[iTCIdm][iTime] * TCEnergy[iTCIdm][iTime];
297  }
298  TCTiming_tot[iTCIdm] /= TCEnergy_tot[iTCIdm];
299  }
300  return;
301 }
302 //
303 //
304 //
305 void
306 TrgEclDigitizer::digitization01(std::vector<std::vector<double>>& TCDigiE,
307  std::vector<std::vector<double>>& TCDigiT)
308 {
309  TCDigiE.clear();
310  TCDigiE.resize(576, vector<double>(64, 0));
311  TCDigiT.clear();
312  TCDigiT.resize(576, vector<double>(64, 0));
313 
314  //
315  double cut_energy_tot = 0.03; // [GeV]
316  int nbin_pedestal = 4; // = nbin_pedestal*fam_sampling_interval [ns] in total
317  double fam_sampling_interval = 125; // [ns]
318  int NSampling = 64; // # of sampling array
319 
320 
321  std::vector< std::vector<float> > noise_pileup(576, std::vector<float>(64, 0.0)); // [GeV]
322  std::vector< std::vector<float> > noise_parallel(576, std::vector<float>(64, 0.0)); // [GeV]
323  std::vector< std::vector<float> > noise_serial(576, std::vector<float>(64, 0.0)); // [GeV]
324  std::vector<float> X_pr(64, 0.0);
325  std::vector<float> X_sr(64, 0.0);
326 
327 
328  // (Make sampling time random between FAM sampling intervals)
329  double random_sampling_correction = 0; // [ns]
330  random_sampling_correction = gRandom->Rndm() * fam_sampling_interval;
331  //==================
332  // (01)Signal digitization
333  //==================
334  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
335  if (TCEnergy_tot[iTCIdm] < cut_energy_tot) {continue;} // TC energy_tot cut
336  for (int iTimeBin = 0; iTimeBin < 80; iTimeBin++) {
337  if (TCEnergy[iTCIdm][iTimeBin] < 0.0001) {continue;} // 0.1MeV cut on TC bin_energy
338  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
339  // inputTiming is in [us] <-- Be careful, here is NOT [ns]
340  double inputTiming
341  = (-TCTiming[iTCIdm][iTimeBin] - TimeRange + (-nbin_pedestal + iSampling) * fam_sampling_interval) * 0.001;
342  inputTiming += random_sampling_correction * 0.001;
343  if (inputTiming < 0 || inputTiming > 2.0) {continue;} // Shaping in t0 ~t0+ 2.0 us
344  if (_FADC == 1) {
345 
346  TCDigiE[iTCIdm][iSampling] += interFADC(inputTiming) * TCEnergy[iTCIdm][iTimeBin];
347  } else {
348  TCDigiE[iTCIdm][iSampling] += SimplifiedFADC(0, inputTiming) * TCEnergy[iTCIdm][iTimeBin];
349  }
350  }
351 
352  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
353  TCDigiT[iTCIdm][iSampling] = (-nbin_pedestal + iSampling - TimeRange / fam_sampling_interval) * fam_sampling_interval;
354  TCDigiT[iTCIdm][iSampling] += random_sampling_correction;
355  }
356  }
357  }
358  //
359  //
360  //
361  if (0) {
362  FILE* f_out_dat = fopen("ztsim.no_noise.dat", "w");
363  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
364  if (TCEnergy_tot[iTCIdm] < cut_energy_tot) { continue; } // TC energy_tot cut
365  fprintf(f_out_dat, "%5i %8.5f %8.5f %8.1f ",
366  iTCIdm + 1, TCEnergy_tot[iTCIdm], TCEnergy[iTCIdm][0], TCDigiT[iTCIdm][0]);
367  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
368  fprintf(f_out_dat, "%7.4f ", TCDigiE[iTCIdm][iSampling]);
369  }
370  fprintf(f_out_dat, "\n");
371  }
372  fclose(f_out_dat);
373  }
374  //==================
375  // (01)noise embedding
376  //==================
377  double tmin_noise = -4; // orignal
378  double tgen = 10.3; // orignal
379  int bkg_level = 1030;
380  double ttt0 = 0; // [us]
381  /* cppcheck-suppress variableScope */
382  double ttt1 = 0; // [us]
383  /* cppcheck-suppress variableScope */
384  double ttt2 = 0; // [us]
385  //
386  double frac_pileup = 0.035; // pileup noise fraction?
387  double frac_parallel = 0.023; // parralel noise fraction?
388  double frac_serial = 0.055; // serial noise fraction?
389  double times_pileup = 1; // noise scale based on Belle noise.
390  double times_parallel = 3.15; // noise scale
391  double times_serial = 3.15; // noise scale
392 
393  double corr_pileup = times_pileup * frac_pileup * sqrt(fam_sampling_interval * 0.001);
394  double corr_parallel = times_parallel * frac_parallel * sqrt(fam_sampling_interval * 0.001);
395  double corr_serial = times_serial * frac_serial * sqrt(fam_sampling_interval * 0.001);
396 
397 
398  if (0) {
399  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
400  if (TCEnergy_tot[iTCIdm] < cut_energy_tot) { continue; } // TC energy_tot cut
401  for (int jjj = 0; jjj < bkg_level; jjj++) {
402  ttt0 = -(tmin_noise + tgen * gRandom->Rndm()); // [us]
403  ttt1 = -(tmin_noise + tgen * gRandom->Rndm()); // [us]
404  ttt2 = -(tmin_noise + tgen * gRandom->Rndm()); // [us]
405  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
406  // (pile-up noise)
407  if (ttt0 > 0) { TCDigiE[iTCIdm][iSampling] += SimplifiedFADC(0, ttt0) * corr_pileup * 0.001; }
408  // (parallel noise)
409  if (ttt1 > 0) { TCDigiE[iTCIdm][iSampling] += SimplifiedFADC(1, ttt1) * corr_parallel; }
410  // (serial noise)
411  if (ttt2 > 0) { TCDigiE[iTCIdm][iSampling] += SimplifiedFADC(2, ttt2) * corr_serial; }
412  ttt0 += fam_sampling_interval * 0.001;
413  ttt1 += fam_sampling_interval * 0.001;
414  ttt2 += fam_sampling_interval * 0.001;
415  }
416  }
417  }
418  }
419  if (1) { //use L Matrix
420  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
421 
422  if (TCEnergy_tot[iTCIdm] < cut_energy_tot) { continue; } // TC energy_tot cut
423 
424  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
425  X_pr[iSampling] = gRandom ->Gaus(0, 1);
426  X_sr[iSampling] = gRandom ->Gaus(0, 1);
427  }
428 
429  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
430  for (int jSampling = 0; jSampling < NSampling; jSampling++) {
431  noise_parallel[iTCIdm][iSampling] += 10 * corr_parallel * MatrixParallel[iSampling][jSampling] * X_pr[jSampling];
432  noise_serial[iTCIdm][iSampling] += 10 * corr_serial * MatrixSerial[iSampling][jSampling] * X_sr[jSampling];
433  }
434  }
435 
436  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
437 
438  TCDigiE[iTCIdm][iSampling] += noise_pileup[iTCIdm][iSampling] + noise_parallel[iTCIdm][iSampling] +
439  noise_serial[iTCIdm][iSampling];
440  }
441  }
442  if (0) {
443  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) { //Only Pile-up noise use old method.
444  if (TCEnergy_tot[iTCIdm] < cut_energy_tot) { continue; } // TC energy_tot cut
445  for (int jjj = 0; jjj < bkg_level; jjj++) {
446  ttt0 = -(tmin_noise + tgen * gRandom->Rndm()); // [us]
447  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
448  // (pile-up noise)
449  if (ttt0 > 0) { TCDigiE[iTCIdm][iSampling] += SimplifiedFADC(0, ttt0) * corr_pileup * 0.001; }
450  ttt0 += fam_sampling_interval * 0.001;
451  }
452  }
453  }
454  }
455  }
456 
457  if (_waveform == 1) {
458 
459  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
460  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
461  WaveForm[iTCIdm][iSampling] = TCDigiE[iTCIdm][iSampling];
462  }
463 
464  }
465  }
466 
467 }
468 void
469 TrgEclDigitizer::digitization02(std::vector<std::vector<double>>& TCDigiE, std::vector<std::vector<double>>& TCDigiT)
470 {
471  //===============
472  // (03)Signal digitization (w/ 12ns interval for method-0)
473  //===============
474  TCDigiE.clear();
475  TCDigiE.resize(576, vector<double>(666, 0));
476  TCDigiT.clear();
477  TCDigiT.resize(576, vector<double>(666, 0));
478  double cut_energy_tot = 0.03; // [GeV]
479  int nbin_pedestal = 100;
480  float fam_sampling_interval = 12; // [ns]
481 
482  std::vector< std::vector<float> > TCDigiEnergy(576, std::vector<float>(666, 0.0)); // [GeV]
483  std::vector< std::vector<float> > TCDigiTiming(576, std::vector<float>(666, 0.0)); // [ns]
484  int NSampling = 666;
485 
486  // Make sampling time random between FAM sampling intervals
487  float random_sampling_correction = 0; // [ns]
488  random_sampling_correction = gRandom->Rndm() * fam_sampling_interval;
489  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
490  if (TCEnergy_tot[iTCIdm] < cut_energy_tot) {continue;} // TC energy_tot cut
491  for (int iTimeBin = 0; iTimeBin < 80; iTimeBin++) {
492  if (TCEnergy[iTCIdm][iTimeBin] < 0.0001) { continue; } // 0.1 MeV cut on TC bin_energy
493  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
494  // inputTiming is in [us] <-- Be careful, here is NOT [ns]
495  float inputTiming
496  = (-TCTiming[iTCIdm][iTimeBin] - TimeRange + (-nbin_pedestal + iSampling) * fam_sampling_interval) * 0.001;
497 
498  inputTiming += random_sampling_correction * 0.001;
499  if (inputTiming < 0 || inputTiming > 2.0) {continue;} // Shaping in t0 ~t0+ 2.0 us
500 
501  TCDigiEnergy[iTCIdm][iSampling] += FADC(0, inputTiming) * TCEnergy[iTCIdm][iTimeBin];
502  }
503  }
504  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
505  TCDigiTiming[iTCIdm][iSampling] = (-nbin_pedestal + iSampling - TimeRange / fam_sampling_interval) * fam_sampling_interval;
506  TCDigiTiming[iTCIdm][iSampling] += random_sampling_correction;
507  }
508  }
509  //==================
510  // (03)noise embedding
511  //==================
512 
513  double tmin_noise = -4; // orignal
514  double tgen = 10.3; //
515  int bkg_level = 1030;
516  double ttt0 = 0; // [us]
517  double ttt1 = 0; // [us]
518  double ttt2 = 0; // [us]
519  //double frac_pileup = 0.035; // pileup noise fraction?
520  //double frac_parallel = 0.023; // parralel noise fraction?
521  //double frac_serial = 0.055; // serial noise fraction?
522  //double times_pileup = 1; // noise scale based on Belle noise.
523  //double times_parallel = 1; // noise scale
524  //double times_serial = 1; // noise scale
525  //double corr_pileup = times_pileup * frac_pileup * sqrt(fam_sampling_interval * 0.001);
526  //double corr_parallel = times_parallel * frac_parallel * sqrt(fam_sampling_interval * 0.001);
527  //double corr_serial = times_serial * frac_serial * sqrt(fam_sampling_interval * 0.001);
528  double corr_pileup = 0.011068;
529  double corr_parallel = 0.00727324;
530  double corr_serial = 0.0173925;
531 
532 
533  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
534  if (TCEnergy_tot[iTCIdm] < cut_energy_tot) { continue; } // 1 MeV TC energy cut
535  for (int jjj = 0; jjj < bkg_level; jjj++) {
536  ttt0 = -(tmin_noise + tgen * gRandom->Rndm()); // [us]
537  ttt1 = -(tmin_noise + tgen * gRandom->Rndm()); // [us]
538  ttt2 = -(tmin_noise + tgen * gRandom->Rndm()); // [us]
539  for (int iSampling = 0; iSampling < NSampling; iSampling++) {
540  // (pile-up noise)
541  if (ttt0 > 0) { TCDigiEnergy[iTCIdm][iSampling] += FADC(0, ttt0) * corr_pileup * 0.001; }
542  // (parallel noise)
543  if (ttt1 > 0) { TCDigiEnergy[iTCIdm][iSampling] += FADC(1, ttt1) * corr_parallel; }
544  // (serial noise)
545  if (ttt2 > 0) { TCDigiEnergy[iTCIdm][iSampling] += FADC(2, ttt2) * corr_serial; }
546  ttt0 += fam_sampling_interval * 0.001;
547  ttt1 += fam_sampling_interval * 0.001;
548  ttt2 += fam_sampling_interval * 0.001;
549  }
550  }
551  }
552 
553 }
554 //
555 //
556 //
557 void
559 {
560  //---------------
561  // Root Output
562  //---------------
563  int m_hitNum = 0;
564  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
565  for (int iBinTime = 0; iBinTime < 80; iBinTime++) {
566  if (TCEnergy[iTCIdm][iBinTime] < 0.001) {continue;}
567  StoreArray<TRGECLDigi0> TCDigiArray;
568  TCDigiArray.appendNew();
569  m_hitNum = TCDigiArray.getEntries() - 1;
570 
571  TCDigiArray[m_hitNum]->setEventId(m_nEvent);
572  TCDigiArray[m_hitNum]->setTCId(iTCIdm + 1);
573  TCDigiArray[m_hitNum]->setiBinTime(iBinTime);
574  TCDigiArray[m_hitNum]->setRawEnergy(TCEnergy[iTCIdm][iBinTime]);
575  TCDigiArray[m_hitNum]->setRawTiming(TCTiming[iTCIdm][iBinTime]);
576  TCDigiArray[m_hitNum]->setBeamBkgTag(TCBeambkgTag[iTCIdm][iBinTime]);
577  }
578  }
579 
580  if (_waveform == 1) {
581  StoreArray<TRGECLWaveform> TCWaveformArray;
582  for (int iTCIdm = 0; iTCIdm < 576; iTCIdm++) {
583  if (iTCIdm == 80) iTCIdm = 512; // skip barrel
584  int tc_phi_id = _TCMap->getTCPhiIdFromTCId(iTCIdm + 1);
585  int tc_theta_id = _TCMap->getTCThetaIdFromTCId(iTCIdm + 1);
586  TRGECLWaveform* newWf =
587  TCWaveformArray.appendNew(iTCIdm + 1, WaveForm[iTCIdm]);
588  newWf->setThetaPhiIDs(tc_theta_id, tc_phi_id);
589  }
590 
591  }
592 
593 
594  return;
595 }
596 //
597 //
598 //
599 double
601 {
602 
603  std::vector<double> SignalAmp;
604  std::vector<double> SignalTime;
605 
606  SignalAmp.clear();
607  SignalTime.clear();
608 
609  timing = timing * 1000;
610  int startbin = (int)(timing) / 12;
611  int endbin = startbin + 1;
612 
613  SignalAmp = { 0, 3.47505e-06, 0.000133173, 0.000939532, 0.00337321, 0.00845977, 0.0170396, 0.0296601, 0.0465713, 0.0677693, 0.0930545, 0.122086, 0.154429, 0.189595, 0.227068, 0.266331, 0.306882, 0.348243, 0.389971, 0.431664, 0.472959, 0.513539, 0.553127, 0.59149, 0.628431, 0.663791, 0.697445, 0.729297, 0.759281, 0.787354, 0.813494, 0.837698, 0.859982, 0.880372, 0.898908, 0.915639, 0.930622, 0.943919, 0.955598, 0.965731, 0.97439, 0.98165, 0.987587, 0.992275, 0.995788, 0.9982, 0.999581, 1, 0.999525, 0.998219, 0.996143, 0.993356, 0.989846, 0.985364, 0.979439, 0.971558, 0.961304, 0.948421, 0.932809, 0.914509, 0.893664, 0.870494, 0.845267, 0.818279, 0.789837, 0.76025, 0.729815, 0.698815, 0.667511, 0.636141, 0.604919, 0.574035, 0.543654, 0.513915, 0.484939, 0.456822, 0.429643, 0.403462, 0.378324, 0.354259, 0.331286, 0.309412, 0.288633, 0.26894, 0.250316, 0.232736, 0.216174, 0.200597, 0.185972, 0.172262, 0.159428, 0.147431, 0.136232, 0.12579, 0.116067, 0.107022, 0.0986191, 0.0908193, 0.0835871, 0.0768874, 0.0706867, 0.0649528, 0.0596551, 0.0547641, 0.0502523, 0.0460932, 0.042262, 0.0387353, 0.0354909, 0.0325082, 0.0297677, 0.0272511, 0.0249416, 0.0228232, 0.020881, 0.0191014, 0.0174714, 0.0159792, 0.0146138, 0.0133649, 0.012223, 0.0111793, 0.0102258, 0.00935504, 0.00856, 0.00783438, 0.00717232, 0.00656842, 0.00601773, 0.00551567, 0.00505807, 0.00464106, 0.00426114, 0.00391506, 0.00359985, 0.0033128, 0.00305143, 0.00281346, 0.00259681, 0.00239957, 0.00222002, 0.00205655, 0.00190773, 0.00177223, 0.00164885, 0.00153648, 0.00143413, 0.00134087, 0.00125589, 0.00117842, 0.00110777, 0.00104332, 0.000984488, 0.000930766, 0.000881678, 0.000836798, 0.000795734, 0.000758134, 0.000723677, 0.00069207, 0.000663051, 0.000636377, 0.000611832, 0.000589219, 0.000568358, 0.000549086, 0.000531258, 0.000514738, 0.000499407, 0.000485156, 0.000471884, 0.000459502, 0.00044793, 0.000437092, 0.000426923, 0.000417363, 0.000408356, 0.000399853, 0.000391811, 0.000384187, 0.000376946, 0.000370055, 0.000363483, 0.000357203, 0.000351192, 0.000345426, 0.000339886, 0.000334554, 0.000329413, 0.000324448, 0.000319645, 0.000314993, 0.000310481, 0.000306098, 0.000301836, 0.000297686, 0.00029364, 0.000289693, 0.000285837, 0.000282068, 0.00027838, 0.000274768, 0.000271229, 0.000267759, 0.000264354, 0.000261011, 0.000257727, 0.000254499, 0.000251326, 0.000248204, 0.000245132, 0.000242108, 0.000239131, 0.000236198, 0.000233308, 0.00023046, 0.000227653, 0.000224885, 0.000222155, 0.000219463, 0.000216807, 0.000214187, 0.000211602, 0.00020905, 0.000206532, 0.000204046, 0.000201593, 0.00019917, 0.000196779, 0.000194417, 0.000192085, 0.000189782, 0.000187508, 0.000185262, 0.000183044, 0.000180853, 0.000178689, 0.000176552, 0.000174441, 0.000172355, 0.000170295, 0.00016826, 0.000166249, 0.000164263, 0.000162301, };
614 
615  SignalTime = { 0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 168, 180, 192, 204, 216, 228, 240, 252, 264, 276, 288, 300, 312, 324, 336, 348, 360, 372, 384, 396, 408, 420, 432, 444, 456, 468, 480, 492, 504, 516, 528, 540, 552, 564, 576, 588, 600, 612, 624, 636, 648, 660, 672, 684, 696, 708, 720, 732, 744, 756, 768, 780, 792, 804, 816, 828, 840, 852, 864, 876, 888, 900, 912, 924, 936, 948, 960, 972, 984, 996, 1008, 1020, 1032, 1044, 1056, 1068, 1080, 1092, 1104, 1116, 1128, 1140, 1152, 1164, 1176, 1188, 1200, 1212, 1224, 1236, 1248, 1260, 1272, 1284, 1296, 1308, 1320, 1332, 1344, 1356, 1368, 1380, 1392, 1404, 1416, 1428, 1440, 1452, 1464, 1476, 1488, 1500, 1512, 1524, 1536, 1548, 1560, 1572, 1584, 1596, 1608, 1620, 1632, 1644, 1656, 1668, 1680, 1692, 1704, 1716, 1728, 1740, 1752, 1764, 1776, 1788, 1800, 1812, 1824, 1836, 1848, 1860, 1872, 1884, 1896, 1908, 1920, 1932, 1944, 1956, 1968, 1980, 1992, 2004, 2016, 2028, 2040, 2052, 2064, 2076, 2088, 2100, 2112, 2124, 2136, 2148, 2160, 2172, 2184, 2196, 2208, 2220, 2232, 2244, 2256, 2268, 2280, 2292, 2304, 2316, 2328, 2340, 2352, 2364, 2376, 2388, 2400, 2412, 2424, 2436, 2448, 2460, 2472, 2484, 2496, 2508, 2520, 2532, 2544, 2556, 2568, 2580, 2592, 2604, 2616, 2628, 2640, 2652, 2664, 2676, 2688, 2700, 2712, 2724, 2736, 2748, 2760, 2772, 2784, 2796, 2808, 2820, 2832, 2844, 2856, 2868, 2880, 2892, 2904, 2916, 2928, };
616 
617 
618  double E_out = 0;
619  if (timing < 0 || timing > 2928) {return E_out;}
620 
621  if (timing > SignalTime[startbin] && timing < SignalTime[endbin]) {
622  E_out = (((SignalAmp[endbin] - SignalAmp[startbin])) / (SignalTime[endbin] - SignalTime[startbin])) *
623  (timing - SignalTime[startbin]) + SignalAmp[startbin];
624  return E_out;
625  } else {
626  E_out = 0;
627  }
628 
629 
630  return E_out;
631 
632 }
633 //
634 //
635 //
636 double
638  double timing)
639 {
640 
641  //--------------------------------------
642  //
643  // o "timing" unit is [us]
644  // o flag_gen = 0(=signal), 1(=parallel), 2(=serial)
645  // o return value(PDF) is [GeV]
646  //
647  //--------------------------------------
648  double tsh, dd;
649  static double tc, tc2, tsc, tris, b1, b2;
650  static double amp, dft, as;
651  static double td, t1, t2;
652 
653  static int ifir = 0;
654 
655  if (ifir == 0) {
656 
657  td = 0.10; // diff time ( 0.10)
658  t1 = 0.10; // integ1 real ( 0.10)
659  b1 = 30.90; // integ1 imag ( 30.90)
660  t2 = 0.01; // integ2 real ( 0.01)
661  b2 = 30.01; // integ2 imag ( 30.01)
662  double ts = 1.00; // scint decay ( 1.00)
663  dft = 0.600; // diff delay ( 0.600)
664  as = 0.548; // diff frac ( 0.548)
665  //
666  amp = 1.0;
667  tris = 0.01;
668  tsc = ts;
669  //
670  int im = 0;
671  int ij = 0;
672  int fm = 0;
673  tc = 0;
674  double tt = u_max(u_max(td, t1), u_max(t2, ts)) * 2;
675  int flag_once = 0;
676  while (flag_once == 0) {
677  double dt = tt / 1000;
678  double tm = 0;
679  for (int j = 1; j <= 1000; j++) {
680  tc2 = tc - dft;
681  double fff =
682  (ShapeF(tc, t1, b1, t2, b2, td, tsc) -
683  ShapeF(tc, t1, b1, t2, b2, td, tris) * 0.01) -
684  (ShapeF(tc2, t1, b1, t2, b2, td, tsc) -
685  ShapeF(tc2, t1, b1, t2, b2, td, tris) * 0.01) * as;
686  if (fff > fm) {
687  fm = fff;
688  tm = tc;
689  im = j;
690  }
691  tc = tc + dt;
692  }
693  if (im >= 1000) {
694  tt = 2 * tt;
695  flag_once = 0;
696  continue;
697  }
698  if (ij == 0) {
699  ij = 1;
700  tc = 0.99 * tm;
701  dt = tm * 0.02 / 1000;
702  flag_once = 0;
703  continue;
704  }
705  flag_once = 1;
706  }
707  amp = 1.0 / fm;
708  ifir = 1;
709  }
710  //
711  //
712  double pdf = 0;
713  if (flag_gen == 0) {
714  //-----<signal>
715  tc2 = timing - dft;
716  pdf = amp * (
717  (ShapeF(timing, t1, b1, t2, b2, td, tsc) -
718  ShapeF(timing, t1, b1, t2, b2, td, tris) * 0.01) -
719  (ShapeF(tc2, t1, b1, t2, b2, td, tsc) -
720  ShapeF(tc2, t1, b1, t2, b2, td, tris) * 0.01) * as);
721  } else if (flag_gen == 1) {
722  //-----<parallel>
723  tc2 = timing - dft;
724  tsh = 0.001;
725  pdf = amp * (
726  ShapeF(timing, t1, b1, t2, b2, td, tsh) -
727  ShapeF(tc2, t1, b1, t2, b2, td, tsh) * as);
728  pdf = pdf * 0.001; // GeV
729  } else {
730  //-----<serial>
731  tc2 = timing - dft;
732  tsh = 0.001;
733  pdf = amp * (
734  ShapeF(timing, t1, b1, t2, b2, td, tsh) -
735  ShapeF(tc2, t1, b1, t2, b2, td, tsh) * as);
736  //
737  tc = timing - 0.01;
738  if (tc < 0) { tc = 0; }
739  dd = timing - tc;
740  tc2 = tc - dft;
741  pdf = (amp * (
742  ShapeF(tc, t1, b1, t2, b2, td, tsh) -
743  ShapeF(tc2, t1, b1, t2, b2, td, tsh) * as) - pdf) / dd;
744  pdf = pdf * 0.001; // GeV
745  }
746 
747  return pdf;
748 }
749 //
750 //
751 //
752 double
754  double t01,
755  double tb1,
756  double t02,
757  double tb2,
758  double td1,
759  double ts1)
760 {
761  double dr;
762  double dzna;
763  double das1, das0, dac0;
764  double dcs0s, dsn0s, dcs0d, dsn0d;
765  double dcs1s, dsn1s, dcs1d, dsn1d;
766 
767  double sv123 = 0.0;
768  if (t00 < 0) return 0;
769 
770  dr = (ts1 - td1) / td1;
771  if (fabs(dr) <= 1.0e-5) {
772  if (ts1 > td1) { ts1 = td1 * 1.00001; }
773  else { ts1 = td1 * 0.99999; }
774  }
775  //
776  dr = (pow((t01 - t02), 2) + pow((tb1 - tb2), 2)) / (pow((t01), 2) + pow((tb1), 2));
777  if (dr <= 1.e-10) {
778  if (t01 < t02) { t01 = t02 / 1.00001; }
779  else { t01 = t02 / 0.99999; }
780  }
781  if (t00 <= 0.0) return 0;
782  //
783  //
784  //
785  double a1 = 1 / t01;
786  double a2 = 1 / tb1;
787  double b1 = 1 / t02;
788  double b2 = 1 / tb2;
789  double c1 = 1 / td1;
790  double c2 = 1 / ts1;
791 
792  das0 = b2 * (pow((b1 - a1), 2) + (b2 + a2) * (b2 - a2));
793  dac0 = -2 * (b1 - a1) * a2 * b2;
794  das1 = a2 * (pow((b1 - a1), 2) - (b2 + a2) * (b2 - a2));
795 
796  dsn0s = ((c2 - a1) * das0 - (-a2) * dac0) / (pow(a2, 2) + pow((c2 - a1), 2));
797  dcs0s = ((-a2) * das0 + (c2 - a1) * dac0) / (pow(a2, 2) + pow((c2 - a1), 2));
798 
799  dsn1s = ((c2 - b1) * das1 - (-b2) * (-dac0)) / (pow(b2, 2) + pow((c2 - b1), 2));
800  dcs1s = ((-b2) * das1 + (c2 - b1) * (-dac0)) / (pow(b2, 2) + pow((c2 - b1), 2));
801 
802  dsn0d = ((c1 - a1) * das0 - (-a2) * dac0) / (pow(a2, 2) + pow((c1 - a1), 2));
803  dcs0d = ((-a2) * das0 + (c1 - a1) * dac0) / (pow(a2, 2) + pow((c1 - a1), 2));
804 
805  dsn1d = ((c1 - b1) * das1 - (-b2) * (-dac0)) / (pow(b2, 2) + pow((c1 - b1), 2));
806  dcs1d = ((-b2) * das1 + (c1 - b1) * (-dac0)) / (pow(b2, 2) + pow((c1 - b1), 2));
807  //
808  //
809  //
810  dzna = (pow((b1 - a1), 2) + pow((b2 - a2), 2)) * (pow((b1 - a1), 2) + pow((a2 + b2), 2));
811 
812  sv123 = (
813  (dcs0s + dcs1s) * exp(-c2 * t00) * (-1) +
814  (dcs0d + dcs1d) * exp(-c1 * t00) +
815  ((dsn0s - dsn0d) * sin(a2 * t00) + (dcs0s - dcs0d) * cos(a2 * t00)) * exp(-a1 * t00) +
816  ((dsn1s - dsn1d) * sin(b2 * t00) + (dcs1s - dcs1d) * cos(b2 * t00)) * exp(-b1 * t00)
817  )
818  / dzna / (1 / c2 - 1 / c1);
819 
820  return sv123;
821 }
822 
823 //
824 //
825 //
826 
827 
828 double
830  double timing)
831 {
832 
833  //--------------------------------------
834  //
835  // o "timing" unit is [us]
836  // o flag_gen = 0(=signal), 1(=parallel), 2(=serial)
837  // o return value(PDF) is [GeV]
838  // o Generate signal shape using a simplified function.
839  //
840  //
841  //--------------------------------------
842  double tsh, dd;
843  static double tc, tc2, tsc, tris;
844  static double amp, dft, as;
845 
846 
847  // int im, ij;
848 
849  static int ifir = 0;
850 
851  if (ifir == 0) {
852 
853  const double td = 0.10; // diff time ( 0.10)
854  const double t1 = 0.10; // integ1 real ( 0.10)
855  // b1 = 30.90; // integ1 imag ( 30.90)
856  const double t2 = 0.01; // integ2 real ( 0.01)
857  // b2 = 30.01; // integ2 imag ( 30.01)
858  double ts = 1.00; // scint decay ( 1.00)
859  dft = 0.600; // diff delay ( 0.600)
860  as = 0.548; // diff frac ( 0.548)
861  //
862  amp = 1.0;
863  tris = 0.01;
864  // ts0 = 0.0;
865  tsc = ts;
866  double fm = 0;
867  //
868  int im = 0;
869  int ij = 0;
870  tc = 0;
871  double tt = u_max(u_max(td, t1), u_max(t2, ts)) * 2;
872  int flag_once = 0;
873  while (flag_once == 0) {
874  double dt = tt / 1000;
875 
876  double tm = 0;
877  for (int j = 1; j <= 1000; j++) {
878  tc2 = tc - dft;
879  double fff =
880  (ShapeF(tc, tsc) -
881  ShapeF(tc, tris) * 0.01) -
882  (ShapeF(tc2, tsc) -
883  ShapeF(tc2, tris) * 0.01) * as;
884  if (fff > fm) {
885  fm = fff;
886  tm = tc;
887  im = j;
888  }
889  tc = tc + dt;
890  }
891  if (im >= 1000) {
892  tt = 2 * tt;
893  flag_once = 0;
894  continue;
895  }
896  if (ij == 0) {
897  ij = 1;
898  tc = 0.99 * tm;
899  dt = tm * 0.02 / 1000;
900  flag_once = 0;
901  continue;
902  }
903  flag_once = 1;
904  }
905  amp = 1.0 / fm;
906  ifir = 1;
907  }
908  //
909  //
910  double pdf = 0;
911  if (flag_gen == 0) {
912  //-----<signal>
913  tc2 = timing - dft;
914  pdf = amp * (
915  (ShapeF(timing, tsc) -
916  ShapeF(timing, tris) * 0.01) -
917  (ShapeF(tc2, tsc) -
918  ShapeF(tc2, tris) * 0.01) * as);
919  } else if (flag_gen == 1) {
920  //-----<parallel>
921  tc2 = timing - dft;
922  tsh = 0.001;
923  pdf = amp * (
924  ShapeF(timing, tsh) -
925  ShapeF(tc2, tsh) * as);
926  pdf = pdf * 0.001; // GeV
927  } else {
928  //-----<serial>
929  tc2 = timing - dft;
930  tsh = 0.001;
931  pdf = amp * (
932  ShapeF(timing, tsh) -
933  ShapeF(tc2, tsh) * as);
934  //
935  tc = timing - 0.01;
936  if (tc < 0) { tc = 0; }
937  dd = timing - tc;
938  tc2 = tc - dft;
939  pdf = (amp * (
940  ShapeF(tc, tsh) -
941  ShapeF(tc2, tsh) * as) - pdf) / dd;
942  pdf = pdf * 0.001; // GeV
943  }
944 
945  return pdf;
946 }
947 
948 
949 double TrgEclDigitizer::ShapeF(double t00, double ts1)
950 {
951  static const double realNaN = std::numeric_limits<double>::quiet_NaN();
952 
953  double dzna;
954  // double das1,das0,dac0;
955  double dcs0s = realNaN, dsn0s = realNaN, dcs0d, dsn0d;
956  double dcs1s = realNaN, dsn1s = realNaN, dcs1d, dsn1d;
957  double a1, a2, b1, b2, c1, c2 = realNaN;
958  double sv123 = 0.0;
959 
960  if (t00 <= 0.0) return 0;
961 
962 
963 
964  a1 = 10 ;
965  a2 = 0.0323625 ;
966  b1 = 100;
967  b2 = 0.0333222;
968  c1 = 10;
969 
970  if (ts1 == 1) {
971  c2 = 1;
972  dsn0s = -29.9897;
973  dcs0s = -0.08627;
974 
975  dsn1s = -2.64784;
976  dcs1s = -0.00285194;
977  }
978  if (ts1 == 0.01) {
979  c2 = 100;
980  dsn0s = 2.999 ;
981  dcs0s = -0.00323517;
982 
983  dsn1s = 5.82524;
984  dcs1s = -7866.7;
985  }
986  if (ts1 == 0.001) {
987  c2 = 1000;
988  dsn0s = 0.272636;
989  dcs0s = -0.000204983;
990 
991  dsn1s = 0.291262;
992  dcs1s = 0.000204894;
993  }
994 
995  dsn0d = -5.998;
996  dcs0d = -8340.22;
997 
998  dsn1d = -2.91262;
999  dcs1d = -0.00323517;
1000  //
1001  //
1002  //
1003  dzna = 6.561e+07;
1004 
1005  sv123 = (
1006  (dcs0s + dcs1s) * exp(-c2 * t00) * (-1) +
1007  (dcs0d + dcs1d) * exp(-c1 * t00) +
1008  ((dsn0s - dsn0d) * sin(a2 * t00) + (dcs0s - dcs0d) * cos(a2 * t00)) * exp(-a1 * t00) +
1009  ((dsn1s - dsn1d) * sin(b2 * t00) + (dcs1s - dcs1d) * cos(b2 * t00)) * exp(-b1 * t00)
1010  )
1011  / dzna / (1 / c2 - 1 / c1);
1012 
1013  return sv123;
1014 }
1015 //
1016 //
1017 //
1018 double
1019 TrgEclDigitizer::u_max(double aaa, double bbb)
1020 {
1021  if (aaa > bbb) { return aaa; }
1022  else { return bbb; }
1023 }
1024 //
1025 //
1026 //
Class to store simulated hits which equate to average of ECLSImHit on crystals input for digitization...
Definition: ECLHit.h:25
double getTimeAve() const
Get average time.
Definition: ECLHit.h:75
int getCellId() const
Get Cell ID.
Definition: ECLHit.h:65
double getEnergyDep() const
Get deposit energy.
Definition: ECLHit.h:70
ClassECLSimHit - Geant4 simulated hit for the ECL.
Definition: ECLSimHit.h:29
int getCellId() const
Get Cell ID.
Definition: ECLSimHit.h:86
double getFlightTime() const
Get Flight time from IP.
Definition: ECLSimHit.h:101
double getEnergyDep() const
Get Deposit energy.
Definition: ECLSimHit.h:106
G4ThreeVector getPosIn() const
Get Position.
Definition: ECLSimHit.h:121
The Class for ECL Geometry Parameters.
static ECLGeometryPar * Instance()
Static method to get a reference to the ECLGeometryPar instance.
ROOT::Math::XYZVector GetCrystalPos(int cid)
The Position of crystal.
ROOT::Math::XYZVector GetCrystalVec(int cid)
The direction of crystal.
virtual unsigned short getBackgroundTag() const
Get background tag.
Definition: SimHitBase.h:46
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
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
Example Detector.
Definition: TRGECLBGTCHit.h:24
Digitize result.
void setThetaPhiIDs(int thid, int phid)
Set Theta and Phi Id of TC.
class TrgEclDataBase;
int _FADC
Flag of choosing the method of waveform generation function 0: use simplifiedFADC,...
double TCTiming_tot[576]
TC Timing converted from Xtarl Timing [GeV].
virtual ~TrgEclDigitizer()
Destructor.
void save(int)
save fitting result into tables
double TCBkgContribution[576][80]
Beambackground contribution.
double WaveForm[576][64]
TC Energy converted from Xtarl Energy [GeV].
double TCRawTiming[576][60]
Input TC timing[ns]
double TCEnergy[576][80]
TC Energy converted from Xtarl Energy [GeV].
double TCSigContribution[576][80]
Signal contribution.
void setup()
setup fam module
std::vector< std::vector< double > > MatrixParallel
Noise Matrix of Parallel and Serial Noise.
TrgEclDataBase * _DataBase
Object of DataBase.
double TCTiming[576][80]
TC Timing converted from Xtarl Timing [GeV].
double TCRawBkgTag[576][60]
Input Beambackground tag
double interFADC(double)
Faster FADC using interpolation.
std::vector< std::vector< double > > MatrixSerial
Noise Low triangle Matrix of Serial noise
double TCRawEnergy[576][60]
Input TC energy[GeV].
double TimeRange
time range(default : -4000 ~ 4000 ns )
int _BeambkgTag
Flag of saving beam background tag or not.
double FADC(int, double)
FADC
double SimplifiedFADC(int, double)
FADC.
void digitization01(std::vector< std::vector< double >> &, std::vector< std::vector< double >> &)
fit method, digi with 125ns interval
double u_max(double, double)
Find max value between 2 vals;.
int _waveform
Flag of waveform table.
int TCBeambkgTag[576][80]
Beambackground tag.
double ShapeF(double, double, double, double, double, double, double)
return shape using FADC function
void getTCHit(int)
get TC Hits from Xtal hits
TrgEclMapping * _TCMap
Object of TC Mapping.
double TCEnergy_tot[576]
TC Energy converted from Xtarl Energy [GeV].
void digitization02(std::vector< std::vector< double >> &, std::vector< std::vector< double >> &)
original no fit method, digi with 12ns interval
A class of TC Mapping.
Definition: TrgEclMapping.h:26
int getTCThetaIdFromTCId(int)
get [TC Theta ID] from [TC ID]
int getTCIdFromXtalId(int)
get [TC ID] from [Xtal ID]
int getTCPhiIdFromTCId(int)
get [TC Phi ID] from [TC ID]
static const double ns
Standard of [time].
Definition: Unit.h:48
static const double GeV
Standard of [energy, momentum, mass].
Definition: Unit.h:51
static const double realNaN
constant for double NaN
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.