Belle II Software development
CDCCrossTalkLibrary Class Reference

Database object for ASIC crosstalk library. More...

#include <CDCCrossTalkLibrary.h>

Inheritance diagram for CDCCrossTalkLibrary:

Public Member Functions

 CDCCrossTalkLibrary ()=default
 Default constructor.
 
void addAsicRecord (const Short_t channel, const Short_t ADC, const asicChannels &asicInfo)
 Add a new ASIC record to the library.
 
const vector< pair< Short_t, asicChannel > > getLibraryCrossTalk (Short_t channel, Short_t TDCin, Short_t ADCin, Short_t TOTin, size_t entry=0, bool insertSignalToOutput=false) const
 Get cross talk record from the library.
 
void dump (int verbosity) const
 Print out contents of the library.
 
void dumpEntry (size_t entry)
 Dump single entry, for a given channel.
 
double pCrossTalk (const Short_t ADC) const
 Get probability of the cross talk.
 
void setPCrossTalk (const double *probs)
 Store x-talk probability.
 

Private Member Functions

 ClassDef (CDCCrossTalkLibrary, 2)
 ClassDef.
 

Private Attributes

std::vector< adcAsicTuplem_library
 Library.
 
array< float, 8196 > m_pCrossTalk
 x-talk probability
 

Detailed Description

Database object for ASIC crosstalk library.

Definition at line 31 of file CDCCrossTalkLibrary.h.

Member Function Documentation

◆ addAsicRecord()

void addAsicRecord ( const Short_t  channel,
const Short_t  ADC,
const asicChannels asicInfo 
)
inline

Add a new ASIC record to the library.

Parameters
channel– Channel number inside RO board (between 0 and 48)
ADC– ADC value
asicInfo– TDC,ADC,TOT information for all channels in ASIC, -1 if no hit.

Definition at line 45 of file CDCCrossTalkLibrary.h.

46 {
47 Short_t ch8 = channel % 8;
48 adcAsicTuple entry{ADC, ch8, asicInfo};
49 // keep sorted
50 auto place = upper_bound(m_library.begin(), m_library.end(), entry, adc_search());
51 m_library.insert(place, entry);
52 }
std::vector< adcAsicTuple > m_library
Library.

◆ dump()

void dump ( int  verbosity) const
inline

Print out contents of the library.

Definition at line 161 of file CDCCrossTalkLibrary.h.

162 {
163 std::cout << "Content of CDCCrossTalkLibrary" << std::endl;
164 std::cout << "Size = " << m_library.size() << "\n";
165 if (verbosity < 1) return;
166
167 for (size_t i = 0 ; i < m_library.size(); i += 1) {
168 auto [adc, ch, record] = m_library[i];
169 std::cout << "ADC: " << adc << " CH: " << ch << " count: " << i << "\n";
170 std::cout << " TDC ADC TOT \n";
171 for (auto rec : record) {
172 std::cout << " " << rec.TDC << " " << rec.ADC << " " << rec.TOT << "\n";
173 }
174 }
175 std::cout << "Probability of cross talk vs ADC: \n";
176 for (size_t a = 0; a < 8196; a++) {
177 std::cout << "P(" << a << ")=" << m_pCrossTalk[a] << "\n";
178 }
179 }
array< float, 8196 > m_pCrossTalk
x-talk probability

◆ dumpEntry()

void dumpEntry ( size_t  entry)
inline

Dump single entry, for a given channel.

Definition at line 182 of file CDCCrossTalkLibrary.h.

183 {
184
185 if (entry > m_library.size()) entry = m_library.size() - 1;
186 auto [adc, ch, record] = m_library[entry];
187 std::cout << "ADC:" << adc << " CH: " << ch << " Size: " << m_library.size() << "\n";
188 std::cout << " TDC ADC TOT \n";
189 for (auto rec : record) {
190 std::cout << " " << rec.TDC << " " << rec.ADC << " " << rec.TOT << "\n";
191 }
192
193 }

◆ getLibraryCrossTalk()

const vector< pair< Short_t, asicChannel > > getLibraryCrossTalk ( Short_t  channel,
Short_t  TDCin,
Short_t  ADCin,
Short_t  TOTin,
size_t  entry = 0,
bool  insertSignalToOutput = false 
) const
inline

Get cross talk record from the library.

Output is a vector of pairs: channel number (from 0 to 48) and corresponding TDC,ADC,TOT values. Depending on the value of insertSignalToOutput, the output may contain the input signal hit.

Parameters
channelreadout board channel number, from 0 to 48
TDCininput channel TDC value
ADCininput channel ADC value
TOTininput channel TOT value
entryfor multiple entries given (channel,ADC) value either return random (entry=0) or specific one (entry>0). If entry > max entries, entry % max entries is used
insertSignalToOutputAdd signal to the output vector

return signal-only, no x-talk

Determine Delta in TDC:

Definition at line 65 of file CDCCrossTalkLibrary.h.

67 {
68 // output
69 vector< pair<Short_t, asicChannel> > outRec;
70 auto prob = gRandom->Uniform();
71
72 if (prob > pCrossTalk(ADCin)) {
74 if (insertSignalToOutput)
75 outRec.emplace_back(std::make_pair(channel, asicChannel{TDCin, ADCin, TOTin}));
76 return outRec;
77 }
78
79 // find a range of possible candidates
80 Short_t ch8 = channel % 8;
81 adcChannelPair query{ADCin, ch8};
82 auto pADC = equal_range(m_library.begin(), m_library.end(), query, adc_search());
83
84 size_t size = std::distance(pADC.first, pADC.second);
85 size_t val = 0;
86
87
88 if (entry != 0) {
89 // select modulo
90 val = entry % size;
91 } else {
92 // select random
93 val = gRandom->Integer(size);
94 }
95
96 asicChannels rec;
97 bool recNotSet = true;
98 if (size == 0) {
99 if (pADC.first == m_library.end()) {
100 rec = m_library.back().record;
101 recNotSet = false;
102 } else {
103 if (pADC.first->Channel == ch8) {
104 rec = (pADC.first)->record;
105 recNotSet = false;
106 } else { // need to step back, if possible
107 if ((--pADC.first)->Channel == ch8) {
108 rec = (--pADC.first)->record;
109 recNotSet = false;
110 } else {
111 B2WARNING("Could not find CDC Cross talk library entry for channel, ADC: " << channel << " " << ADCin);
112 if (insertSignalToOutput)
113 outRec.emplace_back(std::make_pair(channel, asicChannel{TDCin, ADCin, TOTin}));
114 return outRec;
115 }
116 }
117 }
118 } else {
119 size_t count = 0;
120 for (auto p = pADC.first; p != pADC.second; ++p) {
121 if (count == val) {
122 rec = p->record;
123 recNotSet = false;
124 }
125 count += 1;
126 }
127 }
128
129 B2ASSERT("CDC cross talk record not set", !recNotSet);
130
132 Short_t DeltaTDC = TDCin - rec[ch8].TDC;
133
134 if (abs(DeltaTDC) > 1000) {
135 B2WARNING("Large xTalk DeltaTDC=" << DeltaTDC);
136 }
137
138 // std::cout << TDCin << " HHH " << rec[ch8].TDC << " " << ch8 << "\n";
139
140
141 for (int i = 0; i < 8; i += 1) {
142 if (rec[i].TDC > 0) {
143 if (i == ch8) { // store input values
144 B2ASSERT("CDC Cross talk entry for the selected channel cannot be empty " << ch8 << " " << rec[ch8].TDC, rec[ch8].TDC > -1);
145 if (insertSignalToOutput)
146 outRec.emplace_back(std::make_pair(channel, asicChannel{TDCin, ADCin, TOTin}));
147 } else { // adjust TDC for the cross talk, keep ADC and TOT
148 Short_t TDCout = rec[i].TDC + DeltaTDC;
149 outRec.emplace_back(std::make_pair(i - ch8 + channel, asicChannel{TDCout, rec[i].ADC, rec[i].TOT}));
150 }
151 }
152 }
153 return outRec;
154 }
double pCrossTalk(const Short_t ADC) const
Get probability of the cross talk.
array< asicChannel, 8 > asicChannels
fixed sized array of ASIC channels

◆ pCrossTalk()

double pCrossTalk ( const Short_t  ADC) const
inline

Get probability of the cross talk.

Definition at line 198 of file CDCCrossTalkLibrary.h.

199 {
200 if (ADC < 0) return 0;
201 if (ADC >= 8196) return 1;
202 return m_pCrossTalk[ADC];
203 }

◆ setPCrossTalk()

void setPCrossTalk ( const double *  probs)
inline

Store x-talk probability.

Definition at line 206 of file CDCCrossTalkLibrary.h.

207 {
208 for (size_t i = 0; i < m_pCrossTalk.size(); i += 1) {
209 m_pCrossTalk[i] = probs[i];
210 }
211 }

Member Data Documentation

◆ m_library

std::vector<adcAsicTuple> m_library
private

Library.

Definition at line 214 of file CDCCrossTalkLibrary.h.

◆ m_pCrossTalk

array<float, 8196> m_pCrossTalk
private

x-talk probability

Definition at line 215 of file CDCCrossTalkLibrary.h.


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