15#include <cdc/dbobjects/CDCCrossTalkClasses.h>
18using std::upper_bound;
19using std::equal_range;
47 Short_t ch8 = channel % 8;
65 const vector< pair<Short_t, asicChannel> >
getLibraryCrossTalk(Short_t channel, Short_t TDCin, Short_t ADCin, Short_t TOTin,
66 size_t entry = 0,
bool insertSignalToOutput =
false)
const
69 vector< pair<Short_t, asicChannel> > outRec;
70 auto prob = gRandom->Uniform();
74 if (insertSignalToOutput)
75 outRec.emplace_back(std::make_pair(channel,
asicChannel{TDCin, ADCin, TOTin}));
80 Short_t ch8 = channel % 8;
84 size_t size = std::distance(pADC.first, pADC.second);
93 val = gRandom->Integer(size);
97 bool recNotSet =
true;
103 if (pADC.first->Channel == ch8) {
104 rec = (pADC.first)->record;
107 if ((--pADC.first)->Channel == ch8) {
108 rec = (--pADC.first)->record;
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}));
120 for (
auto p = pADC.first; p != pADC.second; ++p) {
129 B2ASSERT(
"CDC cross talk record not set", !recNotSet);
132 Short_t DeltaTDC = TDCin - rec[ch8].TDC;
134 if (abs(DeltaTDC) > 1000) {
135 B2WARNING(
"Large xTalk DeltaTDC=" << DeltaTDC);
141 for (
int i = 0; i < 8; i += 1) {
142 if (rec[i].TDC > 0) {
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}));
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}));
163 std::cout <<
"Content of CDCCrossTalkLibrary" << std::endl;
164 std::cout <<
"Size = " <<
m_library.size() <<
"\n";
165 if (verbosity < 1)
return;
167 for (
size_t i = 0 ; i <
m_library.size(); i += 1) {
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";
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";
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";
200 if (ADC < 0)
return 0;
201 if (ADC >= 8196)
return 1;
Database object for ASIC crosstalk library.
void dumpEntry(size_t entry)
Dump single entry, for a given channel.
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.
ClassDef(CDCCrossTalkLibrary, 2)
ClassDef.
void setPCrossTalk(const double *probs)
Store x-talk probability.
void dump(int verbosity) const
Print out contents of the library.
CDCCrossTalkLibrary()=default
Default constructor.
array< float, 8196 > m_pCrossTalk
x-talk probability
double pCrossTalk(const Short_t ADC) const
Get probability of the cross talk.
void addAsicRecord(const Short_t channel, const Short_t ADC, const asicChannels &asicInfo)
Add a new ASIC record to the library.
std::vector< adcAsicTuple > m_library
Library.
array< asicChannel, 8 > asicChannels
fixed sized array of ASIC channels
Abstract base class for different kinds of events.
tuple to store ADC,Channel -> 8 asicChannels
functions to search in the sorted list of tuples
record to be used to store ASIC info