Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_settings_group.cc
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# <<END-copyright>>
4*/
5
6#include <iostream>
7#include <stdlib.h>
8
9#include "GIDI_settings.hh"
10
11/*
12=========================================================
13*/
14GIDI_settings_group::GIDI_settings_group( std::string const &label, int size1 ) {
15
16 initialize( label, size1, size1, NULL );
17}
18/*
19=========================================================
20*/
21GIDI_settings_group::GIDI_settings_group( std::string const &label, int length, double const *boundaries ) {
22
23 initialize( label, length, length, boundaries );
24}
25/*
26=========================================================
27*/
28GIDI_settings_group::GIDI_settings_group( std::string const &label, std::vector<double> const &boundaries) {
29
30 int size1 = (int) boundaries.size( );
31
32 initialize( label, size1, size1, &(boundaries[0]) );
33}
34/*
35=========================================================
36*/
38
39 initialize( group.mLabel, group.size( ), group.size( ), &(group.mBoundaries[0]) );
40}
41/*
42=========================================================
43*/
44void GIDI_settings_group::initialize( std::string const &label, int size1, int length, double const *boundaries ) {
45
46 int i1;
47
48 mLabel = label;
49 if( size1 < length ) size1 = length;
50 if( size1 < 0 ) size1 = 0;
51 mBoundaries.resize( size1, 0 );
52 for( i1 = 0; i1 < length; ++i1 ) mBoundaries[i1] = boundaries[i1];
53}
54/*
55=========================================================
56*/
58 if ( this != &group ) {
59 initialize( group.mLabel, group.size(), group.size(), &(group.mBoundaries[0]) );
60 }
61 return *this;
62}
63/*
64=========================================================
65*/
69/*
70=========================================================
71*/
72int GIDI_settings_group::getGroupIndexFromEnergy( double energy, bool encloseOutOfRange ) const {
73
74 int iMin = 0, iMid, iMax = (int) mBoundaries.size( ), iMaxM1 = iMax - 1;
75
76 if( iMax == 0 ) return( -3 );
77 if( energy < mBoundaries[0] ) {
78 if( encloseOutOfRange ) return( 0 );
79 return( -2 );
80 }
81 if( energy > mBoundaries[iMaxM1] ) {
82 if( encloseOutOfRange ) return( iMax - 2 );
83 return( -1 );
84 }
85 while( 1 ) { // Loop checking, 11.06.2015, T. Koi
86 iMid = ( iMin + iMax ) >> 1;
87 if( iMid == iMin ) break;
88 if( energy < mBoundaries[iMid] ) {
89 iMax = iMid; }
90 else {
91 iMin = iMid;
92 }
93 }
94 if( iMin == iMaxM1 ) iMin--;
95 return( iMin );
96}
97/*
98=========================================================
99*/
100void GIDI_settings_group::print( bool outline, int valuesPerLine ) const {
101
102 int nbs = size( );
103 char buffer[128];
104
105 std::cout << "GROUP: label = '" << mLabel << "': length = " << nbs << std::endl;
106 if( outline ) return;
107 for( int ib = 0; ib < nbs; ib++ ) {
108 snprintf( buffer, sizeof buffer, "%16.8e", mBoundaries[ib] );
109 std::cout << buffer;
110 if( ( ( ib + 1 ) % valuesPerLine ) == 0 ) std::cout << std::endl;
111 }
112 if( nbs % valuesPerLine ) std::cout << std::endl;
113}
114
115#if 0
116/* ---- GIDI_settings_groups_from_bdfls ---- */
117/*
118=========================================================
119*/
120GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( std::string const &fileName ) {
121
122 initialize( fileName.c_str( ) );
123}
124/*
125=========================================================
126*/
127GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( char const *fileName ) {
128
129 initialize( fileName );
130}
131/*
132=========================================================
133*/
134GIDI_settings_groups_from_bdfls::GIDI_settings_groups_from_bdfls( cbdfls_file const *bdfls ) {
135
136 initialize2( bdfls );
137}
138/*
139=========================================================
140*/
141void GIDI_settings_groups_from_bdfls::initialize( char const *fileName ) {
142
143 cbdfls_file *bdfls;
144 cbdflsErrors Error;
145
146 if( ( bdfls = cbdflsOpen( fileName, &Error ) ) == NULL ) throw Error;
147 initialize2( bdfls );
148 cbdflsRelease( bdfls );
149}
150/*
151=========================================================
152*/
153void GIDI_settings_groups_from_bdfls::initialize2( cbdfls_file const *bdfls ) {
154
155 int ng, ngbs, *gids;
156 double *boundaries;
157 std::string label( "" );
158 char cLabel[100];
159
160 ng = cbdflsGIDs( (cbdfls_file *) bdfls, &gids );
161 for( int ig = 0; ig < ng; ++ig ) {
162 ngbs = cbdflsGetGroup( (cbdfls_file *) bdfls, gids[ig], &boundaries );
163 snprintf( cLabel, sizeof xLabel, "LLNL_gid_%.3d", gids[ig] );
164 label = cLabel;
165 mGroups.push_back( GIDI_settings_group( label, ngbs, boundaries ) );
166 }
167}
168/*
169=========================================================
170*/
171GIDI_settings_groups_from_bdfls::~GIDI_settings_groups_from_bdfls( ) {
172
173}
174/*
175=========================================================
176*/
177GIDI_settings_group GIDI_settings_groups_from_bdfls::getViaGID( int gid ) const {
178
179 std::string label( "" );
180 char cLabel[100];
181
182 snprintf( cLabel, sizeof cLabel, "LLNL_gid_%.3d", gid );
183 label = cLabel;
184 for( int ig = 0; ig < (int) mGroups.size( ); ++ig ) {
185 if( mGroups[ig].isLabel( label ) ) return( mGroups[ig] );
186 }
187 throw 1;
188}
189/*
190=========================================================
191*/
192std::vector<std::string> GIDI_settings_groups_from_bdfls::getLabels( void ) const {
193
194 int size = (int) mGroups.size( );
195 std::vector<std::string> labels( size );
196
197 for( int if1 = 0; if1 < size; ++if1 ) labels[if1] = mGroups[if1].getLabel( );
198 return( labels );
199}
200/*
201=========================================================
202*/
203std::vector<int> GIDI_settings_groups_from_bdfls::getGIDs( void ) const {
204
205 int size = (int) mGroups.size( );
206 std::vector<int> fids( size );
207 char *e;
208
209 for( int if1 = 0; if1 < size; ++if1 ) {
210 fids[if1] = (int) strtol( &(mGroups[if1].getLabel( ).c_str( )[9]), &e, 10 );
211 }
212 return( fids );
213}
214/*
215=========================================================
216*/
217void GIDI_settings_groups_from_bdfls::print( bool outline, int valuesPerLine ) const {
218
219 int ngs = (int) mGroups.size( );
220
221 std::cout << "BDFLS GROUPs: number of groups = " << ngs << std::endl;
222 for( int if1 = 0; if1 < ngs ; ++if1 ) mGroups[if1].print( outline, valuesPerLine );
223}
224#endif
void print(G4double elem)
GIDI_settings_group & operator=(const GIDI_settings_group &group)
int size(void) const
void print(bool outline=false, int valuesPerLine=10) const
GIDI_settings_group(std::string const &label="empty", int size=0)
int getGroupIndexFromEnergy(double energy, bool encloseOutOfRange) const
void initialize(Config const *const theConfig)
Initialize the clustering model based on the Config object.