LDMX Software
HgcrocEmulator.h
1
2#ifndef TOOLS_HGCROCEMULATOR_H
3#define TOOLS_HGCROCEMULATOR_H
4
5#include "Conditions/SimpleTableCondition.h"
6#include "Framework/Configure/Parameters.h"
10
11//----------//
12// ROOT //
13//----------//
14#include "TF1.h"
15#include "TRandom3.h"
16
17namespace ldmx {
18
40 public:
47
50
55 bool hasSeed() const { return noiseInjector_.get() != nullptr; }
56
61 void seedGenerator(uint64_t seed);
62
73 // reset cache of column numbers if table changes
74 if (&table != chipConditions_) conditionNamesToIndex_.clear();
75 chipConditions_ = &table;
76 }
77
151 bool digitize(
152 const int& channelID,
153 std::vector<std::pair<double, double>>& arriving_pulses,
154 std::vector<ldmx::HgcrocDigiCollection::Sample>& digiToAdd) const;
155
176 std::vector<ldmx::HgcrocDigiCollection::Sample> noiseDigi(
177 const int& channel, const double& soi_amplitude = 0) const;
178
185 double noise(const int& channelID) const {
186 return noiseInjector_->Gaus(
187 0, getCondition(channelID, "NOISE") * gain(channelID));
188 };
189
191 double gain(const int& channelID) const {
192 return getCondition(channelID, "GAIN");
193 }
194
196 double pedestal(const int& id) const { return getCondition(id, "PEDESTAL"); }
197
199 double readoutThreshold(const int& id) const {
200 return getCondition(id, "READOUT_THRESHOLD");
201 }
202
203 private:
213 double getCondition(int id, const std::string& name) const {
214 // check if emulator has been passed a table of conditions
215 if (!chipConditions_) {
216 EXCEPTION_RAISE("HgcrocCond",
217 "HGC ROC Emulator was not given a conditions table.");
218 }
219
220 // cache column index for the input name
221 if (conditionNamesToIndex_.count(name) == 0)
223
224 // get condition
225 return chipConditions_->get(id, conditionNamesToIndex_.at(name));
226 }
227
228 private:
237 public:
245 CompositePulse(TF1& func, const double& g, const double& p)
246 : pulseFunc_{func}, gain_{g}, pedestal_{p} {}
247
258 void addOrMerge(const std::pair<double, double>& hit, double hit_merge_ns) {
259 auto imerge{hits_.begin()};
260 for (; imerge != hits_.end(); imerge++)
261 if (fabs(imerge->second - hit.second) < hit_merge_ns) break;
262 if (imerge == hits_.end()) { // didn't find a match, add to the list
263 hits_.push_back(hit);
264 } else { // merge hits, shifting time to average
265 imerge->second =
266 (imerge->second * imerge->first + hit.first * hit.second);
267 imerge->first += hit.first;
268 imerge->second /= imerge->first;
269 }
270 }
271
284 double findCrossing(double low, double high, double level,
285 double prec = 0.01) {
286 // use midpoint algorithm, assumes low is below and high is above
287 double step = high - low;
288 double pt = (high + low) / 2;
289 while (step > prec) {
290 double vmid = at(pt);
291 if (vmid < level) {
292 low = pt;
293 } else {
294 high = pt;
295 }
296 step = high - low;
297 pt = (high + low) / 2;
298 }
299 return pt;
300 }
301
303 void setGainPedestal(double gain, double pedestal) {
304 gain_ = gain;
306 }
307
314 double operator()(double time) const { return at(time); }
315
325 double at(double time) const {
326 double signal = gain_ * pedestal_;
327 for (auto hit : hits_)
328 signal += hit.first * pulseFunc_.Eval(time - hit.second);
329 return signal;
330 };
331
333 const std::vector<std::pair<double, double>>& hits() const { return hits_; }
334
335 private:
341 std::vector<std::pair<double, double>> hits_;
342
345
347 double gain_;
348
350 double pedestal_;
351
352 }; // CompositePulse
353
354 private:
355 /**************************************************************************************
356 * Parameters Identical for all Chips
357 *************************************************************************************/
358
360 bool noise_{true};
361
364
366 int iSOI_;
367
370
373
375 double ns_;
376
379
382
385
388
390 double timePeak_;
391
394
395 /**************************************************************************************
396 * Chip-Dependent Parameters (Conditions)
397 *************************************************************************************/
398
406
413 mutable std::map<std::string, int> conditionNamesToIndex_;
414
415 /**************************************************************************************
416 * Helpful Member Objects
417 *************************************************************************************/
418
420 std::unique_ptr<TRandom3> noiseInjector_;
421
442 mutable TF1 pulseFunc_;
443
444}; // HgcrocEmulator
445
446} // namespace ldmx
447
448#endif // TOOLS_HGCROCEMULATOR_H
Class that represents a digitized hit in a calorimeter cell readout by an HGCROC.
Utility used to generate noise hits.
Class which stores simulated calorimeter hit information.
unsigned int getColumnNumber(const std::string &colname) const
Get a the column number for the given column name.
T get(unsigned int id, unsigned int col) const
Get an entry by DetectorId and number.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
void setGainPedestal(double gain, double pedestal)
Configure the pulses for the current chip.
std::vector< std::pair< double, double > > hits_
pulses entering the chip
const std::vector< std::pair< double, double > > & hits() const
Get list of individual pulses that are entering the chip.
double at(double time) const
Measure the voltage at the input time.
double pedestal_
pedestal for current chip we are emulating
double gain_
gain for current chip we are emulating
double findCrossing(double low, double high, double level, double prec=0.01)
Find the time at which we cross the input level.
double operator()(double time) const
Evaluating this object as a function gives the same result as at.
TF1 & pulseFunc_
reference to pulse shape function shared by all pulses
void addOrMerge(const std::pair< double, double > &hit, double hit_merge_ns)
Put another hit into this composite pulse.
CompositePulse(TF1 &func, const double &g, const double &p)
Constructore.
Emulate the digitization procedure performed by the HGCROC.
void condition(const conditions::DoubleTableCondition &table)
Set Conditions.
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].
bool hasSeed() const
Check if emulator has been seeded.
double pedestal(const int &id) const
Pedestal [ADC Counts] for input channel.
const conditions::DoubleTableCondition * chipConditions_
Handle to table of chip-dependent conditions.
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.
std::map< std::string, int > conditionNamesToIndex_
Map of condition names to column numbers.
double gain(const int &channelID) const
Gain for input channel.
~HgcrocEmulator()
Destructor.
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].
double ns_
Conversion from time [ns] to counts.