Message: Nested Parameterisation: Seg fault with Changing Densities Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Nested Parameterisation: Seg fault with Changing Densities 

Forum: Geometry
Date: 13 Feb, 2012
From: Jonathan Madsen <Jonathan Madsen>

--Apple-Mail=_8B9946C0-714B-4906-A7A5-39EFCFF6EDD1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
 charset=us-ascii

I have a materials question with regards to a Nested Parameterisation

In the ComputeMaterial function I have put:

    G4Material* mate;
    if(changingDensity) {
        mate =3D =
BuildMaterialWithChangingDensity(fMaterials[matIndex],ix,iy,iz);
    } else {
        mate =3D fMaterials[matIndex]; // fMaterials is defined in =
construction std::vector<G4Materials*> fMaterials
    }

    return mate;

Where BuildMaterialWithChangingDensity is:

G4Material* =
DicomNestedDetectorParameterisation::BuildMaterialWithChangingDensity(G4Ma=
terial* material, G4int ix, G4int iy, G4int iz)
{
    G4String origName =3D material->GetName();
    G4int nelem =3D material->GetNumberOfElements();
   =20
    double density =3D densityArray[iy][ix];
    if(density =3D=3D 0) { density =3D 0.001290; }
    G4cout << "New density: " << density << G4endl;
    G4Material* mate =3D new G4Material( origName, density*g/cm3, nelem, =
kStateUndefined, STP_Temperature );
   =20
    for( G4int ii =3D 0; ii < nelem; ii++ ){
        G4double frac =3D material->GetFractionVector()[ii];
        G4Element* elem =3D =
const_cast<G4Element*>(material->GetElement(ii));
        mate->AddElement( elem, frac );
    }
    return mate;
}


It works during visualization and runtime if changingDensity =3D false
It works during visualization but segfaults during runtime if =
changingDensity =3D true;


Here is the segfault when changingDensity =3D true:


---> Begin of EV: 0 (0 s)
1 vertices passed from G4Event.
Primary particle (alpha) --- Transfered with momentum =
(-59.6816,10.8671,11.3865)
A new track 0x7fcc8483df80 (trackID 1, parentID 0) is passed to =
G4StackManager.
1 primaries are passed from G4EventTransformer.
!!!!!!! Now start processing an event !!!!!!!
### pop requested out of 1 stacked tracks.
Track 0x7fcc8483df80 (trackID 1, parentID 0) is passed to =
G4TrackingManager.

=
**************************************************************************=
*******************************
* G4Track Information:   Particle =3D alpha,   Track ID =3D 1,   Parent =
ID =3D 0
=
**************************************************************************=
*******************************

*** G4Navigator::LocateGlobalPointAndSetup: ***
    Called with arguments:=20
    Globalpoint =3D (-21,51,20)
    RelativeSearch =3D 0
Copy Number: 157930, ix,iy,iz: (234,308,0)
New density: 1.0988
New Material:  Material:   Muscle    density:  1.099 g/cm3   RadL:  =
33.118 cm   Nucl.Int.Length:  68.801 cm   Imean:  69.793 eV=20
   --->  Element: Hydrogen (H)   Z =3D  1.0   N =3D   1.0   A =3D   1.01 =
g/mole  ElmMassFraction:  10.20 %  ElmAbundance  63.14 %
   --->  Element: Carbon (C)   Z =3D  6.0   N =3D  12.0   A =3D  12.01 =
g/mole  ElmMassFraction:  14.30 %  ElmAbundance   7.43 %
   --->  Element: Nitrogen (N)   Z =3D  7.0   N =3D  14.0   A =3D  14.01 =
g/mole  ElmMassFraction:   3.40 %  ElmAbundance   1.51 %
   --->  Element: Oxygen (O)   Z =3D  8.0   N =3D  16.0   A =3D  16.00 =
g/mole  ElmMassFraction:  71.00 %  ElmAbundance  27.69 %
   --->  Element: Sodium (Na)   Z =3D 11.0   N =3D  23.0   A =3D  22.99 =
g/mole  ElmMassFraction:   0.10 %  ElmAbundance   0.03 %
   --->  Element: Phosphorus (P)   Z =3D 30.0   N =3D  31.0   A =3D  =
30.97 g/mole  ElmMassFraction:   0.20 %  ElmAbundance   0.04 %
   --->  Element: Sulfur (S)   Z =3D 16.0   N =3D  32.1   A =3D  32.06 =
g/mole  ElmMassFraction:   0.30 %  ElmAbundance   0.06 %
   --->  Element: Chlorine (P)   Z =3D 17.0   N =3D  35.5   A =3D  35.45 =
g/mole  ElmMassFraction:   0.10 %  ElmAbundance   0.02 %
   --->  Element: Potassium (P)   Z =3D 19.0   N =3D  30.1   A =3D  =
30.10 g/mole  ElmMassFraction:   0.40 %  ElmAbundance   0.08 %
Step#    X(mm)    Y(mm)    Z(mm) KinE(MeV)  dE(MeV) StepLeng TrackLeng  =
NextVolume ProcName
    0      -21       51       20     0.511        0        0         0 =
CTb/IM-0003-0002 initStep
Segmentation fault: 11



The density you see above (1.099 g/cm3) is the modified density (default =
set to 1.061 g/cm3), so it is returning what it should.

If ComputeMaterial returns a pointer to the material requested in the =
Navigator, why does this not work? Is this a scoping issue?

Thanks,
Jonathan=

--Apple-Mail=_8B9946C0-714B-4906-A7A5-39EFCFF6EDD1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
 charset=us-ascii

<html><head></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; =
"><div>I have a materials question with regards to a Nested =
Parameterisation</div><div><br></div><div>In the ComputeMaterial =
function I have put:</div><div><br></div><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 11px/normal Menlo; ">&nbsp; &nbsp;&nbsp;G4Material* =
mate;</div><div><span class=3D"Apple-style-span" style=3D"font-family: =
Menlo; font-size: 11px; ">&nbsp; &nbsp;&nbsp;</span><span =
class=3D"Apple-style-span" style=3D"font-family: Menlo; font-size: 11px; =
"><span style=3D"color: #be20a0">if</span></span><span =
class=3D"Apple-style-span" style=3D"font-family: Menlo; font-size: 11px; =
">(changingDensity) {</span></div><div><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 11px/normal Menlo; ">&nbsp; &nbsp; &nbsp; &nbsp; mate =3D =
BuildMaterialWithChangingDensity(fMaterials[matIndex],ix,iy,iz);</div><div=
 style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; =
&nbsp; } <span style=3D"color: #be20a0">else</span> {</div><div =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; =
&nbsp; &nbsp; &nbsp; mate =3D fMaterials[matIndex];&nbsp;<span =
class=3D"Apple-style-span" style=3D"color: rgb(0, 133, 9); ">// =
fMaterials is defined in construction std::vector&lt;G4Materials*&gt; =
fMaterials</span></div><div style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
11px/normal Menlo; ">&nbsp; &nbsp; }</div></div><div style=3D"margin-top: =
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 11px/normal Menlo; "><br></div><div =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><div =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; =
&nbsp;&nbsp;<span style=3D"color: #be20a0">return</span> =
mate;</div><div><br></div><div><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3">Where BuildMaterialWithChangingDensity =
is:</font></div><div><font class=3D"Apple-style-span" face=3D"Helvetica" =
size=3D"3"><br></font></div><div><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3"><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 11px/normal Menlo; ">G4Material* =
DicomNestedDetectorParameterisation::BuildMaterialWithChangingDensity(G4Ma=
terial* material, G4int ix, G4int iy, G4int iz)</div><div =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 11px/normal Menlo; =
">{</div></font><font class=3D"Apple-style-span" face=3D"Helvetica" =
size=3D"3"><div style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
11px/normal Menlo; ">&nbsp; &nbsp;&nbsp;G4String origName =3D =
material-&gt;GetName();</div></font><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3"><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 11px/normal Menlo; ">&nbsp; &nbsp;&nbsp;G4int nelem =3D =
material-&gt;GetNumberOfElements();</div><p style=3D"margin: 0.0px 0.0px =
0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px">&nbsp;&nbsp; =
&nbsp;<br class=3D"webkit-block-placeholder"></p><div style=3D"margin-top:=
 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; <span =
style=3D"color: #be20a0">double</span> density =3D =
densityArray[iy][ix];</div><div style=3D"margin-top: 0px; margin-right: =
0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
11px/normal Menlo; ">&nbsp; &nbsp; <span style=3D"color: =
#be20a0">if</span>(density =3D=3D <span style=3D"color: =
#2422d7">0</span>) { density =3D <span style=3D"color: =
#2422d7">0.001290</span>; }</div><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 11px/normal Menlo; ">&nbsp; &nbsp; G4cout &lt;&lt; <span =
style=3D"color: #d62722">"New density: "</span> &lt;&lt; density =
&lt;&lt; G4endl;</div><div style=3D"margin-top: 0px; margin-right: 0px; =
margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
11px/normal Menlo; ">&nbsp; &nbsp; G4Material* mate =3D <span =
style=3D"color: #be20a0">new</span> G4Material( origName, density*g/cm3, =
nelem, kStateUndefined, STP_Temperature );</div><p style=3D"margin: =
0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: =
13.0px">&nbsp;&nbsp; &nbsp;<br class=3D"webkit-block-placeholder"></p><div=
 style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; =
&nbsp; <span style=3D"color: #be20a0">for</span>( G4int ii =3D <span =
style=3D"color: #2422d7">0</span>; ii &lt; nelem; ii++ ){</div><div =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">&nbsp; =
&nbsp; &nbsp; &nbsp; G4double frac =3D =
material-&gt;GetFractionVector()[ii];</div><div style=3D"margin-top: =
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
normal normal normal 11px/normal Menlo; ">&nbsp; &nbsp; &nbsp; &nbsp; =
G4Element* elem =3D <span style=3D"color: =
#be20a0">const_cast</span>&lt;G4Element*&gt;(material-&gt;GetElement(ii));=
</div><div style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: =
0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; =
">&nbsp; &nbsp; &nbsp; &nbsp; mate-&gt;AddElement( elem, frac =
);</div><div style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: =
0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; =
">&nbsp; &nbsp; }</div></font>&nbsp; &nbsp;&nbsp;<span style=3D"color: =
#be20a0">return</span> mate;<font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3"><div style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal =
normal normal 11px/normal Menlo; ">}</div><br></font></div><div><font =
class=3D"Apple-style-span" face=3D"Helvetica" =
size=3D"3"><br></font></div><div><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3">It works during visualization and runtime =
if changingDensity =3D false</font></div><div><font =
class=3D"Apple-style-span" face=3D"Helvetica" size=3D"3">It works during =
visualization but segfaults during runtime if changingDensity =3D =
true;</font></div><div><font class=3D"Apple-style-span" face=3D"Helvetica"=
 size=3D"3"><br></font></div><div><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3"><br></font></div><div><font =
class=3D"Apple-style-span" face=3D"Helvetica" size=3D"3">Here is the =
segfault when changingDensity =3D true:</font></div><div><font =
class=3D"Apple-style-span" face=3D"Helvetica" =
size=3D"3"><br></font></div><div><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3"><br></font></div><div><font =
class=3D"Apple-style-span" face=3D"Helvetica" size=3D"3"><div>---&gt; =
Begin of EV: 0 (0 s)</div><div>1 vertices passed from =
G4Event.</div><div>Primary particle (alpha) --- Transfered with momentum =
(-59.6816,10.8671,11.3865)</div><div>A new track 0x7fcc8483df80 (trackID =
1, parentID 0) is passed to G4StackManager.</div><div>1 primaries are =
passed from G4EventTransformer.</div><div>!!!!!!! Now start processing =
an event !!!!!!!</div><div>### pop requested out of 1 stacked =
tracks.</div><div>Track 0x7fcc8483df80 (trackID 1, parentID 0) is passed =
to =
G4TrackingManager.</div><div><br></div><div>******************************=
**************************************************************************=
*</div><div>* G4Track Information: &nbsp; Particle =3D alpha, &nbsp; =
Track ID =3D 1, &nbsp; Parent ID =3D =
0</div><div>**************************************************************=
*******************************************</div><div><br></div><div>*** =
G4Navigator::LocateGlobalPointAndSetup: ***</div><div>&nbsp; &nbsp; =
Called with arguments:&nbsp;</div><div>&nbsp; &nbsp; Globalpoint =3D =
(-21,51,20)</div><div>&nbsp; &nbsp; RelativeSearch =3D 0</div><div>Copy =
Number: 157930, ix,iy,iz: (234,308,0)</div><div>New density: =
1.0988</div><div>New Material: &nbsp;Material: &nbsp; Muscle &nbsp; =
&nbsp;density: &nbsp;1.099 g/cm3 &nbsp; RadL: &nbsp;33.118 cm &nbsp; =
Nucl.Int.Length: &nbsp;68.801 cm &nbsp; Imean: &nbsp;69.793 =
eV&nbsp;</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Hydrogen (H) =
&nbsp; Z =3D &nbsp;1.0 &nbsp; N =3D &nbsp; 1.0 &nbsp; A =3D &nbsp; 1.01 =
g/mole &nbsp;ElmMassFraction: &nbsp;10.20 % &nbsp;ElmAbundance =
&nbsp;63.14 %</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Carbon (C) =
&nbsp; Z =3D &nbsp;6.0 &nbsp; N =3D &nbsp;12.0 &nbsp; A =3D &nbsp;12.01 =
g/mole &nbsp;ElmMassFraction: &nbsp;14.30 % &nbsp;ElmAbundance &nbsp; =
7.43 %</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Nitrogen (N) &nbsp; =
Z =3D &nbsp;7.0 &nbsp; N =3D &nbsp;14.0 &nbsp; A =3D &nbsp;14.01 g/mole =
&nbsp;ElmMassFraction: &nbsp; 3.40 % &nbsp;ElmAbundance &nbsp; 1.51 =
%</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Oxygen (O) &nbsp; Z =3D =
&nbsp;8.0 &nbsp; N =3D &nbsp;16.0 &nbsp; A =3D &nbsp;16.00 g/mole =
&nbsp;ElmMassFraction: &nbsp;71.00 % &nbsp;ElmAbundance &nbsp;27.69 =
%</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Sodium (Na) &nbsp; Z =3D =
11.0 &nbsp; N =3D &nbsp;23.0 &nbsp; A =3D &nbsp;22.99 g/mole =
&nbsp;ElmMassFraction: &nbsp; 0.10 % &nbsp;ElmAbundance &nbsp; 0.03 =
%</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Phosphorus (P) &nbsp; Z =
=3D 30.0 &nbsp; N =3D &nbsp;31.0 &nbsp; A =3D &nbsp;30.97 g/mole =
&nbsp;ElmMassFraction: &nbsp; 0.20 % &nbsp;ElmAbundance &nbsp; 0.04 =
%</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Sulfur (S) &nbsp; Z =3D =
16.0 &nbsp; N =3D &nbsp;32.1 &nbsp; A =3D &nbsp;32.06 g/mole =
&nbsp;ElmMassFraction: &nbsp; 0.30 % &nbsp;ElmAbundance &nbsp; 0.06 =
%</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Chlorine (P) &nbsp; Z =3D =
17.0 &nbsp; N =3D &nbsp;35.5 &nbsp; A =3D &nbsp;35.45 g/mole =
&nbsp;ElmMassFraction: &nbsp; 0.10 % &nbsp;ElmAbundance &nbsp; 0.02 =
%</div><div>&nbsp; &nbsp;---&gt; &nbsp;Element: Potassium (P) &nbsp; Z =3D=
 19.0 &nbsp; N =3D &nbsp;30.1 &nbsp; A =3D &nbsp;30.10 g/mole =
&nbsp;ElmMassFraction: &nbsp; 0.40 % &nbsp;ElmAbundance &nbsp; 0.08 =
%</div><div>Step# &nbsp; &nbsp;X(mm) &nbsp; &nbsp;Y(mm) &nbsp; =
&nbsp;Z(mm) KinE(MeV) &nbsp;dE(MeV) StepLeng TrackLeng &nbsp;NextVolume =
ProcName</div><div>&nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp;-21 &nbsp; &nbsp; =
&nbsp; 51 &nbsp; &nbsp; &nbsp; 20 &nbsp; &nbsp; 0.511 &nbsp; &nbsp; =
&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; =
0 CTb/IM-0003-0002 initStep</div><div>Segmentation fault: =
11</div><div><br></div><div><br></div><div><br></div><div>The density =
you see above (1.099 g/cm3) is the modified density (default set to =
1.061 g/cm3), so it is returning what it =
should.</div></font></div><div><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3"><br></font></div><div><font =
class=3D"Apple-style-span" face=3D"Helvetica" size=3D"3">If =
ComputeMaterial returns a pointer to the material requested in the =
Navigator, why does this not work? Is this a scoping =
issue?</font></div><div><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3"><br></font></div><div><font =
class=3D"Apple-style-span" face=3D"Helvetica" =
size=3D"3">Thanks,</font></div><div><font class=3D"Apple-style-span" =
face=3D"Helvetica" size=3D"3">Jonathan</font></div></div></body></html>=

--Apple-Mail=_8B9946C0-714B-4906-A7A5-39EFCFF6EDD1--

 Add Message Add Message
to: "Nested Parameterisation: Seg fault with Changing Densities"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]