ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_PAI_gasMixture.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8
9#include <iostream>
10#include <cmath>
11
12//____________________________________________________________________________
14 AthMessaging(nm),
15 m_name(nm),
17{};
18
19
20//____________________________________________________________________________
22 if ( m_gasFrozen ) {
23 ATH_MSG_ERROR("gasMixture::addComponent: cannot add new gasComponent "
24 "- gas already frozen");
25 return;
26 }
27
28 m_compFracs.push_back(frac);
29 m_pcomp.push_back(pgc);
30 return;
31}
32
33//____________________________________________________________________________
34
36 if ( m_gasFrozen ) return;
37
38 int nComp = m_pcomp.size();
39 double wtot = 0.;
40 for (int j=0; j<nComp; j++) {
41 if ( m_compFracs[j] <= 0. ) {
42 ATH_MSG_ERROR("gasMixture::freezeGas: "
43 "A gasComponent has non-positive fraction");
44 return;
45 }
46 wtot += m_compFracs[j];
47 }
48
49 if ( std::abs(wtot-1.) > 1e-5 ) {
50 ATH_MSG_WARNING("gasMixture::freezeGas: "
51 "Gas fractions do not add to unity but " << wtot
52 << ". Re-normalizing!!");
53 }
54
55 for (int j=0; j<nComp; ++j ) {
56 m_compFracs[j] /= wtot;
57 }
58
59 m_gasFrozen = 1;
60
61 // Now, find the composition in terms of elements
62
63 double w;
65 wtot = 0.;
66 for (int j=0; j<nComp; j++) {
67 for(int i=0; i<m_pcomp[j]->getNElementTypes(); i++) {
68 pe = m_pcomp[j]->getElement(i);
69 w = m_compFracs[j] * m_pcomp[j]->getElementMultiplicity(i);
70 wtot += w;
71 for ( unsigned int k=0; k<m_pelem.size(); k++ ) {
72 if ( pe == m_pelem[k] ) {
73 m_elemWeights[k] += w;
74 w = -999.;
75 break;
76 }
77 }
78 if ( w>0. ) {
79 m_elemWeights.push_back(w);
80 m_pelem.push_back(pe);
81 }
82 }
83 }
84 return;
85}
86
87//____________________________________________________________________________
88
90
91 if ( !m_gasFrozen ) {
92 ATH_MSG_WARNING("gasMixture::showStructure: Showing structure of non-frozen gas");
93 }
94
95 ATH_MSG_INFO("The gas named '" << m_name << "' has the following components:");
96
97 for (unsigned int i=0; i<m_compFracs.size(); i++) {
98 msg(MSG::INFO) << " - " << m_compFracs[i]*100. << " percent "
99 << m_pcomp[i]->getName() << " consisting of: ";
100 for (int j=0; j<m_pcomp[i]->getNElementTypes(); j++) {
101 if ( j>0 ) msg(MSG::INFO) << ",";
102 msg(MSG::INFO) << " " << m_pcomp[i]->getElementMultiplicity(j)
103 << " atoms " << m_pcomp[i]->getElement(j)->getName();
104 }
105 msg(MSG::INFO) << endmsg;
106 }
107 return;
108}
109
110//____________________________________________________________________________
111
113
114 if ( n >= m_pcomp.size() ) {
115 ATH_MSG_ERROR("gasMixture::getComponent: out of bounds");
116 return m_pcomp[0];
117 };
118
119 return m_pcomp[n];
120}
121
122//____________________________________________________________________________
123
125
126 if ( n >= m_compFracs.size() ) {
127 ATH_MSG_ERROR("gasMixture::getCompFraction: out of bounds");
128 return m_compFracs[0];
129 }
130
131 return m_compFracs[n];
132}
133
134//____________________________________________________________________________
135
137
138 if ( n >= m_pelem.size() ) {
139 ATH_MSG_ERROR("TRT_PAI_gasMixture::getElement: out of bounds");
140 return m_pelem[0];
141 };
142
143 return m_pelem[n];
144}
145
146//____________________________________________________________________________
147
148double TRT_PAI_gasMixture::getElemWeight(unsigned int n) {
149
150 if ( n >= m_elemWeights.size() ) {
151 ATH_MSG_ERROR("gasMixture::getElemFraction:Error:out of bounds");
152 return 0;
153 };
154
155 return m_elemWeights[n];
156}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
MsgStream & msg() const
The standard message stream.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Chemical element.
Gas component (molecule)
std::vector< double > m_elemWeights
TRT_PAI_element * getElement(unsigned int n)
Get element no.
void freezeGas()
Components can be added to gas mixture before freezeGas is called.
double getCompFraction(unsigned int n)
Get fraction of gas component no.
void addComponent(TRT_PAI_gasComponent *pgc, double frac)
Add gas component to gas mixture.
std::vector< TRT_PAI_element * > m_pelem
double getElemWeight(unsigned int n)
Get weight of element no.
void showStructure()
Print out of structure of this gas mixture.
std::vector< TRT_PAI_gasComponent * > m_pcomp
TRT_PAI_gasMixture(const std::string &nm)
Construct gas mixture.
std::vector< double > m_compFracs
TRT_PAI_gasComponent * getComponent(unsigned int n)
Get gas component no.