testZHAireSFile.cc
Go to the documentation of this file.
1 #include <io/ZHAireSFile.h>
2 #include <io/ZHAireSIOException.h>
3 #include <io/IoCodes.h>
4 
5 #include <evt/Event.h>
6 #include <evt/ShowerSimData.h>
7 #include <evt/VGaisserHillasParameter.h>
8 #include <evt/RadioSimulation.h>
9 #include <evt/SimRadioPulse.h>
10 
11 #include <utl/AugerUnits.h>
12 #include <utl/Particle.h>
13 
14 #include <fwk/CentralConfig.h>
15 
16 #include <det/Detector.h>
17 
18 #include <tst/Verify.h>
19 #include <cppunit/extensions/HelperMacros.h>
20 
21 #include <iostream>
22 
23 using io::ZHAireSFile;
24 using namespace fwk;
25 using namespace utl;
26 using namespace tst;
27 using namespace std;
28 
29 
30 class testZHAireSFile : public CppUnit::TestFixture {
31 
32  CPPUNIT_TEST_SUITE(testZHAireSFile);
33  CPPUNIT_TEST(testConstruct);
34  CPPUNIT_TEST(testGetNEvents);
35  CPPUNIT_TEST(testRead);
36  CPPUNIT_TEST_SUITE_END();
37 
38 public:
39  // shared data for tests
40 
41  ZHAireSFile* fFile = nullptr;
43 
44  void
46  {
47  fFile = new ZHAireSFile();
48  fEvent = evt::Event();
49  }
50 
51  void
53  delete fFile;
54  fFile = nullptr;
55  }
56 
57  void
59  {
61  CPPUNIT_ASSERT(file = new ZHAireSFile(TESTFILE));
62  delete file;
63  }
64 
65  void
67  {
68  fFile->Open(TESTFILE);
69  CPPUNIT_ASSERT(fFile->GetNEvents() == 1);
70  }
71 
72  void
74  {
75  fwk::CentralConfig::GetInstance(BOOTSTRAPFILE);
76 
77  fFile->Open(TESTFILE);
78  int nEventsInFile = fFile->GetNEvents();
79  int nEventsSeen = 0;
80  fEvent = evt::Event(); // clear event until readers do it.
81  while (fFile->Read(fEvent) != io::eEOF) {
82  ++nEventsSeen;
83  evt::ShowerSimData& shower = fEvent.GetSimShower();
84 
85  const CoordinateSystemPtr refCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
86  shower.MakeGeometry(utl::Point(0,0,0, refCS));
87 
88  // test if AIRES variables are set up correctly
89  CPPUNIT_ASSERT(Verify<Equal>(shower.GetPrimaryParticle(), int(Particle::eProton)));
90  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetEnergy(), 7.4411e17*eV));
91 
92  const utl::CoordinateSystemPtr localCS = shower.GetLocalCoordinateSystem();
93  const double zenith = (-shower.GetDirection()).GetTheta(localCS);
94  CPPUNIT_ASSERT(Verify<CloseTo>(zenith, 51.73*deg));
95  const double azimuth = (-shower.GetDirection()).GetPhi(localCS);
96  const double airesAzimuthDeg = -105.23; // from the .sry file
97  // 90deg for North -> East, -4.23deg for magnetic-North:North misalignement
98  CPPUNIT_ASSERT(Verify<CloseTo>(azimuth, (airesAzimuthDeg + 90 - 4.23)*deg));
99 
100  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerNumber(), nEventsSeen));
101  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerRunId(), std::string("1")));
102  CPPUNIT_ASSERT(Verify<Equal>(shower.HasGroundParticles(), false)); // no particle file
103  CPPUNIT_ASSERT(Verify<Equal>(shower.HasGHParameters(), false));
104 
105  // test if ZHAireS contents are set up correctly
106  CPPUNIT_ASSERT(Verify<Equal>(shower.HasRadioSimulation(), true));
107  evt::RadioSimulation& radsim = shower.GetRadioSimulation();
108  CPPUNIT_ASSERT(Verify<Equal>(radsim.GetNumPulses(), 7L));
109  CPPUNIT_ASSERT(Verify<Equal>(radsim.HasCorePosition(), true));
110  bool ok = false;
111  const evt::SimRadioPulse& simpulse = radsim.GetNextSimRadioPulse(ok);
112  const unsigned int frontpadding = 0; // samples used for padding of the timeseries front
113  const double binning = 0.5*nanosecond;
114  CPPUNIT_ASSERT(Verify<Equal>(ok, true));
115  CPPUNIT_ASSERT(Verify<Equal>(simpulse.GetEfieldTimeSeries().GetSize(), TraceV3D::SizeType(22254+frontpadding)));
116  CPPUNIT_ASSERT(Verify<CloseTo>(simpulse.GetEfieldTimeSeries().GetBinning(), binning));
117  CPPUNIT_ASSERT(Verify<CloseTo>(simpulse.GetBinning(), binning));
118  CPPUNIT_ASSERT(Verify<CloseTo>(simpulse.GetStartTime(), -1126.75*nanosecond - frontpadding*binning));
119 
120  const unsigned int samplenumber = 3575; // test this bin (starts at 0)
121  const Vector3D& sample = simpulse.GetEfieldTimeSeries()[samplenumber + frontpadding];
122  CPPUNIT_ASSERT(Verify<CloseTo>(sample[0]/volt*meter, -2.85945943595946640e-03)); // east component
123  CPPUNIT_ASSERT(Verify<CloseTo>(sample[1]/volt*meter, -2.03602779956765009e-03)); // north component
124  CPPUNIT_ASSERT(Verify<CloseTo>(sample[2]/volt*meter, 2.61886417865753174e-03)); // vertical up component )
125  fEvent = evt::Event(); // clear event until readers do it.
126  }
127 
128  CPPUNIT_ASSERT(Verify<Equal>(nEventsInFile, nEventsSeen));
129  }
130 
131 };
132 
133 
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
double GetBinning() const
Get the sampling time scale.
Definition: SimRadioPulse.h:34
Point object.
Definition: Point.h:32
Data structure for simulated Radio pulses.
Definition: SimRadioPulse.h:29
bool HasGroundParticles() const
Data structure for a radio simulation (including several SimRadioPulses)
double GetBinning() const
size of one slot
Definition: Trace.h:138
const double meter
Definition: GalacticUnits.h:29
bool HasRadioSimulation() const
Check initialization of the RadioSimulation.
bool ok(bool okay)
Definition: testlib.cc:89
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.
std::vector< T >::size_type SizeType
Definition: Trace.h:58
bool HasCorePosition() const
RadioSimulation & GetRadioSimulation()
Get the radio simulation data.
constexpr double nanosecond
Definition: AugerUnits.h:143
double GetEnergy() const
Get the energy of the shower primary particle.
Definition: ShowerSimData.h:89
SizeType GetSize() const
Definition: Trace.h:156
const string file
const SimRadioPulse & GetNextSimRadioPulse(bool &ok)
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 ...
bool HasGHParameters() const
Check initialization of the Gaisser-Hillas parameters.
long GetNumPulses() const
Get the number of radio pulses contained in the RadioSimulation.
const utl::TraceV3D & GetEfieldTimeSeries() const
Get the Trace of the simulated electric field.
Definition: SimRadioPulse.h:44
const double volt
Definition: GalacticUnits.h:38
double GetStartTime() const
Get the timestamp of the first sample.
Definition: SimRadioPulse.h:39

, generated on Tue Sep 26 2023.