Documentation/Tutorials/HasModels/TankResponse.cc
Go to the documentation of this file.
1 
10 #include <tls/VTankResponse.h>
11 #include <tls/TankResponseFactory.h>
12 #include <tls/TankResponseUtilities.h>
13 
14 #include <boost/program_options.hpp>
15 #include <boost/shared_ptr.hpp>
16 
17 #include <utl/Reader.h>
18 #include <utl/AugerUnits.h>
19 #include <utl/AugerException.h>
20 #include <utl/ErrorLogger.h>
21 
22 #include <iostream>
23 #include <cmath>
24 #include <string>
25 
26 #include <TFile.h>
27 #include <TH1D.h>
28 
29 namespace po = boost::program_options;
30 using namespace tls;
31 using namespace utl;
32 using namespace std;
33 
35 vector<double> gTheta;
37 
38 // The following function is just to set the global variables and is at the end.
39 void processOptions(int argc, char* argv[]);
40 
41 int main(int argc, char* argv[]) {
42 
43  processOptions(argc, argv);
44 
45  //TH1::AddDirectory(kFALSE); // this breaks everything in USC!
46  TFile f("TankResponse.root","RECREATE");
47 
48  // Get the configuration. Which implementation is used is determined there.
49  Reader reader(gXMLConfigurationFileName.c_str());
50  Branch branch = reader.GetTopBranch().GetFirstChild();
51  vector<Branch> branchList;
52  while (branch) { branchList.push_back(branch); branch = branch.GetNextSibling(); }
53 
54  // calculate minimum and maximum signal to plot
55  double minMu = gMuonMin-3*sqrt((double)gMuonMin);
56  if (minMu<0) minMu = 0;
57  double maxMu = gMuonMax+3*sqrt((double)gMuonMax);
58 
59  unsigned short nPoints = 400;
60 
61  for (unsigned short iz=0;iz<gTheta.size();++iz) {
62  const double zenith = gTheta[iz];
63  const double smin = minMu*TankMeanTrackLength(zenith*degree);
64  const double smax = maxMu*TankMeanTrackLength(zenith*degree);
65 
66  for (int muons=gMuonMin;muons<=gMuonMax;++muons)
67  for (unsigned short ib=0;ib<branchList.size();++ib)
68  {
69  Branch& branch = branchList[ib];
70 
71  printf("=============================================\n");
72  printf("Using %s",branch.GetName().c_str());
73  printf(" Theta = %.1f Deg, Muons = %i\n",zenith,muons);
74  printf("=============================================\n");
75 
76  ostringstream name;
77  name << branch.GetName() << "_" << int(zenith) << "_" << muons;
78 
79  try {
80  VTankResponse& tankResponse = TankResponseFactory::GetInstance().GetTankResponse(branch);
81 
82  boost::shared_ptr<TH1D> h(new TH1D(name.str().c_str(),
83  ";S / VEM;dp/dS / VEM^{-1}",nPoints,smin,smax));
84 
85  ostringstream name2;
86  name2 << branch.GetName() << "_int_" << int(zenith) << "_" << muons;
87  boost::shared_ptr<TH1D> h2(new TH1D(name2.str().c_str(),
88  ";S_{min} / VEM;P(S > S_{min})",
89  nPoints,smin,smax));
90 
91  for (int ix=1;ix<h->GetNbinsX()+1;++ix) {
92  double s = h->GetXaxis()->GetBinCenter(ix);
93  double p = tankResponse.PDF(s, zenith*degree, 1000*meter, muons);
94  double p2 = tankResponse.CDF(s, zenith*degree, 1000*meter, muons);
95  h->SetBinContent(ix,p);
96  h2->SetBinContent(ix,p2);
97  if (p<0 || p>1) {
98  cerr << "WARNING: s = " << s << " VEM --> p = " << p << endl;
99  if (p<0) p = -p;
100  }
101  if (p2<0 || p2>1) {
102  cerr << "WARNING: s = " << s << " VEM --> p2 = " << p2 << endl;
103  if (p2>1) p2 = 1.;
104  }
105  }
106 
107  cout << " Average signal "
108  << tankResponse.Mean(zenith*degree, 0, static_cast<int>(muons)) << "\n"
109  << " PDF for S < 3.0 VEM "
110  << 1.-tankResponse.CDF(3.0,zenith*degree, 1000*meter, static_cast<int>(muons))
111  << endl;
112 
113  f.cd();
114  h->Write();
115  h2->Write();
116  } catch (NonExistentComponentException& e) {
117  ERROR(e.GetMessage());
118  }
119  } // loop over tank responses, no. of muons
120  } // loop over zenith angles
121  return 0;
122 }
123 
124 void processOptions(int argc, char* argv[])
125 {
126  ostringstream msg;
127  msg << "Usage: " << argv[0] << " -c <xml_config_file> -z <zenith> [-z <zenith>...] --min <muons> --max <muons>\n"
128  << "Example: '" << argv[0] << " -z 60 -z 80 --min 1 --max 10' will histogram the tank\n"
129  << "response probability distributions at theta = 60 deg and theta = 80 deg, for 1 up\n"
130  << "up to 10 muons. Everything is saved in the file testTankResponse.root.\n"
131  << "\nAll options are";
132  po::options_description desc(msg.str());
133  desc.add_options()
134  ("help,h",
135  "write this message")
136  ("config,c",
137  po::value< string > (&gXMLConfigurationFileName),
138  "path to configuration file. Required.")
139  ("zenith,z",
140  po::value< vector<double> >(&gTheta),
141  "Zenith angle (in degrees). Required.")
142  ("min",
143  po::value<int>(&gMuonMin),
144  "Minimal number of expected muons. Required.")
145  ("max",
146  po::value<int>(&gMuonMax),
147  "Maximal number of expected muons. Required.")
148  ;
149 
150 
151  po::variables_map vm;
152  try {
153  po::store(po::parse_command_line(argc, argv, desc), vm);
154  po::notify(vm);
155  }
156  catch (po::error& er) {
157  cerr << "Command line error : " << er.what() << '\n'
158  << desc << endl;
159  exit(EXIT_FAILURE);
160  }
161 
162  if (vm.count("help") || !vm.count("zenith") || !vm.count("min") || !vm.count("max")) {
163  cerr << desc << endl;
164  exit(EXIT_SUCCESS);
165  }
166 }
167 
168 // Configure (x)emacs for this file ...
169 // Local Variables:
170 // mode:c++
171 // compile-command: "make -C .. -k"
172 // End:
Branch GetTopBranch() const
Definition: Branch.cc:63
const double degree
const double meter
Definition: GalacticUnits.h:29
virtual double PDF(const double signal, const double theta, const double r, const ulong muons) const =0
PDF of signal, given a fixed number of muons.
Base class for exceptions trying to access non-existing components.
int exit
Definition: dump1090.h:237
Utility for parsing XML files.
Definition: Reader.h:25
Class representing a document branch.
Definition: Branch.h:107
constexpr double s
Definition: AugerUnits.h:163
Interface class for coupling different tank response calculations into the reconstruction code...
Definition: VTankResponse.h:26
int main(int argc, char *argv[])
Definition: DBSync.cc:58
double TankMeanTrackLength(const double theta)
Mean track length of particle piercing Auger tank with zenith angle theta.
std::string GetName() const
function to get the Branch name
Definition: Branch.cc:374
v push_back(value)
virtual double Mean(const double theta, const double r, const ulong muons) const =0
Average signal, given fixed number of muons.
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
const std::string & GetMessage() const
Retrieve the message from the exception.
virtual double CDF(const double smax, const double theta, const double r, const ulong muons) const =0
Probability of signal begin smaller than smax, given a fixed number of muons.
void processOptions(int argc, char *argv[])

, generated on Tue Sep 26 2023.