4 #include "art/Framework/Core/ModuleMacros.h"
5 #include "messagefacility/MessageLogger/MessageLogger.h"
19 fHistsInitialized(
false),
21 fPedestalRetrievalAlg(art::ServiceHandle<lariov::DetPedestalService>()->GetPedestalProvider())
27 mf::LogInfo(
"RawDigitCharacterizationAlg") <<
"RawDigitCharacterizationAlg configured\n";
45 fRmsRejectionCutHi = pset.get<std::vector<float>> (
"RMSRejectionCutHi", std::vector<float>() = {25.0,25.0,25.0});
46 fRmsRejectionCutLow = pset.get<std::vector<float>> (
"RMSRejectionCutLow", std::vector<float>() = {0.70,0.70,0.70});
47 fRmsSelectionCut = pset.get<std::vector<float>> (
"RMSSelectionCut", std::vector<float>() = {1.40,1.40,1.00});
48 fMinMaxSelectionCut = pset.get<std::vector<short>> (
"MinMaxSelectionCut", std::vector<short>() = {13, 13, 11});
51 fHistsWireGroup = pset.get<std::vector<size_t>>(
"FFTHistsWireGroup", std::vector<size_t>() = {1, 33, 34});
52 fNumWiresToGroup = pset.get<std::vector<size_t>>(
"NumWiresToGroup", std::vector<size_t>() = {48, 48, 96});
65 fAdcCntHist[0] = tfs->make<TH1D>(
"CntUPlane",
";#adc", 200, 2200., 4200.);
66 fAdcCntHist[1] = tfs->make<TH1D>(
"CntVPlane",
";#adc", 200, 2200., 4200.);
67 fAdcCntHist[2] = tfs->make<TH1D>(
"CntWPlane",
";#adc", 200, 2200., 4200.);
68 fAveValHist[0] = tfs->make<TH1D>(
"AveUPlane",
";Ave", 120, -20., 20.);
69 fAveValHist[1] = tfs->make<TH1D>(
"AveVPlane",
";Ave", 120, -20., 20.);
70 fAveValHist[2] = tfs->make<TH1D>(
"AveWPlane",
";Ave", 120, -20., 20.);
71 fRmsTValHist[0] = tfs->make<TH1D>(
"RmsTUPlane",
";RMS", 100, 0., 10.);
72 fRmsTValHist[1] = tfs->make<TH1D>(
"RmsTVPlane",
";RMS", 100, 0., 10.);
73 fRmsTValHist[2] = tfs->make<TH1D>(
"RmsTWPlane",
";RMS", 100, 0., 10.);
74 fRmsFValHist[0] = tfs->make<TH1D>(
"RmsFUPlane",
";RMS", 100, 0., 10.);
75 fRmsFValHist[1] = tfs->make<TH1D>(
"RmsFVPlane",
";RMS", 100, 0., 10.);
76 fRmsFValHist[2] = tfs->make<TH1D>(
"RmsFWPlane",
";RMS", 100, 0., 10.);
77 fPedValHist[0] = tfs->make<TH1D>(
"PedUPlane",
";Ped", 200, 1950, 2150.);
78 fPedValHist[1] = tfs->make<TH1D>(
"PedVPlane",
";Ped", 200, 1950, 2150.);
79 fPedValHist[2] = tfs->make<TH1D>(
"PedWPlane",
";Ped", 200, 350, 550.);
81 fRmsValProf[0] = tfs->make<TProfile>(
"RmsPlane0Prof",
";Wire #", 1200, 0., 1200., 0., 100.);
82 fRmsValProf[1] = tfs->make<TProfile>(
"RmsPlane1Prof",
";Wire #", 5000, 0., 5000., 0., 100.);
83 fRmsValProf[2] = tfs->make<TProfile>(
"RmsPlane2Prof",
";Wire #", 5000, 0., 5000., 0., 100.);
85 fMinMaxValProf[0] = tfs->make<TProfile>(
"MinMaxPlane0Prof",
";Wire #", 1200, 0., 1200., 0., 200.);
86 fMinMaxValProf[1] = tfs->make<TProfile>(
"MinMaxPlane1Prof",
";Wire #", 5000, 0., 5000., 0., 200.);
87 fMinMaxValProf[2] = tfs->make<TProfile>(
"MinMaxPlane2Prof",
";Wire #", 5000, 0., 5000., 0., 200.);
89 fPedValProf[0] = tfs->make<TProfile>(
"PedPlane0Prof",
";Wire #", 1200, 0., 1200., 1500., 2500.);
90 fPedValProf[1] = tfs->make<TProfile>(
"PedPlane1Prof",
";Wire #", 5000, 0., 5000., 1500., 2500.);
91 fPedValProf[2] = tfs->make<TProfile>(
"PedPlane2Prof",
";Wire #", 5000, 0., 5000., 0., 1000.);
93 fAverageHist[0] = tfs->make<TH1D>(
"Average0",
";Bin", 1000, 1500., 2500.);
94 fAverageHist[1] = tfs->make<TH1D>(
"Average1",
";Bin", 1000, 1500., 2500.);
95 fAverageHist[2] = tfs->make<TH1D>(
"Average2",
";Bin", 1000, 0., 1000.);
101 for(
size_t viewIdx = 0; viewIdx < 3; viewIdx++)
124 unsigned int channel,
135 float& neighborRatio,
136 float& pedCorVal)
const
149 std::pair<RawDigitVector::const_iterator,RawDigitVector::const_iterator> minMaxItrPair = std::minmax_element(rawWaveform.begin(),rawWaveform.end());
151 minMax = std::min(*minMaxItrPair.second - *minMaxItrPair.first + 1, 199);
154 std::vector<short> localTimeVec = rawWaveform;
156 std::sort(localTimeVec.begin(),localTimeVec.end(),[](
const auto&
left,
const auto&
right){
return std::fabs(
left) < std::fabs(
right);});
158 float realMean(
float(std::accumulate(localTimeVec.begin(),localTimeVec.end(),0))/float(localTimeVec.size()));
160 median = localTimeVec[localTimeVec.size()/2];
161 mean = std::round(realMean);
163 std::vector<float> adcLessPedVec;
165 adcLessPedVec.resize(localTimeVec.size());
167 std::transform(localTimeVec.begin(),localTimeVec.end(),adcLessPedVec.begin(),std::bind(std::minus<float>(),std::placeholders::_1,realMean));
169 rms = std::sqrt(std::inner_product(adcLessPedVec.begin(), adcLessPedVec.end(), adcLessPedVec.begin(), 0.) / float(adcLessPedVec.size()));
170 skewness = 3. * float(realMean - median) / rms;
174 std::unordered_map<short,short> binAdcMap;
177 for(
const auto& adcVal : rawWaveform) binAdcMap[adcVal]++;
180 std::unordered_map<short,short>::iterator maxBinItr = std::max_element(binAdcMap.begin(),binAdcMap.end(),[](
const auto& lhs,
const auto& rhs){
return lhs.second < rhs.second;});
182 short neighborSum(0);
183 short leftNeighbor(maxBinItr->second);
184 short rightNeighbor(maxBinItr->second);
187 mode = maxBinItr->first;
189 if (binAdcMap.find(mode-1) != binAdcMap.end())
191 leftNeighbor = binAdcMap.find(mode-1)->second;
192 neighborSum += leftNeighbor;
196 if (binAdcMap.find(mode+1) != binAdcMap.end())
198 rightNeighbor = binAdcMap.find(mode+1)->second;
199 neighborSum += rightNeighbor;
203 neighborRatio = float(neighborSum) / float(2*maxBinItr->second);
205 neighborRatio = float(std::min(leftNeighbor,rightNeighbor)) / float(maxBinItr->second);
211 short maxVal = *std::max_element(rawWaveform.begin(),rawWaveform.end());
212 short minVal = *std::min_element(rawWaveform.begin(),rawWaveform.end());
213 short minMax = std::min(maxVal - minVal,199);
216 fAveValHist[view]->Fill(std::max(-29.9, std::min(29.9,
double(truncMean))), 1.);
217 fRmsTValHist[view]->Fill(std::min(19.9,
double(truncRms)), 1.);
218 fRmsFValHist[view]->Fill(std::min(19.9,
double(rms)), 1.);
219 fRmsValProf[view]->Fill(wire,
double(truncRms), 1.);
228 float leastNeighborRatio = float(std::min(leftNeighbor,rightNeighbor)) / float(maxBinItr->second);
250 float& truncRms)
const
253 std::vector<float> adcLessPedVec;
255 adcLessPedVec.resize(rawWaveform.size());
258 std::transform(rawWaveform.begin(),rawWaveform.end(),adcLessPedVec.begin(),std::bind(std::minus<short>(),std::placeholders::_1,pedestal));
261 std::sort(adcLessPedVec.begin(), adcLessPedVec.end(),[](
const auto&
left,
const auto&
right){
return std::fabs(
left) < std::fabs(
right);});
266 truncRms = std::inner_product(adcLessPedVec.begin(), adcLessPedVec.begin() + minNumBins, adcLessPedVec.begin(), 0.);
267 truncRms = std::sqrt(std::max(0.,truncRms /
double(minNumBins)));
273 unsigned int channel,
278 float& pedCorVal)
const
296 pedestal = truncMean;
299 pedCorVal = truncMean - pedestal;
304 short maxVal = *std::max_element(rawWaveform.begin(),rawWaveform.end());
305 short minVal = *std::min_element(rawWaveform.begin(),rawWaveform.end());
306 short minMax = std::min(maxVal - minVal,199);
309 fAveValHist[view]->Fill(std::max(-29.9, std::min(29.9,
double(truncMean - pedestal))), 1.);
310 fRmsFValHist[view]->Fill(std::min(19.9,
double(rmsVal)), 1.);
320 mf::LogInfo(
"RawDigitCharacterizationAlg") <<
">>> Pedestal mismatch, channel: " << channel <<
", new value: " << truncMean <<
", original: " << pedestal <<
", rms: " << rmsVal << std::endl;
334 std::pair<RawDigitVector::const_iterator,RawDigitVector::const_iterator> minMaxValItr = std::minmax_element(rawWaveform.begin(),rawWaveform.end());
336 int minVal = std::floor(*minMaxValItr.first);
337 int maxVal = std::ceil(*minMaxValItr.second);
338 int range = maxVal - minVal + 1;
340 std::vector<int> frequencyVec(range, 0);
344 for(
const auto& val : rawWaveform)
346 int intVal = std::round(val) - minVal;
348 frequencyVec[intVal]++;
350 if (frequencyVec.at(intVal) > mpCount)
352 mpCount = frequencyVec[intVal];
360 int binRange = std::min(16,
int(range/2 + 1));
362 for(
int idx = mpVal-binRange; idx <= mpVal+binRange; idx++)
364 if (idx < 0 || idx >= range)
continue;
366 meanSum += (idx + minVal) * frequencyVec[idx];
367 meanCnt += frequencyVec[idx];
370 aveVal = float(meanSum) / float(meanCnt);
373 std::vector<float> adcLessPedVec(rawWaveform.size());
375 std::transform(rawWaveform.begin(),rawWaveform.end(),adcLessPedVec.begin(),std::bind(std::minus<float>(),std::placeholders::_1,aveVal));
378 rmsVal = std::inner_product(adcLessPedVec.begin(), adcLessPedVec.end(), adcLessPedVec.begin(), 0.);
379 rmsVal = std::sqrt(std::max(
float(0.),rmsVal /
float(adcLessPedVec.size())));
394 std::pair<RawDigitVector::const_iterator,RawDigitVector::const_iterator> minMaxValItr = std::minmax_element(rawWaveform.begin(),rawWaveform.end());
396 int minVal = std::floor(*minMaxValItr.first);
397 int maxVal = std::ceil(*minMaxValItr.second);
398 int range = maxVal - minVal + 1;
400 std::vector<int> frequencyVec(range, 0);
404 for(
const auto& val : rawWaveform)
406 int intVal = std::round(val) - minVal;
408 frequencyVec[intVal]++;
410 if (frequencyVec.at(intVal) > mpCount)
412 mpCount = frequencyVec[intVal];
420 int binRange = std::min(16,
int(range/2 + 1));
422 for(
int idx = mpVal-binRange; idx <= mpVal+binRange; idx++)
424 if (idx < 0 || idx >= range)
continue;
426 meanSum += (idx + minVal) * frequencyVec[idx];
427 meanCnt += frequencyVec[idx];
430 aveVal = float(meanSum) / float(meanCnt);
433 std::vector<float> adcLessPedVec(rawWaveform.size());
435 std::transform(rawWaveform.begin(),rawWaveform.end(),adcLessPedVec.begin(),std::bind(std::minus<float>(),std::placeholders::_1,aveVal));
438 rmsVal = std::inner_product(adcLessPedVec.begin(), adcLessPedVec.end(), adcLessPedVec.begin(), 0.);
439 rmsVal = std::sqrt(std::max(
float(0.),rmsVal /
float(adcLessPedVec.size())));
442 std::vector<float>::iterator newEndItr = std::remove_if(adcLessPedVec.begin(),adcLessPedVec.end(),[rmsVal](
const auto& val){
return std::abs(val) > 2.5*rmsVal;});
444 rmsTrunc = std::inner_product(adcLessPedVec.begin(), newEndItr, adcLessPedVec.begin(), 0.);
446 rmsTrunc = std::sqrt(std::max(
float(0.),rmsTrunc /
float(numBins)));
452 unsigned int viewIdx,
464 bool classified(
false);
471 if (minMax > selectionCut && truncRms < rejectionCut)
475 if (groupToDigitIdxPairMap.find(group) == groupToDigitIdxPairMap.end())
476 groupToDigitIdxPairMap.insert(std::pair<size_t,RawDigitAdcIdxPair>(group,
RawDigitAdcIdxPair()));
479 groupToDigitIdxPairMap.at(group).second.insert(std::pair<size_t,RawDigitVectorIdxPair>(wire,
RawDigitVectorIdxPair(0,rawWaveform.size())));
486 WireToAdcIdxMap& wireToAdcIdxMap = groupToDigitIdxPairMap.at(group).second;
493 if (skewness > 0. && neighborRatio < 0.7 && minMax > 50)
495 RawDigitVector::iterator stopChirpItr = std::find_if(rawWaveform.begin(),rawWaveform.end(),[
mean,threshold](
const short& elem){
return abs(elem - mean) > threshold;});
497 size_t threshIndex =
std::distance(rawWaveform.begin(),stopChirpItr);
499 if (threshIndex > 60) wireToAdcIdxMap[wire].first = threshIndex;
502 else if (minMax > 20 && neighborRatio < 0.7)
506 RawDigitVector::reverse_iterator startChirpItr = std::find_if(rawWaveform.rbegin(),rawWaveform.rend(),[
mean,threshold](
const short& elem){
return abs(elem - mean) > threshold;});
508 size_t threshIndex =
std::distance(rawWaveform.rbegin(),startChirpItr);
510 if (threshIndex > 60) wireToAdcIdxMap[wire].second = rawWaveform.size() - threshIndex;
522 T medianValue(defaultValue);
524 if (!valuesVec.empty())
526 std::sort(valuesVec.begin(),valuesVec.end());
528 size_t medianIdx = valuesVec.size() / 2;
530 medianValue = valuesVec[medianIdx];
532 if (valuesVec.size() > 1 && medianIdx % 2) medianValue = (medianValue + valuesVec[medianIdx+1]) / 2;
535 return std::max(medianValue,defaultValue);
std::vector< float > fRmsSelectionCut
Don't use/apply correction to wires below this.
T getMedian(std::vector< T > &, T) const
RawDigitCharacterizationAlg(fhicl::ParameterSet const &pset)
std::vector< short > fMinMaxSelectionCut
Plane by plane cuts for spread cut.
void getMeanRmsAndPedCor(const RawDigitVector &rawWaveform, unsigned int channel, unsigned int view, unsigned int wire, float &aveVal, float &rmsVal, float &pedCorVal) const
void getMeanAndRms(const RawDigitVector &rawWaveform, float &aveVal, float &rmsVal, int &numBins) const
double fMaxPedestalDiff
Max pedestal diff to db to warn.
bool classifyRawDigitVec(RawDigitVector &rawWaveform, unsigned int viewIdx, unsigned int wire, float truncRms, short minMax, short mean, float skewness, float neighborRatio, GroupToDigitIdxPairMap &groupToDigitIdxPairMap) const
bool fFillHistograms
if true then will fill diagnostic hists
TProfile * fRmsValProf[3]
raw::RawDigit::ADCvector_t RawDigitVector
void getMeanAndTruncRms(const RawDigitVector &rawWaveform, float &aveVal, float &rmsVal, float &rmsTrunc, int &numBins) const
caldata::ChannelGroups fChannelGroups
std::vector< TProfile * > fSkewnessProfiles
std::pair< WireToRawDigitVecMap, WireToAdcIdxMap > RawDigitAdcIdxPair
unsigned int fTheChosenWire
For example hist.
std::pair< size_t, size_t > RawDigitVectorIdxPair
std::map< size_t, RawDigitAdcIdxPair > GroupToDigitIdxPairMap
std::vector< TProfile * > fModeRatioProfiles
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
size_t channelGroup(size_t view, size_t wire) const
TProfile * fMinMaxValProf[3]
std::vector< float > fRmsRejectionCutLow
Minimum rms to consider channel "alive".
TProfile * fPedValProf[3]
void reconfigure(fhicl::ParameterSet const &pset)
const lariov::DetPedestalProvider & fPedestalRetrievalAlg
Keep track of an instance to the pedestal retrieval alg.
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
std::pair< size_t, RawDigitVector & > WireToRawDigitVecPair
std::vector< TProfile * > fMinMaxProfiles
void getTruncatedRMS(const RawDigitVector &rawWaveform, float &pedestal, float &truncRms) const
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
std::string to_string(WindowPattern const &pattern)
~RawDigitCharacterizationAlg()
Destructor.
std::vector< size_t > fNumWiresToGroup
If smoothing, the number of wires to look at.
art::ServiceHandle< art::TFileService > tfs
std::vector< float > fRmsRejectionCutHi
Maximum rms for input channels, reject if larger.
std::vector< size_t > fHistsWireGroup
Wire Group to pick on.
void initializeHists(art::ServiceHandle< art::TFileService > &)
Begin job method.
void getWaveformParams(const RawDigitVector &rawWaveform, unsigned int channel, unsigned int view, unsigned int wire, float &truncMean, float &truncRms, short &mean, short &median, short &mode, float &skewness, float &rms, short &minMax, float &neighborRatio, float &pedCorVal) const
process_name can override from command line with o or output caldata
float fTruncMeanFraction
Fraction for truncated mean.
std::map< size_t, RawDigitVectorIdxPair > WireToAdcIdxMap