// ESAF : Euso Simulation and Analysis Framework
// class FastFocalPlane
// $Id: FastFocalPlane.cc,v 1.33 2005/05/04 14:25:52 moreggia Exp $
//
#include <math.h>
#include "FastFocalPlane.hh"
#include "ElectronicsFactory.hh"
#include "EusoElectronics.hh"
#include "MacroCell.hh"
#include "Photomultiplier.hh"
#include "PmtGeometry.hh"
#include "Config.hh"
#include "IdealFocalSurface.hh"
#include "Etypes.hh"
ClassImp(FastFocalPlane)
//______________________________________________________________________________
FastFocalPlane::FastFocalPlane() {
//
// Constructor
//
}
//______________________________________________________________________________
FastFocalPlane::~FastFocalPlane() {
//
// Destructor
//
}
//______________________________________________________________________________
Photon *FastFocalPlane::Transport(Photon *p) const {
//
// Transport the photon through the optics
//
if (!fElectronics)
FatalError("No electronics defined.");
// photon position relative to local coordinate system
p->pos -= fPos;
MacroCellGeometry *g;
Photon *pOld = p;
for(Int_t i=0; i<fElectronics->NumCell(); i++) {
g=fElectronics->Cell(i)->Geometry();
if ( ( g->IsHit( *p ) ) > kTolerance ){
p = HitMC( p, g );
// photon can be either dead
if (!p) {
pOld->pos += fPos;
return 0;
}
// or can have reached successfully a macrocell
if ( p->MChit) {
p->pos += fPos;
return p;
}
}
}
if(p && !p->MChit) {
if(p->dir[Z] > 0) {
// photon going up
p->pos += fPos;
Double_t DL = CylinderIntersection( p );
if ( DL < kTolerance ) {
p->history = kWalls;
return 0;
}
p->pos+=DL*p->dir.Unit();
p->time+=DL/c_light;
p->history = kWalls;
return 0;
} else {
// reflected photon
EVector dummy=p->dir*((p->pos[Z]-Bottom())/fabs(p->dir[Z]));
p->pos+=dummy;
p->time+=dummy.Mag()/c_light;
p->pos[Z]=Bottom();
p->pos += fPos;
return p;
}
}
return 0;
}
//______________________________________________________________________________
Photon* FastFocalPlane::HitMC(Photon *p, MacroCellGeometry *g) const {
Photomultiplier *HitPMT = g->FindHitPmt( *p );
if (!HitPMT)
return p;
p->MChit=true;
Double_t DL = HitPMT->Geometry()->GetOA()->IsHit(*p);
p->pos+=p->dir.Unit()*DL;
p->time+=DL/c_light;
p->hit=true;
#ifdef DEBUG
cout<<"-------- MACROCELL HIT ---------"<<endl;
//cout<<"Hit MacroCell "<<i<<endl;
cout<<"position = "<<p->pos<<endl;
cout<<"relposition = "<<p->pos-g->GetCenter()<<endl;
cout<<"g->GetNormal() = "<<g->GetNormal()<<endl;
cout<<"direction = "<<p->dir<<endl;
if(HitPMT) {
cout<<"Hit PMT "<<HitPMT->Id()<<endl;
cout <<"Hit PMT position "<<HitPMT->Geometry()->Position()<<endl;
cout <<"Hit PMT distance "<< DL <<endl;
} else {
cout<<"missed PMT"<<endl;
}
#endif /* DEBUG */
p=HitPMT->Geometry()->GetOA()->Transport(p);
// when we get here there are two possibility:
// p==0 if the photon is not reflected by the cathode
// p!=0 if the photon is reflected back
if(p){
#ifdef DEBUG
cerr<<"FastFocalPlane: photon reflected back by the chatode"<<endl;
#endif /* DEBUG */
p=Transport(p);
}
return p;
}