12 #include <det/Detector.h>
13 #include <fdet/FDetector.h>
14 #include <sdet/SDetector.h>
16 #include <evt/Event.h>
17 #include <evt/ShowerRecData.h>
18 #include <evt/ShowerFRecData.h>
20 #include <fdet/Channel.h>
22 #include <fdet/Pixel.h>
25 #include <fevt/EyeHeader.h>
26 #include <fevt/EyeRecData.h>
27 #include <fevt/FEvent.h>
28 #include <fevt/Pixel.h>
29 #include <fevt/PixelRecData.h>
30 #include <fevt/Telescope.h>
32 #include <fwk/CoordinateSystemRegistry.h>
33 #include <fwk/CentralConfig.h>
35 #include <sevt/SEvent.h>
36 #include <sevt/StationRecData.h>
37 #include <sevt/Station.h>
39 #include <utl/ErrorLogger.h>
40 #include <utl/MathConstants.h>
41 #include <utl/PhysicalConstants.h>
42 #include <utl/Reader.h>
43 #include <utl/Transformation.h>
56 using namespace HdAxisFinderUU;
60 double HdAxisFinder::fChi2 = 0;
61 double HdAxisFinder::fMyChiSquare = 0;
62 unsigned int HdAxisFinder::fNDof = 0;
76 ERROR(
"Could not find branch HdAxisFinder");
83 ERROR(
"Could not find branch MinPixels");
95 fMinuitFailed =
false;
100 fCurSEvent = &sevent;
144 this->FillPoints(eye);
147 fRpFirst = eyerecdata.
GetRp() ;
158 if (fMinuitFailed)
continue;
171 det::Detector::GetInstance().GetFDetector().GetEye(eye).GetEyeCoordinateSystem();
173 Vector vertical(0,0,1,eyeCS);
178 if ( horizontalInSDP.
GetPhi(eyeCS) < 0 ||
181 horizontalInSDP *= -1;
186 Vector axis (rot* horizontalInSDP);
191 det::Detector::GetInstance().GetSiteCoordinateSystem();
200 Vector core_eye_vec =
fRp / sin(
kPi - fChi0) * horizontalInSDP;
203 det::Detector::GetInstance().GetFDetector().GetEye(eye).GetPosition();
209 const sdet::SDetector& theSDetector = det::Detector::GetInstance().GetSDetector();
212 double station_level = 0.0 ;
223 station_level += SdPos.
GetZ(eyeCS) ;
227 station_level /= ntanks;
229 station_level = core_eye_vec.
GetZ(eyeCS) ;
234 if (station_level==0) station_level = core_eye_vec.
GetZ(eyeCS) ;
235 double coord_along_axis = (station_level - core_eye_vec.
GetZ(eyeCS))/axis.
GetZ(eyeCS) ;
237 Point core = eyeposition + core_eye_vec + coord_along_axis * axis;
252 eyerecshower.
SetCoreTime(fCurEye->GetHeader().GetTimeStamp() -
299 TMinuit theMinuit(npar);
303 theMinuit.SetPrintLevel(-1);
304 theMinuit.SetFCN(HdAxisFinder::MinuitFitFunc);
306 double arglist[
npar];
311 theMinuit.mnexcm(
"SET ERR", arglist,1,ierflag);
313 if (ierflag)
ERROR (
"Minuit SET ERR failed");
315 static double vstart[
npar];
316 static double step[
npar];
318 vstart[0] = fChi0First;
319 vstart[1] = fT0First;
320 vstart[2] = fRpFirst;
326 theMinuit.mnparm(0,
"Chi0",vstart[0], step[0],0,0,ierflag);
327 theMinuit.mnparm(1,
"T0", vstart[1], step[1],0,0,ierflag);
328 theMinuit.mnparm(2,
"Rp", vstart[2], step[2],0,0,ierflag);
332 theMinuit.mnexcm(
"MIGRAD", arglist ,2,ierflag);
339 ERROR (
"Minuit MIGRAD failed");
342 theMinuit.GetParameter(0,fChi0,fChi0Error);
343 theMinuit.GetParameter(1,fT0,fT0Error);
358 const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
369 fSDP.TransformTo(CS);
372 Vector vertical(0,0,1,CS,Vector::kCartesian);
376 if ( (horizontalWithinSDP.
GetPhi(CS) < 0) || (horizontalWithinSDP.
GetPhi(CS) >
kPi) )
378 horizontalWithinSDP*=-1;
413 double noise = pixrec.
GetRMS() ;
415 double ratio = (charge/noise)/(duration/timebinsize) ;
418 double t_i_Err = (180*exp(-duration/280)+50) * (3.6*exp(-ratio/3)+0.4) ;
422 pixeldir.TransformTo(CS);
426 chi_i_vector.TransformTo(CS);
429 double chi_i =
Angle(chi_i_vector,horizontalWithinSDP);
434 pixrec.
SetT_i(t_i,t_i_Err);
442 HdAxisFinder::MinuitFitFunc(
int& ,
double* ,
double& f,
451 unsigned int ndof =0;
453 double& chi_0 = par[0];
454 double& t_0 = par[1] ;
455 double& r_p = par[2] ;
458 double totalcharge = 0. ;
459 double max_error = 0.0 ;
464 const Pixel& pixel = *iter;
470 if (t_i_Err > max_error) max_error = t_i_Err ;
478 double tmp = t_i - t_expected ;
481 totalcharge += charge ;
486 chisq += tmp*tmp/ t_i_Err / t_i_Err * charge;
487 fMyChiSquare += tmp*tmp/t_i_Err/t_i_Err ;
495 chisq /= totalcharge ;
500 Detector::GetInstance().GetFDetector().GetEye(*fCurEye).GetLocalCoordinateSystem();
502 fSDP.TransformTo(CS) ;
503 Vector vertical(0,0,1,CS,Vector::kCartesian) ;
507 Detector::GetInstance().GetFDetector().GetEye(*fCurEye).GetEyeCoordinateSystem();
509 if ( (horizontal.
GetPhi(EyeCS) < 0) || (horizontal.
GetPhi(EyeCS) >
kPi) )
518 Vector axis (rot*horizontal);
522 double theta =
Angle(axis,vertical);
524 Vector FdCore = r_p / sin(
kPi - chi_0) * horizontal;
525 FdCore.TransformTo(CS) ;
535 double EyeTriggerTime = fCurEye->GetHeader().GetTimeStamp().GetGPSNanoSecond() - 1e5 ;
537 const sdet::SDetector& theSDetector = det::Detector::GetInstance().GetSDetector();
544 double baryWeight, baryWeightSum = 0.0, baryX = 0.0, baryY = 0.0, baryZ = 0.0 ;
547 Stiter != fCurSEvent->CandidateStationsEnd(); ++Stiter) {
554 const Vector FdCoreToTank = TankToEye - FdCore;
562 const double station_level = SdPos.
GetZ(CS);
565 const double coord_along_axis = (station_level - FdCore.GetZ(CS))/axis.
GetZ(CS);
568 const Vector RealCore = FdCore + coord_along_axis * axis;
573 const Vector CoreToTank = TankToEye - RealCore;
575 const double distance = CoreToTank.
GetMag();
579 const double TankProj = FdCoreToTank * axis;
581 const Vector TankToAxis = FdCoreToTank - (TankProj * axis);
582 const double d = TankToAxis.
GetMag();
586 double sigma_t2 = (2800. + 0.0064*distance*distance)/3.5;
593 t_expected += EyeTriggerTime;
598 const double Rinit = 6500./cos(theta) ;
601 const double alpha =
Angle(axis,CoreToTank) ;
602 const double Rcurv =
sqrt(Rinit*Rinit + distance*distance - 2*Rinit*distance*cos(alpha));
605 const double gamma = 1/(2*Rcurv) ;
610 const double crit_dist = 700./
sqrt(cos(theta));
611 sigma_t2 *= 1 +
pow(d/crit_dist, 4);
613 const double tmp = t_i - t_expected;
628 baryWeight =
sqrt(StTotSig);
629 baryWeightSum += baryWeight;
630 baryX += baryWeight * SdPos.
GetX(CS);
631 baryY += baryWeight * SdPos.
GetY(CS);
632 baryZ += baryWeight * station_level;
634 totalcharge += StTotSig;
638 sdchisq += tmp*tmp/sigma_t2 * StTotSig;
639 fMyChiSquare += tmp*tmp/sigma_t2;
645 const int ntanks = ndof - npixels;
647 sdchisq /= totalcharge;
660 baryX /= baryWeightSum;
661 baryY /= baryWeightSum;
662 baryZ /= baryWeightSum;
663 const Vector BaryCenter(baryX, baryY, baryZ, CS);
665 const double coord_along_axis = (baryZ - FdCore.
GetZ(CS))/axis.
GetZ(CS);
666 const Vector RealCore = FdCore + coord_along_axis * axis;
667 const Vector CoreToBary = BaryCenter - RealCore;
668 const double min_distance = CoreToBary.
GetMag();
670 const double dist_err = 500*
m;
671 const double dist_chi = min_distance*min_distance / (dist_err*dist_err);
689 HdAxisFinder::Finish()
AxialVector cross(const Vector &l, const Vector &r)
vector cross product
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
Class to access station level reconstructed data.
const utl::Vector & GetDirection() const
pointing direction of this pixel
void SetChiZero(const double chiZero, const double error)
int GetPulseStop() const
pulse stop (to be defined)
double Angle(const double theta1, const double phi1, const double theta2, const double phi2)
Description of the electronic channel for the 480 channels of the crate.
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Detector description interface for Station-related data.
double GetRMS() const
Get the baseline RMS of the trace.
unsigned int GetTimeOffset() const
Time offset of this Telescope compared to fevt::Header::GetTime [ns].
Fluorescence Detector Eye Event.
const Pixel & GetPixel(const fevt::Pixel &eventPixel) const
Get fdet::Pixel from fevt::Channel.
Interface class to access to the SD part of an event.
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
double GetChiZero() const
int GetPulseStart() const
pulse start (to be defined)
void SetCorePosition(const utl::Point &core)
EyeIterator EyesEnd(const ComponentSelector::Status status)
sevt::StationRecData & GetRecData()
Get station level reconstructed data.
void SetT_i(const double t_i, const double error)
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.
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.
double pow(const double x, const unsigned int i)
Detector description interface for FDetector-related data.
boost::indirect_iterator< ConstInternalPixelIterator, const Pixel & > ConstPixelIterator
Const iterator over pixels used in reconstruction.
utl::Point GetPosition() const
Tank position.
CandidateStationIterator CandidateStationsBegin()
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
class to hold data at Station level
void MakeFRecShower()
Allocate reconstructed shower info.
utl::TimeStamp GetSignalStartTime() const
Start time of the signal.
Fluorescence Detector Pixel event.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
void SetCoreTime(const utl::TimeStamp &coreTime, const utl::TimeInterval &coreTimeErr)
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
utl::TimeInterval GetT_i() const
void SetAxis(const utl::Vector &axis)
double GetTotalSignal() const
Total integrated signal in VEM unit, averaged over pmts.
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)
const Channel & GetChannel(const fevt::Channel &eventChannel) const
Get fdet::Channel from fevt::Channel.
void SetTimeFitChiSquare(const double tfitChi2, const unsigned int ndof)
void GetData(bool &b) const
Overloads of the GetData member template function.
Top of Fluorescence Detector event hierarchy.
Eye-specific shower reconstruction data.
double GetInterval() const
Get the time interval as a double (in Auger base units)
const utl::AxialVector & GetSDP() const
unsigned int GetTelescopeId() const
unsigned int GetNTimeFitPixels() const
Get number of Time Fit pixels.
boost::indirect_iterator< InternalPixelIterator, fevt::Pixel & > PixelIterator
Iterator over pixels used in reconstruction.
double GetY(const CoordinateSystemPtr &coordinateSystem) const
constexpr double kSpeedOfLight
A TimeInterval is used to represent time elapsed between two events.
ResultFlag
Flag returned by module methods to the RunController.
double GetFADCBinSize() const
double GetGPSNanoSecond() const
GPS nanosecond.
double GetTotalCharge() const
integrated pulse charge
PixelIterator TimeFitPixelsEnd()
Interface class to access to Fluorescence reconstruction of a Shower.
Detector description interface for SDetector-related data.
utl::TimeInterval GetT_iError() const
Main configuration utility.
boost::indirect_iterator< InternalStationIterator, Station & > StationIterator
Iterator over all stations.
CandidateStationIterator CandidateStationsEnd()
void SetTZero(const double tzero, const double error)
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
const Station & GetStation(const int stationId) const
Get station by Station Id.
double GetNanoSecond() const
Get integer number of nanoseconds past seconds boundary.
double GetCentroid() const
PixelIterator TimeFitPixelsBegin()
#define ERROR(message)
Macro for logging error messages.
Fluorescence Detector Pixel Reconstructed Data.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
void SetChi_i(const double chi_i)
PixelRecData & GetRecData()
boost::filter_iterator< CandidateStationFilter, ConstStationIterator > ConstCandidateStationIterator
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.