LDMX Software
Public Member Functions | Private Attributes | List of all members
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 > Out_ADC (QIEInputPulse *pp)
 Complete set of ADCs for the pulse.
 
std::vector< int > Out_TDC (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 17 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 11 of file SimQIE.cxx.

11{}

◆ 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 13 of file SimQIE.cxx.

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

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 52 of file SimQIE.cxx.

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

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 124 of file SimQIE.cxx.

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

References maxts_.

◆ Out_ADC()

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

Complete set of ADCs for the pulse.

Parameters
pp= pointer to pulse instance

Definition at line 88 of file SimQIE.cxx.

88 {
89 std::vector<int> OP;
90
91 for (int i = 0; i < maxts_; i++) {
92 float QQ = pp->Integrate(i * tau_, i * tau_ + tau_);
93 OP.push_back(Q2ADC(QQ));
94 }
95 return OP;
96}
float tau_
time period of one time sample [in ns]
Definition SimQIE.h:126
int Q2ADC(float Charge)
Digitizing input charge.
Definition SimQIE.cxx:29

References trigscint::QIEInputPulse::Integrate(), maxts_, Q2ADC(), and tau_.

◆ Out_TDC()

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

Complete set of TDCs for the pulse.

Parameters
pp= pointer to pulse instance

Definition at line 113 of file SimQIE.cxx.

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

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 134 of file SimQIE.cxx.

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

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 29 of file SimQIE.cxx.

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

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

Referenced by Out_ADC().

◆ QErr()

float trigscint::SimQIE::QErr ( float  Q)

Quantization error.

Definition at line 71 of file SimQIE.cxx.

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

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 53 of file SimQIE.h.

53{ 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 46 of file SimQIE.h.

46{ 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 60 of file SimQIE.h.

60{ 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 38 of file SimQIE.h.

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

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 100 of file SimQIE.cxx.

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

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

Referenced by Out_TDC().

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 116 of file SimQIE.h.

116 {-16, 34, 158, 419, 517, 915,
117 1910, 3990, 4780, 7960, 15900, 32600,
118 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 124 of file SimQIE.h.

124{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 142 of file SimQIE.h.

142{false};

Referenced by Q2ADC(), and SimQIE().

◆ maxts_

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

No. of time samples to analyze.

Definition at line 128 of file SimQIE.h.

128{0};

Referenced by CapID(), Out_ADC(), Out_TDC(), PulseCut(), and setNTimeSamples().

◆ mu_

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

mean of gaussian noise (Pedestal)

Definition at line 138 of file SimQIE.h.

138{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 114 of file SimQIE.h.

114{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 134 of file SimQIE.h.

134{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 120 of file SimQIE.h.

120 {3.1, 6.2, 12.4, 24.8, 24.8, 49.6, 99.2, 198.4,
121 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 140 of file SimQIE.h.

140{0};

Referenced by Q2ADC(), and SimQIE().

◆ tau_

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

time period of one time sample [in ns]

Definition at line 126 of file SimQIE.h.

126{25};

Referenced by Out_ADC(), Out_TDC(), PulseCut(), setFreq(), and TDC().

◆ tdc_thr_

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

TDC threshold (default 3.74 microAmpere)

Definition at line 131 of file SimQIE.h.

131{3.74};

Referenced by setTDCThreshold(), and TDC().

◆ trg_

TRandom3* trigscint::SimQIE::trg_
private

Definition at line 135 of file SimQIE.h.


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