RdStationSignalReconstructorWithBgSubtraction.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 #include <fwk/LocalCoordinateSystem.h>
5 
6 #include <utl/ErrorLogger.h>
7 #include <utl/Reader.h>
8 #include <utl/config.h>
9 #include <utl/Trace.h>
10 #include <utl/TraceAlgorithm.h>
11 #include <utl/TimeStamp.h>
12 #include <utl/TimeInterval.h>
13 #include <utl/AugerUnits.h>
14 #include <utl/AugerException.h>
15 #include <utl/FFTDataContainerAlgorithm.h>
16 #include <utl/Math.h>
17 #include <utl/RadioGeometryUtilities.h>
18 #include <utl/HannWindow.h>
19 #include <utl/AnalyticCoordinateTransformator.h>
20 #include <utl/AxialVector.h>
21 #include <utl/Vector.h>
22 
23 #include <evt/Event.h>
24 #include <evt/ShowerRecData.h>
25 #include <evt/ShowerRRecData.h>
26 #include <evt/ShowerRRecDataQuantities.h>
27 #include <revt/REvent.h>
28 #include <revt/Header.h>
29 #include <revt/Station.h>
30 #include <revt/StationRecData.h>
31 #include <revt/StationHeader.h>
32 #include <revt/StationTriggerData.h>
33 #include <revt/Channel.h>
34 
35 #include <det/Detector.h>
36 #include <rdet/RDetector.h>
37 #include <rdet/Station.h>
38 #include <rdet/Channel.h>
39 
40 #include <TVector3.h>
41 #include "Minuit2/Minuit2Minimizer.h"
42 #include "Minuit2/MnMigrad.h"
43 #include "Minuit2/FunctionMinimum.h"
44 #include "Minuit2/MinimumParameters.h"
45 #include "Minuit2/MnPrint.h"
46 
47 #include <boost/algorithm/string/case_conv.hpp>
48 
49 #include <complex> // std::complex, std::abs
50 
51 #include "TGraphErrors.h"
52 
53 #include "simuroutine.C"
54 
55 using namespace revt;
56 using namespace fwk;
57 using namespace utl;
58 using std::complex;
59 using std::stringstream;
60 using std::ostringstream;
61 using std::cerr;
62 using std::cout;
63 using std::endl;
64 using std::max;
65 using std::min;
66 
67 
68 #define OUT(x) if ((x) <= fInfoLevel) cerr << " "
69 
70 
72 
75  {
76  INFO("RdStationSignalReconstructorWithBgSubtraction::Init()");
77 
78  // Read in the configurations of the xml file
79  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdStationSignalReconstructorWithBgSubtraction");
80  topBranch.GetChild("VectorialComponent").GetData(fVectorialComponent);
81  topBranch.GetChild("useEnvelope").GetData(fUseEnvelope);
82  topBranch.GetChild("SignalIntegrationWindowSize").GetData(fSignalIntegrationWindowSize);
83  topBranch.GetChild("EnergyFluenceIntegrationWindowStart").GetData(fEnergyFluenceIntegrationWindowStart);
84  topBranch.GetChild("EnergyFluenceIntegrationWindowStop").GetData(fEnergyFluenceIntegrationWindowStop);
85  topBranch.GetChild("MinSignal").GetData(fMinSignal);
86  topBranch.GetChild("MinSignalToNoise").GetData(fMinSignalToNoise);
87  topBranch.GetChild("RelativeWindowWidthOnEachSide").GetData(fWindowSizeOnEachSide);
88  topBranch.GetChild("SelfTriggeredSNcut").GetData(fSelfTriggeredSNcut);
89  topBranch.GetChild("BackGroundSubtraction").GetData(fBackGroundSubtraction);
90  topBranch.GetChild("DefaultAntennaUncertainty").GetData(fDefaultAntennaUncertainty);
91  topBranch.GetChild("ButterflyAntennaUncertainty").GetData(fButterflyAntennaUncertainty);
92  topBranch.GetChild("BlackSpiderAntennaUncertainty").GetData(fBlackSpiderAntennaUncertainty);
93  topBranch.GetChild("RelativeAmplitudeUncertainty").GetData(fRelativeAmplitudeUncertainty);
94  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
95  INFODebug("");
96 
97  fWindow = new HannWindow(fWindowSizeOnEachSide);
98  // function for BG subtraction in energy fluence //fc: move
99  f_sigmoind = new TF1("f_sigmoind", "[0]*(-(TMath::Pi()*0.5)+TMath::ATan([1]*(x-1)+TMath::Tan((-1./[0])+(TMath::Pi()*0.5))))",0, 10); // 2 pars
100  f_sigmoind->FixParameter(0, 4.);
101  f_sigmoind->FixParameter(1, 0.3);
102 
103  ostringstream info;
104  info << "\n\t Vectorial component: " << fVectorialComponent
105  << "\n\t Signal inegration window: " << fSignalIntegrationWindowSize << "ns";
106  INFO(info);
107  return eSuccess;
108  }
109 
110 
112  RdStationSignalReconstructorWithBgSubtraction::Run(evt::Event& event)
113  {
114  if (fInfoLevel >= eInfoIntermediate)
115  INFO("RdStationSignalReconstructorWithBgSubtraction::Run()");
116 
117  // Check if there are events at all
118  if (!event.HasREvent()) {
119  WARNING("No radio event found!");
120  return eContinueLoop;
121  }
122 
123  ++fTotalNumberOfEvents;
124 
125  ostringstream message;
126 
127  REvent& rEvent = event.GetREvent();
128  //TimeStamp eventTime = rEvent.GetHeader().GetTime();
129 
130  int numberOfStationsWithPulseFound = 0;
131 
132  time_t timeAllStation = time(nullptr);
133 
134  // loop through stations and for every station through every channel
135  for (REvent::StationIterator sIt = rEvent.StationsBegin();
136  sIt != rEvent.StationsEnd(); ++sIt) {
137  time_t timeStation = time(nullptr);
138  Station& station = *sIt;
139 
140 
141  // RRecStation event should have been generated by RdEventInitializer
142  if (!station.HasRecData()) {
143  WARNING("Station has no RecData! Please call RdEventInitializer first!");
144  return eFailure;
145  }
146  StationRecData& recStation = station.GetRecData();
147 
148  // time that is added to all times determined in a trace in ns
149  const double relTime = station.GetRecData().GetParameter(eTraceStartTime);
150 
151  ostringstream info;
152  info << "Apply pulse finder on station " << station.GetId();
153  INFOIntermediate(info);
154 
155  // Read the time trace of this station
156  // gettting a local copy of the electric field data
157 
158  revt::StationFFTDataContainer efieldData = station.GetFFTDataContainer();
159  if (fUseEnvelope)
160  FFTDataContainerAlgorithm::HilbertEnvelope(efieldData);
161  OUT(eInfoDebug) << "size of efield trace = " << efieldData.GetConstTimeSeries().GetSize() << endl;
162 
163  const StationTimeSeries& stationtrace = efieldData.GetConstTimeSeries();
164  const StationTimeSeries& stationtrace_noenvelope = station.GetFFTDataContainer().GetConstTimeSeries();
165 
166  // temporary channel trace to which the selected station data is copied
167  ChannelTimeSeries channeltrace;
168  channeltrace.SetBinning(stationtrace.GetBinning());
169 
170  ChannelTimeSeries channeltrace_noenvelope;
171  channeltrace_noenvelope.SetBinning(stationtrace_noenvelope.GetBinning());
172 
173  revt::ChannelFFTDataContainer meas_FFTDataContainer;
174  meas_FFTDataContainer.GetTimeSeries().SetBinning(channeltrace_noenvelope.GetBinning());
175 
176  revt::ChannelFFTDataContainer bg_FFTDataContainer;
177  bg_FFTDataContainer.GetTimeSeries().SetBinning(channeltrace_noenvelope.GetBinning());
178 
179  revt::ChannelFFTDataContainer avgBgFFTDataContainer;
180  avgBgFFTDataContainer.GetTimeSeries().SetBinning(channeltrace_noenvelope.GetBinning());
181 
182  // Signal and Noise calculator for the electric field
183  double NoiseWindowStart = recStation.GetParameter(eNoiseWindowStart);
184  double NoiseWindowStop = recStation.GetParameter(eNoiseWindowStop);
185  double SignalSearchWindowStart = recStation.GetParameter(eSignalSearchWindowStart);
186  double SignalSearchWindowStop = recStation.GetParameter(eSignalSearchWindowStop);
187  double SignalWindowStart = 0;
188  double SignalWindowStop = 0;
189  double SignalIntegrationWindowSize = fSignalIntegrationWindowSize;
190  double Integral_lowerLimit = fEnergyFluenceIntegrationWindowStart;
191  double Integral_upperLimit = fEnergyFluenceIntegrationWindowStop;
192 
193  recStation.SetParameter(revt::eSignalIntegrationTime, fSignalIntegrationWindowSize);
194 
195  bool PulseFound = false;
196  double MeanNoise = 0;
197  double RMSNoise = 0;
198  unsigned int sampleNSEW = 0;
199  unsigned int sample = 0;
200  double PeakAmplitude = 0;
201  double IntegratedSignal = 0;
202  double SignalTimeFWHM = 0;
203  double PeakTime = 0;
204  double PeakTimeError = 0;
205  double SignalToNoise = 0;
206  unsigned int binsSignal = 0;
207  unsigned int nBinFreq = 0;
208  double freqBinning = 0;
209 
210  // component = 0 is x, 1 is y, 2 is z
211  // component = 4 is xy-plane --> vectorial component!
212  // component 5-6 is vxB and vxvxB plane
213  // component = 3 is absolute value of vectorial sum of station vector data
214  // first find the the peak in NSEW plane needed to set the signal window in the bg subtraction//fc:change
215  channeltrace.Clear();
216  channeltrace_noenvelope.Clear();
217  for (StationTimeSeries::SizeType i = 0; i < stationtrace.GetSize(); ++i) {
218  channeltrace.PushBack(sqrt(Sqr(stationtrace[i][0]) + Sqr(stationtrace[i][1])));
219  channeltrace_noenvelope.PushBack(sqrt(Sqr(stationtrace_noenvelope[i][0]) + Sqr(stationtrace_noenvelope[i][1])));
220  }
221  Pulsefinder(channeltrace, PeakAmplitude, PeakTime, PeakTimeError,
222  SignalSearchWindowStart, SignalSearchWindowStop, sampleNSEW);
223 
224  unsigned int NumComponents = 7;
225  std::vector<double> UncertantySignalSpectrum[NumComponents];
226  std::vector<double> UncertantyBackGroundSpectrum[NumComponents];
227  ChannelFrequencySpectrum channel_spectrum[NumComponents];
228  ChannelFrequencySpectrum channel_spectrum_bg[NumComponents];
229 
230  for (unsigned int component = 0; component < NumComponents; ++component) {
231  channel_spectrum[component].Clear();
232  channel_spectrum_bg[component].Clear();
233  channeltrace.Clear();
234  channeltrace_noenvelope.Clear();
235  meas_FFTDataContainer.GetTimeSeries().Clear();
236  bg_FFTDataContainer.GetTimeSeries().Clear();
237  avgBgFFTDataContainer.GetTimeSeries().Clear();
238  UncertantySignalSpectrum[component].clear();
239  UncertantyBackGroundSpectrum[component].clear();
240  // fixme TH: it would be nice to reserve the appropriate space in the trace here,
241  // but utl::Trace does not offer that functionality (yet)
242  if (component == 0 || component == 1 || component == 2) {
243  for (StationTimeSeries::SizeType i = 0; i < stationtrace.GetSize(); ++i) {
244  channeltrace.PushBack(stationtrace[i][component]);
245  channeltrace_noenvelope.PushBack(stationtrace_noenvelope[i][component]);
246  }
247  } else if (component == 3) {
248  for (StationTimeSeries::SizeType i = 0; i < stationtrace.GetSize(); ++i) {
249  channeltrace.PushBack(stationtrace[i].GetMag());
250  if (std::isnan(stationtrace[i].GetMag())) {
251  message.str("");
252  message << "sample " << i << " of efield trace is nan";
253  WARNING(message);
254  }
255  channeltrace_noenvelope.PushBack(stationtrace_noenvelope[i].GetMag());
256  if (std::isnan(stationtrace_noenvelope[i].GetMag())) {
257  message.str("");
258  message << "sample " << i << " of efield trace is nan";
259  WARNING(message);
260  }
261  }
262  } else if (component == 4) {
263  for (StationTimeSeries::SizeType i = 0; i < stationtrace.GetSize(); ++i) {
264  channeltrace.PushBack(sqrt(Sqr(stationtrace[i][0]) + Sqr(stationtrace[i][1])));
265  channeltrace_noenvelope.PushBack(sqrt(Sqr(stationtrace_noenvelope[i][0]) + Sqr(stationtrace_noenvelope[i][1])));
266  }
267  } else if (component == 5 || component == 6) {
268  // rotate trace to shower plane
269  evt::ShowerRRecData& recShower = event.GetRecShower().GetRRecShower();
270  if (!(recShower.HasReferenceCorePosition(event) && recShower.HasReferenceAxis(event))) {
271  WARNING("Reference direction or core position not set. "
272  "The electric-field can not be rotated into the vxB, vx(vxB) system. "
273  "The calculation will be skipped");
274  continue;
275  }
276  utl::Vector showerAxis = recShower.GetReferenceAxis(event);
277  const utl::CoordinateSystemPtr coreCS =
280  utl::RadioGeometryUtilities(showerAxis, coreCS, recShower.GetMagneticFieldVector());
281  utl::TraceV3D traceShowerPlane = csTrans.GetTraceInShowerPlaneVxB(stationtrace);
282  utl::TraceV3D traceShowerPlane_noenvelope = csTrans.GetTraceInShowerPlaneVxB(stationtrace_noenvelope);
283  for (unsigned int i = 0; i < traceShowerPlane.GetSize(); ++i) {
284  channeltrace.PushBack(traceShowerPlane[i][component - 5]);
285  channeltrace_noenvelope.PushBack(traceShowerPlane_noenvelope[i][component - 5]);
286  }
287  } else {
288  // should never reach that
289  ERROR("This component does not exist!");
290  return eFailure;
291  }
292 
293  // clip windows at trace boundaries
294  double TraceStop = (channeltrace.GetSize() - 1) * channeltrace_noenvelope.GetBinning();
295  NoiseWindowStart = min(max(0.0, NoiseWindowStart), TraceStop);
296  NoiseWindowStop = max(min(NoiseWindowStop, TraceStop), NoiseWindowStart);
297 
298  // calculate noise and find pulse
299  Noisefinder(channeltrace, RMSNoise, MeanNoise, NoiseWindowStart, NoiseWindowStop);
300  Pulsefinder(channeltrace, PeakAmplitude, PeakTime, PeakTimeError,
301  SignalSearchWindowStart, SignalSearchWindowStop, sample);
302 
303  // calculate FWHM and integrated signal
304  PulseFWHMIntegrator(channeltrace, sample, PeakAmplitude, SignalTimeFWHM, IntegratedSignal,
305  SignalWindowStart, SignalWindowStop);
306 
307  SignalToNoise = RMSNoise > 0 ? PeakAmplitude/RMSNoise : 0;
308 
309  // bg Subtraction for EW and NS
310  if (component == 0 || component == 1) {
311  // 1) Create channelSignalSpectrum only for the signal trace and apply the Hann window
312  unsigned int start = int(max(0., round(sampleNSEW*1. - SignalIntegrationWindowSize * 0.5 / channeltrace_noenvelope.GetBinning())));
313  unsigned int stop = int(min(channeltrace_noenvelope.GetSize() * 1., round(sampleNSEW*1. + SignalIntegrationWindowSize * 0.5 / channeltrace_noenvelope.GetBinning())));
314  binsSignal = stop - start;
315  fWindow->SetTraceLength(binsSignal+1);
316  int k = 0;
317  for (unsigned int i = start; i <=stop; ++i) {
318  meas_FFTDataContainer.GetTimeSeries().PushBack(channeltrace_noenvelope[i]/utl::microvolt*fWindow->GetWeightAtBin(k)/channeltrace_noenvelope.GetBinning());
319  ++k;
320  }
321  // 2) Create Trace with the average of many bg traces
322  // number of windows:check if there are more windows before or after the signal windows and set a maximum at 50
323  double U_1 = (start > 2*binsSignal) ? double(start - 2*binsSignal) / double(binsSignal) : 0;
324  double U_2 = (channeltrace_noenvelope.GetSize() > (stop + 2*binsSignal + 2*binsSignal)) ? double(channeltrace_noenvelope.GetSize() - (stop + 2*binsSignal + 2*binsSignal)) / double(binsSignal) : 0;
325  unsigned int numberofnoisewindows = std::max(U_1, U_2);
326  if (numberofnoisewindows > 50)
327  numberofnoisewindows = 50; // 49 used for the average BG and 1 for the fBG
328  unsigned int startBG = U_1 > U_2 ? 2*binsSignal : stop + 2*binsSignal;
329  int kbg = 0;
330  int kavg = 0;
331  for (unsigned int i = startBG; i <= startBG+numberofnoisewindows*binsSignal; ++i) {
332  if (i > (startBG + (numberofnoisewindows/2)*binsSignal) &&
333  i <= (startBG + (numberofnoisewindows/2)*binsSignal) + binsSignal) {
334  // create the Background Trace for the energy fluence BG
335  bg_FFTDataContainer.GetTimeSeries().PushBack(channeltrace_noenvelope[i]/utl::microvolt*fWindow->GetWeightAtBin(kbg)/channeltrace_noenvelope.GetBinning()*fWindow->GetRenormalizationFactor());
336  ++kbg;
337  } else {
338  // create the trace that containes all the bg traces I want to use for the average
339  avgBgFFTDataContainer.GetTimeSeries().PushBack(channeltrace_noenvelope[i]/utl::microvolt/channeltrace_noenvelope.GetBinning());
340  ++kavg;
341  }
342  }
343  // 4) Subtract the BG from the Measurment
344  // calculate bins of frequency 30MHz and 80MHz
345  freqBinning = meas_FFTDataContainer.GetFrequencySpectrum().GetBinning();
346  nBinFreq = meas_FFTDataContainer.GetFrequencySpectrum().GetSize();
347  channel_spectrum[component].SetBinning(freqBinning);
348  channel_spectrum_bg[component].SetBinning(freqBinning);
349  unsigned int startBin = meas_FFTDataContainer.GetBinOfFrequency(Integral_lowerLimit);
350  unsigned int stopBin = meas_FFTDataContainer.GetBinOfFrequency(Integral_upperLimit);
351  double sigmaM[nBinFreq];
352  double meanB[nBinFreq];
353  for (unsigned int i=0; i < nBinFreq; ++i) {
354  sigmaM[i] = 0;
355  meanB[i] = 0;
356  }
357  if (fBackGroundSubtraction && sampleNSEW) {
358  CalculateTheBGAverage(avgBgFFTDataContainer, numberofnoisewindows-1, nBinFreq, binsSignal, sigmaM, meanB);
359  }
360  for (unsigned int i = startBin; i <=stopBin; ++i) {
361  double varSignal = 0;
362  double signal = sqrt(2./(double)binsSignal)*std::abs(meas_FFTDataContainer.GetFrequencySpectrum()[i]);
363  double varBg = 0;
364  double Bg = sqrt(2./(double)binsSignal)*std::abs(bg_FFTDataContainer.GetFrequencySpectrum()[i]);
365  double sigmaB = (fBackGroundSubtraction && sampleNSEW!=0)? sigmaM[i]/sqrt(numberofnoisewindows-1) : 0;
366  if (fBackGroundSubtraction && sampleNSEW) {
367  // signal
368  mean_and_sigma(sqrt(2./(double)binsSignal)*std::abs(meas_FFTDataContainer.GetFrequencySpectrum()[i]), sigmaM[i], meanB[i], sigmaB, 0.01, signal, varSignal);
369  // 1 bg
370  mean_and_sigma(sqrt(2./(double)binsSignal)*std::abs(bg_FFTDataContainer.GetFrequencySpectrum()[i]), sigmaM[i], meanB[i], sigmaB, 0.01, Bg, varBg);
371  }
372  UncertantySignalSpectrum[component].push_back(varSignal);
373  UncertantyBackGroundSpectrum[component].push_back(varBg);
374  channel_spectrum[component].PushBack(std::polar(signal,std::arg(meas_FFTDataContainer.GetFrequencySpectrum()[i])));
375  channel_spectrum_bg[component].PushBack(std::polar(Bg,std::arg(bg_FFTDataContainer.GetFrequencySpectrum()[i])));
376  }
377  } else if (component == 2) {
378  // Electric field and uncertainty --> formulae in GAP2019_076
379  evt::ShowerRRecData& recShower = event.GetRecShower().GetRRecShower();
380  if (!(recShower.HasReferenceCorePosition(event) && recShower.HasReferenceAxis(event))) {
381  WARNING("Reference direction or core position not set. "
382  "The electric-field can not be rotated into the vxB, vx(vxB) system. "
383  "The calculation will be skipped");
384  continue;
385  }
386  utl::Vector showerAxis = recShower.GetReferenceAxis(event);
387  const utl::CoordinateSystemPtr coreCS =
389  double th = AnalyticCoordinateTransformator::GetZenithFromCartesianCoordinates(showerAxis.GetX(coreCS), showerAxis.GetY(coreCS), showerAxis.GetZ(coreCS));
390  double phi = AnalyticCoordinateTransformator::GetAzimuthFromCartesianCoordinates(showerAxis.GetX(coreCS), showerAxis.GetY(coreCS));
391  channel_spectrum[component].SetBinning(freqBinning);
392  channel_spectrum_bg[component].SetBinning(freqBinning);
393  for (ChannelFrequencySpectrum::SizeType i = 0; i < channel_spectrum[0].GetSize(); ++i) {
394  channel_spectrum[component].PushBack((-(channel_spectrum[0][i]* cos(phi) + channel_spectrum[1][i] *sin(phi))*tan(th)));
395  channel_spectrum_bg[component].PushBack((-(channel_spectrum_bg[0][i]* cos(phi) + channel_spectrum_bg[1][i] *sin(phi))*tan(th)));
396  UncertantySignalSpectrum[component].push_back(sqrt(Sqr(UncertantySignalSpectrum[0].at(i)*cos(phi)*tan(th)) + Sqr(UncertantySignalSpectrum[1].at(i)*sin(phi)*tan(th))));
397  UncertantyBackGroundSpectrum[component].push_back(sqrt(Sqr(UncertantyBackGroundSpectrum[0].at(i)*cos(phi)*tan(th)) + Sqr(UncertantyBackGroundSpectrum[1].at(i)*sin(phi)*tan(th))));
398  }
399  } else if (component == 3) {
400  evt::ShowerRRecData& recShower = event.GetRecShower().GetRRecShower();
401  if (!(recShower.HasReferenceCorePosition(event) && recShower.HasReferenceAxis(event))) {
402  WARNING("Reference direction or core position not set. "
403  "The electric-field can not be rotated into the vxB, vx(vxB) system. "
404  "The calculation will be skipped");
405  continue;
406  }
407  utl::Vector showerAxis = recShower.GetReferenceAxis(event);
408  const utl::CoordinateSystemPtr coreCS =
410  double th = AnalyticCoordinateTransformator::GetZenithFromCartesianCoordinates(showerAxis.GetX(coreCS), showerAxis.GetY(coreCS), showerAxis.GetZ(coreCS));
411  double phi = AnalyticCoordinateTransformator::GetAzimuthFromCartesianCoordinates(showerAxis.GetX(coreCS), showerAxis.GetY(coreCS));
412  double factorEW_tot = 2*(1 + pow(cos(phi)*tan(th),2));
413  double factotNS_tot = 2*(1 + pow(sin(phi)*tan(th),2));
414  double factorNSEW_tot = sin(2*phi)*pow(tan(th),2);
415  channel_spectrum[component].SetBinning(freqBinning);
416  channel_spectrum_bg[component].SetBinning(freqBinning);
417  for (ChannelFrequencySpectrum::SizeType i = 0; i < channel_spectrum[0].GetSize(); ++i) {
418  channel_spectrum[component].PushBack(sqrt(std::norm(channel_spectrum[0][i]) + std::norm(channel_spectrum[1][i]) + std::norm(channel_spectrum[2][i])));
419  channel_spectrum_bg[component].PushBack(sqrt(std::norm(channel_spectrum_bg[0][i]) + std::norm(channel_spectrum_bg[1][i]) + std::norm(channel_spectrum_bg[2][i])));
420  double u = pow((std::abs(channel_spectrum[0][i])*factorEW_tot+std::abs(channel_spectrum[1][i])*factorNSEW_tot)*UncertantySignalSpectrum[0].at(i)/(2*std::abs(channel_spectrum[component][i])),2) + pow((factotNS_tot*std::abs(channel_spectrum[1][i])+std::abs(channel_spectrum[0][i])*factorNSEW_tot)*UncertantySignalSpectrum[1].at(i)/(2*std::abs(channel_spectrum[component][i])),2);
421  UncertantySignalSpectrum[component].push_back(sqrt(u));
422  double uBg = pow((std::abs(channel_spectrum_bg[0][i])*factorEW_tot+std::abs(channel_spectrum_bg[1][i])*factorNSEW_tot)*UncertantyBackGroundSpectrum[0].at(i),2) + pow((factotNS_tot*std::abs(channel_spectrum_bg[1][i])+std::abs(channel_spectrum_bg[0][i])*factorNSEW_tot)*UncertantyBackGroundSpectrum[1].at(i),2);
423  UncertantyBackGroundSpectrum[component].push_back(sqrt(uBg/(4*std::norm(channel_spectrum_bg[component][i]))));
424  }
425  } else if (component == 4) {
426  channel_spectrum[component].SetBinning(freqBinning);
427  channel_spectrum_bg[component].SetBinning(freqBinning);
428  for (ChannelFrequencySpectrum::SizeType i = 0; i < channel_spectrum[0].GetSize(); ++i) {
429  channel_spectrum[component].PushBack(sqrt(std::norm(channel_spectrum[0][i]) + std::norm(channel_spectrum[1][i])));
430  double norm = sqrt(std::norm(channel_spectrum[0][i]) + std::norm(channel_spectrum[1][i]));
431  channel_spectrum_bg[component].PushBack(sqrt(std::norm(channel_spectrum_bg[0][i]) + std::norm(channel_spectrum_bg[1][i])));
432  double normBg = sqrt(std::norm(channel_spectrum_bg[0][i]) + std::norm(channel_spectrum_bg[1][i]));
433  UncertantySignalSpectrum[component].push_back(sqrt(Sqr(std::abs(channel_spectrum[0][i])*UncertantySignalSpectrum[0].at(i))+Sqr(std::abs(channel_spectrum[1][i])*UncertantySignalSpectrum[1].at(i)))/(norm));
434  UncertantyBackGroundSpectrum[component].push_back(sqrt(Sqr(std::abs(channel_spectrum_bg[0][i])*UncertantyBackGroundSpectrum[0].at(i))+Sqr(std::abs(channel_spectrum_bg[1][i])*UncertantyBackGroundSpectrum[1].at(i)))/(normBg));
435  }
436  } else if (component == 5 || component == 6) {
437  channel_spectrum[component].SetBinning(freqBinning);
438  channel_spectrum_bg[component].SetBinning(freqBinning);
439  evt::ShowerRRecData& recShower = event.GetRecShower().GetRRecShower();
440  if (!(recShower.HasReferenceCorePosition(event) && recShower.HasReferenceAxis(event))) {
441  WARNING("Reference direction or core position not set. "
442  "The electric-field can not be rotated into the vxB, vx(vxB) system. "
443  "The calculation will be skipped");
444  continue;
445  }
446  utl::Vector showerAxis = recShower.GetReferenceAxis(event);
447  const utl::CoordinateSystemPtr coreCS =
449  double th = AnalyticCoordinateTransformator::GetZenithFromCartesianCoordinates(showerAxis.GetX(coreCS), showerAxis.GetY(coreCS), showerAxis.GetZ(coreCS));
450  double phi = AnalyticCoordinateTransformator::GetAzimuthFromCartesianCoordinates(showerAxis.GetX(coreCS), showerAxis.GetY(coreCS));
452  utl::RadioGeometryUtilities(showerAxis, coreCS, recShower.GetMagneticFieldVector());
453  Vector vxB = Normalized(Cross(-showerAxis, recShower.GetMagneticFieldVector()));
454  Vector vxvxB = Normalized(Cross(-showerAxis, vxB));
455  Vector e3 = Normalized(Cross(vxB, vxvxB));
456  double factorNS = 0;
457  double factorEW = 0;
458  if (component == 5) {
459  factorNS = vxB.GetY(coreCS)-vxB.GetZ(coreCS)*sin(phi)*tan(th);
460  factorEW = vxB.GetX(coreCS)-vxB.GetZ(coreCS)*cos(phi)*tan(th);
461  }
462  if (component == 6) {
463  factorNS = vxvxB.GetY(coreCS)-vxvxB.GetZ(coreCS)*sin(phi)*tan(th);
464  factorEW = vxvxB.GetX(coreCS)-vxvxB.GetZ(coreCS)*cos(phi)*tan(th);
465  }
466  for (ChannelFrequencySpectrum::SizeType i = 0; i < channel_spectrum[0].GetSize(); ++i) {
467  channel_spectrum[component].PushBack(channel_spectrum[0][i]*factorEW+channel_spectrum[1][i]*factorNS);
468  channel_spectrum_bg[component].PushBack(channel_spectrum_bg[0][i]*factorEW+channel_spectrum_bg[1][i]*factorNS);
469  UncertantySignalSpectrum[component].push_back(sqrt(Sqr(UncertantySignalSpectrum[0].at(i)*factorEW) + Sqr(UncertantySignalSpectrum[1].at(i)*factorNS)));
470  UncertantyBackGroundSpectrum[component].push_back(sqrt(Sqr(UncertantyBackGroundSpectrum[0].at(i)*factorEW) + Sqr(UncertantyBackGroundSpectrum[1].at(i)*factorNS)));
471  }
472  } else {
473  // should never reach that
474  ERROR("This component does not exist!");
475  return eFailure;
476  }
477 
478  double signalEnergyFluence = 0;
479  double signalEnergyFluenceError = 0;
480  // Energy fluence integral
481  EnergyFluenceIntegral(channel_spectrum[component], UncertantySignalSpectrum[component], signalEnergyFluence, signalEnergyFluenceError, true);
482 
483  // calculate noise energy fluence
484  double noiseEnergyFluence = 0;
485  double noiseEnergyFluenceError = 0;
486 
487  if (fBackGroundSubtraction && sampleNSEW) {
488  EnergyFluenceIntegral(channel_spectrum_bg[component], UncertantyBackGroundSpectrum[component], noiseEnergyFluence, noiseEnergyFluenceError, true); // for 1 BackgroundTrace
489  double signalEnergyFluence_bg=(f_sigmoind->Eval(signalEnergyFluence/noiseEnergyFluence))*noiseEnergyFluence+signalEnergyFluence;
490  double noiseSignalEnergyFluence_bg = sqrt(pow((f_sigmoind->Eval(signalEnergyFluence/noiseEnergyFluence)*noiseEnergyFluenceError),2)+signalEnergyFluenceError*signalEnergyFluenceError);
491  signalEnergyFluence=signalEnergyFluence_bg;
492  signalEnergyFluenceError=noiseSignalEnergyFluence_bg;
493  }
494 
495  signalEnergyFluence *= (fConversionSignalToEnergyFluence * channeltrace_noenvelope.GetBinning()); // convert to energy fluence
496  noiseEnergyFluence *= (fConversionSignalToEnergyFluence * channeltrace_noenvelope.GetBinning()); // convert to energy fluence
497  signalEnergyFluenceError *= (fConversionSignalToEnergyFluence * channeltrace_noenvelope.GetBinning()); // convert to energy fluence
498  noiseEnergyFluenceError *= (fConversionSignalToEnergyFluence * channeltrace_noenvelope.GetBinning()); // convert to energy fluence
499 
500  info.str("");
501  info << "station " << station.GetId() << " "
502  "component " << component << " "
503  "signaltime (sample) " << PeakTime << "(" << sample << ") "
504  "Integrating f around sample " << sample << " "
505  "f = " << signalEnergyFluence+noiseEnergyFluence << " +/- " << signalEnergyFluenceError << " "
506  "f noise = " << noiseEnergyFluence << " +/- " << noiseEnergyFluenceError;
507  INFODebug(info);
508 
509  double antennaToAntennaUncertainty = 0;
510  for (Station::ChannelIterator cIt = station.ChannelsBegin(); cIt != station.ChannelsEnd(); ++cIt) {
511  Channel& channel = *cIt;
512  if (boost::algorithm::to_lower_copy(
513  det::Detector::GetInstance().GetRDetector().GetStation(station).GetChannel(channel.GetId()).GetAntennaTypeName()
514  ).find("butterfly") != std::string::npos) {
515  if (antennaToAntennaUncertainty < fButterflyAntennaUncertainty)
516  antennaToAntennaUncertainty = fButterflyAntennaUncertainty;
517  } else if (boost::algorithm::to_lower_copy(
518  det::Detector::GetInstance().GetRDetector().GetStation(station).GetChannel(channel.GetId()).GetAntennaTypeName()
519  ).find("blackspider") != std::string::npos) {
520  if (antennaToAntennaUncertainty < fBlackSpiderAntennaUncertainty)
521  antennaToAntennaUncertainty = fBlackSpiderAntennaUncertainty;
522  } else {
523  if (antennaToAntennaUncertainty < fDefaultAntennaUncertainty)
524  antennaToAntennaUncertainty = fDefaultAntennaUncertainty;
525  }
526  }
527 
528  // add relative uncertainty (a factor "2" is used because the energy fluence scales with amplitude squared)
529  signalEnergyFluenceError =
530  sqrt(
531  signalEnergyFluenceError * signalEnergyFluenceError +
532  fRelativeAmplitudeUncertainty * 2 * signalEnergyFluence * fRelativeAmplitudeUncertainty * 2 * signalEnergyFluence +
533  antennaToAntennaUncertainty * 2 * signalEnergyFluence * antennaToAntennaUncertainty * 2 * signalEnergyFluence
534  );
535 
536  // fill the generic variables using the options selected in the xml file
537  if (component == fVectorialComponent) {
538  station.GetRecData().SetParameter(eSignalTime, relTime + PeakTime);
539  station.GetRecData().SetParameter(eSignalToNoise, Sqr(SignalToNoise));
540  station.GetRecData().SetParameter(eNoise, RMSNoise);
541  station.GetRecData().SetParameterError(eSignalTime,
542  sqrt(Sqr(PeakTimeError) +
543  Sqr(station.GetRecData().GetParameterError(revt::eTraceStartTime))));
544  station.GetRecData().SetParameter(eSignal, PeakAmplitude);
545 
546  OUT(eInfoDebug)
547  << "SNR = " << Sqr(SignalToNoise) << "\t"
548  "signal amplitude = " << PeakAmplitude << "\t"
549  "Uncertainty of SignalAmplitude = " << GetSignalUncertainty(PeakAmplitude, Sqr(SignalToNoise))
550  << endl;
551 
552  double tempUncertainty =
553  sqrt(
554  GetSignalUncertainty(PeakAmplitude, Sqr(SignalToNoise)) * GetSignalUncertainty(PeakAmplitude, Sqr(SignalToNoise)) +
555  PeakAmplitude * fRelativeAmplitudeUncertainty * PeakAmplitude * fRelativeAmplitudeUncertainty +
556  PeakAmplitude * antennaToAntennaUncertainty * PeakAmplitude * antennaToAntennaUncertainty
557  );
558  station.GetRecData().SetParameterError(eSignal, tempUncertainty);
559 
560  station.GetRecData().SetParameterError(eNoise, 0.1 * station.GetRecData().GetParameter(eNoise));
561  station.GetRecData().SetParameterError(eSignalToNoise, 0.1 * station.GetRecData().GetParameter(eSignalToNoise));
562 
563  OUT(eInfoDebug) << "Filling the primary parameters..." << endl;
564 
565  station.GetRecData().SetParameter(eSignalWindowStart, SignalWindowStart);
566  station.GetRecData().SetParameter(eSignalWindowStop, SignalWindowStop);
567  station.GetRecData().SetParameter(eMinSignal, fMinSignal);
568  station.GetRecData().SetParameter(eMinSignalToNoise, fMinSignalToNoise);
569  }
570 
571  // fill the variables 3 = vectorial sum!
572  if (component == 3) {
573  station.GetRecData().SetParameter(ePeakAmplitudeMag, PeakAmplitude);
574  station.GetRecData().SetParameter(ePeakTimeMag, relTime + PeakTime);
575  station.GetRecData().SetParameter(eIntegratedSignalMag, IntegratedSignal);
576  station.GetRecData().SetParameter(eSignalFWHMMag, SignalTimeFWHM);
577  station.GetRecData().SetParameter(eNoiseRmsMag, RMSNoise);
578  station.GetRecData().SetParameter(eSignalEnergyFluenceMag, signalEnergyFluence);
579  station.GetRecData().SetParameterError(eSignalEnergyFluenceMag, signalEnergyFluenceError);
580  station.GetRecData().SetParameter(eNoiseEnergyFluenceMag, noiseEnergyFluence);
581  station.GetRecData().SetParameterError(eNoiseEnergyFluenceMag, noiseEnergyFluenceError);
582  } else if (component == 0) {
583  station.GetRecData().SetParameter(ePeakAmplitudeEW, PeakAmplitude);
584  station.GetRecData().SetParameter(ePeakTimeEW, relTime + PeakTime);
585  station.GetRecData().SetParameter(eIntegratedSignalEW, IntegratedSignal);
586  station.GetRecData().SetParameter(eSignalFWHMEW, SignalTimeFWHM);
587  station.GetRecData().SetParameter(eNoiseRmsEW, RMSNoise);
588  station.GetRecData().SetParameter(eSignalEnergyFluenceEW, signalEnergyFluence);
589  station.GetRecData().SetParameterError(eSignalEnergyFluenceEW, signalEnergyFluenceError);
590  station.GetRecData().SetParameter(eNoiseEnergyFluenceEW, noiseEnergyFluence);
591  station.GetRecData().SetParameterError(eNoiseEnergyFluenceEW, noiseEnergyFluenceError);
592  } else if (component == 1) {
593  station.GetRecData().SetParameter(ePeakAmplitudeNS, PeakAmplitude);
594  station.GetRecData().SetParameter(ePeakTimeNS, relTime + PeakTime);
595  station.GetRecData().SetParameter(eIntegratedSignalNS, IntegratedSignal);
596  station.GetRecData().SetParameter(eSignalFWHMNS, SignalTimeFWHM);
597  station.GetRecData().SetParameter(eNoiseRmsNS, RMSNoise);
598  station.GetRecData().SetParameter(eNoiseMeanNS, MeanNoise);
599  station.GetRecData().SetParameter(eSignalEnergyFluenceNS, signalEnergyFluence);
600  station.GetRecData().SetParameterError(eSignalEnergyFluenceNS, signalEnergyFluenceError);
601  station.GetRecData().SetParameter(eNoiseEnergyFluenceNS, noiseEnergyFluence);
602  station.GetRecData().SetParameterError(eNoiseEnergyFluenceNS, noiseEnergyFluenceError);
603  } else if (component == 2) {
604  station.GetRecData().SetParameter(ePeakAmplitudeV, PeakAmplitude);
605  station.GetRecData().SetParameter(ePeakTimeV, relTime + PeakTime);
606  station.GetRecData().SetParameter(eIntegratedSignalV, IntegratedSignal);
607  station.GetRecData().SetParameter(eSignalFWHMV, SignalTimeFWHM);
608  station.GetRecData().SetParameter(eNoiseRmsV, RMSNoise);
609  station.GetRecData().SetParameter(eSignalEnergyFluenceV, signalEnergyFluence);
610  station.GetRecData().SetParameterError(eSignalEnergyFluenceV, signalEnergyFluenceError);
611  station.GetRecData().SetParameter(eNoiseEnergyFluenceV, noiseEnergyFluence);
612  station.GetRecData().SetParameterError(eNoiseEnergyFluenceV, noiseEnergyFluenceError);
613  } else if (component == 4) {
614  station.GetRecData().SetParameter(ePeakAmplitudeNSEWPlane, PeakAmplitude);
615  station.GetRecData().SetParameter(ePeakTimeNSEWPlane, relTime + PeakTime);
616  station.GetRecData().SetParameter(eIntegratedSignalNSEWPlane, IntegratedSignal);
617  station.GetRecData().SetParameter(eSignalFWHMNSEWPLane, SignalTimeFWHM);
618  station.GetRecData().SetParameter(eNoiseRmsNSEWPlane, RMSNoise);
619  station.GetRecData().SetParameter(eSignalEnergyFluenceNSEWPlane, signalEnergyFluence);
620  station.GetRecData().SetParameterError(eSignalEnergyFluenceNSEWPlane, signalEnergyFluenceError);
621  station.GetRecData().SetParameter(eNoiseEnergyFluenceNSEWPLane, noiseEnergyFluence);
622  station.GetRecData().SetParameterError(eNoiseEnergyFluenceNSEWPLane, noiseEnergyFluenceError);
623  } else if (component == 5) {
624  station.GetRecData().SetParameter(ePeakAmplitudeVxB, PeakAmplitude);
625  station.GetRecData().SetParameter(ePeakTimeVxB, relTime + PeakTime);
626  station.GetRecData().SetParameter(eNoiseRmsVxB, RMSNoise);
627  station.GetRecData().SetParameter(eNoiseMeanVxB, MeanNoise);
628  station.GetRecData().SetParameter(eSignalEnergyFluenceVxB, signalEnergyFluence);
629  station.GetRecData().SetParameterError(eSignalEnergyFluenceVxB, signalEnergyFluenceError);
630  station.GetRecData().SetParameter(eNoiseEnergyFluenceVxB, noiseEnergyFluence);
631  station.GetRecData().SetParameterError(eNoiseEnergyFluenceVxB, noiseEnergyFluenceError);
632  station.GetRecData().SetParameter(eSignalToNoiseVxB, SignalToNoise);
633  } else if (component == 6) {
634  station.GetRecData().SetParameter(ePeakAmplitudeVxVxB, PeakAmplitude);
635  station.GetRecData().SetParameter(ePeakTimeVxVxB, relTime + PeakTime);
636  station.GetRecData().SetParameter(eNoiseRmsVxVxB, RMSNoise);
637  station.GetRecData().SetParameter(eNoiseMeanVxVxB, MeanNoise);
638  station.GetRecData().SetParameter(eSignalEnergyFluenceVxVxB, signalEnergyFluence);
639  station.GetRecData().SetParameterError(eSignalEnergyFluenceVxVxB, signalEnergyFluenceError);
640  station.GetRecData().SetParameter(eNoiseEnergyFluenceVxVxB, noiseEnergyFluence);
641  station.GetRecData().SetParameterError(eNoiseEnergyFluenceVxVxB, noiseEnergyFluenceError);
642  station.GetRecData().SetParameter(eSignalToNoiseVxVxB, SignalToNoise);
643  }
644 
645  if (component == fVectorialComponent) {
646  if ((station.GetRecData().GetParameter(eSignalToNoise) > fMinSignalToNoise ||
647  (station.GetTriggerData().GetTriggerSource() == revt::StationTriggerData::eSelf && !fSelfTriggeredSNcut)) &&
648  station.GetRecData().GetParameter(eSignal) > fMinSignal) {
649  ++numberOfStationsWithPulseFound;
650  PulseFound = true;
651  } else {
652  PulseFound = false;
653  message.str("");
654  message << "no signal pulse found for station " << station.GetId();
655  INFODebug(message);
656  }
657 
658  station.GetRecData().SetPulseFound(PulseFound);
659  if (PulseFound) {
660  station.SetSignal(); // mark station as signal station
661  } else {
662  station.SetNoSignal(); // remove signal attribute from station
663  }
664  }
665  } // end of component loop
666 
667  message.str("");
668  message << "needed " << difftime(time(nullptr), timeStation) << " seconds for Station " << station.GetId();
669  INFODebug(message);
670  } // end station loop
671 
672  message.str("");
673  message << "needed " << difftime(time(nullptr), timeAllStation) << " seconds for all stations";
674  INFODebug(message);
675 
676  if (!event.HasRecShower())
677  event.MakeRecShower();
678  evt::ShowerRecData& shower = event.GetRecShower();
679 
680  if (!shower.HasRRecShower())
681  shower.MakeRRecShower();
682 
683  message.str("");
684  message << "Found " << numberOfStationsWithPulseFound << " stations with signal pulse with energy fluence";
685  INFOFinal(message);
686 
687  if (numberOfStationsWithPulseFound == 1)
688  ++fNumberOfEvents1SignalStations;
689  else if (numberOfStationsWithPulseFound == 2)
690  ++fNumberOfEvents2SignalStations;
691  else if (numberOfStationsWithPulseFound == 3)
692  ++fNumberOfEvents3SignalStations;
693  else if (numberOfStationsWithPulseFound == 4)
694  ++fNumberOfEvents4SignalStations;
695  else if (numberOfStationsWithPulseFound == 5)
696  ++fNumberOfEvents5SignalStations;
697  else if (numberOfStationsWithPulseFound >= 5)
698  ++fNumberOfEvents5plusSignalStations;
699 
700  return eSuccess;
701  }
702 
703 
705  RdStationSignalReconstructorWithBgSubtraction::Finish()
706  {
707  ostringstream sstr;
708  sstr << "Event statistics:\n"
709  << "\t" << fTotalNumberOfEvents << " events\n"
710  << "\t" << fNumberOfEvents1SignalStations << " = "
711  << 100. * fNumberOfEvents1SignalStations/fTotalNumberOfEvents << "% events with 1 signal station\n"
712  << "\t" << fNumberOfEvents2SignalStations << " = "
713  << 100. * fNumberOfEvents2SignalStations/fTotalNumberOfEvents << "% events with 2 signal stations\n"
714  << "\t" << fNumberOfEvents3SignalStations << " = "
715  << 100. * fNumberOfEvents3SignalStations/fTotalNumberOfEvents << "% events with 3 signal stations\n"
716  << "\t" << fNumberOfEvents4SignalStations << " = "
717  << 100. * fNumberOfEvents4SignalStations/fTotalNumberOfEvents << "% events with 4 signal stations\n"
718  << "\t" << fNumberOfEvents5SignalStations << " = "
719  << 100. * fNumberOfEvents5SignalStations/fTotalNumberOfEvents << "% events with 5 signal stations\n"
720  << "\t" << fNumberOfEvents5plusSignalStations << " = "
721  << 100. * fNumberOfEvents5plusSignalStations/fTotalNumberOfEvents << "% events "
722  "with more than 5 signal stations\n";
723  INFO(sstr);
724 
725  delete fWindow;
726  fWindow = nullptr;
727 
728  delete f_sigmoind;
729  f_sigmoind = nullptr;
730 
731  return eSuccess;
732  }
733 
734 
735  void
736  RdStationSignalReconstructorWithBgSubtraction::Noisefinder(const revt::ChannelTimeSeries& channeltrace,
737  double& RMSNoise, double& MeanNoise, double NoiseWindowStart,
738  double NoiseWindowStop)
739  const
740  {
741  unsigned int start = NoiseWindowStart / channeltrace.GetBinning();
742  unsigned int stop = NoiseWindowStop / channeltrace.GetBinning();
743  RMSNoise = TraceAlgorithm::RootMeanSquare(channeltrace, start, stop);
744  MeanNoise = TraceAlgorithm::Mean(channeltrace, start, stop);
745  }
746 
747 
748  void
749  RdStationSignalReconstructorWithBgSubtraction::Pulsefinder(const revt::ChannelTimeSeries& channeltrace,
750  double& PeakAmplitude, double& PeakTime, double& PeakTimeError,
751  double SignalSearchWindowStart, double SignalSearchWindowStop,
752  unsigned int& sample)
753  const
754  {
755  PeakAmplitude = 0;
756  unsigned int start = SignalSearchWindowStart / channeltrace.GetBinning();
757  unsigned int stop = SignalSearchWindowStop / channeltrace.GetBinning();
758 
759  OUT(eInfoDebug) << " Pulsefinder startsample = " << start << " lastsample = " << stop << endl;
760 
761  for (unsigned int i = start; i < stop; ++i) {
762  if (channeltrace[i] > PeakAmplitude) {
763  PeakAmplitude = channeltrace[i];
764  PeakTime = i * channeltrace.GetBinning();
765  sample = i; //sample is the bin corresponding to the pick
766  }
767  }
768  /* Here only the uncertainty due to the finite binnig is considered,
769  * the uncertainty due to noise and from the GPS system is added later. */
770  PeakTimeError = channeltrace.GetBinning() / std::sqrt(12);
771  }
772 
773 
774  double
775  RdStationSignalReconstructorWithBgSubtraction::GetSignalUncertainty(const double signalAmplitude, const double SNR)
776  const
777  {
778  return (0.423/sqrt(SNR) - 0.501/SNR + 3.395/pow(SNR,1.5) ) * signalAmplitude;
779  }
780 
781 
782  double
783  RdStationSignalReconstructorWithBgSubtraction::GetSignalTimeUncertainty(const double snr)
784  const
785  {
786  return 11.7 * utl::ns * std::pow(snr, -0.71);
787  }
788 
789 
790  void
791  RdStationSignalReconstructorWithBgSubtraction::EnergyFluenceIntegral(revt::ChannelFrequencySpectrum& channeltrace,
792  const std::vector<double>& uncertainty,
793  double& integratedSignal, double& energyFluenceUncertainty,
794  const bool usePower)
795  const
796  {
797  integratedSignal = 0;
798  energyFluenceUncertainty = 0;
799  for (unsigned int i = 0; i < channeltrace.GetSize(); ++i) {
800  if (usePower) {
801  integratedSignal += std::norm(channeltrace[i]);
802  energyFluenceUncertainty += 4*std::norm(channeltrace[i])*Sqr(uncertainty.at(i));
803  } else {
804  integratedSignal += fabs(std::abs(channeltrace[i]));
805  energyFluenceUncertainty += Sqr(uncertainty.at(i));
806  }
807  }
808  energyFluenceUncertainty = sqrt(energyFluenceUncertainty);
809  }
810 
811 
812  void
813  RdStationSignalReconstructorWithBgSubtraction::CalculateTheBGAverage(revt::ChannelFFTDataContainer& Long_FFTDataContainer,
814  unsigned int nWindows, int nBin, int ntimeBin,
815  double* const sigmaB, double* const meanB)
816  const
817  {
818  double ampNoise[nBin];
819  for (int t = 0; t < nBin; ++t) {
820  ampNoise[t] = meanB[t] = sigmaB[t] = 0;
821  }
822  ChannelFFTDataContainer short_FFTDataContainer;
823  short_FFTDataContainer.GetTimeSeries().SetBinning(Long_FFTDataContainer.GetTimeSeries().GetBinning());
824  double arrayBackground[nWindows][nBin];
825  for (unsigned int i = 0; i < nWindows; ++i) {
826  short_FFTDataContainer.GetTimeSeries().Clear();
827  for (unsigned int j = i*ntimeBin; j < (i+1)*ntimeBin; ++j) {
828  short_FFTDataContainer.GetTimeSeries().PushBack(Long_FFTDataContainer.GetTimeSeries()[j]);
829  }
830  for (int k = 0; k < nBin; ++k) {
831  arrayBackground[i][k] = 0;
832  ampNoise[k] += sqrt(2./(double)ntimeBin)*std::abs(short_FFTDataContainer.GetFrequencySpectrum()[k]);
833  arrayBackground[i][k] = sqrt(2./(double)ntimeBin)*std::abs(short_FFTDataContainer.GetFrequencySpectrum()[k]);
834  }
835  }
836  for (int t = 0; t < nBin; ++t) {
837  meanB[t] = ampNoise[t]/nWindows;
838  double stdB = 0; // standard dev background
839  for (unsigned int inoise = 0; inoise<nWindows; ++inoise) {
840  stdB += pow((arrayBackground[inoise][t] - meanB[t]), 2);
841  }
842  stdB = nWindows > 3 ? sqrt(stdB/double(nWindows-1)) : sqrt(stdB/double(nWindows));
843  sigmaB[t] = stdB;
844  }
845  }
846 
847 
848  void
849  RdStationSignalReconstructorWithBgSubtraction::PulseFWHMIntegrator(const revt::ChannelTimeSeries& channeltrace,
850  unsigned int sample, double PeakAmplitude,
851  double& SignalTimeFWHM, double& IntegratedSignal,
852  double& SignalWindowStart, double& SignalWindowStop)
853  const
854  {
855  SignalTimeFWHM = 0;
856  IntegratedSignal = 0;
857  unsigned int tmp = sample;
858 
859  while (sample < channeltrace.GetSize() && channeltrace[sample] > 0.5 * PeakAmplitude) {
860  ++SignalTimeFWHM;
861  IntegratedSignal += channeltrace[sample];
862  ++sample;
863  }
864  SignalWindowStop = sample * channeltrace.GetBinning();
865  sample = tmp;
866 
867  while (sample > 0 && channeltrace[sample] > 0.5 * PeakAmplitude) {
868  ++SignalTimeFWHM;
869  IntegratedSignal += channeltrace[sample];
870  --sample;
871  }
872  SignalWindowStart = sample * channeltrace.GetBinning();
873  SignalTimeFWHM = SignalTimeFWHM * channeltrace.GetBinning();
874  }
875 
876 }
Branch GetTopBranch() const
Definition: Branch.cc:63
AxialVector Cross(const Vector &l, const Vector &r)
Definition: OperationsAV.h:25
Class to access station level reconstructed data.
void SetParameterError(Parameter i, double value, bool lock=true)
utl::Point GetReferenceCorePosition(const Event &event) const
Returning the reference core position depending on the corresponding flag.
constexpr T Sqr(const T &x)
Abstract base class for analytic windows.
Definition: HannWindow.h:27
int GetId() const
Return Id of the Channel.
StationTriggerData & GetTriggerData()
Get Trigger data for the station.
boost::indirect_iterator< InternalChannelIterator, Channel & > ChannelIterator
Iterator over station for read/write.
void SetPulseFound(const bool pulsefound)
StationRecData & GetRecData()
Get station level reconstructed data.
Interface class to access Shower Reconstructed parameters.
Definition: ShowerRecData.h:33
bool HasRecShower() const
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
Interface class to access to the RD Reconstruction of a Shower.
double GetParameterError(const Parameter i) const
bool HasReferenceAxis(const Event &event) const
Return always true for SD and FD if RecShower exsist, asking for min. rec stage could fix this...
double GetBinning() const
size of one slot
Definition: Trace.h:138
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
StationIterator StationsEnd()
Definition: REvent.h:130
StationIterator StationsBegin()
Definition: REvent.h:128
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
ChannelIterator ChannelsBegin()
begin Channel iterator for read/write
double pow(const double x, const unsigned int i)
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
Definition: REvent.h:125
bool HasREvent() const
ChannelIterator ChannelsEnd()
end Channel iterator for read/write
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
#define INFOIntermediate(y)
Definition: VModule.h:162
#define max(a, b)
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
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
double abs(const SVector< n, T > &v)
bool HasRRecShower() const
C< T > & GetTimeSeries()
read out the time series (write access)
void Clear()
Definition: Trace.h:158
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
int GetId() const
Get the station Id.
AxialVector Normalized(const AxialVector &v)
Definition: AxialVector.h:81
#define INFODebug(y)
Definition: VModule.h:163
constexpr double microvolt
Definition: AugerUnits.h:231
double GetParameter(const Parameter i) const
void SetBinning(const double binning)
Definition: Trace.h:139
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...
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
bool HasReferenceCorePosition(const Event &event) const
Return always true for SD and FD if RecShower exsist, asking for min. rec stage could fix this...
const StationFFTDataContainer & GetFFTDataContainer() const
retrieve Station FFTDataContainer (read access)
double norm(utl::Vector x)
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
TriggerSource GetTriggerSource() const
Get the Trigger Source of the station, i.e. if it triggered itself or was triggered by the central st...
void SetParameter(Parameter i, double value, bool lock=true)
Vector object.
Definition: Vector.h:30
Class that holds the data associated to an individual radio channel.
utl::Vector GetReferenceAxis(const Event &event) const
Returning the referencedirection depending on the corresponding flag.
constexpr double ns
Definition: AugerUnits.h:162
double Mean(const std::vector< double > &v)
Definition: Functions.h:31
bool HasRecData() const
Check whether station reconstructed data exists.
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
#define INFOFinal(y)
Definition: VModule.h:161
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
utl::Vector GetMagneticFieldVector() const
returns the magnetic field vector from the components stored in the parameter storage ...
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.