3 #include <evt/ShowerFRecData.h>
6 #include <fevt/Telescope.h>
7 #include <fevt/Pixel.h>
8 #include <fevt/EyeHeader.h>
9 #include <fevt/FEvent.h>
10 #include <fevt/EyeRecData.h>
11 #include <fevt/TelescopeRecData.h>
13 #include <det/Detector.h>
16 #include <fdet/Pixel.h>
17 #include <fdet/FDetector.h>
19 #include <fwk/RunController.h>
20 #include <fwk/CentralConfig.h>
21 #include <fwk/LocalCoordinateSystem.h>
23 #include <utl/PhysicalConstants.h>
35 namespace FdProfileConstrainedGeometryFitPG {
50 FdProfileConstrainedGeometryFit::Finish()
61 FEvent& fevent =
event.GetFEvent();
66 end = fevent.
EyesEnd(ComponentSelector::eHasData); eye != end; ++eye) {
68 if ((!eye->HasRecData() ||
69 !eye->GetRecData().HasFRecShower()) &&
70 !det::Detector::GetInstance().GetFDetector().GetEye(*eye).IsVirtual()
74 unsigned int eyeId = eye->GetId();
75 cout <<
"PCGF for eye " << eyeId <<
" ...\n";
76 unsigned int eyeBit = (fEyeCut / int(
pow(10., eyeId-1))) % 10;
78 cout <<
"skipping due to eyeCut" <<
"\n";
82 if (det::Detector::GetInstance().GetFDetector().GetEye(*eye).IsVirtual()) {
83 const int prevEye = GetDataFromPreviousFit(event, eyeId);
85 INFO(
"Could not find results from previous fits --- jump to next eye!");
90 if (fPCGFitter.Run(*eye)) {
93 eye->SetStatus(ComponentSelector::eDeSelected);
96 cout <<
"PCGF for eye " << eye->GetId() <<
" DONE\n";
100 ++fwk::RunController::GetInstance().GetRunData().GetNamedCounters()[
"FdProfileConstrainedGeometryFitPG/Good"];
104 return eContinueLoop;
108 FdProfileConstrainedGeometryFit::GetDataFromPreviousFit(
evt::Event& event,
int fgCurEye)
111 const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
114 set<unsigned int> eyeIds;
122 if (fevent.
HasEye(eyeIter->GetId())) {
123 eyeIds.insert(eyeIter->GetId());
131 bool hasData =
false;
139 eyeIds.insert(fgCurEye);
146 if (fevent.
HasEye(eyeIter->GetId())) {
147 eyeIds.insert(eyeIter->GetId());
155 int maxNFitPixels = 0;
156 unsigned int maxNFitPixelsId = 0;
157 for (set<unsigned int>::const_iterator IdIter = eyeIds.begin();
158 IdIter != eyeIds.end();
172 if (nFitPixels > maxNFitPixels) {
173 maxNFitPixels = nFitPixels;
174 maxNFitPixelsId = *IdIter;
177 cout <<
"Eye " << *IdIter <<
" has " << nFitPixels <<
" pixels in the time fit" << endl;
182 if (maxNFitPixelsId != 0) {
183 takeFromEye = maxNFitPixelsId;
188 cout<<
"take from "<<takeFromEye<<endl;
190 const fdet::Eye& detEye = det::Detector::GetInstance().GetFDetector().GetEye(takeFromEye);
191 fevt::Eye& eventEye =
event.GetFEvent().GetEye(takeFromEye);
198 const double fRp = eyeRecData.
GetRp();
203 const double fRpErr = eyeRecData.
GetRpError();
208 const double sdpPhi = eyeRecData.
GetSDP().
GetPhi(telCS);
209 const Vector sdp =
Vector(1, sdpTheta, sdpPhi, telCS, Vector::kSpherical);
222 const Point eyePos = det::Detector::GetInstance().GetFDetector().GetEye(fgCurEye).GetPosition();
228 const int curtelId = detTelIt->GetId();
229 const Point curtelPos = detTelIt->GetPosition();
231 const Point core_in_curtel = fCore-fAxis*fCore.
GetZ(curtelCS)/cos(fAxis.
GetTheta(curtelCS));
233 const Vector curtel_to_core = core_in_curtel-curtelPos;
234 const double chi0_in_curtel =
Angle(curtel_to_core, fAxis);
235 const double rp_in_curtel = curtel_to_core.GetMag()*sin(chi0_in_curtel);
238 const Vector Pt_to_Pct = P_in_curtel - P_in_tel;
248 telRecData.
SetSDP(SDP_in_curtel);
249 telRecData.
SetChiZero(chi0_in_curtel, fChiZeroErr);
250 telRecData.
SetTZero(t0_in_curtel, fTZeroErr);
251 telRecData.
SetRp(rp_in_curtel, fRpErr);
257 if (fillEye && (curtelPos - eyePos).GetMag() < 1e-3) {
258 curEyeRecData.
SetChiZero(chi0_in_curtel, fChiZeroErr);
259 curEyeRecData.
SetTZero(t0_in_curtel, fTZeroErr);
260 curEyeRecData.
SetRp(rp_in_curtel, fRpErr);
261 curEyeRecData.
SetSDP(SDP_in_curtel);
270 double tCore = t0_in_curtel;
271 tCore -= (rp_in_curtel / tan(chi0_in_curtel)) /
kSpeedOfLight;
282 const unsigned int parentEyeId = detTelIt->GetParentPhysicalEyeId();
283 const unsigned int parentTelId = detTelIt->GetParentPhysicalId();
287 pixelIter != parentEyeRecData.
SDPPixelsEnd(); ++pixelIter) {
289 if (pixelIter->GetTelescopeId() == parentTelId) {
298 if (pixelIter->GetTelescopeId() == parentTelId) {
309 unsigned int telId = pixelIter->GetTelescopeId();
312 const Point telPos = det::Detector::GetInstance().GetFDetector().GetEye(fgCurEye).GetTelescope(telId).GetPosition();
315 const double sdpPhi = telRecData.
GetSDP().
GetPhi(telCS);
317 const Vector sdp =
Vector(1, sdpTheta, sdpPhi, telCS, Vector::kSpherical);
318 const Vector vertical(0,0,1, telCS);
321 const Vector pixelDirection = det::Detector::GetInstance().GetFDetector().GetPixel(*pixelIter).GetDirection();
322 const Vector pixelDirInSDP = pixelDirection - (sdp * pixelDirection)*sdp;
323 const double pixelChi =
Angle(pixelDirInSDP, horizontalInSDP);
325 pixelIter->GetRecData().SetChi_i(pixelChi);
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
AxialVector Cross(const Vector &l, const Vector &r)
void SetChiZero(const double chiZero, const double error)
double Angle(const double theta1, const double phi1, const double theta2, const double phi2)
double GetRpError() const
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
void SetSDPFitChiSquare(const double sdpChi2, const unsigned int ndof)
fevt::EyeHeader & GetHeader()
Header for this Eye Event.
Fluorescence Detector Eye Event.
PixelIterator PulsedPixelsEnd()
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
void SetCorePosition(const utl::Point &core)
EyeIterator EyesEnd(const ComponentSelector::Status status)
void SetTimeFitCorrelations(double rRpT0, double rRpChi0, double rChi0T0)
#define INFO(message)
Macro for logging informational messages.
void SetTimeFitCorrelations(const double rRpT0, const double rRpChi0, const double rChi0T0)
void SetRp(const double rp, const double error)
void Init()
Initialise the registry.
const Eye & GetEye(const unsigned int eyeId) const
Find eye by numerical Id.
EyeIterator EyesBegin(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to first eye of given type (ePhysical, eVirtual, eAll)
Detector description interface for Eye-related data.
boost::filter_iterator< ComponentSelector, AllEyeIterator > EyeIterator
selective Eye iterators
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
fevt::TelescopeRecData & GetRecData()
Reconstructed data for this telescope.
void AddSDPPixel(fevt::Pixel &pixel)
add a pixel to the list of SDP pixels
PixelIterator PulsedPixelsBegin()
double pow(const double x, const unsigned int i)
double GetTZeroError() const
Detector description interface for FDetector-related data.
double GetChiZeroError() const
A TimeStamp holds GPS second and nanosecond for some event.
Exception for reporting variable out of valid range.
void SetSDP(const utl::AxialVector &vec)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
void MakeFRecShower()
Allocate reconstructed shower info.
PixelIterator SDPPixelsBegin()
boost::filter_iterator< FDetComponentSelector, AllEyeIterator > EyeIterator
void SetCoreTime(const utl::TimeStamp &coreTime, const utl::TimeInterval &coreTimeErr)
TelescopeIterator TelescopesBegin() const
Beginning of the collection of telescopes.
void SetAxis(const utl::Vector &axis)
bool HasFRecShower() const
Check if reconstructed shower info has been allocated.
evt::ShowerFRecData & GetFRecShower()
Reconstructed shower info for this eye.
EyeIterator EyesBegin(const ComponentSelector::Status status)
void SetChiZero(const double chiZero, const double error)
void SetTimeFitChiSquare(const double tfitChi2, const unsigned int ndof)
Telescope-specific shower reconstruction data.
void GetData(bool &b) const
Overloads of the GetData member template function.
Top of Fluorescence Detector event hierarchy.
Eye-specific shower reconstruction data.
AxialVector Normalized(const AxialVector &v)
Eye & GetEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
return Eye by id
double GetInterval() const
Get the time interval as a double (in Auger base units)
const utl::AxialVector & GetSDP() const
boost::filter_iterator< TelIsCommissioned, InternalConstTelescopeIterator > TelescopeIterator
An iterator over telescopes.
unsigned int GetNTimeFitPixels() const
Get number of Time Fit pixels.
Pixel & GetPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Pixel by Id, throw exception if not existent.
bool HasEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
boost::indirect_iterator< InternalPixelIterator, fevt::Pixel & > PixelIterator
Iterator over pixels used in reconstruction.
constexpr double kSpeedOfLight
A TimeInterval is used to represent time elapsed between two events.
ResultFlag
Flag returned by module methods to the RunController.
void SetTZero(const double tzero, const double error)
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
bool HasTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Check if the telescope is in the event.
void SetTimeFitChiSquare(const double tfitChi2, const unsigned int ndof)
PixelIterator TimeFitPixelsEnd()
Interface class to access to Fluorescence reconstruction of a Shower.
void SetRp(const double rp, const double error)
TelescopeIterator TelescopesEnd() const
End of the collection of telescopes.
void SetSDP(const utl::AxialVector &vec)
void SetTZero(const double tzero, const double error)
PixelIterator SDPPixelsEnd()
void AddTimeFitPixel(fevt::Pixel &pixel)
add a pixel to the list of Time Fit pixels
Fluorescence Detector Telescope Event.
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
const utl::AxialVector & GetSDP() const
PixelIterator TimeFitPixelsBegin()
#define ERROR(message)
Macro for logging error messages.
const utl::Point & GetCorePosition() const
Shower core as reconstructed by the FD or FD eye.
const std::string & GetMessage() const
Retrieve the message from the exception.
utl::Point GetPosition() const
Eye position.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.
bool IsVirtual() const
Returns whether this eye is a virtual eye.
EyeIterator EyesEnd(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to end of available eyes of given type (ePhysical, eVirtual, eAll) ...
const utl::Vector & GetAxis() const
Shower Axis as reconstructed by the FD or FD eye.