//////////////////////////////////////////////////////////////////////// /// \class RAT::DataQualityProc /// /// \brief Parent class for all high level data quality processors /// /// \author Ashley R. Back /// /// REVISION HISTORY:\n // - 2016 11 30 - Mark Stringer - Fixes such that the AddToRATDB method outputs to within the checks field for RATDB compatibility /// /// \details Contains public methods that are used by all data quality\n /// processors, e.g. for handling of RATDB record files, uniform\n /// naming and updating the data quality status words.\n /// Also contains protected members which include the record file and\n /// data quality status words. /// //////////////////////////////////////////////////////////////////////// #ifndef __RAT_DataQualityProc__ #define __RAT_DataQualityProc__ class TFile; class TH1D; class TH1I; class TH2D; class TGraph; class TVector2; class TVector3; class TObject; class TDirectory; #include #include #include #include namespace RAT { namespace DS { class Run; } } #include #include #include namespace RAT { class DataQualityProc : public Processor { public: DataQualityProc( std::string _name ); virtual ~DataQualityProc(); /// /// @param[in] run DS:Run location in data structure virtual void BeginOfRun( DS::Run& run ); /// Get Name of current DQ processor /// /// @return name of processor virtual std::string GetName() const { return fName; } /// Get current run number /// /// @return run number for current run virtual int GetRunID() const { return fRunID; } /// Get current sub-run number /// /// @return sub-run number for current run virtual int GetSubRunID() const { return fSubRunID; } /// Get date of current run /// /// @return date of current run virtual int GetDate() const { return fDate; } /// Get time of current run /// /// @return time of current run virtual int GetTime() const { return fTime; } /// Get output file (base) name, for any DQ output file /// /// @return std::string (base) file name for any DQ output virtual std::string GetOutFileName() const { return fOutFileName; } /// Sets output file name virtual void SetOutFileName(); /// Default is not to produce png images of plots. Method to override /// this behaviour and produce image files. /// /// @param[in] param should be images /// @param[in] value should be 1 if images are required /// @throws ParamUnknown if param is not images /// @throws ParamInvalid if value is not 0 or 1 virtual void SetI( const std::string& param, const int value ); /// Method to set the index on DATAQUALITY_RECORDS table by defualt /// it will be an empty string it can either be set to L1 or L2 depending /// on level of processing of the file. // /// @param[in] param should be processing_level /// @param[in] should either be L1 (raw zdab) or L2 (l2 processed zdab) virtual void SetS(const std::string& param, const std::string& value); /// Updates data quality flags with results of current check /// /// @param[in] checkName std::string name of current DQ check /// @param[in] result bool result of check passed=true, failed=false virtual void Update( const std::string &checkName, const bool& result ); /// Opens ROOT record file for saving histograms virtual void OpenRootFile() const; /// Sets Root gStyle options to ensure uniform output plots virtual void SetRootStyle() const; /// Formats x-axis of histograms nicely for log scale /// /// @param[in] histogram TH1D* histogram for which to format axis virtual void LogBinsX( TH1D* histogram ); /// Formats x-axis of histograms nicely for log scale (negative numbers) /// /// @param[in] histogram TH1D* histogram for which to format axis virtual void NegativeLogBinsX( TH1D* histogram ); /// /// @param[in] obj TObject object to be saved to root file /// @param[in] name of object to be written (for TVectors) virtual void WriteToRoot(TObject* obj, const char* name = NULL, const char* directory=NULL); /// Plots and saves a 1D histogram /// /// @param[in] h1 TH1D* histogram to draw and save /// @param[in] xAxis std::string xAxis title for plot /// @param[in] yAxis std::string yAxis title for plot /// @param[in] logX bool should log-scale be applied to x-axis? (true=yes, false=no) virtual void Plot1DHist( TH1D* h1, const std::string &xAxis, const std::string &yAxis = "Events", const bool &logX = false ) const; /// Plots and saves a 2D histogram /// /// @param[in] histogram TH2D* histogram to draw and save /// @param[in] xAxis std::string xAxis title for plot /// @param[in] yAxis std::string yAxis title for plot virtual void Plot2DHist( TH2D* histogram, const std::string &xAxis, const std::string &yAxis ) const; /// Plots and saves a scatter plot /// /// @param[in] graph TGraph* graph to draw and save /// @param[in] xAxis std::string xAxis title for plot /// @param[in] yAxis std::string yAxis title for plot /// @param[in] markerStyle double requested marker style for plot /// @param[in] markerColor double requested marker color for plot /// @param[in] markerSize double requested marker size for plot virtual void Plot2DScatter( TGraph* graph, const std::string &xAxis, const std::string &yAxis, const double markerStyle, const double markerColor, const double markerSize ) const; /// Transforms vectors on to 2D psup projection virtual TVector2 TransformCoord( const TVector3& V1, const TVector3& V2, const TVector3& V3, const TVector2& A1, const TVector2& A2, const TVector2& A3, const TVector3& P ) const; /// Calculates which case of projection required and then calls TransformCoord /// @param[in] pmtPos TVector3 position of PMT to be projected /// @param[in] segment int& PSUP face on which this PMT is mounted /// @return TVector2 position of PMT on 2D PSUP projection virtual TVector2 IcosProject( TVector3 pmtPos, int &segment) const; /// Returns correct image name for a 1D histogram /// /// @param[in] histogram TH1D requested histogram to save /// @return std::string correct image name for histogram virtual std::string GetImageName( TH1D* histogram ) const; /// Returns correct image name for a 1D histogram /// /// @param[in] histogram TH1I requested histogram to save /// @return std::string correct image name for histogram virtual std::string GetImageName( TH1I* histogram ) const; /// Get correct image name to save a histogram /// /// @param[in] histogram TH2D requested histogram to save /// @return std::string correct image name for histogram virtual std::string GetImageName( TH2D* histogram ) const; /// Get correct image name to save a graph /// /// @param[in] graph TGraph requested graph to save /// @return std::string correct image name for graph virtual std::string GetImageName( TGraph* graph ) const; /// Add comments about check trig type /// Checks Trigger Type virtual bool CheckTrigType( const int triggerMask, const int criteriaMask, const int bit) const; /// Converts MHz ticks value to time in seconds /// /// @param[in] ticks number of oscillator ticks/counts /// @param[in] frequency (int) of oscillator in MHz virtual double MHzTicks2Seconds( unsigned long int ticks, int frequency ) const; /// Returns time formatted as "d d hh:mm:ss" for display /// /// @param[in] seconds (double) input time in seconds /// @return std::string correctly formatted display time virtual std::string DisplayTime( double seconds ) const; /// From an input trigType bitmask, returns active triggers as text /// /// @param[in] trigger (int) trigger mask to convert to text /// @return std::string trigger mask formatted as text virtual std::string TriggerToString( const int trigger ) const; /// Writes key, value pair (not a DQ check) to RATDB /// /// @param[in] key std::string RATDB table key to add /// @param[in] value std::vector RATDB table value to add virtual void AddToRATDB( std::string key, std::vector value); /// Writes key, value pair (not a DQ check) to RATDB /// /// @param[in] key std::string RATDB table key to add /// @param[in] value std::vector RATDB table value to add virtual void AddToRATDB( std::string key, std::vector value); /// Writes key, value pair (not a DQ check) to RATDB /// /// @param[in] key std::string RATDB table key to add /// @param[in] value std::vector RATDB table value to add virtual void AddToRATDB( std::string key, std::vector value); /// Writes key, value pair (not a DQ check) to RATDB /// /// @param[in] key std::string RATDB table key to add /// @param[in] value double RATDB table value to add virtual void AddToRATDB( std::string key, double value); /// Writes key, value pair (not a DQ check) to RATDB /// /// @param[in] key std::string RATDB table key to add /// @param[in] value std::string RATDB table value to add virtual void AddToRATDB( std::string key, std::string value); /// Writes key, value pair (not a DQ check) to RATDB /// /// @param[in] key std::string RATDB table key to add /// @param[in] value int RATDB table value (mask) to add virtual void AddMaskToRATDB( std::string key, int value); /// Writes check results stored in DBTable object to RATDB void WriteToRATDB(); /// /// param[in] run DS::Run location virtual void EndOfRun( DS::Run& run ); protected: static int nDataQualityProc; /// fDQProcs; // vector to fill with the name of each DQ processor run static int nEndOfRunComplete; ///