28 return (lgE - log10(pCal[0])) / pCal[1];
32 return 0.5 * (1 + TMath::Erf((x - pars[0] ) / pars[1]));
40 const double thmax =
mapParameters[
"MaxZenith"] * TMath::DegToRad();
41 const double thmin = 0.;
42 const double thStep = 0.0005;
43 double integralTheta = 0;
47 for (
double thIntegr = thmin; thIntegr < thmax; thIntegr += thStep) {
57 double fnorm = 0.5 * (
pow(TMath::Sin(thmax), 2) -
pow(TMath::Sin(thmin), 2));
58 return integralTheta / fnorm;
63 double efficiency = 1;
80 cerr <<
EfficiencyFlag <<
": no valid efficiency parameterization chosen " << endl;
81 throw std::exception();
88 double efficiency = 1;
100 cerr <<
EfficiencyFlag <<
": no valid efficiency parameterization chosen " << endl;
101 throw std::exception();
112 int ncol = lgEs.GetNoElements();
113 TVectorD biasEnergy(ncol);
115 for (
int i = 0; i < ncol; ++i) {
116 if (
BiasFlag ==
"BiasICRC19_SD1500_preliminary") {
118 double integral = 0.;
119 double deltacos2theta = 0.001;
120 for (Double_t cos2theta = 0.25; cos2theta < 1; cos2theta += deltacos2theta) {
121 double costheta =
sqrt(cos2theta);
129 biasEnergy[i] = integral;
130 }
else if (
BiasFlag ==
"BiasICRC19_SD1500_Offline") {
132 double integral = 0.;
133 double deltacos2theta = 0.001;
134 for (Double_t cos2theta = 0.25; cos2theta < 1; cos2theta += deltacos2theta) {
135 double costheta =
sqrt(cos2theta);
143 biasEnergy[i] = integral;
144 }
else if (
BiasFlag ==
"BiasICRC19_SD1500_Herald") {
146 double integral = 0.;
147 double deltacos2theta = 0.001;
148 for (Double_t cos2theta = 0.25; cos2theta < 1; cos2theta += deltacos2theta) {
149 double costheta =
sqrt(cos2theta);
157 biasEnergy[i] = integral;
158 }
else if (
BiasFlag ==
"BiasICRC19_SD750") {
159 const double fdB = pCal[1];
161 }
else if (
BiasFlag ==
"Bias_TestExample") {
169 cerr <<
BiasFlag <<
": no valid bias parameterization chosen " << endl;
170 throw std::exception();
179 if (
BiasFlag ==
"BiasICRC19_SD1500_preliminary")
181 else if (
BiasFlag ==
"BiasICRC19_SD1500_Offline")
183 else if (
BiasFlag ==
"BiasICRC19_SD1500_Herald")
185 else if (
BiasFlag ==
"BiasICRC19_SD750")
187 const double fdB = pCal[1];
190 else if (
BiasFlag ==
"Bias_TestExample")
196 cerr <<
BiasFlag <<
": no valid bias parameterization chosen " << endl;
197 throw std::exception();
209 const double xmin = 16.5;
210 const double xmax = 20.5;
211 const double z = (lgE - xmin) / (xmax - xmin);
212 const double pars[2] = {0.2, 0.0783};
213 shsh = (1 - z) * pars[0] + z * pars[1];
220 cerr <<
ShowerToShowerFlag <<
": no valid shower to shower parameterization chosen " << endl;
221 throw std::exception();
258 cerr <<
ResolutionFlag <<
": no valid resolution parameterization chosen " << endl;
259 throw std::exception();
266 const double thmax =
mapParameters[
"MaxZenith"] * TMath::DegToRad();
267 const double thmin = 0.;
268 const double thStep = 0.0005;
269 double integralTheta = 0;
270 for (
double thIntegr = thmin; thIntegr < thmax; thIntegr += thStep) {
271 integralTheta +=
ResolutionZenithDistrib(lgE, thIntegr) * thStep * TMath::Cos(thIntegr) * TMath::Sin(thIntegr);
273 double fnorm = 0.5 * (
pow(TMath::Sin(thmax), 2) -
pow(TMath::Sin(thmin), 2));
274 return integralTheta / fnorm;
278 int ncol = lgEs.GetNoElements();
279 TVectorD EnergyRes(ncol);
281 for (
int i = 0; i < ncol; ++i) {
282 double lgE = lgEs[i];
283 double Esd =
pow(10., lgE);
289 double relErrs = TMath::Sqrt(
pow(relErrs1, 2) +
pow(relErrs2, 2));
291 EnergyRes[i] = relErrs * Esd;
301 double resolution = 0;
326 cerr <<
ResolutionFlag <<
": no valid resolution parameterization chosen " << endl;
327 throw std::exception();
335 int N = xos.GetNoElements();
338 TMatrixD tmp_kmatrix(N, N);
339 for (
int j = 0; j < N; ++j) {
340 double ex =
pow(10, xos[j]);
343 for (
int i = 0; i < N; ++i) {
344 double ey =
pow(10, xos[i]);
345 tmp_kmatrix[i][j] = TMath::Gaus(ey, ex * Ebias[j], ses[j],
true) * ey * log(10.) * efficiency;
362 TMatrixD
kResolutionMatrixDD(TVectorD pCal, TVectorD xos, Double_t lat, Double_t deltaMin, Double_t deltaMax) {
363 Int_t diagonalOfMatrix = 40;
366 cout <<
"Declination dependent migration matrix" << endl;
367 cout <<
"Calculates only +-" << diagonalOfMatrix <<
" elements out of " << xos.GetNoElements() <<
"around diagonal to speed up calculation! " << endl;
368 Double_t deltah = 0.1;
369 Double_t deltadelta = 0.1;
370 int N = xos.GetNoElements();
371 TMatrixD tmp_kmatrixDD(N, N);
372 TMatrixD tmp_kmatrixDD_norm(N, N);
373 for (
int i = 0; i < N; ++i)
374 for (
int j = 0; j < N; ++j) {
375 tmp_kmatrixDD_norm[i][j] = 0.;
376 tmp_kmatrixDD[i][j] = 0.;
379 for (
int i = 0; i < N; ++i) {
380 double ey =
pow(10, xos[i]);
381 for (
int j = 0; j < N; ++j) {
382 double ex =
pow(10, xos[j]);
383 if (fabs(i - j) < diagonalOfMatrix)
384 for (Double_t h = 0; h < 2.*TMath::Pi(); h += deltah) {
385 for (Double_t delta = deltaMin; delta < deltaMax; delta += deltadelta) {
386 Double_t cosTheta = sin(lat) * sin(delta) + cos(lat) * cos(delta) * cos(h);
390 double tot_sigma =
sqrt(
pow(resolution, 2) +
pow(sh_shfluct, 2));
394 if (acos(cosTheta) <
mapParameters[
"MaxZenith"] * TMath::DegToRad() && acos(cosTheta) > 0.) {
395 tmp_kmatrixDD_norm[i][j] += deltah * deltadelta * cos (delta) * cosTheta;
396 tmp_kmatrixDD[i][j] += deltah * deltadelta * cos (delta) * cosTheta * efficiency * TMath::Gaus(ey, ex * bias , tot_sigma * ex,
true) * ey * log(10.);
400 if (tmp_kmatrixDD_norm[i][j] > 0)
401 tmp_kmatrixDD[i][j] /= tmp_kmatrixDD_norm[i][j];
416 return tmp_kmatrixDD;
420 Double_t deltah = 0.001;
421 Double_t deltadelta = 0.00001;
423 const double tilt = -30 * TMath::DegToRad();
426 for (Double_t delta = deltaMin; delta < deltaMax; delta += deltadelta) {
427 for (Double_t h = 0; h < 2.*TMath::Pi(); h += deltah) {
428 Double_t cosTheta = sin(lat) * sin(delta) + cos(lat) * cos(delta) * cos(h);
429 Double_t theta = acos(cosTheta);
430 if (acos(cosTheta) <
mapParameters[
"MaxZenith"]* TMath::DegToRad() && acos(cosTheta) > 0.) {
431 double phi = atan2(sin(delta) * cos(lat) - cos(delta) * cos(h) * sin(lat), cos(delta) * sin(h));
432 exposure += deltah * deltadelta * cos(delta) * cosTheta * (1 + 0.00348 * tan(theta) * cos(phi - tilt));
435 if(countDelta%10000000==0)
436 cout<<
"Exposure calculation step "<<countDelta<<endl;
441 cout <<
" Exposure " <<
mapParameters[
"Exposure"] * exposure / 2.35718 <<
"km2 sr yr" << endl;
446 cerr <<
"\n---------------------------------------------------\n";
447 cerr <<
"------------------Parameter Map--------------------\n";
448 cerr <<
"---------------------------------------------------\n";
450 std::map<string, Double_t>::iterator it =
mapParameters.begin();
452 std::string keyName = it->first;
453 double val = it->second;
454 cout << keyName <<
" :: " << val << endl;
458 cout <<
"Model---------------------" <<
Model << endl;
461 cout <<
"BiasFlag------------------" <<
BiasFlag << endl;
464 cout <<
"VersionInput--------------" <<
VersionInput << endl;
466 cerr <<
"---------------------------------------------------\n";
467 cerr <<
"---------------------------------------------------\n";
472 in.open(paramFileName.c_str());
473 string paramString, line;
477 Int_t pos = line.find(
'#');
478 string lineNew = line.substr(0, pos);
479 if (lineNew.length()) {
480 Int_t pos2 = lineNew.find(
' ');
481 string key = lineNew.substr(0, pos2);
483 string lineNew2 = lineNew.substr(pos2, 1000);
484 Int_t posVal = lineNew2.find_first_not_of(
' ');
485 string lineNew3 = lineNew2.substr(posVal, 1000);
486 Int_t posVal2 = lineNew3.find(
' ');
487 string val = lineNew3.substr(0, posVal2);
492 }
else if (key ==
"DataFileName") {
494 }
else if (key ==
"OutPutFileName") {
496 }
else if (key ==
"OutPutFileNameRebinned") {
498 }
else if (key ==
"ModelFunction") {
500 }
else if (key ==
"DeclinationDepentMatrix") {
502 }
else if (key ==
"ResolutionFlag") {
504 }
else if (key ==
"BiasFlag") {
506 }
else if (key ==
"EfficiencyFlag") {
508 }
else if (key ==
"ShowerToShowerFlag") {
510 }
else if (key ==
"VersionInput") {
512 }
else if (key ==
"UseNewTriggers") {
514 }
else if (key ==
"Verbose") {
517 istringstream stringstream(val.c_str());
518 stringstream >> tmpVal;
535 double lgE, S1000, dS1000, theta, phi, dec, ra;
537 string labelA, labelB;
546 evtFile.open(FileName.c_str(), ios::in);
547 if (evtFile.fail()) {
549 cerr << FileName <<
": no valid file name chosen " << endl;
550 throw std::exception();
554 getline(evtFile, headerline);
555 headerline = headerline.substr(0, 1);
556 evtFile >> labelA >> A;
557 evtFile >> labelB >> B;
558 if (headerline !=
"#" || labelA !=
"A" || labelB !=
"B") {
560 cerr << FileName <<
" does not look to be formatted properly " << endl;
561 cerr <<
"Add header line and calibration parameters" << endl;
562 throw std::exception();
574 while (!evtFile.eof()) {
576 evtFile >> AugerId >> EventId >> lgE >> S1000 >> dS1000 >> nst >> theta >> phi >> dec >> ra;
579 lgE = log10(lgE) + 18;
581 if (!evtFile.eof()) {
582 if (dec < maxDecl && dec > minDecl) {
599 double lgE, S1000, dS1000, theta, dtheta, phi, dphi, dec, ra, XCore, YCore, S1000_corr, S38, Nst, Nst_sat;
601 string labelA, labelB;
609 evtFile.open(FileName.c_str(), ios::in);
610 if (evtFile.fail()) {
612 cerr << FileName <<
": no valid file name chosen " << endl;
613 throw std::exception();
616 getline(evtFile, headerline);
617 headerline = headerline.substr(0, 1);
618 evtFile >> labelA >> A;
619 evtFile >> labelB >> B;
620 if (headerline !=
"#" || labelA !=
"A" || labelB !=
"B") {
622 cerr << FileName <<
" does not look to be formatted properly " << endl;
623 cerr <<
"Add header line and calibration parameters" << endl;
624 throw std::exception();
637 while (!evtFile.eof()) {
639 evtFile >> AugerId >> EventId >> GPSTime >> isHybrid >> Nst >> Nst_sat >> lgE >> theta >> dtheta >> phi >> dphi >> XCore >> YCore >> ra >> dec >> S1000 >> dS1000 >> S1000_corr >> S38;
642 if (!evtFile.eof()) {
643 if (dec < maxDecl && dec > minDecl) {
656 evtFile.open(inputName.c_str(), ios::in);
657 stringstream testString;
658 getline(evtFile, headerline);
659 getline(evtFile, headerline);
660 getline(evtFile, headerline);
661 getline(evtFile, headerline);
662 testString << headerline;
667 while (testString >> x) {
672 cout << countCol <<
" columns in the input event file" << endl;
674 cout <<
"Check consistency with... " << endl;
675 if (flagversion == 1)
676 cout <<
"evtFile >> AugerId >> EventId >> GPSTime>> isHybrid>> Nst>> Nst_sat >> lgE >> theta >> dtheta >> phi >> dphi >> XCore >> YCore >> ra>> dec >> S1000 >> dS1000 >> S1000_corr >> S38;" << endl;
677 if (flagversion == 0)
678 cout <<
"evtFile >> AugerId >> EventId >> lgE >> S1000 >> dS1000 >> nst >> theta >> phi >> dec >> ra;" << endl;
684 cerr <<
"The correct number of inputs were not found " << endl;
685 cerr <<
"Expected 2 and got " << nArgs << endl;
686 cerr <<
"Run this program as ./UnfoldSpectrum <parameter file>" << endl;
double SDTriggerEfficiency_AveragedZenithAngle(const double lgE)
double SD1500TriggerEfficiencyHybrids2019(const double lgE)
void PrintUsage(int nArgs)
string OutPutFileNameRebinned
string ShowerToShowerFlag
double ResolutionValue(double lgE, double_t cosTheta)
const bool HeraldAnalysis
TMatrixD kResolutionMatrixDD(TVectorD pCal, TVectorD xos, Double_t lat, Double_t deltaMin, Double_t deltaMax)
TVectorD EnergyResolution(TVectorD lgEs, const bool data, const bool infill)
void PrintMapParameters()
double ResolutionZenithDistrib(double *x, double *par)
double Hybrids_ICRC_2019_SD1500(const double lgE)
double EfficiencyValuesNoDeclDep(double lgE)
TVectorD GetSDCalPars(bool infill=false)
double SD1500TriggerEfficiency_ICRC2019(const double lgE, const double zenith)
void TestFormat(string, int)
double DataSD750EnergyResolution_ICRC2017(const double lgE, const double zenith, TVectorD pCal, double lgS35)
double pow(const double x, const unsigned int i)
double EfficiencyValues(double lgE, double zenith)
double Hybrids_ICRC_2019_SD750(const double lgE)
double HybridBias_2019_11_06_Herald_SD1500(double ESD, double coszenith, double maxZenith)
void LoadParam(string paramFileName)
double HybridBias_2019_11_06_Offline_SD1500(double ESD, double coszenith, double maxZenith)
double IntegrateEnergyResolution(const double lgE, const bool data, const bool infill)
double DataSD1500EnergyResolution(const double lgE, const double zenith)
map< string, Double_t > mapParameters
double HybridBias_2019_SD750(double lgE, double fdB)
double SDTriggerEfficiencyICRC2017_SD750(const double lgE, const double zenith, TVectorD pCal)
double SimulationSD1500EnergyResolution(const double lgE, const double zenith)
double InverseSdCalibration(const double lgE, TVectorD pCal)
double EnergyBias_DD(double lgE, double cosTheta, TVectorD pCal)
double SDTriggerEfficiencyICRC2017_SD1500(const double lgE, const double zenith, TVectorD pCal)
TVectorD EnergyBias(TVectorD lgEs, TVectorD pCal, const bool infill)
double ScaledErrorFunction(const double x, const std::vector< double > &pars)
double ShowerToShowerFluctuation(const double lgE)
void ReadEventListICRC2019(TH1D *th1, TH1D *th2, string FileName)
string DeclinationDepentMatrix
double SimulationSD750EnergyResolution_ICRC2017(const double lgE, const double zenith)
void ReadEventList(TH1D *th1, TH1D *th2, string FileName)
TMatrixD kResolutionMatrix(TVectorD pCal, TVectorD xos, double *resolutionOffset, const bool useResFromData, const bool infill)
double Valerio12_11_2018(const double lgE)
Double_t DirectionalExposure(Double_t lat, Double_t deltaMin, Double_t deltaMax)
double HybridBias_2019_SD1500(double ESD, double coszenith, double maxZenith)
double Hybrids_ICRC_2019_Offline_05_07(const double lgE)
double Resolution_TestExample(const double lgE)
double Hybrids_ICRC_2019_Herald_11_06(const double lgE)
double Hybrids_ICRC_2019_Offline_11_06(const double lgE)
double Bias_TestExample(double ESD, double coszenith)
double TriggerEfficiency_TestExample(const double lgE)
double SDTriggerEfficiencyICRC2019_SD750(const double lgE, const double zenith, TVectorD pCal, bool oldTrig)