12 #include <boost/filesystem/operations.hpp>
14 #include <fwk/CentralConfig.h>
15 #include <fwk/MagneticFieldModel.h>
17 #include <utl/config.h>
18 #include <utl/ErrorLogger.h>
19 #include <utl/Reader.h>
20 #include <utl/RectangleFilter.h>
22 #include <utl/Vector.h>
23 #include <utl/Point.h>
24 #include <utl/BasicVector.h>
25 #include <utl/GeometryUtilities.h>
26 #include <utl/RadioGeometryUtilities.h>
27 #include <utl/CoordinateSystemPtr.h>
28 #include <utl/RadioGeometryUtilities.h>
29 #include <utl/Probability.h>
31 #include <evt/Event.h>
32 #include <evt/ShowerRecData.h>
33 #include <evt/ShowerSRecData.h>
34 #include <evt/ShowerRRecData.h>
35 #include <evt/ShowerFRecData.h>
36 #include <evt/ShowerSimData.h>
38 #include <revt/REvent.h>
39 #include <revt/Station.h>
40 #include <revt/Header.h>
41 #include <revt/StationRecData.h>
43 #include <det/Detector.h>
44 #include <rdet/RDetector.h>
47 #include "TGraphErrors.h"
60 #include "Minuit2/Minuit2Minimizer.h"
61 #include "Minuit2/MnUserParameters.h"
62 #include "Minuit2/MnMigrad.h"
63 #include "Minuit2/MnContours.h"
64 #include "Minuit2/FunctionMinimum.h"
65 #include "Minuit2/MinimumParameters.h"
66 #include "Minuit2/MnPrint.h"
67 #include "Minuit2/MnPlot.h"
68 #include "Minuit2/MnUserCovariance.h"
77 #define OUT(x) if ((x) <= fInfoLevel) std::cerr << " "
78 #define INFO2(x,y) if ((x) <= fInfoLevel) INFO(y)
87 fPlotSigmaContours(true),
90 fStepWidthX(10*utl::
meter),
91 fStepWidthY(10*utl::
meter),
93 fMCUncertaintyOnEFieldVector(0.),
103 RdLDFFitter::~RdLDFFitter()
115 INFO(
"RdLDFFitter::Init()");
165 WARNING(
"No radio event found!");
168 std::stringstream info;
179 if(!(showerrrec.
HasParameter(eRecStage) and showerrrec.
GetParameter(eRecStage) >= evt::ShowerRRecData::kPlaneFit3d)) {
180 WARNING(
"The reconstruction stage is not set or smaller that kPlaneFit3d. LDF Fit can not be performed.");
185 const det::Detector& detector = det::Detector::GetInstance();
190 fLocalCS = LocalCoordinateSystem::Create(coordinateOrigin);
196 INFO(
"Using magnetic field from simulated air shower.");
198 const double magFieldAzimuth =
event.GetSimShower().GetMagneticFieldAzimuth();
199 const double magFieldZenith =
event.GetSimShower().GetMagneticFieldZenith();
201 info <<
"Difference in MC and Offline magnetic field:\n"
207 fShowerAxis = -1. *
event.GetSimShower().GetDirection();
226 "RdLDFFitter: No reconstructed SD shower found. SD core position can't be used to improve radio core. This option will be deactivated for this event.");
231 std::vector<StationFitData> vStationFitData;
250 efield = utl::Probability::GetInstance().GetRandomFisher(
252 info <<
"smeer out efield by " << fMCUncertaintyOnEFieldVector /
utl::deg <<
" degree, ";
254 tmpStationFitData.
efield = efield;
262 "RdLDFFitter: Parameter eAngleToLorentzVector not set. Please run the RdStationEFieldReconstructor Module before the LDF Fitter. This event will be skipped!");
266 vStationFitData.push_back(tmpStationFitData);
270 bool hasScintillator =
271 showerrrec.
HasParameter(revt::eNumberOfAERATopScintWithPulseFound)
272 && (showerrrec.
GetParameter(revt::eNumberOfAERATopScintWithPulseFound) >= 3) ?
275 std::vector<ScintillatorFitData> vScintillatorFitData;
276 if(hasScintillator) {
278 int nSignalScintiallators = 0;
286 tmpScintillatorData.
silent =
false;
287 nSignalScintiallators++;
289 tmpScintillatorData.
silent =
true;
293 vScintillatorFitData.push_back(tmpScintillatorData);
295 if(nSignalScintiallators < 3) {
296 hasScintillator =
false;
297 INFO2(
eIntermediate,
"number of scintillators is less than three, no scintillator LDF will be fitted");
303 if(preScintillatorFit.
status == 0 or preScintillatorFit.
status >= 1000) {
304 info <<
"Pre scintillator LDF fit was successful. N_e = " << preScintillatorFit.
N_e
305 <<
" +/- " << preScintillatorFit.
N_eError;
307 info <<
"Pre scintillator LDF fit was not successful. Error code is " << preScintillatorFit.
status;
323 info <<
"Creating LDF fit function with the following parameters: \n " <<
"LDF Model:\t"
334 vScintillatorFitData,
339 ROOT::Minuit2::MnUserParameters upar;
340 upar.Add(
"coreX", 0., 20);
341 upar.Add(
"coreY", 0., 20);
342 upar.Add(
"coreZ", 0., 10);
348 upar.Add(
"N_e", preScintillatorFit.
N_e, 1.e5);
349 upar.Add(
"s", 1.7, .1);
350 upar.Add(
"Rm", 35., 1.);
353 if(!hasScintillator) {
359 upar.Add(
"A", PreFitResult.
A, PreFitResult.
AError);
360 upar.Add(
"R0", PreFitResult.
R0, PreFitResult.
R0Error);
363 ROOT::Minuit2::MnMigrad migrad(fitFunction, upar);
379 ROOT::Minuit2::FunctionMinimum minimum = migrad();
381 info <<
"minimum: " << minimum;
384 ROOT::Minuit2::MnUserParameterState minUstate_tmp = minimum.UserState();
385 utl::Point core_tmp(minUstate_tmp.Value(
"coreX"), minUstate_tmp.Value(
"coreY"), minUstate_tmp.Value(
"coreZ"),
fLocalCS);
388 double distance = (
event.GetSimShower().GetPosition() - core_tmp).GetMag();
389 info <<
"distance to MC core is " << distance /
utl::m <<
" m";
394 double distance = (
event.GetRecShower().GetSRecShower().GetCorePosition() - core_tmp).GetMag();
395 info <<
"distance to SD core is " << distance /
utl::m <<
" m";
400 if (!minimum.IsValid()) {
401 WARNING(
"Core position fit not converged.");
403 info <<
"current rec stage is " << showerrrec.
GetParameter(eRecStage) << std::endl;
414 ROOT::Minuit2::FunctionMinimum minimum2 = migrad();
415 if (!minimum2.IsValid()) {
416 WARNING(
"Core position fit with free charge excess strength not converged. Saving result without variation of a");
421 info <<
"minimum: " << minimum;
424 showerrrec.
SetParameter(revt::eChargeExcessStrength, minimum2.UserState().Value(
"a"));
426 optimalChargeExcessStrength = minimum2.UserState().Value(
"a");
432 ROOT::Minuit2::MnUserParameterState minUstate = minimum.UserState();
433 ROOT::Minuit2::MnUserCovariance cov = minUstate.Covariance();
435 std::cout <<
"covariance matrix \n" << cov << std::endl;
439 std::vector<double> params (arr, arr +
sizeof(arr) /
sizeof(arr[0]) );
440 const double likelihoodValueAtSDCore = fitFunction(params);
441 showerrrec.
SetParameter(revt::eProbSDCore, TMath::Prob(likelihoodValueAtSDCore, 2));
447 utl::Point core(minUstate.Value(
"coreX"), minUstate.Value(
"coreY"), minUstate.Value(
"coreZ"),
452 showerrrec.
SetParameter(revt::eCoreZ, core.GetZ(referenceCS));
462 info <<
"core (local CS) = (" << minUstate.Value(
"coreX") <<
","
463 << minUstate.Value(
"coreY") <<
"," << minUstate.Value(
"coreZ") <<
")";
466 info <<
"core (reference CS) = (" << core.GetX(referenceCS) <<
","
467 << core.GetY(referenceCS) <<
"," << core.GetZ(referenceCS) <<
")";
470 info <<
"optimal charge excess is " << minUstate.Value(
"a")*100. <<
"%";
474 double distance = (
event.GetRecShower().GetSRecShower().GetCorePosition() - core).GetMag();
475 info <<
"distance to SD core is " << distance /
utl::m <<
" m";
480 double distance = (
event.GetSimShower().GetPosition() - core).GetMag();
481 info <<
"distance to MC core is " << distance /
utl::m <<
" m";
489 showerrrec.
SetParameter(revt::eLDFParameter1, minUstate.Value(
"A"));
490 showerrrec.
SetParameter(revt::eLDFParameter2, minUstate.Value(
"R0"));
499 OUT(
eIntermediate) <<
"LDF parameters at minimum: A = " << minUstate.Value(
"A") <<
"+/-"
500 << minUstate.Error(
"A") <<
"R0 = " << minUstate.Value(
"R0") <<
"+/-"
501 << minUstate.Error(
"R0") << std::endl;
505 TF1
NKG = TF1(
"NKG",
"[0]*TMath::Gamma(4.5-[1])/(2.*TMath::Pi()*[2]*[2]*TMath::Gamma([1])*TMath::Gamma(4.5-(2.*[1])))*TMath::Power((x/[2]),([1]-2.))*TMath::Power((1+(x/[2])),[1]-4.5)");
506 NKG.SetParameter(0, minUstate.Value(
"N_e"));
507 NKG.SetParameter(1, minUstate.Value(
"s"));
508 NKG.SetParameter(2, minUstate.Value(
"Rm"));
509 showerrrec.SetScintLDF(NKG);
520 "RdLDFFitter: No reconstructed SD shower found. SD core position can't be used as center of scan. Scan will not be performed.");
530 "RdLDFFitter: No reconstructed FD shower found. FD core position can't be used as center of scan. Scan will not be performed.");
540 "RdLDFFitter: No reconstructed MC shower found. MC core position can't be used as center of scan. Scan will not be performed.");
543 scanCenter =
event.GetSimShower().GetPosition();
551 std::vector< std::vector<double> > scanResult(
fNStepsX, std::vector<double>(
fNStepsY));
559 filename <<
fOutputFolder <<
"/scan_" << std::setfill(
'0') << std::setw(6) << runNumber <<
"_"
560 << std::setfill(
'0') << std::setw(7) << eventId <<
".png";
561 SaveScan(scanResult, filename.str(), scanCenter.
GetX(referenceCS),
564 filename <<
fOutputFolder <<
"/scan_" << std::setfill(
'0') << std::setw(6) << runNumber <<
"_"
565 << std::setfill(
'0') << std::setw(7) << eventId <<
".png";
566 PlotScan(scanResult, filename.str(),
570 vStationFitData, eventFitData, optimalChargeExcessStrength);
572 filename << std::setfill(
'0') << std::setw(6) << runNumber <<
"_" << std::setfill(
'0')
573 << std::setw(7) << eventId;
583 info <<
"betas at fit optimum are: ";
589 info << anglesCore[i].first /
utl::deg <<
"deg ";
596 sRec.
SetParameter(revt::eBetaScan, anglesCoreScan[i].first);
600 1 / (anglesCoreScan[i].second * anglesCoreScan[i].second)));
603 sRec.
SetParameter(revt::eBetaReferenceCore, anglesReferenceCore[i].first);
607 1 / (anglesReferenceCore[i].second * anglesReferenceCore[i].second)));
616 TF1 fLDF = TF1(
"fLDF",
"[0]*exp(-x/[1])");
617 fLDF.SetParameter(0, minUstate.Value(
"A"));
618 fLDF.SetParameter(1, minUstate.Value(
"R0"));
619 double energy_estimator = fLDF.Eval(110);
620 double energy =
GetEnergy(energy_estimator);
623 std::stringstream sstr;
624 sstr <<
"energy = " << energy <<
" eV";
630 ROOT::Minuit2::MnContours contours(fitFunction, minimum);
631 fitFunction.SetErrorDef(2.3);
632 std::vector<std::pair<double, double> > cont = contours(0, 1, 40);
634 fitFunction.SetErrorDef(5.99);
635 std::vector<std::pair<double, double> > cont2 = contours(0, 1, 40);
639 minUstate.Value(
"coreX"), minUstate.Value(
"coreY"));
657 INFO(
"RdLDFFitter::Finish()");
667 const unsigned int nStepsX,
const unsigned int nStepsY,
668 const double widthX,
const double widthY,
const double a)
674 std::stringstream msg;
676 msg <<
"Scan of Likelihood function around " << coreX <<
", " << coreY <<
" will be performed\n"
677 << nStepsX <<
" steps in x direction with width " << widthX <<
"\n"
678 << nStepsY <<
" steps in y direction with width " << widthY;
681 double Lmin = 9999999999;
682 double xmin(0), ymin(0);
685 msg <<
"loop from " << - (int) (nStepsX / 2) <<
" to " << nStepsX / 2;
688 for (
unsigned int iX = 0; iX < nStepsX; ++iX) {
689 const double x = coreX +
static_cast<int>(iX - nStepsX/2) * widthX;
690 for (
unsigned int iY = 0; iY < nStepsY; ++iY) {
691 const double y = coreY +
static_cast<int>(iY - nStepsY/2) * widthY;
692 const double arr[] = {x, y, coreZ, a};
693 std::vector<double> params (arr, arr +
sizeof(arr) /
sizeof(arr[0]) );
694 double temp = L(params);
696 scanResult[iX][iY] = temp;
704 msg <<
"\bLmin is " << Lmin;
708 msg <<
"Scan result: delta -2*logLikelihood at given core position is "
709 << scanResult[nStepsX/2+1][nStepsY/2+1]<<
"\n"
710 <<
"this corresponds to a probability of " << TMath::Prob(scanResult[nStepsX/2+1][nStepsY/2+1], 2) <<
"\n"
711 <<
"this corresponds to sigma = " << TMath::NormQuantile(TMath::Prob(scanResult[nStepsX/2+1][nStepsY/2+1], 2));
714 for(std::vector< std::vector<double> >::iterator it = scanResult.begin(); it != scanResult.end(); ++it) {
715 for(std::vector<double>::iterator it2 = it->begin(); it2 != it->end(); ++it2) {
724 std::stringstream msg;
727 msg << std::setprecision(2) << std::fixed << number;
729 msg << std::setprecision(1) << std::scientific << number;
738 const unsigned int nStepsX,
const unsigned int nStepsY,
739 const double widthX,
const double widthY,
740 const std::vector<StationFitData>& vStationFitData,
743 bool plotDebug =
false;
744 const det::Detector& detector = det::Detector::GetInstance();
746 const double coreX = scanCenter.
GetX(cs);
747 const double coreY = scanCenter.
GetY(cs);
750 TH2D h = TH2D(
"h",
"", nStepsX,
751 coreX - static_cast<int>(nStepsX / 2) * widthX - 0.5 * widthX,
752 coreX + static_cast<int>(nStepsX / 2) * widthX + 0.5 * widthX, nStepsY,
753 coreY - static_cast<int>(nStepsY / 2) * widthY - 0.5 * widthY,
754 coreY + static_cast<int>(nStepsY / 2) * widthY + 0.5 * widthY);
755 double minimum = 9999999.;
756 std::pair<double, double> minimum_bin (0,0);
757 std::stringstream msg;
759 for (
unsigned int iY = 0; iY < nStepsY; ++iY) {
760 const double y = coreY +
static_cast<int>(iY - nStepsY/2) * widthY;
761 for (
unsigned int iX = 0; iX < nStepsX; ++iX) {
762 const double x = coreX +
static_cast<int>(iX - nStepsX/2) * widthX;
763 msg << scanResult[iX][iY] <<
" ";
764 h.Fill(x, y, scanResult[iX][iY]);
765 if(scanResult[iX][iY] < minimum) {
766 minimum = scanResult[iX][iY];
767 minimum_bin.first = x;
768 minimum_bin.second = y;
774 TCanvas c1(
"c1",
"", 1000,822);
776 c1.GetPad(0)->SetTopMargin(0.02);
777 c1.GetPad(0)->SetLeftMargin(0.10);
778 c1.GetPad(0)->SetBottomMargin(0.08);
779 c1.GetPad(0)->SetRightMargin(0.16);
780 h.GetXaxis()->SetTitle(
"x [m]");
781 h.GetYaxis()->SetTitle(
"y [m]");
782 h.GetYaxis()->SetTitleOffset(1.2);
783 h.GetZaxis()->SetTitle(
"-2 ln(L)");
784 h.GetZaxis()->SetTitleOffset(1.3);
786 const unsigned int nContours = 9;
787 const double contours[nContours] = { -0.00001, 2.29574893, 6.18007431, 11.82915808, 19.33390861, 28.74370243,
788 40.08724343, 53.3822385, 68.50378784};
789 h.SetContour(nContours, contours);
790 h.GetZaxis()->SetRangeUser(-0.00001, 1.1*68.50378784);
795 TLegend leg = TLegend(0.6,0.8,0.84,0.98);
801 TGraph gPosAll = TGraph(stationList.size());
802 for(
unsigned int i = 0; i< stationList.size(); ++i) {
804 gPosAll.SetPoint(i, position.
GetX(cs), position.
GetY(cs));
806 gPosAll.SetMarkerColor(1);
807 gPosAll.SetMarkerStyle(8);
808 gPosAll.SetMarkerSize(2);
809 gPosAll.Draw(
"Psame");
810 leg.AddEntry(&gPosAll,
"RDS",
"P");
813 TGraph gPos = TGraph(vStationFitData.size());
814 for(
unsigned int i = 0; i< vStationFitData.size(); ++i) {
815 gPos.SetPoint(i, vStationFitData[i].antennaPosition.GetX(cs), vStationFitData[i].antennaPosition.GetY(cs));
818 gPos.SetMarkerColor(1);
819 gPos.SetMarkerStyle(22);
820 gPos.SetMarkerSize(2);
822 gPos.SetMarkerColor(1);
823 gPos.SetMarkerStyle(8);
824 gPos.SetMarkerSize(2);
827 leg.AddEntry(&gPos,
"Rd station",
"P");
831 const double sigma = TMath::Prob(scanResult[nStepsX/2][nStepsY/2], 2);
835 gSDCore.SetPoint(0, referenceCore.
GetX(cs), referenceCore.
GetY(cs));
836 gSDCore.SetMarkerStyle(29);
837 gSDCore.SetMarkerColor(6);
838 gSDCore.SetMarkerSize(4);
839 gSDCore.Draw(
"Psame");
851 leg.AddEntry(&gSDCore, msg.str().c_str(),
"P");
854 TLine line = TLine();
855 line.SetLineWidth(2);
857 const double length = nStepsX * widthX * 0.25;
858 line.DrawLine(referenceCore.
GetX(cs), referenceCore.
GetY(cs), referenceCore.
GetX(cs) + cos(azimuth) * length,
859 referenceCore.
GetY(cs) + sin(azimuth) * length);
881 gRdCore.SetPoint(0, coreRd.
GetX(cs), coreRd.
GetY(cs));
882 gRdCore.SetMarkerStyle(23);
883 gRdCore.SetMarkerColor(6);
884 gRdCore.SetMarkerSize(3);
885 gRdCore.Draw(
"Psame");
890 msg <<
"(" << std::setprecision(0) << std::fixed << coreRd.
GetX(cs) /
utl::m <<
"m," << coreRd.
GetY(cs) /
utl::m <<
"m)";
892 leg.AddEntry(&gRdCore, msg.str().c_str(),
"P");
895 double sizeFactor = 1.51;
899 double errorEllipseAngle = 0.5 * atan2(2 * sxy, sx2 - sy2);
900 double sa = sin(errorEllipseAngle);
901 double ca = cos(errorEllipseAngle);
902 double ru = sizeFactor *
sqrt(sx2 * ca * ca + 2 * sxy * sa * ca + sy2 * sa * sa);
903 double rv = sizeFactor *
sqrt(sx2 * sa * sa - 2 * sxy * sa * ca + sy2 * ca * ca);
904 TEllipse cc = TEllipse(referenceCore.
GetX(cs), referenceCore.
GetY(cs), ru, rv, 0., 360.,
907 msg <<
"plotting SD error ellipse with " << referenceCore.
GetX(cs) <<
", "
908 << referenceCore.
GetY(cs) <<
", " << ru <<
", " << rv <<
", " << errorEllipseAngle /
utl::deg;
912 cc.SetFillStyle(3017);
917 msg <<
"scan min (" << std::setprecision(0) << std::fixed << minimum_bin.first <<
"m,"
918 << minimum_bin.second <<
"m)";
920 leg.AddEntry(&gRdCore, msg.str().c_str(),
"");
926 double meanAngle(0.);
928 unsigned int n = angles.size();
929 double p_value_combined(0.);
930 double p_Likelihood = 0.;
931 for(
unsigned int i = 0; i < n; ++i) {
932 meanAngle += angles[i].first;
936 p_value_combined += log(p_value);
938 1 / (angles[i].second * angles[i].second)));
940 p_value_combined *= -2.;
947 msg <<
"#bar{#beta}_{fit} = " << std::setprecision(1) << std::fixed << TMath::RadToDeg() * meanAngle
950 msg <<
", L=" << p_Likelihood;
952 text.SetTextSize(0.030);
959 const double dy = 0.035;
967 utl::Point(minimum_bin.first, minimum_bin.second, coreRd.
GetZ(cs), cs), a);
971 p_value_combined = 0.;
973 for(
unsigned int i = 0; i < n; ++i) {
974 meanAngle += angles[i].first;
978 p_value_combined += log(p_value);
980 1 / (angles[i].second * angles[i].second)));
982 p_value_combined *= -2.;
986 msg <<
"#bar{#beta}_{scan} = " << std::setprecision(1) << std::fixed << TMath::RadToDeg() * meanAngle
989 msg <<
", L=" << p_Likelihood;
1000 p_value_combined = 0.;
1002 for(
unsigned int i = 0; i < n; ++i) {
1003 meanAngle += angles[i].first;
1005 const double p_value = 1
1008 p_value_combined += log(p_value);
1012 1 / (angles[i].second * angles[i].second)));
1014 p_value_combined *= -2.;
1018 msg <<
"#bar{#beta}_{SD} = " << std::setprecision(1) << std::fixed << TMath::RadToDeg() * meanAngle
1021 msg <<
", L=" << p_Likelihood;
1064 double meanSigma = 0.;
1065 double minSigma = 999.;
1067 for(
unsigned int i = 0; i < n; ++i) {
1068 meanAngle += angles[i].first;
1069 meanSigma += angles[i].second;
1070 if(angles[i].
second < minSigma) {
1071 minSigma = angles[i].second;
1077 msg <<
"#delta = " << std::setprecision(1) << std::fixed << TMath::RadToDeg() * meanAngle
1079 <<
" #sigma_{min}=" << minSigma * TMath::RadToDeg() <<
"#circ #bar{#sigma}=" << meanSigma * TMath::RadToDeg() <<
"#circ";
1087 msg <<
"E = " << std::setprecision(2) << std::fixed << energy /
utl::EeV <<
"EeV";
1088 text.DrawLatex(xx, yy, msg.str().c_str());
1093 msg <<
"#Theta = " << std::setprecision(1) << std::fixed << zenith /
utl::deg <<
"#circ";
1094 text.DrawLatex(xx, yy, msg.str().c_str());
1100 msg <<
"E = " << std::setprecision(2) << std::fixed << energy /
utl::EeV <<
"EeV";
1101 text.DrawLatex(xx, yy, msg.str().c_str());
1107 msg <<
"#Theta = " << std::setprecision(1) << std::fixed << zenith /
utl::deg <<
"#circ";
1108 text.DrawLatex(xx, yy, msg.str().c_str());
1113 msg <<
"a = " << std::setprecision(2) <<
a;
1114 text.DrawLatex(xx, yy, msg.str().c_str());
1117 double distance = (referenceCore - coreRd).GetMag();
1119 msg <<
"D_{to SD} = " << std::setprecision(1) << distance /
utl::m <<
" m";
1120 text.DrawLatex(xx, yy, msg.str().c_str());
1125 c1.SaveAs(filename.c_str());
1126 c1.SaveAs((filename+
".C").c_str());
1131 std::vector<std::pair<double, double> > RdLDFFitter::GetAnglesToEFieldExpectation(
const utl::Point core,
const double a)
1133 const det::Detector& detector = det::Detector::GetInstance();
1135 std::vector<std::pair<double, double> > angles;
1146 if (angleToExpectedEField > TMath::Pi() / 2.) {
1147 angleToExpectedEField = TMath::Pi() - angleToExpectedEField;
1149 angles.push_back(std::pair<double, double>(angleToExpectedEField,
1155 std::vector<std::pair<double, double> > RdLDFFitter::GetAnglesToLorentzVector()
1157 const det::Detector& detector = det::Detector::GetInstance();
1159 std::vector<std::pair<double, double> > angles;
1169 double angleToExpectedEField =
utl::Angle(expectedEField, currentEField);
1170 if (angleToExpectedEField > TMath::Pi() / 2.) {
1171 angleToExpectedEField = TMath::Pi() - angleToExpectedEField;
1173 if(fabs(angleToExpectedEField - sRec.
GetParameter(revt::eAngleToLorentzVector)) < 0.0001) {
1174 std::cout <<
"angle to Lorentz angle unequal " << std::endl;
1177 std::pair<double, double>(angleToExpectedEField,
1184 const std::string eventIdentifier,
1187 const det::Detector& detector = det::Detector::GetInstance();
1189 TH1D hAngleToExpectedEField = TH1D(
"hAngleToExpectedEField",
"", 18,0,90);
1190 hAngleToExpectedEField.GetXaxis()->SetTitle(
"#angle(#vec{E}_{exp}, #vec{E}_{measured})");
1191 hAngleToExpectedEField.GetYaxis()->SetTitle(
"entries");
1193 TH1D hAngleToExpectedEFieldSigma = TH1D(
"hAngleToExpectedEFieldSigma",
"", 20,0,10);
1194 hAngleToExpectedEFieldSigma.GetXaxis()->SetTitle(
"#angle(#vec{E}_{exp}, #vec{E}_{measured})/#sigma_{#vec{E}_{measured}}");
1195 hAngleToExpectedEFieldSigma.GetYaxis()->SetTitle(
"entries");
1208 double angleToExpectedEField =
utl::Angle(expectedEField, currentEField);
1209 if (angleToExpectedEField > TMath::Pi() / 2) {
1210 angleToExpectedEField = TMath::Pi() - angleToExpectedEField;
1212 hAngleToExpectedEField.Fill(angleToExpectedEField*TMath::RadToDeg());
1213 hAngleToExpectedEFieldSigma.Fill(angleToExpectedEField/sRec.
GetParameterError(revt::eAngleToLorentzVector));
1215 TCanvas c1(
"c1",
"", 800,800);
1217 hAngleToExpectedEField.SetLineWidth(2);
1218 hAngleToExpectedEField.Draw();
1219 c1.SaveAs((folder+
"/hAngleToEFieldExectation_"+eventIdentifier+
".png").c_str());
1221 TCanvas c2(
"c2",
"", 800,800);
1223 hAngleToExpectedEFieldSigma.SetLineWidth(2);
1224 hAngleToExpectedEFieldSigma.Draw();
1225 c2.SaveAs((folder+
"/hAngleToEFieldExectation_"+eventIdentifier+
"_sigma.png").c_str());
1231 const double coreX,
const double coreY,
1232 const unsigned int nStepsX,
const unsigned int nStepsY,
1233 const double widthX,
const double widthY) {
1234 std::ofstream myfile (filename.c_str());
1235 if (myfile.is_open()) {
1236 for (
unsigned int iX = 0; iX < nStepsX; ++iX) {
1237 const double x = coreX +
static_cast<int>(iX - nStepsX/2) * widthX;
1238 myfile <<
"\t" << x;
1242 for (
unsigned int iY = 0; iY < nStepsY; ++iY) {
1243 const double y = coreY +
static_cast<int>(iY - nStepsY/2) * widthY;
1245 for (
unsigned int iX = 0; iX < nStepsX; ++iX) {
1246 myfile <<
"\t" << scanResult[iX][iY];
1253 else WARNING(
"Unable to open file");
1257 double RdLDFFitter::GetEnergy(
const double energy_estimator)
1263 unsigned int runNumber,
const int eventId,
1264 const std::vector<std::pair<double, double> > contour,
1265 const std::vector<std::pair<double, double> > contour2, ROOT::Minuit2::MnUserCovariance cov,
1266 const double coreX,
const double coreY)
1270 "folder \"output\" does not exist. Can't save confidence contours of radio core position fit. Please create the output folder first.");
1273 std::stringstream sstr(
"");
1275 sstr <<
fOutputFolder <<
"/contour_" << std::setfill(
'0') << std::setw(6) << runNumber <<
"_"
1276 << std::setfill(
'0') << std::setw(7) << eventId <<
".dat";
1280 fout <<
"# fir result: coreX coreY \n" << coreX <<
"\t" << coreY <<
"\n";
1282 fout <<
"# covariance matrix \n" << cov(0, 0) <<
"\t" << cov(0, 1) <<
"\n" << cov(1, 0) <<
"\t"
1283 << cov(1, 1) <<
"\n";
1284 fout <<
"# 68% confidence region: x [m]\t y[m] in local coordinates \n";
1285 for (std::vector<std::pair<double, double> >::const_iterator it = contour.begin();
1286 it != contour.end(); ++it) {
1287 fout << it->first <<
"\t" << it->second <<
"\n";
1289 fout <<
"# 95% confidence region: x [m]\t y[m] in local coordinates \n";
1290 for (std::vector<std::pair<double, double> >::const_iterator it = contour2.begin();
1291 it != contour2.end(); ++it) {
1292 fout << it->first <<
"\t" << it->second <<
"\n";
1298 ParameterLDFModel RdLDFFitter::PreLDFFit(
int LDFModel,
const std::vector<StationFitData>& vStationFitData,
1302 TGraphErrors gLDF = TGraphErrors();
1303 for (
unsigned int i = 0; i < vStationFitData.size(); ++i) {
1307 gLDF.SetPoint(i, distance, data.
signal);
1310 TF1 fLDF = TF1(
"fLDF",
"[0]*exp(-x/[1])");
1311 fLDF.SetParNames(
"A_0",
"R_0");
1312 fLDF.SetParameters(0.1, 100);
1316 par.
A = fLDF.GetParameter(0);
1317 par.
R0 = fLDF.GetParameter(1);
1318 par.
AError = fLDF.GetParError(0);
1319 par.
R0Error = fLDF.GetParError(1);
1323 WARNING(
"Using default LDF model, as chosen model is not implemented\n");
1324 TGraphErrors gLDF = TGraphErrors();
1325 for (
unsigned int i = 0; i < vStationFitData.size(); ++i) {
1329 gLDF.SetPoint(i, distance, data.
signal);
1332 TF1 fLDF = TF1(
"fLDF",
"[0]*exp(-x/[1])");
1333 fLDF.SetParNames(
"A_0",
"R_0");
1334 fLDF.SetParameters(0.1, 100);
1338 par.
A = fLDF.GetParameter(0);
1339 par.
R0 = fLDF.GetParameter(1);
1340 par.
AError = fLDF.GetParError(0);
1341 par.
R0Error = fLDF.GetParError(1);
1348 const std::vector<ScintillatorFitData>& vScintillatorData,
utl::Vector ShowerAxis,
1352 TGraphErrors
g = TGraphErrors();
1353 for (std::vector<ScintillatorFitData>::const_iterator sIt = vScintillatorData.begin(), end =
1354 vScintillatorData.end(); sIt != end; ++sIt) {
1356 ShowerAxis, CorePosition, sIt->scintillatorPosition);
1357 g.SetPoint(g.GetN(), distanceToShowerAxis, sIt->signal);
1358 g.SetPointError(g.GetN() - 1, 0,
sqrt(sIt->signal));
1360 TF1 *NKG_first_stage =
new
1361 TF1(
"NKG_first_stage",
1362 "[0]*TMath::Gamma(4.5-[1])/(2.*TMath::Pi()*[2]*[2]*TMath::Gamma([1])*TMath::Gamma(4.5-(2.*[1])))*TMath::Power((x/[2]),([1]-2.))*TMath::Power((1+(x/[2])),[1]-4.5)",
1365 NKG_first_stage->SetParameter(0, 1. * 1e6);
1366 NKG_first_stage->SetParLimits(0, 100000, 100000000000);
1368 NKG_first_stage->FixParameter(1, 1.7);
1369 NKG_first_stage->SetParameter(2, 35);
1370 NKG_first_stage->SetParLimits(2, 5, 300);
1371 NKG_first_stage->FixParameter(2, 35);
1372 Int_t fitStatus = g.Fit(NKG_first_stage,
"NM");
1373 tmpFitData.
status = fitStatus;
1374 tmpFitData.
N_e = NKG_first_stage->GetParameter(0);
1375 tmpFitData.
N_eError = NKG_first_stage->GetParError(0);
Branch GetTopBranch() const
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger coordinate system associated to the shower core position.
double GetCorrelationXY() const
Class to access station level reconstructed data.
void SetParameter(Parameter i, double value, bool lock=true)
bool HasParameter(const Parameter i) const
utl::Vector GetAxis() const
Returns vector of the shower axis.
static double GetDistanceToAxis(const utl::Vector &ShowerAxis, const utl::Point &CorePosition, const utl::Point &AntennaPosition)
computes the distance from the antenna position to the shower "line" defined by the core position and...
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Report success to RunController.
ParameterScintillatorLDFModel PreScintillatorLDFFit(const std::vector< ScintillatorFitData > &vScintillatorData, utl::Vector ShowerAxis, utl::Point CorePosition)
Interface class to access to the SD Reconstruction of a Shower.
static double GetAngleToEFieldExpectation2D(const utl::Vector &measuredEField, const utl::Point &core, const utl::Vector &showeraxis, const utl::Point &stationPosition, const utl::Vector &vMagField, const double chargeExcessStrength, const utl::CoordinateSystemPtr localCS)
StationRecData & GetRecData()
Get station level reconstructed data.
Interface class to access to the Radio part of an event.
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
ShowerRecData & GetRecShower()
Interface class to access to the RD Reconstruction of a Shower.
bool HasSimShower() const
fwk::VModule::ResultFlag PlotScan(const std::vector< std::vector< double > > &scanResult, const std::string filename, const utl::Point scanCenter, const utl::CoordinateSystemPtr cs, const utl::Point coreSd, const utl::Point coreRd, const unsigned int nStepsX, const unsigned int nStepsY, const double widthX, const double widthY, const std::vector< StationFitData > &vStationFitData, const EventFitData &eventFitData, const double a)
double GetParameterError(const Parameter i) const
const std::vector< int > & GetFullStationList() const
Get list of ID's for all stations available in the database or configuration file.
bool HasParameterError(const Parameter i1) const
const utl::Vector & GetCoreError() const
#define INFO(message)
Macro for logging informational messages.
std::vector< std::pair< double, double > > GetAnglesToEFieldExpectation(const utl::Point core, const double a)
StationIterator StationsEnd()
StationIterator StationsBegin()
void Init()
Initialise the registry.
vector< t2list > out
output of the algorithm: a list of clusters
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
double pow(const double x, const unsigned int i)
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
fwk::VModule::ResultFlag SaveScan(const std::vector< std::vector< double > > &scanResult, const std::string filename, const double coreX, const double coreY, const unsigned int nStepsX, const unsigned int nStepsY, const double widthX, const double widthY)
ShowerRRecData & GetRRecShower()
ShowerSRecData & GetSRecShower()
double GetEnergy(const double energy_estimator)
fwk::VModule::ResultFlag PlotGoodnessOfFit(const std::string folder, const std::string eventIdentifier, const utl::Point core)
double SDCoreXYCorrelation
reconstructs the core position and LDF
Detector description interface for RDetector-related data.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
utl::CoordinateSystemPtr fLocalCS
Class representing a document branch.
utl::Point GetCoordinateOrigin() const
class to hold data at the radio Station level.
const utl::Vector & GetDirection() const
Get the direction of the shower axis. This is the true direction of shower movement.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
std::string GetFormattedNumber(const double number)
bool useStationsWithoutSignal
utl::Point Scan(std::vector< std::vector< double > > &scanResult, const LDFLikelihoodFunction L, const utl::Point core, const unsigned int nStepsX, const unsigned int nStepsY, const double widthX, const double widthY, const double a)
nSteps is considered to be odd. If it is even, nSteps will be increased by 1 to be odd...
static utl::Vector GetLorentzVector(const utl::Vector &showeraxis, const utl::Vector &vMagField)
returns the Lorentz force vector normalized to length = 1 for maximal emission (showeraxis vertical t...
bool HasFRecShower() const
Header & GetHeader()
access to REvent Header
Top of the hierarchy of the detector description interface.
ShowerSimData & GetSimShower()
std::string fOutputFolder
double GetEnergy() const
Get the energy of the shower primary particle.
const utl::Vector & GetAxis() const
static const CSpherical kSpherical
static double GetFisherPDF(const double x, const double kappa)
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
fwk::VModule::ResultFlag SaveContours(unsigned int runNumber, const int eventId, const std::vector< std::pair< double, double > > contour, const std::vector< std::pair< double, double > > contour2, ROOT::Minuit2::MnUserCovariance cov, const double coreX, const double coreY)
AxialVector Normalized(const AxialVector &v)
const revt::REvent * fREvent
double GetParameter(const Parameter i) const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
std::vector< std::pair< double, double > > GetAnglesToLorentzVector()
utl::Point antennaPosition
ResultFlag
Flag returned by module methods to the RunController.
bool HasParameter(const Parameter i) const
double chargeExcessStrength
static utl::Vector GetExpectedEFieldVector(const utl::Point &core, const utl::Vector &showeraxis, const utl::Point &stationPosition, const utl::Vector &vMagField, const double chargeExcessStrength)
utl::Point scintillatorPosition
utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const
Get the reference coordinate system used for analysis (usually PampaAmarilla for Auger) ...
utl::CoordinateSystemPtr fLocalCS
ParameterLDFModel PreLDFFit(int LDFModel, const std::vector< StationFitData > &vStationFitData, utl::Vector ShowerAxis, utl::Point CorePosition)
void SetParameter(Parameter i, double value, bool lock=true)
double Angle(const Vector &left, const Vector &right)
Interface class to access to Fluorescence reconstruction of a Shower.
Report failure to RunController, causing RunController to terminate execution.
const utl::Point & GetCorePosition() const
utl::Point GetCorePosition() const
returns pointer of the position vector of the core in the reference coor system
static double GetFisherCDF(const double x, const double kappa)
const rdet::RDetector & GetRDetector() const
double GetParameter(const Parameter i) const
SignalStationIterator SignalStationsEnd()
bool useSDCoreToImproveRadioCore
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
utl::Vector fMagneticFieldAxis
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
bool useChargeExcessCorrectionInLDFFit
double fMCUncertaintyOnEFieldVector
const Station & GetStation(const int stationId) const
Get station by Station Id.
const utl::Point & GetCorePosition() const
Shower core as reconstructed by the FD or FD eye.
bool HasSRecShower() const
double NKG(const double r, const double n, const double rG, const double s)
const evt::Event * fConstEvent
boost::filter_iterator< SignalStationFilter, AllStationIterator > SignalStationIterator
Iterator over all signal stations.
void SetParameterCovariance(Parameter i1, Parameter i2, double value, bool lock=true)
SignalStationIterator SignalStationsBegin()
boost::filter_iterator< SignalStationFilter, ConstAllStationIterator > ConstSignalStationIterator