Belle II Software development
PDFConstructor Class Reference

PDF construction and log likelihood determination for a given track and particle hypothesis. More...

#include <PDFConstructor.h>

Classes

struct  InverseRaytracerDirect
 Structure that enables defining a template function: direct photons. More...
 
struct  InverseRaytracerReflected
 Structure that enables defining a template function: reflected photons. More...
 
struct  LogL
 Useful data type for returning the results of log likelihood calculation. More...
 
struct  PrismSolution
 Solution of inverse raytracing in prism. More...
 
struct  Pull
 Data type for storing photon pull w.r.t PDF peak. More...
 

Public Types

enum  EPDFOption {
  c_Rough = 0 ,
  c_Fine = 1 ,
  c_Optimal = 2
}
 Signal PDF construction options. More...
 
enum  EStoreOption {
  c_Reduced = 0 ,
  c_Full = 1
}
 Options for storing signal PDF parameters. More...
 

Public Member Functions

 PDFConstructor (const TOPTrack &track, const Const::ChargedStable &hypothesis, EPDFOption PDFOption=c_Optimal, EStoreOption storeOption=c_Reduced, double overrideMass=0)
 Class constructor.
 
bool isValid () const
 Checks the object status.
 
void switchOffDeltaRayPDF () const
 Exclude delta-ray PDF in log likelihood calculation.
 
void switchOnDeltaRayPDF () const
 Include delta-ray PDF in log likelihood calculation (this is default)
 
void switchDeltaRayPDF (bool deltaPDFOn) const
 Include or exclude delta-ray PDF in log likelihood calculation.
 
int getModuleID () const
 Returns slot ID.
 
const Const::ChargedStable & getHypothesis () const
 Returns particle hypothesis.
 
const std::vector< TOPTrack::SelectedHit > & getSelectedHits () const
 Returns selected photon hits belonging to this slot.
 
double getBkgRate () const
 Returns estimated background hit rate.
 
double getCosTotal () const
 Returns cosine of total reflection angle.
 
double getCosCerenkovAngle (double E) const
 Returns cosine of Cerenkov angle at given photon energy.
 
const std::vector< SignalPDF > & getSignalPDF () const
 Returns signal PDF.
 
const BackgroundPDF * getBackgroundPDF () const
 Returns background PDF.
 
const DeltaRayPDF & getDeltaRayPDF () const
 Returns delta-ray PDF.
 
double getExpectedSignalPhotons () const
 Returns the expected number of signal photons within the default time window.
 
double getExpectedDeltaPhotons () const
 Returns the expected number of delta-ray photons within the default time window.
 
double getExpectedBkgPhotons () const
 Returns the expected number of background photons within the default time window.
 
double getExpectedPhotons () const
 Returns the expected number of all photons within the default time window.
 
double getExpectedSignalPhotons (double minTime, double maxTime) const
 Returns the expected number of signal photons within a given time window.
 
double getExpectedDeltaPhotons (double minTime, double maxTime) const
 Returns the expected number of delta-ray photons within a given time window.
 
double getExpectedBkgPhotons (double minTime, double maxTime) const
 Returns the expected number of background photons within a given time window.
 
double getExpectedPhotons (double minTime, double maxTime) const
 Returns the expected number of all photons within a given time window.
 
double getPDFValue (int pixelID, double time, double timeErr, double sigt=0) const
 Returns PDF value.
 
LogL getLogL () const
 Returns extended log likelihood (using the default time window)
 
LogL getLogL (double t0, double sigt=0) const
 Returns extended log likelihood for PDF shifted in time.
 
LogL getLogL (double t0, double minTime, double maxTime, double sigt=0) const
 Returns extended log likelihood for PDF shifted in time and using different time window.
 
LogL getBackgroundLogL () const
 Returns extended log likelihood for background hypothesis using default time window.
 
LogL getBackgroundLogL (double minTime, double maxTime) const
 Returns extended log likelihood for background hypothesis.
 
const std::vector< LogL > & getPixelLogLs (double t0, double sigt=0) const
 Returns extended log likelihoods in pixels for PDF shifted in time.
 
const std::vector< LogL > & getPixelLogLs (double t0, double minTime, double maxTime, double sigt=0) const
 Returns extended log likelihoods in pixels for PDF shifted in time and using different time window.
 
const std::vector< Pull > & getPulls () const
 Returns photon pulls w.r.t PDF peaks.
 
int getNCalls_setPDF (SignalPDF::EPeakType type) const
 Returns number of calls of template function setSignalPDF<T> for a given peak type.
 
int getNCalls_expandPDF (SignalPDF::EPeakType type) const
 Returns number of calls of function expandSignalPDF for a given peak type.
 
const std::map< double, YScanner::Derivatives > & getDerivatives () const
 Returns a collection of derivatives for debugging purposes.
 
void appendPDFOther (const PDFConstructor *pdfOther)
 Append most probable PDF of other track in this module.
 
void clearPDFOther ()
 Clear the container of PDF's of other tracks.
 

Private Member Functions

template<class T>
void setSignalPDF (T &t, unsigned col, double xD, double zD, int Nxm=0, double xmMin=0, double xmMax=0)
 Template function: sets signal PDF in a pixel column and for specific reflection in x.
 
const InverseRaytracer::CerenkovAngle & cerenkovAngle (double dE=0)
 Returns cosine and sine of cerenkov angle.
 
void setSignalPDF ()
 Sets signal PDF.
 
void setSignalPDF_direct ()
 Sets signal PDF for direct photons.
 
void setSignalPDF_reflected ()
 Sets signal PDF for reflected photons.
 
void setSignalPDF_prism ()
 Sets signal PDF for track crossing prism.
 
void setSignalPDF_reflected (int Nxm, double xmMin, double xmMax)
 Sets signal PDF for reflected photons at given reflection number.
 
bool detectionPositionX (double xM, int Nxm, std::vector< double > &xDs, double &minLen)
 Calculates unfolded detection position from known reflection position on the mirror and emission point.
 
bool doRaytracingCorrections (const InverseRaytracer::Solution &sol, double dFic_dx, double xD)
 Corrects the solution of inverse ray-tracing with fast ray-tracing.
 
double deltaXD (double dFic, const InverseRaytracer::Solution &sol, double xD)
 Returns the difference in xD between ray-traced solution rotated by dFic and input argument.
 
bool setDerivatives (YScanner::Derivatives &D, double dL, double de, double dFic)
 Sets the derivatives (numerically) using forward ray-tracing.
 
bool raytrace (const FastRaytracer &rayTracer, double dL=0, double de=0, double dFic=0)
 Forward ray-tracing (called by setDerivatives)
 
double propagationLosses (double E, double propLen, int nx, int ny, SignalPDF::EPeakType type) const
 Returns photon propagation losses (bulk absorption, surface reflectivity, mirror reflectivity)
 
void expandSignalPDF (unsigned col, const YScanner::Derivatives &D, SignalPDF::EPeakType type)
 Expands signal PDF in y (y-scan)
 
bool rangeOfX (double z, double &xmi, double &xma)
 Estimates range of unfolded x coordinate of the hits on given plane perpendicular to z-axis.
 
bool prismRaytrace (const PrismSolution &sol, double dL=0, double dFic=0, double de=0)
 Do forward raytracing of inverse raytracing solution in prism.
 
PrismSolution prismSolution (const PixelPositions::PixelData &pixel, unsigned k, int nx)
 General solution of inverse raytracing in prism: iterative procedure calling basic solution.
 
PrismSolution prismSolution (const ROOT::Math::XYZPoint &rD, double L)
 Basic solution of inverse raytracing in prism: assuming straight line particle trajectory.
 
double pdfValueSignal (int pixelID, double time, double timeErr, double sigt=0) const
 Returns the value of signal PDF normalized to the number of expected photons.
 
double pdfValueSignalDelta (int pixelID, double time, double timeErr, double sigt=0) const
 Returns the value of signal + deltaRay PDF normalized to the number of expected photons.
 
double pdfValue (int pixelID, double time, double timeErr, double sigt=0) const
 Returns the value of PDF normalized to the number of expected photons.
 
void initializePixelLogLs (double minTime, double maxTime) const
 Initializes pixel log likelihoods.
 
void appendPulls (const TOPTrack::SelectedHit &hit) const
 Appends pulls of a photon hit.
 

Static Private Member Functions

static double findReflectionExtreme (double xE, double zE, double zD, int Nxm, double A, const RaytracerBase::Mirror &mirror)
 Finds the position on the mirror of the extreme reflection.
 
static double derivativeOfReflectedX (double x, double xe, double ze, double zd)
 Returns the derivative of reflected position at given x.
 

Private Attributes

int m_moduleID = 0
 slot ID
 
const TOPTrack & m_track
 temporary reference to track at TOP
 
const Const::ChargedStable m_hypothesis
 particle hypothesis
 
const InverseRaytracer * m_inverseRaytracer = 0
 inverse ray-tracer
 
const FastRaytracer * m_fastRaytracer = 0
 fast ray-tracer
 
std::vector< FastRaytracer > m_rayTracers
 copies of fast ray-tracer used to compute derivatives
 
const YScanner * m_yScanner = 0
 PDF expander in y.
 
const BackgroundPDF * m_backgroundPDF = 0
 background PDF
 
DeltaRayPDF m_deltaRayPDF
 delta-ray PDF
 
EPDFOption m_PDFOption = c_Optimal
 signal PDF construction option
 
EStoreOption m_storeOption = c_Reduced
 signal PDF storing option
 
bool m_valid = false
 cross-check flag, true if track is valid and all the pointers above are valid
 
double m_beta = 0
 particle hypothesis beta
 
double m_tof = 0
 time-of-flight from IP to average photon emission position
 
double m_groupIndex = 0
 group refractive index at mean photon energy
 
double m_groupIndexDerivative = 0
 derivative (dn_g/dE) of group refractive index at mean photon energy
 
double m_cosTotal = 0
 cosine of total reflection angle
 
double m_minTime = 0
 time window lower edge
 
double m_maxTime = 0
 time window upper edge
 
std::vector< TOPTrack::SelectedHit > m_selectedHits
 selected photon hits
 
double m_bkgRate = 0
 estimated background hit rate
 
std::vector< SignalPDF > m_signalPDFs
 parameterized signal PDF in pixels (index = pixelID - 1)
 
double m_signalPhotons = 0
 expected number of signal photons
 
bool m_hasPeaks = false
 true if at least one pixel has a PDF peak
 
double m_sumOfPeaks = 0
 sum over the pixels of the normalized number of photons in all peaks
 
double m_minPeakT0 = 0
 position of the earliest PDF peak of all pixels [ns]
 
double m_maxPeakT0 = 0
 position of the latest PDF peak of all pixels [ns]
 
double m_bkgPhotons = 0
 expected number of uniform background photons
 
double m_deltaPhotons = 0
 expected number of delta-ray photons
 
std::map< double, InverseRaytracer::CerenkovAngle > m_cerenkovAngles
 sine and cosine of Cerenkov angles for dE != 0
 
InverseRaytracer::CerenkovAngle m_cerenkovAngle0
 sine and cosine of Cerenkov angle at dE = 0
 
double m_dFic = 0
 temporary storage for dFic used in last call to deltaXD
 
double m_Fic = 0
 temporary storage for Cerenkov azimuthal angle
 
int m_ncallsSetPDF [3] = {0, 0, 0}
 number of calls to setSignalPDF<T>, indexed with SignalPDF::EPeakType
 
int m_ncallsExpandPDF [3] = {0, 0, 0}
 number of calls to expandSignalPDF, indexed with SignalPDF::EPeakType
 
std::vector< LogL > m_pixelLLs
 pixel log likelihoods (index = pixelID - 1)
 
std::vector< Pull > m_pulls
 photon pulls w.r.t PDF peaks
 
bool m_deltaPDFOn = true
 include/exclude delta-ray PDF in likelihood calculation
 
std::map< double, YScanner::Derivatives > m_derivatives
 a map of xD and derivatives
 
std::set< int > m_zeroPixels
 collection of pixelID's with zero pdfValue
 
std::vector< const PDFConstructor * > m_pdfOtherTracks
 most probable PDF's of other tracks in the module
 
double m_f0 = 0
 temporary value of signal PDF
 

Detailed Description

PDF construction and log likelihood determination for a given track and particle hypothesis.

Definition at line 34 of file PDFConstructor.h.

Member Enumeration Documentation

◆ EPDFOption

enum EPDFOption

Signal PDF construction options.

Enumerator
c_Rough 

no dependence on y

c_Fine 

y dependent everywhere

c_Optimal 

y dependent only where necessary

Definition at line 41 of file PDFConstructor.h.

41 {
42 c_Rough = 0,
43 c_Fine = 1,
44 c_Optimal = 2
45 };

◆ EStoreOption

Options for storing signal PDF parameters.

Enumerator
c_Reduced 

only PDF peak data

c_Full 

also extra information and derivatives

Definition at line 50 of file PDFConstructor.h.

50 {
51 c_Reduced = 0,
52 c_Full = 1
53 };
@ c_Full
Full geometry converted from Geant4 (use this for non-standard Belle II setups!).
Definition EveGeometry.h:26

Constructor & Destructor Documentation

◆ PDFConstructor()

PDFConstructor ( const TOPTrack & track,
const Const::ChargedStable & hypothesis,
EPDFOption PDFOption = c_Optimal,
EStoreOption storeOption = c_Reduced,
double overrideMass = 0 )

Class constructor.

Parameters
tracktrack at TOP
hypothesisparticle hypothesis
PDFOptionsignal PDF construction option
storeOptionsignal PDF store option
overrideMassalternative mass value to be used intestead of the one from hypothesis. Ignored if <= 0.

Definition at line 27 of file PDFConstructor.cc.

28 :
29 m_moduleID(track.getModuleID()), m_track(track), m_hypothesis(hypothesis),
30 m_inverseRaytracer(TOPRecoManager::getInverseRaytracer(m_moduleID)),
31 m_fastRaytracer(TOPRecoManager::getFastRaytracer(m_moduleID)),
32 m_yScanner(TOPRecoManager::getYScanner(m_moduleID)),
33 m_backgroundPDF(TOPRecoManager::getBackgroundPDF(m_moduleID)),
34 m_deltaRayPDF(m_moduleID),
35 m_PDFOption(PDFOption), m_storeOption(storeOption)
36 {
37 if (not track.isValid()) {
38 B2ERROR("TOP::PDFConstructor: TOPTrack is not valid, cannot continue");
39 return;
40 }
41
42 m_valid = m_inverseRaytracer != 0 and m_fastRaytracer != 0 and m_yScanner != 0 and m_backgroundPDF != 0;
43 if (not m_valid) {
44 B2ERROR("TOP::PDFConstructor: missing reconstruction objects, cannot continue");
45 return;
46 }
47
48 m_beta = track.getBeta(hypothesis, overrideMass);
49 m_yScanner->prepare(track.getMomentumMag(), m_beta, track.getLengthInQuartz());
50 m_tof = track.getTOF(hypothesis, 0, overrideMass);
51
52 m_groupIndex = TOPGeometryPar::getGroupIndex(m_yScanner->getMeanEnergy());
53 m_groupIndexDerivative = TOPGeometryPar::getGroupIndexDerivative(m_yScanner->getMeanEnergy());
54 m_cosTotal = m_yScanner->getCosTotal();
55 m_minTime = TOPRecoManager::getMinTime();
56 m_maxTime = TOPRecoManager::getMaxTime();
57 m_selectedHits = track.getSelectedHits();
58 m_bkgRate = track.getBkgRate();
59
60 // prepare the memory for storing signal PDF
61
62 const auto& pixelPositions = m_yScanner->getPixelPositions();
63 int numPixels = pixelPositions.getNumPixels();
64 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
65 m_signalPDFs.reserve(numPixels);
66 const TOPNominalTTS* tts = nullptr; // the pixels of a module usually share the PMT type
67 unsigned lastPmtType = 0;
68 for (int pixelID = 1; pixelID <= numPixels; pixelID++) {
69 auto pmtType = pixelPositions.get(pixelID).pmtType;
70 if (not tts or pmtType != lastPmtType) {
71 tts = &geo->getTTS(pmtType);
72 lastPmtType = pmtType;
73 }
74 m_signalPDFs.push_back(SignalPDF(pixelID, *tts));
75 }
76
77 // construct PDF
78
79 if (m_yScanner->isAboveThreshold()) {
80 setSignalPDF();
81 }
82
83 // the sum and the time span of the PDF peaks, used to shortcut getExpectedSignalPhotons
84
85 for (const auto& signalPDF : m_signalPDFs) {
86 m_sumOfPeaks += signalPDF.getSum(); // equals getIntegral over a window containing all the peaks
87 if (signalPDF.getPDFPeaks().empty()) continue;
88 if (m_hasPeaks) {
89 m_minPeakT0 = std::min(m_minPeakT0, signalPDF.getMinT0());
90 m_maxPeakT0 = std::max(m_maxPeakT0, signalPDF.getMaxT0());
91 } else {
92 m_minPeakT0 = signalPDF.getMinT0();
93 m_maxPeakT0 = signalPDF.getMaxT0();
94 m_hasPeaks = true;
95 }
96 }
97
98 m_deltaRayPDF.prepare(track, hypothesis);
99 m_deltaPhotons = m_deltaRayPDF.getNumPhotons();
100
101 m_bkgPhotons = std::max(m_bkgRate * (m_maxTime - m_minTime), 0.1);
102
103 // release the memory not needed anymore
104
105 m_rayTracers.clear();
106 }

Member Function Documentation

◆ appendPDFOther()

void appendPDFOther ( const PDFConstructor * pdfOther)
inline

Append most probable PDF of other track in this module.

Parameters
pdfOtherPDF of other track

Definition at line 387 of file PDFConstructor.h.

388 {
389 if (not pdfOther) return;
390 m_pdfOtherTracks.push_back(pdfOther);
391 }

◆ appendPulls()

void appendPulls ( const TOPTrack::SelectedHit & hit) const
private

Appends pulls of a photon hit.

Parameters
hitphoton hit

Definition at line 1009 of file PDFConstructor.cc.

1010 {
1011 unsigned k = hit.pixelID - 1;
1012 if (k >= m_signalPDFs.size()) return;
1013 const auto& signalPDF = m_signalPDFs[k];
1014
1015 double sfot = m_signalPhotons + m_deltaPhotons + m_bkgPhotons;
1016 double signalFract = m_signalPhotons / sfot;
1017 double wid0 = hit.timeErr * hit.timeErr;
1018 double minT0 = m_maxTime;
1019 double sum = 0;
1020 auto i0 = m_pulls.size();
1021 for (const auto& peak : signalPDF.getPDFPeaks()) {
1022 minT0 = std::min(minT0, peak.t0);
1023 for (const auto& gaus : signalPDF.getTTS()->getTTS()) {
1024 double sig2 = peak.wid + gaus.sigma * gaus.sigma + wid0; // sigma squared!
1025 double x = pow(hit.time - peak.t0 - gaus.position, 2) / sig2;
1026 if (x > 100) continue;
1027 double wt = signalFract * peak.nph * gaus.fraction / sqrt(2 * M_PI * sig2) * exp(-x / 2);
1028 sum += wt;
1029 m_pulls.push_back(Pull(hit.pixelID, hit.time, peak.t0, gaus.position, sqrt(sig2), peak.fic - M_PI, wt));
1030 }
1031 }
1032
1033 double bg = (m_deltaPhotons * m_deltaRayPDF.getPDFValue(hit.pixelID, hit.time) +
1034 m_bkgPhotons * m_backgroundPDF->getPDFValue(hit.pixelID)) / sfot;
1035 sum += bg;
1036 m_pulls.push_back(Pull(hit.pixelID, hit.time, minT0, 0, 0, 0, bg));
1037
1038 if (sum == 0) return;
1039 for (size_t i = i0; i < m_pulls.size(); i++) m_pulls[i].wt /= sum;
1040 }
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28

◆ cerenkovAngle()

const InverseRaytracer::CerenkovAngle & cerenkovAngle ( double dE = 0)
inlineprivate

Returns cosine and sine of cerenkov angle.

Parameters
dEenergy difference to mean photon energy
Returns
cosine and sine of cerenkov angle

Definition at line 779 of file PDFConstructor.h.

780 {
781 // dE = 0 is by far the most frequent argument, so it is kept out of the map
782 auto& cer = (dE == 0) ? m_cerenkovAngle0 : m_cerenkovAngles[dE];
783 if (cer.cosThc == 0 and cer.sinThc == 0) {
784 double meanE = m_yScanner->getMeanEnergy();
785 double cosThc = getCosCerenkovAngle(meanE + dE);
786 cer = InverseRaytracer::CerenkovAngle(cosThc);
787 }
788 return cer;
789 }

◆ clearPDFOther()

void clearPDFOther ( )
inline

Clear the container of PDF's of other tracks.

Definition at line 396 of file PDFConstructor.h.

396{m_pdfOtherTracks.clear();}

◆ deltaXD()

double deltaXD ( double dFic,
const InverseRaytracer::Solution & sol,
double xD )
inlineprivate

Returns the difference in xD between ray-traced solution rotated by dFic and input argument.

Parameters
dFicrotation angle around track direction (delta Cerenkov azimuthal angle)
solsolution of inverse raytracing
xDunfolded detection position in x
Returns
difference in xD

Definition at line 765 of file PDFConstructor.h.

766 {
767 m_dFic = dFic;
768 m_fastRaytracer->propagate(m_inverseRaytracer->getReconstructedPhoton(sol, dFic), true);
769 if (not m_fastRaytracer->getPropagationStatus()) return std::numeric_limits<double>::quiet_NaN();
770 return m_fastRaytracer->getXD() - xD;
771 }

◆ derivativeOfReflectedX()

double derivativeOfReflectedX ( double x,
double xe,
double ze,
double zd )
staticprivate

Returns the derivative of reflected position at given x.

This function is used to find the position of reflection extreme. All arguments must be given in the mirror frame and in units of mirror radius.

Parameters
xposition in x on the mirror
xeunfolded emission position in x
zeemission position in z
zdunfolded detection position in z
Returns
the derivative

Definition at line 599 of file PDFConstructor.cc.

600 {
601 double z = sqrt(1 - x * x);
602 double kx = (x - xe);
603 double kz = (z - ze);
604 double s = 2 * (kx * x + kz * z);
605 double qx = kx - s * x;
606 double qz = kz - s * z;
607
608 double der_z = -x / z;
609 double der_s = 2 * (kx + der_z * kz);
610 double der_qx = (1 - s) - der_s * x;
611 double der_qz = (1 - s) * der_z - der_s * z;
612
613 return 1 - der_z * qx / qz + (zd - z) * (der_qx * qz - der_qz * qx) / (qz * qz);
614 }

◆ detectionPositionX()

bool detectionPositionX ( double xM,
int Nxm,
std::vector< double > & xDs,
double & minLen )
private

Calculates unfolded detection position from known reflection position on the mirror and emission point.

Parameters
xMreflection position x on the mirror
Nxmreflection number before the mirror
xDsunfolded detection positions (appended at each call) [in/out]
minLenminimum of propagation lengths (updated at each call) [in/out]
Returns
true on success

Definition at line 237 of file PDFConstructor.cc.

238 {
239 m_inverseRaytracer->clear();
240 int i0 = m_inverseRaytracer->solveForReflectionPoint(xM, Nxm, m_track.getEmissionPoint(), cerenkovAngle());
241 if (i0 < 0) return false;
242
243 bool ok = false;
244 for (unsigned i = 0; i < 2; i++) {
245 if (not m_inverseRaytracer->getStatus(i)) continue;
246 const auto& solutions = m_inverseRaytracer->getSolutions(i);
247 const auto& sol = solutions[i0];
248 xDs.push_back(sol.xD);
249 minLen = std::min(minLen, sol.len);
250 ok = true;
251 }
252
253 return ok;
254 }

◆ doRaytracingCorrections()

bool doRaytracingCorrections ( const InverseRaytracer::Solution & sol,
double dFic_dx,
double xD )
private

Corrects the solution of inverse ray-tracing with fast ray-tracing.

Corrected solution is available in m_fastRaytracer.

Parameters
solsolution of inverse raytracing
dFic_dxderivative of Cerenkov azimuthal angle over photon detection coordinate x
xDunfolded detection position in x
Returns
true on success

Definition at line 257 of file PDFConstructor.cc.

258 {
259 const double precision = 0.01; // [cm]
260
261 double x1 = 0; // x is dFic
262 double y1 = deltaXD(x1, sol, xD); // y is the difference in xD
263 if (isnan(y1)) return false;
264 if (std::abs(y1) < precision) return m_fastRaytracer->getTotalReflStatus(m_cosTotal);
265 int n1 = m_fastRaytracer->getNxm();
266
267 double step = -dFic_dx * y1;
268 for (int i = 1; i < 20; i++) { // search for zero-crossing interval
269 double x2 = step * i;
270 double y2 = deltaXD(x2, sol, xD);
271 if (isnan(y2)) return false;
272 int n2 = m_fastRaytracer->getNxm();
273 if (n2 != n1) { // x2 is passing the discontinuity caused by different reflection number
274 double x3 = x2;
275 x2 = x1;
276 y2 = y1;
277 for (int k = 0; k < 20; k++) { // move x2 to discontinuity using bisection
278 double x = (x2 + x3) / 2;
279 double y = deltaXD(x, sol, xD);
280 if (isnan(y)) return false;
281 int n = m_fastRaytracer->getNxm();
282 if (n == n1) {
283 x2 = x;
284 y2 = y;
285 } else {
286 x3 = x;
287 }
288 }
289 if (y2 * y1 > 0) return false; // solution does not exist
290 }
291 if (std::abs(y2) < precision) return m_fastRaytracer->getTotalReflStatus(m_cosTotal);
292 if (y2 * y1 < 0) { // zero-crossing interval is identified
293 for (int k = 0; k < 20; k++) { // find zero-crossing using bisection
294 double x = (x1 + x2) / 2;
295 double y = deltaXD(x, sol, xD);
296 if (isnan(y)) return false;
297 if (std::abs(y) < precision) return m_fastRaytracer->getTotalReflStatus(m_cosTotal);
298 if (y * y1 < 0) {
299 x2 = x;
300 } else {
301 x1 = x;
302 y1 = y;
303 }
304 }
305 return m_fastRaytracer->getTotalReflStatus(m_cosTotal);
306 }
307 x1 = x2;
308 y1 = y2;
309 }
310
311 return false;
312 }

◆ expandSignalPDF()

void expandSignalPDF ( unsigned col,
const YScanner::Derivatives & D,
SignalPDF::EPeakType type )
private

Expands signal PDF in y (y-scan)

Parameters
colpixel column (0-based)
Dderivatives
typepeak type, e.g. direct or reflected

Definition at line 412 of file PDFConstructor.cc.

413 {
414 m_ncallsExpandPDF[type]++;
415
416 double Len = m_fastRaytracer->getPropagationLen();
417 double speedOfLightQuartz = Const::speedOfLight / m_groupIndex; // average speed of light in quartz
418
419 // difference of propagation times of true and flipped prism
420 double dTime = m_fastRaytracer->getPropagationLenDelta() / speedOfLightQuartz;
421
422 // derivatives: dt/de, dt/dx, dt/dL
423 double dt_de = (D.dLen_de + Len * m_groupIndexDerivative / m_groupIndex) / speedOfLightQuartz;
424 double dt_dx = D.dLen_dx / speedOfLightQuartz;
425 double dt_dL = D.dLen_dL / speedOfLightQuartz + 1 / m_beta / Const::speedOfLight;
426
427 // contribution of multiple scattering in quartz
428 double sigmaScat = D.dLen_de * m_yScanner->getSigmaScattering() / speedOfLightQuartz;
429
430 // contribution of quartz surface roughness at single reflection and effective number of reflections
431 double sigmaAlpha = D.dLen_de * m_yScanner->getSigmaAlpha() / speedOfLightQuartz;
432 int Ny_eff = 2 * std::abs(m_fastRaytracer->getNym()) + std::abs(m_fastRaytracer->getNyb());
433
434 const auto& pixel = m_yScanner->getPixelPositions().get(col + 1);
435 double L = m_track.getLengthInQuartz();
436
437 // sigma squared: pixel size, parallax, propagation time difference, multiple scattering, surface roughness
438 double wid0 = (pow(dt_dx * pixel.Dx, 2) + pow(dt_dL * L, 2) + pow(dTime, 2)) / 12 + pow(sigmaScat, 2) +
439 pow(sigmaAlpha, 2) * Ny_eff;
440
441 // sigma squared: adding chromatic contribution
442 double wid = wid0 + pow(dt_de * m_yScanner->getRMSEnergy(), 2);
443
444 double yB = m_fastRaytracer->getYB();
445 const auto& photonStates = m_fastRaytracer->getPhotonStates();
446 const auto& atPrismEntrance = photonStates[photonStates.size() - 2];
447 double dydz = atPrismEntrance.getKy() / atPrismEntrance.getKz();
448 if (m_fastRaytracer->getNyb() % 2 != 0) dydz = -dydz;
449
450 bool doScan = (m_PDFOption == c_Fine);
451 if (m_PDFOption == c_Optimal) {
452 double time = m_tof + Len / speedOfLightQuartz;
453 doScan = m_track.isScanRequired(col, time, wid);
454 }
455
456 m_yScanner->expand(col, yB, dydz, D, Ny_eff, doScan);
457
458 double numPhotons = m_yScanner->getNumPhotons() * std::abs(D.dFic_dx * pixel.Dx);
459 int nx = m_fastRaytracer->getNx();
460 int ny = m_fastRaytracer->getNy();
461 for (const auto& result : m_yScanner->getResults()) {
462 double RQE = m_yScanner->getPixelEfficiencies().get(result.pixelID);
463 if (RQE == 0) continue;
464 auto& signalPDF = m_signalPDFs[result.pixelID - 1];
465 double dE = result.e0 - m_yScanner->getMeanEnergy();
466 double propLen = Len + D.dLen_de * dE;
467 double speedOfLight = Const::speedOfLight / TOPGeometryPar::getGroupIndex(result.e0);
468
469 SignalPDF::PDFPeak peak;
470 peak.t0 = m_tof + propLen / speedOfLight;
471 peak.wid = wid0 + dt_de * dt_de * result.sigsq;
472 peak.nph = numPhotons * result.sum * RQE * propagationLosses(result.e0, propLen, nx, ny, type);
473 peak.fic = func::within2PI(m_Fic + D.dFic_de * dE);
474 signalPDF.append(peak);
475
476 if (m_storeOption == c_Reduced) continue;
477
478 SignalPDF::PDFExtra extra;
479 extra.thc = acos(getCosCerenkovAngle(result.e0));
480 extra.e = result.e0;
481 extra.sige = result.sigsq;
482 extra.Nxm = m_fastRaytracer->getNxm();
483 extra.Nxb = m_fastRaytracer->getNxb();
484 extra.Nxe = m_fastRaytracer->getNxe();
485 extra.Nym = m_fastRaytracer->getNym();
486 extra.Nyb = m_fastRaytracer->getNyb();
487 extra.Nye = m_fastRaytracer->getNye();
488 extra.xD = m_fastRaytracer->getXD();
489 extra.yD = m_fastRaytracer->getYD();
490 extra.zD = m_fastRaytracer->getZD();
491 extra.yB = m_fastRaytracer->getYB();
492 const auto& firstState = photonStates.front();
493 extra.kxE = firstState.getKx();
494 extra.kyE = firstState.getKy();
495 extra.kzE = firstState.getKz();
496 const auto& lastState = photonStates.back();
497 extra.kxD = lastState.getKx();
498 extra.kyD = lastState.getKy();
499 extra.kzD = lastState.getKz();
500 extra.type = type;
501 signalPDF.append(extra);
502 }
503
504 }

◆ findReflectionExtreme()

double findReflectionExtreme ( double xE,
double zE,
double zD,
int Nxm,
double A,
const RaytracerBase::Mirror & mirror )
staticprivate

Finds the position on the mirror of the extreme reflection.

Parameters
xEtrue emission position in x
zEemission position in z
zDdetection position in z
Nxmsigned number of reflections before mirror
Awidth of the mirror segment
mirrorspherical mirror data
Returns
position of the extreme if exists or -A/2

Definition at line 617 of file PDFConstructor.cc.

619 {
620
621 if (Nxm % 2 == 0) {
622 xE = func::unfold(xE, -Nxm, A);
623 } else {
624 xE = func::unfold(xE, Nxm, A);
625 }
626
627 double xe = (xE - mirror.xc) / mirror.R;
628 double ze = (zE - mirror.zc) / mirror.R;
629 double zd = (zD - mirror.zc) / mirror.R;
630
631 double Ah = A / 2;
632
633 double x1 = (-Ah - mirror.xc) / mirror.R;
634 double y1 = derivativeOfReflectedX(x1, xe, ze, zd);
635 if (y1 != y1 or std::abs(y1) == INFINITY) return -Ah;
636
637 double x2 = (Ah - mirror.xc) / mirror.R;
638 double y2 = derivativeOfReflectedX(x2, xe, ze, zd);
639 if (y2 != y2 or std::abs(y2) == INFINITY) return -Ah;
640
641 if (y1 * y2 > 0) return -Ah; // no minimum or maximum
642
643 for (int i = 0; i < 50; i++) {
644 double x = (x1 + x2) / 2;
645 double y = derivativeOfReflectedX(x, xe, ze, zd);
646 if (y != y or std::abs(y) == INFINITY) return -Ah;
647 if (y * y1 < 0) {
648 x2 = x;
649 } else {
650 x1 = x;
651 y1 = y;
652 }
653 }
654 double x = (x1 + x2) / 2;
655
656 return x * mirror.R + mirror.xc;
657 }

◆ getBackgroundLogL() [1/2]

LogL getBackgroundLogL ( ) const
inline

Returns extended log likelihood for background hypothesis using default time window.

Returns
log likelihood

Definition at line 327 of file PDFConstructor.h.

327{return getBackgroundLogL(m_minTime, m_maxTime);}

◆ getBackgroundLogL() [2/2]

PDFConstructor::LogL getBackgroundLogL ( double minTime,
double maxTime ) const

Returns extended log likelihood for background hypothesis.

Parameters
minTimetime window lower edge
maxTimetime window upper edge
Returns
log likelihood

Definition at line 916 of file PDFConstructor.cc.

917 {
918 if (not m_valid) {
919 B2ERROR("TOP::PDFConstructor::getBackgroundLogL(): object status is invalid - cannot provide log likelihood");
920 return LogL(0);
921 }
922
923 double bkgPhotons = m_bkgPhotons * (maxTime - minTime) / (m_maxTime - m_minTime);
924
925 LogL LL(bkgPhotons);
926 for (const auto& hit : m_selectedHits) {
927 if (hit.time < minTime or hit.time > maxTime) continue;
928 double f = bkgPhotons * m_backgroundPDF->getPDFValue(hit.pixelID);
929 if (f <= 0) {
930 auto ret = m_zeroPixels.insert(hit.pixelID);
931 if (ret.second) {
932 B2ERROR("TOP::PDFConstructor::getBackgroundLogL(): PDF value is zero or negative"
933 << LogVar("slotID", m_moduleID)
934 << LogVar("pixelID", hit.pixelID) << LogVar("time", hit.time) << LogVar("PDFValue", f));
935 }
936 continue;
937 }
938 LL.logL += log(f);
939 LL.numPhotons++;
940 }
941 return LL;
942 }

◆ getBackgroundPDF()

const BackgroundPDF * getBackgroundPDF ( ) const
inline

Returns background PDF.

Returns
background PDF

Definition at line 179 of file PDFConstructor.h.

179{return m_backgroundPDF;}

◆ getBkgRate()

double getBkgRate ( ) const
inline

Returns estimated background hit rate.

Returns
background hit rate per module

Definition at line 154 of file PDFConstructor.h.

154{return m_bkgRate;}

◆ getCosCerenkovAngle()

double getCosCerenkovAngle ( double E) const
inline

Returns cosine of Cerenkov angle at given photon energy.

Parameters
Ephoton energy [eV]
Returns
cosine of Cerenkov angle

Definition at line 773 of file PDFConstructor.h.

774 {
775 double refind = TOPGeometryPar::getPhaseIndex(E);
776 return std::min(1 / m_beta / refind, 1.0);
777 }
R E
internal precision of FFTW codelets

◆ getCosTotal()

double getCosTotal ( ) const
inline

Returns cosine of total reflection angle.

Returns
cosine of total reflection angle at mean photon energy for beta = 1

Definition at line 160 of file PDFConstructor.h.

160{return m_cosTotal;}

◆ getDeltaRayPDF()

const DeltaRayPDF & getDeltaRayPDF ( ) const
inline

Returns delta-ray PDF.

Returns
delta-ray PDF

Definition at line 185 of file PDFConstructor.h.

185{return m_deltaRayPDF;}

◆ getDerivatives()

const std::map< double, YScanner::Derivatives > & getDerivatives ( ) const
inline

Returns a collection of derivatives for debugging purposes.

The derivatives are available only for EStoreOption::c_Full

Returns
map of xD and derivatives

Definition at line 381 of file PDFConstructor.h.

381{return m_derivatives;}

◆ getExpectedBkgPhotons() [1/2]

double getExpectedBkgPhotons ( ) const
inline

Returns the expected number of background photons within the default time window.

Photons from other tracks in the module are counted here as background.

Returns
expected number of background photons

Definition at line 204 of file PDFConstructor.h.

205 {
206 double photons = m_bkgPhotons;
207 for (const auto* other : m_pdfOtherTracks) {
208 photons += other->getExpectedSignalPhotons() + other->getExpectedDeltaPhotons();
209 }
210 return photons;
211 }

◆ getExpectedBkgPhotons() [2/2]

double getExpectedBkgPhotons ( double minTime,
double maxTime ) const
inline

Returns the expected number of background photons within a given time window.

Photons from other tracks in the module are counted here as background.

Parameters
minTimetime window lower edge
maxTimetime window upper edge
Returns
expected number of background photons

Definition at line 265 of file PDFConstructor.h.

266 {
267 double photons = (maxTime - minTime) / (m_maxTime - m_minTime) * m_bkgPhotons;
268 for (const auto* other : m_pdfOtherTracks) {
269 photons += other->getExpectedSignalPhotons(minTime, maxTime) + other->getExpectedDeltaPhotons(minTime, maxTime);
270 }
271 return photons;
272 }

◆ getExpectedDeltaPhotons() [1/2]

double getExpectedDeltaPhotons ( ) const
inline

Returns the expected number of delta-ray photons within the default time window.

Returns
expected number of delta-ray photons (0 if modeling turned off)

Definition at line 197 of file PDFConstructor.h.

197{return m_deltaPDFOn ? m_deltaPhotons : 0;}

◆ getExpectedDeltaPhotons() [2/2]

double getExpectedDeltaPhotons ( double minTime,
double maxTime ) const
inline

Returns the expected number of delta-ray photons within a given time window.

Parameters
minTimetime window lower edge
maxTimetime window upper edge
Returns
expected number of delta-ray photons (0 if modeling turned off)

Definition at line 253 of file PDFConstructor.h.

254 {
255 return m_deltaPDFOn ? m_deltaRayPDF.getIntegral(minTime, maxTime) * m_deltaPhotons : 0;
256 }

◆ getExpectedPhotons() [1/2]

double getExpectedPhotons ( ) const
inline

Returns the expected number of all photons within the default time window.

Returns
expected number of photons (signal + background + delta-ray)

Definition at line 217 of file PDFConstructor.h.

218 {
219 return getExpectedSignalPhotons() + getExpectedDeltaPhotons() + getExpectedBkgPhotons();
220 }

◆ getExpectedPhotons() [2/2]

double getExpectedPhotons ( double minTime,
double maxTime ) const
inline

Returns the expected number of all photons within a given time window.

Parameters
minTimetime window lower edge
maxTimetime window upper edge
Returns
expected number of photons (signal + background + delta-ray)

Definition at line 280 of file PDFConstructor.h.

281 {
282 return getExpectedSignalPhotons(minTime, maxTime) + getExpectedDeltaPhotons(minTime, maxTime) +
283 getExpectedBkgPhotons(minTime, maxTime);
284 }

◆ getExpectedSignalPhotons() [1/2]

double getExpectedSignalPhotons ( ) const
inline

Returns the expected number of signal photons within the default time window.

Returns
expected number of signal photons

Definition at line 191 of file PDFConstructor.h.

191{return m_signalPhotons;}

◆ getExpectedSignalPhotons() [2/2]

double getExpectedSignalPhotons ( double minTime,
double maxTime ) const
inline

Returns the expected number of signal photons within a given time window.

Parameters
minTimetime window lower edge
maxTimetime window upper edge
Returns
expected number of signal photons

Definition at line 228 of file PDFConstructor.h.

229 {
230 // the time window usually contains either all the PDF peaks or none of them,
231 // and then the sum over the pixels is known in advance
232 double ps = 0;
233 if (not m_hasPeaks) {
234 ; // no peaks at all: the sum stays zero
235 } else if (minTime <= m_minPeakT0 and maxTime >= m_maxPeakT0) {
236 ps = m_sumOfPeaks;
237 } else if (maxTime < m_minPeakT0 or minTime > m_maxPeakT0) {
238 ; // no peak is inside the window: the sum stays zero
239 } else {
240 for (const auto& signalPDF : m_signalPDFs) {
241 ps += signalPDF.getIntegral(minTime, maxTime);
242 }
243 }
244 return ps * m_signalPhotons;
245 }

◆ getHypothesis()

const Const::ChargedStable & getHypothesis ( ) const
inline

Returns particle hypothesis.

Returns
particle hypothesis

Definition at line 142 of file PDFConstructor.h.

142{return m_hypothesis;}

◆ getLogL() [1/3]

PDFConstructor::LogL getLogL ( ) const

Returns extended log likelihood (using the default time window)

Returns
log likelihood

Definition at line 860 of file PDFConstructor.cc.

861 {
862 if (not m_valid) {
863 B2ERROR("TOP::PDFConstructor::getLogL(): object status is invalid - cannot provide log likelihood");
864 return LogL(0);
865 }
866
867 LogL LL(getExpectedPhotons());
868 for (const auto& hit : m_selectedHits) {
869 if (hit.time < m_minTime or hit.time > m_maxTime) continue;
870 double f = pdfValue(hit.pixelID, hit.time, hit.timeErr);
871 if (f <= 0) {
872 auto ret = m_zeroPixels.insert(hit.pixelID);
873 if (ret.second) {
874 B2ERROR("TOP::PDFConstructor::getLogL(): PDF value is zero or negative"
875 << LogVar("slotID", m_moduleID)
876 << LogVar("pixelID", hit.pixelID) << LogVar("time", hit.time) << LogVar("PDFValue", f));
877 }
878 continue;
879 }
880 LL.logL += log(f);
881 LL.numPhotons++;
882 LL.effectiveSignalYield += m_f0 / f;
883 }
884 return LL;
885 }

◆ getLogL() [2/3]

PDFConstructor::LogL getLogL ( double t0,
double minTime,
double maxTime,
double sigt = 0 ) const

Returns extended log likelihood for PDF shifted in time and using different time window.

Parameters
t0time shift
minTimetime window lower edge
maxTimetime window upper edge
sigtadditional time smearing
Returns
log likelihood

Definition at line 888 of file PDFConstructor.cc.

889 {
890 if (not m_valid) {
891 B2ERROR("TOP::PDFConstructor::getLogL(): object status is invalid - cannot provide log likelihood");
892 return LogL(0);
893 }
894
895 LogL LL(getExpectedPhotons(minTime - t0, maxTime - t0));
896 for (const auto& hit : m_selectedHits) {
897 if (hit.time < minTime or hit.time > maxTime) continue;
898 double f = pdfValue(hit.pixelID, hit.time - t0, hit.timeErr, sigt);
899 if (f <= 0) {
900 auto ret = m_zeroPixels.insert(hit.pixelID);
901 if (ret.second) {
902 B2ERROR("TOP::PDFConstructor::getLogL(): PDF value is zero or negative"
903 << LogVar("slotID", m_moduleID)
904 << LogVar("pixelID", hit.pixelID) << LogVar("time", hit.time) << LogVar("PDFValue", f));
905 }
906 continue;
907 }
908 LL.logL += log(f);
909 LL.numPhotons++;
910 LL.effectiveSignalYield += m_f0 / f;
911 }
912 return LL;
913 }

◆ getLogL() [3/3]

LogL getLogL ( double t0,
double sigt = 0 ) const
inline

Returns extended log likelihood for PDF shifted in time.

Parameters
t0time shift
sigtadditional time smearing
Returns
log likelihood

Definition at line 311 of file PDFConstructor.h.

311{return getLogL(t0, m_minTime, m_maxTime, sigt);}

◆ getModuleID()

int getModuleID ( ) const
inline

Returns slot ID.

Returns
slot ID

Definition at line 136 of file PDFConstructor.h.

136{return m_moduleID;}

◆ getNCalls_expandPDF()

int getNCalls_expandPDF ( SignalPDF::EPeakType type) const
inline

Returns number of calls of function expandSignalPDF for a given peak type.

Parameters
typePDF peak type
Returns
number of calls

Definition at line 374 of file PDFConstructor.h.

374{return m_ncallsExpandPDF[type];}

◆ getNCalls_setPDF()

int getNCalls_setPDF ( SignalPDF::EPeakType type) const
inline

Returns number of calls of template function setSignalPDF<T> for a given peak type.

Parameters
typePDF peak type
Returns
number of calls

Definition at line 367 of file PDFConstructor.h.

367{return m_ncallsSetPDF[type];}

◆ getPDFValue()

double getPDFValue ( int pixelID,
double time,
double timeErr,
double sigt = 0 ) const
inline

Returns PDF value.

Parameters
pixelIDpixel ID
timephoton hit time
timeErruncertainty of hit time
sigtadditional time smearing
Returns
PDF value

Definition at line 294 of file PDFConstructor.h.

295 {
296 return pdfValue(pixelID, time, timeErr, sigt) / getExpectedPhotons();
297 }

◆ getPixelLogLs() [1/2]

const std::vector< PDFConstructor::LogL > & getPixelLogLs ( double t0,
double minTime,
double maxTime,
double sigt = 0 ) const

Returns extended log likelihoods in pixels for PDF shifted in time and using different time window.

Parameters
t0time shift
minTimetime window lower edge
maxTimetime window upper edge
sigtadditional time smearing
Returns
pixel log likelihoods (index = pixelID - 1)

Definition at line 946 of file PDFConstructor.cc.

947 {
948 if (not m_valid) {
949 B2ERROR("TOP::PDFConstructor::getPixelLogLs(): object status is invalid - cannot provide log likelihoods");
950 return m_pixelLLs;
951 }
952
953 initializePixelLogLs(minTime - t0, maxTime - t0);
954
955 for (const auto& hit : m_selectedHits) {
956 if (hit.time < minTime or hit.time > maxTime) continue;
957 double f = pdfValue(hit.pixelID, hit.time - t0, hit.timeErr, sigt);
958 if (f <= 0) {
959 auto ret = m_zeroPixels.insert(hit.pixelID);
960 if (ret.second) {
961 B2ERROR("TOP::PDFConstructor::getPixelLogLs(): PDF value is zero or negative"
962 << LogVar("slotID", m_moduleID)
963 << LogVar("pixelID", hit.pixelID) << LogVar("time", hit.time) << LogVar("PDFValue", f));
964 }
965 continue;
966 }
967 unsigned k = hit.pixelID - 1;
968 auto& LL = m_pixelLLs[k];
969 LL.logL += log(f);
970 LL.numPhotons++;
971 LL.effectiveSignalYield += m_f0 / f;
972 }
973
974 return m_pixelLLs;
975 }

◆ getPixelLogLs() [2/2]

const std::vector< LogL > & getPixelLogLs ( double t0,
double sigt = 0 ) const
inline

Returns extended log likelihoods in pixels for PDF shifted in time.

Parameters
t0time shift
sigtadditional time smearing
Returns
pixel log likelihoods (index = pixelID - 1)

Definition at line 343 of file PDFConstructor.h.

344 {return getPixelLogLs(t0, m_minTime, m_maxTime, sigt);}

◆ getPulls()

const std::vector< PDFConstructor::Pull > & getPulls ( ) const

Returns photon pulls w.r.t PDF peaks.

Returns
pulls

Definition at line 997 of file PDFConstructor.cc.

998 {
999 if (m_pulls.empty() and m_valid) {
1000 for (const auto& hit : m_selectedHits) {
1001 if (hit.time < m_minTime or hit.time > m_maxTime) continue;
1002 appendPulls(hit);
1003 }
1004 }
1005
1006 return m_pulls;
1007 }

◆ getSelectedHits()

const std::vector< TOPTrack::SelectedHit > & getSelectedHits ( ) const
inline

Returns selected photon hits belonging to this slot.

Returns
selected photon hits

Definition at line 148 of file PDFConstructor.h.

148{return m_selectedHits;}

◆ getSignalPDF()

const std::vector< SignalPDF > & getSignalPDF ( ) const
inline

Returns signal PDF.

Returns
signal PDF in pixels (index = pixelID - 1)

Definition at line 173 of file PDFConstructor.h.

173{return m_signalPDFs;}

◆ initializePixelLogLs()

void initializePixelLogLs ( double minTime,
double maxTime ) const
private

Initializes pixel log likelihoods.

Parameters
minTimetime window lower edge
maxTimetime window upper edge

Definition at line 977 of file PDFConstructor.cc.

978 {
979 m_pixelLLs.clear();
980
981 double pb = (maxTime - minTime) / (m_maxTime - m_minTime);
982 double bfot = pb * m_bkgPhotons + getExpectedDeltaPhotons(minTime, maxTime);
983 for (const auto* other : m_pdfOtherTracks) bfot += other->getExpectedDeltaPhotons(minTime, maxTime);
984
985 const auto& pixelPDF = m_backgroundPDF->getPDF();
986 for (const auto& signalPDF : m_signalPDFs) {
987 unsigned k = signalPDF.getPixelID() - 1;
988 double phot = signalPDF.getIntegral(minTime, maxTime) * m_signalPhotons + bfot * pixelPDF[k];
989 for (const auto* other : m_pdfOtherTracks) {
990 const auto& otherPDFs = other->getSignalPDF();
991 phot += otherPDFs[k].getIntegral(minTime, maxTime) * other->getExpectedSignalPhotons();
992 }
993 m_pixelLLs.push_back(LogL(phot));
994 }
995 }

◆ isValid()

bool isValid ( ) const
inline

Checks the object status.

Returns
true if track is valid and all requited reconstruction objects are available

Definition at line 114 of file PDFConstructor.h.

114{return m_valid;}

◆ pdfValue()

double pdfValue ( int pixelID,
double time,
double timeErr,
double sigt = 0 ) const
inlineprivate

Returns the value of PDF normalized to the number of expected photons.

Parameters
pixelIDpixel ID
timephoton hit time
timeErruncertainty of hit time
sigtadditional time smearing
Returns
PDF value

Definition at line 751 of file PDFConstructor.h.

752 {
753
754 if (not m_valid) return 0;
755
756 double f = pdfValueSignal(pixelID, time, timeErr, sigt); // signal
757 m_f0 = f;
758 if (m_deltaPDFOn) f += m_deltaPhotons * m_deltaRayPDF.getPDFValue(pixelID, time); // delta electrons
759 f += m_bkgPhotons * m_backgroundPDF->getPDFValue(pixelID); // uniform background
760 for (const auto* other : m_pdfOtherTracks) f += other->pdfValueSignalDelta(pixelID, time, timeErr, sigt); // other tracks
761
762 return f;
763 }

◆ pdfValueSignal()

double pdfValueSignal ( int pixelID,
double time,
double timeErr,
double sigt = 0 ) const
inlineprivate

Returns the value of signal PDF normalized to the number of expected photons.

Parameters
pixelIDpixel ID
timephoton hit time
timeErruncertainty of hit time
sigtadditional time smearing
Returns
PDF value

Definition at line 735 of file PDFConstructor.h.

736 {
737 unsigned k = pixelID - 1;
738 if (k < m_signalPDFs.size() and m_valid) {
739 return m_signalPhotons * m_signalPDFs[k].getPDFValue(time, timeErr, sigt);
740 }
741 return 0;
742 }

◆ pdfValueSignalDelta()

double pdfValueSignalDelta ( int pixelID,
double time,
double timeErr,
double sigt = 0 ) const
inlineprivate

Returns the value of signal + deltaRay PDF normalized to the number of expected photons.

Parameters
pixelIDpixel ID
timephoton hit time
timeErruncertainty of hit time
sigtadditional time smearing
Returns
PDF value

Definition at line 744 of file PDFConstructor.h.

745 {
746 double f = pdfValueSignal(pixelID, time, timeErr, sigt);
747 if (m_deltaPDFOn) f += m_deltaPhotons * m_deltaRayPDF.getPDFValue(pixelID, time);
748 return f;
749 }

◆ prismRaytrace()

bool prismRaytrace ( const PrismSolution & sol,
double dL = 0,
double dFic = 0,
double de = 0 )
private

Do forward raytracing of inverse raytracing solution in prism.

Parameters
solsolution of inverse raytracing in prism
dLstep in length along trajectory for derivative calculation
dFicstep in Cherenkov azimuthal angle for derivative calculation
destep in photon energy for derivative calculation
Returns
true on success

Definition at line 783 of file PDFConstructor.cc.

784 {
785 const auto& emi = m_track.getEmissionPoint(sol.L + dL);
786 const auto& trk = emi.trackAngles;
787 const auto& cer = cerenkovAngle(de);
788
789 double cosDFic = 1;
790 double sinDFic = 0;
791 if (dFic != 0) {
792 cosDFic = cos(dFic);
793 sinDFic = sin(dFic);
794 }
795 double cosFic = sol.cosFic * cosDFic - sol.sinFic * sinDFic;
796 double sinFic = sol.sinFic * cosDFic + sol.cosFic * sinDFic;
797 double a = trk.cosTh * cer.sinThc * cosFic + trk.sinTh * cer.cosThc;
798 double b = cer.sinThc * sinFic;
799 double kx = a * trk.cosFi - b * trk.sinFi;
800 double ky = a * trk.sinFi + b * trk.cosFi;
801 double kz = trk.cosTh * cer.cosThc - trk.sinTh * cer.sinThc * cosFic;
802 PhotonState photon(emi.position, kx, ky, kz);
803 m_fastRaytracer->propagate(photon);
804
805 return m_fastRaytracer->getPropagationStatus();
806 }

◆ prismSolution() [1/2]

PDFConstructor::PrismSolution prismSolution ( const PixelPositions::PixelData & pixel,
unsigned k,
int nx )
private

General solution of inverse raytracing in prism: iterative procedure calling basic solution.

Parameters
pixelpixel data
kindex of unfolded prism exit window
nxnumber of reflections in x
Returns
solution

Definition at line 809 of file PDFConstructor.cc.

811 {
812 const auto& prism = m_inverseRaytracer->getPrism();
813 const auto& win = prism.unfoldedWindows[k];
814 double dz = std::abs(prism.zD - prism.zFlat);
815 ROOT::Math::XYZPoint rD(func::unfold(pixel.xc, nx, prism.A),
816 pixel.yc * win.sy + win.y0 + win.ny * dz,
817 pixel.yc * win.sz + win.z0 + win.nz * dz);
818
819 double L = 0;
820 for (int iter = 0; iter < 100; iter++) {
821 auto sol = prismSolution(rD, L);
822 if (std::abs(sol.L) > m_track.getLengthInQuartz() / 2) return sol;
823 if (std::abs(sol.L - L) < 0.01) return sol;
824 L = sol.L;
825 }
826 B2DEBUG(20, "TOP::PDFConstructor::prismSolution: iterations not converging");
827 return PrismSolution();
828 }

◆ prismSolution() [2/2]

PDFConstructor::PrismSolution prismSolution ( const ROOT::Math::XYZPoint & rD,
double L )
private

Basic solution of inverse raytracing in prism: assuming straight line particle trajectory.

Parameters
rDunfolded pixel position
Lemission position distance along particle trajectory
Returns
solution

Definition at line 831 of file PDFConstructor.cc.

832 {
833 const auto& emi = m_track.getEmissionPoint(L);
834
835 // transformation of detection position to system of particle
836
837 auto r = rD - emi.position;
838 const auto& trk = emi.trackAngles;
839 double xx = r.X() * trk.cosFi + r.Y() * trk.sinFi;
840 double y = -r.X() * trk.sinFi + r.Y() * trk.cosFi;
841 double x = xx * trk.cosTh - r.Z() * trk.sinTh;
842 double z = xx * trk.sinTh + r.Z() * trk.cosTh;
843
844 // solution
845
846 double rho = sqrt(x * x + y * y);
847 const auto& cer = cerenkovAngle();
848
849 PrismSolution sol;
850 sol.len = rho / cer.sinThc;
851 sol.L = L + z - sol.len * cer.cosThc;
852 sol.cosFic = x / rho;
853 sol.sinFic = y / rho;
854
855 return sol;
856 }

◆ propagationLosses()

double propagationLosses ( double E,
double propLen,
int nx,
int ny,
SignalPDF::EPeakType type ) const
private

Returns photon propagation losses (bulk absorption, surface reflectivity, mirror reflectivity)

Parameters
Ephoton energy
propLenpropagation length
nxtotal number of reflections in x
nytotal number of reflections in y
typepeak type, e.g. direct or reflected
Returns
survival probability due to propagation losses

Definition at line 506 of file PDFConstructor.cc.

508 {
509 double bulk = TOPGeometryPar::getAbsorptionLength(E);
510 // the surface reflectivity is a constant of the module, so its powers are tabulated
511 // once per module by the YScanner instead of being re-computed for every photon
512 double surf = m_yScanner->getSurfaceReflectivity(std::abs(nx) + std::abs(ny));
513 double p = exp(-propLen / bulk) * surf;
514 if (type == SignalPDF::c_Reflected) p *= std::min(m_yScanner->getMirror().reflectivity, 1.0);
515 return p;
516 }

◆ rangeOfX()

bool rangeOfX ( double z,
double & xmi,
double & xma )
private

Estimates range of unfolded x coordinate of the hits on given plane perpendicular to z-axis.

Parameters
zposition of the plane
xmilower limit [out]
xmaupper limit [out]
Returns
true if at least some photons can reach the plane within the time window

Definition at line 518 of file PDFConstructor.cc.

519 {
520 double maxLen = (m_maxTime - m_tof) / m_groupIndex * Const::speedOfLight; // maximal propagation length
521 if (maxLen < 0) return false;
522
523 const auto& emission = m_track.getEmissionPoint();
524 const auto& trk = emission.trackAngles;
525 const auto& cer = cerenkovAngle();
526
527 // range in x from propagation length limit
528
529 double dz = z - emission.position.Z();
530 double cosFicLimit = (trk.cosTh * cer.cosThc - dz / maxLen) / (trk.sinTh * cer.sinThc); // at maxLen
531 double cosLimit = (dz > 0) ? cosFicLimit : -cosFicLimit;
532 if (cosLimit < -1) return false; // photons cannot reach the plane at z within propagation length limit
533
534 std::vector<double> xmima;
535 double x0 = emission.position.X();
536 if (cosLimit > 1) {
537 xmima.push_back(x0 - maxLen);
538 xmima.push_back(x0 + maxLen);
539 } else {
540 double a = trk.cosTh * cer.sinThc * cosFicLimit + trk.sinTh * cer.cosThc;
541 double b = cer.sinThc * sqrt(1 - cosFicLimit * cosFicLimit);
542 xmima.push_back(x0 + maxLen * (a * trk.cosFi - b * trk.sinFi));
543 xmima.push_back(x0 + maxLen * (a * trk.cosFi + b * trk.sinFi));
544 std::sort(xmima.begin(), xmima.end());
545 }
546 xmi = xmima[0];
547 xma = xmima[1];
548
549 // range in x from minimal/maximal possible extensions in x, if they exist (d(kx/kz)/dFic = 0)
550
551 double theta = acos(trk.cosTh);
552 if (dz < 0) theta = M_PI - theta; // rotation around x by 180 deg. (z -> -z, phi -> -phi)
553 dz = std::abs(dz);
554 double thetaCer = acos(cer.cosThc);
555 if (theta - thetaCer >= M_PI / 2) return false; // photons cannot reach the plane at z
556
557 std::vector<double> dxdz;
558 double a = -cos(theta + thetaCer) * cos(theta - thetaCer);
559 double b = sin(2 * theta) * trk.cosFi;
560 double c = pow(trk.sinFi * cer.sinThc, 2) - pow(trk.cosFi, 2) * sin(theta + thetaCer) * sin(theta - thetaCer);
561 double D = b * b - 4 * a * c;
562 if (D < 0) return true; // minimum and maximum do not exist, range is given by propagation length limit
563 if (a != 0) {
564 D = sqrt(D);
565 dxdz.push_back((-b - D) / 2 / a);
566 dxdz.push_back((-b + D) / 2 / a);
567 } else {
568 if (b == 0) return true; // minimum and maximum do not exist, range is given by propagation length limit
569 dxdz.push_back(-c / b);
570 dxdz.push_back(copysign(INFINITY, b));
571 }
572 std::vector<double> cosFic(2, cosLimit);
573 for (int i = 0; i < 2; i++) {
574 if (std::abs(dxdz[i]) < INFINITY) {
575 double aa = (dxdz[i] * cos(theta) - trk.cosFi * sin(theta)) * cer.cosThc;
576 double bb = (dxdz[i] * sin(theta) + trk.cosFi * cos(theta)) * cer.sinThc;
577 double dd = trk.sinFi * cer.sinThc;
578 cosFic[i] = aa * bb / (bb * bb + dd * dd);
579 double kz = cos(theta) * cer.cosThc - sin(theta) * cer.sinThc * cosFic[i];
580 if (kz < 0) dxdz[i] = copysign(INFINITY, dxdz[1 - i] - dxdz[i]);
581 }
582 }
583 if (dxdz[0] > dxdz[1]) {
584 std::reverse(dxdz.begin(), dxdz.end());
585 std::reverse(cosFic.begin(), cosFic.end());
586 }
587 for (int i = 0; i < 2; i++) {
588 if (cosFic[i] < cosLimit) xmima[i] = x0 + dxdz[i] * dz;
589 }
590
591 // just to make sure xmi/xma are within the limits given by maximal propagation length
592 xmi = std::max(xmima[0], x0 - maxLen);
593 xma = std::min(xmima[1], x0 + maxLen);
594
595 return xma > xmi;
596 }

◆ raytrace()

bool raytrace ( const FastRaytracer & rayTracer,
double dL = 0,
double de = 0,
double dFic = 0 )
private

Forward ray-tracing (called by setDerivatives)

Parameters
rayTracerforward ray-tracer object
dLvalue to be added to trajectory running parameter [cm]
devalue to be added to photon energy [eV]
dFicvalue to be added to Cherenkov azimuthal angle
Returns
true on success

Definition at line 378 of file PDFConstructor.cc.

379 {
380 const auto& emi = m_track.getEmissionPoint(dL);
381 const auto& trk = emi.trackAngles;
382 const auto& cer = cerenkovAngle(de);
383
384 double fic = m_Fic + dFic;
385 double cosFic = cos(fic);
386 double sinFic = sin(fic);
387 double a = trk.cosTh * cer.sinThc * cosFic + trk.sinTh * cer.cosThc;
388 double b = cer.sinThc * sinFic;
389 double kx = a * trk.cosFi - b * trk.sinFi;
390 double ky = a * trk.sinFi + b * trk.cosFi;
391 double kz = trk.cosTh * cer.cosThc - trk.sinTh * cer.sinThc * cosFic;
392 PhotonState photon(emi.position, kx, ky, kz);
393 rayTracer.propagate(photon, true);
394 if (not rayTracer.getPropagationStatus()) return false;
395
396 if (rayTracer.getNxm() != m_fastRaytracer->getNxm()) return false;
397 if (rayTracer.getNym() != m_fastRaytracer->getNym()) return false;
398 if (rayTracer.getNxe() != m_fastRaytracer->getNxe()) return false;
399 if (rayTracer.getNye() != m_fastRaytracer->getNye()) return false;
400 if (rayTracer.getNxb() != m_fastRaytracer->getNxb()) return false;
401 if (rayTracer.getNyb() != m_fastRaytracer->getNyb()) return false;
402
403 if (rayTracer.getExtraStates().empty() or m_fastRaytracer->getExtraStates().empty()) return true;
404
405 if (rayTracer.getExtraStates().back().getNx() != m_fastRaytracer->getExtraStates().back().getNx()) return false;
406 if (rayTracer.getExtraStates().back().getNy() != m_fastRaytracer->getExtraStates().back().getNy()) return false;
407
408 return true;
409 }

◆ setDerivatives()

bool setDerivatives ( YScanner::Derivatives & D,
double dL,
double de,
double dFic )
private

Sets the derivatives (numerically) using forward ray-tracing.

Parameters
Dderivatives to be set
dLstep in trajectory running parameter [cm]
destep in photon energy [eV]
dFicstep in Cherenkov azimuthal angle
Returns
true on success

Definition at line 315 of file PDFConstructor.cc.

316 {
317 while (m_rayTracers.size() < 3) m_rayTracers.push_back(*m_fastRaytracer); // push back a copy of the object
318
319 bool ok = true;
320 const auto& rayTracer_dL = m_rayTracers[0];
321 for (int i = 0; i < 10; i++) {
322 ok = raytrace(rayTracer_dL, dL);
323 if (ok) break;
324 dL = - dL / 2;
325 }
326 if (not ok) return false;
327
328 const auto& rayTracer_de = m_rayTracers[1];
329 for (int i = 0; i < 10; i++) {
330 ok = raytrace(rayTracer_de, 0, de);
331 if (ok) break;
332 de = - de / 2;
333 }
334 if (not ok) return false;
335
336 const auto& rayTracer_dFic = m_rayTracers[2];
337 for (int i = 0; i < 10; i++) {
338 ok = raytrace(rayTracer_dFic, 0, 0, dFic);
339 if (ok) break;
340 dFic = - dFic / 2;
341 }
342 if (not ok) return false;
343
344 // partial derivatives on L, e and Fic
345
346 double dLen_dL = (rayTracer_dL.getPropagationLen() - m_fastRaytracer->getPropagationLen()) / dL;
347 double dLen_de = (rayTracer_de.getPropagationLen() - m_fastRaytracer->getPropagationLen()) / de;
348 double dLen_dFic = (rayTracer_dFic.getPropagationLen() - m_fastRaytracer->getPropagationLen()) / dFic;
349
350 double dyB_dL = (rayTracer_dL.getYB() - m_fastRaytracer->getYB()) / dL;
351 double dyB_de = (rayTracer_de.getYB() - m_fastRaytracer->getYB()) / de;
352 double dyB_dFic = (rayTracer_dFic.getYB() - m_fastRaytracer->getYB()) / dFic;
353
354 double dx_dL = (rayTracer_dL.getXD() - m_fastRaytracer->getXD()) / dL;
355 double dx_de = (rayTracer_de.getXD() - m_fastRaytracer->getXD()) / de;
356 double dx_dFic = (rayTracer_dFic.getXD() - m_fastRaytracer->getXD()) / dFic;
357
358 if (dx_dFic == 0) return false;
359
360 // derivatives on L, e, and x. Derivatives on L and e have to be given at constant x.
361
362 D.dLen_dx = dLen_dFic / dx_dFic;
363 D.dLen_de = dLen_de - dLen_dFic * dx_de / dx_dFic;
364 D.dLen_dL = dLen_dL - dLen_dFic * dx_dL / dx_dFic;
365
366 D.dyB_dx = dyB_dFic / dx_dFic;
367 D.dyB_de = dyB_de - dyB_dFic * dx_de / dx_dFic;
368 D.dyB_dL = dyB_dL - dyB_dFic * dx_dL / dx_dFic;
369
370 D.dFic_dx = 1 / dx_dFic;
371 D.dFic_de = - dx_de / dx_dFic;
372 D.dFic_dL = - dx_dL / dx_dFic;
373
374 return true;
375 }

◆ setSignalPDF() [1/2]

void setSignalPDF ( )
private

Sets signal PDF.

Definition at line 109 of file PDFConstructor.cc.

110 {
111 // construct PDF analytically
112
113 const auto& prism = m_inverseRaytracer->getPrism();
114
115 if (m_track.getEmissionPoint().position.Z() > prism.zR) {
116 setSignalPDF_direct();
117 setSignalPDF_reflected();
118 } else {
119 setSignalPDF_prism();
120 }
121
122 // count expected number of signal photons
123
124 for (const auto& signalPDF : m_signalPDFs) {
125 m_signalPhotons += signalPDF.getSum();
126 }
127 if (m_signalPhotons == 0) return;
128
129 // normalize PDF
130
131 for (auto& signalPDF : m_signalPDFs) {
132 signalPDF.normalize(m_signalPhotons);
133 }
134 }

◆ setSignalPDF() [2/2]

template<class T>
void setSignalPDF ( T & t,
unsigned col,
double xD,
double zD,
int Nxm = 0,
double xmMin = 0,
double xmMax = 0 )
private

Template function: sets signal PDF in a pixel column and for specific reflection in x.

Parameters
ttemplate parameter of type InverseRaytracerDirect or InverseRaytracerReflected
colpixel column (0-based)
xDunfolded detection position in x
zDdetection position in z
Nxmsigned number of reflections in x before mirror (dummy for direct PDF)
xmMinlower limit of the reflection positions on the mirror (dummy for direct PDF)
xmMaxupper limit of the reflection positions on the mirror (dummy for direct PDF)

Definition at line 793 of file PDFConstructor.h.

794 {
795 m_ncallsSetPDF[t.type]++;
796
797 m_inverseRaytracer->clear();
798 t.inverseRaytracer = m_inverseRaytracer;
799
800 // central solutions
801
802 int i0 = t.solve(xD, zD, Nxm, xmMin, xmMax, m_track.getEmissionPoint(), cerenkovAngle());
803 if (i0 < 0 or not m_inverseRaytracer->getStatus()) return;
804 int n = 0;
805 for (unsigned i = 0; i < 2; i++) {
806 if (not m_inverseRaytracer->getStatus(i)) continue;
807 const auto& solutions = m_inverseRaytracer->getSolutions(i);
808 const auto& sol = solutions[i0];
809 double time = m_tof + sol.len * m_groupIndex / Const::speedOfLight;
810 if (time > m_maxTime + 1.0) continue;
811 n++;
812 }
813 if (n == 0) return;
814
815 // solutions with xD displaced by dx
816
817 double dx = 0.1; // cm
818 int i_dx = t.solve(xD + dx, zD, Nxm, xmMin, xmMax, m_track.getEmissionPoint(), cerenkovAngle(), dx);
819 if (i_dx < 0) return;
820 int k = 0;
821 while (m_inverseRaytracer->isNymDifferent()) { // get rid of discontinuities
822 if (k > 8) {
823 B2DEBUG(20, "TOP::PDFConstructor::setSignalPDF: failed to find the same Nym (dx)");
824 return;
825 }
826 dx = - dx / 2;
827 i_dx = t.solve(xD + dx, zD, Nxm, xmMin, xmMax, m_track.getEmissionPoint(), cerenkovAngle(), dx);
828 if (i_dx < 0) return;
829 k++;
830 }
831
832 // loop over the two solutions, do ray-tracing corrections, compute the derivatives and expand PDF in y
833
834 for (unsigned i = 0; i < 2; i++) {
835 if (not m_inverseRaytracer->getStatus(i)) continue;
836 const auto& solutions = m_inverseRaytracer->getSolutions(i);
837 const auto& sol = solutions[i0];
838 const auto& sol_dx = solutions[i_dx];
839
840 // compute dFic/dx needed in raytracing corrections
841
842 double dFic_dx = YScanner::Derivatives::dFic_d(sol, sol_dx);
843
844 // do raytracing corrections
845
846 m_dFic = 0;
847 bool ok = doRaytracingCorrections(sol, dFic_dx, xD);
848 if (not ok) continue;
849 m_Fic = sol.getFic() + m_dFic;
850
851 // check if time is still within the reconstruction range
852
853 double time = m_tof + m_fastRaytracer->getPropagationLen() * m_groupIndex / Const::speedOfLight;
854 if (time > m_maxTime) continue;
855
856 // compute the derivatives
857
858 YScanner::Derivatives D;
859 ok = setDerivatives(D, 0.1, 0.1, 0.001);
860 if (not ok) {
861 B2DEBUG(20, "TOP::PDFConstructor::setSignalPDF: failed to determine derivatives: "
862 << LogVar("track momentum", m_track.getMomentumMag())
863 << LogVar("impact local z", m_track.getEmissionPoint().position.Z())
864 << LogVar("xD", xD)
865 << LogVar("Nxm", Nxm)
866 << LogVar("time", time)
867 << LogVar("peak type", t.type));
868 continue;
869 }
870 if (m_storeOption == c_Full) m_derivatives[xD] = D;
871
872 // expand PDF in y
873
874 expandSignalPDF(col, D, t.type);
875 }
876 }

◆ setSignalPDF_direct()

void setSignalPDF_direct ( )
private

Sets signal PDF for direct photons.

Definition at line 138 of file PDFConstructor.cc.

139 {
140 const auto& pixelPositions = m_yScanner->getPixelPositions();
141 const auto& bar = m_inverseRaytracer->getBars().front();
142 const auto& prism = m_inverseRaytracer->getPrism();
143
144 // determine the range of number of reflections in x
145
146 double xmi = 0, xma = 0;
147 bool ok = rangeOfX(prism.zD, xmi, xma);
148 if (not ok) return;
149 int kmi = func::lround(xmi / bar.A);
150 int kma = func::lround(xma / bar.A);
151
152 // loop over reflections in x and over pixel columns
153
154 for (int k = kmi; k <= kma; k++) {
155 for (unsigned col = 0; col < pixelPositions.getNumPixelColumns(); col++) {
156 const auto& pixel = pixelPositions.get(col + 1);
157 if (pixel.Dx == 0) continue;
158 double xD = func::unfold(pixel.xc, k, bar.A);
159 if (xD < xmi or xD > xma) continue;
160 InverseRaytracerDirect direct;
161 setSignalPDF(direct, col, xD, prism.zD);
162 }
163 }
164 }

◆ setSignalPDF_prism()

void setSignalPDF_prism ( )
private

Sets signal PDF for track crossing prism.

Definition at line 661 of file PDFConstructor.cc.

662 {
663 const auto& pixelPositions = m_yScanner->getPixelPositions();
664 const auto& prism = m_inverseRaytracer->getPrism();
665 double speedOfLightQuartz = Const::speedOfLight / m_groupIndex; // average speed of light in quartz
666
667 double xE = m_track.getEmissionPoint().position.X();
668 int nxmi = (xE > 0) ? 0 : -1;
669 int nxma = (xE > 0) ? 1 : 0;
670
671 for (const auto& pixel : pixelPositions.getPixels()) {
672 if (not m_yScanner->getPixelMasks().isActive(pixel.ID)) continue;
673 double RQE = m_yScanner->getPixelEfficiencies().get(pixel.ID);
674 if (RQE == 0) continue;
675 auto& signalPDF = m_signalPDFs[pixel.ID - 1];
676 for (int Nxe = nxmi; Nxe <= nxma; Nxe++) {
677 for (size_t k = 0; k < prism.unfoldedWindows.size(); k++) {
678 const auto sol = prismSolution(pixel, k, Nxe);
679 if (sol.len == 0 or std::abs(sol.L) > m_track.getLengthInQuartz() / 2) continue;
680
681 bool ok = prismRaytrace(sol);
682 if (not ok) continue;
683 int Nye = k - prism.k0;
684 if (Nye != m_fastRaytracer->getNy() or Nxe != m_fastRaytracer->getNx()) continue;
685 if (not m_fastRaytracer->getTotalReflStatus(m_cosTotal)) continue;
686 const auto firstState = m_fastRaytracer->getPhotonStates().front(); // a copy of
687 const auto lastState = m_fastRaytracer->getPhotonStates().back(); // a copy of
688
689 double slope = lastState.getKy() / lastState.getKz();
690 double dz = prism.zD - prism.zFlat;
691 double y2 = std::min(pixel.yc + pixel.Dy / 2, prism.yUp + slope * dz);
692 double y1 = std::max(pixel.yc - pixel.Dy / 2, prism.yDown + slope * dz);
693 double Dy = y2 - y1;
694 if (Dy < 0) continue;
695
696 double dL = 0.1; // cm
697 for (int i = 0; i < 4; i++) {
698 ok = prismRaytrace(sol, dL);
699 ok = ok and Nye == m_fastRaytracer->getNy() and Nxe == m_fastRaytracer->getNx();
700 if (ok) break;
701 dL = - dL / 2;
702 }
703 if (not ok) continue;
704 const auto lastState_dL = m_fastRaytracer->getPhotonStates().back(); // a copy of
705
706 double dFic = 0.01; // rad
707 for (int i = 0; i < 4; i++) {
708 ok = prismRaytrace(sol, 0, dFic);
709 ok = ok and Nye == m_fastRaytracer->getNy() and Nxe == m_fastRaytracer->getNx();
710 if (ok) break;
711 dFic = - dFic / 2;
712 }
713 if (not ok) continue;
714 const auto lastState_dFic = m_fastRaytracer->getPhotonStates().back(); // a copy of
715
716 double de = 0.1; // eV
717 for (int i = 0; i < 4; i++) {
718 ok = prismRaytrace(sol, 0, 0, de);
719 ok = ok and Nye == m_fastRaytracer->getNy() and Nxe == m_fastRaytracer->getNx();
720 if (ok) break;
721 de = - de / 2;
722 }
723 if (not ok) continue;
724 const auto lastState_de = m_fastRaytracer->getPhotonStates().back(); // a copy of
725
726 double dx_dL = (lastState_dL.getX() - lastState.getX()) / dL;
727 double dy_dL = (lastState_dL.getY() - lastState.getY()) / dL;
728 double dx_dFic = (lastState_dFic.getX() - lastState.getX()) / dFic;
729 double dy_dFic = (lastState_dFic.getY() - lastState.getY()) / dFic;
730 double Jacobi = dx_dL * dy_dFic - dy_dL * dx_dFic;
731 double numPhotons = m_yScanner->getNumPhotonsPerLen() * pixel.Dx * Dy / std::abs(Jacobi) * RQE;
732
733 double dLen_de = (lastState_de.getPropagationLen() - lastState.getPropagationLen()) / de;
734 double dLen_dL = (lastState_dL.getPropagationLen() - lastState.getPropagationLen()) / dL;
735 double dLen_dFic = (lastState_dFic.getPropagationLen() - lastState.getPropagationLen()) / dFic;
736
737 double dt_de = (dLen_de + sol.len * m_groupIndexDerivative / m_groupIndex) / speedOfLightQuartz;
738 double dt_dL = dLen_dL / speedOfLightQuartz;
739 double dt_dFic = dLen_dFic / speedOfLightQuartz;
740
741 double chromatic = pow(dt_de * m_yScanner->getRMSEnergy(), 2);
742
743 double DL = (dy_dFic * pixel.Dx - dx_dFic * pixel.Dy) / Jacobi;
744 double DFic = (dx_dL * pixel.Dy - dy_dL * pixel.Dx) / Jacobi;
745 double paralax = (pow(dt_dL * DL, 2) + pow(dt_dFic * DFic, 2)) / 12;
746
747 double scattering = pow(dLen_de * m_yScanner->getSigmaScattering() / speedOfLightQuartz, 2);
748
749 SignalPDF::PDFPeak peak;
750 peak.t0 = m_tof + sol.L / m_beta / Const::speedOfLight + sol.len / speedOfLightQuartz;
751 peak.wid = chromatic + paralax + scattering;
752 peak.nph = 1 - exp(-numPhotons); // because photons that pile-up are counted as one
753 peak.fic = atan2(sol.sinFic, sol.cosFic);
754 signalPDF.append(peak);
755
756 if (m_storeOption == c_Reduced) continue;
757
758 SignalPDF::PDFExtra extra;
759 extra.thc = acos(getCosCerenkovAngle(m_yScanner->getMeanEnergy()));
760 extra.e = m_yScanner->getMeanEnergy();
761 extra.sige = m_yScanner->getRMSEnergy();
762 extra.Nxe = Nxe;
763 extra.Nye = Nye;
764 extra.xD = lastState.getXD();
765 extra.yD = lastState.getYD();
766 extra.zD = lastState.getZD();
767 extra.kxE = firstState.getKx();
768 extra.kyE = firstState.getKy();
769 extra.kzE = firstState.getKz();
770 extra.kxD = lastState.getKx();
771 extra.kyD = lastState.getKy();
772 extra.kzD = lastState.getKz();
773 extra.type = SignalPDF::c_Direct;
774 signalPDF.append(extra);
775
776 } // reflections in y (unfolded prism windows)
777 } // reflections in x
778 } // pixels
779
780 }

◆ setSignalPDF_reflected() [1/2]

void setSignalPDF_reflected ( )
private

Sets signal PDF for reflected photons.

Definition at line 166 of file PDFConstructor.cc.

167 {
168 const auto& bar = m_inverseRaytracer->getBars().back();
169 const auto& prism = m_inverseRaytracer->getPrism();
170 const auto& mirror = m_inverseRaytracer->getMirror();
171 const auto& emiPoint = m_track.getEmissionPoint().position;
172
173 // determine the range of number of reflections in x before mirror
174
175 double xmi = 0, xma = 0;
176 bool ok = rangeOfX(mirror.zb, xmi, xma);
177 if (not ok) return;
178 int kmi = func::lround(xmi / bar.A);
179 int kma = func::lround(xma / bar.A);
180
181 // loop over reflections in x before mirror
182
183 double xE = emiPoint.X();
184 double zE = emiPoint.Z();
185 double Ah = bar.A / 2;
186 for (int k = kmi; k <= kma; k++) {
187 double x0 = findReflectionExtreme(xE, zE, prism.zD, k, bar.A, mirror);
188 x0 = func::clip(x0, k, bar.A, xmi, xma);
189 double xL = func::clip(-Ah, k, bar.A, xmi, xma);
190 double xR = func::clip(Ah, k, bar.A, xmi, xma);
191 if (x0 > xL) setSignalPDF_reflected(k, xL, x0);
192 if (x0 < xR) setSignalPDF_reflected(k, x0, xR);
193 }
194 }

◆ setSignalPDF_reflected() [2/2]

void setSignalPDF_reflected ( int Nxm,
double xmMin,
double xmMax )
private

Sets signal PDF for reflected photons at given reflection number.

Parameters
Nxmreflection number in x before mirror
xmMinlower limit of the reflection positions on the mirror
xmMaxupper limit of the reflection positions on the mirror

Definition at line 197 of file PDFConstructor.cc.

198 {
199 const auto& pixelPositions = m_yScanner->getPixelPositions();
200 const auto& bar = m_inverseRaytracer->getBars().back();
201 const auto& prism = m_inverseRaytracer->getPrism();
202
203 // determine the range of number of reflections in x after mirror
204
205 std::vector<double> xDs;
206 double minLen = 1e10;
207 if (not detectionPositionX(xmMin, Nxm, xDs, minLen)) return;
208 if (not detectionPositionX(xmMax, Nxm, xDs, minLen)) return;
209 if (xDs.size() < 2) return;
210
211 double minTime = m_tof + minLen * m_groupIndex / Const::speedOfLight;
212 if (minTime > m_maxTime) return;
213
214 std::sort(xDs.begin(), xDs.end());
215 double xmi = xDs.front();
216 double xma = xDs.back();
217
218 int kmi = func::lround(xmi / bar.A);
219 int kma = func::lround(xma / bar.A);
220
221 // loop over reflections in x after mirror and over pixel columns
222
223 for (int k = kmi; k <= kma; k++) {
224 for (unsigned col = 0; col < pixelPositions.getNumPixelColumns(); col++) {
225 const auto& pixel = pixelPositions.get(col + 1);
226 if (pixel.Dx == 0) continue;
227 double xD = func::unfold(pixel.xc, k, bar.A);
228 if (xD < xmi or xD > xma) continue;
229 InverseRaytracerReflected reflected;
230 setSignalPDF(reflected, col, xD, prism.zD, Nxm, xmMin, xmMax);
231 }
232 }
233
234 }

◆ switchDeltaRayPDF()

void switchDeltaRayPDF ( bool deltaPDFOn) const
inline

Include or exclude delta-ray PDF in log likelihood calculation.

Parameters
deltaPDFOntrue = include, false = exclude

Definition at line 130 of file PDFConstructor.h.

130{m_deltaPDFOn = deltaPDFOn;}

◆ switchOffDeltaRayPDF()

void switchOffDeltaRayPDF ( ) const
inline

Exclude delta-ray PDF in log likelihood calculation.

Definition at line 119 of file PDFConstructor.h.

119{m_deltaPDFOn = false;}

◆ switchOnDeltaRayPDF()

void switchOnDeltaRayPDF ( ) const
inline

Include delta-ray PDF in log likelihood calculation (this is default)

Definition at line 124 of file PDFConstructor.h.

124{m_deltaPDFOn = true;}

Member Data Documentation

◆ m_backgroundPDF

const BackgroundPDF* m_backgroundPDF = 0
private

background PDF

Definition at line 689 of file PDFConstructor.h.

◆ m_beta

double m_beta = 0
private

particle hypothesis beta

Definition at line 695 of file PDFConstructor.h.

◆ m_bkgPhotons

double m_bkgPhotons = 0
private

expected number of uniform background photons

Definition at line 711 of file PDFConstructor.h.

◆ m_bkgRate

double m_bkgRate = 0
private

estimated background hit rate

Definition at line 703 of file PDFConstructor.h.

◆ m_cerenkovAngle0

InverseRaytracer::CerenkovAngle m_cerenkovAngle0
private

sine and cosine of Cerenkov angle at dE = 0

Definition at line 715 of file PDFConstructor.h.

◆ m_cerenkovAngles

std::map<double, InverseRaytracer::CerenkovAngle> m_cerenkovAngles
private

sine and cosine of Cerenkov angles for dE != 0

Definition at line 714 of file PDFConstructor.h.

◆ m_cosTotal

double m_cosTotal = 0
private

cosine of total reflection angle

Definition at line 699 of file PDFConstructor.h.

◆ m_deltaPDFOn

bool m_deltaPDFOn = true
mutableprivate

include/exclude delta-ray PDF in likelihood calculation

Definition at line 724 of file PDFConstructor.h.

◆ m_deltaPhotons

double m_deltaPhotons = 0
private

expected number of delta-ray photons

Definition at line 712 of file PDFConstructor.h.

◆ m_deltaRayPDF

DeltaRayPDF m_deltaRayPDF
private

delta-ray PDF

Definition at line 690 of file PDFConstructor.h.

◆ m_derivatives

std::map<double, YScanner::Derivatives> m_derivatives
private

a map of xD and derivatives

Definition at line 725 of file PDFConstructor.h.

◆ m_dFic

double m_dFic = 0
private

temporary storage for dFic used in last call to deltaXD

Definition at line 716 of file PDFConstructor.h.

◆ m_f0

double m_f0 = 0
mutableprivate

temporary value of signal PDF

Definition at line 729 of file PDFConstructor.h.

◆ m_fastRaytracer

const FastRaytracer* m_fastRaytracer = 0
private

fast ray-tracer

Definition at line 686 of file PDFConstructor.h.

◆ m_Fic

double m_Fic = 0
private

temporary storage for Cerenkov azimuthal angle

Definition at line 717 of file PDFConstructor.h.

◆ m_groupIndex

double m_groupIndex = 0
private

group refractive index at mean photon energy

Definition at line 697 of file PDFConstructor.h.

◆ m_groupIndexDerivative

double m_groupIndexDerivative = 0
private

derivative (dn_g/dE) of group refractive index at mean photon energy

Definition at line 698 of file PDFConstructor.h.

◆ m_hasPeaks

bool m_hasPeaks = false
private

true if at least one pixel has a PDF peak

Definition at line 707 of file PDFConstructor.h.

◆ m_hypothesis

const Const::ChargedStable m_hypothesis
private

particle hypothesis

Definition at line 684 of file PDFConstructor.h.

◆ m_inverseRaytracer

const InverseRaytracer* m_inverseRaytracer = 0
private

inverse ray-tracer

Definition at line 685 of file PDFConstructor.h.

◆ m_maxPeakT0

double m_maxPeakT0 = 0
private

position of the latest PDF peak of all pixels [ns]

Definition at line 710 of file PDFConstructor.h.

◆ m_maxTime

double m_maxTime = 0
private

time window upper edge

Definition at line 701 of file PDFConstructor.h.

◆ m_minPeakT0

double m_minPeakT0 = 0
private

position of the earliest PDF peak of all pixels [ns]

Definition at line 709 of file PDFConstructor.h.

◆ m_minTime

double m_minTime = 0
private

time window lower edge

Definition at line 700 of file PDFConstructor.h.

◆ m_moduleID

int m_moduleID = 0
private

slot ID

Definition at line 682 of file PDFConstructor.h.

◆ m_ncallsExpandPDF

int m_ncallsExpandPDF[3] = {0, 0, 0}
private

number of calls to expandSignalPDF, indexed with SignalPDF::EPeakType

Definition at line 721 of file PDFConstructor.h.

721{0, 0, 0};

◆ m_ncallsSetPDF

int m_ncallsSetPDF[3] = {0, 0, 0}
private

number of calls to setSignalPDF<T>, indexed with SignalPDF::EPeakType

Definition at line 719 of file PDFConstructor.h.

719{0, 0, 0};

◆ m_PDFOption

EPDFOption m_PDFOption = c_Optimal
private

signal PDF construction option

Definition at line 691 of file PDFConstructor.h.

◆ m_pdfOtherTracks

std::vector<const PDFConstructor*> m_pdfOtherTracks
private

most probable PDF's of other tracks in the module

Definition at line 728 of file PDFConstructor.h.

◆ m_pixelLLs

std::vector<LogL> m_pixelLLs
mutableprivate

pixel log likelihoods (index = pixelID - 1)

Definition at line 722 of file PDFConstructor.h.

◆ m_pulls

std::vector<Pull> m_pulls
mutableprivate

photon pulls w.r.t PDF peaks

Definition at line 723 of file PDFConstructor.h.

◆ m_rayTracers

std::vector<FastRaytracer> m_rayTracers
private

copies of fast ray-tracer used to compute derivatives

Definition at line 687 of file PDFConstructor.h.

◆ m_selectedHits

std::vector<TOPTrack::SelectedHit> m_selectedHits
private

selected photon hits

Definition at line 702 of file PDFConstructor.h.

◆ m_signalPDFs

std::vector<SignalPDF> m_signalPDFs
private

parameterized signal PDF in pixels (index = pixelID - 1)

Definition at line 705 of file PDFConstructor.h.

◆ m_signalPhotons

double m_signalPhotons = 0
private

expected number of signal photons

Definition at line 706 of file PDFConstructor.h.

◆ m_storeOption

EStoreOption m_storeOption = c_Reduced
private

signal PDF storing option

Definition at line 692 of file PDFConstructor.h.

◆ m_sumOfPeaks

double m_sumOfPeaks = 0
private

sum over the pixels of the normalized number of photons in all peaks

Definition at line 708 of file PDFConstructor.h.

◆ m_tof

double m_tof = 0
private

time-of-flight from IP to average photon emission position

Definition at line 696 of file PDFConstructor.h.

◆ m_track

const TOPTrack& m_track
private

temporary reference to track at TOP

Definition at line 683 of file PDFConstructor.h.

◆ m_valid

bool m_valid = false
private

cross-check flag, true if track is valid and all the pointers above are valid

Definition at line 693 of file PDFConstructor.h.

◆ m_yScanner

const YScanner* m_yScanner = 0
private

PDF expander in y.

Definition at line 688 of file PDFConstructor.h.

◆ m_zeroPixels

std::set<int> m_zeroPixels
mutableprivate

collection of pixelID's with zero pdfValue

Definition at line 726 of file PDFConstructor.h.


The documentation for this class was generated from the following files: