11 #include <utl/config.h>
15 #include <utl/Reader.h>
16 #include <utl/ErrorLogger.h>
17 #include <utl/AugerUnits.h>
18 #include <utl/MathConstants.h>
20 #include <utl/PhysicalConstants.h>
21 #include <utl/PhysicalFunctions.h>
22 #include <utl/Point.h>
23 #include <utl/TabulatedFunction.h>
24 #include <utl/TabulatedFunctionErrors.h>
25 #include <utl/Trace.h>
26 #include <utl/MultiTabulatedFunction.h>
27 #include <utl/Photon.h>
28 #include <utl/RandomEngine.h>
29 #include <utl/UTMPoint.h>
30 #include <utl/Photon.h>
32 #include <fwk/CentralConfig.h>
33 #include <fwk/RunController.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/Channel.h>
45 #include <fdet/Mirror.h>
46 #include <fdet/Filter.h>
47 #include <fdet/Corrector.h>
49 #include <evt/Event.h>
50 #include <evt/ShowerSimData.h>
52 #include <fevt/FEvent.h>
54 #include <fevt/TelescopeSimData.h>
55 #include <fevt/Telescope.h>
56 #include <fevt/PixelSimData.h>
57 #include <fevt/Pixel.h>
59 #include <atm/ProfileResult.h>
60 #include <atm/InclinedAtmosphericProfile.h>
62 #include <CLHEP/Random/Randomize.h>
64 #include <boost/tuple/tuple.hpp>
67 #include <TDirectory.h>
76 using namespace SpotPhotonGeneratorOG;
85 using CLHEP::RandFlat;
93 CentralConfig::GetInstance()->
GetTopBranch(
"SpotPhotonGenerator");
97 err <<
"Missing configuration file for SpotPhotonGenerator";
102 fRandomEngine = &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
120 << GetVersionInfo(VModule::eRevisionNumber) <<
"\n"
122 " number of photons: " << fNSpotPhotons <<
"\n"
123 " min radius: " << setw(3) << fRDiaMin/
m <<
"m\n"
124 " min bin: " << fMinBin <<
"\n"
125 " max bin: " << fMaxBin;
136 Detector& detector = Detector::GetInstance();
140 ERROR(
"No FEvent. Check your ModuleSequence.");
146 static bool initialized =
false;
154 event.GetHeader().SetTime(simTime);
157 event.GetHeader().SetId(idStr.str());
160 const unsigned int eyeId = iEye->GetId();
165 iTel != iEye->TelescopesEnd(); ++iTel) {
166 const unsigned int telId = iTel->
GetId();
169 ERROR(
"Telescope already there");
195 Detector& detector = Detector::GetInstance();
198 static bool finishedOneSpot =
false;
199 if (finishedOneSpot) {
203 fEvent.
GetEye(fCurrentEyeId,
218 static unsigned int iPix;
226 fCurrentEyeId = iEye->
GetId();
227 fCurrentTelId = iTel->GetId();
228 fCurrentPixId = iPix;
233 fSpotPhotonList.clear();
237 info1 <<
"generating spot for: eye: " << fCurrentEyeId
238 <<
", telescope: " << fCurrentTelId
239 <<
", pixel: " << fCurrentPixId;
248 map<int, TraceD*> traces;
249 for (
int i = 0; i < fNSpotPhotons; ++i) {
251 const double diaPh = RandFlat::shoot(&fRandomEngine->GetEngine(), 0, 2*
kPi);
252 const double diaR =
sqrt(RandFlat::shoot(&fRandomEngine->GetEngine(),
253 fRDiaMin*fRDiaMin, rDia*rDia));
255 const double xDia = diaR*cos(diaPh);
256 const double yDia = diaR*sin(diaPh);
257 const Point pIn(xDia, yDia, 0, telCS);
262 Vector nIn (1, theta, phi, telCS, Vector::kSpherical);
265 const double time = binWidth * RandFlat::shoot(&fRandomEngine->GetEngine(),
267 const double weight = 1;
268 utl::Photon photonIn(pIn, nIn, normWavelength, weight);
274 finishedOneSpot =
true;
297 if (fNSpotPhotons <= 0) {
299 err <<
"Cannot continue with fNSpotPhotons=" << fNSpotPhotons;
304 Detector& detector = Detector::GetInstance();
309 ostringstream spotname;
310 spotname <<
"Eye_" << fCurrentEyeId <<
"_Tel_" << fCurrentTelId <<
"_Pix_" << fCurrentPixId;
311 TH2D*
const hSpot =
new TH2D(spotname.str().c_str(), spotname.str().c_str(),
312 150, -2.75, 2.75, 150, -2.75, 2.75);
313 hSpot->SetXTitle(
"X [cm]");
314 hSpot->SetYTitle(
"Y [cm]");
315 hSpot->SetZTitle(
"Photons");
321 iPh != fSpotPhotonList.end(); ++iPh) {
323 if (RandFlat::shoot(&fRandomEngine->GetEngine(), 0., 1.) > iPh->first.GetWeight())
327 hSpot->Fill(iPh->first.GetPosition().GetX(pixelCS)/
cm,
328 iPh->first.GetPosition().GetY(pixelCS)/
cm);
331 const double efficiency = double(nPhotons) / fNSpotPhotons;
332 const double efficiencyErr =
sqrt((efficiency - efficiency*efficiency) / fNSpotPhotons);
334 info <<
" Efficiency is : " << setw(9) << setprecision(7) << efficiency
335 <<
" +- " << efficiencyErr
336 <<
" for " << fCurrentPixId;
339 fEfficiencies[fCurrentPixId] = efficiency;
340 fEfficienciesErr[fCurrentPixId] = efficiencyErr;
342 gStyle->SetPalette(1);
343 gStyle->SetOptStat(0);
344 gStyle->SetOptTitle(1);
345 TCanvas*
const cSpot =
new TCanvas(
"spot",
"spot", 500, 500);
346 cSpot->SetFillColor(0);
349 cSpot->Print(spotname.str().c_str());
360 filename <<
"Efficiencies_Eye_" << fCurrentEyeId <<
"_Tel_" << fCurrentTelId <<
".dat";
361 ofstream
file(filename.str().c_str());
363 info <<
" Pixel-Efficiencies for Eye: " << fCurrentEyeId <<
" Tel: " << fCurrentTelId <<
"\n";
365 const int lineBreak = 10;
368 for (
unsigned int i = 1; i <= fEfficiencies.size(); ++i) {
369 meanErr += fEfficienciesErr[i];
370 if ((i % lineBreak) == 1) {
374 info << setw(9) << setprecision(7) << fEfficiencies[i] <<
" ";
375 file << setw(9) << setprecision(7) << fEfficiencies[i] <<
" ";
376 if (((i + 1) % lineBreak) == 1) {
382 if (fEfficiencies.size())
383 meanErr /= fEfficiencies.size();
385 info <<
" <!-- Mean uncertainty on efficiencies is: " << meanErr <<
" --> \n";
386 file <<
" <!-- Mean uncertainty on efficiencies is: " << meanErr <<
" --> \n";
391 fEfficiencies.clear();
392 fEfficienciesErr.clear();
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
Branch GetTopBranch() const
unsigned int GetId() const
unsigned int GetId() const
By default from 1..440.
const utl::Vector & GetDirection() const
pointing direction of this pixel
double GetFADCBinSize() const
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Fluorescence Detector Eye Event.
Simulates the FD telescope.
unsigned int GetFirstPixelId() const
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
utl::TimeStamp GetTime() const
Get time pertaining to the detector description.
EyeIterator EyesEnd(const ComponentSelector::Status status)
double GetDiaphragmRadius() const
#define INFO(message)
Macro for logging informational messages.
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
void AddPhoton(const utl::Photon &p)
void MakeEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of 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)
boost::filter_iterator< ComponentSelector, AllEyeIterator > EyeIterator
selective Eye iterators
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
void MakeTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Make Telescope telescopeId.
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.
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
void SetPhotonsStartTime(const utl::TimeStamp &ts)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
void SetSpotPhotonList(PhotonList &phList)
fevt::TelescopeSimData & GetSimData()
Description of simulated data for one Telescope.
Class representing a document branch.
unsigned int GetLastPixelId() const
utl::CoordinateSystemPtr GetTelescopeCoordinateSystem() const
boost::filter_iterator< FDetComponentSelector, AllEyeIterator > EyeIterator
const Telescope & GetTelescope(const unsigned int telescopeId) const
Find Telescope by numerical Id.
Top of the hierarchy of the detector description interface.
EyeIterator EyesBegin(const ComponentSelector::Status status)
const fdet::FDetector & GetFDetector() const
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
PhotonList::const_iterator PhotonListConstIterator
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
void GetData(bool &b) const
Overloads of the GetData member template function.
Top of Fluorescence Detector event hierarchy.
Eye & GetEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
return Eye by id
double GetReferenceLambda() const
boost::filter_iterator< TelIsCommissioned, InternalConstTelescopeIterator > TelescopeIterator
An iterator over telescopes.
const utl::CoordinateSystemPtr & GetPixelCoordinateSystem() const
Detector description interface for Telescope-related data.
A TimeInterval is used to represent time elapsed between two events.
ResultFlag
Flag returned by module methods to the RunController.
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
bool HasTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Check if the telescope is in the event.
Fluorescence Detector Telescope Event.
void SetTime(const utl::TimeInterval &t)
void SetNumberOfPhotonBins(const int n)
#define ERROR(message)
Macro for logging error messages.
bool DoSpot(evt::Event &event)
EyeIterator EyesEnd(const FDetComponentSelector::Type type=FDetComponentSelector::ePhysical) const
iterator pointing to end of available eyes of given type (ePhysical, eVirtual, eAll) ...