testMDetector.cc
Go to the documentation of this file.
1 
9 #include <fwk/RunController.h>
10 #include <fwk/CentralConfig.h>
11 #include <fwk/CoordinateSystemRegistry.h>
12 
13 #include <det/Detector.h>
14 #include <sdet/SDetector.h>
15 #include <sdet/Station.h>
16 
17 #include <utl/TimeStamp.h>
18 #include <utl/UTCDateTime.h>
19 #include <utl/Point.h>
20 #include <utl/ReferenceEllipsoid.h>
21 #include <utl/CoordinateSystem.h>
22 
23 #include <mdet/MDetector.h>
24 #include <mdet/Module.h>
25 #include <mdet/Counter.h>
26 #include <mdet/Scintillator.h>
27 #include <mdet/Channel.h>
28 #include <mdet/PMT.h>
29 #include <mdet/Fiber.h>
30 
31 #include <tst/Verify.h>
32 
33 #include <cppunit/extensions/HelperMacros.h>
34 # include <bitset>
35 
36 using namespace det;
37 using namespace std;
38 using namespace utl;
39 using namespace fwk;
40 using namespace tst;
41 using namespace mdet;
42 
43 #define ASSERT_CLOSE(x, y, eps) CPPUNIT_ASSERT(Verify<CloseTo>(x, y, eps))
44 #define ASSERT_EQUAL(x, y) CPPUNIT_ASSERT(Verify<Equal>(x, y))
45 
46 class MDetectorTest : public CppUnit::TestFixture {
47 
48  CPPUNIT_TEST_SUITE(MDetectorTest);
49  CPPUNIT_TEST(testBasic);
50  CPPUNIT_TEST(testComponentAssignment);
51  CPPUNIT_TEST(testBrokenChannelsAssignment);
52  CPPUNIT_TEST_SUITE_END();
53 
54 public:
55  void
57  {
58  ErrorLogger::GetInstance().SetVerbosity(Verbosity::eVerbose);
59 
60  // CentralConfig must be created first.
61  //
62  /*CentralConfig* fCentralConfig =*/
63  fwk::CentralConfig::GetInstance(BOOTSTRAPFILE);
64 
65  // Create a detector
66  //
67  /*Detector& theDetector =*/
68  Detector::GetInstance();
69  }
70 
71  void tearDown() { }
72 
73  void
75  {
76  Detector& detector = Detector::GetInstance();
77  const TimeStamp t = UTCDateTime(2013,1,1).GetTimeStamp();
78  detector.Update(t);
79 
80  const CoordinateSystemPtr cs = detector.GetSiteCoordinateSystem(); // Malargue CS
81  const MDetector& mDetector = detector.GetMDetector();
82  const Counter& dCounter = mDetector.GetCounter(2); // get counter 2 (associated to SD tank 639)
83 
84  // test if position is correct
85  ASSERT_CLOSE(dCounter.GetPosition().GetX(cs), 9487.37, 1e-3*m);
86  ASSERT_CLOSE(dCounter.GetPosition().GetY(cs), 52594.7, 1e-3*m);
87  ASSERT_CLOSE(dCounter.GetPosition().GetZ(cs), 1337.47, 1e-3*m);
88 
89  const sdet::Station& asscociatedStation = dCounter.GetAssociatedTank();
90  ASSERT_EQUAL(asscociatedStation.GetId(), 639);
91 
92  // segmentation should be 192
93  ASSERT_EQUAL(dCounter.GetSegmentation(), static_cast<unsigned int>(192));
94 
95  // check that counter has 3 modules with IDs from 1 to 3
96  int moduleCounter = 1;
97  for (Counter::ModuleConstIterator cIt = dCounter.ModulesBegin();
98  cIt !=dCounter.ModulesEnd(); ++cIt) {
99  ASSERT_EQUAL(cIt->GetId(), moduleCounter);
100  ++moduleCounter;
101  }
102  ASSERT_EQUAL(moduleCounter, 4);
103 
104  // now test module substructure of module 3 (fibers and scintillators)
105  const Module& dModule = dCounter.GetModule(3);
106 
107  int fiberCounter = 1;
108  for (Module::FiberConstIterator fIt = dModule.FibersBegin();
109  fIt !=dModule.FibersEnd(); ++fIt) {
110  ASSERT_EQUAL(fIt->GetId(), fiberCounter);
111  ++fiberCounter;
112  }
113  ASSERT_EQUAL(fiberCounter, 65);
114 
115  int scintillatorCounter = 1;
117  sIt !=dModule.ScintillatorsEnd(); ++sIt) {
118  ASSERT_EQUAL(sIt->GetId(), scintillatorCounter);
119  ++scintillatorCounter;
120  }
121  ASSERT_EQUAL(scintillatorCounter, 65);
122 
123  }
124 
125  void
126  testBrokenChannelsAssignment( int CtrId, int ModId, TimeStamp t )
127  {
128  Detector& detector = Detector::GetInstance();
129  detector.Update(t);
130 
131  const MDetector& mDetector = detector.GetMDetector();
132  const Counter& dCounter = mDetector.GetCounter(CtrId);
133  const Module& dModule = dCounter.GetModule(ModId);
134  const FrontEnd& frontend = dModule.GetFrontEnd();
135  const ULong64_t mask = dModule.GetFrontEnd().GetMask();
136  const bitset<64> bit_mask = mask;
137 
138  std::cout << "mask for counter " << CtrId << " module " << ModId << "\nin decimal: " << std::endl;
139  std::cout << "Sampling rate:" << frontend.GetMeanSampleRatePeriod() << endl;
140  std::cout << "Buffer length:" << frontend.GetPreT1BufferLength() + frontend.GetPostT1BufferLength() << endl;
141  std::cout << mask << std::endl;
142  std::cout << "in bits: " << std::endl;
143  std::cout << bit_mask << " ==> (" << bit_mask.count() << ")\n";
144 
145  }
146 
147  void
149  {
150  testBrokenChannelsAssignment(1764, 1, UTCDateTime(2015,7,22).GetTimeStamp());
151  testBrokenChannelsAssignment(1764, 2, UTCDateTime(2015,7,23).GetTimeStamp());
152  testBrokenChannelsAssignment(93 , 2, UTCDateTime(2015,7,24).GetTimeStamp());
153  testBrokenChannelsAssignment(1622, 7, UTCDateTime(2015,7,25).GetTimeStamp());
154  }
155 
156  void
158  {
159  Detector& detector = Detector::GetInstance();
160  const TimeStamp t = UTCDateTime(2013,1,1).GetTimeStamp();
161  detector.Update(t);
162 
163  const MDetector& mDetector = detector.GetMDetector();
164 
165  const Counter& dCounter = mDetector.GetCounter(1); // get counter 1 (associated to SD tank 608)
166  const Module& dModule = dCounter.GetModule(1);
167 
168  const PMT& pmt = dModule.GetPMT();
169 
170  int pixelCounter = 1;
171  for (PMT::PixelConstIterator pIt = pmt.PixelsBegin();
172  pIt !=pmt.PixelsEnd(); ++pIt) {
173  ASSERT_EQUAL(pIt->GetId(), pixelCounter);
174  ++pixelCounter;
175  }
176  ASSERT_EQUAL(pixelCounter, 65);
177 
178  const FrontEnd& frontend = dModule.GetFrontEnd();
179 
180  int channelCounter = 1;
181  for (FrontEnd::ChannelConstIterator cIt = frontend.ChannelsBegin();
182  cIt !=frontend.ChannelsEnd(); ++cIt) {
183  ASSERT_EQUAL(cIt->GetId(), channelCounter-1); // channel IDs start at 0
184  ++channelCounter;
185  }
186  ASSERT_EQUAL(channelCounter, 65);
187 
188  // test association of differerent commponents in two ways
189  ASSERT_EQUAL(dModule.ScintillatorToChannelId(10), 10);
190  ASSERT_EQUAL(dModule.ScintillatorToPixelId(10), 22);
191  ASSERT_EQUAL(dModule.ScintillatorToFiberId(10), 10);
192  ASSERT_EQUAL(dModule.GetChannelFor(dModule.GetScintillator(10)).GetId(), 10);
193  ASSERT_EQUAL(dModule.GetPixelFor(dModule.GetScintillator(10)).GetId(), 22);
194  ASSERT_EQUAL(dModule.GetFiberFor(dModule.GetScintillator(10)).GetId(), 10);
195 
196  ASSERT_EQUAL(dModule.ChannelToScintillatorId(10), 10);
197  ASSERT_EQUAL(dModule.ChannelToPixelId(10), 22);
198  ASSERT_EQUAL(dModule.ChannelToFiberId(10), 10);
199  ASSERT_EQUAL(dModule.GetScintillatorFor(dModule.GetChannel(10)).GetId(), 10);
200  ASSERT_EQUAL(dModule.GetPixelFor(dModule.GetChannel(10)).GetId(), 22);
201  ASSERT_EQUAL(dModule.GetFiberFor(dModule.GetChannel(10)).GetId(), 10);
202 
203  ASSERT_EQUAL(dModule.FiberToChannelId(10), 10);
204  ASSERT_EQUAL(dModule.FiberToScintillatorId(10), 10);
205  ASSERT_EQUAL(dModule.FiberToPixelId(26), 10);
206  ASSERT_EQUAL(dModule.GetChannelFor(dModule.GetFiber(10)).GetId(), 10);
207  ASSERT_EQUAL(dModule.GetScintillatorFor(dModule.GetFiber(10)).GetId(), 10);
208  ASSERT_EQUAL(dModule.GetPixelFor(dModule.GetFiber(26)).GetId(), 10);
209 
210  ASSERT_EQUAL(dModule.PixelToScintillatorId(22), 10);
211  ASSERT_EQUAL(dModule.PixelToFiberId(10), 26);
212  ASSERT_EQUAL(dModule.PixelToChannelId(22), 10);
213  ASSERT_EQUAL(dModule.GetScintillatorFor(dModule.GetPixel(22)).GetId(), 10);
214  ASSERT_EQUAL(dModule.GetFiberFor(dModule.GetPixel(10)).GetId(), 26);
215  ASSERT_EQUAL(dModule.GetChannelFor(dModule.GetPixel(22)).GetId(), 10);
216  }
217 
218 
219 };
220 
int PixelToScintillatorId(const int pId) const
void Update(const utl::TimeStamp &time, const bool invData=true, const bool invComp=true, const bool forceRadio=false)
Update detector: deletes currently constructed stations and sets new time.
Definition: Detector.cc:179
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
const Pixel & GetPixel(int pId) const
Detector description interface for Station-related data.
#define ASSERT_EQUAL(x, y)
PixelGroup::ConstIterator PixelConstIterator
Convenience typedef for const iterator over the contained mdet::Pixel instances.
const mdet::MDetector & GetMDetector() const
Definition: Detector.cc:155
int ScintillatorToPixelId(const int sId) const
ChannelConstIterator ChannelsEnd() const
End iterator over the contained channels.
Definition: FrontEnd.h:91
unsigned int GetPostT1BufferLength() const
Number of bins of the post-T1 buffer.
Definition: FrontEnd.cc:65
const Fiber & GetFiberFor(const Component &c) const
Linking between fibers, scintillators, channels and pixels.
Traditional name.
Definition: Verbosity.h:17
const Channel & GetChannelFor(const Component &c) const
Returns the associated mdet::Channel.
int ChannelToPixelId(const int cId) const
ScintillatorConstIterator ScintillatorsBegin() const
Begin iterator over the contained scitillators.
utl::Point GetPosition() const
Electronic front-end for the modules.
Definition: FrontEnd.h:33
unsigned int GetPreT1BufferLength() const
Number of bins of the (cyclic) pre-T1 buffer.
Definition: FrontEnd.cc:57
int ScintillatorToChannelId(const int sId) const
utl::CoordinateSystemPtr GetSiteCoordinateSystem() const
Get the coordinate system for the site.
Definition: Detector.h:137
ModuleConstIterator ModulesEnd() const
Begin iterator for the Modules contained in the Counter.
int FiberToChannelId(const int fId) const
const Channel & GetChannel(int cId) const
Detector associated to muon detector hierarchy.
Definition: MDetector.h:32
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
int ChannelToScintillatorId(const int cId) const
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
ChannelGroup::ConstIterator ChannelConstIterator
Convenience typedef for const iterator over the contained mdet::Channel instances.
Definition: FrontEnd.h:80
void testBrokenChannelsAssignment()
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
Definition: FrontEnd.cc:43
FiberConstIterator FibersBegin() const
Begin iterator over the contained fibers.
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
Array of Scintillator.
int FiberToPixelId(const int fId) const
int PixelToChannelId(const int pId) const
FiberConstIterator FibersEnd() const
End iterator over the contained fibers.
void testComponentAssignment()
ScintillatorGroup::ConstIterator ScintillatorConstIterator
Scintillator handling.
const Scintillator & GetScintillatorFor(const Component &c) const
Returns the associated mdet::Scintillator.
Multiple-pixel photo-multiplier tube.
Definition: MDetector/PMT.h:49
const Pixel & GetPixelFor(const Component &c) const
Returns the associated mdet::Pixel.
const FrontEnd & GetFrontEnd() const
PixelConstIterator PixelsBegin() const
Begin iterator over the contained pixels.
ULong64_t GetMask() const
Size of the (cyclic) external memory buffer associated to each module.
Definition: FrontEnd.cc:104
Root detector of the muon detector hierarchy.
int ScintillatorToFiberId(const int sId) const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
int FiberToScintillatorId(const int fId) const
ScintillatorConstIterator ScintillatorsEnd() const
End iterator over the contained scintillators.
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
const Fiber & GetFiber(int fId) const
FiberGroup::ConstIterator FiberConstIterator
Fiber handling.
ChannelConstIterator ChannelsBegin() const
Begin iterator over the contained channels.
Definition: FrontEnd.h:85
ModuleConstIterator ModulesBegin() const
Begin iterator for the Modules contained in the Counter.
void testBrokenChannelsAssignment(int CtrId, int ModId, TimeStamp t)
const sdet::Station & GetAssociatedTank() const
Retrieve the associated tank.
ModuleGroup::ConstIterator ModuleConstIterator
Convenience typedef for const iterator over the contained Module instances.
unsigned int GetSegmentation() const
#define ASSERT_CLOSE(x, y, eps)
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
const Scintillator & GetScintillator(int sId) const
Direct accesor by id.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
Definition: MDetector.h:68
int ChannelToFiberId(const int cId) const
constexpr double m
Definition: AugerUnits.h:121
TimeStamp GetTimeStamp() const
Definition: UTCDateTime.cc:115
int PixelToFiberId(const int pId) const
PixelConstIterator PixelsEnd() const
End iterator over the contained pixels.
const PMT & GetPMT() const

, generated on Tue Sep 26 2023.