29 fSum.reserve(1024*1440);
30 fSum2.reserve(1024*1440);
43 void InitSize(uint16_t channels, uint16_t samples)
45 fNumChannels = channels;
46 fNumSamples = samples;
48 fSum.assign(samples*channels, 0);
49 fSum2.assign(samples*channels, 0);
80 const int16_t &spos = start[ch];
84 const size_t pos = ch*1024;
86 const int16_t *beg_val = val + pos;
87 int64_t *beg_sum = fSum.data() + pos;
88 int64_t *beg_sum2 = fSum2.data() + pos;
90 const int16_t *pval = beg_val;
91 int64_t *psum = beg_sum + spos;
92 int64_t *psum2 = beg_sum2 + spos;
94 while (psum<beg_sum+1024)
96 const int64_t v = *pval++;
105 while (pval<beg_val+1024)
107 const int64_t v = *pval++;
118 const int32_t *offset,
const int64_t scale)
148 const int16_t &spos = start[ch];
152 const size_t pos = ch*1024;
154 const int16_t *beg_val = val + pos;
155 const int32_t *beg_offset = offset + pos;
156 int64_t *beg_sum = fSum.data() + pos;
157 int64_t *beg_sum2 = fSum2.data() + pos;
160 const int16_t *pval = beg_val;
161 const int32_t *poffset = beg_offset + spos;
162 int64_t *psum = beg_sum + spos;
163 int64_t *psum2 = beg_sum2 + spos;
165 while (psum<beg_sum+1024)
167 const int64_t v = int64_t(*pval++)*scale - *poffset++;
175 poffset = beg_offset;
177 while (pval<beg_val+1024)
179 const int64_t v = int64_t(*pval++)*scale - *poffset++;
219 const int32_t *offset,
const int64_t scale)
251 const int16_t &spos = start[ch];
257 const int32_t *beg_offset = offset + ch*1024;
258 const int16_t *beg_val = val + pos;
259 int64_t *beg_sum = fSum.data() + pos;
260 int64_t *beg_sum2 = fSum2.data() + pos;
263 const int16_t *pval = beg_val;
264 const int32_t *poffset = beg_offset + spos;
265 int64_t *psum = beg_sum;
266 int64_t *psum2 = beg_sum2;
268 if (spos+fNumSamples>1024)
270 while (poffset<beg_offset+1024)
272 const int64_t v = int64_t(*pval++)*scale - *poffset++;
278 poffset = beg_offset;
281 while (psum<beg_sum+fNumSamples)
283 const int64_t v = int64_t(*pval++)*scale - *poffset++;
294 static void ApplyCh(
float *vec,
const int16_t *val, int16_t
start, uint32_t roi,
295 const int32_t *offset,
const int64_t scaleabs,
296 const int64_t *gain,
const int64_t scalegain)
323 const int32_t *poffset = offset +
start;
324 const int64_t *pgain = gain +
start;
325 const int16_t *pval = val;
330 while (poffset<offset+1024)
333 + int64_t(*pval++)*scaleabs - *poffset++
336 *pvec++ = *pgain==0 ? 0 : double(v)*scalegain / *pgain;
348 + int64_t(*pval++)*scaleabs - *poffset++
351 *pvec++ = *pgain==0 ? 0 : double(v)*scalegain / *pgain;
357 static void ApplyCh(
float *vec,
const int16_t *val, int16_t
start, uint32_t roi,
358 const int32_t *offset,
const int64_t scaleabs,
359 const int64_t *gain,
const int64_t scalegain,
360 const int64_t *trgoff,
const int64_t scalerel)
385 const int32_t *poffset = offset +
start;
386 const int64_t *pgain = gain +
start;
387 const int16_t *pval = val;
388 const int64_t *ptrgoff = trgoff;
393 while (poffset<offset+1024)
396 + (int64_t(*pval++)*scaleabs - *poffset++)*scalerel
400 const int64_t div = *pgain * scalerel;
401 *pvec++ = div==0 ? 0 : double(v)*scalegain / div;
413 + (int64_t(*pval++)*scaleabs - *poffset++)*scalerel
417 const int64_t div = *pgain * scalerel;
418 *pvec++ = div==0 ? 0 : double(v)*scalegain / div;
424 static double FindStep(
const size_t ch0,
const float *vec, int16_t roi,
const int16_t pos,
const uint16_t *map=NULL)
430 if (pos==0 || pos>=roi)
438 for (
int p=0; p<8; p++)
440 const size_t hw = ch0+p;
441 const size_t sw = (map?map[hw]:hw)*roi + pos;
443 const double diff = vec[sw]-vec[sw-1];
446 rms += (vec[sw]-vec[sw-1])*(vec[sw]-vec[sw-1]);
451 return cnt==0 ? 0 : step/cnt;
454 static void SubtractStep(
const size_t ch0,
const double avg,
float *vec, int16_t roi, int32_t pos,
const uint16_t *map=NULL)
456 if (pos==0 || pos>=roi)
459 const int begin = avg>0 ? pos : 0;
460 const int end = avg>0 ? roi : pos;
462 const double sub = fabs(avg);
464 for (
int p=0; p<9; p++)
466 for (
int j=begin; j<
end; j++)
468 const size_t hw = ch0+p;
469 const size_t sw = (map?map[hw]:hw)*roi + j;
490 for (
auto it=beg; it!=
end; it++)
494 rc.
rms += it->avg*it->avg;
510 const int16_t *prev,
const int16_t *
start,
511 const int16_t offset,
const uint16_t *map=NULL)
514 std::vector<Step> list;
520 for (
size_t ch=0; ch<nch; ch += 9)
522 if (prev[ch]<0 || start[ch]<0)
525 const int16_t dist = (prev[ch]-start[ch]+1024+offset)%1024;
526 const double step =
FindStep(ch, vec, roi, dist, map);
552 const size_t skip = list.size()/10;
553 rc =
AverageSteps(list.begin()+skip, list.begin()+list.size()-skip);
558 for (
size_t ch=0; ch<nch; ch += 9)
560 const int16_t dist = (prev[ch]-start[ch]+1024+offset)%1024;
572 for (
size_t i=1;
i<roi-2;
i++)
574 if (p[
i]-p[
i-1]>25 && p[
i]-p[
i+1]>25)
576 p[
i] = (p[
i-1]+p[
i+1])/2;
579 if (p[
i]-p[
i-1]>22 && fabs(p[
i]-p[
i+1])<4 && p[
i+1]-p[
i+2]>22)
581 p[
i] = (p[
i-1]+p[
i+2])/2;
592 std::vector<float> Ameas(p, p+roi);
594 std::vector<float> diff(roi);
595 for (
size_t i=1;
i<roi-1;
i++)
596 diff[
i] = (p[
i-1] + p[
i+1])/2 - p[
i];
602 const float fract = 0.8;
604 for (
size_t i=0;
i<roi-3;
i++)
609 if (Ameas[
i+2] - (Ameas[
i] + Ameas[
i+3])/2 > 10)
611 p[
i+1]= (Ameas[
i+3] - Ameas[
i])/3 + Ameas[
i];
612 p[
i+2]= 2*(Ameas[
i+3] - Ameas[
i])/3 + Ameas[
i];
619 if ( (diff[
i+1]<-diff[
i]*fract*2) && (diff[
i+2]>10) )
621 p[
i+1] = (Ameas[
i]+Ameas[
i+2])/2;
622 diff[
i+2] = (p[
i+1] + Ameas[
i+3])/2 - Ameas[
i+2];
657 const float SingleCandidateTHR = -10.;
658 const float DoubleCandidateTHR = -5.;
660 const std::vector<float> src(vec, vec+roi);
662 std::vector<float> diff(roi);
663 for (
size_t i=1;
i<roi-1;
i++)
664 diff[
i] = src[
i] - (src[
i-1] + src[
i+1])/2;
667 for (
unsigned int i=1;
i<roi-3;
i++)
670 if (diff[
i]>=DoubleCandidateTHR)
676 if (diff[
i]<SingleCandidateTHR)
679 if (diff[
i+1] > -1.6*diff[
i])
681 vec[i+1] = (src[
i] + src[i+2]) / 2;
702 if ((diff[
i+1] > -DoubleCandidateTHR) &&
703 (diff[
i+2] > -DoubleCandidateTHR))
705 vec[
i+1] = (src[
i+3] - src[
i])/3 + src[
i];
706 vec[
i+2] = 2*(src[
i+3] - src[
i])/3 + src[
i];
723 for (uint32_t
i=0;
i<roi-6;
i++)
725 double d10, d21, d32, d43, d54;
728 d43 = ptr[
i+4]-ptr[
i+3];
729 d54 = ptr[
i+5]-ptr[
i+4];
731 if ((d43>35 && -d54>35) || (d43<-35 && -d54<-35))
733 ptr[
i+4] = (ptr[
i+3]+ptr[
i+5])/2;
737 d32 = ptr[
i+3]-ptr[
i+2];
738 d54 = ptr[
i+5]-ptr[
i+4];
740 if ((d32>9 && -d54>13 && d32-d54>31))
742 double avg0 = (ptr[
i+2]+ptr[
i+5])/2;
743 double avg1 = (ptr[
i+3]+ptr[
i+4])/2;
745 ptr[
i+3] = ptr[
i+3] - avg1+avg0;
746 ptr[
i+4] = ptr[
i+4] - avg1+avg0;
750 d21 = ptr[
i+2]-ptr[
i+1];
751 d54 = ptr[
i+5]-ptr[
i+4];
753 if (d21>15 && -d54>17)
755 double avg0 = (ptr[
i+1]+ptr[
i+5])/2;
756 double avg1 = (ptr[
i+2]+ptr[
i+3]+ptr[
i+4])/3;
758 ptr[
i+2] = ptr[
i+2] - avg1+avg0;
759 ptr[
i+3] = ptr[
i+3] - avg1+avg0;
760 ptr[
i+4] = ptr[
i+4] - avg1+avg0;
764 d10 = ptr[
i+1]-ptr[
i];
765 d54 = ptr[
i+5]-ptr[
i+4];
767 if (d10>18 && -d54>20)
769 double avg0 = (ptr[
i]+ptr[
i+5])/2;
770 double avg1 = (ptr[
i+1]+ptr[
i+2]+ptr[
i+3]+ptr[
i+4])/4;
772 ptr[
i+1] = ptr[
i+1] - avg1+avg0;
773 ptr[
i+2] = ptr[
i+2] - avg1+avg0;
774 ptr[
i+3] = ptr[
i+3] - avg1+avg0;
775 ptr[
i+4] = ptr[
i+4] - avg1+avg0;
780 static void SlidingAverage(
float *
const vec,
const uint32_t roi,
const uint16_t w)
785 for (
float *pix=vec; pix<vec+1440*roi; pix += roi)
787 for (
float *ptr=pix; ptr<pix+roi-w; ptr++)
789 for (
float *p=ptr+1; p<ptr+w; p++)
799 return make_pair(std::vector<double>(),std::vector<double>());
801 std::vector<double> mean(fSum.size());
802 std::vector<double> error(fSum.size());
804 std::vector<int64_t>::const_iterator it = fSum.begin();
805 std::vector<int64_t>::const_iterator i2 = fSum2.begin();
806 std::vector<double>::iterator im = mean.begin();
807 std::vector<double>::iterator ie = error.begin();
809 while (it!=fSum.end())
812 *ie = sqrt(
double(*i2*int64_t(fNumEntries) - *it * *it))/
fNumEntries;
828 return make_pair(mean, error);
837 memset(ptr, 0,
sizeof(
float)*sz*2);
841 std::vector<int64_t>::const_iterator it = fSum.begin();
842 std::vector<int64_t>::const_iterator i2 = fSum2.begin();
844 while (it!=fSum.end())
847 *(ptr+sz) = scale*sqrt(
double(*i2*fNumEntries - *it * *it))/fNumEntries;
855 static double GetPixelStats(
float *ptr,
const float *
data, uint16_t roi, uint16_t begskip=0, uint16_t endskip=0)
861 const uint beg = roi>begskip ? begskip : 0;
862 const uint
end = roi-beg>endskip ? roi-endskip : roi;
863 const uint len = end-beg;
867 for (uint
i=0;
i<1440;
i++)
869 const float *vec = data+
i*roi;
872 double sum = vec[beg];
873 double sum2 = vec[beg]*vec[beg];
875 for (uint j=beg+1; j<
end; j++)
878 sum2 += vec[j]*vec[j];
896 *(ptr+0*1440+
i) = sum;
897 *(ptr+1*1440+
i) = sum2<0 ? 0 : sqrt(sum2);
898 *(ptr+2*1440+
i) = vec[pos];
899 *(ptr+3*1440+
i) = pos;
907 if (roi==0 || first<0 || last<0 || first>=roi || last>=roi || last<first)
910 for (
int i=0;
i<1440;
i++)
912 const float *beg = data+
i*roi+
first;
913 const float *
end = data+
i*roi+last;
915 const float *pmax = beg;
917 for (
const float *ptr=beg+1; ptr<=
end; ptr++)
938 std::vector<std::pair<double, double>>
fStat;
953 double Sum(uint32_t
i)
const {
return fStat[
i].first; }
954 double W(uint32_t
i)
const {
return fStat[
i].second; }
956 virtual void InitSize(uint16_t channels, uint16_t samples)
958 fNumChannels = channels;
959 fNumSamples = samples;
965 fStat.resize(samples*channels);
970 for (
auto it=fStat.begin(); it!=fStat.end(); it++)
979 if (fNumSamples!=1024 || fNumChannels!=160)
985 for (
size_t ch=0; ch<160; ch++)
987 const size_t tm = ch*9+8;
989 const int16_t spos = start[tm];
993 const size_t pos = ch*1024;
998 for (
size_t i=0;
i<1024-1;
i++)
1000 const size_t rel = tm*1024 +
i;
1002 const float &
v0 = val[rel];
1003 const float &v1 = val[rel+1];
1014 if ((v0<0 && v1<0) || (v0>0 && v1>0))
1020 const double p = v0==v1 ? 0.5 : v0/(v0-v1);
1027 const double l = i+p - (i_prev+p_prev);
1033 const double w0 = 1-p_prev;
1034 fStat[pos+(spos+i_prev)%1024].
first += w0*l;
1035 fStat[pos+(spos+i_prev)%1024].
second += w0;
1037 for (
size_t k=i_prev+1; k<
i; k++)
1039 fStat[pos+(spos+k)%1024].
first += l;
1040 fStat[pos+(spos+k)%1024].
second += 1;
1043 const double w1 = p;
1044 fStat[pos+(spos+
i)%1024].
first += w1*l;
1045 fStat[pos+(spos+
i)%1024].
second += w1;
1058 for (
int ch=0; ch<160; ch++)
1060 const auto beg = fStat.begin() + ch*1024;
1061 const auto end = beg + 1024;
1065 for (
auto it=beg; it!=
end; it++)
1067 if (it->second<fNumEntries-0.5)
1070 avg += it->first / it->second;
1075 for (
auto it=beg; it!=
end; it++)
1077 if (it->second>=fNumEntries-0.5)
1102 for (
int ch=0; ch<160; ch++)
1104 const auto beg = fStat.begin() + ch*1024;
1105 const auto end = beg + 1024;
1113 for (
auto it=beg; it!=
end; it++)
1150 for (
auto it=beg; it!=
end-512; it++, n++)
1152 const double valv = it->first;
1153 const double valw = it->second;
1155 it->first = sumv>0 ? n*(1-s*sumw/sumv) : 0;
1166 for (
auto it=
end-1; it!=beg-1+512; it--, n++)
1168 const double valv = it->first;
1169 const double valw = it->second;
1174 it->first = sumv>0 ? n*(s*sumw/sumv-1) : 0;
1194 const auto p = fStat.begin() + ch*1024;
1196 const uint32_t f = floor(pos);
1198 const double v0 = p[f].first;
1199 const double v1 = p[(f+1)%1024].
first;
1201 return v0 + fmod(pos, 1)*(v1-
v0);
1206 return pos-Offset(ch, pos);
1322 std::string fDateRunBeg[3];
1323 std::string fDateRunEnd[3];
1329 fOffset(1440*1024, 0),
1330 fGain(1440*1024, 4096),
1331 fTrgOff (1600*1024, 0),
1336 fDateObs(
"1970-01-01T00:00:00"),
1337 fDateEnd(
"1970-01-01T00:00:00")
1339 for (
int i=0;
i<3;
i++)
1341 fDateRunBeg[
i] =
"1970-01-01T00:00:00";
1342 fDateRunEnd[
i] =
"1970-01-01T00:00:00";
1347 fOffset(cpy.fOffset),
1349 fTrgOff(cpy.fTrgOff),
1350 fNumOffset(cpy.fNumOffset),
1351 fNumGain(cpy.fNumGain),
1352 fNumTrgOff(cpy.fNumTrgOff),
1356 fDateObs(cpy.fDateObs),
1357 fDateEnd(cpy.fDateEnd)
1359 for (
int i=0;
i<3;
i++)
1370 fOffset.assign(1440*1024, 0);
1371 fGain.assign (1440*1024, 4096);
1372 fTrgOff.assign(1600*1024, 0);
1380 fDateObs =
"1970-01-01T00:00:00";
1381 fDateEnd =
"1970-01-01T00:00:00";
1383 for (
int i=0;
i<3;
i++)
1385 fDateRunBeg[
i] =
"1970-01-01T00:00:00";
1386 fDateRunEnd[
i] =
"1970-01-01T00:00:00";
1395 std::ostringstream msg;
1396 msg <<
"Could not open file '" << str <<
"': " << strerror(errno);
1400 if (file.
GetStr(
"TELESCOP")!=
"FACT")
1402 std::ostringstream msg;
1403 msg <<
"Reading '" << str <<
"' failed: Not a valid FACT file (TELESCOP not FACT in header)";
1407 if (!file.
HasKey(
"STEP"))
1409 std::ostringstream msg;
1410 msg <<
"Reading '" << str <<
"' failed: Is not a DRS calib file (STEP not found in header)";
1416 std::ostringstream msg;
1417 msg <<
"Reading '" << str <<
"' failed: Number of rows in table is not 1.";
1422 fNumOffset = file.
GetInt(
"NBOFFSET");
1423 fNumGain = file.
GetInt(
"NBGAIN");
1424 fNumTrgOff = file.
GetInt(
"NBTRGOFF");
1428 if (file.
HasKey(
"DATE-OBS"))
1429 fDateObs = file.
GetStr(
"DATE-OBS");
1430 if (file.
HasKey(
"DATE-END"))
1431 fDateEnd = file.
GetStr(
"DATE-END");
1433 if (file.
HasKey(
"RUN0-BEG"))
1434 fDateRunBeg[0]= file.
GetStr(
"RUN0-BEG");
1435 if (file.
HasKey(
"RUN1-BEG"))
1436 fDateRunBeg[1]= file.
GetStr(
"RUN1-BEG");
1437 if (file.
HasKey(
"RUN2-BEG"))
1438 fDateRunBeg[2]= file.
GetStr(
"RUN2-BEG");
1439 if (file.
HasKey(
"RUN0-END"))
1440 fDateRunEnd[0]= file.
GetStr(
"RUN0-END");
1441 if (file.
HasKey(
"RUN1-END"))
1442 fDateRunEnd[1]= file.
GetStr(
"RUN1-END");
1443 if (file.
HasKey(
"RUN2-END"))
1444 fDateRunEnd[2]= file.
GetStr(
"RUN2-END");
1450 vec.resize(1440*1024*4 + (1440+fNumTm)*fRoi*2 + 4);
1452 float *base = vec.data();
1454 reinterpret_cast<uint32_t*
>(base)[0] = fRoi;
1459 file.
SetPtrAddress(
"BaselineMean", base+4+0*1024*1440, 1024*1440);
1460 file.
SetPtrAddress(
"BaselineRms", base+4+1*1024*1440, 1024*1440);
1461 file.
SetPtrAddress(
"GainMean", base+4+2*1024*1440, 1024*1440);
1462 file.
SetPtrAddress(
"GainRms", base+4+3*1024*1440, 1024*1440);
1463 file.
SetPtrAddress(
"TriggerOffsetMean", base+4+4*1024*1440, fRoi*1440);
1464 file.
SetPtrAddress(
"TriggerOffsetRms", base+4+4*1024*1440+fRoi*1440, fRoi*1440);
1467 file.
SetPtrAddress(
"TriggerOffsetTMMean", base+4+4*1024*1440+ 2*fRoi*1440, fRoi*fNumTm);
1468 file.
SetPtrAddress(
"TriggerOffsetTMRms", base+4+4*1024*1440+ 2*fRoi*1440+ fRoi*fNumTm, fRoi*fNumTm);
1473 std::ostringstream msg;
1474 msg <<
"Reading data from " << str <<
" failed.";
1485 fOffset.resize(1024*1440);
1486 fGain.resize(1024*1440);
1488 fTrgOff.resize(fRoi*(1440+fNumTm));
1492 for (
int i=0;
i<1024*1440;
i++)
1494 fOffset[
i] = fNumOffset *256*base[
i+1024*1440*0+4]/125;
1495 fGain[
i] = fNumOffset*fNumGain*256*base[
i+1024*1440*2+4]/125;
1498 for (
int i=0;
i<fRoi*1440;
i++)
1499 fTrgOff[
i] = fNumOffset*fNumTrgOff*256*base[
i+1024*1440*4+4]/125;
1501 for (
int i=0;
i<fRoi*fNumTm;
i++)
1502 fTrgOff[
i+1440*fRoi] = fNumOffset*fNumTrgOff*256*base[
i+1024*1440*4+2*fRoi*1440+4]/125;
1512 for (
int i=0;
i<1024*1440;
i++)
1513 fGain[
i] = fNumOffset*4096;
1517 fNumGain *= 1953125;
1518 for (
int i=0;
i<1024*1440;
i++)
1528 return std::string();
1531 std::string
WriteFitsImp(
const std::string &filename,
const std::vector<float> &vec, uint32_t night=0)
const 1533 const size_t n = 1440*1024*4 + 1440*fRoi*2 + fNumTm*fRoi*2 + 3;
1535 ofits file(filename.c_str());
1538 std::ostringstream msg;
1539 msg <<
"Could not open file '" << filename <<
"': " << strerror(errno);
1543 file.AddColumnInt(
"RunNumberBaseline");
1544 file.AddColumnInt(
"RunNumberGain");
1545 file.AddColumnInt(
"RunNumberTriggerOffset");
1547 file.AddColumnFloat(1024*1440,
"BaselineMean",
"mV");
1548 file.AddColumnFloat(1024*1440,
"BaselineRms",
"mV");
1549 file.AddColumnFloat(1024*1440,
"GainMean",
"mV");
1550 file.AddColumnFloat(1024*1440,
"GainRms",
"mV");
1551 file.AddColumnFloat(fRoi*1440,
"TriggerOffsetMean",
"mV");
1552 file.AddColumnFloat(fRoi*1440,
"TriggerOffsetRms",
"mV");
1553 file.AddColumnFloat(fRoi*fNumTm,
"TriggerOffsetTMMean",
"mV");
1554 file.AddColumnFloat(fRoi*fNumTm,
"TriggerOffsetTMRms",
"mV");
1556 file.SetDefaultKeys();
1558 file.SetInt(
"NIGHT", night,
"Night as int");
1560 file.SetStr(
"DATE-OBS", fDateObs,
"First event of whole DRS calibration");
1561 file.SetStr(
"DATE-END", fDateEnd,
"Last event of whole DRS calibration");
1562 file.SetStr(
"RUN0-BEG", fDateRunBeg[0],
"First event of run 0");
1563 file.SetStr(
"RUN1-BEG", fDateRunBeg[1],
"First event of run 1");
1564 file.SetStr(
"RUN2-BEG", fDateRunBeg[2],
"First event of run 2");
1565 file.SetStr(
"RUN0-END", fDateRunEnd[0],
"Last event of run 0");
1566 file.SetStr(
"RUN1-END", fDateRunEnd[1],
"Last event of run 1");
1567 file.SetStr(
"RUN2-END", fDateRunEnd[2],
"Last event of run 2");
1569 file.SetInt(
"STEP", fStep,
"");
1571 file.SetInt(
"ADCRANGE", 2000,
"Dynamic range of the ADC in mV");
1572 file.SetInt(
"DACRANGE", 2500,
"Dynamic range of the DAC in mV");
1573 file.SetInt(
"ADC", 12,
"Resolution of ADC in bits");
1574 file.SetInt(
"DAC", 16,
"Resolution of DAC in bits");
1575 file.SetInt(
"NPIX", 1440,
"Number of channels in the camera");
1576 file.SetInt(
"NTM", fNumTm,
"Number of time marker channels");
1577 file.SetInt(
"NROI", fRoi,
"Region of interest");
1579 file.SetInt(
"NBOFFSET", fNumOffset,
"Num of entries for offset calibration");
1580 file.SetInt(
"NBGAIN", fNumGain/1953125,
"Num of entries for gain calibration");
1581 file.SetInt(
"NBTRGOFF", fNumTrgOff,
"Num of entries for trigger offset calibration");
1587 file.WriteTableHeader(
"DrsCalibration");
1589 if (!file.WriteRow(vec.data()+1, n*
sizeof(float)))
1591 std::ostringstream msg;
1592 msg <<
"Writing data to " << filename <<
" failed.";
1596 return std::string();
1602 std::vector<float> vec;
1603 return ReadFitsImp(str, vec);
1608 bool Apply(
float *vec,
const int16_t *val,
const int16_t *
start, uint32_t roi)
1612 for (
size_t ch=0; ch<1440; ch++)
1614 const size_t pos = ch*roi;
1615 const size_t drs = ch*1024;
1618 fOffset.data()+drs, fNumOffset,
1619 fGain.data() +drs, fNumGain);
1625 for (
size_t ch=0; ch<1440; ch++)
1627 const size_t pos = ch*fRoi;
1628 const size_t drs = ch*1024;
1631 fOffset.data()+drs, fNumOffset,
1632 fGain.data() +drs, fNumGain,
1633 fTrgOff.data()+
pos, fNumTrgOff);
1636 for (
size_t ch=0; ch<fNumTm; ch++)
1638 const size_t pos = (ch+1440)*fRoi;
1639 const size_t drs = (ch*9+8)*1024;
1642 fOffset.data()+drs, fNumOffset,
1643 fGain.data() +drs, fNumGain,
1644 fTrgOff.data()+
pos, fNumTrgOff);
DrsCalibrateTime GetResult() const
Return to feeserver c CVS log Up to[MAIN] dcscvs FeeServer feeserver src Wed FeeServer_v0 v0 FeeServer_v0 v0 FeeServer_v0 v0 FeeServer_v0 v0 FeeServer_v0 v0 FeeServer_v0 v0
std::vector< int32_t > fOffset
bool HasKey(const std::string &key) const
std::string GetStr(const std::string &key) const
static Step CorrectStep(float *vec, uint16_t nch, uint16_t roi, const int16_t *prev, const int16_t *start, const int16_t offset, const uint16_t *map=NULL)
void * SetPtrAddress(const std::string &name)
double Calib(uint32_t ch, double pos) const
std::vector< int64_t > fSum
std::string WriteFitsImp(const std::string &filename, const std::vector< float > &vec, uint32_t night=0) const
structure for storing edges of hexagons (for blurry display)
uint64_t GetUInt(const std::string &key) const
std::vector< std::pair< double, double > > fStat
static void SlidingAverage(float *const vec, const uint32_t roi, const uint16_t w)
static Step AverageSteps(const std::vector< Step >::iterator beg, const std::vector< Step >::iterator end)
int64_t second
offset of this column in the tile, from the start of the heap area
bool Apply(float *vec, const int16_t *val, const int16_t *start, uint32_t roi)
std::pair< std::vector< double >, std::vector< double > > GetSampleStats() const
std::string ReadFitsImp(const std::string &str)
std::string ReadFitsImp(const std::string &str, std::vector< float > &vec)
std::vector< int64_t > fSum2
DrsCalibrateTime(const DrsCalibrateTime &p)
int64_t first
Size of this column in the tile.
static void RemoveSpikes2(float *p, uint32_t roi)
static void RemoveSpikes(float *p, uint32_t roi)
virtual size_t GetNumRows() const
static void ApplyCh(float *vec, const int16_t *val, int16_t start, uint32_t roi, const int32_t *offset, const int64_t scaleabs, const int64_t *gain, const int64_t scalegain, const int64_t *trgoff, const int64_t scalerel)
static void RemoveSpikes3(float *vec, uint32_t roi)
static bool sort(const Step &s, const Step &r)
bool GetNextRow(bool check=true)
std::vector< int64_t > fGain
static void SubtractStep(const size_t ch0, const double avg, float *vec, int16_t roi, int32_t pos, const uint16_t *map=NULL)
virtual void InitSize(uint16_t channels, uint16_t samples)
double Sum(uint32_t i) const
static void GetPixelMax(float *max, const float *data, uint16_t roi, int32_t first, int32_t last)
static double FindStep(const size_t ch0, const float *vec, int16_t roi, const int16_t pos, const uint16_t *map=NULL)
void InitSize(uint16_t channels, uint16_t samples)
void AddRel(const int16_t *val, const int16_t *start)
int64_t GetInt(const std::string &key) const
std::string fDateRunBeg[3]
std::string fDateRunEnd[3]
DrsCalibrateTime GetComplete() const
DrsCalibration(const DrsCalibration &cpy)
virtual ~DrsCalibrateTime()
void GetSampleStats(float *ptr, float scale) const
double Offset(uint32_t ch, double pos) const
static double GetPixelStats(float *ptr, const float *data, uint16_t roi, uint16_t begskip=0, uint16_t endskip=0)
int64_t GetNumEntries() const
std::vector< int64_t > fTrgOff
void AddT(const float *val, const int16_t *start, signed char edge=0)
void AddAbs(const int16_t *val, const int16_t *start, const int32_t *offset, const int64_t scale)
void AddRel(const int16_t *val, const int16_t *start, const int32_t *offset, const int64_t scale)
static void RemoveSpikes4(float *ptr, uint32_t roi)
const std::vector< int64_t > & GetSum() const
double W(uint32_t i) const
static void ApplyCh(float *vec, const int16_t *val, int16_t start, uint32_t roi, const int32_t *offset, const int64_t scaleabs, const int64_t *gain, const int64_t scalegain)