RdStationSimAntennaAlignmentError.cc
Go to the documentation of this file.
2 
3 #include <fwk/CentralConfig.h>
4 #include <fwk/CoordinateSystemRegistry.h>
5 
6 #include <utl/ErrorLogger.h>
7 #include <utl/Reader.h>
8 #include <utl/config.h>
9 #include <utl/Trace.h>
10 #include <utl/TraceAlgorithm.h>
11 #include <utl/TimeStamp.h>
12 #include <utl/TimeInterval.h>
13 #include <utl/AugerUnits.h>
14 #include <utl/AugerException.h>
15 #include <utl/FFTDataContainerAlgorithm.h>
16 #include <utl/Math.h>
17 #include <utl/Vector.h>
18 #include <utl/AxialVector.h>
19 #include <utl/AugerCoordinateSystem.h>
20 #include <utl/CoordinateSystemPtr.h>
21 #include <utl/UTMPoint.h>
22 
23 #include <evt/Event.h>
24 #include <revt/REvent.h>
25 #include <revt/Header.h>
26 #include <evt/ShowerRecData.h>
27 #include <evt/ShowerSimData.h>
28 #include <evt/ShowerRRecData.h>
29 #include <evt/ShowerFRecData.h>
30 #include <evt/ShowerSRecData.h>
31 #include <revt/Channel.h>
32 
33 #include <rdet/RDetector.h>
34 #include <rdet/Station.h>
35 
36 #include <fwk/LocalCoordinateSystem.h>
37 
38 
39 #define OUT(x) if ((x) <= fInfoLevel) cerr << " "
40 
41 using namespace revt;
42 using namespace fwk;
43 using namespace utl;
44 using namespace std;
45 
47 
49  : fInfoLevel(0),
50  fOnlyForVariedEvents(0),
51  fZenithalAlignmentError(0),
52  fAzimuthalAlignmentError(0),
53  fRandomSeed(0),
54  randgen(),
55  normalRandom(0.0, 1.0),
56  normalRandomGenerator(randgen, normalRandom),
57  uniformRandom(0.0, kPi),
58  uniformRandomGenerator(randgen, uniformRandom)
59  {}
60 
61  RdStationSimAntennaAlignmentError::~RdStationSimAntennaAlignmentError() {}
62 
64  {
65  INFO("RdStationSimAntennaAlignmentError::Init()");
66 
67  // Read in the configurations of the xml file
68  Branch topBranch =
69  CentralConfig::GetInstance()->GetTopBranch("RdStationSimAntennaAlignmentError");
70  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
71  topBranch.GetChild("OnlyForVariedEvents").GetData(fOnlyForVariedEvents);
72  topBranch.GetChild("ZenithalAlignmentError").GetData(fZenithalAlignmentError);
73  topBranch.GetChild("AzimuthalAlignmentError").GetData(fAzimuthalAlignmentError);
74  topBranch.GetChild("randomSeed").GetData(fRandomSeed);
75 
76  if (fRandomSeed) {
77  OUT(0) << "Seeding the random generator with " << fRandomSeed << endl;
78  randgen.seed(fRandomSeed);
79  }
80 
81  return eSuccess;
82  }
83 
84  Vector3D RotateZ(Vector3D c, double ang) {
85  Vector3D d;
86  d[0] = cos(ang)*c[0] - sin(ang)*c[1] ;
87  d[1] = sin(ang)*c[0] + cos(ang)*c[1] ;
88  d[2] = c[2];
89  return d;
90  }
91 
92  Vector3D RotateX(Vector3D c, double ang) {
93  Vector3D d;
94  d[0] = c[0] ;
95  d[1] = cos(ang)*c[1] - sin(ang)*c[2];
96  d[2] = sin(ang)*c[1] + cos(ang)*c[2];
97  return d;
98  }
99 
100  Vector3D ApplyAlignmentError(Vector3D c, double angZ1, double angZ2, double angX)
101  {
102  return RotateZ(RotateX(RotateZ(RotateZ(c, angZ1), angZ2), angX), -angZ2);
103  }
104 
105 
106  VModule::ResultFlag RdStationSimAntennaAlignmentError::Run(evt::Event& event)
107  {
108  INFO("RdStationSimAntennaAlignmentError::Run()");
109 
110  // Check wether there are events at all
111  if(!event.HasREvent()) {
112  WARNING("No radio event found!");
113  return eContinueLoop;
114  }
115 
116  REvent& rEvent = event.GetREvent();
117  const rdet::RDetector& rDetector =
118  det::Detector::GetInstance().GetRDetector();
119 
120  int the_id = rEvent.GetHeader().GetId();
121  // This is a workaround for the SELFAS reader that doesn't implement
122  // the reading of the event ID into the rHeader. This should be fixed
123  // in the SELFAS reader and then this if clause should be removed.
124  if (the_id == 1) {
125  the_id = atoi(event.GetHeader().GetId().c_str());
126  rEvent.GetHeader().SetId(the_id);
127  }
128 
129  if (fOnlyForVariedEvents and the_id < 99999999) {
130  OUT(2) << "Not adding a random rotation: the SD event ID is below 99999999 and the antenna orientation will not be randomized." << endl;
131  return eSuccess;
132  }
133 
134 
135  // loop through stations
136  for (REvent::StationIterator sIt = rEvent.StationsBegin();
137  sIt != rEvent.StationsEnd(); ++sIt) {
138 
140  double angZ2 = uniformRandomGenerator();
142 
143  OUT(3) << "Rotating the trace slightly to account for the error in the alignment of the antenna with the earth magnetic field..." << endl;
144  OUT(3) << "Rotation1: about the Z-axis with " << angZ1/degree << " deg drawn from a normal distribution with with sigma=" << fAzimuthalAlignmentError/degree << " deg." << endl;
145  OUT(3) << "Rotation2: about the Z-axis with " << angZ2/degree << " deg drawn from a uniform distribution between 0 and Pi." << endl;
146  OUT(3) << "Rotation3: about the X-axis with " << angX/degree << " deg drawn from a normal distribution with sigma=" << fZenithalAlignmentError/degree << " deg." << endl;
147  OUT(3) << "Rotation4: back around the Z-axis with " << -angZ2/degree << " deg (inverse of rotation2)." << endl;
148 
149  StationTimeSeries &TimeSeries = sIt->GetFFTDataContainer().GetTimeSeries();
150  for (unsigned int i = 0; i < TimeSeries.GetSize(); ++i) {
151  TimeSeries[i] = ApplyAlignmentError(TimeSeries[i], angZ1, angZ2, angX);
152  }
153 
154  }
155  return eSuccess;
156  }
157 
159  RdStationSimAntennaAlignmentError::Finish()
160  {
161 
162  INFO("RdStationSimAntennaAlignmentError::Finish()");
163 
164  return eSuccess;
165  }
166 
167 }
Branch GetTopBranch() const
Definition: Branch.cc:63
const double degree
Report success to RunController.
Definition: VModule.h:62
evt::Header & GetHeader()
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
Skip remaining modules in the current loop and continue with next iteration of the loop...
Definition: VModule.h:68
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
StationIterator StationsEnd()
Definition: REvent.h:130
StationIterator StationsBegin()
Definition: REvent.h:128
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
Definition: REvent.h:125
bool HasREvent() const
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
boost::variate_generator< boost::mt19937, boost::uniform_real< double > > uniformRandomGenerator
Class representing a document branch.
Definition: Branch.h:107
Vector3D ApplyAlignmentError(Vector3D c, double angZ1, double angZ2, double angX)
constexpr double kPi
Definition: MathConstants.h:24
Header & GetHeader()
access to REvent Header
Definition: REvent.h:239
SizeType GetSize() const
Definition: Trace.h:156
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
const std::string & GetId() const
Get the event identifier.
Definition: Event/Header.h:31
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
Definition: Trace-fwd.h:19
void SetId(const int id)
Definition: REvent/Header.h:28
int GetId() const
Definition: REvent/Header.h:21
boost::variate_generator< boost::mt19937, boost::normal_distribution< double > > normalRandomGenerator

, generated on Tue Sep 26 2023.