RdEVASimPreparator.cc
Go to the documentation of this file.
1 #include "RdEVASimPreparator.h"
2 //C++
3 #include <fstream>
4 #include <sstream>
5 #include <ios>
6 #include <cmath>
7 #include <vector>
8 #include <boost/algorithm/string.hpp>
9 #include <boost/tokenizer.hpp>
10 #include <iomanip>
11 
12 //OffLine
13 #include <fwk/CentralConfig.h>
14 #include <utl/AugerCoordinateSystem.h>
15 #include <fwk/LocalCoordinateSystem.h>
16 #include <fwk/CoordinateSystemRegistry.h>
17 
18 #include <rdet/RDetector.h>
19 
20 #include <evt/Event.h>
21 #include <sevt/SEvent.h>
22 #include <revt/REvent.h>
23 #include <revt/Header.h>
24 #include <sevt/Header.h>
25 #include <evt/ShowerRecData.h>
26 #include <evt/ShowerSRecData.h>
27 #include <evt/Header.h>
28 
29 #include <utl/Point.h>
30 #include <utl/UTMPoint.h>
31 #include <utl/ReferenceEllipsoid.h>
32 #include <utl/AugerUnits.h>
33 #include <utl/Reader.h>
34 #include <utl/TimeStamp.h>
35 
36 
37 //Root
38 #include <TFile.h>
39 #include <TTree.h>
40 
41 //#include <utl/Config.h>
42 
43 using namespace evt;
44 using namespace fwk;
45 using namespace utl;
46 using namespace det;
47 using std::vector;
48 using std::string;
49 using std::stringstream;
50 using std::ostringstream;
51 using std::ofstream;
52 using std::cout;
53 using std::endl;
54 
55 
56 typedef boost::tokenizer<boost::char_separator<char> > mytok;
57 
58 namespace RdEVASimPreparator {
60  {
61  ReferenceEllipsoid wgs84 =
62  ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84);
63  const CoordinateSystemPtr ecef = wgs84.GetECEF();
64 
65  UTMPoint rodrigoOrigin(6113924.83*m, 448375.63*m, 1560.0*m, 19, 'H', wgs84);
66  return AugerBaseCoordinateSystem::Create(rodrigoOrigin, ecef);
67  }
68 
69  long int unknown_id = 666; /* if no proper event id is found we
70  revert to counting arbitrarily starting at this nice number */
71 
73  fWorkingDir(""),
74  fUserName(""),
75  fPathToEVA(""),
76  fEVAbin(""),
77  fElectricField(30),
78  fPrim(eProton)
79  {
80  // The geomagnetic field for the simulations
81  // At this moment this is hardcoded here.
82  // The origin of these values can be found on
83  // the wiki page at
84  // https://www.auger.unam.mx/AugerWiki/AERA%2C_Polarization_analysis
85 
86  // First create a UTM point at the specified location of Rodrigo
87  CoordinateSystemPtr rodrigoCs(GetRodrigoCS());
88 
89  // These are the values obtained from the IGRF-11 survey for 2011
90  // values like these need to be stored into the framework of offline
91  // at some point.
92  // the values of Tools/InclinedShowers/MuonProfile/MuonProfileUtilities.h
93  // date from 2007 and are too old.
94  double geoInclination = -35.56728*kPiOnTwo/90.0;
95  double geoDeclination = 2.71397*kPiOnTwo/90.0;
96 
97  fMagneticField = Vector(24333.73*nano*tesla,
98  kPiOnTwo + geoInclination,
99  kPiOnTwo - geoDeclination,
100  rodrigoCs,
101  Vector::kSpherical);
102 
103  };
104 
105  RdEVASimPreparator::~RdEVASimPreparator() {
106  }
107 
109  ostringstream info;
110  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdEVASimPreparator");
111  topBranch.GetChild("WorkingDir").GetData(fWorkingDir);
112  topBranch.GetChild("UserName").GetData(fUserName);
113  topBranch.GetChild("EVAPath").GetData(fPathToEVA);
114  topBranch.GetChild("EVABin").GetData(fEVAbin);
115  topBranch.GetChild("ElectricField").GetData(fElectricField);
116  topBranch.GetChild("UseMGMR").GetData(fUseMGMR);
117  string sPrim;
118  topBranch.GetChild("Primary").GetData(sPrim);
119  fPrim = sPrim == "Proton" ? eProton : eIron;
120  string sCoreZPosition;
121  topBranch.GetChild("CoreZPosition").GetData(sCoreZPosition);
122  fCoreZPosition = sCoreZPosition == "MAXIMA" ? eMAXIMA : (sCoreZPosition == "AERA" ? eAERA : eAuto);
123  topBranch.GetChild("MaxAntennaDistanceFromCore").GetData(fMaxAntennaDistanceFromCore);
124  info.str("");
125  info << " \n-------RdEVASimPreparator::Init \n";
126  info << " WorkingDir : " << fWorkingDir << "\n";
127  info << " EVA : " << fPathToEVA << "/" << fEVAbin << "\n";
128 
129 
130  INFO(info.str());
131 
132  return VModule::eSuccess;
133  }
134 
135  VModule::ResultFlag RdEVASimPreparator::Run(Event& theevent) {
136  stringstream eventidreader;
137  string EVAsim,EVAscript;
138  vector<string> v_detectorfiles;
139  const Header& head=theevent.GetHeader();
140 
141  evt::ShowerRecData& zeShower=theevent.GetRecShower();
142 
143  EVAsim=EVAFileWriter(zeShower,head,theevent);
144  EVAscript=CreateBashScriptEVASim();
145 
146  return VModule::eSuccess;
147  }
148 
149  VModule::ResultFlag RdEVASimPreparator::Finish() {
150  INFO("RdEVASimPreparator::Finish()");
151  return VModule::eSuccess;
152  }
153 
154  string RdEVASimPreparator::EVAFileWriter(evt::ShowerRecData& show, const Header& head, Event& theevent) {
155  ostringstream filename;
156 
157  // Get the radio detector data for later reference
158  Detector& Det = Detector::GetInstance();
159  const rdet::RDetector& RadioDet = Det.GetRDetector();
160 
161  // The reference coordinate system of the detector (usually PampaAmarilla)
162  // is only used to keep the information about
163  // the shower's location. Not actually used in the simulations.
164  const CoordinateSystemPtr referenceCS = Det.GetReferenceCoordinateSystem();
165 
166  // If the Z-position wasn't provided we will set the stations relative to a manually specified station
167  if (fCoreZPosition == eAERA) {
168  cout << "Setting the core position relative to AERA station 13! Overriding the old value for the Z-core position!" << endl;
170  show.GetSRecShower().GetCorePosition().GetX(referenceCS),
171  show.GetSRecShower().GetCorePosition().GetY(referenceCS),
172  RadioDet.GetStation(113).GetPosition().GetZ(referenceCS)/meter, // Z-position of Station AERA 13
173  referenceCS
174  ));
175  } else if (fCoreZPosition == eMAXIMA) {
176  cout << "Setting the core position relative to MAXIMA station 4! Overriding the old value for the Z-core position!" << endl;
178  show.GetSRecShower().GetCorePosition().GetX(referenceCS),
179  show.GetSRecShower().GetCorePosition().GetY(referenceCS),
180  RadioDet.GetStation(10).GetPosition().GetZ(referenceCS)/meter, // Z-position of Station MAXIMA 4
181  referenceCS
182  ));
183  }
184 
185  // UTM coordinate system to determine the height above sea level
186  UTMPoint utmpositionCore(show.GetSRecShower().GetCorePosition(),ReferenceEllipsoid::GetWGS84());
187  //const ReferenceEllipsoid& elliposewgs84=ReferenceEllipsoid::GetWGS84();
188  double HeightUTM = utmpositionCore.GetHeight()/meter;
189 
190  // Core coordinate system. The so called 'local' coordinate system to determine
191  // the Zenith and the Azimuth of the shower as well as the local zenith and local
192  // azimuth of the earth magnetic field
193  /* create coreCS */
194  const evt::ShowerRecData& zeShower=theevent.GetRecShower();
195  const utl::Point& ShowerCore = zeShower.GetSRecShower().GetCorePosition();
196  const CoordinateSystemPtr coreCS = fwk::LocalCoordinateSystem::Create(ShowerCore);
197  /* use the coreCS to determine the local zenith and azimuth directions */
198  double AxisZenith = show.GetSRecShower().GetAxis().GetTheta(coreCS)/degree;
199  double AxisAzimuth = show.GetSRecShower().GetAxis().GetPhi(coreCS)/degree;
200  double MagneticZenith = fMagneticField.GetTheta(coreCS)/degree;
201  double MagneticAzimuth = fMagneticField.GetPhi(coreCS)/degree;
202  double MagneticStrength = fMagneticField.GetMag()/(micro*tesla);
203 
204  /* use the coreCS to determine the core position as a reference */
205  double XCoreReference = ShowerCore.GetX(referenceCS)/meter;
206  double YCoreReference = ShowerCore.GetY(referenceCS)/meter;
207  double ZCoreReference = ShowerCore.GetZ(referenceCS)/meter;
208 
209  // Other relevant shower porameters
210  int gps_seconds = head.GetTime().GetGPSSecond();
211  int gps_nanoseconds = head.GetTime().GetGPSNanoSecond();
212  double primary_energy = show.GetSRecShower().GetEnergy();
213 
214 
215  filename.str("");
216  long int event_id(0);
217  if (theevent.HasSEvent()) {
218  // Ideally the event id should be stored in the SEvent header
219  event_id = theevent.GetSEvent().GetHeader().GetId();
220  } else if (theevent.HasREvent()) {
221  // But it is possible that there is no real SEvent
222  // fallback option if the general id is not available
223  event_id = theevent.GetREvent().GetHeader().GetId();
224  } else {
225  WARNING("No event id seems to be stored anywhere. We are making up some number for you.");
226  event_id = ++unknown_id;
227  }
228  filename << (fUseMGMR ? "MGMR-" : "EVA-") << event_id;
229  string nameWithoutSuffix(filename.str());
230  filename << ".inp";
231  ofstream EVAFile((fWorkingDir+string("/")+filename.str()).c_str(),std::ios_base::out);
232 
233  EVAFile << std::scientific;
234  EVAFile << "set name " << event_id << "\n";
235  EVAFile << "set thin " << "4" << "\n";
236  EVAFile << "set initial " << (fPrim == eProton ? "proton" : (fPrim == eIron ? "iron" : "unknown")) << "\n";
237  EVAFile << "set eprim " << primary_energy/(exa*electronvolt) << "\n";
238  EVAFile << "set shzen " << AxisZenith << "\n";
239  EVAFile << "set shazi " << AxisAzimuth << "\n";
240  EVAFile << "set hground " << HeightUTM << "\n";
241  /* Thes values ximpact and yimpact do not necessarily need to
242  be zero but for offline this is the most convenient choice */
243  EVAFile << "set ximpact " << 0.0 << "\n";
244  EVAFile << "set yimpact " << 0.0 << "\n";
245  /* In some cases, but not implemented in offline, zimpact can
246  be non zero when we have to deal with horizontal showers that
247  skim the earth's surface */
248  EVAFile << "set zimpact " << 0.0 << "\n";
249  EVAFile << "set bgeomag " << MagneticStrength << "\n";
250  EVAFile << "set geozen " << MagneticZenith << "\n";
251  EVAFile << "set geoazi " << MagneticAzimuth << "\n";
252  EVAFile << "extra gpssec " << gps_seconds << "\n";
253  EVAFile << "extra gpsnsec " << gps_nanoseconds << "\n";
254  EVAFile << "extra refcoordx " << XCoreReference << "\n";
255  EVAFile << "extra refcoordy " << YCoreReference << "\n";
256  EVAFile << "extra refcoordz " << ZCoreReference << "\n";
257 
258  ofstream aeralist;
259  vector<string> v_filelist;
260 
261  for (rdet::RDetector::StationIterator rdIt = RadioDet.StationsBegin(); rdIt!=RadioDet.StationsEnd(); ++rdIt) {
262  if (!rdIt->IsInGrid()) {
263  cout << "Antenna not in grid!" << endl;
264  continue;
265  }
266  utl::Point StationPosition = rdIt->GetPosition();
267  utl::Vector VecAntenna=StationPosition-ShowerCore;
268  if (VecAntenna.GetR(coreCS)>fMaxAntennaDistanceFromCore) {
269  cout << "Antenna too far away from core!" << endl;
270  continue;
271  }
272 
273  EVAFile << "set continue yes\n";
274  EVAFile << "set antenna " << rdIt->GetName() << "\n";
275  EVAFile << "set antennax " << VecAntenna.GetX(coreCS)/meter << "\n";
276  EVAFile << "set antennay " << VecAntenna.GetY(coreCS)/meter << "\n";
277  EVAFile << "set antennaz " << VecAntenna.GetZ(coreCS)/meter << "\n";
278  EVAFile << "set refindex " << 1.0 << endl;
279  }
280  EVAFile << "set continue no\n";
281 
282  EVAFile.close();
283 
284  return filename.str();
285  }
286 
287 
289  string RdEVASimPreparator::CreateBashScriptEVASim() {
290  return string("no filename yet...");
291  }
292 
293 
294 } // namespace
Branch GetTopBranch() const
Definition: Branch.cc:63
boost::transform_iterator< InternalStationFunctor, InternalStationIterator, const Station & > StationIterator
StationIterator returns a pointer to a station.
Definition: RDetector.h:61
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
const double tesla
Definition: GalacticUnits.h:40
evt::Header & GetHeader()
Interface class to access Shower Reconstructed parameters.
Definition: ShowerRecData.h:33
double GetR(const CoordinateSystemPtr &coordinateSystem) const
radius r in spherical coordinates coordinates (distance to origin)
Definition: BasicVector.h:257
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
StationIterator StationsEnd() const
End of the collection of pointers to commissioned stations.
Definition: RDetector.h:68
ShowerRecData & GetRecShower()
StationIterator StationsBegin() const
Beginning of the collection of pointers to commissioned stations.
Definition: RDetector.h:64
const double meter
Definition: GalacticUnits.h:29
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
int GetId() const
Definition: SEvent/Header.h:20
void Init()
Initialise the registry.
revt::REvent & GetREvent()
vector< t2list > out
output of the algorithm: a list of clusters
Definition: XbAlgo.cc:32
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
bool HasREvent() const
double GetMag() const
Definition: Vector.h:58
ShowerSRecData & GetSRecShower()
const utl::TimeStamp & GetTime() const
Definition: Event/Header.h:33
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Definition: Branch.h:107
Reference ellipsoids for UTM transformations.
constexpr double exa
Definition: AugerUnits.h:76
double GetHeight() const
Get the height.
Definition: UTMPoint.h:212
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
CoordinateSystemPtr GetRodrigoCS()
constexpr double kPiOnTwo
Definition: MathConstants.h:25
const utl::Vector & GetAxis() const
const CoordinateSystemPtr GetECEF() const
Get the ECEF.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
double GetEnergy() const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
boost::tokenizer< boost::char_separator< char > > mytok
std::string EVAFileWriter(evt::ShowerRecData &show, const evt::Header &head, evt::Event &theevent)
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
double GetGPSNanoSecond() const
GPS nanosecond.
Definition: TimeStamp.h:127
utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const
Get the reference coordinate system used for analysis (usually PampaAmarilla for Auger) ...
Definition: Detector.h:141
Vector object.
Definition: Vector.h:30
const utl::Point & GetCorePosition() const
void SetCorePosition(const utl::Point &core)
sevt::Header & GetHeader()
Definition: SEvent.h:155
constexpr double micro
Definition: AugerUnits.h:65
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
char * filename
Definition: dump1090.h:266
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
constexpr double nano
Definition: AugerUnits.h:64
constexpr double m
Definition: AugerUnits.h:121
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
sevt::SEvent & GetSEvent()
bool HasSEvent() const
int GetId() const
Definition: REvent/Header.h:21
Global event header.
Definition: Event/Header.h:27
constexpr double electronvolt
Definition: AugerUnits.h:172

, generated on Tue Sep 26 2023.