// class ElementaryCell
// $Id: ElementaryCell.cc,v 1.6 2004/08/01 11:31:37 thea Exp $
// M. Pallavicini - created 10-10-03
//
#include "euso.hh"
#include "utils.hh"
#include "ElementaryCell.hh"
#include "PmtGeometry.hh"
#include "FrontEndChip.hh"
ClassImp(ElementaryCell)
int ElementaryCell::gElemCellCounter = 1;
// ctor
ElementaryCell::ElementaryCell() {
}
// dtor
ElementaryCell::~ElementaryCell() {
}
// associate PMTS and compute geometry
void ElementaryCell::AssociatePmts(Photomultiplier *p1, Photomultiplier *p2,
Photomultiplier *p3, Photomultiplier *p4) {
fId = gElemCellCounter++;
if ( !p1 ) {
throw runtime_error("Wrong PMT association in ElementaryCell::AssociatePmts");
}
pPmts[0] = p1;
pPmts[1] = p2;
pPmts[2] = p3;
pPmts[3] = p4;
if ( p1 && !p2 && !p3 && !p4 )
fNumPmts = 1;
else if ( p1 && p2 && p3 && p4 )
fNumPmts = 4;
else
throw runtime_error( "Wrong PMT number in ElementaryCell::AssociatePmts. Can be 1 or 4");
for( int i(0); i<fNumPmts; i++)
pPmts[i]->SetElemCell(this);
// get PmtGeometry pointers and check that FrontEndChip
// attached to these PMTs is unique
PmtGeometry *g[4];
for(int i=0; i<4; i++) {
g[i] = NULL;
if ( pPmts[i] ) {
g[i] = pPmts[i]->Geometry();
if ( pPmts[0]->FrontEnd() != pPmts[i]->FrontEnd() ) {
throw runtime_error("Front End Chip must be unique in ElementaryCell::AssociatePmts()");
}
}
}
// check if normal vectors are parallel (Elementary Cell MUST be planar!)
for(int i=1; i<4; i++) {
if ( g[i] ) {
double s = fabs( g[0]->Normal().Unit().Dot( g[i]->Normal().Unit() ) - 1. );
if ( s > 0.0001 ) {
throw runtime_error("Non planar PMTs in ElementaryCell::AssociatePmts()");
}
}
}
fNormal = g[0]->Normal().Unit();
// check if PMTs are in the right order: 1,2,3,4 counter-clockwise, 1 top-left
// 1 2
// 3 4
// to be done, now assume they are right...
// compute ElementaryCell corners: PMTs can be one or four...
fUpLeft = g[0]->Position();
if ( g[1] ) {
fUpRight = g[1]->Position() + ( g[1]->GetX() * g[1]->Side() );
}
else {
fUpRight = g[0]->Position() + ( g[0]->GetX() * g[0]->Side() );
}
if ( g[2] ) {
fDownLeft = g[2]->Position() - ( g[2]->GetY() * g[2]->Side() ); // Y axis is upward!
}
else {
fDownLeft = g[0]->Position() - ( g[0]->GetY() * g[0]->Side() ); // Y axis is upward!
}
if ( g[3] ) {
fDownRight = g[3]->Position() + ( g[3]->GetX() * g[3]->Side() )
- ( g[3]->GetY() * g[3]->Side() ); // Y axis is upward!
}
else {
fDownRight = g[0]->Position() + ( g[0]->GetX() * g[0]->Side() )
- ( g[0]->GetY() * g[0]->Side() ); // Y axis is upward!
}
// get the axis from the first pmt
fXAxis = g[0]->GetX();
fYAxis = g[0]->GetY();
}
// get central position
EVector ElementaryCell::GetCenter() const {
EVector center = GetUpLeft() + GetUpRight() + GetDownLeft() + GetDownRight();
double a = 0.25000000000000000000;
center *= a;
return center;
}