ATLAS Offline Software
Loading...
Searching...
No Matches
SiTotalCharge.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6// SiTotalCharge.cxx
7// Implementation file for class SiTotalCharge
9// (c) ATLAS Detector software
11// Version 1.5 08/06/2001 David Calvet
13
15#include <iterator>
16
17// Implicit constructor:
22
23// Copy constructor:
25 m_charge(totalCharge.m_charge),
27{}
28
29// Assignment operator:
31{
32 if (this!=&totalCharge) {
33 m_charge=totalCharge.m_charge;
35 } else {}
36 return *this;
37}
38
39// give main single process charge:
41{
42 auto max_element = std::max_element(m_chargeComposition.cbegin(), m_chargeComposition.cend(),
43 [](SiCharge const & lhs, SiCharge const & rhs)
44 { return lhs.charge() < rhs.charge(); }
45 );
46 return *max_element;
47}
48
60
61// add another charge:
63{
64 // increase the total deposited charge
65 m_charge+=charge.charge();
66 // add the SiCharge to the list of charges
68}
69
70// add another total charge:
71void SiTotalCharge::add(const SiTotalCharge &totalCharge)
72{
73 // increase the total deposited charge
74 m_charge+=totalCharge.charge();
75
76 std::for_each(totalCharge.chargeComposition().begin(),
77 totalCharge.chargeComposition().end(),
78 [this](const SiCharge & c) { addSiCharge(c); }
79 );
80}
81
82// remove time information of the SiCharge objects:
84{
85 // save the old charge composition
86 list_t oldComposition;
87 m_chargeComposition.swap(oldComposition);
88
89 // loop on all old charges
90 for(const auto & p_charge : oldComposition) {
91 // add the old charge (without time) to the list
92 addSiCharge(SiCharge(p_charge.charge(),0,
93 p_charge.processType(),p_charge.particleLink()));
94 }
95}
96
97// remove small SiCharge objects:
98void SiTotalCharge::removeSmallCharges(const double minimumCharge)
99{
100 //erase-remove idiom to remove small charges
101 auto new_end = std::remove_if(m_chargeComposition.begin(), m_chargeComposition.end(),
102 [&minimumCharge](const SiCharge& c){ return (c.charge() > -minimumCharge) &&
103 (c.charge() < minimumCharge); });
104 m_chargeComposition.erase(new_end, m_chargeComposition.end());
105}
106
107// add another SiCharge to the charge composition (not the total value):
109{
110 auto element = std::find_if(m_chargeComposition.begin(), m_chargeComposition.end(),
111 [&charge](const SiCharge & other) {
112 return (charge.time() == other.time()) &&
113 (charge.processType() == other.processType()) &&
114 (charge.particleLink() == other.particleLink());
115 } );
116 if(element != m_chargeComposition.end()) element->add(charge);
117 // add the charge to the list if not merged in existing one
118 else m_chargeComposition.push_back(charge);
119}
120
122// Input/Output stream functions:
124std::ostream &operator<<(std::ostream &out,const SiTotalCharge &totalCharge)
125{
126 out << "Total charge=" << totalCharge.charge()
127 << " Composition:" << std::endl;
128 copy(totalCharge.chargeComposition().begin(),
129 totalCharge.chargeComposition().end(),
130 std::ostream_iterator<SiCharge>(out,"\n"));
131 return out;
132}
133
std::ostream & operator<<(std::ostream &out, const SiTotalCharge &totalCharge)
Process processType() const
Definition SiCharge.h:119
@ cut_track
Definition SiCharge.h:28
@ diodeX_Talk
Definition SiCharge.h:28
list_t m_chargeComposition
std::vector< SiCharge > list_t
static const HepMcParticleLink m_emptyLink
void addSiCharge(const SiCharge &charge)
void removeTimeInformation()
SiTotalCharge & operator=(const SiTotalCharge &totalCharge)
const list_t & chargeComposition() const
const SiCharge & mainCharge() const
void removeSmallCharges(const double minimumCharge)
bool fromTrack() const
void add(const SiCharge &charge)
double charge() const
const std::string process
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.