RdStationInterpolator.cc
Go to the documentation of this file.
2 #include <fwk/CentralConfig.h>
3 #include <fwk/VModule.h>
4 
5 #include <rdet/RDetector.h>
6 #include <rdet/Station.h>
7 #include <utl/CoordinateSystem.h>
8 #include <utl/Point.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 <evt/Event.h>
16 #include <evt/ShowerSimData.h>
17 #include <revt/REvent.h>
18 #include <revt/EventTrigger.h>
19 #include <revt/Station.h>
20 #include <revt/Header.h>
21 #include <revt/StationTriggerData.h>
22 #include <revt/StationSimData.h>
23 #include <utl/StringCompare.h>
24 #include <cmath>
25 #include <algorithm>
26 
27 #include <utl/FFTDataContainer.h>
28 #include <string>
29 #include <evt/SimRadioPulse.h>
30 #include <utl/MathConstants.h>
31 #include <complex>
32 #include <map>
33 #include <vector>
34 #include <iomanip>
35 #include <fstream>
36 #include <math.h>
37 #include <boost/utility.hpp>
38 #include <TRandom2.h>
39 #include <boost/algorithm/string.hpp>
40 #include <stdlib.h>
41 #include <rdet/Channel.h>
42 
43 
44 using namespace std;
45 using namespace evt;
46 using namespace det;
47 using namespace utl;
48 using namespace revt;
49 using namespace fwk;
50 
51 #define OUT(x) if ((x) <= fInfoLevel) cerr << " "
52 
53 
55 
56  typedef multimap<double, const SimRadioPulse&> PulseMMap;
57  typedef pair<double, const SimRadioPulse&> PulsePair;
58 
59 
61  fMaximumDistance(5.*meter), // not yet used since not jet tested, up to which distance the interpolation works properly
62  fTracePaddingAtFront(2000.*nanosecond),
63  fMinimumTraceLength(12000.*nanosecond),
64  fEventRate(0.0001*hertz),
65  fEventTimeOffset(0.0),
66  fUseRateTiming(false),
67  //fIncludedStationIds,
68  //fExcludedStationIds
69  fInfoLevel(-1)
70  { }
71 
72 
73  RdStationInterpolator::~RdStationInterpolator()
74  { }
75 
76 
79  {
80  OUT(eFinal) << "RdStationInterpolator::Init()" << endl;
81  string tmpstring;
82  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdStationInterpolator");
83  topBranch.GetChild("MaximumAllowedDistance").GetData(fMaximumDistance);
84  topBranch.GetChild("TracePaddingAtFront").GetData(fTracePaddingAtFront);
85  topBranch.GetChild("MinimumTraceLength").GetData(fMinimumTraceLength);
86  topBranch.GetChild("SimEventRate").GetData(fEventRate);
87  topBranch.GetChild("FirstEventTime").GetData(fFirstEventTime);
88  topBranch.GetChild("UseRateTiming").GetData(tmpstring);
89  fUseRateTiming = utl::StringEquivalent(tmpstring,"yes");
90  topBranch.GetChild("IncludedStationIds").GetData(fIncludedStationIds);
91  topBranch.GetChild("ExcludedStationIds").GetData(fExcludedStationIds);
92  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
93 
94  ostringstream info;
95  if (fUseRateTiming) {
96  info << "\n Ignoring event times provided by simulations! Using rate timing instead.\n"
97  << " First event date " << UTCDateTime(fFirstEventTime) << "\n"
98  << " Events have a rate of " << fEventRate/hertz << " Hz\n";
99  }
100  info << "\n Padding time series data at front by "
102  << " ns and at end to a total length of at least "
104  << " ns."
105  << endl;
106  OUT(eFinal) <<info.str() << endl;
107 
108  return eSuccess;
109  } //Init
110 
111 
113  RdStationInterpolator::Run(evt::Event& theevent)
114  {
115  // This module should not be used to create a sim shower. The interface of the SimRadioPulse changed.
116  INFO("I am a deprecated module. Please update me!");
117 
118  evt::ShowerSimData& simshow = theevent.GetSimShower();
119  evt::RadioSimulation& rsim = simshow.GetRadioSimulation();
120 
122  BuildSimShower(simshow,corsys);
123  Detector& Det = Detector::GetInstance();
124  TimeStamp eventtime = rsim.GetEventTime();
125 
126  // overwrite event time if fUseRateTiming is activated
127  if (fUseRateTiming)
128  eventtime = fFirstEventTime+fEventTimeOffset;
129 
130  // check if the event time has an uninitialized (illegal) value
131  if (eventtime == TimeStamp(0,0)) {
132  WARNING("RdStationInterpolator: Event time of RadioSimulation is not available. Aborting ...");
133  return eFailure;
134  }
135 
136  Det.Update(eventtime);
137  const rdet::RDetector& RadioDet = Det.GetRDetector();
138 
139  if (!theevent.HasREvent())
140  theevent.MakeREvent();
141 
142  revt::REvent& therev = theevent.GetREvent();
143 
144  if (!rsim.GoToFirstSimRadioPulse()) {
145  WARNING("RdStationInterpolator: No SimRadioPulse in RadioSimulation. Aborting ...");
146  return eFailure;
147  }
148 
149  therev.GetHeader().SetId(rsim.GetEventNumber());
150  therev.GetHeader().SetRunNumber(rsim.GetRunNumber());
151  therev.GetHeader().SetTime(eventtime);
152  simshow.MakeTimeStamp(eventtime);
153 
154  // Add Trigger Information to the Event, By default Event are assumed as externally triggered
155  therev.MakeTrigger();
156  therev.GetTrigger().SetExternalTrigger(true);
157  // End of Trigger Information part
158 
159  // fill all Simradiopulses in one multimap
160  PulseMMap mm_simpulse_x;
161  PulseMMap mm_simpulse_y;
162  rsim.GoToFirstSimRadioPulse();
163  bool ok = true;
164 
165  do {
166  const SimRadioPulse& srpulse = rsim.GetNextSimRadioPulse(ok);
167  //leave the loop if there were no further SimRadioPulses
168  if (!ok)
169  break;
170 
171  //position of SimPulses
172  double xcoord = srpulse.GetLocation().GetX(corsys);
173  mm_simpulse_x.insert(PulsePair(xcoord,srpulse));
174  double ycoord = (srpulse.GetLocation()).GetY(corsys);
175  mm_simpulse_y.insert(PulsePair(ycoord,srpulse));
176  } while (ok);
177 
178  vector<double> sPosition(3, 0.);
179  vector<double> distanceBetweenSimloc(3, 0.);
180  vector<double> distanceToStation(3, 0.);
181  vector<revt::StationFFTDataContainer> v_simFFTDataContainer(3);
182  vector<double> starttime(3, 0.);
183  vector<double> binning(3, 0.);
184  vector<double> areaWeight(4, 0.);
185 
186  for (rdet::RDetector::StationIterator rdIt = RadioDet.StationsBegin(); rdIt != RadioDet.StationsEnd(); ++rdIt) {
187  utl::Point Position = rdIt->GetPosition();
188  const int statID = rdIt->GetId();
189  OUT(eObscure) << "Station " << statID;
190 
191  // if station id is listed in fExcludedStationIds, skip this simulated radio pulse (it will not be re-used for the second-closest antenna station!)
192  if (!fExcludedStationIds.empty())
193  if (find(fExcludedStationIds.begin(), fExcludedStationIds.end(), statID) != fExcludedStationIds.end()) {
194  OUT(eObscure) << " -> not interpolated as it is in the exclude list." << endl;
195  continue;
196  }
197 
198  // if there is a list of fIncludedStationIds skip this simulated radio pulse if station id is not in the list
199  if (!fIncludedStationIds.empty())
200  if (find(fIncludedStationIds.begin(), fIncludedStationIds.end(), statID) == fIncludedStationIds.end()) {
201  OUT(eObscure) << " -> station not interpolated as it is not in the include list." << endl;
202  continue;
203  }
204 
205  //find the nearest neighbors of simulated pulses to the station (station ID, timeseries)
206  const PulseMMap& mm_pulse = FindClosestSimPulsesToStation(Position, corsys, mm_simpulse_x, mm_simpulse_y);
207 
208  if (mm_pulse.empty())
209  continue;
210 
211  PulseMMap::const_iterator mmpiter = mm_pulse.begin();
212 
213  //weight of the timseries in interpolation
214  areaWeight[1] = mmpiter->first;
215 
216  starttime[0] = mmpiter->second.GetStartTime();
217  binning[0] = mmpiter->second.GetEfieldTimeSeries().GetBinning();
218  // padding of zeros to end of timeseries
219  v_simFFTDataContainer[0].GetTimeSeries() = PadTimeSeries(mmpiter->second);
220 
221  ++mmpiter;
222 
223  areaWeight[2] = mmpiter->first;
224  starttime[1] = mmpiter->second.GetStartTime();
225  binning[1] = mmpiter->second.GetEfieldTimeSeries().GetBinning();
226  v_simFFTDataContainer[1].GetTimeSeries() = PadTimeSeries(mmpiter->second);
227 
228  ++mmpiter;
229 
230  areaWeight[3] = mmpiter->first;
231  starttime[2] = mmpiter->second.GetStartTime();
232  binning[2] = mmpiter->second.GetEfieldTimeSeries().GetBinning();
233  v_simFFTDataContainer[2].GetTimeSeries() = PadTimeSeries(mmpiter->second);
234 
235  areaWeight[0] = areaWeight[1] + areaWeight[2] + areaWeight[3];
236 
237  // check for same binning of timeseries. Must have the same binning
238  if ((fabs(binning[0] - binning[1])/binning[0]) > 1e-5 || (fabs(binning[0] - binning[2])/binning[0]) > 1e-5) {
239  WARNING("RdStationInterpolator: simtimeseries don't have the same binning. Aborting ...");
240  return eFailure;
241  }
242 
243  //get the design frequencies from the channels and check, if for all channels the same
244  double designLowerFreq = 0;
245  double designLowerFreqFirstCh = 0;
246  double designUpperFreq = 0;
247  double designUpperFreqFirstCh = 0;
248  for (rdet::Station::ChannelIterator cIt = rdIt->ChannelsBegin(); cIt!= rdIt->ChannelsEnd(); ++cIt) {
249  const rdet::Channel& cDetChannel = RadioDet.GetStation(rdIt->GetId()).GetChannel(cIt->GetId());
250  designLowerFreq = cDetChannel.GetDesignLowerFreq();
251  designUpperFreq = cDetChannel.GetDesignUpperFreq();
252  if (cIt == rdIt->ChannelsBegin()) {
253  designLowerFreqFirstCh = designLowerFreq;
254  designUpperFreqFirstCh = designUpperFreq;
255  }
256  if (designLowerFreq != designLowerFreqFirstCh || designUpperFreq != designUpperFreqFirstCh) {
257  WARNING("RdStationInterpolator: design frequency different for different channels");
258  return eFailure;
259  }
260  }
261 
262  // interpolate timeseries
263 
264  for (unsigned int i = 0; i <= v_simFFTDataContainer.size(); ++i) {
265  if (v_simFFTDataContainer[i].GetNyquistZone() != 1) {
266  WARNING("RdStationInterpolator: simtimeseries not in first Nyquist zone.");
267  return eFailure;
268  }
269  }
270 
271  if (v_simFFTDataContainer[0].GetConstFrequencySpectrum().GetSize() != v_simFFTDataContainer[1].GetConstFrequencySpectrum().GetSize() ||
272  v_simFFTDataContainer[0].GetConstFrequencySpectrum().GetSize() != v_simFFTDataContainer[2].GetConstFrequencySpectrum().GetSize()) {
273  WARNING("RdStationInterpolator: simtimeseries don't have the same length.");
274  return eFailure;
275  }
276 
277  const revt::StationFFTDataContainer InterFFTDataContainer = InterpolateInTwoD(v_simFFTDataContainer, areaWeight, designLowerFreqFirstCh, designUpperFreqFirstCh);
278  const revt::StationTimeSeries intertimeseries = InterFFTDataContainer.GetConstTimeSeries();
279 
280  //fill SimRadioPulse into the associated station
281 
282  therev.MakeStation(statID); // Create a new Station, already checks if the station exists
283  revt::Station& Stat = therev.GetStation(statID);
284 
285  // create data structures
286  Stat.MakeGPSData(); // should check before if exists?
287  Stat.MakeTriggerData(); // should check before if exists?
288  Stat.MakeSimData(); // should check before if exists?
289 
290  revt::StationTimeSeries& StatTimeSeries = Stat.GetStationTimeSeries() ;
291 
292  if (StatTimeSeries.GetSize()) {
293  WARNING( "RDStationInterpolator: StatTimeSeries not empty!" );
294  StatTimeSeries.ClearTrace();
295  }
296 
297  // fill the simtimeseries into the Station TimeSeries
298  StatTimeSeries.SetBinning(binning[0]);
299  long numpaddedsamples = fTracePaddingAtFront/binning[0] + 0.5;
300 
301  // interpolate and set start time
302  Stat.SetRawTraceStartTime(therev.GetHeader().GetTime() + TimeInterval((starttime[0]*areaWeight[1] + starttime[1]*areaWeight[2] + starttime[2]*areaWeight[3])/areaWeight[0] - numpaddedsamples*binning[0]));
303 
304  // fill with the interpolated trace
305  for (revt::StationTimeSeries::ConstIterator iter = intertimeseries.Begin(); iter != intertimeseries.End(); ++iter) {
306  StatTimeSeries.PushBack(*iter);
307  }
308 
309  } // for (rdet::RDetector::StationIterator...)
310 
311  return eSuccess;
312  } // Run
313 
314 
316  RdStationInterpolator::Finish()
317  {
318  OUT(eIntermediate)<<"RdStationInterpolator::Finish()"<<endl;
319  return eSuccess;
320  } // Finish
321 
322 
324 
325  PulseMMap
326  RdStationInterpolator::FindClosestSimPulsesToStation(const utl::Point& pt, const utl::CoordinateSystemPtr& coord,
327  const PulseMMap& mm_srpulse_x,
328  const PulseMMap& mm_srpulse_y)
329  const
330  {
331  PulseMMap mm_triangle;
332  PulseMMap::const_iterator iterx = mm_srpulse_x.lower_bound(pt.GetX(coord));
333 
334  //check if x value lays in simulated array
335  if (iterx == mm_srpulse_x.end() || iterx == mm_srpulse_x.begin()) {
336  return mm_triangle; //return empty map
337  }
338 
339  bool firsty = false;
340  // find surrounding neighbors
341  PulseMMap m_surroundingsrpulse = FindSurroundingNN(mm_srpulse_x, pt, coord, firsty);
342 
343  if (m_surroundingsrpulse.empty()) {
344  firsty = true;
345  PulseMMap::const_iterator itery = mm_srpulse_y.lower_bound(pt.GetY(coord));
346  //check if y value lays in simulated array
347  if (itery == mm_srpulse_y.end() || itery == mm_srpulse_y.begin()) {
348  return mm_triangle; //return empty map
349  }
350 
351  m_surroundingsrpulse = FindSurroundingNN(mm_srpulse_y, pt, coord, firsty);
352 
353  if (m_surroundingsrpulse.empty()) {
354  return mm_triangle; //return empty map
355  }
356  }
357 
358  //search for surrounding triangle
359  vector<utl::Point> simloc_triangle;
360  vector<double> areaWeight;
361 
362  double minarea = 0;
363  bool surrTrianglefound = false;
364  PulseMMap::iterator it = m_surroundingsrpulse.begin();
365  for (unsigned int i = 0; i < 2; ++i, ++it) {
366  PulseMMap::iterator secIt = boost::next(it);
367  for (unsigned int j = i + 1; j < 3; ++j, ++secIt) {
368  unsigned int k = j + 1;
369  for (PulseMMap::iterator thirdIt = boost::next(secIt); thirdIt != m_surroundingsrpulse.end(); ++thirdIt, ++k) {
370  simloc_triangle.clear();
371  simloc_triangle.push_back(it->second.GetLocation());
372  simloc_triangle.push_back(secIt->second.GetLocation());
373  simloc_triangle.push_back(thirdIt->second.GetLocation());
374  areaWeight = GetAreaOfTriangles(pt, simloc_triangle, coord);
375 
376  if (fabs(areaWeight[1] + areaWeight[2] + areaWeight[3] - areaWeight[0]) >= 1e-5)
377  continue;
378  if (surrTrianglefound && minarea <= areaWeight[0])
379  continue;
380  minarea = areaWeight[0];
381 
382  mm_triangle.clear();
383  mm_triangle.insert(PulsePair(areaWeight[2], it->second));
384  mm_triangle.insert(PulsePair(areaWeight[3], secIt->second));
385  mm_triangle.insert(PulsePair(areaWeight[1], thirdIt->second));
386  surrTrianglefound = true;
387  }
388  }
389  }
390 
391  return mm_triangle;
392  }
393 
394 
396 
397  PulseMMap
398  RdStationInterpolator::FindSurroundingNN(const PulseMMap& mm_simradiopulse, const utl::Point& pt,
399  const utl::CoordinateSystemPtr& coord, const bool inverse)
400  const
401  {
402  PulseMMap::const_iterator itera = inverse ?
403  mm_simradiopulse.lower_bound(pt.GetY(coord)) :
404  mm_simradiopulse.lower_bound(pt.GetX(coord));
405 
406  //both rows of simulated arrays around station a
407  const double uppera = itera->first;
408  --itera;
409  const double lowera = itera->first;
410 
411  //get all simulated pulses with upper and lower a
412  typedef PulseMMap::const_iterator PulseIterator;
413  typedef pair<PulseIterator, PulseIterator> PulseIteratorPair;
414  PulseIteratorPair upperb_range = mm_simradiopulse.equal_range(uppera);
415  PulseIteratorPair lowerb_range = mm_simradiopulse.equal_range(lowera);
416 
417  //fill a map for each a
418  PulseMMap m_upperb;
419  for (PulseIterator upperb_iter = upperb_range.first;
420  upperb_iter != upperb_range.second; ++upperb_iter) {
421  const double b = inverse ?
422  upperb_iter->second.GetLocation().GetX(coord) :
423  upperb_iter->second.GetLocation().GetY(coord);
424  m_upperb.insert(PulsePair(b, upperb_iter->second));
425  }
426  PulseMMap m_lowerb;
427  for (PulseIterator lowerb_iter = lowerb_range.first;
428  lowerb_iter != lowerb_range.second; ++lowerb_iter) {
429  const double b = inverse ?
430  lowerb_iter->second.GetLocation().GetX(coord) :
431  lowerb_iter->second.GetLocation().GetY(coord);
432  m_lowerb.insert(PulsePair(b, lowerb_iter->second));
433  }
434 
435  //get four sourrounding nearest neighbors for station
436  PulseMMap m_surroundingsrpulse;
437  PulseIterator itu_b;
438  PulseIterator itl_b;
439  if (!inverse) {
440  itu_b = m_upperb.lower_bound(pt.GetY(coord));
441  itl_b = m_lowerb.lower_bound(pt.GetY(coord));
442  } else {
443  itu_b = m_upperb.lower_bound(pt.GetX(coord));
444  itl_b = m_lowerb.lower_bound(pt.GetX(coord));
445  }
446 
447  if (itu_b == m_upperb.end() || itu_b == m_upperb.begin() || itl_b == m_lowerb.end() || itl_b == m_lowerb.begin()) {
448  return m_surroundingsrpulse;
449  }
450 
451  m_surroundingsrpulse.insert(PulsePair(itu_b->first, itu_b->second));
452  m_surroundingsrpulse.insert(PulsePair(itl_b->first, itl_b->second));
453  --itu_b;
454  --itl_b;
455  m_surroundingsrpulse.insert(PulsePair(itu_b->first, itu_b->second));
456  m_surroundingsrpulse.insert(PulsePair(itl_b->first, itl_b->second));
457 
458  return m_surroundingsrpulse;
459  }
460 
461 
463 
464  vector<double>
465  RdStationInterpolator::GetAreaOfTriangles(const utl::Point& stationpos, const vector<utl::Point>& v_simloc, const utl::CoordinateSystemPtr& coord)
466  const
467  {
468  // distance from neighbor to station
469  vector<double> distStation;
470  for (int i = 0; i < 3; ++i) {
471  double distx = stationpos.GetX(coord) - v_simloc[i].GetX(coord);
472  double disty = stationpos.GetY(coord) - v_simloc[i].GetY(coord);
473  distStation.push_back(sqrt(pow(distx, 2) + pow(disty, 2)));
474  }
475 
476  // distance between neighbors
477  vector<double> distSim;
478  distSim.push_back((v_simloc[1] - v_simloc[0]).GetR(coord));
479  distSim.push_back((v_simloc[2] - v_simloc[1]).GetR(coord));
480  distSim.push_back((v_simloc[0] - v_simloc[2]).GetR(coord));
481 
482  // calculating the areas of the different triangles
483  vector<double> s;
484  vector<double> area;
485 
486  s.push_back((distSim[0] + distSim[1] + distSim[2])/2);
487  area.push_back(sqrt(s[0] * (s[0] - distSim[0])*(s[0] - distSim[1])*(s[0] - distSim[2])));
488  s.push_back((distSim[0] + distStation[0] + distStation[1])/2);
489  area.push_back(sqrt(s[1] * (s[1] - distSim[0])*(s[1] - distStation[0])*(s[1] - distStation[1])));
490  s.push_back((distSim[1] + distStation[1] + distStation[2])/2);
491  area.push_back(sqrt(s[2] * (s[2] - distSim[1])*(s[2] - distStation[1])*(s[2] - distStation[2])));
492  s.push_back((distSim[2] + distStation[2] + distStation[0])/2);
493  area.push_back(sqrt(s[3] * (s[3] - distSim[2])*(s[3] - distStation[2])*(s[3] - distStation[0])));
494 
495  return area;
496  }
497 
498 
500 
502  RdStationInterpolator::PadTimeSeries(const SimRadioPulse& simtimeseries)
503  const
504  {
505  revt::StationTimeSeries PaddedTimeSeries;
506 
507  Vector3D V3DZero;
508  V3DZero = 0.0, 0.0, 0.0;
509 
510  double padbinning = simtimeseries.GetBinning();
511  PaddedTimeSeries.SetBinning(padbinning);
512 
513  long numpaddedsamples = fTracePaddingAtFront/padbinning + 0.5;
514 
515  for (long i = 0; i < numpaddedsamples; ++i)
516  PaddedTimeSeries.PushBack(V3DZero);
517 
518  for (revt::StationTimeSeries::ConstIterator iter = simtimeseries.GetEfieldTimeSeries().Begin(); iter != simtimeseries.GetEfieldTimeSeries().End(); ++iter) {
519  PaddedTimeSeries.PushBack(*iter);
520  }
521 
522  // now pad the station trace at the end up to the given minimum trace length
523  while (fMinimumTraceLength - PaddedTimeSeries.GetSize()*padbinning > 1e-6)
524  PaddedTimeSeries.PushBack(V3DZero);
525 
526  // if number of samples is uneven after padding, pad one more sample (otherwise it will again be clipped at the next FFT)
527  if (PaddedTimeSeries.GetSize()/2*2 != PaddedTimeSeries.GetSize())
528  PaddedTimeSeries.PushBack(V3DZero);
529 
530  return PaddedTimeSeries;
531  }
532 
533 
535 
537  RdStationInterpolator::InterpolateInTwoD(const std::vector<revt::StationFFTDataContainer>& simData,
538  const std::vector<double>& area, const double designlowerfreq, const double designupperfreq)
539  const
540  {
541  const double specbinningOne = simData[0].GetConstFrequencySpectrum().GetBinning();
542  const StationFrequencySpectrum::SizeType size1 = simData[0].GetConstFrequencySpectrum().GetSize();
543  const StationFrequencySpectrum& freq1 = simData[0].GetConstFrequencySpectrum();
544 
545  // unused const StationFrequencySpectrum::SizeType size2 = simData[1].GetConstFrequencySpectrum().GetSize();
546  const StationFrequencySpectrum& freq2 = simData[1].GetConstFrequencySpectrum();
547 
548  // unused const StationFrequencySpectrum::SizeType size3 = simData[2].GetConstFrequencySpectrum().GetSize();
549  const StationFrequencySpectrum& freq3 = simData[2].GetConstFrequencySpectrum();
550 
551  TraceV3C V_interspectrum;
552  V_interspectrum.SetBinning(specbinningOne);
553  Vector3C element;
554 
555  Vector3D phaseElementOne;
556  Vector3D phaseElementTwo;
557  Vector3D phaseElementThree;
558  Vector3D phaseElementInter;
559 
560  Vector3D jumps1;
561  jumps1 = 0.0, 0.0, 0.0;
562  Vector3D jumps2;
563  jumps2 = 0.0, 0.0, 0.0;
564  Vector3D jumps3;
565  jumps3 = 0.0, 0.0, 0.0;
566 
567  for (StationFrequencySpectrum::SizeType i = 0 ; i < size1 ; ++i) {
568  for(unsigned int j = 0; j < 3; ++j) { // loop over x,y and z value
569  if (i >= designlowerfreq/specbinningOne && i <= designupperfreq/specbinningOne) {
570  // interpolate amplitudes
571  double interamplitude = (abs(freq1[i][j])*area[1] + abs(freq2[i][j])*area[2] + abs(freq3[i][j])*area[3])/area[0];
572 
573  // unwrap phases of initial signals
574  if (i > 1) {
575 
576  if (arg(freq1[i][j]) < arg(freq1[i-1][j]) && jumps1[j] >= 0) {
577  if (fabs(arg(freq1[i][j])-arg(freq1[i-1][j])) > fabs(arg(freq1[i][j]) + utl::kPi - arg(freq1[i-1][j]))) {
578  ++jumps1[j];
579  }
580  } else {
581  if (fabs(arg(freq1[i][j])-arg(freq1[i-1][j])) > fabs(arg(freq1[i][j]) - utl::kPi - arg(freq1[i-1][j]))) {
582  --jumps1[j];
583  }
584  }
585 
586  if (arg(freq2[i][j]) < arg(freq2[i-1][j]) && jumps2[j] >= 0) {
587  if (fabs(arg(freq2[i][j]) - arg(freq2[i-1][j])) > fabs(arg(freq2[i][j]) + utl::kPi - arg(freq2[i-1][j]))) {
588  ++jumps2[j];
589  }
590  } else {
591  if (fabs(arg(freq2[i][j]) - arg(freq2[i-1][j])) > fabs(arg(freq2[i][j]) - utl::kPi - arg(freq2[i-1][j]))) {
592  --jumps2[j];
593  }
594  }
595 
596  if (arg(freq3[i][j]) < arg(freq3[i-1][j]) && jumps3[j] >= 0) {
597  if (fabs(arg(freq3[i][j]) - arg(freq3[i-1][j])) > fabs(arg(freq3[i][j]) + utl::kPi - arg(freq3[i-1][j]))) {
598  ++jumps3[j];
599  }
600  } else {
601  if (fabs(arg(freq3[i][j]) - arg(freq3[i-1][j])) > fabs(arg(freq3[i][j]) - utl::kPi - arg(freq3[i-1][j]))) {
602  --jumps3[j];
603  }
604  }
605 
606  }
607 
608  phaseElementOne[j] = arg(freq1[i][j]) + jumps1[j]*2*utl::kPi;
609  phaseElementTwo[j] = arg(freq2[i][j]) + jumps2[j]*2*utl::kPi;
610  phaseElementThree[j] = arg(freq3[i][j]) + jumps3[j]*2*utl::kPi;
611 
612  // interpolate phases
613  phaseElementInter[j] = (phaseElementOne[j]*area[1] + phaseElementTwo[j]*area[2] + phaseElementThree[j]*area[3])/area[0];
614 
615  // interpolated spectrum
616  element[j] = polar(interamplitude, phaseElementInter[j]);
617 
618  } else {
619  element[j] = 0;
620  }
621  }
622 
623  V_interspectrum.PushBack(element);
624  }
625 
626  revt::StationFFTDataContainer interpolatedFFTDataContainer;
627  interpolatedFFTDataContainer.GetFrequencySpectrum() = V_interspectrum;
628 
629  return interpolatedFFTDataContainer;
630  }
631 
632 
634 
635  void
636  RdStationInterpolator::BuildSimShower(evt::ShowerSimData& theshower, const utl::CoordinateSystemPtr& coord)
637  {
638  // This function will build a Sim shower with correct data
639  // Inspired by the EventGenerator Module
640 
641  if (!theshower.HasPosition())
642  theshower.MakeGeometry(Point(0, 0, 0, coord));
643 
644  }
645 
646 } // nameSpace
Branch GetTopBranch() const
Definition: Branch.cc:63
boost::transform_iterator< InternalStationFunctor, InternalStationIterator, const Station & > StationIterator
StationIterator returns a pointer to a station.
Definition: RDetector.h:61
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.
Definition: Detector.cc:179
double GetBinning() const
Get the sampling time scale.
Definition: SimRadioPulse.h:34
Point object.
Definition: Point.h:32
Report success to RunController.
Definition: VModule.h:62
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.
Definition: REvent.h:42
void BuildSimShower(evt::ShowerSimData &theshower, const utl::CoordinateSystemPtr &coord)
BuildSimShower---------------------------------------------------------------------------------------...
StationIterator StationsEnd() const
End of the collection of pointers to commissioned stations.
Definition: RDetector.h:68
void MakeSimData()
Make station simulated data object.
Data structure for simulated Radio pulses.
Definition: SimRadioPulse.h:29
utl::TimeStamp GetTime() const
Definition: REvent/Header.h:17
StationIterator StationsBegin() const
Beginning of the collection of pointers to commissioned stations.
Definition: RDetector.h:64
double GetDesignLowerFreq() const
Get design value of the freq-band.
EventTrigger & GetTrigger()
Get the object with central trigger data, throw if n.a.
Definition: REvent.h:229
Data structure for a radio simulation (including several SimRadioPulses)
const double meter
Definition: GalacticUnits.h:29
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
utl::Point GetLocation() const
Definition: SimRadioPulse.h:51
void Init()
Initialise the registry.
revt::REvent & GetREvent()
bool ok(bool okay)
Definition: testlib.cc:89
Detector description interface for Channel-related data.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
revt::StationFFTDataContainer InterpolateInTwoD(const std::vector< revt::StationFFTDataContainer > &simData, const std::vector< double > &area, const double designLowerFreq, const double designUpperFreq) const
interpolation between closest pulses -&gt; station signal
double pow(const double x, const unsigned int i)
bool HasREvent() const
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
Definition: REvent.h:190
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...
Definition: StringCompare.h:38
std::vector< T >::const_iterator ConstIterator
Definition: Trace.h:60
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
void SetTime(const utl::TimeStamp &time)
Version of the AERAEvent used by the DAQ software.
Definition: REvent/Header.h:27
bool HasPosition() const
Check initialization of shower geometry.
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
void MakeGPSData()
Make GPS data object.
void MakeTriggerData()
Make trigger data object.
Iterator Begin()
Definition: Trace.h:75
void SetExternalTrigger(const bool trig)
Set if Event was externally triggered.
Interface class to access Shower Simulated parameters.
Definition: ShowerSimData.h:49
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Iterator next(Iterator it)
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
constexpr double s
Definition: AugerUnits.h:163
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!
C< F > & GetFrequencySpectrum()
read out the frequency spectrum (write access)
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
std::vector< T >::size_type SizeType
Definition: Trace.h:58
void MakeTrigger()
Create the central trigger object.
Definition: REvent.cc:174
constexpr double kPi
Definition: MathConstants.h:24
RadioSimulation & GetRadioSimulation()
Get the radio simulation data.
constexpr double nanosecond
Definition: AugerUnits.h:143
double abs(const SVector< n, T > &v)
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
get local coordinate system anchored at the core position
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
std::vector< double > GetAreaOfTriangles(const utl::Point &stationpos, const std::vector< utl::Point > &v_simloc, const utl::CoordinateSystemPtr &coord) const
weight of the simradiopulses in for interpolation
ShowerSimData & GetSimShower()
pair< double, const SimRadioPulse & > PulsePair
SizeType GetSize() const
Definition: Trace.h:156
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
constexpr double hertz
Definition: AugerUnits.h:153
#define OUT(x)
boost::indirect_iterator< InternalChannelIterator, const Channel & > ChannelIterator
ChannelIterator returns a pointer to a Channel.
PulseMMap FindSurroundingNN(const PulseMMap &mm_simradiopulse, const utl::Point &pt, const utl::CoordinateSystemPtr &coord, const bool inverse) const
find the surrounding four nearest neighbors
void SetBinning(const double binning)
Definition: Trace.h:139
const SimRadioPulse & GetNextSimRadioPulse(bool &ok)
const utl::TimeStamp & GetEventTime() const
Get the event time of the RadioSimulation.
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
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.
Definition: TimeInterval.h:43
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
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.
Definition: Trace-fwd.h:19
PulseMMap FindClosestSimPulsesToStation(const utl::Point &pt, const utl::CoordinateSystemPtr &coord, const PulseMMap &mm_srpulse_x, const PulseMMap &mm_srpulse_y) const
find distances of SimPulses to station
void MakeGeometry(const utl::Point &pointOnShowerAxis)
initialize the shower geometry. Pos is a point on the shower axis, but not necessarily the core ...
std::multimap< double, const evt::SimRadioPulse & > PulseMMap
void SetId(const int id)
Definition: REvent/Header.h:28
Report failure to RunController, causing RunController to terminate execution.
Definition: VModule.h:64
void MakeTimeStamp(const utl::TimeStamp &ts)
Make the TimeStamp of the shower.
int GetRunNumber() const
Get the run number of the RadioSimulation.
void SetRunNumber(const int run)
Definition: REvent/Header.h:32
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
Iterator End()
Definition: Trace.h:76
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
multimap< double, const SimRadioPulse & > PulseMMap
const utl::TraceV3D & GetEfieldTimeSeries() const
Get the Trace of the simulated electric field.
Definition: SimRadioPulse.h:44
void MakeStation(const int stationId)
make a station with specifying Id, throw if invalid stationId
Definition: REvent.cc:94
revt::StationTimeSeries PadTimeSeries(const evt::SimRadioPulse &simtimeseries) const
padding of zeros to the end of the simtimeseries

, generated on Tue Sep 26 2023.