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 | |
---|
15 | |
---|
16 | #include <TMath.h> |
---|
17 | |
---|
18 | using namespace sou; |
---|
19 | |
---|
20 | //______________________________________________________________________________ |
---|
21 | G4Detector::G4Detector() : fElectronics(0) { |
---|
22 | // |
---|
23 | // Constructor |
---|
24 | // |
---|
25 | // FIXME: call the factories to get the right associate child and parent |
---|
26 | // classes in config |
---|
27 | ElectronicsFactory::Get(); |
---|
28 | OpticsFactory::Get(); |
---|
29 | EusoMapping::Get(); |
---|
30 | Build(); |
---|
31 | SetSender("G4Detector"); |
---|
32 | MsgForm(EsafMsg::Info,"Creating G4Detector."); |
---|
33 | } |
---|
34 | |
---|
35 | //______________________________________________________________________________ |
---|
36 | G4Detector::~G4Detector() { |
---|
37 | // |
---|
38 | // Destructor |
---|
39 | // |
---|
40 | if (fGeometry) |
---|
41 | delete fGeometry; |
---|
42 | if (fDetectorTransporter) |
---|
43 | delete fDetectorTransporter; |
---|
44 | ElectronicsFactory::Get()->DeleteEusoElectronics(); |
---|
45 | } |
---|
46 | |
---|
47 | //______________________________________________________________________________ |
---|
48 | void G4Detector::Build() { |
---|
49 | // |
---|
50 | // Build or re-build the detector |
---|
51 | // |
---|
52 | fGeometry = new DetectorGeometry(); |
---|
53 | fGeometry->SetFoV(Pi()/6.); |
---|
54 | |
---|
55 | Msg(EsafMsg::Info) << "Creating G4DetectorTransporter." << MsgDispatch; |
---|
56 | fDetectorTransporter = OpticsFactory::Get()->MakeTransportManager(); |
---|
57 | fElectronics = ElectronicsFactory::Get()->Build(); |
---|
58 | |
---|
59 | Double_t scale = Conf()->GetNum("G4Detector.fScaleFactor"); |
---|
60 | Double_t radius; |
---|
61 | if ( Conf()->GetBool("G4Detector.fFixMaxRadius") ) |
---|
62 | radius = Conf()->GetNum("G4Detector.fMaxRadius"); |
---|
63 | else radius = fDetectorTransporter->GetOuterRadius(); |
---|
64 | |
---|
65 | fGeometry->SetRadius(scale*radius); |
---|
66 | fDetectorTransporter->SetScaleFactor(scale); |
---|
67 | |
---|
68 | // save run parameters |
---|
69 | if ( EEvent::GetCurrent() && EEvent::GetCurrent()->GetRunPars() ) { |
---|
70 | ERunParameters *runpars = EEvent::GetCurrent()->GetRunPars(); |
---|
71 | |
---|
72 | fElectronics->SetDetectorScaleFactor(scale); |
---|
73 | fElectronics->BuildBackgroundChipDist(); |
---|
74 | |
---|
75 | if ( runpars ) { |
---|
76 | // get from EusoMapping the config |
---|
77 | ERunParsPixelMapFiller pxfiller; |
---|
78 | runpars->Fill(pxfiller); |
---|
79 | |
---|
80 | ERunParsPmtsFiller pmtfiller( fElectronics ); |
---|
81 | runpars->Fill(pmtfiller); |
---|
82 | } |
---|
83 | } |
---|
84 | fDetectorTransporter->GetFocalPlane()->SetElectronics(fElectronics); |
---|
85 | } |
---|
86 | |
---|
87 | void G4Detector::Reset() { |
---|
88 | // |
---|
89 | // Reset electronics |
---|
90 | // |
---|
91 | |
---|
92 | if ( fElectronics ) |
---|
93 | fElectronics->Reset(); |
---|
94 | } |
---|
95 | |
---|
96 | Telemetry* G4Detector::Get( PhotonsOnPupil* photons ) { |
---|
97 | // |
---|
98 | // Simulate one event and return a pointer to a Telemetry object |
---|
99 | // |
---|
100 | |
---|
101 | |
---|
102 | // wrapper to track the photons onto the real pupil |
---|
103 | Pupil pupil( photons, GetGeometry()); |
---|
104 | |
---|
105 | if(pupil.GetNphotons()==0) Msg(EsafMsg::Warning) << "NO PHOTONS ON PUPIL !!!"<< MsgDispatch; |
---|
106 | else Msg(EsafMsg::Info) << "PHOTONS ON PUPIL: "<<pupil.GetNphotons()<< MsgDispatch; |
---|
107 | |
---|
108 | // transport photons from pupil to pmts |
---|
109 | fDetectorTransporter->Go( &pupil ); |
---|
110 | |
---|
111 | Double_t tBegin = fDetectorTransporter->GetTimeFirstPhoton(); |
---|
112 | Double_t tEnd = fDetectorTransporter->GetTimeLastPhoton(); |
---|
113 | |
---|
114 | MsgForm(EsafMsg::Info,"Photon Time interval (ns):\t\tSTART=%ld END=%ld", |
---|
115 | (long int)(tBegin), (long int)tEnd); |
---|
116 | |
---|
117 | // simulate electronics and trigger |
---|
118 | if ( !fElectronics->Simulate( tBegin, tEnd ) ) |
---|
119 | return (Telemetry*)0; |
---|
120 | |
---|
121 | // return telemetry object |
---|
122 | return fElectronics->Data(); |
---|
123 | |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | //______________________________________________________________________________ |
---|
128 | Bool_t G4Detector::ClearMemory() { |
---|
129 | // |
---|
130 | // Physically release the memory allocated by the arrays of this object |
---|
131 | // |
---|
132 | |
---|
133 | fElectronics->ClearMemory(); |
---|
134 | |
---|
135 | return kTRUE; |
---|
136 | } |
---|