#ifndef __JDETECTOR__JCALIBRATION__ #define __JDETECTOR__JCALIBRATION__ #include #include #include "JIO/JSerialisable.hh" #include "JLang/JClass.hh" #include "JLang/JManip.hh" /** * \file * * Time calibration (including definition of sign of time offset). * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { using JIO::JReader; using JIO::JWriter; /** * Specification for time-over-threshold corresponding to a one photo-electron pulse. */ const double TIME_OVER_THRESHOLD_NS = 25.08; // [ns] /** * Specification for normalized gain corresponding to a one photo-electron pulse. */ const double NOMINAL_GAIN = 1.0; // [--] /** * Data structure for time calibration. */ class JCalibration { public: /** * Default constructor. */ JCalibration() : t0(0.0) {} /** * Constructor. * * \param __t0 time offset [ns] */ JCalibration(const double __t0) : t0(__t0) {} /** * Get calibration. * * \return calibration */ const JCalibration& getCalibration() const { return *this; } /** * Get calibration. * * \return calibration */ JCalibration& getCalibration() { return *this; } /** * Set calibration. * * \param cal calibration */ void setCalibration(const JCalibration& cal) { *this = cal; } /** * Get time offset. * * \return time offset [ns] */ double getT0() const { return t0; } /** * Set time offset. * * \param t0 time offset [ns] */ void setT0(const double t0) { this->t0 = t0; } /** * Add time offset. * * \param t0 time offset [ns] */ void addT0(const double t0) { this->t0 += t0; } /** * Subtract time offset. * * \param t0 time offset [ns] */ void subT0(const double t0) { this->t0 -= t0; } /** * Read calibration from input. * * \param in input stream * \param cal calibration * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JCalibration& cal) { in >> cal.t0; return in; } /** * Write calibration to output. * * \param out output stream * \param cal calibration * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JCalibration& cal) { const JFormat format(out, getFormat(JFormat_t(9, 3, std::ios::fixed | std::ios::showpos))); out << format << cal.t0; return out; } /** * Read calibration from input. * * \param in reader * \param cal calibration * \return reader */ friend inline JReader& operator>>(JReader& in, JCalibration& cal) { in >> cal.t0; return in; } /** * Write calibration to output. * * \param out writer * \param cal calibration * \return writer */ friend inline JWriter& operator<<(JWriter& out, const JCalibration& cal) { out << cal.t0; return out; } protected: double t0; }; /** * Auxiliary class to apply (de-)calibration to template hit. */ template::is_primitive> struct JCalibrator; /** * Get calibrated time. * * \param t1 time [ns] * \param cal calibration * \return time [ns] */ template inline double getTime(const T& t1, const JCalibration& cal) { return JCalibrator::getTime(t1, cal); } /** * Get de-calibrated time. * * \param t1 time [ns] * \param cal calibration * \return time [ns] */ template inline double putTime(const T& t1, const JCalibration& cal) { return JCalibrator::putTime(t1, cal); } /** * Get calibrated time-over-threshold of hit. * * \param tot time-over-threshold [ns] * \param cal calibration * \return time-over-threshold [ns] */ template inline double getToT(const T& tot, const JCalibration& cal) { return JCalibrator::getToT(tot, cal); } /** * Get de-calibrated time-over-threshold of hit. * * \param tot time-over-threshold [ns] * \param cal calibration * \return time-over-threshold [ns] */ template inline double putToT(const T& tot, const JCalibration& cal) { return JCalibrator::putToT(tot, cal); } /** * Template specialisation of JCalibrator for primitive data types. */ template struct JCalibrator { /** * Get calibrated time. * * \param t1 time [ns] * \param cal calibration * \return time [ns] */ static inline double getTime(const T t1, const JCalibration& cal) { return t1 + cal.getT0(); } /** * Get de-calibrated time. * * \param t1 time [ns] * \param cal calibration * \return time [ns] */ static inline double putTime(const T t1, const JCalibration& cal) { return t1 - cal.getT0(); } /** * Get calibrated time-over-threshold of hit. * * \param tot time-over-threshold [ns] * \param cal calibration * \return time-over-threshold [ns] */ static inline double getToT(const T tot, const JCalibration& cal) { return tot; } /** * Get de-calibrated time-over-threshold of hit. * * \param tot time-over-threshold [ns] * \param cal calibration * \return time-over-threshold [ns] */ static inline double putToT(const T tot, const JCalibration& cal) { return tot; } }; /** * Template specialisation of JCalibrator for non-primitive data types. * It is assumed that the template class has the following methods: *
   *      %getT();
   *      %getToT();
   * 
* which should return the time (ns) and time-over-threshold (ns), respectively. */ template struct JCalibrator { /** * Get calibrated time of hit. * * \param hit hit * \param cal calibration * \return time [ns] */ static inline double getTime(const JHit_t& hit, const JCalibration& cal) { return JDETECTOR::getTime(hit.getT(), cal); } /** * Get de-calibrated time of hit. * * \param hit hit * \param cal calibration * \return time [ns] */ static inline double putTime(const JHit_t& hit, const JCalibration& cal) { return JDETECTOR::putTime(hit.getT(), cal); } /** * Get calibrated time-over-threshold of hit. * * \param hit hit * \param cal calibration * \return time-over-threshold [ns] */ static inline double getToT(const JHit_t& hit, const JCalibration& cal) { return JDETECTOR::getToT(hit.getToT(), cal); } /** * Get de-calibrated time-over-threshold of hit. * * \param hit hit * \param cal calibration * \return time-over-threshold [ns] */ inline double putToT(const JHit_t& hit, const JCalibration& cal) { return JDETECTOR::putToT(hit.getToT(), cal); } }; } #endif