69 #include "CommandLineParser.hh"
73 using namespace G4DNAPARSER;
84 fNeuronFileNameSWC =
G4String(
"GranuleCell-Nr2.CNG.swc");
89 fNeuronFileNameDATA =
G4String(
"NeuralNETWORK.dat");
92 if((commandLine=CommandLineParser::GetParser()->GetCommandIfActive(
"-swc")))
95 SingleNeuronSWCfile(fNeuronFileNameSWC);
101 if ((commandLine =CommandLineParser::GetParser()->
102 GetCommandIfActive(
"-network")))
105 NeuralNetworkDATAfile(fNeuronFileNameDATA);
109 SingleNeuronSWCfile(fNeuronFileNameSWC);
132 std::ifstream infile;
133 infile.open(filename.c_str());
137 G4cout<<
"\n NeuronLoadDataFile::SingleNeuronSWCfile >> datafile "
138 <<filename<<
" not found !!!!"<<
G4endl;
145 G4cout<<
"\n NeuronLoadDataFile::SingleNeuronSWCfile >> opening filename: "
146 <<
"\n" <<
'\t'<<
'\t'<<
'\t'<<
'\t'<<
'\t'<<
"' "<<filename
152 while (getline(infile, sLine))
154 fnNn =
new G4int[nrows];
155 fpNn =
new G4int[nrows];
156 fnNd =
new G4int[nrows];
157 fpNd =
new G4int[nrows];
158 fnNa =
new G4int[nrows];
159 fpNa =
new G4int[nrows];
164 infile.open(filename.c_str());
167 fnbDendritecomp = 0 ;
170 G4double TotVolSoma, TotVolDend, TotVolAxon, TotVolSpine;
171 TotVolSoma=TotVolDend=TotVolAxon=TotVolSpine=0.;
172 G4double TotSurfSoma, TotSurfDend, TotSurfAxon, TotSurfSpine;
173 TotSurfSoma=TotSurfDend=TotSurfAxon=TotSurfSpine=0.;
182 minX=minY=minZ=1
e+09;
183 maxX=maxY=maxZ=-1
e+09;
187 fMassSomacomp =
new G4double[nrows];
193 fHeightDendcomp=
new G4double[nrows];
194 fMassDendcomp =
new G4double[nrows];
196 fDistADendSoma =
new G4double[nrows];
197 fDistBDendSoma =
new G4double[nrows];
202 fHeightAxoncomp=
new G4double[nrows];
203 fMassAxoncomp =
new G4double[nrows];
205 fDistAxonsoma =
new G4double[nrows];
208 fMassSpinecomp =
new G4double[nrows];
209 fMassSpineTot = 0.0 ;
211 fRadSpinecomp =
new G4double[nrows];
213 fRadNeuroncomp =
new G4double[nrows];
214 fHeightNeuroncomp =
new G4double[nrows];
215 fDistNeuronsoma =
new G4double[nrows];
219 fRadNeuroncomp =
new G4double[nrows];
220 fTypeN =
new G4int[nrows];
223 while (getline(infile, sLine))
225 std::istringstream form(sLine);
227 while (getline(form, token,
':'))
229 std::istringstream found(token);
230 while (found >> nNcomp >> typeNcomp >> x >> y >> z >> radius >> pNcomp)
235 if (minX > x) minX =
x;
236 if (minY > y) minY =
y;
237 if (minZ > z) minZ =
z;
238 if (maxX < x) maxX =
x;
239 if (maxY < y) maxY =
y;
240 if (maxZ < z) maxZ =
z;
242 if (maxRad < radius) maxRad =
radius;
249 G4double VolSomacomp = Piconst*pow(radius*
um,3.) ;
250 TotVolSoma = TotVolSoma + VolSomacomp;
251 G4double SurSomacomp = 3.*Piconst*pow(radius*um,2.) ;
252 TotSurfSoma = TotSurfSoma + SurSomacomp;
258 fMassSomacomp[fnbSomacomp] = density*VolSomacomp;
259 fMassSomaTot = fMassSomaTot + fMassSomacomp[fnbSomacomp];
261 fPosSomacomp [fnbSomacomp] = vSoma;
262 fRadSomacomp [fnbSomacomp]=
radius;
271 if (typeNcomp == 3 || typeNcomp == 4)
275 PosDendcomp [fnbDendritecomp] = vDend;
276 fRadDendcomp [fnbDendritecomp]=
radius;
277 fnNd[fnbDendritecomp]= nNcomp-(fnbSomacomp+fnbAxoncomp)-1;
278 fpNd[fnbDendritecomp]= pNcomp-(fnbSomacomp+fnbAxoncomp)-1;
283 G4double Dendxx= PosDendcomp[fnNd[fnbDendritecomp]].
x()+
284 PosDendcomp[fpNd[fnbDendritecomp]].
x();
285 G4double Dendyy= PosDendcomp[fnNd[fnbDendritecomp]].
y()+
286 PosDendcomp[fpNd[fnbDendritecomp]].
y();
287 G4double Dendzz= PosDendcomp[fnNd[fnbDendritecomp]].
z()+
288 PosDendcomp[fpNd[fnbDendritecomp]].
z();
290 Dendyy/2. , Dendzz/2.) ;
291 fPosDendcomp [fnbDendritecomp] = translmDend;
295 if (fpNd[fnbDendritecomp] == -fnbSomacomp)
297 Dendx= PosDendcomp[fnNd[fnbDendritecomp]].
x()-
298 (fPosSomacomp[0].x()+fRadSomacomp[0]);
299 Dendy= PosDendcomp[fnNd[fnbDendritecomp]].
y()-
300 (fPosSomacomp[0].y()+fRadSomacomp[0]);
301 Dendz= PosDendcomp[fnNd[fnbDendritecomp]].
z()-
302 (fPosSomacomp[0].z()+fRadSomacomp[0]);
306 Dendx= PosDendcomp[fnNd[fnbDendritecomp]].
x()-
307 PosDendcomp[fpNd[fnbDendritecomp]].
x();
308 Dendy= PosDendcomp[fnNd[fnbDendritecomp]].
y()-
309 PosDendcomp[fpNd[fnbDendritecomp]].
y();
310 Dendz= PosDendcomp[fnNd[fnbDendritecomp]].
z()-
311 PosDendcomp[fpNd[fnbDendritecomp]].
z();
313 G4double lengthDendcomp = std::sqrt(Dendx*Dendx+Dendy*Dendy+Dendz*Dendz);
315 fHeightDendcomp [fnbDendritecomp]= lengthDendcomp;
318 G4double DendDisx= fPosSomacomp[0].x()-
319 fPosDendcomp [fnbDendritecomp].x();
320 G4double DendDisy= fPosSomacomp[0].y()-
321 fPosDendcomp [fnbDendritecomp].y();
322 G4double DendDisz= fPosSomacomp[0].z()-
323 fPosDendcomp [fnbDendritecomp].z();
324 if (typeNcomp == 3) fDistADendSoma[fnbDendritecomp] =
325 std::sqrt(DendDisx*DendDisx + DendDisy*DendDisy + DendDisz*DendDisz);
326 if (typeNcomp == 4) fDistBDendSoma[fnbDendritecomp] =
327 std::sqrt(DendDisx*DendDisx + DendDisy*DendDisy + DendDisz*DendDisz);
331 TotVolDend = TotVolDend + VolDendcomp;
332 G4double SurDendcomp = 2.*
pi*radius*um*(radius+lengthDendcomp)*um;
333 TotSurfDend = TotSurfDend + SurDendcomp;
334 fMassDendcomp[fnbDendritecomp] = density*VolDendcomp;
335 fMassDendTot = fMassDendTot + fMassDendcomp[fnbDendritecomp];
337 Dendx=Dendx/lengthDendcomp;
338 Dendy=Dendy/lengthDendcomp;
339 Dendz=Dendz/lengthDendcomp;
375 fRotDendcomp [fnbDendritecomp]= rotmDend ;
386 PosAxoncomp [fnbAxoncomp] = vAxon;
387 fRadAxoncomp [fnbAxoncomp]=
radius;
388 fnNa[fnbAxoncomp]= nNcomp-(fnbSomacomp+fnbDendritecomp)-1;
389 fpNa[fnbAxoncomp]= pNcomp-(fnbSomacomp+fnbDendritecomp)-1;
394 G4double Axonxx= PosAxoncomp[fnNa[fnbAxoncomp]].
x()+
395 PosAxoncomp[fpNa[fnbAxoncomp]].
x();
396 G4double Axonyy= PosAxoncomp[fnNa[fnbAxoncomp]].
y()+
397 PosAxoncomp[fpNa[fnbAxoncomp]].
y();
398 G4double Axonzz= PosAxoncomp[fnNa[fnbAxoncomp]].
z()+
399 PosAxoncomp[fpNa[fnbAxoncomp]].
z();
401 Axonyy/2. , Axonzz/2.) ;
402 fPosAxoncomp [fnbAxoncomp] = translmAxon;
406 if (fpNa[fnbAxoncomp] == -(fnbSomacomp+fnbDendritecomp))
408 Axonx= PosAxoncomp[fnNa[fnbAxoncomp]].
x()-
409 (fPosSomacomp[0].x()+fRadSomacomp[0]);
410 Axony= PosAxoncomp[fnNa[fnbAxoncomp]].
y()-
411 (fPosSomacomp[0].y()+fRadSomacomp[0]);
412 Axonz= PosAxoncomp[fnNa[fnbAxoncomp]].
z()-
413 (fPosSomacomp[0].z()+fRadSomacomp[0]);
417 Axonx= PosAxoncomp[fnNa[fnbAxoncomp]].
x()-
418 PosAxoncomp[fpNa[fnbAxoncomp]].
x();
419 Axony= PosAxoncomp[fnNa[fnbAxoncomp]].
y()-
420 PosAxoncomp[fpNa[fnbAxoncomp]].
y();
421 Axonz= PosAxoncomp[fnNa[fnbAxoncomp]].
z()-
422 PosAxoncomp[fpNa[fnbAxoncomp]].
z();
424 G4double lengthAxoncomp = std::sqrt(Axonx*Axonx+Axony*Axony+Axonz*Axonz);
426 fHeightAxoncomp [fnbAxoncomp]= lengthAxoncomp;
429 G4double AxonDisx= fPosSomacomp[0].x()-
430 fPosAxoncomp [fnbAxoncomp].x();
431 G4double AxonDisy= fPosSomacomp[0].y()-
432 fPosAxoncomp [fnbAxoncomp].y();
433 G4double AxonDisz= fPosSomacomp[0].z()-
434 fPosAxoncomp [fnbAxoncomp].z();
435 fDistAxonsoma[fnbAxoncomp] = std::sqrt(AxonDisx*AxonDisx +
436 AxonDisy*AxonDisy + AxonDisz*AxonDisz);
440 TotVolAxon = TotVolAxon + VolAxoncomp;
441 G4double SurAxoncomp = 2.*
pi*radius*um*(radius+lengthAxoncomp)*um;
442 TotSurfAxon = TotSurfAxon + SurAxoncomp;
443 fMassAxoncomp[fnbAxoncomp] = density*VolAxoncomp;
444 fMassAxonTot = fMassAxonTot + fMassAxoncomp[fnbAxoncomp];
445 Axonx=Axonx/lengthAxoncomp;
446 Axony=Axony/lengthAxoncomp;
447 Axonz=Axonz/lengthAxoncomp;
461 fRotAxoncomp [fnbAxoncomp]= rotmAxon ;
467 if (typeNcomp != 1 && typeNcomp != 2 && typeNcomp != 3 && typeNcomp != 4)
469 G4cout <<
" Additional types:--> "<< typeNcomp <<
G4endl;
479 G4double VolSpinecomp = Piconst*pow(radius*
um,3.) ;
480 TotVolSpine = TotVolSpine + VolSpinecomp;
481 G4double SurSpinecomp = 3.*Piconst*pow(radius*um,2.) ;
482 TotSurfSpine = TotSurfSpine + SurSpinecomp;
483 fMassSpinecomp[fnbSpinecomp] = density*VolSpinecomp;
484 fMassSpineTot = fMassSpineTot + fMassSpinecomp[fnbSpinecomp];
489 fPosSpinecomp [fnbSpinecomp] = vSpine;
490 fRadSpinecomp [fnbSpinecomp] =
radius;
500 fTypeN[
nlines] = typeNcomp;
503 PosNeuroncomp [
nlines] = vNeuron;
512 PosNeuroncomp[fpNn[
nlines]].
x();
514 PosNeuroncomp[fpNn[
nlines]].
y();
516 PosNeuroncomp[fpNn[
nlines]].
z();
518 Neuronyy/2. , Neuronzz/2.) ;
519 fPosNeuroncomp [
nlines] = translmNeuron;
523 if (fpNn[nlines] == -2)
525 Neuronx= PosNeuroncomp[fnNn[
nlines]].
x()-
526 fPosNeuroncomp[0].x();
527 Neurony= PosNeuroncomp[fnNn[
nlines]].
y()-
528 fPosNeuroncomp[0].y();
529 Neuronz= PosNeuroncomp[fnNn[
nlines]].
z()-
530 fPosNeuroncomp[0].z();
534 Neuronx= PosNeuroncomp[fnNn[
nlines]].
x()-
535 PosNeuroncomp[fpNn[
nlines]].
x();
536 Neurony= PosNeuroncomp[fnNn[
nlines]].
y()-
537 PosNeuroncomp[fpNn[
nlines]].
y();
538 Neuronz= PosNeuroncomp[fnNn[
nlines]].
z()-
539 PosNeuroncomp[fpNn[
nlines]].
z();
541 G4double lengthNeuroncomp = std::sqrt(Neuronx*Neuronx+
542 Neurony*Neurony+Neuronz*Neuronz);
544 fHeightNeuroncomp [
nlines]= lengthNeuroncomp;
546 G4double NeuronDisx= fPosNeuroncomp[0].x()-
547 fPosNeuroncomp [
nlines].x();
548 G4double NeuronDisy= fPosNeuroncomp[0].y()-
549 fPosNeuroncomp [
nlines].y();
550 G4double NeuronDisz= fPosNeuroncomp[0].z()-
551 fPosNeuroncomp [
nlines].z();
552 fDistNeuronsoma[
nlines] = std::sqrt(NeuronDisx*NeuronDisx +
553 NeuronDisy*NeuronDisy + NeuronDisz*NeuronDisz);
563 Neuronx=Neuronx/lengthNeuroncomp;
564 Neurony=Neurony/lengthNeuroncomp;
565 Neuronz=Neuronz/lengthNeuroncomp;
575 phi_eulerNeuron+
pi/2,
579 fRotNeuroncomp [
nlines]= rotmNeuron ;
589 G4cout <<
" Total number of compartments into Neuron : "
594 fshiftX = (minX + maxX)/2. ;
595 fshiftY = (minY +
maxY)/2. ;
596 fshiftZ = (minZ +
maxZ)/2. ;
600 fwidthB = std::fabs(minX - maxX) + maxRad;
601 fheightB = std::fabs(minY - maxY) + maxRad;
602 fdepthB = std::fabs(minZ - maxZ) + maxRad;
606 fdiagnlLength = std::sqrt(fwidthB*fwidthB + fheightB*fheightB
609 fTotVolNeuron = TotVolSoma+TotVolDend+TotVolAxon;
610 fTotSurfNeuron = TotSurfSoma+TotSurfDend+TotSurfAxon;
611 fTotMassNeuron = fMassSomaTot+fMassDendTot+fMassAxonTot;
613 fTotVolSlice = fwidthB*
um*fheightB*
um*fdepthB*
um;
614 fTotSurfSlice = 2*(fwidthB*um*fheightB*um+fheightB*um*fdepthB*um+
615 fwidthB*um*fdepthB*
um);
616 fTotMassSlice = 1.0 * (
g/
cm3) *fTotVolSlice;
618 fTotVolMedium = Piconst*pow(fdiagnlLength*um/2.,3.) ;
619 fTotSurfMedium = 3.*Piconst*pow(fdiagnlLength*um/2.,2);
620 fTotMassMedium = 1.0 * (
g/
cm3) *fTotVolMedium;
625 fSomaColour->SetForceSolid(
true);
626 fSomaColour->SetVisibility(
true);
631 fDendColour->SetForceSolid(
true);
637 fAxonColour->SetForceSolid(
true);
638 fAxonColour->SetVisibility(
true);
643 fSpineColour->SetForceSolid(
true);
644 fSpineColour->SetVisibility(
true);
649 fNeuronColour->SetForceSolid(
true);
650 fNeuronColour->SetVisibility(
true);
664 std::ifstream infile;
665 infile.open(filename.c_str());
669 G4cout<<
" \n NeuronLoadDataFile::NeuralNetworkDATAfile >> datafile "
670 <<filename<<
" not found !!!!"<<
G4endl;
677 G4cout<<
" NeuronLoadDataFile::NeuralNetworkDATAfile >> opening filename: "
678 <<
"\n" <<
'\t'<<
'\t'<<
'\t'<<
'\t'<<
'\t'<<
"' "<<filename
685 fnbDendritecomp = 0 ;
688 G4double TotVolSoma, TotVolDend, TotVolAxon;
689 TotVolSoma=TotVolDend=TotVolAxon=0.;
690 G4double TotSurfSoma, TotSurfDend, TotSurfAxon;
691 TotSurfSoma=TotSurfDend=TotSurfAxon=0.;
705 while (getline(infile, sLine))
707 std::istringstream form(sLine);
710 form >> fnbNeuroncomp >> nbSoma >> nbDendrite ;
711 fMassSomacomp =
new G4double[nbSoma];
714 fRadSomacomp =
new G4double[nbSoma];
715 fRadDendcomp =
new G4double[nbDendrite];
716 fHeightDendcomp =
new G4double[nbDendrite];
717 fMassDendcomp =
new G4double[nbDendrite];
719 fDistADendSoma =
new G4double[nbDendrite];
720 fDistBDendSoma =
new G4double[nbDendrite];
726 if (nlines > 0 && nlines <= nbSoma)
728 form >> typeNcomp >> x1 >> y1 >> z1 >>
radius ;
729 if (typeNcomp !=1)
break;
731 if (maxRad < radius) maxRad =
radius;
733 G4double VolSomacomp = Piconst*pow(radius*
um,3.) ;
734 TotVolSoma = TotVolSoma + VolSomacomp;
735 G4double SurSomacomp = 3.*Piconst*pow(radius*um,2.) ;
736 TotSurfSoma = TotSurfSoma + SurSomacomp;
737 fMassSomacomp[fnbSomacomp] = density*VolSomacomp;
738 fMassSomaTot = fMassSomaTot + fMassSomacomp[fnbSomacomp];
746 fPosSomacomp [fnbSomacomp] = vSoma;
747 fRadSomacomp [fnbSomacomp]=
radius;
755 if (nlines > nbSoma && nlines <= fnbNeuroncomp)
757 form >> typeNcomp >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> radius >> height;
758 if (typeNcomp != 3 )
break;
766 Dendyy/2. , Dendzz/2.) ;
767 fPosDendcomp [fnbDendritecomp] = translmDend;
768 fRadDendcomp [fnbDendritecomp]=
radius;
771 fHeightDendcomp [fnbDendritecomp]= lengthDendcomp;
776 TotVolDend = TotVolDend + VolDendcomp;
777 G4double SurDendcomp = 2.*
pi*radius*um*(radius+lengthDendcomp)*um;
778 TotSurfDend = TotSurfDend + SurDendcomp;
779 fMassDendcomp[fnbDendritecomp] = density*VolDendcomp;
780 fMassDendTot = fMassDendTot + fMassDendcomp[fnbDendritecomp];
785 Dendx=Dendx/lengthDendcomp;
786 Dendy=Dendy/lengthDendcomp;
787 Dendz=Dendz/lengthDendcomp;
802 fRotDendcomp [fnbDendritecomp]= rotmDend ;
814 G4cout <<
" Total number of compartments into Neuron : "<<
830 fdiagnlLength = std::sqrt(fwidthB*fwidthB + fheightB*fheightB
833 fTotVolNeuron = TotVolSoma+TotVolDend+TotVolAxon;
834 fTotSurfNeuron = TotSurfSoma+TotSurfDend+TotSurfAxon;
835 fTotMassNeuron = fMassSomaTot+fMassDendTot+fMassAxonTot;
837 fTotVolSlice = fwidthB*
um*fheightB*
um*fdepthB*
um;
838 fTotSurfSlice = 2*(fwidthB*um*fheightB*um+fheightB*um*fdepthB*um+
839 fwidthB*um*fdepthB*
um);
840 fTotMassSlice = 1.0 * (
g/
cm3) *fTotVolSlice;
842 fTotVolMedium = Piconst*pow(fdiagnlLength*um/2.,3.) ;
843 fTotSurfMedium = 3.*Piconst*pow(fdiagnlLength*um/2.,2);
844 fTotMassMedium = 1.0 * (
g/
cm3) *fTotVolMedium;
854 delete[] fMassSomacomp ;
855 delete[] fPosSomacomp ;
856 delete[] fRadSomacomp ;
857 delete[] fRadDendcomp ;
858 delete[] fHeightDendcomp;
859 delete[] fMassDendcomp ;
860 delete[] fDistADendSoma ;
861 delete[] fDistBDendSoma ;
862 delete[] fPosDendcomp ;
863 delete[] fRotDendcomp ;
864 delete[] fRadAxoncomp ;
865 delete[] fHeightAxoncomp;
866 delete[] fMassAxoncomp ;
867 delete[] fDistAxonsoma ;
868 delete[] fPosAxoncomp ;
869 delete[] fRotAxoncomp ;
870 delete[] fRadNeuroncomp ;
871 delete[] fHeightNeuroncomp;
872 delete[] fMassNeuroncomp ;
873 delete[] fDistNeuronsoma ;
874 delete[] fPosNeuroncomp ;
875 delete[] fRotNeuroncomp ;
900 G4double cosX = std::sqrt (rotmNeuron.
xx()*rotmNeuron.
xx() +
901 rotmNeuron.
yx()*rotmNeuron.
yx()) ;
905 euX = std::atan2 (rotmNeuron.
zy(),rotmNeuron.
zz());
906 euY = std::atan2 (-rotmNeuron.
zx(),cosX);
907 euZ = std::atan2 (rotmNeuron.
yx(),rotmNeuron.
xx());
911 euX = std::atan2 (-rotmNeuron.
yz(),rotmNeuron.
yy());
912 euY = std::atan2 (-rotmNeuron.
zx(),cosX);
925 (fPosNeuroncomp[copyNo].
x()-fshiftX) *
um,
926 (fPosNeuroncomp[copyNo].
y()-fshiftY) * um,
927 (fPosNeuroncomp[copyNo].
z()-fshiftZ) * um
virtual const G4String & GetOption()
CLHEP::Hep3Vector G4ThreeVector
void SetInnerRadius(G4double newRMin)
void SetOuterRadius(G4double newRMax)
Float_t y1[n_points_granero]
Implementation of the NeuronLoadDataFile class.
Float_t x1[n_points_granero]
CLHEP::HepRotation G4RotationMatrix
void SetTranslation(const G4ThreeVector &v)
void SingleNeuronSWCfile(const G4String &filename)
static constexpr double um
Float_t y2[n_points_geant4]
static constexpr double g
void ComputeDimensions(G4Tubs &cylinderComp, const G4int copyNo, const G4VPhysicalVolume *) const
void SetStartPhiAngle(G4double newSPhi, G4bool trig=true)
static constexpr double deg
void SetZHalfLength(G4double newDz)
void ComputeTransformation(const G4int copyNo, G4VPhysicalVolume *physVol) const
void NeuralNetworkDATAfile(const G4String &filename)
void SetDeltaPhiAngle(G4double newDPhi)
virtual ~NeuronLoadDataFile()
HepRotation & rotateY(double delta)
HepRotation & rotateZ(double delta)
G4GLOB_DLL std::ostream G4cout
void SetColour(const G4Colour &)
void SetRotation(G4RotationMatrix *)
static constexpr double pi
Float_t x2[n_points_geant4]
static constexpr double cm3
HepRotation & rotateX(double delta)
HepRotation inverse() const