source: JEM-EUSO/esaf_lal/branches/camille/packages/simulation/detector/G4Detector/optics/src/G4Detector.cc @ 184

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

changes from biktem r:3032

File size: 4.7 KB
Line 
1#include "G4Detector.hh"
2
3#include "Detector.hh"
4#include "EusoMapping.hh"
5#include "DetectorGeometry.hh"
6#include "VirtualDetectorTransportManager.hh"
7#include "ElectronicsFactory.hh"
8#include "ERunParameters.hh"
9#include "ERunParsPixelMapFiller.hh"
10#include "ERunParsPmtsFiller.hh"
11#include "EusoElectronics.hh"
12#include "OpticsFactory.hh"
13#include "Pupil.hh"
14#include "ParentPhoton.hh"
15#include "Photon.hh"
16
17#include <TMath.h>
18#include <TFile.h>
19using namespace sou;
20
21//______________________________________________________________________________
22G4Detector::G4Detector() : fElectronics(0) {
23    //
24    // Constructor
25    //
26    // FIXME: call the factories to get the right associate child and parent
27    // classes in config
28    ElectronicsFactory::Get();
29    OpticsFactory::Get();
30    EusoMapping::Get();
31    Build();
32    SetSender("G4Detector");
33    MsgForm(EsafMsg::Info,"Creating G4Detector.");
34}
35
36//______________________________________________________________________________
37G4Detector::~G4Detector() {
38    //
39    // Destructor
40    //
41    if (fGeometry)
42        delete fGeometry;
43    if (fDetectorTransporter)
44        delete fDetectorTransporter;
45    ElectronicsFactory::Get()->DeleteEusoElectronics();
46}
47
48//______________________________________________________________________________
49void G4Detector::Build() {
50    //
51    // Build or re-build the detector
52    //
53    fGeometry = new DetectorGeometry();
54    fGeometry->SetFoV(Pi()/6.);
55
56    Msg(EsafMsg::Info)  << "Creating G4DetectorTransporter." << MsgDispatch;
57    fDetectorTransporter = OpticsFactory::Get()->MakeTransportManager();
58    fElectronics = ElectronicsFactory::Get()->Build();
59
60    Double_t scale = Conf()->GetNum("G4Detector.fScaleFactor");
61    Double_t radius;
62    if ( Conf()->GetBool("G4Detector.fFixMaxRadius") )
63         radius = Conf()->GetNum("G4Detector.fMaxRadius");
64    else radius = fDetectorTransporter->GetOuterRadius();
65
66    fGeometry->SetRadius(scale*radius);
67    fDetectorTransporter->SetScaleFactor(scale);
68
69    // save run parameters
70    if ( EEvent::GetCurrent() && EEvent::GetCurrent()->GetRunPars() ) {
71        ERunParameters *runpars = EEvent::GetCurrent()->GetRunPars();
72
73        fElectronics->SetDetectorScaleFactor(scale);
74        fElectronics->BuildBackgroundChipDist();
75
76        if ( runpars ) {
77            // get from EusoMapping the config
78            ERunParsPixelMapFiller pxfiller;
79            runpars->Fill(pxfiller);
80
81            ERunParsPmtsFiller pmtfiller( fElectronics );
82            runpars->Fill(pmtfiller);
83        }
84    }
85    fDetectorTransporter->GetFocalPlane()->SetElectronics(fElectronics);
86}
87
88void G4Detector::Reset() {
89    //
90    // Reset electronics
91    //
92
93    if ( fElectronics )
94        fElectronics->Reset();
95}
96
97Telemetry* G4Detector::Get( PhotonsOnPupil* photons ) {
98    //
99    // Simulate one event and return a pointer to a Telemetry object
100    //
101
102
103    // wrapper to track the photons onto the real pupil
104   
105//     TFile f("output/event.root","RECREATE");
106   
107    Pupil pupil( photons, GetGeometry());
108/*             
109                TTree* t = new TTree("t","tt");
110                Photon* photon =0;
111                ParentPhoton* pp =0;*/
112
113//              TVector3 vpos(0.,0.,0.);
114//              TVector3 vdir(0.,0.,0.);
115//             
116//              t->Branch("position","TVector3",&vpos);
117//              t->Branch("direction","TVector3",&vdir);
118//              t->Branch("wl",&wl,"w/D");
119//              t->Branch("flag",&fl,"flag/I");
120
121//              t->Branch("photon","ParentPhoton",&pp);
122    if(pupil.GetNphotons()==0) Msg(EsafMsg::Warning)  << "NO PHOTONS ON PUPIL !!!"<< MsgDispatch;
123    else {Msg(EsafMsg::Info)  << "PHOTONS ON PUPIL: "<<pupil.GetNphotons()<< MsgDispatch;
124//                      photon = pupil.GetPhoton();
125//                      pp=photon->parent;
126//                      printf("www  %g\n",pp->W());
127//                      int id=0;
128//                     
129//                while(id<pupil.GetNphotons()){
130//                              photon->id = id;
131//                              t->Fill();
132//                             
133//                              photon = pupil.GetPhoton();
134//                              if(photon){
135//                                      pp=photon->parent;
136//                                      printf("www  %g\n",pp->W());
137//                                     
138//                              }
139//                              id++;
140//      //                      photon->Dump();
141//                     
142//                      }
143//                      f.Write();
144//                      f.Close();
145                }
146
147    // transport photons from pupil to pmts
148    fDetectorTransporter->Go( &pupil );
149
150    Double_t tBegin = fDetectorTransporter->GetTimeFirstPhoton();
151    Double_t tEnd = fDetectorTransporter->GetTimeLastPhoton();
152
153    MsgForm(EsafMsg::Info,"Photon Time interval (ns):\t\tSTART=%ld  END=%ld",
154            (long int)(tBegin), (long int)tEnd);
155
156    // simulate electronics and trigger
157    if ( !fElectronics->Simulate( tBegin, tEnd ) )
158        return (Telemetry*)0;
159
160    // return telemetry object
161    return fElectronics->Data();
162
163}
164
165
166//______________________________________________________________________________
167Bool_t G4Detector::ClearMemory() {
168    //
169    // Physically release the memory allocated by the arrays of this object
170    //
171
172    fElectronics->ClearMemory();
173
174    return kTRUE;
175}
Note: See TracBrowser for help on using the repository browser.