13 siStripProcessedRawDigiToken_(
18 forceNoRestore_(conf.getParameter<
bool>(
"ForceNoRestore")),
19 inspectAlgo_(conf.getParameter<
std::
string>(
"APVInspectMode")),
20 restoreAlgo_(conf.getParameter<
std::
string>(
"APVRestoreMode")),
22 useRealMeanCM_(conf.getParameter<
bool>(
"useRealMeanCM")),
23 meanCM_(conf.getParameter<int32_t>(
"MeanCM")),
24 deltaCMThreshold_(conf.getParameter<uint32_t>(
"DeltaCMThreshold")),
26 fraction_(conf.getParameter<double>(
"Fraction")),
27 deviation_(conf.getParameter<uint32_t>(
"Deviation")),
29 restoreThreshold_(conf.getParameter<double>(
"restoreThreshold")),
31 nSaturatedStrip_(conf.getParameter<uint32_t>(
"nSaturatedStrip")),
33 nSigmaNoiseDerTh_(conf.getParameter<uint32_t>(
"nSigmaNoiseDerTh")),
34 consecThreshold_(conf.getParameter<uint32_t>(
"consecThreshold")),
35 nSmooth_(conf.getParameter<uint32_t>(
"nSmooth")),
36 distortionThreshold_(conf.getParameter<uint32_t>(
"distortionThreshold")),
37 applyBaselineCleaner_(conf.getParameter<
bool>(
"ApplyBaselineCleaner")),
38 cleaningSequence_(conf.getParameter<uint32_t>(
"CleaningSequence")),
40 slopeX_(conf.getParameter<int32_t>(
"slopeX")),
41 slopeY_(conf.getParameter<int32_t>(
"slopeY")),
43 hitStripThreshold_(conf.getParameter<uint32_t>(
"hitStripThreshold")),
45 minStripsToFit_(conf.getParameter<uint32_t>(
"minStripsToFit")),
46 applyBaselineRejection_(conf.getParameter<
bool>(
"ApplyBaselineRejection")),
47 filteredBaselineMax_(conf.getParameter<double>(
"filteredBaselineMax")),
48 filteredBaselineDerivativeSumSquare_(conf.getParameter<double>(
"filteredBaselineDerivativeSumSquare")),
50 gradient_threshold_(conf.getParameter<
int>(
"discontinuityThreshold")),
51 last_gradient_(conf.getParameter<
int>(
"lastGradient")),
52 size_window_(conf.getParameter<
int>(
"sizeWindow")),
53 width_cluster_(conf.getParameter<
int>(
"widthCluster")) {
56 <<
"The BaselineFollower restore method requires the BaselineFollower (or Hybrid) inspect method";
76 auto nAPVFlagged =
inspect(
detId, firstAPV, rawDigisPedSubtracted, vmedians);
77 restore(firstAPV, processedRawDigi);
94 for (
const auto& med : vmedians) {
95 auto iAPV = med.first;
100 uint16_t nAPVFlagged = 0;
117 <<
"SiStripAPVRestorer possibilities: (Null), (AbnormalBaseline), (BaselineFollower), (BaselineAndSaturation), " 118 "(DerivativeFollower), (Hybrid), (HybridEmulation)";
132 for (uint16_t iAPV = firstAPV; iAPV < digis.size() /
nTotStripsPerAPV + firstAPV; ++iAPV) {
134 if (!algoToUse.empty()) {
135 if (algoToUse ==
"Flat") {
137 }
else if (algoToUse ==
"BaselineFollower") {
139 }
else if (algoToUse ==
"DerivativeFollower") {
143 <<
"SiStripAPVRestorer possibilities: (Flat), (BaselineFollower), (DerivativeFollower)";
154 uint16_t nAPVflagged = 0;
155 for (uint16_t iAPV = firstAPV; iAPV < digis.size() /
nTotStripsPerAPV + firstAPV; ++iAPV) {
158 uint16_t stripsPerAPV = 0;
159 singleAPVdigi.clear();
163 singleAPVdigi.push_back(
adc);
168 if (stripsPerAPV > 64) {
182 uint16_t nAPVflagged = 0;
188 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
193 MeanAPVCM = itCMMap->second[iAPV];
195 singleAPVdigi.clear();
198 std::back_inserter(singleAPVdigi));
200 const float DeltaCM =
median_[iAPV] - MeanAPVCM;
214 uint16_t nAPVflagged = 0;
215 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
227 uint16_t nAPVflagged = 0;
233 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
237 MeanAPVCM = itCMMap->second[iAPV];
239 singleAPVdigi.clear();
240 uint16_t nSatStrip = 0;
243 const uint16_t digi = digis[
strip];
244 singleAPVdigi.push_back(digi);
249 const float DeltaCM =
median_[iAPV] - MeanAPVCM;
262 uint16_t nAPVflagged = 0;
268 int devCount = 0, qualityCount = 0, minstrip = 0;
269 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
273 MeanAPVCM = itCMMap->second[iAPV];
285 if (devCount >
fraction_ * qualityCount) {
297 uint16_t nAPVflagged = 0;
298 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
300 int zeroCount = 0, qualityCount = 0;
319 uint16_t nAPVflagged = 0;
325 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
329 MeanAPVCM = itCMMap->second[iAPV];
331 const float DeltaCM =
median_[iAPV] - (MeanAPVCM + 1024) / 2;
391 smoothedpoints.clear();
398 float localmin = 999.9;
399 for (uint16_t jstrip =
std::max(0, static_cast<int>(istrip -
nSmooth_ / 2));
400 jstrip < std::min((int)nTotStripsPerAPV, static_cast<int>(istrip +
nSmooth_ / 2));
402 const float nextvalue = adcs[jstrip];
403 if (nextvalue < localmin)
404 localmin = nextvalue;
406 adcsLocalMinSubtracted[istrip] = adcs[istrip] - localmin;
411 std::vector<uint16_t> nConsStrip;
413 uint16_t consecStrips = 0;
415 const int16_t
adc = adcs[istrip];
417 if (adcsLocalMinSubtracted[istrip] <
419 consecpoints.emplace_hint(consecpoints.end(), istrip,
adc);
421 }
else if (consecStrips > 0) {
422 nConsStrip.push_back(consecStrips);
427 if (consecStrips > 0)
428 nConsStrip.push_back(consecStrips);
431 auto itConsecpoints = consecpoints.begin();
432 float MinSmoothValue = 20000., MaxSmoothValue = 0.;
433 for (
const auto consecStrips : nConsStrip) {
436 uint16_t nFirstStrip = itConsecpoints->first;
438 float smoothValue = 0.0;
439 float stripCount = 1;
440 for (uint16_t
n = 0;
n < consecStrips - 2; ++
n) {
441 smoothValue += itConsecpoints->second;
443 smoothValue /= (
float)stripCount;
444 nLastStrip = nFirstStrip + stripCount - 1;
445 smoothedpoints.emplace_hint(smoothedpoints.end(), nFirstStrip, smoothValue);
446 smoothedpoints.emplace_hint(smoothedpoints.end(), nLastStrip, smoothValue);
447 if (smoothValue > MaxSmoothValue)
448 MaxSmoothValue = smoothValue;
449 if (smoothValue < MinSmoothValue)
450 MinSmoothValue = smoothValue;
451 nFirstStrip = nLastStrip + 1;
460 if (stripCount > 1) {
463 smoothValue /=
static_cast<float>(stripCount);
464 nLastStrip = nFirstStrip + stripCount - 1;
465 smoothedpoints.emplace_hint(smoothedpoints.end(), nFirstStrip, smoothValue);
466 smoothedpoints.emplace_hint(smoothedpoints.end(), nLastStrip, smoothValue);
467 if (smoothValue > MaxSmoothValue)
468 MaxSmoothValue = smoothValue;
469 if (smoothValue < MinSmoothValue)
470 MinSmoothValue = smoothValue;
473 for (
int n = 0;
n < consecStrips; ++
n)
508 if (smoothedpoints.size() < 3)
511 auto it = smoothedpoints.begin();
512 while (smoothedpoints.size() > 3 &&
it != --(--smoothedpoints.end())) {
515 const float adc1 = it2->second;
516 const float adc2 = (++it2)->
second;
517 const float adc3 = (++it2)->
second;
520 smoothedpoints.erase(--it2);
535 if (smoothedpoints.size() >= 2) {
536 for (
auto it = smoothedpoints.begin();
it != --smoothedpoints.end(); ++
it) {
539 const float strip1 =
it->first;
540 const float strip2 = itNext->first;
541 const float adc1 =
it->second;
542 const float adc2 = itNext->second;
543 const float m = (adc2 - adc1) / (strip2 - strip1);
548 float strip = itStrip + strip1;
549 while (
strip < strip2) {
553 if (
adc < (adc1 +
m * itStrip - 2 *
noise)) {
554 smoothedpoints.emplace_hint(itNext,
strip,
adc);
564 const uint16_t firstStripFlat = smoothedpoints.begin()->first;
565 const uint16_t lastStripFlat = (--smoothedpoints.end())->
first;
566 const int16_t firstStripFlatADC = smoothedpoints.begin()->second;
567 const int16_t lastStripFlatADC = (--smoothedpoints.end())->
second;
568 if (firstStripFlat > 3) {
569 auto it = smoothedpoints.begin();
571 while (
strip < firstStripFlat) {
574 if (
adc < (firstStripFlatADC - 2 *
noise)) {
582 float strip = lastStripFlat + 1;
586 if (
adc < (lastStripFlatADC - 2 *
noise)) {
587 smoothedpoints.emplace_hint(smoothedpoints.end(),
strip,
adc);
597 if (smoothedpoints.size() < 4)
600 auto it = smoothedpoints.begin();
601 while (smoothedpoints.size() > 2 &&
it != --smoothedpoints.end()) {
606 const float strip1 =
it->first;
607 const float strip2 = itNext->first;
608 const float adc1 =
it->second;
609 const float adc2 = itNext->second;
610 const float m = (adc2 - adc1) / (strip2 - strip1);
613 smoothedpoints.erase(itNext);
616 if (
it == smoothedpoints.begin())
617 smoothedpoints.erase(
it++);
620 smoothedpoints.erase(
it--);
636 const auto lastIt = --smoothedpoints.end();
637 const uint16_t firstStripFlat = smoothedpoints.begin()->first;
638 const uint16_t lastStripFlat = lastIt->first;
639 const int16_t firstStripFlatADC = smoothedpoints.begin()->second;
640 const int16_t lastStripFlatADC = lastIt->second;
643 baseline.erase(baseline.begin(), baseline.begin() + firstStripFlat);
644 baseline.insert(baseline.begin(), firstStripFlat, firstStripFlatADC);
646 baseline.erase(baseline.begin() + lastStripFlat, baseline.end());
647 baseline.insert(baseline.end(),
nTotStripsPerAPV - lastStripFlat, lastStripFlatADC);
650 for (
auto itSmoothedpoints = smoothedpoints.begin(); itSmoothedpoints != (--smoothedpoints.end());
651 ++itSmoothedpoints) {
652 auto itNextSmoothedpoints = itSmoothedpoints;
653 ++itNextSmoothedpoints;
654 const float strip1 = itSmoothedpoints->first;
655 const float strip2 = itNextSmoothedpoints->first;
656 const float adc1 = itSmoothedpoints->second;
657 const float adc2 = itNextSmoothedpoints->second;
659 baseline[strip1] = adc1;
660 baseline[strip2] = adc2;
661 const float m = (adc2 - adc1) / (strip2 - strip1);
662 uint16_t itStrip = strip1 + 1;
663 float stripadc = adc1 +
m;
664 while (itStrip < strip2) {
665 baseline[itStrip] = stripadc;
694 static const size_t savitzky_golay_n_l_r = 16;
695 static const float savitzky_golay_coefficient[2 * savitzky_golay_n_l_r + 1][2 * savitzky_golay_n_l_r + 1] = {
750 {0.172078, 0.153076, 0.135099, 0.118148, 0.102221, 0.0873206, 0.073445,
751 0.0605947, 0.0487697, 0.0379699, 0.0281955, 0.0194463, 0.0117225, 0.00502392,
752 -0.000649351, -0.00529733, -0.00892003, -0.0115174, -0.0130895, -0.0136364},
753 {0.123659, 0.116431, 0.109144, 0.101798, 0.0943921, 0.0869268, 0.0794021,
754 0.0718179, 0.0641743, 0.0564712, 0.0487087, 0.0408868, 0.0330054, 0.0250646,
755 0.0170644, 0.00900473, 0.000885613, -0.00729294, -0.0155309, -0.0238283, -0.0321852},
756 {0.0859684, 0.0868154, 0.0869565, 0.0863919, 0.0851214, 0.0831451, 0.080463, 0.0770751,
757 0.0729814, 0.0681818, 0.0626765, 0.0564653, 0.0495483, 0.0419255, 0.0335968, 0.0245624,
758 0.0148221, 0.00437606, -0.00677583, -0.0186335, -0.0311971, -0.0444664},
759 {0.0565217, 0.0628458, 0.0680971, 0.0722756, 0.0753811, 0.0774139, 0.0783738, 0.0782609,
760 0.0770751, 0.0748165, 0.071485, 0.0670807, 0.0616036, 0.0550536, 0.0474308, 0.0387352,
761 0.0289667, 0.0181254, 0.00621118, -0.00677583, -0.0208357, -0.0359684, -0.0521739},
762 {0.0334615, 0.0434281, 0.0521329, 0.0595759, 0.0657571, 0.0706765, 0.0743341, 0.07673,
763 0.0778641, 0.0777364, 0.0763469, 0.0736957, 0.0697826, 0.0646078, 0.0581712, 0.0504728,
764 0.0415126, 0.0312907, 0.0198069, 0.00706142, -0.00694588, -0.022215, -0.0387458, -0.0565385},
765 {0.0153846, 0.0276923, 0.0386622, 0.0482943, 0.0565886, 0.0635452, 0.0691639, 0.0734448, 0.076388,
766 0.0779933, 0.0782609, 0.0771906, 0.0747826, 0.0710368, 0.0659532, 0.0595318, 0.0517726, 0.0426756,
767 0.0322408, 0.0204682, 0.00735786, -0.0070903, -0.0228763, -0.04, -0.0584615},
768 {0.001221, 0.0149451, 0.027326, 0.0383639, 0.0480586, 0.0564103, 0.0634188, 0.0690842, 0.0734066,
769 0.0763858, 0.078022, 0.078315, 0.077265, 0.0748718, 0.0711355, 0.0660562, 0.0596337, 0.0518681,
770 0.0427595, 0.0323077, 0.0205128, 0.00737485, -0.00710623, -0.0229304, -0.0400977, -0.0586081},
771 {-0.00985222, 0.00463138, 0.0178098, 0.029683, 0.0402509, 0.0495137, 0.0574713, 0.0641236, 0.0694708,
772 0.0735127, 0.0762494, 0.0776809, 0.0778073, 0.0766284, 0.0741442, 0.0703549, 0.0652604, 0.0588607,
773 0.0511557, 0.0421456, 0.0318302, 0.0202097, 0.0072839, -0.00694708, -0.0224833, -0.0393247, -0.0574713},
774 {-0.0184729, -0.00369458, 0.00984169, 0.0221359, 0.0331881, 0.0429982, 0.0515662,
775 0.0588923, 0.0649762, 0.0698181, 0.073418, 0.0757758, 0.0768915, 0.0767652,
776 0.0753968, 0.0727864, 0.0689339, 0.0638394, 0.0575028, 0.0499242, 0.0411035,
777 0.0310408, 0.019736, 0.00718917, -0.00659972, -0.0216307, -0.0379037, -0.0554187},
778 {-0.025139, -0.0103925, 0.00318873, 0.0156046, 0.0268552, 0.0369405, 0.0458605, 0.0536151,
779 0.0602045, 0.0656285, 0.0698872, 0.0729806, 0.0749086, 0.0756714, 0.0752688, 0.0737009,
780 0.0709677, 0.0670692, 0.0620054, 0.0557763, 0.0483818, 0.039822, 0.0300969, 0.0192065,
781 0.0071508, -0.00607024, -0.0204566, -0.0360083, -0.0527253},
782 {-0.0302419, -0.0157536, -0.00234785, 0.00997537, 0.021216, 0.0313741, 0.0404497, 0.0484427,
783 0.0553532, 0.0611811, 0.0659264, 0.0695892, 0.0721695, 0.0736672, 0.0740823, 0.0734149,
784 0.0716649, 0.0688324, 0.0649174, 0.0599198, 0.0538396, 0.0466769, 0.0384316, 0.0291038,
785 0.0186934, 0.00720046, -0.00537502, -0.0190331, -0.0337736, -0.0495968},
786 {-0.0340909, -0.0200147, -0.006937, 0.00514208, 0.0162226, 0.0263045, 0.0353878, 0.0434725,
787 0.0505587, 0.0566463, 0.0617353, 0.0658257, 0.0689175, 0.0710107, 0.0721054, 0.0722014,
788 0.0712989, 0.0693978, 0.0664981, 0.0625999, 0.057703, 0.0518076, 0.0449135, 0.0370209,
789 0.0281297, 0.01824, 0.0073516, -0.00453534, -0.0174209, -0.031305, -0.0461877},
790 {-0.0369318, -0.0233688, -0.0107221, 0.00100806, 0.0118218, 0.0217192, 0.0307001, 0.0387647,
791 0.0459128, 0.0521444, 0.0574597, 0.0618585, 0.0653409, 0.0679069, 0.0695565, 0.0702896,
792 0.0701063, 0.0690066, 0.0669905, 0.0640579, 0.0602089, 0.0554435, 0.0497617, 0.0431635,
793 0.0356488, 0.0272177, 0.0178702, 0.0076063, -0.00357405, -0.0156708, -0.028684, -0.0426136},
794 {-0.038961, -0.025974, -0.0138249, -0.00251362, 0.00795978, 0.0175953, 0.026393, 0.0343527, 0.0414747,
795 0.0477587, 0.0532049, 0.0578132, 0.0615836, 0.0645161, 0.0666108, 0.0678676, 0.0682866, 0.0678676,
796 0.0666108, 0.0645161, 0.0615836, 0.0578132, 0.0532049, 0.0477587, 0.0414747, 0.0343527, 0.026393,
797 0.0175953, 0.00795978, -0.00251362, -0.0138249, -0.025974, -0.038961},
798 {-0.0426136, -0.028684, -0.0156708, -0.00357405, 0.0076063, 0.0178702, 0.0272177, 0.0356488,
799 0.0431635, 0.0497617, 0.0554435, 0.0602089, 0.0640579, 0.0669905, 0.0690066, 0.0701063,
800 0.0702896, 0.0695565, 0.0679069, 0.0653409, 0.0618585, 0.0574597, 0.0521444, 0.0459128,
801 0.0387647, 0.0307001, 0.0217192, 0.0118218, 0.00100806, -0.0107221, -0.0233688, -0.0369318},
802 {-0.0461877, -0.031305, -0.0174209, -0.00453534, 0.0073516, 0.01824, 0.0281297, 0.0370209,
803 0.0449135, 0.0518076, 0.057703, 0.0625999, 0.0664981, 0.0693978, 0.0712989, 0.0722014,
804 0.0721054, 0.0710107, 0.0689175, 0.0658257, 0.0617353, 0.0566463, 0.0505587, 0.0434725,
805 0.0353878, 0.0263045, 0.0162226, 0.00514208, -0.006937, -0.0200147, -0.0340909},
806 {-0.0495968, -0.0337736, -0.0190331, -0.00537502, 0.00720046, 0.0186934, 0.0291038, 0.0384316,
807 0.0466769, 0.0538396, 0.0599198, 0.0649174, 0.0688324, 0.0716649, 0.0734149, 0.0740823,
808 0.0736672, 0.0721695, 0.0695892, 0.0659264, 0.0611811, 0.0553532, 0.0484427, 0.0404497,
809 0.0313741, 0.021216, 0.00997537, -0.00234785, -0.0157536, -0.0302419},
810 {-0.0527253, -0.0360083, -0.0204566, -0.00607024, 0.0071508, 0.0192065, 0.0300969, 0.039822,
811 0.0483818, 0.0557763, 0.0620054, 0.0670692, 0.0709677, 0.0737009, 0.0752688, 0.0756714,
812 0.0749086, 0.0729806, 0.0698872, 0.0656285, 0.0602045, 0.0536151, 0.0458605, 0.0369405,
813 0.0268552, 0.0156046, 0.00318873, -0.0103925, -0.025139},
814 {-0.0554187, -0.0379037, -0.0216307, -0.00659972, 0.00718917, 0.019736, 0.0310408,
815 0.0411035, 0.0499242, 0.0575028, 0.0638394, 0.0689339, 0.0727864, 0.0753968,
816 0.0767652, 0.0768915, 0.0757758, 0.073418, 0.0698181, 0.0649762, 0.0588923,
817 0.0515662, 0.0429982, 0.0331881, 0.0221359, 0.00984169, -0.00369458, -0.0184729},
818 {-0.0574713, -0.0393247, -0.0224833, -0.00694708, 0.0072839, 0.0202097, 0.0318302, 0.0421456, 0.0511557,
819 0.0588607, 0.0652604, 0.0703549, 0.0741442, 0.0766284, 0.0778073, 0.0776809, 0.0762494, 0.0735127,
820 0.0694708, 0.0641236, 0.0574713, 0.0495137, 0.0402509, 0.029683, 0.0178098, 0.00463138, -0.00985222},
821 {-0.0586081, -0.0400977, -0.0229304, -0.00710623, 0.00737485, 0.0205128, 0.0323077, 0.0427595, 0.0518681,
822 0.0596337, 0.0660562, 0.0711355, 0.0748718, 0.077265, 0.078315, 0.078022, 0.0763858, 0.0734066,
823 0.0690842, 0.0634188, 0.0564103, 0.0480586, 0.0383639, 0.027326, 0.0149451, 0.001221},
824 {-0.0584615, -0.04, -0.0228763, -0.0070903, 0.00735786, 0.0204682, 0.0322408, 0.0426756, 0.0517726,
825 0.0595318, 0.0659532, 0.0710368, 0.0747826, 0.0771906, 0.0782609, 0.0779933, 0.076388, 0.0734448,
826 0.0691639, 0.0635452, 0.0565886, 0.0482943, 0.0386622, 0.0276923, 0.0153846},
827 {-0.0565385, -0.0387458, -0.022215, -0.00694588, 0.00706142, 0.0198069, 0.0312907, 0.0415126,
828 0.0504728, 0.0581712, 0.0646078, 0.0697826, 0.0736957, 0.0763469, 0.0777364, 0.0778641,
829 0.07673, 0.0743341, 0.0706765, 0.0657571, 0.0595759, 0.0521329, 0.0434281, 0.0334615},
830 {-0.0521739, -0.0359684, -0.0208357, -0.00677583, 0.00621118, 0.0181254, 0.0289667, 0.0387352,
831 0.0474308, 0.0550536, 0.0616036, 0.0670807, 0.071485, 0.0748165, 0.0770751, 0.0782609,
832 0.0783738, 0.0774139, 0.0753811, 0.0722756, 0.0680971, 0.0628458, 0.0565217},
833 {-0.0444664, -0.0311971, -0.0186335, -0.00677583, 0.00437606, 0.0148221, 0.0245624, 0.0335968,
834 0.0419255, 0.0495483, 0.0564653, 0.0626765, 0.0681818, 0.0729814, 0.0770751, 0.080463,
835 0.0831451, 0.0851214, 0.0863919, 0.0869565, 0.0868154, 0.0859684},
836 {-0.0321852, -0.0238283, -0.0155309, -0.00729294, 0.000885613, 0.00900473, 0.0170644,
837 0.0250646, 0.0330054, 0.0408868, 0.0487087, 0.0564712, 0.0641743, 0.0718179,
838 0.0794021, 0.0869268, 0.0943921, 0.101798, 0.109144, 0.116431, 0.123659},
839 {-0.0136364, -0.0130895, -0.0115174, -0.00892003, -0.00529733, -0.000649351, 0.00502392,
840 0.0117225, 0.0194463, 0.0281955, 0.0379699, 0.0487697, 0.0605947, 0.073445,
841 0.0873206, 0.102221, 0.118148, 0.135099, 0.153076, 0.172078},
904 for (
size_t i = 0;
i < savitzky_golay_n_l_r;
i++) {
905 for (
size_t j = 0;
j < savitzky_golay_n_l_r + 1 +
i;
j++) {
906 filtered_baseline[
i] += savitzky_golay_coefficient[
i][
j] * baseline[
j];
913 filtered_baseline[
i] = savitzky_golay_coefficient[savitzky_golay_n_l_r][savitzky_golay_n_l_r] * baseline[
i];
914 for (
size_t j = 0;
j < savitzky_golay_n_l_r;
j++) {
915 filtered_baseline[
i] += savitzky_golay_coefficient[savitzky_golay_n_l_r][
j] *
916 (baseline[
i +
j - savitzky_golay_n_l_r] + baseline[
i -
j + savitzky_golay_n_l_r]);
921 for (
size_t j = 0;
j < 2 * savitzky_golay_n_l_r + 1;
j++) {
923 savitzky_golay_coefficient[savitzky_golay_n_l_r][
j] *
924 baseline[
i +
j - savitzky_golay_n_l_r];
933 filtered_baseline[
i] += savitzky_golay_coefficient[2 * savitzky_golay_n_l_r +
i + 1 -
nTotStripsPerAPV][
j] *
934 baseline[
i +
j - savitzky_golay_n_l_r];
941 filtered_baseline_derivative[
i] = filtered_baseline[
i + 1] - filtered_baseline[
i];
947 double filtered_baseline_max = 0;
948 double filtered_baseline_derivative_sum_square = 0;
951 const double d = filtered_baseline[
i] - baseline[
i];
953 filtered_baseline_max =
std::max(filtered_baseline_max, static_cast<double>(fabs(
d)));
956 filtered_baseline_derivative_sum_square += filtered_baseline_derivative[
i] * filtered_baseline_derivative[
i];
960 std::cerr << __FILE__ <<
':' << __LINE__ <<
": " 961 << filtered_baseline_max <<
' ' 962 << filtered_baseline_derivative_sum_square << std::endl;
986 for (
const auto& rawDigis :
input) {
989 std::vector<float> meanCMDetSet;
990 meanCMDetSet.reserve(nAPVs);
991 for (uint16_t iAPV = 0; iAPV < nAPVs; ++iAPV) {
998 meanCMDetSet.push_back(minPed);
1005 for (
const auto& rawDigis :
input) {
1006 std::vector<float> meanCMNValue;
1007 meanCMNValue.reserve(rawDigis.size());
1020 singleAPVdigi.clear();
1022 singleAPVdigi.push_back(digis[
strip] + 1024);
1025 discontinuities.clear();
1027 digimap_t::iterator itdiscontinuities;
1031 bool isMinimumAndNoMax =
false;
1032 bool isFirstStrip =
false;
1036 int actualStripADC = 0;
1037 int previousStripADC = 0;
1040 int maximum_value = 0;
1041 const uint32_t n_high_maximum_cluster = 1025 + 1024;
1042 int high_maximum_cluster = n_high_maximum_cluster;
1043 int number_good_minimum = 0;
1044 int first_gradient = 0;
1045 int strip_first_gradient = 0;
1046 int adc_start_point_cluster_pw = 0;
1047 int auxiliary_end_cluster = 0;
1048 int first_start_cluster_strip = 0;
1049 int first_start_cluster_ADC = 0;
1050 bool isAuxiliary_Minimum =
false;
1051 bool isPossible_wrong_minimum =
false;
1058 actualStripADC = singleAPVdigi[
strip];
1060 isFirstStrip =
true;
1061 isMinimumAndNoMax =
true;
1062 discontinuities.insert(discontinuities.end(), std::pair<int, int>(
strip, actualStripADC));
1064 discontinuities.insert(discontinuities.end(), std::pair<uint16_t, int16_t>(
strip, 0 + 1024));
1065 isMinimumAndNoMax =
true;
1066 first_start_cluster_strip =
strip;
1067 first_start_cluster_ADC = 1024;
1071 previousStripADC = actualStripADC;
1072 actualStripADC = singleAPVdigi[
strip];
1073 greadient = actualStripADC - previousStripADC;
1078 discontinuities.size() > 1)) {
1080 isPossible_wrong_minimum =
true;
1081 itdiscontinuities = --discontinuities.end();
1082 if (discontinuities.size() > 1) {
1083 --itdiscontinuities;
1085 strip_first_gradient = itdiscontinuities->first;
1086 adc_start_point_cluster_pw = itdiscontinuities->second;
1087 first_gradient =
std::abs(adc_start_point_cluster_pw - singleAPVdigi[strip_first_gradient + 1]);
1088 discontinuities.erase(++itdiscontinuities);
1089 discontinuities.erase(--discontinuities.end());
1092 if ((discontinuities.size() % 2 == 1) && (!discontinuities.empty())) {
1093 discontinuities.erase(--discontinuities.end());
1096 discontinuities.insert(discontinuities.end(), std::pair<uint16_t, int16_t>(
strip - 1, previousStripADC));
1097 isMinimumAndNoMax =
true;
1099 first_start_cluster_strip =
strip - 1;
1100 first_start_cluster_ADC = previousStripADC;
1102 }
else if ((!isMax) && ((actualStripADC - previousStripADC < 0) && (isMinimumAndNoMax))) {
1104 isMinimumAndNoMax =
false;
1105 high_maximum_cluster = n_high_maximum_cluster;
1106 if ((previousStripADC > maximum_value) && (discontinuities.size() % 2 == 1))
1107 maximum_value = previousStripADC;
1111 if (high_maximum_cluster > (
std::abs(singleAPVdigi[
strip + 1] - actualStripADC))) {
1112 high_maximum_cluster = singleAPVdigi[
strip + 1] - actualStripADC;
1113 auxiliary_end_cluster =
strip + 2;
1119 if ((isMax) && ((actualStripADC - previousStripADC) >= 0) && (
size_window_ > 0) &&
1121 number_good_minimum = 0;
1122 for (uint16_t wintry = 0; wintry <=
size_window_; wintry++) {
1124 ++number_good_minimum;
1126 --number_good_minimum;
1130 isMinimumAndNoMax =
true;
1135 isAuxiliary_Minimum =
true;
1138 if (!discontinuities.empty()) {
1139 itdiscontinuities = --discontinuities.end();
1142 if ((isMax) && (actualStripADC <= first_start_cluster_ADC)) {
1143 if ((
std::abs(first_start_cluster_ADC - singleAPVdigi[
strip + 2]) > first_gradient) &&
1144 (isPossible_wrong_minimum)) {
1145 discontinuities.erase(itdiscontinuities);
1146 discontinuities.insert(discontinuities.end(),
1147 std::pair<int, int>(strip_first_gradient, adc_start_point_cluster_pw));
1148 discontinuities.insert(discontinuities.end(), std::pair<int, int>(
strip, adc_start_point_cluster_pw));
1150 if ((discontinuities.size() % 2 == 0) && (discontinuities.size() > 1)) {
1151 discontinuities.erase(--discontinuities.end());
1153 discontinuities.insert(discontinuities.end(), std::pair<int, int>(
strip, actualStripADC));
1156 adc_start_point_cluster_pw = 0;
1157 isPossible_wrong_minimum =
false;
1158 strip_first_gradient = 0;
1159 first_start_cluster_strip = 0;
1160 first_start_cluster_ADC = 0;
1163 if ((isMax) && ((actualStripADC - previousStripADC) >= 0) &&
1164 (!isAuxiliary_Minimum)) {
1165 if ((
std::abs(first_start_cluster_ADC - singleAPVdigi[
strip + 1]) > first_gradient) &&
1166 (isPossible_wrong_minimum)) {
1167 discontinuities.erase(itdiscontinuities);
1168 discontinuities.insert(discontinuities.end(),
1169 std::pair<int, int>(strip_first_gradient, adc_start_point_cluster_pw));
1172 if ((discontinuities.size() % 2 == 0) && (discontinuities.size() > 1)) {
1173 discontinuities.erase(--discontinuities.end());
1175 discontinuities.insert(discontinuities.end(), std::pair<int, int>(
strip - 1, previousStripADC));
1177 adc_start_point_cluster_pw = 0;
1178 isPossible_wrong_minimum =
false;
1179 strip_first_gradient = 0;
1180 first_start_cluster_strip = 0;
1181 first_start_cluster_ADC = 0;
1188 if (!discontinuities.empty()) {
1190 discontinuities.insert(discontinuities.end(),
1192 if ((isMax) && (isAuxiliary_Minimum))
1193 discontinuities.insert(discontinuities.end(),
1194 std::pair<int, int>(auxiliary_end_cluster, first_start_cluster_ADC));
1198 itdiscontinuities = discontinuities.begin();
1199 ++itdiscontinuities;
1200 ++itdiscontinuities;
1201 int firstADC = itdiscontinuities->second;
1202 --itdiscontinuities;
1203 itdiscontinuities->second = firstADC;
1204 --itdiscontinuities;
1205 itdiscontinuities->second = firstADC;
1208 if (!discontinuities.empty()) {
1209 itdiscontinuities = discontinuities.begin();
1210 uint16_t firstStrip = itdiscontinuities->first;
1211 int16_t firstADC = itdiscontinuities->second;
1212 ++itdiscontinuities;
1213 uint16_t lastStrip = itdiscontinuities->first;
1214 int16_t secondADC = itdiscontinuities->second;
1215 ++itdiscontinuities;
1218 if (
strip > lastStrip && itdiscontinuities != discontinuities.end()) {
1219 firstStrip = itdiscontinuities->first;
1220 firstADC = itdiscontinuities->second;
1221 ++itdiscontinuities;
1222 lastStrip = itdiscontinuities->first;
1223 secondADC = itdiscontinuities->second;
1224 ++itdiscontinuities;
1227 if ((firstStrip <=
strip) && (
strip <= lastStrip) &&
1228 (0 < (singleAPVdigi[
strip] - firstADC -
1231 singleAPVdigi[
strip] - firstADC -
1232 (((secondADC - firstADC) / (lastStrip - firstStrip)) * (
strip - firstStrip));
1242 desc.add(
"ForceNoRestore",
false);
1245 desc.add(
"useRealMeanCM",
false);
1246 desc.add(
"MeanCM", 0);
1247 desc.add(
"DeltaCMThreshold", 20
U);
1248 desc.add(
"Fraction", 0.2);
1249 desc.add(
"Deviation", 25
U);
1250 desc.add(
"restoreThreshold", 0.5);
1251 desc.add(
"nSaturatedStrip", 2
U);
1252 desc.add(
"nSigmaNoiseDerTh", 4
U);
1253 desc.add(
"consecThreshold", 5
U);
1254 desc.add(
"nSmooth", 9
U);
1255 desc.add(
"distortionThreshold", 20
U);
1256 desc.add(
"ApplyBaselineCleaner",
true);
1257 desc.add(
"CleaningSequence", 1
U);
1258 desc.add(
"slopeX", 3);
1259 desc.add(
"slopeY", 4);
1260 desc.add(
"hitStripThreshold", 40
U);
1261 desc.add(
"minStripsToFit", 4
U);
1262 desc.add(
"ApplyBaselineRejection",
true);
1263 desc.add(
"filteredBaselineMax", 6.0);
1264 desc.add(
"filteredBaselineDerivativeSumSquare", 30.0);
1265 desc.add(
"discontinuityThreshold", 12);
1266 desc.add(
"lastGradient", 10);
1267 desc.add(
"sizeWindow", 1);
1268 desc.add(
"widthCluster", 64);
edm::ESWatcher< SiStripQualityRcd > qualityWatcher_
SiStripAPVRestorer(const edm::ParameterSet &conf, edm::ConsumesCollector)
uint32_t nSaturatedStrip_
const Range getRange(const uint32_t &detID) const
void init(const edm::EventSetup &es)
bool IsApvBad(uint32_t detid, short apvNb) const
uint32_t cleaningSequence_
static void fillDescriptions(edm::ParameterSetDescription &desc)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
uint32_t deltaCMThreshold_
void baselineFollowerRestore(uint16_t apvN, uint16_t firstAPV, float median, digivector_t &digis)
bool applyBaselineRejection_
uint16_t baselineAndSaturationInspect(uint16_t firstAPV, const digivector_t &digis)
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
A signed Digi for the silicon strip detector, containing only adc information, and suitable for stori...
const SiStripPedestals * pedestalHandle
std::map< uint16_t, digimap_t > smoothedMaps_
uint16_t baselineFollowerInspect(uint16_t firstAPV, const digivector_t &digis)
double filteredBaselineDerivativeSumSquare_
uint32_t nSigmaNoiseDerTh_
const Range getRange(const uint32_t detID) const
void flatRestore(uint16_t apvN, uint16_t firstAPV, digivector_t &digis)
edm::ESGetToken< SiStripQuality, SiStripQualityRcd > qualityToken_
float getPed(const uint16_t &strip, const Range &range) const
static std::string const input
edm::ESWatcher< SiStripNoisesRcd > noiseWatcher_
void baselineFollower(const digimap_t &, digivector_t &baseline, float median)
void loadMeanCMMap(const edm::Event &)
U second(std::pair< T, U > const &p)
const float & adc() const
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > siStripRawDigiToken_
uint16_t hybridEmulationInspect(uint16_t firstAPV, const digivector_t &digis)
std::vector< std::string > apvFlags_
baselinemap_t baselineMap_
static float getNoiseFast(const uint16_t &strip, const Range &range)
const SiStripQuality * qualityHandle
bool checkBaseline(const std::vector< int16_t > &baseline) const
void baselineCleaner(const digivector_t &adcs, digimap_t &smoothedpoints, uint16_t apvN)
void cleaner_LocalMinimumAdder(const digivector_t &adcs, digimap_t &smoothedpoints, uint16_t apvN)
double filteredBaselineMax_
void cleaner_HighSlopeChecker(digimap_t &smoothedpoints)
Abs< T >::type abs(const T &t)
const SiStripNoises * noiseHandle
edm::EDGetTokenT< edm::DetSetVector< SiStripProcessedRawDigi > > siStripProcessedRawDigiToken_
bool flatRegionsFinder(const digivector_t &adcs, digimap_t &smoothedpoints, uint16_t apvN)
void cleaner_MonotonyChecker(digimap_t &smoothedpoints)
uint16_t inspectAndRestore(uint32_t detId, uint16_t firstAPV, const digivector_t &rawDigisPedSubtracted, digivector_t &processedRawDigi, const medians_t &vmedians)
void derivativeFollowerRestore(uint16_t apvN, uint16_t firstAPV, digivector_t &digis)
void createCMMapCMstored(const edm::DetSetVector< SiStripProcessedRawDigi > &input)
edm::ESGetToken< SiStripPedestals, SiStripPedestalsRcd > pedestalToken_
uint32_t consecThreshold_
uint16_t hybridFormatInspect(uint16_t firstAPV, const digivector_t &digis)
edm::ESWatcher< SiStripPedestalsRcd > pedestalWatcher_
std::vector< bool > apvFlagsBoolOverride_
std::map< uint16_t, digi_t > digimap_t
bool IsStripBad(uint32_t detid, short strip) const
edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > noiseToken_
uint16_t nullInspect(uint16_t firstAPV, const digivector_t &digis)
std::vector< std::pair< short, float > > medians_t
std::vector< bool > badAPVs_
bool check(const edm::EventSetup &iSetup)
const Range getRange(const uint32_t detID) const
std::vector< bool > apvFlagsBool_
uint16_t abnormalBaselineInspect(uint16_t firstAPV, const digivector_t &digis)
std::pair< ContainerIterator, ContainerIterator > Range
std::vector< digi_t > digivector_t
bool applyBaselineCleaner_
std::vector< float > median_
uint32_t distortionThreshold_
void restore(uint16_t firstAPV, digivector_t &digis)
uint16_t forceRestoreInspect(uint16_t firstAPV, const digivector_t &digis)
uint32_t hitStripThreshold_
static constexpr uint16_t nTotStripsPerAPV
Log< level::Warning, false > LogWarning
std::pair< ContainerIterator, ContainerIterator > Range
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
void createCMMapRealPed(const edm::DetSetVector< SiStripRawDigi > &input)
uint16_t *__restrict__ uint16_t const *__restrict__ adc
uint16_t inspect(uint32_t detId, uint16_t firstAPV, const digivector_t &digis, const medians_t &vmedians)