testREASFile.cc
Go to the documentation of this file.
1 
9 #include <io/REASFile.h>
10 #include <io/REASIOException.h>
11 #include <io/IoCodes.h>
12 
13 #include <evt/Event.h>
14 #include <evt/ShowerSimData.h>
15 #include <evt/VGaisserHillasParameter.h>
16 #include <evt/RadioSimulation.h>
17 #include <evt/SimRadioPulse.h>
18 
19 #include <utl/AugerUnits.h>
20 #include <utl/Particle.h>
21 
22 #include <fwk/CentralConfig.h>
23 
24 #include <det/Detector.h>
25 
26 #include <tst/Verify.h>
27 #include <cppunit/extensions/HelperMacros.h>
28 
29 #include <iostream>
30 
31 using io::REASFile;
32 using namespace fwk;
33 using namespace utl;
34 using namespace tst;
35 
36 
37 class testREASFile : public CppUnit::TestFixture {
38 
39  CPPUNIT_TEST_SUITE (testREASFile);
40  CPPUNIT_TEST (testConstruct);
41  //CPPUNIT_TEST_EXCEPTION (testConstructException, io::REASIOException);
42  //CPPUNIT_TEST (testOpen);
43  //CPPUNIT_TEST_EXCEPTION (testOpenNonExisting, io::REASIOException);
44  //CPPUNIT_TEST_EXCEPTION (testOpenForWrite, io::REASIOException);
45  //CPPUNIT_TEST (testClose);
46  //CPPUNIT_TEST_EXCEPTION (testWrite, io::REASIOException);
47  //CPPUNIT_TEST (testFindEvent);
48  //CPPUNIT_TEST (testGotoPosition);
49  CPPUNIT_TEST (testGetNEvents);
50  CPPUNIT_TEST (testRead);
51  //CPPUNIT_TEST_EXCEPTION (testGetNEventsClosedException, io::REASIOException);
52  //CPPUNIT_TEST_EXCEPTION(testIDThrow, io::REASIOException);
53  //CPPUNIT_TEST(testSizeBlock);
54  CPPUNIT_TEST_SUITE_END();
55 
56 public:
57  // shared data for tests
58 
61 
62  void
64  {
65  f = new REASFile();
66  event = evt::Event();
67  }
68 
69  void
71  {
72  delete f;
73  }
74 
75  void
77  {
78  REASFile* file;
79  CPPUNIT_ASSERT(file = new REASFile(TESTFILE));
80  delete file;
81  }
82 
83  /*
84  void
85  testConstructException()
86  {
87  Expected();
88  REASFile f(TESTFILE, io::eWrite);
89  }
90 
91  void
92  testOpen()
93  {
94  f->Open(TESTFILE);
95  }
96 
97  void testOpenNonExisting()
98  {
99  Expected();
100  f->Open("NoSuchREASShowerFile.root");
101  }
102 
103  void
104  testOpenForWrite()
105  {
106  Expected();
107  f->Open(TESTFILE, io::eWrite);
108  }
109 
110  void
111  testClose()
112  {
113  f->Open(TESTFILE);
114  f->Close();
115  }
116 
117  void
118  testFindEvent()
119  {
120  f->Open(TESTFILE);
121  CPPUNIT_ASSERT(f->FindEvent(2) == io::eFail);
122  CPPUNIT_ASSERT(f->FindEvent(0) != io::eFail);
123  }
124 
125  void
126  testGotoPosition()
127  {
128  f->Open(TESTFILE);
129  CPPUNIT_ASSERT(f->GotoPosition(0) != io::eFail);
130  CPPUNIT_ASSERT(f->GotoPosition(2) == io::eFail);
131  }
132 
133  void
134  testWrite()
135  {
136  f->Open(TESTFILE);
137  Expected();
138  f->Write(event);
139  }
140 */
141 
142  void
144  {
145  f->Open(TESTFILE);
146  CPPUNIT_ASSERT(f->GetNEvents() == 1);
147  }
148 
149  /*
150  void
151  testGetNEventsClosedException()
152  {
153  Expected();
154  f->GetNEvents();
155  }
156 */
157 
158  void
160  {
161  fwk::CentralConfig::GetInstance(BOOTSTRAPFILE);
162 
163  f->Open(TESTFILE);
164  int nEventsInFile = f->GetNEvents();
165  int nEventsSeen = 0;
166 
167  while (f->Read(event) != io::eEOF) {
168 
169  ++nEventsSeen;
170  evt::ShowerSimData& shower = event.GetSimShower();
171 
172  const CoordinateSystemPtr refCS = det::Detector::GetInstance().GetReferenceCoordinateSystem();
173  shower.MakeGeometry(utl::Point(0,0,0,refCS));
174 
175  // test if CORSIKA variables are set up correctly
176  CPPUNIT_ASSERT(Verify<Equal>(shower.GetPrimaryParticle(), int(Particle::eProton)));
177  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetEnergy(), 1.36772e+18*eV));
178 
179  const utl::CoordinateSystemPtr localCS = shower.GetLocalCoordinateSystem();
180  const double zenith = (-shower.GetDirection()).GetTheta(localCS);
181  const double azimuth = (-shower.GetDirection()).GetPhi(localCS);
182 
183  // THETAP 58.7811 58.7811
184  // PHIP 23.3532 23.3532
185  // declination: 2.714
186 
187  CPPUNIT_ASSERT(Verify<CloseTo>(zenith/deg, 58.7811));
188  CPPUNIT_ASSERT(Verify<CloseTo>(azimuth/deg+360, 23.3532 + 180 - 2.714 + 90.0)); // the 2.714 degrees are the magnetic declination
189  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerNumber(), nEventsSeen));
190  CPPUNIT_ASSERT(Verify<Equal>(shower.GetShowerRunId(), std::string("1")));
191  CPPUNIT_ASSERT(Verify<Equal>(shower.HasGroundParticles(), false)); // no particle file
192  CPPUNIT_ASSERT(Verify<Equal>(shower.HasGHParameters(), true));
193  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetGHParameters().GetXMax()/g*cm2, 6.7450E+02));
194  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetGHParameters().GetNMax(), 8.3636E+08));
195  CPPUNIT_ASSERT(Verify<CloseTo>(shower.GetDistanceOfShowerMaximum()/cm, 123456.7));
196 
197  // test if REAS contents are set up correctly
198  CPPUNIT_ASSERT(Verify<Equal>(shower.HasRadioSimulation(), true));
199  evt::RadioSimulation& radsim = shower.GetRadioSimulation();
200  CPPUNIT_ASSERT(Verify<Equal>(radsim.GetNumPulses(), (long)14));
201  CPPUNIT_ASSERT(Verify<Equal>(radsim.HasCorePosition(), true));
202  bool ok;
203  const evt::SimRadioPulse& simpulse = radsim.GetNextSimRadioPulse(ok);
204  const unsigned int frontpadding = 0; // samples used for padding of the timeseries front
205  const double binning = 1.4*nanosecond;
206  CPPUNIT_ASSERT(Verify<Equal>(ok, true));
207  CPPUNIT_ASSERT(Verify<Equal>(simpulse.GetEfieldTimeSeries().GetSize(), (TraceV3D::SizeType)2012+frontpadding));
208  CPPUNIT_ASSERT(Verify<CloseTo>(simpulse.GetEfieldTimeSeries().GetBinning(), binning));
209  CPPUNIT_ASSERT(Verify<CloseTo>(simpulse.GetBinning(), binning));
210  CPPUNIT_ASSERT(Verify<CloseTo>(simpulse.GetStartTime(), 5.026e-07*second-frontpadding*binning));
211 
212  //const double conversionfactor = 2.99792458e10; // conversion factor from cgs to microVolt/meter
213  //const unsigned int samplenumber = 10; // test sample number 10
214  //Vector3D sample = simpulse.GetEfieldTimeSeries()[samplenumber+frontpadding-1];
215 
216  // cannot easily test amplitudes any more because of electric field rotation due to magnetic declination
217  //CPPUNIT_ASSERT (Verify<CloseTo>(sample[0]/(micro*volt)*meter, 5.7855425609404e-12*conversionfactor)); // east component (-column 2 from REAS)
218  //CPPUNIT_ASSERT (Verify<CloseTo>(sample[1]/(micro*volt)*meter, -3.375375296975e-11*conversionfactor)); // north component (column 1 from REAS)
219  //CPPUNIT_ASSERT (Verify<CloseTo>(sample[2]/(micro*volt)*meter, -5.5331174800789e-11*conversionfactor)); // vertical up component (column 3 from REAS)
220 
221  }
222 
223  CPPUNIT_ASSERT(Verify<Equal>(nEventsInFile, nEventsSeen));
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 testREAS && (cd ..; testREAS)"
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
double GetBinning() const
Get the sampling time scale.
Definition: SimRadioPulse.h:34
Point object.
Definition: Point.h:32
const evt::VGaisserHillasParameter & GetGHParameters() const
Get the Gaisser-Hillas parameters of the shower.
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
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
double GetDistanceOfShowerMaximum() const
Get the geometrical distance of the shower maximum from the core.
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
const double second
Definition: GalacticUnits.h:32
constexpr double g
Definition: AugerUnits.h:200
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)
void testGetNEvents()
void testConstruct()
Definition: testREASFile.cc:76
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.
constexpr double cm
Definition: AugerUnits.h:117
Read REAS simulation output.
Definition: REASFile.h:34
evt::Event event
Definition: testREASFile.cc:60
long GetNumPulses() const
Get the number of radio pulses contained in the RadioSimulation.
void tearDown()
Definition: testREASFile.cc:70
const utl::TraceV3D & GetEfieldTimeSeries() const
Get the Trace of the simulated electric field.
Definition: SimRadioPulse.h:44
REASFile * f
Definition: testREASFile.cc:59
double GetStartTime() const
Get the timestamp of the first sample.
Definition: SimRadioPulse.h:39
constexpr double cm2
Definition: AugerUnits.h:118

, generated on Tue Sep 26 2023.