TelescopeSimulatorKG2/TelescopeSimulator.cc
Go to the documentation of this file.
1 
12 #include <utl/config.h>
13 
14 #include "TelescopeSimulator.h"
15 #include "RayTracer.h"
16 
17 #include <utl/Reader.h>
18 #include <utl/ErrorLogger.h>
19 #include <utl/AugerUnits.h>
20 #include <utl/MathConstants.h>
21 #include <utl/Math.h>
22 #include <utl/PhysicalConstants.h>
23 #include <utl/PhysicalFunctions.h>
24 #include <utl/Point.h>
25 #include <utl/TabulatedFunction.h>
26 #include <utl/TabulatedFunctionErrors.h>
27 #include <utl/Trace.h>
28 #include <utl/MultiTabulatedFunction.h>
29 #include <utl/Photon.h>
30 #include <utl/RandomEngine.h>
31 #include <utl/UTMPoint.h>
32 
33 #include <fwk/CentralConfig.h>
34 #include <fwk/CoordinateSystemRegistry.h>
35 #include <fwk/RandomEngineRegistry.h>
36 
37 #include <det/Detector.h>
38 
39 #include <fdet/FDetector.h>
40 #include <fdet/Eye.h>
41 #include <fdet/Telescope.h>
42 #include <fdet/Camera.h>
43 #include <fdet/Pixel.h>
44 #include <fdet/Mirror.h>
45 #include <fdet/Filter.h>
46 #include <fdet/Corrector.h>
47 
48 #include <evt/Event.h>
49 
50 #include <fevt/FEvent.h>
51 #include <fevt/Eye.h>
52 #include <fevt/TelescopeSimData.h>
53 #include <fevt/Telescope.h>
54 #include <fevt/PixelSimData.h>
55 #include <fevt/Pixel.h>
56 
57 #include <boost/tuple/tuple.hpp>
58 
59 #include <TDirectory.h>
60 #include <TFile.h>
61 #include <TTree.h>
62 
63 #include <CLHEP/Random/Randomize.h>
64 
65 #include <iomanip>
66 #include <fstream>
67 #include <sstream>
68 
69 using namespace TelescopeSimulatorKG2;
70 using namespace std;
71 using namespace utl;
72 using namespace evt;
73 using namespace fwk;
74 using namespace det;
75 using namespace fdet;
76 
77 using CLHEP::RandFlat;
78 
79 
80 
82  fVerbosityLevel(0)
83 {
84 }
85 
86 
89 {
90  ostringstream info;
91  info << " Version: " << GetVersionInfo(VModule::eRevisionNumber) << "\n";
92 
93 #if 0
94  fDrumMode = false;
95 #endif
96 
97 
99  &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
100 
101  Branch topB =
102  CentralConfig::GetInstance()->GetTopBranch("TelescopeSimulatorKG2");
103 
104  info << " *** Output format: Parameter value (default value) ***\n";
105 
106  //StoreLightComponentsAtPixels default value
108  topB.GetChild("StoreLightComponentsAtPixels").GetData(fStoreLightComponentsAtPixels);
109  info << " * Store light components at pixels: " << (!fStoreLightComponentsAtPixels ? "no" : "yes") << " (no)\n";
110 
111  //MirrorSize
112  topB.GetChild("MirrorSize").GetData(fMirrorSize);
113  info << " * Mirror size: " << (fMirrorSize/deg) << " deg (33.07)" << "\n";
114 
115  //Verbosity default value
116  if (topB.GetChild("VerbosityLevel"))
117  topB.GetChild("VerbosityLevel").GetData(fVerbosityLevel);
118  info << " * Verbosity: " << fVerbosityLevel << " (0)\n";
119 
120  //outputFileName for shadow data
121  fShadowDataOutName = "shadowData.root";
122  if (topB.GetChild("ShadowDataOut"))
123  topB.GetChild("ShadowDataOut").GetData(fShadowDataOutName);
124 
125  //RayTracingOptions default values
126  fSimulateCameraShadow = true;
128  fSimulateMercedesStars = true;
130  fSimulateHaloEffects = true;
131  fSimulateGhostEffects = true;
132  fMaxMirrorReflections = 1; // >=3 simulates ghost as well
133 
134  if (topB.GetChild("RayTracingOptions")){
135  Branch optionsB = topB.GetChild("RayTracingOptions");
136  optionsB.GetChild("SimulateCameraShadow").GetData(fSimulateCameraShadow);
137  optionsB.GetChild("SimualteCameraSupportShadow").GetData(fSimualteCameraSupportShadow);
138  optionsB.GetChild("SimulateMercedesStars").GetData(fSimulateMercedesStars);
139  optionsB.GetChild("SimulateFilterStructure").GetData(fSimulateFilterStructure);
140  optionsB.GetChild("SimulateHaloEffects").GetData(fSimulateHaloEffects);
141  optionsB.GetChild("SimulateGhostEffects").GetData(fSimulateGhostEffects);
142  optionsB.GetChild("MaxMirrorReflections").GetData(fMaxMirrorReflections);
143  }
144  info << " * Raytracing options: \n"
145  << " camera body shadow: " << (fSimulateCameraShadow ? "yes" : "no") << " (yes)\n"
146  << " camera support shadow: " << (fSimualteCameraSupportShadow ? "yes" : "no") << " (yes)\n"
147  << " mercedes collectors: " << (fSimulateMercedesStars ? "yes" : "no") << " (yes)\n"
148  << " filter structure: " << (fSimulateFilterStructure ? "yes" : "no") << " (yes)\n"
149  << " halo effects: " << (fSimulateHaloEffects ? "yes" : "no") << " (yes)\n"
150  << " ghost effects: " << (fSimulateGhostEffects ? "yes" : "no") << " (yes)\n"
151  << " max nr of mirror reflections: " << fMaxMirrorReflections << " (1)\n";
152 
153 
154  // ---------------------------------- ** HALO INPUT ** ----------------------------------
155 
156  //MirrorOptions default values
157  //fMirrorDiffusion != NULL needed for halo
158  //for other parameters: values other than default only needed for abnormal modifications of the halo
159  fMirrorSegmentSigma = 0.;
160  fMirrorRadiusSigma = 0.;
163  fMirrorDiffusionTop = nullptr;
164  fMirrorDiffusionBot = nullptr;
165 
166  if (fSimulateHaloEffects) {
167  if (topB.GetChild("MirrorOptions")){
168  Branch mirrorOptionsB = topB.GetChild("MirrorOptions");
169 
170  mirrorOptionsB.GetChild("MirrorSegmentSigma").GetData(fMirrorSegmentSigma);
171  mirrorOptionsB.GetChild("MirrorRadiusSigma").GetData(fMirrorRadiusSigma);
172  mirrorOptionsB.GetChild("MirrorAbsorptionTop").GetData(fMirrorAbsorptionTop);
173  mirrorOptionsB.GetChild("MirrorAbsorptionBot").GetData(fMirrorAbsorptionBot);
174 
175  //only if MirrorDiffusionTop/Bot branch exists get values for mirror diffusion
176  Branch mirrorDiffusionTopB = mirrorOptionsB.GetChild("MirrorDiffusionTop");
177  mirrorDiffusionTopB.GetChild("MirrorDiffusionValues").GetData(fMirrorDiffusionTopValues);
178  mirrorDiffusionTopB.GetChild("MirrorDiffusionAngles").GetData(fMirrorDiffusionTopAngles);
180 
181  Branch mirrorDiffusionBotB = mirrorOptionsB.GetChild("MirrorDiffusionBot");
182  mirrorDiffusionBotB.GetChild("MirrorDiffusionValues").GetData(fMirrorDiffusionBotValues);
183  mirrorDiffusionBotB.GetChild("MirrorDiffusionAngles").GetData(fMirrorDiffusionBotAngles);
185  } else {
186  ostringstream err;
187  err << "fMirrorDiffusion != 0 needed for halo. \n"
188  << "Can be set in the TelescopeSimulator xml file. \n"
189  << "Stop Simulation.";
190  ERROR(err);
191  return eFailure;
192  }
193  } //end of if fSimulateHaloEffects
194 
195  //Mirror output
196  info << " * Mirror options:" << "\n"
197  << " segment sigma: " << fMirrorSegmentSigma / deg << " deg" << " (0.0)" << "\n"
198  << " radius sigma: " << fMirrorRadiusSigma / mm << " mm" << " (0.0)" << "\n"
199  << " absorption top: " << 100 * fMirrorAbsorptionTop << "\% (0.0)\n"
200  << " absorption bottom: " << 100 * fMirrorAbsorptionBot << "\% (0.0)\n";
201 
202  info << " mirror diffusion top function: ";
203  if (fMirrorDiffusionTop == nullptr)
204  info << "no" << "\n";
205  else
206  info << "yes" << "\n";
207 
208  info << " mirror diffusion bottom function: ";
209  if (fMirrorDiffusionBot == nullptr)
210  info << "no" << "\n";
211  else
212  info << "yes" << "\n";
213 
214  //FilterOptions default values
215  //Might change in decision of what is standard mode (probably without halo ???)
216  fFilterPosition = 12. * cm;
223 
224  if (fSimulateHaloEffects) {
225  if (topB.GetChild("FilterOptions")){
226  Branch filterOptionsB = topB.GetChild("FilterOptions");
227  filterOptionsB.GetChild("FilterIncreaseReflectionInside").GetData(fFilterIncreaseReflectionInside);
228  filterOptionsB.GetChild("FilterIncreaseReflectionOutside").GetData(fFilterIncreaseReflectionOutside);
229  filterOptionsB.GetChild("FilterPosition").GetData(fFilterPosition);
230  filterOptionsB.GetChild("FilterPositionVertical").GetData(fFilterPositionVertical);
231  filterOptionsB.GetChild("FilterPositionVertical2").GetData(fFilterPositionVertical2);
232  filterOptionsB.GetChild("FilterPositionHorizontal").GetData(fFilterPositionHorizontal);
233  filterOptionsB.GetChild("FilterDustAbsorptionOutside").GetData(fFilterDustAbsorptionOutside);
234  }
235  } //end of if fDoNoHalo
236 
237  info << " * Filter options:" << "\n"
238  << " increased reflectivity inside: " << fFilterIncreaseReflectionInside << " (1.0)" << "\n"
239  << " increased reflectivity outside: " << fFilterIncreaseReflectionOutside << " (1.0)" << "\n"
240  << " position (z-direction): " << fFilterPosition / cm << " cm" << " (12.0)" << "\n"
241  << " position vertical bar: " << fFilterPositionVertical / cm << " cm" << "\n"
242  << " position vertical bar2: " << fFilterPositionVertical2 / cm << " cm" << "\n"
243  << " position horizontal bar: " << fFilterPositionHorizontal / cm << " cm" << "\n"
244  << " absorption on dust layer outside: " << fFilterDustAbsorptionOutside * 100 << "% (0.0)" << "\n";
245 
246  //LensOptions default values
248  fLensPosition = 0. * mm;
249  fMinLensThickness = 6.14 * mm;
250  fTorusRadius = 795.27 * mm;
251  fTubeRadius = 8383.00 * mm;
252  fTorusZ0 = fLensPosition + fTubeRadius + 5.96 * mm;
253 
254  if (fSimulateHaloEffects) {
255  if (topB.GetChild("LensOptions")){
256  Branch lensOptionsB = topB.GetChild("LensOptions");
257  lensOptionsB.GetChild("LensIncreaseReflection").GetData(fLensIncreaseReflection);
258  lensOptionsB.GetChild("LensPosition").GetData(fLensPosition);
259 
260  Branch torusOptionsB = lensOptionsB.GetChild("TorusParameters");
261  torusOptionsB.GetChild("MinLensThickness").GetData(fMinLensThickness);
262  torusOptionsB.GetChild("TorusRadius").GetData(fTorusRadius);
263  torusOptionsB.GetChild("TubeRadius").GetData(fTubeRadius);
264  torusOptionsB.GetChild("TorusZ0").GetData(fTorusZ0);
265  }
266  }
267  info << " * Lens options:" << "\n"
268  << " increase reflectivity: " << fLensIncreaseReflection << " (1.0)" << "\n"
269  << " position (z-direction): " << fLensPosition / mm << " mm" << " (0.0)" << "\n"
270  << " min thickness: " << fMinLensThickness / mm << " mm" << " (6.14)" << "\n"
271  << " torus radius: " << fTorusRadius / mm << " mm" << " (795.27)" << "\n"
272  << " tube radius: " << fTubeRadius / mm << " mm" << " (8383.00)" << "\n"
273  << " position of torus center: " << fTorusZ0 / mm << " mm" << " (8388.96)" << "\n";
274 
275  //CameraOptions default values
276  fPMT_n = 2.58;
277 
278  if (fSimulateHaloEffects) {
279  if (topB.GetChild("CameraOptions")){
280  Branch cameraOptionsB = topB.GetChild("CameraOptions");
281  cameraOptionsB.GetChild("pmt_n").GetData(fPMT_n);
282  }
283  }
284  info << " * Camera options: \n"
285  << " PMT window refractive index: " << fPMT_n << " (2.58)\n";
286 
287  // ---------------------------------- ** END OF HALO INPUT ** ----------------------------------
288 
289  //DrawingOptions default values
291  fDraw = false;
292  fDrawMercReflections = false;
293 
294  if (topB.GetChild("DrawingOptions")) {
295  Branch drawingB = topB.GetChild("DrawingOptions");
296  fDraw = true;
297  drawingB.GetChild("mercedesReflections").GetData(fDrawMercReflections);
298  drawingB.GetChild("numberOfPhotons").GetData(fDrawNumberOfPhotons);
299  }
300 
301  if (fDraw) {
302  info << " Drawing options: \n"
303  " plot mercedes reflections: " << (!fDrawMercReflections ? "no" : "yes") << " (no)\n"
304  " save 3D plot with: " << fDrawNumberOfPhotons << " (0) raytraced photons\n";
305  }
306 
307  INFO(info);
308 
309  // ---------------------------------------------------
310  // the model config signature
311  ostringstream configSignature;
312  // use configSignature of normal TelescopeSimulatorKG at the moment
313  // to have its drum calibration constants available
314  // TO DO: enter halo here, once calibration constants are available
315 #warning TO DO: all changeable values have to enter all in configSignature of TelescopeSimulator.cc
316 
317  configSignature << "TelescopeSimulatorKG2";
318 #if 0
319  if (fDoNoShadow || fDoNoShadowSupport || fHasNoMercedes || !fDoNoFilterStructure || !fDoNoHalo || !fDoNoGhost)
320  configSignature << "(camera-shadow / support-shadow / mercedes / filter-structure / halo / ghost) = ("
321  << (!fDoNoShadow ? "yes" : "no") << " / "
322  << (!fDoNoShadowSupport ? "yes" : "no") << " / "
323  << (!fHasNoMercedes ? "yes" : "no") << " / "
324  << (!fDoNoFilterStructure ? "yes" : "no") << " / "
325  << (!fDoNoHalo ? "yes" : "no") << " / "
326  << (!fDoNoGhost ? "yes" : "no") << ")";
327 #endif
328  fGeneralConfigSignature = configSignature.str();
329  INFO(configSignature);
330 
331  return eSuccess;
332 }
333 
334 
337 {
338  if (!event.HasFEvent()) {
339  ERROR("Event has no FEvent.");
340  return eFailure;
341  }
342  fevt::FEvent& fEvent = event.GetFEvent();
343 
344 #if 0
345  if (!fDrumMode && !event.HasSimShower()) {
346  /*
347  In drum mode (AND SPOT MODE) the handling of photons is different from normal mode.
348  While normaly photons are tracked with a weight, in drum mode photons are tracked
349  as physical objects that can only get absorbed - or not.
350  */
351  fDrumMode = true;
352  cout << "fDrumMode = true! " << endl;
353  }
354 #endif
355 
356  const Detector& detector = Detector::GetInstance();
357  const FDetector& detFD = detector.GetFDetector();
358 
359  // loop eyes
361  iEye != fEvent.EyesEnd(fevt::ComponentSelector::eInDAQ); ++iEye) {
362 
363  if (iEye->GetStatus() == fevt::ComponentSelector::eDeSelected)
364  continue;
365 
366  const unsigned int eyeId = iEye->GetId();
367  fevt::Eye& eyeEvent = *iEye;
368  //const fdet::Eye& detEye = detFD.GetEye(*iEye);
369 
370  // loop telescopes
372  iTel != eyeEvent.TelescopesEnd(fevt::ComponentSelector::eInDAQ); ++iTel) {
373 
374  const unsigned int telId = iTel->GetId();
375  fevt::Telescope& telEvent = *iTel;
376  const fdet::Telescope& detTel = detFD.GetTelescope(telEvent);
377 
378  const TabulatedFunction& telMeasEfficiency = detTel.GetMeasuredRelativeEfficiency();
379 
380  fevt::TelescopeSimData& telSim = telEvent.GetSimData();
382 
383  const double normWavelength = detFD.GetReferenceLambda();
384  //const TabulatedFunction& mirRef = detTel.GetMirror().GetReflectivity();
385  const TabulatedFunction& filtTrans = detTel.GetFilter().GetTransmittance();
386 
387  // corrector
388 
389  const fdet::Camera& detCamera = detTel.GetCamera();
390  const unsigned int telTraceNBins = telSim.GetNumberOfPhotonBins();
391  const double telTraceBinWidth = detCamera.GetFADCBinSize();
392 
393  const double nPhotons = telSim.GetNPhotons();
394 
395  if (!nPhotons)
396  continue;
397 
398  ostringstream info;
399  /*info << "Raytracing eye=" << eyeId
400  << ", telescope=" << telId
401  << ", rDia=" << setw(6) << detTel.GetDiaphragmRadius()
402  << ", nPhotons=" << nPhotons;*/
403  info << "Raytracing telescope with " << nPhotons << " Photons";
404  INFO(info);
405 
406  const double minWl = detFD.GetModelMinWavelength();
407  const double maxWl = detFD.GetModelMaxWavelength();
408 
409  map<int, int> rayTracerResults; // for verbose info output: [status:counts]
410 
411  const double drawPhotonProbablility = (double)fDrawNumberOfPhotons / nPhotons;
412 
413  RayTracer* rayTracer = nullptr;
414 
415  const int index = telId + eyeId * 100;
416  fNHit[index] = 0;
417  fN_1[index] = 0;
418  fN_2[index] = 0;
419  fN_3[index] = 0;
420  fN_4[index] = 0;
421  fN_5[index] = 0;
422  fN_6[index] = 0;
423 
424 
425  unsigned int countWlBoundary = 0;
426  /*
427  //These can not be accessed anymore as Trace functions of components no longer give RTResult back but RTNext remove?
428  unsigned int countFilter = 0;
429  unsigned int countMirror = 0;
430  */
431  unsigned int countPhotons = 0;
432 
433  map<int, TraceD*> traces;
435  iPhoton != telSim.PhotonsEnd(); ++iPhoton) {
436 
437  #warning "JD: The number of photons after which rayTracer gets refreshed needs to be optimised for performance vs geometry creeping"
438  if (!(countPhotons % 100000)) {
439  delete rayTracer;
440  rayTracer = new RayTracer(fVerbosityLevel,
441  detTel, *fRandomEngine,
455  fPMT_n,
456  fDraw, fDrawMercReflections, drawPhotonProbablility);
457  }
458  ++countPhotons;
459 
460  const double wavelength = iPhoton->GetWavelength();
461 
462  if (wavelength < minWl || wavelength > maxWl) {
463  ++countWlBoundary;
464  continue;
465  }
466 
467 
468  utl::Photon photonOut;
469  int col = 0;
470  int row = 0;
471 
472  int nReflections = 0; // mercedes reflections
473  int nHaloReflection = 0;
474  const RTResult status = rayTracer->Trace(*iPhoton, photonOut, nReflections, nHaloReflection, col, row);
475  const double weight = photonOut.GetWeight();
476  // DEBUG drum mode with halo
477  //cout << "weight after rayTracer = " << weight << endl;
478 
479  if (status == eTerminate) {
480  WARNING("********************** TERMINATED BY RAYTRACER ***************************");
481  return eSuccess;
482  }
483 
484  if (status != eOK ) { // photon lost
485  rayTracerResults[status]++;
486  continue;
487  } else {
488  if (status == eOK && weight == 0) {
489  rayTracerResults[eAbsorbed]++;
490  continue;
491  }
492  }
493 
494  /*
495  if (nHaloReflection>0) {
496  cout << "RU: nHaloReflection = " << nHaloReflection << endl;
497  }
498  */
499 
500  rayTracerResults[status]++;
501 
502  const unsigned int pxlId = (col - 1) * detTel.GetLastRow() + row;
503  const fdet::Pixel& detPix = detTel.GetPixel(pxlId);
504  const TabulatedFunction& qEff = detPix.GetQEfficiency();
505 
506  // !! this factor is to achive consistency to reconstruction !!
507  // do this also for drum mode
508  double efficiencyCorrection = 0;
509  // if (!fDrumMode) {
510  const double modelRelEff = detTel.GetModelRelativeEfficiency(wavelength);
511  if (modelRelEff)
512  efficiencyCorrection = telMeasEfficiency.Y(wavelength) / modelRelEff;
513  // }
514  // DEBUG drum mode with halo
515  /*cout << "efficiencyCorrection = " << efffactoriciencyCorrection
516  << ", measured efficiency = " << telMeasEfficiency.Y(wavelength)
517  << ", wavelength = " << wavelength;
518  if (efficiencyCorrection != 0)
519  cout << ", modelRelEff = " << telMeasEfficiency.Y(wavelength)/efficiencyCorrection << endl;
520  else
521  cout << endl;
522  */
523 
524  const double time = photonOut.GetTime().GetInterval();
525  const int bin = int(time / telTraceBinWidth);
526 
527  if (fVerbosityLevel > 2) {
528  cerr << " bin=" << setw(4) << bin
529  << " time=" << setw(6) << time/ns
530  << " weight=" << setw(4) << weight
531  << " wl=" << setw(4) << wavelength/nanometer
532  << " col=" << setw(3) << col
533  << " row=" << setw(3) << row
534  << " pixelId=" << setw(3) << pxlId
535  << " telTraceBinWidth=" << setw(3) << telTraceBinWidth
536  << " telTraceNBins=" << setw(5) << telTraceNBins
537  << " EQ=" << qEff.Y(wavelength) / qEff.Y(normWavelength)
538  << " EC=" << efficiencyCorrection
539  << endl;
540  }
541 
542  // check for index out of bound
543  if (bin < 0 || bin >= int(telTraceNBins)) {
544  if (fVerbosityLevel > 2) {
545  ostringstream err;
546  err << "Bin out of range. bin=" << bin
547  << " weight=" << weight;
548  ERROR(err);
549  }
550  continue;
551  }
552 
553  double filterFactor = filtTrans.Y(wavelength);
554  // in the new simulation, the reflections on both surfaces of the filter
555  // (air-glass and glass-air) are already taken into account
556  // using the refractive index of the filter material n = 1.526, the transmission
557  // factor due to the surface reflections is
558  // T = T_in * T_out = 0.9566 * 0.9566 = 0.915
559  // Careful: n_filter = 1.526 is hard-coded in Filter.cc
560  filterFactor /= 0.915;
561 
562  //PMT refractive index is by default set to 2.58, corresponding to a reflectivity R=19.5%
563  //nominal refractive index given by the manufacturer is 1.52, R=4.3%
564  //photons are reflected off the PMT during the ray tracing if simulation of halo is enabled (default),
565  //but the loss of photons due to reflection is included in the QE measurement as well
566  //to avoid double-counting reflections, we correct by pmtReflectionsCorr = 1.0/T(fPMT_n=2.58) = 1.24
567  //we assume QE was measured for normal incidence, hence T is also calculated for normal incidence
568 
569  double pmtRefl = Sqr((1.0 - fPMT_n) / (1.0 + fPMT_n));
570  double pmtReflectionsCorr = 1.0 / (1.0 - pmtRefl);
571 
572  double photonWeight = (weight * filterFactor * pmtReflectionsCorr * qEff.Y(wavelength) / qEff.Y(normWavelength) *
573  efficiencyCorrection);
574 
575  // DEBUG drum mode with halo
576  //cout << "modified photon weight = " << photonWeight << endl;
577  //cout << "filterFactor_reduced = " << filterFactor << " ";
578  //cout << "qEff: " << qEff.Y(wavelength) << " / " << qEff.Y(normWavelength)
579  // << " = " << qEff.Y(wavelength)/qEff.Y(normWavelength) << endl;
580 
581  // iPhoton is initial photon before ray tracing, photonWeight is weight after ray tracing and corrections
582  // In drum mode there is no weight. Photons can only get absorbed or otherwise have weight 1.
583  //
584 
585 #if 0
586  // TODO maybe get rid of that and make no difference anymore between drum mode and normal simulation
587  //if (fDrumMode) {
588  if (RandFlat::shoot(&fRandomEngine->GetEngine(), 0., 1.) > photonWeight / iPhoton->GetWeight()) {
589  rayTracerResults[eAbsorbed]++;
590  continue; // photon absorbed
591  }
592  else
593  photonWeight = 1.;
594  //}
595 #endif
596 
597  // counts total photons (using weights) at the several mercedes surfaces
598  switch (nReflections) {
599  case 0: fNHit[index] += photonWeight; break; // direct hit
600  case 1: fN_1[index] += photonWeight; break;
601  case 2: fN_2[index] += photonWeight; break;
602  case 3: fN_3[index] += photonWeight; break;
603  case 4: fN_4[index] += photonWeight; break;
604  case 5: fN_5[index] += photonWeight; break;
605  case 6: fN_6[index] += photonWeight; break;
606  }
607 
608  // create pixels trace if not there yet
609  if (!traces.count(pxlId)) {
610  if (!telEvent.HasPixel(pxlId))
611  telEvent.MakePixel(pxlId);
612  fevt::Pixel& pixData = telEvent.GetPixel(pxlId);
613  if (!pixData.HasSimData())
614  pixData.MakeSimData();
615  fevt::PixelSimData& pixSimData = pixData.GetSimData();
616  if (!pixSimData.HasPhotonTrace(fevt::FdConstants::eTotal))
617  pixSimData.MakePhotonTrace(telTraceNBins, telTraceBinWidth, fevt::FdConstants::eTotal);
618  traces[pxlId] = &(pixSimData.GetPhotonTrace(fevt::FdConstants::eTotal));
619  }
620  // add to pixel's trace
621  (*(traces[pxlId]))[bin] += photonWeight;
622 
624  const fevt::FdConstants::LightSource lightSource =
625  (fevt::FdConstants::LightSource)iPhoton->GetSource();
626  fevt::PixelSimData& pixSimData = telEvent.GetPixel(pxlId).GetSimData();
627  if (!pixSimData.HasPhotonTrace(lightSource))
628  pixSimData.MakePhotonTrace(telTraceNBins, telTraceBinWidth, lightSource);
629  pixSimData.GetPhotonTrace(lightSource)[bin] += photonWeight;
630  if (!pixSimData.HasPhotonWeightSquareTrace(lightSource))
631  pixSimData.MakePhotonWeightSquareTrace(telTraceNBins, telTraceBinWidth, lightSource);
632  pixSimData.GetPhotonWeightSquareTrace(lightSource)[bin] += photonWeight*photonWeight;
633  }
634 
635  } // loop Photons
636  delete rayTracer;
637 
638  if (fVerbosityLevel > 0) {
639  int debugTotal = 0;
640  for(map<int, int>::const_iterator iRTR = rayTracerResults.begin();
641  iRTR != rayTracerResults.end(); ++iRTR) {
642  cout << " RayTraceResult \"" << RTResultName[iRTR->first] << "\" occured "
643  << iRTR->second << " times " << endl;
644  debugTotal += iRTR->second;
645  }
646  cout << " RayTraceResult \"total\" number of photons is " << debugTotal << endl;
647  cout << " RayTraceResult wl-boundaries: " << countWlBoundary << endl;
648  //cout << " RayTraceResult filter: " << countFilter << endl;
649  //cout << " RayTraceResult mirror: " << countMirror << endl;
650  cout << " RayTraceResult grand-total: " << debugTotal + /*countFilter + countMirror +*/ countWlBoundary << endl;
651  }
652 
653 
654  if (fVerbosityLevel > 2) {
655  // Output pixels with signal
656  for (map<int,TraceD*>::iterator iTrace = traces.begin();
657  iTrace != traces.end(); ++iTrace) {
658  const int pxlId = iTrace->first;
659  const int col = (pxlId - 1) / detTel.GetLastRow() + 1; // (col-1)*lastRow + row;
660  const int row = (pxlId - 1) % detTel.GetLastRow() + 1;
661 
662  cerr << "eyeId=" << eyeId << " telId=" << telId << " pixelId=" << pxlId
663  << " col=" << col << " row=" << row
664  << " trace:"
665  << flush;
666 
667  double signal = 0;
668  for (unsigned int i = 0; i < telTraceNBins; ++i) {
669  if (fVerbosityLevel > 3) {
670  if ((*(iTrace->second))[i])
671  cerr << " i: " << i
672  << " val: " << (*(iTrace->second))[i]
673  << " |"
674  << flush;
675  }
676  signal += (*(iTrace->second))[i];
677  }
678  cerr << " total signal " << signal << endl;
679  }
680  } // end verbose
681 
682  } // End loop over Telescopes
683 
684  } // End loop over Eyes
685 
686  return eSuccess;
687 } // end of Run
688 
689 
692 {
693  // -- shadow factor calculation --
694  //if (fDrumMode) {
695  //TDirectory* save = gDirectory;
696  //TFile output(fShadowDataOutName.c_str(), "UPDATE");
697  for (map<int, unsigned int>::const_iterator iter = fNHit.begin();
698  iter != fNHit.end(); ++iter)
699  {
700  const int index = iter->first;
701 /*
702  ostringstream name;
703  name << "shadow_" << index;
704  TTree* tree = (TTree*) output.Get(name.str().c_str());
705  if (!tree) {
706  tree = new TTree(name.str().c_str(), "shadow info");
707  tree->Branch("direct", &fNHit[index], "direct/i");
708  tree->Branch("refl1", &fN_1[index], "refl1/i");
709  tree->Branch("refl2", &fN_2[index], "refl2/i");
710  tree->Branch("refl3", &fN_3[index], "refl3/i");
711  tree->Branch("refl4", &fN_4[index], "refl4/i");
712  tree->Branch("refl5", &fN_5[index], "refl5/i");
713  tree->Branch("refl6", &fN_6[index], "refl6/i");
714  } else {
715  tree->SetBranchAddress("direct", &fNHit[index]);
716  tree->SetBranchAddress("refl1", &fN_1[index]);
717  tree->SetBranchAddress("refl2", &fN_2[index]);
718  tree->SetBranchAddress("refl3", &fN_3[index]);
719  tree->SetBranchAddress("refl4", &fN_4[index]);
720  tree->SetBranchAddress("refl5", &fN_5[index]);
721  tree->SetBranchAddress("refl6", &fN_6[index]);
722  }
723  tree->Fill();
724  tree->Write();
725 */
726  ostringstream info;
727  info << "\n\n ------------- SHADOW INFO (telId=" << index << ") -----------" << "\n"
728  << " Direct hit of focal surface: " << fNHit[index] << "\n"
729  << " 1 mercedes refl. : " << fN_1[index] << "\n"
730  << " 2 mercedes refl. : " << fN_2[index] << "\n"
731  << " 3 mercedes refl. : " << fN_3[index] << "\n"
732  << " 4 mercedes refl. : " << fN_4[index] << "\n"
733  << " 5 mercedes refl. : " << fN_5[index] << "\n"
734  << " 6 mercedes refl. : " << fN_6[index] << "\n";
735 
736  const double nTot = ((double)fN_1[index] +
737  (double)fN_2[index] +
738  (double)fN_3[index] +
739  (double)fN_4[index] +
740  (double)fN_5[index] +
741  (double)fN_6[index]);
742  const double nMercedes = ((double)fN_1[index] * 1. +
743  (double)fN_2[index] * 2. +
744  (double)fN_3[index] * 3. +
745  (double)fN_4[index] * 4. +
746  (double)fN_5[index] * 5. +
747  (double)fN_6[index] * 6.);
748  const double meanRefls = (double(nMercedes) / (fNHit[index] + nTot));
749  info << " Mean number of reflections from mercedes: " << meanRefls << " at tel=" << index << "\n";
750  info << " -----------------------------------------------------------------";
751  INFO(info);
752  // }
753  //output.Close();
754  //gDirectory = save;
755  }
756  return eSuccess;
757 }
758 
759 
760 #if 0
761 // --------------------------
762 // Wed Jul 26 10:51:33 CEST 2006
763 // this is for SG spot tables !!!!!!!!!
764 void
765 TelescopeSimulator::TransformToLocalCameraCoordinates(const double laz, const double lze, double& caz, double& cze)
766 {
767  const double phi0 = 16.*kPi/180.;
768 
769  const double llaz = lze + 0.5*kPi;
770  const double llze = laz + 0.5*kPi;
771 
772  const double xx = sin(llaz) * cos(llze);
773  const double yy = sin(llaz) * sin(llze);
774  const double zz = cos(llaz);
775 
776  const double x = xx;
777  const double y = yy * cos(phi0) - zz * sin(phi0);
778  const double z = yy * sin(phi0) + zz * cos(phi0);
779 
780  caz = asin(x);
781  cze = phi0 - atan(z/y);
782 }
783 #endif
784 
Branch GetTopBranch() const
Definition: Branch.cc:63
double GetModelRelativeEfficiency(const double wl) const
unsigned int GetId() const
Definition: FEvent/Eye.h:54
bool HasPhotonWeightSquareTrace(const FdConstants::LightSource source) const
Check that trace of sums of squares of weights of simulated photons for source /par source is present...
Definition: PixelSimData.h:91
double GetFADCBinSize() const
constexpr double mm
Definition: AugerUnits.h:113
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
constexpr T Sqr(const T &x)
Report success to RunController.
Definition: VModule.h:62
int GetNumberOfPhotonBins() const
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
void MakePhotonWeightSquareTrace(unsigned int size, double binning, const FdConstants::LightSource source=FdConstants::eTotal)
Definition: PixelSimData.cc:54
RandomEngineType & GetEngine()
Definition: RandomEngine.h:32
bool HasFEvent() const
Class to hold collection (x,y) points and provide interpolation between them.
const utl::TabulatedFunction & GetTransmittance() const
Average transmittance of the filter as a function of the wavelength.
bool HasSimShower() const
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
double GetMeasuredRelativeEfficiency(const double wl) const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
static void TransformToLocalCameraCoordinates(const double laz, const double lze, double &caz, double &cze)
double GetWeight() const
weight assigned to the photon
Definition: Photon.h:21
double GetModelMinWavelength() const
Definition: FDetector.cc:291
PixelSimData & GetSimData()
Definition: FEvent/Pixel.h:35
boost::filter_iterator< ComponentSelector, AllEyeIterator > EyeIterator
selective Eye iterators
Definition: FEvent.h:55
const std::string & GetConfigSignatureStr(const std::string &module) const
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
bool HasPhotonTrace(const FdConstants::LightSource source) const
Check that trace for source /par source is present.
Definition: PixelSimData.h:51
std::string GetVersionInfo(const VersionInfoType v) const
Retrieve different sorts of module version info.
Definition: VModule.cc:26
void MakeSimData()
Definition: FEvent/Pixel.cc:10
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
PhotonIterator PhotonsEnd()
const Camera & GetCamera() const
Get the Camera object that belongs to the telescope.
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
constexpr double nanometer
Definition: AugerUnits.h:102
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
constexpr double deg
Definition: AugerUnits.h:140
void SetConfigSignatureStr(const std::string &configSignatureStr)
void MakePixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Make Pixel telescopeId.
bool HasPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Check if the pixel is in the event.
fevt::TelescopeSimData & GetSimData()
Description of simulated data for one Telescope.
Class representing a document branch.
Definition: Branch.h:107
LightSource
Possible light sources.
Definition: FdConstants.h:9
Fluorescence Detector Pixel event.
Definition: FEvent/Pixel.h:28
const utl::TabulatedFunction & GetQEfficiency() const
Average quantum efficiency as a function of the wavelength.
double GetModelMaxWavelength() const
Definition: FDetector.cc:312
const double ns
TelescopeIterator TelescopesEnd()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:230
constexpr double kPi
Definition: MathConstants.h:24
Simulates all ray tracing inside a telescope.
Definition: /RayTracer.h:43
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
EyeIterator EyesBegin(const ComponentSelector::Status status)
Definition: FEvent.h:58
const fdet::FDetector & GetFDetector() const
Definition: Detector.cc:131
bool HasSimData() const
Definition: FEvent/Pixel.h:38
utl::TraceD & GetPhotonWeightSquareTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Trace of the sums of squares of simulated photon weights.
Definition: PixelSimData.h:78
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
Definition: FEvent/Eye.h:72
unsigned int GetLastRow() const
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
std::list< utl::Photon >::iterator PhotonIterator
RTResult Trace(const utl::Photon &photonIn, utl::Photon &photonOut, int &nreflections, int &nbackscattered, int &col, int &row)
Raytracing through the telescope components.
Definition: /RayTracer.cc:192
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:207
double GetInterval() const
Get the time interval as a double (in Auger base units)
Definition: TimeInterval.h:69
double GetReferenceLambda() const
Definition: FDetector.cc:332
Pixel & GetPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Pixel by Id, throw exception if not existent.
const std::string RTResultName[SIZE_RTResult]
Definition: /RTResult.h:52
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
Detector description interface for Telescope-related data.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
Definition: FDetector.cc:150
const Filter & GetFilter() const
Get the filter that belongs to the telescope.
PhotonIterator PhotonsBegin()
Description of a pixel.
utl::TraceD & GetPhotonTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Simulated Photon Trace.
Definition: PixelSimData.h:37
constexpr double cm
Definition: AugerUnits.h:117
Report failure to RunController, causing RunController to terminate execution.
Definition: VModule.h:64
Fluorescence Detector Telescope Event.
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
utl::TimeInterval GetTime() const
Definition: Photon.h:28
Fluorescence Detector Pixel Simulated Data.
Definition: PixelSimData.h:28
Description of a camera.
void MakePhotonTrace(unsigned int size, double binning, const FdConstants::LightSource source=FdConstants::eTotal)
Definition: PixelSimData.cc:31

, generated on Tue Sep 26 2023.