LDMX Software
trigscint::SimQIE Class Reference

class for simulating QIE chip output More...

#include <SimQIE.h>

Public Member Functions

 SimQIE ()
 Defaut constructor.
 
 SimQIE (float pd, float sg, uint64_t seed)
 Main constructor.
 
void setTDCThreshold (const float thr)
 Set current threshold for TDC latch.
 
void setGain (const float gg=1e+6)
 Set gain of SiPM.
 
void setFreq (const float sf=40)
 Set sampling frequency of QIE.
 
void setNTimeSamples (const int maxts=5)
 Set the number of time samples to analyze.
 
float qErr (float Q)
 Quantization error.
 
int q2Adc (float Charge)
 Digitizing input charge.
 
float adc2Q (int ADC)
 Converting ADC back to charge.
 
int tdc (QIEInputPulse *pp, float T0)
 TDC of the input pulse.
 
std::vector< int > outAdc (QIEInputPulse *pp)
 Complete set of ADCs for the pulse.
 
std::vector< int > outTdc (QIEInputPulse *pp)
 Complete set of TDCs for the pulse.
 
std::vector< int > capId (QIEInputPulse *pp)
 Complete set of Capacitor IDs for the pulse.
 
bool pulseCut (QIEInputPulse *pulse, float cut)
 Method to check if the pulse is good to be stored.
 

Private Attributes

int nbins_ [5] = {0, 16, 36, 57, 64}
 Indices of first bin of each subrange.
 
float edges_ [17]
 Charge lower limit of all the 16 subranges.
 
float sense_ [16]
 sensitivity of the subranges (Total charge/no. of bins)
 
float gain_ {1}
 QIE gain -> to convert from no. of e- to charge in fC.
 
float tau_ {25}
 time period of one time sample [in ns]
 
int maxts_ {0}
 No. of time samples to analyze.
 
float tdc_thr_ {3.74}
 TDC threshold (default 3.74 microAmpere)
 
std::unique_ptr< TRandom3 > rand_ptr_ {nullptr}
 Random number generator (required for noise simulation)
 
TRandom3 * trg_
 
float mu_ {0}
 mean of gaussian noise (Pedestal)
 
float sg_ {0}
 std. dev. of gaussian noise (Actual noise level)
 
bool isnoise_ {false}
 Whether noise is added to the system.
 

Detailed Description

class for simulating QIE chip output

Note
This should be initialized only once per simulation

Definition at line 14 of file SimQIE.h.

Constructor & Destructor Documentation

◆ SimQIE() [1/2]

trigscint::SimQIE::SimQIE ( )

Defaut constructor.

Note
if used, noise & pedestal are not simulated

Definition at line 9 of file SimQIE.cxx.

9{}

◆ SimQIE() [2/2]

trigscint::SimQIE::SimQIE ( float pd,
float sg,
uint64_t seed = 0 )

Main constructor.

Parameters
pdpedestal value
sgnoise value
seedrandom seed for noise generation

Definition at line 11 of file SimQIE.cxx.

11 {
12 isnoise_ = true;
13 if (seed == 0) {
14 EXCEPTION_RAISE("RandomSeedException",
15 "QIE Noise generator not seeded (seed=0)");
16 } else {
17 rand_ptr_ = std::make_unique<TRandom3>(seed);
18 trg_ = rand_ptr_.get();
19 }
20 mu_ = PD;
21 sg_ = SG;
22}
float sg_
std. dev. of gaussian noise (Actual noise level)
Definition SimQIE.h:137
float mu_
mean of gaussian noise (Pedestal)
Definition SimQIE.h:135
bool isnoise_
Whether noise is added to the system.
Definition SimQIE.h:139
std::unique_ptr< TRandom3 > rand_ptr_
Random number generator (required for noise simulation)
Definition SimQIE.h:131

References isnoise_, mu_, rand_ptr_, and sg_.

Member Function Documentation

◆ adc2Q()

float trigscint::SimQIE::adc2Q ( int ADC)

Converting ADC back to charge.

Parameters
ADC= ADC count

Definition at line 50 of file SimQIE.cxx.

50 {
51 if (ADC <= 0) return -16;
52 if (ADC >= 255) return 350000;
53
54 int rr = ADC / 64; // range
55 int v1 = ADC % 64; // temp. var
56 int ss = 0; // sub range
57
58 for (int i = 1; i < 4; i++) { // to get the subrange
59 if (v1 > nbins_[i]) ss++;
60 }
61 // cc is unused, should it be? FIXME
62 // int cc = 64 * rr + nbins_[ss];
63 float temp = edges_[4 * rr + ss] + (v1 - nbins_[ss]) * sense_[4 * rr + ss] +
64 sense_[4 * rr + ss] / 2;
65 return (temp / gain_);
66}
float edges_[17]
Charge lower limit of all the 16 subranges.
Definition SimQIE.h:113
int nbins_[5]
Indices of first bin of each subrange.
Definition SimQIE.h:111
float sense_[16]
sensitivity of the subranges (Total charge/no. of bins)
Definition SimQIE.h:117
float gain_
QIE gain -> to convert from no. of e- to charge in fC.
Definition SimQIE.h:121

References edges_, gain_, nbins_, and sense_.

Referenced by trigscint::EventReadoutProducer::produce(), and trigscint::TrigScintRecHitProducer::produce().

◆ capId()

std::vector< int > trigscint::SimQIE::capId ( QIEInputPulse * pp)

Complete set of Capacitor IDs for the pulse.

Parameters
pp= pointer to pulse instance

Definition at line 122 of file SimQIE.cxx.

122 {
123 std::vector<int> op;
124
125 op.push_back(trg_->Integer(4));
126 for (int i = 0; i < maxts_; i++) {
127 op.push_back((op[i] + 1) % 4);
128 }
129 return op;
130}
int maxts_
No. of time samples to analyze.
Definition SimQIE.h:125

References maxts_.

◆ outAdc()

std::vector< int > trigscint::SimQIE::outAdc ( QIEInputPulse * pp)

Complete set of ADCs for the pulse.

Parameters
pp= pointer to pulse instance

Definition at line 86 of file SimQIE.cxx.

86 {
87 std::vector<int> op;
88
89 for (int i = 0; i < maxts_; i++) {
90 float qq = pp->integrate(i * tau_, i * tau_ + tau_);
91 op.push_back(q2Adc(qq));
92 }
93 return op;
94}
float tau_
time period of one time sample [in ns]
Definition SimQIE.h:123
int q2Adc(float Charge)
Digitizing input charge.
Definition SimQIE.cxx:27

References trigscint::QIEInputPulse::integrate(), maxts_, q2Adc(), and tau_.

◆ outTdc()

std::vector< int > trigscint::SimQIE::outTdc ( QIEInputPulse * pp)

Complete set of TDCs for the pulse.

Parameters
pp= pointer to pulse instance

Definition at line 111 of file SimQIE.cxx.

111 {
112 std::vector<int> op;
113
114 for (int i = 0; i < maxts_; i++) {
115 op.push_back(tdc(pp, tau_ * i));
116 }
117 return op;
118}
int tdc(QIEInputPulse *pp, float T0)
TDC of the input pulse.
Definition SimQIE.cxx:98

References maxts_, tau_, and tdc().

◆ pulseCut()

bool trigscint::SimQIE::pulseCut ( QIEInputPulse * pulse,
float cut )

Method to check if the pulse is good to be stored.

Parameters
pulsepointer to the pulse we want to analyze
Note
ideally, checks if the amplitude is above some threshold.

Definition at line 132 of file SimQIE.cxx.

132 {
133 if (pulse->getNPulses() == 0) return false;
134
135 // float thr_in_pes = 1.0; instead make configurable
136
137 // Only keep the pulse if it produces 1 PE (or whatever the cutoff is set to)
138 // integrate over entire pulse so we catch also single-PE pulses
139 float integral = 0;
140 for (int i = 0; i < maxts_; i++) {
141 // if (pulse->integrate(i * tau_, i * tau_ + tau_) >= thr_in_pes) return
142 // true;
143 integral += pulse->integrate(i * tau_, i * tau_ + tau_);
144 }
145 if (integral >= cut) return true;
146
147 return false;
148}

References trigscint::QIEInputPulse::getNPulses(), trigscint::QIEInputPulse::integrate(), maxts_, and tau_.

◆ q2Adc()

int trigscint::SimQIE::q2Adc ( float Charge)

Digitizing input charge.

Parameters
Charge= The charge to be digitized
Note
default charge unit = femto C = 1e-15 C

Definition at line 27 of file SimQIE.cxx.

27 {
28 float qq = gain_ * charge; // including QIE gain
29 if (isnoise_) qq += trg_->Gaus(mu_, sg_); // Adding gaussian random noise.
30
31 if (qq <= edges_[0]) return 0;
32 if (qq >= edges_[16]) return 255;
33
34 int a = 0;
35 int b = 16;
36
37 // Binary search to find the subrange
38 while (b - a != 1) {
39 if (qq > edges_[(a + b) / 2]) {
40 a = (a + b) / 2;
41 } else
42 b = (a + b) / 2;
43 }
44 return 64 * (a / 4) + nbins_[a % 4] + floor((qq - edges_[a]) / sense_[a]);
45}

References edges_, gain_, isnoise_, mu_, nbins_, sense_, and sg_.

Referenced by outAdc().

◆ qErr()

float trigscint::SimQIE::qErr ( float Q)

Quantization error.

Definition at line 69 of file SimQIE.cxx.

69 {
70 if (Q <= edges_[0]) return 0;
71 if (Q >= edges_[16]) return 0;
72
73 int a = 0;
74 int b = 16;
75 while (b - a != 1) {
76 if (Q > edges_[(a + b) / 2])
77 a = (a + b) / 2;
78 else
79 b = (a + b) / 2;
80 }
81 return (sense_[a] / (sqrt(12) * Q));
82}

References edges_, and sense_.

Referenced by trigscint::EventReadoutProducer::produce().

◆ setFreq()

void trigscint::SimQIE::setFreq ( const float sf = 40)
inline

Set sampling frequency of QIE.

Parameters
sf= sampling frequency in MHz

Definition at line 50 of file SimQIE.h.

50{ tau_ = 1000 / sf; }

References tau_.

◆ setGain()

void trigscint::SimQIE::setGain ( const float gg = 1e+6)
inline

Set gain of SiPM.

Parameters
gg= gain
Note
The multiplicated factor 16e-5 is used to convert from 1.6e-19 to fC

Definition at line 43 of file SimQIE.h.

43{ gain_ = gg * 16e-5; }

References gain_.

◆ setNTimeSamples()

void trigscint::SimQIE::setNTimeSamples ( const int maxts = 5)
inline

Set the number of time samples to analyze.

Parameters
maxtsNo. of time samples to analyze

Definition at line 57 of file SimQIE.h.

57{ maxts_ = maxts; }

References maxts_.

◆ setTDCThreshold()

void trigscint::SimQIE::setTDCThreshold ( const float thr)
inline

Set current threshold for TDC latch.

Parameters
gg= gain

Definition at line 35 of file SimQIE.h.

35{ tdc_thr_ = thr; }
float tdc_thr_
TDC threshold (default 3.74 microAmpere)
Definition SimQIE.h:128

References tdc_thr_.

◆ tdc()

int trigscint::SimQIE::tdc ( QIEInputPulse * pp,
float T0 = 0 )

TDC of the input pulse.

Parameters
pp= pointer to a pulse instance
T0= starting time of the pulse

Definition at line 98 of file SimQIE.cxx.

98 {
99 float thr2 = tdc_thr_ / gain_;
100 if (pp->eval(T0) > thr2) return 62; // when pulse starts high
101 float tt = T0;
102 while (tt < T0 + tau_) {
103 if (pp->eval(tt) >= thr2) return ((int)(2 * (tt - T0)));
104 tt += 0.1;
105 }
106 return 63; // when pulse remains low all along
107}

References trigscint::QIEInputPulse::eval(), gain_, tau_, and tdc_thr_.

Referenced by outTdc().

Member Data Documentation

◆ edges_

float trigscint::SimQIE::edges_[17]
private
Initial value:
= {-16, 34, 158, 419, 517, 915,
1910, 3990, 4780, 7960, 15900, 32600,
38900, 64300, 128000, 261000, 350000}

Charge lower limit of all the 16 subranges.

Definition at line 113 of file SimQIE.h.

113 {-16, 34, 158, 419, 517, 915,
114 1910, 3990, 4780, 7960, 15900, 32600,
115 38900, 64300, 128000, 261000, 350000};

Referenced by adc2Q(), q2Adc(), and qErr().

◆ gain_

float trigscint::SimQIE::gain_ {1}
private

QIE gain -> to convert from no. of e- to charge in fC.

Definition at line 121 of file SimQIE.h.

121{1};

Referenced by adc2Q(), q2Adc(), setGain(), and tdc().

◆ isnoise_

bool trigscint::SimQIE::isnoise_ {false}
private

Whether noise is added to the system.

Definition at line 139 of file SimQIE.h.

139{false};

Referenced by q2Adc(), and SimQIE().

◆ maxts_

int trigscint::SimQIE::maxts_ {0}
private

No. of time samples to analyze.

Definition at line 125 of file SimQIE.h.

125{0};

Referenced by capId(), outAdc(), outTdc(), pulseCut(), and setNTimeSamples().

◆ mu_

float trigscint::SimQIE::mu_ {0}
private

mean of gaussian noise (Pedestal)

Definition at line 135 of file SimQIE.h.

135{0};

Referenced by q2Adc(), and SimQIE().

◆ nbins_

int trigscint::SimQIE::nbins_[5] = {0, 16, 36, 57, 64}
private

Indices of first bin of each subrange.

Definition at line 111 of file SimQIE.h.

111{0, 16, 36, 57, 64};

Referenced by adc2Q(), and q2Adc().

◆ rand_ptr_

std::unique_ptr<TRandom3> trigscint::SimQIE::rand_ptr_ {nullptr}
private

Random number generator (required for noise simulation)

Definition at line 131 of file SimQIE.h.

131{nullptr};

Referenced by SimQIE().

◆ sense_

float trigscint::SimQIE::sense_[16]
private
Initial value:
= {3.1, 6.2, 12.4, 24.8, 24.8, 49.6, 99.2, 198.4,
198.4, 396.8, 793.6, 1587, 1587, 3174, 6349, 12700}

sensitivity of the subranges (Total charge/no. of bins)

Definition at line 117 of file SimQIE.h.

117 {3.1, 6.2, 12.4, 24.8, 24.8, 49.6, 99.2, 198.4,
118 198.4, 396.8, 793.6, 1587, 1587, 3174, 6349, 12700};

Referenced by adc2Q(), q2Adc(), and qErr().

◆ sg_

float trigscint::SimQIE::sg_ {0}
private

std. dev. of gaussian noise (Actual noise level)

Definition at line 137 of file SimQIE.h.

137{0};

Referenced by q2Adc(), and SimQIE().

◆ tau_

float trigscint::SimQIE::tau_ {25}
private

time period of one time sample [in ns]

Definition at line 123 of file SimQIE.h.

123{25};

Referenced by outAdc(), outTdc(), pulseCut(), setFreq(), and tdc().

◆ tdc_thr_

float trigscint::SimQIE::tdc_thr_ {3.74}
private

TDC threshold (default 3.74 microAmpere)

Definition at line 128 of file SimQIE.h.

128{3.74};

Referenced by setTDCThreshold(), and tdc().

◆ trg_

TRandom3* trigscint::SimQIE::trg_
private

Definition at line 132 of file SimQIE.h.


The documentation for this class was generated from the following files: