3 #include <fwk/CentralConfig.h>
5 #include <utl/ErrorLogger.h>
6 #include <utl/Reader.h>
7 #include <utl/config.h>
10 #include <revt/REvent.h>
11 #include <revt/Header.h>
12 #include <revt/Station.h>
13 #include <revt/Channel.h>
26 using std::ostringstream;
42 const vector<int> dummyStationIDlist = topBranch.
GetChild(
"StationIds").
Get<vector<int>>();
43 fStationIds = set<int>(dummyStationIDlist.begin(), dummyStationIDlist.end());
46 const vector<int> dummyChannelIDlist = topBranch.
GetChild(
"ChannelIds").
Get<vector<int>>();
47 fChannelIds = set<int>(dummyChannelIDlist.begin(), dummyChannelIDlist.end());
50 topBranch.
GetChild(
"AsciiSpectrumNameBase").
GetData(fAsciiSpectrumNameBase);
52 topBranch.
GetChild(
"AsciiSpectrumNameBase").
GetData(fAsciiSpectrumNameBase);
55 const string unitstr = topBranch.
GetChild(
"UseUnits").
Get<
string>();
56 fUseUnits = (unitstr ==
"yes");
59 info <<
"fRootFileNameBase = " << fRootFileNameBase;
63 INFOFinal(
"The Module will not convert to physical unit\n"
64 " Be sure of what you are doing");
75 WARNING(
"No radio event found!");
79 const REvent& rEvent =
event.GetREvent();
92 info <<
"Running RdChannelDebugWriter for event number "
93 << fEventCounter <<
" (ID = " << fLastEventID <<
") - step "
94 << fStepCounter <<
" with GPS second " << fLastEventGPSsecond;
97 if (fEventFraction > 0)
98 if (((fEventCounter - 1) % fEventFraction) != 0) {
100 info <<
"Skip event, because only every " << fEventFraction
101 <<
"th event is considered for debug output (as set in XML).";
107 if (!fRootFileNameBase.empty())
108 writeRootOutput(rEvent);
111 if (!fAsciiSpectrumNameBase.empty())
112 writeAsciiSpectrum(rEvent);
115 if (!fAsciiTraceNameBase.empty())
116 writeAsciiTrace(rEvent);
123 RdChannelDebugWriter::writeRootOutput(
const REvent& rEvent)
127 count <<
'_' << fLastEventGPSsecond <<
"_Step-" << fStepCounter;
128 TFile OutputFile((fRootFileNameBase + count.str() +
".root").c_str(),
"recreate");
131 float unitmuvpermhz = 1;
137 for (
const auto& station : rEvent.StationsRange()) {
140 if (!fStationIds.empty() && fStationIds.find(station.GetId()) == fStationIds.end())
144 stat <<
"Station_" << station.GetId();
146 for (
const auto& channel : station.ChannelsRange()) {
148 if (!channel.IsActive())
152 if (!fChannelIds.empty() && fChannelIds.find(channel.GetId()) == fChannelIds.end())
156 const auto& spectrum = channel.GetChannelFrequencySpectrum();
157 const auto& trace = channel.GetChannelTimeSeries();
160 chan <<
"_Ch." << channel.GetId();
163 const double tsSize = trace.GetSize();
164 const double tsStart = trace.GetStart() /
nanosecond;
165 const double tsStop = (trace.GetSize() - 1) /
nanosecond;
167 (stat.str() + chan.str() +
"_TimeSeries" + count.str()).c_str(),
168 (stat.str() + chan.str() +
"_TimeSeries" + count.str()).c_str(),
169 tsSize, tsStart, tsStop
175 const double binFreqSize = spectrum.GetSize();
176 const double binFreqBegin = std::min(
177 channel.GetFrequencyOfBin(0),
178 channel.GetFrequencyOfBin(spectrum.GetSize() - 1)
181 channel.GetFrequencyOfBin(0),
182 channel.GetFrequencyOfBin(spectrum.GetSize() - 1)
186 (stat.str() + chan.str() +
"_Phase" + count.str()).c_str(),
187 (stat.str() + chan.str() +
"_Phase" + count.str()).c_str(),
188 binFreqSize, binFreqBegin, binFreqEnd
191 (stat.str() + chan.str() +
"_Abs" + count.str()).c_str(),
192 (stat.str() + chan.str() +
"_Abs" + count.str()).c_str(),
193 binFreqSize, binFreqBegin, binFreqEnd
197 for (
const auto& el : trace)
198 HistTS.SetBinContent(w++, el / unitmuv);
201 for (
const auto& el : spectrum) {
202 HistPh.SetBinContent(k, std::arg(el) /
deg);
203 HistAbs.SetBinContent(k++,
abs(el) / unitmuvpermhz);
206 HistTS.SetXTitle(
"ns");
207 HistTS.SetYTitle(
"microvolt");
208 HistPh.SetXTitle(
"MHz");
209 HistPh.SetYTitle(
"degrees");
210 HistAbs.SetXTitle(
"MHz");
211 HistAbs.SetYTitle(
"microvolt/MHz");
222 RdChannelDebugWriter::writeAsciiSpectrum(
const REvent& rEvent)
225 float unitmuvpermhz = 1;
229 for (
const auto& station : rEvent.StationsRange()) {
232 if (!fStationIds.empty() && fStationIds.find(station.GetId()) == fStationIds.end())
235 for (
const auto& channel : station.ChannelsRange()) {
237 if (!channel.IsActive())
241 if (!fChannelIds.empty() && fChannelIds.find(channel.GetId()) == fChannelIds.end())
244 const auto& spectrum = channel.GetChannelFrequencySpectrum();
248 filename << fAsciiSpectrumNameBase
249 <<
'_' << fLastEventGPSsecond
250 <<
"_s" << channel.GetStationId()
251 <<
"_c" << channel.GetId()
252 <<
"_Step-" << fStepCounter
254 ofstream outfile(filename.str().c_str());
258 outfile << channel.GetFrequencyOfBin(i) /
megahertz
259 <<
' ' <<
abs(spectrum[i]) / unitmuvpermhz
260 <<
' ' << arg(spectrum[i]) /
deg <<
'\n';
267 RdChannelDebugWriter::writeAsciiTrace(
const REvent& rEvent)
274 for (
const auto& station : rEvent.StationsRange()) {
277 if (!fStationIds.empty() && fStationIds.find(station.GetId()) == fStationIds.end())
280 for (
const auto& channel : station.ChannelsRange()) {
282 if (!channel.IsActive())
286 if (!fChannelIds.empty() && fChannelIds.find(channel.GetId()) == fChannelIds.end())
289 const auto& trace = channel.GetChannelTimeSeries();
293 filename << fAsciiTraceNameBase
294 <<
'_' << fLastEventGPSsecond
295 <<
"_s" << channel.GetStationId()
296 <<
"_c" << channel.GetId()
297 <<
"_Step-" << fStepCounter
299 ofstream outfile(filename.str().c_str());
303 outfile << trace.GetBinning() * i /
nanosecond
304 <<
' ' << trace[i] / unitmuv <<
'\n';
Interface class to access to the Radio part of an event.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
#define INFOIntermediate(y)
Class representing a document branch.
std::vector< std::complex< double > >::size_type SizeType
constexpr double nanosecond
double abs(const SVector< n, T > &v)
Header & GetHeader()
access to REvent Header
constexpr double megahertz
#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.
unsigned long GetGPSSecond() const
GPS second.
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)