FdApertureLightFinderKG/FdApertureLightFinder.cc
Go to the documentation of this file.
1 
10 #include "FdApertureLightFinder.h"
11 
12 #include <fwk/CentralConfig.h>
13 #include <fwk/RunController.h>
14 #include <fwk/CoordinateSystemRegistry.h>
15 #include <fwk/LocalCoordinateSystem.h>
16 
17 #include <utl/Reader.h>
18 #include <utl/ErrorLogger.h>
19 #include <utl/MathConstants.h>
20 #include <utl/Vector.h>
21 #include <utl/PhysicalConstants.h>
22 #include <utl/TabulatedFunctionErrors.h>
23 
24 #include <evt/Event.h>
25 #include <evt/ShowerFRecData.h>
26 
27 #include <fevt/FEvent.h>
28 #include <fevt/Eye.h>
29 #include <fevt/Telescope.h>
30 #include <fevt/EyeHeader.h>
31 #include <fevt/EyeRecData.h>
32 #include <fevt/TelescopeRecData.h>
33 #include <fevt/PixelRecData.h>
34 #include <fevt/Pixel.h>
35 #include <fevt/FdConstants.h>
36 
37 #include <det/Detector.h>
38 
39 #include <fdet/FDetector.h>
40 #include <fdet/Eye.h>
41 #include <fdet/Pixel.h>
42 #include <fdet/Channel.h>
43 #include <fdet/Telescope.h>
44 #include <fdet/Camera.h>
45 
46 #include <utl/Vector.h>
47 
48 #include <vector>
49 #include <list>
50 #include <algorithm>
51 #include <iostream>
52 #include <sstream>
53 
54 using namespace FdApertureLightFinderKG;
55 using namespace fwk;
56 using namespace utl;
57 using namespace evt;
58 using namespace fevt;
59 using namespace det;
60 using namespace std;
61 
62 
65 {
66  CentralConfig* const cc = CentralConfig::GetInstance();
67 
68  Branch topB = cc->GetTopBranch("FdApertureLightKG");
69 
70  if (!topB) {
71  ERROR("Could not find branch FdApertureLightKG");
72  return eFailure;
73  }
74 
75  topB.GetChild("verbosity").GetData(fVerbosity);
76  topB.GetChild("onlyUsedForTimeFit").GetData(fOnlyUsedForTimeFit);
77 
78  Branch zetaB = topB.GetChild("zetaOptimization");
79  // min and max zeta angle
80  zetaB.GetChild("minZetaAngle").GetData(fminZetaAngle);
81  zetaB.GetChild("maxZetaAngle").GetData(fmaxZetaAngle);
82 
83  // zeta search step width
84  zetaB.GetChild("stepZetaAngle").GetData(fstepZetaAngle);
85 
86  // safety margin to enlarge S/N max result
87  zetaB.GetChild("safetyMargin").GetData(fSafetyMargin);
88 
89  return eSuccess;
90 }
91 
92 
95 {
96  if (!event.HasFEvent())
97  return eSuccess;
98 
99  int nGoodEyes = 0;
100  for (FEvent::EyeIterator eyeiter = event.GetFEvent().EyesBegin(ComponentSelector::eHasData);
101  eyeiter != event.GetFEvent().EyesEnd(ComponentSelector::eHasData); ++eyeiter) {
102 
103  Eye& eye = *eyeiter;
104 
105  if (CalculateShowerGeometryData(eye)) {
106  if (FindLightFlux(eye)) {
107  if (fVerbosity >= 0) {
108  ostringstream msg;
109  msg << "Calculated telescope- and eye-based light at aperture for eye " << eye.GetId();
110  INFO(msg);
111  }
112  ++nGoodEyes;
113  } else {
114  if (fVerbosity >= 0) {
115  ostringstream msg;
116  msg << "Failed to calculate light at aperture for eye " << eye.GetId();
117  INFO(msg);
118  }
119  }
120  }
121 
122  }
123 
124  if (!nGoodEyes) {
125  if (fVerbosity > 0)
126  INFO("No good eyes, returning eContinueLoop");
127  return eContinueLoop;
128  }
129 
130  return eSuccess;
131 }
132 
133 
134 bool
136 {
137  fShowerGeometryData.clear();
138 
139  if (!eye.HasRecData() || !eye.GetRecData().HasFRecShower()) {
140  ostringstream msg;
141  msg << "No RecData for eye " << eye.GetId() << " skipping...";
142  if (fVerbosity >= 0)
143  INFO(msg);
144  return false;
145  }
146 
147  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
148  const fdet::Eye& detEye = detFD.GetEye(eye);
150 
151  //---> get reconstructed axis and time fit parameters
152 
153  const ShowerFRecData& shower = eye.GetRecData().GetFRecShower();
154 
155  const utl::Vector& axis = shower.GetAxis(); // upward!
156  const utl::Point& core = shower.GetCorePosition();
157  const utl::TimeStamp& coreTime = shower.GetCoreTime();
158 
159  const TimeStamp& eyeGPSTime = eye.GetHeader().GetTimeStamp();
160  const TimeStamp eyeTriggerTime = eyeGPSTime-TimeInterval(1000*100*utl::ns);
161 
162  //---> get time of first and last pulsed pixel
163 
164  double minT_i = 1e9;
165  double maxT_i = 0;
166  bool firstTime = true;
167 
169  pixiter != eye.GetRecData().TimeFitPixelsEnd();
170  ++pixiter) {
171 
172  if (not pixiter->HasRecData())
173  continue;
174 
175  const fdet::Channel& detChannel = detFD.GetChannel(*pixiter);
176  const double timebinsize = detChannel.GetFADCBinSize();
177 
178  const unsigned int timeoffset = eye.GetTelescope( pixiter->GetTelescopeId() ).GetTimeOffset();
179  const double t1 = timebinsize * pixiter->GetRecData().GetPulseStart() + timeoffset;
180  const double t2 = timebinsize * pixiter->GetRecData().GetPulseStop() + timeoffset;
181 
182  if (t2 > maxT_i || firstTime)
183  maxT_i = t2;
184  if (t1 < minT_i || firstTime)
185  minT_i = t1;
186 
187  if (firstTime)
188  firstTime = false;
189  }
190 
191  if (maxT_i <= minT_i) {
192  INFO("shower time length is <= 0, skipping...");
193  return false;
194  }
195 
196  //---> fill chi_i vector and corresponding ADC bin for each telescope
197 
198  for (fevt::Eye::ConstTelescopeIterator teliter = eye.TelescopesBegin(ComponentSelector::eHasData);
199  teliter != eye.TelescopesEnd(ComponentSelector::eHasData); ++teliter) {
200  const fdet::Telescope& detTel = detFD.GetTelescope(*teliter);
201 
202  const unsigned int telId = teliter->GetId();
203  const fdet::Camera& detCam = detTel.GetCamera();
204  const double timeBinSize = detCam.GetFADCBinSize();
205  const unsigned int adcTraceLength = detCam.GetFADCTraceLength();
206  const unsigned int timeoffset = teliter->GetTimeOffset();
207  const utl::Vector& telAxis = detTel.GetAxis();
208 
209  // for distance from shower core to emission point (aDist)
210  // law of cosines: bDist^2 = aDist^2 + cDist^2 - 2*aDist*cDist*cos(beta)
211  // cDist = distance(telescope, core)
212  // bDist-aDist = (telTime-coreTime)/c = delta (see below)
213  const utl::Point& telPos = detTel.GetPosition();
214  const Vector coreTelescopeVec = telPos-core;
215  const double cDist = coreTelescopeVec.GetMag();
216  const double cosBeta = CosAngle(axis, coreTelescopeVec);
217 
218  // The localTelCS is at the tel. pos., but unlike the TelescopeCoordinateSystem,
219  // its Z-axis points towards the zenith and not towards the aperture.
220  // This is intended as an equivalent of the eyeCS, but at the telescope.
221  // Unfortunately, a telescope has no backwall angle, so we're using the site's
222  // X/Y directions.
224 
225  vector<ShowerGeometryData> telData;
226 
227 //#warning This is a stop-gap measure to prevent aperture-light being calculated on bins that were used for the baseline
228  const unsigned int nBaselineBins = 200;// FIXME constant should come from FdCalibrator
229  for (unsigned int i = nBaselineBins; i < adcTraceLength; ++i) {
230 
231  const double t1 = i * timeBinSize + timeoffset;
232  const double t2 = (i+1) * timeBinSize + timeoffset;
233  const double tMean = t1 + 0.5 * timeBinSize;
234 
235  // "mean" below refering to the middle of the time bin as with tMean
236  utl::TimeStamp meanTimeAtTelescope = eyeTriggerTime + tMean;
237 
238  const double deltaMean =
239  (meanTimeAtTelescope - coreTime).GetInterval()*kSpeedOfLight;
240  const double meanDistance =
241  -(cDist*cDist - deltaMean*deltaMean) / (2*(deltaMean + cDist*cosBeta));
242  const utl::Point meanPointOnShower = core - meanDistance*axis;
243 
244  // Vector from telescope to point on shower axis that corresponds to chi_i.
245  utl::Vector chi_i_vec = meanPointOnShower - telPos;
246  chi_i_vec.Normalize();
247 
248  // outside FOV wrt. the telescopes with margin for zeta
249  // Note: This could be refined by checking chi_i_vec's vertical and horizontal
250  // angles to the telescope axis separately because the telescope is rectagular
251  // and not circular.
252  const double angleToTelAxis = Angle(chi_i_vec, telAxis);
253  if (angleToTelAxis > 25*deg)
254  continue;
255 
256  ShowerGeometryData tmpShGeoData;
257  tmpShGeoData.fADCTraceIndex = i;
258  tmpShGeoData.fT1 = t1;
259  tmpShGeoData.fT2 = t2;
260  tmpShGeoData.fChiVecMean[0] = chi_i_vec.GetX(localTelCS);
261  tmpShGeoData.fChiVecMean[1] = chi_i_vec.GetY(localTelCS);
262  tmpShGeoData.fChiVecMean[2] = chi_i_vec.GetZ(localTelCS);
263  tmpShGeoData.fTelFluxSum = 0;
264  tmpShGeoData.fTelVarianceSum = 0;
265  tmpShGeoData.fTelBgVarianceSum = 0;
266  tmpShGeoData.fEyeFluxSum = 0;
267  tmpShGeoData.fEyeVarianceSum = 0;
268  tmpShGeoData.fEyeBgVarianceSum = 0;
269  tmpShGeoData.fNearBorder = false;
270  tmpShGeoData.fUsedForTimeFit = (t1 >= minT_i && t2 <= maxT_i);
271 
272  telData.push_back(tmpShGeoData);
273  }
274 
275  fShowerGeometryData[telId] = telData;
276  }
277 
278  return true;
279 }
280 
281 
282 bool
284 {
285  // rough stepping in 0.5 degree steps
286  double zStep = 0.5 * degree;
287  double zMin = fminZetaAngle;
288  double zMax = fmaxZetaAngle + zStep;
289  double zeta = FindZeta(eye, zMin, zMax, zStep);
290 
291  // restepping around max
292  zMin = zeta - zStep;
293  zMax = zeta + zStep;
294  zStep = fstepZetaAngle;
295  if (zMin < 0.1*degree)
296  zMin = 0.1*degree;
297 
298  zeta = FindZeta(eye, zMin, zMax, zStep);
299 
300  if (zeta < 0) {
301  INFO("Zeta search failed - Bailing out for this eye");
302  return false;
303  }
304 
305  // enlarge zeta to collect more light
306  zeta += fSafetyMargin;
307 
308  // Since we're fitting a eye-global zeta for now,
309  // we save the same zeta in all telescopes and the eye
310  eye.GetRecData().SetZeta(zeta);
311  for (fevt::Eye::TelescopeIterator zetaTelIter = eye.TelescopesBegin(ComponentSelector::eHasData);
312  zetaTelIter != eye.TelescopesEnd(ComponentSelector::eHasData); ++zetaTelIter) {
313  if (!zetaTelIter->HasRecData())
314  zetaTelIter->MakeRecData();
315  zetaTelIter->GetRecData().SetZeta(zeta);
316  }
317 
318  // find and fill telescope light fluxes at maximum
319  FindZeta(eye, zeta, zeta, zStep, true);
320 
321  // order telescopes in time
322  vector<LastTelTime> timeOrderedTelescopes;
323  for (fevt::Eye::ConstTelescopeIterator teliter = eye.TelescopesBegin(ComponentSelector::eHasData);
324  teliter != eye.TelescopesEnd(ComponentSelector::eHasData); ++teliter) {
325  const unsigned int telId = teliter->GetId();
326  LastTelTime telTime(telId, 0); // just a struct of two unsigned ints for sorting
327  timeOrderedTelescopes.push_back(telTime);
328 
329  const vector<ShowerGeometryData>& telescopeData = fShowerGeometryData[telId];
330 
331  // backwards iteration for finding the last time with signal
332  for (int i = telescopeData.size()-1; i >= 0; --i) {
333  if (telescopeData[i].fEyeVarianceSum > 0) {
334  timeOrderedTelescopes.back().fLastTime = telescopeData[i].fT2;
335  break;
336  }
337  }
338  } // end for each telescope
339  sort(timeOrderedTelescopes.begin(), timeOrderedTelescopes.end(), LastTelTime::TelescopeTimeCmp);
340 
341  vector<double> telFluoTime;
342  vector<double> telFluoTimeBin;
343  vector<double> telFluoFlux;
344  vector<double> telVFluoFlux;
345  vector<double> telVBackground;
346  vector<const vector<unsigned int>*> telPixelsInZeta; // Pointers on purpose. STL Optimization!
347  vector<double> eyeFluoTime;
348  vector<double> eyeFluoTimeBin;
349  vector<double> eyeFluoFlux;
350  vector<double> eyeVFluoFlux;
351  vector<double> eyeVBackground;
352 
353  // loop over telescopes ordered in time
354  unsigned int latestFluxTime = 0;
355  for (vector<LastTelTime>::const_iterator telescopeIter = timeOrderedTelescopes.begin();
356  telescopeIter != timeOrderedTelescopes.end(); ++telescopeIter) {
357  const int telId = telescopeIter->fTelId;
358 
359  const vector<ShowerGeometryData>& telescopeData = fShowerGeometryData[telId];
360  typedef pair<double, double> FarFromBorderTimeRange;
361  list<FarFromBorderTimeRange> spotFarFromBorderRanges;
362 
363  bool isNearBorder = true;
364  double rangeStartTime = -1e99;
365 
366  for (unsigned int i = 0; i < telescopeData.size(); ++i) {
367  const ShowerGeometryData& telDataNow = telescopeData[i];
368  const double dT = telDataNow.fT2 - telDataNow.fT1;
369  const double t_i = telDataNow.fT1 + 0.5*dT;
370 
371  if (isNearBorder) {
372  if (!telDataNow.fNearBorder && telDataNow.fTelVarianceSum > 0) {
373  // start a new "far from border" time range
374  isNearBorder = false;
375  rangeStartTime = telDataNow.fT1; // start of time bin, not center
376  }
377  } else {
378  if (telDataNow.fNearBorder || !(telDataNow.fTelVarianceSum > 0) ) {
379  // stop the current "far from border" time range
380  isNearBorder = true;
381  // runs until end of bin (T2), not center.
382  // now we are near border => end of previous bin (T2) = start of current bin (T1)
383  spotFarFromBorderRanges.push_back(std::make_pair(rangeStartTime, telDataNow.fT1));
384  if (fVerbosity > 0) {
385  ostringstream msg;
386  msg << "Telescope " << telId << ": Detected new time range for "
387  << "light-collection-efficiency-less profile reconstruction: "
388  << rangeStartTime << " ns to " << telDataNow.fT1 << " ns.";
389  INFO(msg);
390  }
391  rangeStartTime = -1e99;
392  }
393  }
394 
395  if (telDataNow.fTelVarianceSum > 0) {
396  telFluoTime.push_back(t_i);
397  telFluoTimeBin.push_back(dT);
398  telFluoFlux.push_back(telDataNow.fTelFluxSum);
399  telVFluoFlux.push_back(telDataNow.fTelVarianceSum);
400  telVBackground.push_back(telDataNow.fTelBgVarianceSum);
401  telPixelsInZeta.push_back(&(telDataNow.fPixelsInZeta));
402  }
403 
404  if (telDataNow.fT1 > latestFluxTime && telDataNow.fUsedForTimeFit) {
405  if (telDataNow.fEyeVarianceSum > 0) {
406  eyeFluoTime.push_back(t_i);
407  eyeFluoTimeBin.push_back(dT);
408  eyeFluoFlux.push_back(telDataNow.fEyeFluxSum);
409  eyeVFluoFlux.push_back(telDataNow.fEyeVarianceSum);
410  eyeVBackground.push_back(telDataNow.fEyeBgVarianceSum);
411  }
412  }
413 
414  } // end for each time bin
415 
416  // If (for some obscure reason), we're still within a "far from border" range at
417  // the end of the track, add another range to the list. This isn't known to happen. Ever.
418  if (rangeStartTime >= 0 && !isNearBorder) {
419  const ShowerGeometryData& last = telescopeData.back();
420  spotFarFromBorderRanges.push_back(std::make_pair(rangeStartTime, last.fT2));
421  if (fVerbosity > 0) {
422  ostringstream msg;
423  msg << "Telescope " << telId << ": Detected new time range for "
424  "light-collection-efficiency-less profile reconstruction: "
425  << rangeStartTime << " ns to " << last.fT2 << " ns. "
426  " This is not expected for normal FD events. BE CAREFUL.";
427  WARNING(msg);
428  }
429  }
430 
431  if (!telFluoTime.empty()) {
432  Telescope& telescope = eye.GetTelescope(telId);
433  FillTelescopeFluxes(telescope, telFluoTime, telFluoTimeBin, telFluoFlux,
434  telVFluoFlux, telVBackground, telPixelsInZeta,
435  spotFarFromBorderRanges);
436  }
437 
438  // clear the telescope profile containers for reuse for the next telescope
439  telFluoTime.clear();
440  telFluoTimeBin.clear();
441  telFluoFlux.clear();
442  telVFluoFlux.clear();
443  telVBackground.clear();
444  telPixelsInZeta.clear();
445  latestFluxTime = telescopeIter->fLastTime;
446  } // end for each telescope
447 
448  if (eyeFluoTime.empty())
449  return false;
450 
451  FillEyeFluxes(eye, eyeFluoTime, eyeFluoTimeBin, eyeFluoFlux, eyeVFluoFlux, eyeVBackground);
452  return true;
453 }
454 
455 
458  const FdConstants::LightSource source)
459 {
460  if (!tel.GetRecData().HasLightFlux(source))
461  tel.GetRecData().MakeLightFlux(source);
462 
463  TabulatedFunctionErrors& flux = tel.GetRecData().GetLightFlux(source);
464  flux.Clear();
465  return flux;
466 }
467 
468 
471  const FdConstants::LightSource source)
472 {
473  if (!eye.GetRecData().HasLightFlux(source))
474  eye.GetRecData().MakeLightFlux(source);
475 
476  TabulatedFunctionErrors& flux = eye.GetRecData().GetLightFlux(source);
477  flux.Clear();
478  return flux;
479 }
480 
481 
482 // Fetches the data structures from the eye and calls the generic
483 // profile filler
484 void
486  const vector<double>& fluoTime,
487  const vector<double>& fluoTimeBin,
488  const vector<double>& fluoFlux,
489  const vector<double>& vfluoFlux,
490  const vector<double>& vBackground)
491 {
492  TabulatedFunctionErrors& fluolightprofile =
493  GetClearedEyeLightFlux(eye, FdConstants::eFluorTotal);
494  TabulatedFunctionErrors& lightprofile =
495  GetClearedEyeLightFlux(eye, FdConstants::eTotal);
496  TabulatedFunctionErrors& backgroundProfile =
497  GetClearedEyeLightFlux(eye, FdConstants::eBackground);
498 
499  FillFluxes(fluolightprofile, lightprofile, backgroundProfile,
500  fluoTime, fluoTimeBin, fluoFlux, vfluoFlux, vBackground);
501 }
502 
503 
504 // Fetches the data structures from the telescope and calls the generic
505 // profile filler
506 void
508  const vector<double>& fluoTime,
509  const vector<double>& fluoTimeBin,
510  const vector<double>& fluoFlux,
511  const vector<double>& vfluoFlux,
512  const vector<double>& vBackground,
513  const vector<const vector<unsigned int>*>& pixelsInZeta,
514  const list<pair<double, double>>& farFromBorderTimeRanges)
515 {
516  TabulatedFunctionErrors& fluolightprofile =
517  GetClearedTelescopeLightFlux(tel, FdConstants::eFluorTotal);
518  TabulatedFunctionErrors& lightprofile =
519  GetClearedTelescopeLightFlux(tel, FdConstants::eTotal);
520  TabulatedFunctionErrors& backgroundProfile =
521  GetClearedTelescopeLightFlux(tel, FdConstants::eBackground);
522 
523  FillFluxes( fluolightprofile, lightprofile, backgroundProfile,
524  fluoTime, fluoTimeBin, fluoFlux, vfluoFlux, vBackground );
525 
526  tel.GetRecData().SetSpotFarFromBorderTimeRanges(farFromBorderTimeRanges);
527 
528  // Fill the "pixels in zeta at given time" information as well
529  const unsigned int nBins = pixelsInZeta.size();
530  vector<vector<unsigned int>>& zetaPixels = tel.GetRecData().GetPixelsInZetaOverTime();
531  zetaPixels.resize(nBins);
532  for (unsigned int iTimeBin = 0; iTimeBin < nBins; ++iTimeBin)
533  zetaPixels[iTimeBin] = *pixelsInZeta[iTimeBin];
534 }
535 
536 
537 // The generic profile filler guts, called only from the eye and tel specific fillers
538 void
540  TabulatedFunctionErrors& lightprofile,
541  TabulatedFunctionErrors& backgroundProfile,
542  const vector<double>& fluoTime,
543  const vector<double>& fluoTimeBin,
544  const vector<double>& fluoFlux,
545  const vector<double>& vfluoFlux,
546  const vector<double>& vBackground)
547 {
548  for (unsigned int i = 0, n = fluoTime.size(); i < n; ++i) {
549  const double sigmaFluoFlux = sqrt(vfluoFlux[i]);
550  const double tMean = fluoTime[i];
551  const double dt = fluoTimeBin[i];
552  lightprofile.PushBack(tMean, 0.5*dt, fluoFlux[i], sigmaFluoFlux);
553  fluolightprofile.PushBack(tMean, 0.5*dt, fluoFlux[i], sigmaFluoFlux);
554  backgroundProfile.PushBack(tMean, 0.5*dt, 0, sqrt(vBackground[i]));
555  }
556 }
557 
558 
559 double
561  double initZeta,
562  double finZeta,
563  double stepZeta,
564  bool fillFlux)
565 {
566  double maxSN = 0;
567  double bestZeta = initZeta;
568 
569  if (fillFlux && (initZeta + 1e-12 < finZeta || initZeta - 1e-12 > finZeta)) {
570  ERROR("You called FindZeta with the fillFlux=true argument, but the initial and final guesses "
571  "for zeta are not identical. This is an error. Either call FindZeta for zeta optimization "
572  "(fillFlux=false) or for filling the light fluxes (fillFlux=true, initial zeta==final zeta)");
573  return -9999*degree;
574  }
575 
576  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
577  //CoordinateSystemPtr eyeCS = detFD.GetEye(eye).GetEyeCoordinateSystem();
578  const double referenceLambda = detFD.GetReferenceLambda();
579 
580  // loop on zeta
581 
582  for (double zeta = initZeta; zeta <= finZeta; zeta += stepZeta) {
583 
584  const double cosZeta = cos(zeta);
585  double totalSignal = 0;
586  double totalNoise2 = 0;
587 
588  for (fevt::Eye::TelescopeIterator teliter = eye.TelescopesBegin(ComponentSelector::eHasData);
589  teliter != eye.TelescopesEnd(ComponentSelector::eHasData); ++teliter) {
590 
591  const unsigned int telId = teliter->GetId();
592 
593  const fdet::Telescope& dettel =
594  det::Detector::GetInstance().GetFDetector().GetTelescope(*teliter);
596  const double gainVariance = dettel.GetCamera().GetGainVariance();
597  const double area = dettel.GetDiaphragmArea();
598  const double area2 = area*area;
599 
600  vector<ShowerGeometryData>& telescopeData = fShowerGeometryData[telId];
601 
602  for (fevt::Telescope::ConstPixelIterator pixiter = teliter->PixelsBegin(ComponentSelector::eHasData);
603  pixiter != teliter->PixelsEnd(ComponentSelector::eHasData); ++pixiter) {
604 
605  if (!pixiter->HasRecData())
606  continue;
607 
608  const fdet::Pixel& detPixel = detFD.GetPixel(*pixiter);
609  // get photon-to-photo electron-factor
610  const double photon2Pe = detPixel.GetDiaPhoton2PEFactor(referenceLambda);
611 
612  const Vector& pixeldir = detPixel.GetDirection();
613  const double pixelX = pixeldir.GetX(localTelCS);
614  const double pixelY = pixeldir.GetY(localTelCS);
615  const double pixelZ = pixeldir.GetZ(localTelCS);
616 
617  // photon trace as written by calibrator: (raw trace - baseline)*calibconst
618  const TraceD& photontrace = pixiter->GetRecData().GetPhotonTrace();
619  const double RMS2 = pow(pixiter->GetRecData().GetRMS(), 2);
620 
621  for (unsigned int i = 0; i < telescopeData.size(); ++i) {
622  ShowerGeometryData& thisTelData = telescopeData[i];
623  // zeta-optimization done only with data that was used for the time fit:
624  if (!thisTelData.fUsedForTimeFit && !fillFlux)
625  continue;
626 
627  const double cosAngle = thisTelData.fChiVecMean[0] * pixelX
628  + thisTelData.fChiVecMean[1] * pixelY
629  + thisTelData.fChiVecMean[2] * pixelZ;
630 
631  if (cosAngle > cosZeta) {
632  const unsigned int idx = thisTelData.fADCTraceIndex;
633  if (idx >= photontrace.GetStart() && idx <= photontrace.GetStop()) {
634  const double photonSignal_i = photontrace[idx];
635  const double noise2_i =
636  photonSignal_i < 0 ? RMS2 : RMS2 + photonSignal_i / photon2Pe * (1 + gainVariance);
637 
638  totalSignal += photonSignal_i;
639  totalNoise2 += noise2_i;
640 
641  if (fillFlux) {
642  thisTelData.fTelFluxSum += photonSignal_i/area;
643  thisTelData.fTelVarianceSum += noise2_i/area2;
644  thisTelData.fTelBgVarianceSum += RMS2/area2;
645  // Fill the vector of pixels that are within Zeta at the given time (bin i)
646  thisTelData.fPixelsInZeta.push_back(pixiter->GetId());
647 
648  if (!IsNearBorder(Vector(thisTelData.fChiVecMean[0],
649  thisTelData.fChiVecMean[1],
650  thisTelData.fChiVecMean[2],
651  localTelCS),
652  *teliter, cosZeta)) {
653  // if NOT near border
654  if (thisTelData.fUsedForTimeFit) {
655  thisTelData.fEyeFluxSum += photonSignal_i/area;
656  thisTelData.fEyeVarianceSum += noise2_i/area2;
657  thisTelData.fEyeBgVarianceSum += RMS2/area2;
658  } else if (fOnlyUsedForTimeFit) {
659  thisTelData.fNearBorder = true;
660  }
661  } else { // NEAR border
662  thisTelData.fNearBorder = true;
663  }
664  }
665  } // end for each charge
666  } // end if pixel is in zeta
667  } // time-loop
668  } // pixel-loop
669  } // telescope-loop
670 
671  const double signalToNoise = totalNoise2 > 0 ? totalSignal / sqrt(totalNoise2) : 0.;
672 
673  if (!fillFlux)
674  cout << " "
675  << " zeta [deg] " << zeta/degree
676  << " S/N " << signalToNoise << " S " << totalSignal
677  << endl;
678 
679  if (signalToNoise > maxSN) {
680  maxSN = signalToNoise;
681  bestZeta = zeta;
682  }
683  } // zeta-loop
684 
685  if (maxSN < 1)
686  bestZeta = -9999*degree;
687 
688  if (!fillFlux)
689  cout << " Best Zeta " << bestZeta/degree << "\n" << endl;
690 
691  return bestZeta;
692 }
693 
694 
695 bool
697  const fevt::Telescope& telescope,
698  const double cosZeta)
699  const
700 {
702  iter != telescope.MirrorEventBorderPixelsEnd(); ++iter) {
703  if (CosAngle(direction, *iter) > cosZeta)
704  return true;
705  }
706 
707  return false;
708 }
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
const utl::Vector & GetDirection() const
pointing direction of this pixel
double GetFADCBinSize() const
bool HasLightFlux(const FdConstants::LightSource source=FdConstants::eTotal) const
Check that light profile for source /par source is present.
Definition: EyeRecData.h:297
void Normalize()
Definition: Vector.h:64
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
const double degree
Point object.
Definition: Point.h:32
double Angle(const double theta1, const double phi1, const double theta2, const double phi2)
Description of the electronic channel for the 480 channels of the crate.
void FillEyeFluxes(fevt::Eye &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &)
fevt::EyeHeader & GetHeader()
Header for this Eye Event.
Definition: FEvent/Eye.cc:180
utl::TabulatedFunctionErrors & GetClearedTelescopeLightFlux(fevt::Telescope &tel, const fevt::FdConstants::LightSource source)
bool HasRecData() const
Definition: FEvent/Eye.h:116
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
SizeType GetStop() const
Get valid data stop bin.
Definition: Trace.h:148
bool HasFEvent() const
const Pixel & GetPixel(const fevt::Pixel &eventPixel) const
Get fdet::Pixel from fevt::Channel.
Definition: FDetector.cc:198
utl::Vector GetAxis() const
double GetGainVariance() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
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
fevt::TelescopeRecData & GetRecData()
Reconstructed data for this telescope.
double pow(const double x, const unsigned int i)
void FillFluxes(utl::TabulatedFunctionErrors &, utl::TabulatedFunctionErrors &, utl::TabulatedFunctionErrors &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &)
void FillTelescopeFluxes(fevt::Telescope &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &, const std::vector< double > &, const std::vector< const std::vector< unsigned int > * > &, const std::list< std::pair< double, double >> &)
double GetMag() const
Definition: Vector.h:58
const Camera & GetCamera() const
Get the Camera object that belongs to the telescope.
std::vector< utl::Vector >::const_iterator ConstMirrorEventBorderPixelsIterator
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
void SetZeta(const double zeta)
Definition: EyeRecData.h:216
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
boost::indirect_iterator< ConstInternalPixelIterator, const Pixel & > ConstPixelIterator
Const iterator over pixels used in reconstruction.
Definition: EyeRecData.h:117
constexpr double deg
Definition: AugerUnits.h:140
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
ConstMirrorEventBorderPixelsIterator MirrorEventBorderPixelsEnd() const
End of list of pixels just outside the mirror event.
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
LightSource
Possible light sources.
Definition: FdConstants.h:9
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
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.
bool HasFRecShower() const
Check if reconstructed shower info has been allocated.
Definition: EyeRecData.h:330
evt::ShowerFRecData & GetFRecShower()
Reconstructed shower info for this eye.
Definition: EyeRecData.h:323
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
void SetSpotFarFromBorderTimeRanges(const std::list< std::pair< double, double >> &timeRanges)
boost::filter_iterator< ComponentSelector, ConstAllPixelIterator > ConstPixelIterator
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 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
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
a second level trigger
Definition: XbT2.h:8
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:207
double GetReferenceLambda() const
Definition: FDetector.cc:332
ConstMirrorEventBorderPixelsIterator MirrorEventBorderPixelsBegin() const
Begin of list of pixels just outside the mirror event.
double FindZeta(fevt::Eye &eye, double initZeta, double finZeta, double stepZeta, bool fillFlux=false)
fevt::FEvent & GetFEvent()
utl::TabulatedFunctionErrors & GetClearedEyeLightFlux(fevt::Eye &eye, const fevt::FdConstants::LightSource source)
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
constexpr double kSpeedOfLight
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
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
Definition: FDetector.cc:150
double GetFADCBinSize() 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
SizeType GetStart() const
Get valid data start bin.
Definition: Trace.h:142
Description of a pixel.
utl::Point GetPosition() const
PixelIterator TimeFitPixelsEnd()
Definition: EyeRecData.h:171
total (shower and background)
Vector object.
Definition: Vector.h:30
Interface class to access to Fluorescence reconstruction of a Shower.
double CosAngle(const Vector &l, const Vector &r)
Definition: OperationsVV.h:71
Main configuration utility.
Definition: CentralConfig.h:51
void MakeLightFlux(const FdConstants::LightSource source=FdConstants::eTotal)
constexpr double ns
Definition: AugerUnits.h:162
bool IsNearBorder(const utl::Vector &direction, const fevt::Telescope &telescope, double zeta) const
Fluorescence Detector Telescope Event.
utl::TabulatedFunctionErrors & GetLightFlux(const FdConstants::LightSource source=fevt::FdConstants::eTotal)
Light flux at diaphragm, photons/m^2 versus time in ns.
Definition: EyeRecData.h:286
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:212
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
PixelIterator TimeFitPixelsBegin()
Definition: EyeRecData.h:167
double GetDiaPhoton2PEFactor(const double wavelength, const std::string &configSignature="") const
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
const utl::Point & GetCorePosition() const
Shower core as reconstructed by the FD or FD eye.
unsigned int GetId() const
boost::filter_iterator< ComponentSelector, ConstAllTelescopeIterator > ConstTelescopeIterator
Definition: FEvent/Eye.h:73
void MakeLightFlux(const FdConstants::LightSource source=FdConstants::eTotal)
Definition: EyeRecData.h:293
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
const utl::TimeStamp & GetCoreTime() const
time when shower front passes through the core point
Description of a camera.
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.
Definition: FEvent/Eye.cc:130
const utl::Vector & GetAxis() const
Shower Axis as reconstructed by the FD or FD eye.

, generated on Tue Sep 26 2023.