1 #ifndef __UnivV2Rec_h__
2 #define __UnivV2Rec_h__
7 #include <fwk/CentralConfig.h>
8 #include <utl/Branch.h>
10 #include <evt/ShowerRecData.h>
11 #include <evt/ShowerSRecData.h>
12 #include <evt/ShowerFRecData.h>
13 #include <evt/ShowerUnivRecData.h>
14 #include <evt/ShowerSimData.h>
15 #include <sevt/SEvent.h>
17 #include <utl/Minou.h>
19 #include <utl/GeometryUtilities.h>
20 #include <utl/PhysicalFunctions.h>
21 #include <utl/NormalDistribution.h>
50 const double pftimeres,
51 const double denseFlag) :
57 heightAboveSL(height),
58 pfTimeResidual(pftimeres),
66 const unsigned int Id;
76 double mcSpRadius = 0;
78 double signalUnit = 0;
81 double stationNSTime = 0;
82 unsigned int signalStartSlot = 0;
83 unsigned int signalStopSlot = 0;
84 double t40RelToStart = 0;
91 double detBestFitXmax = 0;
92 double detBestFitRmu = 0;
93 double detBestFitT0 = 0;
94 double detBestFitN = 0;
101 vector<double> integratedSignal = {0};
102 vector<double> integratedNormalizedSignal = {0};
113 int working_pmts = 0;
114 for (
unsigned int i=1; i<4; ++i) {
116 tmp_AoP += station.GetPMT(i).GetRecData().GetAreaOverPeak();
117 tmp_unit += station.GetPMT(i).GetRecData().GetVEMPeak() / station.GetPMT(i).GetRecData().GetVEMCharge();
126 unit = tmp_unit / working_pmts;
127 avgAoP = tmp_AoP / working_pmts;
129 }
else if (
"SSD" == type) {
131 if (station.GetScintillatorPMT().HasCalibData() &&
132 station.GetScintillatorPMT().HasRecData() &&
133 station.GetScintillator().HasRecData() &&
134 station.GetScintillator().HasMIPTrace()) {
137 unit = station.GetScintillatorPMT().GetRecData().GetVEMPeak() /
138 station.GetScintillatorPMT().GetRecData().GetVEMCharge();
145 WARNING(boost::format(
"No SSD PMT data"));
162 return station.GetVEMTrace(traceType);
168 return station.GetScintillator().GetMIPTrace(traceType);
173 WARNING(
"Detector type not found!");
174 return station.GetVEMTrace(traceType);
186 return station.HasVEMTrace(traceType);
192 return station.GetScintillator().HasMIPTrace(traceType);
197 WARNING(
"Detector type not found!");
198 return station.HasVEMTrace(traceType);
220 bool fIsReal =
false;
228 {
"Xmax", 780., .1, 600., 1200.,
true},
229 {
"Rmu", 1., .01, 0., 3.,
true},
230 {
"lgE", 19., .1, 18, 21.,
false}})
235 AddDetectorData(un2Detector d)
238 fun2Detectors.push_back(d);
243 AddMetaData(
double avgXmax,
double logE,
double theta,
bool sim,
int month)
255 operator()(
const vector<double>&
p)
259 double logLikelihood = 0;
261 for(
unsigned int d = 0; d < fun2Detectors.size(); ++d) {
263 const bool useThrs =
true;
267 const double predSignal =
GetSignal(fModel, p[2], fTheta,
268 fun2Detectors[d].spRadius, fun2Detectors[d].spAzimuth, fun2Detectors[d].heightAboveSL,
270 fun2Detectors[d].type, fMonth, fIsReal, useThrs)[0];
274 if (fun2Detectors[d].totalSignal > 5) {
276 ll += -
utl::Sqr((fun2Detectors[d].totalSignal-predSignal)/fun2Detectors[d].uncertaintySignal);
284 logLikelihood += ll * fun2Detectors[d].weight;
307 bool fIsReal =
false;
315 {
"Xmax", 780., .1, 600., 1200.,
false},
316 {
"Rmu", 1.0, .01, 0., 3.,
false},
317 {
"lgE", 19., .1, 18, 21.,
false}})
322 AddDetector(un2Detector d)
325 fun2Detectors.push_back(d);
333 return fun2DetectorPairs.size();
341 for (
const auto& det : fun2Detectors) {
343 if (
"WCD" == det.type) {
347 const unsigned int id = det.Id;
349 for (
const auto& matchDet : fun2Detectors) {
351 if (
id == matchDet.Id &&
"WCD" == matchDet.type) {
353 fun2DetectorPairs.push_back({det, matchDet});
361 INFO(boost::format(
"Generated %i detector pairs for AugerPrime fit.") % fun2DetectorPairs.size());
362 for (
const auto& dets : fun2DetectorPairs) {
364 INFO(boost::format(
"%i (%i) %.2f MIP / %.2f VEM") % dets.at(0).Id % dets.at(1).Id % dets.at(0).totalSignal % dets.at(1).totalSignal);
371 AddMetaData(
double avgXmax,
double logE,
double theta,
bool sim,
int month)
383 operator()(
const vector<double>& p)
387 if (2>fun2DetectorPairs.size()) {
388 WARNING(
"Too few detector pairs generated for ratio fit!");
392 double logLikelihood = 0;
393 for(
unsigned int d = 0; d < fun2DetectorPairs.size(); ++d) {
395 const bool useThrs =
true;
396 const auto& ssd = fun2DetectorPairs[d].at(0);
397 const auto& wcd = fun2DetectorPairs[d].at(1);
398 const double recSignalSSD = ssd.totalSignal;
399 const double recSignalWCD = wcd.totalSignal;
401 const double predSignalSSD =
GetSignal(fModel, p[2], fTheta,
402 ssd.spRadius, ssd.spAzimuth, ssd.heightAboveSL,
404 ssd.type, fMonth, fIsReal, useThrs)[0];
405 const double predSignalWCD =
GetSignal(fModel, p[2], fTheta,
406 wcd.spRadius, wcd.spAzimuth, wcd.heightAboveSL,
408 wcd.type, fMonth, fIsReal, useThrs)[0];
410 const double z = recSignalSSD / recSignalWCD;
411 const double zPred = predSignalSSD / predSignalWCD;
424 const double mu = z-zPred;
425 const double var = (
utl::Sqr(ssd.uncertaintySignal/recSignalSSD) +
426 utl::Sqr(wcd.uncertaintySignal/recSignalWCD));
431 logLikelihood += logprob;
434 if (predSignalWCD > 5) {
436 logLikelihood += - 0.05 *
utl::Sqr((predSignalWCD-recSignalWCD)/wcd.uncertaintySignal) -
438 logLikelihood += - 0.05 *
utl::Sqr((predSignalSSD-recSignalSSD)/ssd.uncertaintySignal) -
464 bool fIsReal =
false;
474 {
"Xmax", 780., .1, 600., 1200.,
false},
475 {
"Rmu", 1.0, .01, 0., 3.,
false},
476 {
"lgE", 19., .1, 18, 21.,
false}})
482 AddDetectorData(un2Detector d)
485 fun2Detectors.push_back(d);
491 AddMetaData(
double avgXmax,
double logE,
double theta,
492 bool sim,
int month,
bool normalized,
double penalty=0)
507 operator()(
const vector<double>& p)
511 double logLikelihood = 0;
514 for (
unsigned int d = 0; d < fun2Detectors.size(); ++d) {
517 vector<double> timeVec = {};
518 vector<double> timeVecDet = {};
521 const double t0 = p[3+d];
527 for (
unsigned int t = 0; t < fun2Detectors[d].integratedSignal.size(); ++t) {
528 timeVec.push_back(t*fun2Detectors[d].nsBin);
529 timeVecDet.push_back(t*fun2Detectors[d].nsBin - t0);
537 fun2Detectors[d].spRadius, fun2Detectors[d].spAzimuth, fun2Detectors[d].heightAboveSL,
538 p[0] , p[1] , fun2Detectors[d].type, fMonth, fIsReal,
true,
540 fun2Detectors[d].pfTimeResidual, fun2Detectors[d].nsBin,
541 fun2Detectors[d].integratedSignal.back());
544 fun2Detectors[d].spRadius, fun2Detectors[d].spAzimuth, fun2Detectors[d].heightAboveSL,
545 fXmax , 1. , fun2Detectors[d].type, fMonth, fIsReal,
true,
546 fun2Detectors[d].pfTimeResidual, fun2Detectors[d].nsBin,
"unc", 0,
547 fun2Detectors[d].totalSignal);
549 for (
unsigned int t = 0; t < timeVec.size(); ++t ) {
555 ll += -1 *
utl::Sqr((fun2Detectors[d].integratedSignal[t] - st[t]) /
556 (
sqrt(
utl::Sqr(stunc[t]) + fun2Detectors[d].totalSignal)) *
557 fun2Detectors[d].weight);
563 if (!std::isnan(ll)) {
570 logLikelihood += -1e5;
579 for(
unsigned int d = 0; d < fun2Detectors.size(); ++d) {
583 const double predSignal =
GetSignal(fModel, p[2], fTheta,
584 fun2Detectors[d].spRadius, fun2Detectors[d].spAzimuth, fun2Detectors[d].heightAboveSL,
586 fun2Detectors[d].type, fMonth, fIsReal,
true)[0];
588 if (fun2Detectors[d].totalSignal > 5) {
590 ll += -
utl::Sqr((fun2Detectors[d].totalSignal-predSignal)/fun2Detectors[d].uncertaintySignal);
609 if (!std::isnan(ll)) {
611 const double penaltyContribution = log(
XmaxDistribution(p[1], p[0], p[2], fIsReal));
612 logLikelihood += fPenalty * penaltyContribution * 50 *
pow(10, fLogE-19);
613 logLikelihood += ll * fun2Detectors[d].weight * 0.1;
617 logLikelihood += -1e5;
constexpr double kSqrt2Pi
bool HasTrace(sevt::StationConstants::SignalComponent traceType)
constexpr T Sqr(const T &x)
total (shower and background)
double LogarithmOfTruncatedGaussianPDF(const double x, const double mu, const double sigma)
un2Detector(const int id, const sevt::Station &stat, const string detType, const double r, const double az, const double height, const double pftimeres, const double denseFlag)
const sevt::Station & station
const double pfTimeResidual
#define INFO(message)
Macro for logging informational messages.
vector< double > referenceDt0
Base class for exceptions trying to access non-existing components.
vector< un2Detector > fun2Detectors
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
double pow(const double x, const unsigned int i)
Class representing a document branch.
class to hold data at Station level
double XmaxDistribution(const double Rmu, const double Xmax, const double lgE, const bool realEvent)
vector< double > GetSignal(string model, double lgE, double zenith, double r, double psi, double height, double Xmax, double Rmu, string detector, int month, bool realAtmosphere, bool useThreshold)
vector< vector< un2Detector > > fun2DetectorPairs
#define WARNING(message)
Macro for logging warning messages.
std::string GetDataString() const
function to get the data inside an element as one big string
const utl::TraceD & GetTrace(sevt::StationConstants::SignalComponent traceType=sevt::StationConstants::eTotal)
const double heightAboveSL
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
vector< double > GetIntegratedTotalSignalSum(vector< double > t, string model, double lgE, double zenith, double r, double psi, double height, double Xmax, double Rmu, string detector, int month, bool realAtmosphere, bool useThreshold, double planeFrontTimeResidual, double nsBin, double normalized)
vector< double > GetIntegratedTotalSignal(vector< double > t, string model, double lgE, double zenith, double r, double psi, double height, double Xmax, double Rmu, string detector, int month, bool realAtmosphere, bool useThreshold, double planeFrontTimeResidual, double nsBin, string returnValue, int component, double normalized)
vector< un2Detector > fun2Detectors
void SimpleReco(evt::Event &event)
vector< un2Detector > fun2Detectors
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
vector< double > referenceDt40