RayTracer.cc
Go to the documentation of this file.
1 #include "RayTracer.h"
2 #include "Filter.h"
3 #include "Lens.h"
4 #include "Mirror.h"
5 #include "Camera.h"
6 
7 #include <fdet/Telescope.h>
8 
9 #include <utl/RandomEngine.h>
10 #include <utl/Photon.h>
11 
12 #include <fwk/RunController.h>
13 #include <evt/Event.h>
14 #include <evt/Header.h>
15 
16 #include <TPolyLine3D.h>
17 #include <TCanvas.h>
18 #include <TObjArray.h>
19 #include <TFile.h>
20 #include <TRandom.h>
21 
22 #include <string>
23 #include <iostream>
24 
25 using namespace std;
26 using namespace TelescopeSimulatorKG;
27 
29 
30 
31 RayTracer::RayTracer(const fdet::Telescope& tel,
32  utl::RandomEngine& random,
33  bool doShadow,
34  bool doShadowSupport,
35  bool hasMercedes,
36  bool plotPhotonTracks,
37  double drawPhotonsProbabilty)
38  : fTel(&tel),
39  fRandom(&random),
40  fDoShadow(doShadow),
41  fDoShadowSupport(doShadowSupport),
42  fHasMercedes(hasMercedes),
43  fPlotPhotonTracks(plotPhotonTracks),
44  fDrawPhotonProbability(drawPhotonsProbabilty) {
45 
47 
48  fFilter = new Filter(random, tel);
49  fLens = new Lens(random, tel);
50  fMirror = new Mirror(random, tel);
51  fCamera = new Camera(random, tel);
52 
53  if (plotPhotonTracks)
54  fObjectsPhotons = new TObjArray(100);
55 }
56 
57 
59 
60  if (fPlotPhotonTracks) {
61  ostringstream fnameBase, fnameRoot, fnameCanvas;
62  const string id = fwk::RunController::GetInstance().GetCurrentEvent().GetHeader().GetId();
63  fnameBase << "raytrace_" << id
64  << "_Eye" << fTel->GetEyeId()
65  << "_Tel" << fTel->GetId();
66  fnameRoot << fnameBase.str() << ".root";
67  fnameCanvas << fnameBase.str() << ".eps";
68  TCanvas c("view3d");
69  //TObjArray* objectsCamera = fCamera->Draw();
70  //TObjArray* objectsLens = fLens->Draw();
71  //TObjArray* objectsMirror = fMirror->Draw();
72  //TObjArray* objectsFilter = fFilter->Draw();
73  for (int iObj=0; iObj < fObjectsPhotons->GetEntriesFast(); ++iObj) {
74  TPolyLine3D* photon = dynamic_cast<TPolyLine3D*>((*fObjectsPhotons)[iObj]);
75  if (photon)
76  photon->Draw();
77  }
78  c.Print(fnameCanvas.str().c_str());
79  TFile f(fnameRoot.str().c_str(), "RECREATE");
80  /*
81  objectsFilter->Write("filter");
82  objectsLens->Write("lens");
83  objectsMirror->Write("mirror");
84  objectsCamera->Write("camera");
85  fObjectsPhotons->Write("photons");
86  */
87  c.Write();
88  f.Close();
89  }
90 
91  delete fFilter;
92  delete fLens;
93  delete fMirror;
94  delete fCamera;
95 }
96 
97 
102  utl::Photon& photonOut,
103  int& nreflections, int& col, int& row) {
104 
105  nreflections = 0;
106 
107  bool plotTrack = false;
108  int trackColor = kBlue;
109  if (fPlotPhotonTracks) {
110  plotTrack = (gRandom->Rndm() < fDrawPhotonProbability);
112  if (photonIn.GetPosition().GetR(telCS)<0.85*utl::meter) {
113  trackColor = kRed;
114  }
115  }
116 
117 
118 
119  utl::Photon photonFilter;
120  if (fFilter->Trace(photonIn, photonFilter) != eOK)
121  return eAbsorbedByFilter;
122  if (plotTrack)
123  fObjectsPhotons->AddLast(DrawTrack(photonIn.GetPosition(), photonFilter.GetPosition(), trackColor));
124 
125 
126  utl::Photon photonDiaphragm = photonFilter;
127  if (fHasCorrectorRing) {
128 
129  const RTResult lensStatus = fLens->Trace(photonFilter, photonDiaphragm);
130  if (lensStatus != eOK)
131  return lensStatus;
132 
133  }
134  if (plotTrack)
135  fObjectsPhotons->AddLast(DrawTrack(photonFilter.GetPosition(), photonDiaphragm.GetPosition(), trackColor));
136 
137  if (fDoShadow) {
138  if (fCamera->TraceShadow(photonDiaphragm, fDoShadowSupport) != eOK)
139  return eShadowed;
140  }
141 
142 
143  utl::Photon photonMirror;
144  const RTResult mirStatus = fMirror->Trace (photonDiaphragm, photonMirror);
145  if (mirStatus != eOK)
146  return eAbsorbedByMirror;
147 
148  if (plotTrack)
149  fObjectsPhotons->AddLast(DrawTrack(photonDiaphragm.GetPosition(), photonMirror.GetPosition(), trackColor));
150 
151 
152 
153  double cosTheta = 0;
154  RTResult status = fCamera->Trace(photonMirror, photonOut, nreflections, col, row, cosTheta, fHasMercedes);
155  //if (fHasMercedes) result = fCamera->Trace (photonMirror, photonOut, col, row, cosTheta, +2); // WITH MERCEDES
156  //else result = fCamera->Trace (photonMirror, photonOut, col, row, cosTheta, -2); // WITHOUT MERCEDES
157  cosTheta *= -1;
158 
159  if (/*status == eOK &&*/ plotTrack) {
160  fObjectsPhotons->AddLast(DrawTrack(photonMirror.GetPosition(), photonOut.GetPosition(), trackColor));
161  }
162 
163 
164  if (status != eOK) {
165  col = -1; // camera not hit
166  row = -1;
167  return status;
168  }
169 
170  return eOK;
171 
172 }// end of TelescopeSimulator::RayTracing
173 
174 
175 
176 TPolyLine3D* RayTracer::DrawTrack(const utl::Point& p1, const utl::Point& p2, int color) const {
177  // for plottings
179  TPolyLine3D* track = new TPolyLine3D(2);
180  track->SetPoint(0, p1.GetX(telCS), p1.GetY(telCS), p1.GetZ(telCS));
181  track->SetPoint(1, p2.GetX(telCS), p2.GetY(telCS), p2.GetZ(telCS));
182  track->SetLineColor(color);
183  return track;
184 }
RTResult Trace(const utl::Photon &photonIn, utl::Photon &photonOut)
brief Simulate the filter
RTResult Trace(const utl::Photon &photonIn, utl::Photon &photonOut, int &nreflections, int &col, int &row, double &cosTheta, bool doMercedes=true)
Simulates the mirror in the raytracing of the TelescopeSimulator module.
Point object.
Definition: Point.h:32
double GetR(const CoordinateSystemPtr &coordinateSystem) const
radius r in spherical coordinates coordinates (distance to origin)
Definition: BasicVector.h:257
unsigned int GetEyeId() const
bool HasCorrectorRing() const
flag for corrector ring presence
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
utl::CoordinateSystemPtr GetTelescopeCoordinateSystem() const
Simulates the corrector ring in the raytracing of the TelescopeSimulator module.
Definition: Lens.h:46
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
Wraps the random number engine used to generate distributions.
Definition: RandomEngine.h:27
constexpr double meter
Definition: AugerUnits.h:81
const fdet::Telescope * fTel
Definition: RayTracer.h:67
RTResult TraceShadow(const utl::Photon &photonIn, const bool doSupport=true)
RTResult Trace(const utl::Photon &photonIn, utl::Photon &photonOut)
Definition: Lens.cc:70
Simulates the UV filter in the raytracing of the TelescopeSimulator module.
TPolyLine3D * DrawTrack(const utl::Point &p1, const utl::Point &p2, int color) const
Definition: RayTracer.cc:176
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
Detector description interface for Telescope-related data.
RTResult Trace(const utl::Photon &photonIn, utl::Photon &photonOut, int &nreflections, int &col, int &row)
Raytracing through the telescope components.
Definition: RayTracer.cc:101
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
RTResult Trace(const utl::Photon &photonIn, utl::Photon &photonOut)
unsigned int GetId() const
const utl::Point & GetPosition() const
Definition: Photon.h:25

, generated on Tue Sep 26 2023.