Belle II Software development
YScanner.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <top/reconstruction_cpp/RaytracerBase.h>
12#include <top/reconstruction_cpp/InverseRaytracer.h>
13#include <top/reconstruction_cpp/PixelPositions.h>
14#include <top/reconstruction_cpp/PixelMasks.h>
15#include <top/reconstruction_cpp/PixelEfficiencies.h>
16#include <top/reconstruction_cpp/EnergyMask.h>
17#include <vector>
18#include <deque>
19#include <algorithm>
20#include <cmath>
21#include <map>
22#include <utility>
23
24
25namespace Belle2 {
30 namespace TOP {
31
35 class YScanner : public RaytracerBase {
36
37 public:
38
42 struct Derivatives {
43 double dLen_dx = 0;
44 double dLen_de = 0;
45 double dLen_dL = 0;
46 double dyB_dx = 0;
47 double dyB_de = 0;
48 double dyB_dL = 0;
49 double dFic_dx = 0;
50 double dFic_de = 0;
51 double dFic_dL = 0;
52
57 {}
58
67 const InverseRaytracer::Solution& sol_dx,
68 const InverseRaytracer::Solution& sol_de,
69 const InverseRaytracer::Solution& sol_dL);
70
77 static double dLen_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
78
85 static double dyB_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
86
93 static double dFic_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
94 };
95
96
100 struct TableEntry {
101 double y = 0;
102 double x = 0;
103 double xsq = 0;
104
111 TableEntry(double Y, double X, double Xsq):
112 y(Y), x(X), xsq(Xsq)
113 {}
114 };
115
116
120 struct Table {
121 double x0 = 0;
122 double step = 0;
123 std::vector<TableEntry> entries;
124
129 {}
130
134 void clear();
135
141 void set(double X0, double Step);
142
147 void set(const Table& T);
148
153 double getX(int i) const;
154
159 double getXmin() const;
160
165 double getXmax() const;
166
171 int getIndex(double x) const;
172
177 double getY(int i) const;
178 };
179
180
185 double yc = 0;
186 double Dy = 0;
187 const EnergyMask* mask = 0;
188
190 bool operator<(const PixelProjection& other) const {return yc < other.yc;}
191 };
192
193
199 double sy = 0;
200 double sz = 0;
201 double y0 = 0;
202 double z0 = 0;
203 bool evenReflection = false;
204 };
205
206
210 struct Result {
211 int pixelID = 0;
212 double sum = 0;
213 double e0 = 0;
214 double sigsq = 0;
215
220 explicit Result(int ID): pixelID(ID)
221 {}
222
226 void set();
227 };
228
229
236 explicit YScanner(int moduleID, unsigned N = 64);
237
242 static void setScanLimits(int maxReflections)
243 {
244 s_maxReflections = maxReflections;
245 }
246
250 void clear() const;
251
260 void prepare(double momentum, double beta, double length) const;
261
266 bool isAboveThreshold() const {return m_aboveThreshold;}
267
278 void expand(unsigned col, double yB, double dydz, const Derivatives& D, int Ny, bool doScan) const;
279
285
290 const PixelMasks& getPixelMasks() const {return m_pixelMasks;}
291
297
302 const Table& getEfficiencies() const {return m_efficiency;}
303
308 double getCosTotal() const {return m_cosTotal;}
309
314 double getMomentum() const {return m_momentum;}
315
320 double getBeta() const {return m_beta;}
321
326 double getTrackLengthInQuartz() const {return m_length;}
327
332 double getNumPhotonsPerLen() const {return m_numPhotons;}
333
338 double getNumPhotons() const {return m_numPhotons * m_length;}
339
344 double getMeanEnergy() const {return m_meanE;}
345
350 double getRMSEnergy() const {return m_rmsE;}
351
356 double getMeanEnergyBeta1() const {return m_meanE0;}
357
362 double getRMSEnergyBeta1() const {return m_rmsE0;}
363
368 double getSigmaScattering() const {return m_sigmaScat;}
369
374 double getSigmaAlpha() const {return m_sigmaAlpha;}
375
383 double getSurfaceReflectivity(unsigned n) const
384 {
385 if (n < m_surfaceReflectivities.size()) return m_surfaceReflectivities[n];
387 }
388
394
400 const std::map<int, Table>& getQuasyEnergyDistributions() const {return m_quasyEnergyDistributions;}
401
406 const std::vector<Result>& getResults() const {return m_results;}
407
412 bool isScanDone() const {return m_scanDone;}
413
414
415 private:
416
422 double setEnergyDistribution(double beta) const;
423
428 void setQuasyEnergyDistribution(double sigma) const;
429
436 void integrate(const EnergyMask* energyMask, double Ecp, Result& result) const;
437
446 void projectPixel(double yc, double size, int k, double dydz, PixelProjection proj[2]) const
447 {
448 const auto& win = m_windowProjections[k];
449 double halfSize = win.evenReflection ? size / 2 : -size / 2;
450 const double ypix[2] = {yc - halfSize, yc + halfSize}; // pixel edges in y
451 double yproj[2][2] = {{0}}; // pixel projections to prism entrance window (second index corresponds to pixel edges)
452
453 #pragma omp simd
454 for (int i = 0; i < 2; ++i) {
455 /* Formerly YScanner::prismEntranceY. */
456 double z = ypix[i] * win.sz + win.z0;
457 double y = ypix[i] * win.sy + win.y0;
458 double dy = dydz * (m_prismZR - z);
459 yproj[0][i] = y + dy; // even reflections
460 yproj[1][i] = y - dy; // odd reflections
461 }
462
463 double Bh = m_halfBarThickness;
464 for (int i = 0; i < 2; ++i) {
465 yproj[i][0] = std::max(yproj[i][0], -Bh);
466 yproj[i][1] = std::min(yproj[i][1], Bh);
467 proj[i].yc = (yproj[i][0] + yproj[i][1]) / 2;
468 proj[i].Dy = yproj[i][1] - yproj[i][0];
469 }
470 }
471
478 double tabulateSurfaceReflectivity(unsigned n) const;
479
489 void scan(unsigned col, double yB, double dydz, const Derivatives& D, int j1, int j2) const;
490
498 void merge(unsigned col, double dydz, int j1, int j2) const;
499
505
511
512 // variables set in constructor or, for m_surfaceReflectivities, filled lazily on first use
513 // (slot dependent, therefore not reset by clear())
518 std::vector<WindowProjection> m_windowProjections;
519 mutable std::vector<double>
521 double m_prismZR = 0;
523 double m_meanE0 = 0;
524 double m_rmsE0 = 0;
525 double m_cosTotal = 0;
526
527 // variables set in prepare method (track/hypothesis dependent)
528 mutable double m_momentum = 0;
529 mutable double m_beta = 0;
530 mutable double m_length = 0;
531 mutable double m_numPhotons = 0;
532 mutable double m_meanE = 0;
533 mutable double m_rmsE = 0;
534 mutable double m_sigmaScat = 0;
535 mutable double m_sigmaAlpha = 0;
537 mutable std::map<int, Table>
539 mutable Table* m_quasyEnergyDistribution = nullptr;
540 mutable bool m_aboveThreshold = false;
541
542 // scratch space of the scan method, re-used by the subsequent calls
543 mutable std::deque<EnergyMask> m_maskPool;
544
545 // results of expand method (pixel column dependent)
546 mutable std::vector<Result> m_results;
547 mutable bool m_scanDone = false;
548
549 static int s_maxReflections;
550 static unsigned s_maxTabulatedPower;
551
552 friend class TOPRecoManager;
553
554 };
555
556
557 //--- inline functions ------------------------------------------------------------
558
560 const InverseRaytracer::Solution& sol1)
561 {
562 return (sol1.len - sol0.len) / sol1.step;
563 }
564
566 const InverseRaytracer::Solution& sol1)
567 {
568 return (sol1.yB - sol0.yB) / sol1.step;
569 }
570
572 const InverseRaytracer::Solution& sol1)
573 {
574 if (std::abs(sol0.cosFic) > std::abs(sol0.sinFic)) {
575 return (sol1.sinFic - sol0.sinFic) / sol0.cosFic / sol1.step;
576 } else {
577 return -(sol1.cosFic - sol0.cosFic) / sol0.sinFic / sol1.step;
578 }
579 }
580
582 {
583 x0 = 0;
584 step = 0;
585 entries.clear();
586 }
587
588 inline void YScanner::Table::set(double X0, double Step)
589 {
590 x0 = X0;
591 step = Step;
592 entries.clear();
593 }
594
595 inline void YScanner::Table::set(const Table& T)
596 {
597 x0 = T.x0;
598 step = T.step;
599 entries.clear();
600 }
601
602 inline double YScanner::Table::getX(int i) const {return x0 + step * i;}
603
604 inline double YScanner::Table::getXmin() const {return x0;}
605
606 inline double YScanner::Table::getXmax() const {return x0 + step * (entries.size() - 1);}
607
608 inline int YScanner::Table::getIndex(double x) const {return func::lround((x - x0) / step);}
609
610 inline double YScanner::Table::getY(int i) const
611 {
612 unsigned k = i;
613 if (k >= entries.size()) return 0;
614 return entries[k].y;
615 }
616
618 {
619 if (sum == 0) return;
620 e0 /= sum;
621 sigsq = std::max(sigsq / sum - e0 * e0, 0.0);
622 }
623
624 } // namespace TOP
626} // namespace Belle2
627
A mask for energy masking.
Definition EnergyMask.h:24
Pixel relative efficiencies of a single module.
Pixel masks of a single module.
Definition PixelMasks.h:22
Pixel positions and dimensions in module local frame.
RaytracerBase(int moduleID, EGeometry geometry=c_Unified, EOptics optics=c_SemiLinear)
Constructor.
double m_cosTotal
cosine of total reflection angle
Definition YScanner.h:525
void prepare(double momentum, double beta, double length) const
Prepare for the PDF expansion in y for a given track mass hypothesis.
Definition YScanner.cc:149
Table m_energyDistribution
photon energy distribution
Definition YScanner.h:536
double getMeanEnergyBeta1() const
Returns mean photon energy for beta = 1.
Definition YScanner.h:356
static unsigned s_maxTabulatedPower
maximal power of the surface reflectivity that is tabulated
Definition YScanner.h:550
PixelEfficiencies m_pixelEfficiencies
pixel relative efficiencies
Definition YScanner.h:516
double m_beta
particle beta
Definition YScanner.h:529
bool m_scanDone
true if scan performed, false if reflections just merged
Definition YScanner.h:547
Table m_efficiency
nominal photon detection efficiencies (PDE)
Definition YScanner.h:517
double getRMSEnergyBeta1() const
Returns r.m.s of photon energy for beta = 1.
Definition YScanner.h:362
double m_meanE
mean photon energy
Definition YScanner.h:532
double getSigmaScattering() const
Returns r.m.s of multiple scattering angle in quartz converted to photon energy.
Definition YScanner.h:368
PixelMasks & pixelMasks()
Returns non-const pixel masks.
Definition YScanner.h:504
double getTrackLengthInQuartz() const
Returns particle trajectory length inside quartz.
Definition YScanner.h:326
static int s_maxReflections
maximal number of reflections to perform scan
Definition YScanner.h:549
double m_rmsE
r.m.s of photon energy
Definition YScanner.h:533
std::vector< double > m_surfaceReflectivities
bar surface reflectivity to the power of the index; filled on demand, never cleared
Definition YScanner.h:520
bool m_aboveThreshold
true if beta is above the Cerenkov threshold
Definition YScanner.h:540
double m_sigmaScat
r.m.s.
Definition YScanner.h:534
void projectPixel(double yc, double size, int k, double dydz, PixelProjection proj[2]) const
Calculates projections of a pixel to prism entrance window (going down-stream the photon).
Definition YScanner.h:446
const std::map< int, Table > & getQuasyEnergyDistributions() const
Returns photon energy distributions convoluted with multiple scattering and surface roughness.
Definition YScanner.h:400
void merge(unsigned col, double dydz, int j1, int j2) const
Performs expansion by merging all reflections.
Definition YScanner.cc:382
double getNumPhotonsPerLen() const
Returns number of photons per Cerenkov azimuthal angle per track length.
Definition YScanner.h:332
const PixelPositions & getPixelPositions() const
Returns pixel positions and their sizes.
Definition YScanner.h:284
void scan(unsigned col, double yB, double dydz, const Derivatives &D, int j1, int j2) const
Performs expansion w/ the scan over reflections.
Definition YScanner.cc:310
double tabulateSurfaceReflectivity(unsigned n) const
Extends the table of surface reflectivity powers up to n and returns the value.
Definition YScanner.cc:116
double m_meanE0
mean photon energy for beta = 1
Definition YScanner.h:523
double m_momentum
particle momentum magnitude
Definition YScanner.h:528
const PixelMasks & getPixelMasks() const
Returns pixel masks.
Definition YScanner.h:290
Table * m_quasyEnergyDistribution
a pointer to the element in m_quasyEnergyDistributions
Definition YScanner.h:539
double getCosTotal() const
Returns cosine of total reflection angle.
Definition YScanner.h:308
PixelMasks m_pixelMasks
pixel masks
Definition YScanner.h:515
void setQuasyEnergyDistribution(double sigma) const
Sets photon energy distribution convoluted with a normalized Gaussian.
Definition YScanner.cc:223
std::deque< EnergyMask > m_maskPool
energy masks, grown on demand and never released
Definition YScanner.h:543
void integrate(const EnergyMask *energyMask, double Ecp, Result &result) const
Integrates quasy energy distribution multiplied with energy mask.
Definition YScanner.cc:417
void expand(unsigned col, double yB, double dydz, const Derivatives &D, int Ny, bool doScan) const
Performs the PDF expansion in y for a given pixel column using scan or merge methods.
Definition YScanner.cc:274
YScanner(int moduleID, unsigned N=64)
Class constructor.
Definition YScanner.cc:48
std::map< int, Table > m_quasyEnergyDistributions
photon energy distributions convoluted with Gaussian of different widths
Definition YScanner.h:538
PixelEfficiencies & pixelEfficiencies()
Returns non-const pixel relative efficiencies.
Definition YScanner.h:510
std::vector< WindowProjection > m_windowProjections
pixel projection constants of unfolded prism exit windows
Definition YScanner.h:518
double getSurfaceReflectivity(unsigned n) const
Returns the reflectivity of the bar surface raised to the given power.
Definition YScanner.h:383
double getSigmaAlpha() const
Returns surface roughness parameter in units of photon energy.
Definition YScanner.h:374
const Table & getEnergyDistribution() const
Returns photon energy distribution.
Definition YScanner.h:393
double setEnergyDistribution(double beta) const
Sets photon energy distribution and mean photon energy according to nominal PDE and particle beta.
Definition YScanner.cc:194
static void setScanLimits(int maxReflections)
Sets parameters for selection between expand methods.
Definition YScanner.h:242
const Table & getEfficiencies() const
Returns nominal photon detection efficiencies (PDE)
Definition YScanner.h:302
double m_length
length of particle trajectory inside quartz
Definition YScanner.h:530
double getNumPhotons() const
Returns number of photons per Cerenkov azimuthal angle.
Definition YScanner.h:338
double getMeanEnergy() const
Returns mean photon energy.
Definition YScanner.h:344
double m_rmsE0
r.m.s of photon energy for beta = 1
Definition YScanner.h:524
bool isAboveThreshold() const
Returns above Cerenkov threshold flag which is set in the prepare method.
Definition YScanner.h:266
std::vector< Result > m_results
results of PDF expansion in y
Definition YScanner.h:546
double m_prismZR
z of the prism-bar joint (copy of m_prism.zR)
Definition YScanner.h:521
const PixelEfficiencies & getPixelEfficiencies() const
Returns pixel relative efficiencies.
Definition YScanner.h:296
bool isScanDone() const
Checks which expansion method was used.
Definition YScanner.h:412
const std::vector< Result > & getResults() const
Returns the results of PDF expansion in y.
Definition YScanner.h:406
PixelPositions m_pixelPositions
positions and sizes of pixels
Definition YScanner.h:514
void clear() const
Clear mutable variables.
Definition YScanner.cc:130
double m_numPhotons
number of photons per Cerenkov azimuthal angle per track length
Definition YScanner.h:531
double m_halfBarThickness
half thickness of the bar at prism entrance
Definition YScanner.h:522
double m_sigmaAlpha
surface roughness parameter in photon energy units
Definition YScanner.h:535
double getRMSEnergy() const
Returns r.m.s of photon energy.
Definition YScanner.h:350
double getBeta() const
Returns particle beta.
Definition YScanner.h:320
double getMomentum() const
Returns particle momentum.
Definition YScanner.h:314
long lround(double x)
Rounds to the nearest integer, halfway cases away from zero.
Definition func.h:31
Abstract base class for different kinds of events.
Solution of inverse ray-tracing.
double yB
unfolded coordinate y of photon at Bar exit plane
double step
step for numerical derivative calculation
double cosFic
cosine of azimuthal Cerenkov angle
double sinFic
sine of azimuthal Cerenkov angle
double len
propagation length to detector plane
static double dyB_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of unfolded y coordinate at prism entrance.
Definition YScanner.h:565
static double dLen_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of propagation length.
Definition YScanner.h:559
double dFic_de
Cerenkov azimuthal angle over photon energy.
Definition YScanner.h:50
double dLen_de
propagation length over photon energy
Definition YScanner.h:44
Derivatives()
Default constructor.
Definition YScanner.h:56
double dFic_dx
Cerenkov azimuthal angle over photon detection coordinate x.
Definition YScanner.h:49
double dFic_dL
Cerenkov azimuthal angle over running parameter of particle trajectory.
Definition YScanner.h:51
double dLen_dL
propagation length over running parameter of particle trajectory
Definition YScanner.h:45
double dyB_de
unfolded y coordinate at prism entrance over photon energy
Definition YScanner.h:47
double dLen_dx
propagation length over photon detection coordinate x
Definition YScanner.h:43
double dyB_dL
unfolded y coordinate at prism entrance over running parameter of particle trajectory
Definition YScanner.h:48
double dyB_dx
unfolded y coordinate at prism entrance over photon detection coordinate x
Definition YScanner.h:46
static double dFic_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of Cerenkov azimuthal angle.
Definition YScanner.h:571
Down-stream projection of a pixel to prism entrance window w/ a clip on bar exit thickness.
Definition YScanner.h:184
double yc
center in y of clipped pixel projection
Definition YScanner.h:185
bool operator<(const PixelProjection &other) const
operator "less than" needed for sorting
Definition YScanner.h:190
const EnergyMask * mask
the corresponding energy mask
Definition YScanner.h:187
double Dy
size in y of clipped pixel projection
Definition YScanner.h:186
double e0
mean photon energy of the peak
Definition YScanner.h:213
double sum
peak area proportional to number of photons
Definition YScanner.h:212
double sigsq
width of the peak squared, in photon energy units
Definition YScanner.h:214
void set()
Sets the mean and width-squared from the accumulated values.
Definition YScanner.h:617
Result(int ID)
Constructor with pixel ID.
Definition YScanner.h:220
int pixelID
pixel ID (1-based)
Definition YScanner.h:211
TableEntry(double Y, double X, double Xsq)
Constructor.
Definition YScanner.h:111
A table of equidistant entries.
Definition YScanner.h:120
Table()
Default constructor.
Definition YScanner.h:128
double getY(int i) const
Returns y for a given index.
Definition YScanner.h:610
int getIndex(double x) const
Returns index.
Definition YScanner.h:608
std::vector< TableEntry > entries
table entries
Definition YScanner.h:123
double getXmax() const
Returns x of the last entry.
Definition YScanner.h:606
double getX(int i) const
Returns x for a given index.
Definition YScanner.h:602
void clear()
Clear the content entirely.
Definition YScanner.h:581
double getXmin() const
Returns x of the first entry.
Definition YScanner.h:604
double x0
x of first entry
Definition YScanner.h:121
void set(double X0, double Step)
Sets the first x and the step, and clears the entries.
Definition YScanner.h:588
Geometry-only quantities needed to project a pixel to a given unfolded prism exit window.
Definition YScanner.h:198
double sz
window surface direction in z
Definition YScanner.h:200
double z0
z of the window origin, displaced to the prism entrance plane
Definition YScanner.h:202
bool evenReflection
true if the window has the same orientation as the true one
Definition YScanner.h:203
double sy
window surface direction in y
Definition YScanner.h:199
double y0
y of the window origin, displaced to the prism entrance plane
Definition YScanner.h:201