// ESAF : Euso Simulation and Analysis Framework
// $Id: EAtmosphereSingleAdder.cc,v 1.20 2005/10/28 17:19:53 moreggia Exp $
// Author: Anne Stutz Aug, 9 2004
#include "EAtmosphereSingleAdder.hh"
#include "EEvent.hh"
#include "EAtmosphere.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.SetOutFoV(false);
sp.SetTof(fSingle->Tof());
sp.SetNbinter(fSingle->NbOfInteractions());
sp.SetNbMaxInter(atm->GetMaxScatOrder());
// single photon obtained from a bunch
if ( fFromBunch ) {
EBunchPhotons& bp = *(EBunchPhotons*)(*(atm->fBunches))[fSingle->BunchId()-1];
bp.AddSingleRef(&sp);
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(fSingle->IsOutFoV()) sp.SetOutFoV();
sp.SetNbinter(fSingle->NbOfInteractions());
for(UInt_t m=0; m<fSingle->GetHistories().size();m++) sp.SetAllHistory(m,fSingle->GetHistories()[m]);
sp.SetLastTrans(fSingle->GetLastTrans("tot"),TString("tot"));
sp.SetLastTrans(fSingle->GetLastTrans("rayl"),TString("rayl"));
sp.SetLastTrans(fSingle->GetLastTrans("ozone"),TString("ozone"));
sp.SetLastTrans(fSingle->GetLastTrans("aero"),TString("aero"));
sp.SetLastTrans(fSingle->GetLastTrans("cloud"),TString("cloud"));
}
}