Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

EAtmosphereSingleAdder - source file

// ESAF : Euso Simulation and Analysis Framework
// $Id: EAtmosphereSingleAdder.cc,v 1.9 2004/12/16 15:12:36 stutz Exp $
// Author: Anne Stutz   Aug,  9 2004

#include "EAtmosphereSingleAdder.hh"
#include "EEvent.hh"
#include "SinglePhoton.hh"

#include <stdexcept>

#include "ESinglePhoton.hh"
#include "EBunchPhotons.hh"

ClassImp(EAtmosphereSingleAdder)

//_____________________________________________________________________________
EAtmosphereSingleAdder::EAtmosphereSingleAdder(const SinglePhoton* ph, Bool_t news, Bool_t fromb, Int_t count) : EFiller("EAtmosphere"){
    //
    // Constructor
    //
    fSingle = ph;
    fNewSingle = news;
    fFromBunch = fromb;
    fCounter = count;
}

//_____________________________________________________________________________
EAtmosphereSingleAdder::~EAtmosphereSingleAdder() {
    //
    // Destructor
    //
}

//_____________________________________________________________________________
 void EAtmosphereSingleAdder::Fill( EFillable* f) {
    // 
    // fill the root file
    //
    EAtmosphere *atm = (EAtmosphere*)f;

    if ( !fSingle ) return;
   
    if ( fNewSingle ) {
        // new single photon
        if(fCounter !=0 ) throw runtime_error("EAtmosphereSingleAdder cannot add a new Single Photon");
        atm->fNumSingles++;
        new ( (*(atm->fSingles))[atm->fNumSingles-1] ) ESinglePhoton() ;

        // single parameters at the creation point
        ESinglePhoton& sp = *(ESinglePhoton*)(*(atm->fSingles))[atm->fNumSingles-1];

        sp.SetType( fSingle->Type() );
        sp.SetWl( fSingle->Wl() );
	sp.SetShowerPos( fSingle->ShowerPos() );
        sp.SetPos( fSingle->Pos() );
        sp.SetHistory( fSingle->Status() );
	sp.SetDate( fSingle->Date() );
	sp.SetBunchId( fSingle->BunchId() );
	sp.SetAbsorbed(false);
	sp.SetTof(0);
	sp.SetNbinter(0);
        
        // single photon obtained from a bunch
        if ( fFromBunch ) {
            EBunchPhotons& bp = *(EBunchPhotons*)(*(atm->fBunches))[atm->fNumBunches-1];
            bp.fNumSingles++;
            if( fSingle->Type()==0) bp.fNumDir++;
            else if (fSingle->Type()==1 ) bp.fNumRef++;
            else if (fSingle->Type()==2 ) bp.fNumBack++;
	    if(sp.GetBunchId() != bp.GetId()) throw runtime_error("<EAtmosphereSingleAdder::Fill> -> wrong identification Single/Bunch");
        }
   }

    else {
        if ( fCounter >(atm->fNumSingles) ) throw runtime_error("EAtmosphereSingleAdder fCounter greater than fNumsingles");
        fCounter++;
        ESinglePhoton& sp = *(ESinglePhoton*)(*(atm->fSingles))[fCounter-1];
        sp.SetTof(fSingle->Tof());
	if(fSingle->IsAbsorbed()) {
	    sp.SetAbsorbed();
	    if(sp.GetType() == 0) sp.SetNbinter(1);   //TOFIX: if MScatt, need changes
	    else sp.SetNbinter(2);                    //TOFIX: if MScatt, need changes
        }
	else if(sp.GetType() == 0)sp.SetNbinter(0);
	else sp.SetNbinter(1);
    }
}
About Us | EUSO Official Website | Web pages created by Roberto Pesce and Alessandro Thea - Last Update 14-May-2005 21:31