1 #include <utl/config.h>
5 #include <utl/Reader.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/AugerUnits.h>
8 #include <utl/MathConstants.h>
10 #include <utl/PhysicalConstants.h>
11 #include <utl/PhysicalFunctions.h>
12 #include <utl/Point.h>
13 #include <utl/TabulatedFunction.h>
14 #include <utl/TabulatedFunctionErrors.h>
15 #include <utl/Trace.h>
16 #include <utl/MultiTabulatedFunction.h>
17 #include <utl/Photon.h>
18 #include <utl/RandomEngine.h>
19 #include <utl/UTMPoint.h>
21 #include <fwk/CentralConfig.h>
22 #include <fwk/CoordinateSystemRegistry.h>
23 #include <fwk/RandomEngineRegistry.h>
25 #include <det/Detector.h>
27 #include <fdet/FDetector.h>
29 #include <fdet/Telescope.h>
30 #include <fdet/Camera.h>
31 #include <fdet/Pixel.h>
33 #include <evt/Event.h>
35 #include <fevt/FEvent.h>
37 #include <fevt/TelescopeSimData.h>
38 #include <fevt/Telescope.h>
39 #include <fevt/PixelSimData.h>
40 #include <fevt/Pixel.h>
42 #include <CLHEP/Random/Randomize.h>
44 #include <boost/tuple/tuple.hpp>
51 #include <G4RunManager.hh>
52 #include <G4UImanager.hh>
53 #include <G4VUserPhysicsList.hh>
55 #include <G4ProcessTable.hh>
68 using namespace TelescopeSimulatorLX;
76 using CLHEP::RandFlat;
83 fXMLManager.Init(
"TelescopeSimulatorLX");
87 INFO(
"Geant4 telescope ray-tracing (beta-version)");
91 ERROR(
"No XML configuration found for TelescopeSimulatorLX!");
102 fG4Standalone =
false;
104 fROOTFile =
"FDsimG4.root";
110 if (G4optionsB.
GetChild(
"ROOTFile"))
113 if (G4optionsB.
GetChild(
"G4MacroFile"))
116 if (G4optionsB.
GetChild(
"G4Standalone")) {
118 fG4Standalone = (instr ==
"yes");
121 if (G4optionsB.
GetChild(
"weightFactor"))
128 INFO(
"TelescopeSimulatorLX will be run in standalone mode.");
129 if (fG4MacroFile ==
"") {
130 ERROR (
"Standalone mode was selected but no macro file given.");
135 if (fG4MacroFile !=
"")
136 INFO(
"Reading Geant4 macro file.");
138 fWrite2ROOT =
nullptr;
140 #ifdef __TELESCOPE_SIMULATOR_LX_USE_ROOT__
141 if (!fROOTFile.empty())
145 INFO(
"Initializing FDsimG4");
147 fG4RunManager =
new G4RunManager();
152 fG4RunManager->SetUserInitialization(myDetector);
156 fG4RunManager->SetUserAction(fG4PrimGenAct);
165 fG4RunManager->SetUserAction(fG4EventAction);
168 visManager->Initialize();
171 fG4RunManager->Initialize();
174 fG4UImanager = G4UImanager::GetUIpointer();
180 fGeneralConfigSignature =
"TelescopeSimulatorKG";
195 Detector& detector = Detector::GetInstance();
203 event.GetHeader().SetTime(simTime);
204 event.GetHeader().SetId(
"");
207 itEye != detFD.
EyesEnd(); ++itEye) {
209 const int eyeId = itEye->GetId();
214 fevt::Eye& eyeEvent =
event.GetFEvent().GetEye(eyeId);
217 itTel != itEye->TelescopesEnd(); ++itTel) {
219 const int telId = itTel->
GetId();
231 const unsigned int telTraceNBins = 1000;
243 ERROR(
"Event has no FEvent.");
253 if (fWeightFactor != 1) {
254 ERROR(
"Photon weight-factor was not 1. Reseting!");
259 const Detector& detector = Detector::GetInstance();
270 const unsigned int eyeId = iEye->GetId();
278 const unsigned int telId = iTel->GetId();
284 #ifdef __TELESCOPE_SIMULATOR_LX_USE_ROOT__
288 fWrite2ROOT->SetTelCS(telCS);
289 fWrite2ROOT->SetEyeCS(eyeCS);
293 if (fVerbosityLevel > 0) {
295 info <<
"Raytracing eye=" << eyeId <<
", "
296 "telescope=" << telId <<
", "
301 if (!fG4MacroFile.empty()) {
302 const std::string command =
"/control/execute ";
303 fG4UImanager->ApplyCommand(command + fG4MacroFile);
306 if (!fG4Standalone) {
315 if (fVerbosityLevel > 0) {
317 info <<
"Raytracing nPhotons=" << nPhotons;
329 const double wavelength = iPhoton->GetWavelength();
331 if (wavelength < minWl || wavelength > maxWl)
349 g4Photon->
SetDirX(dir.GetX(telCS));
350 g4Photon->
SetDirY(dir.GetY(telCS));
351 g4Photon->
SetDirZ(dir.GetZ(telCS));
355 fG4Photons.push_back(g4Photon);
359 const int nPhot = fG4Photons.size();
362 info <<
"Processing " << nPhot <<
" photons...";
365 fG4PhotonsIter = fG4Photons.begin();
367 fG4RunManager->BeamOn(nPhot);
371 FillTraces(iEye, iTel);
385 delete fG4RunManager ;
387 G4VVisManager * visManager = G4VVisManager::GetConcreteInstance();
391 cout <<
"Vis manager deleted." << endl;
394 fG4EventAction = NULL;
396 #ifdef __TELESCOPE_SIMULATOR_LX_USE_ROOT__
398 fWrite2ROOT->SaveAndClose();
420 fG4PixelHits.push_back(g4PixelHit);
428 for (
const auto p : fG4Photons)
432 fG4PixelHits.clear();
440 Detector& detector = Detector::GetInstance();
443 const unsigned int eyeId = iEye->GetId();
445 const unsigned int telId = iTel->GetId();
459 map<int, TraceD*> traces;
466 for (
const auto& pixelHit : fG4PixelHits) {
468 const unsigned int pxlId = pixelHit.
GetPMTid();
471 const double weight = pixelHit.
GetWeight();
473 if (fVerbosityLevel > 1)
476 if (wavelength < minWl || wavelength > maxWl)
479 const int col = (pxlId - 1) / 22 + 1;
480 const int row = pxlId - 22*(col - 1) ;
484 err <<
" Pixel Id=" << pxlId <<
" does not exists on camera!"
485 <<
" col=" << col <<
" row=" << row;
493 if (wavelength < qEff[0].X() || wavelength > qEff[qEff.
GetNPoints()-1].X())
497 double efficiencyCorrection = 0;
501 efficiencyCorrection = telMeasEfficiency.
Y(wavelength) / modelRelEff;
504 const int bin = int(time / telTraceBinWidth);
506 if (fVerbosityLevel > 1) {
507 cerr <<
" bin=" << setw(4) << bin
508 <<
" time=" << setw(6) << time/
utl::ns
509 <<
" weight=" << setw(4) << weight
511 <<
" col=" << setw(3) << col
512 <<
" row=" << setw(3) << row
513 <<
" pixelId=" << setw(3) << pxlId
514 <<
" telTraceBinWidth=" << setw(3) << telTraceBinWidth
515 <<
" telTraceNBins=" << setw(5) << telTraceNBins
516 <<
" EQ=" << qEff.
Y(wavelength)/qEff.
Y(normWavelength)
517 <<
" EC=" << efficiencyCorrection
521 if (bin < 0 || bin >=
int(telTraceNBins)) {
523 if (fVerbosityLevel > 2) {
525 err <<
"Bin out of range. bin=" << bin
526 <<
" weight=" << weight <<
"telTraceNBins= " << telTraceNBins;
534 if (!traces.count(pxlId)) {
553 (*traces[pxlId])[bin] +=
554 (fDrumMode ? 1 : (weight * fWeightFactor
555 * qEff.
Y(wavelength) / qEff.
Y(normWavelength)
556 * efficiencyCorrection));
560 if (fVerbosityLevel > 2) {
562 for (
auto iTrace = traces.begin(); iTrace != traces.end(); ++iTrace) {
564 const int pxlId = iTrace->first;
566 const int col = (pxlId - 1) / 22 + 1;
567 const int row = (pxlId - 1) % 22 + 1;
569 cerr <<
"eyeId=" << eyeId <<
" telId=" << telId <<
" pixelId=" << pxlId <<
" "
570 "col=" << col <<
" row=" << row <<
" trace:";
573 for (
unsigned int i = 0; i < telTraceNBins; ++i) {
575 if (fVerbosityLevel > 3 && (*iTrace->second)[i]) {
576 cerr <<
" i: " << i <<
" val: " << (*iTrace->second)[i]
579 signal += (*iTrace->second)[i];
582 cerr <<
" total signal " << signal << endl;
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
Branch GetTopBranch() const
double GetModelRelativeEfficiency(const double wl) const
unsigned int GetId() const
unsigned int GetNPoints() const
double GetFADCBinSize() const
void SetWeight(double w=1.0)
int GetNumberOfPhotonBins() const
Fluorescence Detector Eye Event.
void SetPosY(double y=0.0)
unsigned int GetFirstPixelId() const
utl::TimeStamp GetTime() const
Get time pertaining to the detector description.
Class to hold collection (x,y) points and provide interpolation between them.
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()
void MakeEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
fwk::VModule::ResultFlag Run(evt::Event &event) override
Run: invoked once per event.
const Eye & GetEye(const unsigned int eyeId) const
Find eye by numerical Id.
EyeIterator EyesBegin(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to first eye of given type (ePhysical, eVirtual, eAll)
Detector description interface for Eye-related data.
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.
void SetPosX(double x=0.0)
void MakeTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Make Telescope telescopeId.
PhotonIterator PhotonsEnd()
const Camera & GetCamera() const
Get the Camera object that belongs to the telescope.
Detector description interface for FDetector-related data.
A TimeStamp holds GPS second and nanosecond for some event.
constexpr double nanometer
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
void SetPhotonsStartTime(const utl::TimeStamp &ts)
void FillTraces(const fevt::FEvent::EyeIterator &eIt, const fevt::Eye::TelescopeIterator &tIt)
void SetConfigSignatureStr(const std::string &configSignatureStr)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
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.
unsigned int GetLastPixelId() const
utl::CoordinateSystemPtr GetTelescopeCoordinateSystem() const
void SetUseGeneralParticleSource(G4bool use)
boost::filter_iterator< FDetComponentSelector, AllEyeIterator > EyeIterator
Fluorescence Detector Pixel event.
const utl::TabulatedFunction & GetQEfficiency() const
Average quantum efficiency as a function of the wavelength.
double GetModelMaxWavelength() const
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
TelescopeIterator TelescopesEnd()
first available tel of status eHasData (DEPRECATED)
void SetEnergy(double fEne=0.0)
void SetDirX(double dx=0.0)
Top of the hierarchy of the detector description interface.
EyeIterator EyesBegin(const ComponentSelector::Status status)
const fdet::FDetector & GetFDetector() const
FDsimG4StoreOpticalHit * GetG4Photon()
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
void GetData(bool &b) const
Overloads of the GetData member template function.
void SetG4PixelHit(const FDsimG4StoreOpticalHit &g4PixelHit)
Top of Fluorescence Detector event hierarchy.
std::list< utl::Photon >::iterator PhotonIterator
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
double GetWavelength() const
double GetInterval() const
Get the time interval as a double (in Auger base units)
double GetReferenceLambda() const
boost::filter_iterator< TelIsCommissioned, InternalConstTelescopeIterator > TelescopeIterator
An iterator over telescopes.
const utl::Vector & GetDirection() const
fevt::FEvent & GetFEvent()
fwk::VModule::ResultFlag Init() override
Initialize: invoked at beginning of run (NOT beginning of event)
Pixel & GetPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Pixel by Id, throw exception if not existent.
Manager for specific FD description parameters in XML file.
bool HasEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
void SetWavelength(double fWvl=0.0)
constexpr double kSpeedOfLight
Detector description interface for Telescope-related data.
void SetDirZ(double dz=0.0)
ResultFlag
Flag returned by module methods to the RunController.
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
PhotonIterator PhotonsBegin()
bool HasTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Check if the telescope is in the event.
utl::TraceD & GetPhotonTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Simulated Photon Trace.
void SetVerbosityLevel(G4int level)
fwk::VModule::ResultFlag Finish() override
Finish: invoked at end of the run (NOT end of the event)
void SetPosZ(double z=0.0)
Fluorescence Detector Telescope Event.
double GetWavelength() const
void SetTime(double fTi=0.0)
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
void SetNumberOfPhotonBins(const int n)
#define ERROR(message)
Macro for logging error messages.
utl::TimeInterval GetTime() const
void SetDirY(double dy=0.0)
Fluorescence Detector Pixel Simulated Data.
void MakePhotonTrace(unsigned int size, double binning, const FdConstants::LightSource source=FdConstants::eTotal)
EyeIterator EyesEnd(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to end of available eyes of given type (ePhysical, eVirtual, eAll) ...
const utl::Point & GetPosition() const