// $Header: CalSmeared.h $

#ifndef NLD_CALSMEARED_H
#define NLD_CALSMEARED_H

#include "Rtypes.h"
#include "TMath.h"
#include "TRandom.h"
#include "TObjArray.h"
// #include "Cluster.h"
#include "SmearTraj.h" 
#include "SmearFuzz.h"
#include <stdio.h>


//=========================================================
// class CalSmeared : public Cluster {
class CalSmeared : public TObject {
public:
  CalSmeared(SmearTraj& traj, Bool_t hadron, SmearFuzz* pFuzz, TRandom *pRand);
  // May also want constructor taking list of particles
  ~CalSmeared() {}
  // Implicit destructor
  // Implicit copy constructor
  // Implicit assignment operator

  void spew(FILE* ofile);
  void spewDiag(FILE* ofile);

  // Methods needed to satisfy Cluster inheritance
  Float_t GetEnergy(){return energy;}

  Float_t GetEnergyTheta() {return eTheta;}
  Float_t GetEnergyPhi() {return ePhi;}
  Float_t GetEnergyR() {return eR;} 

  // Don't yet do anything sensible for RMS.
  Float_t GetEnergyThetaRms()  {return eThetaRms;}
  Float_t GetEnergyPhiRms()  {return ePhiRms;}
  Float_t GetEnergyRRms()  {return eRRms;}

  Double_t* GetPosPerfect() {return &posPerfect[0];}
  Double_t* GetPosSmeared() {return &pos[0];}
  Double_t  GetEPerfect() {return ePerfect;}

  Float_t GetClusterStartDepth() {return eR;}
  
  TObjArray* McIxList() {return mcContribs;} // Return list of indices of
                                           // MC particles

  // Smeared clusters may be formed without hit information
  TObjArray* MCEList()  {return 0;}
  TObjArray* HitList()  {return 0;}

  // The following more logically belong in some sort of utility class
  static Double_t ToDegrees(Double_t rads) 
  {return (180.0 * rads  / TMath::Pi());}

  static Float_t ToDegrees(Float_t rads) 
  {return (180.0 * rads  / TMath::Pi());}
  
  static Double_t ToRadians(Double_t degs) 
  {return (degs * TMath::Pi() / 180.0);}

  static Float_t ToRadians(Float_t degs) 
  {return (degs * TMath::Pi() / 180.0);}

  // The following takes (x,y,z) to (theta,phi,r)
  static void ToPolar(const Double_t *pRect, Double_t *pPolar);

  // Rotate something  by angle represented by angleVec (i.e., first
  // by theta about y-axis, then by phi about z-axis)
  static void Rotate(Double_t* inVec, Double_t* angleVec, Double_t* result);

  static void RotateTheta(const Double_t theta, Double_t *iVec, 
			  Double_t *rVec);

  static void RotatePhi(const Double_t phi, Double_t *iVec, 
			Double_t *rVec);

private:
  CalSmeared()  {}        // Prohibit public calls

  TObjArray*  mcContribs;  // list of indices of contributing MC particles
  Int_t       pid1;        // Save pid of 1st particle for debugging
  Int_t       nPart;       // # particles in cluster.  For now always 1.
  Double_t    ePerfect;    // original energy of associated MC particle
  Float_t     energy;      // smeared energy
  Float_t     energySigma; // sigma used to smear energy

  // Don't yet distinguish between the following:
  Double_t    posClusterStart[3]; // cluster start pos. 
  Double_t    posPerfect[3]; // (should be) shower max position
  Double_t    pos[3];      // smeared  (x,y,z)
  Double_t    sPerfect;    // path length traversed by particle to shower start
  Double_t    ePhi;        // energy-weighted phi of cluster
  Double_t    eTheta;      // energy-weighted theta of cluster
  Double_t    eR;          // energy-weighted radius of cluster
  Double_t    eThetaRms;   // theta rms comes from transverse smearing sigma
  Double_t    ePhiRms;     // phi rms comes from transverse smearing sigma
  Double_t    eRRms;       // current implementation just sets this to 0.

public:
  ClassDef(CalSmeared,1)      // for Cint dictionary
};
#endif

