Belle II Software  release-05-01-25
SVDSignal.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Peter Kvasnicka, Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef SVDSIGNAL_H
12 #define SVDSIGNAL_H
13 
14 #include <framework/dataobjects/RelationElement.h>
15 #include <string>
16 #include <sstream>
17 #include <deque>
18 #include <map>
19 #include <svd/simulation/SVDSimulationTools.h>
20 
21 namespace Belle2 {
26  namespace SVD {
27 
44  class SVDSignal {
45 
46  public:
47 
54  struct Wave {
56  Wave(double initTime, double charge, double tau,
58  m_initTime(initTime), m_charge(charge), m_tau(tau), m_particle(particle),
59  m_truehit(truehit)
60  {}
62  std::string toString() const
63  {
64  std::ostringstream os;
65  os << m_initTime << '\t' << m_charge << '\t' << m_tau << std::endl;
66  return os.str();
67  }
69  double m_initTime;
71  double m_charge;
73  double m_tau;
78  };
79 
81  typedef std::deque< Wave > function_list;
82 
84  typedef std::map<RelationElement::index_type, RelationElement::weight_type> relations_map;
86  typedef std::map<RelationElement::index_type, RelationElement::weight_type>::value_type relation_value_type;
87 
90 
92  SVDSignal(const SVDSignal& other)
93  {
94  m_charge = other.getCharge();
95  for (Wave wave : other.getFunctions())
96  m_functions.push_back(wave);
97  }
98 
103  bool isNoise() const { return m_charge < 0; }
104 
115  void add(double initTime, double charge, double tau, int particle = -1, int truehit = -1)
116  {
117  if (charge > 0) {
118  m_charge += charge;
119  m_functions.push_back(Wave(initTime, charge, tau, particle, truehit));
120  if (particle > -1) m_particles[particle] += static_cast<float>(charge);
121  if (truehit > -1) m_truehits[truehit] += static_cast<float>(charge);
122  } else if (m_charge == 0)
123  m_charge += charge;
124  }
125 
130  SVDSignal& operator=(const SVDSignal& other)
131  {
132  m_charge = other.getCharge();
133  m_functions.clear();
134  std::copy(other.getFunctions().begin(), other.getFunctions().end(), m_functions.begin());
135  return *this;
136  }
137 
147  double waveform(double t, double initTime, double charge, double tau,
148  waveFunction wfun = w_betaprime) const
149  {
150  double z = (t - initTime) / tau;
151  return charge * wfun(z);
152  }
153 
159  double waveform(double t, const Wave& wave) const
160  { return waveform(t, wave.m_initTime, wave.m_charge, wave.m_tau); }
161 
166  double operator()(double t) const
167  {
168  double wave_sum = 0;
169  for (SVDSignal::Wave wave : m_functions) {
170  wave_sum += waveform(t, wave);
171  }
172  return wave_sum;
173  }
174 
178  double getCharge() const { return m_charge; }
179 
183  const function_list& getFunctions() const { return m_functions; }
184 
188  const relations_map& getMCParticleRelations() const { return m_particles; }
189 
193  const relations_map& getTrueHitRelations() const { return m_truehits; }
195  std::string toString() const
196  {
197  std::ostringstream os;
198  size_t i = 0;
199  for (auto w : m_functions)
200  os << ++i << '\t' << w.toString();
201  return os.str();
202  }
203 
204  protected:
205 
207  double m_charge;
214 
215  }; // class SVDSignal
216 
217  } // end namespace SVD
219 } // end namespace Belle2
220 
221 #endif
Belle2::EvtPDLUtil::charge
double charge(int pdgCode)
Returns electric charge of a particle with given pdg code.
Definition: EvtPDLUtil.cc:46
Belle2::SVD::SVDSignal::operator=
SVDSignal & operator=(const SVDSignal &other)
Make the SVDSignal assignable.
Definition: SVDSignal.h:138
Belle2::SVD::SVDSignal::m_particles
relations_map m_particles
Map of MCParticle associations.
Definition: SVDSignal.h:219
Belle2::SVD::SVDSignal::m_charge
double m_charge
charge of the pixel
Definition: SVDSignal.h:215
Belle2::SVD::SVDSignal::SVDSignal
SVDSignal()
Default constructor.
Definition: SVDSignal.h:97
Belle2::SVD::SVDSignal::function_list
std::deque< Wave > function_list
List of elementary waveforms.
Definition: SVDSignal.h:89
Belle2::SVD::SVDSignal::getMCParticleRelations
const relations_map & getMCParticleRelations() const
Return the list of MCParticle relations.
Definition: SVDSignal.h:196
Belle2::SVD::waveFunction
std::function< double(double)> waveFunction
Wavefrom function type.
Definition: SVDSimulationTools.h:56
Belle2::SVD::SVDSignal::m_functions
function_list m_functions
list of elementary waveform parameters.
Definition: SVDSignal.h:217
Belle2::SVD::SVDSignal::Wave::m_truehit
RelationElement::index_type m_truehit
DataStore index of the associated SVDTrueHit.
Definition: SVDSignal.h:85
Belle2::SVD::SVDSignal::add
void add(double initTime, double charge, double tau, int particle=-1, int truehit=-1)
Add a chargelet to the strip signal.
Definition: SVDSignal.h:123
Belle2::SVD::SVDSignal::getCharge
double getCharge() const
Return the charge collected in the strip.
Definition: SVDSignal.h:186
Belle2::SVD::SVDSignal::Wave::m_tau
double m_tau
Decay time of the waveform.
Definition: SVDSignal.h:81
Belle2::SVD::SVDSignal::operator()
double operator()(double t) const
Make SVDSignal a functor.
Definition: SVDSignal.h:174
Belle2::SVD::SVDSignal::relation_value_type
std::map< RelationElement::index_type, RelationElement::weight_type >::value_type relation_value_type
Type of relation_map elements.
Definition: SVDSignal.h:94
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RelationElement::index_type
unsigned int index_type
type used for indices.
Definition: RelationElement.h:37
Belle2::SVD::SVDSignal::Wave::m_particle
RelationElement::index_type m_particle
DataStore index of the generating MC Particle.
Definition: SVDSignal.h:83
Belle2::SVD::SVDSignal::Wave::m_initTime
double m_initTime
Start time of the waveform.
Definition: SVDSignal.h:77
Belle2::SVD::SVDSignal::Wave
Type to store elementary waveforms.
Definition: SVDSignal.h:62
Belle2::SVD::w_betaprime
double w_betaprime(double t)
Beta-prime wave function, x^alpha/(1+x)^beta.
Definition: SVDSimulationTools.h:89
Belle2::SVD::SVDSignal::relations_map
std::map< RelationElement::index_type, RelationElement::weight_type > relations_map
Type to store contributions to strip signal by different particles on output of SVDSignal.
Definition: SVDSignal.h:92
Belle2::SVD::SVDSignal::waveform
double waveform(double t, double initTime, double charge, double tau, waveFunction wfun=w_betaprime) const
Waveform shape.
Definition: SVDSignal.h:155
Belle2::SVD::SVDSignal::m_truehits
relations_map m_truehits
Map of TrueHit associations.
Definition: SVDSignal.h:221
Belle2::SVD::SVDSignal::Wave::m_charge
double m_charge
Charge of the wave.
Definition: SVDSignal.h:79
Belle2::SVD::SVDSignal::Wave::toString
std::string toString() const
Create a string containing data of this Wave object.
Definition: SVDSignal.h:70
Belle2::SVD::SVDSignal::getFunctions
const function_list & getFunctions() const
Return the list of waveform parameters.
Definition: SVDSignal.h:191
Belle2::SVD::SVDSignal::getTrueHitRelations
const relations_map & getTrueHitRelations() const
Return the list of TrueHit relations.
Definition: SVDSignal.h:201
Belle2::SVD::SVDSignal::Wave::Wave
Wave(double initTime, double charge, double tau, RelationElement::index_type particle, RelationElement::index_type truehit)
Constructor.
Definition: SVDSignal.h:64
Belle2::SVD::SVDSignal::toString
std::string toString() const
Produce a string representation of the object.
Definition: SVDSignal.h:203
Belle2::SVD::SVDSignal
The SVD signal class.
Definition: SVDSignal.h:52
Belle2::SVD::SVDSignal::isNoise
bool isNoise() const
Check whether this is a noise signal.
Definition: SVDSignal.h:111