10 : quality_cache_id(-1),
12 pedestal_cache_id(-1),
13 forceNoRestore_(conf.getParameter<
bool>(
"ForceNoRestore")),
14 inspectAlgo_(conf.getParameter<
std::
string>(
"APVInspectMode")),
15 restoreAlgo_(conf.getParameter<
std::
string>(
"APVRestoreMode")),
17 useRealMeanCM_(conf.getParameter<
bool>(
"useRealMeanCM")),
18 meanCM_(conf.getParameter<int32_t>(
"MeanCM")),
19 deltaCMThreshold_(conf.getParameter<uint32_t>(
"DeltaCMThreshold")),
21 fraction_(conf.getParameter<double>(
"Fraction")),
22 deviation_(conf.getParameter<uint32_t>(
"Deviation")),
24 restoreThreshold_(conf.getParameter<double>(
"restoreThreshold")),
26 nSaturatedStrip_(conf.getParameter<uint32_t>(
"nSaturatedStrip")),
28 nSigmaNoiseDerTh_(conf.getParameter<uint32_t>(
"nSigmaNoiseDerTh")),
29 consecThreshold_(conf.getParameter<uint32_t>(
"consecThreshold")),
30 nSmooth_(conf.getParameter<uint32_t>(
"nSmooth")),
31 distortionThreshold_(conf.getParameter<uint32_t>(
"distortionThreshold")),
32 applyBaselineCleaner_(conf.getParameter<
bool>(
"ApplyBaselineCleaner")),
33 cleaningSequence_(conf.getParameter<uint32_t>(
"CleaningSequence")),
35 slopeX_(conf.getParameter<int32_t>(
"slopeX")),
36 slopeY_(conf.getParameter<int32_t>(
"slopeY")),
38 hitStripThreshold_(conf.getParameter<uint32_t>(
"hitStripThreshold")),
40 minStripsToFit_(conf.getParameter<uint32_t>(
"minStripsToFit")),
41 applyBaselineRejection_(conf.getParameter<
bool>(
"ApplyBaselineRejection")),
42 filteredBaselineMax_(conf.getParameter<double>(
"filteredBaselineMax")),
43 filteredBaselineDerivativeSumSquare_(conf.getParameter<double>(
"filteredBaselineDerivativeSumSquare")),
45 gradient_threshold_(conf.getParameter<
int>(
"discontinuityThreshold")),
46 last_gradient_(conf.getParameter<
int>(
"lastGradient")),
47 size_window_(conf.getParameter<
int>(
"sizeWindow")),
48 width_cluster_(conf.getParameter<
int>(
"widthCluster")) {
51 <<
"The BaselineFollower restore method requires the BaselineFollower (or Hybrid) inspect method";
85 auto nAPVFlagged =
inspect(detId, firstAPV, rawDigisPedSubtracted, vmedians);
86 restore(firstAPV, processedRawDigi);
103 for (
const auto& med : vmedians) {
104 auto iAPV = med.first;
109 uint16_t nAPVFlagged = 0;
126 <<
"SiStripAPVRestorer possibilities: (Null), (AbnormalBaseline), (BaselineFollower), (BaselineAndSaturation), "
127 "(DerivativeFollower), (Hybrid), (HybridEmulation)";
141 for (uint16_t iAPV = firstAPV; iAPV < digis.size() /
nTotStripsPerAPV + firstAPV; ++iAPV) {
143 if (!algoToUse.empty()) {
144 if (algoToUse ==
"Flat") {
146 }
else if (algoToUse ==
"BaselineFollower") {
148 }
else if (algoToUse ==
"DerivativeFollower") {
152 <<
"SiStripAPVRestorer possibilities: (Flat), (BaselineFollower), (DerivativeFollower)";
163 uint16_t nAPVflagged = 0;
164 for (uint16_t iAPV = firstAPV; iAPV < digis.size() /
nTotStripsPerAPV + firstAPV; ++iAPV) {
167 uint16_t stripsPerAPV = 0;
168 singleAPVdigi.clear();
172 singleAPVdigi.push_back(
adc);
177 if (stripsPerAPV > 64) {
191 uint16_t nAPVflagged = 0;
197 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
202 MeanAPVCM = itCMMap->second[iAPV];
204 singleAPVdigi.clear();
207 std::back_inserter(singleAPVdigi));
209 const float DeltaCM =
median_[iAPV] - MeanAPVCM;
223 uint16_t nAPVflagged = 0;
224 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
236 uint16_t nAPVflagged = 0;
242 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
246 MeanAPVCM = itCMMap->second[iAPV];
248 singleAPVdigi.clear();
249 uint16_t nSatStrip = 0;
252 const uint16_t digi = digis[
strip];
253 singleAPVdigi.push_back(digi);
258 const float DeltaCM =
median_[iAPV] - MeanAPVCM;
271 uint16_t nAPVflagged = 0;
277 int devCount = 0, qualityCount = 0, minstrip = 0;
278 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
282 MeanAPVCM = itCMMap->second[iAPV];
285 const auto fs = static_cast<int>(digis[istrip - firstAPV *
nTotStripsPerAPV]);
294 if (devCount >
fraction_ * qualityCount) {
306 uint16_t nAPVflagged = 0;
307 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
309 int zeroCount = 0, qualityCount = 0;
311 const auto fs = static_cast<int>(digis[istrip - firstAPV *
nTotStripsPerAPV]);
328 uint16_t nAPVflagged = 0;
334 for (uint16_t iAPV = firstAPV; iAPV < firstAPV + digis.size() /
nTotStripsPerAPV; ++iAPV) {
338 MeanAPVCM = itCMMap->second[iAPV];
340 const float DeltaCM =
median_[iAPV] - (MeanAPVCM + 1024) / 2;
400 smoothedpoints.clear();
407 float localmin = 999.9;
408 for (uint16_t jstrip =
std::max(0, static_cast<int>(istrip -
nSmooth_ / 2));
409 jstrip < std::min((int)nTotStripsPerAPV, static_cast<int>(istrip +
nSmooth_ / 2));
411 const float nextvalue = adcs[jstrip];
412 if (nextvalue < localmin)
413 localmin = nextvalue;
415 adcsLocalMinSubtracted[istrip] = adcs[istrip] - localmin;
420 std::vector<uint16_t> nConsStrip;
422 uint16_t consecStrips = 0;
424 const int16_t
adc = adcs[istrip];
426 if (adcsLocalMinSubtracted[istrip] <
428 consecpoints.emplace_hint(consecpoints.end(), istrip,
adc);
430 }
else if (consecStrips > 0) {
431 nConsStrip.push_back(consecStrips);
436 if (consecStrips > 0)
437 nConsStrip.push_back(consecStrips);
440 auto itConsecpoints = consecpoints.begin();
441 float MinSmoothValue = 20000., MaxSmoothValue = 0.;
442 for (
const auto consecStrips : nConsStrip) {
445 uint16_t nFirstStrip = itConsecpoints->first;
447 float smoothValue = 0.0;
448 float stripCount = 1;
449 for (uint16_t
n = 0;
n < consecStrips - 2; ++
n) {
450 smoothValue += itConsecpoints->second;
452 smoothValue /= (
float)stripCount;
453 nLastStrip = nFirstStrip + stripCount - 1;
454 smoothedpoints.emplace_hint(smoothedpoints.end(), nFirstStrip, smoothValue);
455 smoothedpoints.emplace_hint(smoothedpoints.end(), nLastStrip, smoothValue);
456 if (smoothValue > MaxSmoothValue)
457 MaxSmoothValue = smoothValue;
458 if (smoothValue < MinSmoothValue)
459 MinSmoothValue = smoothValue;
460 nFirstStrip = nLastStrip + 1;
469 if (stripCount > 1) {
472 smoothValue /= static_cast<float>(stripCount);
473 nLastStrip = nFirstStrip + stripCount - 1;
474 smoothedpoints.emplace_hint(smoothedpoints.end(), nFirstStrip, smoothValue);
475 smoothedpoints.emplace_hint(smoothedpoints.end(), nLastStrip, smoothValue);
476 if (smoothValue > MaxSmoothValue)
477 MaxSmoothValue = smoothValue;
478 if (smoothValue < MinSmoothValue)
479 MinSmoothValue = smoothValue;
482 for (
int n = 0;
n < consecStrips; ++
n)
517 if (smoothedpoints.size() < 3)
520 auto it = smoothedpoints.begin();
521 while (smoothedpoints.size() > 3 && it != --(--smoothedpoints.end())) {
524 const float adc1 = it2->second;
525 const float adc2 = (++it2)->
second;
526 const float adc3 = (++it2)->
second;
529 smoothedpoints.erase(--it2);
544 if (smoothedpoints.size() >= 2) {
545 for (
auto it = smoothedpoints.begin(); it != --smoothedpoints.end(); ++it) {
548 const float strip1 = it->first;
549 const float strip2 = itNext->first;
550 const float adc1 = it->second;
551 const float adc2 = itNext->second;
552 const float m = (adc2 - adc1) / (strip2 - strip1);
557 float strip = itStrip + strip1;
558 while (
strip < strip2) {
562 if (
adc < (adc1 +
m * itStrip - 2 *
noise)) {
563 smoothedpoints.emplace_hint(itNext,
strip,
adc);
573 const uint16_t firstStripFlat = smoothedpoints.begin()->first;
574 const uint16_t lastStripFlat = (--smoothedpoints.end())->
first;
575 const int16_t firstStripFlatADC = smoothedpoints.begin()->second;
576 const int16_t lastStripFlatADC = (--smoothedpoints.end())->
second;
577 if (firstStripFlat > 3) {
578 auto it = smoothedpoints.begin();
580 while (
strip < firstStripFlat) {
583 if (
adc < (firstStripFlatADC - 2 *
noise)) {
584 smoothedpoints.emplace_hint(it,
strip,
adc);
591 float strip = lastStripFlat + 1;
595 if (
adc < (lastStripFlatADC - 2 *
noise)) {
596 smoothedpoints.emplace_hint(smoothedpoints.end(),
strip,
adc);
606 if (smoothedpoints.size() < 4)
609 auto it = smoothedpoints.begin();
610 while (smoothedpoints.size() > 2 && it != --smoothedpoints.end()) {
615 const float strip1 = it->first;
616 const float strip2 = itNext->first;
617 const float adc1 = it->second;
618 const float adc2 = itNext->second;
619 const float m = (adc2 - adc1) / (strip2 - strip1);
622 smoothedpoints.erase(itNext);
625 if (it == smoothedpoints.begin())
626 smoothedpoints.erase(it++);
629 smoothedpoints.erase(it--);
645 const auto lastIt = --smoothedpoints.end();
646 const uint16_t firstStripFlat = smoothedpoints.begin()->first;
647 const uint16_t lastStripFlat = lastIt->first;
648 const int16_t firstStripFlatADC = smoothedpoints.begin()->second;
649 const int16_t lastStripFlatADC = lastIt->second;
652 baseline.erase(baseline.begin(), baseline.begin() + firstStripFlat);
653 baseline.insert(baseline.begin(), firstStripFlat, firstStripFlatADC);
655 baseline.erase(baseline.begin() + lastStripFlat, baseline.end());
656 baseline.insert(baseline.end(),
nTotStripsPerAPV - lastStripFlat, lastStripFlatADC);
659 for (
auto itSmoothedpoints = smoothedpoints.begin(); itSmoothedpoints != (--smoothedpoints.end());
660 ++itSmoothedpoints) {
661 auto itNextSmoothedpoints = itSmoothedpoints;
662 ++itNextSmoothedpoints;
663 const float strip1 = itSmoothedpoints->first;
664 const float strip2 = itNextSmoothedpoints->first;
665 const float adc1 = itSmoothedpoints->second;
666 const float adc2 = itNextSmoothedpoints->second;
668 baseline[strip1] = adc1;
669 baseline[strip2] = adc2;
670 const float m = (adc2 - adc1) / (strip2 - strip1);
671 uint16_t itStrip = strip1 + 1;
672 float stripadc = adc1 +
m;
673 while (itStrip < strip2) {
674 baseline[itStrip] = stripadc;
703 static const size_t savitzky_golay_n_l_r = 16;
704 static const float savitzky_golay_coefficient[2 * savitzky_golay_n_l_r + 1][2 * savitzky_golay_n_l_r + 1] = {
759 {0.172078, 0.153076, 0.135099, 0.118148, 0.102221, 0.0873206, 0.073445,
760 0.0605947, 0.0487697, 0.0379699, 0.0281955, 0.0194463, 0.0117225, 0.00502392,
761 -0.000649351, -0.00529733, -0.00892003, -0.0115174, -0.0130895, -0.0136364},
762 {0.123659, 0.116431, 0.109144, 0.101798, 0.0943921, 0.0869268, 0.0794021,
763 0.0718179, 0.0641743, 0.0564712, 0.0487087, 0.0408868, 0.0330054, 0.0250646,
764 0.0170644, 0.00900473, 0.000885613, -0.00729294, -0.0155309, -0.0238283, -0.0321852},
765 {0.0859684, 0.0868154, 0.0869565, 0.0863919, 0.0851214, 0.0831451, 0.080463, 0.0770751,
766 0.0729814, 0.0681818, 0.0626765, 0.0564653, 0.0495483, 0.0419255, 0.0335968, 0.0245624,
767 0.0148221, 0.00437606, -0.00677583, -0.0186335, -0.0311971, -0.0444664},
768 {0.0565217, 0.0628458, 0.0680971, 0.0722756, 0.0753811, 0.0774139, 0.0783738, 0.0782609,
769 0.0770751, 0.0748165, 0.071485, 0.0670807, 0.0616036, 0.0550536, 0.0474308, 0.0387352,
770 0.0289667, 0.0181254, 0.00621118, -0.00677583, -0.0208357, -0.0359684, -0.0521739},
771 {0.0334615, 0.0434281, 0.0521329, 0.0595759, 0.0657571, 0.0706765, 0.0743341, 0.07673,
772 0.0778641, 0.0777364, 0.0763469, 0.0736957, 0.0697826, 0.0646078, 0.0581712, 0.0504728,
773 0.0415126, 0.0312907, 0.0198069, 0.00706142, -0.00694588, -0.022215, -0.0387458, -0.0565385},
774 {0.0153846, 0.0276923, 0.0386622, 0.0482943, 0.0565886, 0.0635452, 0.0691639, 0.0734448, 0.076388,
775 0.0779933, 0.0782609, 0.0771906, 0.0747826, 0.0710368, 0.0659532, 0.0595318, 0.0517726, 0.0426756,
776 0.0322408, 0.0204682, 0.00735786, -0.0070903, -0.0228763, -0.04, -0.0584615},
777 {0.001221, 0.0149451, 0.027326, 0.0383639, 0.0480586, 0.0564103, 0.0634188, 0.0690842, 0.0734066,
778 0.0763858, 0.078022, 0.078315, 0.077265, 0.0748718, 0.0711355, 0.0660562, 0.0596337, 0.0518681,
779 0.0427595, 0.0323077, 0.0205128, 0.00737485, -0.00710623, -0.0229304, -0.0400977, -0.0586081},
780 {-0.00985222, 0.00463138, 0.0178098, 0.029683, 0.0402509, 0.0495137, 0.0574713, 0.0641236, 0.0694708,
781 0.0735127, 0.0762494, 0.0776809, 0.0778073, 0.0766284, 0.0741442, 0.0703549, 0.0652604, 0.0588607,
782 0.0511557, 0.0421456, 0.0318302, 0.0202097, 0.0072839, -0.00694708, -0.0224833, -0.0393247, -0.0574713},
783 {-0.0184729, -0.00369458, 0.00984169, 0.0221359, 0.0331881, 0.0429982, 0.0515662,
784 0.0588923, 0.0649762, 0.0698181, 0.073418, 0.0757758, 0.0768915, 0.0767652,
785 0.0753968, 0.0727864, 0.0689339, 0.0638394, 0.0575028, 0.0499242, 0.0411035,
786 0.0310408, 0.019736, 0.00718917, -0.00659972, -0.0216307, -0.0379037, -0.0554187},
787 {-0.025139, -0.0103925, 0.00318873, 0.0156046, 0.0268552, 0.0369405, 0.0458605, 0.0536151,
788 0.0602045, 0.0656285, 0.0698872, 0.0729806, 0.0749086, 0.0756714, 0.0752688, 0.0737009,
789 0.0709677, 0.0670692, 0.0620054, 0.0557763, 0.0483818, 0.039822, 0.0300969, 0.0192065,
790 0.0071508, -0.00607024, -0.0204566, -0.0360083, -0.0527253},
791 {-0.0302419, -0.0157536, -0.00234785, 0.00997537, 0.021216, 0.0313741, 0.0404497, 0.0484427,
792 0.0553532, 0.0611811, 0.0659264, 0.0695892, 0.0721695, 0.0736672, 0.0740823, 0.0734149,
793 0.0716649, 0.0688324, 0.0649174, 0.0599198, 0.0538396, 0.0466769, 0.0384316, 0.0291038,
794 0.0186934, 0.00720046, -0.00537502, -0.0190331, -0.0337736, -0.0495968},
795 {-0.0340909, -0.0200147, -0.006937, 0.00514208, 0.0162226, 0.0263045, 0.0353878, 0.0434725,
796 0.0505587, 0.0566463, 0.0617353, 0.0658257, 0.0689175, 0.0710107, 0.0721054, 0.0722014,
797 0.0712989, 0.0693978, 0.0664981, 0.0625999, 0.057703, 0.0518076, 0.0449135, 0.0370209,
798 0.0281297, 0.01824, 0.0073516, -0.00453534, -0.0174209, -0.031305, -0.0461877},
799 {-0.0369318, -0.0233688, -0.0107221, 0.00100806, 0.0118218, 0.0217192, 0.0307001, 0.0387647,
800 0.0459128, 0.0521444, 0.0574597, 0.0618585, 0.0653409, 0.0679069, 0.0695565, 0.0702896,
801 0.0701063, 0.0690066, 0.0669905, 0.0640579, 0.0602089, 0.0554435, 0.0497617, 0.0431635,
802 0.0356488, 0.0272177, 0.0178702, 0.0076063, -0.00357405, -0.0156708, -0.028684, -0.0426136},
803 {-0.038961, -0.025974, -0.0138249, -0.00251362, 0.00795978, 0.0175953, 0.026393, 0.0343527, 0.0414747,
804 0.0477587, 0.0532049, 0.0578132, 0.0615836, 0.0645161, 0.0666108, 0.0678676, 0.0682866, 0.0678676,
805 0.0666108, 0.0645161, 0.0615836, 0.0578132, 0.0532049, 0.0477587, 0.0414747, 0.0343527, 0.026393,
806 0.0175953, 0.00795978, -0.00251362, -0.0138249, -0.025974, -0.038961},
807 {-0.0426136, -0.028684, -0.0156708, -0.00357405, 0.0076063, 0.0178702, 0.0272177, 0.0356488,
808 0.0431635, 0.0497617, 0.0554435, 0.0602089, 0.0640579, 0.0669905, 0.0690066, 0.0701063,
809 0.0702896, 0.0695565, 0.0679069, 0.0653409, 0.0618585, 0.0574597, 0.0521444, 0.0459128,
810 0.0387647, 0.0307001, 0.0217192, 0.0118218, 0.00100806, -0.0107221, -0.0233688, -0.0369318},
811 {-0.0461877, -0.031305, -0.0174209, -0.00453534, 0.0073516, 0.01824, 0.0281297, 0.0370209,
812 0.0449135, 0.0518076, 0.057703, 0.0625999, 0.0664981, 0.0693978, 0.0712989, 0.0722014,
813 0.0721054, 0.0710107, 0.0689175, 0.0658257, 0.0617353, 0.0566463, 0.0505587, 0.0434725,
814 0.0353878, 0.0263045, 0.0162226, 0.00514208, -0.006937, -0.0200147, -0.0340909},
815 {-0.0495968, -0.0337736, -0.0190331, -0.00537502, 0.00720046, 0.0186934, 0.0291038, 0.0384316,
816 0.0466769, 0.0538396, 0.0599198, 0.0649174, 0.0688324, 0.0716649, 0.0734149, 0.0740823,
817 0.0736672, 0.0721695, 0.0695892, 0.0659264, 0.0611811, 0.0553532, 0.0484427, 0.0404497,
818 0.0313741, 0.021216, 0.00997537, -0.00234785, -0.0157536, -0.0302419},
819 {-0.0527253, -0.0360083, -0.0204566, -0.00607024, 0.0071508, 0.0192065, 0.0300969, 0.039822,
820 0.0483818, 0.0557763, 0.0620054, 0.0670692, 0.0709677, 0.0737009, 0.0752688, 0.0756714,
821 0.0749086, 0.0729806, 0.0698872, 0.0656285, 0.0602045, 0.0536151, 0.0458605, 0.0369405,
822 0.0268552, 0.0156046, 0.00318873, -0.0103925, -0.025139},
823 {-0.0554187, -0.0379037, -0.0216307, -0.00659972, 0.00718917, 0.019736, 0.0310408,
824 0.0411035, 0.0499242, 0.0575028, 0.0638394, 0.0689339, 0.0727864, 0.0753968,
825 0.0767652, 0.0768915, 0.0757758, 0.073418, 0.0698181, 0.0649762, 0.0588923,
826 0.0515662, 0.0429982, 0.0331881, 0.0221359, 0.00984169, -0.00369458, -0.0184729},
827 {-0.0574713, -0.0393247, -0.0224833, -0.00694708, 0.0072839, 0.0202097, 0.0318302, 0.0421456, 0.0511557,
828 0.0588607, 0.0652604, 0.0703549, 0.0741442, 0.0766284, 0.0778073, 0.0776809, 0.0762494, 0.0735127,
829 0.0694708, 0.0641236, 0.0574713, 0.0495137, 0.0402509, 0.029683, 0.0178098, 0.00463138, -0.00985222},
830 {-0.0586081, -0.0400977, -0.0229304, -0.00710623, 0.00737485, 0.0205128, 0.0323077, 0.0427595, 0.0518681,
831 0.0596337, 0.0660562, 0.0711355, 0.0748718, 0.077265, 0.078315, 0.078022, 0.0763858, 0.0734066,
832 0.0690842, 0.0634188, 0.0564103, 0.0480586, 0.0383639, 0.027326, 0.0149451, 0.001221},
833 {-0.0584615, -0.04, -0.0228763, -0.0070903, 0.00735786, 0.0204682, 0.0322408, 0.0426756, 0.0517726,
834 0.0595318, 0.0659532, 0.0710368, 0.0747826, 0.0771906, 0.0782609, 0.0779933, 0.076388, 0.0734448,
835 0.0691639, 0.0635452, 0.0565886, 0.0482943, 0.0386622, 0.0276923, 0.0153846},
836 {-0.0565385, -0.0387458, -0.022215, -0.00694588, 0.00706142, 0.0198069, 0.0312907, 0.0415126,
837 0.0504728, 0.0581712, 0.0646078, 0.0697826, 0.0736957, 0.0763469, 0.0777364, 0.0778641,
838 0.07673, 0.0743341, 0.0706765, 0.0657571, 0.0595759, 0.0521329, 0.0434281, 0.0334615},
839 {-0.0521739, -0.0359684, -0.0208357, -0.00677583, 0.00621118, 0.0181254, 0.0289667, 0.0387352,
840 0.0474308, 0.0550536, 0.0616036, 0.0670807, 0.071485, 0.0748165, 0.0770751, 0.0782609,
841 0.0783738, 0.0774139, 0.0753811, 0.0722756, 0.0680971, 0.0628458, 0.0565217},
842 {-0.0444664, -0.0311971, -0.0186335, -0.00677583, 0.00437606, 0.0148221, 0.0245624, 0.0335968,
843 0.0419255, 0.0495483, 0.0564653, 0.0626765, 0.0681818, 0.0729814, 0.0770751, 0.080463,
844 0.0831451, 0.0851214, 0.0863919, 0.0869565, 0.0868154, 0.0859684},
845 {-0.0321852, -0.0238283, -0.0155309, -0.00729294, 0.000885613, 0.00900473, 0.0170644,
846 0.0250646, 0.0330054, 0.0408868, 0.0487087, 0.0564712, 0.0641743, 0.0718179,
847 0.0794021, 0.0869268, 0.0943921, 0.101798, 0.109144, 0.116431, 0.123659},
848 {-0.0136364, -0.0130895, -0.0115174, -0.00892003, -0.00529733, -0.000649351, 0.00502392,
849 0.0117225, 0.0194463, 0.0281955, 0.0379699, 0.0487697, 0.0605947, 0.073445,
850 0.0873206, 0.102221, 0.118148, 0.135099, 0.153076, 0.172078},
913 for (
size_t i = 0;
i < savitzky_golay_n_l_r;
i++) {
914 for (
size_t j = 0;
j < savitzky_golay_n_l_r + 1 +
i;
j++) {
915 filtered_baseline[
i] += savitzky_golay_coefficient[
i][
j] * baseline[
j];
922 filtered_baseline[
i] = savitzky_golay_coefficient[savitzky_golay_n_l_r][savitzky_golay_n_l_r] * baseline[
i];
923 for (
size_t j = 0;
j < savitzky_golay_n_l_r;
j++) {
924 filtered_baseline[
i] += savitzky_golay_coefficient[savitzky_golay_n_l_r][
j] *
925 (baseline[
i +
j - savitzky_golay_n_l_r] + baseline[
i -
j + savitzky_golay_n_l_r]);
930 for (
size_t j = 0;
j < 2 * savitzky_golay_n_l_r + 1;
j++) {
932 savitzky_golay_coefficient[savitzky_golay_n_l_r][
j] *
933 baseline[
i +
j - savitzky_golay_n_l_r];
942 filtered_baseline[
i] += savitzky_golay_coefficient[2 * savitzky_golay_n_l_r +
i + 1 -
nTotStripsPerAPV][
j] *
943 baseline[
i +
j - savitzky_golay_n_l_r];
950 filtered_baseline_derivative[
i] = filtered_baseline[
i + 1] - filtered_baseline[
i];
956 double filtered_baseline_max = 0;
957 double filtered_baseline_derivative_sum_square = 0;
960 const double d = filtered_baseline[
i] - baseline[
i];
962 filtered_baseline_max =
std::max(filtered_baseline_max, static_cast<double>(fabs(
d)));
965 filtered_baseline_derivative_sum_square += filtered_baseline_derivative[
i] * filtered_baseline_derivative[
i];
969 std::cerr << __FILE__ <<
':' << __LINE__ <<
": "
970 << filtered_baseline_max <<
' '
971 << filtered_baseline_derivative_sum_square << std::endl;
985 iEvent.getByLabel(
"siStripDigis",
"VirginRaw",
input);
989 iEvent.getByLabel(
"MEANAPVCM", inputCM);
995 for (
const auto& rawDigis :
input) {
998 std::vector<float> meanCMDetSet;
999 meanCMDetSet.reserve(nAPVs);
1000 for (uint16_t iAPV = 0; iAPV < nAPVs; ++iAPV) {
1007 meanCMDetSet.push_back(minPed);
1014 for (
const auto& rawDigis :
input) {
1015 std::vector<float> meanCMNValue;
1016 meanCMNValue.reserve(rawDigis.size());
1029 singleAPVdigi.clear();
1031 singleAPVdigi.push_back(digis[
strip] + 1024);
1034 discontinuities.clear();
1036 digimap_t::iterator itdiscontinuities;
1040 bool isMinimumAndNoMax =
false;
1041 bool isFirstStrip =
false;
1045 int actualStripADC = 0;
1046 int previousStripADC = 0;
1049 int maximum_value = 0;
1050 const uint32_t n_high_maximum_cluster = 1025 + 1024;
1051 int high_maximum_cluster = n_high_maximum_cluster;
1052 int number_good_minimum = 0;
1053 int first_gradient = 0;
1054 int strip_first_gradient = 0;
1055 int adc_start_point_cluster_pw = 0;
1056 int auxiliary_end_cluster = 0;
1057 int first_start_cluster_strip = 0;
1058 int first_start_cluster_ADC = 0;
1059 bool isAuxiliary_Minimum =
false;
1060 bool isPossible_wrong_minimum =
false;
1067 actualStripADC = singleAPVdigi[
strip];
1069 isFirstStrip =
true;
1070 isMinimumAndNoMax =
true;
1071 discontinuities.insert(discontinuities.end(), std::pair<int, int>(
strip, actualStripADC));
1073 discontinuities.insert(discontinuities.end(), std::pair<uint16_t, int16_t>(
strip, 0 + 1024));
1074 isMinimumAndNoMax =
true;
1075 first_start_cluster_strip =
strip;
1076 first_start_cluster_ADC = 1024;
1080 previousStripADC = actualStripADC;
1081 actualStripADC = singleAPVdigi[
strip];
1082 greadient = actualStripADC - previousStripADC;
1087 discontinuities.size() > 1)) {
1089 isPossible_wrong_minimum =
true;
1090 itdiscontinuities = --discontinuities.end();
1091 if (discontinuities.size() > 1) {
1092 --itdiscontinuities;
1094 strip_first_gradient = itdiscontinuities->first;
1095 adc_start_point_cluster_pw = itdiscontinuities->second;
1096 first_gradient =
std::abs(adc_start_point_cluster_pw - singleAPVdigi[strip_first_gradient + 1]);
1097 discontinuities.erase(++itdiscontinuities);
1098 discontinuities.erase(--discontinuities.end());
1101 if ((discontinuities.size() % 2 == 1) && (!discontinuities.empty())) {
1102 discontinuities.erase(--discontinuities.end());
1105 discontinuities.insert(discontinuities.end(), std::pair<uint16_t, int16_t>(
strip - 1, previousStripADC));
1106 isMinimumAndNoMax =
true;
1108 first_start_cluster_strip =
strip - 1;
1109 first_start_cluster_ADC = previousStripADC;
1111 }
else if ((!isMax) && ((actualStripADC - previousStripADC < 0) && (isMinimumAndNoMax))) {
1113 isMinimumAndNoMax =
false;
1114 high_maximum_cluster = n_high_maximum_cluster;
1115 if ((previousStripADC > maximum_value) && (discontinuities.size() % 2 == 1))
1116 maximum_value = previousStripADC;
1120 if (high_maximum_cluster > (
std::abs(singleAPVdigi[
strip + 1] - actualStripADC))) {
1121 high_maximum_cluster = singleAPVdigi[
strip + 1] - actualStripADC;
1122 auxiliary_end_cluster =
strip + 2;
1128 if ((isMax) && ((actualStripADC - previousStripADC) >= 0) && (
size_window_ > 0) &&
1130 number_good_minimum = 0;
1131 for (uint16_t wintry = 0; wintry <=
size_window_; wintry++) {
1133 ++number_good_minimum;
1135 --number_good_minimum;
1139 isMinimumAndNoMax =
true;
1144 isAuxiliary_Minimum =
true;
1147 if (!discontinuities.empty()) {
1148 itdiscontinuities = --discontinuities.end();
1151 if ((isMax) && (actualStripADC <= first_start_cluster_ADC)) {
1152 if ((
std::abs(first_start_cluster_ADC - singleAPVdigi[
strip + 2]) > first_gradient) &&
1153 (isPossible_wrong_minimum)) {
1154 discontinuities.erase(itdiscontinuities);
1155 discontinuities.insert(discontinuities.end(),
1156 std::pair<int, int>(strip_first_gradient, adc_start_point_cluster_pw));
1157 discontinuities.insert(discontinuities.end(), std::pair<int, int>(
strip, adc_start_point_cluster_pw));
1159 if ((discontinuities.size() % 2 == 0) && (discontinuities.size() > 1)) {
1160 discontinuities.erase(--discontinuities.end());
1162 discontinuities.insert(discontinuities.end(), std::pair<int, int>(
strip, actualStripADC));
1165 adc_start_point_cluster_pw = 0;
1166 isPossible_wrong_minimum =
false;
1167 strip_first_gradient = 0;
1168 first_start_cluster_strip = 0;
1169 first_start_cluster_ADC = 0;
1172 if ((isMax) && ((actualStripADC - previousStripADC) >= 0) &&
1173 (!isAuxiliary_Minimum)) {
1174 if ((
std::abs(first_start_cluster_ADC - singleAPVdigi[
strip + 1]) > first_gradient) &&
1175 (isPossible_wrong_minimum)) {
1176 discontinuities.erase(itdiscontinuities);
1177 discontinuities.insert(discontinuities.end(),
1178 std::pair<int, int>(strip_first_gradient, adc_start_point_cluster_pw));
1181 if ((discontinuities.size() % 2 == 0) && (discontinuities.size() > 1)) {
1182 discontinuities.erase(--discontinuities.end());
1184 discontinuities.insert(discontinuities.end(), std::pair<int, int>(
strip - 1, previousStripADC));
1186 adc_start_point_cluster_pw = 0;
1187 isPossible_wrong_minimum =
false;
1188 strip_first_gradient = 0;
1189 first_start_cluster_strip = 0;
1190 first_start_cluster_ADC = 0;
1197 if (!discontinuities.empty()) {
1199 discontinuities.insert(discontinuities.end(),
1201 if ((isMax) && (isAuxiliary_Minimum))
1202 discontinuities.insert(discontinuities.end(),
1203 std::pair<int, int>(auxiliary_end_cluster, first_start_cluster_ADC));
1207 itdiscontinuities = discontinuities.begin();
1208 ++itdiscontinuities;
1209 ++itdiscontinuities;
1210 int firstADC = itdiscontinuities->second;
1211 --itdiscontinuities;
1212 itdiscontinuities->second = firstADC;
1213 --itdiscontinuities;
1214 itdiscontinuities->second = firstADC;
1217 if (!discontinuities.empty()) {
1218 itdiscontinuities = discontinuities.begin();
1219 uint16_t firstStrip = itdiscontinuities->first;
1220 int16_t firstADC = itdiscontinuities->second;
1221 ++itdiscontinuities;
1222 uint16_t lastStrip = itdiscontinuities->first;
1223 int16_t secondADC = itdiscontinuities->second;
1224 ++itdiscontinuities;
1227 if (
strip > lastStrip && itdiscontinuities != discontinuities.end()) {
1228 firstStrip = itdiscontinuities->first;
1229 firstADC = itdiscontinuities->second;
1230 ++itdiscontinuities;
1231 lastStrip = itdiscontinuities->first;
1232 secondADC = itdiscontinuities->second;
1233 ++itdiscontinuities;
1236 if ((firstStrip <=
strip) && (
strip <= lastStrip) &&
1237 (0 < (singleAPVdigi[
strip] - firstADC -
1240 singleAPVdigi[
strip] - firstADC -
1241 (((secondADC - firstADC) / (lastStrip - firstStrip)) * (
strip - firstStrip));