Universita' di GenovaINFN Sezione di Genova  
AIRWATCH / EUSO Genova

PhPRootFileLightToEuso - source file

// $Id: PhPRootFileLightToEuso.cc,v 1.8 2005/07/08 14:59:12 thea 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 "DetectorGeometry.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.rfind(ext) != (fFileName.size()-ext.size()))
        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);
    Int_t nTransmitted = 0;

    // DEBUG
    // FILE* flog = fopen("php-out.log","w");
    // DEBUG

    for( Int_t i(0); i<fNumPhotons; i++) {

        EPhoton* ph = (EPhoton*)fPhotons->At(i);
        if (ph->GetPos().Mag() > dg->GetRadius() ) continue;

        ParentPhoton* parent = new ParentPhoton( i, v, ph->GetPos(), ph->GetTheta(),
                ph->GetPhi(), ph->GetLambda(), ph->GetTime(), (ParentPhotonType)ph->GetType()); 
        fPhotonsOnPupil->Add(parent);
        nTransmitted++;

        //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 %d, Transmitted %d",
            fNumPhotons, nTransmitted);

    // 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() );
    fMCTruth->SetHclouds( fTruth->GetTrueHclouds() );
    fMCTruth->SetCloudsthick( fTruth->GetTrueCloudsthick() );
    fMCTruth->SetCloudsOD( fTruth->GetTrueCloudsOD() );
    fMCTruth->SetLatitude( fTruth->GetTrueLatitude() );
    fMCTruth->SetLongitude( fTruth->GetTrueLongitude() );
    fMCTruth->SetDate( fTruth->GetTrueDate() );


    // save the truth
    EEvent* ev = EEvent::GetCurrent();
    if ( ev ) {
        EEventTruthAdder a( fMCTruth );
        ev->Fill(a);
    }

    fEvCounter++;

    return fPhotonsOnPupil;
}
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