ICRC2019/UnfoldUtilities.hh
Go to the documentation of this file.
1 /* Utilities to unfold the vertical spectrum such as done for ICRC 2015 */
2 
3 /* Author: I. ValiƱo, based on functions provided by A. Schulz */
4 
5 string CodeUsed;
6 map <string, Double_t> mapParameters;
7 string Verbose = "no";
8 string SDFile;
11 string Model;
14 string BiasFlag;
17 string VersionInput = "standard";
18 string UseNewTriggers = "no";
19 TVectorD GetSDCalPars() {
20  //Calibration constants
21  TVectorD pCal(2);
22  pCal[0] = mapParameters["A"];
23  pCal[1] = mapParameters["B"];
24  return pCal;
25 }
26 
27 double InverseSdCalibration(const double lgE, TVectorD pCal) {
28  return (lgE - log10(pCal[0])) / pCal[1]; /* returns lgS38 or lgS35 */
29 }
30 
31 double ScaledErrorFunction(const double x, const std::vector<double>& pars) {
32  return 0.5 * (1 + TMath::Erf((x - pars[0] ) / pars[1]));
33 }
34 
36 // TRIGGER EFFICIENCY
38 double SDTriggerEfficiency_AveragedZenithAngle(const double lgE) {
39 //The functions can be used integrated in zenith angle
40  const double thmax = mapParameters["MaxZenith"] * TMath::DegToRad();
41  const double thmin = 0.;
42  const double thStep = 0.0005; //0.0005 delivers a result consistent with root methods within 0.01%.
43  double integralTheta = 0;
44  const TVectorD pCal = GetSDCalPars();
45  const bool oldTrig = ("no" == UseNewTriggers);
46 
47  for (double thIntegr = thmin; thIntegr < thmax; thIntegr += thStep) {
48  if (EfficiencyFlag == "ICRC17_SD1500")
49  integralTheta += SDTriggerEfficiencyICRC2017_SD1500(lgE, thIntegr, pCal) * thStep * TMath::Cos(thIntegr) * TMath::Sin(thIntegr);
50  if (EfficiencyFlag == "ICRC17_SD750")
51  integralTheta += SDTriggerEfficiencyICRC2017_SD750(lgE, thIntegr, pCal) * thStep * TMath::Cos(thIntegr) * TMath::Sin(thIntegr);
52  if (EfficiencyFlag == "ICRC19_SD750")
53  integralTheta += SDTriggerEfficiencyICRC2019_SD750(lgE, thIntegr, pCal, oldTrig) * thStep * TMath::Cos(thIntegr) * TMath::Sin(thIntegr);
54  if (EfficiencyFlag == "ICRC19_SD1500_June2019")
55  integralTheta += SD1500TriggerEfficiency_ICRC2019(lgE, thIntegr) * thStep * TMath::Cos(thIntegr) * TMath::Sin(thIntegr);
56  }
57  double fnorm = 0.5 * (pow(TMath::Sin(thmax), 2) - pow(TMath::Sin(thmin), 2));
58  return integralTheta / fnorm;
59 }
60 
61 double EfficiencyValues(double lgE, double zenith) {
62  const TVectorD pCal = GetSDCalPars();
63  double efficiency = 1;
64  const bool oldTrig = ("no" == UseNewTriggers);
65 
66  if (EfficiencyFlag == "ICRC17_SD1500")
67  efficiency = SDTriggerEfficiencyICRC2017_SD1500(lgE, zenith, pCal);
68  else if (EfficiencyFlag == "ICRC17_SD750")
69  efficiency = SDTriggerEfficiencyICRC2017_SD750(lgE, zenith, pCal);
70  else if (EfficiencyFlag == "ICRC19_SD1500_May2019")
71  efficiency = SD1500TriggerEfficiencyHybrids2019(lgE);
72  else if (EfficiencyFlag == "ICRC19_SD1500_June2019")
73  efficiency = SD1500TriggerEfficiency_ICRC2019(lgE, zenith);
74  else if (EfficiencyFlag == "ICRC19_SD750")
75  efficiency = SDTriggerEfficiencyICRC2019_SD750(lgE, zenith, pCal, oldTrig);
76  else if ( EfficiencyFlag == "TriggerEfficiency_TestExample" )
77  efficiency = TriggerEfficiency_TestExample(lgE);
78  else {
79  cerr << endl;
80  cerr << EfficiencyFlag << ": no valid efficiency parameterization chosen " << endl;
81  throw std::exception();
82  }
83  return efficiency;
84 }
85 
86 double EfficiencyValuesNoDeclDep(double lgE) {
87  //If values are zenith angle dependent average over the entire zenith angle range
88  double efficiency = 1;
89  if (EfficiencyFlag == "ICRC17_SD1500" ||
90  EfficiencyFlag == "ICRC17_SD750" ||
91  EfficiencyFlag == "ICRC19_SD1500_June2019" ||
92  EfficiencyFlag == "ICRC19_SD750")
94  else if (EfficiencyFlag == "ICRC19_SD1500_May2019")
95  efficiency = SD1500TriggerEfficiencyHybrids2019(lgE);
96  else if ( EfficiencyFlag == "TriggerEfficiency_TestExample" )
97  efficiency = TriggerEfficiency_TestExample(lgE);
98  else {
99  cerr << endl;
100  cerr << EfficiencyFlag << ": no valid efficiency parameterization chosen " << endl;
101  throw std::exception();
102  }
103 
104  return efficiency;
105 }
106 
108 // BIAS
110 TVectorD EnergyBias(TVectorD lgEs, TVectorD pCal) {
111  //used by the non-declination dependent matrix calculation
112  int ncol = lgEs.GetNoElements();
113  TVectorD biasEnergy(ncol);
114 
115  for (int i = 0; i < ncol; ++i) {
116  if (BiasFlag == "BiasICRC19_SD1500_preliminary") {
117  //calculates the average over cos2theta of bias for each energy
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);
122  integral += (HybridBias_2019_SD1500(lgEs[i], costheta, mapParameters["MaxZenith"]) - 1.) * deltacos2theta;
123  }
124  integral /= 0.75; //normalization
125  integral += 1.;
126 
127  if ( lgEs[i] > 18.4)
128  integral = 1.;
129  biasEnergy[i] = integral;
130  } else if (BiasFlag == "BiasICRC19_SD1500_Offline") {
131  //calculates the average over cos2theta of bias for each energy
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);
136  integral += (HybridBias_2019_11_06_Offline_SD1500(lgEs[i], costheta, mapParameters["MaxZenith"]) - 1.) * deltacos2theta;
137  }
138  integral /= 0.75; //normalization
139  integral += 1.;
140 
141  if ( lgEs[i] > 18.4)
142  integral = 1.;
143  biasEnergy[i] = integral;
144  } else if (BiasFlag == "BiasICRC19_SD1500_Herald") {
145  //calculates the average over cos2theta of bias for each energy
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);
150  integral += (HybridBias_2019_11_06_Herald_SD1500(lgEs[i], costheta, mapParameters["MaxZenith"]) - 1.) * deltacos2theta;
151  }
152  integral /= 0.75; //normalization
153  integral += 1.;
154 
155  if ( lgEs[i] > 18.4)
156  integral = 1.;
157  biasEnergy[i] = integral;
158  } else if (BiasFlag == "BiasICRC19_SD750") {
159  const double fdB = pCal[1];
160  biasEnergy[i] = HybridBias_2019_SD750(lgEs[i], fdB);
161  } else if (BiasFlag == "Bias_TestExample") {
162  //something...
163  //......
164  biasEnergy[i] = 1.;
165  } else if (BiasFlag == "TOZERO")
166  biasEnergy[i] = 1.;
167  else {
168  cerr << endl;
169  cerr << BiasFlag << ": no valid bias parameterization chosen " << endl;
170  throw std::exception();
171  }
172  }
173 
174  return biasEnergy;
175 }
176 
177 double EnergyBias_DD(double lgE, double cosTheta, TVectorD pCal) {
178  double bias = 1;
179  if (BiasFlag == "BiasICRC19_SD1500_preliminary")
180  bias = HybridBias_2019_SD1500(lgE, cosTheta, mapParameters["MaxZenith"]);
181  else if (BiasFlag == "BiasICRC19_SD1500_Offline")
182  bias = HybridBias_2019_11_06_Offline_SD1500(lgE, cosTheta, mapParameters["MaxZenith"]);
183  else if (BiasFlag == "BiasICRC19_SD1500_Herald")
184  bias = HybridBias_2019_11_06_Herald_SD1500(lgE, cosTheta, mapParameters["MaxZenith"]);
185  else if (BiasFlag == "BiasICRC19_SD750")
186  {
187  const double fdB = pCal[1];
188  bias = HybridBias_2019_SD750(lgE, fdB);
189  }
190  else if (BiasFlag == "Bias_TestExample")
191  bias = Bias_TestExample(lgE, cosTheta);
192  else if (BiasFlag == "TOZERO")
193  bias = 1;
194  else {
195  cerr << endl;
196  cerr << BiasFlag << ": no valid bias parameterization chosen " << endl;
197  throw std::exception();
198  }
199 
200  return bias;
201 }
202 
204 // SHOWER TO SHOWER FLUCTUATIONS
206 double ShowerToShowerFluctuation(const double lgE) {
207  double shsh = 0;
208  if (ShowerToShowerFlag == "ICRC17_SD1500Data") {
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];
214  } else if (ShowerToShowerFlag == "ICRC17_SD750Data")
215  shsh = 0.13;
216  else if (ShowerToShowerFlag == "TOZERO")
217  shsh = 0;
218  else {
219  cerr << endl;
220  cerr << ShowerToShowerFlag << ": no valid shower to shower parameterization chosen " << endl;
221  throw std::exception();
222  }
223  return shsh;
224 }
225 
227 // RESOLUTION
229 double ResolutionZenithDistrib(double lgE, double zenith) {
230  TVectorD pCal = GetSDCalPars();//only for data resolution
231  const double lgS38 = InverseSdCalibration(lgE, pCal);
232 
233  double res;
234  if (ResolutionFlag == "ICRC17_SD750Data")
235  res = DataSD750EnergyResolution_ICRC2017(lgE, zenith, pCal, lgS38);
236  else if (ResolutionFlag == "ICRC17_SD1500Data")
237  res = DataSD1500EnergyResolution(lgE, zenith, pCal, lgS38);
238  else if (ResolutionFlag == "ICRC17_SD750Simu")
239  res = SimulationSD750EnergyResolution_ICRC2017(lgE, zenith);
240  else if (ResolutionFlag == "ICRC17_SD1500Simu") //Zenith angle independent... Not necessary here in the zenith integration
241  res = SimulationSD1500EnergyResolution(lgE, zenith);
242  else if (ResolutionFlag == "Valerio12_11_2018")
243  res = Valerio12_11_2018(lgE);
244  else if (ResolutionFlag == "Hybrids_ICRC_2019_preliminary") //Zenith angle independent... Not necessary here in the zenith integration
245  res = Hybrids_ICRC_2019_SD1500(lgE);
246  else if (ResolutionFlag == "Hybrids_ICRC_2019_SD750")
247  res = Hybrids_ICRC_2019_SD750(lgE);
248  else if (ResolutionFlag == "Hybrids_ICRC_2019_Offline")
250  else if (ResolutionFlag == "Hybrids_ICRC_2019_Offline_05_07")
252  else if (ResolutionFlag == "Hybrids_ICRC_2019_Herald")
254  else if (ResolutionFlag == "Resolution_TestExample") //Zenith angle independent... Not necessary here in the zenith integration
255  res = Resolution_TestExample(lgE);
256  else {
257  cerr << endl;
258  cerr << ResolutionFlag << ": no valid resolution parameterization chosen " << endl;
259  throw std::exception();
260  }
261 
262  return res;
263 }
264 
265 double IntegrateEnergyResolution(const double lgE) {
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);
272  }
273  double fnorm = 0.5 * (pow(TMath::Sin(thmax), 2) - pow(TMath::Sin(thmin), 2));
274  return integralTheta / fnorm;
275 }
276 
277 TVectorD EnergyResolution(TVectorD lgEs) {
278  int ncol = lgEs.GetNoElements();
279  TVectorD EnergyRes(ncol);
280 
281  for (int i = 0; i < ncol; ++i) {
282  double lgE = lgEs[i];
283  double Esd = pow(10., lgE);
284 
285  double relErrs1 = IntegrateEnergyResolution(lgE);
286  double relErrs2 = 0;
287  relErrs2 = ShowerToShowerFluctuation(lgE);
288 
289  double relErrs = TMath::Sqrt(pow(relErrs1, 2) + pow(relErrs2, 2));
290 
291  EnergyRes[i] = relErrs * Esd;
292  }
293 
294  return EnergyRes;
295 }
296 
297 double ResolutionValue(double lgE, double_t cosTheta) {
298  TVectorD pCal = GetSDCalPars();//only for data resolution
299  const double lgS38 = InverseSdCalibration(lgE, pCal);
300 
301  double resolution = 0;
302  if (ResolutionFlag == "ICRC17_SD1500Data")
303  resolution = DataSD1500EnergyResolution(lgE, acos(cosTheta), pCal, lgS38);
304  else if (ResolutionFlag == "ICRC17_SD750Data")
305  resolution = DataSD750EnergyResolution_ICRC2017(lgE, acos(cosTheta), pCal, lgS38);
306  else if (ResolutionFlag == "ICRC17_SD1500Simu")
307  resolution = SimulationSD1500EnergyResolution(lgE, acos(cosTheta));
308  else if (ResolutionFlag == "ICRC17_SD750Simu")
309  resolution = SimulationSD750EnergyResolution_ICRC2017(lgE, acos(cosTheta));
310  else if (ResolutionFlag == "Valerio12_11_2018")
311  resolution = Valerio12_11_2018(lgE);
312  else if (ResolutionFlag == "Hybrids_ICRC_2019_preliminary")
313  resolution = Hybrids_ICRC_2019_SD1500(lgE);
314  else if (ResolutionFlag == "Hybrids_ICRC_2019_SD750")
315  resolution = Hybrids_ICRC_2019_SD750(lgE);
316  else if (ResolutionFlag == "Hybrids_ICRC_2019_Offline")
317  resolution = Hybrids_ICRC_2019_Offline_11_06(lgE);
318  else if (ResolutionFlag == "Hybrids_ICRC_2019_Offline_05_07")
319  resolution = Hybrids_ICRC_2019_Offline_05_07(lgE);
320  else if (ResolutionFlag == "Hybrids_ICRC_2019_Herald")
321  resolution = Hybrids_ICRC_2019_Herald_11_06(lgE);
322  else if (ResolutionFlag == "Resolution_TestExample")
323  resolution = Resolution_TestExample(lgE);
324  else {
325  cerr << endl;
326  cerr << ResolutionFlag << ": no valid resolution parameterization chosen " << endl;
327  throw std::exception();
328  }
329  return resolution;
330 }
331 
332 
333 // Standard migration matrix
334 TMatrixD kResolutionMatrix(TVectorD pCal, TVectorD xos, double* resolutionOffset) {
335  int N = xos.GetNoElements();
336  TVectorD ses = EnergyResolution(xos);
337  TVectorD Ebias = EnergyBias(xos, pCal);
338  TMatrixD tmp_kmatrix(N, N);
339  for (int j = 0; j < N; ++j) {
340  double ex = pow(10, xos[j]);
341  double efficiency = EfficiencyValuesNoDeclDep(xos[j]);
342 
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;
346  }
347  }
348 
349  /* ofstream outMatrixFile("matrixFile_OLD.txt");
350  for (int i = 0; i < N; ++i)
351  {
352  for (int j = 0; j < N; ++j)
353  outMatrixFile<<tmp_kmatrix[i][j]<<" ";
354 
355  outMatrixFile<<endl;
356  }
357  */
358  return tmp_kmatrix;
359 }
360 
361 // Declination dependent migration matrix
362 TMatrixD kResolutionMatrixDD(TVectorD pCal, TVectorD xos, Double_t lat, Double_t deltaMin, Double_t deltaMax) {
363  Int_t diagonalOfMatrix = 40;
364 // To speed up! verify always if there is a bias...
365 // The edges of the diagonal should be always very small. In first approximation they can be neglected..
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.;
377  }
378 
379  for (int i = 0; i < N; ++i) {
380  double ey = pow(10, xos[i]);//reco
381  for (int j = 0; j < N; ++j) {
382  double ex = pow(10, xos[j]);//real
383  if (fabs(i - j) < diagonalOfMatrix)
384  for (Double_t h = 0; h < 2.*TMath::Pi(); h += deltah) { //integrate over h
385  for (Double_t delta = deltaMin; delta < deltaMax; delta += deltadelta) { // integrate over delta
386  Double_t cosTheta = sin(lat) * sin(delta) + cos(lat) * cos(delta) * cos(h);
387 
388  double resolution = ResolutionValue(xos[j], cosTheta);
389  double sh_shfluct = ShowerToShowerFluctuation(xos[j]);
390  double tot_sigma = sqrt(pow(resolution, 2) + pow(sh_shfluct, 2));
391  double efficiency = EfficiencyValues(xos[j], acos(cosTheta));
392  double bias = EnergyBias_DD(xos[j], cosTheta, pCal);
393 
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.);
397  }
398  }
399  }
400  if (tmp_kmatrixDD_norm[i][j] > 0)
401  tmp_kmatrixDD[i][j] /= tmp_kmatrixDD_norm[i][j];
402  }
403  if (i % 25 == 0)
404  cout << i << endl;
405  }
406  /*
407  ofstream outMatrixFile("matrixFile_FULL_NEW.txt");
408  for (int i = 0; i < N; ++i)
409  {
410  for (int j = 0; j < N; ++j)
411  outMatrixFile<<tmp_kmatrixDD[i][j]<<" ";
412 
413  outMatrixFile<<endl;
414  }
415  */
416  return tmp_kmatrixDD;
417 }
418 
419 Double_t DirectionalExposure(Double_t lat, Double_t deltaMin, Double_t deltaMax) {
420  Double_t deltah = 0.001;
421  Double_t deltadelta = 0.00001;//To make the exposure calculation more precise
422 // Double_t deltadelta = 0.001;
423  const double tilt = -30 * TMath::DegToRad();
424  int countDelta=0;
425  Double_t exposure = 0.;
426  for (Double_t delta = deltaMin; delta < deltaMax; delta += deltadelta) {
427  for (Double_t h = 0; h < 2.*TMath::Pi(); h += deltah) { //integrate over h
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));
433  }
434 
435  if(countDelta%10000000==0)
436  cout<<"Exposure calculation step "<<countDelta<<endl;
437 
438  countDelta++;
439  }
440  }
441  cout << " Exposure " << mapParameters["Exposure"] * exposure / 2.35718 << "km2 sr yr" << endl;
442  return mapParameters["Exposure"] * exposure / 2.35718;
443 }
444 
446  cerr << "\n---------------------------------------------------\n";
447  cerr << "------------------Parameter Map--------------------\n";
448  cerr << "---------------------------------------------------\n";
449 
450  std::map<string, Double_t>::iterator it = mapParameters.begin();
451  while (it != mapParameters.end()) {
452  std::string keyName = it->first;
453  double val = it->second;
454  cout << keyName << " :: " << val << endl;
455  it++;
456  }
457 
458  cout << "Model---------------------" << Model << endl;
459  cout << "DeclinationDepentMatrix---" << DeclinationDepentMatrix << endl;
460  cout << "ResolutionFlag------------" << ResolutionFlag << endl;
461  cout << "BiasFlag------------------" << BiasFlag << endl;
462  cout << "EfficiencyFlag------------" << EfficiencyFlag << endl;
463  cout << "ShowerToShowerFlag--------" << ShowerToShowerFlag << endl;
464  cout << "VersionInput--------------" << VersionInput << endl;
465  cout << "UseNewTriggers------------" << UseNewTriggers << endl;
466  cerr << "---------------------------------------------------\n";
467  cerr << "---------------------------------------------------\n";
468 }
469 
470 void LoadParam(string paramFileName) {
471  ifstream in;
472  in.open(paramFileName.c_str());
473  string paramString, line;
474 
475  while (!in.eof()) {
476  getline(in, 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);
482 
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);
488 
489  Double_t tmpVal;
490  if (key == "Code") { //if we read a string... Define a string variable
491  CodeUsed = val;
492  } else if (key == "DataFileName") {
493  SDFile = val;
494  } else if (key == "OutPutFileName") {
495  OutPutFileName = val;
496  } else if (key == "OutPutFileNameRebinned") {
498  } else if (key == "ModelFunction") {
499  Model = val;
500  } else if (key == "DeclinationDepentMatrix") {
502  } else if (key == "ResolutionFlag") {
503  ResolutionFlag = val;
504  } else if (key == "BiasFlag") {
505  BiasFlag = val;
506  } else if (key == "EfficiencyFlag") {
507  EfficiencyFlag = val;
508  } else if (key == "ShowerToShowerFlag") {
509  ShowerToShowerFlag = val;
510  } else if (key == "VersionInput") {
511  VersionInput = val;
512  } else if (key == "UseNewTriggers") {
513  UseNewTriggers = val;
514  } else if (key == "Verbose") {
515  Verbose = val;
516  } else { // if we read a number do nothing... Only add parameter into the config file.
517  istringstream stringstream(val.c_str());
518  stringstream >> tmpVal;
519  mapParameters.insert(make_pair(key.c_str(), tmpVal));
520  }
521  }
522  }
523 
524  if ("no" != Verbose)
526 
527 }
528 
529 
530 void ReadEventList(TH1D* th1, TH1D* th2, string FileName) {
531 
532  long int AugerId;
533  long int EventId;
534  int nst;
535  double lgE, S1000, dS1000, theta, phi, dec, ra;
536  Double_t A, B;
537  string labelA, labelB;
538  ifstream evtFile;
539 
540  // test format. Minimal check: verify that the number of columns is compatible with expectations...
541  // The user is responsible for the content of the event file!
542  if ("no" != Verbose)
543  TestFormat(FileName, 0);
544 
545 
546  evtFile.open(FileName.c_str(), ios::in);
547  if (evtFile.fail()) {
548  cerr << endl;
549  cerr << FileName << ": no valid file name chosen " << endl;
550  throw std::exception();
551  }
552 
553  string headerline;
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") {
559  cerr << endl;
560  cerr << FileName << " does not look to be formatted properly " << endl;
561  cerr << "Add header line and calibration parameters" << endl;
562  throw std::exception();
563  }
564  mapParameters.insert(make_pair(labelA.c_str(), A));
565  mapParameters.insert(make_pair(labelB.c_str(), B));
566 
567  Double_t maxDecl = mapParameters["MaxDeclination"];
568  Double_t minDecl = mapParameters["MinDeclination"];
569  if (DeclinationDepentMatrix == "no") { //TODO
570  maxDecl = 9000.;
571  minDecl = -9000;
572  }
573 
574  while (!evtFile.eof()) {
575 
576  evtFile >> AugerId >> EventId >> lgE >> S1000 >> dS1000 >> nst >> theta >> phi >> dec >> ra;
577 
578  if (HeraldAnalysis)
579  lgE = log10(lgE) + 18;
580 
581  if (!evtFile.eof()) {
582  if (dec < maxDecl && dec > minDecl) {
583  th1->Fill(lgE);
584  th2->Fill(lgE);
585  }
586  }
587  }
588 
589  evtFile.close();
590 }
591 
592 
593 void ReadEventListICRC2019(TH1D* th1, TH1D* th2, string FileName) {
594 
595  long int AugerId;
596  long int EventId;
597  long int GPSTime;
598  int isHybrid;
599  double lgE, S1000, dS1000, theta, dtheta, phi, dphi, dec, ra, XCore, YCore, S1000_corr, S38, Nst, Nst_sat;
600  Double_t A, B;
601  string labelA, labelB;
602  ifstream evtFile;
603 
604  // test format. Minimal check: verify that the number of columns is compatible with expectations...
605  // The user is responsible for the content of the event file!
606  if ("no" != Verbose)
607  TestFormat(FileName, 1);
608 
609  evtFile.open(FileName.c_str(), ios::in);
610  if (evtFile.fail()) {
611  cerr << endl;
612  cerr << FileName << ": no valid file name chosen " << endl;
613  throw std::exception();
614  }
615  string headerline;
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") {
621  cerr << endl;
622  cerr << FileName << " does not look to be formatted properly " << endl;
623  cerr << "Add header line and calibration parameters" << endl;
624  throw std::exception();
625  }
626 
627  mapParameters.insert(make_pair(labelA.c_str(), A));
628  mapParameters.insert(make_pair(labelB.c_str(), B));
629 
630  Double_t maxDecl = mapParameters["MaxDeclination"];
631  Double_t minDecl = mapParameters["MinDeclination"];
632  if (DeclinationDepentMatrix == "no") {
633  maxDecl = 90.;
634  minDecl = -90;
635  }
636 
637  while (!evtFile.eof()) {
638 
639  evtFile >> AugerId >> EventId >> GPSTime >> isHybrid >> Nst >> Nst_sat >> lgE >> theta >> dtheta >> phi >> dphi >> XCore >> YCore >> ra >> dec >> S1000 >> dS1000 >> S1000_corr >> S38;
640 // evtFile >> AugerId >> EventId >> GPSTime>> isHybrid >> lgE >> theta >> dtheta >> phi >> dphi >> XCore >> YCore >> ra>> dec >> S1000 >> dS1000 >> S1000_corr >> S38;//PRELIMINARY VERSION FOR ICRC2019
641 
642  if (!evtFile.eof()) {
643  if (dec < maxDecl && dec > minDecl) { // && theta <30.26)
644  th1->Fill(lgE);
645  th2->Fill(lgE);
646  }
647  }
648  }
649  evtFile.close();
650 }
651 
652 
653 void TestFormat(string inputName, int flagversion) {
654  ifstream evtFile;
655  string headerline;
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;
663  double x;
664  int countCol = 0;
665  cout << endl;
666 
667  while (testString >> x) {
668  cout << x << " ";
669  countCol++;
670  }
671  cout << endl;
672  cout << countCol << " columns in the input event file" << endl;
673 
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;
679  evtFile.close();
680 }
681 
682 
683 void PrintUsage(int nArgs) {
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;
687 }
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)
string Verbose
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)
string ResolutionFlag
double pow(const double x, const unsigned int i)
double EfficiencyValues(double lgE, double zenith)
double exposure
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)
string UseNewTriggers
map< string, Double_t > mapParameters
string VersionInput
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)
string BiasFlag
double InverseSdCalibration(const double lgE, TVectorD pCal)
double EnergyBias_DD(double lgE, double cosTheta, TVectorD pCal)
string SDFile
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)
string OutPutFileName
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)
string CodeUsed
double Hybrids_ICRC_2019_Herald_11_06(const double lgE)
string Model
double Hybrids_ICRC_2019_Offline_11_06(const double lgE)
double Bias_TestExample(double ESD, double coszenith)
double TriggerEfficiency_TestExample(const double lgE)
string EfficiencyFlag
double SDTriggerEfficiencyICRC2019_SD750(const double lgE, const double zenith, TVectorD pCal, bool oldTrig)

, generated on Tue Sep 26 2023.