1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // Author: Andrei Gheata 10/07/2003
19 #include "TObjString.h"
20 #include "TFlukaGeo.h"
21 #include "TFlukaMCGeometry.h"
22 #include "TGeoManager.h"
23 #include "TGeoVolume.h"
28 # define idnrwr idnrwr_
30 # define g1rtwr g1rtwr_
31 # define conhwr conhwr_
32 # define inihwr inihwr_
33 # define jomiwr jomiwr_
34 # define lkdbwr lkdbwr_
35 # define lkfxwr lkfxwr_
36 # define lkmgwr lkmgwr_
38 # define magfld magfld_
39 # define nrmlwr nrmlwr_
40 # define rgrpwr rgrpwr_
41 # define isvhwr isvhwr_
45 # define idnrwr IDNRWR
47 # define g1rtwr G1RTWR
48 # define conhwr CONHWR
49 # define inihwr INIHWR
50 # define jomiwr JOMIWR
51 # define lkdbwr LKDBWR
52 # define lkfxwr LKFXWR
53 # define lkmgwr LKMGWR
55 # define magfld MAGFLD
56 # define nrmlwr NRMLWR
57 # define rgrpwr RGRPWR
58 # define isvhwr ISVHWR
62 //____________________________________________________________________________
66 // Prototypes for FLUKA navigation methods
68 Int_t type_of_call idnrwr(const Int_t & /*nreg*/, const Int_t & /*mlat*/);
69 void type_of_call g1wr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
70 Double_t * /*pV*/, Int_t & /*oldReg*/ , const Int_t & /*oldLttc*/, Double_t & /*propStep*/,
71 Int_t & /*nascFlag*/, Double_t & /*retStep*/, Int_t & /*newReg*/,
72 Double_t & /*saf*/, Int_t & /*newLttc*/, Int_t & /*LttcFlag*/,
73 Double_t *s /*Lt*/, Int_t * /*jrLt*/);
75 void type_of_call g1rtwr();
76 void type_of_call conhwr(Int_t & /*intHist*/, Int_t * /*incrCount*/);
77 void type_of_call inihwr(Int_t & /*intHist*/);
78 void type_of_call jomiwr(const Int_t & /*nge*/, const Int_t & /*lin*/, const Int_t & /*lou*/,
79 Int_t & /*flukaReg*/);
80 void type_of_call lkdbwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
81 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
82 Int_t & /*newReg*/, Int_t & /*flagErr*/, Int_t & /*newLttc*/);
83 void type_of_call lkfxwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
84 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
85 Int_t & /*newReg*/, Int_t & /*flagErr*/, Int_t & /*newLttc*/);
86 void type_of_call lkmgwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
87 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
88 Int_t & /*flagErr*/, Int_t & /*newReg*/, Int_t & /*newLttc*/);
89 void type_of_call lkwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
90 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
91 Int_t & /*newReg*/, Int_t & /*flagErr*/, Int_t & /*newLttc*/);
92 // void type_of_call magfld(const Double_t & /*pX*/, const Double_t & /*pY*/, const Double_t & /*pZ*/,
93 // Double_t & /*cosBx*/, Double_t & /*cosBy*/, Double_t & /*cosBz*/,
94 // Double_t & /*Bmag*/, Int_t & /*reg*/, Int_t & /*idiscflag*/);
95 void type_of_call nrmlwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
96 Double_t & /*pVx*/, Double_t & /*pVy*/, Double_t & /*pVz*/,
97 Double_t * /*norml*/, const Int_t & /*oldReg*/,
98 const Int_t & /*newReg*/, Int_t & /*flagErr*/);
99 void type_of_call rgrpwr(const Int_t & /*flukaReg*/, const Int_t & /*ptrLttc*/, Int_t & /*g4Reg*/,
100 Int_t * /*indMother*/, Int_t * /*repMother*/, Int_t & /*depthFluka*/);
101 Int_t type_of_call isvhwr(const Int_t & /*fCheck*/, const Int_t & /*intHist*/);
104 // TFluka global pointer
106 TFlukaMCGeometry *mcgeom = 0;
109 ClassImp(TFlukaMCGeometry)
111 TFlukaMCGeometry* TFlukaMCGeometry::fgInstance=0;
113 //_____________________________________________________________________________
114 TFlukaMCGeometry::TFlukaMCGeometry(const char *name, const char *title)
115 : TVirtualMCGeometry(name, title)
118 // Standard constructor
125 fluka = (TFluka*)gMC;
130 //_____________________________________________________________________________
131 TFlukaMCGeometry::TFlukaMCGeometry()
132 : TVirtualMCGeometry()
135 // Default constructor
142 fluka = (TFluka*)gMC;
147 //_____________________________________________________________________________
148 TFlukaMCGeometry::~TFlukaMCGeometry()
154 if (fRegionList) delete [] fRegionList;
155 if (gGeoManager) delete gGeoManager;
161 //_____________________________________________________________________________
162 TFlukaMCGeometry::TFlukaMCGeometry(const TFlukaMCGeometry &)
163 : TVirtualMCGeometry()
170 //_____________________________________________________________________________
171 Double_t* TFlukaMCGeometry::CreateDoubleArray(Float_t* array, Int_t size) const
173 // Converts Float_t* array to Double_t*,
174 // !! The new array has to be deleted by user.
177 Double_t* doubleArray;
179 doubleArray = new Double_t[size];
180 for (Int_t i=0; i<size; i++) doubleArray[i] = array[i];
184 doubleArray = new Double_t[1];
190 //_____________________________________________________________________________
191 void TFlukaMCGeometry::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,
192 Float_t &dens, Float_t &radl, Float_t &absl,
193 Float_t* /*ubuf*/, Int_t& /*nbuf*/)
195 if (fDebug) printf("Gfmate %i\n", imat);
197 TIter next (gGeoManager->GetListOfMaterials());
198 while ((mat = (TGeoMaterial*)next())) {
199 if (mat->GetUniqueID() == (UInt_t)imat) break;
202 Error("Gfmate", "no material with index %i found", imat);
205 sprintf(name, "%s", mat->GetName());
208 dens = mat->GetDensity();
209 radl = mat->GetRadLen();
210 absl = mat->GetIntLen();
211 if (fDebug) printf(" ->material found : %s a=%g, z=%g, dens=%g, radl=%g, absl=%g\n", name, a,z,dens,radl,absl);
214 //_____________________________________________________________________________
215 void TFlukaMCGeometry::Gfmate(Int_t imat, char *name, Double_t &a, Double_t &z,
216 Double_t &dens, Double_t &radl, Double_t &absl,
217 Double_t* /*ubuf*/, Int_t& /*nbuf*/)
219 if (fDebug) printf("Gfmate %i\n", imat);
221 TIter next (gGeoManager->GetListOfMaterials());
222 while ((mat = (TGeoMaterial*)next())) {
223 if (mat->GetUniqueID() == (UInt_t)imat) break;
226 Error("Gfmate", "no material with index %i found", imat);
229 sprintf(name, "%s", mat->GetName());
232 dens = mat->GetDensity();
233 radl = mat->GetRadLen();
234 absl = mat->GetIntLen();
235 if (fDebug) printf(" ->material found : %s a=%g, z=%g, dens=%g, radl=%g, absl=%g\n", name, a,z,dens,radl,absl);
238 //_____________________________________________________________________________
239 void TFlukaMCGeometry::Material(Int_t& kmat, const char* name, Double_t a, Double_t z,
240 Double_t dens, Double_t radl, Double_t absl, Float_t* buf,
244 // Defines a Material
246 // kmat number assigned to the material
247 // name material name
248 // a atomic mass in au
250 // dens density in g/cm3
251 // absl absorbtion length in cm
252 // if >=0 it is ignored and the program
253 // calculates it, if <0. -absl is taken
254 // radl radiation length in cm
255 // if >=0 it is ignored and the program
256 // calculates it, if <0. -radl is taken
257 // buf pointer to an array of user words
258 // nbuf number of user words
261 Double_t* dbuf = CreateDoubleArray(buf, nwbuf);
262 Material(kmat, name, a, z, dens, radl, absl, dbuf, nwbuf);
266 //_____________________________________________________________________________
267 void TFlukaMCGeometry::Material(Int_t& kmat, const char* name, Double_t a, Double_t z,
268 Double_t dens, Double_t radl, Double_t absl, Double_t* /*buf*/,
272 // Defines a Material
274 // kmat number assigned to the material
275 // name material name
276 // a atomic mass in au
278 // dens density in g/cm3
279 // absl absorbtion length in cm
280 // if >=0 it is ignored and the program
281 // calculates it, if <0. -absl is taken
282 // radl radiation length in cm
283 // if >=0 it is ignored and the program
284 // calculates it, if <0. -radl is taken
285 // buf pointer to an array of user words
286 // nbuf number of user words
289 kmat = gGeoManager->GetListOfMaterials()->GetSize();
290 gGeoManager->Material(name, a, z, dens, kmat, radl, absl);
291 if (fDebug) printf("Material %s: kmat=%i, a=%g, z=%g, dens=%g\n", name, kmat, a, z, dens);
294 //_____________________________________________________________________________
295 void TFlukaMCGeometry::Mixture(Int_t& kmat, const char* name, Float_t* a, Float_t* z,
296 Double_t dens, Int_t nlmat, Float_t* wmat)
299 // Defines mixture OR COMPOUND IMAT as composed by
300 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
302 // If NLMAT > 0 then wmat contains the proportion by
303 // weights of each basic material in the mixture.
305 // If nlmat < 0 then WMAT contains the number of atoms
306 // of a given kind into the molecule of the COMPOUND
307 // In this case, WMAT in output is changed to relative
311 Double_t* da = CreateDoubleArray(a, TMath::Abs(nlmat));
312 Double_t* dz = CreateDoubleArray(z, TMath::Abs(nlmat));
313 Double_t* dwmat = CreateDoubleArray(wmat, TMath::Abs(nlmat));
315 Mixture(kmat, name, da, dz, dens, nlmat, dwmat);
316 for (Int_t i=0; i<nlmat; i++) {
317 a[i] = da[i]; z[i] = dz[i]; wmat[i] = dwmat[i];
325 //_____________________________________________________________________________
326 void TFlukaMCGeometry::Mixture(Int_t& kmat, const char* name, Double_t* a, Double_t* z,
327 Double_t dens, Int_t nlmat, Double_t* wmat)
330 // Defines mixture OR COMPOUND IMAT as composed by
331 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
333 // If NLMAT > 0 then wmat contains the proportion by
334 // weights of each basic material in the mixture.
336 // If nlmat < 0 then WMAT contains the number of atoms
337 // of a given kind into the molecule of the COMPOUND
338 // In this case, WMAT in output is changed to relative
346 for (i=0;i<nlmat;i++) {
347 amol += a[i]*wmat[i];
349 for (i=0;i<nlmat;i++) {
350 wmat[i] *= a[i]/amol;
353 kmat = gGeoManager->GetListOfMaterials()->GetSize();
355 printf("Mixture %s with %i elem: kmat=%i, dens=%g\n", name, nlmat, kmat, dens);
356 for (Int_t j=0; j<nlmat; j++) printf(" Elem %i: z=%g a=%g w=%g\n",j,z[j],a[j],wmat[j]);
358 gGeoManager->Mixture(name, a, z, dens, nlmat, wmat, kmat);
360 //_____________________________________________________________________________
361 Int_t TFlukaMCGeometry::GetMedium() const
363 // Get current medium number
365 TGeoNode *node = gGeoManager->GetCurrentNode();
366 if (!node) imed = gGeoManager->GetTopNode()->GetVolume()->GetMedium()->GetId();
367 else imed = node->GetVolume()->GetMedium()->GetId();
368 if (fDebug) printf("GetMedium=%i\n", imed);
372 //_____________________________________________________________________________
373 Int_t TFlukaMCGeometry::GetFlukaMaterial(Int_t imed) const
375 // Returns FLUKA material index for medium IMED
376 TGeoMedium *med = (TGeoMedium*)gGeoManager->GetListOfMedia()->At(imed-1);
378 Error("GetFlukaMaterial", "MEDIUM %i nor found", imed);
381 Int_t imatfl = med->GetMaterial()->GetIndex();
385 //_____________________________________________________________________________
386 Int_t *TFlukaMCGeometry::GetRegionList(Int_t imed, Int_t &nreg)
388 // Get an ordered list of regions matching a given medium number
390 if (!fRegionList) fRegionList = new Int_t[NofVolumes()+1];
391 TIter next(gGeoManager->GetListOfUVolumes());
394 while ((vol = (TGeoVolume*)next())) {
395 imedium = vol->GetMedium()->GetId();
396 if (imedium == imed) {
397 ireg = vol->GetNumber();
398 fRegionList[nreg++] = ireg;
404 //_____________________________________________________________________________
405 Int_t *TFlukaMCGeometry::GetMaterialList(Int_t imat, Int_t &nreg)
407 // Get an ordered list of regions matching a given medium number
409 if (!fRegionList) fRegionList = new Int_t[NofVolumes()+1];
410 TIter next(gGeoManager->GetListOfUVolumes());
412 Int_t imaterial, ireg;
413 while ((vol = (TGeoVolume*)next())) {
414 imaterial = vol->GetMedium()->GetMaterial()->GetIndex();
415 if (imaterial == imat) {
416 ireg = vol->GetNumber();
417 fRegionList[nreg++] = ireg;
422 //_____________________________________________________________________________
423 void TFlukaMCGeometry::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
424 Int_t ifield, Double_t fieldm, Double_t tmaxfd,
425 Double_t stemax, Double_t deemax, Double_t epsil,
426 Double_t stmin, Float_t* ubuf, Int_t nbuf)
429 // kmed tracking medium number assigned
430 // name tracking medium name
431 // nmat material number
432 // isvol sensitive volume flag
433 // ifield magnetic field
434 // fieldm max. field value (kilogauss)
435 // tmaxfd max. angle due to field (deg/step)
436 // stemax max. step allowed
437 // deemax max. fraction of energy lost in a step
438 // epsil tracking precision (cm)
439 // stmin min. step due to continuous processes (cm)
441 // ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
442 // ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
443 // performed with g3helix; ifield = 3 if tracking performed with g3helx3.
446 //printf("Creating mediuma: %s, numed=%d, nmat=%d\n",name,kmed,nmat);
447 Double_t* dubuf = CreateDoubleArray(ubuf, nbuf);
448 Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
453 //_____________________________________________________________________________
454 void TFlukaMCGeometry::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
455 Int_t ifield, Double_t fieldm, Double_t tmaxfd,
456 Double_t stemax, Double_t deemax, Double_t epsil,
457 Double_t stmin, Double_t* /*ubuf*/, Int_t /*nbuf*/)
460 // kmed tracking medium number assigned
461 // name tracking medium name
462 // nmat material number
463 // isvol sensitive volume flag
464 // ifield magnetic field
465 // fieldm max. field value (kilogauss)
466 // tmaxfd max. angle due to field (deg/step)
467 // stemax max. step allowed
468 // deemax max. fraction of energy lost in a step
469 // epsil tracking precision (cm)
470 // stmin min. step due to continuos processes (cm)
472 // ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
473 // ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
474 // performed with g3helix; ifield = 3 if tracking performed with g3helx3.
477 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
478 gGeoManager->Medium(name,kmed,nmat, isvol, ifield, fieldm, tmaxfd, stemax,deemax, epsil, stmin);
479 if (fDebug) printf("Medium %s: kmed=%i, nmat=%i, isvol=%i\n", name, kmed, nmat,isvol);
482 //_____________________________________________________________________________
483 void TFlukaMCGeometry::Matrix(Int_t& krot, Double_t thex, Double_t phix, Double_t they,
484 Double_t phiy, Double_t thez, Double_t phiz)
487 // krot rotation matrix number assigned
488 // theta1 polar angle for axis i
489 // phi1 azimuthal angle for axis i
490 // theta2 polar angle for axis ii
491 // phi2 azimuthal angle for axis ii
492 // theta3 polar angle for axis iii
493 // phi3 azimuthal angle for axis iii
495 // it defines the rotation matrix number irot.
498 krot = gGeoManager->GetListOfMatrices()->GetEntriesFast();
499 gGeoManager->Matrix(krot, thex, phix, they, phiy, thez, phiz);
500 if (fDebug) printf("Rotation %i defined\n", krot);
503 //_____________________________________________________________________________
504 Int_t TFlukaMCGeometry::Gsvolu(const char *name, const char *shape, Int_t nmed,
505 Float_t *upar, Int_t npar)
510 // NUMED Tracking medium number
511 // NPAR Number of shape parameters
512 // UPAR Vector containing shape parameters
514 // It creates a new volume in the JVOLUM data structure.
517 Double_t* dupar = CreateDoubleArray(upar, npar);
518 Int_t id = Gsvolu(name, shape, nmed, dupar, npar);
523 //_____________________________________________________________________________
524 Int_t TFlukaMCGeometry::Gsvolu(const char *name, const char *shape, Int_t nmed,
525 Double_t *upar, Int_t npar)
530 // NUMED Tracking medium number
531 // NPAR Number of shape parameters
532 // UPAR Vector containing shape parameters
534 // It creates a new volume in the JVOLUM data structure.
541 TGeoVolume* vol = gGeoManager->Volume(vname, shape, nmed, upar, npar);
542 if (fDebug) printf("Volume %s: id=%i shape=%s, nmed=%i\n", vname, vol->GetNumber(), shape, nmed);
543 return vol->GetNumber();
546 //_____________________________________________________________________________
547 void TFlukaMCGeometry::Gsdvn(const char *name, const char *mother, Int_t ndiv,
551 // Create a new volume by dividing an existing one
554 // MOTHER Mother volume name
555 // NDIV Number of divisions
558 // X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
559 // It divides a previously defined volume.
564 Vname(mother,vmother);
566 gGeoManager->Division(vname, vmother, iaxis, ndiv, 0, 0, 0, "n");
567 if (fDebug) printf("Division %s: mother=%s iaxis=%i ndiv=%i\n", vname, vmother, iaxis, ndiv);
570 //_____________________________________________________________________________
571 void TFlukaMCGeometry::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
572 Int_t iaxis, Double_t c0i, Int_t numed)
575 // Create a new volume by dividing an existing one
577 // Divides mother into ndiv divisions called name
578 // along axis iaxis starting at coordinate value c0.
579 // the new volume created will be medium number numed.
584 Vname(mother,vmother);
586 gGeoManager->Division(vname, vmother, iaxis, ndiv, c0i, 0, numed, "nx");
588 //_____________________________________________________________________________
589 void TFlukaMCGeometry::Gsdvt(const char *name, const char *mother, Double_t step,
590 Int_t iaxis, Int_t numed, Int_t /*ndvmx*/)
593 // Create a new volume by dividing an existing one
595 // Divides MOTHER into divisions called NAME along
596 // axis IAXIS in steps of STEP. If not exactly divisible
597 // will make as many as possible and will centre them
598 // with respect to the mother. Divisions will have medium
599 // number NUMED. If NUMED is 0, NUMED of MOTHER is taken.
600 // NDVMX is the expected maximum number of divisions
601 // (If 0, no protection tests are performed)
606 Vname(mother,vmother);
608 gGeoManager->Division(vname, vmother, iaxis, 0, 0, step, numed, "s");
611 //_____________________________________________________________________________
612 void TFlukaMCGeometry::Gsdvt2(const char *name, const char *mother, Double_t step,
613 Int_t iaxis, Double_t c0, Int_t numed, Int_t /*ndvmx*/)
616 // Create a new volume by dividing an existing one
618 // Divides MOTHER into divisions called NAME along
619 // axis IAXIS starting at coordinate value C0 with step
621 // The new volume created will have medium number NUMED.
622 // If NUMED is 0, NUMED of mother is taken.
623 // NDVMX is the expected maximum number of divisions
624 // (If 0, no protection tests are performed)
629 Vname(mother,vmother);
631 gGeoManager->Division(vname, vmother, iaxis, 0, c0, step, numed, "sx");
634 //_____________________________________________________________________________
635 void TFlukaMCGeometry::Gsord(const char * /*name*/, Int_t /*iax*/)
638 // Flags volume CHNAME whose contents will have to be ordered
639 // along axis IAX, by setting the search flag to -IAX
643 // IAX = 4 Rxy (static ordering only -> GTMEDI)
644 // IAX = 14 Rxy (also dynamic ordering -> GTNEXT)
645 // IAX = 5 Rxyz (static ordering only -> GTMEDI)
646 // IAX = 15 Rxyz (also dynamic ordering -> GTNEXT)
647 // IAX = 6 PHI (PHI=0 => X axis)
648 // IAX = 7 THETA (THETA=0 => Z axis)
651 // TBC - keep this function
652 // nothing to be done for TGeo //xx
655 //_____________________________________________________________________________
656 void TFlukaMCGeometry::Gspos(const char *name, Int_t nr, const char *mother, Double_t x,
657 Double_t y, Double_t z, Int_t irot, const char *konly)
660 // Position a volume into an existing one
663 // NUMBER Copy number of the volume
664 // MOTHER Mother volume name
665 // X X coord. of the volume in mother ref. sys.
666 // Y Y coord. of the volume in mother ref. sys.
667 // Z Z coord. of the volume in mother ref. sys.
668 // IROT Rotation matrix number w.r.t. mother ref. sys.
669 // ONLY ONLY/MANY flag
671 // It positions a previously defined volume in the mother.
674 TString only = konly;
676 Bool_t isOnly = kFALSE;
677 if (only.Contains("only")) isOnly = kTRUE;
681 Vname(mother,vmother);
684 gGeoManager->Node(vname, nr, vmother, x, y, z, irot, isOnly, upar);
685 if (fDebug) printf("Adding daughter %s to %s: cpy=%i irot=%i only=%s\n", vname,vmother,nr,irot,only.Data());
688 //_____________________________________________________________________________
689 void TFlukaMCGeometry::Gsposp(const char *name, Int_t nr, const char *mother,
690 Double_t x, Double_t y, Double_t z, Int_t irot,
691 const char *konly, Float_t *upar, Int_t np )
694 // Place a copy of generic volume NAME with user number
695 // NR inside MOTHER, with its parameters UPAR(1..NP)
698 Double_t* dupar = CreateDoubleArray(upar, np);
699 Gsposp(name, nr, mother, x, y, z, irot, konly, dupar, np);
703 //_____________________________________________________________________________
704 void TFlukaMCGeometry::Gsposp(const char *name, Int_t nr, const char *mother,
705 Double_t x, Double_t y, Double_t z, Int_t irot,
706 const char *konly, Double_t *upar, Int_t np )
709 // Place a copy of generic volume NAME with user number
710 // NR inside MOTHER, with its parameters UPAR(1..NP)
713 TString only = konly;
715 Bool_t isOnly = kFALSE;
716 if (only.Contains("only")) isOnly = kTRUE;
720 Vname(mother,vmother);
722 gGeoManager->Node(vname,nr,vmother, x,y,z,irot,isOnly,upar,np);
723 if (fDebug) printf("Adding daughter(s) %s to %s: cpy=%i irot=%i only=%s\n", vname,vmother,nr,irot,only.Data());
726 //_____________________________________________________________________________
727 Int_t TFlukaMCGeometry::VolId(const Text_t *name) const
730 // Return the unique numeric identifier for volume name
733 Int_t uid = gGeoManager->GetUID(name);
735 printf("VolId: Volume %s not found\n",name);
738 if (fDebug) printf("VolId for %s: %i\n", name, uid);
742 //_____________________________________________________________________________
743 const char* TFlukaMCGeometry::VolName(Int_t id) const
746 // Return the volume name given the volume identifier
748 TGeoVolume *volume = gGeoManager->GetVolume(id);
750 Error("VolName","volume with id=%d does not exist",id);
753 if (fDebug) printf("VolName for id=%i: %s\n", id, volume->GetName());
754 return volume->GetName();
757 //_____________________________________________________________________________
758 Int_t TFlukaMCGeometry::NofVolumes() const
761 // Return total number of volumes in the geometry
764 return gGeoManager->GetListOfUVolumes()->GetEntriesFast()-1;
767 //_____________________________________________________________________________
768 Int_t TFlukaMCGeometry::VolId2Mate(Int_t id) const
771 // Return material number for a given volume id
773 TGeoVolume *volume = gGeoManager->GetVolume(id);
775 Error("VolId2Mate","volume with id=%d does not exist",id);
778 TGeoMedium *med = volume->GetMedium();
780 if (fDebug) printf("VolId2Mate id=%i: idmed=%i\n", id, med->GetId());
784 //_____________________________________________________________________________
785 Int_t TFlukaMCGeometry::CurrentVolID(Int_t& copyNo) const
787 // Returns the current volume ID and copy number
788 if (gGeoManager->IsOutside()) return 0;
789 TGeoNode *node = gGeoManager->GetCurrentNode();
790 copyNo = node->GetNumber();
791 Int_t id = node->GetVolume()->GetNumber();
792 if (fDebug) printf("CurrentVolId(cpy=%i) = %i\n", copyNo, id);
796 //_____________________________________________________________________________
797 Int_t TFlukaMCGeometry::CurrentVolOffID(Int_t off, Int_t& copyNo) const
799 // Return the current volume "off" upward in the geometrical tree
800 // ID and copy number
801 if (off<0 || off>gGeoManager->GetLevel()) return 0;
802 if (off==0) return CurrentVolID(copyNo);
803 TGeoNode *node = gGeoManager->GetMother(off);
805 copyNo = node->GetNumber();
806 if (fDebug) printf("CurrentVolOffId(off=%i,cpy=%i) = %i\n", off,copyNo,node->GetVolume()->GetNumber() );
807 return node->GetVolume()->GetNumber();
811 //_____________________________________________________________________________
812 const char* TFlukaMCGeometry::CurrentVolName() const
815 // Returns the current volume name
817 if (gGeoManager->IsOutside()) return 0;
818 if (fDebug) printf("CurrentVolName : %s\n", gGeoManager->GetCurrentVolume()->GetName());
819 return gGeoManager->GetCurrentVolume()->GetName();
821 //_____________________________________________________________________________
822 const char* TFlukaMCGeometry::CurrentVolOffName(Int_t off) const
825 // Return the current volume "off" upward in the geometrical tree
826 // ID, name and copy number
827 // if name=0 no name is returned
829 if (off<0 || off>gGeoManager->GetLevel()) return 0;
830 if (off==0) return CurrentVolName();
831 TGeoNode *node = gGeoManager->GetMother(off);
833 if (fDebug) printf("CurrentVolOffName(off=%i) : %s\n", off,node->GetVolume()->GetName());
834 return node->GetVolume()->GetName();
837 //_____________________________________________________________________________
838 void TFlukaMCGeometry::Gsatt(const char *name, const char *att, Int_t val)
842 // IOPT Name of the attribute to be set
843 // IVAL Value to which the attribute is to be set
844 // see: TFluka::Gsatt
849 gGeoManager->SetVolumeAttribute(vname, vatt, val);
852 //_____________________________________________________________________________
853 void TFlukaMCGeometry::Gdtom(Float_t *xd, Float_t *xm, Int_t iflag)
856 // Computes coordinates XM (Master Reference System
857 // knowing the coordinates XD (Detector Ref System)
858 // The local reference system can be initialized by
859 // - the tracking routines and GDTOM used in GUSTEP
860 // - a call to GSCMED(NLEVEL,NAMES,NUMBER)
861 // (inverse routine is GMTOD)
863 // If IFLAG=1 convert coordinates
864 // IFLAG=2 convert direction cosinus
866 Double_t xmL[3], xdL[3];
868 for (i=0;i<3;i++) xdL[i] = xd[i];
869 if (iflag == 1) gGeoManager->LocalToMaster(xdL,xmL);
870 else gGeoManager->LocalToMasterVect(xdL,xmL);
871 for (i=0;i<3;i++) xm[i]=xmL[i];
874 //_____________________________________________________________________________
875 void TFlukaMCGeometry::Gdtom(Double_t *xd, Double_t *xm, Int_t iflag)
877 if (iflag == 1) gGeoManager->LocalToMaster(xd,xm);
878 else gGeoManager->LocalToMasterVect(xd,xm);
881 //_____________________________________________________________________________
882 void TFlukaMCGeometry::Gmtod(Float_t *xm, Float_t *xd, Int_t iflag)
885 // Computes coordinates XD (in DRS)
886 // from known coordinates XM in MRS
887 // The local reference system can be initialized by
888 // - the tracking routines and GMTOD used in GUSTEP
889 // - a call to GMEDIA(XM,NUMED,CHECK)
890 // - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
891 // (inverse routine is GDTOM)
893 // If IFLAG=1 convert coordinates
894 // IFLAG=2 convert direction cosinus
896 Double_t xmL[3], xdL[3];
898 for (i=0;i<3;i++) xmL[i]=xm[i];
899 if (iflag == 1) gGeoManager->MasterToLocal(xmL,xdL);
900 else gGeoManager->MasterToLocalVect(xmL,xdL);
901 for (i=0;i<3;i++) xd[i] = xdL[i];
904 //_____________________________________________________________________________
905 void TFlukaMCGeometry::Gmtod(Double_t *xm, Double_t *xd, Int_t iflag)
907 if (iflag == 1) gGeoManager->MasterToLocal(xm,xd);
908 else gGeoManager->MasterToLocalVect(xm,xd);
911 //_____________________________________________________________________________
912 void TFlukaMCGeometry::CreateFlukaMatFile(const char *fname)
914 // ==== from FLUGG ====
915 // NAMES OF ELEMENTS AND COMPOUNDS: the names must be written in upper case,
916 // according to the fluka standard. In addition,. they must be equal to the
917 // names of the fluka materials - see fluka manual - in order that the
918 // program load the right cross sections, and equal to the names included in
919 // the .pemf. Otherwise the user must define the LOW-MAT CARDS, and make his
920 // own .pemf, in order to get the right cross sections loaded in memory.
923 static char elNames[220] = {
924 // 1 ============================= 5 ==================================== 10 ===================================== 15 ===
925 'H','_','H','E','L','I','B','E','B','_','C','_','N','_','O','_','F','_','N','E','N','A','M','G','A','L','S','I','P','_',
926 'S','_','C','L','A','R','K','_','C','A','S','C','T','I','V','_','C','R','M','N','F','E','C','O','N','I','C','U','Z','N',
927 'G','A','G','E','A','S','S','E','B','R','K','R','R','B','S','R','Y','_','Z','R','N','B','M','O','T','C','R','U','R','H',
928 'P','D','A','G','C','D','I','N','S','N','S','B','T','E','I','_','X','E','C','S','B','A','L','A','C','E','P','R','N','D',
929 'P','M','S','M','E','U','G','D','T','B','D','Y','H','O','E','R','T','M','Y','B','L','U','H','F','T','A','W','_','R','E',
930 'O','S','I','R','P','T','A','U','H','G','T','L','P','B','B','I','P','O','A','T','R','N','F','R','R','A','A','C','T','H',
931 'P','A','U','_','N','P','P','U','A','M','C','M','B','K','C','F','E','S','F','M','M','D','N','O','L','R','R','F','D','B',
932 'S','G','B','H','H','S','M','T','D','S'};
933 memset(zelem, 0, 128*sizeof(Int_t));
935 gGeoManager->Export("flgeom.root");
936 if (fname) sname = fname;
937 else sname = "flukaMat.inp";
939 out.open(sname.Data(), ios::out);
941 Fatal("CreateFlukaMatFile", "could not open file %s for writing", sname.Data());
944 PrintHeader(out, "MATERIALS AND COMPOUNDS");
945 PrintHeader(out, "MATERIALS");
946 TList *matlist = gGeoManager->GetListOfMaterials();
948 Int_t nmater = matlist->GetSize();
950 TObjArray *listfluka = new TObjArray(nmater+50);
951 TObjArray *listflukanames = new TObjArray(nmater+50);
952 TGeoMaterial *mat, *matorig;
953 TGeoMixture *mix = 0;
955 TObjString *objstr, *objstrother;
959 Double_t amat,zmat,rhomat;
960 Double_t zel, ael, wel, rho;
961 char elname[8] = {' ',' ','_', 'E','L','E','M','\0'};
963 Bool_t found = kFALSE;
965 if (fDebug) printf("Creating materials and compounds\n");
966 for (i=0; i<nmater; i++) {
967 mat = (TGeoMaterial*)matlist->At(i);
968 if (mat->GetZ()<1E-1) {
969 mat->SetIndex(2); // vacuum, built-in inside FLUKA
972 // printf("material: %s index=%i: Z=%f A=%f rho=%f\n", mat->GetName(), mat->GetIndex(),mat->GetZ(),mat->GetA(),mat->GetDensity());
973 matorig = gGeoManager->FindDuplicateMaterial(mat);
975 idmat = matorig->GetIndex();
976 mat->SetIndex(idmat);
977 // printf(" -> found a duplicate: %s with index %i\n", matorig->GetName(), idmat);
980 // printf(" Adding to temp list with index %i\n", nfmater+3);
982 mat->SetIndex(nfmater+3);
984 objstr = new TObjString(mat->GetName());
985 listflukanames->Add(objstr);
987 // look if name is existing
989 matname = objstr->GetString();
990 ToFlukaString(matname);
991 objstr->SetString(matname.Data());
994 if (nfmater == 1) break;
995 for (j=0; j<nfmater-1; j++) {
996 objstrother = (TObjString*)listflukanames->At(j);
997 if (objstr->IsEqual(objstrother)) {
998 // we have to change the name
1000 Error("CreateFlukaMatFile", "too many materials having same name");
1004 k = matname.Index(" ");
1005 if (k<0 || k>6) k=6;
1007 sprintf(digit, "%d", nidmat);
1010 sprintf(&digit[1], "%d", nidmat);
1012 matname.Insert(k,digit);
1014 objstr->SetString(matname.Data());
1017 if (j == nfmater-2) {
1023 // printf(" newmat name: %s\n", matname.Data());
1025 // now we have unique materials with unique names in the lists
1027 if (matorig && matorig->IsMixture()) {
1028 // create dummy materials for elements
1030 mix = (TGeoMixture*)matorig;
1031 nelem = mix->GetNelements();
1032 // printf(" material is a MIXTURE with %i elements:\n", nelem);
1033 for (j=0; j<nelem; j++) {
1035 zel = (mix->GetZmixt())[j];
1036 ael = (mix->GetAmixt())[j];
1037 // printf(" Zelem[%i] = %g\n",j,zel);
1038 if ((zel-Int_t(zel))>0.01) {
1040 for (Int_t imat=0; imat<nfmater; imat++) {
1041 mat1 = (TGeoMaterial*)listfluka->At(imat);
1042 if (TMath::Abs(mat1->GetZ()-zel)>1E-4) continue;
1043 if (TMath::Abs(mat1->GetA()-ael)>1E-4) continue;
1047 if (!found) Warning("CreateFlukaMatFile", "element with Z=%f\n", zel);
1049 if (!zelem[Int_t(zel)] && !found) {
1050 // write fluka element
1051 memcpy(elname, &elNames[2*Int_t(zel-1)], 2);
1052 zelem[Int_t(zel)] = 1;
1053 mat = new TGeoMaterial(elname, ael, zel, rho);
1054 mat->SetIndex(nfmater+3);
1055 // printf(" element not in list: new material %s at index=%i, Z=%g, A=%g, dummyrho=%g\n",
1056 // elname,nfmater+3,zel,ael,rho);
1057 listfluka->Add(mat);
1058 objstr = new TObjString(elname);
1059 listflukanames->Add(objstr);
1065 // now dump materials in the file
1066 // printf("DUMPING %i materials\n", nfmater);
1067 for (i=0; i<nfmater; i++) {
1068 mat = (TGeoMaterial*)listfluka->At(i);
1069 out << setw(10) << "MATERIAL ";
1070 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1071 // matname = mat->GetName();
1072 objstr = (TObjString*)listflukanames->At(i);
1073 matname = objstr->GetString();
1074 ToFlukaString(matname);
1076 if (zmat-Int_t(zmat)>0.01) {
1077 if (zmat-Int_t(zmat)>0.5) zmat = Int_t(zmat)+1.;
1078 else zmat = Int_t(zmat);
1081 rhomat = mat->GetDensity();
1082 // write material card
1083 if (mat->IsMixture()) {
1084 out << setw(10) << " ";
1085 out << setw(10) << " ";
1086 mix = (TGeoMixture*)mat;
1088 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << zmat;
1089 out << setw(10) << setprecision(3) << amat;
1091 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1092 out << setw(10) << setiosflags(ios::scientific) << setprecision(3) << rhomat;
1093 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1094 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(i+3);
1095 out << setw(10) << " ";
1096 out << setw(10) << " ";
1097 out << setw(8) << matname.Data() << endl;
1099 if (!mat->IsMixture()) {
1100 out << setw(10) << "LOW-MAT ";
1101 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1102 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(i+3);
1103 out << setw(10) << " ";
1104 out << setw(10) << " ";
1105 out << setw(10) << " ";
1106 out << setw(10) << " ";
1107 out << setw(10) << " ";
1108 out << setw(8) << matname.Data() << endl;
1111 // write mixture header
1112 PrintHeader(out, "COMPOUNDS");
1114 TGeoMaterial *element;
1115 for (i=0; i<nfmater; i++) {
1116 mat = (TGeoMaterial*)listfluka->At(i);
1117 if (!mat->IsMixture()) continue;
1118 mix = (TGeoMixture*)mat;
1120 out << setw(10) << "COMPOUND ";
1121 nelem = mix->GetNelements();
1122 objstr = (TObjString*)listflukanames->At(i);
1123 matname = objstr->GetString();
1124 // printf("MIXTURE %s with index %i having %i elements\n", matname.Data(), mat->GetIndex(),nelem);
1125 for (j=0; j<nelem; j++) {
1126 // dump mixture cards
1127 // printf(" #elem %i: Z=%g, A=%g, W=%g\n", j, (mix->GetZmixt())[j],
1128 // (mix->GetAmixt())[j],(mix->GetWmixt())[j]);
1129 wel = (mix->GetWmixt())[j];
1130 zel = (mix->GetZmixt())[j];
1131 ael = (mix->GetAmixt())[j];
1132 if (zel-Int_t(zel)>0.01) {
1133 // loop the temporary list
1136 for (Int_t imat=0; imat<i; imat++) {
1137 mat1 = (TGeoMaterial*)listfluka->At(imat);
1138 if (TMath::Abs(mat1->GetZ()-zel)>1E-4) continue;
1139 if (TMath::Abs(mat1->GetA()-ael)>1E-4) continue;
1144 memcpy(elname, &elNames[2*Int_t(zel-1)], 2);
1145 element = (TGeoMaterial*)listfluka->FindObject(elname);
1148 Error("CreateFlukaMatFile", "Element Z=%g %s not found", zel, elname);
1151 idmat = element->GetIndex();
1152 // printf("element %s , index=%i\n", element->GetName(), idmat);
1153 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1154 out << setw(10) << setiosflags(ios::fixed) << setprecision(6) << -wel;
1155 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1156 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(idmat);
1158 if (counttothree == 3) {
1159 out << matname.Data();
1161 if ( (j+1) != nelem) out << setw(10) << "COMPOUND ";
1165 //Unless we have 3, 6, 9... submaterials we need to put some empty
1166 //space and the compound name
1168 for (j=0; j<(3-(nelem%3)); j++)
1169 out << setw(10) << " " << setw(10) << " ";
1170 out << matname.Data();
1175 // Now print the list of regions (volumes in TGeo)
1176 Int_t nvols = gGeoManager->GetListOfUVolumes()->GetEntriesFast()-1;
1179 PrintHeader(out, "TGEO VOLUMES");
1180 for (i=1; i<=nvols; i++) {
1181 vol = gGeoManager->GetVolume(i);
1182 out.setf(std::ios::left, std::ios::adjustfield);
1183 out << setw(10) << i;
1184 out << setw(20) << vol->GetName() << endl;
1187 // Now print the material assignments
1188 Double_t flagfield = 0.;
1189 printf("#############################################################\n");
1190 if (fluka->IsFieldEnabled()) {
1192 printf("Magnetic field enabled\n");
1193 } else printf("Magnetic field disabled\n");
1194 printf("#############################################################\n");
1196 PrintHeader(out, "TGEO MATERIAL ASSIGNMENTS");
1197 for (i=1; i<=nvols; i++) {
1198 vol = gGeoManager->GetVolume(i);
1199 mat = vol->GetMedium()->GetMaterial();
1200 idmat = mat->GetIndex();
1201 out << setw(10) << "ASSIGNMAT ";
1202 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1203 out << setw(10) << setiosflags(ios::fixed) << Double_t(idmat);
1204 out << setw(10) << setiosflags(ios::fixed) << Double_t(i);
1205 out << setw(10) << "0.0";
1206 out << setw(10) << "0.0";
1207 out << setw(10) << setiosflags(ios::fixed) << flagfield;
1208 out << setw(10) << "0.0";
1212 listflukanames->Delete();
1213 delete listflukanames;
1215 fLastMaterial = nfmater+2;
1218 //_____________________________________________________________________________
1219 void TFlukaMCGeometry::PrintHeader(ofstream &out, const char *text) const
1221 // Print a FLUKA header.
1222 out << "*\n" << "*\n" << "*\n";
1223 out << "********************* " << text << " *********************\n"
1225 out << "*...+....1....+....2....+....3....+....4....+....5....+....6....+....7..."
1230 //_____________________________________________________________________________
1231 Int_t TFlukaMCGeometry::RegionId() const
1233 // Returns current region id <-> TGeo node id
1234 if (gGeoManager->IsOutside()) return 0;
1235 return gGeoManager->GetCurrentNode()->GetUniqueID();
1237 //_____________________________________________________________________________
1238 void TFlukaMCGeometry::SetMreg(Int_t mreg)
1240 // Update if needed next history;
1241 if (fluka->GetDummyBoundary()==2) {
1242 gGeoManager->CdNode(fNextLattice-1);
1245 Int_t curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1246 if (mreg==curreg) return;
1247 if (mreg==fNextRegion) {
1248 if (fNextLattice!=999999999) gGeoManager->CdNode(fNextLattice-1);
1251 if (mreg == fCurrentRegion) {
1252 if (fCurrentLattice!=999999999) gGeoManager->CdNode(fCurrentLattice-1);
1256 if (fDebug) printf("ERROR: mreg=%i neither current nor next region\n", mreg);
1259 //_____________________________________________________________________________
1260 void TFlukaMCGeometry::SetCurrentRegion(Int_t mreg, Int_t latt)
1262 // Set index/history for next entered region
1263 fCurrentRegion = mreg;
1264 fCurrentLattice = latt;
1267 //_____________________________________________________________________________
1268 void TFlukaMCGeometry::SetNextRegion(Int_t mreg, Int_t latt)
1270 // Set index/history for next entered region
1272 fNextLattice = latt;
1275 //_____________________________________________________________________________
1276 void TFlukaMCGeometry::ToFlukaString(TString &str) const
1278 // ToFlukaString converts an string to something usefull in FLUKA:
1279 // * Capital letters
1281 // * Replace ' ' by '_'
1282 if (str.Length()<8) {
1287 for (ilast=7; ilast>0; ilast--) if (str(ilast)!=' ') break;
1289 for (Int_t pos=0; pos<ilast; pos++)
1290 if (str(pos)==' ') str.Replace(pos,1,"_",1);
1293 //______________________________________________________________________________
1294 void TFlukaMCGeometry::Vname(const char *name, char *vname) const
1297 // convert name to upper case. Make vname at least 4 chars
1299 Int_t l = strlen(name);
1302 for (i=0;i<l;i++) vname[i] = toupper(name[i]);
1303 for (i=l;i<4;i++) vname[i] = ' ';
1308 // FLUKA GEOMETRY WRAPPERS - to replace FLUGG wrappers
1310 //_____________________________________________________________________________
1311 Int_t idnrwr(const Int_t & /*nreg*/, const Int_t & /*mlat*/)
1314 // Wrapper for setting DNEAR option on fluka side. Must return 0
1315 // if user doesn't want Fluka to use DNEAR to compute the
1316 // step (the same effect is obtained with the GLOBAL (WHAT(3)=-1)
1317 // card in fluka input), returns 1 if user wants Fluka always to
1318 // use DNEAR (in this case, be sure that GEANT4 DNEAR is unique,
1319 // coming from all directions!!!)
1320 if (mcgeom->IsDebugging()) printf("========== Dummy IDNRWR\n");
1324 //_____________________________________________________________________________
1325 void g1wr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1326 Double_t *pV, Int_t &oldReg , const Int_t &oldLttc, Double_t &propStep,
1327 Int_t &nascFlag, Double_t &retStep, Int_t &newReg,
1328 Double_t &saf, Int_t &newLttc, Int_t <tcFlag,
1329 Double_t *sLt, Int_t *jrLt)
1332 // Initialize FLUKa point and direction;
1336 mcgeom->SetDebugMode(kTRUE);
1337 fluka->SetVerbosityLevel(3);
1340 mcgeom->SetDebugMode(kFALSE);
1341 fluka->SetVerbosityLevel(0);
1343 if ((kNstep%10)==0) printf("step %i\n", kNstep);
1346 if (mcgeom->IsDebugging()) {
1347 printf("========== Inside G1WR\n");
1348 printf(" point/dir:(%14.9f, %14.9f, %14.9f, %g, %g, %g)\n", pSx,pSy,pSz,pV[0],pV[1],pV[2]);
1349 printf(" oldReg=%i oldLttc=%i pstep=%f\n",oldReg, oldLttc, propStep);
1351 gGeoManager->SetCurrentPoint(pSx, pSy, pSz);
1352 gGeoManager->SetCurrentDirection(pV);
1353 mcgeom->SetCurrentRegion(oldReg, oldLttc);
1354 // Initialize default return values
1356 jrLt[lttcFlag] = oldLttc;
1357 sLt[lttcFlag] = propStep;
1358 jrLt[lttcFlag+1] = -1;
1359 sLt[lttcFlag+1] = 0.;
1362 // check if dummy boundary flag is set
1363 Int_t curLttc, curReg;
1364 if (fluka->IsDummyBoundary()) {
1365 // printf("Dummy boundary intercepted. Point is: %f, %f, %f\n", pSx, pSy, pSz);
1366 Bool_t crossedDummy = (oldLttc == TFlukaMCGeometry::kLttcVirtual)?kTRUE:kFALSE;
1368 // FLUKA crossed the dummy boundary - update new region/history
1371 mcgeom->GetNextRegion(newReg, newLttc);
1372 mcgeom->SetMreg(newReg);
1373 if (mcgeom->IsDebugging()) printf(" virtual newReg=%i newLttc=%i\n", newReg, newLttc);
1374 sLt[lttcFlag] = 0.; // null step in current region
1376 jrLt[lttcFlag] = newLttc;
1377 sLt[lttcFlag] = 0.; // null step in next region
1378 jrLt[lttcFlag+1] = -1;
1379 sLt[lttcFlag+1] = 0.;
1380 fluka->SetDummyBoundary(0);
1385 // Reset outside flag
1386 if (gGeoManager->IsOutside()) {
1387 gGeoManager->SetOutside(kFALSE);
1388 gGeoManager->CdTop();
1391 // Reset dummy boundary flag
1392 fluka->SetDummyBoundary(0);
1394 curLttc = gGeoManager->GetCurrentNodeId()+1;
1395 curReg = gGeoManager->GetCurrentVolume()->GetNumber();
1396 if (oldLttc != curLttc) {
1397 // FLUKA crossed the boundary : we trust that the given point is really there,
1398 // so we just update TGeo state
1399 gGeoManager->CdNode(oldLttc-1);
1400 curLttc = gGeoManager->GetCurrentNodeId()+1;
1401 curReg = gGeoManager->GetCurrentVolume()->GetNumber();
1402 if (mcgeom->IsDebugging()) printf(" re-initialized point: curReg=%i curLttc=%i\n", curReg, curLttc);
1404 // Now the current TGeo state reflects the FLUKA state
1405 if (mcgeom->IsDebugging()) printf(" current path: %s\n", gGeoManager->GetPath());
1406 Double_t extra = 1E-6;
1407 Double_t tmpStep = propStep + extra;
1408 gGeoManager->FindNextBoundary(-tmpStep);
1409 Double_t snext = gGeoManager->GetStep();
1412 // FLUKA is in the wrong region, notify it
1413 if (mcgeom->IsDebugging()) printf("ERROR: snext=%f\n", snext);
1418 saf = gGeoManager->GetSafeDistance();
1419 Bool_t cross = kFALSE;
1420 Bool_t onBound = kFALSE;
1421 if (snext<tmpStep) {
1422 // We have some boundary in the way
1423 Double_t dd = snext-propStep;
1428 if (dd < 1E-8) onBound = kTRUE;
1431 if (mcgeom->IsDebugging()) {
1432 if (!cross) printf(" physical step approved: %f\n", propStep);
1433 else printf(" boundary crossing at: %f\n", snext);
1434 if (onBound) printf(" step on boundary limit ! NASC=%i\n", nascFlag);
1437 // Next boundary further than proposed step, which is approved
1439 sLt[lttcFlag] = propStep;
1442 // The next boundary is closer. We try to cross it.
1443 Double_t *point = gGeoManager->GetCurrentPoint();
1444 Double_t *dir = gGeoManager->GetCurrentDirection();
1446 memcpy(pt, point, 3*sizeof(Double_t));
1449 for (i=0;i<3;i++) point[i] += snext*dir[i];
1450 gGeoManager->FindNode();
1451 newLttc = (gGeoManager->IsOutside())?(TFlukaMCGeometry::kLttcOutside):gGeoManager->GetCurrentNodeId()+1;
1452 if (newLttc == oldLttc) {
1454 // Just try a fast extra small step
1456 for (i=0;i<3;i++) point[i] = pt[i]+snext*dir[i];
1457 gGeoManager->FindNode();
1458 newLttc = (gGeoManager->IsOutside())?(TFlukaMCGeometry::kLttcOutside):gGeoManager->GetCurrentNodeId()+1;
1459 if (newLttc == oldLttc) {
1460 // check if state changes at the end of the proposed step
1461 for (i=0;i<3;i++) point[i] = pt[i]+propStep*dir[i];
1462 gGeoManager->FindNode();
1463 newLttc = (gGeoManager->IsOutside())?(TFlukaMCGeometry::kLttcOutside):gGeoManager->GetCurrentNodeId()+1;
1464 if (newLttc==oldLttc) {
1467 sLt[lttcFlag] = propStep;
1470 // snext is underestimated - we will create a virtual one to overcome the error
1471 // printf("some boundary in the way...\n");
1474 gGeoManager->SetCurrentPoint(pt);
1475 // newLttc = (gGeoManager->IsOutside())?(TFlukaMCGeometry::kLttcOutside):gGeoManager->GetCurrentNodeId()+1;
1476 newReg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1477 if (mcgeom->IsDebugging()) printf(" newReg=%i newLttc=%i\n", newReg, newLttc);
1479 // We really crossed the boundary, but is it the same region ?
1480 mcgeom->SetNextRegion(newReg, newLttc);
1481 if (newReg == oldReg) {
1482 // Virtual boundary between replicants
1483 if (mcgeom->IsDebugging()) printf(" DUMMY boundary\n");
1484 newReg = 1; // cheat FLUKA telling it it crossed the TOP region
1485 newLttc = TFlukaMCGeometry::kLttcVirtual;
1486 // mark that next boundary is virtual
1487 fluka->SetDummyBoundary(1);
1490 sLt[lttcFlag] = snext;
1492 jrLt[lttcFlag] = newLttc;
1493 sLt[lttcFlag] = snext;
1494 jrLt[lttcFlag+1] = -1;
1495 sLt[lttcFlag+1] = 0.;
1497 if (newLttc!=oldLttc) {
1498 if (gGeoManager->IsOutside()) {
1499 gGeoManager->SetOutside(kFALSE);
1500 gGeoManager->CdTop();
1502 gGeoManager->CdTop();
1503 if (!gGeoManager->GetCurrentMatrix()->IsIdentity()) printf("ERROR at step %i\n", kNstep);
1504 gGeoManager->CdNode(oldLttc-1);
1506 if (mcgeom->IsDebugging()) {
1507 printf("=> snext=%g safe=%g\n", snext, saf);
1508 for (Int_t i=0; i<lttcFlag+1; i++) printf(" jrLt[%i]=%i sLt[%i]=%g\n", i,jrLt[i],i,sLt[i]);
1510 if (mcgeom->IsDebugging()) printf("<= G1WR (in: %s)\n", gGeoManager->GetPath());
1513 //_____________________________________________________________________________
1516 if (mcgeom->IsDebugging()) printf("========== Dummy G1RTWR\n");
1519 //_____________________________________________________________________________
1520 void conhwr(Int_t & /*intHist*/, Int_t * /*incrCount*/)
1522 if (mcgeom->IsDebugging()) printf("========== Dummy CONHWR\n");
1525 //_____________________________________________________________________________
1526 void inihwr(Int_t &intHist)
1528 if (mcgeom->IsDebugging()) printf("========== Inside INIHWR -> reinitializing history: %i\n", intHist);
1529 if (gGeoManager->IsOutside()) gGeoManager->CdTop();
1531 // printf("=== wrong history number\n");
1534 if (intHist==0) gGeoManager->CdTop();
1535 else gGeoManager->CdNode(intHist-1);
1536 if (mcgeom->IsDebugging()) {
1537 printf(" --- current path: %s\n", gGeoManager->GetPath());
1538 printf("<= INIHWR\n");
1542 //_____________________________________________________________________________
1543 void jomiwr(const Int_t & /*nge*/, const Int_t & /*lin*/, const Int_t & /*lou*/,
1546 // Geometry initialization wrapper called by FLUKAM. Provides to FLUKA the
1547 // number of regions (volumes in TGeo)
1548 // build application geometry
1549 if (mcgeom->IsDebugging()) printf("========== Inside JOMIWR\n");
1550 flukaReg = gGeoManager->GetListOfUVolumes()->GetEntriesFast();
1551 if (mcgeom->IsDebugging()) printf("<= JOMIWR: last region=%i\n", flukaReg);
1554 //_____________________________________________________________________________
1555 void lkdbwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1556 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1557 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1559 if (mcgeom->IsDebugging()) {
1560 printf("========== Inside LKDBWR (%f, %f, %f)\n",pSx, pSy, pSz);
1561 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1562 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1564 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1565 if (gGeoManager->IsOutside()) {
1566 newReg = mcgeom->NofVolumes()+1;
1567 // newLttc = gGeoManager->GetCurrentNodeId();
1568 newLttc = 999999999;
1569 if (mcgeom->IsDebugging()) {
1570 printf("OUTSIDE\n");
1571 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1572 printf("<= LKMGWR\n");
1577 newReg = node->GetVolume()->GetNumber();
1578 newLttc = gGeoManager->GetCurrentNodeId()+1;
1579 mcgeom->SetNextRegion(newReg, newLttc);
1581 if (mcgeom->IsDebugging()) {
1582 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1583 printf("<= LKDBWR\n");
1587 //_____________________________________________________________________________
1588 void lkfxwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1589 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1590 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1592 if (mcgeom->IsDebugging()) {
1593 printf("========== Inside LKFXWR (%f, %f, %f)\n",pSx, pSy, pSz);
1594 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1595 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1597 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1598 if (gGeoManager->IsOutside()) {
1599 newReg = mcgeom->NofVolumes()+1;
1600 // newLttc = gGeoManager->GetCurrentNodeId();
1601 newLttc = 999999999;
1602 if (mcgeom->IsDebugging()) {
1603 printf("OUTSIDE\n");
1604 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1605 printf("<= LKMGWR\n");
1610 newReg = node->GetVolume()->GetNumber();
1611 newLttc = gGeoManager->GetCurrentNodeId()+1;
1612 mcgeom->SetNextRegion(newReg, newLttc);
1614 if (mcgeom->IsDebugging()) {
1615 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1616 printf("<= LKFXWR\n");
1620 //_____________________________________________________________________________
1621 void lkmgwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1622 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1623 Int_t &flagErr, Int_t &newReg, Int_t &newLttc)
1625 if (mcgeom->IsDebugging()) {
1626 printf("========== Inside LKMGWR (%f, %f, %f)\n",pSx, pSy, pSz);
1627 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1628 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1630 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1631 if (gGeoManager->IsOutside()) {
1632 newReg = mcgeom->NofVolumes()+1;
1633 // newLttc = gGeoManager->GetCurrentNodeId();
1634 newLttc = 999999999;
1635 if (mcgeom->IsDebugging()) {
1636 printf("OUTSIDE\n");
1637 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1638 printf("<= LKMGWR\n");
1643 newReg = node->GetVolume()->GetNumber();
1644 newLttc = gGeoManager->GetCurrentNodeId()+1;
1645 mcgeom->SetNextRegion(newReg, newLttc);
1647 if (mcgeom->IsDebugging()) {
1648 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1649 printf("<= LKMGWR\n");
1653 //_____________________________________________________________________________
1654 void lkwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1655 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1656 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1658 if (mcgeom->IsDebugging()) {
1659 printf("========== Inside LKWR (%f, %f, %f)\n",pSx, pSy, pSz);
1660 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1661 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1663 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1664 if (gGeoManager->IsOutside()) {
1665 newReg = mcgeom->NofVolumes()+1;
1666 // newLttc = gGeoManager->GetCurrentNodeId();
1667 newLttc = 999999999;
1668 if (mcgeom->IsDebugging()) {
1669 printf("OUTSIDE\n");
1670 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1671 printf("<= LKMGWR\n");
1676 newReg = node->GetVolume()->GetNumber();
1677 newLttc = gGeoManager->GetCurrentNodeId()+1;
1678 mcgeom->SetNextRegion(newReg, newLttc);
1680 if (mcgeom->IsDebugging()) {
1681 printf(" out: newReg=%i newLttc=%i in %s\n", newReg, newLttc, gGeoManager->GetPath());
1682 printf("<= LKWR\n");
1686 //_____________________________________________________________________________
1687 void nrmlwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1688 Double_t &pVx, Double_t &pVy, Double_t &pVz,
1689 Double_t *norml, const Int_t &oldReg,
1690 const Int_t &newReg, Int_t &flagErr)
1692 if (mcgeom->IsDebugging()) {
1693 printf("========== Inside NRMLWR (%g, %g, %g, %g, %g, %g)\n", pSx,pSy,pSz,pVx,pVy,pVz);
1694 printf(" oldReg=%i, newReg=%i\n", oldReg,newReg);
1696 // Int_t curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1697 // Int_t curLttc = gGeoManager->GetCurrentNodeId()+1;
1698 // if (mcgeom->IsDebugging()) printf(" curReg=%i, curLttc=%i in: %s\n", curreg, curLttc, gGeoManager->GetPath());
1699 // Bool_t regsame = (curreg==oldReg)?kTRUE:kFALSE;
1700 gGeoManager->SetCurrentPoint(pSx, pSy, pSz);
1701 gGeoManager->SetCurrentDirection(pVx,pVy,pVz);
1704 if (mcgeom->IsDebugging()) printf(" REGIONS DOEN NOT MATCH\n");
1705 gGeoManager->FindNode();
1706 curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1707 curLttc = gGeoManager->GetCurrentNodeId()+1;
1708 if (mcgeom->IsDebugging()) printf(" re-initialized point: curReg=%i curLttc=%i curPath=%s\n", curreg, curLttc, gGeoManager->GetPath());
1711 Double_t *dnorm = gGeoManager->FindNormalFast();
1714 printf(" ERROR: Cannot compute fast normal\n");
1720 norml[0] = -dnorm[0];
1721 norml[1] = -dnorm[1];
1722 norml[2] = -dnorm[2];
1723 if (mcgeom->IsDebugging()) printf(" normal to boundary: (%g, %g, %g)\n", norml[0], norml[1], norml[2]);
1724 // curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1725 // curLttc = gGeoManager->GetCurrentNodeId()+1;
1726 if (mcgeom->IsDebugging()) {
1727 // printf(" final location: curReg=%i, curLttc=%i in %s\n", curreg,curLttc,gGeoManager->GetPath());
1728 printf("<= NRMLWR\n");
1732 //_____________________________________________________________________________
1733 void rgrpwr(const Int_t & /*flukaReg*/, const Int_t & /*ptrLttc*/, Int_t & /*g4Reg*/,
1734 Int_t * /*indMother*/, Int_t * /*repMother*/, Int_t & /*depthFluka*/)
1736 if (mcgeom->IsDebugging()) printf("=> Dummy RGRPWR\n");
1739 //_____________________________________________________________________________
1740 Int_t isvhwr(const Int_t &check, const Int_t & intHist)
1743 // Wrapper for saving current navigation history (fCheck=default)
1744 // and returning its pointer. If fCheck=-1 copy of history pointed
1745 // by intHist is made in NavHistWithCount object, and its pointer
1746 // is returned. fCheck=1 and fCheck=2 cases are only in debugging
1747 // version: an array is created by means of FGeometryInit functions
1748 // (but could be a static int * ptrArray = new int[10000] with
1749 // file scope as well) that stores a flag for deleted/undeleted
1750 // histories and at the end of event is checked to verify that
1751 // all saved history objects have been deleted.
1753 // For TGeo, just return the current node ID. No copy need to be made.
1755 if (mcgeom->IsDebugging()) printf("=> Inside ISVHWR\n");
1756 if (check<0) return intHist;
1757 Int_t histInt = gGeoManager->GetCurrentNodeId()+1;
1758 if (mcgeom->IsDebugging()) printf("<= ISVHWR: history is: %i in: %s\n", histInt, gGeoManager->GetPath());