testArtificialShowerFile.cc
Go to the documentation of this file.
1 #include <io/ArtificialShowerFile.h>
2 #include <evt/Event.h>
3 #include <evt/ShowerSimData.h>
4 #include <utl/AugerException.h>
5 
6 #include <string>
7 #include <fstream>
8 #include <iostream>
9 
10 #include <io/IoCodes.h>
11 #include <evt/Event.h>
12 #include <evt/ShowerSimData.h>
13 #include <utl/AugerUnits.h>
14 #include <utl/Particle.h>
15 #include <utl/ShowerParticleIterator.h>
16 #include <fwk/CentralConfig.h>
17 #include <det/Detector.h>
18 
19 #include <tst/Verify.h>
20 #include <cppunit/extensions/HelperMacros.h>
21 
22 #include <iostream>
23 #include <string>
24 
25 using namespace fwk;
26 using namespace evt;
27 using namespace io;
28 using namespace utl;
29 using namespace std;
30 using namespace tst;
31 using tst::Expected;
32 
33 
34 class testArtificialShowerFile : public CppUnit::TestFixture {
35 
36 private:
37  CPPUNIT_TEST_SUITE(testArtificialShowerFile);
38  CPPUNIT_TEST(testConstruct);
39  CPPUNIT_TEST_EXCEPTION(testConstructException, utl::IOFailureException);
40  CPPUNIT_TEST(testOpen);
41  CPPUNIT_TEST_EXCEPTION(testOpenOpen, utl::IOFailureException);
42  CPPUNIT_TEST_EXCEPTION(testOpenForWrite, utl::IOFailureException);
43  CPPUNIT_TEST(testClose);
44  CPPUNIT_TEST(testCloseClose);
45  CPPUNIT_TEST_EXCEPTION(testWrite, utl::IOFailureException);
46  CPPUNIT_TEST(testFindEvent);
47  CPPUNIT_TEST(testGotoPosition);
48  CPPUNIT_TEST(testGetNEvents);
49  CPPUNIT_TEST(testRead);
50  CPPUNIT_TEST(testParticleRead);
51  CPPUNIT_TEST_EXCEPTION(testGetNEventsClosedException,
53  CPPUNIT_TEST_SUITE_END();
54 
55 public:
56  // shared data for tests
57 
60 
61  void
63  {
64  CentralConfig::GetInstance(BOOTSTRAPFILE);
65  f = new ArtificialShowerFile();
66  event = evt::Event();
67  }
68 
69  void
71  {
72  delete f;
73  f = 0;
74  }
75 
76  void
78  {
80  CPPUNIT_ASSERT(file = new ArtificialShowerFile("BLAHBLAH"));
81  delete file;
82  }
83 
84  void
86  {
87  Expected();
88  ArtificialShowerFile ftest("BLAHBLAH",io::eWrite);
89  }
90 
91  void testOpen()
92  { f->Open("BLAHBLAH"); }
93 
94 
95  void
97  {
98  f->Open("BLAHBLAH");
99  Expected();
100  f->Open("BLAHBLAH");
101  }
102 
103  void
105  {
106  Expected();
107  f->Open("BLAHBLAH", io::eWrite);
108  }
109 
110  void testClose()
111  { f->Close(); }
112 
113  void
115  {
116  f->Close();
117  Expected();
118  f->Close();
119  }
120 
121  void
123  {
124  f->Open("BLAH");
125  CPPUNIT_ASSERT(Verify<Not<Equal> >(f->FindEvent(1), io::eFail));
126  CPPUNIT_ASSERT(Verify<Equal>(f->FindEvent(0), io::eFail));
127  }
128 
129  void
131  {
132  f->Open("BLAH");
133  CPPUNIT_ASSERT(Verify<Not<Equal> >(f->GotoPosition(0), io::eFail));
134  }
135 
136  void
138  {
139  f->Open("BLAH");
140  Expected();
141  f->Write(event);
142  }
143 
144  void
146  {
147  f->Open("BLAH");
148  CPPUNIT_ASSERT(Verify<Equal>(f->GetNEvents(), 1));
149  }
150 
151  void
153  {
154  Expected();
155  f->GetNEvents();
156  }
157 
158  void
160  {
161  f->Open("BLAH");
162  int nEventsInFile = f->GetNEvents();
163  int nEventsSeen = 0;
164  while (f->Read(event) != io::eEOF) {
165  ++nEventsSeen;
166 
167  evt::ShowerSimData& shower = event.GetSimShower();
168 
169  const CoordinateSystemPtr refCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
170  shower.MakeGeometry(utl::Point(0,0,0,refCS));
171 
172  CPPUNIT_ASSERT(Verify<Equal>(shower.GetPrimaryParticle(),
173  int(Particle::eProton)));
174  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetEnergy(), 1e19*eV));
175 
176  const utl::CoordinateSystemPtr localCS = shower.GetLocalCoordinateSystem();
177  const double zenith = (-shower.GetDirection()).GetTheta(localCS);
178  const double azimuth = (-shower.GetDirection()).GetPhi(localCS);
179 
180  CPPUNIT_ASSERT(Verify<CloseTo>(zenith, 45.0*deg));
181  CPPUNIT_ASSERT(Verify<CloseTo>(azimuth, 0.0*deg));
182  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerNumber(),
183  nEventsSeen));
184  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerRunId(), std::string("1")));
185  }
186  CPPUNIT_ASSERT(Verify<Equal>(nEventsInFile, nEventsSeen));
187  }
188 
189  void
191  {
192  f->Open("irrelevant.com");
193  for (int i = 0; i < f->GetNEvents(); ++i) {
194  event = evt::Event(); // clear event until readers do it.
195  f->Read(event);
196  evt::ShowerSimData& shower = event.GetSimShower();
197 
198  shower.MakeGeometry(
199  Point(0,0,0, det::Detector::GetInstance().GetSiteCoordinateSystem())
200  );
201 
202  long double nParticles = 0;
204  p != shower.GroundParticlesEnd(); ++p) {
205  nParticles += p->GetWeight();
206  }
207  CPPUNIT_ASSERT(Verify<Greater>(nParticles, 8e7L));
208  CPPUNIT_ASSERT(Verify<Less>(nParticles, 9e7L));
209  }
210  }
211 };
212 
213 
215 
216 
217 // Configure (x)emacs for this file ...
218 // Local Variables:
219 // mode: c++
220 // compile-command: "make -C .. -k testCorsika && (cd ..; testCorsika)"
221 // End:
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
Iterator to retrieve particles from utl::VShowerParticlList.
Point object.
Definition: Point.h:32
utl::ShowerParticleIterator GroundParticlesEnd() const
Read Only access.
Definition: IoCodes.h:18
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Base class to report exceptions in IO.
constexpr double deg
Definition: AugerUnits.h:140
Definition: Test.h:180
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
Artificial shower generator: uniform particle density, direction.
const utl::Vector & GetDirection() const
Get the direction of the shower axis. This is the true direction of shower movement.
bool Verify(const Predicate &pred, const T &lhs, const T &rhs)
Test condition by evaluating a predicate and print on failure.
Definition: Verify.h:38
void Expected()
Print `Expected&#39; for expected failures.
Definition: Verify.h:85
double GetEnergy() const
Get the energy of the shower primary particle.
Definition: ShowerSimData.h:89
const string file
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 ...
utl::ShowerParticleIterator GroundParticlesBegin() const

, generated on Tue Sep 26 2023.