Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4LocatorChangeRecord.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4LocatorChangeRecord class implementation
27//
28// Author: John Apostolakis (CERN), 27 August 2019
29// --------------------------------------------------------------------
30
31#include <iostream>
32#include <iomanip>
33#include <locale>
34
36
37// Must correspond exactly with the count of the enum EChangeLocation
38//
39const char * G4LocatorChangeRecord::fNameChangeLocation[] =
40 { "Invalid", "Unknown", "Initialising", "IntersectsAF", "IntersectsFB", // 5
41 "NoIntersections-AForFB", "RecalculatedB", // 2
42 "InsertingMidPoint", "RecalculatedB-2ndHalf", // 2
43 "Level Pop" };
44
45// --------------------------------------------------------------------
46//
49 G4int iter,
50 unsigned int count,
51 const G4FieldTrack& fieldTrack )
52 : fCodeLocation( codeLocation),
53 fIteration(iter),
54 fEventCount(count),
55 fFieldTrack( fieldTrack )
56{
57}
58
59// --------------------------------------------------------------------
60//
61std::ostream& G4LocatorChangeRecord::ReportVector ( std::ostream& os,
62 const std::string & name,
63 const std::vector<G4LocatorChangeRecord> & vecRec )
64{
65 using std::setw;
66 G4int prec= 16;
67 if( vecRec.empty() )
68 {
69 os << "Locator Change Record for " << name << " is empty" << G4endl;
70 return os;
71 }
72
73 G4long oldprc = os.precision(prec);
74
75 // std::vector<G4LocatorChangeRecord>::const_iterator
76 auto itRec
77 = std::vector<G4LocatorChangeRecord>::const_iterator(vecRec.cbegin());
78
79 os << setw( 7 ) << "Change#" << " "
80 << setw( 4 ) << "Iter" << " "
81 << std::left
82 << setw( prec+9 ) << "Length" << " "
83 << setw( 15 ) << "Code-Location" << " "
84 << G4endl;
85 os << "====================================================================="
86 << G4endl;
87
88 do
89 {
90 auto locationCode= (*itRec).GetLocation();
91 os << std::internal
92 << setw( 7 ) << (*itRec).GetCount() << " " // Event Count
93 << setw( 4 ) << (*itRec).GetIteration() << " "
94 << std::left
95 << setw( prec+9 ) << (*itRec).GetLength() << " "
96 << setw( 2 ) << locationCode << " " // location enum
97 << setw( 15 ) << fNameChangeLocation[ locationCode ]
98 << std::internal
99 ;
100 os << G4endl;
101 ++itRec;
102
103 } while ( itRec != vecRec.cend() );
104
105 os.precision(oldprc);
106 return os;
107}
108
109// --------------------------------------------------------------------
110//
111std::ostream&
113 std::ostream& os,
114 const std::vector<G4LocatorChangeRecord> & startA,
115 const std::vector<G4LocatorChangeRecord> & endB )
116{
117 using std::setw;
118 G4int prec= 16;
119 const G4bool confirm = true;
120 G4long oldprc = os.precision(prec);
121
122 std::vector<G4LocatorChangeRecord>::const_iterator itrecA, itrecB;
123 itrecA= startA.begin();
124 itrecB= endB.begin();
125 os << G4endl;
126 os << "=========================================================================================";
127 os << G4endl << " ** Change records: " << G4endl;
128 os << " * endPoints A (start) and B (end): combined changes of AB intervals" << G4endl;
129 os << " * Sizes of change records: start(A) : " << startA.size()
130 << " end(B) : " << endB.size() << G4endl;
131 os << "========================================================================================="
132 << G4endl;
133
134 os << setw( 7 ) << "Change#" << " "
135 << setw( 4 ) << "Iter" << " "
136 << setw( 20 ) << "CodeLocation" << " "
137 << setw( prec+9 ) << "Length-A (start)" << " "
138 << setw( prec+9 ) << "Length-B (end)" << " "
139 << G4endl;
140 os << "=====================================================================";
141
142
143 auto eventA = (*itrecA).GetCount();
144 auto eventB = (*itrecB).GetCount();
145
146 G4bool isLastA= false;
147 G4bool isLastB= false;
148
149 G4int maxEvent = std::max( startA[ startA.size() - 1 ].GetCount() ,
150 endB[ endB.size() - 1 ].GetCount() );
151 G4int prevA = -1;
152 G4int prevB = -1;
153
154 G4bool advanceA= false, advanceB= false;
155 do
156 {
157 advanceA= false;
158 advanceB= false;
159
160 if( ((G4int)eventA>prevA) && ((G4int)eventB>prevB) )
161 {
162 auto codeLocA= (*itrecA).GetLocation();
163
164 os << G4endl;
165 os << setw( 7 ) << eventA << " "
166 << setw( 4 ) << (*itrecA).GetIteration() << " "
167 << setw( 3 ) << codeLocA << " "
168 << setw( 15 ) << fNameChangeLocation[ codeLocA ] << " "
169 << setw( prec+9 ) << (*itrecA).GetLength() << " "
170 << setw( prec+9 ) << (*itrecB).GetLength() << " ";
171 if( confirm )
172 {
173 os << setw( 4 ) << (*itrecB).GetIteration() << " "
174 << setw( 15 ) << (*itrecB).GetLocation();
175 }
176 }
177 else
178 {
179 if ( (G4int)eventA > prevA )
180 {
181 auto codeLocA = (*itrecA).GetLocation();
182 os << G4endl;
183 os << setw( 7 ) << (*itrecA).GetCount() << " "
184 << setw( 4 ) << (*itrecA).GetIteration() << " "
185 << setw( 3 ) << codeLocA << " "
186 << setw( 15 ) << fNameChangeLocation[ codeLocA ] << " "
187 << setw( prec+9 ) << (*itrecA).GetLength() << " "
188 << setw( prec+9 ) << " " << " ";
189 }
190 else
191 {
192 // assert( (G4int)eventB > prevB );
193 auto codeLocB = (*itrecB).GetLocation();
194
195 os << G4endl;
196 os << setw( 7 ) << eventB << " "
197 << setw( 4 ) << (*itrecB).GetIteration() << " "
198 << setw( 3 ) << codeLocB << " "
199 << setw( 15 ) << fNameChangeLocation[ codeLocB ] << " "
200 << setw( prec+9 ) << " " << " "
201 << setw( prec+9 ) << (*itrecB).GetLength() << " " ;
202 }
203 }
204
205 prevA= eventA;
206 prevB= eventB;
207
208 auto nextA= itrecA;
209 auto nextB= itrecB;
210
211 G4int nextAct = maxEvent, nextBct = maxEvent;
212 ++nextA;
213 ++nextB;
214 if ( nextA != startA.end() ) { nextAct = (*nextA).GetCount(); }
215 if ( nextB != endB.end() ) { nextBct = (*nextB).GetCount(); }
216
217 isLastA= ( nextA >= startA.end() );
218 isLastB= ( nextB >= endB.end() );
219
220 advanceA= ( nextAct <= nextBct ) && !isLastA;
221 advanceB= ( nextBct <= nextAct ) && !isLastB;
222
223 if( advanceA )
224 {
225 ++itrecA;
226 if( !isLastA ) { eventA = (*itrecA).GetCount(); }
227 else { eventA = maxEvent; }
228 }
229
230 if( advanceB )
231 {
232 ++itrecB;
233 if( !isLastB ) { eventB = (*itrecB).GetCount(); }
234 else { eventB = maxEvent; }
235 }
236
237 // Checks
238 if( isLastA != ( nextA == startA.end() ) )
239 {
240 os << G4endl;
241 os << " Checking isLastA= " << isLastA << " vs expected : "
242 << ( itrecA == startA.end() );
243 os << " BAD --- ERROR " << G4endl;
244 }
245 if( isLastB != ( nextB == endB.end() ) )
246 {
247 os << G4endl;
248 os << " Checking isLastB= " << isLastB << " vs expected : "
249 << ( itrecB == endB.end() );
250 os << " BAD --- ERROR " << G4endl;
251 }
252
253 } while ( ! ( isLastA && isLastB ) );
254
255 os << G4endl;
256 os.precision(oldprc);
257 return os;
258}
259
260// --------------------------------------------------------------------
261// Streaming operator dumping record
262//
263std::ostream& operator<< ( std::ostream& os, const G4LocatorChangeRecord& e )
264{
265 return e.StreamInfo(os);
266}
267
268// --------------------------------------------------------------------
269// Stream object contents to an output stream
270//
271std::ostream& G4LocatorChangeRecord::StreamInfo(std::ostream& os) const
272{
273 G4long oldprc = os.precision(16);
274 os << " count = " << fEventCount
275 << " iter= " << fIteration
276 << " Location code = " << fCodeLocation
277 << " Length = " << GetLength() << G4endl;
278 os.precision(oldprc);
279 return os;
280}
281
282// --------------------------------------------------------------------
283// Streaming operator
284//
285std::ostream& operator << ( std::ostream& os,
286 const std::vector<G4LocatorChangeRecord> & vecR )
287{
289 return os;
290}
291
292// --------------------------------------------------------------------
293//
295{
296 return fNameChangeLocation[loc];
297}
std::ostream & operator<<(std::ostream &os, const G4LocatorChangeRecord &e)
long G4long
Definition G4Types.hh:87
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4FieldTrack defines a data structure bringing together a magnetic track's state (position,...
G4LocatorChangeRecord(EChangeLocation codeLocation, G4int iter, unsigned int count, const G4FieldTrack &fieldTrack)
static const char * GetNameChangeLocation(EChangeLocation)
static std::ostream & ReportEndChanges(std::ostream &os, const std::vector< G4LocatorChangeRecord > &startA, const std::vector< G4LocatorChangeRecord > &endB)
std::ostream & StreamInfo(std::ostream &os) const
static std::ostream & ReportVector(std::ostream &os, const std::string &nameOfRecord, const std::vector< G4LocatorChangeRecord > &lcr)