ROOT logo
#pragma implementation
using namespace std;
#include <stdlib.h>
#include <iostream> 
#include <iomanip>
#include "hshowerframe.h"

ClassImp(HShowerFrameCorner)
ClassImp(HShowerFrame)

//_HADES_CLASS_DESCRIPTION 
/////////////////////////////////////////////////////////////
// HShowerFrameCorner
// Class describe coordinates one corner in frame
//
// HShowerFrame
// Description of local coordinates of frame  
//
/////////////////////////////////////////////////////////////

HShowerFrameCorner::HShowerFrameCorner() {
  fXcor = 0.0f;
  fYcor = 0.0f;
  nFlagArea = 0;
}

/////////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////////

HShowerFrame::HShowerFrame() {
  m_nModuleID = -1;
  reset();
} // eof constructor


HShowerFrame::~HShowerFrame() {
  reset();
} // eof destructor

void HShowerFrame::reset()
{
//clearing data
  nCorners = 0;
  m_FrameArr.Delete();
}

HShowerFrameCorner* HShowerFrame::getCorner(Int_t n)
{
// retrieve corner information
   if ((n < 0) || (n >= nCorners))
      return NULL;

   return (HShowerFrameCorner*)m_FrameArr.At(n);
}


Int_t HShowerFrame::setCorner(HShowerFrameCorner* pCorner, Int_t n)
{
//set corner information at n position
   if ((n < 0) || (n >= nCorners))
      return 0;

   delete m_FrameArr.At(n);
   m_FrameArr.AddAt(pCorner, n);

   return 1;
}

Int_t HShowerFrame::addCorner(HShowerFrameCorner* pCorner)
{
// add new corner into table
  m_FrameArr.Add(pCorner);
  return nCorners++;
}

Int_t HShowerFrame::isOut(Float_t x, Float_t y) {
// returns 1 if point x,y is outside frame, otherwise 0
  Float_t a,b;
  if (nCorners<=2) {
    Error("isOut(Float_t,Float_t)","Frame must have at least 3 corners!");
    exit(1);
  }

  Float_t X0, X1, Y0, Y1;
  Int_t nFlag;

  for (Int_t i=0; i < nCorners - 1; i++) {
    X0 = getCorner(i)->getX();
    X1 = getCorner(i + 1)->getX();
    Y0 = getCorner(i)->getY();
    Y1 = getCorner(i + 1)->getY();
    nFlag = getCorner(i)->getFlagArea(); 
 
    if (X0 == X1) {
      if (nFlag == 0 && x > X0) return 1;
      else if (nFlag == 1 && x < X0) return 1;
    } else if (Y0 == Y1) {
      b = (X1 * Y0 - X0 * Y1)/(X1 - X0);
      if (nFlag == 0 && y > Y0) return 1;
      else if (nFlag == 1 && y < Y0) return 1;
    } else {
      a = (Y1 - Y0)/(X1 - X0);
      b = (X1*Y0 - X0*Y1)/(X1 - X0);
      if (a<0 && 
          ((nFlag == 0 && y>(a*x+b)) || 
           (nFlag == 1 && y<(a*x+b)))) return 1;
      else if (a>0 &&
               ((nFlag==0 && y<(a*x+b)) ||
                (nFlag==1 && y>(a*x+b)))) return 1;
    }
  }

  return 0;
}

void HShowerFrame::printParams() {
  cout<<"Module "<<m_nModuleID<<" Wire frame corners:"<<endl; 
  for (Int_t i=0; i < nCorners; i++) {
    cout<<"  "<<i<<setw(10)<<right<<fixed<<setprecision(3)<<getCorner(i)->getX()
        <<setw(10)<<right<<fixed<<setprecision(3)<<getCorner(i)->getY()
        <<setw(3)<<right<<getCorner(i)->getFlagArea()<<endl;
  }
  cout<<endl;
}
 hshowerframe.cc:1
 hshowerframe.cc:2
 hshowerframe.cc:3
 hshowerframe.cc:4
 hshowerframe.cc:5
 hshowerframe.cc:6
 hshowerframe.cc:7
 hshowerframe.cc:8
 hshowerframe.cc:9
 hshowerframe.cc:10
 hshowerframe.cc:11
 hshowerframe.cc:12
 hshowerframe.cc:13
 hshowerframe.cc:14
 hshowerframe.cc:15
 hshowerframe.cc:16
 hshowerframe.cc:17
 hshowerframe.cc:18
 hshowerframe.cc:19
 hshowerframe.cc:20
 hshowerframe.cc:21
 hshowerframe.cc:22
 hshowerframe.cc:23
 hshowerframe.cc:24
 hshowerframe.cc:25
 hshowerframe.cc:26
 hshowerframe.cc:27
 hshowerframe.cc:28
 hshowerframe.cc:29
 hshowerframe.cc:30
 hshowerframe.cc:31
 hshowerframe.cc:32
 hshowerframe.cc:33
 hshowerframe.cc:34
 hshowerframe.cc:35
 hshowerframe.cc:36
 hshowerframe.cc:37
 hshowerframe.cc:38
 hshowerframe.cc:39
 hshowerframe.cc:40
 hshowerframe.cc:41
 hshowerframe.cc:42
 hshowerframe.cc:43
 hshowerframe.cc:44
 hshowerframe.cc:45
 hshowerframe.cc:46
 hshowerframe.cc:47
 hshowerframe.cc:48
 hshowerframe.cc:49
 hshowerframe.cc:50
 hshowerframe.cc:51
 hshowerframe.cc:52
 hshowerframe.cc:53
 hshowerframe.cc:54
 hshowerframe.cc:55
 hshowerframe.cc:56
 hshowerframe.cc:57
 hshowerframe.cc:58
 hshowerframe.cc:59
 hshowerframe.cc:60
 hshowerframe.cc:61
 hshowerframe.cc:62
 hshowerframe.cc:63
 hshowerframe.cc:64
 hshowerframe.cc:65
 hshowerframe.cc:66
 hshowerframe.cc:67
 hshowerframe.cc:68
 hshowerframe.cc:69
 hshowerframe.cc:70
 hshowerframe.cc:71
 hshowerframe.cc:72
 hshowerframe.cc:73
 hshowerframe.cc:74
 hshowerframe.cc:75
 hshowerframe.cc:76
 hshowerframe.cc:77
 hshowerframe.cc:78
 hshowerframe.cc:79
 hshowerframe.cc:80
 hshowerframe.cc:81
 hshowerframe.cc:82
 hshowerframe.cc:83
 hshowerframe.cc:84
 hshowerframe.cc:85
 hshowerframe.cc:86
 hshowerframe.cc:87
 hshowerframe.cc:88
 hshowerframe.cc:89
 hshowerframe.cc:90
 hshowerframe.cc:91
 hshowerframe.cc:92
 hshowerframe.cc:93
 hshowerframe.cc:94
 hshowerframe.cc:95
 hshowerframe.cc:96
 hshowerframe.cc:97
 hshowerframe.cc:98
 hshowerframe.cc:99
 hshowerframe.cc:100
 hshowerframe.cc:101
 hshowerframe.cc:102
 hshowerframe.cc:103
 hshowerframe.cc:104
 hshowerframe.cc:105
 hshowerframe.cc:106
 hshowerframe.cc:107
 hshowerframe.cc:108
 hshowerframe.cc:109
 hshowerframe.cc:110
 hshowerframe.cc:111
 hshowerframe.cc:112
 hshowerframe.cc:113
 hshowerframe.cc:114
 hshowerframe.cc:115
 hshowerframe.cc:116
 hshowerframe.cc:117
 hshowerframe.cc:118
 hshowerframe.cc:119
 hshowerframe.cc:120
 hshowerframe.cc:121
 hshowerframe.cc:122
 hshowerframe.cc:123
 hshowerframe.cc:124
 hshowerframe.cc:125
 hshowerframe.cc:126