ATLAS Offline Software
Loading...
Searching...
No Matches
ForwardTracker/src/Beamline.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include <cmath> //fabs
9#include <iostream> //<<, ostream
10#include <iomanip> //setw
11#include <sstream> //stringstream
12#include <ios> //std::fixed
13#include <algorithm> //std::find_if
14#include <stdexcept> //std::runtime_error
15
16
17namespace ForwardTracker {
18
19 bool isEndMarker(const IBeamElement::ConstPtr_t& be) { return be->isEndElement(); }
20
22
23 IBeamElement::Iter_t ei = std::find_if(container.begin(), container.end(), isEndMarker);
24
25 if (ei != container.end()) ++ei;
26 else throw std::runtime_error("Could not find the end of the beamline.");
27
28 return ei;
29 }
30
32
33 public:
34
35 bool operator() (const IBeamElement::ConstPtr_t& be, double zpos) { return std::fabs(zpos) > std::fabs(be->position().z()); }
36 };
37
39
40 IBeamElement::Container_t temp(begin, end);
42 IBeamElement::Container_t temp2(temp.begin(), tempIter);
43 m_elements.swap(temp2);
44 }
45
47
49 m_elements.swap(temp);
50 }
51
53
54 public:
55
56 ParticleTracker(IParticle& particle): m_particle(particle) {}
57
59
60 be->track(m_particle);
61
62 if (m_particle.debug()) std::cout << std::setw(12) << be->label() << m_particle << std::endl;
63
64 return m_particle.isOutOfAperture();
65 }
66
67 private:
68
70 };
71
72 void Beamline::track(IParticle& particle) const { // Pass the particle to beam elements until out of aperture or endPlane
73
74 IBeamElement::ConstIter_t nextElement = std::lower_bound(m_elements.begin(), m_elements.end(), particle.z(), zPosNextElement());
75
76 [[maybe_unused]]const auto & firstOutOfAperture = std::find_if(nextElement, m_elements.end(), ParticleTracker(particle));
77 }
78
79 class Stringer {
80
81 public:
82
83 Stringer(): m_ost(new std::stringstream) { (*m_ost) << "----------------- Beamline -----------------\n"; }
84
86
87 (*m_ost) << std::fixed << std::left
88 << std::setw(15) << be->label()
89 << std::setw(10) << be->side() << std::right
90 << std::setw(12) << be->frontFace()
91 << std::setw(12) << be->rearFace()
92 << " pos" << be->position()
93 << "\n";
94 }
95
96 std::string str() const { return m_ost->str(); }
97
98 private:
99
100 std::shared_ptr<std::stringstream> m_ost;
101 };
102
103 std::string Beamline::str() const { return (std::for_each(m_elements.begin(), m_elements.end(), Stringer())).str(); }
104
105 std::ostream& operator<<(std::ostream& os, const Beamline& bl) { os << bl.str(); return os; }
106}
std::shared_ptr< const IBeamElement > ConstPtr_t
bool operator()(const IBeamElement::ConstPtr_t &be)
void operator()(const IBeamElement::ConstPtr_t &be)
std::shared_ptr< std::stringstream > m_ost
bool operator()(const IBeamElement::ConstPtr_t &be, double zpos)
STL class.
bool isEndMarker(const IBeamElement::ConstPtr_t &be)
std::ostream & operator<<(std::ostream &, const Beamline &)
IBeamElement::Iter_t findBeamLineEnd(IBeamElement::Container_t &container)
STL namespace.