Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

EDetectorPhotonAdder - source file

// ESAF : Euso Simulation and Analysis Framework
// $Id: EDetectorPhotonAdder.cc,v 1.7 2005/10/24 10:40:26 pesce Exp $
// Alessandro Thea created Oct, 24 2003

#include "EDetectorPhotonAdder.hh"
#include "EEvent.hh"
#include "Etypes.hh"
#include "Photon.hh"
#include "PmtSignal.hh"
#include "ParentPhoton.hh"

#include "EDetector.hh"
#include "EDetPhoton.hh"

ClassImp(EDetectorPhotonAdder)

//______________________________________________________________________________
 EDetectorPhotonAdder::EDetectorPhotonAdder(Photon* ph, PmtSignal* s, Bool_t newph)
    : EFiller("EDetector") {
    // ctor
    
    fPhoton = ph;
    fSignal = s;
    fNewPh = newph;
    fPhotonHistory.Set(0);
}

//______________________________________________________________________________
 EDetectorPhotonAdder::EDetectorPhotonAdder(TArrayI arr)
    : EFiller("EDetector") {
    // ctor
    
    fPhoton = 0;
    fSignal = 0;
    fNewPh = kFALSE;
    fPhotonHistory = arr;
}

//______________________________________________________________________________
 EDetectorPhotonAdder::~EDetectorPhotonAdder() {
    // dtor

}

//______________________________________________________________________________
 void EDetectorPhotonAdder::Fill( EFillable* f ) {
    // filler
     
    EDetector *det;
    if ( !(det = dynamic_cast<EDetector*>(f)) ) {
        MsgForm(EsafMsg::Warning,"Fill(): f is not an EDetector* ");
        return; 
    }

    // increase the number of photons in the detector status
    EDetStatus *status = &(det->fStatus);

    // fill the photons history
    if ( fPhotonHistory.GetSize()!=0 ) {
        status->fPhotonHistory = fPhotonHistory;
        return;
    }
    
    if ( fNewPh ) status->fNumPhotons++;
    
    // if photons are disabled return
    if ( !det->IsPhotonFillable() ) return;

    if ( !fPhoton ) return;
    
    if ( fNewPh ) {
        if ( det->IsPhotonFillable() ) 
            // if photons filling is enabled add a new ph
            new ( (*(det->fPhotons))[det->fNumPhotons++] ) EDetPhoton();
        
        // otherwise save only the time of the first and the last one
        if ( fPhoton->time < det->fFirstTime ) 
            det->fFirstTime = fPhoton->time;
        if ( fPhoton->time > det->fLastTime ) 
            det->fLastTime = fPhoton->time;       
    }
    

    EDetPhoton& p = *(EDetPhoton*)(*(det->fPhotons))[det->fNumPhotons-1];
    
    // photon params at the pupil
    if ( fNewPh ) {
        p.fType = fPhoton->parent->Type();  // type of photon 
        p.fStatusBits = 0;         // flag to know if phtoton has generated signal 
        p.fShowerPosX = fPhoton->parent->ShowerPos()[X];  // X position of origin in shower
        p.fShowerPosY = fPhoton->parent->ShowerPos()[Y];  // Y position of origin in shower
        p.fShowerPosZ = fPhoton->parent->ShowerPos()[Z];  // Z position of origin in shower
        p.fTheta = fPhoton->dir.Theta();    // photon theta direction in Euso detector
        p.fPhi = fPhoton->dir.Phi();        //    "   phi       "      "   "     "
        p.fLambda = fPhoton->wl;            // photon wavelength
        p.fTime = fPhoton->time;            // photon time (detection)

        p.fPosX           = kHuge;      // X position of hit in focal surface
        p.fPosY           = kHuge;      // Y position of hit in focal surface
        p.fPosZ           = kHuge;      // Z position of hit in focal surface
        p.fIdealFocalPosX = kHuge;      // X position of hit in focal surface
        p.fIdealFocalPosY = kHuge;      // Y position of hit in focal surface
        p.fIdealFocalPosZ = kHuge;      // Z position of hit in focal surface

        p.fSignalId       = -1;         // id of pmt signal
        p.fCharge         = -1.e-12;    // charge in C
        p.fIPeak          = -1.e-6;     // peak current in Amps

        p.fHistory        = kNotInside; // code of the last position 
        p.fFate           = 0;          // 0 until the photon is alive

        p.fMacroCell      = 0;          // macrocell id (starts from 1)
        p.fFe             = 0;          // front end chip id (starts from 1)
        p.fXCell          = -1;         // macrocell X coordinate
        p.fYCell          = -1;         // macrocell Y coordinate

        p.fGtu            = -1;         // gtu reldetant for this photon
        p.fPixelUID       = -1;         // unique id of hit pixel
    }

    // impact point on focal plane 
    if ( fPhoton ) {
        p.fPosX = fPhoton->pos[X];
        p.fPosY = fPhoton->pos[Y];
        p.fPosZ = fPhoton->pos[Z];
        p.fIdealFocalPosX = fPhoton->posOnIfs[X];
        p.fIdealFocalPosY = fPhoton->posOnIfs[Y];
        p.fIdealFocalPosZ = fPhoton->posOnIfs[Z];

        if ( fPhoton->hitIfs ) p.SetCrossedIFS();
        
        p.fHistory = fPhoton->history;
        p.fPixelUID = fPhoton->pixelUid;
        p.fFate = fPhoton->fate;
    }

    // pmt response
    if ( fSignal ) {
        p.SetMadeSignal();
        
        p.fSignalId = fSignal->Id();
        p.fCharge = fSignal->Charge();
        p.fIPeak = fSignal->Current(fSignal->Time());
        p.fSignalTime = fSignal->Time();
    }
}
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