Belle II Software  release-08-01-10
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 
23 namespace 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 
417  double prismEntranceY(double y, int k, double dydz) const;
418 
427  void projectPixel(double yc, double size, int k, double dydz, PixelProjection& proj) const;
428 
438  void scan(unsigned col, double yB, double dydz, const Derivatives& D, int j1, int j2) const;
439 
447  void merge(unsigned col, double dydz, int j1, int j2) const;
448 
454 
460 
461  // variables set in constructor (slot dependent)
466  double m_meanE0 = 0;
467  double m_rmsE0 = 0;
468  double m_cosTotal = 0;
470  // variables set in prepare method (track/hypothesis dependent)
471  mutable double m_momentum = 0;
472  mutable double m_beta = 0;
473  mutable double m_length = 0;
474  mutable double m_numPhotons = 0;
475  mutable double m_meanE = 0;
476  mutable double m_rmsE = 0;
477  mutable double m_sigmaScat = 0;
478  mutable double m_sigmaAlpha = 0;
480  mutable std::map<int, Table>
482  mutable Table* m_quasyEnergyDistribution = nullptr;
483  mutable bool m_aboveThreshold = false;
485  // results of expand method (pixel column dependent)
486  mutable std::vector<Result> m_results;
487  mutable bool m_scanDone = false;
489  static int s_maxReflections;
491  friend class TOPRecoManager;
492 
493  };
494 
495 
496  //--- inline functions ------------------------------------------------------------
497 
499  const InverseRaytracer::Solution& sol1)
500  {
501  return (sol1.len - sol0.len) / sol1.step;
502  }
503 
505  const InverseRaytracer::Solution& sol1)
506  {
507  return (sol1.yB - sol0.yB) / sol1.step;
508  }
509 
511  const InverseRaytracer::Solution& sol1)
512  {
513  if (std::abs(sol0.cosFic) > std::abs(sol0.sinFic)) {
514  return (sol1.sinFic - sol0.sinFic) / sol0.cosFic / sol1.step;
515  } else {
516  return -(sol1.cosFic - sol0.cosFic) / sol0.sinFic / sol1.step;
517  }
518  }
519 
521  {
522  x0 = 0;
523  step = 0;
524  entries.clear();
525  }
526 
527  inline void YScanner::Table::set(double X0, double Step)
528  {
529  x0 = X0;
530  step = Step;
531  entries.clear();
532  }
533 
534  inline void YScanner::Table::set(const Table& T)
535  {
536  x0 = T.x0;
537  step = T.step;
538  entries.clear();
539  }
540 
541  inline double YScanner::Table::getX(int i) const {return x0 + step * i;}
542 
543  inline double YScanner::Table::getXmin() const {return x0;}
544 
545  inline double YScanner::Table::getXmax() const {return x0 + step * (entries.size() - 1);}
546 
547  inline int YScanner::Table::getIndex(double x) const {return lround((x - x0) / step);}
548 
549  inline double YScanner::Table::getY(int i) const
550  {
551  unsigned k = i;
552  if (k >= entries.size()) return 0;
553  return entries[k].y;
554  }
555 
556  inline void YScanner::Result::set()
557  {
558  if (sum == 0) return;
559  e0 /= sum;
560  sigsq = std::max(sigsq / sum - e0 * e0, 0.0);
561  }
562 
563  } // namespace TOP
565 } // namespace Belle2
566 
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:468
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:479
const std::map< int, Table > getQuasyEnergyDistributions() const
Returns photon energy distributions convoluted with multiple scattering and surface roughness.
Definition: YScanner.h:372
double getMeanEnergyBeta1() const
Returns mean photon energy for beta = 1.
Definition: YScanner.h:341
PixelEfficiencies & pixelEfficiencies()
Returns non-const pixel relative efficiencies.
Definition: YScanner.h:459
PixelEfficiencies m_pixelEfficiencies
pixel relative efficiencies
Definition: YScanner.h:464
double m_beta
particle beta
Definition: YScanner.h:472
bool m_scanDone
true if scan performed, false if reflections just merged
Definition: YScanner.h:487
void projectPixel(double yc, double size, int k, double dydz, PixelProjection &proj) const
Calculates a projection of a pixel to prism entrance window (going down-stream the photon).
Definition: YScanner.cc:421
Table m_efficiency
nominal photon detection efficiencies (PDE)
Definition: YScanner.h:465
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:475
double getSigmaScattering() const
Returns r.m.s of multiple scattering angle in quartz converted to photon energy.
Definition: YScanner.h:353
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:489
const PixelPositions & getPixelPositions() const
Returns pixel positions and their sizes.
Definition: YScanner.h:269
double m_rmsE
r.m.s of photon energy
Definition: YScanner.h:476
const std::vector< Result > & getResults() const
Returns the results of PDF expansion in y.
Definition: YScanner.h:378
bool m_aboveThreshold
true if beta is above the Cerenkov threshold
Definition: YScanner.h:483
double m_sigmaScat
r.m.s.
Definition: YScanner.h:477
void merge(unsigned col, double dydz, int j1, int j2) const
Performs expansion by merging all reflections.
Definition: YScanner.cc:338
double getNumPhotonsPerLen() const
Returns number of photons per Cerenkov azimuthal angle per track length.
Definition: YScanner.h:317
PixelMasks & pixelMasks()
Returns non-const pixel masks.
Definition: YScanner.h:453
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:466
double m_momentum
particle momentum magnitude
Definition: YScanner.h:471
Table * m_quasyEnergyDistribution
a pointer to the element in m_quasyEnergyDistributions
Definition: YScanner.h:482
double getCosTotal() const
Returns cosine of total reflection angle.
Definition: YScanner.h:293
PixelMasks m_pixelMasks
pixel masks
Definition: YScanner.h:463
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:370
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
YScanner(int moduleID, unsigned N=64)
Class constructor.
Definition: YScanner.cc:47
const PixelEfficiencies & getPixelEfficiencies() const
Returns pixel relative efficiencies.
Definition: YScanner.h:281
std::map< int, Table > m_quasyEnergyDistributions
photon energy distributions convoluted with Gaussian of different widths
Definition: YScanner.h:481
const Table & getEnergyDistribution() const
Returns photon energy distribution.
Definition: YScanner.h:365
double getSigmaAlpha() const
Returns surface roughness parameter in units of photon energy.
Definition: YScanner.h:359
double prismEntranceY(double y, int k, double dydz) const
Calculates y at prism entrance from detection position, reflection number and photon slope.
Definition: YScanner.cc:411
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
double m_length
length of particle trajectory inside quartz
Definition: YScanner.h:473
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:467
const Table & getEfficiencies() const
Returns nominal photon detection efficiencies (PDE)
Definition: YScanner.h:287
bool isAboveThreshold() const
Returns above Cerenkov threshold flag which is set in the prepare method.
Definition: YScanner.h:251
std::vector< Result > m_results
results of PDF expansion in y
Definition: YScanner.h:486
const PixelMasks & getPixelMasks() const
Returns pixel masks.
Definition: YScanner.h:275
bool isScanDone() const
Checks which expansion method was used.
Definition: YScanner.h:384
PixelPositions m_pixelPositions
positions and sizes of pixels
Definition: YScanner.h:462
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:474
double m_sigmaAlpha
surface roughness parameter in photon energy units
Definition: YScanner.h:478
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:504
static double dLen_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of propagation length.
Definition: YScanner.h:498
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:510
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:556
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:549
int getIndex(double x) const
Returns index.
Definition: YScanner.h:547
std::vector< TableEntry > entries
table entries
Definition: YScanner.h:121
double getXmax() const
Returns x of the last entry.
Definition: YScanner.h:545
double getX(int i) const
Returns x for a given index.
Definition: YScanner.h:541
void clear()
Clear the content entirely.
Definition: YScanner.h:520
double getXmin() const
Returns x of the first entry.
Definition: YScanner.h:543
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:527