testAiresShowerFile.cc
Go to the documentation of this file.
1 
9 #include <io/AiresShowerFile.h>
10 #include <io/AiresUtilities.h>
11 #include <io/IoCodes.h>
12 #include <evt/Event.h>
13 #include <evt/ShowerSimData.h>
14 #include <utl/AugerUnits.h>
15 #include <utl/Particle.h>
16 #include <utl/NucleusProperties.h>
17 #include <utl/ShowerParticleIterator.h>
18 #include <fwk/CentralConfig.h>
19 #include <det/Detector.h>
20 
21 #include <tst/Verify.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 
24 #include <iostream>
25 
27 using namespace fwk;
28 using namespace std;
29 using namespace tst;
30 using namespace utl;
31 using namespace tst;
32 using namespace tst;
33 
34 
35 class testAiresShowerFile : public CppUnit::TestFixture {
36 
37  CPPUNIT_TEST_SUITE(testAiresShowerFile);
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(testOpenNonExisting, utl::IOFailureException);
43  //CPPUNIT_TEST_EXCEPTION(testOpenForWrite, utl::IOFailureException);
44  CPPUNIT_TEST(testClose);
45  //CPPUNIT_TEST(testCloseClose);
46  //CPPUNIT_TEST_EXCEPTION(testWrite, utl::IOFailureException);
47  //CPPUNIT_TEST(testFindEvent);
48  //CPPUNIT_TEST(testGotoPosition);
49  CPPUNIT_TEST(testGetNEvents);
50  CPPUNIT_TEST(testRead);
51  CPPUNIT_TEST(testReadNucleus);
52  CPPUNIT_TEST(testParticleRead);
53 
54  // split into tests for longitudinal development and energy deposit
55  //
56  CPPUNIT_TEST(testLongitudinalProfile);
57  CPPUNIT_TEST(testdEdX);
58  CPPUNIT_TEST(testSingleShowerLongitudinalProfile);
59  CPPUNIT_TEST(testSingleShowerdEdX);
60 
61  /*CPPUNIT_TEST_EXCEPTION(testGetNEventsClosedException,
62  utl::IOFailureException);*/
63  CPPUNIT_TEST_SUITE_END();
64 
65 public:
66  // shared data for tests
67 
70 
71  void
73  {
74  f = new AiresShowerFile();
75  event = evt::Event();
76  }
77 
78  void tearDown()
79  {
80  delete f;
81  }
82 
84  {
86  CPPUNIT_ASSERT(file = new AiresShowerFile(TESTFILE));
87  delete file;
88  }
89 
90  void
92  {
93  Expected();
94  AiresShowerFile f(TESTFILE, io::eWrite);
95  }
96 
97  void testOpen() { f->Open(TESTFILE); }
98 
99  void
101  {
102  Expected();
103  f->Open("NoSuchAiresEventFile.grdpcles");
104  }
105 
106  void
108  {
109  f->Open(TESTFILE);
110  Expected();
111  f->Open(TESTFILE);
112  }
113 
114  void
116  {
117  Expected();
118  f->Open(TESTFILE, io::eWrite);
119  }
120 
121  void testClose() { f->Close(); }
122 
123  void
125  {
126  f->Close();
127  Expected();
128  f->Close();
129  }
130 
131  void
133  {
134  f->Open(TESTFILE);
135  CPPUNIT_ASSERT(f->FindEvent(2) != io::eFail);
136  CPPUNIT_ASSERT(f->FindEvent(0) == io::eFail);
137  }
138 
139  void
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
149  {
150  f->Open(TESTFILE);
151  Expected();
152  f->Write(event);
153  }
154 
155  void
157  {
158  f->Open(TESTFILE);
159  CPPUNIT_ASSERT(f->GetNEvents() == 5);
160  }
161 
162  void
164  {
165  Expected();
166  f->GetNEvents();
167  }
168 
169  void
171  {
172  f->Open(TESTFILE);
173  event = evt::Event();
174  const int nEventsInFile = f->GetNEvents();
175  int nEventsSeen = 0;
176  int showerId = 1;
177  while (f->Read(event) != io::eEOF) {
178  ++nEventsSeen;
179 
180  CPPUNIT_ASSERT(event.HasSimShower());
181  const evt::ShowerSimData& shower = event.GetSimShower();
182 
183  // The values used to do the checks here are set in AiresTest.inp
184  //
185  CPPUNIT_ASSERT(shower.GetPrimaryParticle() == Particle::eProton);
186  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetEnergy(), 1.e20*eV));
187  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetZenith(), 32.42*deg));
188  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetMinRadiusCut(), 1.*m)); // from RLimsFile
189  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetMaxRadiusCut(), 10.*km)); // from RLimsFile
190  CPPUNIT_ASSERT(shower.GetShowerRunId() == string("AiresTest"));
191 
192  // fix this check.
193  //CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetAzimuth(),
194  // 145.59*deg-90.*deg-4.233*deg));
195 
196  CPPUNIT_ASSERT(shower.GetShowerNumber() == showerId);
197  ++showerId;
198  event = evt::Event();
199  }
200 
201  CPPUNIT_ASSERT(nEventsInFile == nEventsSeen);
202  }
203 
204  void
206  {
207  f->Open(TESTFILEIRON);
208  event = evt::Event();
209  f->Read(event);
210 
211  CPPUNIT_ASSERT(event.HasSimShower());
212  const evt::ShowerSimData& shower = event.GetSimShower();
213 
214  CPPUNIT_ASSERT(shower.GetPrimaryParticle() ==
215  NucleusProperties::TypeCode(26, 56));
216  }
217 
218  void
220  {
221  CentralConfig::GetInstance(BOOTSTRAPFILE);
222  f->Open(TESTFILE);
223 
224  for (int i = 0; i < f->GetNEvents(); i++) {
225 
226  event = evt::Event(); // clear event until readers do it.
227  f->Read(event);
228 
229  CPPUNIT_ASSERT(event.HasSimShower());
230  evt::ShowerSimData& shower = event.GetSimShower();
231 
232  shower.MakePosition(Point(0,0,0,
233  det::Detector::GetInstance().GetSiteCoordinateSystem()));
234 
235  double nParticles = 0;
236  long num = 0;
237 
238  for (ShowerParticleIterator p = shower.GroundParticlesBegin();
239  p != shower.GroundParticlesEnd(); ++p, ++num)
240  nParticles += p->GetWeight();
241 
242  // reasonable numbers for a shower at 10^20 eV
243  CPPUNIT_ASSERT(1e11 < nParticles && nParticles < 1e12);
244 
245  }
246  }
247 
248  void
250  {
251  CentralConfig::GetInstance(BOOTSTRAPFILE);
252  f->Open(TESTFILE);
253 
254  // Just read the first event for this test.
255  event = evt::Event();
256  f->Read(event);
257 
258  CPPUNIT_ASSERT(event.HasSimShower());
259  const evt::ShowerSimData& shower = event.GetSimShower();
260 
261  CPPUNIT_ASSERT(shower.HasLongitudinalProfile());
262  const TabulatedFunction& prof = shower.GetLongitudinalProfile();
263 
264  const double zen = shower.GetZenith();
265 
266  CPPUNIT_ASSERT(Verify<CloseTo>(prof.Y(43.2583*(g/cm2)/cos(zen)),
267  1.381535E+07)); // from AiresTest_s0001.t1291
268  CPPUNIT_ASSERT(Verify<CloseTo>(prof.Y(242.240*(g/cm2)/cos(zen)),
269  1.182769E+09)); // from AiresTest_s0001.t1291
270  }
271 
272  void
274  {
275  CentralConfig::GetInstance(BOOTSTRAPFILE);
276  f->Open(TESTFILE);
277 
278  // Just read the first event for this test.
279  event = evt::Event();
280  f->Read(event);
281  CPPUNIT_ASSERT(event.HasSimShower());
282  const evt::ShowerSimData& shower = event.GetSimShower();
283 
284  const double zen = shower.GetZenith();
285 
286  // ground depth (873.792) and number of obs levels (100) taken from AiresTest.inp
287  const double auxStep = 873.792/100./cos(zen);
288 
289  CPPUNIT_ASSERT(shower.HasdEdX());
290  const TabulatedFunction& dEdX = shower.GetdEdX();
291 
292  CPPUNIT_ASSERT(Verify<CloseTo>(dEdX.Y(43.2583*(g/cm2)/cos(zen))*auxStep/(GeV/(g/cm2)),
293  531851.)); // from AiresTest_s0001.t7991
294  CPPUNIT_ASSERT(Verify<CloseTo>(dEdX.Y(795.930*(g/cm2)/cos(zen))*auxStep/(GeV/(g/cm2)),
295  1.494458E+09)); // from AiresTest_s0001.t7991
296  }
297 
298  void
300  {
301  f->Open(TESTFILESINGLESHOWER);
302  event = evt::Event();
303  f->Read(event);
304 
305  CPPUNIT_ASSERT(event.HasSimShower());
306  const evt::ShowerSimData& shower = event.GetSimShower();
307 
308  CPPUNIT_ASSERT(shower.HasLongitudinalProfile());
309  const TabulatedFunction& prof = shower.GetLongitudinalProfile();
310 
311  const double zen = shower.GetZenith();
312 
313  CPPUNIT_ASSERT(Verify<CloseTo>(prof.Y(43.2583*(g/cm2)/cos(zen)),
314  182081.)); // from AiresTestSingleShower.t1291
315  CPPUNIT_ASSERT(Verify<CloseTo>(prof.Y(242.240*(g/cm2)/cos(zen)),
316  5.742057E+08)); // from AiresTestSingleShower.t1291
317  }
318 
319  void
321  {
322  f->Open(TESTFILESINGLESHOWER);
323  event = evt::Event();
324  f->Read(event);
325 
326  CPPUNIT_ASSERT(event.HasSimShower());
327  const evt::ShowerSimData& shower = event.GetSimShower();
328 
329  const double zen = shower.GetZenith();
330 
331  // ground depth (873.792) and number of obs levels (100) taken from AiresTest.inp
332  const double auxStep = 873.792/100./cos(zen);
333 
334  CPPUNIT_ASSERT(shower.HasdEdX());
335  const TabulatedFunction& dEdX = shower.GetdEdX();
336 
337  CPPUNIT_ASSERT(Verify<CloseTo>(dEdX.Y(43.2583*(g/cm2)/cos(zen))*auxStep/(GeV/(g/cm2)),
338  263848.)); // from AiresTest_s0001.t7991
339  CPPUNIT_ASSERT(Verify<CloseTo>(dEdX.Y(795.930*(g/cm2)/cos(zen))*auxStep/(GeV/(g/cm2)),
340  1.598191E+09)); // from AiresTest_s0001.t7991
341  }
342 
343 };
344 
345 
347 
348 
349 // Configure (x)emacs for this file ...
350 // Local Variables:
351 // mode:c++
352 // compile-command: "make -C .. -k testAires && (cd ..; testAires)"
353 // End:
354 
const double eV
Definition: GalacticUnits.h:35
Iterator to retrieve particles from utl::VShowerParticlList.
Point object.
Definition: Point.h:32
Class to hold collection (x,y) points and provide interpolation between them.
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
void Expected()
Print `Expected&#39; for expected failures.
Definition: Verify.h:85
const double km
constexpr double g
Definition: AugerUnits.h:200
const string file
constexpr double GeV
Definition: AugerUnits.h:187
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
Utility to open an Aires generated shower file on disc.
constexpr double m
Definition: AugerUnits.h:121
constexpr double cm2
Definition: AugerUnits.h:118

, generated on Tue Sep 26 2023.