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"
11
12//----------//
13// ROOT //
14//----------//
15#include "TF1.h"
16#include "TRandom3.h"
17
18namespace ldmx {
19
41 public:
48
51
56 bool hasSeed() const { return noiseInjector_.get() != nullptr; }
57
62 void seedGenerator(uint64_t seed);
63
74 // reset cache of column numbers if table changes
75 if (&table != chipConditions_) conditionNamesToIndex_.clear();
76 chipConditions_ = &table;
77 }
78
152 bool digitize(
153 const int& channelID,
154 std::vector<std::pair<double, double>>& arriving_pulses,
155 std::vector<ldmx::HgcrocDigiCollection::Sample>& digiToAdd) const;
156
177 std::vector<ldmx::HgcrocDigiCollection::Sample> noiseDigi(
178 const int& channel, const double& soi_amplitude = 0) const;
179
186 double noise(const int& channelID) const {
187 return noiseInjector_->Gaus(
188 0, getCondition(channelID, "NOISE") * gain(channelID));
189 };
190
192 double gain(const int& channelID) const {
193 return getCondition(channelID, "GAIN");
194 }
195
197 double pedestal(const int& id) const { return getCondition(id, "PEDESTAL"); }
198
200 double readoutThreshold(const int& id) const {
201 return getCondition(id, "READOUT_THRESHOLD");
202 }
203
204 private:
214 double getCondition(int id, const std::string& name) const {
215 // check if emulator has been passed a table of conditions
216 if (!chipConditions_) {
217 EXCEPTION_RAISE("HgcrocCond",
218 "HGC ROC Emulator was not given a conditions table.");
219 }
220
221 // cache column index for the input name
222 if (conditionNamesToIndex_.count(name) == 0)
224
225 // get condition
226 return chipConditions_->get(id, conditionNamesToIndex_.at(name));
227 }
228
229 private:
238 public:
246 CompositePulse(TF1& func, const double& g, const double& p)
247 : pulseFunc_{func}, gain_{g}, pedestal_{p} {}
248
259 void addOrMerge(const std::pair<double, double>& hit, double hit_merge_ns) {
260 auto imerge{hits_.begin()};
261 for (; imerge != hits_.end(); imerge++)
262 if (fabs(imerge->second - hit.second) < hit_merge_ns) break;
263 if (imerge == hits_.end()) { // didn't find a match, add to the list
264 hits_.push_back(hit);
265 } else { // merge hits, shifting time to average
266 imerge->second =
267 (imerge->second * imerge->first + hit.first * hit.second);
268 imerge->first += hit.first;
269 imerge->second /= imerge->first;
270 }
271 }
272
285 double findCrossing(double low, double high, double level,
286 double prec = 0.01) {
287 // use midpoint algorithm, assumes low is below and high is above
288 double step = high - low;
289 double pt = (high + low) / 2;
290 while (step > prec) {
291 double vmid = at(pt);
292 if (vmid < level) {
293 low = pt;
294 } else {
295 high = pt;
296 }
297 step = high - low;
298 pt = (high + low) / 2;
299 }
300 return pt;
301 }
302
304 void setGainPedestal(double gain, double pedestal) {
305 gain_ = gain;
307 }
308
315 double operator()(double time) const { return at(time); }
316
326 double at(double time) const {
327 double signal = gain_ * pedestal_;
328 for (auto hit : hits_)
329 signal += hit.first * pulseFunc_.Eval(time - hit.second);
330 return signal;
331 };
332
334 const std::vector<std::pair<double, double>>& hits() const { return hits_; }
335
336 private:
342 std::vector<std::pair<double, double>> hits_;
343
346
348 double gain_;
349
351 double pedestal_;
352
353 }; // CompositePulse
354
355 private:
356 /**************************************************************************************
357 * Parameters Identical for all Chips
358 *************************************************************************************/
359
361 bool noise_{true};
362
365
367 int iSOI_;
368
371
374
376 double ns_;
377
380
383
386
389
391 double timePeak_;
392
395
396 /**************************************************************************************
397 * Chip-Dependent Parameters (Conditions)
398 *************************************************************************************/
399
407
414 mutable std::map<std::string, int> conditionNamesToIndex_;
415
416 /**************************************************************************************
417 * Helpful Member Objects
418 *************************************************************************************/
419
421 std::unique_ptr<TRandom3> noiseInjector_;
422
443 mutable TF1 pulseFunc_;
444
446 enableLogging("HgcrocEmulator")
447}; // HgcrocEmulator
448
449} // namespace ldmx
450
451#endif // TOOLS_HGCROCEMULATOR_H
Base classes for all user event processing components to extend.
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:29
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].
HgcrocEmulator(const framework::config::Parameters &ps)
Constructor.
double ns_
Conversion from time [ns] to counts.