2#include "Tools/HgcrocEmulator.h"
29 "[0]*((1.0+exp([1]*(-[2]+[3])))*(1.0+exp([5]*(-[6]+[3]))))/"
30 "((1.0+exp([1]*(x-[2]+[3]-[4])))*(1.0+exp([5]*(x-[6]+[3]-[4]))))",
47 std::vector<std::pair<double, double>> &arriving_pulses,
48 std::vector<ldmx::HgcrocDigiCollection::Sample> &digiToAdd)
const {
55 double padCapacitance =
getCondition(channelID,
"PAD_CAPACITANCE");
58 double toaThreshold =
getCondition(channelID,
"TOA_THRESHOLD");
59 double totThreshold =
getCondition(channelID,
"TOT_THRESHOLD");
64 double drainRate =
getCondition(channelID,
"DRAIN_RATE");
71 arriving_pulses.begin(), arriving_pulses.end(),
72 [](
const std::pair<double, double> &a,
73 const std::pair<double, double> &b) { return a.first > b.first; });
88 for (
int iADC = 0; iADC <
nADCs_; iADC++) {
93 bool startTOT =
false;
97 for (
auto hit : pulse.
hits()) {
102 double vpeak = pulse(hit.second);
104 if (vpeak > totThreshold) {
106 if (toverTOT < hit.second)
107 toverTOT = hit.second;
110 if (vpeak > toaThreshold) {
111 if (!overTOA || hit.second < toverTOA) toverTOA = hit.second;
118 if (!overTOA && pulse(startBX +
clockCycle_) > toaThreshold) {
119 if (pulse(startBX) < toaThreshold) {
133 double charge_deposited =
145 double tot = charge_deposited / drainRate;
150 int tdc_counts = int(tot * 4096 / totMax) +
pedestal;
157 toa = digiToAdd.back().toa();
160 double timecross = pulse.
findCrossing(startBX, toverTOT, toaThreshold);
161 toa = int((timecross - startBX) *
ns_);
163 if (toa == 0) toa = 1;
164 if (toa > 1023) toa = 1023;
167 digiToAdd.emplace_back(
169 (iADC > 0) ? digiToAdd.at(iADC - 1).adc_t()
177 while (digiToAdd.size() <
nADCs_) {
178 digiToAdd.emplace_back(
true,
false,
189 int adc = bxvolts /
gain;
190 if (adc < 0) adc = 0;
191 if (adc > 1023) adc = 1023;
195 if (pulse(startBX) < toaThreshold && overTOA) {
196 double timecross = pulse.
findCrossing(startBX, toverTOA, toaThreshold);
197 toa = int((timecross - startBX) *
ns_);
199 if (toa == 0) toa = 1;
200 if (toa > 1023) toa = 1023;
206 digiToAdd.emplace_back(
208 (iADC > 0) ? digiToAdd.at(iADC - 1).adc_t()
222 const int &channel,
const double &soi_amplitude)
const {
227 std::vector<ldmx::HgcrocDigiCollection::Sample> noise_digi;
228 for (
int iADC{0}; iADC <
nADCs_; iADC++) {
230 int adc_tm1{
static_cast<int>(
pedestal)};
232 adc_tm1 = noise_digi.at(iADC - 1).adc_t();
237 if (iADC ==
iSOI_) adc_t += soi_amplitude /
gain;
241 noise_digi.emplace_back(
false,
false, adc_tm1, adc_t, 0);
Class encapsulating parameters for configuring a processor.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
const std::vector< std::pair< double, double > > & hits() const
Get list of individual pulses that are entering the chip.
double findCrossing(double low, double high, double level, double prec=0.01)
Find the time at which we cross the input level.
void addOrMerge(const std::pair< double, double > &hit, double hit_merge_ns)
Put another hit into this composite pulse.
double readoutThreshold(const int &id) const
Readout Threshold (ADC Counts)
double rateUpSlope_
Rate of Up Slope in Pulse Shape [1/ns].
void seedGenerator(uint64_t seed)
Seed the emulator for random number generation.
double noise(const int &channelID) const
Get random noise amplitdue for input channel [mV].
double pedestal(const int &id) const
Pedestal [ADC Counts] for input channel.
double getCondition(int id, const std::string &name) const
Get condition for input chip ID, condition name, and default value.
double hit_merge_ns_
Hit merging time [ns].
double timeUpSlope_
Time of Up Slope relative to Pulse Shape Fit [ns].
double timePeak_
Time of Peak relative to pulse shape fit [ns].
int iSOI_
Index for the Sample Of Interest in the list of digi samples.
bool digitize(const int &channelID, std::vector< std::pair< double, double > > &arriving_pulses, std::vector< ldmx::HgcrocDigiCollection::Sample > &digiToAdd) const
Digitize the signals from the simulated hits.
std::unique_ptr< TRandom3 > noiseInjector_
Generates Gaussian noise on top of real hits.
double gain(const int &channelID) const
Gain for input channel.
double timingJitter_
Jitter of timing mechanism in the chip [ns].
int nADCs_
Depth of ADC buffer.
bool noise_
Put noise in channels, only configure to false if testing.
double timeDnSlope_
Time of Down Slope relative to Pulse Shape Fit [ns].
TF1 pulseFunc_
Functional shape of signal pulse in time.
double clockCycle_
Time interval for chip clock [ns].
std::vector< ldmx::HgcrocDigiCollection::Sample > noiseDigi(const int &channel, const double &soi_amplitude=0) const
Generate a digi of pure noise.
double rateDnSlope_
Rate of Down Slope in Pulse Shape [1/ns].
HgcrocEmulator(const framework::config::Parameters &ps)
Constructor.
double ns_
Conversion from time [ns] to counts.