Rd2dLDFFitter.cc
Go to the documentation of this file.
1 /* ################################################################################################
2 
3  Removed support for this module from framework and adst with revision 34470 (01.11.21)
4 
5 #################################################################################################*/
6 
7 #include "Rd2dLDFFitter.h"
8 #include <utl/ErrorLogger.h>
9 
10 #include <cmath>
11 
12 #include <fwk/CentralConfig.h>
13 
14 #include <utl/Vector.h>
15 #include <utl/Point.h>
16 #include <utl/BasicVector.h>
17 #include <utl/GeometryUtilities.h>
18 #include <utl/RadioGeometryUtilities.h>
19 #include <utl/CoordinateSystemPtr.h>
20 #include <utl/StringCompare.h>
21 
22 #include <evt/Event.h>
23 #include <evt/ShowerRecData.h>
24 #include <evt/ShowerSRecData.h>
25 #include <evt/ShowerRRecData.h>
26 #include <evt/ShowerFRecData.h>
27 #include <evt/ShowerSimData.h>
28 #include <evt/RadioSimulation.h>
29 
30 
31 #include <revt/REvent.h>
32 #include <revt/Station.h>
33 #include <revt/Header.h>
34 #include <revt/StationRecData.h>
35 #include <revt/StationRRecDataQuantities.h>
36 
37 #include <det/Detector.h>
38 #include <rdet/RDetector.h>
39 
40 // include root stuff
41 #include "TGraph2DErrors.h"
42 #include "TF2.h"
43 #include "TMath.h"
44 #include "TMinuit.h"
45 #include "TFitResultPtr.h"
46 #include "TRandom3.h"
47 
48 #include <cstddef>
49 #include <string>
50 #include <cstdlib>
51 #include <iostream>
52 
53 #include <sstream>
54 #include <fstream>
55 #include <iomanip>
56 #include <stdlib.h>
57 #include <sys/stat.h>
58 #include <math.h>
59 #include <algorithm>
60 #include <vector>
61 
62 using namespace evt;
63 using namespace fwk;
64 using namespace std;
65 using namespace utl;
66 using namespace det;
67 
68 
69 namespace Rd2dLDFFitter {
70 
72  fUseSilentStations(false)
73 { }
74 
75 
78 {
79  INFODebug("Rd2dLDFFitter::Init()");
80 
81  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("Rd2dLDFFitter");
82 
83  // Read in the configurations of the xml file
84  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
85 
86  topBranch.GetChild("FixCore").GetData(fFixCore);
87  topBranch.GetChild("useSilentStations").GetData(fUseSilentStations);
88  topBranch.GetChild("extrasigmacheck").GetData(fextrasigmacheck);
89  topBranch.GetChild("randomseed").GetData(fRandomseed);
90 
91  topBranch.GetChild("A_scale").GetData(fA_scale);
92  topBranch.GetChild("C3").GetData(fC3);
93  topBranch.GetChild("C4").GetData(fC4);
94 
95  topBranch.GetChild("C1theta_0_10").GetData(fC1theta_0_10);
96  topBranch.GetChild("C2theta_0_10").GetData(fC2theta_0_10);
97 
98  topBranch.GetChild("C1theta_10_20").GetData(fC1theta_10_20);
99  topBranch.GetChild("C2theta_10_20").GetData(fC2theta_10_20);
100 
101  topBranch.GetChild("C1theta_20_30").GetData(fC1theta_20_30);
102  topBranch.GetChild("C2theta_20_30").GetData(fC2theta_20_30);
103 
104  topBranch.GetChild("C1theta_30_40").GetData(fC1theta_30_40);
105  topBranch.GetChild("C2theta_30_40").GetData(fC2theta_30_40);
106 
107  topBranch.GetChild("C1theta_40_50").GetData(fC1theta_40_50);
108  topBranch.GetChild("C2theta_40_50").GetData(fC2theta_40_50);
109 
110  topBranch.GetChild("C1theta_50_55").GetData(fC1theta_50_55);
111  topBranch.GetChild("C2theta_50_55").GetData(fC2theta_50_55);
112  topBranch.GetChild("A_scale_50_55").GetData(fA_scale_50_55);
113 
114  topBranch.GetChild("C1theta_55").GetData(fC1theta_55);
115  topBranch.GetChild("C2theta_55").GetData(fC2theta_55);
116  topBranch.GetChild("A_scale_55").GetData(fA_scale_55);
117 
118  return eSuccess;
119 }
120 
121 
123 Rd2dLDFFitter::Run(evt::Event& event)
124 {
125  INFODebug("Rd2dLDFFitter::Run()");
126 
127  // Check if there are events at all
128  if (!event.HasREvent()) {
129  WARNING("No radio event found!");
130  return eSuccess;
131  }
132 
133  // initialize data structures
134  revt::REvent& rEvent = event.GetREvent();
135  if (!event.HasRecShower())
136  event.MakeRecShower();
137  if (!event.GetRecShower().HasRRecShower())
138  event.GetRecShower().MakeRRecShower();
139  ShowerRRecData& showerrrec = event.GetRecShower().GetRRecShower();
140 
141  TGraph2DErrors lateralDistribution2DvxB;
142 
143  //const det::Detector& detector = det::Detector::GetInstance();
144  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
145 
149 
150  // get reference coordinate system of detector (usually PampaAmarilla)
151  const CoordinateSystemPtr referenceCS =
152  det::Detector::GetInstance().GetReferenceCoordinateSystem();
153 
154  const Point core = showerrrec.GetReferenceCorePosition(event);
155  utl::CoordinateSystemPtr localCS = LocalCoordinateSystem::Create(core);
156  utl::Vector showerAxis = showerrrec.GetReferenceAxis(event);
157  const double zenith = showerAxis.GetTheta(localCS);
158  //const double azimuth = showerAxis.GetPhi(localCS);
159  //double zenith = acos(showerAxis.GetZ(CS) / showerAxis.GetMag());
160 
161  const int nant = showerrrec.GetParameter(revt::eNumberOfStationsWithPulseFound);
162 
163  if (nant < 3) {
164  WARNING("Number of signalstations less than 3 -> doing nothing");
165  return eSuccess;
166  }
167 
168  Vector magneticField = showerrrec.GetMagneticFieldVector();
169  utl::RadioGeometryUtilities transformation =
170  utl::RadioGeometryUtilities(showerAxis, localCS, magneticField);
171 
172  magneticField /= magneticField.GetMag();
173 
174  unsigned int numberOfSignalStations = 0;
175  unsigned int numberOfSilentStations = 0;
176 
178  sIt != rEvent.CandidateStationsEnd(); ++sIt) {
179  revt::Station& station = *sIt;
180  //StationRecData& sRec = station.GetRecData();
181  if (station.IsSaturated()) // skip saturated stations
182  continue;
183  if (!station.HasSignal()) // skip silent station
184  ++numberOfSilentStations;
185  else
186  ++numberOfSignalStations;
187  }
188  //For now, satured stations are no included.
189  if (numberOfSignalStations < 3) {
190  WARNING("Number of signalstations after rejection of saturated stations < 3 -> doing nothing!");
191  return eSuccess;
192  }
193  double ratio_sil2sig = 1;
194  if (numberOfSilentStations > numberOfSignalStations) { // limit influence of silent stations only if we have more silent than signal stations
195  ratio_sil2sig = numberOfSilentStations / numberOfSignalStations;
196  }
197  double index_signal_stations[numberOfSignalStations][5];
198  unsigned int i = 0;
200  sIt != rEvent.CandidateStationsEnd(); ++sIt) {
201  revt::Station& station = *sIt;
202  revt::StationRecData& sRec = station.GetRecData();
203  if (station.IsSaturated()) // skip saturated stations
204  continue;
205  if (!fUseSilentStations && !station.HasSignal()) // skip silent stations
206  continue;
207 
208  const Point sPos = rDetector.GetStation(station).GetPosition();
209  double x_VxB = 0;
210  double y_VxB = 0;
211  double z_VxB = 0;
212 
213  // due to the choice of coordinate system the station position will be evaluated relative to the core position
214  transformation.GetVectorInShowerPlaneVxB(x_VxB, y_VxB, z_VxB, sPos);
215  sRec.SetParameter(revt::eLDFFitStationPositionVxB, x_VxB);
216  sRec.SetParameter(revt::eLDFFitStationPositionVxVxB, y_VxB);
217  sRec.SetParameter(revt::eLDFFitStationPositionV, z_VxB);
218 
219  const double integral = sRec.GetParameter(revt::eSignalEnergyFluenceMag);
220  const double uncertainty = sRec.GetParameterError(revt::eSignalEnergyFluenceMag);
221  //const double noiseLevel = sRec.GetParameter(revt::eNoiseEnergyFluenceMag);
222 
223  stringstream sstr;
224  sstr << "Signal: " << integral << "+/-" << uncertainty << "\n"
225  "Station position (reference CS): " << sPos.GetX(referenceCS) / utl::m << ", "
226  << sPos.GetY(referenceCS) / utl::m << ", " << sPos.GetZ(referenceCS) / utl::m << "\n"
227  "Station Position (localCS): " << sPos.GetX(localCS) / utl::m << ", "
228  << sPos.GetY(localCS) / utl::m << ", " << sPos.GetZ(localCS) / utl::m << "\n"
229  "core position (reference CS): " << core.GetX(referenceCS) << ", "
230  << core.GetY(referenceCS) << ", " << core.GetZ(referenceCS) << "\n"
231  "showerAxis (local cs): " << showerAxis.GetX(localCS) << ", "
232  << showerAxis.GetY(localCS) << ", " << showerAxis.GetZ(localCS) << "\n"
233  "magnetic field (localCS): " << magneticField.GetX(localCS) << ", "
234  << magneticField.GetY(localCS) << ", " << magneticField.GetZ(localCS) << "\n"
235  "magnetic field (referenceCS): " << magneticField.GetX(referenceCS) << ", "
236  << magneticField.GetY(referenceCS) << ", " << magneticField.GetZ(referenceCS) << "\n"
237  "position in vxB, vxvxB, z: " << x_VxB << ", " << y_VxB << ", " << z_VxB << endl;
238  INFODebug(sstr.str());
239 
240  // set subthreshold stations to 0 and increase their uncertainty by N_silent/N_signal
241  if (!station.HasSignal()) {
242  lateralDistribution2DvxB.SetPoint(lateralDistribution2DvxB.GetN(), x_VxB, y_VxB, integral);
243  lateralDistribution2DvxB.SetPointError(lateralDistribution2DvxB.GetN() - 1, 0., 0.,
244  uncertainty * ratio_sil2sig);
245  } else {
246  lateralDistribution2DvxB.SetPoint(lateralDistribution2DvxB.GetN(), x_VxB, y_VxB, integral);
247  lateralDistribution2DvxB.SetPointError(lateralDistribution2DvxB.GetN() - 1, 0., 0.,
248  uncertainty);
249  index_signal_stations[i][0] = lateralDistribution2DvxB.GetN() - 1;
250  index_signal_stations[i][1] = x_VxB;
251  index_signal_stations[i][2] = y_VxB;
252  index_signal_stations[i][3] = integral;
253  index_signal_stations[i][4] = uncertainty;
254  ++i;
255  }
256  }
257 
258  double chi2 = 1e20;
259  double sigma_max = 500; //Upper limit for the sigma parameter
260 
261  double covRoot[9][9];
262 
263  TF2 ldf_pre_fit(
264  "LDF_pre_fit", "[0]*TMath::Exp(-((x-[1])*(x-[1])/([2]*[2])+(y-[3])*(y-[3])/([2]*[2])))",
265  lateralDistribution2DvxB.GetXmin() - 100, lateralDistribution2DvxB.GetXmax() + 100,
266  lateralDistribution2DvxB.GetYmin() - 100, lateralDistribution2DvxB.GetYmax() + 100
267  );
268 
269  TF2 ldf2DFit(
270  "LDF2DFit",
271  "[0]*TMath::Exp(-((x-([1]+[5]))**2+(y-[2])**2)/[3]**2)-[6]*[0]*TMath::Exp(-((x-([1]+[4]))**2+(y-[2])**2)/TMath::Exp([7]+[8]*[3])**2)",
272  lateralDistribution2DvxB.GetXmin() - 100, lateralDistribution2DvxB.GetXmax() + 100,
273  lateralDistribution2DvxB.GetYmin() - 100, lateralDistribution2DvxB.GetYmax() + 100
274  );
275 
276  ldf_pre_fit.SetParameter(0, lateralDistribution2DvxB.GetZmax());
277  ldf_pre_fit.SetParLimits(0, 1e-20 * 6.24150934 * 1e18, 1e-14 * 6.24150934 * 1e18);
278  ldf_pre_fit.SetParameter(1, 0);
279  ldf_pre_fit.SetParameter(2, 100);
280  ldf_pre_fit.SetParLimits(2, 0, 1000);
281  ldf_pre_fit.SetParameter(3, 0);
282 
283  lateralDistribution2DvxB.Fit(&ldf_pre_fit);
284 
285  if (gMinuit->fCstatu == "CONVERGED ") {
286  ldf2DFit.SetParameter(0, ldf_pre_fit.GetParameter(0));
287  ldf2DFit.SetParLimits(0, 1e-20 * 6.24150934 * 1e18, 1e-14 * 6.24150934 * 1e18);
288  ldf2DFit.SetParameter(1, ldf_pre_fit.GetParameter(1));
289  ldf2DFit.SetParameter(2, ldf_pre_fit.GetParameter(3));
290  ldf2DFit.SetParameter(3, ldf_pre_fit.GetParameter(2));
291  ldf2DFit.SetParLimits(3, 0, sigma_max);
292  } else {
293  ldf2DFit.SetParameter(0, lateralDistribution2DvxB.GetZmax());
294  ldf2DFit.SetParLimits(1, 1e-20 * 6.24150934 * 1e18, 1e-14 * 6.24150934 * 1e18);
295  ldf2DFit.SetParameter(1, 0);
296  ldf2DFit.SetParameter(2, 0);
297  ldf2DFit.SetParameter(3, 50);
298  ldf2DFit.SetParLimits(3, 0, sigma_max);
299  }
300 
301  double a_scale = fA_scale;
302  double c1 = 0;
303  double c2 = 0;
304  double c0 = 0.41;
305 
306  if (zenith < 10*utl::degree) {
307  c1 = fC1theta_0_10;
308  c2 = fC2theta_0_10;
309  } else if (zenith < 20*utl::degree) {
310  c1 = fC1theta_10_20;
311  c2 = fC2theta_10_20;
312  } else if (zenith < 30*utl::degree) {
313  c1 = fC1theta_20_30;
314  c2 = fC2theta_20_30;
315  } else if (zenith < 40*utl::degree) {
316  c1 = fC1theta_30_40;
317  c2 = fC2theta_30_40;
318  } else if (zenith < 50*utl::degree) {
319  c1 = fC1theta_40_50;
320  c2 = fC2theta_40_50;
321  } else if (zenith < 55*utl::degree) {
322  c1 = fC1theta_50_55;
323  c2 = fC2theta_50_55;
324  a_scale = fA_scale_50_55;
325  c0 = 0.46;
326  } else {
327  c1 = fC1theta_55;
328  c2 = fC2theta_55;
329  a_scale = fA_scale_55;
330  c0 = 0.71;
331  }
332 
333  ldf2DFit.FixParameter(4, c2);
334  ldf2DFit.FixParameter(5, c1);
335  ldf2DFit.FixParameter(6, a_scale);
336  ldf2DFit.FixParameter(7, fC3);
337  ldf2DFit.FixParameter(8, fC4);
338 
339  const bool fitCore = !(numberOfSignalStations < 5 || fFixCore == true);
340  if (!fitCore) {
341  ldf2DFit.FixParameter(1, 0.);
342  ldf2DFit.FixParameter(2, 0.);
343  }
344 
345  TFitResultPtr result = lateralDistribution2DvxB.Fit(&ldf2DFit, "S");
346  chi2 = ldf2DFit.GetChisquare();
347  INFODebug("chi2 with prefit input " + to_string(chi2));
348  bool fitSucessful = false;
349  if (gMinuit->fCstatu == "CONVERGED " || gMinuit->fCstatu == "OK " || gMinuit->fCstatu == "SUCCESSFUL") {
350  fitSucessful = true;
351  gMinuit->mnemat(&covRoot[0][0], 9);
352  }
353 
354  //vary the initial parameter for the width of the big Gaussian to avoid local minima
355  for (int k = 1; k < 9; ++k) {
356  ldf2DFit.SetParameter(3, k * 25);
357  TFitResultPtr result_temp = lateralDistribution2DvxB.Fit(&ldf2DFit, "S");
358  INFODebug("varying sigma= " + to_string(k*25) + "=> chi2 " + to_string(ldf2DFit.GetChisquare()));
359  if (ldf2DFit.GetChisquare() < chi2) {
360  if (gMinuit->fCstatu == "CONVERGED " || gMinuit->fCstatu == "OK " || gMinuit->fCstatu == "SUCCESSFUL") {
361  fitSucessful = true;
362  result = result_temp;
363  chi2 = ldf2DFit.GetChisquare();
364  gMinuit->mnemat(&covRoot[0][0], 9);
365  }
366  }
367  }
368 
369  if (!fitSucessful) {
370  INFO("None of the fit attempts delivered a successful fit -> SKIP");
372  return eSuccess;
373  }
374  if (result->Parameter(3) > sigma_max - 1.) {
376  INFO("final reconstructed sigma at parameter limit -> SKIP");
377  return eSuccess;
378  }
379 
380  /* vary the energy densities 1000 times within their uncertainty and re-fit the LDF.
381  The resulting distribution of the fit parameters can be used to deselect events with unstable fits. */
382  if (fextrasigmacheck) {
383  TRandom3 r(fRandomseed);
384  //const evt::Header& header = event.GetHeader();
385  ldf2DFit.SetFitResult(*result);
386  vector<double> var_A;
387  vector<double> var_sigma;
388  for (int k = 0; k < 1000; ++k) {
389  for (unsigned int l = 0; l < numberOfSignalStations; ++l) {
390  lateralDistribution2DvxB.SetPoint(
391  index_signal_stations[l][0], index_signal_stations[l][1], index_signal_stations[l][2],
392  r.Gaus(index_signal_stations[l][3], index_signal_stations[l][4]));
393  }
394  if (fInfoLevel >= eInfoDebug) {
395  lateralDistribution2DvxB.Fit(&ldf2DFit, "SV");
396  } else {
397  lateralDistribution2DvxB.Fit(&ldf2DFit, "SQ");
398  }
399 
400  if (gMinuit->fCstatu == "CONVERGED " ||
401  gMinuit->fCstatu == "OK " ||
402  gMinuit->fCstatu == "SUCCESSFUL") {
403  if (ldf2DFit.GetParameter(3) < sigma_max - 1.) {
404  var_A.push_back(ldf2DFit.GetParameter(0));
405  var_sigma.push_back(ldf2DFit.GetParameter(3));
406  }
407  }
408  }
409 
410  if (var_A.size() < 500) {
412  INFO("less than 500 of the 1000 additional fits were successful -> SKIP!");
413  return eSuccess;
414  }
415 
416  //deselect events based on the the distributions of fitted parameters
417  const double q_A_15_9 = Quantile(var_A, 15.9);
418  const double q_A_50 = Quantile(var_A, 50.);
419  const double q_A_84_1 = Quantile(var_A, 84.1);
420  INFODebug("amplitude quantiles" + to_string(q_A_15_9) + " " + to_string(q_A_50) +
421  " " + to_string(q_A_84_1));
422 
423  const double q_sigma_15_9 = Quantile(var_sigma, 15.9);
424  const double q_sigma_50 = Quantile(var_sigma, 50.);
425  const double q_sigma_84_1 = Quantile(var_sigma, 84.1);
426  INFODebug("sigma quantiles" + to_string(q_sigma_15_9) + " " + to_string(q_sigma_50) +
427  " " + to_string(q_sigma_84_1));
428 
429  bool unstableFit = false;
430  if (q_A_50 < (result->Parameter(0) - result->ParError(0)) ||
431  q_A_50 > (result->Parameter(0) + result->ParError(0))) {
433  INFO("2DLDF Fit rejected, difference between mean of A-distribution and A too big!");
434  unstableFit = true;
435  }
436  if (q_sigma_50 < (result->Parameter(3) - result->ParError(3)) ||
437  q_sigma_50 > (result->Parameter(3) + result->ParError(3))) {
439  INFO("2DLDF Fit rejected, difference between mean of Sigma-distribution and Sigma too big!");
440  unstableFit = true;
441  }
442  if ((q_A_50 - q_A_15_9) / (q_A_84_1 - q_A_50) < 0.5 ||
443  (q_A_50 - q_A_15_9) / (q_A_84_1 - q_A_50) > 2) {
445  INFO("2DLDF Fit rejected, A-distribution too asymmetric!");
446  unstableFit = true;
447  }
448  if ((q_sigma_50 - q_sigma_15_9) / (q_sigma_84_1 - q_sigma_50) < 0.5 ||
449  (q_sigma_50 - q_sigma_15_9) / (q_sigma_84_1 - q_sigma_50) > 2) {
451  INFO("2DLDF Fit rejected, Sigma-distribution too asymmetric!");
452  unstableFit = true;
453  }
454  if (unstableFit)
455  return eSuccess;
456  }
457 
458  // fit was successful and stable (if fextrasigmacheck is set)
459  // save fit result, increase recStage and compute energy
460 
461  showerrrec.Set2dLDFFitResult(*result);
462  if (fitCore){
463  double x = result->Parameter(1);
464  double y = result->Parameter(2);
465  utl::Point radioCore = transformation.GetVectorFromShowerPlaneVxB(x, y);
466 
467  showerrrec.SetParameter(revt::eCoreX, radioCore.GetX(referenceCS));
468  showerrrec.SetParameter(revt::eCoreY, radioCore.GetY(referenceCS));
469  showerrrec.SetParameter(revt::eCoreZ, radioCore.GetZ(referenceCS));
470  }
471 
472  double A = result->Parameter(0);
473  double sigma = result->Parameter(3);
474  double A_error = result->ParError(0);
475  double sigma_error = result->ParError(3);
476  double sigmaA_error = result->CovMatrix(0, 3);
477  double radiationEnergy = A * TMath::Pi()
478  * (pow(sigma, 2) - c0 * TMath::Exp(2 * fC3 + 2 * fC4 * sigma));
479  double radiationEnergyError = pow(
480  pow(TMath::Pi(), 2) * pow(c0 * TMath::Exp(2 * fC3 + 2 * fC4 * sigma) - pow(sigma, 2), 2)
481  * pow(A_error, 2)
482  + pow(A, 2) * pow(TMath::Pi(), 2)
483  * pow((2 * c0 * fC4 * TMath::Exp(2 * fC4 * sigma + 2 * fC3) - 2 * sigma), 2)
484  * pow(sigma_error, 2)
485  - TMath::Pi() * (2 * c0 * fC4 * TMath::Exp(2 * fC4 * sigma + 2 * fC3) - 2 * sigma)
486  * sigmaA_error,
487  0.5);
488 
489  showerrrec.SetParameter(revt::eRadiationEnergy, radiationEnergy);
490  showerrrec.SetParameterError(revt::eRadiationEnergy, radiationEnergyError);
491 
492  INFOIntermediate("Final result: radiation energy = " + to_string(radiationEnergy)
493  + " +/- " + to_string(radiationEnergyError));
494  if (fInfoLevel >= eInfoIntermediate) {
495  if (event.HasSimShower() && event.GetSimShower().HasRadioSimulation()) {
496  const double radiationEnergySim =
497  event.GetSimShower().GetRadioSimulation().GetRadiationEnergy();
498  if (radiationEnergySim != 0.) {
499  const double Erad_resolution = (radiationEnergy - radiationEnergySim) / radiationEnergySim * 100;
500  INFOIntermediate(to_string(Erad_resolution) + " % wrt true/simulated radiation energy");
501  }
502  }
503  }
504 
505  stringstream sstr;
506  sstr << "Final result: sigma = " << sigma << " +/- " << sigma_error << "\n"
507  << "Final result: x = " << result->Parameter(1) << " +/- " << result->ParError(1) << "\n"
508  << "Final result: y = " << result->Parameter(2) << " +/- " << result->ParError(2) << "\n";
509  INFODebug(sstr.str());
510 
511  // calculate cosmic ray energy
512  const double sineAlpha =
513  RadioGeometryUtilities::GetLorentzVector(
514  showerrrec.GetReferenceAxis(event),
515  showerrrec.GetMagneticFieldVector()
516  ).GetMag();
517  const double d = 2.3137 * 1e14; // energy calibration parameters from Aab et al., PRD 93, 122005 (2016)
518  const double c = 0.505;
519  const double energy = d * std::pow(radiationEnergy / (sineAlpha * sineAlpha), c);
520  const double energyError =
521  c * d * std::pow(1 / (sineAlpha * sineAlpha), c) *
522  std::pow(radiationEnergy, c - 1) * radiationEnergyError;
523  showerrrec.SetParameter(revt::eCosmicRayEnergy, energy);
524  showerrrec.SetParameterError(revt::eCosmicRayEnergy, energyError);
525 
526  double chi2signal = 0.;
527  ldf2DFit.SetFitResult(*result);
528  for (unsigned int u = 0; u < numberOfSignalStations; ++u) {
529  chi2signal += pow(
530  (index_signal_stations[u][3] -
531  ldf2DFit.Eval(index_signal_stations[u][1], index_signal_stations[u][2]))
532  / index_signal_stations[u][4],
533  2);
534  }
535 
536  int NDF = 0;
537  if (!fitCore) {
538  NDF = numberOfSignalStations - 2;
539  } else {
540  NDF = numberOfSignalStations - 4;
541  }
542 
543  showerrrec.SetParameter(revt::e2DLDFfitSignalChi2, chi2signal);
544  showerrrec.SetParameter(revt::e2DLDFfitSignalNDF, NDF);
545 
546  return eSuccess;
547 }
548 
549 
551 Rd2dLDFFitter::Finish()
552 {
553  INFODebug("Rd2dLDFFitter::Finish()");
554  return eSuccess;
555 }
556 
557 
558 double
559 Rd2dLDFFitter::Quantile(vector<double> data, const double percent)
560  const
561 {
562  sort(data.begin(), data.end());
563  const unsigned int length = data.size() - 1;
564  const int index_above = ceil(length * percent / 100.);
565  const int index_below = floor(length * percent / 100.);
566  if (index_above == index_below) {
567  return data[index_above];
568  } else {
569  const double m = data[index_above] - data[index_below];
570  const double b = data[index_above] - m * index_above;
571  return length * percent / 100. * m + b;
572  }
573 }
574 
575 }
Branch GetTopBranch() const
Definition: Branch.cc:63
Class to access station level reconstructed data.
void SetParameter(Parameter i, double value, bool lock=true)
utl::Point GetReferenceCorePosition(const Event &event) const
Returning the reference core position depending on the corresponding flag.
Point object.
Definition: Point.h:32
boost::filter_iterator< CandidateStationFilter, AllStationIterator > CandidateStationIterator
Iterator over all CandidateStations (i.e., HasSignal, HasNoSignal)
Definition: REvent.h:141
Report success to RunController.
Definition: VModule.h:62
StationRecData & GetRecData()
Get station level reconstructed data.
bool HasRecShower() const
CandidateStationIterator CandidateStationsEnd()
Definition: REvent.h:146
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
ShowerRecData & GetRecShower()
Interface class to access to the RD Reconstruction of a Shower.
bool HasSimShower() const
double GetParameterError(const Parameter i) const
constexpr double percent
Definition: AugerUnits.h:283
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
double Quantile(std::vector< double > data, const double percent) const
double pow(const double x, const unsigned int i)
bool HasREvent() const
int fInfoLevel
Definition: VModule.h:123
double GetMag() const
Definition: Vector.h:58
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
#define INFOIntermediate(y)
Definition: VModule.h:162
utl::Point GetVectorFromShowerPlaneVxB(const double x, const double y, const double z, const bool verticalZero) const
in case of positions, the positions has to be relative to the core positions!!!
Class representing a document branch.
Definition: Branch.h:107
class to hold data at the radio Station level.
void SetRejected(const unsigned long long int reason)
Definition: REvent.h:243
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
const Data result[]
bool HasRRecShower() const
bool IsSaturated() const
CandidateStationIterator CandidateStationsBegin()
Definition: REvent.h:144
constexpr double degree
#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
#define INFODebug(y)
Definition: VModule.h:163
revt::ShowerRRecDataQuantities Parameter
double GetParameter(const Parameter i) const
void GetVectorInShowerPlaneVxB(double &x, double &y, double &z, const utl::Point &point) const
in case of positions, the positions has to be relative to the core positions!!!
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
void SetParameterError(Parameter i, double value, bool lock=true)
uint16_t * data
Definition: dump1090.h:228
void SetParameter(Parameter i, double value, bool lock=true)
Vector object.
Definition: Vector.h:30
utl::Vector GetReferenceAxis(const Event &event) const
Returning the referencedirection depending on the corresponding flag.
double GetParameter(const Parameter i) const
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
utl::Vector GetMagneticFieldVector() const
returns the magnetic field vector from the components stored in the parameter storage ...
constexpr double m
Definition: AugerUnits.h:121
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
bool HasSignal() const

, generated on Tue Sep 26 2023.