RdCOREASSimulationCreator.cc
Go to the documentation of this file.
1 #include <fwk/CentralConfig.h>
2 #include <utl/Reader.h>
3 #include <utl/ErrorLogger.h>
4 #include <utl/Reader.h>
5 #include <fwk/VModule.h>
6 #include <fwk/MagneticFieldModel.h>
7 #include <evt/Event.h>
8 
9 #include <evt/ShowerRecData.h>
10 #include <evt/ShowerSRecData.h>
11 
12 #include <revt/Station.h>
13 
14 #include <utl/TimeStamp.h>
15 #include <utl/AugerUnits.h>
16 #include <det/Detector.h>
17 #include <rdet/RDetector.h>
18 
19 #include <fwk/LocalCoordinateSystem.h>
20 #include <fwk/CoordinateSystemRegistry.h>
21 
22 #include <sstream>
23 #include <iomanip>
24 
25 #include <utl/Point.h>
26 #include <utl/UTMPoint.h>
27 #include <utl/ReferenceEllipsoid.h>
28 
30 
31 using namespace fwk;
32 using namespace utl;
33 using namespace evt;
34 using namespace det;
35 using namespace rdet;
36 using namespace std;
37 
38 
40 
42  fInfoLevel(eFinal)
43  {
44  }
45 
46  RdCOREASSimulationCreator::~RdCOREASSimulationCreator()
47  {
48  }
49 
51  {
52  INFO("RdCOREASSimulationCreator::Init()");
53 
54  Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdCOREASSimulationCreator");
55 
56  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
57  topBranch.GetChild("CorsikaDirectory").GetData(fCorsikaDirectory);
58  topBranch.GetChild("CorsikaBinary").GetData(fCorsikaBinary);
59  topBranch.GetChild("FlukaDirectory").GetData(fFlukaDirectory);
60  topBranch.GetChild("DataDirectory").GetData(fDataDirectory);
61  topBranch.GetChild("InputSource").GetData(fInputSource);
62  topBranch.GetChild("CorsikaUser").GetData(fCorsikaUser);
63 
64  Branch models = topBranch.GetChild("Showers");
65 
66  for (Branch curmodel = models.GetFirstChild(); curmodel; curmodel = curmodel.GetNextSibling()) {
67  if (curmodel.GetName() == "Shower") {
68  simparams* shower = new simparams();
69  for(Branch curp = curmodel.GetFirstChild(); curp; curp = curp.GetNextSibling()) {
70  if(curp.GetName() == "CorsikaDirectory") {
71  curp.GetData(shower->CorsikaDirectory);
72  }
73  if(curp.GetName() == "CorsikaBinary") {
74  curp.GetData(shower->CorsikaBinary);
75  }
76  if(curp.GetName() == "FlukaDirectory") {
77  curp.GetData(shower->FlukaDirectory);
78  }
79  if(curp.GetName() == "DataDirectory") {
80  curp.GetData(shower->DataDirectory);
81  }
82  if(curp.GetName() == "Run") {
83  curp.GetData(shower->Run);
84  }
85  if(curp.GetName() == "Seed1") {
86  curp.GetData(shower->Seed1);
87  }
88  if(curp.GetName() == "Seed2") {
89  curp.GetData(shower->Seed2);
90  }
91  if(curp.GetName() == "Seed3") {
92  curp.GetData(shower->Seed3);
93  }
94  if(curp.GetName() == "REASSeed") {
95  curp.GetData(shower->REASSeed);
96  }
97  if(curp.GetName() == "PrimaryParticle") {
98  curp.GetData(shower->PrimaryParticle);
99  }
100  if(curp.GetName() == "Energy") {
101  curp.GetData(shower->Energy);
102  }
103  if(curp.GetName() == "Zenith") {
104  curp.GetData(shower->Zenith);
105  }
106  if(curp.GetName() == "Azimuth") {
107  curp.GetData(shower->Azimuth);
108  }
109  if(curp.GetName() == "CoreX") {
110  curp.GetData(shower->CoreX);
111  }
112  if(curp.GetName() == "CoreY") {
113  curp.GetData(shower->CoreY);
114  }
115  if(curp.GetName() == "CoreZ") {
116  curp.GetData(shower->CoreZ);
117  }
118  if(curp.GetName() == "UTCDate") {
119  curp.GetData(shower->UTCDate);
120  cout << "DATE: " << shower->UTCDate << endl;
121  }
122  }
123  fShowers.push_back(shower);
124  }
125  }
126 
127  fShowerIterator = fShowers.begin();
128 
129  return eSuccess;
130 
131  }
132 
133  VModule::ResultFlag RdCOREASSimulationCreator::Run(evt::Event& event) {
134  cout << "Starting simulation creator" << endl;
135  // Detector initialization
136  if(fShowerIterator == fShowers.end())
137  return eBreakLoop;
138  cout << "test" << endl;
139  event.MakeRecShower();
140  event.GetRecShower().MakeSRecShower();
141  ShowerSRecData& shower = event.GetRecShower().GetSRecShower();
142  Detector& Det = Detector::GetInstance();
144  const rdet::RDetector& RadioDet = Det.GetRDetector();
145  const CoordinateSystemPtr coordsys = det::Detector::GetInstance().GetReferenceCoordinateSystem();
146 
147  // Defining coordinates
148  double coreX = (*fShowerIterator)->CoreX * m;
149  double coreY = (*fShowerIterator)->CoreY * m;
150  double coreZ = (*fShowerIterator)->CoreZ * m;
151  int eventid = (*fShowerIterator)->Run;
152  double energy = (*fShowerIterator)->Energy;
153  double theta = (*fShowerIterator)->Zenith;
154  double phi = (*fShowerIterator)->Azimuth;
155 
156  // Defining core
157 
158  Point core(coreX,coreY,coreZ,coordsys);
159  cout << "X : " << core.GetX(coordsys)/m << " Y: " << core.GetY(coordsys)/m << " Z : " << core.GetZ(coordsys)/m << endl;
160  shower.SetCorePosition(core);
162  utl::Vector axis(cos(phi)*sin(theta), sin(phi)*sin(theta), cos(theta),coordsys);
163  shower.SetAxis(axis);
164  shower.SetEnergy(energy, 0);
165  Header& head = event.GetHeader();
166  stringstream ev_id("");
167  ev_id << eventid;
168  head.SetId(ev_id.str().c_str());
169 
170  double date = (*fShowerIterator)->UTCDate;
171  cout << (*fShowerIterator)->UTCDate <<" " << date << endl;
172 
173  const int kGPSEpoch = 315964815;
174  TimeStamp ts((*fShowerIterator)->UTCDate - kGPSEpoch, 0);
175  head.SetTime(ts);
176  det::Detector::GetInstance().Update(head.GetTime());
177 
178  // Writing files
180  ostringstream filename;
181  filename.str("");
182  filename << "RUN";
183  filename << setw(6) << setfill('0');
184  filename << (*fShowerIterator)->Run << ".inp";
185  string corsikaparameterfile = filename.str();
186  ofstream inpfile(((*fShowerIterator)->DataDirectory + "/" + filename.str()).c_str());
187 
188  MagneticFieldModel* siteMagneticField = new MagneticFieldModel(coreCS, date);
189 
190  double az = (atan2(shower.GetAxis().GetY(coreCS),shower.GetAxis().GetX(coreCS)) + siteMagneticField->GetDeclination()) / degree + 90;
191  double zen = acos(shower.GetAxis().GetZ(coreCS)) / degree;
192  UTMPoint utmcore(core,ReferenceEllipsoid::GetWGS84());
193  if (az > 360)
194  az -= 360;
195  inpfile << "RUNNR\t"<< (*fShowerIterator)->Run << endl;
196  inpfile << "EVTNR\t1" << endl;
197 // inpfile << "CORSIKA\tT" << endl;
198 // Put the empty line for coreas
199  inpfile << endl;
200  inpfile << "SEED\t" << (*fShowerIterator)->Seed1 <<"\t0\t0" << endl;
201  inpfile << "SEED\t" << (*fShowerIterator)->Seed2 <<"\t0\t0" << endl;
202  inpfile << "SEED\t" << (*fShowerIterator)->Seed3 <<"\t0\t0" << endl;
203  inpfile << "NSHOW\t1" << endl;
204  inpfile << "ERANGE\t" << shower.GetEnergy() / GeV << "\t" << shower.GetEnergy() / GeV << endl;
205  inpfile << "PRMPAR\t" << (*fShowerIterator)->PrimaryParticle << endl;
206  inpfile << "THETAP\t" << zen << "\t" << zen << endl;
207  inpfile << "PHIP\t"<< az << "\t" << az <<"\n";
208  inpfile << "ECUTS\t3.000E-01\t3.000E-01\t4.010E-04\t4.010E-04\n";
209  inpfile << "ELMFLG\tT\tT\n";
210  inpfile << "THIN\t1.000E-06\t" << shower.GetEnergy() / GeV*1e-6 << "\t0.000E+00\n";
211  inpfile << "THINH\t1.000E+01\t1.000E+02\n";
212  inpfile << "OBSLEV\t"<< utmcore.GetHeight()/cm << endl;
213  inpfile << "ECTMAP\t1.E5" << endl;
214  inpfile << "STEPFC\t1.0" << endl;
215  inpfile << "MUADDI\tT" << endl;
216  inpfile << "MUMULT\tT" << endl;
217  inpfile << "MAXPRT\t1" << endl;
218  inpfile << "MAGNET\t" << siteMagneticField->GetHorizontalComponent() / microtesla << "\t" << siteMagneticField->GetHorizontalComponent() / microtesla << endl;
219  inpfile << "ATMOD\t0\tF" << endl;
220  inpfile << "PAROUT\tF\tF" << endl;
221  inpfile << "LONGI\tT\t5.\tT\tT" << endl;
222  inpfile << "RADNKG\t5.e5" << endl;
223  inpfile << "DIRECT\t" << (*fShowerIterator)->DataDirectory <<"/" << endl;
224  inpfile << "DATBAS\tF" << endl;
225  inpfile << "USER\t" << fCorsikaUser << endl;
226  inpfile << "EXIT\n";
227  inpfile.close();
228 
229  // CoREAS config
230 
231  filename.str("");
232  filename << "SIM";
233  filename << setw(6) << setfill('0');
234  filename << (*fShowerIterator)->Run << ".reas";
235  ofstream reasfile(((*fShowerIterator)->DataDirectory + "/" + filename.str()).c_str());
236  //----------------------------------------------------------------------------------------------
237  //----------------------------------------------------------------------------------------------
238  reasfile <<"# global parameters:\n";
239  reasfile <<"ParameterFileVersion = 22 ; do not change manually\n";
240  reasfile <<"NumParticlesToCalculate = 10000000000\n";
241  reasfile <<"NumSimultaneousParticles = 1000000\n";
242  reasfile <<"RandomSeed = " << (*fShowerIterator)->REASSeed <<" ; -1: chosen randomly, other: chosen manually\n";
243  reasfile <<"AtmosphereModel = 0 ; 0: US Standard, 10: Argentina Winter, 20: Europe January, 30: South Pole March, 90: Constant Density\n";
244  reasfile <<"CurvedGeometry = 0\n";
245  reasfile <<"EarthRadius = 637131500 ; in cm, only used if Curved = 1\n";
246 
247 
248  reasfile <<"\n# parameters setting up the spatial observer configuration:\n\n";
249 
250  reasfile <<"CoreCoordinateNorth = 0 ; in cm\n";
251  reasfile <<"CoreCoordinateWest = 0 ; in cm\n";
252  reasfile <<"CoreCoordinateVertical = " << utmcore.GetHeight() / cm<< " ; in cm\n";
253 // reasfile <<"MaximumRadius = 250000\n";
254 
255  reasfile<<"\n# parameters setting up the temporal observer configuration:\n\n";
256 
257  reasfile<<"TimeLowerBoundary = -1 ; in s, only if AutomaticTimeBoundaries set to 0\n";
258  reasfile<<"TimeUpperBoundary = 1 ; in s, only if AutomaticTimeBoundaries set to 0\n";
259  reasfile<<"TimeResolution = 2e-10 ; in s\n";
260  reasfile<<"GroundLevelRefractiveIndex = 1.000292 ; specify refractive index at 0 m asl\n";
261 
262 
263  reasfile<<"\n# parameters setting the optimisation strategies:\n\n";
264 
265  reasfile<<"AutomaticTimeBoundaries = 4e-07 ; 0: off, x: automatic boundaries with width x in s\n";
266  reasfile<<"ResolutionReductionScale = 5000 ; 0: off, x: decrease time resolution linearly every x cm in radius\n";
267  reasfile<<"AutomaticLambdaEnlargementToggle = 1\n";
268  reasfile<<"AutomaticBinInactivationToggle = 1\n";
269  reasfile<<"ComparisonLowestFrequency = 0 ; in Hz, for automatic groundbin inactivation\n";
270  reasfile<<"ComparisonHighestFrequency = 100000000 ; in Hz, for automatic groundbin inactivation\n";
271  reasfile<<"RequiredRelativePrecision = 0.001 ; in case of automatic groundbin inactivation\n";
272  reasfile<<"SufficientDynamicRange = 0.001 ; in case of automatic groundbin inactivation\n";
273  reasfile<< "NumPrecisionComparisons = 5 ; in case of automatic groundbin inactivation\n";
274  reasfile<<"TrajectoryPointsPerUnitPathDepth = 0\n";
275 
276 
277  reasfile<<"\n# general air shower related parameters:\n\n";
278 
279  reasfile<<"ShowerEvolutionClippingDistance = 100000 ; in cm\n";
280  reasfile<<"MeanPathDepth = 0.05 ; in g/cm^2\n";
281  reasfile<<"PathDepthProjectionToggle = 1 ; backproject path depths appropriately\n";
282 
283 
284 /* reasfile<<"\n# parameters read from CORSIKA files, these are not interpreted by REAS but stated here for your convenience\n\n";
285 
286  reasfile<<"PrimaryParticleEnergy = "<< shower.GetEnergy() / electronvolt <<" ; in eV\n";
287  reasfile<<"ShowerZenithAngle = "<< zen <<" ; in degrees\n";
288  reasfile <<"ShowerAzimuthAngle = "<< az <<" ; in degrees, 0: shower propagates to north, 90: to west\n"; */
289 /*
290  reasfile <<"DepthOfShowerMaximum = 736.2164307 ; slant depth in g/cm^2 (not used in case of CORSIKA histogrammed shower evolution)\n";
291  reasfile <<"MagneticFieldStrength = 0.2312055363 ; in Gauss\n"; //To be set to Malargue
292  reasfile <<"MagneticFieldInclinationAngle = -37.2664019 ; in degrees, >0: in northern hemisphere, <0: in southern hemisphere\n";
293 */
294 
295  reasfile <<"\n# parameters specific to CORSIKA based showers - other parameters are read from the CORSIKA input file:\n\n";
296 
297 // reasfile <<"\nCorsikaFilePath = "<<fWorkingDir <<"/ ; path to the CORSIKA files (cannot include space characters!)\n";
298  reasfile <<"\nCorsikaFilePath = ./ ; path to the CORSIKA files (cannot include space characters!)\n";
299  reasfile <<"CorsikaParameterFile = " << corsikaparameterfile <<"; specify CORSIKA card file\n";
300  reasfile <<"CorsikaSlantOptionToggle = 1 ; set to 1 if CORSIKA option SLANT is used\n";
301  reasfile <<"SelectedCorsikaShower = 1 ; 0: averaged, i: i-th shower\n";
302  reasfile<<"ShowerEvolutionShift = 0 ; apply slant depth shift to CORSIKA-derived shower evolution, in g/cm^2\n";
303 
304 /* reasfile <<"\n# parameters related to electric field effects:\n\n";
305 
306  reasfile <<"ElectricFieldToggle = 0 ;\n ";
307  reasfile <<"ElectricFieldStrength ="<< fElectricField <<" ; in V/m\n";
308  reasfile <<"ElectricFieldInclinationAngle = 90 ; in degrees, 90: field points downwards\n";
309  reasfile <<"ElectricFieldAzimuthAngle = 0 ; in degrees, 90: field points westwards\n";
310 */
311  reasfile <<"\n# parameters not used by REAS but needed for read-in to Offline\n";
312 
313  reasfile <<"EventNumber = "<< eventid << "\n";
314  reasfile <<"GPSSecs = "<< head.GetTime().GetGPSSecond() << "\n";
315  reasfile <<"GPSNanoSecs = "<< head.GetTime().GetGPSNanoSecond() << "\n";
316  reasfile <<"CoreEastingOffline = " << shower.GetCorePosition().GetX(coordsys) / meter << "; in meters\n";
317  reasfile <<"CoreNorthingOffline = " << shower.GetCorePosition().GetY(coordsys) / meter << "; in meters\n";
318  reasfile <<"CoreVerticalOffline = " << shower.GetCorePosition().GetZ(coordsys) / meter << "; in meters\n";
319  reasfile <<"RotationAngleForMagfieldDeclination = " << siteMagneticField->GetDeclination() / degree << "; in degrees\n";
320 
321  //-------------------------------------------------------------------------
322  //--------------------------------------------------------------------------
323  reasfile.close();
324 
325  filename.str("");
326  filename << "SIM";
327  filename << setw(6) << setfill('0');
328  filename << (*fShowerIterator)->Run << ".list";
329  ofstream reaslist(((*fShowerIterator)->DataDirectory + "/" + filename.str()).c_str());
330 
331  for (rdet::RDetector::StationIterator rdIt = RadioDet.StationsBegin(); rdIt != RadioDet.StationsEnd(); ++rdIt) {
332  if (!rdIt->IsInGrid())
333  continue;
334  Point Position = rdIt->GetPosition();
335  Vector VecAntenna = Position - core;
336 
337  double antX = Position.GetX(coreCS);
338  double antY = Position.GetY(coreCS);
339  double antZ = utmcore.GetHeight() + Position.GetZ(coreCS);
340  double rotX = cos(siteMagneticField->GetDeclination()) * antX - sin(siteMagneticField->GetDeclination()) * antY;
341  double rotY = sin(siteMagneticField->GetDeclination()) * antX + cos(siteMagneticField->GetDeclination()) * antY;
342 
343  reaslist << "AntennaPosition = "<< rotY / cm << " " << -rotX / cm << " " << antZ / cm << " " << rdIt->GetName() << endl;
344  }
345 
346  reaslist.close();
347 
348  ++fShowerIterator;
349 
350  return VModule::eSuccess;
351  }
352 
353  VModule::ResultFlag RdCOREASSimulationCreator::Finish() {
354  INFO("RdCOREASSimulationCreator::Finish()");
355  return eSuccess;
356  }
357 
358 
359 }
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
void Update(const utl::TimeStamp &time, const bool invData=true, const bool invComp=true, const bool forceRadio=false)
Update detector: deletes currently constructed stations and sets new time.
Definition: Detector.cc:179
const double degree
Point object.
Definition: Point.h:32
Report success to RunController.
Definition: VModule.h:62
Interface class to access to the SD Reconstruction of a Shower.
void SetTime(const utl::TimeStamp &t)
Definition: Event/Header.h:38
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
CoordinateSystemPtr GetCoordinateSystem() const
Get the coordinate system of the current internal representation.
Definition: BasicVector.h:234
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
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
int fInfoLevel
xml settings: info level (verbosity)
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
const utl::TimeStamp & GetTime() const
Definition: Event/Header.h:33
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
void SetId(const std::string &id)
Set the event identifier.
Definition: Event/Header.h:36
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Definition: Branch.h:107
Break current loop. It works for nested loops too!
Definition: VModule.h:66
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
void SetAxis(const utl::Vector &axis)
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
const utl::Vector & GetAxis() const
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
constexpr double microtesla
Definition: AugerUnits.h:250
double GetEnergy() const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
constexpr double GeV
Definition: AugerUnits.h:187
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
double GetGPSNanoSecond() const
GPS nanosecond.
Definition: TimeStamp.h:127
constexpr double cm
Definition: AugerUnits.h:117
Vector object.
Definition: Vector.h:30
Get the magnetic field of the earth dependent on location and time.
TimeStamp GetCurrentSystemTime()
get current time as reported by system
Definition: TimeStamp.cc:46
const utl::Point & GetCorePosition() const
void SetCorePosition(const utl::Point &core)
const rdet::RDetector & GetRDetector() const
Definition: Detector.cc:143
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
void SetEnergy(const double energy, const double error)
char * filename
Definition: dump1090.h:266
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
constexpr double m
Definition: AugerUnits.h:121
Global event header.
Definition: Event/Header.h:27

, generated on Tue Sep 26 2023.