FdLightCollectionEfficiency.cc
Go to the documentation of this file.
1 
11 #include "SimMockEvent.h"
12 #include "SubModule.h"
14 #include "Bootstrapper.h"
15 #include "TimeRangeCalculator.h"
16 #include "CleanupSentry.h"
18 
19 //#define NDEBUG
20 #undef NDEBUG
21 #include <assert.h>
22 
23 // switch for writing debugging graphs to a ROOT file
24 //#define DEBUG
25 #undef DEBUG
26 
27 #include <vector>
28 #include <map>
29 #include <string>
30 
31 #include <fwk/CentralConfig.h>
32 #include <fwk/RunController.h>
33 
34 #include <utl/Reader.h>
35 #include <utl/ErrorLogger.h>
36 
37 #include <utl/TabulatedFunction.h>
38 
39 #include <utl/UTMPoint.h>
40 #include <utl/ReferenceEllipsoid.h>
41 #include <utl/Vector.h>
42 #include <utl/AxialVector.h>
43 #include <utl/TimeStamp.h>
44 
45 #include <utl/MathConstants.h>
46 #include <utl/PhysicalConstants.h>
47 #include <utl/AugerUnits.h>
48 #include <utl/CoordinateSystem.h>
49 #include <utl/AugerCoordinateSystem.h>
50 
51 #include <utl/Trace.h>
52 
53 #include <evt/Event.h>
54 #include <evt/ShowerRecData.h>
55 #include <evt/ShowerFRecData.h>
56 #include <evt/ShowerSimData.h>
57 #include <evt/VGaisserHillasParameter.h>
58 #include <evt/GaisserHillas2Parameter.h>
59 #include <evt/GaisserHillas4Parameter.h>
60 
61 #include <fevt/FEvent.h>
62 #include <fevt/Eye.h>
63 #include <fevt/EyeHeader.h>
64 #include <fevt/Telescope.h>
65 #include <fevt/EyeRecData.h>
66 #include <fevt/TelescopeRecData.h>
67 #include <fevt/TelescopeSimData.h>
68 #include <fevt/PixelRecData.h>
69 #include <fevt/Pixel.h>
70 #include <fevt/Channel.h>
71 #include <fevt/FdConstants.h>
72 
73 #include <det/Detector.h>
74 #include <atm/Atmosphere.h>
75 
76 #include <fdet/FDetector.h>
77 #include <fdet/Eye.h>
78 #include <fdet/Pixel.h>
79 #include <fdet/Channel.h>
80 #include <fdet/Camera.h>
81 #include <fdet/Telescope.h>
82 
83 #include <utl/AugerException.h>
84 #include <utl/Vector.h>
85 
86 #include <sstream>
87 
88 
89 // modules to be remote controlled
94 // just for the config MD5 hash generation for the calib. constants
96 
97 
98 // Still only for debugging, but then I'll get unused parameter errors. gcc--
99 //#ifdef DEBUG
100 #include <TFile.h>
101 #include <TH1D.h>
102 #include <TGraph.h>
103 #include <TGraphErrors.h>
104 //#endif
105 
106 using namespace FdLightCollectionEfficiencyKG;
107 using namespace fwk;
108 using namespace utl;
109 using namespace evt;
110 using namespace fevt;
111 using namespace det;
112 using namespace fdet;
113 using namespace std;
114 
115 
116 /*************************************************************************/
119 {
120  // Note: eCherDirect and eCherMieScattered will be automatically
121  // copied from eFluorDirect and eCherRayleighScattered
122  // efficiencies if missing!
123  fLightComponents.push_back(FdConstants::eFluorDirect);
124 // fLightComponents.push_back(FdConstants::eCherDirect);
125  fLightComponents.push_back(FdConstants::eCherRayleighScattered);
126 // fLightComponents.push_back(FdConstants::eCherMieScattered);
127 
128  // Read configuration
129  CentralConfig* cc = CentralConfig::GetInstance();
130 
131  Branch topB = cc->GetTopBranch("FdLightCollectionEfficiencyKG");
132 
133  Branch profCalcB = topB.GetChild("profileCalculation");
134  // steps in depth for calculation of the dEdX and Ne profiles
135  profCalcB.GetChild("depthBinning").GetData(fProfileXBinning);
136 
137  Branch lightAtDiaB = topB.GetChild("lightAtDiaphragm");
138  // factor the the number of bins in light@dia simulation
139  lightAtDiaB.GetChild("binning").GetData(fLightAtDiaBinning);
140 
141  Branch lightCollB = topB.GetChild("lightCollection");
142  lightCollB.GetChild("useZeta").GetData(fUseZeta);
143 
144  topB.GetChild("verbosity").GetData(fVerbosity);
145 
146  // Get the ShowerPhotonGeneratorOG overrides (ray tracing no. photons)
147  Branch rayTracingB = topB.GetChild("rayTracing");
148  rayTracingB.GetChild("minNRayTracePerBin").GetData(fMinNRayTracePerBin);
149  rayTracingB.GetChild("maxNRayTracePerBin").GetData(fMaxNRayTracePerBin);
150  rayTracingB.GetChild("extraRayTraceFactor").GetData(fExtraRayTraceFactor);
151  rayTracingB.GetChild("nIterations").GetData(fNRayTracingIterations);
152  rayTracingB.GetChild("targetUncertainty").GetData(fTargetUncertainty);
153  rayTracingB.GetChild("minRelevantEfficiency").GetData(fMinRelevantEfficiency);
154  rayTracingB.GetChild("maxIterations").GetData(fMaxIterations);
155  rayTracingB.GetChild("targetApertureLightUncertaintyChange").GetData(fTargetWorstCaseLAtApUncertaintyChange);
156  rayTracingB.GetChild("lowerLimitOnUncertainty").GetData(fLowerUncertaintyLimit);
157 
158  std::string stopCondition;
159  rayTracingB.GetChild("stopCondition").GetData(stopCondition);
160  if (stopCondition == "eFixed")
161  fStopCondition = eFixed;
162  else if (stopCondition == "eTargetUncertainty")
163  fStopCondition = eTargetUncertainty;
164  else if (stopCondition == "eSmallEnough")
165  fStopCondition = eSmallEnough;
166  else if (stopCondition == "eBootstrap")
167  fStopCondition = eBootstrap;
168  else
169  throw utl::XMLParseException("Invalid stop conditon. No such enumeration value.");
170 
171  // TODO: flexible sub-module configuration and selection from XML
172 
173  // This is the list of all modules we "control"
174  if (fSubModulesList.size() == 0) {
175  fSubModulesList["FdProfileReconstructorKG"] = SubModule("FdProfileReconstructorKG", fVerbosity);
176  fSubModulesList["ShowerLightSimulatorKG"] = SubModule("ShowerLightSimulatorKG", fVerbosity);
177  fSubModulesList["LightAtDiaphragmSimulatorKG"] = SubModule("LightAtDiaphragmSimulatorKG", fVerbosity);
178  fSubModulesList["ShowerPhotonGeneratorOG"] = SubModule("ShowerPhotonGeneratorOG", fVerbosity);
179  fSubModulesList["TelescopeSimulatorKG"] = SubModule("TelescopeSimulatorKG", fVerbosity);
180  fSubModulesList["FdElectronicsSimulatorOG"] = SubModule("FdElectronicsSimulatorOG", fVerbosity);
181  }
182 
183  // initialize the sub-modules
184  for (map<string, SubModule>::iterator iModule = fSubModulesList.begin();
185  iModule != fSubModulesList.end(); ++iModule) {
186  SubModule& subModule = iModule->second;
187  fwk::VModule::ResultFlag status = subModule.Init();
188  if (status != eSuccess) {
189  std::ostringstream msg;
190  msg << "SubModule '" << subModule.GetName() << "' failed Init()" << endl;
191  WARNING(msg);
192  return status;
193  }
194  }
195 
196  if (fVerbosity > 0) {
197  cout << "--[FdLightCollectionEfficiencyKG]--> Configuration:\n"
198  << " verbosity: " << fVerbosity << "\n"
199  << " simulated profile depth binning: " << fProfileXBinning/(g/cm/cm) << "\n"
200  << " use only pixels within zeta: " << (fUseZeta ? "true" : "false") << "\n"
201  << " number of ray-tracing iterations: " << fNRayTracingIterations << "\n"
202  << " min no. ray traced photons per bin: " << fMinNRayTracePerBin << "\n"
203  << " max no. ray traced photons per bin: " << fMaxNRayTracePerBin << "\n"
204  << " extra-ray-tracing-factor: " << fMaxNRayTracePerBin << "\n"
205  << endl;
206  }
207 
208  if (fVerbosity > -1) {
209  if (!fUseZeta) {
210  WARNING("Not using the light collection angle Zeta for calculating the light collection"
211  " efficiency. If you are not debugging the FdLightCollectionEfficiencyKG module,"
212  " then this is very likely an error in your configuration");
213  }
214  }
215 
216  return eSuccess;
217 }
218 
219 
220 /*************************************************************************/
223 {
224  if (!event.HasFEvent())
225  return eSuccess;
226 
227  return ProcessEvent(event);
228 }
229 
230 /*************************************************************************/
233 {
234  //const RunController& runCtrl = RunController::GetInstance();
235 
236  typedef map<int, ShowerFRecData*> FRecMap;
237  FRecMap dataSets;
238  const fwk::VModule::ResultFlag status = DoInitialReconstruction(realEvent, dataSets);
239  if (status != eSuccess)
240  return status;
241 
242  // Do simulation for each data set (each eye)
243  // FRecMap::iterator dataSetsIter = dataSets.begin(); // redundant definition
244  for (FRecMap::iterator dataSetsIter = dataSets.begin(), end = dataSets.end();
245  dataSetsIter != end; ++dataSetsIter)
246  {
247  const int eyeId = dataSetsIter->first;
248  ShowerFRecData& frecData = *dataSetsIter->second;
249 
250  // Don't clone. Some modules may be irritated if the
251  // event contains what they presume to be their own result before
252  // they even start
253  //evt::Event myEvent = realEvent;
254  SimMockEvent myEvent(fProfileXBinning);
255  myEvent.SetVerbosity(fVerbosity);
256 
257  bool atLeastOneTel = myEvent.PrepareEvent(eyeId, frecData, realEvent,
258  realEvent.GetFEvent().GetEye(eyeId));
259  if (!atLeastOneTel) {
260  ostringstream msg;
261  msg << "Skipping eye " << eyeId << ": Either not in DAQ or no good telescope.";
262  INFO(msg);
263  continue;
264  }
265 
267  status = fSubModulesList.find("ShowerLightSimulatorKG")->second.Run(myEvent.GetEvent());
268  if (status != eSuccess)
269  return status;
270 
271  status = fSubModulesList.find("LightAtDiaphragmSimulatorKG")->second.Run(myEvent.GetEvent());
272  if (status != eSuccess)
273  return status;
274 
275  // Run LightAtDiaphragmSimulatorKG
276  SubModule& lightAtDiaMod = fSubModulesList.find("LightAtDiaphragmSimulatorKG")->second;
277  /*LightAtDiaphragmSimulatorKG::LightAtDiaphragmSimulator& lightAtDia =
278  dynamic_cast<LightAtDiaphragmSimulatorKG::LightAtDiaphragmSimulator&>(lightAtDiaMod.GetModule());*/
279 
280 #warning THIS DOES NOT WORK LIKE THIS ANY MORE!!!!!!!!!!!!
281  // const double lightAtDiaBinning = lightAtDia.GetBinning(); // remember
282  // lightAtDia.SetBinning(fLightAtDiaBinning); // overwrite
283  status = lightAtDiaMod.Run(myEvent.GetEvent()); // RUN
284  // lightAtDia.SetBinning(lightAtDiaBinning); // reset
285 
286  if (status != eSuccess)
287  return status;
288 
289  // Initialize cached converter for light-at-pixel to light-at-aperture conversion
290  fLightConverter = new PixelToApertureLightConverter(det::Detector::GetInstance().GetFDetector(),
291  myEvent.GetEvent().GetFEvent().GetEye(eyeId, ComponentSelector::eExists));
292  CleanupSentry<PixelToApertureLightConverter> converterGuard(fLightConverter); // this'll clean up before scope exit
293 
294  for (unsigned int iLightSource = 0; iLightSource < fLightComponents.size(); ++iLightSource)
295  {
296  const fevt::FdConstants::LightSource lightSource = fLightComponents[iLightSource];
297 
298  fTimeCorrectedApertureTraces = new std::map<unsigned int, utl::TraceD>();
299  // this'll clean up before scope exit:
300  CleanupSentry<std::map<unsigned int, utl::TraceD> > apTracesGuard(fTimeCorrectedApertureTraces);
301 
302  // Run photon-generation and ray tracing iteratively
303  std::pair<VModule::ResultFlag, unsigned int> tmp
304  = RunPhotonGenerationRayTracingLoop(myEvent.GetEvent(), realEvent,
305  ( (fStopCondition==eTargetUncertainty
306  ||fStopCondition==eSmallEnough)
307  ? 1
308  : (unsigned int)fNRayTracingIterations ),
309  lightSource);
310  status = tmp.first;
311  const unsigned int nRayTraced = tmp.second;
312  if (status != eSuccess)
313  return status; // reporting done in RunPhotonGenerationRayTracingLoop
314 
315  // Note: We do not run FdElectronicsSimulatorOG at all,
316  // because it is only needed for the config hash calculation
317 
318  // The actual efficiency calculation...
319  if (fStopCondition != eBootstrap)
320  CalculateEfficiency(myEvent.GetEvent(), realEvent, eyeId,
321  nRayTraced, lightSource);
322  } // end for each light source
323 
324 #ifdef DEBUG
325  TFile* theFile = NULL;
326  if (fStopCondition == eBootstrap)
327  theFile = new TFile("lightCollectionEfficiency.root", "UPDATE");
328 #endif /* DEBUG */
329 
330  // Dual purpose loop:
331  // - Calculate lc-eff start/stop times
332  // - Copy Fluorescence LCEff to direct Cherenkov LCEff
333  // and Rayleigh sc. Ch. light to Mie sc. Ch. light
334  for (fevt::FEvent::EyeIterator iEye = realEvent.GetFEvent().EyesBegin(ComponentSelector::eHasData);
335  iEye != realEvent.GetFEvent().EyesEnd(ComponentSelector::eHasData); ++iEye)
336  {
337  fevt::Eye& realEye = *iEye;
338  for (fevt::Eye::TelescopeIterator iTel = realEye.TelescopesBegin(ComponentSelector::eHasData);
339  iTel != realEye.TelescopesEnd(ComponentSelector::eHasData); ++iTel)
340  {
341  fevt::Telescope& realTel = *iTel;
342  if (!realTel.HasRecData())
343  continue;
344  fevt::TelescopeRecData& recData = realTel.GetRecData();
345  if (!recData.HasLightCollectionEfficiency())
346  continue;
347 
349 
350  // lceff/aperture light time debugging couts...
351  /* const utl::TabulatedFunctionErrors& l = lcEff.GetTabulatedFunctionErrors(FdConstants::eFluorDirect);
352  const utl::TabulatedFunctionErrors& ap = recData.GetLightFlux(FdConstants::eTotal);
353  const list<pair<double, double> > ss = recData.GetSpotFarFromBorderTimeRanges();
354  cout << "eye " << realEye.GetId() << " tel " << realTel.GetId() << endl;
355  cout << " AP start time: " << ap.GetX(0) << endl;
356  cout << " lceff start time: " << l.GetX(0) << endl;
357  cout << " time ranges start times: ";
358  for (list<pair<double, double> >::const_iterator it = ss.begin(), end=ss.end();
359  it != end; ++it)
360  cout << it->first << " ";
361  cout << endl;
362  cout << " AP stop time: " << ap.GetX(ap.GetNPoints()-1) << endl;
363  cout << " lceff stop time: " << l.GetX(l.GetNPoints()-1) << endl;
364  cout << " time ranges stop times: ";
365  for (list<pair<double, double> >::const_iterator it = ss.begin(), end=ss.end();
366  it != end; ++it)
367  cout << it->second << " ";
368  cout << endl;
369  */
370 
371 
372  // Update l@aperture validity start/stop times
373  TimeRangeCalculator calc(recData, fVerbosity);
374  calc.UpdateSpotFarFromBorderTimes(fMinRelevantEfficiency);
375 
376  // eFluorDirect => eCherDirect if necessary
381 
382  // eCherRayleighScattered => eCherMieScattered if necessary
387 #ifdef DEBUG
388  if (fStopCondition == eBootstrap) {
389  for (utl::MultiTabulatedFunctionErrors::Iterator componentIt = lcEff.Begin(), end = lcEff.End();
390  componentIt != end; ++componentIt)
391  {
392  int component = componentIt->GetLabel();
393  const utl::TabulatedFunctionErrors& thisLCEff = lcEff.GetTabulatedFunctionErrors(component);
394  TGraphErrors* relHist = new TGraphErrors(thisLCEff.GetNPoints());
395  for (unsigned int i = 0; i < thisLCEff.GetNPoints(); ++i) {
396  relHist->SetPoint(i+1, thisLCEff.GetX(i), thisLCEff.GetY(i));
397  relHist->SetPointError(i+1, thisLCEff.GetXErr(i), thisLCEff.GetYErr(i));
398  }
399  ostringstream relname;
400  relname << "relHistFinal_e" << iEye->GetId() << "_t" << iTel->GetId() << "_c" << component;
401  relHist->SetNameTitle(relname.str().c_str(), relname.str().c_str());
402  relHist->Write();
403  } // end foreach light component
404  } // end if do bootstrap
405 #endif /* DEBUG */
406  } // end foreach telescope
407  } // end for eye
408 
409 #ifdef DEBUG
410  if (fStopCondition == eBootstrap)
411  theFile->Close();
412 #endif /* DEBUG */
413 
414  } // end foreach data set
415 
416  return eSuccess;
417 }
418 
419 
420 /*************************************************************************/
423 {
425 
426  // finish the sub-modules
427  for (map<string, SubModule>::iterator iModule = fSubModulesList.begin(), end = fSubModulesList.end();
428  iModule != end; ++iModule) {
429  SubModule& subModule = iModule->second;
430  fwk::VModule::ResultFlag status = subModule.Finish();
431  if (status != eSuccess) {
432  cerr << "SubModule '" << subModule.GetName() << "' failed Finish()" << endl;
433  return status;
434  }
435  if (fVerbosity >= 0)
436  subModule.PrintTiming(timeTab);
437  }
438 
439  // Print timing information
440  if (fVerbosity >= 0)
442 
443  return eSuccess;
444 }
445 
446 
447 /*************************************************************************/
448 bool
450  const int eyeId, const unsigned int nRayTracingIterations,
451  const fevt::FdConstants::LightSource lightSource)
452 {
453  if (fVerbosity > 0)
454  cout << "--[FdLightCollectionEfficiency]--> Calculating efficiency..." << endl;
455 
456  if (!simEvent.GetFEvent().HasEye(eyeId, ComponentSelector::eInDAQ)) {
457  ostringstream msg;
458  msg << "Efficiency calculation for eye " << eyeId
459  << ": FEvent doesn't have that eye after simulation";
460  ERROR(msg);
461  return false;
462  }
463 
464  const fevt::Eye& simEye = simEvent.GetFEvent().GetEye(eyeId, ComponentSelector::eInDAQ);
465  fevt::Eye& realEye = realEvent.GetFEvent().GetEye(eyeId, ComponentSelector::eHasData);
466 
467  for (fevt::Eye::TelescopeIterator iTel = realEye.TelescopesBegin(ComponentSelector::eHasData);
468  iTel != realEye.TelescopesEnd(ComponentSelector::eHasData); ++iTel) {
469  const unsigned int telId = iTel->GetId();
470  if (!realEye.HasTelescope(telId))
471  continue;
472  if (!realEye.GetTelescope(telId).HasRecData())
473  continue;
474 
475  try {
476  const fevt::Telescope& simTel = simEye.GetTelescope(iTel->GetId(), ComponentSelector::eInDAQ);
477  if (!CalculateTelescopeEfficiency(simTel, *iTel, realEye, nRayTracingIterations, lightSource))
478  continue;
480  cout << "Caught exception: " << e.GetMessage() << " => Skipping." << endl;
481  continue;
482  }
483  }
484 
485  return true;
486 }
487 
488 
489 /*************************************************************************/
490 bool
492  fevt::Telescope& realTel,
493  const fevt::Eye& realEye,
494  const unsigned int /*nRayTracingIterations*/,
495  const fevt::FdConstants::LightSource lightSource)
496 {
497  if (!simTel.HasSimData()) {
498  if (fVerbosity > 1)
499  cout << "--[FdLightCollectionEfficiency]--> Skipping efficiency calculation for telescope "
500  << simTel.GetId() << " of eye " << simTel.GetEyeId() << " (lack of sim data)\n";
501  return false;
502  }
503 
504  if (!realTel.HasRecData()
506  {
507  if (fVerbosity > 1)
508  cout << "--[FdLightCollectionEfficiency]--> Skipping efficiency calculation for telescope "
509  << simTel.GetId() << " of eye " << simTel.GetEyeId() << " (lack of telescope total l@ap)\n";
510  return false;
511  }
512 
513 
514  if (fVerbosity > 0) {
515  cout << "--[FdLightCollectionEfficiency]--> Calculating efficiency for telescope "
516  << simTel.GetId() << " of eye " << simTel.GetEyeId()
517  << "...\n";
518  }
519 
520  const utl::TimeStamp& tracesStartTime = simTel.GetTracesStartTime();
521  const fevt::TelescopeSimData& telSimData = simTel.GetSimData();
522  const utl::TimeStamp& simApertureStartTime = telSimData.GetPhotonsStartTime();
523 
524  if (!realTel.HasRecData()) {
525  ostringstream msg;
526  msg << "Telescope " << realTel.GetId() << " of eye " << realTel.GetEyeId()
527  << " has no TelescopeRecData => Skipping.";
528  WARNING(msg);
529  return false;
530  }
531 
532  fevt::TelescopeRecData& telRecData = realTel.GetRecData();
533 
534  // Get this telescope's time-corrected aperture light trace
535  if (fTimeCorrectedApertureTraces->find(simTel.GetId())
536  == fTimeCorrectedApertureTraces->end()) {
537  ostringstream msg;
538  msg << "Telescope " << realTel.GetId() << " of eye " << realTel.GetEyeId()
539  << " has no corrected light at aperture trace!";
540  ERROR(msg);
541  return false;
542  }
543  const utl::TraceD& correctedApTrace = (*fTimeCorrectedApertureTraces)[simTel.GetId()];
544 
545  if (!telRecData.HasLightCollectionEfficiency())
546  telRecData.MakeLightCollectionEfficiency();
547 
548 #ifdef DEBUG
549  TFile* const theFile = new TFile("lightCollectionEfficiency.root", "UPDATE");
550  WARNING("ENABLED DEBUG OUTPUT TO ROOT FILE 'lightCollectionEfficiency.root'");
551 #endif
552 
553  const vector<vector<unsigned int> >& pixelsInZeta = telRecData.GetPixelsInZetaOverTime();
554  const fdet::Eye& detEye = det::Detector::GetInstance().GetFDetector().GetEye(realEye.GetId());
555  const fdet::Channel& detChannel = detEye.GetTelescope(realTel.GetId()).GetChannel(1);
556 
557  const utl::TimeStamp eyeTriggerTime =
558  realEye.GetHeader().GetTimeStamp() -
559  TimeInterval(detChannel.GetFADCTraceLength() * detChannel.GetFADCBinSize() * nanosecond);
560 
561  // debugging output only
562  if (fVerbosity > 2) {
563  const utl::TimeStamp simApLightStartTime =
564  eyeTriggerTime + TimeInterval(simTel.GetTimeOffset()*nanosecond);
565  const utl::TimeStamp realApLightStartTime =
566  eyeTriggerTime + TimeInterval(realTel.GetTimeOffset()*nanosecond);
567 
568  cout << "================================================\n"
569  "= FdLightCollectionEfficiency debugging output =\n"
570  "================================================\n"
571  "Event time stamp: " << realEye.GetHeader().GetTimeStamp() << "\n"
572  "Eye Trigger time: " << eyeTriggerTime
573  << "(GPS nano: " << eyeTriggerTime.GetGPSNanoSecond() << ")\n"
574  "Real Aperture start time: " << realApLightStartTime
575  << "(GPS nano: " << realApLightStartTime.GetGPSNanoSecond() << ")\n"
576  "Calc. sim. start time: " << simApLightStartTime
577  << "(GPS nano: " << simApLightStartTime.GetGPSNanoSecond() << ")\n"
578  "Sim. Aperture start time (from trace): " << simApertureStartTime
579  << "(GPS nano: " << simApertureStartTime.GetGPSNanoSecond() << ")\n"
580  "Sim. Traces start time: " << tracesStartTime
581  << "(GPS nano: " << tracesStartTime.GetGPSNanoSecond() << ")\n"
582  "Diff (sim-real)/ns: " << (simApertureStartTime-realApLightStartTime).GetNanoSecond() << "\n"
583  "real TelTimeOff: " << realTel.GetTimeOffset() << "\n"
584  "trace length: " << TimeInterval(detChannel.GetFADCTraceLength()
585  * detChannel.GetFADCBinSize() * nanosecond).GetNanoSecond() << endl;
586  } // end debugging output only
587 
588  const double simTimeOffset = (simApertureStartTime - eyeTriggerTime).GetInterval() / ns;
589  if (fVerbosity > 0)
590  cout << " Simulation time offset: " << simTimeOffset << "ns" << endl;
591 
592  const utl::TabulatedFunctionErrors& realApLightFlux = telRecData.GetLightFlux();
593 
595  switch (lightSource) {
598  break;
603  break;
604  default:
605  throw utl::NonExistentComponentException("Unsupported LightSource!");
606  }
607 
608  const utl::TraceD totalWlTrace2 = CalculateTelescopeTraceSum(simTel, lightSource, emode);
609  const utl::TraceD& totalWlTrace = correctedApTrace; // FIXME: Temporary override...
610  cout << "Binning: " << totalWlTrace2.GetBinning() << " " << totalWlTrace.GetBinning() << endl;
611  cout << "Size: " << totalWlTrace2.GetSize() << " " << totalWlTrace.GetSize() << endl;
612  cout << "Start: " << totalWlTrace2.GetStart() << " " << totalWlTrace.GetStart() << endl;
613  cout << "Stop: " << totalWlTrace2.GetStop() << " " << totalWlTrace.GetStop() << endl;
614  double sum1 = 0., sum2 = 0.;
615  for (unsigned int i = 0; i< totalWlTrace.GetSize();++i) {
616  sum1 +=totalWlTrace[i];
617  sum2 += totalWlTrace2[i];
618  }
619  cout << "Sum:" << sum1 << " " << sum2 << endl;
620 
621  const double wlTraceBinSize = totalWlTrace.GetBinning();
622  const double wlTraceBins = totalWlTrace.GetSize();
623  if (wlTraceBins == 0) {
624  if (fVerbosity > 0) {
625  cout << "--[FdLightCollectionEfficiency]--> Skipping light component "
626  << lightSource << " for this telescope. No light-at-aperture trace.\n";
627  }
628  return false;
629  }
630 
631  const utl::TabulatedFunctionErrors totalPixelTrace =
632  CalculatePixelTraceSum(simTel, lightSource, simTimeOffset, pixelsInZeta, realApLightFlux);
633 
634  const double pixTraceBins = totalPixelTrace.GetNPoints();
635  if (pixTraceBins == 0) {
636  if (fVerbosity > 0) {
637  cout << "--[FdLightCollectionEfficiency]--> Skipping light component "
638  << lightSource << " for this telescope. No pixel traces.\n";
639  }
640  return false;
641  }
642 
643  if (fVerbosity > 1) {
644  cout << "Component " << lightSource << " wlTrace: nBins="
645  << wlTraceBins << ", binSize=" << wlTraceBinSize << "\n"
646  "Component " << lightSource << " pixTrace: nBins="
647  << pixTraceBins << "\n"
648  "Component " << lightSource << " nRayTraced: nBins="
650  << ", binSize=" << simTel.GetSimData().GetRayTracedPhotonTrace().GetBinning() << endl;
651  }
652 
654  CalcTraceDivision(totalPixelTrace, totalWlTrace,
656  1);
657  //nRayTracingIterations);
658 
659 #ifdef DEBUG
660  theFile->cd();
661  WriteDebugInfo(realEye.GetId(), simTel.GetId(), simTimeOffset, lightSource, totalPixelTrace, totalWlTrace, realApLightFlux, telEff);
662 #endif
663 
664  // Store the light collection efficiency for this light source
665  // in the TelescopeSimData
666 
668  if (lightCollEff.HasLabel(lightSource))
669  lightCollEff.GetTabulatedFunctionErrors(lightSource) = telEff;
670  else
671  lightCollEff.AddTabulatedFunctionErrors(telEff, lightSource);
672 
673 #ifdef DEBUG
674  theFile->Close();
675 #endif
676 
677  return true;
678 }
679 
680 
681 /*************************************************************************/
682 void
683 FdLightCollectionEfficiency::WriteDebugInfo(const int eyeId, const int simTelId, const double simTimeOffset,
684  const FdConstants::LightSource component,
685  const utl::TabulatedFunctionErrors& totalPixelTrace,
686  const utl::TraceD& totalWlTrace,
687  const utl::TabulatedFunctionErrors& realApLightFlux,
688  const utl::TabulatedFunctionErrors& telEff)
689 {
690  ostringstream pixname;
691  pixname << "pixHist_e" << eyeId << "_t" << simTelId << "_c" << component;
692  vector<double> pixHistX, pixHistY;
693  for (unsigned int i = 0; i < totalPixelTrace.GetNPoints(); ++i) {
694  pixHistX.push_back(totalPixelTrace.GetX(i) + simTimeOffset);
695  pixHistY.push_back(totalPixelTrace.GetY(i));
696  }
697  TGraph* const pixHist =
698  new TGraph(totalPixelTrace.GetNPoints(), &pixHistX.front(), &pixHistY.front());
699  pixHist->SetNameTitle(pixname.str().c_str(), pixname.str().c_str());
700  pixHist->Write();
701 
702  ostringstream apname;
703  apname << "apHist_e" << eyeId << "_t" << simTelId << "_c" << component;
704  TH1D* const apHist =
705  new TH1D(apname.str().c_str(), apname.str().c_str(),
706  totalWlTrace.GetSize(), simTimeOffset,
707  simTimeOffset + totalWlTrace.GetBinning()*totalWlTrace.GetSize());
708  for (unsigned int i = 1; i <= totalWlTrace.GetSize(); ++i)
709  apHist->SetBinContent(i, totalWlTrace.At(i-1));
710  apHist->Write();
711 
712  ostringstream realapname;
713  realapname << "realApLight_e" << eyeId << "_t" << simTelId << "_c" << component;
714  TGraph* const realAp =
715  new TGraph(realApLightFlux.GetNPoints(),
716  &realApLightFlux.XFront(), &realApLightFlux.YFront());
717  realAp->SetNameTitle(realapname.str().c_str(), realapname.str().c_str());
718  realAp->Write();
719 
720  ostringstream relname;
721  relname << "relHist_e" << eyeId << "_t" << simTelId << "_c" << component;
722  vector<double> relHistX, relHistXe, relHistY, relHistYe;
723  for (unsigned int i = 0; i < telEff.GetNPoints(); ++i) {
724  relHistX.push_back(telEff.GetX(i) + simTimeOffset);
725  relHistXe.push_back(telEff.GetXErr(i));
726  relHistY.push_back(telEff.GetY(i));
727  relHistYe.push_back(telEff.GetYErr(i));
728  }
729  TGraphErrors* const relHist =
730  new TGraphErrors(telEff.GetNPoints(), &relHistX.front(), &relHistY.front(),
731  &relHistXe.front(), &relHistYe.front());
732  relHist->SetNameTitle(relname.str().c_str(), relname.str().c_str());
733  relHist->Write();
734 }
735 
736 /*************************************************************************/
739  const fevt::FdConstants::LightSource lightSource,
740  const atm::Atmosphere::EmissionMode /*lightType*/)
741 {
742  const fevt::TelescopeSimData& telSimData = tel.GetSimData();
743  utl::TraceD totalWlTrace;
744  if (!telSimData.HasPhotonTrace(lightSource))
745  return totalWlTrace;
746 
747  const fdet::FDetector& fdetector = det::Detector::GetInstance().GetFDetector();
748  const fdet::Telescope& detTel = fdetector.GetEye(tel.GetEyeId()).GetTelescope(tel.GetId());
749 
750  //const atm::Atmosphere& atmo = det::Detector::GetInstance().GetAtmosphere();
751  //const vector<double>& wavelengths = atmo.GetWavelengths(lightType);
752 
753  const double refWl = fdetector.GetReferenceLambda();
754  //const TabulatedFunction& modelEfficiency = detTel.GetModelRelativeEfficiency(refWl);
755  const TabulatedFunction& measuredEfficiency = detTel.GetMeasuredRelativeEfficiency();
756  //const double refModelEfficiency = modelEfficiency.Y(refWl);
757  //const double refMeasuredEfficiency = measuredEfficiency.Y(refWl);
758 
759  // Note: Taking the Q-Eff from a single pixel may be a hack, but should *currently*
760  // be reliable: Here, the pixQEff is only used for determining the min/max
761  // supported wavelength. This whole min/max logi mimics what is done elsewhere
762  // in the same context, so we have to do the same in order to remain consistent.
763  const TabulatedFunction& pixelQEff = detTel.GetPixel(1).GetQEfficiency();
764  //const double refPixelQEff = pixelQEff.Y(refWl);
765 
766  // The efficiency TabulatedFunctions don't cover arbitrary wavelengths
767  const double minWl =
768  std::max(std::max(detTel.GetModelMinWavelength(), measuredEfficiency.GetX(0)), pixelQEff.GetX(0));
769  const double maxWl =
770  std::min(std::min(detTel.GetModelMaxWavelength(), measuredEfficiency.GetX(measuredEfficiency.GetNPoints()-1)),
771  pixelQEff.GetX( pixelQEff.GetNPoints() - 1));
772 
773  bool firstWl = true;
774 
775  const double diaArea = detTel.GetDiaphragmArea();
776  //cout << "diaArea: " << diaArea << endl;
777 
778  for (TelescopeSimData::ConstPhotonTraceIterator traceIter = telSimData.PhotonTracesBegin(lightSource),
779  end = telSimData.PhotonTracesEnd(lightSource);
780  traceIter != end; ++traceIter) {
781  const utl::TraceD& wlTrace = traceIter->GetTrace();
782  //cout << "Trace " << traceIter->GetLabel() << " length: " << wlTrace.GetSize() << endl;
783  // Note: overriding the wavelengths with the reference wavelength since
784  // we manually override the wavelength sampling in the ShowerPhotonGenerator
785  // TODO understand why this is necessary?
786  const double wl = refWl;//wavelengths[traceIter->GetLabel()];
787 
788  // Replicate the behaviour of the TelescopeSimulatorKG
789  if (wl < minWl || wl > maxWl) {
790  //cout << "Skipping wl. min="<<minWl << " wl=" << wl << " max=" << maxWl << endl;
791  continue;
792  }
793 
794  if (firstWl) {
795  // Set the binning/start/stop
796  totalWlTrace.SetBinning(wlTrace.GetBinning());
797  totalWlTrace.SetStart(wlTrace.GetStart());
798  totalWlTrace.SetStop(wlTrace.GetStop());
799 
800  for (unsigned int i = 0; i < wlTrace.GetSize(); ++i)
801  totalWlTrace.PushBack(0);
802 
803  firstWl = false;
804  } else {
805  // Note: This is likely not necessary as the start/end times should be the same for all
806  // wl's, but let's be defensive for now, it doesn't hurt.
807  // Also, the trace length should be quite the same.
808  if (wlTrace.GetStart() < totalWlTrace.GetStart())
809  totalWlTrace.SetStart(wlTrace.GetStart());
810  if (wlTrace.GetStop() > totalWlTrace.GetStop())
811  totalWlTrace.SetStop(wlTrace.GetStop());
812  if (wlTrace.GetSize() != totalWlTrace.GetSize())
813  throw OutOfBoundException("The wavelength-specific traces differ in their length!");
814  }
815 
816  for (unsigned int i = 0; i < wlTrace.GetSize(); ++i)
817  totalWlTrace[i] += wlTrace[i] * diaArea;
818 
819  } // end for each wavelength
820 
821  //cout << "total wl trace size=" << totalWlTrace.GetSize() << endl;
822  return totalWlTrace;
823 }
824 
825 
826 /*************************************************************************/
829  const fevt::FdConstants::LightSource component,
830  const double simTimeOffset,
831  const vector<vector<unsigned int> >& pixelsInZeta,
832  const utl::TabulatedFunctionErrors& realApLight)
833 {
834  utl::TabulatedFunctionErrors totalPixelTrace;
835 
836  const fdet::FDetector& theFDet = det::Detector::GetInstance().GetFDetector();
837  const fdet::Telescope& detTel = theFDet.GetTelescope( tel );
838  const unsigned int telId = tel.GetId();
839 
840  const unsigned int nPoints = realApLight.GetNPoints();
841  for (unsigned int iTimeBin = 0; iTimeBin < nPoints; ++iTimeBin) {
842  const vector<unsigned int>& thisTimeZetaPixels = pixelsInZeta[iTimeBin];
843  const double timeBinCenter = realApLight.GetX(iTimeBin) - simTimeOffset;
844  const double dtHalf = realApLight.GetXErr(iTimeBin); // half time bin width
845  double timeBinSignal = 0.;
846  double timeBinSignalVar = 0.;
847 
848  const unsigned int nPixels =
849  fUseZeta ? thisTimeZetaPixels.size() : detTel.GetLastPixelId()-detTel.GetFirstPixelId()+1;
850 
851  for (unsigned int iPixId = 0; iPixId < nPixels; ++iPixId) {
852  const unsigned int pixId = fUseZeta ? thisTimeZetaPixels[iPixId] : iPixId + 1;
853  if (!tel.HasPixel(pixId, ComponentSelector::eInDAQ))
854  continue;
855 
856  // Fetch or calculate pixel efficiency modification
857  double pixEffMod = fLightConverter->GetConversionConstant(telId, pixId);
858 
859  const fevt::Pixel& pix = tel.GetPixel(pixId);
860  const fevt::PixelSimData& pixSim = pix.GetSimData();
861  if (!pixSim.HasPhotonTrace(component)) {
862 //#warning The light-at-pixel information should be available at this point. Skipping the light component seems wrong.
863  //cout << "PixelSimData for pixel " << pix.GetId() << " of telescope " << tel.GetId() << " does not have light component " << component << ". Skipping." << endl;
864  continue;
865  }
866  const utl::TraceD& pixTrace = pixSim.GetPhotonTrace(component);
867  const double pixSignalInBin =
868  CalcTraceBinContent<double>(pixTrace, timeBinCenter - dtHalf, timeBinCenter + dtHalf);
869  timeBinSignal += pixSignalInBin * pixEffMod;
870 
871  const utl::TraceD& pixWSTrace = pixSim.GetPhotonWeightSquareTrace(component);
872  const double pixSignalVarInBin =
873  CalcTraceBinContent<double>(pixWSTrace, timeBinCenter - dtHalf, timeBinCenter + dtHalf);
874  timeBinSignalVar += pixSignalVarInBin * pixEffMod*pixEffMod;
875  } // end for each zeta pixel
876 
877  totalPixelTrace.PushBack(timeBinCenter, dtHalf, timeBinSignal, sqrt(timeBinSignalVar));
878  } // end for each aperture time bin
879 
880  return totalPixelTrace;
881 }
882 
883 
884 /*************************************************************************/
886 FdLightCollectionEfficiency::DoInitialReconstruction(evt::Event& event, std::map<int, evt::ShowerFRecData*>& dataSets)
887 {
888  SubModule& profRecMod = fSubModulesList.find("FdProfileReconstructorKG")->second;
889 
891  dynamic_cast<FdProfileReconstructorKG::FdProfileReconstructor&>(profRecMod.GetModule());
892 
893  const bool propGeo = reconstructor.GetPropagateGeometryErrors();
894  const bool propAtm = reconstructor.GetPropagateAtmUncertainties();
895  reconstructor.SetPropagateGeometryErrors(false);
896  reconstructor.SetPropagateAtmUncertainties(false);
897 
898  fwk::VModule::ResultFlag status = profRecMod.Run(event);
899 
900  reconstructor.SetPropagateGeometryErrors(propGeo);
901  reconstructor.SetPropagateAtmUncertainties(propAtm);
902 
903  // Now, do some minor validation to make sure the event has been reconstructed
904  // in a *remotely* physical way.
905 
906  // At the same time, create a map of eye-id => ShowerFRecData as the set
907  // of data to operate on down the road
909  end = event.GetFEvent().EyesEnd(fevt::ComponentSelector::eHasData);
910  iEye != end; ++iEye)
911  {
912  // Hierarchically check all the necessary structures
913  if (!iEye->HasRecData()) {
914  if (fVerbosity > 0)
915  cout << " Skipping eye " << iEye->GetId() << ": no EyeRecData.\n";
916  continue;
917  }
918 
919  EyeRecData& eyeRecData = iEye->GetRecData();
920  if (!eyeRecData.HasFRecShower()) {
921  if (fVerbosity > 0)
922  cout << " Skipping eye " << iEye->GetId() << ": no ShowerFRecData.\n";
923  continue;
924  }
925 
926  ShowerFRecData& frecData = eyeRecData.GetFRecShower();
927  if (!frecData.HasGHParameters() ||
928  !frecData.HasLongitudinalProfile() ||
929  !frecData.HasEnergyDeposit()) {
930  if (fVerbosity > 0)
931  cout << " Skipping eye " << iEye->GetId() << ": no profile reconstruction.\n";
932  continue;
933  }
934 
935  const evt::VGaisserHillasParameter& ghParam = frecData.GetGHParameters();
936  const evt::GaisserHillas4Parameter* gh4 = dynamic_cast<const evt::GaisserHillas4Parameter*>(&ghParam);
937  if (!gh4) {
938  if (fVerbosity > 0)
939  cout << " Skipping eye " << iEye->GetId() << ": no profile GH parameters after profile reconstruction.\n";
940  continue;
941  }
942 
943  if (gh4->GetXMax() < 0. || gh4->GetNMax() < 0.) {
944  if (fVerbosity > 0)
945  cout << " Skipping eye " << iEye->GetId() << ": unphysical profile reconstruction.\n";
946  continue;
947  }
948 
949  dataSets[iEye->GetId()] = &frecData;
950  } // end of eye loop
951 
952  return status;
953 }
954 
955 
956 /*************************************************************************/
957 std::pair<fwk::VModule::ResultFlag, unsigned int>
959  evt::Event& realEvent,
960  unsigned int nRayTracingIterations,
961  const fevt::FdConstants::LightSource lightSource)
962 {
963  fevt::FEvent& theFEvent = event.GetFEvent();
964 
965  // Prepare ShowerPhotonGeneratorOG configuration
966  SubModule& photGenMod = fSubModulesList.find("ShowerPhotonGeneratorOG")->second;
968  dynamic_cast<ShowerPhotonGeneratorOG::ShowerPhotonGenerator&>(photGenMod.GetModule());
969 
970  const unsigned int maxNRayTraceOld = photGen.GetMaxNRayTrace(); // remember
971  const unsigned int minNRayTraceOld = photGen.GetMinNRayTrace(); // remember
972  const double extraFactor = photGen.GetExtraRayTraceFactor(); // remember
973  const int sourceSelection = photGen.GetLightSourceSelection(); // remember
974  const bool useOnlyReferenceWl = photGen.GetUseOnlyReferenceWavelength(); // remember
975  photGen.SetMaxNRayTrace(fMaxNRayTracePerBin); // overwrite
976  photGen.SetMinNRayTrace(fMinNRayTracePerBin); // overwrite
977  photGen.SetUseOnlyReferenceWavelength(true); // overwrite
978  photGen.SetExtraRayTraceFactor(fExtraRayTraceFactor); // overwrite
979  photGen.SetLightSourceSelection(lightSource); // overwrite
980 
981  // Prepare TelescopeSimulatorKG configuration
982  SubModule& telSimMod = fSubModulesList.find("TelescopeSimulatorKG")->second;
984  dynamic_cast<TelescopeSimulatorKG::TelescopeSimulator&>(telSimMod.GetModule());
985 
986  const bool storeLightAtPixels = telSim.StoreLightComponentsAtPixels(); // remember
987  const bool telSimVerbosity = telSim.GetVerbosity(); // remember
988 
989  telSim.SetStoreLightComponentsAtPixels(true); // overwrite
990  telSim.SetVerbosity(1); // overwrite
991 
992  if (fVerbosity > 0)
993  cout << "\n Performing at least " << nRayTracingIterations
994  << " ray-tracing iteration(s):" << endl;
995 
996  typedef std::list<utl::TabulatedFunctionErrors> TelLCEfficiencies;
997  typedef std::map<unsigned int, TelLCEfficiencies> EyeLCEfficiences;
998  typedef std::map<unsigned int, EyeLCEfficiences> EventLCEfficiencies;
999  EventLCEfficiencies lcEfficiencies;
1000 
1001  fwk::VModule::ResultFlag status = eFailure;
1002  for (unsigned int iRayTrace = 1; iRayTrace <= (unsigned int)nRayTracingIterations; ++iRayTrace) {
1003 
1004  bool needRepeat = false;
1005 
1006  if (fVerbosity > 0)
1007  cout << "\n Ray-tracing iteration " << iRayTrace << " ..." << endl;
1008 
1009 //#warning Temporary measure until I can reproduce the ShowerPhotonGenerator exceptions
1010  try { // FIXME this is a temporary measure in order not to lose a whole job for absurd events
1011  status = photGenMod.Run(event); // RUN
1012  if (status != eSuccess)
1013  break;
1014  }
1015  catch (...) {
1016  ostringstream err;
1017  err << "ShowerPhotonGenerator threw an exception."
1018  " Skipping the event for lack of better options...";
1019  ERROR(err);
1020  status = eContinueLoop;
1021  break;
1022  }
1023 
1024  // Note: we won't catch exceptions from the TelescopeSimulator.
1025  // There is no reason to throw any even for a fairly malformed
1026  // event.
1027  status = telSimMod.Run(event); // RUN
1028  if (status != eSuccess)
1029  break;
1030 
1031  // Now, calculate the sum of photon weights at aperture (but using their
1032  // 3D-shifted time), then empty the photon traces
1033  // (TelescopeSimulatorKG doesn't do the latter, currently)
1034 
1035  // loop eyes
1037  end = theFEvent.EyesEnd(fevt::ComponentSelector::eInDAQ);
1038  iEye != end; ++iEye)
1039  {
1040  if (iEye->GetStatus() == fevt::ComponentSelector::eDeSelected)
1041  continue;
1042 
1043  fevt::Eye& eyeEvent = *iEye;
1044 
1045  const unsigned int eyeId = eyeEvent.GetId();
1046 
1047  // loop telescopes for calculating time-corrected aperture light trace
1050  iTel != end; ++iTel)
1051  {
1052  const unsigned int telId = iTel->GetId();
1053 
1054  fevt::TelescopeSimData& simData = iTel->GetSimData();
1055  if (simData.HasRayTracedPhotonTrace()) {
1056  // Get the corrected aperture light trace
1057  utl::TraceD& apTrace = (*fTimeCorrectedApertureTraces)[telId];
1058  // Add photons to the corrected ap. light trace
1059  CorrectedApLightCalculator calc(simData,
1060  apTrace,
1061  //eyeId, // unused. LN.
1062  telId,
1063  fVerbosity);
1064  calc.Run();
1065  }
1066  } // end for telescope
1067 
1068  if (fStopCondition != eFixed)
1069  CalculateEfficiency(event, realEvent, eyeId, iRayTrace, lightSource);
1070 
1071  EyeLCEfficiences& eyeLCEff = lcEfficiencies[eyeId];
1072 
1073  // loop telescopes
1076  iTel != end; ++iTel)
1077  {
1078  const unsigned int telId = iTel->GetId();
1079 
1080  fevt::TelescopeSimData& simData = iTel->GetSimData();
1081  simData.ClearPhotons();
1082 
1083  if (fStopCondition == eBootstrap) {
1084  // If we're bootstrapping, we calculate the efficiency for each iteration,
1085  // then use the list of efficiencies to arrive at a final results.
1086  // That means we need to clean up the intermediate results or we'll get
1087  // a wrong end result.
1088  if (simData.HasRayTracedPhotonTrace())
1089  simData.ClearRayTracedPhotonTrace();
1090 
1091  // Clear the simulated photon traces @ pixel
1092  for (fevt::Telescope::PixelIterator iPix = iTel->PixelsBegin(fevt::ComponentSelector::eInDAQ),
1093  end = iTel->PixelsEnd(fevt::ComponentSelector::eInDAQ);
1094  iPix != end; ++iPix)
1095  {
1096  iPix->GetSimData().ClearPhotonTraces();
1097  iPix->GetSimData().ClearPhotonWeightSquareTraces();
1098  }
1099 
1100  TelLCEfficiencies& telLCEff = eyeLCEff[telId];
1101  if (!realEvent.GetFEvent().HasEye(eyeId, ComponentSelector::eHasData))
1102  continue;
1103 
1104  fevt::Eye& reye = realEvent.GetFEvent().GetEye(eyeId, ComponentSelector::eHasData);
1105  if (!reye.HasTelescope(telId, ComponentSelector::eHasData))
1106  continue;
1107 
1108  fevt::Telescope& rtel = reye.GetTelescope(telId, ComponentSelector::eHasData);
1109  if (!rtel.HasRecData())
1110  continue;
1111 
1112  TelescopeRecData& recData = reye.GetTelescope(telId, ComponentSelector::eHasData).GetRecData();
1113  telLCEff.push_back( recData.GetLightCollectionEfficiency().GetTabulatedFunctionErrors(lightSource) );
1114 
1115  // Check whether we arrived at the end of the mandatory number of
1116  // iterations. If so, recalculate the net efficiency
1117  if (iRayTrace == nRayTracingIterations) {
1118  cout << "Bootstrapping uncertainties..." << endl;
1119  Bootstrapper bs(telLCEff, fVerbosity);
1120  // Repeat if we haven't met the uncertainty target yet
1121  if (!needRepeat &&
1122  !bs.MaxRelUncertaintyBelowThreshold(fTargetUncertainty, fMinRelevantEfficiency)) {
1123  needRepeat = true;
1124  continue;
1125  }
1127  mult.GetTabulatedFunctionErrors(lightSource) = bs.GetMean();
1128  }
1129  } // end if using bootstrap method
1130  } // end for telescopes
1131  } // end for eyes
1132 
1133 
1134  // If we're aiming for a certain upper limit on the uncertainty of the efficiency,
1135  // we predict the number of photons remaining to be simulated
1136  if ((fStopCondition == eTargetUncertainty
1137  || fStopCondition == eSmallEnough)
1138  && iRayTrace == 1)
1139  {
1140  double targetRelUncertainty = 0.;
1141  if (fStopCondition == eSmallEnough) {
1142  // Get uncertainty from l@aperture errors
1143  targetRelUncertainty =
1144  CalculateTargetRelUncertainty(realEvent.GetFEvent(),
1145  event.GetFEvent(), lightSource,
1146  fMinRelevantEfficiency,
1147  fTargetWorstCaseLAtApUncertaintyChange);
1148  // Make sure we don't go crazy on the uncertainty...
1149  if (targetRelUncertainty < fLowerUncertaintyLimit)
1150  targetRelUncertainty = fLowerUncertaintyLimit;
1151  }
1152  else
1153  targetRelUncertainty = fTargetUncertainty;
1154 
1155  const double additionalIter =
1156  CalculateAdditionalIterationsToMeetTarget(realEvent.GetFEvent(),
1157  event.GetFEvent(), lightSource,
1158  targetRelUncertainty, fMinRelevantEfficiency);
1159  if (additionalIter > 0.) {
1160  needRepeat = true;
1161  unsigned int addIter = (unsigned int)additionalIter;
1162  addIter = (additionalIter - (double)addIter > 0.) ? addIter+1 : addIter; // ceil
1163  ostringstream msg;
1164  msg << "Determined that at least " << additionalIter
1165  << " ray-tracing iterations are necessary to reach uncertainty target."
1166  << endl;
1167  INFO(msg);
1168  nRayTracingIterations += addIter-1; // one iteration added by virtue of needRepeat
1169  }
1170  else
1171  INFO("Met uncertainty target for this light component for all bins.");
1172  } // end if in eTargetUncertainty mode and at first iteration
1173 
1174 
1175  // Now check whether we need to keep going according to the uncertainty target and the
1176  // calculated uncertainties from bootstrapping.
1177  if (needRepeat) {
1178  if (iRayTrace == fMaxIterations) {
1179  cout << "Would need an additional iteration according to stop "
1180  << "criterion, but we hit the hard upper limit. Stopping iteration." << endl;
1181  nRayTracingIterations = iRayTrace;
1182  break;
1183  }
1184  else {
1185  cout << "Performing additional iteration to meet uncertainty target..." << endl;
1186  nRayTracingIterations++;
1187  }
1188  }
1189  else if (fStopCondition != eFixed && iRayTrace == fMaxIterations) {
1190  cout << "Would need an additional iteration according to stop "
1191  << "criterion, but we hit the hard upper limit. Stopping iteration." << endl;
1192  nRayTracingIterations = iRayTrace;
1193  break;
1194  }
1195  } // end for nRayTrace iterations
1196 
1197  // Reset ShowerPhotonGeneratorOG configuration
1198  photGen.SetMaxNRayTrace(maxNRayTraceOld); // reset
1199  photGen.SetMinNRayTrace(minNRayTraceOld); // reset
1200  photGen.SetExtraRayTraceFactor(extraFactor); // reset
1201  photGen.SetUseOnlyReferenceWavelength(useOnlyReferenceWl); // reset
1202  if (sourceSelection < 0)
1203  photGen.ResetLightSourceSelection(); // reset
1204  else
1205  photGen.SetLightSourceSelection((fevt::FdConstants::LightSource)sourceSelection); // reset
1206 
1207  // Reset TelescopeSimulatorKG configuration
1208  telSim.SetStoreLightComponentsAtPixels(storeLightAtPixels); // reset
1209  telSim.SetVerbosity(telSimVerbosity); // reset
1210 
1211  return std::make_pair(status, nRayTracingIterations);
1212 }
1213 
1214 
1215 /*************************************************************************/
1216 double
1218  const fevt::FEvent& theSimFEvent,
1219  const fevt::FdConstants::LightSource& lightSource,
1220  const double targetRelUncertainty,
1221  const double minRelevantEfficiency)
1222 {
1223  double minNIterationsRequired = 0.;
1224  double photonsRayTracedAtMinimum = 0;
1225  double efficiencyAtMinimum = 0;
1226  double efficiencyUncertaintyAtMinimum = 0;
1227  // loop eyes
1229  end = theSimFEvent.EyesEnd(fevt::ComponentSelector::eInDAQ);
1230  iEye != end; ++iEye)
1231  {
1232  if (iEye->GetStatus() == fevt::ComponentSelector::eDeSelected)
1233  continue;
1234  if (!theRealFEvent.HasEye(iEye->GetId(), fevt::ComponentSelector::eHasData))
1235  continue;
1236 
1237  const fevt::Eye& eyeEvent = *iEye;
1238  const fevt::Eye& realEye = theRealFEvent.GetEye(iEye->GetId(), fevt::ComponentSelector::eHasData);
1239 
1240  // loop telescopes
1243  iTel != end; ++iTel)
1244  {
1245  if (!iTel->HasSimData())
1246  continue;
1247  const fevt::TelescopeSimData& simData = iTel->GetSimData();
1248 
1249  if (!realEye.HasTelescope(iTel->GetId(), fevt::ComponentSelector::eHasData))
1250  continue;
1251  const fevt::Telescope& realTel = realEye.GetTelescope(iTel->GetId(), fevt::ComponentSelector::eHasData);
1252 
1253  if (!realTel.HasRecData())
1254  continue;
1255  const TelescopeRecData& recData = realTel.GetRecData();
1256 
1257  if (!recData.HasLightCollectionEfficiency()
1258  || !recData.GetLightCollectionEfficiency().HasLabel(lightSource))
1259  continue;
1260 
1262 
1263  if (!simData.HasRayTracedPhotonTrace())
1264  continue;
1265  const utl::TraceI& nRayTraced = simData.GetRayTracedPhotonTrace();
1266 
1267  const unsigned int nPoints = lcEff.GetNPoints();
1268  for (unsigned int i = 0; i < nPoints; ++i) {
1269  if (lcEff.GetY(i) >= minRelevantEfficiency) {
1270  if (nRayTraced[i] == 0)
1271  continue;
1272  const double yerr = lcEff.GetYErr(i);
1273  const double nPhotNow = nRayTraced[i];
1274  if (yerr > targetRelUncertainty) {
1275  // sigma > sigma_t => sigma/sqrt(n) = sigma_t => n = (sigma/sigma_t)^2
1276  // s_mean_now = s / sqrt(n_now); s_mean_target = s / sqrt(n_target)
1277  // => s_mean_target * sqrt(n_target) = s_mean_now * sqrt(n_now)
1278  // => n_target = (s_mean_now / s_mean_target)^2 * n_now
1279  // Note: targetRelUncertainty is a relative uncertainty!
1280  const double nTarget = pow(yerr/(targetRelUncertainty*lcEff.GetY(i)), 2.) * nPhotNow;
1281  const double thisMinNPhot = nTarget - nPhotNow;
1282  const double thisMinNIter = thisMinNPhot / (double)nPhotNow; // one iteration yields nPhotNow photons in this bin
1283  if (thisMinNIter > minNIterationsRequired) {
1284  minNIterationsRequired = thisMinNIter;
1285  photonsRayTracedAtMinimum = nPhotNow;
1286  efficiencyAtMinimum = lcEff.GetY(i);
1287  efficiencyUncertaintyAtMinimum = yerr;
1288  }
1289  }
1290  }
1291  } // end foreach lceff bin
1292 
1293  } // end for telescopes
1294  } // end for eyes
1295 
1296  if (fVerbosity > 0) {
1297  ostringstream msg;
1298  msg << "Calculated that we'll need " << minNIterationsRequired
1299  << " more iterations to meet uncertainty target.";
1300  if (fVerbosity > 1) {
1301  msg << " In the bin of the minimum, we ray-traced " << photonsRayTracedAtMinimum
1302  << " so far, therefore, we need "
1303  << (minNIterationsRequired+1)*photonsRayTracedAtMinimum
1304  << " photons in total to meet target. In this bin, the efficiency was: "
1305  << efficiencyAtMinimum << " +/- " << efficiencyUncertaintyAtMinimum;
1306  }
1307  INFO(msg);
1308  }
1309 
1310  return minNIterationsRequired;
1311 }
1312 
1313 
1314 /*************************************************************************/
1315 double
1317  const fevt::FEvent& theSimFEvent,
1318  const fevt::FdConstants::LightSource& lightSource,
1319  const double minRelevantEfficiency,
1320  const double maxUncertaintyChangeFraction)
1321 {
1322  unsigned int worstTel = 0;
1323  unsigned int worstBin = 0;
1324  double worstTime = 0.;
1325  double worstCaseRelUncertainty = 1.e9;
1326  // loop eyes
1328  end = theSimFEvent.EyesEnd(fevt::ComponentSelector::eInDAQ);
1329  iEye != end; ++iEye)
1330  {
1331  if (iEye->GetStatus() == fevt::ComponentSelector::eDeSelected)
1332  continue;
1333  if (!theRealFEvent.HasEye(iEye->GetId(), fevt::ComponentSelector::eHasData))
1334  continue;
1335 
1336  const fevt::Eye& eyeEvent = *iEye;
1337  const fevt::Eye& realEye = theRealFEvent.GetEye(eyeEvent.GetId(), fevt::ComponentSelector::eHasData);
1338 
1339  // loop telescopes
1342  iTel != end; ++iTel)
1343  {
1344  if (!iTel->HasSimData())
1345  continue;
1346 
1347  const unsigned int telId = iTel->GetId();
1348 
1349  if (!realEye.HasTelescope(telId, fevt::ComponentSelector::eHasData))
1350  continue;
1351  const fevt::Telescope& realTel = realEye.GetTelescope(telId, fevt::ComponentSelector::eHasData);
1352 
1353  if (!realTel.HasRecData())
1354  continue;
1355  const TelescopeRecData& recData = realTel.GetRecData();
1356 
1358  || !recData.HasLightCollectionEfficiency()
1359  || !recData.GetLightCollectionEfficiency().HasLabel(lightSource))
1360  continue;
1361 
1363  const utl::TabulatedFunctionErrors& lAtAp = recData.GetLightFlux(fevt::FdConstants::eTotal); // FIXME eTotal light is a worst-case?
1364 
1365  const unsigned int nPoints = lcEff.GetNPoints();
1366  assert(nPoints == lAtAp.GetNPoints());
1367 
1368  for (unsigned int i = 0; i < nPoints; ++i) {
1369  const double eff = lcEff.GetY(i);
1370  if (eff >= minRelevantEfficiency) {
1371  const double light = fabs(lAtAp.GetY(i));
1372  const double lightErr = lAtAp.GetYErr(i);
1373  const double requiredRelEff = sqrt( pow(maxUncertaintyChangeFraction+1, 2)-1 ) * lightErr / light;
1374  if (requiredRelEff < worstCaseRelUncertainty) {
1375  worstTel = telId;
1376  worstBin = i;
1377  worstTime = lAtAp.GetX(i);
1378  worstCaseRelUncertainty = requiredRelEff;
1379  cout << telId << " " << i << " " << maxUncertaintyChangeFraction << " "
1380  << lightErr << " " << light << " " << lightErr/light << " " << requiredRelEff
1381  << endl;
1382  }
1383  }
1384  } // end foreach lceff bin
1385 
1386  } // end for telescopes
1387  } // end for eyes
1388 
1389  if (fVerbosity > 0) {
1390  ostringstream msg;
1391  msg << "Calculated worst-case required relative uncertainty on efficiency is "
1392  << worstCaseRelUncertainty << ". ";
1393  if (worstCaseRelUncertainty < fLowerUncertaintyLimit) {
1394  msg << " It is smaller than the lower bound for the rel. unc. ("
1395  << fLowerUncertaintyLimit << ") and thus, we'll use the latter instead. ";
1396  }
1397  msg << "This will be the basis for calculating the "
1398  "required number of iterations.";
1399  if (fVerbosity > 1) {
1400  msg << " The most stringent requirement was found in tel. " << worstTel
1401  << " for bin " << worstBin << " at time " << worstTime << ".";
1402  }
1403  INFO(msg);
1404  }
1405 
1406  return worstCaseRelUncertainty;
1407 }
1408 
1409 
1410 /*************************************************************************/
1413  const utl::TraceD& apertureTrace,
1414  const utl::TraceI& /*nRayTracedTrace*/,
1415  const double nRayTracingIterations)
1416 {
1417  const unsigned int nBins = pixelTrace.GetNPoints();
1418  vector<double> vx(nBins), vxerr(nBins), vy(nBins), vyerr(nBins)/*, n(nBins)*/;
1419 
1420  for (unsigned int i = 0; i < nBins; ++i) {
1421  const double binCenter = pixelTrace.GetX(i);
1422  const double halfBinWidth = pixelTrace.GetXErr(i);
1423  const double binStart = binCenter - halfBinWidth;
1424  const double binEnd = binCenter + halfBinWidth;
1425 
1426  const double pixelSignal = pixelTrace.GetY(i);
1427  const double pixelSignalErr = pixelTrace.GetYErr(i);
1428  assert(isfinite(pixelSignal));
1429  assert(isfinite(pixelSignalErr));
1430 
1431  const double apertureSignal = CalcTraceBinContent(apertureTrace, binStart, binEnd) * nRayTracingIterations;
1432  assert(isfinite(apertureSignal));
1433  //const double nRayTraced = CalcTraceBinContent(nRayTracedTrace, binStart, binEnd);
1434 
1435  const double x = binCenter;
1436  if (apertureSignal >= 1.e-9) {
1437  const double y = pixelSignal / apertureSignal;
1438  assert(isfinite(y));
1439  vy[i] = y;
1440  vyerr[i] = pixelSignalErr / apertureSignal;
1441  }
1442  else {
1443  vy[i] = 0.; // default to zero efficiency if there was no light@aperture
1444  vyerr[i] = 1.e3;
1445  }
1446 
1447  vx[i] = x;
1448  vxerr[i] = halfBinWidth;
1449  //n[i] = nRayTraced;
1450  //efficiency.PushBack(x, xerr, 0., 0.);
1451  } // end foreach bin
1452 
1454  for (unsigned int i = 0; i < nBins; ++i) {
1455  const double yerr = vyerr[i];
1456  assert(isfinite(vx[i]));
1457  assert(isfinite(vxerr[i]));
1458  assert(isfinite(vy[i]));
1459  assert(isfinite(yerr));
1460  division.PushBack(vx[i], vxerr[i], vy[i], yerr);
1461  }
1462 
1463  return division;
1464 }
1465 
1466 #undef DEBUG
1467 
1468 // Configure (x)emacs for this file ...
1469 // Local Variables:
1470 // mode: c++
1471 // End:
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
Definition: FEvent/Eye.cc:57
unsigned int GetId() const
Definition: FEvent/Eye.h:54
void WriteDebugInfo(const int eyeId, const int simTelId, const double simTimeOffset, const fevt::FdConstants::LightSource component, const utl::TabulatedFunctionErrors &totalPixelTrace, const utl::TraceD &totalWlTrace, const utl::TabulatedFunctionErrors &realApLightFlux, const utl::TabulatedFunctionErrors &telEff)
bool HasRecData() const
unsigned int GetNPoints() const
boost::transform_iterator< LabeledObjectFunctor, typename MultiObjectContainer::iterator, LabeledTabulatedFunctionErrors > Iterator
Definition: MultiObject.h:78
void SetStop(const SizeType stop)
Set valid data stop bin.
Definition: Trace.h:151
T & At(const SizeType i)
trace entry with checked address
Definition: Trace.h:205
bool StoreLightComponentsAtPixels()
Returns whether pixel traces are stored for individual light components.
utl::TabulatedFunctionErrors CalcTraceDivision(const utl::TabulatedFunctionErrors &pixelTrace, const utl::TraceD &apertureTrace, const utl::TraceI &nRayTracedTrace, const double nRayTracingIterations)
Description of the electronic channel for the 480 channels of the crate.
unsigned int GetMaxNRayTrace() const
Get the max. no. of photons raytraced per time bin.
void SetMaxNRayTrace(unsigned int nphotons)
Set the max. no. of photons raytraced per time bin.
fevt::EyeHeader & GetHeader()
Header for this Eye Event.
Definition: FEvent/Eye.cc:180
fwk::VModule::ResultFlag Init()
Definition: SubModule.cc:39
unsigned int GetTimeOffset() const
Time offset of this Telescope compared to fevt::Header::GetTime [ns].
bool HasPhotonTrace(const fevt::FdConstants::LightSource source, const int wl) const
Check that light trace for source /par source is present for the given wavelength bin...
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
boost::filter_iterator< ComponentSelector, ConstAllEyeIterator > ConstEyeIterator
Definition: FEvent.h:56
bool GetUseOnlyReferenceWavelength() const
Returns whether photons will be generated only at the reference wavelength.
SizeType GetStop() const
Get valid data stop bin.
Definition: Trace.h:148
bool HasFEvent() const
unsigned int GetFirstPixelId() const
Utility class to do (cached!) conversion from photons at the pixel to photons at aperture.
double GetModelMaxWavelength() const
Class to hold collection (x,y) points and provide interpolation between them.
const utl::TabulatedFunctionErrors & GetMean()
Definition: Bootstrapper.h:35
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
double GetBinning() const
size of one slot
Definition: Trace.h:138
unsigned int GetEyeId() const
double GetMeasuredRelativeEfficiency(const double wl) const
fwk::VModule::ResultFlag DoInitialReconstruction(evt::Event &event, std::map< int, evt::ShowerFRecData * > &dataSets)
Runs the FdProfileReconstructor before the efficiency calculation.
utl::TraceI & GetRayTracedPhotonTrace()
Number of photons that were actually ray-traced (per time bin)
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
PixelSimData & GetSimData()
Definition: FEvent/Pixel.h:35
Base class for exceptions trying to access non-existing components.
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
utl::TimeStamp GetPhotonsStartTime() const
Start Time of the photons trace.
void SetLightSourceSelection(const fevt::FdConstants::LightSource source)
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
fevt::TelescopeRecData & GetRecData()
Reconstructed data for this telescope.
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 ClearRayTracedPhotonTrace()
Clear the trace of ray traced photons.
Iterator Begin()
Definition: MultiObject.h:83
Exception for errors encountered when parsing XML.
void PrintTiming(utl::TabularStream &tabStream)
Prints the sub-module timing to the given tabular stream.
Definition: SubModule.cc:89
Estimate the uncertainty of the light-collection efficiency with the bootstrap method.
Definition: Bootstrapper.h:29
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
Exception for reporting variable out of valid range.
const Pixel & GetPixel(const unsigned int pixelId) const
Get Pixel by id, throw utl::NonExistentComponentException if n.a.
fwk::VModule::ResultFlag Run(evt::Event &event)
Definition: SubModule.cc:70
void SetVerbosity(const int verbosity)
Definition: SimMockEvent.h:41
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.
#define max(a, b)
utl::TabulatedFunctionErrors & GetLightFlux(const FdConstants::LightSource source=fevt::FdConstants::eTotal)
Light flux at diaphragm, photons/m^2 versus time in ns.
Class representing a document branch.
Definition: Branch.h:107
unsigned int GetLastPixelId() const
const double & GetYErr(const unsigned int idx) const
ArrayConstReference XFront() const
read-only reference to front of array of X
LightSource
Possible light sources.
Definition: FdConstants.h:9
bool HasLongitudinalProfile() 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
TelescopeIterator TelescopesEnd()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:230
bool HasLightFlux(const FdConstants::LightSource source=FdConstants::eTotal) const
Check that light profile for source /par source is present.
constexpr double nanosecond
Definition: AugerUnits.h:143
bool CalculateEfficiency(const evt::Event &simEvent, evt::Event &realEvent, const int eyeId, const unsigned int nRayTracingIterations, const fevt::FdConstants::LightSource lightSource)
Calculates the light collection efficiency of a sim shower.
const Telescope & GetTelescope(const unsigned int telescopeId) const
Find Telescope by numerical Id.
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
bool PrepareEvent(const unsigned int eyeId, const evt::ShowerFRecData &recData, const evt::Event &event, const fevt::Eye &eye)
bool HasFRecShower() const
Check if reconstructed shower info has been allocated.
Definition: EyeRecData.h:330
void SetStart(const SizeType start)
Set valid data start bin.
Definition: Trace.h:145
evt::ShowerFRecData & GetFRecShower()
Reconstructed shower info for this eye.
Definition: EyeRecData.h:323
int GetVerbosity()
Returns the current verbosity level.
EyeIterator EyesBegin(const ComponentSelector::Status status)
Definition: FEvent.h:58
int GetFADCTraceLength() const
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
ArrayConstReference YFront() const
read-only reference to front of array of Y
Adaptor class for FdLightCollectionEfficiency&#39;s sub-modules for initializing, running, timing them.
Definition: SubModule.h:34
Telescope-specific shower reconstruction data.
constexpr double g
Definition: AugerUnits.h:200
utl::TabulatedFunctionErrors CalculatePixelTraceSum(const fevt::Telescope &tel, const fevt::FdConstants::LightSource component, const double simTimeOffset, const std::vector< std::vector< unsigned int > > &pixelsInZeta, const utl::TabulatedFunctionErrors &realApLight)
Calculate the sum of pixel traces (simTimeOffset in ns)
utl::MultiTabulatedFunctionErrors & GetLightCollectionEfficiency()
Get the light-collection-efficiency multi tabulated function (for various LightSources) ...
utl::TraceD & GetPhotonWeightSquareTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Trace of the sums of squares of simulated photon weights.
Definition: PixelSimData.h:78
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
Definition: FEvent/Eye.h:72
const std::vector< std::vector< unsigned int > > & GetPixelsInZetaOverTime() const
Returns the time-vector of vectors of pixel ids which are within zeta at the given time...
void MakeLightCollectionEfficiency()
Add a light-collection-efficiency multi tabulated function (for various LightSources) ...
void SetExtraRayTraceFactor(double factor)
Set the artificial scaling factor for the number of ray-traced photons.
class to format data in tabular form
SizeType GetSize() const
Definition: Trace.h:156
A collection of TabulatedFunctionErrors, which provides methods to access different sources...
PhotonTraceIterator PhotonTracesEnd(const fevt::FdConstants::LightSource source)
void PushBack(const double x, const double xErr, const double y, const double yErr)
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
unsigned int GetMinNRayTrace() const
Get the min. no. of photons raytraced per time bin.
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
TabulatedFunctionErrors & GetTabulatedFunctionErrors(const int label=0)
Returns the TabulatedFunctionErrors for /par source.
Calculates an aperture light trace based on the ray-traced photons&#39; times.
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
const double & GetXErr(const unsigned int idx) const
Eye-specific shower reconstruction data.
Definition: EyeRecData.h:65
Eye & GetEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
return Eye by id
Definition: FEvent.cc:70
bool HasRayTracedPhotonTrace() const
Check that &quot;ray-traced photon trace&quot; is present.
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:207
double CalculateAdditionalIterationsToMeetTarget(const fevt::FEvent &theRealFEvent, const fevt::FEvent &theSimFEvent, const fevt::FdConstants::LightSource &lightSource, const double targetRelUncertainty, const double minRelevantEfficiency)
const double & GetY(const unsigned int idx) const
bool HasLightCollectionEfficiency() const
Check that a light-collection-efficiency multi tabulated function exists (for various LightSources) ...
std::pair< fwk::VModule::ResultFlag, unsigned int > RunPhotonGenerationRayTracingLoop(evt::Event &event, evt::Event &realEvent, unsigned int nRayTracingIterations, const fevt::FdConstants::LightSource lightSource)
Runs the ShowerPhotonGenerator and TelescopeSimulator nRayTracingIterations times.
static utl::TabularStream TimingHeader()
Prepares a TabularStream for timing printout.
Definition: SubModule.cc:101
void UpdateSpotFarFromBorderTimes(const double effThreshold)
double GetReferenceLambda() const
Definition: FDetector.cc:332
fevt::FEvent & GetFEvent()
Pixel & GetPixel(const unsigned int pixelId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Pixel by Id, throw exception if not existent.
bool HasGHParameters() const
double GetModelMinWavelength() const
bool HasEye(const unsigned int eyeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Definition: FEvent.cc:57
void SetBinning(const double binning)
Definition: Trace.h:139
boost::filter_iterator< ComponentSelector, AllPixelIterator > PixelIterator
selective Pixel iterators
Detector description interface for Telescope-related data.
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
PhotonTraceIterator PhotonTracesBegin(const fevt::FdConstants::LightSource source)
const std::string & GetName() const
Definition: SubModule.h:48
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
Definition: FDetector.cc:150
double GetFADCBinSize() const
double GetGPSNanoSecond() const
GPS nanosecond.
Definition: TimeStamp.h:127
unsigned int GetId() const
double GetDiaphragmArea() const
utl::TimeStamp GetTimeStamp() const
Time of the Eye Event as tagged by FD-DAS (== eye trigger time plus pixel trace length) ...
Definition: EyeHeader.h:118
Container for a faked event that knows how to claw the necessary information from the sim...
Definition: SimMockEvent.h:35
void SetUseOnlyReferenceWavelength(bool onlyRefWl)
Set whether photons should be generated only at the reference wavelength (used by FdLightCollectionEf...
SizeType GetStart() const
Get valid data start bin.
Definition: Trace.h:142
bool HasTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData) const
Check if the telescope is in the event.
Definition: FEvent/Eye.cc:117
utl::TraceD & GetPhotonTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Simulated Photon Trace.
Definition: PixelSimData.h:37
constexpr double cm
Definition: AugerUnits.h:117
Interface class for access to the Gaisser-Hillas parameters.
const double & GetX(const unsigned int idx) const
Interface class to access to Fluorescence reconstruction of a Shower.
bool MaxRelUncertaintyBelowThreshold(const double relUncertaintyThreshold, const double absValueThreshold=0.)
fwk::VModule::ResultFlag ProcessEvent(evt::Event &realEvent)
Main entry point. Run() is just a proxy.
static void FinishTimingPrintout(utl::TabularStream &tabStream)
Finishes the printout and actually dumps it to stdout.
Definition: SubModule.cc:111
Main configuration utility.
Definition: CentralConfig.h:51
Iterator End()
Definition: MultiObject.h:85
Fluorescence Detector Telescope Event.
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
Gaisser Hillas with 4 parameters.
double CalculateTargetRelUncertainty(const fevt::FEvent &theRealFEvent, const fevt::FEvent &theSimFEvent, const fevt::FdConstants::LightSource &lightSource, const double minRelevantEfficiency, const double maxUncertaintyChangeFraction)
Recalculates and sets the valid time ranges for profile reconstruction based on the telescope apertur...
bool CalculateTelescopeEfficiency(const fevt::Telescope &simTel, fevt::Telescope &realTel, const fevt::Eye &realEye, const unsigned int nRayTracingIterations, const fevt::FdConstants::LightSource lightSource)
Calculates the light collection efficiency of a telescope.
utl::MultiTraceD::ConstIterator ConstPhotonTraceIterator
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
void SetVerbosity(const int verbosity)
Sets the verbosity level.
bool HasSimData() const
void SetMinNRayTrace(unsigned int nphotons)
Set the min. no. of photons raytraced per time bin.
boost::filter_iterator< ComponentSelector, ConstAllTelescopeIterator > ConstTelescopeIterator
Definition: FEvent/Eye.h:73
Simulate photon injection into FD telescope.
const std::string & GetMessage() const
Retrieve the message from the exception.
bool HasEnergyDeposit() const
bool HasLabel(const int label) const
Definition: MultiObject.h:91
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
utl::TraceD CalculateTelescopeTraceSum(const fevt::Telescope &tel, const fevt::FdConstants::LightSource component, const atm::Atmosphere::EmissionMode lightType)
Calculate the wavelength-efficiency weighted sum of light-at-aperture traces.
double GetExtraRayTraceFactor() const
Get the artificial scaling factor for the number of ray-traced photons.
void SetStoreLightComponentsAtPixels(const bool store)
Sets whether pixel traces are stored for individual light components.
Fluorescence Detector Pixel Simulated Data.
Definition: PixelSimData.h:28
utl::TimeStamp GetTracesStartTime() const
fwk::VModule::ResultFlag Finish()
Definition: SubModule.cc:51

, generated on Tue Sep 26 2023.