10 #include <fwk/CentralConfig.h>
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>
21 #include <evt/Event.h>
22 #include <evt/ShowerRecData.h>
23 #include <evt/ShowerFRecData.h>
25 #include <fevt/FEvent.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>
35 #include <det/Detector.h>
37 #include <fdet/FDetector.h>
38 #include <fdet/Telescope.h>
39 #include <fdet/Camera.h>
40 #include <fdet/Pixel.h>
56 using namespace FdPulseFinderOG;
66 ERROR(
"Could not find branch FdPulseFinder ");
78 TTree::SetMaxTreeSize(1000*Long64_t(2000000000));
83 " Version: " << GetVersionInfo(VModule::eRevisionNumber) <<
"\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";
90 info <<
" use all pixels: " << fuseAllPixels <<
'\n';
102 INFO(
" searching for pulses ");
107 bool flagPrintout =
false;
109 FEvent& fevent =
event.GetFEvent();
111 eyeiter != fevent.
EyesEnd(ComponentSelector::eHasData); ++eyeiter) {
113 bool firstRun =
true;
114 if (eyeiter->HasRecData()) {
122 INFO(
"Running 2nd time, using reconstructed geometry to find more pulses.");
129 INFO(
"cleaning up pulsed pixel list ");
137 INFO(
"cleaning up sdp pixel list ");
145 INFO(
"cleaning up time fit pixel list ");
152 eyeiter->MakeRecData();
155 teliter != eyeiter->TelescopesEnd(ComponentSelector::eHasData); ++teliter) {
161 fCountNoTrigData = 0;
165 pixiter!= teliter->PixelsEnd(ComponentSelector::eHasData); ++pixiter) {
167 bool pulseSearched =
false;
168 bool pulseFound =
false;
177 pulseFound = FindAdditionalPulse(*pixiter, *eyeiter, eyeRec.
GetFRecShower());
178 pulseSearched =
true;
180 if (event.
HasRecShower() &&
event.GetRecShower().HasFRecShower()) {
182 pulseSearched =
true;
188 const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
191 fOffset =
static_cast<unsigned int>(fOffsetTime / lengthFADCBin);
192 fMinWindowLength =
static_cast<int>(fMinWindowLengthTime / lengthFADCBin);
193 fMaxWindowLength =
static_cast<int>(fMaxWindowLengthTime / lengthFADCBin);
196 pulseFound = FindPulse(*pixiter);
200 EyeRecData& eyerecdata = eyeiter->GetRecData();
208 info <<
"nPix=" << fCountPix
209 <<
" nFLT=" << fCountFlt
210 <<
" nNoRec=" << fCountNoRecData
211 <<
" nNoTrg=" << fCountNoTrigData
212 <<
" nErr=" << fCountBoundsErr
213 <<
" nPulse=" << fCountPulsed;
225 FdPulseFinder::Finish()
256 const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
259 const int pixelId = pixel.
GetId();
260 const int eyeId = detPixel.
GetEyeId();
267 if (fVerbosity > 2) {
269 info <<
" Pixel: " << pixelId <<
" tel: " << telId <<
" eye: " << eyeId <<
" has no rec-data ";
279 if (fVerbosity > 2) {
281 info <<
" Pixel: " << pixelId <<
" tel: " << telId <<
" eye: " << eyeId <<
" has no trigger-data ";
298 cout <<
"\nPixel=" << pixelId <<
" Tel=" << telId <<
" channel=" <<channelId
299 <<
" fltBin=" << firstFLTbin << endl;
302 unsigned int start = 0;
303 unsigned int stop = 0;
305 if (firstFLTbin >= 0) {
309 const double fltBinSize = fltTrace.
GetBinning();
310 const unsigned int fltTraceLength = fltTrace.
GetSize();
313 if (fltTraceLength != trace.
GetSize()) {
315 err <<
" FADC and FLT trace have different sizes! nFADC=" << trace.
GetSize()
316 <<
" and nFLT=" << fltTraceLength <<
". CONNOT HANDLE!";
323 err <<
" FADC and FLT binning differs! bFADC=" << trace.
GetBinning()/
ns
324 <<
" and bFLT=" << fltBinSize/
ns <<
". CONNOT HANDLE!";
330 vector<unsigned int> length;
331 vector<unsigned int> firstSectionBin;
332 vector<unsigned int> lastSectionBin;
334 if (fVerbosity > 0) {
335 cout <<
"FLT-trace: ";
336 for (
unsigned int bin = 0; bin < fltTraceLength; ++bin)
346 unsigned int currLength = 0;
347 bool gotTrigger =
false;
348 for (
unsigned int bin = 0; bin < fltTraceLength; ++bin) {
354 firstSectionBin.push_back(bin);
358 }
else if (gotTrigger) {
360 length.push_back(currLength);
361 lastSectionBin.push_back(bin - 1);
371 length.push_back(currLength);
372 lastSectionBin.push_back(fltTraceLength - 1);
377 double maxSectionCharge = 0;
378 unsigned int noMaxChargeSection = 0;
379 for (
unsigned int section = 0; section < length.size(); ++section) {
381 unsigned int sectionStart = firstSectionBin[section];
382 unsigned int sectionStop = lastSectionBin[section];
386 if (sectionStart < fltBoxcar)
389 sectionStart = sectionStart - fltBoxcar;
391 if (sectionStop + fltBoxcar >= fltTraceLength)
392 sectionStop = fltTraceLength-1;
394 sectionStop = sectionStop + fltBoxcar;
396 const double sectionCharge = TraceAlgorithm::Sum(trace, sectionStart, sectionStop);
399 if (fVerbosity > 0) {
400 cout <<
"Section " << section
401 <<
": " << firstSectionBin[section]
402 <<
" - " << lastSectionBin[section]
403 <<
" -> " << sectionStart
404 <<
" - " << sectionStop
405 <<
", charge: " << sectionCharge << endl;
408 firstSectionBin[section] = sectionStart;
409 lastSectionBin[section] = sectionStop;
411 if (sectionCharge > maxSectionCharge) {
412 maxSectionCharge = sectionCharge;
413 noMaxChargeSection = section;
420 double maxSignal = 0;
421 unsigned int maxSignalBin = 0;
422 if (firstSectionBin.size() > noMaxChargeSection) {
424 for (
unsigned int i = firstSectionBin[noMaxChargeSection];
425 i < lastSectionBin[noMaxChargeSection]; ++i) {
427 if (trace[i] > maxSignal) {
428 maxSignal = trace[i];
439 maxSignalBin = firstFLTbin;
444 if (maxSignalBin < fOffset)
447 start = maxSignalBin-fOffset;
449 if (maxSignalBin + fOffset > trace.
GetStop())
452 stop = maxSignalBin+fOffset;
454 if (fVerbosity > 0) {
455 cout <<
"Selected section " << noMaxChargeSection
456 <<
" and found biggest signal in bin " << maxSignalBin
462 if (!fuseAllPixels) {
465 cout <<
"no FLT -> skipping" << endl;
475 return FindBestSignalOverNoise(pixel, start, stop);
486 const int start,
const int stop)
492 const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
493 const unsigned int eyeId = pixel.
GetEyeId();
515 const double r_01 = exp(-4 *
kPi *
pow(deltaT * F, 2));
517 const int pixelId = pixel.
GetId();
525 if( fVerbosity > 0) {
527 cout <<
"\nPixel " << pixelId <<
" channel=" << channelId
528 <<
" == > searching pulse between: " << start <<
" - " << stop << endl;
530 cout <<
" == > searching pulse between: " << start <<
" - " << stop << endl;
533 unsigned int pulseStart = 0;
534 unsigned int pulseStop = 0;
536 double maxSnRatio = 0;
538 double rmsnoise = pixelrec.
GetRMS();
540 for (
int windowStart = start; windowStart < stop - fMinWindowLength; ++windowStart) {
542 for (
int windowStop = windowStart + fMinWindowLength;
543 windowStop < windowStart + fMaxWindowLength && windowStop <= stop;
546 const double value = TraceAlgorithm::Sum(trace, windowStart, windowStop);
549 const double w =
abs(
double(windowStop - windowStart));
550 const double snratio = value / (
sqrt(w) * rmsnoise);
552 if (snratio > maxSnRatio) {
554 maxSnRatio = snratio;
555 pulseStart = windowStart;
556 pulseStop = windowStop;
564 if (pulseStart <= trace.
GetStart()) {
568 if (pulseStop >= trace.
GetStop()) {
591 pulseStart-1 == trace.
GetStart() || pulseStop + 1 == trace.
GetStop()) {
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;
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;
606 if ((extendStart || (!extendStart && (!stopThr || !stopSnRatio))) &&
607 startThr && startSnRatio)
609 else if ((!extendStart || (extendStart && (!startThr || !startSnRatio))) &&
610 stopThr && stopSnRatio)
616 const double charge = TraceAlgorithm::Sum(trace, pulseStart, pulseStop);
619 const double new_snRatio =
620 charge /
sqrt(
double(pulseStop - pulseStart)) / rmsnoise;
622 if (new_snRatio > fMinSnRatio) {
630 const double centroid = TraceAlgorithm::Centroid(trace, pulseStart, pulseStop);
636 const double rmspe2 =
Sqr(rmsnoise*photon2pe);
638 double centroid_err2 = 0;
639 double peCovariance = r_01;
641 for (
unsigned int i = pulseStart; i <= pulseStop; ++i) {
646 const double trace0 = (trace[i] < rmsnoise) ? 0 : trace[i];
647 const double trace1 = (trace[i+1] < rmsnoise) ? 0 : trace[i+1];
650 const double peVariance = rmspe2 + trace0 * photon2pe * (1 + Vg);
653 const double timeVariance = trace0 ? 1 / (12 * trace0 * photon2pe) : 0;
657 peCovariance = r_01 *
sqrt((rmspe2 + trace0 * photon2pe*(1 + Vg)) * (rmspe2 + trace1 * photon2pe*(1 + Vg)));
659 const double binTime = i + 0.5;
662 (
Sqr(binTime - centroid) * peVariance + 2*(binTime - centroid)*(binTime + 1 - centroid) * peCovariance +
Sqr(trace0*photon2pe)*timeVariance) /
Sqr(charge*photon2pe);
668 const double centroid_err =
sqrt(centroid_err2);
672 if (fVerbosity > 0) {
673 cout <<
"Found Pulse at " << centroid <<
" with charge " << charge
674 <<
" between " << pulseStart <<
" - " << pulseStop << endl;
696 const int pixelId = pixel.
GetId();
700 cout <<
"\n FindAdditionalPulse for Pixel=" << pixelId <<
" Tel=" << telId <<
'\n';
702 const fdet::FDetector& detFD = det::Detector::GetInstance().GetFDetector();
715 const Vector vertical(0,0,1, eyeCS);
724 const Vector horizontal_in_sdp =
Cross(sdp, vertical);
726 const double T0 = eyeRec.
GetTZero();
728 const double Rp = eyeRec.
GetRp();
733 const Vector chi_i_vector = pixelDir - (sdp * pixelDir) * sdp;
735 const double Chi_i =
Angle(horizontal_in_sdp, chi_i_vector);
736 const double alpha = Chi_0 - Chi_i - 90*
deg;
739 const double t = T0 + Rp/
utl::kSpeedOfLight * (tan(alpha) + 1/cos(alpha)) - telTimeOffset;
741 const unsigned int bin = ceil(t / fadcBinning);
744 cout <<
" pixel chi_i=" << Chi_i/deg <<
" alpha=" << alpha/deg
745 <<
" t=" << t <<
" bin=" << bin
746 <<
" telOffset=" << telTimeOffset
749 <<
" chi0=" << Chi_0/deg
750 <<
" recChi_i=" << pixelrec.
GetChi_i()/deg
753 if (t < 0 || bin >= fadcSize) {
755 INFO(
"Shower out of FD-DAQ time-window (for this pixel)!");
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;
770 info <<
" -> Found FLT pixel with pulse at time=" << pulseTime;
774 if (pulseTime > start && pulseTime < stop) {
776 INFO(
"Pixel had already valid pulse. Keeping.");
780 INFO(
"Pulse possibly wrong. Refine search...");
783 if (fVerbosity > 1) {
785 info <<
" -> Search additional pulse in pixel=" << pixelId <<
" within [" << start <<
" - " << stop <<
"]";
789 if (FindBestSignalOverNoise(pixel, start, stop)) {
791 info <<
"New pulse found in pixel=" << pixelId;
797 INFO (
"No pulse found");
Telescope & GetTelescope(const unsigned int telescopeId, const ComponentSelector::Status status=ComponentSelector::eHasData)
Retrieve Telescope by Id, throw exception if not existent.
AxialVector Cross(const Vector &l, const Vector &r)
PixelIterator RemoveTimeFitPixel(PixelIterator it)
Remove a pixel from the list of Time Fit pixels.
const utl::Vector & GetDirection() const
pointing direction of this pixel
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)
ShowerFRecData & GetFRecShower()
double GetRMS() const
Get the baseline RMS of the trace.
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.
SizeType GetStop() const
Get valid data stop bin.
PixelIterator PulsedPixelsEnd()
bool HasRecShower() const
const Pixel & GetPixel(const fevt::Pixel &eventPixel) const
Get fdet::Pixel from fevt::Channel.
double GetChiZero() const
Fluorescence Detector Pixel Trigger Data.
ShowerRecData & GetRecShower()
double GetCutoffFrequency() const
PixelTriggerData & GetTriggerData()
EyeIterator EyesEnd(const ComponentSelector::Status status)
double GetBinning() const
size of one slot
double GetGainVariance() const
#define INFO(message)
Macro for logging informational messages.
void SetPulseFound(bool flag=true)
void SetTotalCharge(const double charge)
void Init()
Initialise the registry.
const Eye & GetEye(const unsigned int eyeId) const
Find eye by numerical Id.
Detector description interface for Eye-related data.
boost::filter_iterator< ComponentSelector, AllEyeIterator > EyeIterator
selective Eye iterators
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
PixelIterator PulsedPixelsBegin()
double pow(const double x, const unsigned int i)
bool PulseIsFound() const
const Camera & GetCamera() const
Get the Camera object that belongs to the telescope.
int GetFLTBoxcarSumLength() const
Detector description interface for FDetector-related data.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
unsigned int GetId() const
Class representing a document branch.
utl::TraceD & GetPhotonTrace(const FdConstants::LightSource source=FdConstants::eTotal)
void AddPulsedPixel(fevt::Pixel &pixel)
add a pixel to the list of pulsed pixels
void SetCentroid(const double centroid, const double err)
PixelIterator SDPPixelsBegin()
Fluorescence Detector Pixel event.
unsigned int GetChannelId() const
utl::CoordinateSystemPtr GetEyeCoordinateSystem() const
Returns the Eye Coordinate system.
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.
evt::ShowerFRecData & GetFRecShower()
Reconstructed shower info for this eye.
EyeIterator EyesBegin(const ComponentSelector::Status status)
boost::filter_iterator< ComponentSelector, AllTelescopeIterator > TelescopeIterator
selective Telescope iterators
unsigned int GetNPulsedPixels() const
Get number of pulsed pixels.
void GetData(bool &b) const
Overloads of the GetData member template function.
Top of Fluorescence Detector event hierarchy.
void SetPulseStop(const int stop)
Eye-specific shower reconstruction data.
unsigned int GetEyeId() const
double GetReferenceLambda() const
const utl::AxialVector & GetSDP() const
unsigned int GetTelescopeId() const
boost::indirect_iterator< InternalPixelIterator, fevt::Pixel & > PixelIterator
Iterator over pixels used in reconstruction.
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.
const Telescope & GetTelescope(const fevt::Telescope &eventTel) const
Get fdet::Telescope from fevt::Telescope.
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
SizeType GetStart() const
Get valid data start bin.
utl::TraceB & GetFLTTrace()
PixelIterator TimeFitPixelsEnd()
Interface class to access to Fluorescence reconstruction of a Shower.
Main configuration utility.
PixelIterator SDPPixelsEnd()
Fluorescence Detector Telescope Event.
double GetCentroid() const
PixelIterator RemovePulsedPixel(PixelIterator it)
remove a pixel from the list of pulsed pixels
PixelIterator TimeFitPixelsBegin()
double GetDiaPhoton2PEFactor(const double wavelength, const std::string &configSignature="") const
#define ERROR(message)
Macro for logging error messages.
PixelIterator RemoveSDPPixel(PixelIterator it)
Remove a pixel from the list of SDP pixels.
Fluorescence Detector Pixel Reconstructed Data.
int GetFirstTriggeredTimeBin() const
returns the first triggerd time bin of trace (T1)
int GetFADCTraceLength() const
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()
fevt::EyeRecData & GetRecData()
Reconstructed data for this eye.
bool HasTriggerData() const