#include "MMcEvt.hxx"

#include "MLog.h"
#include "MLogManip.h"

//==========
// MMcEvt
//    
// This class handles and contains the MonteCarlo information
// with which the events have been generated
// This information exists for each event.
 


ClassImp(MMcEvt);



MMcEvt::MMcEvt()
{
    //
    //  default constructor
    //  set all values to zero
    fName  = "MMcEvt";
    fTitle = "Event info from Monte Carlo";

    Clear();
}

MMcEvt::MMcEvt( UShort_t usPId,
		Float_t  fEner, 
		Float_t  fThet, 
		Float_t  fPhii, 
		Float_t  fCorD, 
		Float_t  fCorX, 
		Float_t  fCorY,
		Float_t  fImpa, 
		UInt_t   uiPin, 
		UInt_t   uiPat,  
		UInt_t   uiPre, 
		UInt_t   uiPco,  
		UInt_t   uiPelS,
		UInt_t   uiPelC ) {

    fName  = "MMcEvt";
    fTitle = "Event info from Monte Carlo";
  //
  //  constuctor II 
  //
  //  All datamembers are parameters. 
  //
  //  Don't use this memberfunction in analysis
  //  

  fPartId = usPId  ;
  fEnergy  = fEner  ;

  fTheta   = fThet ;
  fPhi     = fPhii ;

  fCoreD   = fCorD ;
  fCoreX   = fCorX ;
  fCoreY   = fCorY ;
  fImpact  = fImpa ;

  fPhotIni      = uiPin ;
  fPassPhotAtm  = uiPat ;
  fPassPhotRef  = uiPre ;
  fPassPhotCone = uiPco ;
  fPhotElfromShower = uiPelS ;
  fPhotElinCamera   = uiPelC ;
}



MMcEvt::~MMcEvt() {
  //
  //  default destructor
  //
}




void MMcEvt::Clear(Option_t *opt)
{
    //
    //  reset all values to values as nonsense as possible
    //
    fPartId = 0;
    fEnergy = -1;

    fTheta = 0;
    fPhi   = 0;

    fCoreD  =  0;
    fCoreX  =  0;
    fCoreY  =  0;
    fImpact = -1;

    fPhotIni          = 0;
    fPassPhotAtm      = 0;
    fPassPhotRef      = 0;
    fPassPhotCone     = 0;
    fPhotElfromShower = 0;
    fPhotElinCamera   = 0;
}

void MMcEvt::Fill( UShort_t usPId, 
		   Float_t  fEner, 
		   Float_t  fThet, 
		   Float_t  fPhii, 
		   Float_t  fCorD, 
		   Float_t  fCorX, 
		   Float_t  fCorY,
		   Float_t  fImpa, 
		   UInt_t   uiPin, 
		   UInt_t   uiPat,  
		   UInt_t   uiPre, 
		   UInt_t   uiPco,  
		   UInt_t   uiPelS,  
		   UInt_t   uiPelC ) {
  //
  //  All datamembers are filled with the correspondin parameters. 
  //
  //  Don't use this memberfunction in analysis
  //  

  fPartId = usPId  ;
  fEnergy = fEner  ;

  fTheta  = fThet ;
  fPhi    = fPhii ;

  fCoreD  = fCorD ;
  fCoreX  = fCorX ;
  fCoreY  = fCorY ;
  fImpact = fImpa ;

  fPhotIni      = uiPin ;
  fPassPhotAtm  = fPhotIni-uiPat ;
  fPassPhotRef  = fPassPhotAtm-uiPre ;
  fPassPhotCone = uiPco ;
  fPhotElfromShower = uiPelS ;
  fPhotElinCamera = uiPelC ;
}

/*
void MMcEvt::AsciiWrite(ofstream &fout) const
{
    fout << fEnergy << " ";
    fout << fTheta ;
}
*/

// --------------------------------------------------------------------------
//
// Print the contents of the container.
//
//  if you specify an option only the requested data members are printed:
//  allowed options are:
//   id, energy, impact
//
void MMcEvt::Print(Option_t *opt) const
{
    //
    //  print out the data member on screen
    //
    TString str(opt);
    if (str.IsNull())
    {
        *fLog << all << endl;
        *fLog << "Monte Carlo output:" << endl;
        *fLog << " Particle Id:    ";
        switch(fPartId)
        {
        case kGAMMA:
            *fLog << "Gamma" << endl;
            break;
        case kPROTON:
            *fLog << "Proton" << endl;
            break;
        case kHELIUM:
            *fLog << "Helium" << endl;
            break;
        }
        *fLog << " Energy:         " << fEnergy << "GeV" << endl;
        *fLog << " Impactpar.:     " << fImpact/100 << "m" << endl;
        *fLog << " Photoelectrons: " << fPhotElfromShower << endl;
        *fLog << endl;
        return;
    }
    if (str.Contains("id", TString::kIgnoreCase))
        switch(fPartId)
        {
        case kGAMMA:
            *fLog << "Particle: Gamma" << endl;
            break;
        case kPROTON:
            *fLog << "Particle: Proton" << endl;
            break;
        case kHELIUM:
            *fLog << "Particle: Helium" << endl;
            break;
        }
    if (str.Contains("energy", TString::kIgnoreCase))
        *fLog << "Energy: " << fEnergy << "GeV" << endl;
    if (str.Contains("impact", TString::kIgnoreCase))
        *fLog << "Impact: " << fImpact << "cm" << endl;
}
