Documentation/Tutorials/HasModels/EMComponent.cc
Go to the documentation of this file.
1 
9 #include <tls/EMComponent.h>
10 #include <tls/MuonProfileUtilities.h>
11 
12 #include <utl/AugerUnits.h>
13 #include <utl/MathConstants.h>
14 #include <utl/Reader.h>
15 #include <utl/CoordinateSystemPtr.h>
16 #include <utl/ReferenceEllipsoid.h>
17 #include <utl/AugerCoordinateSystem.h>
18 #include <utl/UTMPoint.h>
19 #include <utl/Transformation.h>
20 #include <utl/Vector.h>
21 #include <utl/Point.h>
22 
23 #include <iostream>
24 #include <cstdlib>
25 #include <sstream>
26 #include <string>
27 #include <cmath>
28 
29 #include <boost/shared_ptr.hpp>
30 #include <boost/program_options.hpp>
31 
32 #include <TROOT.h>
33 #include <TObjectTable.h>
34 #include <TFile.h>
35 #include <TH2.h>
36 
37 namespace po = boost::program_options;
38 using namespace tls;
39 using namespace utl;
40 using namespace std;
41 
43 vector<int> gTheta;
44 vector<int> gLgRMu;
45 
46 // The following function is just to set the global variables and is at the end.
47 void processOptions(int argc, char* argv[]);
48 
49 // This is to create a coordinate system (in Malargue) since the framework is not there.
51 
52 int main(int argc, char* argv[]) {
53  processOptions(argc, argv);
54 
55  double xMax = 5.0; // km
56  double yMax = 5.0; // km
57  int xBins = 200;
58  int yBins = 200;
59 
60  TFile* f = TFile::Open("EMComponent.root","RECREATE");
61 
62  // The geomagnetic field that will be used to change reference frames:
63  CoordinateSystemPtr localCs = GetLocalCS();
64  const Vector gMagneticField = Vector(1,
67  localCs,
68  Vector::kSpherical);
69 
70  Reader reader(gXMLConfigurationFileName.c_str());
71  Branch branch = reader.GetTopBranch().GetFirstChild();
72  while(branch) {
73  EMComponent emComponent(branch);
74 
75  for(unsigned int irmu = 0; irmu != gLgRMu.size(); ++irmu)
76  for(unsigned int ith = 0; ith != gTheta.size(); ++ith)
77  {
78  const double theta = gTheta[ith]*degree;
79  const double rmu = pow(10.,gLgRMu[irmu]);
80  double phi = 90*degree;
81 
82  const Vector axis(1,theta,phi,localCs, Vector::kSpherical);
83  const CoordinateSystemPtr showerCs =
84  CoordinateSystem::RotationY(theta,CoordinateSystem::RotationZ(phi, localCs));
85  const CoordinateSystemPtr geomagneticCs =
86  CoordinateSystem::RotationZ(gMagneticField.GetPhi(showerCs) - kPiOnTwo, showerCs);
87 
88  ostringstream label, title;
89  char buf[256]; sprintf(buf,"%s_%i_%i",branch.GetName().c_str(),
90  int(round(log10(rmu))),
91  int(round(theta/degree)) );
92  label << buf;
93  title << branch.GetName() << ";x / km;y / km;S_{em} / S_{#mu}";
94  TH2D* histo = new TH2D(label.str().c_str(),title.str().c_str(),xBins,-xMax,xMax, yBins, -yMax, yMax);
95  histo->SetDirectory(0);
96 
97  for(int ix = 1; ix < xBins+1; ++ix)
98  for(int iy = 1; iy < yBins+1; ++iy)
99  {
100  const double x = histo->GetXaxis()->GetBinCenter(ix);
101  const double y = histo->GetYaxis()->GetBinCenter(iy);
102 
103  Point p(x, y, 0,showerCs);
104 
105  Point p_ground = p - Vector(0, 0, p.GetZ(localCs)/axis.GetZ(localCs), showerCs);
106  const double xp = p_ground.GetX(localCs);
107  const double yp = p_ground.GetY(localCs);
108 
109 
110  const double semsmu = emComponent.SignalRatio(xp*km, yp*km, rmu, theta, phi);
111  histo->SetBinContent(ix,iy,semsmu);
112  }
113 
114  histo->SetTitle("Em correction on the shower plane");
115  histo->Write();
116  }
117 
118  branch = branch.GetNextSibling();
119  }
120 
121  f->Close();
122 
123  return 0;
124 }
125 
126 void processOptions(int argc, char* argv[])
127 {
128  ostringstream msg;
129  msg << "Usage: " << argv[0] << " -c <xml_config_file> -z <zenith> [-z <zenith> ...] -m <lgRMu> [-m <lgRMu> ... ]\n"
130  << "Example: '" << argv[0] << " -z 60 -z 70 -m 0' will histogram the em components for the zenith angles 60 deg and 70 deg and an energy estimator lgRMu = 0.\n"
131  << "Everything is saved in the file EMComponent.root.\n"
132  << "\nAll options are";
133  po::options_description desc(msg.str());
134  desc.add_options()
135  ("help,h",
136  "write this message")
137  ("config,c",
138  po::value< string > (&gXMLConfigurationFileName),
139  "path to configuration file. Required.")
140  ("zenith,z",
141  po::value< vector<int> >(&gTheta),
142  "Zenith angle (in degrees). Required.")
143  ("lgrmu,m",
144  po::value< vector<int> >(&gLgRMu),
145  "lg(energy estimator). Required.")
146  ;
147 
148  po::variables_map vm;
149  try {
150  po::store(po::parse_command_line(argc, argv, desc), vm);
151  po::notify(vm);
152  }
153  catch (po::error& er) {
154  cerr << "Command line error : " << er.what() << '\n'
155  << desc << endl;
156  exit(EXIT_FAILURE);
157  }
158 
159  if ( vm.count("help") || !vm.count("zenith") || !vm.count("lgrmu") ) {
160  cerr << desc << endl;
161  exit(EXIT_SUCCESS);
162  }
163 }
164 
166 {
167  ReferenceEllipsoid wgs84 =
168  ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84);
169  const CoordinateSystemPtr ecef = wgs84.GetECEF();
170 
171  UTMPoint malargueOrigin(6060000*m, 440000*m, 1400*m, 19, 'H', wgs84);
172  return AugerBaseCoordinateSystem::Create(malargueOrigin, ecef);
173 }
174 
175 // Configure (x)emacs for this file ...
176 // Local Variables:
177 // mode:c++
178 // compile-command: "make -C .. -k"
179 // End:
Branch GetTopBranch() const
Definition: Branch.cc:63
Facade for any instance of EMComponent.
Definition: EMComponent.h:43
const double degree
Point object.
Definition: Point.h:32
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Definition: BasicVector.h:254
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
double pow(const double x, const unsigned int i)
int exit
Definition: dump1090.h:237
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Utility for parsing XML files.
Definition: Reader.h:25
Class representing a document branch.
Definition: Branch.h:107
Reference ellipsoids for UTM transformations.
int main(int argc, char *argv[])
Definition: DBSync.cc:58
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
constexpr double kPiOnTwo
Definition: MathConstants.h:25
const double km
const CoordinateSystemPtr GetECEF() const
Get the ECEF.
static const double kInclination
kInclination of geomagnetic field in Malargüe, 2007
static const double kDeclination
kDeclination of geomagnetic field in Malargüe, 2007
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
double SignalRatio(double x, double y, double rmu, double theta, double phi)
Ratio between electromagnetic and muon signal.
Definition: EMComponent.h:51
Vector object.
Definition: Vector.h:30
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
CoordinateSystemPtr GetLocalCS()
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
constexpr double m
Definition: AugerUnits.h:121
void processOptions(int argc, char *argv[])

, generated on Tue Sep 26 2023.