Documentation/Tutorials/HasModels/MuonProfile.cc
Go to the documentation of this file.
1 
10 #include <det/Detector.h>
11 
12 #include <tls/MuonProfile.h>
13 #include <tls/MuonProfileUtilities.h>
14 
15 #include <utl/AugerUnits.h>
16 #include <utl/MathConstants.h>
17 #include <utl/Reader.h>
18 #include <utl/Branch.h>
19 #include <utl/Vector.h>
20 #include <utl/Point.h>
21 #include <utl/CoordinateSystemPtr.h>
22 #include <utl/ReferenceEllipsoid.h>
23 #include <utl/AugerCoordinateSystem.h>
24 #include <utl/UTMPoint.h>
25 #include <utl/Transformation.h>
26 
27 #include <string>
28 #include <sstream>
29 #include <vector>
30 
31 using namespace tls;
32 using namespace utl;
33 using namespace std;
34 
35 #include <boost/shared_ptr.hpp>
36 #include <boost/program_options.hpp>
37 
38 #include <TFile.h>
39 #include <TH2.h>
40 
41 namespace po = boost::program_options;
42 
45 vector<double> gTheta;
46 vector<double> gPhi;
47 
48 // The following function is just to set the global variables and is at the end.
49 void processOptions(int argc, char* argv[]);
50 
51 // This is to create a coordinate system (in Malargue) since the framework is not there.
53 
54 int main(int argc, char* argv[]) {
55  processOptions(argc, argv);
56 
57  const double xMax = 3000*m;
58  const double yMax = 3000*m;
59  const int xBins = 200;
60  const int yBins = 200;
61 
62  //TH1::AddDirectory(kFALSE); // this breaks everything in USC!
63  TFile f("MuonProfile.root","RECREATE");
64 
65  // Get the configurations for the muon maps:
66  Reader reader(gXMLConfigurationFileName.c_str());
67  Branch topBranch = reader.GetTopBranch();
68  Branch b = topBranch.GetFirstChild();
69  vector<MuonProfile> muonProfiles;
70  vector<string> muonProfileNames;
71  while (b)
72  {
73  muonProfileNames.push_back(b.GetName());
74  muonProfiles.push_back(MuonProfile(b));
75  b = b.GetNextSibling();
76  }
77 
78  // The geomagnetic field that will be used to change reference frames:
79  CoordinateSystemPtr localCs = GetLocalCS();
83  localCs,
84  Vector::kSpherical);
85 
86  // Loop for all values of zenith and azimuth, filling histograms according to the muon maps
87  for(unsigned int i = 0; i != gTheta.size(); ++i)
88  for(unsigned int j = 0; j != gPhi.size(); ++j)
89  {
90  const double theta = gTheta[i]*degree;
91  const double phi = gPhi[j]*degree;
92  const double energy = 10.*EeV;
93 
94  const Vector axis(1,theta,phi,localCs, Vector::kSpherical);
95  const CoordinateSystemPtr showerCs =
96  CoordinateSystem::RotationY(theta,CoordinateSystem::RotationZ(phi, localCs));
97  const CoordinateSystemPtr geomagneticCs =
98  CoordinateSystem::RotationZ(gMagneticField.GetPhi(showerCs) - kPiOnTwo, showerCs);
99 
100  for (unsigned int iType=0;iType<muonProfiles.size();++iType)
101  {
102  const string& name = muonProfileNames[iType];
103  MuonProfile& mp = muonProfiles[iType];
104 
105  ostringstream label;
106  label << name << "NMu" << "_" << theta/deg << "_" << phi/deg;
107  boost::shared_ptr<TH2D> histoNMu(new TH2D(label.str().c_str(),name.c_str(),
108  xBins,-xMax,xMax, yBins, -yMax, yMax));
109 
110  label.str("");
111  label << name << "ThMu" << "_" << theta/deg << "_" << phi/deg;
112  boost::shared_ptr<TH2D> histoThMu(new TH2D(label.str().c_str(),name.c_str(),
113  xBins,-xMax,xMax, yBins, -yMax, yMax));
114 
115  label.str("");
116  label << name << "EnMu" << "_" << theta/deg << "_" << phi/deg;
117  boost::shared_ptr<TH2D> histoEnMu(new TH2D(label.str().c_str(),name.c_str(),
118  xBins,-xMax,xMax, yBins, -yMax, yMax));
119 
120  cout << "Processing " << name << " " << theta/deg << " " << phi/deg << endl;
121 
122  for(int i = 1; i <= xBins+1; ++i) for(int j = 1; j <= yBins+1; ++j)
123  {
124  const double x = histoNMu->GetXaxis()->GetBinCenter(i);
125  const double y = histoNMu->GetYaxis()->GetBinCenter(j);
126  Point p(x, y, 0, geomagneticCs);
127  Point p_ground = p - Vector(0, 0, p.GetZ(localCs)/axis.GetZ(localCs), geomagneticCs);
128  const double xp = p_ground.GetX(localCs);
129  const double yp = p_ground.GetY(localCs);
130 
131  histoNMu->Fill(x, y, mp.NMuon(xp, yp, theta, phi, energy));
132  histoThMu->Fill(x, y, mp.ThetaMuon(xp, yp, theta, phi, energy));
133  histoEnMu->Fill(x, y, mp.EnergyMuon(xp, yp, theta, phi, energy));
134  }
135 
136  f.cd();
137  histoNMu->Write();
138  histoThMu->Write();
139  histoEnMu->Write();
140  } // loop over types
141  } // loop over theta, phi combinatins
142 
143  f.cd();
144  f.Close();
145 
146  return 0;
147 }
148 
149 void processOptions(int argc, char* argv[])
150 {
151  ostringstream msg;
152  msg << "Usage: " << argv[0] << " -c <xml_config_file> -z <zenith> [-z <zenith>...] -a <azimuth> [-a <azimuth>...]\n"
153  << "Example: '" << argv[0] << " -c MuonProfile.xml -z 60 -z 70 -a 0 -a 90' will histogram the maps for the following directions: (60 deg,0), (60 deg,90 deg), (70 deg,0) and (79 deg,90 deg).\n"
154  << "Everything is saved in the file MuonProfile.root.\n"
155  << "\nAll options are";
156  po::options_description desc(msg.str());
157  desc.add_options()
158  ("help,h",
159  "write this message")
160  ("config,c",
161  po::value< string > (&gXMLConfigurationFileName),
162  "path to configuration file. Required.")
163  ("zenith,z",
164  po::value< vector<double> >(&gTheta),
165  "Zenith angle (in degrees). Required.")
166  ("azimuth,a",
167  po::value< vector<double> >(&gPhi),
168  "Azimuth angle (in degrees). Required.")
169  ;
170 
171  po::variables_map vm;
172  try {
173  po::store(po::parse_command_line(argc, argv, desc), vm);
174  po::notify(vm);
175  }
176  catch (po::error& er) {
177  cerr << "Command line error : " << er.what() << '\n'
178  << desc << endl;
179  exit(EXIT_FAILURE);
180  }
181 
182  if (vm.count("help") || !vm.count("zenith") || !vm.count("azimuth")) {
183  cerr << desc << endl;
184  exit(EXIT_SUCCESS);
185  }
186 }
187 
189 {
190  ReferenceEllipsoid wgs84 =
191  ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84);
192  const CoordinateSystemPtr ecef = wgs84.GetECEF();
193 
194  UTMPoint malargueOrigin(6060000*m, 440000*m, 1400*m, 19, 'H', wgs84);
195  return AugerBaseCoordinateSystem::Create(malargueOrigin, ecef);
196 }
197 
198 // Configure (x)emacs for this file ...
199 // Local Variables:
200 // mode:c++
201 // compile-command: "make -C .. -k"
202 // End:
Branch GetTopBranch() const
Definition: Branch.cc:63
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 handle average muon profiles.
Definition: MuonProfile.h:38
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
int exit
Definition: dump1090.h:237
const double EeV
Definition: GalacticUnits.h:34
double ThetaMuon(double xpos, double ypos, double theta, double phi, double energy)
Definition: MuonProfile.h:63
constexpr double deg
Definition: AugerUnits.h:140
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
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
double EnergyMuon(double xpos, double ypos, double theta, double phi, double energy)
Definition: MuonProfile.h:73
constexpr double kPiOnTwo
Definition: MathConstants.h:25
double NMuon(double xpos, double ypos, double theta, double phi, double energy)
Definition: MuonProfile.h:53
const CoordinateSystemPtr GetECEF() const
Get the ECEF.
std::string GetName() const
function to get the Branch name
Definition: Branch.cc:374
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
Vector object.
Definition: Vector.h:30
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
CoordinateSystemPtr GetLocalCS()
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.