#ifndef __JACOUSTICS__JEVT__ #define __JACOUSTICS__JEVT__ #include #include #include #include #include #include "JLang/JManip.hh" #include "JIO/JSerialisable.hh" #include "JIO/JSTDIO.hh" #include "JAcoustics/JTimeRange.hh" /** * \file * * Acoustic event fit. * \author mdejong */ namespace JACOUSTICS {} namespace JPP { using namespace JACOUSTICS; } namespace JACOUSTICS { using JIO::JSerialisable; using JIO::JReader; using JIO::JWriter; /** * Acoustic single fit. */ struct JFit : public TObject { /** * Default constructor. */ JFit() : id (-1), tx (0.0), ty (0.0), tx2(0.0), ty2(0.0), vs (0.0) {} /** * Constructor. * * \param id string identifier * \param tx slope dx/dz * \param ty slope dy/dz * \param tx2 2nd order correction of slope dx/dz * \param ty2 2nd order correction of slope dy/dz * \param vs stretching factor */ JFit(const int id, const double tx, const double ty, const double tx2, const double ty2, const double vs) : id (id), tx (tx), ty (ty), tx2(tx2), ty2(ty2), vs (vs) {} /** * Virtual destructor. */ virtual ~JFit() {} /** * Write fit to output. * * \param out output stream * \param fit fit * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JFit& fit) { using namespace std; out << setw(4) << fit.id << ' ' << FIXED(10,7) << fit.tx << ' ' << FIXED(10,7) << fit.ty << ' ' << SCIENTIFIC(12,3) << fit.tx2 << ' ' << SCIENTIFIC(12,3) << fit.ty2 << ' ' << FIXED(8,5) << fit.vs; return out; } /** * Read fit from input. * * \param in reader * \param object fit * \return reader */ friend inline JReader& operator>>(JReader& in, JFit& object) { in >> object.id; in >> object.tx; in >> object.ty; in >> object.tx2; in >> object.ty2; in >> object.vs; return in; } /** * Write fit to output. * * \param out writer * \param object fit * \return writer */ friend inline JWriter& operator<<(JWriter& out, const JFit& object) { out << object.id; out << object.tx; out << object.ty; out << object.tx2; out << object.ty2; out << object.vs; return out; } ClassDefOverride(JFit, 2); int id; ///< string identifier double tx; ///< slope dx/dz double ty; ///< slope dy/dz double tx2; ///< 2nd order correction of slope dx/dz double ty2; ///< 2nd order correction of slope dy/dz double vs; ///< stretching factor }; /** * Acoustic event header. */ struct JHead { /** * Default constructor. */ JHead() : detid(), UNIXTimeStart(0.0), UNIXTimeStop (0.0), nhit(0), nfit(0), npar(0), ndf (0.0), chi2(0.0) {} /** * Constructor. * * \param detid detector identifer * \param range UNIX start and stop time [s] * \param nhit number of hits * \param nfit number of hits used in fit (after outlier removal) * \param npar number of fit parameters * \param ndf weighed number of degrees of freedom * \param chi2 chi2 */ JHead(const int detid, const JTimeRange& range, const int nhit, const int nfit, const int npar, const double ndf, const double chi2) : detid(detid), UNIXTimeStart(range.getLowerLimit()), UNIXTimeStop (range.getUpperLimit()), nhit(nhit), nfit(nfit), npar(npar), ndf (ndf), chi2(chi2) {} /** * Virtual destructor. */ virtual ~JHead() {} /** * Read head from input. * * \param in reader * \param object head * \return reader */ friend inline JReader& operator>>(JReader& in, JHead& object) { in >> object.detid; in >> object.UNIXTimeStart; in >> object.UNIXTimeStop; in >> object.nhit; in >> object.nfit; in >> object.npar; in >> object.ndf; in >> object.chi2; return in; } /** * Write head to output. * * \param out writer * \param object head * \return writer */ friend inline JWriter& operator<<(JWriter& out, const JHead& object) { out << object.detid; out << object.UNIXTimeStart; out << object.UNIXTimeStop; out << object.nhit; out << object.nfit; out << object.npar; out << object.ndf; out << object.chi2; return out; } ClassDef(JHead, 6); int detid; ///< detector identifier double UNIXTimeStart; ///< start time double UNIXTimeStop; ///< stop time int nhit; ///< number of hits int nfit; ///< number of hits used in fit (after outlier removal) int npar; ///< number of fit parameters double ndf; ///< weighed number of degrees of freedom double chi2; ///< chi2 }; /** * Less than operator for acoustics event headers. * * The less than operator is applied to the object identifier, * the UNIX start time and the UNIX stop time, respectively. * * \param first first header * \param second second header * \return true if first event header earliear than second; else false */ inline bool operator<(const JHead& first, const JHead& second) { if (first.detid == second.detid) { if (first.UNIXTimeStart == second.UNIXTimeStart) { return first.UNIXTimeStop < second.UNIXTimeStop; } else { return first.UNIXTimeStart < second.UNIXTimeStart; } } else { return first.detid < second.detid; } } /** * Acoustic event fit. */ struct JEvt : public virtual JSerialisable, public JHead, public std::vector, public TObject { /** * Auxiliary class to determine value of acoustic events.\n * This class can be used with JSUPPORT::JTreeScanner so to read acoustics events in order of start time. */ struct JEvaluator { /** * Type definition of time value. */ typedef double value_type; /** * Default constructor. */ JEvaluator() {} /** * Get value of object. * * \param event event * \return value */ inline value_type operator()(const JEvt& event) const { return event.UNIXTimeStart; } }; /** * Default constructor. */ JEvt() : JHead() {} /** * Constructor. * * \param header header */ JEvt(const JHead& header) : JHead(header) {} /** * Virtual destructor. */ virtual ~JEvt() {} /** * Write event to output. * * \param out output stream * \param event event * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JEvt& event) { using namespace std; out << event.detid << endl << FIXED(20,5) << event.UNIXTimeStart << endl << FIXED(20,5) << event.UNIXTimeStop << endl << setw(5) << event.nhit << ' ' << setw(5) << event.nfit << ' ' << setw(4) << event.npar << endl << FIXED(12,3) << event.chi2 << '/' << FIXED(7,1) << event.ndf << endl; for (JEvt::const_iterator fit = event.begin(); fit != event.end(); ++fit) { out << *fit << endl; } return out; } /** * Read from input. * * \param in reader * \return reader */ virtual JReader& read(JReader& in) override { in >> static_cast (*this); in >> static_cast&>(*this); return in; } /** * Write to output. * * \param out writer * \return writer */ virtual JWriter& write(JWriter& out) const override { out << static_cast (*this); out << static_cast&>(*this); return out; } ClassDefOverride(JEvt, 8); }; } #endif