15 #include <fwk/CentralConfig.h>
16 #include <fwk/LocalCoordinateSystem.h>
17 #include <fwk/CoordinateSystemRegistry.h>
19 #include <evt/Event.h>
20 #include <revt/Header.h>
21 #include <revt/EventTrigger.h>
23 #include <det/Detector.h>
24 #include <rdet/RDetector.h>
25 #include <rdet/Channel.h>
26 #include <rdet/Station.h>
28 #include <utl/Trace.h>
29 #include <utl/TimeStamp.h>
30 #include <utl/LeapSeconds.h>
31 #include <utl/TraceAlgorithm.h>
32 #include <utl/ErrorLogger.h>
33 #include <utl/Reader.h>
34 #include <utl/FFTDataContainerAlgorithm.h>
35 #include <utl/config.h>
36 #include <utl/AugerUnits.h>
37 #include <utl/ErrorLogger.h>
38 #include <utl/StringCompare.h>
39 #include <utl/UTCDateTime.h>
41 #include <utl/PhysicalConstants.h>
42 #include <utl/AxialVector.h>
45 #include <evt/Event.h>
46 #include <evt/ShowerRecData.h>
47 #include <evt/ShowerRRecData.h>
48 #include <revt/REvent.h>
49 #include <revt/Station.h>
50 #include <revt/Header.h>
51 #include <revt/StationRecData.h>
53 #include <CLHEP/Matrix/Matrix.h>
54 #include <CLHEP/Matrix/Vector.h>
64 REvent* RdMonitoring::fgCurrentREvent;
73 fDownsample10sTriggers(true),
74 fPathToStoreOutput(
""),
78 fBeaconFrequencies(vector<double>()),
79 fSpectrumNoiseFilterSize(31),
80 fSpectrumPeakFilterSize(9),
81 fSpectrumMinPeakSNR(0),
82 fSpectrumFractionToSearch(0.01),
89 INFO(
"RdMonitoring::Init()");
94 CentralConfig::GetInstance()->
GetTopBranch(
"RdMonitoring");
111 vector<int> dummyStationIDlist;
113 fDebugStationIds = set<int>(dummyStationIDlist.begin(), dummyStationIDlist.end());
119 if (fMinFrequency < 0 || fMinFrequency > 100) {
120 WARNING(
"MinFrequency is negative or larger than 100 MHz! Set it to 0 MHz! \n");
124 WARNING(
"MinFrequency is not smaller than MaxFrequency! Set MinFrequency to 0 MHz and MaxFrequency to 100 MHz.\n");
129 WARNING(
"MaxFrequency is larger than 100 MHz! Set it to 100 MHz! \n");
135 info <<
"Output files will be written as: \n" <<
fOutputFileName <<
'\n';
139 std::ofstream mysqloutputfile;
141 mysqloutputfile.close();
150 ERROR(
"Read event without radio part");
156 REvent& rEvent =
event.GetREvent();
176 if(beaconFrequencies.size() < 1) {
180 ERROR (
"Error reading Beacon frequencies from database");
186 if (beaconFrequencies.size() > 100) {
187 cout <<
"Too many active beacon frequencies extracted from the database!? Exiting... " << endl;
190 if (beaconFrequencies.size() < 1) {
191 cout <<
"Can not read any active beacon frequencies from the database! Exiting ..." << endl;
204 for (Station::ChannelIterator cIt = sIt->ChannelsBegin(); cIt != sIt->ChannelsEnd(); ++cIt) {
206 if (!cIt->IsActive()) {
230 double traceMax = TraceAlgorithm::Max(trace, 0, trace.
GetSize()-1) ;
231 double traceMin = TraceAlgorithm::Min(trace, 0, trace.
GetSize()-1) ;
239 std::ofstream mysqltraceoutputfile;
241 cout <<
"\tStoring trace for "
245 <<
"\tN_samples="<< trace.
GetSize() << endl;
248 mysqltraceoutputfile << j*timeBinning<<
"\t" << trace[j] << endl;
250 mysqltraceoutputfile.close();
264 double PowerInBand = 0;
265 double PowerOutsideBand = 0;
266 list<float> freqList = {28,33,38,43,51,58,69,80};
267 float PowerAt[8] = { 0. };
271 for (
float f : freqList) {
272 PowerAt[i_freqList] =
abs(spectrum[ round((f-cIt->GetFrequencyOfBin(0)/
megahertz)/(spectrum.
GetBinning()*1000)) ]);
279 std::ofstream mysqlspectrumoutputfile;
281 cout <<
"\tStoring spectrum for: "
285 <<
"\tN_samples="<< spectrum.
GetSize() << endl;
286 for (
unsigned int j = spectrum.
GetStart(); j < spectrum.
GetSize(); ++j) {
287 mysqlspectrumoutputfile << cIt->GetFrequencyOfBin(j)/
megahertz <<
"\t" <<
abs(spectrum[j]) << endl;
289 mysqlspectrumoutputfile.close();
295 for (
unsigned int j = spectrum.
GetStart()+1; j < spectrum.
GetSize(); ++j) {
297 PowerInBand +=
abs(spectrum[j]);
300 PowerOutsideBand +=
abs(spectrum[j]);
327 std::ofstream mysqloutputfile;
343 unsigned int SpectrumSize=spectrum.
GetSize()-1;
347 std::vector<float> UnsortedSpectrum;
349 UnsortedSpectrum.push_back(
abs(spectrum[i+1]));
353 std::vector<int> SpectrumSortedIndices;
354 for(
size_t i = 0; i < SpectrumSize; ++i) {
355 SpectrumSortedIndices.push_back(i);
357 std::sort(SpectrumSortedIndices.begin(),SpectrumSortedIndices.end(), [&](
int i1,
int i2) {
return UnsortedSpectrum[i1] > UnsortedSpectrum[i2]; } );
360 std::vector<int> _SpectrumPeakPos;
361 std::vector<float> _SpectrumPeakHeight;
362 for(
size_t i = 0; i < SpectrumBinsToSearch; ++i){
363 _SpectrumPeakPos.push_back(SpectrumSortedIndices[i]);
364 _SpectrumPeakHeight.push_back(UnsortedSpectrum[SpectrumSortedIndices[i]]);
368 int SpectrumNarrowBandPeaks=0;
370 std::string tempString=
"";
371 std::vector<int> SpectrumRejectedPos;
374 for(
size_t i = 0; i < SpectrumBinsToSearch; ++i){
378 if (( std::find(SpectrumRejectedPos.begin(), SpectrumRejectedPos.end(), _SpectrumPeakPos[i]) != SpectrumRejectedPos.end() )==
false){
380 double noise = TraceAlgorithm::Median(amplitudeSpectrum,
383 double snr = (_SpectrumPeakHeight[i]*_SpectrumPeakHeight[i])/(noise*noise) ;
387 SpectrumNarrowBandPeaks++;
391 double CurrentFrequency=cIt->GetFrequencyOfBin(_SpectrumPeakPos[i]+1)*1000;
393 for (
unsigned int BqIt = 0; BqIt < beaconFrequencies.size(); ++BqIt) {
394 if (TMath::Abs(CurrentFrequency - beaconFrequencies[BqIt]*1000.) < f_step) {
396 SpectrumNarrowBandPeaks-=1;
399 tempString+=
"INSERT INTO RdMonitoringBeacon (RdMonitoringChannel_id,BeaconFreq,BeaconSNR) VALUES (LAST_INSERT_ID(),"+std::to_string(beaconFrequencies[BqIt]*1000)+
","+std::to_string(snr)+
");\n";
406 SpectrumRejectedPos.push_back(j);
430 mysqloutputfile <<
"INSERT INTO RdMonitoringChannel (" <<
448 "PowerOutsideband," <<
450 "SpectrumNarrowBandPeaks," <<
469 PowerInBand <<
"," <<
470 PowerOutsideBand <<
"," <<
471 TraceOutliers <<
"," <<
472 SpectrumNarrowBandPeaks <<
"," <<
474 mysqloutputfile << tempString.c_str() ;
475 mysqloutputfile.close();
492 RdMonitoring::Finish()
Branch GetTopBranch() const
double StandardDeviation(const std::vector< double > &v, const double mean)
std::set< int > fDebugStationIds
List of station IDs which will be included into debugging file.
Report success to RunController.
double fSpectrumMinPeakSNR
bool fDownsample10sTriggers
bool IsPeriodicTrigger() const
Check if Event comes from PERIODIC trigger.
Interface class to access to the Radio part of an event.
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
std::vector< double > fBeaconFrequencies
double GetBinning() const
size of one slot
#define INFO(message)
Macro for logging informational messages.
StationIterator StationsEnd()
StationIterator StationsBegin()
void Init()
Initialise the registry.
vector< t2list > out
output of the algorithm: a list of clusters
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
bool StringEquivalent(const std::string &a, const std::string &b, Predicate p)
Utility to compare strings for equivalence. It takes a predicate to determine the equivalence of indi...
const std::vector< double > & GetBeaconFrequencies() const
Get vector of Beacon Frequencies for given detector-time from Manager.
std::string fOutputFileName
int fSpectrumNoiseFilterSize
Detector description interface for RDetector-related data.
Class representing a document branch.
Exception to use in case requested data not found in the database with detailed printout.
std::vector< std::complex< double > >::size_type SizeType
double abs(const SVector< n, T > &v)
Header & GetHeader()
access to REvent Header
Top of the hierarchy of the detector description interface.
constexpr double megahertz
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
int fSpectrumPeakFilterSize
ResultFlag
Flag returned by module methods to the RunController.
unsigned long GetGPSSecond() const
GPS second.
double fSpectrumFractionToSearch
SizeType GetStart() const
Get valid data start bin.
Report failure to RunController, causing RunController to terminate execution.
std::string fPathToStoreOutput
const rdet::RDetector & GetRDetector() const
double Mean(const std::vector< double > &v)
void PushBack(const T &value)
Insert a single value at the end.
#define ERROR(message)
Macro for logging error messages.
static revt::REvent * fgCurrentREvent