//////////////////////////////////////////////////////////////////// /// \class RAT::PCACal /// /// \brief Apply PCA calibration to (ECA) Calibrated PMT data /// /// \author Freija Descamps /// /// REVISION HISTORY:\n /// 15 Feb 2013 : F. Descamps - First version \n /// 14 Oct 2014 : F. Descamps - Small cppcheck fix /// /// \details This class applies the constants generated from /// PCA runs to the ECA-calibrated PMT data. The first /// version is adapted from the SNO PCA calibration /// code. See J. Cameron's thesis and SNO code. /// /// //////////////////////////////////////////////////////////////////// #ifndef __RAT_PCACal__ #define __RAT_PCACal__ #include #include #include #include namespace RAT { namespace DS { class Run; } class PCACal{ public: /// Construct the PCACal PCACal(); /// Close PCACal virtual ~PCACal(); /// Command to load the PCA calibration constants from the database /// /// Only called in at the being of each run void BeginOfRun( DS::Run& run ); /// Construct a calibrated PMT from a calibrated pmt /// /// @param[in] pmt a calibrated pmt /// @return a calibrated PMT DS::PMTCal CalibratePMT( const DS::PMTCal& pmt ); /// Function that uses the PCA calibration constants to calibrate the hittime /// /// @param[in] qhs ECA-calibrated QHS /// @param[in] qhl ECA-calibrated QHL /// @param[in] qlx ECA-calibrated QlX /// @param[in] time ECA-calibrated time /// @param[in] PMTNum lcn number void CalibrateHit(const float qhs, const float qhl, const float qlx, const double time, const int PMTNum); /// Function that returns the PCA calibrated charge QHS /// /// @return QHS qhs charge float GetQHS() {return fQHS;} /// Function that returns the PCA calibrated charge QHL /// /// @return QHL qhl charge float GetQHL() {return fQHL;} /// Function that returns the PCA calibrated charge QLX /// /// @return QLX qlx charge float GetQLX() {return fQLX;} /// Function that returns the PCA calibrated time /// /// @return time PCA calibrated time double GetTime() {return fTime;} /// Function that returns the PCA calibration status /// /// @return status PCA calibration status DS::BitMask GetStatus() {return fStatus;} protected: typedef enum {NOPCA=1,GAINFIT=2,FIRSTINT=3,SECONDINT=4,LOWQHS=5,SNOCONST=6} LiveFlagErr; /// Function that prints error messages for non-fatal errors /// /// void DontDie(LiveFlagErr flagErr, const int info1, const int info2); /// The actual time calibration function that returns the time-walk corrected time /// /// @param[in] lcn the PMT ID number void TimeWalkCal(const int lcn); /// Validation method for the TimeWalk /// /// @param[in] lcn the PMT ID number void ValidateTimeWalk(const int lcn); /// Validation method for the entire calibration /// /// @param[in] lcn the PMT ID number void ValidateCalibrate(const int lcn); /// Method to check and comply with tolerance levels void CalStatus(); PCABits fPack; ///< An instance of PCABits for the unpacking float fQHS; ///< QHS charge float fQHL; ///< QHL charge float fQLX; ///< QLX charge double fTime; ///< time DS::BitMask fStatus; ///< status word for the PCA calibration of this hit DBLinkPtr fCalbank; ///< database table for calibration DBLinkPtr fTimeWalkBank; ///< database table that contains the TW constants int fPCANpointsTimeWalk; ///< number of TW interpolation points per PMT bool fIsSNO; ///< boolean to indicate if SNO constants are used int fPCAtype; ///< type of PCA calibration that is required int fTolLevel; ///< PCA calibration tolerance level bool fIsMC; ///< True if is MC bool fTimeWalkResultOK; ///< boolean to indicate TW calibration status bool fGainFitresultOK; ///< boolean to indicate GF calibration status bool fDoTimeWalk; ///< do timewalk (TW) correction bool fDoGainFit; ///< do gain fit (GF) calculation: not implemented std::vector fTimeWalkPoints; ///< TW PMT-specific interpolation points std::vector fTimeWalkStatus; ///< TW PMT-specific status std::map > fTimeWalkTime; ///< TW PMT-specific interpolation points time std::map > fTimeWalkCharge; ///< TW PMT-specific interpolation points charge std::map fTimeWalkGradient; ///< TW PMT-specific interpolation points gradient std::map fTimeWalkIntercept; ///< TW PMT-specific interpolation points intercept }; } // namespace RAT #endif // __RAT_PCACal__