FDsimG4Write2ROOT.cc
Go to the documentation of this file.
1 #include "FDsimG4Defs.hh"
2 #ifdef __TELESCOPE_SIMULATOR_LX_USE_ROOT__
3 
4 #include "FDsimG4Write2ROOT.hh"
6 #include <TFile.h>
7 #include <TTree.h>
8 #include <TDirectory.h>
9 #include <utl/Photon.h>
10 #include <utl/AugerUnits.h>
11 #include <iostream>
12 #include <string>
13 
14 namespace TelescopeSimulatorLX{double RCam = 1.743*utl::m;}
15 
16 using namespace std;
17 using namespace TelescopeSimulatorLX;
18 
19 FDsimG4Write2ROOT::FDsimG4Write2ROOT() :
20  fRootFile(NULL),
21  fTreePhotons(NULL)
22 {
23 }
24 
25 
26 FDsimG4Write2ROOT::FDsimG4Write2ROOT(const string& RootFilename)
27 {
28  Open(RootFilename);
29  CreateTree();
30 }
31 
32 
34 {
35  SaveAndClose();
36 }
37 
38 
39 void FDsimG4Write2ROOT::Open(const string& filename)
40 {
41  TDirectory *tmpSaveDir = gDirectory;
42  fRootFile = new TFile(filename.c_str(), "RECREATE");
43  fSaveDir=gDirectory;
44  tmpSaveDir->cd();
45 }
46 
47 
49 {
50  if (fRootFile) {
51  if (fRootFile->IsOpen()) {
52  TDirectory *tmpSaveDir = gDirectory;
53  fSaveDir->cd();
54  fTreePhotons->Write("",TObject::kOverwrite);
55  fRootFile->Close();
56  tmpSaveDir->cd();
57  fTreePhotons = NULL;
58  }
59  }
60 
61  if (fRootFile) {
62  delete fRootFile;
63  fRootFile = NULL;
64  }
65 }
66 
67 
69 {
70  TDirectory *tmpSaveDir = gDirectory;
71  fSaveDir->cd();
72  if (!fRootFile->Get("Photons")){
73  fTreePhotons = new TTree("Photons","Photons Tree");
74 
75  fTreePhotons->Branch("G4",
76  &fG4_info,
77  "x/D:y/D:z/D:alfa/D:beta/D:E/D:w/D:t/D:LocX/D:LocY/D:LocZ/D:PixX/D:PixY/D:PixZ/D:HitID/D:PMTid/D");
78 
79  fTreePhotons->Branch("G4Filter",&fG4Filter_info,"x/D:y/D:z/D");
80  fTreePhotons->Branch("G4Lens",&fG4Lens_info,"x/D:y/D:z/D");
81  fTreePhotons->Branch("G4Mirror",&fG4Mirror_info,"x/D:y/D:z/D");
82  fTreePhotons->Branch("G4Mercedes",&fG4Mercedes_info,"x/D:y/D:z/D");
83  fTreePhotons->Branch("G4FS",&fG4FS_info,"x/D:y/D:z/D:alfa/D:beta/D:th/D:phi/D");
84  fTreePhotons->Branch("nHit",
85  &fn_info,
86  "G4Filter/I:G4Lens/I:G4Mirror/I:G4Mercedes/I:G4FS/I:G4/I");
87 
88  fTreePhotons->Branch("IN",
89  &fIN_info,
90  "x/D:y/D:z/D:DX/D:DY/D:DZ/D:th/D:phi/D:wantedPix/D:wantedTh/D:wantedPhi/D");
91  fTreePhotons->Branch("INExp",
92  &fINExp_info,
93  "x/D:y/D:z/D:alfa/D:beta/D:DX/D:DY/D:DZ/D:th/D:phi/D");
94  }
95  else
96  {
97  fTreePhotons = (TTree*)fRootFile->Get("Photons");
98 
99  fTreePhotons->SetBranchAddress("G4",&fG4_info);
100  fTreePhotons->SetBranchAddress("G4Filter",&fG4Filter_info);
101  fTreePhotons->SetBranchAddress("G4Lens",&fG4Lens_info);
102  fTreePhotons->SetBranchAddress("G4Mirror",&fG4Mirror_info);
103  fTreePhotons->SetBranchAddress("G4Mercedes",&fG4Mercedes_info);
104  fTreePhotons->SetBranchAddress("G4FS",&fG4FS_info);
105  fTreePhotons->SetBranchAddress("nHit",&fn_info);
106  fTreePhotons->SetBranchAddress("IN",&fIN_info);
107  fTreePhotons->SetBranchAddress("INExp",&fINExp_info);
108  }
109  tmpSaveDir->cd();
110 }
111 
112 
114 {
115  fG4Filter_info.x = G4_photon->GetPosX()*utl::mm;
116  fG4Filter_info.y = G4_photon->GetPosY()*utl::mm;
117  fG4Filter_info.z = G4_photon->GetPosZ()*utl::mm;
118  fn_info.G4Filter = 1;
119 }
120 
121 
123 {
124  fG4Lens_info.x = G4_photon->GetPosX()*utl::mm;
125  fG4Lens_info.y = G4_photon->GetPosY()*utl::mm;
126  fG4Lens_info.z = G4_photon->GetPosZ()*utl::mm;
127  fn_info.G4Lens = 1;
128 }
129 
130 
132 {
133  fG4Mirror_info.x = G4_photon->GetPosX()*utl::mm;
134  fG4Mirror_info.y = G4_photon->GetPosY()*utl::mm;
135  fG4Mirror_info.z = G4_photon->GetPosZ()*utl::mm;
136  fn_info.G4Mirror = 1;
137 }
138 
139 
141 {
142  fG4Mercedes_info.x = G4_photon->GetPosX()*utl::mm;
143  fG4Mercedes_info.y = G4_photon->GetPosY()*utl::mm;
144  fG4Mercedes_info.z = G4_photon->GetPosZ()*utl::mm;
145  fn_info.G4Mercedes = 1;
146 }
147 
148 
150 {
151  fG4FS_info.x = G4_photon->GetPosX()*utl::mm;
152  fG4FS_info.y = G4_photon->GetPosY()*utl::mm;
153  fG4FS_info.z = G4_photon->GetPosZ()*utl::mm;
154 //calcula
155 
156  fG4FS_info.alfa = asin(fG4FS_info.x/RCam);
157  fG4FS_info.beta = asin(fG4FS_info.y/-RCam);
158 
160  tempVec*=-1;
161  //debugpj//cout << tempVec.GetTheta(ftelCS)/3.1416*180. <<" telG4 "<<tempVec.GetPhi(ftelCS)/3.1416*180.<<" tel "<<tempVec.GetMag() <<endl;
162  //debugpj//cout << tempVec.GetTheta(feyeCS)/3.1416*180. <<" G$ "<<tempVec.GetPhi(feyeCS)/3.1416*180.<<endl;
163 
164 //Changed for Valerio//
165 fG4FS_info.th = tempVec.GetTheta(feyeCS);
166 //Changed for Valerio//
167 fG4FS_info.phi = tempVec.GetPhi(feyeCS);
168 //Changed for Valerio
169 // fG4FS_info.th = tempVec.GetTheta(ftelCS);
170 // fG4FS_info.phi = tempVec.GetPhi(ftelCS);
171 
172 
173  fn_info.G4FS = 1;
174 }
175 
176 
178 {
179  fG4_info.x = G4_photon->GetPosX()*utl::mm;
180  fG4_info.y = G4_photon->GetPosY()*utl::mm;
181  fG4_info.z = G4_photon->GetPosZ()*utl::mm;
182  fn_info.G4 = 1;
183 //calcula
184  fG4_info.alfa = asin(fG4_info.x/RCam);
185  fG4_info.beta = asin(fG4_info.y/-RCam);
186 // Other info
187 
188  fG4_info.E = G4_photon->GetEnergy()*utl::eV;
189  fG4_info.w= G4_photon->GetWavelength()*utl::nanometer;
190  fG4_info.t = G4_photon->GetTime()*utl::ns;
191 
192  fG4_info.LocX = G4_photon->GetLocalPosX()*utl::mm;
193  fG4_info.LocY = G4_photon->GetLocalPosY()*utl::mm;
194  fG4_info.LocZ = G4_photon->GetLocalPosZ()*utl::mm;
195 
196  fG4_info.PixX = G4_photon->GetPixelPosX()*utl::mm;
197  fG4_info.PixY = G4_photon->GetPixelPosY()*utl::mm;
198  fG4_info.PixZ = G4_photon->GetPixelPosZ()*utl::mm;
199 
200  fG4_info.HitID = G4_photon->GetHitID();
201  fG4_info.PMTid = G4_photon->GetPMTid();
202 }
203 
205 {
206 
207  double X = G4_photon->GetPosX()*utl::mm;
208  double Y = G4_photon->GetPosY()*utl::mm;
209  double Z = G4_photon->GetPosZ()*utl::mm;
210 
211  double DX = G4_photon->GetDirX();
212  double DY = G4_photon->GetDirY();
213  double DZ = G4_photon->GetDirZ();
214 
215  double lambda = G4_photon->GetWavelength()*utl::nanometer;
216  double weight = G4_photon->GetWeight();
217 
218  utl::Point Pos = utl::Point(X,Y,Z,ftelCS);
219  utl::Vector Dir = utl::Vector(DX,DY,DZ,ftelCS);
220 
221  utl::Photon IN_photon(Pos,Dir,lambda,weight);
222 
223  SetINPhoton(IN_photon,ftelCS,feyeCS);
224 }
225 
226 
227 void
231 {
232  utl::CoordinateSystemPtr CS=eyeCS;
233  static double RCam=1.743*utl::m;
234  fIN_info.x = IN_photon.GetPosition().GetX(telCS);
235  fIN_info.y = IN_photon.GetPosition().GetY(telCS);
236  fIN_info.z = IN_photon.GetPosition().GetZ(telCS);
237  fIN_info.DX = IN_photon.GetDirection().GetX(telCS);
238  fIN_info.DY = IN_photon.GetDirection().GetY(telCS);
239  fIN_info.DZ = IN_photon.GetDirection().GetZ(telCS);
240 
241 //atencao que isto aponta para dentro do Tel
242  fIN_info.th = IN_photon.GetDirection().GetTheta(telCS);
243  fIN_info.phi = IN_photon.GetDirection().GetPhi(telCS);
244 
245  //temporary container for thphi
246  fINExp_info.th=IN_photon.GetDirection().GetTheta(telCS);
247  fINExp_info.phi=IN_photon.GetDirection().GetPhi(telCS);
248 
249  fINExp_info.x = RCam*sin(fINExp_info.th)*cos(fINExp_info.phi);
250  fINExp_info.y = RCam*sin(fINExp_info.th)*sin(fINExp_info.phi);
251  fINExp_info.z = -RCam*cos(fINExp_info.th);
252  fINExp_info.alfa = asin(fINExp_info.x/RCam);
253  fINExp_info.beta = asin(fINExp_info.y/-RCam);
254 
255 // utl::Vector tempVec= utl::Vector(fINExp_info.x,fINExp_info.y,-fINExp_info.z,ftelCS);
256 // tempVec*=-1;
257 // fINExp_info.th = tempVec.GetTheta(feyeCS);
258 // fINExp_info.phi = tempVec.GetPhi(feyeCS);
259 }
260 
261 
263 {
264  WriteIt();
265 }
266 
267 
269 {
270  fTreePhotons->Fill();
271 }
272 
273 
275 {
276  fG4Filter_info.x = nan("");
277  fG4Filter_info.y = nan("");
278  fG4Filter_info.z = nan("");
279 
280  fG4Lens_info.x = nan("");
281  fG4Lens_info.y = nan("");
282  fG4Lens_info.z = nan("");
283 
284  fG4Mirror_info.x = nan("");
285  fG4Mirror_info.y = nan("");
286  fG4Mirror_info.z = nan("");
287 
288  fG4Mercedes_info.x = nan("");
289  fG4Mercedes_info.y = nan("");
290  fG4Mercedes_info.z = nan("");
291 
292  fG4FS_info.x = nan("");
293  fG4FS_info.y = nan("");
294  fG4FS_info.z = nan("");
295  fG4FS_info.alfa = nan("");
296  fG4FS_info.beta = nan("");
297  fG4FS_info.th=nan("");
298  fG4FS_info.phi=nan("");
299 
300  fG4_info.x = nan("");
301  fG4_info.y = nan("");
302  fG4_info.z = nan("");
303  fG4_info.E = nan("");
304  fG4_info.w = nan("");
305  fG4_info.t = nan("");
306  fG4_info.LocX = nan("");
307  fG4_info.LocY = nan("");
308  fG4_info.LocZ = nan("");
309  fG4_info.PixX = nan("");
310  fG4_info.PixY = nan("");
311  fG4_info.PixZ = nan("");
312  fG4_info.HitID = nan("");
313  fG4_info.PMTid = nan("");
314 
315  fIN_info.x= nan("");
316  fIN_info.y= nan("");
317  fIN_info.z= nan("");
318  fIN_info.DX= nan("");
319  fIN_info.DY= nan("");
320  fIN_info.DZ= nan("");
321  fIN_info.th= nan("");
322  fIN_info.phi= nan("");
323 
324  fINExp_info.x= nan("");
325  fINExp_info.y= nan("");
326  fINExp_info.z= nan("");
327  fINExp_info.alfa= nan("");
328  fINExp_info.beta= nan("");
329  fINExp_info.DX= nan("");
330  fINExp_info.DY= nan("");
331  fINExp_info.DZ= nan("");
332  fINExp_info.th= nan("");
333  fINExp_info.phi= nan("");
334 
335  fn_info.G4Filter = 0;
336  fn_info.G4Lens = 0;
337  fn_info.G4Mirror = 0;
338  fn_info.G4Mercedes = 0;
339  fn_info.G4FS =0;
340  fn_info.G4 = 0;
341 }
342 
343 #endif
constexpr double eV
Definition: AugerUnits.h:185
constexpr double mm
Definition: AugerUnits.h:113
void SetG4Photon(FDsimG4StoreOpticalHit *G4_photon)
Point object.
Definition: Point.h:32
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Definition: BasicVector.h:254
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::kn_info fn_info
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
void SetINPhoton(FDsimG4StoreOpticalHit *G4_photon)
void SetG4MirrorPhoton(FDsimG4StoreOpticalHit *G4_photon)
constexpr double nanometer
Definition: AugerUnits.h:102
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::IN_infoExp fINExp_info
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::G4_infoFS fG4FS_info
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
void SetG4LensPhoton(FDsimG4StoreOpticalHit *G4_photon)
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::G4_info fG4Mercedes_info
void SetG4FSPhoton(FDsimG4StoreOpticalHit *G4_photon)
void SetG4FilterPhoton(FDsimG4StoreOpticalHit *G4_photon)
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::G4_info2 fG4_info
const utl::Vector & GetDirection() const
Definition: Photon.h:26
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::G4_info fG4Lens_info
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::G4_info fG4Filter_info
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::IN_info fIN_info
Vector object.
Definition: Vector.h:30
struct TelescopeSimulatorLX::FDsimG4Write2ROOT::G4_info fG4Mirror_info
constexpr double ns
Definition: AugerUnits.h:162
char * filename
Definition: dump1090.h:266
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
constexpr double m
Definition: AugerUnits.h:121
void SetG4MercedesPhoton(FDsimG4StoreOpticalHit *G4_photon)
const utl::Point & GetPosition() const
Definition: Photon.h:25
void Open(const std::string &RootFilename)

, generated on Tue Sep 26 2023.