// $Id: PhPRootFileLightToEuso.cc,v 1.4 2005/04/14 12:43:24 moreggia Exp $
// Author: Alessandro Thea 2005/02/14
/*****************************************************************************
* ESAF: Euso Simulation and Analysis Framework *
* *
* Id: PhPRootFileLightToEuso *
* Package: <packagename> *
* Coordinator: <coordinator> *
* *
*****************************************************************************/
//_____________________________________________________________________________
//
// PhPRootFileLightToEuso
//
// <extensive class description>
//
// Config file parameters
// ======================
//
// <parameter name>: <parameter description>
// -Valid options: <available options>
//
#include "PhPRootFileLightToEuso.hh"
#include "MCTruth.hh"
#include "ETruth.hh"
#include "ListPhotonsOnPupil.hh"
#include "EPhoton.hh"
#include "EEvent.hh"
#include "EEventTruthAdder.hh"
#include <TTree.h>
#include <TFile.h>
#include <TClonesArray.h>
// DEBUG
// #include "stdio.h"
// DEBUG
ClassImp(PhPRootFileLightToEuso)
using namespace TMath;
//_____________________________________________________________________________
PhPRootFileLightToEuso::PhPRootFileLightToEuso() : LightToEuso("PHPROOTFILE"),
fTruth(0), fNumPhotons(0), fPhotons(0) {
//
// Constructor
//
fFileName = Conf()->GetStr("PhPRootFileLightToEuso.fFileName");
fFirstEvent = (Long64_t)Conf()->GetNum("PhPRootFileLightToEuso.fFirstEvent") ;
fMCTruth = new MCTruth;
fPhotonsOnPupil = new ListPhotonsOnPupil();
Init();
}
//_____________________________________________________________________________
PhPRootFileLightToEuso::~PhPRootFileLightToEuso() {
//
// Destructor
//
SafeDelete( fFile );
SafeDelete( fPhotonsOnPupil );
SafeDelete( fMCTruth );
SafeDelete( fTruth );
SafeDelete( fPhotons );
}
//______________________________________________________________________________
void PhPRootFileLightToEuso::Init() {
//
// Open file and associate objects
//
string ext = ".php.root";
if (fFileName.find(ext) != (fFileName.size()-8))
fFileName += ext;
fFile = new TFile(fFileName.c_str());
if ( fFile->IsZombie() )
FatalError("Unable to open "+fFileName);
if (!(fTree = (TTree*)fFile->Get("PhPTree")))
FatalError("No PhPTree in "+fFileName);
fTree->SetBranchAddress("EPhotons",&fPhotons);
fTree->SetBranchAddress("ENumPhotons",&fNumPhotons);
fTree->SetBranchAddress("ETruth",&fTruth);
fEvCounter = fFirstEvent;
}
//______________________________________________________________________________
PhotonsOnPupil* PhPRootFileLightToEuso::Get(const DetectorGeometry* dg) {
//
// Reads file and creates the list of photons
//
fPhotonsOnPupil->Clear();
fMCTruth->Clear();
if ( fEvCounter >= fTree->GetEntriesFast() )
return 0;
fTree->GetEntry(fEvCounter++);
if ( fNumPhotons != fPhotons->GetEntries())
MsgForm(EsafMsg::Warning,"Mismatch between EPhotons size and ENumPhotons",
fNumPhotons, fPhotons->GetEntries());
TVector3 v(0,0,0);
// DEBUG
// FILE* flog = fopen("php-out.log","w");
// DEBUG
for( Int_t i(0); i<fNumPhotons; i++) {
EPhoton* ph = (EPhoton*)fPhotons->At(i);
ParentPhoton* parent = new ParentPhoton( i, v, ph->GetPos(), ph->GetTheta(),
ph->GetPhi(), ph->GetLambda(), ph->GetTime(), (ParentPhotonType)ph->GetType());
fPhotonsOnPupil->Add(parent);
//Photon& p=parent->GetPhoton();
// DEBUG
// fprintf(flog,"%d %.3f %.3f %.3f %.3f %.3f %.3f %.3fn",
// p.parent->Type(), p.dir.Theta()/deg, p.dir.Phi()/deg, p.wl/nm, p.time/ns,
// p.pos.X(), p.pos.Y(), p.pos.Z());
// DEBUG
}
// DEBUG
// fclose(flog);
// DEBUG
MsgForm(EsafMsg::Info,"PhP event %d read", fEvCounter);
MsgForm(EsafMsg::Info," Energy: %.3g MeV ParticleCode: %d",
fTruth->GetTrueEnergy(), fTruth->GetTrueParticleCode());
MsgForm(EsafMsg::Info," Theta: %.3f Phi: %.3f", fTruth->GetTrueTheta()*RadToDeg(),
fTruth->GetTruePhi()*RadToDeg());
MsgForm(EsafMsg::Info," NumPhotons %.3d", fNumPhotons);
// copy ETruth in MCTruth
fMCTruth->SetEnergy( fTruth->GetTrueEnergy() );
fMCTruth->SetThetaPhi( fTruth->GetTrueTheta(), fTruth->GetTruePhi() );
fMCTruth->SetParticle( fTruth->GetTrueParticleCode() );
fMCTruth->SetFirstInt( fTruth->GetTrueInitPos(), fTruth->GetTrueX1() );
fMCTruth->SetEarthImpact( fTruth->GetTrueEarthImpact(), fTruth->GetTrueEarthAge() );
fMCTruth->SetShowerMax( fTruth->GetTrueShowerMaxPos(), fTruth->GetTrueShowerXMax() );
// save the truth
EEvent* ev = EEvent::GetCurrent();
if ( ev ) {
EEventTruthAdder a( fMCTruth );
ev->Fill(a);
}
return fPhotonsOnPupil;
}