//////////////////////////////////////////////////////////////////// // Apply ECA calibration to PMTUnCal data (/MC) // // Authors: Gabriel D. Orebi Gann Author and contact // Javier Caravaca - Contact // // REVISION HISTORY: // 17 Oct 2011 : Gabriel Orebi Gann - Move bit funcs to BitManip.\n // 03 Feb 2014 : GDOG - allow up to 99 TSlope points.\n // 08 Apr 2014 : GDOG - handle railed TACs, and adjacent same-valued points.\n // 02 May 2014 : P Jones - changed status to DS::BitMask system.\n // 27 Jun 2015 : J Caravaca - perform calibration by rate and occupancy // // This class applies the constants generated from // ECA runs to the uncalibrated PMT data. // This can be applied either to raw data, // or to `uncalibrated' MC events. // //////////////////////////////////////////////////////////////////// #ifndef __RAT_ECACal__ #define __RAT_ECACal__ #include #include #include #include #include #include #include #include namespace RAT { class ECACal{ public: // ECACal constructor ECACal(); // ECACal destructor virtual ~ECACal(); // Load ECA calibration constants from DB once per run void BeginOfRun( DS::Run& /*run*/ ); // Construct a calibrated PMT from an uncalibrated pmt DS::PMTCal CalibratePMT( const DS::PMTUncal& pmt ); // Apply ECA calibration provided the four charges and the CCCC cell id // Store the calibrated charges in fQHS, fQHL, fQLX and fTAC void CalibrateHit(float qhs, float qhl, float qlx, double tac, int cccc); //Get calibrated QHS float GetQHS() {return fQHS;}; //Get calibrated QHL float GetQHL() {return fQHL;}; //Get calibrated QLX float GetQLX() {return fQLX;}; //Get calibrated TAC double GetTime() {return fTAC;}; //Get ECA calibration status DS::BitMask GetStatus() {return fStatus;}; protected: // Subtract pedestals void PedestalCal(int cccc); // Linear interpolation of TAC slope points: ADC->ns conversion void TSlopeCal(int cccc); // Applies ValidateQ and ValidateT void ValidateCalibrate(int cccc); // Set fStatus according to PDST tests void ValidateQ(int cccc); // Set fStatus according to TSLP tests void ValidateT(int cccc); // Set fCharge[i] to extreme values according to fStatus for PDST and TSLP // (all four methods) void PedCalStatus(int i); void PedADCStatus(int i); void TSlpCalStatus(); void TSlpADCStatus(); // Output and status methods void Die(std::string message, int flag_err, int info1, int info2, int return_code=1); void DontDie(std::string message, int flag_err, int info1, int info2); DBLinkPtr fCalbank; // Table for general PMT calibrations (PMTCAL) DBLinkPtr fPedsbank; // Pedestal ECA constants (ECA_PDST) DBLinkPtr fTslpbank; // Time Slopes ECA constants (ECA_TSLP) DBLinkPtr fDQXXbank; // Channel Hardware Status table (PMT_DQXX) DBLinkPtr fBADCbank; // Information from CALDAC tests table (BADC) int fECAlogverb; // Processor verbosity level int fECAtype; // Calibration type (PDST - TSLP) int fECAPDSTpattern; // ECA PDST pattern type int fECAPDSTrate; // ECA PDST pulser rate int fECATSLPpattern; // ECA TSLP pattern type int fECATSLPrate; // ECA TSLP pulser rate int fNSlopePoints; // Number of points in the time slope int fNTotCell; // Total number of cells int fNdim; // Number of 32bits words in the Tlope words: fTslopeBad, int fTolLevel; // Tolerance level int fTolADC; // Tolerance level bool fDoPed; // Do pedestal calibration flag bool fDoTslp; // Do time slope calibration flag float fTimeOffset; // Time offset for TAC timing double fQHSTestMax; // Upper QHS threshold to be flagged double fQHLTestMax; // Upper QHL threshold to be flagged double fQLXTestMax; // Upper QLX threshold to be flagged double fQHSTestMin; // Lower QHS threshold to be flagged double fQHLTestMin; // Lower QHS threshold to be flagged double fQLXTestMin; // Lower QHS threshold to be flagged double fQLXvsQHSTest; // Upper QLX/QHS threshold to be flagged std::vector > fPedQ; // Pedestal charges std::vector fTslope; // Time slope points std::vector fTslopeX; // Time slope times (x-axis) std::vector fPedStat; // ECA pedestal status word std::vector fPedBID; // Daughter board ID of the ECA run std::vector fTslopeStat; // ECA time slope status word std::vector fTslopeBadTemp; // Time slope 'bad' word as read from the ECA table std::vector > fTslopeBad; // Time slope 'bad' word used std::vector fTslopeBID; // Daughter board ID of the ECA run std::vector fDQIDtemp; // Daughter board ID of the current run to be calibrated as read from PMT_DQXX std::vector fDQID; // Daughter board ID of the current run to be calibrated used std::vector > fPedADC; // Charges status from CALDAC test std::vector fTACADC; // TAC status from CALDAC test float fQHS; // Calibrated QHS float fQHL; // Calibrated QHL float fQLX; // Calibrated QLX float fCharge[3]; // Calibrated charges copied to fQHS, fQHL and fQLX after validation double fTAC; // Calibrated TAC DS::BitMask fStatus; // ECA calibration status word }; } // namespace RAT #endif