ATLAS Offline Software
Loading...
Searching...
No Matches
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
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}
41void 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}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
double drawJitter(const Amg::Vector3D &localDir, CLHEP::HepRandomEngine *rndmEngine) const
void cacheAngleInterval(const double minAngle, std::vector< double > &&timeProbs)
std::vector< JitterBin > m_bins
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 3, 1 > Vector3D
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.