RdStationDebugWriter.cc
Go to the documentation of this file.
1 #include "RdStationDebugWriter.h"
2 
3 #include <fwk/CentralConfig.h>
4 
5 #include <utl/ErrorLogger.h>
6 #include <utl/Reader.h>
7 #include <utl/config.h>
8 
9 #include <evt/Event.h>
10 #include <revt/REvent.h>
11 #include <revt/Header.h>
12 #include <revt/Station.h>
13 
14 
15 using namespace fwk;
16 using namespace utl;
17 using namespace revt;
18 using namespace evt;
19 using std::ostringstream;
20 using std::ofstream;
21 using std::endl;
22 using std::ios;
23 
24 
26 
29  {
30  INFO("RdStationDebugWriter::Init()");
31  // Read in of the xml-configuration
32  Branch topBranch =
33  CentralConfig::GetInstance()->GetTopBranch("RdStationDebugWriter");
34  topBranch.GetChild("AsciiSpectrumNameBase").GetData(fAsciiSpectrumNameBase);
35  topBranch.GetChild("AsciiTraceNameBase").GetData(fAsciiTraceNameBase);
36 
37  return eSuccess;
38  }
39 
40 
42  RdStationDebugWriter::Run(evt::Event& event)
43  {
44  // Check if radio event data exists
45  if (!event.HasREvent()){
46  ERROR ("Event has no radio event. Use RdStationAssociator i.e.!");
47  return eContinueLoop;
48  }
49  REvent& rEvent = event.GetREvent();
50 
51  // Get the event id and and check if it has changed since the last time
52  if ( fLastEventID != rEvent.GetHeader().GetId() ) {
53  ++fEventCounter;
54  fStepCounter = 0;
55  fLastEventID = rEvent.GetHeader().GetId();
56  } else {
57  ++fStepCounter;
58  }
59 
60  ostringstream info;
61 
62  // Loop over all stations in the radio event
63  for (const auto& station : rEvent.StationsRange()) {
64 
65  // Get the frequency spectrum
66  const auto& spectrum = station.GetStationFrequencySpectrum();
67 
68  info.str("");
69  info << "Spectrum reaches from " << station.GetFrequencyOfBin(0) / megahertz
70  << " MHz to " << station.GetFrequencyOfBin(spectrum.GetSize() - 1) / megahertz
71  << " MHz with a binning of " << spectrum.GetBinning() / megahertz << " MHz.";
72  INFO(info);
73 
74  // Open ascii file for specrum data
75  ostringstream filenamespec;
76  filenamespec << fAsciiSpectrumNameBase << "_" << fLastEventID
77  << "_s" << station.GetId()
78  << "_Step-" << fStepCounter << ".dat";
79 
80  ofstream outfilespec;
81  outfilespec.open(filenamespec.str().c_str(), ios::out);
82 
83  // Write the frequency, the amplitude, and the phase of the spectrum binwise to the file
84  for (auto i = 0LU; i < spectrum.GetSize(); ++i){
85  outfilespec << station.GetFrequencyOfBin(i) / megahertz
86  << " " << abs(spectrum[i][0]) / ((micro*volt)/(meter*megahertz))
87  << " " << abs(spectrum[i][1]) / ((micro*volt)/(meter*megahertz))
88  << " " << abs(spectrum[i][2]) / ((micro*volt)/(meter*megahertz))
89  << endl;
90  }
91  outfilespec.close();
92 
93  // Get the time series
94  const auto& timeSeries = station.GetStationTimeSeries();
95 
96  info.str("");
97  info << "Trace consists of " << timeSeries.GetSize() << " bins with a binning of "
98  << timeSeries.GetBinning()/nanosecond << " ns.";
99  INFO(info);
100 
101  // Open ascii file for trace data
102  ostringstream filenametrc;
103  filenametrc << fAsciiTraceNameBase << "_" << fLastEventID
104  << "_s" << station.GetId()
105  << "_Step-" << fStepCounter << ".dat";
106 
107  ofstream outfiletrc;
108  outfiletrc.open(filenametrc.str().c_str(), ios::out);
109 
110  // Write the time and the amplitudes of the trace binwise to the file
111  for (auto i = 0LU; i < timeSeries.GetSize(); ++i){
112  outfiletrc << timeSeries.GetBinning() * static_cast<double>(i) / nanosecond
113  << " " << timeSeries[i][0] / (micro*volt/meter)
114  << " " << timeSeries[i][1] / (micro*volt/meter)
115  << " " << timeSeries[i][2] / (micro*volt/meter)
116  << endl;
117  }
118  outfiletrc.close();
119  }
120 
121  return eSuccess;
122  }
123 
124 
126  RdStationDebugWriter::Finish()
127  {
128  return eSuccess;
129  }
130 
131 }
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
const double meter
Definition: GalacticUnits.h:29
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
vector< t2list > out
output of the algorithm: a list of clusters
Definition: XbAlgo.cc:32
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
bool HasREvent() const
Class representing a document branch.
Definition: Branch.h:107
constexpr double nanosecond
Definition: AugerUnits.h:143
double abs(const SVector< n, T > &v)
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
constexpr double megahertz
Definition: AugerUnits.h:155
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
constexpr double micro
Definition: AugerUnits.h:65
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
int GetId() const
Definition: REvent/Header.h:21
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
const double volt
Definition: GalacticUnits.h:38

, generated on Tue Sep 26 2023.