Belle II Software  release-05-01-25
VXDElectronDeposit.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #ifndef VXD_SIMULATION_ELECTRONDEPOSIT_H
13 #define VXD_SIMULATION_ELECTRONDEPOSIT_H
14 
15 #include <algorithm>
16 #include <cmath>
17 
18 namespace Belle2 {
35  public:
37  enum EBits {
48  };
49 
52  explicit VXDElectronDeposit(unsigned int packed): m_packed(packed) {}
53 
59  VXDElectronDeposit(float fraction, float electrons)
60  {
61  const unsigned int intfrac = std::round(std::max(0.f, fraction) * c_MaxFraction);
62  const unsigned int intelec = std::round(std::max(0.f, electrons));
63  m_packed = std::min(intfrac, (unsigned int) c_MaxFraction)
64  + (std::min(intelec, (unsigned int) c_MaxElectrons) << c_FractionBits);
65  }
67  float getFraction() const
68  {
69  return (m_packed & c_MaxFraction) * 1.0 / c_MaxFraction;
70  }
72  unsigned int getElectrons() const
73  {
75  }
77  unsigned int getPacked() const { return m_packed; }
79  operator unsigned int() const { return m_packed; }
80  private:
82  unsigned int m_packed: c_TotalBits;
83  };
84 
86 } //Belle2 namespace
87 #endif // VXD_SIMULATION_ELECTRONDEPOSIT_H
Belle2::VXDElectronDeposit::VXDElectronDeposit
VXDElectronDeposit(float fraction, float electrons)
create a new instance from a fraction along the path and a number of electrons.
Definition: VXDElectronDeposit.h:59
Belle2::VXDElectronDeposit::m_packed
unsigned int m_packed
packed representation of the fraction and electron deposition
Definition: VXDElectronDeposit.h:82
Belle2::VXDElectronDeposit::getFraction
float getFraction() const
get the fraction along the path
Definition: VXDElectronDeposit.h:67
Belle2::VXDElectronDeposit::c_MaxElectrons
@ c_MaxElectrons
Maximum number of electrons allowed.
Definition: VXDElectronDeposit.h:47
Belle2::VXDElectronDeposit
Packed class to represent energy deposit along a path in electrons.
Definition: VXDElectronDeposit.h:34
Belle2::VXDElectronDeposit::c_TotalBits
@ c_TotalBits
Total number of bits needed for the packed structure.
Definition: VXDElectronDeposit.h:43
Belle2::VXDElectronDeposit::getPacked
unsigned int getPacked() const
get the packed value
Definition: VXDElectronDeposit.h:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXDElectronDeposit::c_ElectronBits
@ c_ElectronBits
Number of bits to encode the number of electrons.
Definition: VXDElectronDeposit.h:41
Belle2::VXDElectronDeposit::EBits
EBits
Enum storing the bit informations for the packed information.
Definition: VXDElectronDeposit.h:37
Belle2::VXDElectronDeposit::c_MaxFraction
@ c_MaxFraction
Maximum integer value allowed for the fraction part.
Definition: VXDElectronDeposit.h:45
Belle2::VXDElectronDeposit::c_FractionBits
@ c_FractionBits
Number of bits to encode the fraction along the path.
Definition: VXDElectronDeposit.h:39
Belle2::VXDElectronDeposit::VXDElectronDeposit
VXDElectronDeposit(unsigned int packed)
Create a new instance from a packed value.
Definition: VXDElectronDeposit.h:52
Belle2::VXDElectronDeposit::getElectrons
unsigned int getElectrons() const
get the number of deposited electrons
Definition: VXDElectronDeposit.h:72