31 void copyWaveform(
const std::vector<float>&
adc, std::vector<float>& ch_waveform) {
32 const string myname =
"PdspNoiseRemoval::copyWaveform: ";
33 size_t n_samples = adc.size();
34 if ( ch_waveform.size() < adc.size() ) {
35 cout << myname <<
"ERROR: ADC size: " << n_samples <<
" > FFT size: " << ch_waveform.size() <<
endl;
36 cout << myname <<
"ERROR: Increase FFTSize in the LArFFT service" <<
endl;
39 if ( ch_waveform.size() > 2*adc.size() ) {
40 cout << myname <<
"ERROR: FFT size: " << ch_waveform.size() <<
" > 2*(ADC size: " << n_samples <<
")" <<
endl;
41 cout << myname <<
"ERROR: Decrease FFTSize in the LArFFT service" <<
endl;
44 std::copy(adc.begin(), adc.end(), ch_waveform.begin());
45 for (
size_t s = n_samples;
s < ch_waveform.size(); ++
s ) {
46 ch_waveform[
s] = ch_waveform[2*n_samples -
s - 1];
57 : m_LogLevel(ps.
get<
int>(
"LogLevel")) {
58 const string myname =
"PdspNoiseRemoval::ctor: ";
82 std::cout <<
"PdspNoiseRemoval WARNING: correction set to mean value." <<
std::endl;
86 double binWidth = 1.0/(fFFT->FFTSize()*
sampling_rate(clockData)*1.0e-6);
89 float f = binWidth * i;
96 cout << myname <<
" RemoveCoherent: " << fRemoveCoherent <<
endl;
97 cout << myname <<
" CutoffFrequency: " << fCutoffFrequency <<
endl;
98 cout << myname <<
" CoherentOffline16: " << fCoherentOffline16 <<
endl;
99 cout << myname <<
" CoherentDaq8: " << fCoherentDaq8 <<
endl;
100 cout << myname <<
" CoherentDaq16: " << fCoherentDaq16 <<
endl;
101 cout << myname <<
" CoherentFEMB128: " << fCoherentFEMB128 <<
endl;
102 cout << myname <<
"CoherentOffline16Groups: [";
103 for(
size_t i=0; i<fCoherentOffline16Groups.size(); i++) {
104 cout<< fCoherentOffline16Groups.at(i) <<
", ";
106 cout <<
" ]" <<
endl;
107 cout << myname <<
"CoherentDaq8Groups: [";
108 for(
size_t i=0; i<fCoherentDaq8Groups.size(); i++) {
109 cout<< fCoherentDaq8Groups.at(i) <<
", ";
111 cout <<
" ]" <<
endl;
112 cout << myname <<
"CoherentDaq16Groups: [";
113 for(
size_t i=0; i<fCoherentDaq16Groups.size(); i++) {
114 cout<< fCoherentDaq16Groups.at(i) <<
", ";
116 cout <<
" ]" <<
endl;
117 cout << myname <<
"CoherentFEMB128Groups: [";
118 for(
size_t i=0; i<fCoherentFEMB128Groups.size(); i++) {
119 cout<< fCoherentFEMB128Groups.at(i) <<
", ";
121 cout <<
" ]" <<
endl;
122 cout << myname <<
" UseBasicROIForCNR: " << fUseBasicROIForCNR <<
endl;
123 cout << myname <<
" RoiStartThreshold: " << fRoiStartThreshold <<
endl;
124 cout << myname <<
" RoiEndThreshold: " << fRoiEndThreshold <<
endl;
125 cout << myname <<
" RoiPadLow: " << fRoiPadLow <<
endl;
126 cout << myname <<
" RoiPadHigh: " << fRoiPadHigh <<
endl;
132 const string myname =
"PdspNoiseRemoval::updateMap: ";
135 if (acds.size() == 0) {
136 std::cout << myname <<
"WARNING: No channels found." <<
std::endl;
170 for(
auto &
entry : datamap) {
179 const string myname =
"PdspNoiseRemoval::fftFltInPlace: ";
180 std::vector< TComplex > ch_spectrum(
fFFT->
FFTSize() / 2 + 1);
181 std::vector< float > ch_waveform(
fFFT->
FFTSize(), 0);
182 size_t n_samples = adc.size();
183 if (
m_LogLevel >= 3 ) cout << myname <<
"N_ADC = " << adc.size() <<
", N_WF = " << ch_waveform.size() <<
endl;
184 copyWaveform(adc, ch_waveform);
186 for(
size_t c = 0;
c < coeffs.size(); ++
c) {
187 ch_spectrum[
c] *= coeffs[
c];
190 std::copy(ch_waveform.begin(), ch_waveform.begin()+n_samples, adc.begin());
195 std::vector< TComplex > ch_spectrum(
fFFT->
FFTSize() / 2 + 1);
196 std::vector< float > ch_waveform(
fFFT->
FFTSize(), 0);
197 size_t n_samples = adc.size();
198 copyWaveform(adc, ch_waveform);
200 for(
size_t c = 0;
c < coeffs.size(); ++
c) {
201 ch_spectrum[
c] *= coeffs[
c];
204 std::vector< float > flt_adc(n_samples);
205 std::copy(ch_waveform.begin(), ch_waveform.begin()+n_samples, flt_adc.begin());
214 for(
unsigned int ch = 0; ch < nchan; ++ch) {
215 size_t g = ch / gsize;
216 if(gidx.empty() ||
has(gidx, g)) {
228 for(
unsigned int ch = 0; ch < nchan; ++ch) {
230 if(gidx.empty() ||
has(gidx, g)) {
232 groups[
g].push_back(ch);
246 for(
unsigned int ch = 0; ch < nchan; ++ch) {
250 if(gidx.empty() ||
has(gidx, g) ) {
253 case 0: groups[3*
g].push_back(ch);
255 case 1: groups[3*g+1].push_back(ch);
257 case 2: groups[3*g+2].push_back(ch);
268 if(datamap.empty())
return;
271 for(
const auto &
entry : ch_groups) {
273 std::vector<float> correction;
277 else if(
fMode == 2) {
281 auto iacd = datamap.find(ch);
282 if(iacd == datamap.end())
continue;
284 if(acd.
samples.size() == 0)
continue;
285 if(acd.
samples.size() > correction.size()) correction.resize(acd.
samples.size(), 0.);
286 for(
size_t s = 0;
s < acd.
samples.size(); ++
s) {
295 size_t n_samples = datamap.begin()->second.samples.size();
296 std::vector<size_t> ch_averaged(n_samples, 0);
297 std::vector<float> correction(n_samples, 0);
298 for(
unsigned int ch : channels) {
299 auto iacd = datamap.find(ch);
300 if(iacd == datamap.end())
continue;
302 if(acd.
samples.size()>n_samples) {
303 ch_averaged.resize(acd.
samples.size(), 0.);
304 correction.resize(acd.
samples.size(), 0.);
308 for(
size_t s = 0;
s < acd.
samples.size(); ++
s) {
309 if (!
mask[
s]) {
continue; }
311 if(flag !=
AdcGood) {
continue; }
317 for(
size_t s = 0;
s < acd.
samples.size(); ++
s) {
318 if(acd.
signal[
s]) {
continue; }
320 if(flag !=
AdcGood) {
continue; }
326 for(
size_t s = 0;
s < correction.size(); ++
s) {
327 if(ch_averaged[
s] > 0) {
328 correction[
s] /= ch_averaged[
s];
334 size_t n_samples = datamap.begin()->second.samples.size();
335 std::vector< std::vector<float> > samples(n_samples);
336 for(
unsigned int ch : channels) {
337 auto iacd = datamap.find(ch);
338 if(iacd == datamap.end())
continue;
340 if(acd.
samples.size()>n_samples) samples.resize(acd.
samples.size());
343 for(
size_t s = 0;
s < acd.
samples.size(); ++
s) {
344 if (!
mask[
s]) {
continue; }
346 if(flag !=
AdcGood) {
continue; }
347 samples[
s].push_back(acd.
samples[s]);
351 for(
size_t s = 0;
s < acd.
samples.size(); ++
s) {
352 if(acd.
signal[
s]) {
continue; }
354 if(flag !=
AdcGood) {
continue; }
359 std::vector<float> correction(samples.size());
360 for(
size_t s = 0;
s < samples.size(); ++
s) {
361 size_t n = samples[
s].size();
362 if(n < 2) { correction[
s] = 0;
continue; }
363 std::sort(samples[
s].
begin(), samples[
s].
end());
364 if((n % 2) == 0) { correction[
s] = 0.5 * (samples[
s][n/2] + samples[
s][(n/2)-1]); }
365 else { correction[
s] = samples[
s][(n-1)/2]; }
376 for (
int i = 0; i < (
int)acd_flt.size(); ++i) {
377 auto sig = acd_flt[i];
403 size_t DaqChan = 2560*apa + 512* wib + 128* femb + fembChan;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< size_t > fCoherentDaq16Groups
const geo::Geometry * fGeometry
static constexpr double g
unsigned int FEMBChannelFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB channel.
bool fRemoveHighFrequency
void removeCoherent(const GroupChannelMap &ch_groups, AdcChannelDataMap &datamap) const
DataMap & setStatus(int stat)
std::vector< size_t > fCoherentFEMB128Groups
std::vector< float > getMedianCorrection(const std::vector< unsigned int > &channels, const AdcChannelDataMap &datamap) const
std::vector< bool > roiMask(const AdcChannelData &adc) const
void DoFFT(std::vector< T > &input, std::vector< TComplex > &output)
void removeHighFreq(AdcChannelDataMap &datamap) const
std::vector< float > fftFlt(const std::vector< float > &adc, const std::vector< float > &coeffs) const
art framework interface to geometry description
unsigned int APAFromOfflineChannel(unsigned int offlineChannel) const
Returns APA/crate.
void DoInvFFT(std::vector< TComplex > &input, std::vector< T > &output)
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
QCollection::Item first()
GroupChannelMap makeGroupsByOfflineChannels(size_t gsize, const std::vector< size_t > &gidx) const
void fftFltInPlace(std::vector< float > &adc, const std::vector< float > &coeffs) const
bool has(const std::vector< size_t > &v, size_t idx) const
T get(std::string const &key) const
GroupChannelMap makeGroupsByFEMBPlaneType(size_t gsize, const std::vector< size_t > &gidx) const
std::vector< float > fLowPassCoeffs
static constexpr double ps
unsigned int PlaneFromOfflineChannel(unsigned int offlineChannel) const
Returns plane.
unsigned int WIBFromOfflineChannel(unsigned int offlineChannel) const
Returns WIB/slot.
std::unordered_map< unsigned int, std::vector< unsigned int > > GroupChannelMap
DataMap updateMap(AdcChannelDataMap &acds) const override
GroupChannelMap makeGroupsByDAQChannels(size_t gsize, const std::vector< size_t > &gidx) const
std::vector< size_t > fCoherentOffline16Groups
Interface for experiment-specific channel quality info provider.
unsigned int FEMBFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB/fiber.
PdspNoiseRemoval(fhicl::ParameterSet const &ps)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::vector< size_t > fCoherentDaq8Groups
auto const & get(AssnsNode< L, R, D > const &r)
Interface for experiment-specific service for channel quality info.
static size_t getDAQChan(size_t LAr_chan)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
std::vector< float > getMeanCorrection(const std::vector< unsigned int > &channels, const AdcChannelDataMap &datamap) const
QTextStream & endl(QTextStream &s)