/**
 * \class BDHadMuMon
 *
 * \ingroup BeamDataUtil
 *
 * \brief Hadron and Muon monitor data.
 *
 * Provide routines specific to hadron and muon monitors for unpacking
 * the data based on channel or pixel numbers.
 *
 * The hadron monitor channel mapping is different (transposed) from
 * the muon monitors mapping.  Both count pixels starting from row=1
 * and col=1 with the origin at the lower left.  See NuMI-B-1084 for
 * diagrams.
 *
 * \author (last to touch it) $Author: bv $
 *
 * \version $Revision: 1.4 $
 *
 * \date $Date: 2005/05/16 16:23:02 $
 *
 * Contact: bv@bnl.gov
 *
 * Created on: Fri Apr 15 14:25:38 2005
 *
 * $Id: BDHadMuMon.h,v 1.4 2005/05/16 16:23:02 bv Exp $
 *
 */

#ifndef BDHADMUMON_H
#define BDHADMUMON_H

#include <BeamDataUtil/BDSwicDevice.h>

class BDHadMuMon : public BDSwicDevice {
public:
    /** \brief Default constructor.
     *
     * Constructed this way, this object will not be valid until
     * SetData() is called.
     */
    BDHadMuMon();

    /** \brief Construct a BDHadMuMon with an initial RawBeamData object.
     *
     * The RawBeamData object should be from Hadron or muon monitor data.
     */
    BDHadMuMon(const RawBeamData& hadmu_data);

    virtual ~BDHadMuMon();

    /** \brief Set the RawBeamData from a Hadron or Muon monitor device.
     *
     */
    virtual void SetData(const RawBeamData& hadmu_data);

    /** \brief Convert hardware channel [1,max_channel] to index into
	data array [0,max_channel-1]. */
    int Index(int channel);

    /** \brief Convert pixel row,col (each [1,max_rowcol]) to hardware
	channel [1,max_channel].  Pixel origin is lower left. */
    int Channel(int row, int col);

    /** \brief Return the pixel position given either a row or column
	[1,max_rowcol].  Rows and column numbers originate in lower left */
    double PixelPosition(int rowcol);

    /** \brief Calculate statistical measure of beam center and width.
     *
     * \return a double giving the integrated signal
     */
    double GetStats(double& xmean, double &ymean, double &xrms, double &yrms);

    int GetNrowcol() const { return fNrowcol; }

private:

    void UpdateCache();

    int fNrowcol, fNchannels;
    double fRowColSpacing;
};

#endif  // BDHADMUMON_H
