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 <algorithm>
19#include <cmath>
20#include <map>
21
22
23namespace Belle2 {
28 namespace TOP {
29
33 class YScanner : public RaytracerBase {
34
35 public:
36
40 struct Derivatives {
41 double dLen_dx = 0;
42 double dLen_de = 0;
43 double dLen_dL = 0;
44 double dyB_dx = 0;
45 double dyB_de = 0;
46 double dyB_dL = 0;
47 double dFic_dx = 0;
48 double dFic_de = 0;
49 double dFic_dL = 0;
50
55 {}
56
65 const InverseRaytracer::Solution& sol_dx,
66 const InverseRaytracer::Solution& sol_de,
67 const InverseRaytracer::Solution& sol_dL);
68
75 static double dLen_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
76
83 static double dyB_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
84
91 static double dFic_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
92 };
93
94
98 struct TableEntry {
99 double y = 0;
100 double x = 0;
101 double xsq = 0;
102
109 TableEntry(double Y, double X, double Xsq):
110 y(Y), x(X), xsq(Xsq)
111 {}
112 };
113
114
118 struct Table {
119 double x0 = 0;
120 double step = 0;
121 std::vector<TableEntry> entries;
122
127 {}
128
132 void clear();
133
139 void set(double X0, double Step);
140
145 void set(const Table& T);
146
151 double getX(int i) const;
152
157 double getXmin() const;
158
163 double getXmax() const;
164
169 int getIndex(double x) const;
170
175 double getY(int i) const;
176 };
177
178
183 double yc = 0;
184 double Dy = 0;
185 const EnergyMask* mask = 0;
186
188 bool operator<(const PixelProjection& other) const {return yc < other.yc;}
189 };
190
191
197 double sy = 0;
198 double sz = 0;
199 double y0 = 0;
200 double z0 = 0;
201 bool evenReflection = false;
202 };
203
204
208 struct Result {
209 int pixelID = 0;
210 double sum = 0;
211 double e0 = 0;
212 double sigsq = 0;
213
218 explicit Result(int ID): pixelID(ID)
219 {}
220
224 void set();
225 };
226
227
234 explicit YScanner(int moduleID, unsigned N = 64);
235
240 static void setScanLimits(int maxReflections)
241 {
242 s_maxReflections = maxReflections;
243 }
244
248 void clear() const;
249
258 void prepare(double momentum, double beta, double length) const;
259
264 bool isAboveThreshold() const {return m_aboveThreshold;}
265
276 void expand(unsigned col, double yB, double dydz, const Derivatives& D, int Ny, bool doScan) const;
277
283
288 const PixelMasks& getPixelMasks() const {return m_pixelMasks;}
289
295
300 const Table& getEfficiencies() const {return m_efficiency;}
301
306 double getCosTotal() const {return m_cosTotal;}
307
312 double getMomentum() const {return m_momentum;}
313
318 double getBeta() const {return m_beta;}
319
324 double getTrackLengthInQuartz() const {return m_length;}
325
330 double getNumPhotonsPerLen() const {return m_numPhotons;}
331
336 double getNumPhotons() const {return m_numPhotons * m_length;}
337
342 double getMeanEnergy() const {return m_meanE;}
343
348 double getRMSEnergy() const {return m_rmsE;}
349
354 double getMeanEnergyBeta1() const {return m_meanE0;}
355
360 double getRMSEnergyBeta1() const {return m_rmsE0;}
361
366 double getSigmaScattering() const {return m_sigmaScat;}
367
372 double getSigmaAlpha() const {return m_sigmaAlpha;}
373
381 double getSurfaceReflectivity(unsigned n) const
382 {
383 if (n < m_surfaceReflectivities.size()) return m_surfaceReflectivities[n];
385 }
386
392
398 const std::map<int, Table>& getQuasyEnergyDistributions() const {return m_quasyEnergyDistributions;}
399
404 const std::vector<Result>& getResults() const {return m_results;}
405
410 bool isScanDone() const {return m_scanDone;}
411
412
413 private:
414
420 double setEnergyDistribution(double beta) const;
421
426 void setQuasyEnergyDistribution(double sigma) const;
427
434 void integrate(const EnergyMask* energyMask, double Ecp, Result& result) const;
435
444 void projectPixel(double yc, double size, int k, double dydz, PixelProjection proj[2]) const
445 {
446 const auto& win = m_windowProjections[k];
447 double halfSize = win.evenReflection ? size / 2 : -size / 2;
448 const double ypix[2] = {yc - halfSize, yc + halfSize}; // pixel edges in y
449 double yproj[2][2] = {{0}}; // pixel projections to prism entrance window (second index corresponds to pixel edges)
450
451 #pragma omp simd
452 for (int i = 0; i < 2; ++i) {
453 /* Formerly YScanner::prismEntranceY. */
454 double z = ypix[i] * win.sz + win.z0;
455 double y = ypix[i] * win.sy + win.y0;
456 double dy = dydz * (m_prismZR - z);
457 yproj[0][i] = y + dy; // even reflections
458 yproj[1][i] = y - dy; // odd reflections
459 }
460
461 double Bh = m_halfBarThickness;
462 for (int i = 0; i < 2; ++i) {
463 yproj[i][0] = std::max(yproj[i][0], -Bh);
464 yproj[i][1] = std::min(yproj[i][1], Bh);
465 proj[i].yc = (yproj[i][0] + yproj[i][1]) / 2;
466 proj[i].Dy = yproj[i][1] - yproj[i][0];
467 }
468 }
469
476 double tabulateSurfaceReflectivity(unsigned n) const;
477
487 void scan(unsigned col, double yB, double dydz, const Derivatives& D, int j1, int j2) const;
488
496 void merge(unsigned col, double dydz, int j1, int j2) const;
497
503
509
510 // variables set in constructor or, for m_surfaceReflectivities, filled lazily on first use
511 // (slot dependent, therefore not reset by clear())
516 std::vector<WindowProjection> m_windowProjections;
517 mutable std::vector<double>
519 double m_prismZR = 0;
521 double m_meanE0 = 0;
522 double m_rmsE0 = 0;
523 double m_cosTotal = 0;
524
525 // variables set in prepare method (track/hypothesis dependent)
526 mutable double m_momentum = 0;
527 mutable double m_beta = 0;
528 mutable double m_length = 0;
529 mutable double m_numPhotons = 0;
530 mutable double m_meanE = 0;
531 mutable double m_rmsE = 0;
532 mutable double m_sigmaScat = 0;
533 mutable double m_sigmaAlpha = 0;
535 mutable std::map<int, Table>
537 mutable Table* m_quasyEnergyDistribution = nullptr;
538 mutable bool m_aboveThreshold = false;
539
540 // results of expand method (pixel column dependent)
541 mutable std::vector<Result> m_results;
542 mutable bool m_scanDone = false;
543
544 static int s_maxReflections;
545 static unsigned s_maxTabulatedPower;
546
547 friend class TOPRecoManager;
548
549 };
550
551
552 //--- inline functions ------------------------------------------------------------
553
555 const InverseRaytracer::Solution& sol1)
556 {
557 return (sol1.len - sol0.len) / sol1.step;
558 }
559
561 const InverseRaytracer::Solution& sol1)
562 {
563 return (sol1.yB - sol0.yB) / sol1.step;
564 }
565
567 const InverseRaytracer::Solution& sol1)
568 {
569 if (std::abs(sol0.cosFic) > std::abs(sol0.sinFic)) {
570 return (sol1.sinFic - sol0.sinFic) / sol0.cosFic / sol1.step;
571 } else {
572 return -(sol1.cosFic - sol0.cosFic) / sol0.sinFic / sol1.step;
573 }
574 }
575
577 {
578 x0 = 0;
579 step = 0;
580 entries.clear();
581 }
582
583 inline void YScanner::Table::set(double X0, double Step)
584 {
585 x0 = X0;
586 step = Step;
587 entries.clear();
588 }
589
590 inline void YScanner::Table::set(const Table& T)
591 {
592 x0 = T.x0;
593 step = T.step;
594 entries.clear();
595 }
596
597 inline double YScanner::Table::getX(int i) const {return x0 + step * i;}
598
599 inline double YScanner::Table::getXmin() const {return x0;}
600
601 inline double YScanner::Table::getXmax() const {return x0 + step * (entries.size() - 1);}
602
603 inline int YScanner::Table::getIndex(double x) const {return func::lround((x - x0) / step);}
604
605 inline double YScanner::Table::getY(int i) const
606 {
607 unsigned k = i;
608 if (k >= entries.size()) return 0;
609 return entries[k].y;
610 }
611
613 {
614 if (sum == 0) return;
615 e0 /= sum;
616 sigsq = std::max(sigsq / sum - e0 * e0, 0.0);
617 }
618
619 } // namespace TOP
621} // namespace Belle2
622
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:523
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:534
double getMeanEnergyBeta1() const
Returns mean photon energy for beta = 1.
Definition YScanner.h:354
static unsigned s_maxTabulatedPower
maximal power of the surface reflectivity that is tabulated
Definition YScanner.h:545
PixelEfficiencies m_pixelEfficiencies
pixel relative efficiencies
Definition YScanner.h:514
double m_beta
particle beta
Definition YScanner.h:527
bool m_scanDone
true if scan performed, false if reflections just merged
Definition YScanner.h:542
Table m_efficiency
nominal photon detection efficiencies (PDE)
Definition YScanner.h:515
double getRMSEnergyBeta1() const
Returns r.m.s of photon energy for beta = 1.
Definition YScanner.h:360
double m_meanE
mean photon energy
Definition YScanner.h:530
double getSigmaScattering() const
Returns r.m.s of multiple scattering angle in quartz converted to photon energy.
Definition YScanner.h:366
PixelMasks & pixelMasks()
Returns non-const pixel masks.
Definition YScanner.h:502
double getTrackLengthInQuartz() const
Returns particle trajectory length inside quartz.
Definition YScanner.h:324
static int s_maxReflections
maximal number of reflections to perform scan
Definition YScanner.h:544
double m_rmsE
r.m.s of photon energy
Definition YScanner.h:531
std::vector< double > m_surfaceReflectivities
bar surface reflectivity to the power of the index; filled on demand, never cleared
Definition YScanner.h:518
bool m_aboveThreshold
true if beta is above the Cerenkov threshold
Definition YScanner.h:538
double m_sigmaScat
r.m.s.
Definition YScanner.h:532
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:444
const std::map< int, Table > & getQuasyEnergyDistributions() const
Returns photon energy distributions convoluted with multiple scattering and surface roughness.
Definition YScanner.h:398
void merge(unsigned col, double dydz, int j1, int j2) const
Performs expansion by merging all reflections.
Definition YScanner.cc:377
double getNumPhotonsPerLen() const
Returns number of photons per Cerenkov azimuthal angle per track length.
Definition YScanner.h:330
const PixelPositions & getPixelPositions() const
Returns pixel positions and their sizes.
Definition YScanner.h:282
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:521
double m_momentum
particle momentum magnitude
Definition YScanner.h:526
const PixelMasks & getPixelMasks() const
Returns pixel masks.
Definition YScanner.h:288
Table * m_quasyEnergyDistribution
a pointer to the element in m_quasyEnergyDistributions
Definition YScanner.h:537
double getCosTotal() const
Returns cosine of total reflection angle.
Definition YScanner.h:306
PixelMasks m_pixelMasks
pixel masks
Definition YScanner.h:513
void setQuasyEnergyDistribution(double sigma) const
Sets photon energy distribution convoluted with a normalized Gaussian.
Definition YScanner.cc:223
void integrate(const EnergyMask *energyMask, double Ecp, Result &result) const
Integrates quasy energy distribution multiplied with energy mask.
Definition YScanner.cc:412
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:536
PixelEfficiencies & pixelEfficiencies()
Returns non-const pixel relative efficiencies.
Definition YScanner.h:508
std::vector< WindowProjection > m_windowProjections
pixel projection constants of unfolded prism exit windows
Definition YScanner.h:516
double getSurfaceReflectivity(unsigned n) const
Returns the reflectivity of the bar surface raised to the given power.
Definition YScanner.h:381
double getSigmaAlpha() const
Returns surface roughness parameter in units of photon energy.
Definition YScanner.h:372
const Table & getEnergyDistribution() const
Returns photon energy distribution.
Definition YScanner.h:391
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:240
const Table & getEfficiencies() const
Returns nominal photon detection efficiencies (PDE)
Definition YScanner.h:300
double m_length
length of particle trajectory inside quartz
Definition YScanner.h:528
double getNumPhotons() const
Returns number of photons per Cerenkov azimuthal angle.
Definition YScanner.h:336
double getMeanEnergy() const
Returns mean photon energy.
Definition YScanner.h:342
double m_rmsE0
r.m.s of photon energy for beta = 1
Definition YScanner.h:522
bool isAboveThreshold() const
Returns above Cerenkov threshold flag which is set in the prepare method.
Definition YScanner.h:264
std::vector< Result > m_results
results of PDF expansion in y
Definition YScanner.h:541
double m_prismZR
z of the prism-bar joint (copy of m_prism.zR)
Definition YScanner.h:519
const PixelEfficiencies & getPixelEfficiencies() const
Returns pixel relative efficiencies.
Definition YScanner.h:294
bool isScanDone() const
Checks which expansion method was used.
Definition YScanner.h:410
const std::vector< Result > & getResults() const
Returns the results of PDF expansion in y.
Definition YScanner.h:404
PixelPositions m_pixelPositions
positions and sizes of pixels
Definition YScanner.h:512
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:529
double m_halfBarThickness
half thickness of the bar at prism entrance
Definition YScanner.h:520
double m_sigmaAlpha
surface roughness parameter in photon energy units
Definition YScanner.h:533
double getRMSEnergy() const
Returns r.m.s of photon energy.
Definition YScanner.h:348
double getBeta() const
Returns particle beta.
Definition YScanner.h:318
double getMomentum() const
Returns particle momentum.
Definition YScanner.h:312
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:560
static double dLen_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of propagation length.
Definition YScanner.h:554
double dFic_de
Cerenkov azimuthal angle over photon energy.
Definition YScanner.h:48
double dLen_de
propagation length over photon energy
Definition YScanner.h:42
Derivatives()
Default constructor.
Definition YScanner.h:54
double dFic_dx
Cerenkov azimuthal angle over photon detection coordinate x.
Definition YScanner.h:47
double dFic_dL
Cerenkov azimuthal angle over running parameter of particle trajectory.
Definition YScanner.h:49
double dLen_dL
propagation length over running parameter of particle trajectory
Definition YScanner.h:43
double dyB_de
unfolded y coordinate at prism entrance over photon energy
Definition YScanner.h:45
double dLen_dx
propagation length over photon detection coordinate x
Definition YScanner.h:41
double dyB_dL
unfolded y coordinate at prism entrance over running parameter of particle trajectory
Definition YScanner.h:46
double dyB_dx
unfolded y coordinate at prism entrance over photon detection coordinate x
Definition YScanner.h:44
static double dFic_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of Cerenkov azimuthal angle.
Definition YScanner.h:566
Down-stream projection of a pixel to prism entrance window w/ a clip on bar exit thickness.
Definition YScanner.h:182
double yc
center in y of clipped pixel projection
Definition YScanner.h:183
bool operator<(const PixelProjection &other) const
operator "less than" needed for sorting
Definition YScanner.h:188
const EnergyMask * mask
the corresponding energy mask
Definition YScanner.h:185
double Dy
size in y of clipped pixel projection
Definition YScanner.h:184
double e0
mean photon energy of the peak
Definition YScanner.h:211
double sum
peak area proportional to number of photons
Definition YScanner.h:210
double sigsq
width of the peak squared, in photon energy units
Definition YScanner.h:212
void set()
Sets the mean and width-squared from the accumulated values.
Definition YScanner.h:612
Result(int ID)
Constructor with pixel ID.
Definition YScanner.h:218
int pixelID
pixel ID (1-based)
Definition YScanner.h:209
TableEntry(double Y, double X, double Xsq)
Constructor.
Definition YScanner.h:109
A table of equidistant entries.
Definition YScanner.h:118
Table()
Default constructor.
Definition YScanner.h:126
double getY(int i) const
Returns y for a given index.
Definition YScanner.h:605
int getIndex(double x) const
Returns index.
Definition YScanner.h:603
std::vector< TableEntry > entries
table entries
Definition YScanner.h:121
double getXmax() const
Returns x of the last entry.
Definition YScanner.h:601
double getX(int i) const
Returns x for a given index.
Definition YScanner.h:597
void clear()
Clear the content entirely.
Definition YScanner.h:576
double getXmin() const
Returns x of the first entry.
Definition YScanner.h:599
double x0
x of first entry
Definition YScanner.h:119
void set(double X0, double Step)
Sets the first x and the step, and clears the entries.
Definition YScanner.h:583
Geometry-only quantities needed to project a pixel to a given unfolded prism exit window.
Definition YScanner.h:196
double sz
window surface direction in z
Definition YScanner.h:198
double z0
z of the window origin, displaced to the prism entrance plane
Definition YScanner.h:200
bool evenReflection
true if the window has the same orientation as the true one
Definition YScanner.h:201
double sy
window surface direction in y
Definition YScanner.h:197
double y0
y of the window origin, displaced to the prism entrance plane
Definition YScanner.h:199