2 #include <fwk/CentralConfig.h>
3 #include <fwk/VModule.h>
5 #include <rdet/RDetector.h>
6 #include <rdet/Station.h>
7 #include <utl/CoordinateSystem.h>
9 #include <evt/RadioSimulation.h>
10 #include <utl/TimeStamp.h>
11 #include <utl/TimeInterval.h>
12 #include <utl/UTCDateTime.h>
13 #include <utl/Trace.h>
14 #include <utl/AugerUnits.h>
15 #include <utl/RadioGeometryUtilities.h>
16 #include <evt/Event.h>
17 #include <evt/ShowerSimData.h>
18 #include <revt/REvent.h>
19 #include <revt/EventTrigger.h>
20 #include <revt/Station.h>
21 #include <revt/Header.h>
22 #include <revt/StationTriggerData.h>
23 #include <revt/StationSimData.h>
24 #include <utl/StringCompare.h>
29 #include <utl/FFTDataContainer.h>
31 #include <evt/SimRadioPulse.h>
32 #include <utl/MathConstants.h>
39 #include <boost/utility.hpp>
41 #include <boost/algorithm/string.hpp>
43 #include <rdet/Channel.h>
45 #define OUT(x) if ((x) <= fInfoLevel) cerr << " "
56 fMaximumDistance(5.*
meter),
59 fEventRate(0.0001*
hertz),
60 fEventTimeOffset(0.0),
61 fUseRateTiming(false),
62 fIncludedStationIds(vector<int>()),
63 fExcludedStationIds(vector<int>()),
68 RdStationInterpolatorStarShape::~RdStationInterpolatorStarShape()
75 OUT(
eFinal)<<
"RdStationInterpolatorStarShape::Init()"<<endl;
77 Branch topBranch = CentralConfig::GetInstance()->
GetTopBranch(
"RdStationInterpolatorStarShape");
91 info <<
"\n Ignoring event times provided by simulations! Using rate timing instead.\n"
95 info <<
"\n Padding time series data at front by "
97 <<
" ns and at end to a total length of at least "
115 Detector& Det = Detector::GetInstance();
124 WARNING(
"RdStationInterpolatorStarShape: Event time of RadioSimulation is not available. Aborting ...");
137 WARNING(
"RdStationInterpolatorStarShape: No SimRadioPulse in RadioSimulation. Aborting ...");
151 vector<SimPulseEntry> simPulses;
152 set<double> radiusValues;
153 set<double> azimuthValues;
154 set<double> altitudeValues;
170 simPulses.push_back(
SimPulseEntry(radius, azimuth, &srpulse));
171 radiusValues.insert(
long(radius*1000+0.5)/1000.);
172 azimuthValues.insert(
long(azimuth*1000+0.5)/1000.);
173 altitudeValues.insert(
long(altitude*1000+0.5)/1000.);
178 if (radiusValues.size()*azimuthValues.size() != simPulses.size()) {
179 WARNING(
"RdStationInterpolatorStarShape: Simulation does not have star shape. Aborting ...");
184 std::cout <<
"\nSimulation has " << radiusValues.size() <<
" rings, " << azimuthValues.size()
185 <<
" angle bins and spans heights from " << (*altitudeValues.begin()) /
meter
186 <<
" m to " << (*altitudeValues.rbegin()) /
meter <<
" m above core.\n\n" << endl;
191 sort(simPulses.begin(), simPulses.end());
197 int statID = rdIt->GetId();
204 OUT(
eObscure) <<
" -> not associated as it is in the exclude list." << endl;
211 OUT(
eObscure) <<
" -> station not associated as it is not in the include list." << endl;
216 double stationRadius = RadioGeometryUtilities::GetDistanceToAxis(simshow.
GetDirection(), simshow.
GetPosition(),
219 double stationAzimuth = (Position-simshow.
GetPosition()).GetPhi(corsys);
221 double stationAltitude = (Position.
GetZ(corsys));
224 <<
" m with azimuth " << stationAzimuth/
deg
225 <<
" degree at altitude " << stationAltitude /
meter
229 if (stationRadius >= (*radiusValues.rbegin())) {
233 else if (stationRadius <= (*radiusValues.begin())) {
234 cout <<
"\nStation " << statID <<
" is in innermost ring, skip it.\n\n";
240 long indexHighHigh = distance(radiusValues.begin(),radiusValues.upper_bound(stationRadius))*azimuthValues.size()+distance(azimuthValues.begin(),azimuthValues.upper_bound(stationAzimuth));
241 long indexHighLow = indexHighHigh-1;
243 if (indexHighHigh >=
long(simPulses.size()) ||
244 fabs(simPulses.at(indexHighHigh).fDistanceFromShowerAxis-simPulses.at(indexHighLow).fDistanceFromShowerAxis)/simPulses.at(indexHighHigh).fDistanceFromShowerAxis > 1.0e-3)
246 indexHighHigh -= azimuthValues.size();
248 long indexLowHigh = indexHighHigh-azimuthValues.size();
249 long indexLowLow = indexHighLow-azimuthValues.size();
259 double designLowerFreq = 0.0;
260 double designLowerFreqFirstCh = 0.;
261 double designUpperFreq = 0.0;
262 double designUpperFreqFirstCh = 0.;
267 if (cIt == rdIt->ChannelsBegin()) {
268 designLowerFreqFirstCh = designLowerFreq;
269 designUpperFreqFirstCh = designUpperFreq;
271 if(designLowerFreq != designLowerFreqFirstCh || designUpperFreq != designUpperFreqFirstCh) {
272 WARNING(
"RdStationInterpolatorStarShape: design frequency different for different channels");
284 const double starttime1 = simPulses.at(indexLowLow).fRadioPulse->GetStartTime();
285 const double radius1 = simPulses.at(indexLowLow).fDistanceFromShowerAxis;
286 const double azimuth1 = simPulses.at(indexLowLow).fObserverAzimuthAngle;
287 const double binning1 = simPulses.at(indexLowLow).fRadioPulse->GetEfieldTimeSeries().GetBinning();
292 const double starttime2 = simPulses.at(indexHighLow).fRadioPulse->GetStartTime();;
293 const double radius2 = simPulses.at(indexHighLow).fDistanceFromShowerAxis;
294 const double binning2 = simPulses.at(indexHighLow).fRadioPulse->GetEfieldTimeSeries().
GetBinning();
298 const double starttime3 = simPulses.at(indexLowHigh).fRadioPulse->GetStartTime();;
299 const double azimuth2 = simPulses.at(indexLowHigh).fObserverAzimuthAngle;
300 const double binning3 = simPulses.at(indexLowHigh).fRadioPulse->GetEfieldTimeSeries().
GetBinning();
304 const double starttime4 = simPulses.at(indexHighHigh).fRadioPulse->GetStartTime();;
305 const double binning4 = simPulses.at(indexHighHigh).fRadioPulse->GetEfieldTimeSeries().
GetBinning();
310 if ( (fabs(binning2 - binning1)/binning1 > 1.e-4)
311 || (fabs(binning3 - binning1)/binning1 > 1.e-4)
312 || (fabs(binning4 - binning1)/binning1 > 1.e-4) )
314 WARNING(
"RdStationInterpolatorStarShape: simtimeseries don't have the same binning. Aborting ...");
319 WARNING(
"RdStationInterpolatorStarShape: simtimeseries not in first Nyquist zone.");
323 if ( simFFTDataContainer1.GetConstFrequencySpectrum().GetSize() != simFFTDataContainer2.GetConstFrequencySpectrum().GetSize() ) {
324 WARNING(
"RdStationInterpolatorStarshape: simtimeseries don't have the same length.");
329 const revt::StationFFTDataContainer InterFFTDataContainerLeft =
Interpolate(simFFTDataContainer1, simFFTDataContainer2, radius1, radius2, stationRadius, designLowerFreqFirstCh, designUpperFreqFirstCh);
330 const double starttimeLeft = starttime1*(radius2-stationRadius)/(radius2-radius1)+starttime2*(stationRadius-radius1)/(radius2-radius1);
331 const revt::StationFFTDataContainer InterFFTDataContainerRight =
Interpolate(simFFTDataContainer3, simFFTDataContainer4, radius1, radius2, stationRadius, designLowerFreqFirstCh, designUpperFreqFirstCh);
332 const double starttimeRight = starttime3*(radius2-stationRadius)/(radius2-radius1)+starttime4*(stationRadius-radius1)/(radius2-radius1);
335 const revt::StationFFTDataContainer InterFFTDataContainer =
Interpolate(InterFFTDataContainerLeft, InterFFTDataContainerRight, azimuth1, azimuth2, stationAzimuth, designLowerFreqFirstCh, designUpperFreqFirstCh);
336 const double InterStartTime = starttimeLeft*(azimuth2-stationAzimuth)/(azimuth2-azimuth1)+starttimeRight*(stationAzimuth-azimuth1)/(azimuth2-azimuth1);
352 if(StatTimeSeries.
GetSize() != 0)
354 WARNING(
"RDStationInterpolator: StatTimeSeries not empty!" );
355 StatTimeSeries.ClearTrace();
392 V3DZero = 0.0, 0.0, 0.0;
394 double padbinning = simtimeseries.
GetBinning();
399 for (
long i=0; i<numpaddedsamples; ++i)
413 return PaddedTimeSeries;
421 const double specbinning1 = (simData1.GetConstFrequencySpectrum()).GetBinning();
438 jumps1 = 0.0,0.0,0.0;
440 jumps2 = 0.0,0.0,0.0;
444 for(
unsigned int j = 0; j < 3; j++)
446 if( i >= designlowerfreq/specbinning1 && i <= designupperfreq/specbinning1 ) {
448 double interamplitude = (
abs(freq1[i][j])*(x2-x)/(x2-x1) +
abs(freq2[i][j])*(x-x1)/(x2-x1));
453 if( arg(freq1[i][j]) < arg(freq1[i-1][j]) && jumps1[j] >= 0 )
455 if( fabs(arg(freq1[i][j])-arg(freq1[i-1][j])) > fabs(arg(freq1[i][j]) +
utl::kPi - arg(freq1[i-1][j])) )
461 if( fabs(arg(freq1[i][j])-arg(freq1[i-1][j])) > fabs(arg(freq1[i][j]) -
utl::kPi - arg(freq1[i-1][j])) )
467 if( arg(freq2[i][j]) < arg(freq2[i-1][j]) && jumps2[j] >= 0 )
469 if( fabs(arg(freq2[i][j])-arg(freq2[i-1][j])) > fabs(arg(freq2[i][j]) +
utl::kPi - arg(freq2[i-1][j])) )
475 if( fabs(arg(freq2[i][j])-arg(freq2[i-1][j])) > fabs(arg(freq2[i][j]) -
utl::kPi - arg(freq2[i-1][j])) )
483 phaseElement1[j] = arg(freq1[i][j]) + jumps1[j]*2*
utl::kPi;
484 phaseElement2[j] = arg(freq2[i][j]) + jumps2[j]*2*
utl::kPi;
487 phaseElementInter[j] = (phaseElement1[j]*(x2-x)/(x2-x1) + phaseElement2[j]*(x-x1)/(x2-x1));
490 element[j]=polar(interamplitude,phaseElementInter[j]);
503 return interpolatedFFTDataContainer;
std::vector< int > fIncludedStationIds
Branch GetTopBranch() const
boost::transform_iterator< InternalStationFunctor, InternalStationIterator, const Station & > StationIterator
StationIterator returns a pointer to a station.
utl::TimeStamp fFirstEventTime
void Update(const utl::TimeStamp &time, const bool invData=true, const bool invComp=true, const bool forceRadio=false)
Update detector: deletes currently constructed stations and sets new time.
double GetBinning() const
Get the sampling time scale.
Report success to RunController.
double GetDesignUpperFreq() const
Get design value of the freq-band.
int GetEventNumber() const
Get the event number of the RadioSimulation.
Interface class to access to the Radio part of an event.
StationIterator StationsEnd() const
End of the collection of pointers to commissioned stations.
unsigned int GetNyquistZone() const
get the Nyquist zone
void MakeSimData()
Make station simulated data object.
double Interpolate(const double dx, const double dy, const double x)
Data structure for simulated Radio pulses.
StationIterator StationsBegin() const
Beginning of the collection of pointers to commissioned stations.
double GetDesignLowerFreq() const
Get design value of the freq-band.
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
Data structure for a radio simulation (including several SimRadioPulses)
double GetBinning() const
size of one slot
utl::Point GetLocation() const
void Init()
Initialise the registry.
revt::REvent & GetREvent()
Detector description interface for Channel-related data.
revt::StationTimeSeries PadTimeSeries(const evt::SimRadioPulse &simtimeseries)
padding of zeros to the end of the simtimeseries
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
StationTimeSeries & GetStationTimeSeries()
retrieve Station Time Series (write access, only use this if you intend to change the data) ...
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...
std::vector< T >::const_iterator ConstIterator
A TimeStamp holds GPS second and nanosecond for some event.
bool HasPosition() const
Check initialization of shower geometry.
Detector description interface for RDetector-related data.
void MakeGPSData()
Make GPS data object.
void MakeTriggerData()
Make trigger data object.
void SetExternalTrigger(const bool trig)
Set if Event was externally triggered.
Interface class to access Shower Simulated parameters.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
class to hold data at the radio Station level.
void SetRawTraceStartTime(const utl::TimeStamp &time)
Set absolute start time of the station-level trace as originally provided in raw data, for reconstructions use eTraceStartTime in StationRecData!
double fTracePaddingAtFront
revt::StationFFTDataContainer Interpolate(const revt::StationFFTDataContainer &simData1, const revt::StationFFTDataContainer &simData2, double x1, double x2, double x, double designlowerfreq, double designupperfreq)
interpolation between two pulses
const utl::Vector & GetDirection() const
Get the direction of the shower axis. This is the true direction of shower movement.
C< F > & GetFrequencySpectrum()
read out the frequency spectrum (write access)
std::vector< T >::size_type SizeType
void MakeTrigger()
Create the central trigger object.
std::vector< int > fExcludedStationIds
RadioSimulation & GetRadioSimulation()
Get the radio simulation data.
constexpr double nanosecond
double abs(const SVector< n, T > &v)
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
get local coordinate system anchored at the core position
const utl::Point & GetPosition() const
Get the position of the shower core.
Header & GetHeader()
access to REvent Header
Top of the hierarchy of the detector description interface.
ShowerSimData & GetSimShower()
C< T > & GetTimeSeries()
read out the time series (write access)
utl::TimeInterval fEventTimeOffset
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
boost::indirect_iterator< InternalChannelIterator, const Channel & > ChannelIterator
ChannelIterator returns a pointer to a Channel.
void SetBinning(const double binning)
const SimRadioPulse & GetNextSimRadioPulse(bool &ok)
const utl::TimeStamp & GetEventTime() const
Get the event time of the RadioSimulation.
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.
bool GoToFirstSimRadioPulse()
Jump to the first SimRadioPulse, returns false if the vector is empty.
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
void MakeGeometry(const utl::Point &pointOnShowerAxis)
initialize the shower geometry. Pos is a point on the shower axis, but not necessarily the core ...
Report failure to RunController, causing RunController to terminate execution.
void MakeTimeStamp(const utl::TimeStamp &ts)
Make the TimeStamp of the shower.
int GetRunNumber() const
Get the run number of the RadioSimulation.
const rdet::RDetector & GetRDetector() const
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
void PushBack(const T &value)
Insert a single value at the end.
const Station & GetStation(const int stationId) const
Get station by Station Id.
const utl::TraceV3D & GetEfieldTimeSeries() const
Get the Trace of the simulated electric field.
void MakeStation(const int stationId)
make a station with specifying Id, throw if invalid stationId
double fMinimumTraceLength
void BuildSimShower(evt::ShowerSimData &theshower, const utl::CoordinateSystemPtr &coord)
BuildSimShower---------------------------------------------------------------------------------------...