CDetector/Station.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <boost/lexical_cast.hpp>
4 
5 #include <det/Detector.h>
6 #include <cdet/Station.h>
7 #include <cdet/CDetector.h>
8 #include <cevt/Pad.h>
9 #include <sdet/Station.h>
10 #include <utl/ErrorLogger.h>
11 #include <utl/Math.h>
12 #include <utl/Point.h>
13 #include <utl/Line.h>
14 #include <utl/GeometryUtilities.h>
15 #include <utl/UTMPoint.h>
16 #include <utl/TimeStamp.h>
17 #include <utl/UTCDateTime.h>
18 #include <utl/TimeRange.h>
19 #include <utl/TimeInterval.h>
20 #include <utl/Reader.h>
21 #include <utl/AugerUnits.h>
22 #include <utl/CoordinateSystem.h>
23 #include <utl/AugerCoordinateSystem.h>
24 #include <utl/ReferenceEllipsoid.h>
25 #include <fwk/LocalCoordinateSystem.h>
26 
27 using namespace det;
28 using namespace cdet;
29 using namespace std;
30 using namespace utl;
31 
32 const double Station::kTimeBinSize = 1.0*utl::nanosecond;
33 
34 
35 Station::Station(const int id) :
36  fId(id)
37  ,fStationIdString(boost::lexical_cast<string>(id))
38  //fPadVector
39  //fPartnerIds
40  //fAxes
41  //fName
42  //fInGrid
43  //fRadius
44  //fHeight
45  //fThickness
46  //fCrowns
47  //fReferenceSystem
48  //fPosition
49  //fWaterAbsLength
50  //fWaterRefractionIndex
51  //fLinerReflectivity
52  //fLinerSigmaAlpha
53  //fLinerSpecularLobe
54  //fLinerSpecularSpike
55  //fGroupId
56  //fCommissionRange
57  ,fDense(false)
58 {
59  fRPCPositions.clear();
60  fRPCRotations.clear();
61  fRPCCoordinateSystems.clear();
62 }
63 
64 
66 {
67  fRPCPositions.clear();
68  fRPCRotations.clear();
69  fRPCCoordinateSystems.clear();
70 }
71 
72 
73 const string&
75  const
76 {
77  if (!fName.IsValid()) {
78  GetStationData(fName.Get(), "name", "stationList", "station name");
79  fName.SetValid();
80  }
81  return fName.Get();
82 }
83 
84 
85 const TimeRange&
87  const
88 {
90  if (fDense) { // Dense stations are managed by SDetector
92  Detector::GetInstance().GetSDetector().GetStation(fId).GetCommissionTimeRange();
93  }
94  else {
95  string timeString;
96  GetStationData(timeString, "commission", "stationList", "commission time");
97  const TimeStamp start =
98  boost::lexical_cast<UTCDateTime>(timeString).GetTimeStamp();
99  GetStationData(timeString, "decommission", "stationList", "commission time");
100  const TimeStamp stop =
101  boost::lexical_cast<UTCDateTime>(timeString).GetTimeStamp();
102  fCommissionTimeRange = TimeRange(start, stop);
103  }
104  }
105  return fCommissionTimeRange.Get();
106 }
107 
108 
109 Point
111  const
112 {
113 
114  if (!fPosition.IsValid()) {
115  if (fDense) { // Dense stations are managed by SDetector
116  fPosition =
117  Detector::GetInstance().GetSDetector().GetStation(fId).GetPosition();
118  }
119  else {
120  double northing;
121  GetStationData(northing, "northing", "stationList", "northing");
122  double easting;
123  GetStationData(easting, "easting", "stationList", "easting");
124  double altitude;
125  GetStationData(altitude, "altitude", "stationList", "altitude");
126 
127  string ellipsoid;
128  GetStationData(ellipsoid, "ellipsoid", "stationList", "ellipsoid for UTM conversion");
129  fEllipsoid = ReferenceEllipsoid::GetEllipsoidIDFromString(ellipsoid);
130  string band;
131  GetStationData(band, "band", "stationList", "band for UTM conversion");
132  int zone;
133  GetStationData(zone, "zone", "stationList", "zone for UTM conversion");
134 
135  const UTMPoint utmPosition(northing, easting, altitude, zone, band[0], fEllipsoid);
136  const CoordinateSystemPtr cs = Detector::GetInstance().GetSiteCoordinateSystem();
137  fPosition = utmPosition.GetPoint(cs);
138  }
139  }
140 
141  return fPosition.Get();
142 }
143 
144 
145 int
147  const
148 {
149  if (!fNumberRPCChambers.IsValid()) {
150  GetStationData(fNumberRPCChambers.Get(), "numberRPCChambers", "rpc_positions", "number RPC chambers");
152  }
153  return fNumberRPCChambers.Get();
154 }
155 
156 
157 
158 const Point&
159 Station::GetRPCPosition(const unsigned int id)
160  const
161 {
162  if (fRPCPositions.find(id) == fRPCPositions.end()) {
163 
164  vector<double> coords;
165  GetRPCData(boost::lexical_cast<string>(id),coords,"RPCPosition", "rpc_positions", "RPC coordinates");
166 
167  // Return the RPC chamber position in the SD station coordinate system, whose origin is at
168  // the center of the tank.
169 
170  const sdet::Station & station = Detector::GetInstance().GetSDetector().GetStation(fId);
171 
172  const CoordinateSystemPtr CS = station.GetLocalCoordinateSystem();
173 
174  const double halfHeight = station.GetHeight()/2.;
175  const double thickness = station.GetThickness();
176 
177  fRPCPositions.insert(make_pair(id,Point(coords[0], coords[1], coords[2]-halfHeight-thickness, CS)));
178 
179  }
180 
181  return (fRPCPositions.find(id))->second;
182 }
183 
184 double
185 Station::GetRPCRotation(const unsigned int id)
186  const
187 {
188  if (fRPCRotations.find(id) == fRPCRotations.end()) {
189 
190  double rotation = 0.0;
191  GetRPCData(boost::lexical_cast<string>(id),rotation,"RPCRotation", "rpc_positions", "RPC rotation");
192 
193  // Return the RPC chamber rotation
194 
195  fRPCRotations.insert(make_pair(id,rotation));
196 
197  }
198 
199  return fRPCRotations.find(id)->second;
200 }
201 
203 Station::GetRPCCoordinateSystem(const unsigned int id)
204  const
205 {
206  if (fRPCCoordinateSystems.find(id) == fRPCCoordinateSystems.end()) {
207  const CoordinateSystemPtr & stationCS =
208  det::Detector::GetInstance().GetSDetector().GetStation(fId).GetLocalCoordinateSystem();
209 
210  const Point rpcCenter = GetRPCPosition(id) +
211  Vector(0.0,0.0,GetRPCHousingThickness()[2]+GetRPCHousingInnerDimensions()[2]/2.0,stationCS);
212 
214 
215  const double rot = GetRPCRotation(id);
216 
217  fRPCCoordinateSystems.insert(make_pair(id,CoordinateSystem::RotationZ(-rot, CS)));
218  }
219 
220  return fRPCCoordinateSystems.find(id)->second;
221 }
222 
223 
224 vector<double>
226  const
227 {
229  GetStationData(fTankSupportTopSlabDimensions.Get(), "top_slab", "tank_support", "top slab dimensions");
231  }
233 }
234 
235 
236 vector<double>
238  const
239 {
241  GetStationData(fTankSupportCentralFootDimensions.Get(), "central_foot", "tank_support", "central foot dimensions");
243  }
245 }
246 
247 
248 vector<double>
250  const
251 {
253  GetStationData(fTankSupportCentralFootBaseDimensions.Get(), "central_foot_base", "tank_support", "central foot base dimensions");
255  }
257 }
258 
259 
260 vector<double>
262  const
263 {
265  GetStationData(fTankSupportOuterFootDimensions.Get(), "outer_foot", "tank_support", "outer foot dimensions");
267  }
269 }
270 
271 
272 vector<double>
274  const
275 {
277  GetStationData(fTankSupportOuterFootBaseDimensions.Get(), "outer_foot_base", "tank_support", "outer foot base dimensions");
279  }
281 }
282 
283 
284 double
286  const
287 {
289  GetStationData(fTankSupportOuterFootDistanceToCenter.Get(), "outer_foot_distance_to_center", "tank_support", "outer foot distance to center");
291  }
293 }
294 
295 
296 vector<double>
298  const
299 {
301  GetStationData(fRPCHousingInnerDimensions.Get(), "inner_dimensions", "rpc_housing", "RPC housing inner dimensions");
303  }
305 }
306 
307 
308 vector<double>
310  const
311 {
312  if (!fRPCHousingThickness.IsValid()) {
313  GetStationData(fRPCHousingThickness.Get(), "thickness", "rpc_housing", "RPC housing thickness");
315  }
316  return fRPCHousingThickness.Get();
317 }
318 
319 
321 double
323  const
324 {
325  if (!fRPCSizeX.IsValid()) {
326  GetStationData(fRPCSizeX.Get(), "size_x", "rpc_chamber", "RPC size in X");
328  }
329  return fRPCSizeX.Get();
330 }
331 
332 
333 double
335  const
336 {
337  if (!fRPCSizeY.IsValid()) {
338  GetStationData(fRPCSizeY.Get(), "size_y", "rpc_chamber", "RPC size in Y");
340  }
341  return fRPCSizeY.Get();
342 }
343 
344 
346 vector<unsigned int>
348  const
349 {
350  if (!fListPadIds.IsValid() || fListPadIds.Get().begin() == fListPadIds.Get().end()) {
352  for (int ir=1; ir<GetNumberRPCChambers()+1;++ir)
353  for (int row=1; row<GetNumberPadsY()+1 ;++row)
354  for (int col=1; col<GetNumberPadsX()+1;++col)
355  fListPadIds.Get().push_back(10000*ir+(row-1)*GetNumberPadsX() + col);
356  }
357 
358  return fListPadIds.Get();
359 }
360 
361 
362 int
364  const
365 {
366  if (!fNumberPadsX.IsValid()) {
367  GetStationData(fNumberPadsX.Get(), "number_pads_x", "rpc_readout", "Number of pads in X");
369  }
370  return fNumberPadsX.Get();
371 }
372 
373 
374 int
376  const
377 {
378  if (!fNumberPadsY.IsValid()) {
379  GetStationData(fNumberPadsY.Get(), "number_pads_y", "rpc_readout", "Number of pads in Y");
381  }
382  return fNumberPadsY.Get();
383 }
384 
385 
386 double
388  const
389 {
390  if (!fPadSizeX.IsValid()) {
391  fPadSizeX.Get() = GetRPCSizeX()/float(GetNumberPadsX());
393  }
394  return fPadSizeX.Get();
395 }
396 
397 
398 double
400  const
401 {
402  if (!fPadSizeY.IsValid()) {
403  fPadSizeY.Get() = GetRPCSizeY()/float(GetNumberPadsY());
405  }
406  return fPadSizeY.Get();
407 }
408 
409 
410 double
412  const
413 {
414  if (!fPadArea.IsValid()) {
416  fPadArea.SetValid();
417  }
418  return fPadArea.Get();
419 }
420 
421 
422 Point
424  const
425 {
426  return GetPadPosition(pad.GetId());
427 }
428 
429 
430 Point
431 Station::GetPadPosition(const unsigned int & id)
432  const
433 {
434  const unsigned int chamberId = int(id/10000);
435  const unsigned int padId = id - chamberId*10000;
436 
437  const double sizeX = GetRPCSizeX();
438  const double sizeY = GetRPCSizeY();
439  const unsigned int nPadsX = GetNumberPadsX();
440  const double padSizeX = GetPadSizeX();
441  const double padSizeY = GetPadSizeY();
442 
443  const unsigned int row = int((padId-1)/nPadsX) + 1;
444  const unsigned int col = padId - int((row-1)*nPadsX);
445 
446  // Coords of cener of pad w.r.t. center of RPC chamber
447  const float padX = -sizeX/2.0 + (col-1)*padSizeX + padSizeX/2.0;
448  const float padY = -sizeY/2.0 + (row-1)*padSizeY + padSizeY/2.0;
449  const float padZ = 0.0*meter;
450 
451  // Define RPC Coordinate System centered in center of RPC
452  const utl::CoordinateSystemPtr rpcCS = GetRPCCoordinateSystem(chamberId);
453 
454  return Point(padX,padY,padZ,rpcCS);
455 }
456 
457 
458 unsigned int
460  const
461 {
462  const unsigned int nRPC = GetNumberRPCChambers();
463  const unsigned int numPadsX = GetNumberPadsX();
464 
465  const float rpcSizeX = GetRPCSizeX();
466  const float rpcSizeY = GetRPCSizeY();
467  const float rpcSizeZ = GetRPCHousingInnerDimensions()[2];
468 
469  const float padSizeX = GetPadSizeX();
470  const float padSizeY = GetPadSizeY();
471 
472  double posX = numeric_limits<double>::max();
473  double posY = numeric_limits<double>::max();
474  double posZ = numeric_limits<double>::max();
475 
476  unsigned int rpcId = 0;
477 
478  for (unsigned int i = 1; i < nRPC+1; ++i) {
479 
481 
482  posX = pos.GetX(CS);
483  posY = pos.GetY(CS);
484  posZ = pos.GetZ(CS);
485 
486  if (abs(posX) < rpcSizeX/2.0 && abs(posY) < rpcSizeY/2.0 && abs(posZ) < rpcSizeZ/2.0) {
487  rpcId = i;
488  break;
489  }
490  }
491 
492  int padId = 0;
493 
494  if (abs(posX) < rpcSizeX/2.0 && abs(posY) < rpcSizeY/2.0) {
495  int col = int((posX-(-rpcSizeX/2.0))/padSizeX) + 1;
496  int row = int((posY-(-rpcSizeY/2.0))/padSizeY) + 1;
497 
498  if (row > 0 && col > 0)
499  padId = (row-1)*numPadsX + col;
500  }
501 
502  if (rpcId > 0 && padId > 0)
503  padId = 10000*rpcId + padId;
504 
505  return padId;
506 }
507 
508 
509 double
511  const
512 {
513  if (!fDeadTime.IsValid()) {
514  GetStationData(fDeadTime.Get(), "dead_time", "rpc_readout", "Dead time");
516  }
517  return fDeadTime.Get();
518 }
519 
520 
521 bool
523  const
524 {
525  if (!fInGrid.IsValid()) {
526  InGridType& inGrid = fInGrid.Get();
527  inGrid.reset();
528  vector<bool> data;
529 
530  if (fDense)
531  data.clear();
532  else
533  GetStationData(data, "inGrid", "stationList", "get is-in-grid");
534 
535  for (size_t i = 0; i < data.size() && i < inGrid.size(); ++i)
536  inGrid[i] = data[i];
537  fInGrid.SetValid();
538  }
539 
540  const InGridType& inGrid = fInGrid.Get();
541  if (index == CDetectorConstants::eAny)
542  return inGrid.any();
543  else
544  return inGrid[index];
545 }
546 
547 
548 void
549 Station::NotFoundAndThrow(const string& msg)
550  const
551 {
552  ostringstream err;
553  err << "Did not find requested component: '" << msg
554  << "' for station = " << fStationIdString;
555  throw NonExistentComponentException(err.str());
556 }
557 
558 
559 void
561  const
562 {
563  /*
564  In this method we clean all the variables that might change with time and deleted whatever was allocated in the get*'s
565  Data members that are NOT reset are:
566  fName
567  fInGrid
568  fRadius
569  fHeight
570  fThickness
571  fCommissionTime
572  fDecommissionTime
573  fPosition (unless it is a dense station)
574  fStationIdString
575  fPartnerIdsSet
576  fPartnerIds
577  fAxes
578  */
579 
580  if (fDense) {
581  fPosition.SetValid(false);
582  fReferenceSystem = CoordinateSystemPtr(); // clear the ptr so CS can be reassigned
583  fRPCPositions.clear();
584  fRPCRotations.clear();
585  fRPCCoordinateSystems.clear();
586  fListPadIds.Get().clear();
587  }
588 }
589 
590 // Configure (x)emacs for this file ...
591 // Local Variables:
592 // mode: c++
593 // End:
utl::Validated< std::string > fName
utl::Validated< double > fRPCSizeY
double GetPadArea() const
Point object.
Definition: Point.h:32
Detector description interface for Station-related data.
utl::Validated< double > fPadArea
utl::Validated< int > fNumberPadsX
Time interval defined by two TimeStamps.
Definition: TimeRange.h:23
unsigned int GetPadId(const utl::Point &position) const
utl::ReferenceEllipsoid::EllipsoidID fEllipsoid
const utl::TimeRange & GetCommissionTimeRange() const
Station commission time range.
utl::CoordinateSystemPtr GetRPCCoordinateSystem(unsigned int id) const
utl::Validated< utl::Point > fPosition
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
std::map< unsigned int, double > fRPCRotations
utl::Validated< utl::TimeRange > fCommissionTimeRange
double GetPadSizeY() const
std::string fStationIdString
int GetNumberPadsX() const
RPC readout parameters.
utl::Validated< double > fTankSupportOuterFootDistanceToCenter
void Update() const
double GetRPCSizeX() const
Dimensions of the RPC chamber.
const double meter
Definition: GalacticUnits.h:29
bool IsInGrid(const cdet::CDetectorConstants::GridIndex index=cdet::CDetectorConstants::eStandard) const
Tells whether the station is in the regular triangular grid.
std::vector< double > GetTankSupportOuterFootBaseDimensions() const
Base class for exceptions trying to access non-existing components.
det::VManager::Status GetStationData(T &requestedData, const std::string &property, const std::string &component, const std::string &errorMsg, const bool throwOnFailure=true) const
std::map< unsigned int, utl::Point > fRPCPositions
utl::Point GetPosition() const
Station position in Site Cartesian Coordinates.
utl::Validated< double > fRPCSizeX
utl::Validated< std::vector< double > > fTankSupportOuterFootBaseDimensions
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
utl::Validated< double > fPadSizeY
const std::string & GetName() const
Station name.
class to hold data at Pad level
Definition: Pad.h:27
unsigned int GetId() const
Return Id of the Pad.
Definition: Pad.h:31
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
std::vector< double > GetRPCHousingInnerDimensions() const
Size of the RPC aluminum housing.
utl::Validated< std::vector< double > > fTankSupportOuterFootDimensions
#define max(a, b)
std::vector< double > GetTankSupportOuterFootDimensions() const
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
utl::Point GetPadPosition(const cevt::Pad &pad) const
Pad position relative to center of the tank.
utl::Validated< double > fPadSizeX
utl::Validated< double > fDeadTime
int GetNumberRPCChambers() const
Number of RPC Chambers.
constexpr double nanosecond
Definition: AugerUnits.h:143
std::vector< double > GetTankSupportCentralFootDimensions() const
utl::Validated< InGridType > fInGrid
double abs(const SVector< n, T > &v)
double GetRPCSizeY() const
utl::Validated< int > fNumberRPCChambers
const double second
Definition: GalacticUnits.h:32
bool IsValid() const
Definition: Validated.h:64
utl::CoordinateSystemPtr fReferenceSystem
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger reference system centered on the tank.
double GetHeight() const
Height of the tank (water only)
std::vector< unsigned int > GetListPadIds() const
RPC readout parameters.
det::VManager::Status GetRPCData(const std::string &id, T &requestedData, const std::string &property, const std::string &component, const std::string &errorMsg, const bool throwOnFailure=true) const
double GetDeadTime() const
utl::Validated< std::vector< double > > fRPCHousingThickness
utl::Validated< int > fNumberPadsY
utl::Validated< std::vector< double > > fTankSupportCentralFootDimensions
std::map< unsigned int, utl::CoordinateSystemPtr > fRPCCoordinateSystems
std::vector< double > GetRPCHousingThickness() const
Thickness of walls of the RPC aluminum housing.
std::vector< double > GetTankSupportCentralFootBaseDimensions() const
double GetTankSupportOuterFootDistanceToCenter() const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
double GetThickness() const
Thickness of the tank walls.
const utl::Point & GetRPCPosition(const unsigned int id) const
RPC position.
uint16_t * data
Definition: dump1090.h:228
std::bitset< CDetectorConstants::kGridIndexSize > InGridType
utl::Validated< std::vector< double > > fTankSupportCentralFootBaseDimensions
Vector object.
Definition: Vector.h:30
double GetRPCRotation(const unsigned int id) const
RPC rotation around its Z axis (axis perpendicular to RPC plane.
void SetValid(const bool valid=true)
Definition: Validated.h:66
void NotFoundAndThrow(const std::string &msg) const
int GetNumberPadsY() const
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
utl::Validated< std::vector< unsigned int > > fListPadIds
RPC readout parameters.
utl::Validated< std::vector< double > > fTankSupportTopSlabDimensions
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
Point GetPoint(const CoordinateSystemPtr &theCS=CoordinateSystemPtr()) const
Get a cartesian point from an UTMPoint.
Definition: UTMPoint.cc:45
double GetPadSizeX() const
utl::Validated< std::vector< double > > fRPCHousingInnerDimensions
std::vector< double > GetTankSupportTopSlabDimensions() const

, generated on Tue Sep 26 2023.