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;
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;
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;
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;
188 bool operator<(const PixelProjection& other) const {return yc < other.yc;}
189 };
190
191
195 struct Result {
196 int pixelID = 0;
197 double sum = 0;
198 double e0 = 0;
199 double sigsq = 0;
205 explicit Result(int ID): pixelID(ID)
206 {}
207
211 void set();
212 };
213
214
221 explicit YScanner(int moduleID, unsigned N = 64);
222
227 static void setScanLimits(int maxReflections)
228 {
229 s_maxReflections = maxReflections;
230 }
231
235 void clear() const;
236
245 void prepare(double momentum, double beta, double length) const;
246
251 bool isAboveThreshold() const {return m_aboveThreshold;}
252
263 void expand(unsigned col, double yB, double dydz, const Derivatives& D, int Ny, bool doScan) const;
264
270
275 const PixelMasks& getPixelMasks() const {return m_pixelMasks;}
276
282
287 const Table& getEfficiencies() const {return m_efficiency;}
288
293 double getCosTotal() const {return m_cosTotal;}
294
299 double getMomentum() const {return m_momentum;}
300
305 double getBeta() const {return m_beta;}
306
311 double getTrackLengthInQuartz() const {return m_length;}
312
317 double getNumPhotonsPerLen() const {return m_numPhotons;}
318
323 double getNumPhotons() const {return m_numPhotons * m_length;}
324
329 double getMeanEnergy() const {return m_meanE;}
330
335 double getRMSEnergy() const {return m_rmsE;}
336
341 double getMeanEnergyBeta1() const {return m_meanE0;}
342
347 double getRMSEnergyBeta1() const {return m_rmsE0;}
348
353 double getSigmaScattering() const {return m_sigmaScat;}
354
359 double getSigmaAlpha() const {return m_sigmaAlpha;}
360
366
372 const std::map<int, Table> getQuasyEnergyDistributions() const {return m_quasyEnergyDistributions;}
373
378 const std::vector<Result>& getResults() const {return m_results;}
379
384 bool isScanDone() const {return m_scanDone;}
385
386
387 private:
388
394 double setEnergyDistribution(double beta) const;
395
400 void setQuasyEnergyDistribution(double sigma) const;
401
408 void integrate(const EnergyMask* energyMask, double Ecp, Result& result) const;
409
418 void projectPixel(double yc, double size, int k, double dydz, PixelProjection proj[2]) const;
419
429 void scan(unsigned col, double yB, double dydz, const Derivatives& D, int j1, int j2) const;
430
438 void merge(unsigned col, double dydz, int j1, int j2) const;
439
445
451
452 // variables set in constructor (slot dependent)
457 double m_meanE0 = 0;
458 double m_rmsE0 = 0;
459 double m_cosTotal = 0;
461 // variables set in prepare method (track/hypothesis dependent)
462 mutable double m_momentum = 0;
463 mutable double m_beta = 0;
464 mutable double m_length = 0;
465 mutable double m_numPhotons = 0;
466 mutable double m_meanE = 0;
467 mutable double m_rmsE = 0;
468 mutable double m_sigmaScat = 0;
469 mutable double m_sigmaAlpha = 0;
471 mutable std::map<int, Table>
473 mutable Table* m_quasyEnergyDistribution = nullptr;
474 mutable bool m_aboveThreshold = false;
476 // results of expand method (pixel column dependent)
477 mutable std::vector<Result> m_results;
478 mutable bool m_scanDone = false;
480 static int s_maxReflections;
482 friend class TOPRecoManager;
483
484 };
485
486
487 //--- inline functions ------------------------------------------------------------
488
490 const InverseRaytracer::Solution& sol1)
491 {
492 return (sol1.len - sol0.len) / sol1.step;
493 }
494
496 const InverseRaytracer::Solution& sol1)
497 {
498 return (sol1.yB - sol0.yB) / sol1.step;
499 }
500
502 const InverseRaytracer::Solution& sol1)
503 {
504 if (std::abs(sol0.cosFic) > std::abs(sol0.sinFic)) {
505 return (sol1.sinFic - sol0.sinFic) / sol0.cosFic / sol1.step;
506 } else {
507 return -(sol1.cosFic - sol0.cosFic) / sol0.sinFic / sol1.step;
508 }
509 }
510
512 {
513 x0 = 0;
514 step = 0;
515 entries.clear();
516 }
517
518 inline void YScanner::Table::set(double X0, double Step)
519 {
520 x0 = X0;
521 step = Step;
522 entries.clear();
523 }
524
525 inline void YScanner::Table::set(const Table& T)
526 {
527 x0 = T.x0;
528 step = T.step;
529 entries.clear();
530 }
531
532 inline double YScanner::Table::getX(int i) const {return x0 + step * i;}
533
534 inline double YScanner::Table::getXmin() const {return x0;}
535
536 inline double YScanner::Table::getXmax() const {return x0 + step * (entries.size() - 1);}
537
538 inline int YScanner::Table::getIndex(double x) const {return lround((x - x0) / step);}
539
540 inline double YScanner::Table::getY(int i) const
541 {
542 unsigned k = i;
543 if (k >= entries.size()) return 0;
544 return entries[k].y;
545 }
546
548 {
549 if (sum == 0) return;
550 e0 /= sum;
551 sigsq = std::max(sigsq / sum - e0 * e0, 0.0);
552 }
553
554 } // namespace TOP
556} // namespace Belle2
557
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.
Base class with geometry data.
Definition: RaytracerBase.h:27
Singleton class providing pre-constructed reconstruction objects.
Utility for expanding the PDF in y direction.
Definition: YScanner.h:33
double m_cosTotal
cosine of total reflection angle
Definition: YScanner.h:459
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:118
Table m_energyDistribution
photon energy distribution
Definition: YScanner.h:470
double getMeanEnergyBeta1() const
Returns mean photon energy for beta = 1.
Definition: YScanner.h:341
PixelEfficiencies m_pixelEfficiencies
pixel relative efficiencies
Definition: YScanner.h:455
double m_beta
particle beta
Definition: YScanner.h:463
bool m_scanDone
true if scan performed, false if reflections just merged
Definition: YScanner.h:478
Table m_efficiency
nominal photon detection efficiencies (PDE)
Definition: YScanner.h:456
double getRMSEnergyBeta1() const
Returns r.m.s of photon energy for beta = 1.
Definition: YScanner.h:347
double m_meanE
mean photon energy
Definition: YScanner.h:466
double getSigmaScattering() const
Returns r.m.s of multiple scattering angle in quartz converted to photon energy.
Definition: YScanner.h:353
PixelMasks & pixelMasks()
Returns non-const pixel masks.
Definition: YScanner.h:444
double getTrackLengthInQuartz() const
Returns particle trajectory lenght inside quartz.
Definition: YScanner.h:311
static int s_maxReflections
maximal number of reflections to perform scan
Definition: YScanner.h:480
double m_rmsE
r.m.s of photon energy
Definition: YScanner.h:467
bool m_aboveThreshold
true if beta is above the Cerenkov threshold
Definition: YScanner.h:474
double m_sigmaScat
r.m.s.
Definition: YScanner.h:468
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.cc:409
void merge(unsigned col, double dydz, int j1, int j2) const
Performs expansion by merging all reflections.
Definition: YScanner.cc:337
double getNumPhotonsPerLen() const
Returns number of photons per Cerenkov azimuthal angle per track length.
Definition: YScanner.h:317
const PixelPositions & getPixelPositions() const
Returns pixel positions and their sizes.
Definition: YScanner.h:269
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:274
double m_meanE0
mean photon energy for beta = 1
Definition: YScanner.h:457
double m_momentum
particle momentum magnitude
Definition: YScanner.h:462
const PixelMasks & getPixelMasks() const
Returns pixel masks.
Definition: YScanner.h:275
Table * m_quasyEnergyDistribution
a pointer to the element in m_quasyEnergyDistributions
Definition: YScanner.h:473
double getCosTotal() const
Returns cosine of total reflection angle.
Definition: YScanner.h:293
PixelMasks m_pixelMasks
pixel masks
Definition: YScanner.h:454
void setQuasyEnergyDistribution(double sigma) const
Sets photon energy distribution convoluted with a normalized Gaussian.
Definition: YScanner.cc:192
void integrate(const EnergyMask *energyMask, double Ecp, Result &result) const
Integrates quasy energy distribution multiplied with energy mask.
Definition: YScanner.cc:368
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:238
std::map< int, Table > m_quasyEnergyDistributions
photon energy distributions convoluted with Gaussian of different widths
Definition: YScanner.h:472
PixelEfficiencies & pixelEfficiencies()
Returns non-const pixel relative efficiencies.
Definition: YScanner.h:450
double getSigmaAlpha() const
Returns surface roughness parameter in units of photon energy.
Definition: YScanner.h:359
const Table & getEnergyDistribution() const
Returns photon energy distribution.
Definition: YScanner.h:365
double setEnergyDistribution(double beta) const
Sets photon energy distribution and mean photon energy according to nominal PDE and particle beta.
Definition: YScanner.cc:163
static void setScanLimits(int maxReflections)
Sets parameters for selection between expand methods.
Definition: YScanner.h:227
const Table & getEfficiencies() const
Returns nominal photon detection efficiencies (PDE)
Definition: YScanner.h:287
double m_length
length of particle trajectory inside quartz
Definition: YScanner.h:464
double getNumPhotons() const
Returns number of photons per Cerenkov azimuthal angle.
Definition: YScanner.h:323
double getMeanEnergy() const
Returns mean photon energy.
Definition: YScanner.h:329
double m_rmsE0
r.m.s of photon energy for beta = 1
Definition: YScanner.h:458
bool isAboveThreshold() const
Returns above Cerenkov threshold flag which is set in the prepare method.
Definition: YScanner.h:251
const std::map< int, Table > getQuasyEnergyDistributions() const
Returns photon energy distributions convoluted with multiple scattering and surface roughness.
Definition: YScanner.h:372
std::vector< Result > m_results
results of PDF expansion in y
Definition: YScanner.h:477
const PixelEfficiencies & getPixelEfficiencies() const
Returns pixel relative efficiencies.
Definition: YScanner.h:281
bool isScanDone() const
Checks which expansion method was used.
Definition: YScanner.h:384
const std::vector< Result > & getResults() const
Returns the results of PDF expansion in y.
Definition: YScanner.h:378
PixelPositions m_pixelPositions
positions and sizes of pixels
Definition: YScanner.h:453
void clear() const
Clear mutable variables.
Definition: YScanner.cc:99
double m_numPhotons
number of photons per Cerenkov azimuthal angle per track length
Definition: YScanner.h:465
double m_sigmaAlpha
surface roughness parameter in photon energy units
Definition: YScanner.h:469
double getRMSEnergy() const
Returns r.m.s of photon energy.
Definition: YScanner.h:335
double getBeta() const
Returns particle beta.
Definition: YScanner.h:305
double getMomentum() const
Returns particle momentum.
Definition: YScanner.h:299
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:495
static double dLen_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of propagation length.
Definition: YScanner.h:489
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:501
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
Single PDF peak data.
Definition: YScanner.h:195
double e0
mean photon energy of the peak
Definition: YScanner.h:198
double sum
peak area proportional to number of photons
Definition: YScanner.h:197
double sigsq
width of the peak squared, in photon energy units
Definition: YScanner.h:199
void set()
Sets the mean and width-squared from the accumulated values.
Definition: YScanner.h:547
Result(int ID)
Constructor with pixel ID.
Definition: YScanner.h:205
int pixelID
pixel ID (1-based)
Definition: YScanner.h:196
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 step
step size
Definition: YScanner.h:120
double getY(int i) const
Returns y for a given index.
Definition: YScanner.h:540
int getIndex(double x) const
Returns index.
Definition: YScanner.h:538
std::vector< TableEntry > entries
table entries
Definition: YScanner.h:121
double getXmax() const
Returns x of the last entry.
Definition: YScanner.h:536
double getX(int i) const
Returns x for a given index.
Definition: YScanner.h:532
void clear()
Clear the content entirely.
Definition: YScanner.h:511
double getXmin() const
Returns x of the first entry.
Definition: YScanner.h:534
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:518