SenecaShowerFile.cc
Go to the documentation of this file.
1 
9 #include "SenecaShowerFile.h"
10 
11 #include <evt/Event.h>
12 #include <evt/ShowerSimData.h>
13 #include <evt/DefaultShowerGeometryProducer.h>
14 
15 #include <utl/AugerException.h>
16 #include <utl/ErrorLogger.h>
17 #include <utl/Math.h>
18 
19 #include <string>
20 #include <fstream>
21 #include <iostream>
22 
23 using namespace evt;
24 using namespace io;
25 using namespace utl;
26 using namespace std;
27 
28 
29 namespace io {
30 
31  SenecaShowerFile::SenecaShowerFile()
32  {
33  fSenecaParticleIterator.SetSenecaFileParser(&fFileParser);
34  }
35 
36 
37  SenecaShowerFile::SenecaShowerFile(const std::string& fileName, const io::Mode mode, utl::Branch* const b)
38  {
39  fSenecaParticleIterator.SetSenecaFileParser(&fFileParser);
40  Open(fileName, mode, b);
41  }
42 
43 
44  void
45  SenecaShowerFile::Open(const std::string& fileName, const io::Mode mode, utl::Branch* const /*b*/)
46  {
47  const io::Status check = fFileParser.OpenSenecaFile(fileName, mode);
48  if (check != eSuccess) {
49  const string msg = "Seneca IO Exception: Could not open " + fileName;
50  throw utl::IOFailureException(msg);
51  }
52  }
53 
54 
55  void
56  SenecaShowerFile::Close()
57  {
58  fFileParser.CloseSenecaFile();
59  }
60 
61 
62  Status
63  SenecaShowerFile::Read(evt::Event& event)
64  {
65  Status check = fFileParser.FileStatus();
66  if (check != eSuccess)
67  return check;
68 
69  if (!event.HasSimShower()) {
70  const double rotationZ = utl::kPi; // Seneca phi-angle is "incoming" not "outgoing"
71  event.MakeSimShower(DefaultShowerGeometryProducer(rotationZ));
72  } else {
73  ERROR("ShowerSimData already exists. Cannot read seneca.");
74  return eFail;
75  }
76 
77  evt::ShowerSimData& shower = event.GetSimShower();
78  check = fFileParser.GetNextEvent();
79  if (check != eSuccess)
80  return check;
81 
82  SenecaEventHeaderRecord* const eventHeader = fFileParser.GetCurrentEventHeader();
83  if (!eventHeader)
84  return eFail;
85 
86  shower.SetPrimaryParticle(SenecaParticleIDToAuger(eventHeader->ID0));
87  shower.SetEnergy(eventHeader->E0 * GeV);
89  shower.SetGroundParticleCoordinateSystemAzimuth(eventHeader->Phi);
90 
91  ostringstream info;
92  info << "SenecaShowerFile" << eventHeader->Theta/degree << ' ' << eventHeader->Phi/degree;
93  INFO(info);
94  shower.SetShowerNumber(fFileParser.GetCurrentEvent());
95  shower.SetShowerRunId("1");
96 
97  if (!shower.HasGroundParticles())
98  shower.MakeGroundParticles();
99 
100  if (CreateSenecaFileParticleIterator() != eSuccess)
101  return eFail;
102 
103  shower.GetGroundParticles().SetFileInterface(&fSenecaParticleIterator);
104 
105  return eSuccess;
106  }
107 
108 
109  void
110  SenecaShowerFile::Write(const evt::Event& /*event*/)
111  {
112  const string msg = "Seneca IO Exception: Cannot write to Seneca files.\n";
113  throw utl::IOFailureException(msg);
114  }
115 
116 
117  Status
118  SenecaShowerFile::FindEvent(const unsigned int eventId)
119  {
120  return fFileParser.GotoEvent(eventId);
121  }
122 
123 
124  Status
125  SenecaShowerFile::GotoPosition(const unsigned int position)
126  {
127  return fFileParser.GotoPosition(position);
128  }
129 
130 
131  int
132  SenecaShowerFile::GetNEvents()
133  {
134  return fFileParser.GetNumberEvents();
135  }
136 
137 
138  Status
139  SenecaShowerFile::CreateSenecaFileParticleIterator()
140  {
141  return fSenecaParticleIterator.SetSenecaFileParser(&fFileParser);
142  }
143 
144 
145  int
146  SenecaShowerFile::SenecaParticleIDToAuger(const int senecaID)
147  {
148  int particleID = utl::Particle::eUndefined;
149  switch (senecaID) {
150  case 10:
151  particleID = utl::Particle::ePhoton;
152  break;
153  case 12:
154  particleID = utl::Particle::eElectron;
155  break;
156  case -12:
157  particleID = utl::Particle::ePositron;
158  break;
159  case 14:
160  particleID = utl::Particle::eMuon;
161  break;
162  case -14:
163  particleID = utl::Particle::eAntiMuon;
164  break;
165  case 110:
166  particleID = utl::Particle::ePiZero;
167  break;
168  case 120:
169  particleID = utl::Particle::ePiPlus;
170  break;
171  case -120:
172  particleID = utl::Particle::ePiMinus;
173  break;
174  case 220:
175  particleID = utl::Particle::eEta;
176  break;
177  case 130:
178  particleID = utl::Particle::eKaonPlus;
179  break;
180  case -130:
181  particleID = utl::Particle::eKaonMinus;
182  break;
183  case 230:
184  particleID = utl::Particle::eUndefined;
185  break;
186  case -230:
187  particleID = utl::Particle::eUndefined;
188  break;
189  case 330:
190  particleID = utl::Particle::eUndefined;
191  break;
192  case 1120:
193  particleID = utl::Particle::eProton;
194  break;
195  case 1220:
196  particleID = utl::Particle::eNeutron;
197  break;
198  case 1130:
199  particleID = utl::Particle::eUndefined;
200  break;
201  case 1230:
202  particleID = utl::Particle::eUndefined;
203  break;
204  case 2130:
205  particleID = utl::Particle::eLambda;
206  break;
207  }
208  return particleID;
209  }
210 
211 }
const double degree
bool HasGroundParticles() const
bool HasSimShower() const
Mode
Available open modes.
Definition: IoCodes.h:16
void SetGroundParticleCoordinateSystemAzimuth(const double azimuth)
Set the azimuth angle of the shower. Angle in x-y plane wrt. to the x axis (0 is from east)...
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
Base class to report exceptions in IO.
void SetFileInterface(VShowerFileParticleIterator *const interface)
Interface class to access Shower Simulated parameters.
Definition: ShowerSimData.h:49
Class representing a document branch.
Definition: Branch.h:107
Status
Return code for seek operation.
Definition: IoCodes.h:24
constexpr double kPi
Definition: MathConstants.h:24
void SetEnergy(const double theEnergy)
Set the energy of the shower primary particle.
Definition: ShowerSimData.h:91
utl::ShowerParticleList & GetGroundParticles()
Get particle list Proxy.
void SetPrimaryParticle(const int type)
Set the type of the shower primary particle.
constexpr double GeV
Definition: AugerUnits.h:187
void SetGroundParticleCoordinateSystemZenith(const double zenith)
Set the zenith angle of the shower. Room angle between z-axis and direction from where the shower is ...
void SetShowerNumber(const int sid)
Definition: ShowerSimData.h:75
void SetShowerRunId(const std::string srid)
Definition: ShowerSimData.h:81
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.