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 TelescopeSimulatorKG;
77 using CLHEP::RandFlat;
94 CentralConfig::GetInstance()->
GetTopBranch(
"TelescopeSimulatorKG");
97 &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
101 if (topB.
GetChild(
"verbosityLevel"))
141 info <<
" Version: " <<
GetVersionInfo(VModule::eRevisionNumber) <<
"\n"
144 info <<
" camera body shadow: " << (!
fDoNoShadow ?
"yes" :
"no") <<
"\n"
146 " mercedes collectors: " << (!
fHasNoMercedes ?
"yes" :
"no") <<
"\n";
156 ostringstream configSS;
157 configSS <<
"TelescopeSimulatorKG";
159 configSS <<
"(camera-shadow / support-shadow / mercedes) = ("
173 ERROR(
"Event has no FEvent.");
187 const Detector& detector = Detector::GetInstance();
197 const unsigned int eyeId = iEye->GetId();
204 const unsigned int telId = iTel->
GetId();
231 info <<
"Raytracing eye=" << eyeId
232 <<
", telescope=" << telId
234 <<
", nPhotons=" << nPhotons;
240 map<int, int> rayTracerResults;
245 fDraw, drawPhotonProbablility);
247 const int index = telId + eyeId * 100;
256 unsigned int countWlBoundary = 0;
257 unsigned int countFilterMirror = 0;
259 map<int, TraceD*> traces;
277 const double wavelength = iPhoton->GetWavelength();
278 const double inputWeight = iPhoton->GetWeight();
280 if (wavelength < minWl || wavelength > maxWl) {
285 const double filterMirFactor = mirRef.
Y(wavelength) * filtTrans.
Y(wavelength);
298 int nreflections = 0;
299 const RTResult status = rayTracer.
Trace(*iPhoton, photonOut, nreflections, col, row);
300 const double weight = photonOut.
GetWeight();
304 if (status !=
eOK ) {
305 rayTracerResults[status]++;
308 if (status ==
eOK && weight==0) {
325 rayTracerResults[status]++;
327 const unsigned int pxlId = (col-1)*detTel.
GetLastRow() + row;
333 double efficiencyWavelengthCorrection = 0;
337 efficiencyWavelengthCorrection = telMeasEfficiency.
Y(wavelength) / modelRelEff;
341 const int bin = int(time/telTraceBinWidth);
345 dbg <<
" bin=" << setw(4) << bin
346 <<
" time=" << setw(6) << time/
ns
347 <<
" weight=" << setw(4) << weight
348 <<
" wl=" << setw(4) << wavelength/
nanometer
349 <<
" col=" << setw(3) << col
350 <<
" row=" << setw(3) << row
351 <<
" pixelId=" << setw(3) << pxlId
352 <<
" telTraceBinWidth=" << setw(3) << telTraceBinWidth
353 <<
" telTraceNBins=" << setw(5) << telTraceNBins
354 <<
" EQ=" << qEff.
Y(wavelength)/qEff.
Y(normWavelength)
355 <<
" EC=" << efficiencyWavelengthCorrection;
359 if (bin < 0 || bin >=
int(telTraceNBins)) {
362 err <<
"Bin out of range. bin=" << bin
363 <<
" weight=" << weight;
371 const double QEffCorrection = qEff.
Y(wavelength) / qEff.
Y(normWavelength);
372 const double photonWeight =
373 (
fDrumMode ? 1 : (weight * filterMirFactor * QEffCorrection * efficiencyWavelengthCorrection));
375 switch (nreflections) {
376 case 0:
fNHit[index] += photonWeight;
break;
377 case 1:
fN_1[index] += photonWeight;
break;
378 case 2:
fN_2[index] += photonWeight;
break;
379 case 3:
fN_3[index] += photonWeight;
break;
380 case 4:
fN_4[index] += photonWeight;
break;
381 case 5:
fN_5[index] += photonWeight;
break;
382 case 6:
fN_6[index] += photonWeight;
break;
386 if (!traces.count(pxlId)) {
399 (*(traces[pxlId]))[bin] += photonWeight;
423 const double photonInputWeight = inputWeight * QEffCorrection * efficiencyWavelengthCorrection;
440 pixSimData.
MakePhotonTrace(telTraceNBins, telTraceBinWidth, lightSource);
453 for(map<int, int>::const_iterator iRTR = rayTracerResults.begin();
454 iRTR != rayTracerResults.end(); ++iRTR) {
455 info <<
" RayTraceResult \"" <<
RTResultName[iRTR->first] <<
"\" occured " << iRTR->second <<
" times " << endl;
456 debugTotal += iRTR->second;
458 info <<
" RayTraceResult \"total\" number of photons is " << debugTotal << endl;
459 info <<
" RayTraceResult wl-boundaries: " << countWlBoundary << endl;
460 info <<
" RayTraceResult filt-mirror: " << countFilterMirror << endl;
461 info <<
" RayTraceResult grand-total: " << debugTotal + countFilterMirror + countWlBoundary;
468 for (map<int,TraceD*>::iterator iTrace = traces.begin();
469 iTrace != traces.end(); ++iTrace) {
470 const int pxlId = iTrace->first;
471 const int col = (pxlId - 1) / detTel.
GetLastRow() + 1;
472 const int row = (pxlId - 1) % detTel.
GetLastRow() + 1;
475 info <<
"eyeId=" << eyeId <<
" telId=" << telId <<
" pixelId=" << pxlId
476 <<
" col=" << col <<
" row=" << row
480 for (
unsigned int i = 0; i < telTraceNBins; ++i) {
482 if ((*(iTrace->second))[i])
484 <<
" val: " << (*(iTrace->second))[i]
487 signal += (*(iTrace->second))[i];
489 info <<
" total signal " << signal;
508 TDirectory* save = gDirectory;
510 for (map<int, unsigned int>::const_iterator iter =
fNHit.begin();
511 iter !=
fNHit.end(); ++iter)
513 const int index = iter->first;
515 name <<
"shadow_" << index;
516 TTree* tree = (TTree*) output.Get(name.str().c_str());
518 tree =
new TTree(name.str().c_str(),
"shadow info");
519 tree->Branch(
"direct", &
fNHit[index],
"direct/i");
520 tree->Branch(
"refl1", &
fN_1[index],
"refl1/i");
521 tree->Branch(
"refl2", &
fN_2[index],
"refl2/i");
522 tree->Branch(
"refl3", &
fN_3[index],
"refl3/i");
523 tree->Branch(
"refl4", &
fN_4[index],
"refl4/i");
524 tree->Branch(
"refl5", &
fN_5[index],
"refl5/i");
525 tree->Branch(
"refl6", &
fN_6[index],
"refl6/i");
527 tree->SetBranchAddress(
"direct", &
fNHit[index]);
528 tree->SetBranchAddress(
"refl1", &
fN_1[index]);
529 tree->SetBranchAddress(
"refl2", &
fN_2[index]);
530 tree->SetBranchAddress(
"refl3", &
fN_3[index]);
531 tree->SetBranchAddress(
"refl4", &
fN_4[index]);
532 tree->SetBranchAddress(
"refl5", &
fN_5[index]);
533 tree->SetBranchAddress(
"refl6", &
fN_6[index]);
539 info <<
"\n\n ------------- SHADOW INFO (telId=" << index <<
") -----------" <<
"\n"
540 <<
" Direct hit of focal surface: " <<
fNHit[index] <<
"\n"
541 <<
" 1 mercedes refl. : " <<
fN_1[index] <<
"\n"
542 <<
" 2 mercedes refl. : " <<
fN_2[index] <<
"\n"
543 <<
" 3 mercedes refl. : " <<
fN_3[index] <<
"\n"
544 <<
" 4 mercedes refl. : " <<
fN_4[index] <<
"\n"
545 <<
" 5 mercedes refl. : " <<
fN_5[index] <<
"\n"
546 <<
" 6 mercedes refl. : " <<
fN_6[index] <<
"\n";
548 const double nTot = ((double)
fN_1[index] +
549 (
double)
fN_2[index] +
550 (double)
fN_3[index] +
551 (
double)
fN_4[index] +
552 (double)
fN_5[index] +
553 (
double)fN_6[index]);
554 const double nMercedes = ((double)
fN_1[index] * 1. +
555 (
double)
fN_2[index] * 2. +
556 (double)
fN_3[index] * 3. +
557 (
double)
fN_4[index] * 4. +
558 (double)
fN_5[index] * 5. +
559 (
double)fN_6[index] * 6.);
560 const double meanRefls = (double(nMercedes) / (
fNHit[index] + nTot));
561 info <<
" Mean number of reflections from mercedes: " << meanRefls <<
" at tel=" << index <<
"\n";
562 info <<
" -----------------------------------------------------------------";
587 const double phi0 = 16.*
kPi/180.;
589 const double llaz = lze + 0.5*
kPi;
590 const double llze = laz + 0.5*
kPi;
592 const double xx = sin(llaz) * cos(llze);
593 const double yy = sin(llaz) * sin(llze);
594 const double zz = cos(llaz);
597 const double y = yy * cos(phi0) - zz * sin(phi0);
598 const double z = yy * sin(phi0) + zz * cos(phi0);
601 cze = phi0 - atan(z/y);
Branch GetTopBranch() const
double GetModelRelativeEfficiency(const double wl) const
const std::string RTResultName[]
unsigned int GetId() const
std::map< int, unsigned int > fN_2
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
Report success to RunController.
int GetNumberOfPhotonBins() const
Fluorescence Detector Eye Event.
void MakePhotonWeightSquareTrace(unsigned int size, double binning, const FdConstants::LightSource source=FdConstants::eTotal)
RandomEngineType & GetEngine()
std::list< std::pair< utl::Photon, int > > PhotonList
Class to hold collection (x,y) points and provide interpolation between them.
std::map< int, unsigned int > fN_1
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)
double GetDiaphragmRadius() const
double GetMeasuredRelativeEfficiency(const double wl) const
#define INFO(message)
Macro for logging informational messages.
double GetWeight() const
weight assigned to the photon
double GetModelMinWavelength() const
PixelSimData & GetSimData()
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
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.
std::string GetVersionInfo(const VersionInfoType v) const
Retrieve different sorts of module version info.
PhotonIterator PhotonsEnd()
const Camera & GetCamera() const
Get the Camera object that belongs to the telescope.
Detector description interface for FDetector-related data.
std::map< int, unsigned int > fNHit
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
constexpr double nanometer
bool fStoreLightComponentsAtPixels
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
void SetConfigSignatureStr(const std::string &configSignatureStr)
PhotonList * fSpotPhotonList
void MakePixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Make Pixel telescopeId.
void SetSpotPhotonList(PhotonList &phList)
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.
LightSource
Possible light sources.
Fluorescence Detector Pixel event.
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)
Top of the hierarchy of the detector description interface.
EyeIterator EyesBegin(const ComponentSelector::Status status)
std::string fGeneralConfigSignature
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
std::string fShadowDataOutName
void GetData(bool &b) const
Overloads of the GetData member template function.
Top of Fluorescence Detector event hierarchy.
std::map< int, unsigned int > fN_5
std::list< utl::Photon >::iterator PhotonIterator
const utl::TabulatedFunction & GetReflectivity() const
Average reflectivity of the segments as a function of the wavelength.
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
double GetInterval() const
Get the time interval as a double (in Auger base units)
double GetReferenceLambda() const
utl::RandomEngine * fRandomEngine
Pixel & GetPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Pixel by Id, throw exception if not existent.
Simulates all ray tracing inside a telescope.
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.
PhotonIterator PhotonsBegin()
utl::TraceD & GetPhotonTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Simulated Photon Trace.
std::map< int, unsigned int > fN_4
const Mirror & GetMirror() const
Get the Mirror object that belongs to the telescope.
Report failure to RunController, causing RunController to terminate execution.
Fluorescence Detector Telescope Event.
RTResult Trace(const utl::Photon &photonIn, utl::Photon &photonOut, int &nreflections, int &col, int &row)
Raytracing through the telescope components.
std::map< int, unsigned int > fN_6
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.
utl::TimeInterval GetTime() const
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
static void TransformToLocalCameraCoordinates(const double laz, const double lze, double &caz, double &cze)
std::map< int, unsigned int > fN_3
Fluorescence Detector Pixel Simulated Data.
void MakePhotonTrace(unsigned int size, double binning, const FdConstants::LightSource source=FdConstants::eTotal)