FdApertureLightFinderOG/FdApertureLightFinder.cc
Go to the documentation of this file.
1 
10 #include "FdApertureLightFinder.h"
11 
12 #include <fwk/CentralConfig.h>
13 #include <fwk/CoordinateSystemRegistry.h>
14 
15 #include <utl/Reader.h>
16 #include <utl/ErrorLogger.h>
17 #include <utl/MathConstants.h>
18 #include <utl/Vector.h>
19 #include <utl/PhysicalConstants.h>
20 #include <utl/TabulatedFunctionErrors.h>
21 
22 #include <evt/Event.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/PixelRecData.h>
30 #include <fevt/Pixel.h>
31 #include <fevt/FdComponentSelector.h>
32 
33 #include <det/Detector.h>
34 
35 #include <fdet/FDetector.h>
36 #include <fdet/Eye.h>
37 #include <fdet/Pixel.h>
38 #include <fdet/Channel.h>
39 #include <fdet/Camera.h>
40 #include <fdet/Telescope.h>
41 
42 #include <utl/Vector.h>
43 
44 #include <sstream>
45 #include <iomanip>
46 
47 using namespace FdApertureLightFinderOG;
48 using namespace fwk;
49 using namespace utl;
50 using namespace evt;
51 using namespace fevt;
52 using namespace det;
53 using namespace fdet;
54 using namespace std;
55 
58 
59 
62 
63  Branch topB =
64  CentralConfig::GetInstance()->GetTopBranch("FdApertureLightFinder");
65 
66  if (!topB) {
67  ERROR("Could not find branch FdApertureLightFinder");
68  return eFailure;
69  }
70 
71  topB.GetChild("minZetaAngle").GetData(fminZetaAngle);
72  topB.GetChild("maxZetaAngle").GetData(fmaxZetaAngle);
73  topB.GetChild("stepZetaAngle").GetData(fstepZetaAngle);
74  topB.GetChild("safetyMargin").GetData(fSafetyMargin);
75  topB.GetChild("nEquivMin").GetData(fnEquivMin);
76  topB.GetChild("nProfMax").GetData(fnProfMax);
77 
78  fTStart=0;
79  fTStop =0;
80 
81  return eSuccess;
82 }
83 
84 
87 {
88  if (!event.HasFEvent())
89  return eSuccess;
90 
91  FEvent& fevent = event.GetFEvent();
92 
93  FEvent::EyeIterator eyeiter;
94 
95  int nGoodEyes = 0;
96  for (eyeiter = fevent.EyesBegin(ComponentSelector::eHasData);
97  eyeiter != fevent.EyesEnd(ComponentSelector::eHasData);
98  ++eyeiter){
99 
100  fevt::Eye& eye = *eyeiter;
101 
102  if (!eye.HasRecData()) {
103  INFO("T0 must be taken from EyeRecData, skip this Eye");
104  continue;
105  }
106 
107  if (!eye.GetRecData().HasFRecShower()){
108  INFO("No Geometrical info for this Eye - skip this Eye");
109  continue;
110  }
111 
112  if ( FindLightFlux(eye) )
113  nGoodEyes ++;
114 
115  } // end eyeiter-loop
116 
117  if ( nGoodEyes == 0 )
118  return eContinueLoop;
119  else
120  return eSuccess;
121 
122 }
123 
124 
127 {
128  return eSuccess;
129 }
130 
131 
132 bool
134 {
135 
136  // find first and last hit pixels to find shower start and stop
137  if ( !FindSignalTimeRange(eye) )
138  return false;
139 
140  // rough stepping in 0.5 degree steps
141  double zStep=.5*degree;
142  double zMin=fminZetaAngle;
143  double zMax=fmaxZetaAngle+zStep;
144  double zeta=FindZeta(eye,zMin,zMax,zStep);
145 
146  // restepping around max
147  zMin=zeta-zStep;
148  zMax=zeta+zStep;
149  zStep=fstepZetaAngle;
150  if(zMin<0.1*degree)
151  zMin=0.1*degree;
152  zeta=FindZeta(eye,zMin,zMax,zStep);
153 
154  if (zeta <0){
155  INFO("Zeta search failed - Bailing out for this eye");
156  return false;
157  }
158 
159  // enlarge zeta to collect more light
160  zeta += fSafetyMargin;
161 
162  eye.GetRecData().SetZeta(zeta);
163 
164  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
165  const CoordinateSystemPtr& eyeCS = detFD.GetEye(eye).GetEyeCoordinateSystem();
166  const Point& eyePos = detFD.GetEye(eye).GetPosition();
167  const EyeRecData& eyerecdata = eye.GetRecData();
168  const double T0 = eyerecdata.GetTZero();
169  const double chi0 = eyerecdata.GetChiZero();
170  const double Rp = eyerecdata.GetRp();
171  const Vector axis = eyerecdata.GetFRecShower().GetAxis();
172  const Point core = eyerecdata.GetFRecShower().GetCorePosition();
173  const Vector eyeToCore = core - eyePos;
174 
175 //#warning fixed time binning at aperture !!!
176  const double timeBinSize = 100*ns; // light at aperture binning fixed !!
177 
178  deque <double> fluoTime, fluoFlux, vfluoFlux, vBackground;
179 
180  // loop on time slots
181  for (double time= fTStart;
182  time <= fTStop;
183  time += timeBinSize) {
184 
185  double flux_i=0; //total light flux for that time
186  double fluxVariance_i=0;
187  double backgroundVariance_i=0;
188 
189  // vector from the detector to the light spot at start of that time bin
190  const double chi_1 = chi0 - 2*atan( kSpeedOfLight/Rp *(time - T0) );
191  double l = eyeToCore.GetMag() * sin(chi_1) / sin(chi0 - chi_1);
192  if(l<0)
193  l*=-1;
194  Vector chi_i_vec1 = eyeToCore + l * axis;
195  chi_i_vec1.Normalize();
196 
197  // vector from the detector to the light spot at end of that time bin
198  const double chi_2 = chi0 - 2*atan( kSpeedOfLight/Rp *(time - T0+timeBinSize) );
199  l = eyeToCore.GetMag() * sin(chi_2) / sin(chi0 - chi_2);
200  if(l<0)
201  l*=-1;
202  Vector chi_i_vec2 = eyeToCore + l * axis;
203  chi_i_vec2.Normalize();
204 
205  // vector from the detector to the light spot at mid of that time bin
206  Vector chi_i_vec = chi_i_vec1 + chi_i_vec2;
207  chi_i_vec.Normalize();
208 
209  if (chi_i_vec.GetTheta(eyeCS) > kTelescopeMaxTheta ||
210  chi_i_vec.GetTheta(eyeCS) < kTelescopeMinTheta)
211  continue;
212 
213  unsigned int ntelescopes=0; // keep track if signal is from
214  // one or two telescopes
215 
216  const double referenceLambda = detFD.GetReferenceLambda();
217 
218  // loop on telescopes
220  for (teliter = eye.TelescopesBegin(ComponentSelector::eHasData);
221  teliter != eye.TelescopesEnd(ComponentSelector::eHasData);
222  ++teliter){
223 
224  double telescope_flux_i=0; // light flux seen by this telescope
225  double telescope_variance_i=0;
226  double telescope_bgVariance_i=0;
227 
228  double telescopeTimeOffset = teliter->GetTimeOffset();
229 
230  const fdet::Telescope& detTel = detFD.GetTelescope(*teliter);
231  const double area = detTel.GetDiaphragmArea();
232  const double squaredArea = area*area;
233  const double gainVariance = detTel.GetCamera().GetGainVariance();
234 
235  bool hasSignal = false; // signal present?
236  bool isNearBorder = false; // spot near the border?
237 
239  for (pixiter = teliter->PixelsBegin(ComponentSelector::eHasData);
240  pixiter != teliter->PixelsEnd(ComponentSelector::eHasData);
241  ++pixiter){
242 
243  const fdet::Pixel& detPixel = detFD.GetPixel(*pixiter);
244  const Vector& pixeldir = detPixel.GetDirection();
245  const double photon2Pe = detPixel.GetDiaPhoton2PEFactor(referenceLambda);
246 
247  const double alpha=(Angle(chi_i_vec1, pixeldir) + Angle(chi_i_vec2, pixeldir))/2.;
248 
249  // check the pixel is inside the spot
250  if(alpha < zeta) {
251 
252  hasSignal = true;
253  isNearBorder = IsNearBorder(chi_i_vec, detTel,zeta);
254  // if the spot is near the border, discard this time slot
255  // for this telescope
256  if (isNearBorder) {
257  telescope_flux_i=0;
258  telescope_variance_i=0;
259  telescope_bgVariance_i=0;
260  break;
261  }
262 
263  if (not pixiter->HasRecData())
264  continue;
265 
266  const TraceD& photontrace= pixiter->GetRecData().GetPhotonTrace();
267 
268  int idx = int((time - telescopeTimeOffset)/timeBinSize);
269 
270  if(idx>=(int) photontrace.GetStart()&&
271  idx<=(int) photontrace.GetStop()) {
272 
273  // cosangle correction not included
274  // should be already in the end to end calibration
275  telescope_flux_i += photontrace[idx]/area;
276 
277  const double baseLineVariance =
278  pow(pixiter->GetRecData().GetRMS(),2)/squaredArea;
279 
280  telescope_bgVariance_i += baseLineVariance;
281 
282  if (photontrace[idx]<0)
283  telescope_variance_i += baseLineVariance;
284  else {
285  const double signalVariance =
286  photontrace[idx]/photon2Pe * (1.+gainVariance);
287  telescope_variance_i +=
288  (signalVariance/squaredArea + baseLineVariance);
289  }
290  }
291  } // if angle
292  }// for pixel
293 
294 
295  if (!isNearBorder && hasSignal ){
296  // only if the spot is totally contained add total flux
297  flux_i+= telescope_flux_i;
298  fluxVariance_i+= telescope_variance_i;
299  backgroundVariance_i+= telescope_bgVariance_i;
300  ntelescopes++;
301 
302  } // if isfullycontained
303  } // for telescope
304 
305  if (ntelescopes) {
306  flux_i/=ntelescopes; // average in case signal is from two telescopes
307  fluxVariance_i/=ntelescopes;
308  backgroundVariance_i/=ntelescopes;
309  }
310 
311  // fill deques with fluxes for subsequent combination
312  if (flux_i){
313  fluoTime.push_back(time);
314  fluoFlux.push_back(flux_i);
315  vfluoFlux.push_back(fluxVariance_i);
316  vBackground.push_back(backgroundVariance_i);
317  }
318 
319  } // for time
320 
321 
322  // FdPulseFinder artifically enlarges pulse width
323  // --> pop a few bins at the beginning and end
324  // of light flux until above 2*RMS
325  unsigned int nPopFront=0;
326  for ( unsigned int i=0;i<fluoTime.size();i++) {
327  if(fluoFlux[i]>2.*sqrt(vfluoFlux[i]))
328  break;
329  nPopFront++;
330  }
331  for ( unsigned int i=0;i<nPopFront;i++) {
332  fluoTime.pop_front();
333  fluoFlux.pop_front();
334  vfluoFlux.pop_front();
335  vBackground.pop_front();
336  }
337 
338  unsigned int nPopBack=0;
339  for ( int i=(int) fluoTime.size()-1;i>-1;i--) {
340  if(fluoFlux[i]>2.*sqrt(vfluoFlux[i]))
341  break;
342  nPopBack++;
343  }
344  for ( unsigned int i=0;i<nPopBack;i++) {
345  fluoTime.pop_back();
346  fluoFlux.pop_back();
347  vfluoFlux.pop_back();
348  vBackground.pop_back();
349  }
350 
351  // combine bins and fill them in event structure
352  if(fluoTime.size()<1)
353  return false;
354  else {
355  CombineAndFillFluxes(eye, fluoTime, fluoFlux, vfluoFlux, vBackground);
356  return true;
357  }
358 
359 }
360 
361 
362 //************************************************************************
363 bool
365 {
366 
367  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
368  const EyeRecData& eyerecdata = eye.GetRecData();
369 
370  double minT_i = 1e6;
371  double maxT_i = 0;
372  bool firstTime = true;
373 
375  for (pixiter = eyerecdata.TimeFitPixelsBegin();
376  pixiter != eyerecdata.TimeFitPixelsEnd(); ++pixiter){
377 
378  if (not pixiter->HasRecData())
379  continue;
380 
381  const fdet::Channel& detChannel = detFD.GetChannel(*pixiter);
382  const double timeBinSize = detChannel.GetFADCBinSize();
383 
384  const double timeoffset =
385  eye.GetTelescope(pixiter->GetTelescopeId()).GetTimeOffset();
386  const fevt::PixelRecData & pixelRecData = pixiter->GetRecData();
387  const double t1 = timeBinSize*pixelRecData.GetPulseStart()+timeoffset;
388  const double t2 = timeBinSize*pixelRecData.GetPulseStop()+timeoffset;
389 
390  if (t2 > maxT_i || firstTime)
391  maxT_i = t2;
392  if (t1 < minT_i || firstTime) {
393  minT_i = t1;
394  firstTime=false;
395  }
396 
397  }
398  fTStart = minT_i;
399  fTStop = maxT_i;
400 
401  if (fTStop <= fTStart)
402  return false;
403  else
404  return true;
405 
406 }
407 
408 
409 //************************************************************************
410 void
412  const deque<double>& fluoTime,
413  const deque<double>& fluoFlux,
414  const deque<double>& vfluoFlux,
415  const deque<double>& vBackgroundFlux)
416 {
417 
418 //#warning Fixed 100ns time binning at the aperture
419  const double timeBinSize = 100. * ns; // light at aperture binning fixed !!
420 
421  // make light fluxes in the event if necessary and fill
422  // both total fluorescence light and total light.
423  // During Cherenkov subtraction, fluorescence light will
424  // undergo corrections
425 
428 
431 
434 
435  TabulatedFunctionErrors& fluoLightProfile =
437 
438  TabulatedFunctionErrors& lightProfile =
440 
441  TabulatedFunctionErrors& backgroundProfile =
443 
444  fluoLightProfile.Clear();
445  lightProfile.Clear();
446  backgroundProfile.Clear();
447 
448  // ------------ combine bins with low statistics --------------
449 
450  vector<double> c_fluoTime, c_fluoDTime, c_fluoFlux, c_vfluoFlux, c_vbgFlux;
451  double nBins=0;
452  double t1=fluoTime[0];
453  double sum=0.;
454  double sum2=0.;
455  double bgSum2=0;
456  double lastTime=fluoTime[0];
457 
458  //#warning here
459  //const double timeBinSize = fdet::Channel::GetFADCBinSize();
460 
461  for ( unsigned int i=0;i<fluoTime.size();i++) {
462 
463  if(t1==0.)
464  t1=fluoTime[i];
465 
466  // stop averaging if encounter a hole
467  if(fluoTime[i]-lastTime>timeBinSize) {
468  if(nBins>0.) {
469  double dt = fluoTime[i-1]-t1+timeBinSize;
470  c_fluoTime.push_back(t1);
471  c_fluoDTime.push_back(dt);
472  c_fluoFlux.push_back(sum);
473  c_vfluoFlux.push_back(sum2);
474  c_vbgFlux.push_back(bgSum2);
475  nBins=0.; sum=0.; sum2=0.; bgSum2=0.; t1=0.;
476  }
477  }
478 
479  if(t1==0.)
480  t1=fluoTime[i];
481 
482  nBins++;
483  sum += fluoFlux[i];
484  sum2+= vfluoFlux[i];
485  bgSum2+= vBackgroundFlux[i];
486  lastTime=fluoTime[i];
487  double nEquiv=sum*sum/sum2;
488  if( fnEquivMin<=0 || nEquiv>fnEquivMin || i==fluoTime.size()-1 ) {
489  double dt = fluoTime[i]-t1+timeBinSize;
490  c_fluoTime.push_back(t1);
491  c_fluoDTime.push_back(dt);
492  c_fluoFlux.push_back(sum);
493  c_vfluoFlux.push_back(sum2);
494  c_vbgFlux.push_back(bgSum2);
495  nBins=0.; sum=0.; sum2=0.; bgSum2=0.; t1=0.;
496  }
497  }
498 
499  // ------------ combine bins if above fnProfMax --------------
500  if(c_fluoTime.size()>(unsigned int) fnProfMax) {
501 
502  double nCombi=(double) c_fluoTime.size()/ (double) fnProfMax;
503  double combined=0.;
504 
505  t1=c_fluoTime[0];
506  sum=0.;
507  sum2=0.;
508  bgSum2=0;
509  lastTime=t1;
510 
511  for (unsigned int i=0;i<c_fluoTime.size();i++) {
512 
513  if(t1==0.)
514  t1=c_fluoTime[i];
515 
516  // stop averaging if encounter a hole
517  if(sum>0.&&c_fluoTime[i]-lastTime>c_fluoDTime[i-1]) {
518  double dt = c_fluoTime[i-1]-t1+c_fluoDTime[i-1];
519  lightProfile.PushBack (t1+dt/2.,dt/2.,sum,sqrt(sum2));
520  fluoLightProfile.PushBack (t1+dt/2.,dt/2.,sum,sqrt(sum2));
521  backgroundProfile.PushBack(t1+dt/2.,dt/2., 0.,sqrt(bgSum2));
522  sum=0.; sum2=0.; t1=0.; bgSum2=0.; combined=0;
523  }
524 
525  combined+=1.;
526  sum += c_fluoFlux[i];
527  sum2+= c_vfluoFlux[i];
528  bgSum2+= c_vbgFlux[i];
529  lastTime=c_fluoTime[i];
530 
531  if(t1==0.)
532  t1=c_fluoTime[i];
533  if(combined>=nCombi||i==c_fluoTime.size()-1) {
534  double dt = c_fluoTime[i]-t1+c_fluoDTime[i];
535  lightProfile.PushBack (t1+dt/2.,dt/2.,sum,sqrt(sum2));
536  fluoLightProfile.PushBack (t1+dt/2.,dt/2.,sum,sqrt(sum2));
537  backgroundProfile.PushBack(t1+dt/2.,dt/2., 0.,sqrt(bgSum2));
538  sum=0.; sum2=0.; t1=0.; bgSum2=0.; combined=0;
539  }
540  }
541  }
542  else {
543  for (unsigned int i=0;i<c_fluoTime.size();i++) {
544  sum = c_fluoFlux[i];
545  sum2 = c_vfluoFlux[i];
546  bgSum2 = c_vbgFlux[i];
547  double dt = c_fluoDTime[i];
548  lightProfile.PushBack (c_fluoTime[i]+dt/2.,dt/2.,sum,sqrt(sum2));
549  fluoLightProfile.PushBack (c_fluoTime[i]+dt/2.,dt/2.,sum,sqrt(sum2));
550  backgroundProfile.PushBack(c_fluoTime[i]+dt/2.,dt/2., 0.,sqrt(bgSum2));
551  }
552  }
553 }
554 
555 
556 bool
558  const fdet::Telescope& telescope,
559  double zeta)
560  const
561 {
562 
564  telescope.OutOfBorderPixelsBegin();
565  iter!= telescope.OutOfBorderPixelsEnd();
566  ++iter){
567 
568  if (Angle(direction,*iter) < zeta)
569  return true;
570  }
571 
572  return false;
573 
574 }
575 
576 unsigned int
578  const
579 {
580 
581  unsigned int maxoffset = 0;
582 
583  for ( fevt::Eye::ConstTelescopeIterator teliter =
584  eye.TelescopesBegin(ComponentSelector::eHasData);
585  teliter != eye.TelescopesEnd(ComponentSelector::eHasData);
586  ++teliter) {
587 
588  const unsigned int tmp = teliter->GetTimeOffset();
589 
590  if (tmp > maxoffset)
591  maxoffset = tmp;
592 
593  }
594 
595  return maxoffset;
596 }
597 
598 
599 // New (faster) version of FindZeta by M. Unger
600 double
601 FdApertureLightFinder::FindZeta(const fevt::Eye& eye, double initZeta,
602  double finZeta, double stepZeta)
603  const
604 {
605 
606  ostringstream info;
607  info << "Eye: " << eye.GetId() << '\n';
608 
609  const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
610  const CoordinateSystemPtr& eyeCS = detFD.GetEye(eye).GetEyeCoordinateSystem();
611  const Point& eyePos = detFD.GetEye(eye).GetPosition();
612 
613  const EyeRecData& eyerecdata = eye.GetRecData();
614  const double T0 = eyerecdata.GetTZero();
615  const double chi0 = eyerecdata.GetChiZero();
616  const double Rp = eyerecdata.GetRp();
617  const Vector axis = eyerecdata.GetFRecShower().GetAxis();
618  const Point core = eyerecdata.GetFRecShower().GetCorePosition();
619  const Vector eyeToCore = core - eyePos;
620 
621 //#warning fixed time binning at aperture !!!
622  const double timeBinSize = 100.*ns;
623 
624  double maxSN = 0;
625  double bestZeta = initZeta;
626 
627  // M.U. : precalculate components of chi_i array for nested loop
628 
629  const int nTimes=(int) ((fTStop-fTStart)/timeBinSize)+1;
630  // create vectors to hold component
631  double * chi_i_vecX = new double[nTimes];
632  double * chi_i_vecY = new double[nTimes];
633  double * chi_i_vecZ = new double[nTimes];
634 
635  const double distEyeToCore = eyeToCore.GetMag();
636  double time;
637  int iTime=0;
638  for (time= fTStart;
639  time <= fTStop;
640  time+= timeBinSize) { // loop over time bins
641 
642  const double chi_i = chi0-2.* atan( kSpeedOfLight/Rp * (time - T0) );
643  double l = distEyeToCore * sin(chi_i) / sin(chi0 - chi_i);
644  if(l<0)
645  l*=-1;
646  Vector chi_i_vec = eyeToCore + l * axis;
647  chi_i_vec.Normalize();
648 
649  if (chi_i_vec.GetTheta(eyeCS) > kTelescopeMaxTheta ||
650  chi_i_vec.GetTheta(eyeCS) < kTelescopeMinTheta) {
651 
652  chi_i_vecX[iTime] = 9999; // flag that outside telescope
653  chi_i_vecY[iTime] = 9999; // flag that outside telescope
654  chi_i_vecZ[iTime] = 9999; // flag that outside telescope
655 
656  } else {
657 
658  chi_i_vecX[iTime] = chi_i_vec.GetX(eyeCS);
659  chi_i_vecY[iTime] = chi_i_vec.GetY(eyeCS);
660  chi_i_vecZ[iTime] = chi_i_vec.GetZ(eyeCS);
661 
662  }
663 
664  iTime++;
665  }
666 
667  // loop on zeta
668 
669  for (double zeta = initZeta;
670  zeta <= finZeta;
671  zeta+=stepZeta) {
672 
673  double signalOverNoise=0;
674  double signalSum =0;
675  double varianceSum =0;
676 
677  // M.U. : optimize speed by changing loop order
678 
679  double charge_i=0.,noise2_i=0;
680 
681  const double referenceLambda = detFD.GetReferenceLambda();
682 
683  for ( fevt::Eye::ConstTelescopeIterator teliter =
684  eye.TelescopesBegin(ComponentSelector::eHasData);
685  teliter != eye.TelescopesEnd(ComponentSelector::eHasData);
686  ++teliter){
687 
688  const unsigned int telescopeTimeOffset = teliter->GetTimeOffset();
689 
690  const fdet::Telescope& detTel = detFD.GetTelescope(*teliter);
691  const double gainVariance = detTel.GetCamera().GetGainVariance();
692 
694  teliter->PixelsBegin(ComponentSelector::eHasData);
695  pixiter != teliter->PixelsEnd(ComponentSelector::eHasData);
696  ++pixiter) {
697 
698  const fdet::Pixel& detPixel = detFD.GetPixel(*pixiter);
699  const Vector& pixeldir = detPixel.GetDirection();
700  const double photon2Pe = detPixel.GetDiaPhoton2PEFactor(referenceLambda);
701 
702  const double pixelX = pixeldir.GetX(eyeCS);
703  const double pixelY = pixeldir.GetY(eyeCS);
704  const double pixelZ = pixeldir.GetZ(eyeCS);
705 
706  if (!pixiter->HasRecData())
707  continue;
708 
709  const TraceD& photontrace = pixiter->GetRecData().GetPhotonTrace();
710  const double baseLineVariance = pow(pixiter->GetRecData().GetRMS(),2);
711 
712 
713  int iTime=0;
714  for (time= fTStart; // loop on time bin
715  time <= fTStop;
716  time+= timeBinSize) {
717 
718  if(*(chi_i_vecX+iTime)<100) { // inside telescope
719 
720  const double angle = acos(*(chi_i_vecX+iTime)*pixelX+
721  *(chi_i_vecY+iTime)*pixelY+
722  *(chi_i_vecZ+iTime)*pixelZ);
723 
724 
725  if (angle<zeta) {
726  const int idx = int((time - telescopeTimeOffset)/timeBinSize);
727 
728  if( idx>=(int) photontrace.GetStart()&&
729  idx<=(int) photontrace.GetStop()) {
730 
731  charge_i = photontrace[idx];
732  if ( charge_i < 0 )
733  noise2_i = baseLineVariance;
734  else {
735  const double signalVariance =
736  charge_i / photon2Pe * (1.+gainVariance);
737  noise2_i = baseLineVariance + signalVariance;
738  }
739 
740  signalSum += charge_i;
741  varianceSum += noise2_i;
742  }
743 
744  } //if zeta
745  } // if telescope
746  iTime++;
747 
748  }// for time
749  } // for pixel
750  } // for telescope
751 
752 
753  if (varianceSum)
754  signalOverNoise = signalSum / sqrt(varianceSum);
755 
756  info << " "
757  << " zeta [deg] " << setw(5) << zeta/degree
758  << ", S/N " << setw(10) << signalOverNoise
759  << ", S " << setw(9) << signalSum << '\n';
760 
761  if (signalOverNoise > maxSN) {
762  maxSN = signalOverNoise;
763  bestZeta = zeta;
764  }
765  } // for zeta
766 
767  delete [] chi_i_vecX;
768  delete [] chi_i_vecY;
769  delete [] chi_i_vecZ;
770 
771  if (maxSN < 1)
772  bestZeta = -9999*degree;
773  info << " Best Zeta " << bestZeta/degree;
774  INFO(info);
775 
776  return bestZeta;
777 }
778 
779 
780 // Configure (x)emacs for this file ...
781 // Local Variables:
782 // mode:c++
783 // compile-command: "make -C .. -k"
784 // 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
Branch GetTopBranch() const
Definition: Branch.cc:63
unsigned int GetId() const
Definition: FEvent/Eye.h:54
const utl::Vector & GetDirection() const
pointing direction of this pixel
void CombineAndFillFluxes(fevt::Eye &eye, const std::deque< double > &fluoTime, const std::deque< double > &fluoFlux, const std::deque< double > &vfluoFlux, const std::deque< double > &vBackground)
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
int GetPulseStop() const
pulse stop (to be defined)
Definition: PixelRecData.h:72
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.
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
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
double FindZeta(const fevt::Eye &eye, double initZeta, double finZeta, double stepZeta) const
double GetChiZero() const
Definition: EyeRecData.h:85
int GetPulseStart() const
pulse start (to be defined)
Definition: PixelRecData.h:70
EyeIterator EyesEnd(const ComponentSelector::Status status)
Definition: FEvent.h:66
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
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
double pow(const double x, const unsigned int i)
unsigned int GetMaxOffset(const fevt::Eye &eye) const
Get the maximum time offset of the telescopes in the event.
double GetMag() const
Definition: Vector.h:58
const Camera & GetCamera() const
Get the Camera object that belongs to the telescope.
Detector description interface for FDetector-related data.
Definition: FDetector.h:44
void SetZeta(const double zeta)
Definition: EyeRecData.h:216
boost::indirect_iterator< ConstInternalPixelIterator, const Pixel & > ConstPixelIterator
Const iterator over pixels used in reconstruction.
Definition: EyeRecData.h:117
OutOfBorderPixelsIterator OutOfBorderPixelsEnd() const
End of pixels out of the border.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Definition: Branch.h:107
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
const double ns
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
TelescopeIterator TelescopesEnd()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:230
fwk::VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
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
boost::filter_iterator< ComponentSelector, ConstAllPixelIterator > ConstPixelIterator
constexpr double degree
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
Definition: FEvent/Eye.h:72
std::vector< utl::Vector >::const_iterator OutOfBorderPixelsIterator
void PushBack(const double x, const double xErr, const double y, const double yErr)
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
a second level trigger
Definition: XbT2.h:8
Eye-specific shower reconstruction data.
Definition: EyeRecData.h:65
TelescopeIterator TelescopesBegin()
first available tel of status eHasData (DEPRECATED)
Definition: FEvent/Eye.cc:207
double GetReferenceLambda() const
Definition: FDetector.cc:332
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
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 GetFADCBinSize() const
double GetDiaphragmArea() const
double GetRp() const
Definition: EyeRecData.h:87
SizeType GetStart() const
Get valid data start bin.
Definition: Trace.h:142
fwk::VModule::ResultFlag Run(evt::Event &event)
Run: invoked once per event.
Description of a pixel.
PixelIterator TimeFitPixelsEnd()
Definition: EyeRecData.h:171
Vector object.
Definition: Vector.h:30
OutOfBorderPixelsIterator OutOfBorderPixelsBegin() const
Begin of pixels out of the border.
double GetTZero() const
Definition: EyeRecData.h:83
fwk::VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of 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
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
bool IsNearBorder(const utl::Vector &direction, const fdet::Telescope &telescope, double zeta) const
const utl::Point & GetCorePosition() const
Shower core as reconstructed by the FD or FD eye.
Fluorescence Detector Pixel Reconstructed Data.
Definition: PixelRecData.h:27
boost::filter_iterator< ComponentSelector, ConstAllTelescopeIterator > ConstTelescopeIterator
Definition: FEvent/Eye.h:73
utl::Point GetPosition() const
Eye position.
void MakeLightFlux(const FdConstants::LightSource source=FdConstants::eTotal)
Definition: EyeRecData.h:293
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.