137 size_t maxTimeSamples(wireToRawDigitVecMap.begin()->second.size());
138 size_t baseWireIdx(wireToRawDigitVecMap.begin()->first - wireToRawDigitVecMap.begin()->first %
fNumWiresToGroup[planeIdx]);
140 std::vector<float> corValVec(maxTimeSamples);
144 if (wireToAdcIdxMap.size() > 2)
147 std::fill(corValVec.begin(),corValVec.end(),0.);
150 for(
size_t sampleIdx = 0; sampleIdx < maxTimeSamples; sampleIdx++)
155 std::vector<float> adcValuesVec;
157 for(
const auto& wireAdcItr : wireToAdcIdxMap)
161 if (sampleIdx < wireAdcItr.second.first || sampleIdx >= wireAdcItr.second.second)
continue;
163 int wireIdx(wireAdcItr.first - baseWireIdx);
166 adcValuesVec.push_back(
float(wireToRawDigitVecMap.at(wireAdcItr.first)[sampleIdx]) - truncMeanWireVec[wireIdx]);
170 float aveValue = std::accumulate(adcValuesVec.begin(),adcValuesVec.end(),0.) / float(adcValuesVec.size());
173 corValVec[sampleIdx] = aveValue;
181 std::vector<std::complex<double>> fftOutputVec(halfFFTSize);
183 lfftw.DoFFT(corValVec, fftOutputVec);
185 std::vector<double> powerVec(halfFFTSize);
186 std::transform(fftOutputVec.begin(), fftOutputVec.begin() + halfFFTSize, powerVec.begin(), [](
const auto& val){
return std::abs(val);});
189 std::vector<double> firstDerivVec(powerVec.size(), 0.);
192 for(
size_t idx = 1; idx < firstDerivVec.size() - 1; idx++)
193 firstDerivVec.at(idx) = 0.5 * (powerVec.at(idx + 1) - powerVec.at(idx - 1));
196 std::vector<std::tuple<size_t,size_t,size_t>> peakTupleVec;
200 if (!peakTupleVec.empty())
202 for(
const auto& peakTuple : peakTupleVec)
204 size_t startTick = std::get<0>(peakTuple);
205 size_t stopTick = std::get<2>(peakTuple);
207 if (stopTick > startTick)
209 std::complex<double> slope = (fftOutputVec[stopTick] - fftOutputVec[startTick]) /
double(stopTick - startTick);
213 std::complex<double> interpVal = fftOutputVec[startTick] + double(
tick - startTick) * slope;
215 fftOutputVec[
tick] = interpVal;
221 std::vector<double> tmpVec(corValVec.size());
223 lfftw.DoInvFFT(fftOutputVec, tmpVec);
225 std::transform(corValVec.begin(),corValVec.end(),tmpVec.begin(),corValVec.begin(),std::minus<double>());
230 for(
size_t sampleIdx = 0; sampleIdx < maxTimeSamples; sampleIdx++)
233 for (
const auto& wireAdcItr : wireToAdcIdxMap)
235 float corVal(corValVec[sampleIdx]);
236 int wireIdx(wireAdcItr.first - baseWireIdx);
241 if (sampleIdx < wireAdcItr.second.first || sampleIdx >= wireAdcItr.second.second)
245 short& rawDataTimeVal = wireToRawDigitVecMap.at(wireAdcItr.first)[sampleIdx];
248 float newAdcValueFloat = float(rawDataTimeVal) - corVal - pedCorWireVec[wireIdx];
249 rawDataTimeVal = std::round(newAdcValueFloat);
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
std::map< size_t, RawDigitVector & > WireToRawDigitVecMap
std::map< size_t, RawDigitVectorIdxPair > WireToAdcIdxMap