Belle II Software development
VXDElectronDeposit.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#ifndef VXD_SIMULATION_ELECTRONDEPOSIT_H
11#define VXD_SIMULATION_ELECTRONDEPOSIT_H
12
13#include <algorithm>
14#include <cmath>
15
16namespace Belle2 {
33 public:
35 enum EBits {
46 };
47
50 explicit VXDElectronDeposit(unsigned int packed): m_packed(packed) {}
51
57 VXDElectronDeposit(float fraction, float electrons)
58 {
59 const unsigned int intfrac = std::round(std::max(0.f, fraction) * static_cast<float>(c_MaxFraction));
60 const unsigned int intelec = std::round(std::max(0.f, electrons));
61 m_packed = std::min(intfrac, static_cast<unsigned int>(c_MaxFraction))
62 + (std::min(intelec, static_cast<unsigned int>(c_MaxElectrons)) << c_FractionBits);
63 }
65 float getFraction() const
66 {
67 return (m_packed & c_MaxFraction) * 1.0 / static_cast<float>(c_MaxFraction);
68 }
70 unsigned int getElectrons() const
71 {
73 }
75 unsigned int getPacked() const { return m_packed; }
77 operator unsigned int() const { return m_packed; }
78 private:
80 unsigned int m_packed: c_TotalBits;
81 };
82
84} //Belle2 namespace
85#endif // VXD_SIMULATION_ELECTRONDEPOSIT_H
Packed class to represent energy deposit along a path in electrons.
unsigned int getElectrons() const
get the number of deposited electrons
EBits
Enum storing the bit informations for the packed information.
@ c_TotalBits
Total number of bits needed for the packed structure.
@ c_MaxFraction
Maximum integer value allowed for the fraction part.
@ c_ElectronBits
Number of bits to encode the number of electrons.
@ c_FractionBits
Number of bits to encode the fraction along the path.
@ c_MaxElectrons
Maximum number of electrons allowed.
unsigned int m_packed
packed representation of the fraction and electron deposition
float getFraction() const
get the fraction along the path
VXDElectronDeposit(unsigned int packed)
Create a new instance from a packed value.
VXDElectronDeposit(float fraction, float electrons)
create a new instance from a fraction along the path and a number of electrons.
unsigned int getPacked() const
get the packed value
Abstract base class for different kinds of events.