12 #include <utl/config.h>
17 #include <utl/Reader.h>
18 #include <utl/ErrorLogger.h>
19 #include <utl/AugerUnits.h>
20 #include <utl/MathConstants.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>
33 #include <fwk/CentralConfig.h>
34 #include <fwk/CoordinateSystemRegistry.h>
35 #include <fwk/RandomEngineRegistry.h>
37 #include <det/Detector.h>
39 #include <fdet/FDetector.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>
48 #include <evt/Event.h>
50 #include <fevt/FEvent.h>
52 #include <fevt/TelescopeSimData.h>
53 #include <fevt/Telescope.h>
54 #include <fevt/PixelSimData.h>
55 #include <fevt/Pixel.h>
57 #include <boost/tuple/tuple.hpp>
59 #include <TDirectory.h>
63 #include <CLHEP/Random/Randomize.h>
69 using namespace TelescopeSimulatorKG2;
77 using CLHEP::RandFlat;
91 info <<
" Version: " <<
GetVersionInfo(VModule::eRevisionNumber) <<
"\n";
99 &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
102 CentralConfig::GetInstance()->
GetTopBranch(
"TelescopeSimulatorKG2");
104 info <<
" *** Output format: Parameter value (default value) ***\n";
113 info <<
" * Mirror size: " << (
fMirrorSize/
deg) <<
" deg (33.07)" <<
"\n";
116 if (topB.
GetChild(
"VerbosityLevel"))
134 if (topB.
GetChild(
"RayTracingOptions")){
144 info <<
" * Raytracing options: \n"
167 if (topB.
GetChild(
"MirrorOptions")){
176 Branch mirrorDiffusionTopB = mirrorOptionsB.
GetChild(
"MirrorDiffusionTop");
181 Branch mirrorDiffusionBotB = mirrorOptionsB.
GetChild(
"MirrorDiffusionBot");
187 err <<
"fMirrorDiffusion != 0 needed for halo. \n"
188 <<
"Can be set in the TelescopeSimulator xml file. \n"
189 <<
"Stop Simulation.";
196 info <<
" * Mirror options:" <<
"\n"
202 info <<
" mirror diffusion top function: ";
204 info <<
"no" <<
"\n";
206 info <<
"yes" <<
"\n";
208 info <<
" mirror diffusion bottom function: ";
210 info <<
"no" <<
"\n";
212 info <<
"yes" <<
"\n";
225 if (topB.
GetChild(
"FilterOptions")){
237 info <<
" * Filter options:" <<
"\n"
240 <<
" position (z-direction): " <<
fFilterPosition /
cm <<
" cm" <<
" (12.0)" <<
"\n"
267 info <<
" * Lens options:" <<
"\n"
269 <<
" position (z-direction): " <<
fLensPosition /
mm <<
" mm" <<
" (0.0)" <<
"\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";
279 if (topB.
GetChild(
"CameraOptions")){
284 info <<
" * Camera options: \n"
285 <<
" PMT window refractive index: " <<
fPMT_n <<
" (2.58)\n";
294 if (topB.
GetChild(
"DrawingOptions")) {
302 info <<
" Drawing options: \n"
311 ostringstream configSignature;
315 #warning TO DO: all changeable values have to enter all in configSignature of TelescopeSimulator.cc
317 configSignature <<
"TelescopeSimulatorKG2";
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") <<
")";
329 INFO(configSignature);
339 ERROR(
"Event has no FEvent.");
352 cout <<
"fDrumMode = true! " << endl;
356 const Detector& detector = Detector::GetInstance();
366 const unsigned int eyeId = iEye->GetId();
374 const unsigned int telId = iTel->
GetId();
403 info <<
"Raytracing telescope with " << nPhotons <<
" Photons";
409 map<int, int> rayTracerResults;
415 const int index = telId + eyeId * 100;
425 unsigned int countWlBoundary = 0;
431 unsigned int countPhotons = 0;
433 map<int, TraceD*> traces;
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)) {
460 const double wavelength = iPhoton->GetWavelength();
462 if (wavelength < minWl || wavelength > maxWl) {
472 int nReflections = 0;
473 int nHaloReflection = 0;
474 const RTResult status = rayTracer->
Trace(*iPhoton, photonOut, nReflections, nHaloReflection, col, row);
475 const double weight = photonOut.
GetWeight();
480 WARNING(
"********************** TERMINATED BY RAYTRACER ***************************");
484 if (status !=
eOK ) {
485 rayTracerResults[status]++;
488 if (status ==
eOK && weight == 0) {
500 rayTracerResults[status]++;
502 const unsigned int pxlId = (col - 1) * detTel.
GetLastRow() + row;
508 double efficiencyCorrection = 0;
512 efficiencyCorrection = telMeasEfficiency.
Y(wavelength) / modelRelEff;
525 const int bin = int(time / telTraceBinWidth);
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
543 if (bin < 0 || bin >=
int(telTraceNBins)) {
546 err <<
"Bin out of range. bin=" << bin
547 <<
" weight=" << weight;
553 double filterFactor = filtTrans.
Y(wavelength);
560 filterFactor /= 0.915;
570 double pmtReflectionsCorr = 1.0 / (1.0 - pmtRefl);
572 double photonWeight = (weight * filterFactor * pmtReflectionsCorr * qEff.
Y(wavelength) / qEff.
Y(normWavelength) *
573 efficiencyCorrection);
598 switch (nReflections) {
599 case 0:
fNHit[index] += photonWeight;
break;
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;
609 if (!traces.count(pxlId)) {
621 (*(traces[pxlId]))[bin] += photonWeight;
628 pixSimData.
MakePhotonTrace(telTraceNBins, telTraceBinWidth, lightSource);
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;
646 cout <<
" RayTraceResult \"total\" number of photons is " << debugTotal << endl;
647 cout <<
" RayTraceResult wl-boundaries: " << countWlBoundary << endl;
650 cout <<
" RayTraceResult grand-total: " << debugTotal + countWlBoundary << endl;
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;
660 const int row = (pxlId - 1) % detTel.
GetLastRow() + 1;
662 cerr <<
"eyeId=" << eyeId <<
" telId=" << telId <<
" pixelId=" << pxlId
663 <<
" col=" << col <<
" row=" << row
668 for (
unsigned int i = 0; i < telTraceNBins; ++i) {
670 if ((*(iTrace->second))[i])
672 <<
" val: " << (*(iTrace->second))[i]
676 signal += (*(iTrace->second))[i];
678 cerr <<
" total signal " << signal << endl;
697 for (map<int, unsigned int>::const_iterator iter =
fNHit.begin();
698 iter !=
fNHit.end(); ++iter)
700 const int index = iter->first;
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";
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 <<
" -----------------------------------------------------------------";
767 const double phi0 = 16.*
kPi/180.;
769 const double llaz = lze + 0.5*
kPi;
770 const double llze = laz + 0.5*
kPi;
772 const double xx = sin(llaz) * cos(llze);
773 const double yy = sin(llaz) * sin(llze);
774 const double zz = cos(llaz);
777 const double y = yy * cos(phi0) - zz * sin(phi0);
778 const double z = yy * sin(phi0) + zz * cos(phi0);
781 cze = phi0 - atan(z/y);
Branch GetTopBranch() const
double GetModelRelativeEfficiency(const double wl) const
unsigned int GetId() const
std::map< int, unsigned int > fNHit
double fFilterIncreaseReflectionInside
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...
double GetFADCBinSize() const
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
constexpr T Sqr(const T &x)
Report success to RunController.
double fMirrorAbsorptionTop
int GetNumberOfPhotonBins() const
Fluorescence Detector Eye Event.
void MakePhotonWeightSquareTrace(unsigned int size, double binning, const FdConstants::LightSource source=FdConstants::eTotal)
RandomEngineType & GetEngine()
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.
double fMirrorSegmentSigma
bool fSimulateCameraShadow
bool HasSimShower() const
EyeIterator EyesEnd(const ComponentSelector::Status status)
double GetMeasuredRelativeEfficiency(const double wl) const
#define INFO(message)
Macro for logging informational messages.
static void TransformToLocalCameraCoordinates(const double laz, const double lze, double &caz, double &cze)
double GetWeight() const
weight assigned to the photon
double fMirrorRadiusSigma
double GetModelMinWavelength() const
PixelSimData & GetSimData()
bool fDrawMercReflections
double fLensIncreaseReflection
boost::filter_iterator< ComponentSelector, AllEyeIterator > EyeIterator
selective Eye iterators
const std::string & GetConfigSignatureStr(const std::string &module) const
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
bool HasPhotonTrace(const FdConstants::LightSource source) const
Check that trace for source /par source is present.
bool fStoreLightComponentsAtPixels
std::string GetVersionInfo(const VersionInfoType v) const
Retrieve different sorts of module version info.
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.
bool fSimulateMercedesStars
constexpr double nanometer
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
bool fSimulateHaloEffects
void SetConfigSignatureStr(const std::string &configSignatureStr)
std::map< int, unsigned int > fN_6
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()
double fFilterPositionVertical
Description of simulated data for one Telescope.
Class representing a document branch.
double fFilterIncreaseReflectionOutside
std::string fShadowDataOutName
std::map< int, unsigned int > fN_4
LightSource
Possible light sources.
Fluorescence Detector Pixel event.
std::string fGeneralConfigSignature
const utl::TabulatedFunction & GetQEfficiency() const
Average quantum efficiency as a function of the wavelength.
double GetModelMaxWavelength() const
TelescopeIterator TelescopesEnd()
first available tel of status eHasData (DEPRECATED)
Simulates all ray tracing inside a telescope.
bool fSimualteCameraSupportShadow
Top of the hierarchy of the detector description interface.
utl::TabulatedFunction * fMirrorDiffusionBot
utl::RandomEngine * fRandomEngine
utl::TabulatedFunction * fMirrorDiffusionTop
EyeIterator EyesBegin(const ComponentSelector::Status status)
std::map< int, unsigned int > fN_5
const fdet::FDetector & GetFDetector() const
utl::TraceD & GetPhotonWeightSquareTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Trace of the sums of squares of simulated photon weights.
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
unsigned int GetLastRow() const
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
Top of Fluorescence Detector event hierarchy.
std::list< utl::Photon >::iterator PhotonIterator
std::vector< double > fMirrorDiffusionTopValues
RTResult Trace(const utl::Photon &photonIn, utl::Photon &photonOut, int &nreflections, int &nbackscattered, int &col, int &row)
Raytracing through the telescope components.
double fFilterPositionVertical2
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
std::map< int, unsigned int > fN_2
double GetInterval() const
Get the time interval as a double (in Auger base units)
double GetReferenceLambda() const
Pixel & GetPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Pixel by Id, throw exception if not existent.
std::map< int, unsigned int > fN_1
const std::string RTResultName[SIZE_RTResult]
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.
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
const Filter & GetFilter() const
Get the filter that belongs to the telescope.
bool fSimulateGhostEffects
double fMirrorAbsorptionBot
PhotonIterator PhotonsBegin()
double fFilterPositionHorizontal
utl::TraceD & GetPhotonTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Simulated Photon Trace.
std::vector< double > fMirrorDiffusionBotValues
Report failure to RunController, causing RunController to terminate execution.
double fFilterDustAbsorptionOutside
Fluorescence Detector Telescope Event.
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
std::vector< double > fMirrorDiffusionTopAngles
#define ERROR(message)
Macro for logging error messages.
utl::TimeInterval GetTime() const
std::map< int, unsigned int > fN_3
std::vector< double > fMirrorDiffusionBotAngles
int fMaxMirrorReflections
Fluorescence Detector Pixel Simulated Data.
void MakePhotonTrace(unsigned int size, double binning, const FdConstants::LightSource source=FdConstants::eTotal)
bool fSimulateFilterStructure