ROOT logo
#ifndef HMDCKICKPLANE_H
#define HMDCKICKPLANE_H

#include "TObject.h"
#include "hgeomvector.h"
#include "hsymmat.h"

class HSymMat;
class HMdcSeg;

class HMdcKickPlane : public TObject {
protected:
  //Plane equation: y=fDx*x + fDz[i]*z + fC[i]
  Double_t fDzLimit[2];
  Double_t fDx;
  Double_t fDz[3];
  Double_t fC[3];
  //Plane equation: parA[i]*x + parB[i]*y + z = padD[i]
  Double_t parA[3];
  Double_t parB[3];
  Double_t parD[3];
  
  void setDefaultParam(void);
public:
  HMdcKickPlane(void) {setDefaultParam();}
  ~HMdcKickPlane(void) {}
  inline void calcIntersection(const HGeomVector &p,const HGeomVector &dir,HGeomVector &out) const;
  inline void calcSegIntersec(Double_t z0,Double_t r,Double_t theta,Double_t phi,HGeomVector &out) const;
  
  void calcIntersection(Double_t x1,Double_t y1,Double_t z1,
                        Double_t x2, Double_t y2, Double_t z2,
                        Double_t& x, Double_t& y, Double_t& z) const;
  void calcIntersection(Double_t x1,Double_t y1,Double_t z1,
                        Double_t x2,Double_t y2,Double_t z2, HGeomVector &out) const;
  
  void calcSegIntersec(Float_t z0,Float_t r0,Float_t theta,Float_t phi,
		       HGeomVector &p, HGeomVector &dir, HGeomVector &out) const;
  
  void calcSegIntersec(Float_t z0,Float_t r0,Float_t theta,Float_t phi, HSymMat &m, 
                        HGeomVector &p, HGeomVector &dir,HGeomVector &out,
                        Double_t &errX,Double_t &errY) const;
  void calcSegIntersec(HMdcSeg *seg1,HGeomVector &p, HGeomVector &dir, HGeomVector &out,
                       HGeomVector *sOnKick) const;
  void calcSegIntersec(HMdcSeg *seg, HGeomVector &out) const;
  
  ClassDef(HMdcKickPlane,0) //Defines a plane surface
};

inline void HMdcKickPlane::calcIntersection(const HGeomVector &p,const HGeomVector &dir,
				            HGeomVector &out) const {
  // Calcul. a cross of the line with plane       y=fDx*x+fDz*z+fC
  for(Int_t i=0;i<3;i++) {
    Double_t c2  = fDz[i]*dir.getZ();
    Double_t c3  = p.getY()-fC[i];
    
    Double_t cDx = fDx;
    Double_t c1  = cDx*dir.getX()-dir.getY();
    Double_t div = 1/(c1+c2);
    Double_t cx  = dir.getX()*(c3-fDz[i]*p.getZ())+ p.getX()*(c2-dir.getY());
    Double_t x   = cx*div;
    if(x<0) {
      cDx = -fDx;
      c1  = cDx*dir.getX()-dir.getY();
      div = 1/(c1+c2);
      x   = cx*div;
    }   
    Double_t z = (dir.getZ()*(c3-cDx*p.getX()) + p.getZ()*c1)*div;
    if(i<2 && z<fDzLimit[i]) continue;
    out.setXYZ(x,cDx*x+fDz[i]*z+fC[i],z);
    break;
  }
}

inline void HMdcKickPlane::calcSegIntersec(Double_t z0,Double_t r0,Double_t theta,Double_t phi,
				       HGeomVector &out) const {
  // Calcul. a cross of the line with plane       y=fDx*x+fDz*z+fC
  Double_t cosPhi = TMath::Cos(phi);
  Double_t sinPhi = TMath::Sin(phi);
  Double_t x0     = -r0*sinPhi;   
  Double_t y0     =  r0*cosPhi; 
  Double_t dZ     = TMath::Cos(theta);
  Double_t dxy    = TMath::Sqrt(1.-dZ*dZ);
  Double_t dX     = dxy*cosPhi;
  Double_t dY     = dxy*sinPhi;

  for(Int_t i=0;i<3;i++) {
    Double_t c2  = fDz[i]*dZ;
    Double_t c3  = y0-fC[i];
    
    Double_t cDx = fDx;
    Double_t c1  = cDx*dX-dY;
    Double_t div = 1./(c1+c2);
    Double_t cx  = dX*(c3-fDz[i]*z0)+ x0*(c2-dY);
    Double_t x   = cx*div;
    if(x<0) {
      cDx = -fDx;
      c1  = cDx*dX-dY;
      div = 1./(c1+c2);
      x   = cx*div;
    }   
    Double_t z = (dZ*(c3-cDx*x0) + z0*c1)*div;
    if(i<2 && z<fDzLimit[i]) continue;
    out.setXYZ(x,cDx*x+fDz[i]*z+fC[i],z);
    break;
  }
}

#endif   /*!HMDCKICKPLANE_H*/
 hmdckickplane.h:1
 hmdckickplane.h:2
 hmdckickplane.h:3
 hmdckickplane.h:4
 hmdckickplane.h:5
 hmdckickplane.h:6
 hmdckickplane.h:7
 hmdckickplane.h:8
 hmdckickplane.h:9
 hmdckickplane.h:10
 hmdckickplane.h:11
 hmdckickplane.h:12
 hmdckickplane.h:13
 hmdckickplane.h:14
 hmdckickplane.h:15
 hmdckickplane.h:16
 hmdckickplane.h:17
 hmdckickplane.h:18
 hmdckickplane.h:19
 hmdckickplane.h:20
 hmdckickplane.h:21
 hmdckickplane.h:22
 hmdckickplane.h:23
 hmdckickplane.h:24
 hmdckickplane.h:25
 hmdckickplane.h:26
 hmdckickplane.h:27
 hmdckickplane.h:28
 hmdckickplane.h:29
 hmdckickplane.h:30
 hmdckickplane.h:31
 hmdckickplane.h:32
 hmdckickplane.h:33
 hmdckickplane.h:34
 hmdckickplane.h:35
 hmdckickplane.h:36
 hmdckickplane.h:37
 hmdckickplane.h:38
 hmdckickplane.h:39
 hmdckickplane.h:40
 hmdckickplane.h:41
 hmdckickplane.h:42
 hmdckickplane.h:43
 hmdckickplane.h:44
 hmdckickplane.h:45
 hmdckickplane.h:46
 hmdckickplane.h:47
 hmdckickplane.h:48
 hmdckickplane.h:49
 hmdckickplane.h:50
 hmdckickplane.h:51
 hmdckickplane.h:52
 hmdckickplane.h:53
 hmdckickplane.h:54
 hmdckickplane.h:55
 hmdckickplane.h:56
 hmdckickplane.h:57
 hmdckickplane.h:58
 hmdckickplane.h:59
 hmdckickplane.h:60
 hmdckickplane.h:61
 hmdckickplane.h:62
 hmdckickplane.h:63
 hmdckickplane.h:64
 hmdckickplane.h:65
 hmdckickplane.h:66
 hmdckickplane.h:67
 hmdckickplane.h:68
 hmdckickplane.h:69
 hmdckickplane.h:70
 hmdckickplane.h:71
 hmdckickplane.h:72
 hmdckickplane.h:73
 hmdckickplane.h:74
 hmdckickplane.h:75
 hmdckickplane.h:76
 hmdckickplane.h:77
 hmdckickplane.h:78
 hmdckickplane.h:79
 hmdckickplane.h:80
 hmdckickplane.h:81
 hmdckickplane.h:82
 hmdckickplane.h:83
 hmdckickplane.h:84
 hmdckickplane.h:85
 hmdckickplane.h:86
 hmdckickplane.h:87
 hmdckickplane.h:88
 hmdckickplane.h:89
 hmdckickplane.h:90
 hmdckickplane.h:91
 hmdckickplane.h:92
 hmdckickplane.h:93
 hmdckickplane.h:94
 hmdckickplane.h:95
 hmdckickplane.h:96
 hmdckickplane.h:97
 hmdckickplane.h:98
 hmdckickplane.h:99
 hmdckickplane.h:100
 hmdckickplane.h:101
 hmdckickplane.h:102
 hmdckickplane.h:103
 hmdckickplane.h:104
 hmdckickplane.h:105
 hmdckickplane.h:106
 hmdckickplane.h:107
 hmdckickplane.h:108