3 #include <fwk/CentralConfig.h>
5 #include <utl/config.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/Reader.h>
10 #include <revt/REvent.h>
11 #include <revt/Station.h>
12 #include <revt/Channel.h>
18 using std::ostringstream;
29 topBranch.
GetChild(
"CorrectChannelMixing").
GetData(fCorrectChannelMixing);
40 WARNING(
"No radio event found!");
44 REvent& rEvent =
event.GetREvent();
47 for (
auto& station : rEvent.StationsRange()) {
50 if (fCorrectChannelMixing) {
51 std::vector<std::pair<ChannelADCTimeSeries, ChannelADCTimeSeries>> traceOpts;
52 std::pair<ChannelADCTimeSeries, ChannelADCTimeSeries> currTraces;
54 for (
const auto& channel : station.ChannelsRange()) {
56 if (!channel.IsActive())
59 if (channel.GetId() == 0) {
60 currTraces.first = channel.GetChannelADCTimeSeries();
62 currTraces.second = channel.GetChannelADCTimeSeries();
66 const double binning = station.GetChannel(0).GetChannelADCTimeSeries().GetBinning();
67 const int traceLength = currTraces.first.GetSize();
71 traceOpts.push_back(currTraces);
74 for (
int i = 0; i < traceLength; i += 2) {
75 currTraces.first[i] = traceOpts[0].first[i];
76 currTraces.first[i+1] = traceOpts[0].second[i];
77 currTraces.second[i] = traceOpts[0].second[i+1];
78 currTraces.second[i+1] = traceOpts[0].first[i+1];
80 traceOpts.push_back(currTraces);
83 for (
int i = 0; i < traceLength; i += 2) {
84 currTraces.first[i] = traceOpts[0].first[i+1];
85 currTraces.first[i+1] = traceOpts[0].second[i+1];
86 currTraces.second[i] = traceOpts[0].second[i];
87 currTraces.second[i+1] = traceOpts[0].first[i];
89 traceOpts.push_back(currTraces);
93 std::vector<double> freqRatios;
94 for (
auto const& opt : traceOpts) {
95 Channel& channelNS = station.GetChannel(0);
101 timeTrace.SetBinning(binning);
102 timeTrace = opt.first * 1.0;
107 const double ratio = CalculateRatio(freqSpectrum, traceLength);
108 freqRatios.push_back(ratio);
111 const int maxIndex = std::max_element(freqRatios.begin(), freqRatios.end()) - freqRatios.begin();
114 info <<
"\n" << (maxIndex ?
"Original trace correct " :
"Channel mixing ")
115 <<
"identified. Saved correct trace.";
118 for (
auto& channel : station.ChannelsRange()) {
120 if (!channel.IsActive())
123 auto& adcTrace = channel.GetChannelADCTimeSeries();
125 if (channel.GetId() == 0) {
126 adcTrace = traceOpts[maxIndex].first;
128 adcTrace = traceOpts[maxIndex].second;
139 RdADCTraceFixer::Finish()
152 for (
const auto& amp : freqSpectrum) {
153 freq = double(counter) / double(traceLength) * 250;
155 if (freq >= 30 && freq <= 80) {
158 outRange +=
abs(amp);
162 return inRange / outRange;
ChannelFFTDataContainer & GetFFTDataContainer()
retrieve Channel FFTDataContainer (write access)
Branch GetTopBranch() const
Interface class to access to the Radio part of an event.
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
ChannelTimeSeries & GetChannelTimeSeries()
retrieve Channel Time Series (write access, only use this if you intend to change the data) ...
Class representing a document branch.
C< F > & GetFrequencySpectrum()
read out the frequency spectrum (write access)
double abs(const SVector< n, T > &v)
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
ResultFlag
Flag returned by module methods to the RunController.
Class that holds the data associated to an individual radio channel.