FdPulseFinder.cc
Go to the documentation of this file.
1 
10 #include <fwk/CentralConfig.h>
11 
12 #include <utl/Reader.h>
13 #include <utl/ErrorLogger.h>
14 #include <utl/Trace.h>
15 #include <utl/TraceAlgorithm.h>
16 #include <utl/PhysicalConstants.h>
17 #include <utl/Vector.h>
18 #include <utl/Point.h>
19 #include <utl/Math.h>
20 
21 #include <evt/Event.h>
22 #include <evt/ShowerRecData.h>
23 #include <evt/ShowerFRecData.h>
24 
25 #include <fevt/FEvent.h>
26 #include <fevt/Eye.h>
27 #include <fevt/Telescope.h>
28 #include <fevt/EyeRecData.h>
29 #include <fevt/EyeHeader.h>
30 #include <fevt/Pixel.h>
31 #include <fevt/PixelRecData.h>
32 #include <fevt/PixelTriggerData.h>
33 #include <fevt/SLTData.h>
34 
35 #include <det/Detector.h>
36 
37 #include <fdet/FDetector.h>
38 #include <fdet/Telescope.h>
39 #include <fdet/Camera.h>
40 #include <fdet/Pixel.h>
41 #include <fdet/Eye.h>
42 
43 #include "FdPulseFinder.h"
44 
45 #include "TTree.h"
46 
47 #include <sstream>
48 
49 using namespace std;
50 using namespace fwk;
51 using namespace utl;
52 using namespace evt;
53 using namespace fevt;
54 using namespace det;
55 using namespace fdet;
56 using namespace FdPulseFinderOG;
57 
58 
61 {
62  CentralConfig& cc = *CentralConfig::GetInstance();
63  Branch topB = cc.GetTopBranch("FdPulseFinder");
64 
65  if (!topB) {
66  ERROR("Could not find branch FdPulseFinder ");
67  return eFailure;
68  }
69 
70  topB.GetChild("verbosity").GetData(fVerbosity);
71  topB.GetChild("useAllPixels").GetData(fuseAllPixels);
72  topB.GetChild("minSnRatio").GetData(fMinSnRatio);
73  topB.GetChild("offset").GetData(fOffsetTime);
74  topB.GetChild("minWindowLength").GetData(fMinWindowLengthTime);
75  topB.GetChild("maxWindowLength").GetData(fMaxWindowLengthTime);
76 
77  // SetMaxTreeSize to avoid problems with large files
78  TTree::SetMaxTreeSize(1000*Long64_t(2000000000));
79 
80  // info output
81  ostringstream info;
82  info << "\n"
83  " Version: " << GetVersionInfo(VModule::eRevisionNumber) << "\n"
84  " Parameters:\n"
85  " min SN ratio: " << fMinSnRatio << "\n"
86  " offset: " << fOffsetTime / ns << "ns\n"
87  " min window length: " << fMinWindowLengthTime / ns << "ns\n"
88  " max window length: " << fMaxWindowLengthTime / ns << "ns\n";
89  if (fuseAllPixels)
90  info << " use all pixels: " << fuseAllPixels << '\n';
91 
92  INFO(info);
93 
94  return eSuccess;
95 }
96 
97 
99 FdPulseFinder::Run(evt::Event& event)
100 {
101  if (fVerbosity > 0)
102  INFO(" searching for pulses ");
103 
104  if (!event.HasFEvent())
105  return eSuccess;
106 
107  bool flagPrintout = false;
108 
109  FEvent& fevent = event.GetFEvent();
110  for (FEvent::EyeIterator eyeiter = fevent.EyesBegin(ComponentSelector::eHasData);
111  eyeiter != fevent.EyesEnd(ComponentSelector::eHasData); ++eyeiter) {
112 
113  bool firstRun = true;
114  if (eyeiter->HasRecData()) {
115 
116  EyeRecData& eyeRec = eyeiter->GetRecData();
117 
118  if (eyeRec.GetNPulsedPixels()) {
119 
120  if (!flagPrintout) {
121  flagPrintout = true;
122  INFO("Running 2nd time, using reconstructed geometry to find more pulses.");
123  }
124 
125  firstRun = false;
126 
127  // RESET pulsed pixels list
128  if (fVerbosity > 1)
129  INFO("cleaning up pulsed pixel list ");
130  for (EyeRecData::PixelIterator iPixel = eyeRec.PulsedPixelsBegin();
131  iPixel != eyeRec.PulsedPixelsEnd(); ) {
132  iPixel = eyeRec.RemovePulsedPixel(iPixel);
133  }
134 
135  // RESET sdp pixels list
136  if (fVerbosity > 1)
137  INFO("cleaning up sdp pixel list ");
138  for (EyeRecData::PixelIterator iPixel = eyeRec.SDPPixelsBegin();
139  iPixel != eyeRec.SDPPixelsEnd(); ) {
140  iPixel = eyeRec.RemoveSDPPixel(iPixel);
141  }
142 
143  // RESET time fit pixels list
144  if (fVerbosity > 1)
145  INFO("cleaning up time fit pixel list ");
146  for (EyeRecData::PixelIterator iPixel = eyeRec.TimeFitPixelsBegin();
147  iPixel != eyeRec.TimeFitPixelsEnd(); ) {
148  iPixel = eyeRec.RemoveTimeFitPixel(iPixel);
149  }
150  }
151  } else
152  eyeiter->MakeRecData();
153 
154  for (fevt::Eye::TelescopeIterator teliter = eyeiter->TelescopesBegin(ComponentSelector::eHasData);
155  teliter != eyeiter->TelescopesEnd(ComponentSelector::eHasData); ++teliter) {
156 
157  fCountPix = 0;
158  fCountFlt = 0;
159  fCountPulsed = 0;
160  fCountNoRecData = 0;
161  fCountNoTrigData = 0;
162  fCountBoundsErr = 0;
163 
164  for (fevt::Telescope::PixelIterator pixiter = teliter->PixelsBegin(ComponentSelector::eHasData);
165  pixiter!= teliter->PixelsEnd(ComponentSelector::eHasData); ++pixiter) {
166 
167  bool pulseSearched = false;
168  bool pulseFound = false;
169 
170  if (!firstRun) {
171 
172  EyeRecData& eyeRec = eyeiter->GetRecData();
173 
174  // Check if module runs after geometry reconstruction
175  // If so, use the geometry to find more pulses in non-triggered pixels !
176  if (eyeRec.HasFRecShower()) {
177  pulseFound = FindAdditionalPulse(*pixiter, *eyeiter, eyeRec.GetFRecShower());
178  pulseSearched = true;
179  } else {
180  if (event.HasRecShower() && event.GetRecShower().HasFRecShower()) {
181  pulseFound = FindAdditionalPulse(*pixiter, *eyeiter, event.GetRecShower().GetFRecShower());
182  pulseSearched = true;
183  }
184  }
185  }
186 
187  // Convert the pulse window widths from time to no. of bins
188  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
189  const fdet::Camera& detCamera = detFD.GetTelescope(*teliter).GetCamera();
190  const double lengthFADCBin = detCamera.GetFADCBinSize();
191  fOffset = static_cast<unsigned int>(fOffsetTime / lengthFADCBin);
192  fMinWindowLength = static_cast<int>(fMinWindowLengthTime / lengthFADCBin);
193  fMaxWindowLength = static_cast<int>(fMaxWindowLengthTime / lengthFADCBin);
194 
195  if (!pulseSearched)
196  pulseFound = FindPulse(*pixiter);
197 
198  if (pulseFound) {
199 
200  EyeRecData& eyerecdata = eyeiter->GetRecData();
201  eyerecdata.AddPulsedPixel(*pixiter);
202 
203  }
204 
205  }
206 
207  ostringstream info;
208  info << "nPix=" << fCountPix
209  << " nFLT=" << fCountFlt
210  << " nNoRec=" << fCountNoRecData
211  << " nNoTrg=" << fCountNoTrigData
212  << " nErr=" << fCountBoundsErr
213  << " nPulse=" << fCountPulsed;
214  INFO(info);
215 
216  } // for teliter
217 
218  } // for eyeiter
219 
220  return eSuccess;
221 }
222 
223 
225 FdPulseFinder::Finish()
226 {
227  return eSuccess;
228 }
229 
230 
253 bool
254 FdPulseFinder::FindPulse(fevt::Pixel& pixel)
255 {
256  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
257  const fdet::Pixel& detPixel = detFD.GetPixel(pixel);
258 
259  const int pixelId = pixel.GetId();
260  const int eyeId = detPixel.GetEyeId();
261  const int telId = detPixel.GetTelescopeId();
262  const int channelId = detPixel.GetChannelId();
263 
264  ++fCountPix;
265 
266  if (!pixel.HasRecData()) {
267  if (fVerbosity > 2) {
268  ostringstream info;
269  info << " Pixel: " << pixelId << " tel: " << telId << " eye: " << eyeId << " has no rec-data ";
270  INFO(info);
271  }
272  ++fCountNoRecData;
273  return false;
274  }
275 
276  fevt::PixelRecData& pixelrec = pixel.GetRecData();
277 
278  if (!pixel.HasTriggerData()) {
279  if (fVerbosity > 2) {
280  ostringstream info;
281  info << " Pixel: " << pixelId << " tel: " << telId << " eye: " << eyeId << " has no trigger-data ";
282  INFO(info);
283  }
284  ++fCountNoTrigData;
285  return false;
286  }
287 
288  const fevt::PixelTriggerData& pixelTrig = pixel.GetTriggerData();
289  const utl::TraceB& fltTrace = pixelTrig.GetFLTTrace();
290 
291  const fdet::Telescope& detTel = detFD.GetEye(eyeId).GetTelescope(telId);
292  const fdet::Camera& detCamera = detTel.GetCamera();
293 
294  const TraceD& trace = pixelrec.GetPhotonTrace();
295  const int firstFLTbin = pixelrec.GetFirstTriggeredTimeBin(); // use as 'has FLT' flag
296 
297  if (fVerbosity > 0)
298  cout << "\nPixel=" << pixelId << " Tel=" << telId << " channel=" <<channelId
299  << " fltBin=" << firstFLTbin << endl;
300 
301  // pulse search region
302  unsigned int start = 0;
303  unsigned int stop = 0;
304 
305  if (firstFLTbin >= 0) {
306 
307  ++fCountFlt;
308 
309  const double fltBinSize = fltTrace.GetBinning(); //detCamera.GetTraceSLTBinSize();
310  const unsigned int fltTraceLength = fltTrace.GetSize(); //detCamera.GetTraceSLTBinSize();
311 
312  // sanity checks
313  if (fltTraceLength != trace.GetSize()) {
314  ostringstream err;
315  err << " FADC and FLT trace have different sizes! nFADC=" << trace.GetSize()
316  << " and nFLT=" << fltTraceLength << ". CONNOT HANDLE!";
317  ERROR(err.str());
318  return false;
319  }
320 
321  if (fltBinSize != trace.GetBinning()) {
322  ostringstream err;
323  err << " FADC and FLT binning differs! bFADC=" << trace.GetBinning()/ns
324  << " and bFLT=" << fltBinSize/ns << ". CONNOT HANDLE!";
325  ERROR(err.str());
326  return false;
327  }
328 
329  // storage for all FLT trigger section (pulses)
330  vector<unsigned int> length; // length of SLT triggered section
331  vector<unsigned int> firstSectionBin; // SLT trace binning
332  vector<unsigned int> lastSectionBin; // SLT trace binning
333 
334  if (fVerbosity > 0) {
335  cout << "FLT-trace: ";
336  for (unsigned int bin = 0; bin < fltTraceLength; ++bin)
337  if (fltTrace[bin])
338  cout << "1";
339  else
340  cout << "0";
341  cout << endl;
342  }
343 
344  // loop FLT/FADC - pixel trace
345 
346  unsigned int currLength = 0;
347  bool gotTrigger = false;
348  for (unsigned int bin = 0; bin < fltTraceLength; ++bin) {
349 
350  if (fltTrace[bin]) { // bin was FLT
351 
352  ++currLength;
353  if (!gotTrigger) {
354  firstSectionBin.push_back(bin);
355  gotTrigger = true;
356  }
357 
358  } else if (gotTrigger) { // triggered section has ended -> check length
359 
360  length.push_back(currLength);
361  lastSectionBin.push_back(bin - 1);
362 
363  // reset
364  currLength = 0;
365  gotTrigger = false;
366  }
367  } // end loop FLT/FADC trace
368 
369  // necessary if last section reaches end of trace
370  if (gotTrigger) {
371  length.push_back(currLength);
372  lastSectionBin.push_back(fltTraceLength - 1);
373  }
374 
375  // loop found FLT sections, and select the prime candidate for pulse search
376 
377  double maxSectionCharge = 0;
378  unsigned int noMaxChargeSection = 0;
379  for (unsigned int section = 0; section < length.size(); ++section) {
380 
381  unsigned int sectionStart = firstSectionBin[section];
382  unsigned int sectionStop = lastSectionBin[section];
383 
384  unsigned int fltBoxcar = detCamera.GetFLTBoxcarSumLength();
385 
386  if (sectionStart < fltBoxcar)
387  sectionStart = 0;
388  else
389  sectionStart = sectionStart - fltBoxcar;
390 
391  if (sectionStop + fltBoxcar >= fltTraceLength)
392  sectionStop = fltTraceLength-1;
393  else
394  sectionStop = sectionStop + fltBoxcar;
395 
396  const double sectionCharge = TraceAlgorithm::Sum(trace, sectionStart, sectionStop);
397  //firstSectionBin[section], lastSectionBin[section] );
398 
399  if (fVerbosity > 0) {
400  cout << "Section " << section
401  << ": " << firstSectionBin[section]
402  << " - " << lastSectionBin[section]
403  << " -> " << sectionStart
404  << " - " << sectionStop
405  << ", charge: " << sectionCharge << endl;
406  }
407 
408  firstSectionBin[section] = sectionStart;
409  lastSectionBin[section] = sectionStop;
410 
411  if (sectionCharge > maxSectionCharge) {
412  maxSectionCharge = sectionCharge;
413  noMaxChargeSection = section;
414  }
415 
416  } // loop over triggered sections
417 
418  // starting to search for highest signal in 'biggest' FLT triggered section
419 
420  double maxSignal = 0;
421  unsigned int maxSignalBin = 0;
422  if (firstSectionBin.size() > noMaxChargeSection) {
423 
424  for (unsigned int i = firstSectionBin[noMaxChargeSection];
425  i < lastSectionBin[noMaxChargeSection]; ++i) {
426 
427  if (trace[i] > maxSignal) {
428  maxSignal = trace[i];
429  maxSignalBin = i;
430  }
431 
432  }
433 
434  } else {
435 
436  // IF WE CAME HERE WITHOUT FINDING ANY PULSE, SOMETHING MUST BE WRONG WITH THE EVENT
437  // -> no detailed FLT information: using the first FLT bin for pulse search
438 
439  maxSignalBin = firstFLTbin;
440  }
441 
442  // setting the final search boundaries
443 
444  if (maxSignalBin < fOffset)
445  start = trace.GetStart();
446  else
447  start = maxSignalBin-fOffset;
448 
449  if (maxSignalBin + fOffset > trace.GetStop())
450  stop = trace.GetStop();
451  else
452  stop = maxSignalBin+fOffset;
453 
454  if (fVerbosity > 0) {
455  cout << "Selected section " << noMaxChargeSection
456  << " and found biggest signal in bin " << maxSignalBin
457  << endl;
458  }
459 
460  } else { // firstFLTbin < 0 ---> No FLT trigger
461 
462  if (!fuseAllPixels) {
463  // Don't look at non-triggered pixels !
464  if (fVerbosity > 0)
465  cout << "no FLT -> skipping" << endl;
466  return false;
467  }
468 
469  // -> Use full trace range ........
470 
471  start = trace.GetStart();
472  stop = trace.GetStop();
473  }
474 
475  return FindBestSignalOverNoise(pixel, start, stop);
476 }
477 
478 
479 // changed start and stop and windowstart, windowstop to type int instead of
480 // unsigned int to avoid problems with this comparison:
481 // windowStart< (stop - fMaxWindowLength)
482 // when (stop - fMaxWindowLength) is negative
483 
484 bool
485 FdPulseFinder::FindBestSignalOverNoise(fevt::Pixel& pixel,
486  const int start, const int stop)
487  const
488 {
489  fevt::PixelRecData& pixelrec = pixel.GetRecData();
490  const TraceD& trace = pixelrec.GetPhotonTrace();
491 
492  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
493  const unsigned int eyeId = pixel.GetEyeId();
494  const unsigned int telId = pixel.GetTelescopeId();
495  const fdet::Pixel& detPixel = detFD.GetPixel(pixel);
496  const fdet::Telescope& detTel = detFD.GetEye(eyeId).GetTelescope(telId);
497  const fdet::Camera& detCamera = detTel.GetCamera();
498  const double Vg = detCamera.GetGainVariance();
499  const double referenceLambda = detFD.GetReferenceLambda();
500  const double photon2pe = detPixel.GetDiaPhoton2PEFactor(referenceLambda);
501 
502  // calculate correlation from cutoffFrequency, see A.Menshikov et al,
503  // IEEE Vol. 50 (2003), 1208 Eq.(5) and (6)
504 
505  // original numbers from P.Wahrlich:
506  // r_01 = 0.2; standard telescopes
507  // r_01 = 0.43; HEAT
508 
509  // calculated numbers (as of FModelConfig.xml March 2012):
510  // r_01 = 0.30; standard telescopes
511  // r_01 = 0.46; HEAT
512 
513  const double F = detCamera.GetCutoffFrequency();
514  const double deltaT = detCamera.GetFADCBinSize();
515  const double r_01 = exp(-4 * kPi * pow(deltaT * F, 2));
516 
517  const int pixelId = pixel.GetId();
518  const int channelId = detPixel.GetChannelId();
519 
520  // ####### Start to search for pulse #############
521 
522  //if (start < trace.GetStart()) start = trace.GetStart();
523  //if (stop > trace.GetStop()) stop = trace.GetStop();
524 
525  if( fVerbosity > 0) {
526  if (fuseAllPixels) {
527  cout << "\nPixel " << pixelId << " channel=" << channelId
528  << " == > searching pulse between: " << start << " - " << stop << endl;
529  } else
530  cout << " == > searching pulse between: " << start << " - " << stop << endl;
531  }
532 
533  unsigned int pulseStart = 0;
534  unsigned int pulseStop = 0;
535 
536  double maxSnRatio = 0;
537 
538  double rmsnoise = pixelrec.GetRMS();
539 
540  for (int windowStart = start; windowStart < stop - fMinWindowLength; ++windowStart) {
541 
542  for (int windowStop = windowStart + fMinWindowLength;
543  windowStop < windowStart + fMaxWindowLength && windowStop <= stop;
544  ++windowStop) {
545 
546  const double value = TraceAlgorithm::Sum(trace, windowStart, windowStop);
547 
548  //double snratio = value / ((windowStop - windowStart) * rmsnoise);
549  const double w = abs(double(windowStop - windowStart));
550  const double snratio = value / (sqrt(w) * rmsnoise);
551 
552  if (snratio > maxSnRatio) {
553 
554  maxSnRatio = snratio;
555  pulseStart = windowStart;
556  pulseStop = windowStop;
557 
558  }
559 
560  }
561 
562  }
563 
564  if (pulseStart <= trace.GetStart()) {
565  ++fCountBoundsErr;
566  return false; // check bounds
567  }
568  if (pulseStop >= trace.GetStop()) {
569  ++fCountBoundsErr;
570  return false;
571  }
572 
573  // pwahrlich 13/08/10, modified 3 Nov 2010:
574  // Added a constraint that while extending the pulse
575  // window, the total signal/noise can not drop below 5-sigma.
576 
577  // The pulse window is extended in 1-bin increments in the direction with
578  // the highest 1-bin signal
579 
580  // The complicated logic is to check other pulse window boundary when
581  // the chosen boundary fails to following criteria:
582 
583  // Extend trace until:
584  // 1-bin signal drops below 1-sigma
585  // AND
586  // 3-bin signal drops below sqrt(3)-sigma
587 
588  while (true) {
589 
590  if (pulseStart == trace.GetStart() || pulseStop == trace.GetStop() ||
591  pulseStart-1 == trace.GetStart() || pulseStop + 1 == trace.GetStop()) {
592  ++fCountBoundsErr;
593  return false;
594  }
595 
596  const double sigStart = trace[pulseStart-1] + trace[pulseStart] + trace[pulseStart+1];
597  const double sigStop = trace[pulseStop+1] + trace[pulseStop] + trace[pulseStop-1];
598  const double noiseQuadSum = sqrt(pulseStop - pulseStart + 1) * rmsnoise;
599 
600  const bool extendStart = trace[pulseStart-1] >= trace[pulseStop+1];
601  const bool startThr = sigStart > rmsnoise*sqrt(3) || trace[pulseStart-1] > rmsnoise;
602  const bool stopThr = sigStop > rmsnoise*sqrt(3) || trace[pulseStop+1] > rmsnoise;
603  const bool startSnRatio = TraceAlgorithm::Sum(trace, pulseStart - 1, pulseStop) / noiseQuadSum > fMinSnRatio;
604  const bool stopSnRatio = TraceAlgorithm::Sum(trace, pulseStart, pulseStop + 1) / noiseQuadSum > fMinSnRatio;
605 
606  if ((extendStart || (!extendStart && (!stopThr || !stopSnRatio))) &&
607  startThr && startSnRatio)
608  --pulseStart;
609  else if ((!extendStart || (extendStart && (!startThr || !startSnRatio))) &&
610  stopThr && stopSnRatio)
611  ++pulseStop;
612  else
613  break;
614  }
615 
616  const double charge = TraceAlgorithm::Sum(trace, pulseStart, pulseStop);
617 
618  // redefine sn ratio
619  const double new_snRatio =
620  charge / sqrt(double(pulseStop - pulseStart)) / rmsnoise;
621 
622  if (new_snRatio > fMinSnRatio) {
623 
624  pixelrec.SetPulseFound();
625  pixelrec.SetPulseStart(pulseStart);
626  pixelrec.SetPulseStop(pulseStop);
627 
628  pixelrec.SetTotalCharge(charge);
629 
630  const double centroid = TraceAlgorithm::Centroid(trace, pulseStart, pulseStop);
631  // centroid "time" is at center of bins
632 
633  // p. wahrlich 12/04/10: see GAP2009-133 for details
634  // of the centroid error calculation
635 
636  const double rmspe2 = Sqr(rmsnoise*photon2pe);
637 
638  double centroid_err2 = 0;
639  double peCovariance = r_01;
640 
641  for (unsigned int i = pulseStart; i <= pulseStop; ++i) {
642 
643  // if the trace is negative, set the trace to zero for error calculation.
644  // this means that the bin is assumed to contain only noise (no signal).
645 
646  const double trace0 = (trace[i] < rmsnoise) ? 0 : trace[i];
647  const double trace1 = (trace[i+1] < rmsnoise) ? 0 : trace[i+1];
648 
649  // photoelectron variance
650  const double peVariance = rmspe2 + trace0 * photon2pe * (1 + Vg);
651 
652  // mean photoelectron time variance
653  const double timeVariance = trace0 ? 1 / (12 * trace0 * photon2pe) : 0;
654 
655  // photoelectron covariance
656  if (i != pulseStop)
657  peCovariance = r_01 * sqrt((rmspe2 + trace0 * photon2pe*(1 + Vg)) * (rmspe2 + trace1 * photon2pe*(1 + Vg)));
658 
659  const double binTime = i + 0.5;
660 
661  centroid_err2 +=
662  (Sqr(binTime - centroid) * peVariance + 2*(binTime - centroid)*(binTime + 1 - centroid) * peCovariance + Sqr(trace0*photon2pe)*timeVariance) / Sqr(charge*photon2pe);
663 
664  }
665 
666  //----------End centroid error determination
667 
668  const double centroid_err = sqrt(centroid_err2);
669 
670  pixelrec.SetCentroid(centroid, centroid_err);
671 
672  if (fVerbosity > 0) {
673  cout << "Found Pulse at " << centroid << " with charge " << charge
674  << " between " << pulseStart << " - " << pulseStop << endl;
675  }
676 
677  ++fCountPulsed;
678  return true;
679 
680  } // if new_snRatio
681 
682  return false;
683 }
684 
685 
686 bool
687 FdPulseFinder::FindAdditionalPulse(fevt::Pixel& pixel,
688  const fevt::Eye& eyeEvt,
689  const evt::ShowerFRecData& /*frec*/)
690  const
691 {
692  if (!pixel.HasRecData())
693  return false;
694 
695  fevt::PixelRecData& pixelrec = pixel.GetRecData();
696  const int pixelId = pixel.GetId();
697  const int telId = pixel.GetTelescopeId();
698 
699  if (fVerbosity > 0)
700  cout << "\n FindAdditionalPulse for Pixel=" << pixelId << " Tel=" << telId << '\n';
701 
702  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
703 
704  const fevt::Telescope& telEvent = eyeEvt.GetTelescope(pixel.GetTelescopeId());
705  const fevt::EyeRecData& eyeRec = eyeEvt.GetRecData();
706  //const fevt::EyeHeader& eyeHeader = eyeEvt.GetHeader();
707 
708  const fdet::Telescope& detTel = detFD.GetTelescope(telEvent);
709  const fdet::Camera& detCamera = detTel.GetCamera();
710  double fadcBinning = detCamera.GetFADCBinSize();
711  unsigned int fadcSize = detCamera.GetFADCTraceLength();
712 
713  const fdet::Eye& detEye = detFD.GetEye(eyeEvt);
714  const CoordinateSystemPtr& eyeCS = detEye.GetEyeCoordinateSystem();
715  const Vector vertical(0,0,1, eyeCS);
716 
717  const fdet::Pixel& detPixel = detFD.GetPixel(pixel);
718  const utl::Vector& pixelDir = detPixel.GetDirection();
719 
720  //const Vector& axis = frec.GetAxis();
721  //const utl::Point& core = frec.GetCorePosition();
722 
723  const Vector sdp = eyeRec.GetSDP();
724  const Vector horizontal_in_sdp = Cross(sdp, vertical);
725 
726  const double T0 = eyeRec.GetTZero();
727  const double Chi_0 = eyeRec.GetChiZero();
728  const double Rp = eyeRec.GetRp();
729 
730  //TimeStamp eyeTrig = eyeHeader.GetTimeStamp();
731  const double telTimeOffset = telEvent.GetTimeOffset();
732 
733  const Vector chi_i_vector = pixelDir - (sdp * pixelDir) * sdp;
734 
735  const double Chi_i = Angle(horizontal_in_sdp, chi_i_vector);
736  const double alpha = Chi_0 - Chi_i - 90*deg;
737 
738  // all times relative to eye trigger time
739  const double t = T0 + Rp/utl::kSpeedOfLight * (tan(alpha) + 1/cos(alpha)) - telTimeOffset;
740 
741  const unsigned int bin = ceil(t / fadcBinning);// - fadcSize;
742 
743  if (fVerbosity > 0)
744  cout << " pixel chi_i=" << Chi_i/deg << " alpha=" << alpha/deg
745  << " t=" << t << " bin=" << bin
746  << " telOffset=" << telTimeOffset
747  << " Rp=" << Rp
748  << " T0=" << T0
749  << " chi0=" << Chi_0/deg
750  << " recChi_i=" << pixelrec.GetChi_i()/deg
751  << endl;
752 
753  if (t < 0 || bin >= fadcSize) {
754  if (fVerbosity >= 1)
755  INFO("Shower out of FD-DAQ time-window (for this pixel)!");
756  return false;
757  }
758 
759  // setting the search boundaries
760 
761  unsigned int offset = fOffset/2;
762  const unsigned int start = (bin < offset) ? 0 : bin - offset;
763  unsigned int stop = (bin + offset >= fadcSize) ? fadcSize - 1 : bin + offset;
764 
765  if (pixelrec.PulseIsFound()) {
766 
767  const double pulseTime = pixelrec.GetCentroid();
768 
769  ostringstream info;
770  info << " -> Found FLT pixel with pulse at time=" << pulseTime;
771  INFO(info);
772 
773  // check for already existing pulse in time-window
774  if (pulseTime > start && pulseTime < stop) {
775  if (fVerbosity > 0)
776  INFO("Pixel had already valid pulse. Keeping.");
777  return true;
778  }
779 
780  INFO("Pulse possibly wrong. Refine search...");
781  }
782 
783  if (fVerbosity > 1) {
784  ostringstream info;
785  info << " -> Search additional pulse in pixel=" << pixelId << " within [" << start << " - " << stop << "]";
786  INFO(info);
787  }
788 
789  if (FindBestSignalOverNoise(pixel, start, stop)) {
790  ostringstream info;
791  info << "New pulse found in pixel=" << pixelId;
792  INFO(info);
793  return true;
794  }
795 
796  if (fVerbosity > 1)
797  INFO ("No pulse found");
798 
799  return false;
800 }
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
AxialVector Cross(const Vector &l, const Vector &r)
Definition: OperationsAV.h:25
PixelIterator RemoveTimeFitPixel(PixelIterator it)
Remove a pixel from the list of Time Fit pixels.
Definition: EyeRecData.h:180
const utl::Vector & GetDirection() const
pointing direction of this pixel
double GetChi_i() const
Definition: PixelRecData.h:117
double GetFADCBinSize() const
constexpr T Sqr(const T &x)
double Angle(const double theta1, const double phi1, const double theta2, const double phi2)
void SetPulseStart(const int start)
Definition: PixelRecData.h:103
ShowerFRecData & GetFRecShower()
double GetRMS() const
Get the baseline RMS of the trace.
Definition: PixelRecData.h:76
unsigned int GetTelescopeId() const
1..6 for normal FD, 1..3 for HEAT
unsigned int GetTimeOffset() const
Time offset of this Telescope compared to fevt::Header::GetTime [ns].
Fluorescence Detector Eye Event.
Definition: FEvent/Eye.h:29
SizeType GetStop() const
Get valid data stop bin.
Definition: Trace.h:148
PixelIterator PulsedPixelsEnd()
Definition: EyeRecData.h:121
bool HasRecShower() const
bool HasFEvent() const
const Pixel & GetPixel(const fevt::Pixel &eventPixel) const
Get fdet::Pixel from fevt::Channel.
Definition: FDetector.cc:198
double GetChiZero() const
Definition: EyeRecData.h:85
Fluorescence Detector Pixel Trigger Data.
ShowerRecData & GetRecShower()
double GetCutoffFrequency() const
bool HasRecData() const
Definition: FEvent/Pixel.h:43
PixelTriggerData & GetTriggerData()
Definition: FEvent/Pixel.h:45
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
double GetBinning() const
size of one slot
Definition: Trace.h:138
double GetGainVariance() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void SetPulseFound(bool flag=true)
Definition: PixelRecData.h:108
void SetTotalCharge(const double charge)
Definition: PixelRecData.h:102
void Init()
Initialise the registry.
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
PixelIterator PulsedPixelsBegin()
Definition: EyeRecData.h:119
double pow(const double x, const unsigned int i)
bool PulseIsFound() const
Definition: PixelRecData.h:84
const Camera & GetCamera() const
Get the Camera object that belongs to the telescope.
int GetFLTBoxcarSumLength() const
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
constexpr double deg
Definition: AugerUnits.h:140
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
unsigned int GetId() const
Definition: FEvent/Pixel.h:31
Class representing a document branch.
Definition: Branch.h:107
utl::TraceD & GetPhotonTrace(const FdConstants::LightSource source=FdConstants::eTotal)
Definition: PixelRecData.h:35
void AddPulsedPixel(fevt::Pixel &pixel)
add a pixel to the list of pulsed pixels
Definition: EyeRecData.h:129
void SetCentroid(const double centroid, const double err)
Definition: PixelRecData.h:81
PixelIterator SDPPixelsBegin()
Definition: EyeRecData.h:139
Fluorescence Detector Pixel event.
Definition: FEvent/Pixel.h:28
unsigned int GetChannelId() const
const double ns
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
constexpr double kPi
Definition: MathConstants.h:24
double abs(const SVector< n, T > &v)
const Telescope & GetTelescope(const unsigned int telescopeId) const
Find Telescope by numerical Id.
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
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
Definition: FEvent/Eye.h:72
SizeType GetSize() const
Definition: Trace.h:156
unsigned int GetNPulsedPixels() const
Get number of pulsed pixels.
Definition: EyeRecData.h:137
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
Top of Fluorescence Detector event hierarchy.
Definition: FEvent.h:33
void SetPulseStop(const int stop)
Definition: PixelRecData.h:104
Eye-specific shower reconstruction data.
Definition: EyeRecData.h:65
unsigned int GetEyeId() const
Definition: FEvent/Pixel.h:33
double GetReferenceLambda() const
Definition: FDetector.cc:332
const utl::AxialVector & GetSDP() const
Definition: EyeRecData.h:75
unsigned int GetTelescopeId() const
Definition: FEvent/Pixel.h:32
boost::indirect_iterator< InternalPixelIterator, fevt::Pixel & > PixelIterator
Iterator over pixels used in reconstruction.
Definition: EyeRecData.h:113
boost::filter_iterator< ComponentSelector, AllPixelIterator > PixelIterator
selective Pixel iterators
constexpr double kSpeedOfLight
Detector description interface for Telescope-related data.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
Definition: FDetector.cc:150
double GetRp() const
Definition: EyeRecData.h:87
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
Definition: Trace-fwd.h:19
SizeType GetStart() const
Get valid data start bin.
Definition: Trace.h:142
utl::TraceB & GetFLTTrace()
Description of a pixel.
PixelIterator TimeFitPixelsEnd()
Definition: EyeRecData.h:171
Vector object.
Definition: Vector.h:30
Interface class to access to Fluorescence reconstruction of a Shower.
Main configuration utility.
Definition: CentralConfig.h:51
double GetTZero() const
Definition: EyeRecData.h:83
PixelIterator SDPPixelsEnd()
Definition: EyeRecData.h:143
Fluorescence Detector Telescope Event.
double GetCentroid() const
Definition: PixelRecData.h:78
PixelIterator RemovePulsedPixel(PixelIterator it)
remove a pixel from the list of pulsed pixels
Definition: EyeRecData.h:133
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
PixelIterator RemoveSDPPixel(PixelIterator it)
Remove a pixel from the list of SDP pixels.
Definition: EyeRecData.h:161
Fluorescence Detector Pixel Reconstructed Data.
Definition: PixelRecData.h:27
int GetFirstTriggeredTimeBin() const
returns the first triggerd time bin of trace (T1)
Definition: PixelRecData.h:65
unsigned int GetEyeId() const
1..5 (4x normal FD, 1x HEAT)
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
PixelRecData & GetRecData()
Definition: FEvent/Pixel.h:40
Description of a camera.
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.
Definition: FEvent/Eye.cc:130
bool HasTriggerData() const
Definition: FEvent/Pixel.h:48

, generated on Tue Sep 26 2023.