Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

PipesOpticalAdaptor - source file

// ESAF : Euso Simulation and Analysis Framework
// $Id: PipesOpticalAdaptor.cc,v 1.15 2005/10/02 14:17:55 thea Exp $
// A.Thea created Nov,  8 2002

#include "PipesOpticalAdaptor.hh"
#include "Photomultiplier.hh"

using namespace sou;

ClassImp(PipesOpticalAdaptor)

int PipesOpticalAdaptor::_nrows = 0;
int PipesOpticalAdaptor::_npads = 0;
double PipesOpticalAdaptor::_pad_side=0.;
double PipesOpticalAdaptor::_bottom_inner_strip = 0.;
double PipesOpticalAdaptor::_bottom_pad_side = 0.;
EVector PipesOpticalAdaptor::_corners[10][10][2];

//______________________________________________________________________________
 PipesOpticalAdaptor::PipesOpticalAdaptor() {
    //
    // Constructor
    //
    
    if (_npads <= 0)
       SetPipesGeometry();

    fReflectivity = Conf()->GetNum("PipesOpticalAdaptor.fCathode.reflectivity");

    fSide=Conf()->GetNum("PipesOpticalAdaptor.fSide")*mm;
    fHeight=Conf()->GetNum("PipesOpticalAdaptor.fHeight")*mm;
}

//______________________________________________________________________________
 PipesOpticalAdaptor::~PipesOpticalAdaptor() {
    // 
    // Destructor
    // 
}

//______________________________________________________________________________
 void PipesOpticalAdaptor::SetPipesGeometry(){
    
    if (_npads == 0) {
       _nrows= (int) Conf()->GetNum("PipesOpticalAdaptor.size");
       _npads=_nrows*_nrows;
       _pad_side=fSide/(double)_nrows;
       _bottom_inner_strip=Conf()->GetNum("PipesOpticalAdaptor.bottom.inner.strip")*mm;
       _bottom_pad_side=Conf()->GetNum("PipesOpticalAdaptor.bottom.pad.side")*mm;
       
       EVector loc_par_X(1.,0.,0.);
       EVector loc_par_Y(0.,1.,0.);
       EVector loc_par_Z(0.,0.,1.);

       // computes the positon of the two corners
       EVector blu_corner= (fSide-(_bottom_pad_side*_nrows
		           +_bottom_inner_strip*(_nrows-1)))*0.5
	                   *(loc_par_X-loc_par_Y);
#ifdef DEBUG
       cout << "prova " << (fSide-(_bottom_pad_side*_nrows+_bottom_inner_strip*(_nrows-1)))*0.5 << "\n" <<
	       "blu_corner= " << blu_corner << endl;
#endif /* DEBUG */
       for(int row=0; row < _nrows; row++) {
          for(int col=0; col < _nrows; col++) {
	    
             _corners[row][col][0]=_pad_side*((col+1)*loc_par_X
			     -row*loc_par_Y)
		             +fHeight*loc_par_Z;

	     _corners[row][col][1]=blu_corner
		             +(_bottom_pad_side+_bottom_inner_strip)*col*loc_par_X
		             -(_bottom_pad_side*(row+1)+_bottom_inner_strip*row)*loc_par_Y;
	     
#ifdef DEBUG
	     if(row < 4 && col < 4){
	     cout << "_corner[" << row << "][" << col << "][1]=\n" <<
		     "X = " << _corners[row][col][1][X] << " mm\n" 
		     "Y = " << _corners[row][col][1][Y] << " mm\n" 
		     "Z = " << _corners[row][col][1][Z] << " mm\n" 
		     << endl;
	     }
#endif /* DEBUG */
	     
	  }
       }
    
    }
#ifdef DEBUG
    cout << "PipesOpticalAdaptor created\n" <<
	    "     fSide=" << fSide << "\n" <<
	    "     fHeight=" << fHeight << "\n" <<
	    "     size=" << _nrows << "\n" <<
	    "     inner strip="<< _bottom_inner_strip << "\n" <<
	    "     bottom pad side=" << _bottom_pad_side << endl;
#endif /* DEBUG */
  	
}


//______________________________________________________________________________
 Photon *PipesOpticalAdaptor::Transport(Photon *p) const {

	EVector lpos=p->pos-fPos;
	lpos=goLocal(lpos);

	int hitFace = whichFace(p);
	int row, col;
	
	
	if (hitFace==TOP) {
#ifdef DEBUG
	cout << "PipesOpticalAdaptorTransport: hitface = TOP\n" <<
	       	"Hit coordinates (local): X=" << lpos[X] << " mm Y=" << lpos[Y] << " mm" << endl;
#endif /* DEBUG */
	   row=0;
	   for(col=0; col<_nrows;col++){
#ifdef DEBUG
		  cout << "col: lpos[X]=" << lpos[X] << " bounds: " << _corners[row][col][0][X]-_pad_side << "<X <" << _corners[row][col][0][X] << endl;
#endif /* DEBUG */ 
	      if (lpos[X] >= _corners[row][col][0][X]-_pad_side
	          && lpos[X] < _corners[row][col][0][X]) break;
	      }
	   for(row=0; row<_nrows;row++){
#ifdef DEBUG
		  cout << "row: lpos[Y]=" << lpos[Y] << " bounds: " << _corners[row][col][0][Y]-_pad_side << "<X <" << _corners[row][col][0][Y] << endl;
#endif /* DEBUG */ 
	      if(lpos[Y] >= _corners[row][col][0][Y]-_pad_side
	          && lpos[Y] < _corners[row][col][0][Y]
	          ) break;
	   }
	
	} else if (hitFace == BOTTOM) {
#ifdef DEBUG
	cout << "PipesOpticalAdaptorTransport: hitface = BOTTOM" << endl;
#endif /* DEBUG */
	  row=0;
	  for(col=0; col<_nrows;col++)
	      if (lpos[X] >= _corners[row][col][1][X]
	         && lpos[X] < _corners[row][col][1][X]+_bottom_pad_side) break;
	  for(row=0; row<_nrows;row++)
              if (lpos[Y] >= _corners[row][col][1][Y] 
	          && lpos[Y] < _corners[row][col][1][Y]-_bottom_pad_side) break;
	} else {
          cerr<<"warning: photon on OpticalAdaptor edge. Killed"<<endl;
	  return 0; // wrong face 
	}
#ifdef DEBUG
	cout << "     Pipe hit: row =" << row << " col =" << col << endl;
#endif /* DEBUG */
	
	if (row==_nrows || col==_nrows) {
          cerr<<"warning: photon on OpticalAdaptor edge. Killed"<<endl;
	  return 0; // wrong face 
	}
	
	EVector c1=goGlobal(_corners[row][col][0])+fPos;
	EVector c2=goGlobal(_corners[row][col][1])+fPos;
#ifdef DEBUG
	cout << "Creating LightPipe"<< endl;
	cout << "   pos=" << fPos << "\n"
	     << "   row=" << row << " col=" << col << "\n"
	     << "   corner[0]=" << _corners[row][col][0] << "\n"
	     << "   corner[1]=" << _corners[row][col][1] << "\n"
	     << "   c1=" << c1 << "\n"
             << "   c2=" << c2 << "\n"
	     << "   pad side=" << _pad_side << "\n"
	     << "   bottom pad side=" << _bottom_pad_side << endl;
		
#endif /* DEBUG */
	LightPipe pipe(c1, c2, _pad_side, _pad_side, _bottom_pad_side, _bottom_pad_side, pmt);
	p=pipe.Transport(p);

	hitFace=whichFace(p);
	if (hitFace==TOP){
	   return p;
	} else if (hitFace==BOTTOM){
	   if (isReflectedByCathode()) {
                        EVector ldir=goLocal(p->dir);
                        ldir[Z] *= -1;
                        p->dir=goGlobal(ldir);
                        p->MChit=false;
                        p->hit=false;
                        return Transport(p);
	   }

         // Add photon to PMT
         if(!pmt->Pmt()->Add(*p)) {
#ifdef DEBUG
            cout<<"photon rejected by PMT"<<endl;
#endif /* DEBUG */
         } else {
#ifdef DEBUG
            cout<<"photon accepted by PMT"<<endl;
#endif /* DEBUG */
         }
                
         return 0;
	   
	}
	return 0;
}


About Us | EUSO Official Website | Web pages created by Roberto Pesce and Alessandro Thea - Last Update Wed Nov 16 16:57:39 2005 Wed Nov 16 16:29:22 2005