source: JEM-EUSO/esaf_cc_at_lal/packages/simulation/lighttoeuso/src/FileUnisimLightToEuso.cc @ 114

Last change on this file since 114 was 114, checked in by moretto, 11 years ago

actual version of ESAF at CCin2p3

File size: 4.1 KB
Line 
1// ESAF : Euso Simulation and Analysis Framework
2// $Id: FileUnisimLightToEuso.cc 2604 2006-03-20 21:51:35Z thea $
3// M. Pallavicini created Jul,  2 2002
4
5#include "FileUnisimLightToEuso.hh"
6#include "EEventTruthAdder.hh"
7#include "DetectorGeometry.hh"
8#include <zlib.h>
9
10using namespace sou;
11
12ClassImp(FileUnisimLightToEuso)
13
14//_________________________________________________________________________________________
15FileUnisimLightToEuso::FileUnisimLightToEuso() : LightToEuso("UNISIM_FILE"), fP(NULL), fTruth(0){
16    //
17    // Constructor
18    //
19    fName = "";
20    fFirstEvent = 0;
21    fCurrentEvent = 0;
22    fPhotons.SetZdisk( Conf()->GetNum("FileUnisimLightToEuso.fZdisk") );
23}
24
25//_________________________________________________________________________________________
26FileUnisimLightToEuso::~FileUnisimLightToEuso() {
27    //
28    // Destructor
29    //
30}
31
32//______________________________________________________________________________
33Bool_t FileUnisimLightToEuso::ClearMemory() {
34    //
35    //
36    //
37
38    fPhotons.ClearMemory();
39
40    return kTRUE;
41}
42
43//_________________________________________________________________________________________   
44void FileUnisimLightToEuso::ReplaceInputFile(const char* fn) {
45
46    if ( fP )
47        FatalError("FileUnisimLightToEuso: Cannot change name when file is already open!");
48    if (!fn) {
49        MsgForm(EsafMsg::Warning,"FileUnisimLightToEuso: NULL file name ignored");
50        return;
51    }
52    Conf()->ReplaceStr("FileUnisimLightToEuso.FileName",fn);
53    Msg(EsafMsg::Info) << "Input file name changed to " << fn << MsgDispatch;
54}
55
56
57//_________________________________________________________________________________________
58void FileUnisimLightToEuso::Open() {
59    //
60    // Open file
61    //
62
63    fName      = Conf()->GetStr("FileUnisimLightToEuso.fFileName");
64    fFirstEvent = (Int_t)Conf()->GetNum("FileUnisimLightToEuso.fFirstEvent") ;
65
66    if ( fFirstEvent < 0 ) {
67        Msg(EsafMsg::Warning) << "fFirstEvent < 0 in cfg file. Setting to 0." << MsgDispatch;
68        fFirstEvent = 0;
69    }
70
71    fP = (FILE*)gzopen( fName.c_str(), "rb" );
72
73    if( fP == NULL ) 
74        Msg(EsafMsg::Panic) << "Can't open file " << fName << MsgDispatch;
75    Msg(EsafMsg::Info) << "File: " << fName << " successfully opened " << MsgDispatch;
76}
77
78//_________________________________________________________________________________________
79PhotonsOnPupil *FileUnisimLightToEuso::Get(const DetectorGeometry* dg) {
80    //
81    // Returns the list of photons for the pupil
82    //
83    if ( !fP )
84        Open();   
85
86    EEvent* event = EEvent::GetCurrent();
87
88    // set the target's size
89    fPhotons.SetRmaxDisk( dg->GetRadius() );
90
91    while (1) { 
92        if (fCurrentEvent >= fFirstEvent)           
93            if ( fPhotons.Load( fP ) ) {
94                MCTruth *t = GetTruth();
95                if (event) {
96                    EEventTruthAdder a( t );
97                    event->Fill( a );
98                }
99                MsgForm(EsafMsg::Info,"Unisim Event %d: %d photons loaded:",
100                        fCurrentEvent, fPhotons.GetNphotons());
101                MsgForm(EsafMsg::Info,"    Energy %.2E MeV, Theta = %2f deg, Phi = %.2f deg",
102                        t->GetEnergy()/MeV, t->GetTheta()/deg, t->GetPhi()/deg);
103                MsgForm(EsafMsg::Info,"    at (%.2f,%.2f,%.2f) km",
104                        t->GetInitPos().X()/km,t->GetInitPos().Y()/km,t->GetInitPos().Z());
105                fCurrentEvent++;       
106                return &fPhotons;
107            }
108            else {
109                Msg(EsafMsg::Info) << "FileUnisimLightToEuso: End of file " << fName << " reached" << MsgDispatch;
110                return (UnisimPhotonsOnPupil*)0;
111            }
112        else {
113
114            if (!fPhotons.SkipEvent( fP )) {
115                Msg(EsafMsg::Info) << "FileUnisimLightToEuso: End of file " << fName << " reached" << MsgDispatch;
116                return (UnisimPhotonsOnPupil*)0;
117            }
118            fCurrentEvent++;
119        }
120
121    }
122}
123 
124//_________________________________________________________________________________________
125MCTruth* FileUnisimLightToEuso::GetTruth(){
126#ifdef debug
127    cout << fPhotons.Truth()->Dump() << endl;
128#endif
129    return fPhotons.Truth();
130}
131
132
Note: See TracBrowser for help on using the repository browser.