3 #include <utl/ErrorLogger.h>
6 #include <evt/ShowerRecData.h>
7 #include <evt/ShowerRRecData.h>
8 #include <evt/BeamQuantities.h>
9 #include <revt/REvent.h>
10 #include <revt/Header.h>
11 #include <revt/Station.h>
13 #include <rdet/RDetector.h>
15 #include <utl/Trace.h>
16 #include <utl/TraceAlgorithm.h>
17 #include <utl/ErrorLogger.h>
18 #include <utl/Reader.h>
19 #include <utl/config.h>
20 #include <utl/AugerUnits.h>
21 #include <utl/Triple.h>
22 #include <utl/FFTDataContainerAlgorithm.h>
23 #include <utl/CoordinateSystemPtr.h>
25 #include <fwk/CentralConfig.h>
26 #include <fwk/LocalCoordinateSystem.h>
28 #include <Minuit2/MnMinimize.h>
29 #include <Minuit2/VariableMetricMinimizer.h>
30 #include <Minuit2/FunctionMinimum.h>
31 #include <Minuit2/MnPrint.h>
40 #define PRINT(...) {stringstream msg; msg << __VA_ARGS__; INFO(msg.str());}
47 RdBeamTimeOptimizer::~RdBeamTimeOptimizer()
54 INFO(
"RdBeamTimeOptimizer::Init()");
57 CentralConfig::GetInstance()->
GetTopBranch(
"RdBeamTimeOptimizer");
80 void RdBeamTimeOptimizer::shiftsToDelays(
REvent& rEvent,
TimeStamp meanTime, vector<double> ×) {
85 vector<double>::iterator time = times.begin();
86 for (; stat != rEvent.
StationsEnd(); ++stat, ++time) {
87 (*time) += ( stat -> GetTraceStartTime() - meanTime).GetInterval();
91 void RdBeamTimeOptimizer::delaysToShifts(
REvent& rEvent,
TimeStamp meanTime, vector<double> ×) {
96 vector<double>::iterator time = times.begin();
97 for (; stat != rEvent.
StationsEnd(); ++stat, ++time) {
98 (*time) -= ( stat -> GetTraceStartTime() - meanTime ).GetInterval();
106 waveModel->setSkyPos (skyPos);
107 const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
109 vector<double> delays;
114 delays.push_back( waveModel->delay(pos) );
123 waveModel->setSkyPos (skyPos);
124 const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
126 vector<double> shifts;
129 double middleOfTrace;
131 int start = stat->GetConstStationTimeSeries().GetStart(),
132 stop = stat->GetConstStationTimeSeries().GetStop();
133 if ((startbin != -1) && (startbin > start)) start = startbin;
134 if ((stopbin != -1) && (stopbin < stop)) stop = stopbin;
135 middleOfTrace = (stop+start) * stat->GetConstStationTimeSeries().GetBinning() /2.0;
141 shifts.push_back( waveModel->delay(pos) - (stat -> GetTraceStartTime() - rrec.GetCoreTime()).GetInterval() + middleOfTrace );
151 for (
int i = 0; i < (stop-start); i++, it++)
152 out[i] = it->GetMag2();
156 const vector<double>& shifts)
const {
166 int start = it->GetConstStationTimeSeries().GetStart(),
167 stop = it->GetConstStationTimeSeries().GetStop();
168 if ((startbin != -1) && (startbin > start)) start = startbin;
169 if ((stopbin != -1) && (stopbin < stop)) stop = stopbin;
171 TraceD sum(stop-start, it->GetConstStationTimeSeries().GetBinning()),
172 addend(stop-start, it->GetConstStationTimeSeries().GetBinning());
174 vector<double>::const_iterator shiftIt = shifts.begin();
176 for (; it != rEvent.
StationsEnd(); ++it, ++shiftIt) {
184 efieldtopower (ts, addend, start, stop);
189 return sum * (1.0 / num) ;
200 uint n = it1->GetSize();
201 for (
int i = 0; i < (stop-start); ++i, ++it1, ++it2) {
203 for (uint j = 0; j < n; ++j)
204 prod += it1->At(j) * it2->At(j);
209 const vector<double>& shifts)
const {
216 int start = it->GetConstStationTimeSeries().GetStart(),
217 stop = it->GetConstStationTimeSeries().GetStop();
218 if ((startbin != -1) && (startbin > start)) start = startbin;
219 if ((stopbin != -1) && (stopbin < stop)) stop = stopbin;
221 TraceD sum(stop-start, it->GetConstStationTimeSeries().GetBinning()),
222 addend(stop-start, it->GetConstStationTimeSeries().GetBinning());
226 vector<double>::const_iterator shiftIt = shifts.begin();
227 for (uint i=0; it != rEvent.
StationsEnd(); ++it, ++shiftIt, ++i) {
228 stationData[i] = it->GetFFTDataContainer();
235 for (uint i=0; i < n; ++i)
236 for (uint j=i+1; j < n; ++j) {
237 efieldproduct (stationData[i].GetTimeSeries(),stationData[j].GetTimeSeries(), addend, start, stop);
242 return sum * (1.0/num);
246 RdBeamTimeOptimizer::xtrace (
TraceD ccTrace,
double ccMean,
TraceD pwNormal) {
250 for (;it != result.
End(); it++, itPW++) {
251 (*it) *=
abs ( (*it - ccMean) / (*itPW) );
261 RdBeamTimeOptimizer::findPeak (
const TraceD& trace) {
263 const double maxval = *
max;
264 const int maxi = (max - trace.
Begin());
265 const double maxtime = maxi * trace.
GetBinning();
273 return evt::BeamPeak ( maxval, maxtime, rms, offset);
277 RdBeamTimeOptimizer::writeRecData(
REvent &rEvent, std::vector<double> &shifts){
279 std::vector<double>::const_iterator shift = shifts.begin();
282 if (!stat->HasRecData()) {stat->MakeRecData();}
283 stat->GetRecData().SetSignalTime(stat -> GetTraceStartTime() + ((*shift) + peakTime));
293 DEBUGLOG(
"RdBeamTimeOptimizer::Run()");
297 WARNING(
"No radio event found!");
298 return eContinueLoop;
303 stringstream fMessage;
304 fMessage <<
"Radio event found with "
308 INFO(fMessage.str());
313 fMessage <<
"Header ID "
317 INFO(fMessage.str());
324 using namespace ROOT::Minuit2;
325 MnUserParameters upar;
327 if (!event.
HasRecShower() || !
event.GetRecShower().HasRRecShower()) {
328 WARNING(
"No RRecShower found!");
329 WARNING(
"Falling back to: All time shifts 0.0 initially." );
331 for (
int i=0; i<nStat; i++)
332 { stringstream parname; parname <<
"shift " <<i;
333 upar.Add(parname.str(), 0.0, 10000.0 *
nanosecond);
338 INFO(
"RRecShower found.\nCalculating start time shift values from wave model "
339 "with Axis and CorePosition.");
342 std::vector <double> startTimes = shiftsFromRRec(rEvent, rrec);
345 for (std::vector<double>::const_iterator it=startTimes.begin();
346 it!=startTimes.end();it++,i++)
347 { stringstream parname; parname <<
"shift " <<i;
348 upar.Add(parname.str(), (*it), 10000.0 *
nanosecond);
354 msg<<
"Start parameters (time shifts): ";
355 vector<double> params = upar.Params();
356 copy (params.begin(),
358 ostream_iterator<double> (msg,
"\t"));
362 INFO (
"Maximizing power peak ...");
365 MnMinimize
m( static_cast<const FCNBase&>(fcn), upar);
366 FunctionMinimum fmin =
m(10000);
368 upar = fmin.UserParameters();
374 msg<<
"Shifts after optimizing power peak: ";
375 vector<double> params = upar.Params();
376 copy (params.begin(),
378 ostream_iterator<double> (msg,
"\t"));
382 INFO (
"Maximizing cross corellation peak");
385 MnMinimize
m( static_cast<const FCNBase&>(fcn), upar);
386 FunctionMinimum fmin =
m(10000);
388 upar = fmin.UserParameters();
393 msg<<
"Shifts after optimizing cross correlation peak: ";
394 vector<double> params = upar.Params();
395 copy (params.begin(),
397 ostream_iterator<double> (msg,
"\t"));
400 INFO (
"Writing Params to StationRecData.");
401 writeRecData(rEvent, params);
458 RdBeamTimeOptimizer::Finish()
460 INFO(
"RdBeamTimeOptimizer::Finish()");
472 station.GetConstStationFrequencySpectrum();
476 outfile.open(filename.c_str(),
ios::out);
493 const evt::BeamPeak &pwPeak,
const evt::BeamPeak & ccPeak,
const evt::BeamPeak &xPeak,
498 WriteTrace3D((power-pwPeak.GetOffset()) / pwPeak.GetRMS(),
499 "pw_"+outfile, rThetaPhi);
501 WriteTrace3D((cc-ccPeak.GetOffset()) / ccPeak.GetRMS(),
502 "cc_"+outfile, rThetaPhi);
504 WriteTrace3D((x-xPeak.GetOffset()) / xPeak.GetRMS(),
505 "x_"+outfile, rThetaPhi);
520 const evt::BeamPeak &pwPeak,
521 const evt::BeamPeak &ccPeak,
522 const evt::BeamPeak &xPeak,
525 utl::Triple xyz = boost::make_tuple( coords.get<0>() /
km, coords.get<1>() /
km, coords.get<2>() /
km );
527 WriteTrace3D((power ) / pwPeak.GetRMS(),
530 WriteTrace3D((cc ) / ccPeak.GetRMS(),
533 WriteTrace3D((x ) / xPeak.GetRMS(),
538 RdBeamTimeOptimizer::WriteTrace3D(
const TraceD& trace,
544 outfile.open(filename.c_str(),
ios::out|ios::app);
548 outfile << coords.get<0>() <<
" "
549 << coords.get<1>() <<
" "
550 << coords.get<2>() <<
" "
563 outfile.open(filename.c_str(),
ios::out|ios::app);
564 outfile << coords.get<0> () <<
" "
565 << coords.get<1> () <<
" "
566 << coords.get<2> () <<
" "
Branch GetTopBranch() const
utl::Vector GetAxis() const
Returns vector of the shower axis.
double GetFrequencyOfBin(const StationFrequencySpectrum::SizeType bin) const
Get the frequency corresponding to a bin of the frequency spectrum.
SizeType GetStop() const
Get valid data stop bin.
bool HasRecShower() const
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.
Interface class to access to the RD Reconstruction of a Shower.
double GetBinning() const
size of one slot
Plane wave arrival Delays for Radio Imaging.
#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.
const phoenix::function< PowerToImpl > power
std::vector< T >::const_iterator ConstIterator
A TimeStamp holds GPS second and nanosecond for some event.
Exception for reporting variable out of valid range.
Detector description interface for RDetector-related data.
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
int GetNumberOfStations() const
Get total number of stations in the event.
C< T > & GetTimeSeries()
read out the time series (write access)
static double RMS(const Trace< T > &trace, const unsigned int bin1, const unsigned int bin2)
constexpr double megahertz
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.
void writeValue3D(double val, const string &filename, const utl::Triple &coords)
Template class for a data container that offers and takes both time series and corresponding frequenc...
A TimeInterval is used to represent time elapsed between two events.
ResultFlag
Flag returned by module methods to the RunController.
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.
utl::Point GetCorePosition() const
returns pointer of the position vector of the core in the reference coor system
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
const Station & GetStation(const int stationId) const
Get station by Station Id.
Spherical wave arrival Delays for Radio Imaging.
std::vector< double >::iterator Iterator