//
// $Id: TestOpticalAdaptor.cc,v 1.15 2004/12/23 00:39:46 thea Exp $
//
#include "TRotation.h"
#include "TestOpticalAdaptor.hh"
#include "OpticsFactory.hh"
#include "Photomultiplier.hh"
#include "TROOT.h"
#include "EEvent.hh"
ClassImp(TestOpticalAdaptor)
//______________________________________________________________________________
TestOpticalAdaptor::TestOpticalAdaptor() {
//
// Contructor
//
fReflectivity = Conf()->GetNum("TestOpticalAdaptor.fCathode.reflectivity");
fSide=Conf()->GetNum("TestOpticalAdaptor.fSide")*mm;
fHeight=Conf()->GetNum("TestOpticalAdaptor.fHeight")*mm;
}
//______________________________________________________________________________
Photon *TestOpticalAdaptor::Transport(Photon *p) const {
vector<EVector> ips=intPoints(p);
// find the hit position
int hitFace;
for(hitFace=0; hitFace<6; hitFace++)
if(isInside(ips[hitFace], hitFace)) break;
if(hitFace==6) {//throw runtime_error("TestOpticalAdaptor: shouldn't happen. no face hit");
cerr<<"warning: photon on OpticalAdaptor edge. Killed"<<endl;
return 0;
}
#ifdef DEBUG
cout<<"hit face: "<<hitFace<<endl;
cout<<"hit position (local): "<<ips[hitFace]<<endl;
#endif /* DEBUG */
EVector dummy=p->pos; // previous photon position
p->pos=goGlobal(ips[hitFace]);
p->pos+=fPos; // new photon position
p->time+=(p->pos-dummy).Mag()/c_light;
#ifdef DEBUG
cout<<"hit position (global): "<<p->pos<<endl;
#endif /* DEBUG */
if(hitFace==BOTTOM) {
// Cathode reflectivity
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;
}
if(hitFace==TOP) return p;
#ifdef DEBUG
cout<<"photon hit on OA side"<<endl;
#endif /* DEBUG */
const PmtGeometry *nearest=pmt->Nearest((OAFace)hitFace);
if(!nearest) {
// photon hit on PMT wall
#ifdef DEBUG
cout<<"photon destroyed, no nearest"<<endl;
#endif /* DEBUG */
// photon absorbed
return 0;
}
#ifdef DEBUG
cout<<"cur_PMT_Id: "<<pmt->Pmt()->Id()<<endl;
cout<<"near_PMT_Id: "<<nearest->Pmt()->Id()<<endl;
#endif
OpticalAdaptor *oa=nearest->GetOA();
// photon doesn't need to be propagated from one OA side to the
// other one because unlike PMTs they are stuck together
p=oa->Transport(p);
delete oa;
return p;
}