Belle II Software  release-06-01-15
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 
20 
21 namespace Belle2 {
26  namespace TOP {
27 
31  class YScanner : public RaytracerBase {
32 
33  public:
34 
38  struct Derivatives {
39  double dLen_dx = 0;
40  double dLen_de = 0;
41  double dLen_dL = 0;
42  double dyD_dx = 0;
43  double dyD_de = 0;
44  double dyD_dL = 0;
45  double dyB_dx = 0;
46  double dyB_de = 0;
47  double dyB_dL = 0;
48  double dFic_dx = 0;
49  double dFic_de = 0;
50  double dFic_dL = 0;
56  {}
57 
66  const InverseRaytracer::Solution& sol_dx,
67  const InverseRaytracer::Solution& sol_de,
68  const InverseRaytracer::Solution& sol_dL);
69 
76  double dLen_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
77 
84  double dyD_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
85 
92  double dyB_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
93 
100  double dFic_d(const InverseRaytracer::Solution& sol0, const InverseRaytracer::Solution& sol1);
101  };
102 
103 
107  struct TableEntry {
108  double y = 0;
109  double x = 0;
110  double xsq = 0;
118  TableEntry(double Y, double X, double Xsq):
119  y(Y), x(X), xsq(Xsq)
120  {}
121  };
122 
123 
127  struct Table {
128  double x0 = 0;
129  double step = 0;
130  std::vector<TableEntry> entries;
136  {}
137 
141  void clear();
142 
148  void set(double X0, double Step);
149 
154  void set(const Table& T);
155 
160  double getX(int i) const;
161 
166  double getXmin() const;
167 
172  double getXmax() const;
173 
178  int getIndex(double x) const;
179 
184  double getY(int i) const;
185  };
186 
187 
192  double yc = 0;
193  double Dy = 0;
194  const EnergyMask* mask = 0;
197  bool operator<(const PixelProjection& other) const {return yc < other.yc;}
198  };
199 
200 
204  struct Result {
205  int pixelID = 0;
206  double sum = 0;
207  double e0 = 0;
208  double sigsq = 0;
214  explicit Result(int ID): pixelID(ID)
215  {}
216 
220  void set();
221  };
222 
223 
230  explicit YScanner(int moduleID, unsigned N = 64);
231 
236  static void setScanLimits(int maxReflections)
237  {
238  s_maxReflections = maxReflections;
239  }
240 
244  void clear() const;
245 
254  void prepare(double momentum, double beta, double length) const;
255 
260  bool isAboveThreshold() const {return m_aboveThreshold;}
261 
271  void expand(unsigned col, double yB, double dydz, const Derivatives& D, bool doScan) const;
272 
278 
283  const PixelMasks& getPixelMasks() const {return m_pixelMasks;}
284 
290 
295  const Table& getEfficiencies() const {return m_efficiency;}
296 
301  double getCosTotal() const {return m_cosTotal;}
302 
307  double getMomentum() const {return m_momentum;}
308 
313  double getBeta() const {return m_beta;}
314 
319  double getTrackLengthInQuartz() const {return m_length;}
320 
325  double getNumPhotonsPerLen() const {return m_numPhotons;}
326 
331  double getNumPhotons() const {return m_numPhotons * m_length;}
332 
337  double getMeanEnergy() const {return m_meanE;}
338 
343  double getRMSEnergy() const {return m_rmsE;}
344 
349  double getMeanEnergyBeta1() const {return m_meanE0;}
350 
355  double getRMSEnergyBeta1() const {return m_rmsE0;}
356 
361  double getSigmaScattering() const {return m_sigmaScat;}
362 
368 
374 
379  const std::vector<Result>& getResults() const {return m_results;}
380 
385  bool isScanDone() const {return m_scanDone;}
386 
387 
388  private:
389 
395  double setEnergyDistribution(double beta) const;
396 
403  void integrate(const EnergyMask* energyMask, double Ecp, Result& result) const;
404 
412  double prismEntranceY(double y, int k, double dydz) const;
413 
422  void projectPixel(double yc, double size, int k, double dydz, PixelProjection& proj) const;
423 
433  void scan(unsigned col, double yB, double dydz, const Derivatives& D, int j1, int j2) const;
434 
442  void merge(unsigned col, double dydz, int j1, int j2) const;
443 
449 
455 
456  // variables set in constructor (slot dependent)
461  double m_meanE0 = 0;
462  double m_rmsE0 = 0;
463  double m_cosTotal = 0;
465  // variables set in prepare method (track/hypothesis dependent)
466  mutable double m_momentum = 0;
467  mutable double m_beta = 0;
468  mutable double m_length = 0;
469  mutable double m_numPhotons = 0;
470  mutable double m_meanE = 0;
471  mutable double m_rmsE = 0;
472  mutable double m_sigmaScat = 0;
475  mutable bool m_aboveThreshold = false;
477  // results of expand method (pixel column dependent)
478  mutable std::vector<Result> m_results;
479  mutable bool m_scanDone = false;
481  static int s_maxReflections;
483  friend class TOPRecoManager;
484 
485  };
486 
487 
488  //--- inline functions ------------------------------------------------------------
489 
491  const InverseRaytracer::Solution& sol1)
492  {
493  return (sol1.len - sol0.len) / sol1.step;
494  }
495 
497  const InverseRaytracer::Solution& sol1)
498  {
499  return (sol1.yD - sol0.yD) / sol1.step;
500  }
501 
503  const InverseRaytracer::Solution& sol1)
504  {
505  return (sol1.yB - sol0.yB) / sol1.step;
506  }
507 
509  const InverseRaytracer::Solution& sol1)
510  {
511  if (abs(sol0.cosFic) > abs(sol0.sinFic)) {
512  return (sol1.sinFic - sol0.sinFic) / sol0.cosFic / sol1.step;
513  } else {
514  return -(sol1.cosFic - sol0.cosFic) / sol0.sinFic / sol1.step;
515  }
516  }
517 
519  {
520  x0 = 0;
521  step = 0;
522  entries.clear();
523  }
524 
525  inline void YScanner::Table::set(double X0, double Step)
526  {
527  x0 = X0;
528  step = Step;
529  entries.clear();
530  }
531 
532  inline void YScanner::Table::set(const Table& T)
533  {
534  x0 = T.x0;
535  step = T.step;
536  entries.clear();
537  }
538 
539  inline double YScanner::Table::getX(int i) const {return x0 + step * i;}
540 
541  inline double YScanner::Table::getXmin() const {return x0;}
542 
543  inline double YScanner::Table::getXmax() const {return x0 + step * (entries.size() - 1);}
544 
545  inline int YScanner::Table::getIndex(double x) const {return lround((x - x0) / step);}
546 
547  inline double YScanner::Table::getY(int i) const
548  {
549  unsigned k = i;
550  if (k >= entries.size()) return 0;
551  return entries[k].y;
552  }
553 
554  inline void YScanner::Result::set()
555  {
556  if (sum == 0) return;
557  e0 /= sum;
558  sigsq = std::max(sigsq / sum - e0 * e0, 0.0);
559  }
560 
561  } // namespace TOP
563 } // namespace Belle2
564 
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:31
double m_cosTotal
cosine of total reflection angle
Definition: YScanner.h:463
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:121
Table m_energyDistribution
photon energy distribution
Definition: YScanner.h:473
Table m_quasyEnergyDistribution
photon energy distribution convoluted with multiple scattering
Definition: YScanner.h:474
double getMeanEnergyBeta1() const
Returns mean photon energy for beta = 1.
Definition: YScanner.h:349
PixelEfficiencies & pixelEfficiencies()
Returns non-const pixel relative efficiencies.
Definition: YScanner.h:454
PixelEfficiencies m_pixelEfficiencies
pixel relative efficiencies
Definition: YScanner.h:459
double m_beta
particle beta
Definition: YScanner.h:467
bool m_scanDone
true if scan performed, false if reflections just merged
Definition: YScanner.h:479
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:397
Table m_efficiency
nominal photon detection efficiencies (PDE)
Definition: YScanner.h:460
double getRMSEnergyBeta1() const
Returns r.m.s of photon energy for beta = 1.
Definition: YScanner.h:355
double m_meanE
mean photon energy
Definition: YScanner.h:470
double getSigmaScattering() const
Returns r.m.s of multiple scattering angle in quartz converted to photon energy.
Definition: YScanner.h:361
double getTrackLengthInQuartz() const
Returns particle trajectory lenght inside quartz.
Definition: YScanner.h:319
static int s_maxReflections
maximal number of reflections to perform scan
Definition: YScanner.h:481
void expand(unsigned col, double yB, double dydz, const Derivatives &D, bool doScan) const
Performs the PDF expansion in y for a given pixel column using scan or merge methods.
Definition: YScanner.cc:217
const PixelPositions & getPixelPositions() const
Returns pixel positions and their sizes.
Definition: YScanner.h:277
double m_rmsE
r.m.s of photon energy
Definition: YScanner.h:471
const std::vector< Result > & getResults() const
Returns the results of PDF expansion in y.
Definition: YScanner.h:379
bool m_aboveThreshold
true if beta is above the Cerenkov threshold
Definition: YScanner.h:475
double m_sigmaScat
r.m.s.
Definition: YScanner.h:472
void merge(unsigned col, double dydz, int j1, int j2) const
Performs expansion by merging all reflections.
Definition: YScanner.cc:314
double getNumPhotonsPerLen() const
Returns number of photons per Cerenkov azimuthal angle per track length.
Definition: YScanner.h:325
PixelMasks & pixelMasks()
Returns non-const pixel masks.
Definition: YScanner.h:448
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:250
double m_meanE0
mean photon energy for beta = 1
Definition: YScanner.h:461
double m_momentum
particle momentum magnitude
Definition: YScanner.h:466
double getCosTotal() const
Returns cosine of total reflection angle.
Definition: YScanner.h:301
PixelMasks m_pixelMasks
pixel masks
Definition: YScanner.h:458
void integrate(const EnergyMask *energyMask, double Ecp, Result &result) const
Integrates quasy energy distribution multiplied with energy mask.
Definition: YScanner.cc:346
YScanner(int moduleID, unsigned N=64)
Class constructor.
Definition: YScanner.cc:52
const PixelEfficiencies & getPixelEfficiencies() const
Returns pixel relative efficiencies.
Definition: YScanner.h:289
const Table & getEnergyDistribution() const
Returns photon energy distribution.
Definition: YScanner.h:367
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:387
double setEnergyDistribution(double beta) const
Sets photon energy distribution and mean photon energy according to nominal PDE and particle beta.
Definition: YScanner.cc:188
static void setScanLimits(int maxReflections)
Sets parameters for selection between expand methods.
Definition: YScanner.h:236
double m_length
length of particle trajectory inside quartz
Definition: YScanner.h:468
const Table & getQuasyEnergyDistribution() const
Returns photon energy distribution convoluted with multiple scattering.
Definition: YScanner.h:373
double getNumPhotons() const
Returns number of photons per Cerenkov azimuthal angle.
Definition: YScanner.h:331
double getMeanEnergy() const
Returns mean photon energy.
Definition: YScanner.h:337
double m_rmsE0
r.m.s of photon energy for beta = 1
Definition: YScanner.h:462
const Table & getEfficiencies() const
Returns nominal photon detection efficiencies (PDE)
Definition: YScanner.h:295
bool isAboveThreshold() const
Returns above Cerenkov threshold flag which is set in the prepare method.
Definition: YScanner.h:260
std::vector< Result > m_results
results of PDF expansion in y
Definition: YScanner.h:478
const PixelMasks & getPixelMasks() const
Returns pixel masks.
Definition: YScanner.h:283
bool isScanDone() const
Checks which expansion method was used.
Definition: YScanner.h:385
PixelPositions m_pixelPositions
positions and sizes of pixels
Definition: YScanner.h:457
void clear() const
Clear mutable variables.
Definition: YScanner.cc:104
double m_numPhotons
number of photons per Cerenkov azimuthal angle per track length
Definition: YScanner.h:469
double getRMSEnergy() const
Returns r.m.s of photon energy.
Definition: YScanner.h:343
double getBeta() const
Returns particle beta.
Definition: YScanner.h:313
double getMomentum() const
Returns particle momentum.
Definition: YScanner.h:307
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
double yD
unfolded coordinate y of photon at Detector plane
double dyB_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of unfolded y coordinate at prism entrance.
Definition: YScanner.h:502
double dLen_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of propagation length.
Definition: YScanner.h:490
double dyD_dL
unfolded y coordinate at detection over running parameter of particle trajectory
Definition: YScanner.h:44
double dFic_de
Cerenkov azimuthal angle over photon energy.
Definition: YScanner.h:49
double dLen_de
propagation length over photon energy
Definition: YScanner.h:40
Derivatives()
Default constructor.
Definition: YScanner.h:55
double dyD_de
unfolded y coordinate at detection over photon energy
Definition: YScanner.h:43
double dyD_dx
unfolded y coordinate at detection over photon detection coordinate x
Definition: YScanner.h:42
double dFic_dx
Cerenkov azimuthal angle over photon detection coordinate x.
Definition: YScanner.h:48
double dFic_dL
Cerenkov azimuthal angle over running parameter of particle trajectory.
Definition: YScanner.h:50
double dLen_dL
propagation length over running parameter of particle trajectory
Definition: YScanner.h:41
double dyD_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of unfolded y coordinate at detection.
Definition: YScanner.h:496
double dyB_de
unfolded y coordinate at prism entrance over photon energy
Definition: YScanner.h:46
double dLen_dx
propagation length over photon detection coordinate x
Definition: YScanner.h:39
double dyB_dL
unfolded y coordinate at prism entrance over running parameter of particle trajectory
Definition: YScanner.h:47
double dyB_dx
unfolded y coordinate at prism entrance over photon detection coordinate x
Definition: YScanner.h:45
double dFic_d(const InverseRaytracer::Solution &sol0, const InverseRaytracer::Solution &sol1)
Calculates the derivative of Cerenkov azimuthal angle.
Definition: YScanner.h:508
Down-stream projection of a pixel to prism entrance window w/ a clip on bar exit thickness.
Definition: YScanner.h:191
double yc
center in y of clipped pixel projection
Definition: YScanner.h:192
bool operator<(const PixelProjection &other) const
operator "less than" needed for sorting
Definition: YScanner.h:197
const EnergyMask * mask
the corresponding energy mask
Definition: YScanner.h:194
double Dy
size in y of clipped pixel projection
Definition: YScanner.h:193
Single PDF peak data.
Definition: YScanner.h:204
double e0
mean photon energy of the peak
Definition: YScanner.h:207
double sum
peak area proportional to number of photons
Definition: YScanner.h:206
double sigsq
width of the peak squared, in photon energy units
Definition: YScanner.h:208
void set()
Sets the mean and width-squared from the accumulated values.
Definition: YScanner.h:554
Result(int ID)
Constructor with pixel ID.
Definition: YScanner.h:214
int pixelID
pixel ID (1-based)
Definition: YScanner.h:205
TableEntry(double Y, double X, double Xsq)
Constructor.
Definition: YScanner.h:118
A table of equidistant entries.
Definition: YScanner.h:127
Table()
Default constructor.
Definition: YScanner.h:135
double step
step size
Definition: YScanner.h:129
double getY(int i) const
Returns y for a given index.
Definition: YScanner.h:547
int getIndex(double x) const
Returns index.
Definition: YScanner.h:545
std::vector< TableEntry > entries
table entries
Definition: YScanner.h:130
double getXmax() const
Returns x of the last entry.
Definition: YScanner.h:543
double getX(int i) const
Returns x for a given index.
Definition: YScanner.h:539
void clear()
Clear the content entirely.
Definition: YScanner.h:518
double getXmin() const
Returns x of the first entry.
Definition: YScanner.h:541
double x0
x of first entry
Definition: YScanner.h:128
void set(double X0, double Step)
Sets the first x and the step, and clears the entries.
Definition: YScanner.h:525