//////////////////////////////////////////////////////////////////// /// \class RAT::DS::Digitiser /// /// \brief This class represents a detected event on the CAEN v1720 /// digitiser board /// /// \author Gabriel Orebi Gann /// /// REVISION HISTORY: \n /// 25 Sep 2013 - A. Mastbaum: Store samples directly rather than in /// TrigSum and generalize identifiers.\n /// 2014-03-26 : P G Jones - refactor in line with dsreview \n /// 30 May 2017: Eric Marzec - Add convenience methods for analyzing waveforms /// /// \details This contains the waveforms from the CAEN digitiser board /// //////////////////////////////////////////////////////////////////////// #ifndef __RAT_DS_Digitiser__ #define __RAT_DS_Digitiser__ #include #include #include namespace RAT { namespace DS { class Digitiser : public TObject { public: /// Construct the digitiser, set members to 0 Digitiser() : TObject(),eventID(0), trigTime(0), nWords(0), boardID(0), bit24(0), dataFormat(0), ioPins(0), chanMask(0) { } /// Get the board trigger ID /// /// @return event ID Int_t GetEventID() const { return eventID; } /// Set the board trigger ID /// /// @param[in] id of the trigger void SetEventID( const Int_t id ) { eventID = id; } /// Get the board trigger time /// /// @return the trigger time Int_t GetTrigTime() const { return trigTime; } /// Set the board trigger time /// /// @param[in] time of the trigger void SetTrigTime( const Int_t time ) { trigTime = time; } /// Get the number of 32-bit words in a waveform /// /// @return the number of 32-bit words in a waveform UInt_t GetNWords() const { return nWords; } /// Set the number of 32-bit words in a waveform /// /// @param[in] count of 32-bit words void SetNWords( const UInt_t count ) { nWords = count; } /// Get the Board VME ID /// /// @return the board VME ID UInt_t GetBoardID() const { return boardID; } /// Set the board VME ID /// /// @param[in] id of the board VME void SetBoardID( const UInt_t id ) { boardID = id; } /// Get the input header bit 24 /// /// @return the input header bit 24 UShort_t GetBit24() const { return bit24; } /// Set the input header bit 24 /// /// @param[in] value for the input header bit 24 void SetBit24( const UShort_t value ) { bit24 = value; } /// Get the data format/packing type /// /// @return the data format/packing type UShort_t GetDataFormat() const { return dataFormat; } /// Set the the data format/packing type /// /// @param[in] type of the data format/packing void SetDataFormat( const UShort_t type ) { dataFormat = type; } /// Get the front panel IO Pins /// /// @return the front panel IO Pins UShort_t GetIOPins() const { return ioPins; } /// Set the front panel IO Pins /// /// @param[in] pins the front panel IO Pins void SetIOPins( const UShort_t pins ) { ioPins = pins; } /// Check if a waveform exists /// /// @param[in] waveformID to check /// @return True if exists Bool_t ExistsWaveform( const UShort_t waveformID ) const { return waveforms.count( waveformID ) > 0; } /// Get a waveform /// /// @param[in] waveformID to retrieve /// @return the waveform as a vector of UShort_t /// @throws out_of_range error if the waveform doesn't exist std::vector GetWaveform( const UShort_t waveformID ) const { return waveforms.at( waveformID ); } /// Set a waveform, overwrites existing /// /// @param[in] waveformID to set /// @param[in] samples of the wavform void SetWaveform( const UShort_t waveformID, const std::vector& samples ) { waveforms[waveformID] = samples; } ///Get a map of waveform IDs to digitized waveforms /// ///@return the map of IDs to waveforms std::map > GetAllWaveforms() const {return waveforms;} /// Delete all waveforms void PruneWaveforms() { waveforms.clear(); } /// Get the average of the waveform specified by waveformID over the range /// specified / by start and end. If start is unspcified it defaults to sample /// 0, if end / is either unspecified or less than start it defaults to /// waveform.size() double Average(const UShort_t waveformId, size_t start, size_t end) const { std::vector trace = GetWaveform(waveformId); end = check_bounds(start, end, trace.size()); double sum = Integral(waveformId ,start, end); double denom = end - (start+1); denom = (denom == 0) ? 1 : denom; return sum/denom; } /// Gets the integral using the trapazoidal rule of the waveform specified by /// waveformID over the range [start,end). If start is unspcified it /// defaults to sample 0, if end is either unspecified or less than start /// it defaults to waveform.size() double Integral(const UShort_t waveformId, size_t start, size_t end) const { double sum=0.0; std::vector trace = GetWaveform(waveformId); end = check_bounds(start, end, trace.size()); sum += (trace.at(start) + trace.at(end-1))/2.0; for(size_t i=start+1; i < end-1; i++) { // Using [i] for array look up instead of .at(i) b/c i is guranteed // to be between start and end, and an error already would have // ocurred if those were out bounds. sum += trace[i]; } return sum; } /// Finds the minimum value in the waveform specified by waveformID over the /// range [start, end). If start is unspcified it defaults to sample 0, if /// end is either unspecified or less than start it defaults to waveform.size() UShort_t Min(const UShort_t waveformId, size_t start, size_t end) const { std::vector trace = GetWaveform(waveformId); end = check_bounds(start, end, trace.size()); UShort_t min = trace.at(start); for(size_t i=start; i trace = GetWaveform(waveformId); end = check_bounds(start, end, trace.size()); UShort_t max = trace.at(start); for(size_t i=start; i max) { max = trace.at(i); } } return max; } /// Get a list (vector) of all the IDs that are available /// /// @return a list of all the useable IDs as a vector of UShort_t std::vector GetIDs() const { std::vector ret; for (std::map >::const_iterator it= waveforms.begin(); it != waveforms.end(); it++) { ret.push_back(it->first); } return ret; } // This ROOT macro adds dictionary methods to this class. // The number should be incremented whenever this class's members are changed. // It assumes this class has no virtual methods, use ClassDef if change this. ClassDefNV(Digitiser, 4); protected: std::map > waveforms; ///< Map of input number to samples Int_t eventID; ///< The event Global Trigger ID, GTID, as understood by the digitiser Int_t trigTime; ///< The trigger time on the digitiser UInt_t nWords; ///< Number of 32bit words in each waveform UInt_t boardID; ///< The board VME ID UShort_t bit24; ///< Input header bit 24 UShort_t dataFormat; ///< The data format type UShort_t ioPins; ///< Front panel IO pins UShort_t chanMask; ///< Current channel mask private: // Utility function used by public functions that operate over a subset of a // waveform. Checks that the desired subset is valid. size_t check_bounds(size_t start, size_t end, size_t alternate) const { return end <= start ? alternate : end; } }; } // namespace DS } // namespace RAT #endif // __RAT_DS_Digitiser__