testSenecaShowerFile.cc
Go to the documentation of this file.
1 #include <io/SenecaShowerFile.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/CoordinateSystemRegistry.h>
17 #include <fwk/CentralConfig.h>
18 #include <det/Detector.h>
19 
20 #include <tst/Verify.h>
21 #include <cppunit/extensions/HelperMacros.h>
22 
23 #include <iostream>
24 #include <string>
25 
26 using namespace fwk;
27 using namespace evt;
28 using namespace io;
29 using namespace utl;
30 using namespace std;
31 using namespace tst;
32 using tst::Expected;
33 
34 
35 class testSenecaShowerFile : public CppUnit::TestFixture {
36 
37 private:
38  CPPUNIT_TEST_SUITE(testSenecaShowerFile);
39  CPPUNIT_TEST(testConstruct);
40  CPPUNIT_TEST_EXCEPTION(testConstructException, utl::IOFailureException);
41  CPPUNIT_TEST(testOpen);
42  CPPUNIT_TEST_EXCEPTION(testOpenOpen, utl::IOFailureException);
43  CPPUNIT_TEST_EXCEPTION(testOpenNonExisting, utl::IOFailureException);
44  CPPUNIT_TEST_EXCEPTION(testOpenForWrite, utl::IOFailureException);
45  CPPUNIT_TEST(testClose);
46  CPPUNIT_TEST(testCloseClose);
47  CPPUNIT_TEST_EXCEPTION(testWrite, utl::IOFailureException);
48  CPPUNIT_TEST(testFindEvent);
49  CPPUNIT_TEST(testGotoPosition);
50  CPPUNIT_TEST(testGetNEvents);
51  CPPUNIT_TEST(testRead);
52  CPPUNIT_TEST(testParticleRead);
53  CPPUNIT_TEST_EXCEPTION(testGetNEventsClosedException,
55  CPPUNIT_TEST_SUITE_END();
56 
57 public:
58  // shared data for tests
59 
62 
63  void
65  {
66  f = new SenecaShowerFile();
67  event = evt::Event();
68  }
69 
70  void
72  {
73  delete f;
74  f = 0;
75  }
76 
77  void
79  {
81  CPPUNIT_ASSERT(file = new SenecaShowerFile(TESTFILE));
82  delete file;
83  }
84 
85  void
87  {
88  Expected();
89  SenecaShowerFile ftest(TESTFILE,io::eWrite);
90  }
91 
92  void testOpen()
93  { f->Open(TESTFILE); }
94 
95  void
97  {
98  Expected();
99  f->Open("NoSuchSenecaShowerFile.ptcl");
100  }
101 
102  void
104  {
105  f->Open(TESTFILE);
106  Expected();
107  f->Open(TESTFILE);
108  }
109 
110  void
112  {
113  Expected();
114  f->Open(TESTFILE, io::eWrite);
115  }
116 
117  void testClose()
118  { f->Close(); }
119 
120  void
122  {
123  f->Close();
124  Expected();
125  f->Close();
126  }
127 
128  void
130  {
131  f->Open(TESTFILE);
132  CPPUNIT_ASSERT(Verify<Not<Equal> >(f->FindEvent(2), io::eFail));
133  CPPUNIT_ASSERT(Verify<Equal>(f->FindEvent(0), io::eFail));
134  }
135 
136  void
138  {
139  f->Open(TESTFILE);
140  CPPUNIT_ASSERT(Verify<Not<Equal> >(f->GotoPosition(0), io::eFail));
141  }
142 
143  void
145  {
146  f->Open(TESTFILE);
147  Expected();
148  f->Write(event);
149  }
150 
151  void
153  {
154  f->Open(TESTFILE);
155  CPPUNIT_ASSERT(Verify<Equal>(f->GetNEvents(), 2));
156  }
157 
158  void
160  {
161  Expected();
162  f->GetNEvents();
163  }
164 
165  void
167  {
168  CentralConfig::GetInstance(BOOTSTRAPFILE);
169 
170  f->Open(TESTFILE);
171  int nEventsInFile = f->GetNEvents();
172  int nEventsSeen = 0;
173  while (f->Read(event) != io::eEOF) {
174  ++nEventsSeen;
175 
176  evt::ShowerSimData& shower = event.GetSimShower();
177 
178  const CoordinateSystemPtr refCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
179  shower.MakeGeometry(utl::Point(0,0,0,refCS));
180 
181  CPPUNIT_ASSERT(Verify<Equal>(shower.GetPrimaryParticle(),
182  int(Particle::eProton)));
183  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetEnergy(), 9.99995e19*eV));
184 
185  const utl::CoordinateSystemPtr localCS = shower.GetLocalCoordinateSystem();
186  const double zenith = (-shower.GetDirection()).GetTheta(localCS);
187  const double azimuth = (-shower.GetDirection()).GetPhi(localCS);
188 
189  CPPUNIT_ASSERT(Verify<CloseTo>(zenith, 32.4199*deg));
190  CPPUNIT_ASSERT(Verify<CloseTo>(azimuth, 91.0196*deg - 180*deg)); // todo: for an expert to check if the azimuth angle definition for Seneca is indeed correct like this, and thus in the rest of Offline !
191  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerNumber(),
192  nEventsSeen));
193  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerRunId(), std::string("1")));
194 
195  event = evt::Event(); // reset
196  }
197 
198  CPPUNIT_ASSERT(Verify<Equal>(nEventsInFile, nEventsSeen));
199  }
200 
201  void
203  {
204  CentralConfig::GetInstance(BOOTSTRAPFILE);
205  f->Open(TESTFILE);
206  for (int i = 0; i < f->GetNEvents(); ++i) {
207  event = evt::Event(); // clear event until readers do it.
208  f->Read(event);
209  evt::ShowerSimData& shower = event.GetSimShower();
210 
211  shower.MakeGeometry(
212  Point(0,0,0, det::Detector::GetInstance().GetSiteCoordinateSystem())
213  );
214 
215  long double nParticles = 0;
217  p != shower.GroundParticlesEnd(); ++p) {
218  nParticles += p->GetWeight();
219  }
220  CPPUNIT_ASSERT(Verify<Greater>(nParticles, 1e11L));
221  CPPUNIT_ASSERT(Verify<Less>(nParticles, 1e12L));
222 
223  event = evt::Event(); // reset
224  }
225  }
226 };
227 
228 
230 
231 
232 // Configure (x)emacs for this file ...
233 // Local Variables:
234 // mode: c++
235 // compile-command: "make -C .. -k testCorsika && (cd ..; testCorsika)"
236 // 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
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 ...
Read data from the output of Seneca.
utl::ShowerParticleIterator GroundParticlesBegin() const

, generated on Tue Sep 26 2023.