|
| 1 | + |
| 2 | +#include "DigitalNoiseChannelStatus.h" |
| 3 | +#include "TMath.h" |
| 4 | +#include "lardataobj/RawData/raw.h" |
| 5 | +#include "art/Framework/Principal/Event.h" |
| 6 | + |
| 7 | +sbnd::DigitalNoiseChannelStatus::DigitalNoiseChannelStatus(fhicl::ParameterSet const& p, art::ActivityRegistry& areg) |
| 8 | +// : |
| 9 | +// Initialize member data here. |
| 10 | +{ |
| 11 | + fRMSCutWire = p.get<float>("RMSCutWire",100.0); |
| 12 | + fRMSCutRawDigit = p.get<float>("RMSCutRawDigit",100.0); |
| 13 | + fNBADCutRawDigit = p.get<float>("NBADCutRawDigit",5); |
| 14 | + fRawDigitLabel = p.get<std::string>("RawDigitLabel","daq"); |
| 15 | + fRecobWireLabel = p.get<std::string>("RecobWireLabel","caldata"); |
| 16 | + fNAwayFromPedestalRawDigit = p.get<int>("NAwayFromPedestalRawDigit",100); |
| 17 | + fDistFromPedestalRawDigit = p.get<int>("DistFromPedestalRawDigit",100); |
| 18 | + fNAwayFromPedestalRecobWire = p.get<int>("NAwayFromPedestalRecobWire",100); |
| 19 | + fDistFromPedestalRecobWire = p.get<float>("DistFromPedestalRecobWire",100); |
| 20 | + |
| 21 | + areg.sPreProcessEvent.watch(this, &sbnd::DigitalNoiseChannelStatus::pub_PrepEvent); |
| 22 | +} |
| 23 | + |
| 24 | +bool sbnd::DigitalNoiseChannelStatus::IsBad(raw::ChannelID_t chan) const |
| 25 | +{ |
| 26 | + return (fDNChannels.find(chan) != fDNChannels.end()); |
| 27 | +} |
| 28 | + |
| 29 | +const std::unordered_set<raw::ChannelID_t> & sbnd::DigitalNoiseChannelStatus::GetSetOfBadChannels() const |
| 30 | +{ |
| 31 | + return fDNChannels; |
| 32 | +} |
| 33 | + |
| 34 | +size_t sbnd::DigitalNoiseChannelStatus::NBadChannels() const |
| 35 | +{ |
| 36 | + return fDNChannels.size(); |
| 37 | +} |
| 38 | + |
| 39 | +// prepare channel status data for the event |
| 40 | + |
| 41 | +// put cuts on RMS, number of 0xBAD samples, and whether the differences between a sample and |
| 42 | +// the first are all even (catches all the powers of two). |
| 43 | + |
| 44 | +void sbnd::DigitalNoiseChannelStatus::pub_PrepEvent(const art::Event& evt, art::ScheduleContext) |
| 45 | +{ |
| 46 | + fDNChannels.clear(); |
| 47 | + if (fRawDigitLabel != "") |
| 48 | + { |
| 49 | + auto const& rawdigits = evt.getProduct<std::vector<raw::RawDigit>>(fRawDigitLabel); |
| 50 | + for (const auto& rd : rawdigits) |
| 51 | + { |
| 52 | + bool chanbad = false; |
| 53 | + chanbad |= (rd.GetSigma() > fRMSCutRawDigit); |
| 54 | + int nhexbad = 0; |
| 55 | + std::vector<short> rawadc; |
| 56 | + rawadc.resize(rd.Samples()); |
| 57 | + raw::Uncompress(rd.ADCs(), rawadc, rd.GetPedestal(), rd.Compression()); |
| 58 | + bool alleven = true; |
| 59 | + int naway = 0; |
| 60 | + const short adc0 = rawadc.at(0); |
| 61 | + for (size_t i=0; i< rd.Samples(); ++i) |
| 62 | + { |
| 63 | + const short adc = rawadc.at(i); |
| 64 | + if (adc == 0xBAD) ++nhexbad; |
| 65 | + alleven &= ( ((adc - adc0) % 2) == 0 ); |
| 66 | + if (std::abs(adc - rd.GetPedestal()) > fDistFromPedestalRawDigit) |
| 67 | + { |
| 68 | + ++naway; |
| 69 | + } |
| 70 | + } |
| 71 | + chanbad |= (nhexbad > fNBADCutRawDigit); |
| 72 | + chanbad |= alleven; |
| 73 | + chanbad |= (naway > fNAwayFromPedestalRawDigit); |
| 74 | + if (chanbad) fDNChannels.emplace(rd.Channel()); |
| 75 | + } |
| 76 | + } |
| 77 | + else if (fRecobWireLabel != "") |
| 78 | + { |
| 79 | + art::InputTag rwtag(fRecobWireLabel); |
| 80 | + auto const& rbwires = evt.getProduct<std::vector<recob::Wire>>(fRecobWireLabel); |
| 81 | + for (const auto& rw : rbwires) |
| 82 | + { |
| 83 | + bool chanbad = false; |
| 84 | + auto rms = TMath::RMS(rw.NSignal(),rw.Signal().data()); |
| 85 | + chanbad |= (rms > fRMSCutWire); |
| 86 | + auto mns = TMath::Mean(rw.NSignal(),rw.Signal().data()); |
| 87 | + int naway = 0; |
| 88 | + for (size_t i=0; i<rw.NSignal(); ++i) |
| 89 | + { |
| 90 | + if (std::abs(rw.Signal()[i] - mns) > fDistFromPedestalRecobWire) |
| 91 | + { |
| 92 | + naway ++; |
| 93 | + } |
| 94 | + } |
| 95 | + chanbad |= (naway > fNAwayFromPedestalRecobWire); |
| 96 | + if (chanbad) fDNChannels.emplace(rw.Channel()); |
| 97 | + } |
| 98 | + } |
| 99 | + //std::cout << "sbnd::DigitalNoiseStatus_service: NBadChannels: " << fDNChannels.size() << std::endl; |
| 100 | + //for (const auto& c : fDNChannels) |
| 101 | + // { |
| 102 | + // std::cout << "noisy chan: " << c << std::endl; |
| 103 | + // } |
| 104 | +} |
| 105 | + |
| 106 | +DEFINE_ART_SERVICE(sbnd::DigitalNoiseChannelStatus) |
| 107 | + |
| 108 | + |
0 commit comments