FD2ADSTUtil.cc
Go to the documentation of this file.
1 #include <utl/config.h>
2 
3 #include "FD2ADSTUtil.h"
4 #include "ConversionUtil.h"
5 
6 #include <adst/RecEvent.h>
7 
8 #include <fwk/CentralConfig.h>
9 #include <fwk/LocalCoordinateSystem.h>
10 #include <fwk/CoordinateSystemRegistry.h>
11 
12 #include <det/VManager.h>
13 #include <det/Detector.h>
14 #include <det/ManagerRegister.h>
15 
16 #include <fdet/FDetector.h>
17 #include <fdet/Pixel.h>
18 #include <fdet/Camera.h>
19 #include <fdet/Eye.h>
20 #include <fdet/Telescope.h>
21 
22 #include <sdet/SDetector.h>
23 #include <sdet/Station.h>
24 
25 #include <evt/Event.h>
26 #include <evt/ShowerRecData.h>
27 #include <evt/ShowerSimData.h>
28 #include <evt/ShowerFRecData.h>
29 #include <evt/ShowerSRecData.h>
30 #include <evt/RiseTime1000.h>
31 
32 #include <evt/GaisserHillas4Parameter.h>
33 #include <evt/GaisserHillas6Parameter.h>
34 
35 #include <fevt/FEvent.h>
36 #include <fevt/Header.h>
37 #include <fevt/Eye.h>
38 #include <fevt/EyeHeader.h>
39 #include <fevt/EyeRecData.h>
40 #include <fevt/EyeTriggerData.h>
41 #include <fevt/Telescope.h>
42 #include <fevt/TelescopeTriggerData.h>
43 #include <fevt/TelescopeRecData.h>
44 #include <fevt/TelescopeSimData.h>
45 #include <fevt/TelescopeRecData.h>
46 #include <fevt/Pixel.h>
47 #include <fevt/PixelRecData.h>
48 #include <fevt/FdComponentSelector.h>
49 
50 #include <atm/MeasuredDBMieModel.h>
51 #include <atm/GDASProfileModel.h>
52 #include <atm/InclinedAtmosphericProfile.h>
53 #include <atm/ProfileResult.h>
54 
55 #include <utl/Vector.h>
56 #include <utl/Point.h>
57 #include <utl/ReferenceEllipsoid.h>
58 
59 //#warning FDEventLib/IoAuger should not be used in Offline2ADST converter
60 #include <AugerEvent.h>
61 #include <EyeEvent.hh>
62 #include <EyeEventHeader.hh>
63 
64 #include <iostream>
65 #include <string>
66 #include <vector>
67 
68 using namespace std;
69 using namespace otoa;
70 using namespace otoa::fd;
71 using namespace fevt;
72 using namespace utl;
73 using namespace atm;
74 
75 
76 std::map<int, bool>
78 {
79  std::map<int, bool> hasTLT;
80 
81  for (auto teliter = eye.TelescopesBegin(ComponentSelector::eHasData);
82  teliter != eye.TelescopesEnd(ComponentSelector::eHasData); ++teliter) {
83  const int telID = teliter->GetId();
84  if (teliter->HasTriggerData()) {
85  const fevt::TelescopeTriggerData& telTrig = teliter->GetTriggerData();
86  hasTLT[telID] = telTrig.IsTLTAccepted();
87  } else
88  hasTLT[telID] = false;
89  }
90  return hasTLT;
91 }
92 
93 
94 std::map<int, std::string>
96 {
97  std::map<int, std::string> label;
98 
99  for (auto teliter = eye.TelescopesBegin(ComponentSelector::eHasData);
100  teliter != eye.TelescopesEnd(ComponentSelector::eHasData); ++teliter) {
101  const int telID = teliter->GetId();
102  if (teliter->HasTriggerData()) {
103  const fevt::TelescopeTriggerData& telTrig = teliter->GetTriggerData();
104  label[telID] = telTrig.IsTLTAccepted() ? telTrig.GetTLTLabel() : " --- ";
105  } else
106  label[telID] = " --- ";
107  }
108  return label;
109 }
110 
111 
112 unsigned long long
114 {
115  unsigned long long telBits = 0;
116  bool telHasData = false;
117  for (auto teliter = eye.TelescopesBegin(ComponentSelector::eHasData);
118  teliter != eye.TelescopesEnd(ComponentSelector::eHasData); ++teliter) {
119  telHasData = false;
120  for (auto iPixel = teliter->PixelsBegin(ComponentSelector::eHasData);
121  iPixel != teliter->PixelsEnd(ComponentSelector::eHasData); ++iPixel) {
122  if (!iPixel->HasRecData())
123  continue;
124  telHasData = true;
125  break;
126  }
127  if (telHasData) {
128  const int bit = teliter->GetId() - 1;
129  telBits += 1ULL << bit;
130  }
131  }
132  return telBits;
133 }
134 
135 
136 unsigned long long
138 {
139  unsigned long long telBits = 0;
140  for (auto iTel = eye.TelescopesBegin(fevt::ComponentSelector::eInDAQ);
141  iTel != eye.TelescopesEnd(fevt::ComponentSelector::eInDAQ); ++iTel) {
142  const int bit = iTel->GetId() - 1;
143  telBits += 1ULL << bit;
144  }
145  return telBits;
146 }
147 
148 
149 std::map<UShort_t, Int_t>
151 {
152  std::map<UShort_t, Int_t> timeOffset;
153  for (auto teliter = eye.TelescopesBegin(ComponentSelector::eHasData);
154  teliter != eye.TelescopesEnd(ComponentSelector::eHasData); ++teliter)
155  timeOffset[teliter->GetId()] = teliter->GetTimeOffset();
156 
157  return timeOffset;
158 }
159 
160 
161 bool
163 {
164  // first check if Mie DB data is actually used ...
166  utl::Branch mieModel = topB.GetChild("MieModel");
167  if (!mieModel)
168  return false;
169  string mieModelName;
170  mieModel.GetData(mieModelName);
171 
172  // ... then check if there is data inside
173  if (mieModelName == "Super" || mieModelName == "MeasuredDB") {
174  atm::MeasuredDBMieModel measuredMieModel;
175  return measuredMieModel.HasData();
176  }
177  return false;
178 }
179 
180 
181 bool
183 {
184  // first check if GDAS data is actually used ...
186  utl::Branch profileModel = topB.GetChild("ProfileModel");
187  if (!profileModel)
188  return false;
189  string profileModelName;
190  profileModel.GetData(profileModelName);
191 
192  // ... then check if there is data inside
193  if (profileModelName == "Super" || profileModelName == "GDAS") {
194  atm::GDASProfileModel gdasProfileModel;
195  return gdasProfileModel.HasData();
196  }
197  return false;
198 }
199 
200 
201 double
202 otoa::fd::ConvertXToChi(const double x, const fdet::Eye& detEye,
203  const Point& core, const Vector& axis, const Vector& sdp)
204 {
205  ReferenceEllipsoid wgs84(ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84));
206 
207  try {
208  const double deltaX = 10*g/cm2;
209  InclinedAtmosphericProfile incModel(core, axis, deltaX);
210 
211  // use the inclined atmosphere model
212  const ProfileResult& distVsSlantDepth = incModel.EvaluateDistanceVsSlantDepth();
213 
214  double distance = 0;
215  if (distVsSlantDepth.MinX() < x && x < distVsSlantDepth.MaxX())
216  distance = -distVsSlantDepth.Y(x); // DEF: p = core + distance * axis
217 
218  const utl::Point& eyePos = detEye.GetPosition();
219 
220  const utl::Point& xPoint = core + distance*axis;
221 
222  const CoordinateSystemPtr eyeCS = detEye.GetEyeCoordinateSystem();
223  const Vector vertical(0, 0, 1, eyeCS);
224  const Vector horizontal = cross(sdp, vertical);
225 
226  double angle = Angle((xPoint-eyePos), horizontal);
227 
228  return angle;
230  // do nothing
231  } catch (OutOfBoundException& e) {
232  // do nothing
233  }
234 
235  return 0;
236 }
237 
238 
239 double
240 otoa::fd::ConvertXToChi(const double x, const fdet::Telescope& detTel,
241  const Point& core, const Vector& axis, const Vector& sdp)
242 {
243  ReferenceEllipsoid wgs84(ReferenceEllipsoid::Get(ReferenceEllipsoid::eWGS84));
244 
245  try {
246  const double deltaX = 10*g/cm2;
247  InclinedAtmosphericProfile incModel(core, axis, deltaX);
248 
249  // use the inclined atmosphere model
250  const ProfileResult& distVsSlantDepth = incModel.EvaluateDistanceVsSlantDepth();
251  //const ProfileResult &heightVsSlantDepth = incModel.EvaluateHeightVsSlantDepth();
252 
253  double distance = 0;
254  if (distVsSlantDepth.MinX() < x && x < distVsSlantDepth.MaxX())
255  distance = -distVsSlantDepth.Y(x); // DEF: p = core + distance * axis
256 
257  const utl::Point& telPos = detTel.GetPosition();
258 
259  const utl::Point& xPoint = core + distance*axis;
260 
262  // Note that the following is wrong for telescopes:
263  //const CoordinateSystemPtr localCS = detTel.GetTelescopeeCoordinateSystem();
264  const Vector vertical(0, 0, 1, localCS);
265  const Vector horizontal = cross(sdp, vertical);
266 
267  double angle = Angle((xPoint-telPos), horizontal);
268 
269  return angle;
271  // do nothing
272  } catch (OutOfBoundException& e) {
273  // do nothing
274  }
275 
276  return 0;
277 }
278 
279 
280 double
281 otoa::fd::LinearProfileFitChiSquare(const FdRecShower& recShower)
282 {
283  const vector<double>& edep = recShower.GetEnergyDeposit();
284  const vector<double>& edep_err = recShower.GetEnergyDepositError();
285  const vector<double>& ne = recShower.GetElectrons();
286  const vector<double>& ne_err = recShower.GetElectronsError();
287 
288  const vector<double>& y = edep.empty() ? ne : edep;
289  const vector<double>& ye = edep_err.empty() ? ne_err : edep_err;
290 
291  double a1 = 0;
292  double a2 = 0;
293  double chi2 = 0;
294 
295  otoa::LinearFit(recShower.GetDepth(), y, ye, a1, a2, chi2);
296 
297  return std::isnan(chi2) ? 0 : chi2;
298 }
299 
300 
301 double
303 {
304  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
305  const fdet::Pixel& detPixel = detFD.GetPixel(evtpixel);
306 
307  const int telid = detPixel.GetTelescopeId();
308  const int eyeid = detPixel.GetEyeId();
309  const int pixelid = detPixel.GetId();
310 
311  // Get the calibration constant for this channel
312  const TabulatedFunction& calibration = detPixel.GetEndToEndCalibrationConstant();
313 
314  if (!calibration.GetNPoints()) {
315  ostringstream err;
316  err << "Could not find calibration for eye " << eyeid
317  << " tel " << telid << " pix " << pixelid;
318  ERROR(err);
319  return false;
320  }
321 
322  // check calibration status
323  if (detPixel.GetStatus() != fdet::Pixel::eGood) {
324  ostringstream warn;
325  warn << " bad calibration data for eye " << eyeid
326  << " tel " << telid << " pix " << pixelid
327  << " status = " << detPixel.GetStatus();
328  WARNING(warn);
329  return false;
330  }
331 
332  const double bestCalibConst =
334 
335  return bestCalibConst;
336 }
AxialVector cross(const Vector &l, const Vector &r)
vector cross product
Definition: OperationsAV.h:32
Status GetStatus() const
Get the pixel status flag.
unsigned int GetId() const
By default from 1..440.
unsigned int GetNPoints() const
Molecular profile taken from GDAS database.
double ConvertXToChi(const double x, const fdet::Eye &detEye, const utl::Point &core, const utl::Vector &axis, const utl::Vector &sdp)
Definition: FD2ADSTUtil.cc:202
Point object.
Definition: Point.h:32
double Angle(const double theta1, const double phi1, const double theta2, const double phi2)
unsigned int GetTelescopeId() const
1..6 for normal FD, 1..3 for HEAT
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
const utl::TabulatedFunction & GetEndToEndCalibrationConstant() const
end to end calibration function
double GetCalibrationConstant(const fevt::Pixel &evtpixel)
Fetches the calibration constant for the given pixel.
Definition: FD2ADSTUtil.cc:302
const Pixel & GetPixel(const fevt::Pixel &eventPixel) const
Get fdet::Pixel from fevt::Channel.
Definition: FDetector.cc:198
Class to hold collection (x,y) points and provide interpolation between them.
double GetEndToEndCalibrationAtReferenceWavelength() const
Detector description interface for Eye-related data.
Definition: FDetector/Eye.h:45
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
Class for computing aerosol scattering and attenuation using database measurements.
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
double Y(const double x) const
Get the Y value (coordinate) for given X (ordinate)
Exception for reporting variable out of valid range.
std::string GetTLTLabel() const
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
std::map< int, bool > CalcMirrorTLTMap(const fevt::Eye &eye)
Definition: FD2ADSTUtil.cc:77
int fd
Definition: dump1090.h:233
Class representing a document branch.
Definition: Branch.h:107
Reference ellipsoids for UTM transformations.
std::map< int, std::string > CalcMirrorTLTLabelMap(const fevt::Eye &eye)
Definition: FD2ADSTUtil.cc:95
Fluorescence Detector Pixel event.
Definition: FEvent/Pixel.h:28
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
Class describing the Atmospheric profile.
Definition: ProfileResult.h:25
TelescopeIterator TelescopesEnd()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:230
bool HasData() const
True if a data source is for the given model.
bool HasData() const
Determine if the DB tables are full or if an update is needed.
constexpr double g
Definition: AugerUnits.h:200
#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
double LinearProfileFitChiSquare(const FdRecShower &recShower)
Calculates the chi2 of a linear fit to the fd profile.
Definition: FD2ADSTUtil.cc:281
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:207
Provides translational services for inclined profile.
bool UsingMieAttenuationDatabase()
Returns whether the Mie DB was used for the current event (i.e. current Detector...?)
Definition: FD2ADSTUtil.cc:162
Detector description interface for Telescope-related data.
double MinX() const
Return the minimum value for X (ordinate) stored in the profile.
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
unsigned long long CalcMirrorsInDAQBitField(const fevt::Eye &eye)
Definition: FD2ADSTUtil.cc:137
bool UsingGDASProfileDatabase()
Returns whether GDAS data was used for the current event (i.e. current Detector...?)
Definition: FD2ADSTUtil.cc:182
Description of a pixel.
utl::Point GetPosition() const
execption handling for calculation/access for inclined atmosphere model
Vector object.
Definition: Vector.h:30
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
Description of trigger data for one Telescope.
void LinearFit(const vector< double > &x, const vector< double > &y, const vector< double > &ey, double &a0, double &a1, double &chi2)
Do a linear fit and return coefficients and chi2.
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
unsigned long long CalcMirrorsInEventBitField(const fevt::Eye &eye)
Definition: FD2ADSTUtil.cc:113
const atm::ProfileResult & EvaluateDistanceVsSlantDepth() const
Table of distance as a function of slant depth.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
unsigned int GetEyeId() const
1..5 (4x normal FD, 1x HEAT)
utl::Point GetPosition() const
Eye position.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
double MaxX() const
Return the maximum value for X (ordinate) stored in the profile.
constexpr double cm2
Definition: AugerUnits.h:118
std::map< UShort_t, Int_t > CalcMirrorTimeOffsetMap(const fevt::Eye &eye)
Definition: FD2ADSTUtil.cc:150

, generated on Tue Sep 26 2023.