#ifndef HPARTICLEANGLECOR_H
#define HPARTICLEANGLECOR_H
#include "hades.h"
#include "hevent.h"
#include "hparticlecand.h"
#include "heventheader.h"
#include "hgeomvector.h"
#include "hparticledef.h"
#include "TObject.h"
#include "TMath.h"
#include "TString.h"
#include <queue>
using namespace std;
class HParticleAngleCor : public TObject {
protected:
Float_t meanZTarget;
Float_t zRichCenter;
Float_t zMirror;
Float_t rMirror;
Float_t drShield;
Float_t maxRhoShield;
Bool_t useMeanXY;
Bool_t useShield;
Int_t vertexType;
Bool_t bDoWarn;
Double_t sumXVertex;
Double_t sumYVertex;
UInt_t maxAverage;
HGeomVector globalVertex;
queue<Float_t> qxVertex;
queue<Float_t> qyVertex;
UInt_t evtSeqNo;
public:
HParticleAngleCor(void);
~HParticleAngleCor(void) {};
void initParam(void);
void resetMeanVertex();
Bool_t recalcEmission(const Double_t z, const Double_t rho, const Double_t theta, const Double_t phi,
Double_t & zCor, Double_t & rhoCor, Double_t & thetaCor, Double_t & phiCor);
Bool_t recalcEmission(const HParticleCand * pCand,
Double_t & zCor, Double_t & rhoCor, Double_t & thetaCor,Double_t & phiCor);
Bool_t recalcAngles (const HParticleCand * pCand, Double_t & thetaCor, Double_t & phiCor);
Bool_t recalcSetAngles (HParticleCand* pCand);
Bool_t recalcSetEmission(HParticleCand* pCand);
static Bool_t alignRichRing(const Double_t theta, const Double_t phi, Double_t & thetaCor, Double_t & phiCor);
static Bool_t alignRichRing(HParticleCand* pCand);
static Bool_t realignRichRing(const HParticleCand* pCand, Double_t & thetaCor, Double_t & phiCor);
static Bool_t realignRichRing(HParticleCand* pCand);
static Float_t matchRingTrack(HParticleCand* cand);
void calcSegVector(const Double_t z, const Double_t rho, const Double_t phi, const Double_t theta,
HGeomVector &base, HGeomVector &dir);
void setMeanZTarget(const Float_t zValue);
void setShield(const Bool_t shieldFlag);
Bool_t setDefaults(const TString beamtime);
void setMaxAverage(UInt_t n) { if (n > 1 ) maxAverage = n; }
void setUseMeanXYVertex(void);
void setUseEventXYVertex(void);
void setDoWarning(Bool_t warn) { bDoWarn = warn; }
Bool_t getMeanXYVertex(Float_t & xValue, Float_t & yValue);
Float_t getMeanZTarget(void) {return meanZTarget;};
void setVertexType(Int_t v=Particle::kVertexSegment) { vertexType = v ;}
Int_t getVertexType(){ return vertexType ;}
HGeomVector getGlobalVertex(Int_t v=Particle::kVertexParticle,Bool_t warn=kFALSE);
Bool_t setGlobalVertex(void);
ClassDef(HParticleAngleCor,0)
};
#endif //HPARTICLEANGLECOR_H