2 // Author: Andrei Gheata 10/07/2003
4 #include "TObjString.h"
6 //#include "TVirtualMCApplication.h"
7 #include "TFlukaMCGeometry.h"
8 #include "TGeoManager.h"
9 #include "TGeoVolume.h"
14 # define idnrwr idnrwr_
16 # define g1rtwr g1rtwr_
17 # define conhwr conhwr_
18 # define inihwr inihwr_
19 # define jomiwr jomiwr_
20 # define lkdbwr lkdbwr_
21 # define lkfxwr lkfxwr_
22 # define lkmgwr lkmgwr_
24 # define magfld magfld_
25 # define nrmlwr nrmlwr_
26 # define rgrpwr rgrpwr_
27 # define isvhwr isvhwr_
31 # define idnrwr IDNRWR
33 # define g1rtwr G1RTWR
34 # define conhwr CONHWR
35 # define inihwr INIHWR
36 # define jomiwr JOMIWR
37 # define lkdbwr LKDBWR
38 # define lkfxwr LKFXWR
39 # define lkmgwr LKMGWR
41 # define magfld MAGFLD
42 # define nrmlwr NRMLWR
43 # define rgrpwr RGRPWR
44 # define isvhwr ISVHWR
48 //____________________________________________________________________________
52 // Prototypes for FLUKA navigation methods
54 Int_t type_of_call idnrwr(const Int_t & /*nreg*/, const Int_t & /*mlat*/);
55 void type_of_call g1wr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
56 Double_t * /*pV*/, Int_t & /*oldReg*/ , const Int_t & /*oldLttc*/, Double_t & /*propStep*/,
57 Int_t & /*nascFlag*/, Double_t & /*retStep*/, Int_t & /*newReg*/,
58 Double_t & /*saf*/, Int_t & /*newLttc*/, Int_t & /*LttcFlag*/,
59 Double_t *s /*Lt*/, Int_t * /*jrLt*/);
61 void type_of_call g1rtwr();
62 void type_of_call conhwr(Int_t & /*intHist*/, Int_t * /*incrCount*/);
63 void type_of_call inihwr(Int_t & /*intHist*/);
64 void type_of_call jomiwr(const Int_t & /*nge*/, const Int_t & /*lin*/, const Int_t & /*lou*/,
65 Int_t & /*flukaReg*/);
66 void type_of_call lkdbwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
67 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
68 Int_t & /*newReg*/, Int_t & /*flagErr*/, Int_t & /*newLttc*/);
69 void type_of_call lkfxwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
70 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
71 Int_t & /*newReg*/, Int_t & /*flagErr*/, Int_t & /*newLttc*/);
72 void type_of_call lkmgwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
73 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
74 Int_t & /*flagErr*/, Int_t & /*newReg*/, Int_t & /*newLttc*/);
75 void type_of_call lkwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
76 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
77 Int_t & /*newReg*/, Int_t & /*flagErr*/, Int_t & /*newLttc*/);
78 // void type_of_call magfld(const Double_t & /*pX*/, const Double_t & /*pY*/, const Double_t & /*pZ*/,
79 // Double_t & /*cosBx*/, Double_t & /*cosBy*/, Double_t & /*cosBz*/,
80 // Double_t & /*Bmag*/, Int_t & /*reg*/, Int_t & /*idiscflag*/);
81 void type_of_call nrmlwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
82 Double_t & /*pVx*/, Double_t & /*pVy*/, Double_t & /*pVz*/,
83 Double_t * /*norml*/, const Int_t & /*oldReg*/,
84 const Int_t & /*newReg*/, Int_t & /*flagErr*/);
85 void type_of_call rgrpwr(const Int_t & /*flukaReg*/, const Int_t & /*ptrLttc*/, Int_t & /*g4Reg*/,
86 Int_t * /*indMother*/, Int_t * /*repMother*/, Int_t & /*depthFluka*/);
87 Int_t type_of_call isvhwr(const Int_t & /*fCheck*/, const Int_t & /*intHist*/);
90 // TFluka global pointer
92 TFlukaMCGeometry *mcgeom = 0;
94 ClassImp(TFlukaMCGeometry)
96 TFlukaMCGeometry* TFlukaMCGeometry::fgInstance=0;
98 //_____________________________________________________________________________
99 TFlukaMCGeometry::TFlukaMCGeometry(const char *name, const char *title)
100 : TVirtualMCGeometry(name, title)
103 // Standard constructor
110 fluka = (TFluka*)gMC;
114 //_____________________________________________________________________________
115 TFlukaMCGeometry::TFlukaMCGeometry()
116 : TVirtualMCGeometry()
119 // Default constructor
126 fluka = (TFluka*)gMC;
130 //_____________________________________________________________________________
131 TFlukaMCGeometry::~TFlukaMCGeometry()
137 if (fRegionList) delete [] fRegionList;
138 if (gGeoManager) delete gGeoManager;
144 //_____________________________________________________________________________
145 TFlukaMCGeometry::TFlukaMCGeometry(const TFlukaMCGeometry &)
146 : TVirtualMCGeometry()
153 //_____________________________________________________________________________
154 Double_t* TFlukaMCGeometry::CreateDoubleArray(Float_t* array, Int_t size) const
156 // Converts Float_t* array to Double_t*,
157 // !! The new array has to be deleted by user.
160 Double_t* doubleArray;
162 doubleArray = new Double_t[size];
163 for (Int_t i=0; i<size; i++) doubleArray[i] = array[i];
167 doubleArray = new Double_t[1];
173 //_____________________________________________________________________________
174 void TFlukaMCGeometry::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,
175 Float_t &dens, Float_t &radl, Float_t &absl,
176 Float_t* /*ubuf*/, Int_t& /*nbuf*/)
178 if (fDebug) printf("Gfmate %i\n", imat);
180 TIter next (gGeoManager->GetListOfMaterials());
181 while ((mat = (TGeoMaterial*)next())) {
182 if (mat->GetUniqueID() == (UInt_t)imat) break;
185 Error("Gfmate", "no material with index %i found", imat);
188 sprintf(name, "%s", mat->GetName());
191 dens = mat->GetDensity();
192 radl = mat->GetRadLen();
193 absl = mat->GetIntLen();
194 if (fDebug) printf(" ->material found : %s a=%g, z=%g, dens=%g, radl=%g, absl=%g\n", name, a,z,dens,radl,absl);
197 //_____________________________________________________________________________
198 void TFlukaMCGeometry::Gfmate(Int_t imat, char *name, Double_t &a, Double_t &z,
199 Double_t &dens, Double_t &radl, Double_t &absl,
200 Double_t* /*ubuf*/, Int_t& /*nbuf*/)
202 if (fDebug) printf("Gfmate %i\n", imat);
204 TIter next (gGeoManager->GetListOfMaterials());
205 while ((mat = (TGeoMaterial*)next())) {
206 if (mat->GetUniqueID() == (UInt_t)imat) break;
209 Error("Gfmate", "no material with index %i found", imat);
212 sprintf(name, "%s", mat->GetName());
215 dens = mat->GetDensity();
216 radl = mat->GetRadLen();
217 absl = mat->GetIntLen();
218 if (fDebug) printf(" ->material found : %s a=%g, z=%g, dens=%g, radl=%g, absl=%g\n", name, a,z,dens,radl,absl);
221 //_____________________________________________________________________________
222 void TFlukaMCGeometry::Material(Int_t& kmat, const char* name, Double_t a, Double_t z,
223 Double_t dens, Double_t radl, Double_t absl, Float_t* buf,
227 // Defines a Material
229 // kmat number assigned to the material
230 // name material name
231 // a atomic mass in au
233 // dens density in g/cm3
234 // absl absorbtion length in cm
235 // if >=0 it is ignored and the program
236 // calculates it, if <0. -absl is taken
237 // radl radiation length in cm
238 // if >=0 it is ignored and the program
239 // calculates it, if <0. -radl is taken
240 // buf pointer to an array of user words
241 // nbuf number of user words
244 Double_t* dbuf = CreateDoubleArray(buf, nwbuf);
245 Material(kmat, name, a, z, dens, radl, absl, dbuf, nwbuf);
249 //_____________________________________________________________________________
250 void TFlukaMCGeometry::Material(Int_t& kmat, const char* name, Double_t a, Double_t z,
251 Double_t dens, Double_t radl, Double_t absl, Double_t* /*buf*/,
255 // Defines a Material
257 // kmat number assigned to the material
258 // name material name
259 // a atomic mass in au
261 // dens density in g/cm3
262 // absl absorbtion length in cm
263 // if >=0 it is ignored and the program
264 // calculates it, if <0. -absl is taken
265 // radl radiation length in cm
266 // if >=0 it is ignored and the program
267 // calculates it, if <0. -radl is taken
268 // buf pointer to an array of user words
269 // nbuf number of user words
272 kmat = gGeoManager->GetListOfMaterials()->GetSize();
273 gGeoManager->Material(name, a, z, dens, kmat, radl, absl);
274 if (fDebug) printf("Material %s: kmat=%i, a=%g, z=%g, dens=%g\n", name, kmat, a, z, dens);
277 //_____________________________________________________________________________
278 void TFlukaMCGeometry::Mixture(Int_t& kmat, const char* name, Float_t* a, Float_t* z,
279 Double_t dens, Int_t nlmat, Float_t* wmat)
282 // Defines mixture OR COMPOUND IMAT as composed by
283 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
285 // If NLMAT > 0 then wmat contains the proportion by
286 // weights of each basic material in the mixture.
288 // If nlmat < 0 then WMAT contains the number of atoms
289 // of a given kind into the molecule of the COMPOUND
290 // In this case, WMAT in output is changed to relative
294 Double_t* da = CreateDoubleArray(a, TMath::Abs(nlmat));
295 Double_t* dz = CreateDoubleArray(z, TMath::Abs(nlmat));
296 Double_t* dwmat = CreateDoubleArray(wmat, TMath::Abs(nlmat));
298 Mixture(kmat, name, da, dz, dens, nlmat, dwmat);
299 for (Int_t i=0; i<nlmat; i++) {
300 a[i] = da[i]; z[i] = dz[i]; wmat[i] = dwmat[i];
308 //_____________________________________________________________________________
309 void TFlukaMCGeometry::Mixture(Int_t& kmat, const char* name, Double_t* a, Double_t* z,
310 Double_t dens, Int_t nlmat, Double_t* wmat)
313 // Defines mixture OR COMPOUND IMAT as composed by
314 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
316 // If NLMAT > 0 then wmat contains the proportion by
317 // weights of each basic material in the mixture.
319 // If nlmat < 0 then WMAT contains the number of atoms
320 // of a given kind into the molecule of the COMPOUND
321 // In this case, WMAT in output is changed to relative
329 for (i=0;i<nlmat;i++) {
330 amol += a[i]*wmat[i];
332 for (i=0;i<nlmat;i++) {
333 wmat[i] *= a[i]/amol;
336 kmat = gGeoManager->GetListOfMaterials()->GetSize();
338 printf("Mixture %s with %i elem: kmat=%i, dens=%g\n", name, nlmat, kmat, dens);
339 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]);
341 gGeoManager->Mixture(name, a, z, dens, nlmat, wmat, kmat);
343 //_____________________________________________________________________________
344 Int_t TFlukaMCGeometry::GetMedium() const
346 // Get current medium number
348 TGeoNode *node = gGeoManager->GetCurrentNode();
349 if (!node) imed = gGeoManager->GetTopNode()->GetVolume()->GetMedium()->GetId();
350 else imed = node->GetVolume()->GetMedium()->GetId();
351 if (fDebug) printf("GetMedium=%i\n", imed);
355 //_____________________________________________________________________________
356 Int_t TFlukaMCGeometry::GetFlukaMaterial(Int_t imed) const
358 // Returns FLUKA material index for medium IMED
359 TGeoMedium *med = (TGeoMedium*)gGeoManager->GetListOfMedia()->At(imed-1);
361 Error("GetFlukaMaterial", "MEDIUM %i nor found", imed);
364 Int_t imatfl = med->GetMaterial()->GetIndex();
368 //_____________________________________________________________________________
369 Int_t *TFlukaMCGeometry::GetRegionList(Int_t imed, Int_t &nreg)
371 // Get an ordered list of regions matching a given medium number
373 if (!fRegionList) fRegionList = new Int_t[NofVolumes()+1];
374 TIter next(gGeoManager->GetListOfUVolumes());
377 while ((vol = (TGeoVolume*)next())) {
378 imedium = vol->GetMedium()->GetId();
379 if (imedium == imed) {
380 ireg = vol->GetNumber();
381 fRegionList[nreg++] = ireg;
387 //_____________________________________________________________________________
388 Int_t *TFlukaMCGeometry::GetMaterialList(Int_t imat, Int_t &nreg)
390 // Get an ordered list of regions matching a given medium number
392 if (!fRegionList) fRegionList = new Int_t[NofVolumes()+1];
393 TIter next(gGeoManager->GetListOfUVolumes());
395 Int_t imaterial, ireg;
396 while ((vol = (TGeoVolume*)next())) {
397 imaterial = vol->GetMedium()->GetMaterial()->GetIndex();
398 if (imaterial == imat) {
399 ireg = vol->GetNumber();
400 fRegionList[nreg++] = ireg;
405 //_____________________________________________________________________________
406 void TFlukaMCGeometry::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
407 Int_t ifield, Double_t fieldm, Double_t tmaxfd,
408 Double_t stemax, Double_t deemax, Double_t epsil,
409 Double_t stmin, Float_t* ubuf, Int_t nbuf)
412 // kmed tracking medium number assigned
413 // name tracking medium name
414 // nmat material number
415 // isvol sensitive volume flag
416 // ifield magnetic field
417 // fieldm max. field value (kilogauss)
418 // tmaxfd max. angle due to field (deg/step)
419 // stemax max. step allowed
420 // deemax max. fraction of energy lost in a step
421 // epsil tracking precision (cm)
422 // stmin min. step due to continuous processes (cm)
424 // ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
425 // ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
426 // performed with g3helix; ifield = 3 if tracking performed with g3helx3.
429 //printf("Creating mediuma: %s, numed=%d, nmat=%d\n",name,kmed,nmat);
430 Double_t* dubuf = CreateDoubleArray(ubuf, nbuf);
431 Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
436 //_____________________________________________________________________________
437 void TFlukaMCGeometry::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
438 Int_t ifield, Double_t fieldm, Double_t tmaxfd,
439 Double_t stemax, Double_t deemax, Double_t epsil,
440 Double_t stmin, Double_t* /*ubuf*/, Int_t /*nbuf*/)
443 // kmed tracking medium number assigned
444 // name tracking medium name
445 // nmat material number
446 // isvol sensitive volume flag
447 // ifield magnetic field
448 // fieldm max. field value (kilogauss)
449 // tmaxfd max. angle due to field (deg/step)
450 // stemax max. step allowed
451 // deemax max. fraction of energy lost in a step
452 // epsil tracking precision (cm)
453 // stmin min. step due to continuos processes (cm)
455 // ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
456 // ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
457 // performed with g3helix; ifield = 3 if tracking performed with g3helx3.
460 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
461 gGeoManager->Medium(name,kmed,nmat, isvol, ifield, fieldm, tmaxfd, stemax,deemax, epsil, stmin);
462 if (fDebug) printf("Medium %s: kmed=%i, nmat=%i, isvol=%i\n", name, kmed, nmat,isvol);
465 //_____________________________________________________________________________
466 void TFlukaMCGeometry::Matrix(Int_t& krot, Double_t thex, Double_t phix, Double_t they,
467 Double_t phiy, Double_t thez, Double_t phiz)
470 // krot rotation matrix number assigned
471 // theta1 polar angle for axis i
472 // phi1 azimuthal angle for axis i
473 // theta2 polar angle for axis ii
474 // phi2 azimuthal angle for axis ii
475 // theta3 polar angle for axis iii
476 // phi3 azimuthal angle for axis iii
478 // it defines the rotation matrix number irot.
481 krot = gGeoManager->GetListOfMatrices()->GetEntriesFast();
482 gGeoManager->Matrix(krot, thex, phix, they, phiy, thez, phiz);
483 if (fDebug) printf("Rotation %i defined\n", krot);
486 //_____________________________________________________________________________
487 Int_t TFlukaMCGeometry::Gsvolu(const char *name, const char *shape, Int_t nmed,
488 Float_t *upar, Int_t npar)
493 // NUMED Tracking medium number
494 // NPAR Number of shape parameters
495 // UPAR Vector containing shape parameters
497 // It creates a new volume in the JVOLUM data structure.
500 Double_t* dupar = CreateDoubleArray(upar, npar);
501 Int_t id = Gsvolu(name, shape, nmed, dupar, npar);
506 //_____________________________________________________________________________
507 Int_t TFlukaMCGeometry::Gsvolu(const char *name, const char *shape, Int_t nmed,
508 Double_t *upar, Int_t npar)
513 // NUMED Tracking medium number
514 // NPAR Number of shape parameters
515 // UPAR Vector containing shape parameters
517 // It creates a new volume in the JVOLUM data structure.
524 TGeoVolume* vol = gGeoManager->Volume(vname, shape, nmed, upar, npar);
525 if (fDebug) printf("Volume %s: id=%i shape=%s, nmed=%i\n", vname, vol->GetNumber(), shape, nmed);
526 return vol->GetNumber();
529 //_____________________________________________________________________________
530 void TFlukaMCGeometry::Gsdvn(const char *name, const char *mother, Int_t ndiv,
534 // Create a new volume by dividing an existing one
537 // MOTHER Mother volume name
538 // NDIV Number of divisions
541 // X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
542 // It divides a previously defined volume.
547 Vname(mother,vmother);
549 gGeoManager->Division(vname, vmother, iaxis, ndiv, 0, 0, 0, "n");
550 if (fDebug) printf("Division %s: mother=%s iaxis=%i ndiv=%i\n", vname, vmother, iaxis, ndiv);
553 //_____________________________________________________________________________
554 void TFlukaMCGeometry::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
555 Int_t iaxis, Double_t c0i, Int_t numed)
558 // Create a new volume by dividing an existing one
560 // Divides mother into ndiv divisions called name
561 // along axis iaxis starting at coordinate value c0.
562 // the new volume created will be medium number numed.
567 Vname(mother,vmother);
569 gGeoManager->Division(vname, vmother, iaxis, ndiv, c0i, 0, numed, "nx");
571 //_____________________________________________________________________________
572 void TFlukaMCGeometry::Gsdvt(const char *name, const char *mother, Double_t step,
573 Int_t iaxis, Int_t numed, Int_t /*ndvmx*/)
576 // Create a new volume by dividing an existing one
578 // Divides MOTHER into divisions called NAME along
579 // axis IAXIS in steps of STEP. If not exactly divisible
580 // will make as many as possible and will centre them
581 // with respect to the mother. Divisions will have medium
582 // number NUMED. If NUMED is 0, NUMED of MOTHER is taken.
583 // NDVMX is the expected maximum number of divisions
584 // (If 0, no protection tests are performed)
589 Vname(mother,vmother);
591 gGeoManager->Division(vname, vmother, iaxis, 0, 0, step, numed, "s");
594 //_____________________________________________________________________________
595 void TFlukaMCGeometry::Gsdvt2(const char *name, const char *mother, Double_t step,
596 Int_t iaxis, Double_t c0, Int_t numed, Int_t /*ndvmx*/)
599 // Create a new volume by dividing an existing one
601 // Divides MOTHER into divisions called NAME along
602 // axis IAXIS starting at coordinate value C0 with step
604 // The new volume created will have medium number NUMED.
605 // If NUMED is 0, NUMED of mother is taken.
606 // NDVMX is the expected maximum number of divisions
607 // (If 0, no protection tests are performed)
612 Vname(mother,vmother);
614 gGeoManager->Division(vname, vmother, iaxis, 0, c0, step, numed, "sx");
617 //_____________________________________________________________________________
618 void TFlukaMCGeometry::Gsord(const char * /*name*/, Int_t /*iax*/)
621 // Flags volume CHNAME whose contents will have to be ordered
622 // along axis IAX, by setting the search flag to -IAX
626 // IAX = 4 Rxy (static ordering only -> GTMEDI)
627 // IAX = 14 Rxy (also dynamic ordering -> GTNEXT)
628 // IAX = 5 Rxyz (static ordering only -> GTMEDI)
629 // IAX = 15 Rxyz (also dynamic ordering -> GTNEXT)
630 // IAX = 6 PHI (PHI=0 => X axis)
631 // IAX = 7 THETA (THETA=0 => Z axis)
634 // TBC - keep this function
635 // nothing to be done for TGeo //xx
638 //_____________________________________________________________________________
639 void TFlukaMCGeometry::Gspos(const char *name, Int_t nr, const char *mother, Double_t x,
640 Double_t y, Double_t z, Int_t irot, const char *konly)
643 // Position a volume into an existing one
646 // NUMBER Copy number of the volume
647 // MOTHER Mother volume name
648 // X X coord. of the volume in mother ref. sys.
649 // Y Y coord. of the volume in mother ref. sys.
650 // Z Z coord. of the volume in mother ref. sys.
651 // IROT Rotation matrix number w.r.t. mother ref. sys.
652 // ONLY ONLY/MANY flag
654 // It positions a previously defined volume in the mother.
657 TString only = konly;
659 Bool_t isOnly = kFALSE;
660 if (only.Contains("only")) isOnly = kTRUE;
664 Vname(mother,vmother);
667 gGeoManager->Node(vname, nr, vmother, x, y, z, irot, isOnly, upar);
668 if (fDebug) printf("Adding daughter %s to %s: cpy=%i irot=%i only=%s\n", vname,vmother,nr,irot,only.Data());
671 //_____________________________________________________________________________
672 void TFlukaMCGeometry::Gsposp(const char *name, Int_t nr, const char *mother,
673 Double_t x, Double_t y, Double_t z, Int_t irot,
674 const char *konly, Float_t *upar, Int_t np )
677 // Place a copy of generic volume NAME with user number
678 // NR inside MOTHER, with its parameters UPAR(1..NP)
681 Double_t* dupar = CreateDoubleArray(upar, np);
682 Gsposp(name, nr, mother, x, y, z, irot, konly, dupar, np);
686 //_____________________________________________________________________________
687 void TFlukaMCGeometry::Gsposp(const char *name, Int_t nr, const char *mother,
688 Double_t x, Double_t y, Double_t z, Int_t irot,
689 const char *konly, Double_t *upar, Int_t np )
692 // Place a copy of generic volume NAME with user number
693 // NR inside MOTHER, with its parameters UPAR(1..NP)
696 TString only = konly;
698 Bool_t isOnly = kFALSE;
699 if (only.Contains("only")) isOnly = kTRUE;
703 Vname(mother,vmother);
705 gGeoManager->Node(vname,nr,vmother, x,y,z,irot,isOnly,upar,np);
706 if (fDebug) printf("Adding daughter(s) %s to %s: cpy=%i irot=%i only=%s\n", vname,vmother,nr,irot,only.Data());
709 //_____________________________________________________________________________
710 Int_t TFlukaMCGeometry::VolId(const Text_t *name) const
713 // Return the unique numeric identifier for volume name
716 Int_t uid = gGeoManager->GetUID(name);
718 printf("VolId: Volume %s not found\n",name);
721 if (fDebug) printf("VolId for %s: %i\n", name, uid);
725 //_____________________________________________________________________________
726 const char* TFlukaMCGeometry::VolName(Int_t id) const
729 // Return the volume name given the volume identifier
731 TGeoVolume *volume = gGeoManager->GetVolume(id);
733 Error("VolName","volume with id=%d does not exist",id);
736 if (fDebug) printf("VolName for id=%i: %s\n", id, volume->GetName());
737 return volume->GetName();
740 //_____________________________________________________________________________
741 Int_t TFlukaMCGeometry::NofVolumes() const
744 // Return total number of volumes in the geometry
747 return gGeoManager->GetListOfUVolumes()->GetEntriesFast()-1;
750 //_____________________________________________________________________________
751 Int_t TFlukaMCGeometry::VolId2Mate(Int_t id) const
754 // Return material number for a given volume id
756 TGeoVolume *volume = gGeoManager->GetVolume(id);
758 Error("VolId2Mate","volume with id=%d does not exist",id);
761 TGeoMedium *med = volume->GetMedium();
763 if (fDebug) printf("VolId2Mate id=%i: idmed=%i\n", id, med->GetId());
767 //_____________________________________________________________________________
768 Int_t TFlukaMCGeometry::CurrentVolID(Int_t& copyNo) const
770 // Returns the current volume ID and copy number
771 if (gGeoManager->IsOutside()) return 0;
772 TGeoNode *node = gGeoManager->GetCurrentNode();
773 copyNo = node->GetNumber();
774 Int_t id = node->GetVolume()->GetNumber();
775 if (fDebug) printf("CurrentVolId(cpy=%i) = %i\n", copyNo, id);
779 //_____________________________________________________________________________
780 Int_t TFlukaMCGeometry::CurrentVolOffID(Int_t off, Int_t& copyNo) const
782 // Return the current volume "off" upward in the geometrical tree
783 // ID and copy number
784 if (off<0 || off>gGeoManager->GetLevel()) return 0;
785 if (off==0) return CurrentVolID(copyNo);
786 TGeoNode *node = gGeoManager->GetMother(off);
788 copyNo = node->GetNumber();
789 if (fDebug) printf("CurrentVolOffId(off=%i,cpy=%i) = %i\n", off,copyNo,node->GetVolume()->GetNumber() );
790 return node->GetVolume()->GetNumber();
794 //_____________________________________________________________________________
795 const char* TFlukaMCGeometry::CurrentVolName() const
798 // Returns the current volume name
800 if (gGeoManager->IsOutside()) return 0;
801 if (fDebug) printf("CurrentVolName : %s\n", gGeoManager->GetCurrentVolume()->GetName());
802 return gGeoManager->GetCurrentVolume()->GetName();
804 //_____________________________________________________________________________
805 const char* TFlukaMCGeometry::CurrentVolOffName(Int_t off) const
808 // Return the current volume "off" upward in the geometrical tree
809 // ID, name and copy number
810 // if name=0 no name is returned
812 if (off<0 || off>gGeoManager->GetLevel()) return 0;
813 if (off==0) return CurrentVolName();
814 TGeoNode *node = gGeoManager->GetMother(off);
816 if (fDebug) printf("CurrentVolOffName(off=%i) : %s\n", off,node->GetVolume()->GetName());
817 return node->GetVolume()->GetName();
820 //_____________________________________________________________________________
821 void TFlukaMCGeometry::Gsatt(const char *name, const char *att, Int_t val)
825 // IOPT Name of the attribute to be set
826 // IVAL Value to which the attribute is to be set
827 // see: TFluka::Gsatt
832 gGeoManager->SetVolumeAttribute(vname, vatt, val);
835 //_____________________________________________________________________________
836 void TFlukaMCGeometry::Gdtom(Float_t *xd, Float_t *xm, Int_t iflag)
839 // Computes coordinates XM (Master Reference System
840 // knowing the coordinates XD (Detector Ref System)
841 // The local reference system can be initialized by
842 // - the tracking routines and GDTOM used in GUSTEP
843 // - a call to GSCMED(NLEVEL,NAMES,NUMBER)
844 // (inverse routine is GMTOD)
846 // If IFLAG=1 convert coordinates
847 // IFLAG=2 convert direction cosinus
849 Double_t XM[3], XD[3];
851 for (i=0;i<3;i++) XD[i] = xd[i];
852 if (iflag == 1) gGeoManager->LocalToMaster(XD,XM);
853 else gGeoManager->LocalToMasterVect(XD,XM);
854 for (i=0;i<3;i++) xm[i]=XM[i];
857 //_____________________________________________________________________________
858 void TFlukaMCGeometry::Gdtom(Double_t *xd, Double_t *xm, Int_t iflag)
860 if (iflag == 1) gGeoManager->LocalToMaster(xd,xm);
861 else gGeoManager->LocalToMasterVect(xd,xm);
864 //_____________________________________________________________________________
865 void TFlukaMCGeometry::Gmtod(Float_t *xm, Float_t *xd, Int_t iflag)
868 // Computes coordinates XD (in DRS)
869 // from known coordinates XM in MRS
870 // The local reference system can be initialized by
871 // - the tracking routines and GMTOD used in GUSTEP
872 // - a call to GMEDIA(XM,NUMED,CHECK)
873 // - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
874 // (inverse routine is GDTOM)
876 // If IFLAG=1 convert coordinates
877 // IFLAG=2 convert direction cosinus
879 Double_t XM[3], XD[3];
881 for (i=0;i<3;i++) XM[i]=xm[i];
882 if (iflag == 1) gGeoManager->MasterToLocal(XM,XD);
883 else gGeoManager->MasterToLocalVect(XM,XD);
884 for (i=0;i<3;i++) xd[i] = XD[i];
887 //_____________________________________________________________________________
888 void TFlukaMCGeometry::Gmtod(Double_t *xm, Double_t *xd, Int_t iflag)
890 if (iflag == 1) gGeoManager->MasterToLocal(xm,xd);
891 else gGeoManager->MasterToLocalVect(xm,xd);
894 //_____________________________________________________________________________
895 void TFlukaMCGeometry::CreateFlukaMatFile(const char *fname)
897 // ==== from FLUGG ====
898 // NAMES OF ELEMENTS AND COMPOUNDS: the names must be written in upper case,
899 // according to the fluka standard. In addition,. they must be equal to the
900 // names of the fluka materials - see fluka manual - in order that the
901 // program load the right cross sections, and equal to the names included in
902 // the .pemf. Otherwise the user must define the LOW-MAT CARDS, and make his
903 // own .pemf, in order to get the right cross sections loaded in memory.
906 static char elNames[220] = {
907 // 1 ============================= 5 ==================================== 10 ===================================== 15 ===
908 'H','_','H','E','L','I','B','E','B','_','C','_','N','_','O','_','F','_','N','E','N','A','M','G','A','L','S','I','P','_',
909 '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',
910 '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',
911 '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',
912 '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',
913 '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',
914 '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',
915 'S','G','B','H','H','S','M','T','D','S'};
916 memset(zelem, 0, 128*sizeof(Int_t));
918 gGeoManager->Export("flgeom.root");
919 if (fname) sname = fname;
920 else sname = "flukaMat.inp";
922 out.open(sname.Data(), ios::out);
924 Fatal("CreateFlukaMatFile", "could not open file %s for writing", sname.Data());
927 PrintHeader(out, "MATERIALS AND COMPOUNDS");
928 PrintHeader(out, "MATERIALS");
929 TList *matlist = gGeoManager->GetListOfMaterials();
931 Int_t nmater = matlist->GetSize();
933 TObjArray *listfluka = new TObjArray(nmater+50);
934 TObjArray *listflukanames = new TObjArray(nmater+50);
935 TGeoMaterial *mat, *matorig;
936 TGeoMixture *mix = 0;
938 TObjString *objstr, *objstrother;
942 Double_t amat,zmat,rhomat;
943 Double_t zel, ael, wel, rho;
944 char elname[8] = {' ',' ','_', 'E','L','E','M','\0'};
946 Bool_t found = kFALSE;
948 if (fDebug) printf("Creating materials and compounds\n");
949 for (i=0; i<nmater; i++) {
950 mat = (TGeoMaterial*)matlist->At(i);
951 if (mat->GetZ()<1E-1) {
952 mat->SetIndex(2); // vacuum, built-in inside FLUKA
955 // printf("material: %s index=%i: Z=%f A=%f rho=%f\n", mat->GetName(), mat->GetIndex(),mat->GetZ(),mat->GetA(),mat->GetDensity());
956 matorig = gGeoManager->FindDuplicateMaterial(mat);
958 idmat = matorig->GetIndex();
959 mat->SetIndex(idmat);
960 // printf(" -> found a duplicate: %s with index %i\n", matorig->GetName(), idmat);
963 // printf(" Adding to temp list with index %i\n", nfmater+3);
965 mat->SetIndex(nfmater+3);
967 objstr = new TObjString(mat->GetName());
968 listflukanames->Add(objstr);
970 // look if name is existing
972 matname = objstr->GetString();
973 ToFlukaString(matname);
974 objstr->SetString(matname.Data());
977 if (nfmater == 1) break;
978 for (j=0; j<nfmater-1; j++) {
979 objstrother = (TObjString*)listflukanames->At(j);
980 if (objstr->IsEqual(objstrother)) {
981 // we have to change the name
983 Error("CreateFlukaMatFile", "too many materials having same name");
987 k = matname.Index(" ");
990 sprintf(digit, "%d", nidmat);
993 sprintf(&digit[1], "%d", nidmat);
995 matname.Insert(k,digit);
997 objstr->SetString(matname.Data());
1000 if (j == nfmater-2) {
1006 // printf(" newmat name: %s\n", matname.Data());
1008 // now we have unique materials with unique names in the lists
1010 if (matorig && matorig->IsMixture()) {
1011 // create dummy materials for elements
1013 mix = (TGeoMixture*)matorig;
1014 nelem = mix->GetNelements();
1015 // printf(" material is a MIXTURE with %i elements:\n", nelem);
1016 for (j=0; j<nelem; j++) {
1018 zel = (mix->GetZmixt())[j];
1019 ael = (mix->GetAmixt())[j];
1020 // printf(" Zelem[%i] = %g\n",j,zel);
1021 if ((zel-Int_t(zel))>0.01) {
1023 for (Int_t imat=0; imat<nfmater; imat++) {
1024 mat1 = (TGeoMaterial*)listfluka->At(imat);
1025 if (TMath::Abs(mat1->GetZ()-zel)>1E-4) continue;
1026 if (TMath::Abs(mat1->GetA()-ael)>1E-4) continue;
1030 if (!found) Warning("CreateFlukaMatFile", "element with Z=%f\n", zel);
1032 if (!zelem[Int_t(zel)] && !found) {
1033 // write fluka element
1034 memcpy(elname, &elNames[2*Int_t(zel-1)], 2);
1035 zelem[Int_t(zel)] = 1;
1036 mat = new TGeoMaterial(elname, ael, zel, rho);
1037 mat->SetIndex(nfmater+3);
1038 // printf(" element not in list: new material %s at index=%i, Z=%g, A=%g, dummyrho=%g\n",
1039 // elname,nfmater+3,zel,ael,rho);
1040 listfluka->Add(mat);
1041 objstr = new TObjString(elname);
1042 listflukanames->Add(objstr);
1048 // now dump materials in the file
1049 // printf("DUMPING %i materials\n", nfmater);
1050 for (i=0; i<nfmater; i++) {
1051 mat = (TGeoMaterial*)listfluka->At(i);
1052 out << setw(10) << "MATERIAL ";
1053 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1054 // matname = mat->GetName();
1055 objstr = (TObjString*)listflukanames->At(i);
1056 matname = objstr->GetString();
1057 ToFlukaString(matname);
1059 if (zmat-Int_t(zmat)>0.01) {
1060 if (zmat-Int_t(zmat)>0.5) zmat = Int_t(zmat)+1.;
1061 else zmat = Int_t(zmat);
1064 rhomat = mat->GetDensity();
1065 // write material card
1066 if (mat->IsMixture()) {
1067 out << setw(10) << " ";
1068 out << setw(10) << " ";
1069 mix = (TGeoMixture*)mat;
1071 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << zmat;
1072 out << setw(10) << setprecision(3) << amat;
1074 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1075 out << setw(10) << setiosflags(ios::scientific) << setprecision(3) << rhomat;
1076 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1077 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(i+3);
1078 out << setw(10) << " ";
1079 out << setw(10) << " ";
1080 out << setw(8) << matname.Data() << endl;
1082 // write mixture header
1083 PrintHeader(out, "COMPOUNDS");
1085 TGeoMaterial *element;
1086 for (i=0; i<nfmater; i++) {
1087 mat = (TGeoMaterial*)listfluka->At(i);
1088 if (!mat->IsMixture()) continue;
1089 mix = (TGeoMixture*)mat;
1091 out << setw(10) << "COMPOUND ";
1092 nelem = mix->GetNelements();
1093 objstr = (TObjString*)listflukanames->At(i);
1094 matname = objstr->GetString();
1095 // printf("MIXTURE %s with index %i having %i elements\n", matname.Data(), mat->GetIndex(),nelem);
1096 for (j=0; j<nelem; j++) {
1097 // dump mixture cards
1098 // printf(" #elem %i: Z=%g, A=%g, W=%g\n", j, (mix->GetZmixt())[j],
1099 // (mix->GetAmixt())[j],(mix->GetWmixt())[j]);
1100 wel = (mix->GetWmixt())[j];
1101 zel = (mix->GetZmixt())[j];
1102 ael = (mix->GetAmixt())[j];
1103 if (zel-Int_t(zel)>0.01) {
1104 // loop the temporary list
1107 for (Int_t imat=0; imat<i; imat++) {
1108 mat1 = (TGeoMaterial*)listfluka->At(imat);
1109 if (TMath::Abs(mat1->GetZ()-zel)>1E-4) continue;
1110 if (TMath::Abs(mat1->GetA()-ael)>1E-4) continue;
1115 memcpy(elname, &elNames[2*Int_t(zel-1)], 2);
1116 element = (TGeoMaterial*)listfluka->FindObject(elname);
1119 Error("CreateFlukaMatFile", "Element Z=%g %s not found", zel, elname);
1122 idmat = element->GetIndex();
1123 // printf("element %s , index=%i\n", element->GetName(), idmat);
1124 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1125 out << setw(10) << setiosflags(ios::fixed) << setprecision(6) << -wel;
1126 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1127 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(idmat);
1129 if (counttothree == 3) {
1130 out << matname.Data();
1132 if ( (j+1) != nelem) out << setw(10) << "COMPOUND ";
1136 //Unless we have 3, 6, 9... submaterials we need to put some empty
1137 //space and the compound name
1139 for (j=0; j<(3-(nelem%3)); j++)
1140 out << setw(10) << " " << setw(10) << " ";
1141 out << matname.Data();
1146 // Now print the list of regions (volumes in TGeo)
1147 Int_t nvols = gGeoManager->GetListOfUVolumes()->GetEntriesFast()-1;
1150 PrintHeader(out, "TGEO VOLUMES");
1151 for (i=1; i<=nvols; i++) {
1152 vol = gGeoManager->GetVolume(i);
1153 out.setf(std::ios::left, std::ios::adjustfield);
1154 out << setw(10) << i;
1155 out << setw(20) << vol->GetName() << endl;
1158 // Now print the material assignments
1160 PrintHeader(out, "TGEO MATERIAL ASSIGNMENTS");
1161 for (i=1; i<=nvols; i++) {
1162 vol = gGeoManager->GetVolume(i);
1163 mat = vol->GetMedium()->GetMaterial();
1164 idmat = mat->GetIndex();
1165 // flagfield = (vol->GetField())?1.:0.;
1167 out << setw(10) << "ASSIGNMAT ";
1168 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1169 out << setw(10) << setiosflags(ios::fixed) << Double_t(idmat);
1170 out << setw(10) << setiosflags(ios::fixed) << Double_t(i);
1171 out << setw(10) << "0.0";
1172 out << setw(10) << "0.0";
1173 out << setw(10) << setiosflags(ios::fixed) << flagfield;
1174 out << setw(10) << "0.0";
1178 listflukanames->Delete();
1179 delete listflukanames;
1181 fLastMaterial = nfmater+2;
1184 //_____________________________________________________________________________
1185 void TFlukaMCGeometry::PrintHeader(ofstream &out, const char *text) const
1187 // Print a FLUKA header.
1188 out << "*\n" << "*\n" << "*\n";
1189 out << "********************* " << text << " *********************\n"
1191 out << "*...+....1....+....2....+....3....+....4....+....5....+....6....+....7..."
1196 //_____________________________________________________________________________
1197 Int_t TFlukaMCGeometry::RegionId() const
1199 // Returns current region id <-> TGeo node id
1200 if (gGeoManager->IsOutside()) return 0;
1201 return gGeoManager->GetCurrentNode()->GetUniqueID();
1203 //_____________________________________________________________________________
1204 void TFlukaMCGeometry::SetMreg(Int_t mreg)
1206 // Update if needed next history;
1207 Int_t curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1208 if (mreg==curreg) return;
1209 if (mreg==fNextRegion) {
1210 if (fNextLattice!=999999999) gGeoManager->CdNode(fNextLattice-1);
1213 if (fDebug) printf("ERROR: mreg=%i neither current nor next region\n", mreg);
1216 //_____________________________________________________________________________
1217 void TFlukaMCGeometry::SetNextRegion(Int_t mreg, Int_t latt)
1219 // Set index/history for next entered region
1221 fNextLattice = latt;
1224 //_____________________________________________________________________________
1225 void TFlukaMCGeometry::ToFlukaString(TString &str) const
1227 // ToFlukaString converts an string to something usefull in FLUKA:
1228 // * Capital letters
1230 // * Replace ' ' by '_'
1231 if (str.Length()<8) {
1236 for (ilast=7; ilast>0; ilast--) if (str(ilast)!=' ') break;
1238 for (Int_t pos=0; pos<ilast; pos++)
1239 if (str(pos)==' ') str.Replace(pos,1,"_",1);
1242 //______________________________________________________________________________
1243 void TFlukaMCGeometry::Vname(const char *name, char *vname) const
1246 // convert name to upper case. Make vname at least 4 chars
1248 Int_t l = strlen(name);
1251 for (i=0;i<l;i++) vname[i] = toupper(name[i]);
1252 for (i=l;i<4;i++) vname[i] = ' ';
1257 // FLUKA GEOMETRY WRAPPERS - to replace FLUGG wrappers
1259 //_____________________________________________________________________________
1260 Int_t idnrwr(const Int_t & /*nreg*/, const Int_t & /*mlat*/)
1263 // Wrapper for setting DNEAR option on fluka side. Must return 0
1264 // if user doesn't want Fluka to use DNEAR to compute the
1265 // step (the same effect is obtained with the GLOBAL (WHAT(3)=-1)
1266 // card in fluka input), returns 1 if user wants Fluka always to
1267 // use DNEAR (in this case, be sure that GEANT4 DNEAR is unique,
1268 // coming from all directions!!!)
1269 if (mcgeom->IsDebugging()) printf("========== Dummy IDNRWR\n");
1273 //_____________________________________________________________________________
1274 void g1wr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1275 Double_t *pV, Int_t &oldReg , const Int_t &oldLttc, Double_t & propStep,
1276 Int_t & /*nascFlag*/, Double_t &retStep, Int_t &newReg,
1277 Double_t &saf, Int_t &newLttc, Int_t <tcFlag,
1278 Double_t *sLt, Int_t *jrLt)
1281 // Wrapper for geometry tracking: returns approved step of
1282 // particle and all variables that fluka G1 computes.
1284 // Initialize current point/direction
1285 if (mcgeom->IsDebugging()) {
1286 printf("========== Inside G1WR\n");
1287 printf(" point/dir:(%14.9f, %14.9f, %14.9f, %g, %g, %g)\n", pSx,pSy,pSz,pV[0],pV[1],pV[2]);
1289 gGeoManager->SetCurrentPoint(pSx, pSy, pSz);
1290 gGeoManager->SetCurrentDirection(pV);
1291 if (mcgeom->IsDebugging()) printf(" oldReg=%i oldLttc=%i pstep=%f\n",oldReg, oldLttc, propStep);
1292 if (oldLttc==999999999) printf("WOOPS - wrong old lattice\n");
1293 if (gGeoManager->IsOutside()) {
1294 gGeoManager->SetOutside(kFALSE);
1295 gGeoManager->CdTop();
1297 Int_t curLttc = gGeoManager->GetCurrentNodeId()+1;
1298 Int_t curreg = gGeoManager->GetCurrentVolume()->GetNumber();
1299 if (mcgeom->IsDebugging()) printf(" curReg=%i curLttc=%i curPath=%s\n", curreg, curLttc, gGeoManager->GetPath());
1300 Bool_t regsame = (curreg==oldReg)?kTRUE:kFALSE;
1301 if (!regsame && mcgeom->IsDebugging()) printf(" REGIONS DOES NOT MATCH\n");
1302 if (oldLttc != curLttc) {
1303 if (mcgeom->IsDebugging()) printf(" HISTORIES DOES NOT MATCH\n");
1304 gGeoManager->CdNode(oldLttc-1);
1305 curLttc = gGeoManager->GetCurrentNodeId()+1;
1306 curreg = gGeoManager->GetCurrentVolume()->GetNumber();
1307 if (mcgeom->IsDebugging()) printf(" re-initialized point: curReg=%i curLttc=%i curPath=%s\n", curreg, curLttc, gGeoManager->GetPath());
1311 jrLt[lttcFlag] = curLttc;
1312 // now 'oldregion' contains the real region, matching or not the old history
1314 // Compute geometry step/safety within physical step limit
1315 // newReg = oldregion;
1316 Double_t *point = gGeoManager->GetCurrentPoint();
1317 Double_t *dir = gGeoManager->GetCurrentDirection();
1318 Double_t steptot = 0.;
1319 Double_t snext = 0.;
1321 Bool_t done = kFALSE;
1325 gGeoManager->FindNextBoundary(-propStep);
1326 snext = gGeoManager->GetStep();
1327 if (mcgeom->IsDebugging()) printf(" FindNextBoundary(%g) snext=%g\n", propStep, snext);
1329 saf = gGeoManager->GetSafeDistance();
1330 if (mcgeom->IsDebugging()) printf(" Safety: %g\n", saf);
1332 sLt[lttcFlag] = propStep;
1333 jrLt[lttcFlag] = gGeoManager->GetCurrentNodeId()+1;
1336 jrLt[lttcFlag] = -1;
1339 if (snext<propStep) {
1340 // There is a boundary on the way.
1341 // Make a step=snext+1E-6 to force boundary crossing
1344 sLt[lttcFlag] = snext;
1347 // make the step to get into the next region
1348 for (i=0;i<3;i++) point[i]+=(snext+1E-6)*dir[i];
1349 gGeoManager->FindNode();
1351 if (mcgeom->IsDebugging()) printf(" boundary: step made %g\n", snext);
1352 while (gGeoManager->IsSameLocation() && steptot<propStep) {
1354 printf("Geometry error: could not cross boundary after extra 10 microns\n");
1357 for (i=0;i<3;i++) point[i]+=1E-6*dir[i];
1358 gGeoManager->FindNode();
1359 sLt[lttcFlag] += 1E-6;
1360 retStep = sLt[lttcFlag];
1364 if (steptot>propStep) {printf("Error\n");return;}
1365 // we managed to cross the boundary -> in which region
1366 newReg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1368 newLttc = (gGeoManager->IsOutside())?999999999:gGeoManager->GetCurrentNodeId()+1;
1369 sLt[lttcFlag] = snext; // at 1
1370 jrLt[lttcFlag] = newLttc;
1371 sLt[lttcFlag+1] = 0.;
1372 jrLt[lttcFlag+1] = -1;
1375 while (newReg==oldReg && steptot<propStep) {
1376 if (mcgeom->IsDebugging()) printf(" Entered SAME region... continue\n");
1377 pst = propStep-steptot;
1378 gGeoManager->FindNextBoundary(-pst);
1379 snext = gGeoManager->GetStep();
1382 printf("Found new boundary\n");
1383 sLt[lttcFlag] = snext;
1384 retStep = steptot; // ???
1385 for (i=0;i<3;i++) point[i]+=(snext+1E-6)*dir[i];
1387 gGeoManager->FindNode();
1388 if (gGeoManager->IsSameLocation()) {
1389 printf("Cannot cross boundary\n");
1392 newReg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1393 newLttc = (gGeoManager->IsOutside())?999999999:gGeoManager->GetCurrentNodeId()+1;
1394 if (mcgeom->IsDebugging()) printf("Found newreg=%i, newLttc=%i, lttFlag is: %i\n", newReg, newLttc, lttcFlag);
1395 sLt[lttcFlag-1] += snext; // correct step in old region
1396 sLt[lttcFlag] = propStep-snext;
1397 jrLt[lttcFlag] = newLttc;
1398 sLt[lttcFlag+1] = 0.;
1399 jrLt[lttcFlag+1] = -1;
1400 if (newReg != oldReg) break; // lttcFlag=1
1403 if (mcgeom->IsDebugging()) printf("Not crossing next\n");
1406 sLt[lttcFlag] = retStep;
1407 sLt[lttcFlag+1] = 0.;
1408 jrLt[lttcFlag+1] = -1;
1414 if (mcgeom->IsDebugging()) {
1415 if (!gGeoManager->IsOutside()) {
1416 printf(" ENTERED region %i, newLttc=%i in: %s\n", newReg,newLttc,gGeoManager->GetPath());
1417 } else printf(" EXIT GEOMETRY: BLKHOLE reg=%i\n", newReg);
1420 // no boundary within proposed step
1424 if (mcgeom->IsDebugging()) printf("=> newReg=%i newLttc=%i lttcFlag=%i\n", newReg, newLttc, lttcFlag);
1425 mcgeom->SetNextRegion(newReg, newLttc);
1426 if (mcgeom->IsDebugging()) {
1427 printf("=> snext=%g safe=%g\n", snext, saf);
1428 for (Int_t i=0; i<lttcFlag+1; i++) printf(" jrLt[%i]=%i sLt[%i]=%g\n", i,jrLt[i],i,sLt[i]);
1430 if (newLttc!=oldLttc) {
1431 if (gGeoManager->IsOutside()) {
1432 gGeoManager->SetOutside(kFALSE);
1433 gGeoManager->CdTop();
1435 gGeoManager->CdNode(oldLttc-1);
1437 if (mcgeom->IsDebugging()) printf("<= G1WR (in: %s)\n", gGeoManager->GetPath());
1440 //_____________________________________________________________________________
1443 if (mcgeom->IsDebugging()) printf("========== Dummy G1RTWR\n");
1446 //_____________________________________________________________________________
1447 void conhwr(Int_t & /*intHist*/, Int_t * /*incrCount*/)
1449 if (mcgeom->IsDebugging()) printf("========== Dummy CONHWR\n");
1452 //_____________________________________________________________________________
1453 void inihwr(Int_t &intHist)
1455 if (mcgeom->IsDebugging()) printf("========== Inside INIHWR -> reinitializing history: %i\n", intHist);
1456 if (gGeoManager->IsOutside()) gGeoManager->CdTop();
1458 // printf("=== wrong history number\n");
1461 if (intHist==0) gGeoManager->CdTop();
1462 else gGeoManager->CdNode(intHist-1);
1463 if (mcgeom->IsDebugging()) {
1464 printf(" --- current path: %s\n", gGeoManager->GetPath());
1465 printf("<= INIHWR\n");
1469 //_____________________________________________________________________________
1470 void jomiwr(const Int_t & /*nge*/, const Int_t & /*lin*/, const Int_t & /*lou*/,
1473 // Geometry initialization wrapper called by FLUKAM. Provides to FLUKA the
1474 // number of regions (volumes in TGeo)
1475 // build application geometry
1476 if (mcgeom->IsDebugging()) printf("========== Inside JOMIWR\n");
1477 flukaReg = gGeoManager->GetListOfUVolumes()->GetEntriesFast();
1478 if (mcgeom->IsDebugging()) printf("<= JOMIWR: last region=%i\n", flukaReg);
1481 //_____________________________________________________________________________
1482 void lkdbwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1483 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1484 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1486 if (mcgeom->IsDebugging()) {
1487 printf("========== Inside LKDBWR (%f, %f, %f)\n",pSx, pSy, pSz);
1488 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1489 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1491 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1492 if (gGeoManager->IsOutside()) {
1493 newReg = mcgeom->NofVolumes()+1;
1494 // newLttc = gGeoManager->GetCurrentNodeId();
1495 newLttc = 999999999;
1496 if (mcgeom->IsDebugging()) {
1497 printf("OUTSIDE\n");
1498 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1499 printf("<= LKMGWR\n");
1504 newReg = node->GetVolume()->GetNumber();
1505 newLttc = gGeoManager->GetCurrentNodeId()+1;
1507 if (mcgeom->IsDebugging()) {
1508 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1509 printf("<= LKDBWR\n");
1513 //_____________________________________________________________________________
1514 void lkfxwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1515 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1516 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1518 if (mcgeom->IsDebugging()) {
1519 printf("========== Inside LKFXWR (%f, %f, %f)\n",pSx, pSy, pSz);
1520 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1521 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1523 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1524 if (gGeoManager->IsOutside()) {
1525 newReg = mcgeom->NofVolumes()+1;
1526 // newLttc = gGeoManager->GetCurrentNodeId();
1527 newLttc = 999999999;
1528 if (mcgeom->IsDebugging()) {
1529 printf("OUTSIDE\n");
1530 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1531 printf("<= LKMGWR\n");
1536 newReg = node->GetVolume()->GetNumber();
1537 newLttc = gGeoManager->GetCurrentNodeId()+1;
1539 if (mcgeom->IsDebugging()) {
1540 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1541 printf("<= LKFXWR\n");
1545 //_____________________________________________________________________________
1546 void lkmgwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1547 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1548 Int_t &flagErr, Int_t &newReg, Int_t &newLttc)
1550 if (mcgeom->IsDebugging()) {
1551 printf("========== Inside LKMGWR (%f, %f, %f)\n",pSx, pSy, pSz);
1552 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1553 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1555 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1556 if (gGeoManager->IsOutside()) {
1557 newReg = mcgeom->NofVolumes()+1;
1558 // newLttc = gGeoManager->GetCurrentNodeId();
1559 newLttc = 999999999;
1560 if (mcgeom->IsDebugging()) {
1561 printf("OUTSIDE\n");
1562 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1563 printf("<= LKMGWR\n");
1568 newReg = node->GetVolume()->GetNumber();
1569 newLttc = gGeoManager->GetCurrentNodeId()+1;
1571 if (mcgeom->IsDebugging()) {
1572 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1573 printf("<= LKMGWR\n");
1577 //_____________________________________________________________________________
1578 void lkwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1579 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1580 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1582 if (mcgeom->IsDebugging()) {
1583 printf("========== Inside LKWR (%f, %f, %f)\n",pSx, pSy, pSz);
1584 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1585 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1587 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1588 if (gGeoManager->IsOutside()) {
1589 newReg = mcgeom->NofVolumes()+1;
1590 // newLttc = gGeoManager->GetCurrentNodeId();
1591 newLttc = 999999999;
1592 if (mcgeom->IsDebugging()) {
1593 printf("OUTSIDE\n");
1594 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1595 printf("<= LKMGWR\n");
1600 newReg = node->GetVolume()->GetNumber();
1601 newLttc = gGeoManager->GetCurrentNodeId()+1;
1603 if (mcgeom->IsDebugging()) {
1604 printf(" out: newReg=%i newLttc=%i in %s\n", newReg, newLttc, gGeoManager->GetPath());
1605 printf("<= LKWR\n");
1609 //_____________________________________________________________________________
1610 void nrmlwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1611 Double_t &pVx, Double_t &pVy, Double_t &pVz,
1612 Double_t *norml, const Int_t &oldReg,
1613 const Int_t &newReg, Int_t &flagErr)
1615 if (mcgeom->IsDebugging()) {
1616 printf("========== Inside NRMLWR (%g, %g, %g, %g, %g, %g)\n", pSx,pSy,pSz,pVx,pVy,pVz);
1617 printf(" oldReg=%i, newReg=%i\n", oldReg,newReg);
1619 Int_t curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1620 Int_t curLttc = gGeoManager->GetCurrentNodeId()+1;
1621 if (mcgeom->IsDebugging()) printf(" curReg=%i, curLttc=%i in: %s\n", curreg, curLttc, gGeoManager->GetPath());
1622 Bool_t regsame = (curreg==oldReg)?kTRUE:kFALSE;
1623 gGeoManager->SetCurrentPoint(pSx, pSy, pSz);
1624 gGeoManager->SetCurrentDirection(pVx,pVy,pVz);
1626 if (mcgeom->IsDebugging()) printf(" REGIONS DOEN NOT MATCH\n");
1627 gGeoManager->FindNode();
1628 curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1629 curLttc = gGeoManager->GetCurrentNodeId()+1;
1630 if (mcgeom->IsDebugging()) printf(" re-initialized point: curReg=%i curLttc=%i curPath=%s\n", curreg, curLttc, gGeoManager->GetPath());
1632 Double_t *dnorm = gGeoManager->FindNormalFast();
1635 printf(" ERROR: Cannot compute fast normal\n");
1641 norml[0] = -dnorm[0];
1642 norml[1] = -dnorm[1];
1643 norml[2] = -dnorm[2];
1644 if (mcgeom->IsDebugging()) printf(" normal to boundary: (%g, %g, %g)\n", norml[0], norml[1], norml[2]);
1645 curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1646 curLttc = gGeoManager->GetCurrentNodeId()+1;
1647 if (mcgeom->IsDebugging()) {
1648 printf(" final location: curReg=%i, curLttc=%i in %s\n", curreg,curLttc,gGeoManager->GetPath());
1649 printf("<= NRMLWR\n");
1653 //_____________________________________________________________________________
1654 void rgrpwr(const Int_t & /*flukaReg*/, const Int_t & /*ptrLttc*/, Int_t & /*g4Reg*/,
1655 Int_t * /*indMother*/, Int_t * /*repMother*/, Int_t & /*depthFluka*/)
1657 if (mcgeom->IsDebugging()) printf("=> Dummy RGRPWR\n");
1660 //_____________________________________________________________________________
1661 Int_t isvhwr(const Int_t &check, const Int_t & intHist)
1664 // Wrapper for saving current navigation history (fCheck=default)
1665 // and returning its pointer. If fCheck=-1 copy of history pointed
1666 // by intHist is made in NavHistWithCount object, and its pointer
1667 // is returned. fCheck=1 and fCheck=2 cases are only in debugging
1668 // version: an array is created by means of FGeometryInit functions
1669 // (but could be a static int * ptrArray = new int[10000] with
1670 // file scope as well) that stores a flag for deleted/undeleted
1671 // histories and at the end of event is checked to verify that
1672 // all saved history objects have been deleted.
1674 // For TGeo, just return the current node ID. No copy need to be made.
1676 if (mcgeom->IsDebugging()) printf("=> Inside ISVHWR\n");
1677 if (check<0) return intHist;
1678 Int_t histInt = gGeoManager->GetCurrentNodeId()+1;
1679 if (mcgeom->IsDebugging()) printf("<= ISVHWR: history is: %i in: %s\n", histInt, gGeoManager->GetPath());