FdBackgroundSimulator.cc
Go to the documentation of this file.
1 
13 #include <utl/Reader.h>
14 #include <utl/ErrorLogger.h>
15 #include <utl/AugerUnits.h>
16 #include <utl/MathConstants.h>
17 #include <utl/PhysicalConstants.h>
18 #include <utl/TabulatedFunction.h>
19 #include <utl/TabulatedFunctionErrors.h>
20 #include <utl/Trace.h>
21 #include <utl/MultiTabulatedFunction.h>
22 #include <utl/ReferenceEllipsoid.h>
23 #include <utl/Vector.h>
24 
25 #include <fwk/CentralConfig.h>
26 
27 #include <det/Detector.h>
28 #include <fdet/FDetector.h>
29 #include <fdet/Telescope.h>
30 #include <fdet/Pixel.h>
31 #include <fdet/Camera.h>
32 #include <fdet/Mirror.h>
33 #include <fdet/Corrector.h>
34 #include <fdet/Filter.h>
35 #include <fdet/Eye.h>
36 
37 
38 #include <evt/Event.h>
39 #include <fevt/FEvent.h>
40 #include <fevt/Eye.h>
41 #include <fevt/Telescope.h>
42 #include <fevt/TelescopeSimData.h>
43 #include <fevt/PixelSimData.h>
44 #include <fevt/Pixel.h>
45 
46 #include "FdBackgroundSimulator.h"
47 
48 using namespace FdBackgroundSimulatorOG;
49 using namespace std;
50 using namespace utl;
51 using namespace evt;
52 using namespace fwk;
53 using namespace det;
54 using namespace fevt;
55 
56 
58 
59  CentralConfig* cc = CentralConfig::GetInstance();
60 
61  Branch topB = cc->GetTopBranch("FdBackgroundSimulator");
62 
63  fVerbosity = 0;
64  if (topB.GetChild("verbosity"))
65  topB.GetChild("verbosity").GetData(fVerbosity);
66 
67  string tmp;
68  topB.GetChild("bgMode").GetData(tmp);
69  if (tmp=="table") {
70  fMode = eTable;
71  } else if (tmp=="parametric") {
72  fMode = eParametric;
73  } else if (tmp=="bgLoop") {
74  fMode = eBGLoop;
75  } else {
76  ostringstream err;
77  err << "unknown mode for bg model: " << tmp;
78  ERROR(err.str());
79  return eFailure;
80  }
81 
82  topB.GetChild("backgroundFlux").GetData(fBackgroundFlux);
83 
84  if (fBackgroundFlux.size()!=440) {
85  ERROR("Dimensions of the the vector with the photon background is different from 440. ");
86  return eFailure;
87  }
88 
89  // info output
90  ostringstream info;
91  info << " Version: "
92  << GetVersionInfo(VModule::eRevisionNumber) << "\n"
93  " Parameters:\n"
94  " bg photon model: ";
95  switch(fMode) {
96  case eTable: info << "XML datacard tables \n"; break;
97  case eBGLoop: info << "bgLoop database \n"; break;
98  case eParametric: info << "sky-variance parametrisation \n"; break;
99  default: info << "UNKNOWN \n"; break;
100  }
101  INFO(info);
102 
103  return eSuccess;
104 
105 } // end of Init
106 
107 
109 
110  if (!event.HasFEvent()) {
111  ERROR ("Event has no FEvent.");
112  return eFailure;
113  }
114 
115  FEvent& fEvent = event.GetFEvent();
116 
117  for (FEvent::EyeIterator iEye = fEvent.EyesBegin(ComponentSelector::eInDAQ);
118  iEye != fEvent.EyesEnd(ComponentSelector::eInDAQ);
119  ++iEye){
120 
121  if (iEye->GetStatus()==fevt::ComponentSelector::eDeSelected)
122  continue;
123 
124  fevt::Eye& eyeEvent = *iEye;
125 
126  for (fevt::Eye::TelescopeIterator iTel = eyeEvent.TelescopesBegin(ComponentSelector::eInDAQ);
127  iTel != eyeEvent.TelescopesEnd(ComponentSelector::eInDAQ);
128  ++iTel) {
129 
130 
131  fevt::Telescope& telEvent = *iTel;
132 
133  for (fevt::Telescope::PixelIterator iPixel = telEvent.PixelsBegin(ComponentSelector::eInDAQ);
134  iPixel != telEvent.PixelsEnd(ComponentSelector::eInDAQ);
135  ++iPixel) {
136 
137  if (iPixel->HasSimData()) {
138  if (fMode == eTable)
139  AddBackground(telEvent, event);
140  else
141  AddBackgroundFromVariance(telEvent, event);
142 
143  break; // move to next tel
144  }
145 
146  }// end loop over Pixels
147 
148  }// end loop over Telescopes
149 
150  }// end loop over Eyes
151 
152  return eSuccess;
153 
154 }// end of Run
155 
156 
157 
159  return eSuccess;
160 }// end of Finish
161 
162 
164  evt::Event& /*event*/)
165 {
166  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
167  const double normWavelength = detFD.GetReferenceLambda();
168 
169  unsigned int telId = telEvent.GetId();
170  unsigned int eyeId = telEvent.GetEyeId();
171 
172  if (fVerbosity > 0) {
173  ostringstream info;
174  info << "Loading photon background to eye=" << eyeId
175  << " mirror=" << telId;
176  INFO (info);
177  }
178 
179  const fdet::Telescope& detTel = detFD.GetTelescope(telEvent);
180  const fdet::Camera& detCamera = detTel.GetCamera();
181 
182  for (unsigned int pixelId = detTel.GetFirstPixelId();
183  pixelId <= detTel.GetLastPixelId();
184  ++pixelId) {
185 
186  if (!telEvent.HasPixel(pixelId))
187  telEvent.MakePixel(pixelId);
188 
189  fevt::Pixel& pix = telEvent.GetPixel(pixelId);
190  const fdet::Pixel& detPixel = detTel.GetPixel(pixelId);
191 
192  const double pixelAperture =
193  detTel.GetDiaphragmArea() * detPixel.GetSolidAngle();
194 
195  if (!pix.HasSimData())
196  pix.MakeSimData();
197 
198  fevt::PixelSimData& simdata = pix.GetSimData();
199 
201  ostringstream warn;
202  warn << "The pixel: " << pixelId << " already has a background trace.";
203  INFO (warn);
204  continue;
205  }
206 
207  const double timeBinSize = detCamera.GetFADCBinSize();
208 
209  //use diaPhotonToPE with the correct config of the TelescopeSimulator used
210  const string& configSignature = telEvent.GetSimData().GetConfigSignature();
211  const double diaPhotonToPE =
212  detPixel.GetDiaPhoton2PEFactor(normWavelength, configSignature);
213  const double opticalEfficiency =
214  diaPhotonToPE / detPixel.GetQEfficiency().Y(normWavelength);
215 
216  const double flux = fBackgroundFlux[pixelId-1];
217  const double bgPhotons = flux * pixelAperture * timeBinSize * opticalEfficiency;
218 
219  simdata.SetMeanBgPhotonFlux(bgPhotons);
220 
221  if (fVerbosity > 0) {
222  ostringstream info;
223  info << "bg-TABLE: Eye n." << eyeId << " mirror n." << telId
224  << " pixel n." << pixelId << " bgPhotons " << bgPhotons
225  << " OpticalFactor -> " << opticalEfficiency;
226  INFO(info);
227  }
228 
229  } // end loop over Pixels
230 
231  return true;
232 
233 } // end of AddBackground
234 
235 
237 {
238  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
239  const fdet::Telescope& detTel = detFD.GetTelescope(telEvent);
240  const fdet::Eye& detEye = detFD.GetEye(detTel.GetParentPhysicalEyeId());
241  const fdet::Camera& detCamera = detTel.GetCamera();
242  const double timeBinSize = detCamera.GetFADCBinSize();
243  const CoordinateSystemPtr& eyeCS = detEye.GetEyeCoordinateSystem();
244 
245 
246  // see IEEE Trans.Nucl.Sci.50:1208-1213,2003
247  //
248  // comment: here we increase the variance by analogElectronicsFactor
249  // to account for later reduction by Gaussian convolution
250  // in FdElectronicsSimulator...
251  //
252  const double cutoffFrequency = detCamera.GetCutoffFrequency();
253  const double noiseEqBdw = 0.5*cutoffFrequency*sqrt(kPi/log(2.0));
254  const double samplingFrequency = 1./timeBinSize;
255  const double analogElectronicsFactor = 2. * noiseEqBdw / samplingFrequency;
256 
257 
258  const double normWavelength = detFD.GetReferenceLambda();
259 
260  const unsigned int telId = telEvent.GetId();
261  const unsigned int eyeId = telEvent.GetEyeId();
262 
263  if (fVerbosity > 0) {
264  ostringstream info;
265  info << "Loading photon background to eye=" << eyeId
266  << " mirror=" << telId;
267  INFO (info);
268  }
269 
270  for (unsigned int pixelId = detTel.GetFirstPixelId();
271  pixelId <= detTel.GetLastPixelId();
272  ++pixelId) {
273 
274  if (!telEvent.HasPixel(pixelId))
275  telEvent.MakePixel(pixelId);
276 
277  fevt::Pixel& pixel = telEvent.GetPixel(pixelId);
278  const fdet::Channel& detChannel = detFD.GetChannel(pixel);
279  const fdet::Pixel& detPixel = detFD.GetPixel(pixel);
280 
281  if (!pixel.HasSimData())
282  pixel.MakeSimData();
283 
284  fevt::PixelSimData& simdata = pixel.GetSimData();
285 
287  ostringstream warn;
288  warn << "The pixel: " << pixelId << " already has a background trace.";
289  INFO (warn);
290  continue;
291  }
292 
293  const double VARelec = detChannel.GetElectronicNoiseVariance(); // [ADC counts**2]
294 
295  double VARsky = 0;
296  if(fMode==eBGLoop) {
297  VARsky = (detChannel.GetADCVariance() - VARelec);
298  }
299  else {
300  const double theta =
301  detTel.GetPixel(pixelId).GetDirection().GetTheta(eyeCS);
302  const double VARskyStandardASTel = GetParametricSkyVariance(theta);
303  VARsky = VARskyStandardASTel * timeBinSize / (100*ns);
304  }
305  VARsky /= analogElectronicsFactor;
306 
307  if (VARsky<=0) {
308  simdata.SetMeanBgPhotonFlux(0.0);
309  pixel.SetStatus(ComponentSelector::eDeSelected);
310  cout << " pixel de-selected: " << pixelId << endl;
311  continue;
312  }
313 
314  const TabulatedFunction& qEff = detPixel.GetQEfficiency();
315  const double absGain = detChannel.GetElectronicsGain(); // [ ADC per PE ]
316 
317  // see GAP 2004-072 for conversion
318 
319  const double Vg = detChannel.GetGainVariance();
320 
321  //double gain = 1; // todo
322  const double VARskyPE = VARsky / (absGain*absGain);
323  const double nPE = VARskyPE / (1+Vg);
324 
325  const double bgPhotons = nPE / qEff.Y(normWavelength);
326 
327  if (fVerbosity > 0) {
328  const double theta = detTel.GetPixel(pixelId).GetDirection().GetTheta(eyeCS);
329  ostringstream info;
330  if (fMode==eBGLoop) info << " bg-BGLoop: " ;
331  else info << " bg-Prmtrc: ";
332  info << " Eye n." << eyeId << " mirror n." << telId
333  << " pixel n." << pixelId << " pixel zenith "
334  << theta/deg << " var_sky " << VARsky << " bgPhotons " << bgPhotons;
335  INFO(info);
336  }
337 
338  simdata.SetMeanBgPhotonFlux(bgPhotons);
339 
340  } // end loop over Pixels
341 
342  return eSuccess;
343 
344 } // end of AddParametricBkg
345 
346 
347 
348 
349 
350 // variance [ADC^2] of standard Auger South telescopes, see GAP 2006-090
352 
353  const double f = 0.501;
354  const double k = 0.3862;
355  const double bl = 14.27;
356 
357  double V = 1 / sqrt (1 - 0.96*sin(theta)*sin(theta) );
358  double expon = -.4*k*(V-1);
359  double var = bl * ( 1 - f + f * V ) * pow(10., expon);
360 
361  return var;
362 }
363 
364 
365 // Configure (x)emacs for this file ...
366 // Local Variables:
367 // mode:c++
368 // compile-command: "cd $AUGER_BASE && make"
369 // End:
const utl::Vector & GetDirection() const
pointing direction of this pixel
double GetFADCBinSize() const
Description of the electronic channel for the 480 channels of the crate.
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
bool HasFEvent() const
unsigned int GetFirstPixelId() const
const Pixel & GetPixel(const fevt::Pixel &eventPixel) const
Get fdet::Pixel from fevt::Channel.
Definition: FDetector.cc:198
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
Class to hold collection (x,y) points and provide interpolation between them.
unsigned int GetParentPhysicalEyeId() const
double GetElectronicNoiseVariance() const
double GetCutoffFrequency() const
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
unsigned int GetEyeId() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
PixelSimData & GetSimData()
Definition: FEvent/Pixel.h:35
const Eye & GetEye(const unsigned int eyeId) const
Find eye by numerical Id.
Definition: FDetector.cc:68
Detector description interface for Eye-related data.
Definition: FDetector/Eye.h:45
boost::filter_iterator< ComponentSelector, AllEyeIterator > EyeIterator
selective Eye iterators
Definition: FEvent.h:55
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
double pow(const double x, const unsigned int i)
void MakeSimData()
Definition: FEvent/Pixel.cc:10
double GetElectronicsGain() const
const Camera & GetCamera() const
Get the Camera object that belongs to the telescope.
bool AddBackgroundFromVariance(fevt::Telescope &tel, evt::Event &event)
PixelIterator PixelsEnd()
iterator pointing to end of available pixels of status eHasData (DEPRECATED)
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
#define V
constexpr double deg
Definition: AugerUnits.h:140
void SetMeanBgPhotonFlux(const double mean)
Set mean bg photon flux.
Definition: PixelSimData.h:135
double GetSolidAngle() const
The solid angle viewed by this pixel.
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()
Class representing a document branch.
Definition: Branch.h:107
unsigned int GetLastPixelId() const
Fluorescence Detector Pixel event.
Definition: FEvent/Pixel.h:28
const utl::TabulatedFunction & GetQEfficiency() const
Average quantum efficiency as a function of the wavelength.
const double ns
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
TelescopeIterator TelescopesEnd()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:230
constexpr double kPi
Definition: MathConstants.h:24
bool AddBackground(fevt::Telescope &tel, evt::Event &event)
EyeIterator EyesBegin(const ComponentSelector::Status status)
Definition: FEvent.h:58
const Channel & GetChannel(const fevt::Channel &eventChannel) const
Get fdet::Channel from fevt::Channel.
Definition: FDetector.cc:161
const std::string & GetConfigSignature() const
bool HasSimData() const
Definition: FEvent/Pixel.h:38
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
Definition: FEvent/Eye.h:72
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
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
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:207
double GetGainVariance() const
double GetReferenceLambda() const
Definition: FDetector.cc:332
void SetStatus(ComponentSelector::Status status)
Definition: FEvent/Pixel.h:53
Pixel & GetPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Pixel by Id, throw exception if not existent.
boost::filter_iterator< ComponentSelector, AllPixelIterator > PixelIterator
selective Pixel iterators
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
unsigned int GetId() const
double GetDiaphragmArea() const
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
Description of a pixel.
Main configuration utility.
Definition: CentralConfig.h:51
double GetADCVariance() const
Fluorescence Detector Telescope Event.
PixelIterator PixelsBegin()
iterator pointing to first available pixel of status eHasData (DEPRECATED)
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
double GetDiaPhoton2PEFactor(const double wavelength, const std::string &configSignature="") const
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
Fluorescence Detector Pixel Simulated Data.
Definition: PixelSimData.h:28
Description of a camera.

, generated on Tue Sep 26 2023.