Tools/InclinedShowers/TankResponse/USCInter/TankResponse.cc
Go to the documentation of this file.
1 #include "TankResponse.h"
2 
3 #include <utl/AugerException.h>
4 #include <utl/Branch.h>
5 #include <utl/AugerUnits.h>
6 #include <utl/NormalDistribution.h>
7 #include <utl/Math.h>
8 
9 #include <string>
10 #include <sstream>
11 #include <fstream>
12 
13 #include <TFile.h>
14 #include <TH1D.h>
15 
16 using namespace USCInterTankResponseNS;
17 using namespace utl;
18 using namespace std;
19 using namespace tls;
20 
21 inline
22 double
23 TriggerPDF(const double signal, const double* pars)
24 {
25  return pow(signal,pars[0])/(pow(signal,pars[0]) + pars[1]);
26 }
27 
29 {
30  static TankResponse singleton(topBranch);
31  return singleton;
32 }
33 
35 {
36  branch.GetChild("Simulation").GetData(fSimulationMode);
37 
38  string dataFilePath;
39  branch.GetChild("DataFile").GetData(dataFilePath);
40 
41  string dataSilentFilePath;
42  branch.GetChild("DataSilentFile").GetData(dataSilentFilePath);
43 
44  string dataSilentSimFilePath;
45  branch.GetChild("DataSilentSimFile").GetData(dataSilentSimFilePath);
46 
47  vector<double> buffer;
48  branch.GetChild("TriggerParameters").GetData(buffer);
49  fTriggerParameters[0][0] = buffer[0];
50  fTriggerParameters[0][1] = buffer[1];
51 
52  vector<double>().swap(buffer);
53  branch.GetChild("TriggerSimParameters").GetData(buffer);
54  fTriggerParameters[1][0] = buffer[0];
55  fTriggerParameters[1][1] = buffer[1];
56 
57  TFile* f = TFile::Open(dataFilePath.c_str(),"READ");
58  if (!f) {
59  ostringstream msg;
60  msg << "ERROR: could not open file " << dataFilePath;
61  throw NoDataForModelException(msg.str());
62  }
63 
64  const int Nz = 15;
65  const int Nr = 8;
66  const int Nmu = 8;
67  boost::multi_array<double,3> data(boost::extents[NBIN][Nz][Nr]);
68  boost::multi_array<double,2> data_avg(boost::extents[Nz][Nr]);
69  boost::multi_array<double,2> data_sigma(boost::extents[Nz][Nr]);
70 
71  for (int nmu = 1; nmu <= Nmu; ++nmu)
72  {
73  for (int ze = 0; ze < Nz; ++ze)
74  {
75  int theta = 60 + 2 * ze;
76  for (int rr = 0; rr < Nr; ++rr)
77  {
78  //open the histogram
79  ostringstream histoID;
80  if (nmu==1)
81  histoID << "thPmt_" << theta << "_" << rr << "_0";
82  else
83  histoID << "thConv_" << theta << "_" << rr << "_0" << "_" << nmu;
84 
85  TH1D *histResponse = 0;
86  histResponse = static_cast<TH1D*>(f->Get(histoID.str().c_str()));
87  if (!histResponse)
88  {
89  ostringstream msg;
90  msg << "ERROR: Histogram " << histoID.str() << " not found in " << dataFilePath << "\n";
91  throw NoDataForModelException(msg.str());
92  }
93 
94  if (nmu==1)
95  {
96  data_avg[ze][rr] = histResponse->GetMean();
97  data_sigma[ze][rr] = histResponse->GetRMS();
98  fDS = histResponse->GetBinWidth(1);
99  }
100 
101  for (int bin = 0; bin < histResponse->GetNbinsX(); bin++)
102  data[bin][ze][rr] = histResponse->GetBinContent(bin+1);
103  }
104  }
105 
106  fUSCTankModel[nmu-1] = USCTankModel(GetThetaMin(),GetThetaMax(),GetLogrMin(),GetLogrMax(),data);
107 
108  if (nmu==1)
109  {
110  fUSCAvgTankModel = USCAvgTankModel(GetThetaMin(),GetThetaMax(),GetLogrMin(),GetLogrMax(),data_avg);
111  fUSCSigmaTankModel = USCSigmaTankModel(GetThetaMin(),GetThetaMax(),GetLogrMin(),GetLogrMax(),data_sigma);
112  }
113  }
114 
115  delete f;
116 
117  // Load silent station probability
118  ifstream fOutProb;
119  int dummy0, dummy1;
120 
121  fOutProb.open(dataSilentSimFilePath.c_str());
122  for(int pp=0;pp<16;pp++)
123  for(int k=0;k<30;k++)
124  fOutProb >> dummy0 >> dummy1 >> fProbNoTriggerSilent[1][pp][k];
125  fOutProb.close();
126 
127  fOutProb.open(dataSilentFilePath.c_str());
128  for(int pp=0;pp<16;pp++)
129  for(int k=0;k<30;k++)
130  fOutProb >> dummy0 >> dummy1 >> fProbNoTriggerSilent[0][pp][k];
131  fOutProb.close();
132 }
133 
134 double
135 TankResponse::Mean(const double theta, const double r, const ulong nmuon)
136  const
137 {
138  double th = theta;
139  if(th < GetThetaMin())
140  th = GetThetaMin();
141 
142  if(th > GetThetaMax())
143  th = GetThetaMax();
144 
145  double logr = log10(r/meter);
146 
147  if(logr < GetLogrMin())
148  logr = GetLogrMin();
149 
150  if(logr > GetLogrMax())
151  logr = GetLogrMax();
152 
153  const double a = fUSCAvgTankModel(th,logr);
154  return a*nmuon;
155 }
156 
157 double
158 TankResponse::StDev(const double theta, const double r, const ulong nmuon)
159  const
160 {
161  double th = theta;
162  if(th < GetThetaMin())
163  th = GetThetaMin();
164 
165  if(th > GetThetaMax())
166  th = GetThetaMax();
167 
168  double logr = log10(r/meter);
169 
170  if(logr < GetLogrMin())
171  logr = GetLogrMin();
172 
173  if(logr > GetLogrMax())
174  logr = GetLogrMax();
175 
176  const double b = fUSCSigmaTankModel(th,logr);
177 
178  return b*sqrt(nmuon);
179 }
180 
181 double
182 TankResponse::PDF(const double signal, const double theta, const double r, const ulong nmuon)
183  const
184 {
185  double th = theta;
186  if(th < GetThetaMin())
187  th = GetThetaMin();
188 
189  if(th > GetThetaMax())
190  th = GetThetaMax();
191 
192  double logr = log10(r/meter);
193 
194  if(logr < GetLogrMin())
195  logr = GetLogrMin();
196 
197  if(logr > GetLogrMax())
198  logr = GetLogrMax();
199 
200  if (nmuon <= GetMaxMuonNumber()) {
201 
202  if (signal <= 0)
203  return 0.0;
204 
205  static vector<double> interpolatedTrace(NBIN);
206  fUSCTankModel[nmuon-1](interpolatedTrace, th, logr);
207 
208  size_t i = static_cast<size_t>(signal/fDS);
209  if (i > NBIN-1)
210  i = NBIN-1;
211 
212  // I don't understand this (HD)
213 
214  double prob = interpolatedTrace[i];
215  prob *= TriggerPDF(signal, fTriggerParameters[int(fSimulationMode)]);
216  if (prob < 0) prob = 0;
217 
218  return prob;
219 
220  } else {
221 
222  const double a = fUSCAvgTankModel(th,logr);
223  const double b = fUSCSigmaTankModel(th,logr);
224 
225  const double mean = a*nmuon;
226  const double sigma = b*sqrt(nmuon);
227  return NormalPDF(signal,mean,sigma);
228  }
229 }
230 
231 double
232 TankResponse::CDF(const double signalmin, const double theta, const double r, const ulong nmuon)
233  const
234 {
235  double th = theta;
236  if(th < GetThetaMin())
237  th = GetThetaMin();
238 
239  if(th > GetThetaMax())
240  th = GetThetaMax();
241 
242  double logr = log10(r/meter);
243 
244  if(logr < GetLogrMin())
245  logr = GetLogrMin();
246 
247  if(logr > GetLogrMax())
248  logr = GetLogrMax();
249 
250  if (nmuon <= 30) {
251  double theta_deg = th/degree;
252  int c_bin = int( (theta_deg - 59.0)/2.0 );
253  int entry = nmuon-1;
254 
255  // I don't understand this (HD)
256 
257  double prob_silent = 1.0-fProbNoTriggerSilent[int(fSimulationMode)][c_bin][entry];
258 
259  return prob_silent;
260 
261  } else {
262 
263  const double a = fUSCAvgTankModel(th,logr);
264  const double b = fUSCSigmaTankModel(th,logr);
265 
266  double mean = a*nmuon;
267  double sigma = b*sqrt( (double)nmuon );
268  return NormalCDF(signalmin, mean, sigma);
269  }
270 }
virtual double StDev(const double theta, const double r, const ulong muons) const
Standard deviation of signal, given fixed number of muons.
const double degree
unsigned long ulong
Definition: VTankResponse.h:28
void swap(OverCounted &oc1, OverCounted &oc2)
const double meter
Definition: GalacticUnits.h:29
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
double pow(const double x, const unsigned int i)
virtual double PDF(const double signal, const double theta, const double r, const ulong muons) const
PDF of signal, given a fixed number of muons.
virtual double Mean(const double theta, const double r, const ulong muons) const
Average signal, given fixed number of muons.
double NormalPDF(const double x)
double NormalCDF(const double x)
Exception to use in a atmosphere model cannot find data it needs.
Class representing a document branch.
Definition: Branch.h:107
utl::Spline::Interpolator2D USCSigmaTankModel
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
uint16_t * data
Definition: dump1090.h:228
utl::Spline::VectorInterpolator2D USCTankModel
double TriggerPDF(const double signal, const double *pars)
virtual double CDF(const double threshold, const double theta, const double r, const ulong muons) const
Probability of signal begin smaller than smax, given a fixed number of muons.
utl::Spline::Interpolator2D USCAvgTankModel

, generated on Tue Sep 26 2023.