14 #include "Math/PdfFuncMathCore.h"
16 #include "Math/WrappedTF1.h"
17 #include "Math/RootFinder.h"
20 #include <boost/format.hpp>
22 #include "Minuit2/MnMigrad.h"
23 #include "Minuit2/MnHesse.h"
24 #include "Minuit2/MnPrint.h"
25 #include "Minuit2/MnStrategy.h"
27 #include <tls/UnivTimeKGLogNormal.h>
28 #include <tls/UnivTimeKGGamma.h>
30 #include <utl/PhysicalFunctions.h>
31 #include <utl/UTMPoint.h>
32 #include <utl/ReferenceEllipsoid.h>
33 #include <utl/TimeInterval.h>
34 #include <utl/AugerCoordinateSystem.h>
35 #include <utl/PhysicalFunctions.h>
36 #include <utl/AugerUnits.h>
37 #include <utl/CovarianceMatrix.h>
38 #include <utl/NumericalErrorPropagator.h>
39 #include <utl/GeometryUtilities.h>
46 using namespace ROOT::Minuit2;
53 namespace UnivFitterKG {
62 const double z = (sigmaFactor - 1.05) / 0.05;
63 const double t = 1 / (1 + std::exp(z));
64 return t + (1 - t) /
Sqr(sigmaFactor);
71 const double kRadius = 1.8 *
meter;
72 const double kHeight = 1.2 *
meter;
73 const double sinTheta =
sqrt(1 -
pow(cosTheta, 2.));
74 return 1 / (cosTheta + 2 * kHeight * sinTheta / (
kPi * kRadius));
90 const double calPars[2] = { 2.51594443, 1.03997067 };
91 const double cicPars[3] = { 1.07546532, 2.10875764, -0.37034705 };
94 const double s38 = showerSize / (1 + cossqref * (cicPars[0] + cossqref * (cicPars[1] + cossqref * cicPars[2])));
95 return calPars[0] * 1e17 *
pow(s38, calPars[1]);
105 const double calPars_p[2] = { 2.51594443, 1.03997067 };
107 const double calPars_data[2] = { 1.89541, 1.02465 };
109 const double s38 =
pow(sdenergy / (calPars_data[0] * 1e17), 1 / calPars_data[1]);
111 return calPars_p[0] * 1e17 *
pow(s38, calPars_p[1]);
115 WCDFitFunction::WCDFitFunction(
const Fitter& theEf) : ef(theEf) { }
127 for (
unsigned int i = 0; i < pars.size(); ++i) {
128 if (std::isnan(pars[i]))
134 const double relCoreTime = pars[3];
137 const double theta = pars[4];
138 const double phi = pars[5];
141 CoordinateSystem::RotationY(theta, CoordinateSystem::RotationZ(phi, coreCS))
145 double Nmu = pars[7];
151 const double mmu_offset = pars[9];
157 using namespace utl::InvisibleEnergy;
161 TF1 func(
"f",
"[3]*([0]-[1]*(x/1e18)**(-[2])) - x/[4]");
162 func.SetParameter(0,
p[0]);
163 func.SetParameter(1,
p[1]);
164 func.SetParameter(2,
p[2]);
165 func.SetParameter(3, mf);
166 func.SetParameter(4, totalEnergy);
168 ROOT::Math::RootFinder rf;
169 ROOT::Math::WrappedTF1 wf1(func);
170 rf.SetFunction(wf1, 0.5 * totalEnergy, 1.5 * totalEnergy);
172 double calEnergy = rf.Root();
174 double dummycostheta=0.7071067;
178 const double logTotalEnergy = log10(totalEnergy);
186 printf(
"x %.4f, y %.4f, z %.4f, relct %.3f, ", pars[0], pars[1], pars[2], pars[3]);
189 printf(
"Nmu %.3f, loge %.3f, ", Nmu, logTotalEnergy);
196 double TotalLikelihood = 0;
201 for (std::vector<StationFitData>::const_iterator sIt =
ef.
fitData.begin(); sIt !=
ef.
fitData.end(); ++sIt) {
203 if (!(sIt->useForLDFFit || sIt->useForShapeFit || sIt->useForStartTimeFit))
206 sIt->LDFLikelihood = 0;
207 sIt->ShapeLikelihood = 0;
208 sIt->StartTimeLikelihood = 0;
209 sIt->planeFrontTime =
PlaneFrontTime(showerPlaneCS, core, sIt->position);
210 const double stationRho = sIt->position.GetRho(showerPlaneCS);
211 const double stationPsi = sIt->position.GetPhi(showerPlaneCS);
218 sIt->firstParticleTimes.clear();
222 sIt->firstParticleTimes.push_back(fpt_global);
227 const double h1 =
ef.
fAtmosphere->SlantDepthToHeight(xmax /
gpercm2, theta) + D_TO * 1e5 * cos(theta);
229 sIt->firstParticleTimes.push_back(
ef.
fAtmosphere->GetTimeCF_h(stationRho /
cm, stationPsi, h1, theta, sIt->height /
cm));
233 const Vector stationToCore = core - sIt->position;
234 const Vector stationToCenter = stationToCore + sIt->distToFirstInteraction * axis;
235 const double rStation = stationToCenter.
GetMag();
236 const double cosThetaStation = stationToCenter.
GetZ(
ef.
fBaryCS) / rStation;
254 ef.
timeModels[icomp]->setShapeParameters(sIt->DX_diffusive /
gpercm2, stationRho, stationPsi, theta, logTotalEnergy);
257 double predTotalSignal = 0;
258 sIt->compSignals.clear();
265 sIt->compSignals.push_back(sig);
266 predTotalSignal += sig;
270 const double totalSignalUncertainty = poissonFactor * sigmaFactor *
std::sqrt(predTotalSignal);
271 sIt->signalUncertainty = totalSignalUncertainty;
273 const double stationTime = (sIt->startTime - coreTime).GetInterval();
280 const double stationTimePF = stationTime - sIt->planeFrontTime -
ef.
fStartTimeBias;
282 double StationLikelihood = 0;
283 const double fem = sIt->compSignals[1] / predTotalSignal;
287 double StationShapeLikelihood = 0;
291 const double qs[2] = { 0.1, 0.5 };
292 const double qts[2] = { sIt->t10, sIt->t50 };
294 for (
unsigned int qi = 0; qi < 2; ++qi) {
297 const double nps = predTotalSignal * pfac;
298 const double ih = nps * qs[qi];
304 pdfval +=
ef.
timeModels[icomp]->pdf(stationTimePF + qts[qi] - sIt->firstParticleTimes[icomp]);
305 cdfval +=
ef.
timeModels[icomp]->cdf(stationTimePF + qts[qi] - sIt->firstParticleTimes[icomp]);
312 const double LLq = log(norm *
pow(1 - cdfval, nps - ih - 1) *
pow(cdfval, ih) * pdfval);
314 StationShapeLikelihood += (std::isnan(LLq) || std::isinf(LLq)) ? 200 : LLq;
320 for (
unsigned int curBin = 0; curBin < sIt->trace.size(); ++curBin) {
321 const double curBinContent = sIt->trace[curBin];
323 if (sIt->isSaturated) {
326 curBinContent > 0.95 * sIt->Smaxbin)
335 (
int(curBin) < sIt->firstFitBin ||
int(curBin) > sIt->lastFitBin))
338 const double binPFTime = stationTimePF + (curBin + 1 - sIt->startBin) * sIt->binwidth;
342 cout <<
"Bin " << curBin <<
" is skipped because it is later than t50 " << sIt->t50 << endl;
346 double predictedBinContent = 0;
347 double predictedBinComponentContent = 0;
348 const double totalBinSigma = poissonFactor * sigmaFactor *
std::sqrt(curBinContent);
349 double StationShapeBinLikelihood = 0;
353 predictedBinComponentContent =
354 (
ef.
timeModels[icomp]->cdf(binPFTime - sIt->firstParticleTimes[icomp] + sIt->binwidth / 2) -
355 ef.
timeModels[icomp]->cdf(binPFTime - sIt->firstParticleTimes[icomp] - sIt->binwidth / 2)) *
356 sIt->compSignals[icomp];
357 predictedBinContent += predictedBinComponentContent;
360 StationShapeBinLikelihood +=
LogarithmOfNormalPDF(curBinContent, predictedBinContent, totalBinSigma);
362 cout <<
"id=" << sIt->stationId <<
" bin=" << curBin
363 <<
" S=" << curBinContent <<
" pred=" << predictedBinContent
364 <<
" LL=" << -StationShapeBinLikelihood << endl;
367 StationShapeLikelihood += StationShapeBinLikelihood;
372 StationLikelihood += StationShapeLikelihood;
374 sIt->ShapeLikelihood = StationShapeLikelihood;
381 const double startTimeProb =
383 ef.
timeModels[
sc_mu]->firstParticlePdfSmeared(stationTimePF - sIt->firstParticleTimes[
sc_mu], muonsInStation) :
385 const double StationStartTimeLikelihood = log(startTimeProb);
389 <<
" id " << sIt->stationId
390 <<
" npart " << muonsInStation
391 <<
" fpt " << sIt->firstParticleTimes[
sc_mu] <<
" stpf " << stationTimePF <<
" stprob " << startTimeProb
392 <<
" pft " << format(
" %.10e ") % sIt->planeFrontTime
393 <<
" stl " << StationStartTimeLikelihood
396 StationLikelihood += StationStartTimeLikelihood;
398 sIt->StartTimeLikelihood = StationStartTimeLikelihood;
401 if (sIt->useForLDFFit || ((sIt->useForLDFFit || sIt->useForShapeFit) &&
ef.
fOnlySignalLikelihood && !sIt->isSaturated)) {
403 double StationLDFLikelihood = 0;
406 <<
" id " << sIt->stationId
407 <<
" signal " << sIt->totalSignal
408 <<
" pred " << predTotalSignal
409 <<
" sigma " << totalSignalUncertainty
412 StationLDFLikelihood +=
413 TMath::Log(TMath::Poisson(poissonFactor * sIt->totalSignal, poissonFactor * predTotalSignal));
415 if (!(std::isnan(StationLDFLikelihood) || std::isinf(StationLDFLikelihood))) {
416 StationLikelihood += StationLDFLikelihood;
418 sIt->LDFLikelihood = StationLDFLikelihood;
424 const double constrLL =
LogarithmOfNormalPDF(sIt->recoveredSignal, predTotalSignal, sIt->recoveredSignalUncertainty);
425 StationLikelihood += constrLL;
428 if (sIt->useForMuonTimeFit) {
429 double StationMuonTimeLikelihood = 0;
431 for (
unsigned int k = 0; k < sIt->muonTimes.size(); k++) {
432 const double muonTimePF = sIt->muonTimes[k] - sIt->planeFrontTime;
435 StationMuonTimeLikelihood += MuonTimeLikelihood;
437 cout <<
" id " << sIt->stationId
439 <<
" fpt " << sIt->firstParticleTimes[
sc_mu]
440 <<
" muon LL " << MuonTimeLikelihood
444 StationLikelihood += StationMuonTimeLikelihood;
448 const double predMuonSignal = sIt->compSignals[
sc_mu];
452 StationLikelihood += muonConstraint;
455 TotalLikelihood += StationLikelihood;
484 if (std::isnan(TotalLikelihood) || std::isinf(TotalLikelihood))
488 printf(
"ll %.3f\n", TotalLikelihood);
490 return -TotalLikelihood;
538 const double minScanValue = val - delta;
539 const double maxScanValue = val + delta;
540 const double scanStep = (maxScanValue - minScanValue) / nSteps;
551 for (
double scanValue = minScanValue; scanValue < maxScanValue; scanValue += scanStep) {
552 scanVals.
x.push_back(scanValue);
553 params[parIndex] = scanValue;
554 const double funcval = (*fFunc)(params);
555 scanVals.
f.push_back(funcval);
569 const double deltaX,
const double deltaY,
const int nSteps)
571 const double minScanValuex = valx - deltaX;
572 const double maxScanValuex = valx + deltaX;
573 const double minScanValuey = valy - deltaY;
574 const double maxScanValuey = valy + deltaY;
575 const double scanStepx = (maxScanValuex - minScanValuex) / nSteps;
576 const double scanStepy = (maxScanValuey - minScanValuey) / nSteps;
587 for (
int i = 0; i < nSteps; ++i) {
588 scanVals.
x.push_back(minScanValuex + i * scanStepx);
589 scanVals.
y.push_back(minScanValuey + i * scanStepy);
592 for (
int iy = 0; iy < nSteps; ++iy) {
593 for (
int ix = 0; ix < nSteps; ++ix) {
594 params[parIndexx] = scanVals.
x[ix];
595 params[parIndexy] = scanVals.
y[iy];
596 scanVals.
f.push_back(-(*
fFunc)(params));
608 const int nSteps = 1000;
616 std::ofstream
out(
"scan_out.txt");
617 for (
unsigned int i = 0; i < scan.
x.size(); ++i) {
618 out << format(
"%.15e ") % scan.
x[i]
619 << format(
"%.15e ") % scan.
f[i]
620 << format(
"%.15e ") % scan.
fLDF[i]
621 << format(
"%.15e ") % scan.
fShape[i]
643 UTMPoint malargueOrigin(6060000 *
m, 440000 *
m, 0, 19,
'H', wgs84);
647 CoordinateSystemPtr pampaAmarillaCS = AugerCoordinateSystem::Create(pampaAmarillaOrigin, malargueCS);
757 for (
int icomp = 0; icomp <
fNSigComps; ++icomp)
759 }
else if (version == 2) {
760 for (
int icomp = 0; icomp <
fNSigComps; ++icomp)
763 cout <<
"ERROR: invalid time model version" << endl;
772 for (
int icomp = 0; icomp <
fNSigComps; ++icomp)
868 for (std::vector<StationFitData>::iterator sIt =
fitData.begin(); sIt !=
fitData.end(); ++sIt) {
869 if (sIt->stationId == stationId)
917 upar.SetLimits(
"relCoreTime", -1e6 *
nanosecond, 1e6 * nanosecond);
927 upar.Fix(
"relCoreTime");
937 upar.SetLimits(
"theta", minTheta, upar.Value(
"theta") +
fAxisFitLimit);
954 upar.SetLimits(
"Nmu", 0., 4.);
964 upar.SetLimits(
"TimeModelOffset", -3., 3.);
966 upar.Fix(
"TimeModelOffset");
969 upar.SetLimits(
"x0", 0., 500);
989 for (std::vector<StationFitData>::iterator sIt =
fitData.begin(); sIt !=
fitData.end(); ++sIt) {
995 sIt->denseRho * sin(sIt->densePsi), 0, rotatedMCCoreCS);
1025 cout <<
"ERROR: invalid initMode" << endl;
1036 double weightSum = 0;
1038 for (std::vector<StationFitData>::const_iterator sIt =
fitData.begin(); sIt !=
fitData.end(); ++sIt) {
1039 const double weight =
sqrt(sIt->totalSignal);
1040 weightSum += weight;
1041 barySum += weight * (sIt->position - siteOrigin);
1043 barySum /= weightSum;
1047 double hottestStationSignal = 0;
1048 Point hottestStationPosition;
1049 for (std::vector<StationFitData>::iterator sIt =
fitData.begin(); sIt !=
fitData.end(); ++sIt) {
1050 if (sIt->totalSignal > hottestStationSignal) {
1051 hottestStationPosition = sIt->position;
1052 hottestStationSignal = sIt->totalSignal;
1053 if (sIt->isSaturated)
1054 cout <<
"hottest station " << sIt->stationId <<
" is saturated" << endl;
1063 cout <<
"ERROR: Energy rescaling requires Sd parameters at the moment!" << endl;
1072 <<
"station selection:\n"
1073 <<
"-------------------------\n";
1076 for (std::vector<StationFitData>::iterator sIt =
fitData.begin(); sIt !=
fitData.end(); ++sIt) {
1080 int nBinsAboveShapeFitLimit = 0;
1084 if (sIt->trace.size() > 0) {
1085 for (
unsigned int curBin = 0; curBin < sIt->trace.size(); ++curBin) {
1087 ++nBinsAboveShapeFitLimit;
1088 if (sIt->trace[curBin] > Smaxbin)
1089 Smaxbin = sIt->trace[curBin];
1092 for (
int curBin = sIt->startBin; curBin <= sIt->stopBin; ++curBin) {
1093 sIt->traceSum += sIt->trace[curBin];
1096 double traceCumulative = 0;
1097 for (
unsigned int curBin = 0; curBin < sIt->trace.size(); ++curBin) {
1098 traceCumulative += sIt->trace[curBin];
1099 if (!sIt->firstFitBin && traceCumulative >= 0.05 * sIt->traceSum)
1100 sIt->firstFitBin = curBin;
1101 if (!sIt->lastFitBin && traceCumulative >= 0.8 * sIt->traceSum)
1102 sIt->lastFitBin = curBin - 1;
1106 sIt->Smaxbin = Smaxbin;
1111 sIt->useForShapeFit =
1119 !sIt->useForShapeFit &&
1120 !sIt->isSaturated &&
1124 sIt->useForStartTimeFit =
1126 !sIt->useForShapeFit &&
1131 if (sIt->useForLDFFit)
1133 if (sIt->useForShapeFit)
1135 if (sIt->useForStartTimeFit)
1139 sIt->useForMuonTimeFit =
true;
1142 cout <<
"id " << sIt->stationId
1143 <<
" r " << showpoint << stationRho
1144 <<
" S " << showpoint << sIt->totalSignal <<
" "
1145 << (sIt->useForLDFFit ?
"ldf " :
" ")
1146 << (sIt->useForShapeFit ?
"shape " :
" ")
1147 << (sIt->useForStartTimeFit ?
"time " :
" ")
1148 << (sIt->isSaturated ?
"saturated " :
" ")
1149 << (sIt->useUnsaturatedTrace ?
"(use simulated unsaturated trace)" :
" ");
1151 if (sIt->useForMuonTimeFit)
1152 cout << sIt->muonTimes.size() <<
" muons";
1155 cout <<
" fit bins " << sIt->firstFitBin <<
" " << sIt->lastFitBin;
1168 cout <<
"-------------------------\n";
1171 bool hesseOk =
true;
1172 MnUserParameters upar;
1175 if (upar.VariableParameters() > 0) {
1176 const int maxSteps = 100000;
1179 FunctionMinimum* min = 0;
1187 migrad.Fix(
"theta");
1189 migrad.Fix(
"energy");
1190 migrad.Fix(
"TimeModelOffset");
1191 migrad.Fix(
"relCoreTime");
1193 migrad.Release(
"coreX");
1194 migrad.Release(
"coreY");
1195 migrad.Release(
"Nmu");
1199 min =
new FunctionMinimum(migrad(maxSteps,
fMigradTol));
1202 migrad.Fix(
"coreX");
1203 migrad.Fix(
"coreY");
1206 migrad.Release(
"relCoreTime");
1207 migrad.Release(
"TimeModelOffset");
1219 const bool dbgprint(
true);
1230 const double lgE0 = log10(migrad.Value(
"energy") *
fEnergyScale);
1248 const double lgE = log10(migrad.Value(
"energy") *
fEnergyScale);
1249 const double theta = migrad.Value(
"theta");
1254 migrad.SetValue(
"xmax", xmax);
1255 migrad.SetValue(
"Nmu", nmu);
1259 cout <<
"Energy before stage 1: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1260 cout <<
"Xmax before stage 1: " << migrad.Value(
"xmax") << endl;
1261 cout <<
"Nmu before stage 1: " << migrad.Value(
"Nmu") << endl;
1262 cout <<
"Zenith before stage 1: " << migrad.Value(
"theta") << endl;
1263 cout <<
"RelCoreTime before stage 1: " << migrad.Value(
"relCoreTime") << endl;
1266 migrad.Fix(
"TimeModelOffset");
1270 migrad.Fix(
"theta");
1272 migrad.Fix(
"relCoreTime");
1275 migrad.Release(
"energy");
1277 migrad.Fix(
"energy");
1279 migrad.Release(
"coreX");
1280 migrad.Release(
"coreY");
1282 min =
new FunctionMinimum(migrad(maxSteps,
fMigradTol));
1285 cout <<
"Energy after stage 1: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1286 cout <<
"Xmax after stage 1: " << migrad.Value(
"xmax") << endl;
1287 cout <<
"Nmu after stage 1: " << migrad.Value(
"Nmu") << endl;
1288 cout <<
"Zenith after stage 1: " << migrad.Value(
"theta") << endl;
1289 cout <<
"RelCoreTime after stage 1: " << migrad.Value(
"relCoreTime") << endl;
1299 const double lgE = log10(migrad.Value(
"energy") *
fEnergyScale);
1300 const double theta = migrad.Value(
"theta");
1305 migrad.SetValue(
"xmax", xmax);
1306 migrad.SetValue(
"Nmu", nmu);
1310 cout <<
"Energy before stage 2: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1311 cout <<
"Xmax before stage 2: " << migrad.Value(
"xmax") << endl;
1312 cout <<
"Nmu before stage 2: " << migrad.Value(
"Nmu") << endl;
1313 cout <<
"Zenith before stage 2: " << migrad.Value(
"theta") << endl;
1314 cout <<
"RelCoreTime after stage 2: " << migrad.Value(
"relCoreTime") << endl;
1319 migrad.Fix(
"theta");
1321 migrad.Fix(
"relCoreTime");
1324 migrad.Release(
"energy");
1326 migrad.Fix(
"energy");
1328 migrad.Release(
"coreX");
1329 migrad.Release(
"coreY");
1334 cout <<
"Energy after stage 2: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1335 cout <<
"Xmax after stage 2: " << migrad.Value(
"xmax") << endl;
1336 cout <<
"Nmu after stage 2: " << migrad.Value(
"Nmu") << endl;
1337 cout <<
"Zenith after stage 2: " << migrad.Value(
"theta") << endl;
1338 cout <<
"RelCoreTime after stage 2: " << migrad.Value(
"relCoreTime") << endl;
1347 migrad.Fix(
"energy");
1348 migrad.Fix(
"coreX");
1349 migrad.Fix(
"coreY");
1351 migrad.Fix(
"theta");
1354 migrad.Release(
"relCoreTime");
1363 migrad.Release(
"relCoreTime");
1364 migrad.Release(
"xmax");
1369 cout <<
"Energy after stage 3: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1370 cout <<
"Xmax after stage 3: " << migrad.Value(
"xmax") << endl;
1371 cout <<
"Nmu after stage 3: " << migrad.Value(
"Nmu") << endl;
1372 cout <<
"Zenith after stage 3: " << migrad.Value(
"theta") << endl;
1373 cout <<
"RelCoreTime after stage 3: " << migrad.Value(
"relCoreTime") << endl;
1403 cout <<
"Energy before stage 4: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1404 cout <<
"Xmax before stage 4: " << migrad.Value(
"xmax") << endl;
1405 cout <<
"Nmu before stage 4: " << migrad.Value(
"Nmu") << endl;
1406 cout <<
"Zenith before stage 4: " << migrad.Value(
"theta") << endl;
1407 cout <<
"RelCoreTime before stage 4: " << migrad.Value(
"relCoreTime") << endl;
1411 migrad.Fix(
"energy");
1412 migrad.Fix(
"coreX");
1413 migrad.Fix(
"coreY");
1415 migrad.Release(
"theta");
1416 migrad.Release(
"phi");
1423 const double lgE = log10(migrad.Value(
"energy") *
fEnergyScale);
1424 const double theta = migrad.Value(
"theta");
1425 const double xmax = migrad.Value(
"xmax");
1429 migrad.SetValue(
"Nmu", nmu);
1433 cout <<
"Energy after stage 4: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1434 cout <<
"Xmax after stage 4: " << migrad.Value(
"xmax") << endl;
1435 cout <<
"Nmu after stage 4: " << migrad.Value(
"Nmu") << endl;
1436 cout <<
"Zenith after stage 4: " << migrad.Value(
"theta") << endl;
1437 cout <<
"RelCoreTime after stage 4: " << migrad.Value(
"relCoreTime") << endl;
1507 migrad.Fix(
"energy");
1508 migrad.Fix(
"coreX");
1509 migrad.Fix(
"coreY");
1510 migrad.Fix(
"theta");
1512 migrad.Fix(
"relCoreTime");
1515 migrad.Release(
"Nmu");
1520 cout <<
"Energy after stage 5: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1521 cout <<
"Xmax after stage 5: " << migrad.Value(
"xmax") << endl;
1522 cout <<
"Nmu after stage 5: " << migrad.Value(
"Nmu") << endl;
1523 cout <<
"Zenith after stage 5: " << migrad.Value(
"theta") << endl;
1524 cout <<
"RelCoreTime after stage 5: " << migrad.Value(
"relCoreTime") << endl;
1539 migrad.Release(
"theta");
1540 migrad.Release(
"phi");
1541 migrad.Release(
"xmax");
1546 cout <<
"Energy after stage 6: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1547 cout <<
"Xmax after stage 6: " << migrad.Value(
"xmax") << endl;
1548 cout <<
"Nmu after stage 6: " << migrad.Value(
"Nmu") << endl;
1549 cout <<
"Zenith after stage 6: " << migrad.Value(
"theta") << endl;
1550 cout <<
"RelCoreTime after stage 6: " << migrad.Value(
"relCoreTime") << endl;
1562 migrad.Fix(
"theta");
1565 migrad.Release(
"energy");
1570 cout <<
"Energy after stage 7: " << log10(migrad.Value(
"energy") *
fEnergyScale) << endl;
1571 cout <<
"Xmax after stage 7: " << migrad.Value(
"xmax") << endl;
1572 cout <<
"Nmu after stage 7: " << migrad.Value(
"Nmu") << endl;
1573 cout <<
"Zenith after stage 7: " << migrad.Value(
"theta") << endl;
1574 cout <<
"RelCoreTime after stage 7: " << migrad.Value(
"relCoreTime") << endl;
1597 min =
new FunctionMinimum(migrad(maxSteps,
fMigradTol));
1609 "No convergence according to Minuit. Fixing the core position and running again."
1611 migrad.Fix(
"coreX");
1612 migrad.Fix(
"coreY");
1621 cout <<
"\n\n### calculating hesse matrix\n" << endl;
1625 hesse(migrad.Fcnbase(), *min, maxSteps);
1627 hesseOk = !min->HesseFailed();
1629 const MnUserParameterState& us = min->UserState();
1631 if (fVerbosityLevel > 1)
1632 cout << min->UserCovariance() << endl;
1672 (*fFunc)(us.Params());
1680 (*fFunc)(upar.Params());
1686 return fitOk && hesseOk;
1693 const MnUserParameterState& us = min.UserState();
1694 if (!min.IsValid() || !us.IsValid() || min.IsAboveMaxEdm() || min.HasReachedCallLimit())
1697 const vector<double>& pars = us.Params();
1698 for (
unsigned int i = 0; i < pars.size(); ++i) {
1699 if (std::isnan(pars[i]))
1710 const double eoutsc = 1e18;
1714 cout << format(
"E/eV") << endl;
1716 cout << format(
" MC %.2f * 10^%i") % (
mcPars.
energy / eoutsc) % log10(eoutsc) << endl;
1717 cout << format(
" init %.2f * 10^%i") % (
initPars.
energy / eoutsc) % log10(eoutsc) << endl;
1724 cout <<
"Nmu" << endl;
1726 cout << format(
" MC %.2f") % (
mcPars.
Nmu) << endl;
1727 cout << format(
" init %.2f") % (
initPars.
Nmu) << endl;
1737 cout <<
"xmax/gcm^-2" << endl;
1751 cout <<
"x0/gcm^-2" << endl;
1762 cout <<
"core (site) " << endl;
1776 cout <<
"core time " << endl;
1792 cout <<
"axis (site)" << endl;
1799 cout << format(
" fit theta %.2f ± %.2f, phi %.2f ± %.2f")
1807 cout <<
"TimeModelOffset (dM_mu)" << endl;
1811 cout <<
"fixed to calibrated value (see code)!";
1820 <<
"likelihood contributions:" << endl
1821 <<
"id ldf shape time" << endl;
1823 for (std::vector<StationFitData>::iterator sIt =
fitData.begin(); sIt !=
fitData.end(); ++sIt) {
1824 if (!(sIt->useForLDFFit || sIt->useForShapeFit || sIt->useForStartTimeFit))
continue;
1825 cout << format(
"%i %.3f %.3f %.3f") % sIt->stationId
1826 % sIt->LDFLikelihood % sIt->ShapeLikelihood
1827 % sIt->StartTimeLikelihood << endl;
std::vector< double > fFittedMinuitParams
void initTimeModel(const unsigned int version)
double Factor(const double energyEM, const EInteractionModel intMod, const ECompositionModel compMod, const double cosTheta)
invisible energy factor, finv=Etot/Eem, given Eem. CosTheta only needed when using data driven estima...
void setupMinuit(ROOT::Minuit2::MnUserParameters &upar)
double NormalizeAngleMinusPiPi(const double x)
Normalize angle to lie between -pi and pi (-180 and 180 deg)
constexpr T Sqr(const T &x)
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
utl::CoordinateSystemPtr fSiteCS
double getDistToFirstInteraction(double hfi, double sHeight, double zenith, double dist, double psi)
double RelativeTrackLength(const double cosTheta)
double ModelFactor(const EInteractionModel interaction, const ECompositionModel composition)
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Class to hold and convert a point in geodetic coordinates.
double getMeanParametrizedXmaxData(double loge)
utl::CoordinateSystemPtr showerCS
void addStationFitData(const StationFitData &sdata)
double operator()(const std::vector< double > &pars) const
int fMinBinsAboveShapeFitLimit
std::vector< UnivTimeKG::TimeModel * > timeModels
std::unique_ptr< UnivParamTimeNS::UnivParamTime > fUnivParamTime
double ConvertToMCEnergyScale(const double sdenergy)
vector< t2list > out
output of the algorithm: a list of clusters
double pow(const double x, const unsigned int i)
double fUpperRadiusCutShape
std::unique_ptr< FitFunction > fFunc
A TimeStamp holds GPS second and nanosecond for some event.
fitConstraint fXmaxConstraint
bool TimeModelOffsetFixed
minScan2D scanMinimum2D(const int parIndexx, const int parIndexy, const double valx, const double valy, const double deltaX, const double deltaY, const int nSteps)
double fUpperRadiusCutTime
double operator()(const std::vector< double > &pars) const
double fLowerRadiusCutShape
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
double getX0(int version, double xmax, double loge)
double fLowerRadiusCutLDF
Reference ellipsoids for UTM transformations.
double operator()(const std::vector< double > &pars) const
double getMeanParametrizedXmax(double loge)
bool doSaturatedStartTimeFit
double GetX(const CoordinateSystemPtr &coordinateSystem) const
void setRecType(const unsigned int type)
double getFirstParticleArrivalTime(double r, double dx0)
constexpr double nanosecond
std::unique_ptr< WCDFitFunction > fWCDFunc
double getMeanParametrizedNmuData(double loge, double theta)
minScan1D scanMinimum1D(const int parIndex, const double val, const double delta, const int nSteps)
double GetMeanMuonOffsetDataCalibrated(double r, double lgE, double theta)
double fStartTimeLikelihood
double Beta(const double energy)
Calculate the electron energy versus the relativistic beta.
bool smearFirstParticlePdf
bool fOnlySignalLikelihood
double getMeanXmaxBias(double loge, double theta, bool saturated)
double PlaneFrontTime(const CoordinateSystemPtr showerCS, const Point &corePosition, const Point &position)
Calculate time of arrival of the plan front at point x.
fitConstraint fCoreTimeConstraint
double fMaxBinContentForSatShapeFit
utl::CoordinateSystemPtr coreCS
double fLowerRadiusCutTime
double GetMeanMuonOffset(double r, double offset0)
double GetY(const CoordinateSystemPtr &coordinateSystem) const
constexpr double kSpeedOfLight
FitFunction(const Fitter &theEf)
bool isLDFFitCandidate(const int stationId)
double fMinBinContentForSatShapeFit
StationFitData & getStationFitData(const int stationId)
unsigned long GetGPSSecond() const
GPS second.
double fUpperRadiusCutLDF
double GetGPSNanoSecond() const
GPS nanosecond.
bool isCandidateStation(const int stationId)
bool addMuonLDFConstraint
double operator()(const std::vector< double > &pars) const
const double * FitParameters(const ECompositionModel composition)
double OldSmoothPoissonFactor(const double sigmaFactor)
fitConstraint fCoreConstraint
std::unique_ptr< UnivParamNS::UnivParam > fUnivParam
std::unique_ptr< UnivCalibConstantsNS::UnivCalibConstants > fUnivCalibConstants
std::vector< double > fStartTime
double MCEnergyCalibration(const double showerSize, const double theta, bool isInfill)
double RelativeTrackLength(const double cosTheta)
double fMinBinContentForShapeFit
double SignalUncertaintyFactor(const ESignalVarianceModel model, const double cosTheta)
fitConstraint fThetaConstraint
static double getAngle(const utl::Vector &v1, const utl::Vector &v2)
bool addRecovSignalConstraint
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
fitConstraint fX0Constraint
std::unique_ptr< AtmosphereNS::Atmosphere > fAtmosphere
double PlaneFrontTime(const CoordinateSystemPtr showerCS, const Point &corePosition, const Point &position)
utl::CoordinateSystemPtr fHottestStationCS
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
bool fApplyXmaxBiasCorrection
double GetMeanMuonOffsetMCCalibrated(double, double, double)
double LogarithmOfNormalPDF(const double x)
std::vector< StationFitData > fitData
fitConstraint fPhiConstraint
fitConstraint fEnergyConstraint
bool isFitOk(const ROOT::Minuit2::FunctionMinimum &min)
std::vector< double > fLDF
utl::CoordinateSystemPtr fBaryCS
double PoissonFactor(const double sigmaFactor)
double TimeModelOffsetUnc
double fMaxBinContentForShapeFit
std::vector< double > fShape
bool isStartTimeFitCandidate(const int stationId)
bool isShapeFitCandidate(const int stationId)