testCorsikaShowerFile.cc
Go to the documentation of this file.
1 
9 #include <io/CorsikaShowerFile.h>
10 #include <io/CorsikaBlock.h>
11 #include <io/CorsikaIOException.h>
12 #include <io/IoCodes.h>
13 #include <evt/Event.h>
14 #include <evt/ShowerSimData.h>
15 #include <utl/AugerUnits.h>
16 #include <utl/Particle.h>
17 #include <utl/ShowerParticleIterator.h>
18 #include <utl/UTCDateTime.h>
19 
20 //#include <fwk/CoordinateSystemRegistry.h>
21 #include <fwk/CentralConfig.h>
22 
23 #include <det/Detector.h>
24 
25 #include <tst/Verify.h>
26 #include <cppunit/extensions/HelperMacros.h>
27 
28 #include <iostream>
29 #include <iomanip>
30 #include <string>
31 
32 using io::Corsika::Block;
34 using tst::Expected;
35 using namespace fwk;
36 using namespace utl;
37 using namespace tst;
38 
39 using std::endl;
40 using std::cerr;
41 
42 class testCorsikaShowerFile : public CppUnit::TestFixture {
43 
44  CPPUNIT_TEST_SUITE(testCorsikaShowerFile);
45  CPPUNIT_TEST(testConstruct);
46  CPPUNIT_TEST_EXCEPTION(testConstructException, io::CorsikaIOException);
47  CPPUNIT_TEST(testOpen);
48  CPPUNIT_TEST_EXCEPTION(testOpenOpen, io::CorsikaIOException);
49  CPPUNIT_TEST_EXCEPTION(testOpenNonExisting, io::CorsikaIOException);
50  CPPUNIT_TEST_EXCEPTION(testOpenForWrite, io::CorsikaIOException);
51  CPPUNIT_TEST(testClose);
52  CPPUNIT_TEST(testCloseClose);
53  CPPUNIT_TEST_EXCEPTION(testWrite, io::CorsikaIOException);
54  CPPUNIT_TEST(testFindEvent);
55  CPPUNIT_TEST(testGotoPosition);
56  CPPUNIT_TEST(testGetNEvents);
57  CPPUNIT_TEST(testRead);
58  CPPUNIT_TEST(testParticleRead);
59  CPPUNIT_TEST(testCherenkovShower);
60  CPPUNIT_TEST_EXCEPTION(testGetNEventsClosedException,
62  CPPUNIT_TEST_SUITE_END();
63 
64 public:
65  // shared data for tests
66 
69 
70  void setUp()
71  {
72  f = new CorsikaShowerFile();
73  event = evt::Event();
74  }
75 
76  void tearDown()
77  {
78  delete f;
79  }
80 
82  {
84  CentralConfig::GetInstance(BOOTSTRAPFILE);
85  det::Detector& theDet = det::Detector::GetInstance();
86  theDet.Update(utl::UTCDateTime(2000,4,1,1).GetTimeStamp()); // any reasonable time will do for the magnetic field model
87  CPPUNIT_ASSERT(file = new CorsikaShowerFile(TESTFILE));
88  delete file;
89  }
90 
92  {
93  Expected();
94  CorsikaShowerFile f(TESTFILE, io::eWrite);
95  }
96 
97  void testOpen()
98  {
99  f->Open(TESTFILE);
100  }
101 
103  {
104  Expected();
105  f->Open("NoSuchCorsikaShowerFile.part");
106  }
107 
109  {
110  f->Open(TESTFILE);
111  Expected();
112  f->Open(TESTFILE);
113  }
114 
116  {
117  Expected();
118  f->Open(TESTFILE, io::eWrite);
119  }
120 
121  void testClose()
122  {
123  f->Close();
124  }
125 
127  {
128  f->Close();
129  Expected();
130  f->Close();
131  }
132 
134  {
135  f->Open(TESTFILE);
136  CPPUNIT_ASSERT(f->FindEvent(2) != io::eFail);
137  CPPUNIT_ASSERT(f->FindEvent(0) == io::eFail);
138  }
139 
141  {
142  f->Open(TESTFILE);
143  CPPUNIT_ASSERT(f->GotoPosition(0) != io::eFail);
144  CPPUNIT_ASSERT(f->GotoPosition(2) == io::eFail);
145  }
146 
147  void testWrite()
148  {
149  f->Open(TESTFILE);
150  Expected();
151  f->Write(event);
152  }
153 
155  {
156  f->Open(TESTFILE);
157  CPPUNIT_ASSERT(f->GetNEvents() == 2);
158  }
159 
161  {
162  Expected();
163  f->GetNEvents();
164  }
165 
166  void testRead()
167  {
168  f->Open(TESTFILE);
169  int nEventsInFile = f->GetNEvents();
170  int nEventsSeen = 0;
171  while (f->Read(event) != io::eEOF) {
172  ++nEventsSeen;
173 
174  evt::ShowerSimData& shower = event.GetSimShower();
175 
176  const CoordinateSystemPtr refCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
177  shower.MakeGeometry(utl::Point(0,0,0,refCS));
178 
179  CPPUNIT_ASSERT(Verify<Equal>(shower.GetPrimaryParticle(),
180  int(Particle::eProton)));
181  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetEnergy()/eV, 1.e20));
182 
183  const utl::CoordinateSystemPtr localCS = shower.GetLocalCoordinateSystem();
184  const double zenith = (-shower.GetDirection()).GetTheta(localCS);
185  const double azimuth = (-shower.GetDirection()).GetPhi(localCS);
186 
187  // Test shower has: Zenith=32.42 deg, Azimuth=325.59 deg,
188  // Note: azimuth is already corrected by 180deg (incoming vs. outgoing)
189  // AARANG: 0
190 
191  CPPUNIT_ASSERT(Verify<CloseTo>(zenith/deg, 32.42));
192  CPPUNIT_ASSERT(Verify<CloseTo>(azimuth/deg, 325.59+90.-4.233-360));
193  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetMinRadiusCut(), // set in THIN parameter of CorsikaTest.inp
194  101.*cm));
195  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerNumber(),
196  nEventsSeen));
197  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerRunId(), std::string("1")));
198 
199  event = evt::Event(); // clear
200  }
201 
202  CPPUNIT_ASSERT(Verify<Equal>(nEventsInFile, nEventsSeen));
203  }
204 
206  {
207 
208  f->Open(TESTFILE);
209  for (int i = 0; i < f->GetNEvents(); ++i) {
210  event=evt::Event(); // clear event until readers do it.
211  f->Read(event);
212  evt::ShowerSimData& shower = event.GetSimShower();
213 
214  shower.MakeGeometry(Point(0, 0, 0,
215  det::Detector::GetInstance().GetSiteCoordinateSystem()));
216 
217  long double nParticles = 0;
219  p != shower.GroundParticlesEnd();
220  ++p) {
221  nParticles += p->GetWeight();
222  }
223  CPPUNIT_ASSERT(nParticles > 1e11);
224  CPPUNIT_ASSERT(nParticles < 1e12);
225  }
226  }
227 
229  {
230  f->Open(TESTFILE2);
231  int nEventsInFile = f->GetNEvents();
232  int nEventsSeen = 0;
233 
234  f->SetReadLongFile(false);
235 
236  while (f->Read(event) != io::eEOF) {
237  ++nEventsSeen;
238 
239  evt::ShowerSimData& shower = event.GetSimShower();
240 
241  const CoordinateSystemPtr refCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
242  shower.MakeGeometry(utl::Point(0,0,0,refCS));
243 
244  CPPUNIT_ASSERT(Verify<Equal>(shower.GetPrimaryParticle(),
245  int(Particle::eProton)));
246  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetEnergy()/GeV, 6952381.7620710116));
247 
248  const utl::CoordinateSystemPtr localCS = shower.GetLocalCoordinateSystem();
249  const double zenith = (-shower.GetDirection()).GetTheta(localCS);
250  const double azimuth = (-shower.GetDirection()).GetPhi(localCS);
251 
252  // Zenith=25.2917 deg, Azimuth=239.904 deg
253  // Note: azimuth is already corrected by 180deg (incoming vs. outgoing)
254  // AARANG: -85.767 deg
255 
256  CPPUNIT_ASSERT(Verify<CloseTo>(zenith/deg, 25.291737580210896));
257  // azimuth is corrected for: geomagnetic north direction, CORSIKA 180deg rotation of arrival direction
258  CPPUNIT_ASSERT(Verify<CloseTo>(azimuth/deg, 239.904454153400025+90-4.233-360));
259  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerNumber(), nEventsSeen));
260 
261  event = evt::Event(); // clear
262  }
263 
264  CPPUNIT_ASSERT(Verify<Equal>(nEventsInFile, nEventsSeen));
265  }
266 
267 };
268 
269 
271 
272 
273 // Configure (x)emacs for this file ...
274 // Local Variables:
275 // mode: c++
276 // compile-command: "make -C .. -k testCorsika && (cd ..; testCorsika)"
277 // End:
278 
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger coordinate system associated to the shower core position.
const double eV
Definition: GalacticUnits.h:35
int GetPrimaryParticle() const
Get the type of the shower primary particle.
Definition: ShowerSimData.h:84
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
Iterator to retrieve particles from utl::VShowerParticlList.
Point object.
Definition: Point.h:32
utl::ShowerParticleIterator GroundParticlesEnd() const
double GetMinRadiusCut() const
Get the minimum radius from shower axis for which there are valid particles in the shower...
Read Only access.
Definition: IoCodes.h:18
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
constexpr double deg
Definition: AugerUnits.h:140
Interface class to access Shower Simulated parameters.
Definition: ShowerSimData.h:49
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
int GetShowerNumber() const
Get the number of the shower in the file.
Definition: ShowerSimData.h:72
const utl::Vector & GetDirection() const
Get the direction of the shower axis. This is the true direction of shower movement.
Base for exceptions in the CORSIKA reader.
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
void Expected()
Print `Expected&#39; for expected failures.
Definition: Verify.h:85
Read data from the output of CORSIKA.
double GetEnergy() const
Get the energy of the shower primary particle.
Definition: ShowerSimData.h:89
const string file
BasicBlock< ParticleData, CherenkovData, kParticlesInBlock, 39 > Block
Definition: CorsikaBlock.h:443
constexpr double GeV
Definition: AugerUnits.h:187
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
std::string GetShowerRunId() const
Get the run id for the shower.
Definition: ShowerSimData.h:78
void MakeGeometry(const utl::Point &pointOnShowerAxis)
initialize the shower geometry. Pos is a point on the shower axis, but not necessarily the core ...
constexpr double cm
Definition: AugerUnits.h:117
utl::ShowerParticleIterator GroundParticlesBegin() const

, generated on Tue Sep 26 2023.