-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDigitizer.cxx
More file actions
602 lines (540 loc) · 22.1 KB
/
Digitizer.cxx
File metadata and controls
602 lines (540 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "FT0Simulation/Digitizer.h"
#include "FT0Simulation/DigitizationConstants.h"
#include "FT0Base/FT0DigParam.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "CommonConstants/PhysicsConstants.h"
#include "CommonDataFormat/InteractionRecord.h"
#include "DataFormatsFT0/LookUpTable.h"
#include "FT0Base/Constants.h"
#include <map>
#include <array>
#include <regex>
#include <string>
#include "TMath.h"
#include "TRandom.h"
#include <TH1F.h>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <optional>
#include <Vc/Vc>
using namespace o2::ft0;
ClassImp(Digitizer);
namespace o2::ft0
{
// signal shape function
template <typename Float>
Float signalForm_i(Float x)
{
float p0, p1, p2, p3, p4, p5, p6, p7;
p0 = 1.30853;
p1 = 0.516807;
p2 = 3.36714;
p3 = -1.01206;
p4 = 1.42832;
p5 = 1.1589;
p6 = 1.22019;
p7 = 0.426818;
Double_t val = 0;
if (x > p3) {
Double_t x1 = x - p3;
Double_t arg1 = (log(x1) - p0) / p1;
val += p2 * (1.0 / (x1 * p1 * sqrt(2 * TMath::Pi()))) * exp(-0.5 * arg1 * arg1);
}
if (x > p7) {
Double_t x2 = x - p7;
Double_t arg2 = (log(x2) - p4) / p5;
val += p6 * (1.0 / (x2 * p5 * sqrt(2 * TMath::Pi()))) * exp(-0.5 * arg2 * arg2);
}
return val;
};
// integrated signal shape function
inline float signalForm_integral(float x)
{
float p0, p1, p2, p3, p4, p5, p6, p7;
p0 = 1.30853;
p1 = 0.516807;
p2 = 3.36714;
p3 = -1.01206;
p4 = 1.42832;
p5 = 1.1589;
p6 = 1.22019;
p7 = 0.426818;
Double_t val = 0;
if (x > p3) {
Double_t x1 = x - p3;
Double_t z1 = (log(x1) - p0) / (sqrt(2) * p1);
val += p2 * 0.5 * (1 + TMath::Erf(z1)); // norm1 * CDF1
}
if (x > p7) {
Double_t x2 = x - p7;
Double_t z2 = (log(x2) - p4) / (sqrt(2) * p5);
val += p6 * 0.5 * (1 + TMath::Erf(z2)); // norm2 * CDF2
}
return val;
};
/*
// signal shape function
template <typename Float>
Float signalForm_i(Float x)
{
using namespace std;
Float const a = -0.45458;
Float const b = -0.83344945;
return x > Float(0) ? -(exp(b * x) - exp(a * x)) / Float(7.8446501) : Float(0);
};
// integrated signal shape function
inline float signalForm_integral(float x)
{
using namespace std;
double const a = -0.45458;
double const b = -0.83344945;
if (x < 0) {
x = 0;
}
return -(exp(b * x) / b - exp(a * x) / a) / 7.8446501;
};
*/
// SIMD version of the integrated signal shape function
inline Vc::float_v signalForm_integralVc(Vc::float_v x)
{
auto const mask = (x >= 0.0f);
Vc::float_v arg(0);
arg.assign(x, mask); // branchless if
Vc::float_v const a(-0.45458f);
Vc::float_v const b(-0.83344945f);
Vc::float_v result = -(Vc::exp(b * arg) / b - Vc::exp(a * arg) / a) / 7.8446501f;
return result;
};
} // namespace o2::ft0
Digitizer::CFDOutput Digitizer::get_time(const std::vector<float>& times, float deadTime)
{
assert(std::is_sorted(std::begin(times), std::end(times)));
// get a new batch of random values
for (float& n : mNoiseSamples) {
n = mRndGaus.getNextValue();
}
// this lambda function evaluates the signal shape at a give time
auto value_at = [&](float time) {
float val = 0;
// (1) sum over individual hits
Vc::float_v acc(0);
Vc::float_v tableVal(0);
const float* tp = times.data();
size_t m = times.size() / Vc::float_v::size();
for (size_t i = 0; i < m; ++i) {
tableVal.load(tp);
tp += Vc::float_v::size();
Vc::prefetchForOneRead(tp);
acc += signalFormVc(time - tableVal);
}
val += acc.sum();
// non-SIMD tail
for (size_t i = Vc::float_v::size() * m; i < times.size(); ++i, ++tp) {
val += signalForm(time - (*tp));
}
// (2) add noise
// find the right indices into the sinc table
int timeIndex = std::lround(time / FT0DigParam::Instance().mNoisePeriod * mSincTable.size());
int timeOffset = timeIndex / mSincTable.size();
timeIndex %= mSincTable.size();
if (timeOffset >= mNumNoiseSamples) { // this happens when time >= 25 ns
timeOffset = mNumNoiseSamples - 1;
LOG(debug) << "timeOffset >= mNumNoiseSamples";
}
if (timeOffset <= -mNumNoiseSamples) { // this happens when time <= -25 ns
timeOffset = -mNumNoiseSamples + 1;
LOG(debug) << "timeOffset <= -mNumNoiseSamples";
}
Vc::float_v noiseVal(0);
const float* np = mNoiseSamples.data();
tp = mSincTable[timeIndex].data() + mNumNoiseSamples - timeOffset;
acc = 0.0f;
m = mNumNoiseSamples / Vc::float_v::Size;
for (size_t i = 0; i < m; ++i) {
tableVal.load(tp);
tp += Vc::float_v::Size;
Vc::prefetchForOneRead(tp);
noiseVal.load(np);
np += Vc::float_v::Size;
Vc::prefetchForOneRead(np);
acc += noiseVal * tableVal;
}
val += acc.sum(); // horizontal sum
// non-SIMD tail
for (size_t i = Vc::float_v::Size * m; i < mNumNoiseSamples; ++i, ++tp, ++np) {
val += (*np) * (*tp);
}
return val;
};
auto const min_time = std::max(deadTime, *std::min_element(std::begin(times),
std::end(times)));
CFDOutput result{std::nullopt, -0.5f * FT0DigParam::Instance().mBunchWidth};
bool is_positive = true;
// reset the chache
std::fill_n(std::begin(mSignalCache), std::size(mSignalCache), -1.0f);
const auto& params = FT0DigParam::Instance();
// we need double precision for time in order to match previous behaviour
for (double time = min_time; time < 0.5 * params.mBunchWidth; time += DP::SIGNAL_CACHE_DT) {
float const val = value_at(time);
int const index = std::lround((time + 0.5 * params.mBunchWidth) / DP::SIGNAL_CACHE_DT);
if (index >= 0 && index < mSignalCache.size()) { // save the value for later use
mSignalCache[index] = val;
}
// look up the time-shifted signal value from the past
float val_prev = 0.0f;
int const index_prev = std::lround((time - params.mCFDShiftPos + 0.5f * params.mBunchWidth) / DP::SIGNAL_CACHE_DT);
val_prev = ((index_prev < 0 || index_prev >= mSignalCache.size() || mSignalCache[index_prev] < 0.0f)
? value_at(time - params.mCFDShiftPos) // was not computed before
: mSignalCache[index_prev]); // is available in the cache
float const cfd_val = 5.0f * val_prev - val;
if (std::abs(val) > params.mCFD_trsh && !is_positive && cfd_val > 0.0f) {
if (!result.particle) {
result.particle = time;
}
result.deadTime = time + params.mCFDdeadTime;
time += params.mCFDdeadTime - DP::SIGNAL_CACHE_DT;
is_positive = true;
} else {
is_positive = cfd_val > 0.0f;
}
}
return result;
}
double Digitizer::measure_amplitude(const std::vector<float>& times) const
{
float const from = FT0DigParam::Instance().mAmpRecordLow;
float const to = from + FT0DigParam::Instance().mAmpRecordUp;
// SIMD version has a negligible effect on the total wall time
Vc::float_v acc(0);
Vc::float_v tv(0);
const float* tp = times.data();
size_t const m = times.size() / Vc::float_v::Size;
for (size_t i = 0; i < m; ++i) {
tv.load(tp);
tp += Vc::float_v::Size;
Vc::prefetchForOneRead(tp);
acc += signalForm_integralVc(to - tv) - signalForm_integralVc(from - tv);
}
float result = acc.sum(); // horizontal sum
// non-SIMD tail
for (size_t i = Vc::float_v::Size * m; i < times.size(); ++i, ++tp) {
result += signalForm_integral(to - (*tp)) - signalForm_integral(from - (*tp));
}
return result;
}
void Digitizer::process(const std::vector<o2::ft0::HitType>* hits,
std::vector<o2::ft0::Digit>& digitsBC,
std::vector<o2::ft0::ChannelData>& digitsCh,
std::vector<o2::ft0::DetTrigInput>& digitsTrig,
o2::dataformats::MCTruthContainer<o2::ft0::MCLabel>& label)
{
;
// Calculating signal time, amplitude in mean_time +- time_gate --------------
LOG(debug) << " process firstBCinDeque " << firstBCinDeque << " mIntRecord " << mIntRecord;
if (firstBCinDeque != mIntRecord) {
flush(digitsBC, digitsCh, digitsTrig, label);
}
Int_t parent = -10;
for (auto const& hit : *hits) {
if (hit.GetEnergyLoss() > 0) {
continue;
}
Int_t hit_ch = hit.GetDetectorID();
// If the dead channel map is used, and the channel with ID 'hit_ch' is dead, don't process this hit.
if (mDeadChannelMap && !mDeadChannelMap->isChannelAlive(hit_ch)) {
continue;
}
const auto& params = FT0DigParam::Instance();
Bool_t is_A_side = (hit_ch < 4 * mGeometry.NCellsA);
// Subtract time-of-flight from hit time
const Float_t timeOfFlight = hit.GetPos().R() / o2::constants::physics::LightSpeedCm2NS;
const Float_t timeOffset = is_A_side ? params.hitTimeOffsetA : params.hitTimeOffsetC;
Double_t hit_time = hit.GetTime() - timeOfFlight + timeOffset + mIntRecord.getTimeOffsetWrtBC();
if (hit_time > 150) {
continue; // not collect very slow particles
}
auto relBC = o2::InteractionRecord{hit_time};
if (mCache.size() <= relBC.bc) {
mCache.resize(relBC.bc + 1);
}
mCache[relBC.bc].hits.emplace_back(BCCache::particle{hit_ch, hit_time - relBC.bc2ns()});
// charge particles in MCLabel
Int_t parentID = hit.GetTrackID();
if (parentID != parent) {
mCache[relBC.bc].labels.emplace(parentID, mEventID, mSrcID, hit_ch);
parent = parentID;
}
}
}
void Digitizer::storeBC(BCCache& bc,
std::vector<o2::ft0::Digit>& digitsBC,
std::vector<o2::ft0::ChannelData>& digitsCh,
std::vector<o2::ft0::DetTrigInput>& digitsTrig,
o2::dataformats::MCTruthContainer<o2::ft0::MCLabel>& labels)
{
if (bc.hits.empty()) {
return;
}
// Initialize mapping channelID -> PM hash and PM side (A/C) using FT0 LUT
static bool pmLutInitialized = false;
static std::array<uint8_t, o2::ft0::Constants::sNCHANNELS_PM> mChID2PMhash{};
static std::map<uint8_t, bool> mMapPMhash2isAside; // hashed PM -> is A side
if (!pmLutInitialized) {
std::map<std::string, uint8_t> mapFEE2hash; // module name -> hashed PM id
uint8_t tcmHash = 0;
const auto& lut = o2::ft0::SingleLUT::Instance().getVecMetadataFEE();
auto lutSorted = lut;
std::sort(lutSorted.begin(), lutSorted.end(),
[](const auto& first, const auto& second) { return first.mModuleName < second.mModuleName; });
uint8_t binPos = 0;
for (const auto& lutEntry : lutSorted) {
const auto& moduleName = lutEntry.mModuleName;
const auto& moduleType = lutEntry.mModuleType;
const auto& strChID = lutEntry.mChannelID;
auto [it, inserted] = mapFEE2hash.insert({moduleName, binPos});
if (inserted) {
if (moduleName.find("PMA") != std::string::npos) {
mMapPMhash2isAside.insert({binPos, true});
} else if (moduleName.find("PMC") != std::string::npos) {
mMapPMhash2isAside.insert({binPos, false});
}
++binPos;
}
if (std::regex_match(strChID, std::regex("^[0-9]{1,3}$"))) {
int chID = std::stoi(strChID);
if (chID < o2::ft0::Constants::sNCHANNELS_PM) {
mChID2PMhash[chID] = mapFEE2hash[moduleName];
} else {
LOG(fatal) << "Incorrect LUT entry: chID " << strChID << " | " << moduleName;
}
} else if (moduleType != "TCM") {
LOG(fatal) << "Non-TCM module w/o numerical chID: chID " << strChID << " | " << moduleName;
} else { // TCM
tcmHash = mapFEE2hash[moduleName];
}
}
pmLutInitialized = true;
}
int n_hit_A = 0, n_hit_C = 0, mean_time_A = 0, mean_time_C = 0;
int summ_ampl_A = 0, summ_ampl_C = 0;
int sum_A_ampl = 0, sum_C_ampl = 0;
int nPMTs = mGeometry.NCellsA * 4 + mGeometry.NCellsC * 4;
std::vector<int> sum_ampl_ipmt(nPMTs, 0);
// Per-PM summed charge (like in digits2trgFT0)
std::map<uint8_t, int> mapPMhash2sumAmpl;
for (const auto& entry : mMapPMhash2isAside) {
mapPMhash2sumAmpl.insert({entry.first, 0});
}
int vertex_time;
const auto& params = FT0DigParam::Instance();
int first = digitsCh.size(), nStored = 0;
auto& particles = bc.hits;
std::sort(std::begin(particles), std::end(particles));
auto channel_end = particles.begin();
std::vector<float> channel_times;
for (Int_t ipmt = 0; ipmt < params.mMCPs; ++ipmt) {
auto channel_begin = channel_end;
channel_end = std::find_if(channel_begin, particles.end(),
[ipmt](BCCache::particle const& p) { return p.hit_ch != ipmt; });
// The hits between 'channel_begin' and 'channel_end' now contains all hits for channel 'ipmt'
if (channel_end - channel_begin < params.mAmp_trsh) {
continue;
}
channel_times.resize(channel_end - channel_begin);
std::transform(channel_begin, channel_end, channel_times.begin(), [](BCCache::particle const& p) { return p.hit_time; });
int chain = (std::rand() % 2) ? 1 : 0;
auto cfd = get_time(channel_times, mDeadTimes[ipmt].intrec.bc2ns() -
firstBCinDeque.bc2ns() +
mDeadTimes[ipmt].deadTime);
mDeadTimes[ipmt].intrec = firstBCinDeque;
mDeadTimes[ipmt].deadTime = cfd.deadTime;
if (!cfd.particle) {
continue;
}
// miscalibrate CFD with cahnnel offsets
int miscalib = 0;
if (mCalibOffset) {
miscalib = mCalibOffset->mTimeOffsets[ipmt];
}
int smeared_time = 1000. * (*cfd.particle - params.mCfdShift) * params.mChannelWidthInverse + miscalib; // + int(1000. * mIntRecord.getTimeOffsetWrtBC() * params.mChannelWidthInverse);
bool is_time_in_signal_gate = (smeared_time > -params.mTime_trg_gate && smeared_time < params.mTime_trg_gate);
float charge = measure_amplitude(channel_times) * params.mCharge2amp;
float amp = is_time_in_signal_gate ? params.mMV_2_Nchannels * charge : 0;
if (amp > 4095) {
amp = 4095;
}
LOG(debug) << mEventID << " bc " << firstBCinDeque.bc << " orbit " << firstBCinDeque.orbit << ", ipmt " << ipmt << ", smeared_time " << smeared_time << " nStored " << nStored << " offset " << miscalib;
if (is_time_in_signal_gate) {
chain |= (1 << o2::ft0::ChannelData::EEventDataBit::kIsCFDinADCgate);
chain |= (1 << o2::ft0::ChannelData::EEventDataBit::kIsEventInTVDC);
// Sum channel charge per PM (similar logic as in digits2trgFT0)
if (ipmt < o2::ft0::Constants::sNCHANNELS_PM) {
mapPMhash2sumAmpl[mChID2PMhash[static_cast<uint8_t>(ipmt)]] += static_cast<int>(amp);
}
}
digitsCh.emplace_back(ipmt, smeared_time, int(amp), chain);
nStored++;
// fill triggers
Bool_t is_A_side = (ipmt < 4 * mGeometry.NCellsA);
if (!is_time_in_signal_gate) {
continue;
}
sum_ampl_ipmt[ipmt] += amp;
if (is_A_side) {
n_hit_A++;
summ_ampl_A += amp;
mean_time_A += smeared_time;
} else {
n_hit_C++;
summ_ampl_C += amp;
mean_time_C += smeared_time;
}
}
for (size_t i = 0; i < sum_ampl_ipmt.size(); i++) {
sum_ampl_ipmt[i] = sum_ampl_ipmt[i] >> 3;
if (i < 4 * mGeometry.NCellsA) {
sum_A_ampl += sum_ampl_ipmt[i];
} else {
sum_C_ampl += sum_ampl_ipmt[i];
}
}
// Sum over PMs (using per-PM map) for debug/monitoring
int sum_PM_ampl_debug = 0;
int sum_PM_ampl_A_debug = 0;
int sum_PM_ampl_C_debug = 0;
for (const auto& entry : mapPMhash2sumAmpl) {
int pmAmpl = (entry.second >> 3);
sum_PM_ampl_debug += pmAmpl;
auto itSide = mMapPMhash2isAside.find(entry.first);
if (itSide != mMapPMhash2isAside.end()) {
if (itSide->second) {
sum_PM_ampl_A_debug += pmAmpl;
} else {
sum_PM_ampl_C_debug += pmAmpl;
}
}
}
LOG(debug) << "Sum PM amplitude (LUT-based): total=" << sum_PM_ampl_debug
<< " A-side=" << sum_PM_ampl_A_debug
<< " C-side=" << sum_PM_ampl_C_debug;
Bool_t is_A, is_C, isVertex, is_Central, is_SemiCentral = 0;
is_A = n_hit_A > 0;
is_C = n_hit_C > 0;
is_Central = sum_PM_ampl_A_debug + sum_PM_ampl_C_debug >= 2 * params.mtrg_central_trh;
is_SemiCentral = sum_PM_ampl_A_debug + sum_PM_ampl_C_debug >= 2 * params.mtrg_semicentral_trh && !is_Central;
uint32_t amplA = is_A ? summ_ampl_A * 0.125 : -5000; // sum amplitude A side / 8 (hardware)
uint32_t amplC = is_C ? summ_ampl_C * 0.125 : -5000; // sum amplitude C side / 8 (hardware)
int timeA = is_A ? mean_time_A / n_hit_A : -5000; // average time A side
int timeC = is_C ? mean_time_C / n_hit_C : -5000; // average time C side
vertex_time = (timeC - timeA) * 0.5;
isVertex = is_A && is_C && (vertex_time > -params.mTime_trg_vertex_gate && vertex_time < params.mTime_trg_vertex_gate);
LOG(debug) << " A " << is_A << " timeA " << timeA << " mean_time_A " << mean_time_A << " n_hit_A " << n_hit_A << " C " << is_C << " timeC " << timeC << " mean_time_C " << mean_time_C << " n_hit_C " << n_hit_C << " vertex_time " << vertex_time;
Triggers triggers;
bool isLaser = false;
bool isOutputsAreBlocked = false;
bool isDataValid = true;
if (nStored > 0) {
triggers.setTriggers(is_A, is_C, isVertex, is_Central, is_SemiCentral, int8_t(n_hit_A), int8_t(n_hit_C),
amplA, amplC, timeA, timeC, isLaser, isOutputsAreBlocked, isDataValid);
digitsBC.emplace_back(first, nStored, firstBCinDeque, triggers, mEventID - 1);
digitsTrig.emplace_back(firstBCinDeque, is_A, is_C, isVertex, is_Central, is_SemiCentral);
size_t const nBC = digitsBC.size();
for (auto const& lbl : bc.labels) {
labels.addElement(nBC - 1, lbl);
}
}
// Debug output -------------------------------------------------------------
LOG(debug) << "Event ID: " << mEventID << ", bc " << firstBCinDeque.bc << ", N hit " << bc.hits.size();
LOG(debug) << "N hit A: " << int(triggers.getNChanA()) << " N hit C: " << int(triggers.getNChanC()) << " summ ampl A: " << int(triggers.getAmplA())
<< " summ ampl C: " << int(triggers.getAmplC()) << " mean time A: " << triggers.getTimeA()
<< " mean time C: " << triggers.getTimeC() << " nStored " << nStored;
LOG(debug) << "IS A " << triggers.getOrA() << " IsC " << triggers.getOrC() << " vertex " << triggers.getVertex() << " is Central " << triggers.getCen() << " is SemiCentral " << triggers.getSCen();
}
//------------------------------------------------------------------------
void Digitizer::flush(std::vector<o2::ft0::Digit>& digitsBC,
std::vector<o2::ft0::ChannelData>& digitsCh,
std::vector<o2::ft0::DetTrigInput>& digitsTrig,
o2::dataformats::MCTruthContainer<o2::ft0::MCLabel>& labels)
{
assert(firstBCinDeque <= mIntRecord);
while (firstBCinDeque < mIntRecord && !mCache.empty()) {
storeBC(mCache.front(), digitsBC, digitsCh, digitsTrig, labels);
mCache.pop_front();
++firstBCinDeque;
}
firstBCinDeque = mIntRecord;
}
void Digitizer::flush_all(std::vector<o2::ft0::Digit>& digitsBC,
std::vector<o2::ft0::ChannelData>& digitsCh,
std::vector<o2::ft0::DetTrigInput>& digitsTrig,
o2::dataformats::MCTruthContainer<o2::ft0::MCLabel>& labels)
{
assert(firstBCinDeque <= mIntRecord);
++mEventID;
while (!mCache.empty()) {
storeBC(mCache.front(), digitsBC, digitsCh, digitsTrig, labels);
mCache.pop_front();
++firstBCinDeque;
}
}
void Digitizer::initParameters()
{
auto const sinc = [](double x) { x *= TMath::Pi(); return (std::abs(x) < 1e-12) ? 1.0 : std::sin(x) / x; };
// number of noise samples in one BC
const auto& params = FT0DigParam::Instance();
mNumNoiseSamples = std::ceil(params.mBunchWidth / params.mNoisePeriod);
mNoiseSamples.resize(mNumNoiseSamples);
// set up tables with sinc function values (times noiseVar)
for (size_t i = 0, n = mSincTable.size(); i < n; ++i) {
float const time = i / float(n) * params.mNoisePeriod; // [0 .. 1/params.mNoisePeriod)
LOG(debug) << "initParameters " << i << "/" << n << " " << time;
// we make a table of sinc values between -num_noise_samples and 2*num_noise_samples
mSincTable[i].resize(3 * mNumNoiseSamples);
for (int j = -mNumNoiseSamples; j < 2 * mNumNoiseSamples; ++j) {
mSincTable[i][mNumNoiseSamples + j] = params.mNoiseVar * sinc((time + 0.5f * params.mBunchWidth) / params.mNoisePeriod - j);
}
}
// set up the lookup table for the signal form
for (size_t i = 0; i < DP::SIGNAL_TABLE_SIZE; ++i) {
float const x = float(i) / float(DP::SIGNAL_TABLE_SIZE) * params.mBunchWidth;
mSignalTable[i] = signalForm_i(x);
}
// cache for signal time series used by the CFD -BC/2 .. +3BC/2
mSignalCache.resize(std::lround(params.mBunchWidth / DP::SIGNAL_CACHE_DT));
}
//_______________________________________________________________________
void Digitizer::init()
{
LOG(info) << " @@@ Digitizer::init " << std::endl;
mDeadTimes.fill({InteractionRecord(0), -100.});
printParameters();
}
//_______________________________________________________________________
void Digitizer::finish()
{
printParameters();
}
//_______________________________________________________________________
void Digitizer::printParameters() const
{
const auto& params = FT0DigParam::Instance();
LOG(info) << " Run Digitzation with parametrs: \n"
<< " CFD amplitude threshold \n " << params.mCFD_trsh << " CFD signal gate in ps \n"
<< params.mTime_trg_gate << "shift to have signal around zero after CFD trancformation \n"
<< params.mCfdShift << "CFD distance between 0.3 of max amplitude to max \n"
<< params.mCFDShiftPos << "MIP -> mV " << params.mMip_in_V << " Pe in MIP \n"
<< params.mPe_in_mip << "noise level " << params.mNoiseVar << " noise frequency \n"
<< params.mNoisePeriod << " mMCPs " << params.mMCPs;
}
O2ParamImpl(FT0DigParam);