49 G4String FileExperimentalData,
G4String FileExperimentalDataOut):startCurve(0),
50 stopCurve(0),chi2Factor(0)
53 sprintf(a,
"%d", seed);
55 saving_in_Selected_Voxels_every_events=saveEvents;
59 fullFileOut=FileExperimentalDataOut+seedName+
".m";
60 fullFileIn=FileExperimentalData;
61 nParticle=nTotalEvents=0;
65 minZone.
set(extr, extr, extr);
66 maxZone.
set(-extr, -extr, -extr);
67 bHasExperimentalData=bData;
75 delete [] nVoxelsgeometry;
79 bHasExperimentalData=
true;
91 in.getline(a,1000,
'\n'); headerText1=(
G4String)a;
92 in.getline(a,1000,
'\n');
94 startCurve=
new G4int[nCurves];
95 stopCurve=
new G4int[nCurves];
97 for (
int i=0; i< nCurves; i++)
104 in.getline(a,1000,
'\n');
105 in.getline(a,1000,
'\n'); headerText2=(
G4String)a;
111 if (bHasExperimentalData)
127 voxels.push_back(voxel);
130 if (minZone.
getX()>pos.getX()-halfSize.getX())
131 {minZone.
setX(pos.getX()-halfSize.getX());}
132 if (maxZone.
getX()<pos.getX()+halfSize.getX())
133 {maxZone.
setX(pos.getX()+halfSize.getX());}
135 if (minZone.
getY()>pos.getY()-halfSize.getY())
136 {minZone.
setY(pos.getY()-halfSize.getY());}
137 if (maxZone.
getY()<pos.getY()+halfSize.getY())
138 {maxZone.
setY(pos.getY()+halfSize.getY());}
140 if (minZone.
getZ()>pos.getZ()-halfSize.getZ())
141 {minZone.
setZ(pos.getZ()-halfSize.getZ());}
142 if (maxZone.
getZ()<pos.getZ()+halfSize.getZ())
143 {maxZone.
setZ(pos.getZ()+halfSize.getZ());}
149 std::cout <<
"ERROR I can't find the experimental data file" <<
G4endl;
154 nVoxelsgeometry=
new G4int[(
G4int) voxels.size()];
161 for (
int i=0; i<(
int) voxels.size(); i++ )
162 {nVoxelsgeometry[i]=0;}
184 for (
int i=0; i<(
int)voxels.size(); i++)
186 minPos=voxels[i].pos-voxels[i].halfSize;
187 maxPos=voxels[i].pos+voxels[i].halfSize;
192 voxelVolume=voxels[i].halfSize.getX()*voxels[i].halfSize.getY()*voxels[i].halfSize.getZ()*8.;
193 voxelMass=density*voxelVolume;
195 dose=depEnergy/(voxelMass*nRecycling);
197 nVoxelsgeometry[i]++;
198 voxels[i].depEnergy+=
dose;
199 voxels[i].depEnergy2+=dose*
dose;
217 if (nTotalEvents%saving_in_Selected_Voxels_every_events==0 && nTotalEvents>0)
227 int n=voxels[0].nEvents;
228 for (
int i=0;i<(
int)voxels.size();i++)
230 if (n>voxels[i].nEvents){n = voxels[i].nEvents;}
236 int n=nVoxelsgeometry[0];
237 for (
int i=0;i<(
int)voxels.size();i++)
239 if (n<nVoxelsgeometry[i]){n = nVoxelsgeometry[i];}
243 void CML2ExpVoxels::saveHeader()
246 out.open(fullFileOut, std::ios::out);
247 out <<
"% "<< headerText1 <<
G4endl;
248 out <<
"n"<< seedName<<
"="<< nCurves<<
";" <<
G4endl;
249 out <<
"fh"<< seedName<<
"=["<<
G4endl;
250 for (
int i=0; i< nCurves; i++)
252 out << startCurve[i] <<
'\t';
253 out << stopCurve[i] <<
'\t';
254 out << chi2Factor[i]<<
G4endl;
257 out <<
"% x [mm], y [mm], z [mm], Dx [mm], Dy [mm], Dz [mm], expDose [Gy], Calculated dose [Gy], Calculated dose2 [Gy^2], nEvents, normDose [Gy], normDoseError [Gy]";
266 calculateNormalizedEd(voxels);
270 out <<
"d"<< seedName<<
"=["<<
G4endl;
271 for (
int i=0; i<(
int)voxels.size(); i++)
273 out <<voxels[i].pos.getX()/
mm<<
'\t'<<voxels[i].pos.getY()/
mm<<
'\t'<<voxels[i].pos.getZ()/
mm<<
'\t';
274 out <<voxels[i].halfSize.getX()/
mm<<
'\t'<<voxels[i].halfSize.getY()/
mm<<
'\t'<<voxels[i].halfSize.getZ()/
mm<<
'\t';
275 out <<voxels[i].expDose/(
joule/
kg)<<
'\t'<<voxels[i].depEnergy/(
joule/
kg)<<
'\t'<<voxels[i].depEnergy2/((
joule/
kg)*(
joule/
kg))<<
'\t'<<voxels[i].nEvents<<
'\t';
276 out <<voxels[i].depEnergyNorm/(
joule/
kg)<<
'\t'<<voxels[i].depEnergyNormError/(
joule/
kg);
284 void CML2ExpVoxels::calculateNormalizedEd(std::vector <Svoxel> &
vox)
291 for (j=0;j<nCurves;j++)
294 for (i=startCurve[j]-1;i<stopCurve[j];i++)
296 cs+=vox[i].depEnergy*vox[i].expDose;
297 cc+=vox[i].depEnergy*vox[i].depEnergy;
303 for (i=startCurve[j]-1;i<stopCurve[j];i++)
305 dd=vox[i].depEnergy*vox[i].depEnergy;
306 d2=vox[i].depEnergy2;
308 vox[i].depEnergyNorm=chi2Factor[j]*vox[i].depEnergy;
311 if (n>1){vox[i].depEnergyNormError=chi2Factor[j]*std::sqrt(v/(n-1));}
312 if (n==1){vox[i].depEnergyNormError=vox[i].depEnergyNorm;}