testCONEXFile.cc
Go to the documentation of this file.
1 
9 #include <io/CONEXFile.h>
10 #include <io/CONEXIOException.h>
11 #include <io/CONEXStructures.h>
12 #include <io/IoCodes.h>
13 
14 #include <evt/Event.h>
15 #include <evt/ShowerSimData.h>
16 
17 #include <utl/AugerUnits.h>
18 #include <utl/Particle.h>
19 #include <utl/TabulatedFunction.h>
20 
21 #include <fwk/CentralConfig.h>
22 
23 #include <det/Detector.h>
24 
25 #include <cppunit/extensions/HelperMacros.h>
26 
27 #include <iostream>
28 
29 #include <tst/Verify.h>
30 
31 using io::CONEXFile;
32 using namespace fwk;
33 using namespace utl;
34 using namespace tst;
35 using tst::Expected;
36 
37 
38 class testCONEXFile : public CppUnit::TestFixture {
39 
40  CPPUNIT_TEST_SUITE(testCONEXFile);
41  CPPUNIT_TEST(testConstruct);
42  CPPUNIT_TEST_EXCEPTION(testConstructException, io::CONEXIOException);
43  CPPUNIT_TEST(testOpen);
44  CPPUNIT_TEST_EXCEPTION(testOpenNonExisting, io::CONEXIOException);
45  CPPUNIT_TEST_EXCEPTION(testOpenForWrite, io::CONEXIOException);
46  CPPUNIT_TEST(testClose);
47  CPPUNIT_TEST_EXCEPTION(testWrite, io::CONEXIOException);
48  CPPUNIT_TEST(testFindEvent);
49  CPPUNIT_TEST(testGotoPosition);
50  CPPUNIT_TEST(testGetNEvents);
51  CPPUNIT_TEST(testRead);
52  CPPUNIT_TEST(testProfileRead);
53  CPPUNIT_TEST_EXCEPTION(testGetNEventsClosedException, io::CONEXIOException);
54  CPPUNIT_TEST_SUITE_END();
55 
56 public:
57  // shared data for tests
58 
61 
62  void
64  {
65  f = new CONEXFile;
66  event = evt::Event();
67  }
68 
69  void tearDown()
70  { delete f; }
71 
72  void
74  {
75  CONEXFile* file;
76  CPPUNIT_ASSERT (file = new CONEXFile (TESTFILE));
77  delete file;
78  }
79 
80  void
82  {
83  Expected();
84  CONEXFile f(TESTFILE, io::eWrite);
85  }
86 
87  void testOpen()
88  { f->Open (TESTFILE); }
89 
90  void
92  {
93  Expected();
94  f->Open("NoSuchCONEXShowerFile.root");
95  }
96 
97  void
99  {
100  Expected();
101  f->Open(TESTFILE, io::eWrite);
102  }
103 
104  void
106  {
107  f->Open(TESTFILE);
108  f->Close();
109  }
110 
111  void
113  {
114  f->Open(TESTFILE);
115  CPPUNIT_ASSERT(f->FindEvent(2) == io::eFail);
116  CPPUNIT_ASSERT(f->FindEvent(0) != io::eFail);
117  }
118 
119  void
121  {
122  f->Open(TESTFILE);
123  CPPUNIT_ASSERT(f->GotoPosition(0) != io::eFail);
124  CPPUNIT_ASSERT(f->GotoPosition(2) == io::eFail);
125  }
126 
127  void
129  {
130  f->Open(TESTFILE);
131  Expected();
132  f->Write(event);
133  }
134 
135  void
137  {
138  f->Open(TESTFILE);
139  CPPUNIT_ASSERT(f->GetNEvents() == 1);
140  }
141 
142  void
144  {
145  Expected();
146  f->GetNEvents();
147  }
148 
149  void
151  {
152  CentralConfig::GetInstance(BOOTSTRAPFILE);
153  f->Open(TESTFILE);
154  const int nEventsInFile = f->GetNEvents();
155  int nEventsSeen = 0;
156 
157  event = evt::Event(); // clear event until readers do it.
158  while (f->Read(event) != io::eEOF) {
159  ++nEventsSeen;
160  evt::ShowerSimData& shower = event.GetSimShower();
161 
162  const CoordinateSystemPtr refCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
163  shower.MakeGeometry(utl::Point(0,0,0,refCS));
164 
165  CPPUNIT_ASSERT(Verify<Equal>(shower.GetPrimaryParticle(),
166  int(Particle::eProton)));
167  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetEnergy(), 1.e19*eV));
168 
169  const utl::CoordinateSystemPtr localCS = shower.GetLocalCoordinateSystem();
170  const double zenith = (-shower.GetDirection()).GetTheta(localCS);
171  const double azimuth = (-shower.GetDirection()).GetPhi(localCS);
172 
173  CPPUNIT_ASSERT(Verify<CloseTo>(zenith, 60.*deg));
174  CPPUNIT_ASSERT(Verify<CloseTo>(azimuth, 0*deg));
175  event = evt::Event(); // clear event until readers do it.
176  }
177 
178  CPPUNIT_ASSERT(Verify<Equal>(nEventsInFile, nEventsSeen));
179  }
180 
181  void
183  {
184  //CentralConfig::GetInstance(BOOTSTRAPFILE);
185  f->Open(TESTFILE);
186 
187  for (int i = 0; i < f->GetNEvents(); ++i) {
188  event = evt::Event(); // clear event until readers do it.
189  f->Read(event);
190  evt::ShowerSimData& shower = event.GetSimShower();
191 
192  CPPUNIT_ASSERT(shower.HasLongitudinalProfile());
193  CPPUNIT_ASSERT(shower.HasdEdX());
194  //CPPUNIT_ASSERT(shower.HasDirection());
195  //CPPUNIT_ASSERT(shower.HasPosition());
196 
197  //utl::TabulatedFunction& profile = shower.GetLongitudinalProfile();
198 
199  //CPPUNIT_ASSERT(nParticles > 1e11);
200  //CPPUNIT_ASSERT(nParticles < 1e12);
201  }
202  }
203 
204 };
205 
206 
208 
209 
210 // Configure (x)emacs for this file ...
211 // Local Variables:
212 // mode: c++
213 // compile-command: "make -C .. -k testCONEX && (cd ..; testCONEX)"
214 // End:
215 
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
Read profiles from CONEX.
Definition: CONEXFile.h:36
Point object.
Definition: Point.h:32
void testConstruct()
void testFindEvent()
void testGetNEventsClosedException()
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.
const utl::Vector & GetDirection() const
Get the direction of the shower axis. This is the true direction of shower movement.
void testGetNEvents()
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
void testConstructException()
const string file
evt::Event event
Base for exceptions in the CORSIKA reader.
bool HasdEdX() const
Check initialization of the energy deposit.
void testProfileRead()
CONEXFile * f
void testGotoPosition()
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
void MakeGeometry(const utl::Point &pointOnShowerAxis)
initialize the shower geometry. Pos is a point on the shower axis, but not necessarily the core ...
void testOpenNonExisting()
void testOpenForWrite()
bool HasLongitudinalProfile(const ProfileType type=eCharged) const
Check initialization of the longitudinal profile.

, generated on Tue Sep 26 2023.