15 #include <Eigen/Cholesky>
19 #include <evt/Event.h>
20 #include <sevt/SEvent.h>
21 #include <sevt/Header.h>
22 #include <evt/ShowerRecData.h>
23 #include <evt/ShowerSRecData.h>
24 #include <fwk/VModule.h>
25 #include <fwk/CentralConfig.h>
26 #include <utl/ErrorLogger.h>
30 #include <fwk/LocalCoordinateSystem.h>
31 #include <utl/CoordinateSystemPtr.h>
35 #include <boost/random.hpp>
36 #include <boost/random/normal_distribution.hpp>
46 using namespace Eigen;
48 #define OUT(x) if ((x) <= fInfoLevel) cerr << " "
51 namespace SdMonteCarloPropagatorKVI {
72 typedef Matrix<double, kNumParameters, kNumParameters>
MatrixmNxNd;
73 typedef Matrix<double, kNumParameters, 1>
VectorNd;
80 auto topB = CentralConfig::GetInstance()->GetTopBranch(
"SdMonteCarloPropagator");
82 topB.GetChild(
"infoLevel").GetData(fInfoLevel);
83 topB.GetChild(
"randomSeed").GetData(fRandomSeed);
98 INFO(
"SdMonteCarloPropagator::Run()");
103 OUT(1) <<
"Restoring the original event." << endl;
111 int sEventId =
event.GetSEvent().GetHeader().GetId();
112 auto eventId =
event.GetHeader().GetId();
113 bool finishEarly =
false;
114 if (
Is(
"_original").NotIn(eventId) &&
Is(
"_varied").NotIn(eventId)) {
115 eventId += string(
"_original");
118 const auto originalStart = eventId.find(
"_original");
119 unsigned int newNum = 0;
120 if (originalStart == string::npos) {
121 newNum = atoi(eventId.substr(eventId.length()-4).c_str()) + 1;
124 eventId = eventId.substr(0, originalStart) +
"_varied0000";
127 eventId = eventId.substr(0, eventId.length()-4);
128 ostringstream numOut;
129 numOut << eventId << setfill(
'0') << setw(4) << newNum;
130 eventId = numOut.str();
132 event.GetHeader().SetId(eventId);
133 event.GetSEvent().GetHeader().SetId(sEventId);
142 OUT(2) <<
"Seeding the random generator with " << sEventId*fRandomSeed << endl;
143 fRandgen.seed(sEventId*fRandomSeed);
162 covarianceMatrix(i, j) = 0;
173 WARNING(
"There is no shower axis available! Sorry, I can't proceed with this event...");
182 origParameters(
eYCore) = core.GetY(gBaryCS);
216 const double xyCoreCov = recShower.
GetCorrelationXY() * xCoreErr * yCoreErr;
220 covarianceMatrix(
eUv,
eVv) = covarianceMatrix(
eVv,
eUv) = uvCov;
223 OUT(2) <<
"Testing errorpropagator " << sEventId << endl;
224 OUT(2) <<
"Original parameters:" << endl;
225 OUT(2) << origParameters << endl;
226 OUT(2) <<
"Covariance matrix:" << endl;
227 OUT(2) << covarianceMatrix << endl;
229 Eigen::LDLT<MatrixmNxNd> ldlt(covarianceMatrix);
232 if (!ldlt.isPositive()) {
233 ERROR(
"Covariance matrix not positive (semi)definite! "
234 "You are the weakest link, good bye! "
235 "(by the way this should definitely not be happening. "
236 "Beter make sure that the SD reconstruction is ok...)");
250 cMDSqrt(i, i) =
sqrt(cMD(i));
253 MatrixmNxNd covarianceMatrixSqrt = cMP.transpose() * cML * cMDSqrt;
256 OUT(2) <<
"Testing wether the 'square root' of the covariance matrix is correctly computed... " << endl;
257 if (!(covarianceMatrixSqrt * covarianceMatrixSqrt.transpose()).isApprox(covarianceMatrix, 1e-12) ) {
258 ERROR(
"The test for the sanity of the covariance matrix failed! This should not be happening.");
264 randomGaussianValues(i) = fRandomGenerator();
266 randomShiftInParameters = covarianceMatrixSqrt * randomGaussianValues;
267 variedParameters = origParameters + randomShiftInParameters;
272 const double variedXCore = variedParameters(
eXCore);
273 const double variedYCore = variedParameters(
eYCore);
274 const double variedZcore = core.GetZ(gBaryCS);
278 recShower.
SetParameter(eShowerAxisX, variedParameters(eShowerAxisX));
279 recShower.
SetParameter(eShowerAxisY, variedParameters(eShowerAxisY));
282 unsigned int variedSeconds = coreTimeSeconds;
284 variedSeconds += variedNanoSeconds/
trillion - 1;
286 const TimeStamp variedCoreTime(variedSeconds, variedNanoSeconds);
291 const double axisU = variedParameters(
eUv);
292 const double axisV = variedParameters(
eVv);
293 const double axisW =
sqrt(1 -
Sqr(axisU) -
Sqr(axisV));
303 OUT(3) <<
"Varied parameters:\n" << variedParameters << endl;
304 OUT(1) <<
"Finished varying parametrs for EventID " << eventId <<
", SEventID " << sEventId << endl;
Matrix< double, kNumParameters, 1 > VectorNd
double GetCorrelationXY() const
void SetCurvature(const double curvature, const double error)
gaussian curvature = 1 / Rc
evt::Event * originalEvent
double GetCurvatureError() const
void SetShowerSize(const double value, const double error)
constexpr T Sqr(const T &x)
Transpositions< kNumParameters, kNumParameters, int > TranspositionmNxNd
double GetCurvature() const
gaussian curvature = 1 / Rc
void SetBeta(const double beta, const double error)
IsProxy< T > Is(const T &x)
Interface class to access to the SD Reconstruction of a Shower.
double GetBetaError() const
double GetParameterCovariance(const Parameter q1, const Parameter q2) const
const utl::Vector & GetCoreError() const
#define INFO(message)
Macro for logging informational messages.
double GetShowerSize() const
void Init()
Initialise the registry.
double GetEnergyError() const
A TimeStamp holds GPS second and nanosecond for some event.
utl::CoordinateSystemPtr gBaryCS
Matrix< double, kNumParameters, kNumParameters > MatrixmNxNd
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
double GetParameter(const Parameter q) const
void SetParameter(const Parameter q, const double param, const bool lock=true)
double GetX(const CoordinateSystemPtr &coordinateSystem) const
const utl::TimeStamp & GetCoreTime() const
time when shower front passes through the core point
void SetAxis(const utl::Vector &axis)
const utl::Point & GetBarycenter() const
#define WARNING(message)
Macro for logging warning messages.
void SetCoreTime(const utl::TimeStamp &coreTime, const utl::TimeInterval &coreTimeErr)
double GetInterval() const
Get the time interval as a double (in Auger base units)
double GetY(const CoordinateSystemPtr &coordinateSystem) const
const utl::TimeInterval & GetCoreTimeError() const
double GetGammaError() const
bool HasParameter(const Parameter q) const
ResultFlag
Flag returned by module methods to the RunController.
unsigned long GetGPSSecond() const
GPS second.
double GetGPSNanoSecond() const
GPS nanosecond.
double GetShowerSizeError() const
const utl::Point & GetCorePosition() const
void SetCorePosition(const utl::Point &core)
void SetGamma(const double gamma, const double error)
void SetEnergy(const double energy, const double error)
#define ERROR(message)
Macro for logging error messages.