11 #include <evt/Event.h>
12 #include <evt/ShowerRecData.h>
13 #include <evt/ShowerRRecData.h>
14 #include <evt/ShowerSimData.h>
15 #include <evt/BeamQuantities.h>
16 #include <revt/REvent.h>
17 #include <revt/Header.h>
18 #include <revt/Station.h>
19 #include <revt/Channel.h>
20 #include <revt/StationRecData.h>
22 #include <det/Detector.h>
23 #include <rdet/RDetector.h>
25 #include <utl/Trace.h>
26 #include <utl/TraceAlgorithm.h>
27 #include <utl/ErrorLogger.h>
28 #include <utl/Reader.h>
29 #include <utl/config.h>
30 #include <utl/AugerUnits.h>
31 #include <utl/PhysicalConstants.h>
32 #include <utl/Triple.h>
33 #include <utl/FFTDataContainerAlgorithm.h>
34 #include <utl/TimeStamp.h>
35 #include <utl/UTCDateTime.h>
36 #include <utl/UTMPoint.h>
37 #include <utl/CoordinateSystem.h>
38 #include <utl/CoordinateSystemPtr.h>
39 #include <utl/ReferenceEllipsoid.h>
40 #include <utl/RadioGeometryUtilities.h>
53 #include <fwk/CentralConfig.h>
54 #include <fwk/LocalCoordinateSystem.h>
55 #include <fwk/MagneticFieldModel.h>
76 #define PRINT(...) {stringstream msg; msg << __VA_ARGS__; INFO(msg.str());}
78 #define SSTR( x ) dynamic_cast< std::ostringstream & >(( std::ostringstream() << std::dec << x ) ).str()
86 RdBeamFormer::~RdBeamFormer()
93 INFO(
"RdBeamFormer::Init()");
113 std::string confstring;
118 if (confstring ==
"ePolar")
120 else if (confstring ==
"eCarthesian")
131 double RdBeamFormer::shiftTraces(std::vector<revt::StationFFTDataContainer>& stationData,
int& nStat,
double& binning,
142 std::vector<int> start_bins;
143 std::vector<int> stop_bins;
144 std::vector<double> shifts;
146 const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
148 REvent& rEvent =
event.GetREvent();
151 binning = it->GetConstStationTimeSeries().GetBinning();
152 double offset = (stop - start) * binning *
offsetfactor;
163 static double old_binning = it->GetConstStationTimeSeries().GetBinning();
164 double new_binning = it->GetConstStationTimeSeries().GetBinning();
165 if (
abs(new_binning - old_binning) >= eps) {
166 ERROR (
"Traces have different binning!");
171 start_bins.push_back(it->GetConstStationTimeSeries().GetStart());
172 stop_bins.push_back(it->GetConstStationTimeSeries().GetStop());
176 double traceStartTime = 0.;
180 ERROR (
"Parameter eTraceStartTime is not set!");
184 double signalTime = 0.;
188 ERROR (
"Parameter eSignalTime is not set!");
194 shift=shift-traceStartTime;
195 shifts.push_back(-shift + offset);
199 std::vector<double>::iterator min_shift_iter;
200 std::vector<double>::iterator max_shift_iter;
202 min_shift_iter = std::min_element(shifts.begin(), shifts.end());
203 max_shift_iter = std::max_element(shifts.begin(), shifts.end());
205 int min_pos = min_shift_iter - shifts.begin();
206 int max_pos = max_shift_iter - shifts.begin();
208 double min_shift = *min_shift_iter;
209 double max_shift = *max_shift_iter;
213 int max_start = *std::max_element(start_bins.begin(), start_bins.end());
215 int min_stop = *std::min_element(stop_bins.begin(), stop_bins.end());
311 double traceStartTime = sRec.
GetParameter(eTraceStartTime);
328 if (min_shift >= 0 && max_shift >=0) {
333 else if (min_shift < 0 && max_shift < 0) {
338 else if (min_shift <= 0 && max_shift >= 0) {
349 if (min_shift >= 0 && max_shift >=0) {
351 start = (max_shift - min_shift)/binning + 1;
353 if (start < max_start)
356 while (stop - start < 100) {
357 shifts.erase(shifts.begin() + max_pos);
358 stationData.erase(stationData.begin() + max_pos);
360 min_shift_iter = std::min_element(shifts.begin(), shifts.end());
361 max_shift_iter = std::max_element(shifts.begin(), shifts.end());
363 min_pos = min_shift_iter - shifts.begin();
364 max_pos = max_shift_iter - shifts.begin();
366 min_shift = *min_shift_iter;
367 max_shift = *max_shift_iter;
371 start = (max_shift - min_shift)/binning + 1;
374 if (start < max_start)
381 else if (min_shift < 0 && max_shift < 0) {
383 stop = min_stop - (max_shift - min_shift)/binning;
388 while (stop - start < 100) {
389 shifts.erase(shifts.begin() + min_pos);
390 stationData.erase(stationData.begin() + min_pos);
392 min_shift_iter = std::min_element(shifts.begin(), shifts.end());
393 max_shift_iter = std::max_element(shifts.begin(), shifts.end());
395 min_pos = min_shift_iter - shifts.begin();
396 max_pos = max_shift_iter - shifts.begin();
398 min_shift = *min_shift_iter;
399 max_shift = *max_shift_iter;
403 stop = min_stop - (max_shift - min_shift)/binning;
413 else if (min_shift <= 0 && max_shift >= 0) {
415 start = max_shift/binning + 1;
416 stop = min_stop -
abs(min_shift)/binning;
418 while (stop - start < 100) {
419 if (
abs(max_shift) -
abs(min_shift) > 0) {
420 shifts.erase(shifts.begin() + max_pos);
421 stationData.erase(stationData.begin() + max_pos);
423 min_shift_iter = std::min_element(shifts.begin(), shifts.end());
424 max_shift_iter = std::max_element(shifts.begin(), shifts.end());
426 min_pos = min_shift_iter - shifts.begin();
427 max_pos = max_shift_iter - shifts.begin();
429 min_shift = *min_shift_iter;
430 max_shift = *max_shift_iter;
434 start = max_shift/binning + 1;
435 stop = min_stop -
abs(min_shift)/binning;
438 if (start < max_start)
447 shifts.erase(shifts.begin() + min_pos);
448 stationData.erase(stationData.begin() + min_pos);
450 min_shift_iter = std::min_element(shifts.begin(), shifts.end());
451 max_shift_iter = std::max_element(shifts.begin(), shifts.end());
453 min_pos = min_shift_iter - shifts.begin();
454 max_pos = max_shift_iter - shifts.begin();
456 min_shift = *min_shift_iter;
457 max_shift = *max_shift_iter;
461 start = max_shift/binning + 1;
462 stop = min_stop -
abs(min_shift)/binning;
465 if (start < max_start)
496 return offset - start*binning;
503 int n = it1->GetSize();
506 for (
int i = 0; i < (stop-start); ++i) {
508 for (
int j = 0; j < n; ++j) {
509 prod += it1->At(j) * it2->At(j);
517 TraceD RdBeamFormer::crosscorr (std::vector<revt::StationFFTDataContainer>& stationData,
int nStat,
518 double binning,
int start,
int stop) {
519 TraceD sum(stop-start, binning);
520 TraceD addend(stop-start, binning);
521 TraceD res(stop-start, binning);
523 double pair_of_Stat = nStat*(nStat-1)/2;
525 for (
int i=0; i < nStat; ++i) {
526 for (
int j=i+1; j < nStat; ++j) {
527 efieldproduct (stationData[i].GetTimeSeries(),stationData[j].GetTimeSeries(), addend, start, stop);
543 return sum*(1.0/pair_of_Stat);
548 for (
int i = 0; i < (stop-start); ++i) {
549 out[i] = it->GetMag2();
554 TraceD RdBeamFormer::powertrace (std::vector<revt::StationFFTDataContainer>& stationData,
555 int nStat,
double binning,
int start,
int stop) {
556 TraceD sum(stop-start, binning);
557 TraceD addend(stop-start, binning);
558 TraceD res(stop-start, binning);
560 for (
int i = 0; i<nStat; ++i) {
574 return sum*(1.0/nStat);
582 (*it) *=
abs ( (*itCC) / (*itPW) );
589 evt::BeamPeak RdBeamFormer::findPeak (
const TraceD& trace,
const double timeOffset) {
591 const double maxval = *
max;
592 const int maxi = (max - trace.
Begin());
593 const double maxtime = maxi * trace.
GetBinning();
615 const double mean = algo.
Mean ( trace, start, stop);
616 const double snr = maxval/rms;
620 return evt::BeamPeak ( maxval, maxtime, rms, snr);
630 WARNING(
"No radio event found!");
634 REvent& rEvent =
event.GetREvent();
638 PRINT (
"Header ID: " << rHeader.
GetId() <<
" and timestamp: " << rHeader.
GetTime());
640 if (!event.
HasRecShower() || !
event.GetRecShower().HasRRecShower()) {
641 WARNING(
"No RecShower or RRecShower found!");
658 WARNING (
"Not enough stations found to perform beam-forming!");
797 std::vector<StationFFTDataContainer> stationData(n);
800 double timeOffset =
shiftTraces(stationData, n, binning, start, stop, event);
806 WARNING (
"Not enough stations found to perform beam-forming!");
813 evt::BeamPeak ccPeak =
findPeak (cc, timeOffset);
814 evt::BeamPeak pwPeak =
findPeak (power, timeOffset);
816 TraceD x =
xtrace(cc, cc-ccPeak.GetOffset(), power-pwPeak.GetOffset());
817 evt::BeamPeak xPeak =
findPeak (x, timeOffset);
819 WriteASCII (cc, power, x, ccPeak, pwPeak, xPeak, event);
1138 RdBeamFormer::Finish()
1140 INFO(
"RdBeamFormer::Finish()");
1148 const evt::BeamPeak& ccPeak,
const evt::BeamPeak& pwPeak,
const evt::BeamPeak& xPeak,
1154 static std::string outfile_name =
outfile +
"_";
1158 int eventId =
event.GetREvent().GetHeader().GetId();
1159 std::string stringId =
SSTR(eventId);
1161 static int oldId = -1;
1163 if (eventId != oldId) {
1167 std::string buffer =
SSTR(oldId) +
"_";
1168 outfile_name.replace(
outfile.size()+1,buffer.size(),buffer);
1174 double r = polarCoords.get<0>()/
km;
1175 static double oldR = -1;
1177 if (
abs(r - oldR) >=
eps) {
1181 std::string buffer =
SSTR(oldR);
1182 outfile_name.replace(
outfile.size()+stringId.size()+2,buffer.size()+10,buffer);
1188 static double oldRho = -1;
1190 if (
abs(Rho - oldRho) >= eps) {
1194 std::string buffer =
SSTR(oldRho);
1195 outfile_name.replace(
outfile.size()+stringId.size()+2,buffer.size()+10,buffer);
1203 static double old_Rho = -1;
1204 static double old_b = -1;
1206 if (
abs(b - old_b) >= eps) {
1211 std::string buffer1 =
SSTR(old_Rho);
1212 std::string buffer2 =
SSTR(old_b);
1213 std::string buffer = buffer1 +
"_" + buffer2;
1214 outfile_name.replace(
outfile.size()+stringId.size()+2,buffer.size()+10,buffer);
1226 WritePeak(ccPeak,
"cc_max_"+outfile_name+
".txt", rrec);
1227 WritePeak(pwPeak,
"pw_max_"+outfile_name+
".txt", rrec);
1228 WritePeak(xPeak,
"x_max_"+outfile_name+
".txt", rrec);
1231 void RdBeamFormer::WriteTrace(
const TraceD& trace,
const evt::BeamPeak &Peak,
1234 fout.open(filename.c_str(),
ios::out|ios::app);
1240 fout<<polarCoords.get<0>()/
km<<
" "<<polarCoords.get<1>()/
degree<<
" "<<polarCoords.get<2>()/
degree<<
" "
1242 <<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1252 <<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1261 <<polarCoords.get<0>()/
km<<
" "<<polarCoords.get<1>()/
degree<<
" "<<polarCoords.get<2>()/
degree<<
" "
1263 <<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1273 fout<<xyz.get<0>()/
km<<
" "<<xyz.get<1>()/
km<<
" "<<xyz.get<2>()/
km<<
" "
1275 <<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1285 <<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1294 <<xyz.get<0>()/
km<<
" "<<xyz.get<1>()/
km<<
" "<<xyz.get<2>()/
km<<
" "
1296 <<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1310 fout.open(filename.c_str(),
ios::out|ios::app);
1315 fout<<polarCoords.get<0>()/
km<<
" "<<polarCoords.get<1>()/
degree<<
" "<<polarCoords.get<2>()/
degree<<
" "
1316 <<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1323 <<polarCoords.get<2>()/
degree<<
" "<<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1330 <<polarCoords.get<1>()/
degree<<
" "<<polarCoords.get<2>()/
degree<<
" "<<Peak.GetHeight()<<
" "
1331 <<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1339 fout<<xyz.get<0>()/
km<<
" "<<xyz.get<1>()/
km<<
" "<<xyz.get<2>()/
km<<
" "<<Peak.GetHeight()<<
" "
1340 <<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1347 <<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
1354 <<xyz.get<2>()/
km<<
" "<<Peak.GetHeight()<<
" "<<Peak.GetTime()<<
" "<<Peak.GetOffset()<<
"\n";
Branch GetTopBranch() const
Class to access station level reconstructed data.
utl::Vector GetAxis() const
Returns vector of the shower axis.
boost::filter_iterator< CandidateStationFilter, AllStationIterator > CandidateStationIterator
Iterator over all CandidateStations (i.e., HasSignal, HasNoSignal)
Report success to RunController.
SizeType GetStop() const
Get valid data stop bin.
bool HasRecShower() const
CandidateStationIterator CandidateStationsEnd()
Interface class to access to the Radio part of an event.
static double Mean(const Trace< T > &trace, const unsigned int bin1, const unsigned int bin2)
Evaluate the mean of trace between bin1 and bin2.
Skip remaining modules in the current loop and continue with next iteration of the loop...
Interface class to access to the RD Reconstruction of a Shower.
double GetBinning() const
size of one slot
#define INFO(message)
Macro for logging informational messages.
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.
const phoenix::function< PowerToImpl > power
std::vector< T >::const_iterator ConstIterator
Detector description interface for RDetector-related data.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
boost::tuple< double, double, double > Triple
Coordinate triple for easy getting or setting of coordinates.
class to hold data at the radio Station level.
algorithms to manipulate traces
std::vector< T >::size_type SizeType
constexpr double nanosecond
#define DEBUGLOG(message)
Macro for logging debugging messages.
double abs(const SVector< n, T > &v)
static void ShiftTimeSeries(FFTDataContainer< C, T, F > &container, const TimeInterval &shift)
shifts the time series of the FFTDataContainer in time
Header & GetHeader()
access to REvent Header
CandidateStationIterator CandidateStationsBegin()
Algorithms working on FFTDataContainer objects.
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
static double RootMeanSquare(const Trace< T > &trace, const unsigned int bin1, const unsigned int bin2)
Evaluate the RootMeanSquare of trace between bin1 and bin2.
double GetParameter(const Parameter i) const
ResultFlag
Flag returned by module methods to the RunController.
bool HasParameter(const Parameter i) const
const StationFFTDataContainer & GetFFTDataContainer() const
retrieve Station FFTDataContainer (read access)
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
SizeType GetStart() const
Get valid data start bin.
Report failure to RunController, causing RunController to terminate execution.
utl::Point GetCorePosition() const
returns pointer of the position vector of the core in the reference coor system
double GetParameter(const Parameter i) const
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
#define ERROR(message)
Macro for logging error messages.
const Station & GetStation(const int stationId) const
Get station by Station Id.
std::vector< double >::iterator Iterator