ATLAS Offline Software
TgcDigitJitterData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "CLHEP/Random/RandFlat.h"
9 #include "CLHEP/Random/RandomEngine.h"
10 
12  AthMessaging{"TgcDigitJitterData"} {}
13 
15  CLHEP::HepRandomEngine* rndmEngine) const {
16  const double injectionAngle = std::atan2(std::abs(localDir.z()), std::abs(localDir.x())) / Gaudi::Units::deg;
17 
18  const size_t ithAngle = std::min(static_cast<size_t>(injectionAngle / m_angleInterval), m_bins.size() - 1);
19  const size_t jthAngle = std::min(ithAngle + 1, m_bins.size() -1);
20  ATH_MSG_DEBUG("Direction "<<Amg::toString(localDir)<<", injection angle: "<<injectionAngle
21  <<", bin i: "<<ithAngle<<", bin j: "<<jthAngle);
22  const double wAngle = std::fmod(injectionAngle, m_angleInterval);
23 
24  double jitter{0.}, prob{1.}, probRef{0.};
25  const std::vector<double>& ith_probs{m_bins[ithAngle].timeProbs};
26  const std::vector<double>& jth_probs{m_bins[jthAngle].timeProbs};
27  unsigned int trials{0};
28  while (prob > probRef) {
29  prob = CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0);
30  jitter = CLHEP::RandFlat::shoot(rndmEngine, 0.0, 1.0) * m_timeInterval;
31  size_t ithJitter = static_cast<size_t>(jitter);
32  // probability distribution calculated from weighted sum between
33  // neighboring bins of angles
34  probRef = (1. - wAngle) * (ithJitter < ith_probs.size() ? ith_probs[ithJitter] : 0.) +
35  wAngle * (ithJitter < jth_probs.size() ? jth_probs[ithJitter] : 0.);
36  ATH_MSG_VERBOSE("Trial: "<<(++trials)<<" jitter: "<<jitter<<", prob: "<<prob
37  <<", probRef: "<<probRef);
38  }
39  return jitter;
40 }
41 void TgcDigitJitterData::cacheAngleInterval(const double minAngle, std::vector<double>&& timeProbs) {
42  m_bins.emplace_back(minAngle, std::move(timeProbs));
43 }
45  if (m_bins.empty()) {
46  ATH_MSG_FATAL("No jitter bins were defined.");
47  return StatusCode::FAILURE;
48  }
49  std::sort(m_bins.begin(), m_bins.end());
50  for (size_t b = 0 ; b < m_bins.size() - 1; ++b) {
51  m_bins[b].maxAngle = m_bins[b+1].minAngle;
52  if (b == 0) {
53  m_angleInterval = m_bins[b].maxAngle - m_bins[b].minAngle;
54  } else if (std::abs(m_bins[b].maxAngle - m_bins[b].minAngle - m_angleInterval) >
55  std::numeric_limits<double>::epsilon()) {
56  ATH_MSG_FATAL("The angular bin "<<b<<" ranging from "<<m_bins[b].minAngle
57  <<" to "<<m_bins[b].maxAngle<<" is outside of the fixed interval "
58  <<m_angleInterval<<". Only fixed bin size is supported");
59  return StatusCode::FAILURE;
60  }
61  if (m_bins[b].timeProbs.empty()) {
62  ATH_MSG_FATAL("The angular bin "<<b<<" has no probabilities associated.");
63  return StatusCode::FAILURE;
64  }
65  m_timeInterval = std::max(m_timeInterval, -1. + m_bins[b].timeProbs.size());
66  }
67  return StatusCode::SUCCESS;
68 }
TgcDigitJitterData::m_timeInterval
double m_timeInterval
Definition: TgcDigitJitterData.h:50
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
TgcDigitJitterData::drawJitter
double drawJitter(const Amg::Vector3D &localDir, CLHEP::HepRandomEngine *rndmEngine) const
Definition: TgcDigitJitterData.cxx:14
deg
#define deg
Definition: SbPolyhedron.cxx:17
TgcDigitJitterData.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
covarianceTool.prob
prob
Definition: covarianceTool.py:678
TgcDigitJitterData::initialize
StatusCode initialize()
Definition: TgcDigitJitterData.cxx:44
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
TgcDigitJitterData::m_bins
std::vector< JitterBin > m_bins
Definition: TgcDigitJitterData.h:48
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TgcDigitJitterData::m_angleInterval
double m_angleInterval
Definition: TgcDigitJitterData.h:51
TgcDigitJitterData::cacheAngleInterval
void cacheAngleInterval(const double minAngle, std::vector< double > &&timeProbs)
Definition: TgcDigitJitterData.cxx:41
GeoPrimitivesToStringConverter.h
TgcDigitJitterData::TgcDigitJitterData
TgcDigitJitterData()
Definition: TgcDigitJitterData.cxx:11