Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

WCSimGeometry Class Reference

#include "WCSimGeometry.hh"

List of all members.

Public Types

enum  EGeoConfiguration {
  kDUSEL_Unknown = 0, kDUSEL_100kton_10inch_12percent = 1001012, kDUSEL_100kton_10inch_15percent = 1001015, kDUSEL_100kton_10inch_30percent = 1001030,
  kDUSEL_100kton_10inch_40percent = 1001040, kDUSEL_200kton_10inch_12percent = 2001012, kDUSEL_200kton_12inch_10percent = 2001210, kDUSEL_200kton_12inch_14percent = 2001214,
  kDUSEL_150ktonMailbox_10inch_15percent = 101501015, kDUSEL_150ktonMailbox_10inch_30percent = 101501030, kDUSEL_150ktonMailbox_10inch_40percent = 101501040
}
enum  EGeoType { kUnknown = -1, kCylinder = 0, kMailBox = 1 }
enum  EGeoRegion {
  kTop = 0, kSide = 1, kBottom = 2, kFront = 10,
  kBack = 12, kLeft = 20, kRight = 22
}
typedef enum
WCSimGeometry::EGeoConfiguration 
GeoConfiguration_t
typedef enum
WCSimGeometry::EGeoType 
GeoType_t
typedef enum
WCSimGeometry::EGeoRegion 
GeoRegion_t

Public Member Functions

const char * AsString (GeoConfiguration_t config)
void SetGeometry (WCSimRootGeom *geom)
void WriteToFile (const char *filename="wcsim.geometry.root")
WCSimRootGeom * GetWCSimGeometry ()
Int_t GetGeoConfig ()
Int_t GetGeoType ()
Bool_t IsCylinder ()
Double_t GetCylRadius ()
Double_t GetCylLength ()
Double_t GetCylFiducialRadius ()
Double_t GetCylFiducialLength ()
Bool_t IsMailBox ()
Double_t GetMailBoxX ()
Double_t GetMailBoxY ()
Double_t GetMailBoxZ ()
Double_t GetMailBoxFiducialX ()
Double_t GetMailBoxFiducialY ()
Double_t GetMailBoxFiducialZ ()
Double_t GetArea ()
Double_t GetVolume ()
Double_t GetFiducialVolume ()
Int_t GetNumPMTs ()
Double_t GetPMTRadius ()
Double_t GetPMTCoverage ()
Double_t GetPMTSeparation ()
Int_t GetRegion (Int_t tube)
Double_t GetX (Int_t tube)
Double_t GetY (Int_t tube)
Double_t GetZ (Int_t tube)
Bool_t InsideDetector (Double_t x, Double_t y, Double_t z)
Bool_t InsideFiducialVolume (Double_t x, Double_t y, Double_t z)
Bool_t InsideDetector (Double_t vx, Double_t vy, Double_t vz, Double_t ex, Double_t ey, Double_t ez)
Double_t DistanceToEdge (Double_t x, Double_t y, Double_t z)
void ProjectToNearEdge (Double_t x0, Double_t y0, Double_t z0, Double_t px, Double_t py, Double_t pz, Double_t &x, Double_t &y, Double_t &z, Int_t &region)
void ProjectToFarEdge (Double_t x0, Double_t y0, Double_t z0, Double_t px, Double_t py, Double_t pz, Double_t &x, Double_t &y, Double_t &z, Int_t &region)
Double_t ForwardProjectionToEdge (Double_t x, Double_t y, Double_t z, Double_t px, Double_t py, Double_t pz)
Double_t BackwardProjectionToEdge (Double_t x, Double_t y, Double_t z, Double_t px, Double_t py, Double_t pz)
void ProjectToEdge (Bool_t useFarEdge, Double_t x0, Double_t y0, Double_t z0, Double_t px, Double_t py, Double_t pz, Double_t &x, Double_t &y, Double_t &z, Int_t &region)
void ProjectToEdgeOld (Bool_t UseFarEdge, Double_t x0, Double_t y0, Double_t z0, Double_t px, Double_t py, Double_t pz, Double_t &x, Double_t &y, Double_t &z, Int_t &region)
void XYZtoUV (Int_t region, Double_t x, Double_t y, Double_t z, Double_t &u, Double_t &v)

Static Public Member Functions

static WCSimGeometryInstance ()
static void BuildGeometry (WCSimRootGeom *geom)
static void PrintGeometry ()
static void WriteGeometry (const char *filename="wcsim.geometry.root")
static Bool_t TouchGeometry ()
static void Reset ()
static void FindCircle (Double_t x0, Double_t y0, Double_t z0, Double_t x1, Double_t y1, Double_t z1, Double_t x2, Double_t y2, Double_t z2, Double_t &rx, Double_t &ry, Double_t &rz, Double_t &nx, Double_t &ny, Double_t &nz, Double_t &r)
static void FindCircle (Double_t xp, Double_t yp, Double_t zp, Double_t x0, Double_t y0, Double_t z0, Double_t angle_degrees, Double_t omega_degrees, Double_t &rx, Double_t &ry, Double_t &rz, Double_t &nx, Double_t &ny, Double_t &nz, Double_t &r)
static void FindCircleOld (Double_t xp, Double_t yp, Double_t zp, Double_t x0, Double_t y0, Double_t z0, Double_t angle_degrees, Double_t omega_degrees, Double_t &rx, Double_t &ry, Double_t &rz, Double_t &nx, Double_t &ny, Double_t &nz, Double_t &r)
static void FindVertex (Double_t x0, Double_t y0, Double_t z0, Double_t t0, Double_t x1, Double_t y1, Double_t z1, Double_t t1, Double_t x2, Double_t y2, Double_t z2, Double_t t2, Double_t x3, Double_t y3, Double_t z3, Double_t t3, Double_t &vxm, Double_t &vym, Double_t &vzm, Double_t &vtm, Double_t &vxp, Double_t &vyp, Double_t &vzp, Double_t &vtp)
static void DistanceToIntersectLine (Double_t x0, Double_t y0, Double_t z0, Double_t vx, Double_t vy, Double_t vz, Double_t ex, Double_t ey, Double_t ez, Double_t &x, Double_t &y, Double_t &z, Double_t &L)
static Double_t DistanceToIntersectLine (Double_t x0, Double_t y0, Double_t z0, Double_t sx, Double_t sy, Double_t sz, Double_t ex, Double_t ey, Double_t ez, Double_t &x, Double_t &y, Double_t &z)
static Double_t DistanceToIntersectLine (Double_t *pos, Double_t *start, Double_t *end, Double_t *intersection)

Private Member Functions

 WCSimGeometry ()
 WCSimGeometry (WCSimRootGeom *geom)
 ~WCSimGeometry ()

Private Attributes

Double_t fScale
Int_t fPMTs
Double_t * fPmtX
Double_t * fPmtY
Double_t * fPmtZ
Int_t * fPmtRegion
Double_t fPMTRadius
Double_t fPMTCoverage
Double_t fPMTSeparation
Double_t fPMTSurfaceArea
Int_t fGeoType
Int_t fGeoTypeInput
Int_t fGeoConfig
Bool_t fCylinder
Double_t fCylRadius
Double_t fCylLength
Double_t fCylFiducialRadius
Double_t fCylFiducialLength
Bool_t fMailBox
Double_t fMailBoxX
Double_t fMailBoxY
Double_t fMailBoxZ
Double_t fMailBoxFiducialX
Double_t fMailBoxFiducialY
Double_t fMailBoxFiducialZ
Double_t fDetectorArea
Double_t fDetectorVolume
Double_t fDetectorFiducialVolume
Int_t fTube
Int_t fRegion
Double_t fXpos
Double_t fYpos
Double_t fZpos
WCSimRootGeom * fWCSimRootGeom

Detailed Description

Definition at line 8 of file WCSimGeometry.hh.


Member Typedef Documentation


Member Enumeration Documentation

Enumerator:
kDUSEL_Unknown 
kDUSEL_100kton_10inch_12percent 
kDUSEL_100kton_10inch_15percent 
kDUSEL_100kton_10inch_30percent 
kDUSEL_100kton_10inch_40percent 
kDUSEL_200kton_10inch_12percent 
kDUSEL_200kton_12inch_10percent 
kDUSEL_200kton_12inch_14percent 
kDUSEL_150ktonMailbox_10inch_15percent 
kDUSEL_150ktonMailbox_10inch_30percent 
kDUSEL_150ktonMailbox_10inch_40percent 

Definition at line 12 of file WCSimGeometry.hh.

Enumerator:
kTop 
kSide 
kBottom 
kFront 
kBack 
kLeft 
kRight 

Definition at line 32 of file WCSimGeometry.hh.

                          {
   kTop     = 0,
   kSide    = 1,
   kBottom  = 2,
   kFront   = 10,
   kBack    = 12,
   kLeft    = 20,
   kRight   = 22
  } GeoRegion_t;

Enumerator:
kUnknown 
kCylinder 
kMailBox 

Definition at line 26 of file WCSimGeometry.hh.

                        {
   kUnknown  = -1,
   kCylinder = 0,
   kMailBox  = 1
  } GeoType_t; 


Constructor & Destructor Documentation

WCSimGeometry::WCSimGeometry (  )  [private]

Definition at line 136 of file WCSimGeometry.cc.

References SetGeometry().

Referenced by Instance().

                             :
  fPMTs(0),
  fPmtX(0),
  fPmtY(0),
  fPmtZ(0),
  fPmtRegion(0),
  fWCSimRootGeom(0)
{
  this->SetGeometry(0);
}

WCSimGeometry::WCSimGeometry ( WCSimRootGeom *  geom  )  [private]

Definition at line 147 of file WCSimGeometry.cc.

References SetGeometry().

                                                :
  fPMTs(0),
  fPmtX(0),
  fPmtY(0),
  fPmtZ(0),
  fPmtRegion(0),
  fWCSimRootGeom(0)
{
  this->SetGeometry(geom);
}

WCSimGeometry::~WCSimGeometry (  )  [private]

Definition at line 158 of file WCSimGeometry.cc.

References fPmtRegion, fPmtX, fPmtY, and fPmtZ.

{
  if( fPmtX )         delete [] fPmtX;       
  if( fPmtY )         delete [] fPmtY;       
  if( fPmtZ )         delete [] fPmtZ;       
  if( fPmtRegion )    delete [] fPmtRegion;  
}


Member Function Documentation

const char * WCSimGeometry::AsString ( GeoConfiguration_t  config  ) 

Definition at line 106 of file WCSimGeometry.cc.

References kDUSEL_100kton_10inch_12percent, kDUSEL_100kton_10inch_15percent, kDUSEL_100kton_10inch_30percent, kDUSEL_100kton_10inch_40percent, kDUSEL_150ktonMailbox_10inch_15percent, kDUSEL_150ktonMailbox_10inch_30percent, kDUSEL_150ktonMailbox_10inch_40percent, kDUSEL_200kton_10inch_12percent, kDUSEL_200kton_12inch_10percent, kDUSEL_200kton_12inch_14percent, and kDUSEL_Unknown.

{
  switch( config ){
    case WCSimGeometry::kDUSEL_Unknown:
      return "DUSEL_Unknown";
    case WCSimGeometry::kDUSEL_100kton_10inch_12percent:
      return "DUSEL_100kton_10inch_12percent";
    case WCSimGeometry::kDUSEL_100kton_10inch_15percent:
      return "DUSEL_100kton_10inch_15percent";
    case WCSimGeometry::kDUSEL_100kton_10inch_30percent:
      return "DUSEL_100kton_10inch_30percent";
    case WCSimGeometry::kDUSEL_100kton_10inch_40percent:
      return "DUSEL_100kton_10inch_40percent";
    case WCSimGeometry::kDUSEL_200kton_10inch_12percent:
      return "DUSEL_200kton_10inch_12percent";
    case WCSimGeometry::kDUSEL_200kton_12inch_10percent:
      return "DUSEL_200kton_12inch_10percent";
    case WCSimGeometry::kDUSEL_200kton_12inch_14percent:
      return "DUSEL_200kton_12inch_14percent";
    case WCSimGeometry::kDUSEL_150ktonMailbox_10inch_15percent:
      return "DUSEL_150ktonMailbox_10inch_15percent";
    case WCSimGeometry::kDUSEL_150ktonMailbox_10inch_30percent:
      return "DUSEL_150ktonMailbox_10inch_30percent";
    case WCSimGeometry::kDUSEL_150ktonMailbox_10inch_40percent:
      return "DUSEL_150ktonMailbox_10inch_40percent";
    default:
      return "DUSEL_Unknown";
  }
}

Double_t WCSimGeometry::BackwardProjectionToEdge ( Double_t  x,
Double_t  y,
Double_t  z,
Double_t  px,
Double_t  py,
Double_t  pz 
)

Definition at line 757 of file WCSimGeometry.cc.

References kUnknown, and ProjectToNearEdge().

Referenced by InsideDetector(), and WCSimRecoNtuple::WriteVariables().

{
  Double_t xproj = 0.0;
  Double_t yproj = 0.0;
  Double_t zproj = 0.0;
  Int_t regionproj = 0;

  this->ProjectToNearEdge(x,y,z,
                          -px,-py,-pz,
                          xproj,yproj,zproj,
                          regionproj);

  if( regionproj > WCSimGeometry::kUnknown ){
    return sqrt( (xproj-x)*(xproj-x)
               + (yproj-y)*(yproj-y)
               + (zproj-z)*(zproj-z) );
  }

  this->ProjectToNearEdge(x,y,z,
                          px,py,pz,
                          xproj,yproj,zproj,
                          regionproj);

  if( regionproj > WCSimGeometry::kUnknown ){
    return -sqrt( (xproj-x)*(xproj-x)
                + (yproj-y)*(yproj-y)
                + (zproj-z)*(zproj-z) );
  }

  return -99999.9;
}

void WCSimGeometry::BuildGeometry ( WCSimRootGeom *  geom  )  [static]

Definition at line 42 of file WCSimGeometry.cc.

References Instance(), and SetGeometry().

Referenced by WCSimInterface::AddFile(), and WCSimEventWriter::Run().

{
  return WCSimGeometry::Instance()->SetGeometry(geom);
}

Double_t WCSimGeometry::DistanceToEdge ( Double_t  x,
Double_t  y,
Double_t  z 
)

Definition at line 549 of file WCSimGeometry.cc.

References fCylLength, fCylRadius, fGeoType, fMailBoxX, fMailBoxY, fMailBoxZ, InsideDetector(), kCylinder, and kMailBox.

Referenced by WCSimVertexFinderPoint::PenaltyChi2(), and WCSimRecoNtuple::WriteVariables().

{
  // Cylindrical Geometry
  // ====================
  if( fGeoType==WCSimGeometry::kCylinder ){

    // inside detector (convention: +ve dr)
    if( this->InsideDetector(x,y,z) ){
      Double_t dr = 0.0;
      if( fCylRadius>dr ) dr = fCylRadius;
      if( 0.5*fCylLength>dr ) dr = 0.5*fCylLength;
      if( -sqrt(x*x+y*y)+fCylRadius<dr ) dr = -sqrt(x*x+y*y)+fCylRadius;
      if( -z+0.5*fCylLength<dr ) dr = -z+0.5*fCylLength;
      if( +z+0.5*fCylLength<dr ) dr = +z+0.5*fCylLength;
      return dr;
    }

    // outside detector (convention: -ve dr)
    else{

      // side region
      if( z>=-0.5*fCylLength && z<=+0.5*fCylLength ){
        return -sqrt(x*x+y*y)+fCylRadius;
      }

      // top region
      if( z<=-0.5*fCylLength
       && x*x+y*y<fCylRadius*fCylRadius ){
        return +z+0.5*fCylLength;
      }
      if( z>=+0.5*fCylLength
       && x*x+y*y<fCylRadius*fCylRadius ){
        return -z+0.5*fCylLength;
      }

      // corner regions
      if( z>=+0.5*fCylLength
       && x*x+y*y>=fCylRadius ){
        Double_t dr = sqrt(x*x+y*y)-fCylRadius;
        Double_t dz = -z+0.5*fCylLength;
        return -sqrt(dr*dr+dz*dz);
      }
      if( z<=-0.5*fCylLength
       && x*x+y*y>=fCylRadius ){
        Double_t dr = sqrt(x*x+y*y)-fCylRadius;
        Double_t dz = +z+0.5*fCylLength;
        return -sqrt(dr*dr+dz*dz);
      }
    }
  }

  // Mailbox Geometry
  // ================
  if( fGeoType==WCSimGeometry::kMailBox ){

    // inside detector (convention: +ve dr)
    if( this->InsideDetector(x,y,z) ){
      Double_t dr = 0.0;
      if( 0.5*fMailBoxX>dr ) dr = 0.5*fMailBoxX;
      if( 0.5*fMailBoxY>dr ) dr = 0.5*fMailBoxY;
      if( 0.5*fMailBoxZ>dr ) dr = 0.5*fMailBoxZ;
      if( -x+0.5*fMailBoxX<dr ) dr = -x+0.5*fMailBoxX;
      if( +x+0.5*fMailBoxX<dr ) dr = +x+0.5*fMailBoxX;
      if( -y+0.5*fMailBoxY<dr ) dr = -y+0.5*fMailBoxY;
      if( +y+0.5*fMailBoxY<dr ) dr = +y+0.5*fMailBoxY;
      if( -z+0.5*fMailBoxZ<dr ) dr = -z+0.5*fMailBoxZ;
      if( +z+0.5*fMailBoxZ<dr ) dr = +z+0.5*fMailBoxZ;
      return dr;
    }

    // outside detector (convention: -ve dr)
    else{

      // six edge regions
      if( x<=-0.5*fMailBoxX 
       && y>=-0.5*fMailBoxY && y<=+0.5*fMailBoxY 
       && z>=-0.5*fMailBoxZ && z<=+0.5*fMailBoxZ ){
        return +x+0.5*fMailBoxX;
      }
      if( x>=+0.5*fMailBoxX 
       && y>=-0.5*fMailBoxY && y<=+0.5*fMailBoxY  
       && z>=-0.5*fMailBoxZ && z<=+0.5*fMailBoxZ ){
        return -x+0.5*fMailBoxX;
      }
      if( x>=-0.5*fMailBoxX && x<=+0.5*fMailBoxX
       && y<=-0.5*fMailBoxY 
       && z>=-0.5*fMailBoxZ && z<=+0.5*fMailBoxZ ){
        return +y+0.5*fMailBoxY;
      }
      if( x>=-0.5*fMailBoxX && x<=+0.5*fMailBoxX
       && y>=+0.5*fMailBoxY 
       && z>=-0.5*fMailBoxZ && z<=+0.5*fMailBoxZ ){
        return -y+0.5*fMailBoxY;
      }
      if( x>=-0.5*fMailBoxX && x<=+0.5*fMailBoxX 
       && y>=-0.5*fMailBoxY && y<=+0.5*fMailBoxY  
       && z<=-0.5*fMailBoxZ ){
        return +z+0.5*fMailBoxZ;
      }
      if( x>=-0.5*fMailBoxX && x<=+0.5*fMailBoxX 
       && y>=-0.5*fMailBoxY && y<=+0.5*fMailBoxY 
       && z>=+0.5*fMailBoxZ ){
        return -z+0.5*fMailBoxZ;
      }

      // eight corner regions
      if( x<=-0.5*fMailBoxX 
       && y<=-0.5*fMailBoxY 
       && z<=-0.5*fMailBoxZ ){
        Double_t dx = +x+0.5*fMailBoxX;
        Double_t dy = +y+0.5*fMailBoxY;
        Double_t dz = +z+0.5*fMailBoxZ;
        return -sqrt(dx*dx+dy*dy+dz*dz);
      }
      if( x>=+0.5*fMailBoxX 
       && y<=-0.5*fMailBoxY 
       && z<=-0.5*fMailBoxZ ){
        Double_t dx = -x+0.5*fMailBoxX;
        Double_t dy = +y+0.5*fMailBoxY;
        Double_t dz = +z+0.5*fMailBoxZ;
        return -sqrt(dx*dx+dy*dy+dz*dz);
      }
      if( x<=-0.5*fMailBoxX 
       && y>=+0.5*fMailBoxY 
       && z<=-0.5*fMailBoxZ ){
        Double_t dx = +x+0.5*fMailBoxX;
        Double_t dy = -y+0.5*fMailBoxY;
        Double_t dz = +z+0.5*fMailBoxZ;
        return -sqrt(dx*dx+dy*dy+dz*dz);
      }
      if( x<=-0.5*fMailBoxX 
       && y<=-0.5*fMailBoxY 
       && z>=+0.5*fMailBoxZ ){
        Double_t dx = +x+0.5*fMailBoxX;
        Double_t dy = +y+0.5*fMailBoxY;
        Double_t dz = -z+0.5*fMailBoxZ;
        return -sqrt(dx*dx+dy*dy+dz*dz);
      }
      if( x>=+0.5*fMailBoxX 
       && y>=+0.5*fMailBoxY 
       && z<=-0.5*fMailBoxZ ){
        Double_t dx = -x+0.5*fMailBoxX;
        Double_t dy = -y+0.5*fMailBoxY;
        Double_t dz = +z+0.5*fMailBoxZ;
        return -sqrt(dx*dx+dy*dy+dz*dz);
      }
      if( x>=+0.5*fMailBoxX 
       && y<=-0.5*fMailBoxY 
       && z>=+0.5*fMailBoxZ ){
        Double_t dx = -x+0.5*fMailBoxX;
        Double_t dy = +y+0.5*fMailBoxY;
        Double_t dz = -z+0.5*fMailBoxZ;
        return -sqrt(dx*dx+dy*dy+dz*dz);
      }
      if( x<=-0.5*fMailBoxX 
       && y>=+0.5*fMailBoxY 
       && z>=+0.5*fMailBoxZ ){
        Double_t dx = +x+0.5*fMailBoxX;
        Double_t dy = -y+0.5*fMailBoxY;
        Double_t dz = -z+0.5*fMailBoxZ;
        return -sqrt(dx*dx+dy*dy+dz*dz);
      }
      if( x>=+0.5*fMailBoxX 
       && y>=+0.5*fMailBoxY 
       && z>=+0.5*fMailBoxZ ){
        Double_t dx = -x+0.5*fMailBoxX;
        Double_t dy = -y+0.5*fMailBoxY;
        Double_t dz = -z+0.5*fMailBoxZ;
        return -sqrt(dx*dx+dy*dy+dz*dz);
      }
    }
  }

  return -99999.9;
}

void WCSimGeometry::DistanceToIntersectLine ( Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  vx,
Double_t  vy,
Double_t  vz,
Double_t  ex,
Double_t  ey,
Double_t  ez,
Double_t &  x,
Double_t &  y,
Double_t &  z,
Double_t &  L 
) [static]

Definition at line 2321 of file WCSimGeometry.cc.

References WCSimParameters::CherenkovAngle().

Referenced by DistanceToIntersectLine().

{
  Double_t dx = 0.0;
  Double_t dy = 0.0;
  Double_t dz = 0.0;
  Double_t ds = 0.0;
  
  Double_t px = 0.0;
  Double_t py = 0.0;
  Double_t pz = 0.0;
  Double_t dsTrack = 0.0;

  Double_t qx = 0.0;
  Double_t qy = 0.0;
  Double_t qz = 0.0;
  Double_t dsPmt = 0.0;

  // vector from vertex to end
  dx = ex - vx;
  dy = ey - vy;
  dz = ez - vz;
  ds = sqrt( dx*dx+dy*dy+dz*dz );

  if( ds>0.0 ){
    px = dx/ds;
    py = dy/ds;
    pz = dz/ds;
    dsTrack = ds;
  }

  // vector from vertex to pmt
  dx = x0 - vx;
  dy = y0 - vy;
  dz = z0 - vz;
  ds = sqrt( dx*dx+dy*dy+dz*dz );

  if( ds>0.0 ){
    qx = dx/ds;
    qy = dy/ds;
    qz = dz/ds;
    dsPmt = ds;
  }
     
  // Cherenkov geometry
  // ==================
  Double_t cosphi = px*qx+py*qy+pz*qz;
  Double_t phi = acos(cosphi); 
  Double_t theta = WCSimParameters::CherenkovAngle()*TMath::Pi()/180.0;    

  Double_t Ltrack = 0.0;
  Double_t Lphoton = 0.0;
    
  if( phi<theta ){
    Ltrack  = +dsPmt*sin(theta-phi)/sin(theta);
    Lphoton = +dsPmt*sin(phi)/sin(theta);
  }
  else{
    Ltrack  = -dsPmt*sin(phi-theta)/sin(phi);
    Lphoton = -dsPmt*sin(phi)/sin(theta);
  }
 
  // return intersection
  // ===================
  x = vx + px*Ltrack;
  y = vy + py*Ltrack;
  z = vz + pz*Ltrack;
  L = Lphoton;

  return;
}

Double_t WCSimGeometry::DistanceToIntersectLine ( Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  sx,
Double_t  sy,
Double_t  sz,
Double_t  ex,
Double_t  ey,
Double_t  ez,
Double_t &  x,
Double_t &  y,
Double_t &  z 
) [static]

Definition at line 2393 of file WCSimGeometry.cc.

References DistanceToIntersectLine().

{
  Double_t L = -1.0;

  WCSimGeometry::DistanceToIntersectLine(x0,y0,z0,
                                         sx,sy,sz,
                                         ex,ey,ez,
                                         x,y,z,L);
  return L;
}

Double_t WCSimGeometry::DistanceToIntersectLine ( Double_t *  pos,
Double_t *  start,
Double_t *  end,
Double_t *  intersection 
) [static]

Definition at line 2404 of file WCSimGeometry.cc.

References DistanceToIntersectLine().

{
  Double_t x = -999.9;
  Double_t y = -999.9;
  Double_t z = -999.9; 
  Double_t L = -1.0;

  WCSimGeometry::DistanceToIntersectLine(pos[0],   pos[1],   pos[2],
                                         start[0], start[1], start[2],
                                         end[0],   end[1],   end[2],
                                         x,y,z,L);

  intersection[0]=x; intersection[1]=y; intersection[2]=z;  
  
  return L;
}

void WCSimGeometry::FindCircle ( Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  x1,
Double_t  y1,
Double_t  z1,
Double_t  x2,
Double_t  y2,
Double_t  z2,
Double_t &  rx,
Double_t &  ry,
Double_t &  rz,
Double_t &  nx,
Double_t &  ny,
Double_t &  nz,
Double_t &  r 
) [static]

Definition at line 1917 of file WCSimGeometry.cc.

Referenced by WCSimDisplayAB::DrawRing(), WCSimRingFinder::HoughTransform(), and WCSimRingFinder::HoughTransformArray().

{
  Double_t centre[3] = {0.0,0.0,0.0};
  Double_t normal[3] = {0.0,0.0,0.0};
  Double_t radius = 0.0;

  Double_t p01[3] = {x0-x1, y0-y1, z0-z1};
  Double_t p12[3] = {x1-x2, y1-y2, z1-z2};
  Double_t p20[3] = {x2-x0, y2-y0, z2-z0};

  Double_t n[3] = {p01[1]*p12[2]-p01[2]*p12[1],
                   p01[2]*p12[0]-p01[0]*p12[2],
                   p01[0]*p12[1]-p01[1]*p12[0]};

  Double_t D2 = n[0]*n[0]+n[1]*n[1]+n[2]*n[2];

  if( D2>0.0 ){
    Double_t a0 = -(p12[0]*p12[0]+p12[1]*p12[1]+p12[2]*p12[2])*(p01[0]*p20[0]+p01[1]*p20[1]+p01[2]*p20[2])/(2.0*D2);
    Double_t a1 = -(p20[0]*p20[0]+p20[1]*p20[1]+p20[2]*p20[2])*(p12[0]*p01[0]+p12[1]*p01[1]+p12[2]*p01[2])/(2.0*D2);
    Double_t a2 = -(p01[0]*p01[0]+p01[1]*p01[1]+p01[2]*p01[2])*(p20[0]*p12[0]+p20[1]*p12[1]+p20[2]*p12[2])/(2.0*D2);
    Double_t D = sqrt(D2);

    centre[0] = a0*x0 + a1*x1 + a2*x2;
    centre[1] = a0*y0 + a1*y1 + a2*y2;
    centre[2] = a0*z0 + a1*z1 + a2*z2;

    radius = sqrt( (p01[0]*p01[0]+p01[1]*p01[1]+p01[2]*p01[2])
                  *(p12[0]*p12[0]+p12[1]*p12[1]+p12[2]*p12[2])
                  *(p20[0]*p20[0]+p20[1]*p20[1]+p20[2]*p20[2]))/(2.0*D);

    if( n[0]*centre[0]
      + n[1]*centre[1]
      + n[2]*centre[2]>0.0 ){
      normal[0] = +n[0]/D;
      normal[1] = +n[1]/D;
      normal[2] = +n[2]/D;
    }
    else{
      normal[0] = -n[0]/D;
      normal[1] = -n[1]/D;
      normal[2] = -n[2]/D;
    }
  }

  rx = centre[0];
  ry = centre[1];
  rz = centre[2];

  nx = normal[0];
  ny = normal[1];
  nz = normal[2];

  r = radius;

  return;
}

void WCSimGeometry::FindCircle ( Double_t  xp,
Double_t  yp,
Double_t  zp,
Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  angle_degrees,
Double_t  omega_degrees,
Double_t &  rx,
Double_t &  ry,
Double_t &  rz,
Double_t &  nx,
Double_t &  ny,
Double_t &  nz,
Double_t &  r 
) [static]

Definition at line 2106 of file WCSimGeometry.cc.

{
  // default
  // =======
  rx = xp;
  ry = yp;
  rz = zp;
  
  nx = 0.0;
  ny = 0.0;
  nz = 0.0;

  r = 0.0;

  // inputs
  // ======
  Double_t angle = (TMath::Pi()/180.0)*angle_degrees; // radians
  Double_t omega = (TMath::Pi()/180.0)*omega_degrees; // radians

  Double_t dx = xp-x0;
  Double_t dy = yp-y0;
  Double_t dz = zp-z0;
  Double_t ds = sqrt(dx*dx+dy*dy+dz*dz);

  Double_t px = 0.0;
  Double_t py = 0.0;
  Double_t pz = 0.0;

  if( ds>0.0 ){
    px = dx/ds;
    py = dy/ds;
    pz = dz/ds;
  }
  else{
    return;
  }

  // do the rotations
  // ================
  TVector3 myVtx(x0,y0,z0);
  TVector3 myDir(px,py,pz);

  TVector3 initDir = myDir;
  TVector3 orthDir = myDir.Orthogonal();
  myDir.Rotate(angle,orthDir);
  myDir.Rotate(omega,initDir);
 
  // outputs
  // =======
  rx = x0 + ds*myDir.x();
  ry = y0 + ds*myDir.y();
  rz = z0 + ds*myDir.z();
  
  nx = myDir.x();
  ny = myDir.y();
  nz = myDir.z();

  r = ds*sin(angle);

  return;
}

void WCSimGeometry::FindCircleOld ( Double_t  xp,
Double_t  yp,
Double_t  zp,
Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  angle_degrees,
Double_t  omega_degrees,
Double_t &  rx,
Double_t &  ry,
Double_t &  rz,
Double_t &  nx,
Double_t &  ny,
Double_t &  nz,
Double_t &  r 
) [static]

Definition at line 1974 of file WCSimGeometry.cc.

{
  // inputs
  // ======
  Double_t phi = 0.0;
  Double_t theta = 0.0;
  Double_t angle = (TMath::Pi()/180.0)*angle_degrees;
  Double_t omega = (TMath::Pi()/180.0)*omega_degrees;

  Double_t x = xp;
  Double_t y = yp;
  Double_t z = zp;

  Double_t xtemp = 0.0;
  Double_t ytemp = 0.0;
  Double_t ztemp = 0.0;

  Double_t dx = 0.0;
  Double_t dy = 0.0;
  Double_t dz = 0.0;
  Double_t ds = 0.0;

  Double_t radius = 0.0;

  // subtract vertex
  // ===============
  x -= x0;
  y -= y0;
  z -= z0;

  // forward rotation (x,y,z)->(x,0,z)
  // =================================
  phi = 0.0;

  if( x!=0.0 ){
    phi = atan(y/x);
  }
  if( x<=0.0 ){
    if( y>0.0 ) phi += TMath::Pi();
    if( y<0.0 ) phi -= TMath::Pi();
  }

  xtemp = x;
  ytemp = y;
  ztemp = z;  

  x = + xtemp*cos(phi) + ytemp*sin(phi);
  y = - xtemp*sin(phi) + ytemp*cos(phi);
  z = + ztemp;

  // forward rotation (x,0,z)->(0,0,z)
  // =================================
  theta = 0.0;

  if( z!=0.0 ){
    theta = atan(x/z);
  }
  if( z<=0.0 ){
    if( x>0.0 ) theta += TMath::Pi();
    if( x<0.0 ) theta -= TMath::Pi();
  }

  xtemp = x;
  ytemp = y;
  ztemp = z;  
 
  x = + xtemp*cos(theta) - ztemp*sin(theta);
  y = + ytemp;
  z = + xtemp*sin(theta) + ztemp*cos(theta);

  // apply rotation: cone angle + azimuthal angle
  // ============================================  
  xtemp = x;
  ytemp = y;
  ztemp = z;  

  x = ztemp*sin(angle)*cos(omega);
  y = ztemp*sin(angle)*sin(omega);
  z = ztemp*cos(angle);

  radius = ztemp*sin(angle);

  // backward rotation (0,0,z)->(x,0,z)
  // ==================================
  xtemp = x;
  ytemp = y;
  ztemp = z;  
 
  x = + xtemp*cos(-theta) - ztemp*sin(-theta);
  y = + ytemp;
  z = + xtemp*sin(-theta) + ztemp*cos(-theta);

  // backward rotation (x,0,z)->(x,y,z)
  // =================================
  xtemp = x;
  ytemp = y;
  ztemp = z;  

  x = + xtemp*cos(-phi) + ytemp*sin(-phi);
  y = - xtemp*sin(-phi) + ytemp*cos(-phi);
  z = + ztemp;

  // add on vertex
  // =============
  x += x0;
  y += y0;
  z += z0;

  // return coordinates
  // ==================
  rx = x;
  ry = y;
  rz = z;

  // return normal 
  // =============
  dx = rx - x0;
  dy = ry - y0;
  dz = rz - z0;
  ds = sqrt(dx*dx+dy*dy+dz*dz);

  nx = dx/ds;
  ny = dy/ds;
  nz = dz/ds;

  // return radius
  // =============
  r = radius;

  return;
}

void WCSimGeometry::FindVertex ( Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  t0,
Double_t  x1,
Double_t  y1,
Double_t  z1,
Double_t  t1,
Double_t  x2,
Double_t  y2,
Double_t  z2,
Double_t  t2,
Double_t  x3,
Double_t  y3,
Double_t  z3,
Double_t  t3,
Double_t &  vxm,
Double_t &  vym,
Double_t &  vzm,
Double_t &  vtm,
Double_t &  vxp,
Double_t &  vyp,
Double_t &  vzp,
Double_t &  vtp 
) [static]

Definition at line 2168 of file WCSimGeometry.cc.

Referenced by WCSimVertexGeometry::CalcVertexSeeds().

{
  // switch off error messages
  // =========================
  // suppress messages like: 
  //  Error in <TDecompLU::DecomposeLUCrout>: matrix is singular
  Int_t myIgnoreLevel = gErrorIgnoreLevel;
  gErrorIgnoreLevel = kFatal;
  
  // default vertex
  // ==============
  vxm = -99999.9; 
  vym = -99999.9;
  vzm = -99999.9;
  vtm = -99999.9;

  vxp = -99999.9; 
  vyp = -99999.9;
  vzp = -99999.9;
  vtp = -99999.9;  

  // speed of light in water
  // =======================
  Double_t c = 29.98/1.33; // cm/ns [water]

  // causality checks
  // ================
  if( (x1-x0)*(x1-x0) + (y1-y0)*(y1-y0) + (z1-z0)*(z1-z0) >= c*c*(t1-t0)*(t1-t0)
   && (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) >= c*c*(t2-t1)*(t2-t1)
   && (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2) + (z3-z2)*(z3-z2) >= c*c*(t3-t2)*(t3-t2)
   && (x2-x0)*(x2-x0) + (y2-y0)*(y2-y0) + (z2-z0)*(z2-z0) >= c*c*(t2-t0)*(t2-t0)
   && (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1) + (z3-z1)*(z3-z1) >= c*c*(t3-t1)*(t3-t1)
   && (x3-x0)*(x3-x0) + (y3-y0)*(y3-y0) + (z3-z0)*(z3-z0) >= c*c*(t3-t0)*(t3-t0) ){

    // [Note: for causality, require that |x_{i}-x_{j}| >= c*|t_{i}-t_{j}|
    //        for each pair of points]

    Double_t dx1 = x1-x0;  Double_t dy1 = y1-y0;  Double_t dz1 = z1-z0;  Double_t dt1 = c*(t1-t0);
    Double_t dx2 = x2-x0;  Double_t dy2 = y2-y0;  Double_t dz2 = z2-z0;  Double_t dt2 = c*(t2-t0);
    Double_t dx3 = x3-x0;  Double_t dy3 = y3-y0;  Double_t dz3 = z3-z0;  Double_t dt3 = c*(t3-t0);

    Double_t epsilon = 1.0e-7;

    // check that points don't all lie in a plane
    if( !( fabs(dx1)<epsilon && fabs(dx2)<epsilon && fabs(dx3)<epsilon )
     && !( fabs(dy1)<epsilon && fabs(dy2)<epsilon && fabs(dy3)<epsilon )
     && !( fabs(dz1)<epsilon && fabs(dz2)<epsilon && fabs(dz3)<epsilon ) 
     && !( fabs(dx1)<epsilon && fabs(dy1)<epsilon && fabs(dz1)<epsilon )
     && !( fabs(dx2)<epsilon && fabs(dy2)<epsilon && fabs(dz2)<epsilon )
     && !( fabs(dx3)<epsilon && fabs(dy3)<epsilon && fabs(dz3)<epsilon ) ){

      // [Note: this is a problem for detectors with flat faces!]

      Double_t Mdata[9] = { dx1, dy1, dz1,
                            dx2, dy2, dz2,
                            dx3, dy3, dz3 };

      Double_t Qdata[3] = { 0.5*( dx1*dx1 + dy1*dy1 + dz1*dz1 - dt1*dt1 ),
                            0.5*( dx2*dx2 + dy2*dy2 + dz2*dz2 - dt2*dt2 ),
                            0.5*( dx3*dx3 + dy3*dy3 + dz3*dz3 - dt3*dt3 ) };
                      
      Double_t Tdata[3] = { dt1,
                            dt2,
                            dt3 };
     
      TMatrixD M(3,3,Mdata);
      TMatrixD Q(3,1,Qdata);
      TMatrixD T(3,1,Tdata);

      if( M.Determinant() != 0.0 ){

        TMatrixD A(3,1);
        TMatrixD B(3,1);

        M.Invert();
        A.Mult(M,T);
        B.Mult(M,Q);
    
        Double_t ax = A(0,0);
        Double_t ay = A(1,0);
        Double_t az = A(2,0);

        Double_t bx = B(0,0);
        Double_t by = B(1,0);
        Double_t bz = B(2,0);

        Double_t ab = ax*bx + ay*by + az*bz;
        Double_t a2 = ax*ax + ay*ay + az*az;
        Double_t b2 = bx*bx + by*by + bz*bz;

        Double_t qa = a2-1.0;
        Double_t qb = 2.0*ab;
        Double_t qc = b2;

        // check for solutions
        if( qb*qb-4.0*qa*qc>0.0 ){

          // The common vertex is given by a quadratic equation, which has two solutions.
          // Typically, one solution corresponds to photons travelling forwards in time,
          // and the other solution corresponds to photons travelling backwards in time.
          // However, sometimes there appear to be two valid solutions.

          Double_t ctm = ( -qb - sqrt(qb*qb-4.0*qa*qc) ) / ( 2.0*qa );
          Double_t ctp = ( -qb + sqrt(qb*qb-4.0*qa*qc) ) / ( 2.0*qa );

          Double_t tm = t0 + ctm/c;
          Double_t xm = x0 + ctm*ax + bx;
          Double_t ym = y0 + ctm*ay + by;
          Double_t zm = z0 + ctm*az + bz;
          Bool_t foundVertexM = 0;

          if( tm<t0 && tm<t1 
           && tm<t2 && tm<t3 ){
            vxm = xm;
            vym = ym;
            vzm = zm;
            vtm = tm;
            foundVertexM = 1;
          }

          Double_t tp = t0 + ctp/c;
          Double_t xp = x0 + ctp*ax + bx;
          Double_t yp = y0 + ctp*ay + by;
          Double_t zp = z0 + ctp*az + bz;
          Bool_t foundVertexP = 0;

          if( tp<t0 && tp<t1 
           && tp<t2 && tp<t3 ){
            vxp = xp;
            vyp = yp;
            vzp = zp;
            vtp = tp;
            foundVertexP = 1;
          }

          // std::cout << "  Vertex: [a=" << qa << ",b=" << qb << ",c=" << qc << "] [ctm=" << ctm << ",ctp=" << ctp << "] " << std::endl
          //           << "   Low T:  (x,y,z,t)=(" << xm << "," << ym << "," << zm << "," << tm << ") [foundVtx=" << foundVertexM << "] " << std::endl
          //           << "   High T: (x,y,z,t)=(" << xp << "," << yp << "," << zp << "," << tp << ") [foundVtx=" << foundVertexP << "] " << std::endl;
          
        }
      }
    }
  }

  // switch on error messages
  // ========================
  gErrorIgnoreLevel = myIgnoreLevel;

  return;
}

Double_t WCSimGeometry::ForwardProjectionToEdge ( Double_t  x,
Double_t  y,
Double_t  z,
Double_t  px,
Double_t  py,
Double_t  pz 
)

Definition at line 725 of file WCSimGeometry.cc.

References kUnknown, and ProjectToNearEdge().

Referenced by InsideDetector(), and WCSimRecoNtuple::WriteVariables().

{
  Double_t xproj = 0.0;
  Double_t yproj = 0.0;
  Double_t zproj = 0.0;
  Int_t regionproj = 0;

  this->ProjectToNearEdge(x,y,z,
                          px,py,pz,
                          xproj,yproj,zproj,
                          regionproj);

  if( regionproj > WCSimGeometry::kUnknown ){
    return sqrt( (xproj-x)*(xproj-x)
               + (yproj-y)*(yproj-y)
               + (zproj-z)*(zproj-z) );
  }

  this->ProjectToNearEdge(x,y,z,
                          -px,-py,-pz,
                          xproj,yproj,zproj,
                          regionproj);

  if( regionproj > WCSimGeometry::kUnknown ){
    return -sqrt( (xproj-x)*(xproj-x)
                + (yproj-y)*(yproj-y)
                + (zproj-z)*(zproj-z) );
  }

  return -99999.9;
}

Double_t WCSimGeometry::GetArea (  )  [inline]

Definition at line 80 of file WCSimGeometry.hh.

References fDetectorArea.

{ return fDetectorArea; }

Double_t WCSimGeometry::GetCylFiducialLength (  )  [inline]

Definition at line 70 of file WCSimGeometry.hh.

References fCylFiducialLength.

{ return fCylFiducialLength; }

Double_t WCSimGeometry::GetCylFiducialRadius (  )  [inline]

Definition at line 69 of file WCSimGeometry.hh.

References fCylFiducialRadius.

{ return fCylFiducialRadius; }

Double_t WCSimGeometry::GetCylLength (  )  [inline]

Definition at line 68 of file WCSimGeometry.hh.

References fCylLength.

Referenced by WCSimEveDisplay::BuildGeometry(), and WCSimDisplayAB::BuildGeometry().

{ return fCylLength; }

Double_t WCSimGeometry::GetCylRadius (  )  [inline]

Definition at line 67 of file WCSimGeometry.hh.

References fCylRadius.

Referenced by WCSimEveDisplay::BuildGeometry(), and WCSimDisplayAB::BuildGeometry().

{ return fCylRadius; }

Double_t WCSimGeometry::GetFiducialVolume (  )  [inline]

Definition at line 82 of file WCSimGeometry.hh.

References fDetectorFiducialVolume.

Int_t WCSimGeometry::GetGeoConfig (  )  [inline]

Definition at line 60 of file WCSimGeometry.hh.

References fGeoConfig.

{ return fGeoConfig; }

Int_t WCSimGeometry::GetGeoType (  )  [inline]

Definition at line 64 of file WCSimGeometry.hh.

References fGeoType.

Referenced by WCSimDisplayAB::BuildGeometry().

{ return fGeoType; }

Double_t WCSimGeometry::GetMailBoxFiducialX (  )  [inline]

Definition at line 76 of file WCSimGeometry.hh.

References fMailBoxFiducialX.

{ return fMailBoxFiducialX; }

Double_t WCSimGeometry::GetMailBoxFiducialY (  )  [inline]

Definition at line 77 of file WCSimGeometry.hh.

References fMailBoxFiducialY.

{ return fMailBoxFiducialY; }

Double_t WCSimGeometry::GetMailBoxFiducialZ (  )  [inline]

Definition at line 78 of file WCSimGeometry.hh.

References fMailBoxFiducialZ.

{ return fMailBoxFiducialZ; }

Double_t WCSimGeometry::GetMailBoxX (  )  [inline]

Definition at line 73 of file WCSimGeometry.hh.

References fMailBoxX.

Referenced by WCSimEveDisplay::BuildGeometry(), and WCSimDisplayAB::BuildGeometry().

{ return fMailBoxX; }

Double_t WCSimGeometry::GetMailBoxY (  )  [inline]

Definition at line 74 of file WCSimGeometry.hh.

References fMailBoxY.

Referenced by WCSimEveDisplay::BuildGeometry(), and WCSimDisplayAB::BuildGeometry().

{ return fMailBoxY; }

Double_t WCSimGeometry::GetMailBoxZ (  )  [inline]

Definition at line 75 of file WCSimGeometry.hh.

References fMailBoxZ.

Referenced by WCSimEveDisplay::BuildGeometry(), and WCSimDisplayAB::BuildGeometry().

{ return fMailBoxZ; }

Int_t WCSimGeometry::GetNumPMTs (  )  [inline]

Definition at line 87 of file WCSimGeometry.hh.

References fPMTs.

Referenced by Reset().

{ return fPMTs; }

Double_t WCSimGeometry::GetPMTCoverage (  )  [inline]

Definition at line 89 of file WCSimGeometry.hh.

References fPMTCoverage.

{ return fPMTCoverage; }

Double_t WCSimGeometry::GetPMTRadius (  )  [inline]

Definition at line 88 of file WCSimGeometry.hh.

References fPMTRadius.

{ return fPMTRadius; }

Double_t WCSimGeometry::GetPMTSeparation (  )  [inline]

Definition at line 90 of file WCSimGeometry.hh.

References fPMTSeparation.

{ return fPMTSeparation; }

Int_t WCSimGeometry::GetRegion ( Int_t  tube  ) 

Definition at line 166 of file WCSimGeometry.cc.

References fPmtRegion, and fPMTs.

Referenced by WCSimEventWriter::Run().

{
  if( tube>=0 && tube<fPMTs ){
    return fPmtRegion[tube];
  }

  return -1;
}

Double_t WCSimGeometry::GetVolume (  )  [inline]

Definition at line 81 of file WCSimGeometry.hh.

References fDetectorVolume.

{ return fDetectorVolume; }

WCSimRootGeom* WCSimGeometry::GetWCSimGeometry (  )  [inline]

Definition at line 56 of file WCSimGeometry.hh.

References fWCSimRootGeom.

{ return fWCSimRootGeom; }

Double_t WCSimGeometry::GetX ( Int_t  tube  ) 

Definition at line 175 of file WCSimGeometry.cc.

References fPMTs, and fPmtX.

Referenced by WCSimEventWriter::Run().

{
  if( tube>=0 && tube<fPMTs ){
    return fPmtX[tube];
  }

  return -99999.9;
}

Double_t WCSimGeometry::GetY ( Int_t  tube  ) 

Definition at line 184 of file WCSimGeometry.cc.

References fPMTs, and fPmtY.

Referenced by WCSimEventWriter::Run().

{
  if( tube>=0 && tube<fPMTs ){
    return fPmtY[tube];
  } 

  return -99999.9;
}

Double_t WCSimGeometry::GetZ ( Int_t  tube  ) 

Definition at line 193 of file WCSimGeometry.cc.

References fPMTs, and fPmtZ.

Referenced by WCSimEventWriter::Run().

{
  if( tube>=0 && tube<fPMTs ){
    return fPmtZ[tube];
  } 

  return -99999.9;
}

Bool_t WCSimGeometry::InsideDetector ( Double_t  vx,
Double_t  vy,
Double_t  vz,
Double_t  ex,
Double_t  ey,
Double_t  ez 
)

Definition at line 529 of file WCSimGeometry.cc.

References BackwardProjectionToEdge(), and ForwardProjectionToEdge().

{
  Double_t dx = ex-vx;
  Double_t dy = ey-vy;
  Double_t dz = ez-vz;
  Double_t ds = sqrt(dx*dx+dy*dy+dz*dz);

  Double_t px = dx/ds;
  Double_t py = dy/ds;
  Double_t pz = dz/ds;

  if( this->ForwardProjectionToEdge(vx,vy,vz,px,py,pz) >= 0.0
   && this->BackwardProjectionToEdge(ex,ey,ez,px,py,pz) >= 0.0 ){
    return 1;
  }
  else{
    return 0;
  }
}

Bool_t WCSimGeometry::InsideDetector ( Double_t  x,
Double_t  y,
Double_t  z 
)

Definition at line 491 of file WCSimGeometry.cc.

References fCylLength, fCylRadius, fGeoType, fMailBoxX, fMailBoxY, fMailBoxZ, kCylinder, and kMailBox.

Referenced by DistanceToEdge(), and WCSimVertexFinderPoint::PenaltyChi2().

{
  if( fGeoType==WCSimGeometry::kCylinder ){
    if( z>=-0.5*fCylLength && z<=+0.5*fCylLength
     && x*x+y*y<=fCylRadius*fCylRadius ){
      return 1;
    }
  }
  if( fGeoType==WCSimGeometry::kMailBox ){
    if( x>=-0.5*fMailBoxX && x<=+0.5*fMailBoxX
     && y>=-0.5*fMailBoxY && y<=+0.5*fMailBoxY
     && z>=-0.5*fMailBoxZ && z<=+0.5*fMailBoxZ ){
      return 1;
    }
  }

  return 0;
}

Bool_t WCSimGeometry::InsideFiducialVolume ( Double_t  x,
Double_t  y,
Double_t  z 
)
WCSimGeometry * WCSimGeometry::Instance (  )  [static]
Bool_t WCSimGeometry::IsCylinder (  )  [inline]

Definition at line 66 of file WCSimGeometry.hh.

References fCylinder.

{ return fCylinder; }

Bool_t WCSimGeometry::IsMailBox (  )  [inline]

Definition at line 72 of file WCSimGeometry.hh.

References fMailBox.

{ return fMailBox; }

void WCSimGeometry::PrintGeometry (  )  [static]

Definition at line 52 of file WCSimGeometry.cc.

References TouchGeometry().

Referenced by SetGeometry().

{
  std::cout << " *** WCSimGeometry::PrintGeometry() *** " << std::endl;

  if( WCSimGeometry::TouchGeometry() ){

    // geometry type
    if( fgGeometryHandle->GetGeoType()==WCSimGeometry::kCylinder ){
      std::cout << "  Detector Geometry: CYLINDER " << std::endl
                << "   radius[m]=" <<  1.0e-2*fgGeometryHandle->GetCylRadius() << std::endl
                << "   length[m]=" << 1.0e-2*fgGeometryHandle->GetCylLength() << std::endl              
                << "   fiducial_radius[m]=" <<  1.0e-2*fgGeometryHandle->GetCylFiducialRadius() << std::endl
                << "   fiducial_length[m]=" << 1.0e-2*fgGeometryHandle->GetCylFiducialLength() << std::endl;
      std::cout << "   area[m^2]=" << 1.0e-4*fgGeometryHandle->GetArea() << std::endl
                << "   volume[m^3]=" << 1.0e-6*fgGeometryHandle->GetVolume() << std::endl
                << "   fiducial_volume[m^3]=" << 1.0e-6*fgGeometryHandle->GetFiducialVolume() << std::endl;
    }
    if( fgGeometryHandle->GetGeoType()==WCSimGeometry::kMailBox ){
      std::cout << "  Detector Geometry: MAILBOX " << std::endl
                << "   dx[m]=" << 1.0e-2*fgGeometryHandle->GetMailBoxX() << std::endl
                << "   dy[m]=" << 1.0e-2*fgGeometryHandle->GetMailBoxY() << std::endl
                << "   dz[m]=" << 1.0e-2*fgGeometryHandle->GetMailBoxZ() << std::endl
                << "   fiducial_dx[m]=" << 1.0e-2*fgGeometryHandle->GetMailBoxFiducialX() << std::endl
                << "   fiducial_dy[m]=" << 1.0e-2*fgGeometryHandle->GetMailBoxFiducialY() << std::endl
                << "   fiducial_dz[m]=" << 1.0e-2*fgGeometryHandle->GetMailBoxFiducialZ() << std::endl;
      std::cout << "   area[m^2]=" << 1.0e-4*fgGeometryHandle->GetArea() << std::endl
                << "   volume[m^3]=" << 1.0e-6*fgGeometryHandle->GetVolume() << std::endl
                << "   fiducial_volume[m^3]=" << 1.0e-6*fgGeometryHandle->GetFiducialVolume() << std::endl;
    }
    if( fgGeometryHandle->GetGeoType()==WCSimGeometry::kUnknown ){
      std::cout << "  Detector Geometry: UNKNOWN " << std::endl;
      std::cout << "   <warning> geometry unknown! " << std::endl;
    }  

    // Dteector PMTs
    std::cout << "  Detector PMTs: " << std::endl;
    std::cout << "   number=" << fgGeometryHandle->GetNumPMTs() << std::endl;
    std::cout << "   radius[cm]=" << fgGeometryHandle->GetPMTRadius() << std::endl;
    std::cout << "   separation[cm]=" << fgGeometryHandle->GetPMTSeparation() << std::endl;
    std::cout << "   coverage=" << fgGeometryHandle->GetPMTCoverage() << std::endl;

    // attempt to figure out configuration...
    std::cout << "  Detector Configuration: " << std::endl; 
    GeoConfiguration_t config = (GeoConfiguration_t)(fgGeometryHandle->GetGeoConfig());
    std::cout << "   " << fgGeometryHandle->AsString(config) << std::endl;
  }
  
  else {
    std::cout << " <warning> no geometry loaded " << std::endl;
  }

  return;
}

void WCSimGeometry::ProjectToEdge ( Bool_t  useFarEdge,
Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  px,
Double_t  py,
Double_t  pz,
Double_t &  x,
Double_t &  y,
Double_t &  z,
Int_t &  region 
)

Definition at line 1454 of file WCSimGeometry.cc.

References fCylLength, fCylRadius, fGeoType, fMailBoxX, fMailBoxY, fMailBoxZ, kCylinder, and kMailBox.

Referenced by ProjectToFarEdge(), and ProjectToNearEdge().

{
  // default locations
  // =================
  xproj = -99999.9;
  yproj = -99999.9;
  zproj = -99999.9;
  regionproj = WCSimGeometry::kUnknown;

  Double_t xNear = -99999.9;
  Double_t yNear = -99999.9;
  Double_t zNear = -99999.9;
  Int_t regionNear = WCSimGeometry::kUnknown;

  Double_t xFar = -99999.9;
  Double_t yFar = -99999.9;
  Double_t zFar = -99999.9;
  Int_t regionFar = WCSimGeometry::kUnknown;


  // CYLINDRICAL GEOMETRY
  // ====================
  if( fGeoType==WCSimGeometry::kCylinder ){  

    Double_t r = fCylRadius;
    Double_t L = fCylLength;

    Bool_t foundProjectionXY = 0;
    Bool_t foundProjectionZ = 0;

    Double_t t1 = 0.0;
    Double_t x1 = 0.0;
    Double_t y1 = 0.0;
    Double_t z1 = 0.0;
    Int_t region1 = -1;

    Double_t t2 = 0.0;  
    Double_t x2 = 0.0;
    Double_t y2 = 0.0;
    Double_t z2 = 0.0;
    Int_t region2 = -1;

    Double_t rSq = r*r;
    Double_t r0r0 = x0*x0 + y0*y0;
    Double_t r0p = x0*px + y0*py;
    Double_t pSq = px*px+py*py;
    
    // calculate intersection in XY
    if( pSq>0.0 ){
      if( r0p*r0p - pSq*(r0r0-rSq)>0.0 ){
        t1 = ( -r0p - sqrt(r0p*r0p-pSq*(r0r0-rSq)) ) / pSq;
        t2 = ( -r0p + sqrt(r0p*r0p-pSq*(r0r0-rSq)) ) / pSq;
        foundProjectionXY = 1;
      }
    }

    // propagation along z-axis
    else if( r0r0<=rSq ){

      if( pz>0 ){
        t1 = -L/2.0 - z0;
        t2 = +L/2.0 - z0;
      }
      else{
        t1 = -L/2.0 + z0;
        t2 = +L/2.0 + z0;
      }
      foundProjectionXY = 1;
    }
    
    // found intersection in XY
    if( foundProjectionXY ){

      z1 = z0 + t1*pz;
      z2 = z0 + t2*pz;

      if( ( z1>=-L/2.0 && z2<=+L/2.0 )
       || ( z2>=-L/2.0 && z1<=+L/2.0 ) ){
        foundProjectionZ = 1;
      }
    }

    // found intersection in Z
    if( foundProjectionZ ){

      // first intersection
      if( z1>-L/2.0 && z1<+L/2.0 ){
        region1 = WCSimGeometry::kSide;
      }
      if( z1>=+L/2.0 ){
        region1 = WCSimGeometry::kTop;
        if( z1>+L/2.0 ){
          z1 = +L/2.0; 
          t1 = (+L/2.0-z0)/pz;
        }
      }
      if( z1<=-L/2.0 ){
        region1 = WCSimGeometry::kBottom;
        if( z1<-L/2.0 ){
          z1 = -L/2.0; 
          t1 = (-L/2.0-z0)/pz;
        }
      }

      x1 = x0 + t1*px;
      y1 = y0 + t1*py;

      // second intersection
      if( z2>-L/2.0 && z2<+L/2.0 ){
        region2 = WCSimGeometry::kSide;
      }
      if( z2>=+L/2.0 ){
        region2 = WCSimGeometry::kTop;
        if( z2>+L/2.0 ){
          z2 = +L/2.0; 
          t2 = (+L/2.0-z0)/pz;
        }
      }
      if( z2<=-L/2.0 ){
        region2 = WCSimGeometry::kBottom;
        if( z2<-L/2.0 ){
          z2 = -L/2.0; 
          t2 = (-L/2.0-z0)/pz;
        }
      }

      x2 = x0 + t2*px;
      y2 = y0 + t2*py;

      // near/far projection
      if( t1>=0 ){
        xNear = x1;
        yNear = y1;
        zNear = z1;
        regionNear = region1;

        xFar = x2;
        yFar = y2;
        zFar = z2;
        regionFar = region2;
      }
      else if( t2>0 ){
        xNear = x2;
        yNear = y2;
        zNear = z2;
        regionNear = region2;

        xFar = x2;
        yFar = y2;
        zFar = z2;
        regionFar = region2;
      }
    }
 
  }

  // MAILBOX GEOMETRY
  // ================
  if( fGeoType==WCSimGeometry::kMailBox ){

    Double_t dX = fMailBoxX;
    Double_t dY = fMailBoxY;
    Double_t dZ = fMailBoxZ;

    Bool_t foundProjection = 0;

    Double_t t = 0.0;
    Double_t x = 0.0;
    Double_t y = 0.0;
    Double_t z = 0.0;

    Double_t t1 = 0.0;
    Double_t x1 = 0.0;
    Double_t y1 = 0.0;
    Double_t z1 = 0.0;
    Int_t region1 = -1;

    Double_t t2 = 0.0;  
    Double_t x2 = 0.0;
    Double_t y2 = 0.0;
    Double_t z2 = 0.0;
    Int_t region2 = -1;

    if( pz!=0 ){

      // top face (+dZ/2.0)
      t = (+dZ/2.0-z0)/pz;
      x = x0 + t*px;
      y = y0 + t*py;
      if( x>=-dX/2.0 && x<=+dX/2.0 
       && y>=-dY/2.0 && y<=+dY/2.0 ){
        if( pz>0.0 ){
          t2 = t;
          region2 = WCSimGeometry::kTop;
          foundProjection = 1;
        }
        else{
          t1 = t;
          region1 = WCSimGeometry::kTop;
          foundProjection = 1;
        }
      }

      // bottom face (-dZ/2.0)
      t = (-dZ/2.0-z0)/pz;
      x = x0 + t*px;
      y = y0 + t*py;
      if( x>=-dX/2.0 && x<=+dX/2.0 
       && y>=-dY/2.0 && y<=+dY/2.0 ){
        if( pz<0.0 ){
          t2 = t;
          region2 = WCSimGeometry::kBottom;
          foundProjection = 1;
        }
        else{
          t1 = t;
          region1 = WCSimGeometry::kBottom;
          foundProjection = 1;
        }
      }
    }

    if( px!=0 ){

      // front face (+dX/2.0)
      t = (+dX/2.0-x0)/px;
      y = y0 + t*py;
      z = z0 + t*pz;
      if( y>=-dY/2.0 && y<=+dY/2.0 
       && z>=-dZ/2.0 && z<=+dZ/2.0 ){
        if( px>0.0 ){
          t2 = t;
          region2 = WCSimGeometry::kFront;
          foundProjection = 1;
        }
        else{
          t1 = t;
          region1 = WCSimGeometry::kFront;
          foundProjection = 1;
        }
      }

      // back face (-dX/2.0)
      t = (-dX/2.0-x0)/px;
      y = y0 + t*py;
      z = z0 + t*pz;
      if( y>=-dY/2.0 && y<=+dY/2.0 
       && z>=-dZ/2.0 && z<=+dZ/2.0 ){
        if( px<0.0 ){
          t2 = t;
          region2 = WCSimGeometry::kBack;
          foundProjection = 1;
        }
        else{
          t1 = t;
          region1 = WCSimGeometry::kBack;
          foundProjection = 1;
        }
      }
    }

    if( py!=0 ){

      // left face (+dY/2.0)
      t = (+dY/2.0-y0)/py;
      z = z0 + t*pz;
      x = x0 + t*px;
      if( z>=-dZ/2.0 && z<=+dZ/2.0 
       && x>=-dX/2.0 && x<=+dX/2.0 ){
        if( py>0.0 ){
          t2 = t;
          region2 = WCSimGeometry::kLeft;
          foundProjection = 1;
        }
        else{
          t1 = t;
          region1 = WCSimGeometry::kLeft;
          foundProjection = 1;
        }
      }
    
      // right face (-dY/2.0)
      t = (-dY/2.0-y0)/py;
      z = z0 + t*pz;
      x = x0 + t*px;
      if( z>=-dZ/2.0 && z<=+dZ/2.0 
       && x>=-dX/2.0 && x<=+dX/2.0 ){
        if( py<0.0 ){
          t2 = t;
          region2 = WCSimGeometry::kRight;
          foundProjection = 1;
        }
        else{
          t1 = t;
          region1 = WCSimGeometry::kRight;
          foundProjection = 1;
        }
      }
    }

    // found projection
    if( foundProjection = 1 ){

      x1 = x0 + t1*px;
      y1 = y0 + t1*py;
      z1 = z0 + t1*pz;

      x2 = x0 + t2*px;
      y2 = y0 + t2*py;
      z2 = z0 + t2*pz;

      // near/far projection
      if( t1>=0 ){
        xNear = x1;
        yNear = y1;
        zNear = z1;
        regionNear = region1;

        xFar = x2;
        yFar = y2;
        zFar = z2;
        regionFar = region2;
      }
      else if( t2>0 ){
        xNear = x2;
        yNear = y2;
        zNear = z2;
        regionNear = region2;

        xFar = x2;
        yFar = y2;
        zFar = z2;
        regionFar = region2;
      }
    }
  }

  // set projections
  // ===============
  if( useFarEdge ){
    xproj = xFar;
    yproj = yFar;
    zproj = zFar;
    regionproj = regionFar;
  }
  else{
    xproj = xNear;
    yproj = yNear;
    zproj = zNear;
    regionproj = regionNear;
  }

  return;
}

void WCSimGeometry::ProjectToEdgeOld ( Bool_t  UseFarEdge,
Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  px,
Double_t  py,
Double_t  pz,
Double_t &  x,
Double_t &  y,
Double_t &  z,
Int_t &  region 
)

Definition at line 827 of file WCSimGeometry.cc.

References fCylLength, fCylRadius, fGeoType, fMailBoxX, fMailBoxY, fMailBoxZ, kCylinder, kMailBox, and kUnknown.

{
  // default locations
  // =================
  xproj = -99999.9;
  yproj = -99999.9;
  zproj = -99999.9;
  regionproj = WCSimGeometry::kUnknown;

  // CYLINDRICAL GEOMETRY
  // ====================
  if( fGeoType==WCSimGeometry::kCylinder ){

    //
    // std::cout << " --- ProjectToEdge --- " << std::endl
    //           << "  Vtx=(" << x0 << "," << y0 << "," << z0 << ") " << std::endl
    //           << "  Dir=(" << px << "," << py << "," << pz << ") --- " << std::endl; 
    //

    // projections
    // =========== 
    Double_t r = fCylRadius;
    Double_t L = fCylLength;

    Double_t x = 0.0;
    Double_t y = 0.0;
    Double_t z = 0.0;
    Int_t region = WCSimGeometry::kUnknown;

    Double_t mxy = 0.0;
    Double_t mz = 0.0;    
    Double_t xlow = 0.0;
    Double_t ylow = 0.0;
    Double_t zlow = 0.0;
    Double_t slow = 0.0;
    Double_t xhigh = 0.0;
    Double_t yhigh = 0.0;
    Double_t zhigh = 0.0;
    Double_t shigh = 0.0;

    Bool_t foundProjectionXY = 0;
    Bool_t foundProjectionX = 0;
    Bool_t foundProjectionY = 0;
    Bool_t foundProjectionZ = 0;
    Bool_t foundProjection = 0;

    // find radial intersections
    // =========================
    if( px!=0.0 ){
      mxy = py/px;

      // sanity check: is there an intersection?
      if( (1.0+mxy*mxy)*r*r - (mxy*x0-y0)*(mxy*x0-y0) > 0.0 ){

        // intersection at low x
        xlow = -(x0+mxy*y0) - sqrt( (1.0+mxy*mxy)*r*r - (mxy*x0-y0)*(mxy*x0-y0) );
        xlow /= (1.0+mxy*mxy);
        ylow = mxy*xlow;

        // intersection at high x
        xhigh = -(x0+mxy*y0) + sqrt( (1.0+mxy*mxy)*r*r - (mxy*x0-y0)*(mxy*x0-y0) );
        xhigh /= (1.0+mxy*mxy);
        yhigh = mxy*xhigh;

        // forward or backward
        if( px>=0 ){
          if( xlow>=0.0 ) slow = +1.0; else slow = -1.0;
          if( xhigh>=0.0 ) shigh = +1.0; else shigh = -1.0;
        }
        else{
          if( xlow<=0.0 ) slow = +1.0; else slow = -1.0;
          if( xhigh<=0.0 ) shigh = +1.0; else shigh = -1.0;
        }

        // intersection z values
        mz = pz/sqrt(px*px+py*py);
        zlow = z0 + mz*slow*sqrt(xlow*xlow+ylow*ylow);
        zhigh = z0 + mz*shigh*sqrt(xhigh*xhigh+yhigh*yhigh);

        // found radial projection
        foundProjectionXY = 1;
      }
    }

    // travelling along y-z plane
    else if( py!=0.0 ) { 

      // sanity check: is there an intersection?
      if( r*r-x0*x0 > 0.0 ){ 

        // intersection at low y
        xlow = 0.0;
        ylow = -sqrt( r*r-x0*x0 ) - y0;

        // intersection at high y
        xhigh = 0.0;
        yhigh = +sqrt( r*r-x0*x0 ) - y0;

        // forward or backward
        if( py>=0 ){
          if( ylow>=0.0 ) slow = +1.0; else slow = -1.0;
          if( yhigh>=0.0 ) shigh = +1.0; else shigh = -1.0;
        }
        else{
          if( ylow<=0.0 ) slow = +1.0; else slow = -1.0;
          if( yhigh<=0.0 ) shigh = +1.0; else shigh = -1.0;
        }

        // intersection z values
        mz = pz/sqrt(px*px+py*py);
        zlow = z0 + mz*slow*sqrt(xlow*xlow+ylow*ylow);
        zhigh = z0 + mz*shigh*sqrt(xhigh*xhigh+yhigh*yhigh);

        // found radial projection
        foundProjectionXY = 1;
      }
    }

    // travelling along z-axis
    else if( pz!=0.0 ) {     

      // sanity check: is there an intersection?
      if( x0*x0+y0*y0 < r*r ){ 
        xlow = -x0;
        ylow = -y0;
        zlow = -L/2.0;

        xhigh = -x0;
        yhigh = -y0;
        zhigh = +L/2.0;
        
        // found radial projection
        foundProjectionXY = 1;
      }
    }

    // check projection with cylinder
    // ==============================
    if( foundProjectionXY ){

      // project backwards along x-axis
      if( px<0.0 ){
        if( xlow<0 || xhigh<=0 ){
          foundProjectionX = 1;
        }
      }

      // project forwards along x-axis
      if( px>0.0 ){
        if( xlow>=0 || xhigh>0 ){
          foundProjectionX = 1;
        }
      }

      // project backwards along y-axis
      if( py<0.0 ){
        if( ylow<0 || yhigh<=0 ){
          foundProjectionY = 1;
        }
      }

      // project forwards along y-axis
      if( py>0.0 ){
        if( ylow>=0 || yhigh>0 ){
          foundProjectionY = 1;
        }
      }

      // project backwards along z-axis
      if( pz<0.0 ){
        if( z0>-L/2.0 
          && ( zlow<=+L/2.0 || zhigh<=+L/2.0 ) ){
          foundProjectionZ = 1;
        }
      }

      // project forwards along z-axis
      if( pz>0 ){
        if( z0<+L/2.0 
         && ( zlow>=-L/2.0 || zhigh>=-L/2.0 ) ){
          foundProjectionZ = 1;
        }
      }

      // overall projection
      if( foundProjectionX 
       && foundProjectionY
       && foundProjectionZ ){
        foundProjection = 1;
      }
    }

    // apply top/bottom correction
    // ===========================
    if( foundProjection ){

      if( zlow>+L/2.0 ){
        xlow *= (L/2.0-z0)/(zlow-z0);
        ylow *= (L/2.0-z0)/(zlow-z0);  
        zlow = +L/2.0; 
      }

      if( zlow<-L/2.0 ){
        xlow *= (-L/2.0-z0)/(zlow-z0);
        ylow *= (-L/2.0-z0)/(zlow-z0);
        zlow = -L/2.0;
      }
 
      if( zhigh>+L/2.0 ){
        xhigh *= (L/2.0-z0)/(zhigh-z0);
        yhigh *= (L/2.0-z0)/(zhigh-z0);  
        zhigh = +L/2.0; 
      }

      if( zhigh<-L/2.0 ){
        xhigh *= (-L/2.0-z0)/(zhigh-z0);
        yhigh *= (-L/2.0-z0)/(zhigh-z0);
        zhigh = -L/2.0;
      }

    }

    //
    // std::cout << "  FoundProjection = " << foundProjection << std::endl;
    // std::cout << "   low(x,y,z) = (" << xlow+x0 << "," << ylow+y0 << "," << zlow << ") " << std::endl; 
    // std::cout << "   high(x,y,z) = (" << xhigh+x0 << "," << yhigh+y0 << "," << zhigh << ") " << std::endl;
    //

    // choose intersection point
    // =========================
    if( foundProjection ){

      if( px!=0.0 ){

        // project backwards along x-axis
        if( px<0 ){
          if( useFarEdge ){
            if( xlow<=0.0 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
          }
          else{
            if( xhigh<0.0 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
            else if( xlow<=0.0 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
          }
        }        

        // project forwards along x-axis
        if( px>0.0 ){
          if( useFarEdge ){
            if( xhigh>=0.0 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
          }
          else{
            if( xlow>0.0 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
            else if( xhigh>=0.0 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
          }
        }
      }

      else if( py!=0.0 ){

        // project backwards along y-axis
        if( py<0.0 ){
          if( useFarEdge ){
            if( ylow<=0.0 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
          }
          else{
            if( yhigh<0.0 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
            else if( ylow<=0.0 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
          }
        }

        // project forwards along y-axis
        if( py>0.0 ){
          if( useFarEdge ){
            if( yhigh>=0.0 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
          }
          else{
            if( ylow>0.0 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
            else if( yhigh>=0.0 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
          }
        }

      }

      else{

        // project backwards along z-axis
        if( pz<0.0 ){
          if( useFarEdge ){
            if( z0>=-L/2.0 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
          }
          else{
            if( z0>+L/2 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
            else if( z0>=-L/2.0 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
          }
        }

        // project forwards along z-axis
        if( pz>0.0 ){
          if( useFarEdge ){
            if( z0<=+L/2.0 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
          }
          else{
            if( z0<-L/2 ){
              x = xlow+x0;
              y = ylow+y0;
              z = zlow;
            }
            else if( z0<=+L/2.0 ){
              x = xhigh+x0;
              y = yhigh+y0;
              z = zhigh;
            }
          }
        }

      }

      // assign region
      if( -L/2.0<z && z<+L/2.0 ){
        region = WCSimGeometry::kSide; // region 1
      }

      if( z>=+L/2.0 ){ 
        region = WCSimGeometry::kTop; // region 0 
      }

      if( z<=-L/2.0 ){ 
        region = WCSimGeometry::kBottom; // region 2
      }

    }
    
    //   
    // std::cout << "  Return Projection: x=" << x << " y=" << y << " z=" << z << " region=" << region << std::endl;
    //

    // return projection
    // =================
    if( region > WCSimGeometry::kUnknown ){

      xproj = x;
      yproj = y;
      zproj = z;
      regionproj = region;

      return;
    }
  }

  // MAILBOX GEOMETRY
  // ================
  if( fGeoType==WCSimGeometry::kMailBox ){

    Double_t dX = fMailBoxX;
    Double_t dY = fMailBoxY;
    Double_t dZ = fMailBoxZ;

    Double_t x_top    = -99999.9;
    Double_t y_top    = -99999.9;
    Double_t z_top    = -99999.9;

    Double_t x_bottom = -99999.9;
    Double_t y_bottom = -99999.9;
    Double_t z_bottom = -99999.9;

    Double_t x_front  = -99999.9;
    Double_t y_front  = -99999.9;
    Double_t z_front  = -99999.9;    

    Double_t x_back   = -99999.9;
    Double_t y_back   = -99999.9;
    Double_t z_back   = -99999.9;   

    Double_t x_right  = -99999.9;
    Double_t y_right  = -99999.9;
    Double_t z_right  = -99999.9;

    Double_t x_left   = -99999.9;
    Double_t y_left   = -99999.9;
    Double_t z_left   = -99999.9;  

    Double_t x = 0.0;
    Double_t y = 0.0;
    Double_t z = 0.0;
    Int_t region = WCSimGeometry::kUnknown;
  
    // calculate projections in each plane
    // ===================================
    if( pz!=0.0 ){
      x_top    = x0 + (px/pz)*(+0.5*dZ-z0);
      y_top    = y0 + (py/pz)*(+0.5*dZ-z0);
      z_top    = +0.5*dZ;

      x_bottom = x0 + (px/pz)*(-0.5*dZ-z0);
      y_bottom = y0 + (py/pz)*(-0.5*dZ-z0);
      z_bottom = -0.5*dZ;
    }

    if( py!=0.0 ){
      z_left  = z0 + (pz/py)*(+0.5*dY-y0);
      x_left  = x0 + (px/py)*(+0.5*dY-y0);   
      y_left  = +0.5*dY;
    
      z_right   = z0 + (pz/py)*(-0.5*dY-y0);
      x_right   = x0 + (px/py)*(-0.5*dY-y0);
      y_right   = -0.5*dY;
    }

    if( px!=0.0 ){
      y_front  = y0 + (py/px)*(+0.5*dX-x0);
      z_front  = z0 + (pz/px)*(+0.5*dX-x0);
      x_front  = +0.5*dX;

      y_back   = y0 + (py/px)*(-0.5*dX-x0);
      z_back   = z0 + (pz/px)*(-0.5*dX-x0);
      x_back   = -0.5*dX;
    }

    // calculate intersections with box
    // ================================
    if( x_top>=-0.5*dX && x_top<=+0.5*dX
     && y_top>=-0.5*dY && y_top<=+0.5*dY ){
      if( pz<0.0 && z0>z_top ){
        if( !useFarEdge ){
          x = x_top;  
          y = y_top;  
          z = z_top;
          region = WCSimGeometry::kTop;
        }
      }
      if( pz>0.0 && z0<=z_top ){
        if( z0>z_bottom
         || useFarEdge ){
          x = x_top;  
          y = y_top;  
          z = z_top;
          region = WCSimGeometry::kTop;
        }
      }
    }   

    if( x_bottom>=-0.5*dX && x_bottom<=+0.5*dX
     && y_bottom>=-0.5*dY && y_bottom<=+0.5*dY ){
      if( pz>0.0 && z0<z_bottom ){
        if( !useFarEdge ){
          x = x_bottom;  
          y = y_bottom;  
          z = z_bottom;
          region = WCSimGeometry::kBottom;
        }
      }
      if( pz<0.0 && z0>=z_bottom ){
        if( z0<z_top
         || useFarEdge ){
          x = x_bottom;  
          y = y_bottom;  
          z = z_bottom;
          region = WCSimGeometry::kBottom;
        }
      }
    }

    if( y_front>=-0.5*dY && y_front<=+0.5*dY
     && z_front>=-0.5*dZ && z_front<=+0.5*dZ ){
      if( px<0.0 && x0>x_front ){
        if( !useFarEdge ){
          x = x_front;  
          y = y_front;  
          z = z_front;
          region = WCSimGeometry::kFront;
        }
      }
      if( px>0.0 && x0<=x_front ){
        if( x0>x_back
         || useFarEdge ){
          x = x_front;  
          y = y_front;  
          z = z_front;
          region = WCSimGeometry::kFront;
        }
      }

    }       

    if( y_back>=-0.5*dY && y_back<=+0.5*dY
     && z_back>=-0.5*dZ && z_back<=+0.5*dZ ){
      if( px>0.0 && x0<x_back ){
        if( !useFarEdge ){
          x = x_back;  
          y = y_back;  
          z = z_back;
          region = WCSimGeometry::kBack;
        }
      }
      if( px<0.0 && x0>=x_back ){
        if( x0<x_front
         || useFarEdge ){
          x = x_back;  
          y = y_back;  
          z = z_back;
          region = WCSimGeometry::kBack;
        }
      }
    }     

    if( z_left>=-0.5*dZ && z_left<=+0.5*dZ
     && x_left>=-0.5*dX && x_left<=+0.5*dX ){
      if( py<0.0 && y0>y_left ){
        if( !useFarEdge ){
          x = x_left;  
          y = y_left;  
          z = z_left;
          region = WCSimGeometry::kLeft;
        }
      }
      if( py>0.0 && y0<=y_left ){
        if( y0>y_right
         || useFarEdge ){
          x = x_left;  
          y = y_left;  
          z = z_left;
          region = WCSimGeometry::kLeft;
        }
      }    
    }          

    if( z_right>=-0.5*dZ && z_right<=+0.5*dZ
     && x_right>=-0.5*dX && x_right<=+0.5*dX ){
      if( py>0.0 && y0<y_right ){
        if( !useFarEdge ){
          x = x_right;  
          y = y_right;  
          z = z_right;
          region = WCSimGeometry::kRight;
        }
      }
      if( py<0.0 && y0>=y_right ){
        if( y0<y_left
         || useFarEdge ){
          x = x_right;  
          y = y_right;  
          z = z_right;
          region = WCSimGeometry::kRight;
        }
      }
    }      

    // return projection
    // =================
    if( region > WCSimGeometry::kUnknown ){
 
      xproj = x;
      yproj = y;
      zproj = z;
      regionproj = region;

      return;
    }
  }

  return;
}

void WCSimGeometry::ProjectToFarEdge ( Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  px,
Double_t  py,
Double_t  pz,
Double_t &  x,
Double_t &  y,
Double_t &  z,
Int_t &  region 
)

Definition at line 808 of file WCSimGeometry.cc.

References ProjectToEdge().

Referenced by WCSimDisplayAB::DrawRing(), and WCSimDisplayAB::DrawVertex().

{  
  this->ProjectToEdge(1,
                      x0,y0,z0,
                      px,py,pz,
                      xproj,yproj,zproj,
                      regionproj);

  //
  // this->ProjectToEdgeOld(1,
  //                        x0,y0,z0,
  //                        px,py,pz,
  //                        xproj,yproj,zproj,
  //                        regionproj);
  //
  
  return;
}

void WCSimGeometry::ProjectToNearEdge ( Double_t  x0,
Double_t  y0,
Double_t  z0,
Double_t  px,
Double_t  py,
Double_t  pz,
Double_t &  x,
Double_t &  y,
Double_t &  z,
Int_t &  region 
)

Definition at line 789 of file WCSimGeometry.cc.

References ProjectToEdge().

Referenced by BackwardProjectionToEdge(), and ForwardProjectionToEdge().

{
  this->ProjectToEdge(0,
                      x0,y0,z0,
                      px,py,pz,
                      xproj,yproj,zproj,
                      regionproj);

  //
  // this->ProjectToEdgeOld(0,
  //                        x0,y0,z0,
  //                        px,py,pz,
  //                        xproj,yproj,zproj,
  //                        regionproj);
  //

  return;
}

void WCSimGeometry::Reset (  )  [static]

Definition at line 202 of file WCSimGeometry.cc.

References GetNumPMTs(), Instance(), and SetGeometry().

{
  if( WCSimGeometry::Instance()->GetNumPMTs()>0 ){
    std::cout << " *** WCSimGeometry::Reset() *** " << std::endl;
  }

  WCSimGeometry::Instance()->SetGeometry(0);
}

void WCSimGeometry::SetGeometry ( WCSimRootGeom *  geom  ) 

Definition at line 211 of file WCSimGeometry.cc.

References fCylFiducialLength, fCylFiducialRadius, fCylinder, fCylLength, fCylRadius, fDetectorArea, fDetectorFiducialVolume, fDetectorVolume, fGeoConfig, fGeoType, fGeoTypeInput, fMailBox, fMailBoxFiducialX, fMailBoxFiducialY, fMailBoxFiducialZ, fMailBoxX, fMailBoxY, fMailBoxZ, fPMTCoverage, fPMTRadius, fPmtRegion, fPMTs, fPMTSeparation, fPMTSurfaceArea, fPmtX, fPmtY, fPmtZ, fWCSimRootGeom, kCylinder, kMailBox, and PrintGeometry().

Referenced by BuildGeometry(), Reset(), and WCSimGeometry().

{  
  // Store WCSim Geometry
  // ====================
  fWCSimRootGeom = myGeometry;

  // Reset Geometry
  // ==============
  fPMTs = 0;

  if( fPmtX ) delete [] fPmtX;             fPmtX = 0;
  if( fPmtY ) delete [] fPmtY;             fPmtY = 0;
  if( fPmtZ ) delete [] fPmtZ;             fPmtZ = 0;
  if( fPmtRegion ) delete [] fPmtRegion;   fPmtRegion = 0;

  // Reset Geometry
  // ==============
  fGeoType = WCSimGeometry::kUnknown;
  fGeoConfig = WCSimGeometry::kDUSEL_Unknown;

  fCylinder = 0;
  fCylRadius = 0.0;
  fCylLength = 0.0;  
  fCylFiducialRadius = 0.0;
  fCylFiducialLength = 0.0;
    
  fMailBox = 0;
  fMailBoxX = 0.0;
  fMailBoxY = 0.0;
  fMailBoxZ = 0.0;  
  fMailBoxFiducialX = 0.0;
  fMailBoxFiducialY = 0.0;
  fMailBoxFiducialZ = 0.0;

  fDetectorArea = 0.0;
  fDetectorVolume = 0.0;
  fDetectorFiducialVolume = 0.0;

  // Sanity Check
  // ============
  if( myGeometry == 0 ){
    return;
  }

  // Building New Geometry
  // =====================
  std::cout << " *** WCSimGeometry::BuildGeometry(...) *** " << std::endl;

  // Get Geometry Type
  // =================
  fGeoTypeInput = myGeometry->GetGeo_Type();

  std::cout << "   reading geometry: type=" << fGeoTypeInput << std::endl;

  // --- hack ---
  if( fGeoTypeInput<0 || fGeoTypeInput>1 ){
    std::cout << "   <warning> Detected Unknown Geometry: " << fGeoTypeInput << std::endl;
    std::cout << "             Horrible hack! Assume it's a cylinder..." << std::endl;
    std::cout << "             Setting GeoType = 0 " << std::endl;
    fGeoTypeInput = 0;
  }

  if( fGeoTypeInput==0 ){  // geotype=0: cylinder
    std::cout << "   building cylindrical geometry " << std::endl;
    fGeoType = WCSimGeometry::kCylinder;
    fCylinder = 1;
    fCylRadius = myGeometry->GetWCCylRadius();
    fCylLength = myGeometry->GetWCCylLength();
    if( fCylRadius<3000.0 ){                      // hack for 100kton -> 200kton transition
      fCylFiducialRadius = fCylRadius - 250.0;    // note: fiducial volume formerly defined
    }                                             //       as 2.5m from cylinder edge, but
    else{                                         //       is now reduced to 2.0m from edge.
      fCylFiducialRadius = fCylRadius - 200.0;    //                 
    }                                             //
    fCylFiducialLength = fCylLength - 400.0;      //
    fDetectorArea = 2.0*TMath::Pi()*fCylRadius*(fCylRadius
                                              + fCylLength);
    fDetectorVolume = TMath::Pi()*fCylRadius*fCylRadius*fCylLength;
    fDetectorFiducialVolume = TMath::Pi()*fCylFiducialRadius*fCylFiducialRadius*fCylFiducialLength;
  }
  
  if( fGeoTypeInput==1 ){  // geotype=1: mailbox
    std::cout << "   building mailbox geometry " << std::endl;
    fGeoType = WCSimGeometry::kMailBox;
    fMailBox = 1;
    fMailBoxX = myGeometry->GetMailBox_x();
    fMailBoxY = myGeometry->GetMailBox_y();
    fMailBoxZ = myGeometry->GetMailBox_z();
    fMailBoxFiducialX = fMailBoxX - 400.0;          // note: fiducial volume defined
    fMailBoxFiducialY = fMailBoxY - 400.0;          //       2.0m from mailbox edge
    fMailBoxFiducialZ = fMailBoxZ - 400.0;
    fDetectorArea = 2.0*(fMailBoxX*fMailBoxY 
                       + fMailBoxY*fMailBoxZ 
                       + fMailBoxZ*fMailBoxX);
    fDetectorVolume = fMailBoxX*fMailBoxY*fMailBoxZ;
    fDetectorFiducialVolume = fMailBoxFiducialX*fMailBoxFiducialY*fMailBoxFiducialZ;
  }

  // Look up PMT Locations (NB: +1 to stop overflow)
  // ===============================================
  std::cout << "   reading PMTs: " << myGeometry->GetWCNumPMT() << std::endl;
  fPMTs = myGeometry->GetWCNumPMT() + 1;

  fPmtX = new Double_t[fPMTs];
  fPmtY = new Double_t[fPMTs];
  fPmtZ = new Double_t[fPMTs];
  fPmtRegion = new Int_t[fPMTs];

  for( Int_t n=0; n<fPMTs; n++ ){
    fPmtX[n] = -99999.9;
    fPmtY[n] = -99999.9;
    fPmtZ[n] = -99999.9;
    fPmtRegion[n] = -1;
  }

  for( Int_t n=0; n<myGeometry->GetWCNumPMT(); n++ ){

    // get next PMT
    WCSimRootPMT myPmt = myGeometry->GetPMT(n);

    Int_t tube = myPmt.GetTubeNo();
    Int_t region = -1; // myPmt.GetCylLoc();
    Double_t x = myPmt.GetPosition(0);
    Double_t y = myPmt.GetPosition(1);
    Double_t z = myPmt.GetPosition(2);

    // hack the region (for now)
    Double_t delta = 10.0; // cm

    if( fCylinder ){
      if( z>=-0.5*fCylLength+delta 
       && z<=+0.5*fCylLength-delta ) region = WCSimGeometry::kSide;
      if( z<-0.5*fCylLength+delta )  region = WCSimGeometry::kBottom;
      if( z>+0.5*fCylLength-delta )  region = WCSimGeometry::kTop;
    }

    if( fMailBox ){
      //if( z>=-0.5*fMailBoxZ+delta 
      // && z<=+0.5*fMailBoxZ-delta ) region = WCSimGeometry::kSide;
      if( z<-0.5*fMailBoxZ+delta )  region = WCSimGeometry::kBottom;
      if( z>+0.5*fMailBoxZ-delta )  region = WCSimGeometry::kTop;
      if( x<-0.5*fMailBoxX+delta )  region = WCSimGeometry::kBack;
      if( x>+0.5*fMailBoxX-delta )  region = WCSimGeometry::kFront;
      if( y<-0.5*fMailBoxY+delta )  region = WCSimGeometry::kRight;
      if( y>+0.5*fMailBoxY-delta )  region = WCSimGeometry::kLeft;
    }

    // add to array
    if( tube>=0 && tube<fPMTs ){
      fPmtX[tube] = x;
      fPmtY[tube] = y;
      fPmtZ[tube] = z;
      fPmtRegion[tube] = region;
    }
  }

  // Calculate PMT Coverage
  // ======================

  // horrible hack (WCSim switched units on me!)   
  if( myGeometry->GetWCPMTRadius()<100.0 ){
    fPMTRadius = 1.0*myGeometry->GetWCPMTRadius(); // [must be cm already]
  }
  else{
    fPMTRadius = 0.1*myGeometry->GetWCPMTRadius(); // [must be mm, so convert to cm]
  }

  fPMTSurfaceArea = 0.0;
  fPMTCoverage = 0.0;
  fPMTSeparation = 0.0;

  if( fPMTs>0 && fDetectorArea>0.0 ){
    fPMTSurfaceArea = fPMTs*TMath::Pi()*fPMTRadius*fPMTRadius;
    fPMTCoverage = fPMTSurfaceArea/fDetectorArea;
    fPMTSeparation = sqrt(fDetectorArea/fPMTs);
  }

  // Determine Detector Configuration
  // ================================
  std::cout << "   determing detector configuration " << std::endl;
  
  Double_t kton = 0.5+1.0e-9*fDetectorFiducialVolume;
  Int_t kton_rounded = (Int_t)(10.0*(Int_t)(0.1*kton));
  Double_t pmtdiam = 0.5+(2.0/2.54)*fPMTRadius;
  Int_t pmtdiam_rounded = (Int_t)(2.0*(Int_t)(0.5*pmtdiam));
  Double_t coverage = 0.5 + 100.0*fPMTCoverage;
  Int_t coverage_rounded = (Int_t)(coverage);

  std::cout << "    DUSEL_" << kton_rounded << "kton"; 
  if( fgGeometryHandle->GetGeoType()==WCSimGeometry::kMailBox ) std::cout << "Mailbox";
  std::cout << "_";
  std::cout << pmtdiam_rounded
            << "inch_" << coverage_rounded
            << "perCent " << std::endl;

  // cylindrical geometry
  if( fGeoType==WCSimGeometry::kCylinder ){
    if( kton_rounded==100 && pmtdiam_rounded==10 && coverage_rounded==12 ) fGeoConfig = WCSimGeometry::kDUSEL_100kton_10inch_12percent;    
    if( kton_rounded==100 && pmtdiam_rounded==10 && coverage_rounded==15 ) fGeoConfig = WCSimGeometry::kDUSEL_100kton_10inch_15percent;    
    if( kton_rounded==100 && pmtdiam_rounded==10 && coverage_rounded==30 ) fGeoConfig = WCSimGeometry::kDUSEL_100kton_10inch_30percent;  
    if( kton_rounded==100 && pmtdiam_rounded==10 && coverage_rounded==40 ) fGeoConfig = WCSimGeometry::kDUSEL_100kton_10inch_40percent; 
    if( kton_rounded==200 && pmtdiam_rounded==10 && coverage_rounded==12 ) fGeoConfig = WCSimGeometry::kDUSEL_200kton_10inch_12percent; 
    if( kton_rounded==200 && pmtdiam_rounded==12 && coverage_rounded==10 ) fGeoConfig = WCSimGeometry::kDUSEL_200kton_12inch_10percent;
    if( kton_rounded==200 && pmtdiam_rounded==12 && coverage_rounded==14 ) fGeoConfig = WCSimGeometry::kDUSEL_200kton_12inch_14percent;
  }

  // mailbox geometry
  else if( fGeoType==WCSimGeometry::kMailBox ){
    if( kton_rounded==150 && pmtdiam_rounded==10 && coverage_rounded==15 ) fGeoConfig = WCSimGeometry::kDUSEL_150ktonMailbox_10inch_15percent;
    if( kton_rounded==150 && pmtdiam_rounded==10 && coverage_rounded==30 ) fGeoConfig = WCSimGeometry::kDUSEL_150ktonMailbox_10inch_30percent;
    if( kton_rounded==150 && pmtdiam_rounded==10 && coverage_rounded==40 ) fGeoConfig = WCSimGeometry::kDUSEL_150ktonMailbox_10inch_40percent;
  }

  // --- sanity check ---
  else{
    std::cout << " <error> unknown geometry" << std::endl;
    assert(0);
  }

  // Print Geometry
  // ==============
  PrintGeometry();

  return;
}

Bool_t WCSimGeometry::TouchGeometry (  )  [static]

Definition at line 20 of file WCSimGeometry.cc.

References Instance().

Referenced by WCSimDisplayViewer::controlStart(), PrintGeometry(), WCSimNtupleWriter::Run(), and WCSimVertexGeometry::WCSimVertexGeometry().

{
  if( WCSimGeometry::Instance()->GetNumPMTs()>0 ){
    return true;
  }
  else{
    std::cout << " ***  WCSimGeometry::TouchData() *** " << std::endl;
    std::cout << "  <error> need to build geometry... " << std::endl
              << "    Call: WCSimGeometry::BuildGeometry(WCSimRootGeom*) " << std::endl; 
    return false;
  }
}

void WCSimGeometry::WriteGeometry ( const char *  filename = "wcsim.geometry.root"  )  [static]

Definition at line 47 of file WCSimGeometry.cc.

References Instance(), and WriteToFile().

Referenced by WCSimEventWriter::Run().

void WCSimGeometry::WriteToFile ( const char *  filename = "wcsim.geometry.root"  ) 

Definition at line 437 of file WCSimGeometry.cc.

References fPmtRegion, fPMTs, fPmtX, fPmtY, fPmtZ, fRegion, fTube, fXpos, fYpos, and fZpos.

Referenced by WriteGeometry().

{
  std::cout << " *** WCSimGeometry::WriteGeometry() *** " << std::endl;

  if( fPMTs<=0 ){
    std::cout << "  warning: no geometry loaded " << std::endl;
    return;
  }

  std::cout << "  writing geometry to: "  << filename << std::endl;

  TDirectory* tmpd = 0;
  TFile* fFileGeometry = 0;
  TTree* fTreeGeometry = 0;

  if( !fFileGeometry ){
    tmpd = gDirectory;
    fFileGeometry = new TFile(filename,"recreate");
    fTreeGeometry = new TTree("ntuple","detector geometry");
    fTreeGeometry->Branch("tube",&fTube,"tube/I");
    fTreeGeometry->Branch("region",&fRegion,"region/I");
    fTreeGeometry->Branch("x",&fXpos,"x/D");
    fTreeGeometry->Branch("y",&fYpos,"y/D");
    fTreeGeometry->Branch("z",&fZpos,"z/D");
    fTreeGeometry->SetAutoSave(100);
    gDirectory = tmpd;  
  }
  
  for( Int_t n =0; n<fPMTs; n++ ){    
    fTube = n;
    fRegion = fPmtRegion[n];
    fXpos = fPmtX[n];
    fYpos = fPmtY[n];
    fZpos = fPmtZ[n];

    if( fRegion>=0 ){
      tmpd = gDirectory;
      fFileGeometry->cd();
      fTreeGeometry->Fill();
      gDirectory = tmpd;
    }
  }
 
  tmpd = gDirectory;
  fFileGeometry->cd();
  fTreeGeometry->Write();
  fFileGeometry->Close();
  fFileGeometry = 0;
  fTreeGeometry = 0;
  gDirectory = tmpd;

  return;
}

void WCSimGeometry::XYZtoUV ( Int_t  region,
Double_t  x,
Double_t  y,
Double_t  z,
Double_t &  u,
Double_t &  v 
)

Definition at line 1809 of file WCSimGeometry.cc.

References fCylLength, fCylRadius, fGeoType, fMailBoxX, fMailBoxY, fMailBoxZ, kBack, kBottom, kCylinder, kFront, kLeft, kMailBox, kRight, kSide, and kTop.

Referenced by WCSimDisplayAB::DrawCleanDisplay(), WCSimDisplayAB::DrawDisplay(), WCSimDisplayAB::DrawRing(), and WCSimDisplayAB::DrawVertex().

{
  // default locations
  u = -99999.9;
  v = -99999.9;

  // Note:
  // ====
  //  assume that beam points along -ve x direction

  // CYLINDRICAL GEOMETRY
  // ====================
  if( fGeoType==WCSimGeometry::kCylinder ){

    // PMTs on top face
    if( region==WCSimGeometry::kTop ){
      u = y;
      v = +0.5*fCylLength+fCylRadius+x;
    }

    // PMTs on side
    if( region==WCSimGeometry::kSide ){
      Double_t theta = 0.0;
      if( x!=0.0 ) theta = TMath::ATan(-y/x);
      if( x>=0 ){
        if( y>0.0 ) theta += TMath::Pi();
        if( y<0.0 ) theta -= TMath::Pi();
      }
      u = fCylRadius*theta;
      v = z;
    }

    // PMTs on bottom face
    if( region==WCSimGeometry::kBottom ){
      u = y;
      v = -0.5*fCylLength-fCylRadius-x;
    }
  }

  // MAILBOX GEOMETRY
  // ================
  //
  // Default Coordinate System:
  //
  //               +ve z(Top)
  //                   ^   
  //                   |  / +ve y(Left)
  //                   | /
  //    -ve x(Back) -- --> +ve x(Front)          
  //                 / |
  //   -ve y(Right) /  |
  //                  -ve z(Bottom)
  //
  // Rolled out as follows:
  // 
  //              -----
  //             |  T  |
  //    --- ----- ----- ----- ---
  //   | F |  R  |  B  |  L  | F |
  //    --- ----- ----- ----- ---
  //             |  B  |
  //              -----
  //

  if( fGeoType==WCSimGeometry::kMailBox ){

    // PMTs on top face
    if( region==WCSimGeometry::kTop ){
      u = y;
      v = +0.5*fMailBoxZ+0.5*fMailBoxX+x;
    }

    // PMTs on front face
    if( region==WCSimGeometry::kFront ){      
      if( y>0.0 ) u = +fMailBoxX+fMailBoxY-y;
      if( y<0.0 ) u = -fMailBoxX-fMailBoxY-y;
      v = z;
    }

    // PMTs on left face
    if( region==WCSimGeometry::kLeft ){      
      u = +0.5*fMailBoxX+0.5*fMailBoxY+x;
      v = z;
    }

    // PMTs on right face
    if( region==WCSimGeometry::kRight ){
      u = -0.5*fMailBoxX-0.5*fMailBoxY-x;
      v = z;
    }

    // PMTs on back face
    if( region==WCSimGeometry::kBack ){
      u = y;
      v = z;
    }    

    // PMTs on bottom face
    if( region==WCSimGeometry::kBottom ){
      u = y;
      v = -0.5*fMailBoxZ-0.5*fMailBoxX-x;
    }

  }

  return;
}


Member Data Documentation

Definition at line 254 of file WCSimGeometry.hh.

Referenced by GetCylFiducialLength(), InsideFiducialVolume(), and SetGeometry().

Definition at line 253 of file WCSimGeometry.hh.

Referenced by GetCylFiducialRadius(), InsideFiducialVolume(), and SetGeometry().

Bool_t WCSimGeometry::fCylinder [private]

Definition at line 250 of file WCSimGeometry.hh.

Referenced by IsCylinder(), and SetGeometry().

Double_t WCSimGeometry::fCylLength [private]
Double_t WCSimGeometry::fCylRadius [private]
Double_t WCSimGeometry::fDetectorArea [private]

Definition at line 264 of file WCSimGeometry.hh.

Referenced by GetArea(), and SetGeometry().

Definition at line 266 of file WCSimGeometry.hh.

Referenced by GetFiducialVolume(), and SetGeometry().

Double_t WCSimGeometry::fDetectorVolume [private]

Definition at line 265 of file WCSimGeometry.hh.

Referenced by GetVolume(), and SetGeometry().

Int_t WCSimGeometry::fGeoConfig [private]

Definition at line 248 of file WCSimGeometry.hh.

Referenced by GetGeoConfig(), and SetGeometry().

Int_t WCSimGeometry::fGeoType [private]

Definition at line 247 of file WCSimGeometry.hh.

Referenced by SetGeometry().

Bool_t WCSimGeometry::fMailBox [private]

Definition at line 256 of file WCSimGeometry.hh.

Referenced by IsMailBox(), and SetGeometry().

Definition at line 260 of file WCSimGeometry.hh.

Referenced by GetMailBoxFiducialX(), InsideFiducialVolume(), and SetGeometry().

Definition at line 261 of file WCSimGeometry.hh.

Referenced by GetMailBoxFiducialY(), InsideFiducialVolume(), and SetGeometry().

Definition at line 262 of file WCSimGeometry.hh.

Referenced by GetMailBoxFiducialZ(), InsideFiducialVolume(), and SetGeometry().

Double_t WCSimGeometry::fMailBoxX [private]
Double_t WCSimGeometry::fMailBoxY [private]
Double_t WCSimGeometry::fMailBoxZ [private]
Double_t WCSimGeometry::fPMTCoverage [private]

Definition at line 242 of file WCSimGeometry.hh.

Referenced by GetPMTCoverage(), and SetGeometry().

Double_t WCSimGeometry::fPMTRadius [private]

Definition at line 241 of file WCSimGeometry.hh.

Referenced by GetPMTRadius(), and SetGeometry().

Int_t* WCSimGeometry::fPmtRegion [private]

Definition at line 239 of file WCSimGeometry.hh.

Referenced by GetRegion(), SetGeometry(), WriteToFile(), and ~WCSimGeometry().

Int_t WCSimGeometry::fPMTs [private]

Definition at line 235 of file WCSimGeometry.hh.

Referenced by GetNumPMTs(), GetRegion(), GetX(), GetY(), GetZ(), SetGeometry(), and WriteToFile().

Double_t WCSimGeometry::fPMTSeparation [private]

Definition at line 243 of file WCSimGeometry.hh.

Referenced by GetPMTSeparation(), and SetGeometry().

Double_t WCSimGeometry::fPMTSurfaceArea [private]

Definition at line 244 of file WCSimGeometry.hh.

Referenced by SetGeometry().

Double_t* WCSimGeometry::fPmtX [private]

Definition at line 236 of file WCSimGeometry.hh.

Referenced by GetX(), SetGeometry(), WriteToFile(), and ~WCSimGeometry().

Double_t* WCSimGeometry::fPmtY [private]

Definition at line 237 of file WCSimGeometry.hh.

Referenced by GetY(), SetGeometry(), WriteToFile(), and ~WCSimGeometry().

Double_t* WCSimGeometry::fPmtZ [private]

Definition at line 238 of file WCSimGeometry.hh.

Referenced by GetZ(), SetGeometry(), WriteToFile(), and ~WCSimGeometry().

Int_t WCSimGeometry::fRegion [private]

Definition at line 269 of file WCSimGeometry.hh.

Referenced by WriteToFile().

Double_t WCSimGeometry::fScale [private]

Definition at line 233 of file WCSimGeometry.hh.

Int_t WCSimGeometry::fTube [private]

Definition at line 268 of file WCSimGeometry.hh.

Referenced by WriteToFile().

WCSimRootGeom* WCSimGeometry::fWCSimRootGeom [private]

Definition at line 274 of file WCSimGeometry.hh.

Referenced by GetWCSimGeometry(), and SetGeometry().

Double_t WCSimGeometry::fXpos [private]

Definition at line 270 of file WCSimGeometry.hh.

Referenced by WriteToFile().

Double_t WCSimGeometry::fYpos [private]

Definition at line 271 of file WCSimGeometry.hh.

Referenced by WriteToFile().

Double_t WCSimGeometry::fZpos [private]

Definition at line 272 of file WCSimGeometry.hh.

Referenced by WriteToFile().


The documentation for this class was generated from the following files: