/* ======================================================================== *\
!
! *
! * This file is part of MARS, the MAGIC Analysis and Reconstruction
! * Software. It is distributed to you in the hope that it can be a useful
! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
! * It is distributed WITHOUT ANY WARRANTY.
! *
! * Permission to use, copy, modify and distribute this software and its
! * documentation for any purpose is hereby granted without fee,
! * provided that the above copyright notice appear in all copies and
! * that both that copyright notice and this permission notice appear
! * in supporting documentation. It is provided "as is" without express
! * or implied warranty.
! *
!
!
!   Author(s): Keiichi Mase 10/2004 <mailto:mase@mppmu.mpg.de>
!              Markus Meyer 10/2004 <mailto:meyer@astro.uni-wuerzburg.de>
!
!   Copyright: MAGIC Software Development, 2000-2004
!
!
\* ======================================================================== */

/////////////////////////////////////////////////////////////////////////////
//
// MMuonCalibPar
//
// Storage Container for muon
//
//  This class holds some information for a calibraion using muons. Muons 
// are identified by using the class of the MMuonSearchParCalc. You can fill 
// these information by using the MMuonCalibParCalc. See also these class
// manuals.
//
//  
//  Input Containers:
//   [MGeomCam]
//   [MCerPhotEvt]
//   [MMuonSearchPar]
//
/////////////////////////////////////////////////////////////////////////////
#include "MMuonCalibPar.h"

#include <fstream>

#include "MLog.h"
#include "MLogManip.h"
#include "MCerPhotEvt.h"
#include "MCerPhotPix.h"
#include "MMuonSearchPar.h"
#include "MBinning.h"

using namespace std;

ClassImp(MMuonCalibPar);

// --------------------------------------------------------------------------
//
// Default constructor.
//
MMuonCalibPar::MMuonCalibPar(const char *name, const char *title)
{
    fName  = name  ? name  : "MMuonCalibPar";
    fTitle = title ? title : "Muon calibration parameters";

    fHistPhi   = new TH1F;
    fHistWidth = new TH1F;

    fHistPhi->SetName("HistPhi");
    fHistPhi->SetTitle("HistPhi");
    fHistPhi->SetXTitle("phi [deg.]");
    fHistPhi->SetYTitle("sum of ADC");
    fHistPhi->SetDirectory(NULL);
    fHistPhi->SetFillStyle(4000);
    fHistPhi->UseCurrentStyle();

    fHistWidth->SetName("HistWidth");
    fHistWidth->SetTitle("HistWidth");
    fHistWidth->SetXTitle("distance from the ring center [deg.]");
    fHistWidth->SetYTitle("sum of ADC");
    fHistWidth->SetDirectory(NULL);
    fHistWidth->SetFillStyle(4000);
    fHistWidth->UseCurrentStyle();

    fMargin = 60.;  // in mm
    fArcPhiThres  = 100.;
    fArcWidthThres  = 100.;
    fArcPhiBinNum = 20;
    fArcPhiHistStartVal = -180.; // deg.
    fArcPhiHistEndVal   = 180.;  // deg.
    fArcWidthBinNum = 28;
    fArcWidthHistStartVal = 0.3; // deg.
    fArcWidthHistEndVal   = 1.7; // deg.
}

// --------------------------------------------------------------------------
//
MMuonCalibPar::~MMuonCalibPar()
{
  delete fHistPhi;
  delete fHistWidth;
}

// --------------------------------------------------------------------------
//
void MMuonCalibPar::Reset()
{
  fArcLength   = -1.;
  fArcPhi      =  0.;
  fArcWidth    = -1.;
  fChiArcPhi   = -1.;
  fChiArcWidth = -1.;
  fMuonSize    =  0.;
  fEstImpact   = -1.;
  fUseUnmap    = kFALSE;
  fPeakPhi     =  0.;

  fHistPhi->Reset();
  fHistWidth->Reset();
}

void MMuonCalibPar::Print(Option_t *) const
{
    *fLog << all;
    *fLog << "Muon Parameters (" << GetName() << ")"    << endl;
    *fLog << " - Arc Length    [deg.]  = " << fArcLength     << endl;
    *fLog << " - Arc Phi       [deg.]  = " << fArcPhi     << endl;
    *fLog << " - Arc Width     [deg.]  = " << fArcWidth     << endl;
    *fLog << " - Chi Arc Phi   [x2/ndf]= " << fChiArcPhi  << endl;
    *fLog << " - Chi Arc Width [x2/ndf]= " << fChiArcWidth  << endl;
    *fLog << " - Est. I. P.    [m]     = " << fEstImpact  << endl;
    *fLog << " - Size of muon          = " << fMuonSize   << endl;
    *fLog << " - Peak Phi      [deg.]  = " << fPeakPhi    << endl;
    *fLog << " - UseUnmap              = " << fUseUnmap   << endl;
}




