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
106 fluka = (TFluka*)gMC;
110 //_____________________________________________________________________________
111 TFlukaMCGeometry::TFlukaMCGeometry()
112 : TVirtualMCGeometry()
115 // Default constructor
118 fluka = (TFluka*)gMC;
122 //_____________________________________________________________________________
123 TFlukaMCGeometry::~TFlukaMCGeometry()
129 if (gGeoManager) delete gGeoManager;
135 //_____________________________________________________________________________
136 TFlukaMCGeometry::TFlukaMCGeometry(const TFlukaMCGeometry &)
137 : TVirtualMCGeometry()
144 //_____________________________________________________________________________
145 Double_t* TFlukaMCGeometry::CreateDoubleArray(Float_t* array, Int_t size) const
147 // Converts Float_t* array to Double_t*,
148 // !! The new array has to be deleted by user.
151 Double_t* doubleArray;
153 doubleArray = new Double_t[size];
154 for (Int_t i=0; i<size; i++) doubleArray[i] = array[i];
158 doubleArray = new Double_t[1];
164 //_____________________________________________________________________________
165 void TFlukaMCGeometry::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,
166 Float_t &dens, Float_t &radl, Float_t &absl,
167 Float_t* /*ubuf*/, Int_t& /*nbuf*/)
169 printf("Gfmate %i\n", imat);
171 TIter next (gGeoManager->GetListOfMaterials());
172 while ((mat = (TGeoMaterial*)next())) {
173 if (mat->GetUniqueID() == (UInt_t)imat) break;
176 Error("Gfmate", "no material with index %i found", imat);
179 sprintf(name, "%s", mat->GetName());
182 dens = mat->GetDensity();
183 radl = mat->GetRadLen();
184 absl = mat->GetIntLen();
185 printf(" ->material found : %s a=%g, z=%g, dens=%g, radl=%g, absl=%g\n", name, a,z,dens,radl,absl);
188 //_____________________________________________________________________________
189 void TFlukaMCGeometry::Gfmate(Int_t imat, char *name, Double_t &a, Double_t &z,
190 Double_t &dens, Double_t &radl, Double_t &absl,
191 Double_t* /*ubuf*/, Int_t& /*nbuf*/)
193 printf("Gfmate %i\n", imat);
195 TIter next (gGeoManager->GetListOfMaterials());
196 while ((mat = (TGeoMaterial*)next())) {
197 if (mat->GetUniqueID() == (UInt_t)imat) break;
200 Error("Gfmate", "no material with index %i found", imat);
203 sprintf(name, "%s", mat->GetName());
206 dens = mat->GetDensity();
207 radl = mat->GetRadLen();
208 absl = mat->GetIntLen();
209 printf(" ->material found : %s a=%g, z=%g, dens=%g, radl=%g, absl=%g\n", name, a,z,dens,radl,absl);
212 //_____________________________________________________________________________
213 void TFlukaMCGeometry::Material(Int_t& kmat, const char* name, Double_t a, Double_t z,
214 Double_t dens, Double_t radl, Double_t absl, Float_t* buf,
218 // Defines a Material
220 // kmat number assigned to the material
221 // name material name
222 // a atomic mass in au
224 // dens density in g/cm3
225 // absl absorbtion length in cm
226 // if >=0 it is ignored and the program
227 // calculates it, if <0. -absl is taken
228 // radl radiation length in cm
229 // if >=0 it is ignored and the program
230 // calculates it, if <0. -radl is taken
231 // buf pointer to an array of user words
232 // nbuf number of user words
235 Double_t* dbuf = CreateDoubleArray(buf, nwbuf);
236 Material(kmat, name, a, z, dens, radl, absl, dbuf, nwbuf);
240 //_____________________________________________________________________________
241 void TFlukaMCGeometry::Material(Int_t& kmat, const char* name, Double_t a, Double_t z,
242 Double_t dens, Double_t radl, Double_t absl, Double_t* /*buf*/,
246 // Defines a Material
248 // kmat number assigned to the material
249 // name material name
250 // a atomic mass in au
252 // dens density in g/cm3
253 // absl absorbtion length in cm
254 // if >=0 it is ignored and the program
255 // calculates it, if <0. -absl is taken
256 // radl radiation length in cm
257 // if >=0 it is ignored and the program
258 // calculates it, if <0. -radl is taken
259 // buf pointer to an array of user words
260 // nbuf number of user words
263 kmat = gGeoManager->GetListOfMaterials()->GetSize();
264 gGeoManager->Material(name, a, z, dens, kmat, radl, absl);
265 printf("Material %s: kmat=%i, a=%g, z=%g, dens=%g\n", name, kmat, a, z, dens);
268 //_____________________________________________________________________________
269 void TFlukaMCGeometry::Mixture(Int_t& kmat, const char* name, Float_t* a, Float_t* z,
270 Double_t dens, Int_t nlmat, Float_t* wmat)
273 // Defines mixture OR COMPOUND IMAT as composed by
274 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
276 // If NLMAT > 0 then wmat contains the proportion by
277 // weights of each basic material in the mixture.
279 // If nlmat < 0 then WMAT contains the number of atoms
280 // of a given kind into the molecule of the COMPOUND
281 // In this case, WMAT in output is changed to relative
285 Double_t* da = CreateDoubleArray(a, TMath::Abs(nlmat));
286 Double_t* dz = CreateDoubleArray(z, TMath::Abs(nlmat));
287 Double_t* dwmat = CreateDoubleArray(wmat, TMath::Abs(nlmat));
289 Mixture(kmat, name, da, dz, dens, nlmat, dwmat);
290 for (Int_t i=0; i<nlmat; i++) {
291 a[i] = da[i]; z[i] = dz[i]; wmat[i] = dwmat[i];
299 //_____________________________________________________________________________
300 void TFlukaMCGeometry::Mixture(Int_t& kmat, const char* name, Double_t* a, Double_t* z,
301 Double_t dens, Int_t nlmat, Double_t* wmat)
304 // Defines mixture OR COMPOUND IMAT as composed by
305 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
307 // If NLMAT > 0 then wmat contains the proportion by
308 // weights of each basic material in the mixture.
310 // If nlmat < 0 then WMAT contains the number of atoms
311 // of a given kind into the molecule of the COMPOUND
312 // In this case, WMAT in output is changed to relative
320 for (i=0;i<nlmat;i++) {
321 amol += a[i]*wmat[i];
323 for (i=0;i<nlmat;i++) {
324 wmat[i] *= a[i]/amol;
327 kmat = gGeoManager->GetListOfMaterials()->GetSize();
328 printf("Mixture %s with %i elem: kmat=%i, dens=%g\n", name, nlmat, kmat, dens);
329 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]);
330 gGeoManager->Mixture(name, a, z, dens, nlmat, wmat, kmat);
332 //_____________________________________________________________________________
333 Int_t TFlukaMCGeometry::GetMedium() const
335 // Get current medium number
337 TGeoNode *node = gGeoManager->GetCurrentNode();
338 if (!node) imed = gGeoManager->GetTopNode()->GetVolume()->GetMedium()->GetId();
339 else imed = node->GetVolume()->GetMedium()->GetId();
340 printf("GetMedium=%i\n", imed);
344 //_____________________________________________________________________________
345 void TFlukaMCGeometry::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
346 Int_t ifield, Double_t fieldm, Double_t tmaxfd,
347 Double_t stemax, Double_t deemax, Double_t epsil,
348 Double_t stmin, Float_t* ubuf, Int_t nbuf)
351 // kmed tracking medium number assigned
352 // name tracking medium name
353 // nmat material number
354 // isvol sensitive volume flag
355 // ifield magnetic field
356 // fieldm max. field value (kilogauss)
357 // tmaxfd max. angle due to field (deg/step)
358 // stemax max. step allowed
359 // deemax max. fraction of energy lost in a step
360 // epsil tracking precision (cm)
361 // stmin min. step due to continuous processes (cm)
363 // ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
364 // ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
365 // performed with g3helix; ifield = 3 if tracking performed with g3helx3.
368 //printf("Creating mediuma: %s, numed=%d, nmat=%d\n",name,kmed,nmat);
369 Double_t* dubuf = CreateDoubleArray(ubuf, nbuf);
370 Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
375 //_____________________________________________________________________________
376 void TFlukaMCGeometry::Medium(Int_t& kmed, const char* name, Int_t nmat, Int_t isvol,
377 Int_t ifield, Double_t fieldm, Double_t tmaxfd,
378 Double_t stemax, Double_t deemax, Double_t epsil,
379 Double_t stmin, Double_t* /*ubuf*/, Int_t /*nbuf*/)
382 // kmed tracking medium number assigned
383 // name tracking medium name
384 // nmat material number
385 // isvol sensitive volume flag
386 // ifield magnetic field
387 // fieldm max. field value (kilogauss)
388 // tmaxfd max. angle due to field (deg/step)
389 // stemax max. step allowed
390 // deemax max. fraction of energy lost in a step
391 // epsil tracking precision (cm)
392 // stmin min. step due to continuos processes (cm)
394 // ifield = 0 if no magnetic field; ifield = -1 if user decision in guswim;
395 // ifield = 1 if tracking performed with g3rkuta; ifield = 2 if tracking
396 // performed with g3helix; ifield = 3 if tracking performed with g3helx3.
399 kmed = gGeoManager->GetListOfMedia()->GetSize()+3; // !!! in FLUKA they start with 3
400 gGeoManager->Medium(name,kmed,nmat, isvol, ifield, fieldm, tmaxfd, stemax,deemax, epsil, stmin);
401 printf("Medium %s: kmed=%i, nmat=%i, isvol=%i\n", name, kmed, nmat,isvol);
404 //_____________________________________________________________________________
405 void TFlukaMCGeometry::Matrix(Int_t& krot, Double_t thex, Double_t phix, Double_t they,
406 Double_t phiy, Double_t thez, Double_t phiz)
409 // krot rotation matrix number assigned
410 // theta1 polar angle for axis i
411 // phi1 azimuthal angle for axis i
412 // theta2 polar angle for axis ii
413 // phi2 azimuthal angle for axis ii
414 // theta3 polar angle for axis iii
415 // phi3 azimuthal angle for axis iii
417 // it defines the rotation matrix number irot.
420 krot = gGeoManager->GetListOfMatrices()->GetEntriesFast();
421 gGeoManager->Matrix(krot, thex, phix, they, phiy, thez, phiz);
422 printf("Rotation %i defined\n", krot);
425 //_____________________________________________________________________________
426 Int_t TFlukaMCGeometry::Gsvolu(const char *name, const char *shape, Int_t nmed,
427 Float_t *upar, Int_t npar)
432 // NUMED Tracking medium number
433 // NPAR Number of shape parameters
434 // UPAR Vector containing shape parameters
436 // It creates a new volume in the JVOLUM data structure.
439 Double_t* dupar = CreateDoubleArray(upar, npar);
440 Int_t id = Gsvolu(name, shape, nmed, dupar, npar);
445 //_____________________________________________________________________________
446 Int_t TFlukaMCGeometry::Gsvolu(const char *name, const char *shape, Int_t nmed,
447 Double_t *upar, Int_t npar)
452 // NUMED Tracking medium number
453 // NPAR Number of shape parameters
454 // UPAR Vector containing shape parameters
456 // It creates a new volume in the JVOLUM data structure.
463 TGeoVolume* vol = gGeoManager->Volume(vname, shape, nmed, upar, npar);
464 printf("Volume %s: id=%i shape=%s, nmed=%i\n", vname, vol->GetNumber(), shape, nmed);
465 return vol->GetNumber();
468 //_____________________________________________________________________________
469 void TFlukaMCGeometry::Gsdvn(const char *name, const char *mother, Int_t ndiv,
473 // Create a new volume by dividing an existing one
476 // MOTHER Mother volume name
477 // NDIV Number of divisions
480 // X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
481 // It divides a previously defined volume.
486 Vname(mother,vmother);
488 gGeoManager->Division(vname, vmother, iaxis, ndiv, 0, 0, 0, "n");
489 printf("Division %s: mother=%s iaxis=%i ndiv=%i\n", vname, vmother, iaxis, ndiv);
492 //_____________________________________________________________________________
493 void TFlukaMCGeometry::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
494 Int_t iaxis, Double_t c0i, Int_t numed)
497 // Create a new volume by dividing an existing one
499 // Divides mother into ndiv divisions called name
500 // along axis iaxis starting at coordinate value c0.
501 // the new volume created will be medium number numed.
506 Vname(mother,vmother);
508 gGeoManager->Division(vname, vmother, iaxis, ndiv, c0i, 0, numed, "nx");
510 //_____________________________________________________________________________
511 void TFlukaMCGeometry::Gsdvt(const char *name, const char *mother, Double_t step,
512 Int_t iaxis, Int_t numed, Int_t /*ndvmx*/)
515 // Create a new volume by dividing an existing one
517 // Divides MOTHER into divisions called NAME along
518 // axis IAXIS in steps of STEP. If not exactly divisible
519 // will make as many as possible and will centre them
520 // with respect to the mother. Divisions will have medium
521 // number NUMED. If NUMED is 0, NUMED of MOTHER is taken.
522 // NDVMX is the expected maximum number of divisions
523 // (If 0, no protection tests are performed)
528 Vname(mother,vmother);
530 gGeoManager->Division(vname, vmother, iaxis, 0, 0, step, numed, "s");
533 //_____________________________________________________________________________
534 void TFlukaMCGeometry::Gsdvt2(const char *name, const char *mother, Double_t step,
535 Int_t iaxis, Double_t c0, Int_t numed, Int_t /*ndvmx*/)
538 // Create a new volume by dividing an existing one
540 // Divides MOTHER into divisions called NAME along
541 // axis IAXIS starting at coordinate value C0 with step
543 // The new volume created will have medium number NUMED.
544 // If NUMED is 0, NUMED of mother is taken.
545 // NDVMX is the expected maximum number of divisions
546 // (If 0, no protection tests are performed)
551 Vname(mother,vmother);
553 gGeoManager->Division(vname, vmother, iaxis, 0, c0, step, numed, "sx");
556 //_____________________________________________________________________________
557 void TFlukaMCGeometry::Gsord(const char * /*name*/, Int_t /*iax*/)
560 // Flags volume CHNAME whose contents will have to be ordered
561 // along axis IAX, by setting the search flag to -IAX
565 // IAX = 4 Rxy (static ordering only -> GTMEDI)
566 // IAX = 14 Rxy (also dynamic ordering -> GTNEXT)
567 // IAX = 5 Rxyz (static ordering only -> GTMEDI)
568 // IAX = 15 Rxyz (also dynamic ordering -> GTNEXT)
569 // IAX = 6 PHI (PHI=0 => X axis)
570 // IAX = 7 THETA (THETA=0 => Z axis)
573 // TBC - keep this function
574 // nothing to be done for TGeo //xx
577 //_____________________________________________________________________________
578 void TFlukaMCGeometry::Gspos(const char *name, Int_t nr, const char *mother, Double_t x,
579 Double_t y, Double_t z, Int_t irot, const char *konly)
582 // Position a volume into an existing one
585 // NUMBER Copy number of the volume
586 // MOTHER Mother volume name
587 // X X coord. of the volume in mother ref. sys.
588 // Y Y coord. of the volume in mother ref. sys.
589 // Z Z coord. of the volume in mother ref. sys.
590 // IROT Rotation matrix number w.r.t. mother ref. sys.
591 // ONLY ONLY/MANY flag
593 // It positions a previously defined volume in the mother.
596 TString only = konly;
598 Bool_t isOnly = kFALSE;
599 if (only.Contains("only")) isOnly = kTRUE;
603 Vname(mother,vmother);
606 gGeoManager->Node(vname, nr, vmother, x, y, z, irot, isOnly, upar);
607 printf("Adding daughter %s to %s: cpy=%i irot=%i only=%s\n", vname,vmother,nr,irot,only.Data());
610 //_____________________________________________________________________________
611 void TFlukaMCGeometry::Gsposp(const char *name, Int_t nr, const char *mother,
612 Double_t x, Double_t y, Double_t z, Int_t irot,
613 const char *konly, Float_t *upar, Int_t np )
616 // Place a copy of generic volume NAME with user number
617 // NR inside MOTHER, with its parameters UPAR(1..NP)
620 Double_t* dupar = CreateDoubleArray(upar, np);
621 Gsposp(name, nr, mother, x, y, z, irot, konly, dupar, np);
625 //_____________________________________________________________________________
626 void TFlukaMCGeometry::Gsposp(const char *name, Int_t nr, const char *mother,
627 Double_t x, Double_t y, Double_t z, Int_t irot,
628 const char *konly, Double_t *upar, Int_t np )
631 // Place a copy of generic volume NAME with user number
632 // NR inside MOTHER, with its parameters UPAR(1..NP)
635 TString only = konly;
637 Bool_t isOnly = kFALSE;
638 if (only.Contains("only")) isOnly = kTRUE;
642 Vname(mother,vmother);
644 gGeoManager->Node(vname,nr,vmother, x,y,z,irot,isOnly,upar,np);
645 printf("Adding daughter(s) %s to %s: cpy=%i irot=%i only=%s\n", vname,vmother,nr,irot,only.Data());
648 //_____________________________________________________________________________
649 Int_t TFlukaMCGeometry::VolId(const Text_t *name) const
652 // Return the unique numeric identifier for volume name
655 Int_t uid = gGeoManager->GetUID(name);
657 printf("VolId: Volume %s not found\n",name);
660 printf("VolId for %s: %i\n", name, uid);
664 //_____________________________________________________________________________
665 const char* TFlukaMCGeometry::VolName(Int_t id) const
668 // Return the volume name given the volume identifier
670 TGeoVolume *volume = gGeoManager->GetVolume(id);
672 Error("VolName","volume with id=%d does not exist",id);
675 printf("VolName for id=%i: %s\n", id, volume->GetName());
676 return volume->GetName();
679 //_____________________________________________________________________________
680 Int_t TFlukaMCGeometry::NofVolumes() const
683 // Return total number of volumes in the geometry
686 return gGeoManager->GetListOfUVolumes()->GetEntriesFast()-1;
689 //_____________________________________________________________________________
690 Int_t TFlukaMCGeometry::VolId2Mate(Int_t id) const
693 // Return material number for a given volume id
695 TGeoVolume *volume = gGeoManager->GetVolume(id);
697 Error("VolId2Mate","volume with id=%d does not exist",id);
700 TGeoMedium *med = volume->GetMedium();
702 printf("VolId2Mate id=%i: idmed=%i\n", id, med->GetId());
706 //_____________________________________________________________________________
707 Int_t TFlukaMCGeometry::CurrentVolID(Int_t& copyNo) const
709 // Returns the current volume ID and copy number
710 if (gGeoManager->IsOutside()) return 0;
711 TGeoNode *node = gGeoManager->GetCurrentNode();
712 copyNo = node->GetNumber();
713 Int_t id = node->GetVolume()->GetNumber();
714 printf("CurrentVolId(cpy=%i) = %i\n", copyNo, id);
718 //_____________________________________________________________________________
719 Int_t TFlukaMCGeometry::CurrentVolOffID(Int_t off, Int_t& copyNo) const
721 // Return the current volume "off" upward in the geometrical tree
722 // ID and copy number
723 if (off<0 || off>gGeoManager->GetLevel()) return 0;
724 if (off==0) return CurrentVolID(copyNo);
725 TGeoNode *node = gGeoManager->GetMother(off);
727 copyNo = node->GetNumber();
728 printf("CurrentVolOffId(off=%i,cpy=%i) = %i\n", off,copyNo,node->GetVolume()->GetNumber() );
729 return node->GetVolume()->GetNumber();
733 //_____________________________________________________________________________
734 const char* TFlukaMCGeometry::CurrentVolName() const
737 // Returns the current volume name
739 if (gGeoManager->IsOutside()) return 0;
740 printf("CurrentVolName : %s\n", gGeoManager->GetCurrentVolume()->GetName());
741 return gGeoManager->GetCurrentVolume()->GetName();
743 //_____________________________________________________________________________
744 const char* TFlukaMCGeometry::CurrentVolOffName(Int_t off) const
747 // Return the current volume "off" upward in the geometrical tree
748 // ID, name and copy number
749 // if name=0 no name is returned
751 if (off<0 || off>gGeoManager->GetLevel()) return 0;
752 if (off==0) return CurrentVolName();
753 TGeoNode *node = gGeoManager->GetMother(off);
755 printf("CurrentVolOffName(off=%i) : %s\n", off,node->GetVolume()->GetName());
756 return node->GetVolume()->GetName();
759 //_____________________________________________________________________________
760 void TFlukaMCGeometry::Gsatt(const char *name, const char *att, Int_t val)
764 // IOPT Name of the attribute to be set
765 // IVAL Value to which the attribute is to be set
766 // see: TFluka::Gsatt
771 gGeoManager->SetVolumeAttribute(vname, vatt, val);
774 //_____________________________________________________________________________
775 void TFlukaMCGeometry::Gdtom(Float_t *xd, Float_t *xm, Int_t iflag)
778 // Computes coordinates XM (Master Reference System
779 // knowing the coordinates XD (Detector Ref System)
780 // The local reference system can be initialized by
781 // - the tracking routines and GDTOM used in GUSTEP
782 // - a call to GSCMED(NLEVEL,NAMES,NUMBER)
783 // (inverse routine is GMTOD)
785 // If IFLAG=1 convert coordinates
786 // IFLAG=2 convert direction cosinus
788 Double_t XM[3], XD[3];
790 for (i=0;i<3;i++) XD[i] = xd[i];
791 if (iflag == 1) gGeoManager->LocalToMaster(XD,XM);
792 else gGeoManager->LocalToMasterVect(XD,XM);
793 for (i=0;i<3;i++) xm[i]=XM[i];
796 //_____________________________________________________________________________
797 void TFlukaMCGeometry::Gdtom(Double_t *xd, Double_t *xm, Int_t iflag)
799 if (iflag == 1) gGeoManager->LocalToMaster(xd,xm);
800 else gGeoManager->LocalToMasterVect(xd,xm);
803 //_____________________________________________________________________________
804 void TFlukaMCGeometry::Gmtod(Float_t *xm, Float_t *xd, Int_t iflag)
807 // Computes coordinates XD (in DRS)
808 // from known coordinates XM in MRS
809 // The local reference system can be initialized by
810 // - the tracking routines and GMTOD used in GUSTEP
811 // - a call to GMEDIA(XM,NUMED,CHECK)
812 // - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
813 // (inverse routine is GDTOM)
815 // If IFLAG=1 convert coordinates
816 // IFLAG=2 convert direction cosinus
818 Double_t XM[3], XD[3];
820 for (i=0;i<3;i++) XM[i]=xm[i];
821 if (iflag == 1) gGeoManager->MasterToLocal(XM,XD);
822 else gGeoManager->MasterToLocalVect(XM,XD);
823 for (i=0;i<3;i++) xd[i] = XD[i];
826 //_____________________________________________________________________________
827 void TFlukaMCGeometry::Gmtod(Double_t *xm, Double_t *xd, Int_t iflag)
829 if (iflag == 1) gGeoManager->MasterToLocal(xm,xd);
830 else gGeoManager->MasterToLocalVect(xm,xd);
833 //_____________________________________________________________________________
834 void TFlukaMCGeometry::CreateFlukaMatFile(const char *fname)
836 // ==== from FLUGG ====
837 // NAMES OF ELEMENTS AND COMPOUNDS: the names must be written in upper case,
838 // according to the fluka standard. In addition,. they must be equal to the
839 // names of the fluka materials - see fluka manual - in order that the
840 // program load the right cross sections, and equal to the names included in
841 // the .pemf. Otherwise the user must define the LOW-MAT CARDS, and make his
842 // own .pemf, in order to get the right cross sections loaded in memory.
845 static char elNames[220] = {
846 // 1 ============================= 5 ==================================== 10 ===================================== 15 ===
847 'H','_','H','E','L','I','B','E','B','_','C','_','N','_','O','_','F','_','N','E','N','A','M','G','A','L','S','I','P','_',
848 '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',
849 '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',
850 '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',
851 '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',
852 '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',
853 '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',
854 'S','G','B','H','H','S','M','T','D','S'};
855 memset(zelem, 0, 128*sizeof(Int_t));
857 gGeoManager->Export("flgeom.root");
858 if (fname) sname = fname;
859 else sname = "flukaMat.inp";
861 out.open(sname.Data(), ios::out);
863 Fatal("CreateFlukaMatFile", "could not open file %s for writing", sname.Data());
866 PrintHeader(out, "MATERIALS AND COMPOUNDS");
867 PrintHeader(out, "MATERIALS");
868 TList *matlist = gGeoManager->GetListOfMaterials();
870 Int_t nmater = matlist->GetSize();
872 TObjArray *listfluka = new TObjArray(nmater+50);
873 TObjArray *listflukanames = new TObjArray(nmater+50);
874 TGeoMaterial *mat, *matorig;
875 TGeoMixture *mix = 0;
877 TObjString *objstr, *objstrother;
881 Double_t amat,zmat,rhomat;
882 Double_t zel, ael, wel, rho;
883 char elname[8] = {' ',' ','_', 'E','L','E','M','\0'};
885 Bool_t found = kFALSE;
887 printf("Creating materials and compounds\n");
888 for (i=0; i<nmater; i++) {
889 mat = (TGeoMaterial*)matlist->At(i);
890 if (mat->GetZ()<1E-1) {
891 mat->SetIndex(2); // vacuum, built-in inside FLUKA
894 // printf("material: %s index=%i: Z=%f A=%f rho=%f\n", mat->GetName(), mat->GetIndex(),mat->GetZ(),mat->GetA(),mat->GetDensity());
895 matorig = gGeoManager->FindDuplicateMaterial(mat);
897 idmat = matorig->GetIndex();
898 mat->SetIndex(idmat);
899 // printf(" -> found a duplicate: %s with index %i\n", matorig->GetName(), idmat);
902 // printf(" Adding to temp list with index %i\n", nfmater+3);
904 mat->SetIndex(nfmater+3);
906 objstr = new TObjString(mat->GetName());
907 listflukanames->Add(objstr);
909 // look if name is existing
911 matname = objstr->GetString();
912 ToFlukaString(matname);
913 objstr->SetString(matname.Data());
916 if (nfmater == 1) break;
917 for (j=0; j<nfmater-1; j++) {
918 objstrother = (TObjString*)listflukanames->At(j);
919 if (objstr->IsEqual(objstrother)) {
920 // we have to change the name
922 Error("CreateFlukaMatFile", "too many materials having same name");
926 k = matname.Index(" ");
929 sprintf(digit, "%d", nidmat);
932 sprintf(&digit[1], "%d", nidmat);
934 matname.Insert(k,digit);
936 objstr->SetString(matname.Data());
939 if (j == nfmater-2) {
945 // printf(" newmat name: %s\n", matname.Data());
947 // now we have unique materials with unique names in the lists
949 if (matorig && matorig->IsMixture()) {
950 // create dummy materials for elements
952 mix = (TGeoMixture*)matorig;
953 nelem = mix->GetNelements();
954 // printf(" material is a MIXTURE with %i elements:\n", nelem);
955 for (j=0; j<nelem; j++) {
957 zel = (mix->GetZmixt())[j];
958 ael = (mix->GetAmixt())[j];
959 // printf(" Zelem[%i] = %g\n",j,zel);
960 if ((zel-Int_t(zel))>0.01) {
962 for (Int_t imat=0; imat<nfmater; imat++) {
963 mat1 = (TGeoMaterial*)listfluka->At(imat);
964 if (TMath::Abs(mat1->GetZ()-zel)>1E-4) continue;
965 if (TMath::Abs(mat1->GetA()-ael)>1E-4) continue;
969 if (!found) Warning("CreateFlukaMatFile", "element with Z=%f\n", zel);
971 if (!zelem[Int_t(zel)] && !found) {
972 // write fluka element
973 memcpy(elname, &elNames[2*Int_t(zel-1)], 2);
974 zelem[Int_t(zel)] = 1;
975 mat = new TGeoMaterial(elname, ael, zel, rho);
976 mat->SetIndex(nfmater+3);
977 // printf(" element not in list: new material %s at index=%i, Z=%g, A=%g, dummyrho=%g\n",
978 // elname,nfmater+3,zel,ael,rho);
980 objstr = new TObjString(elname);
981 listflukanames->Add(objstr);
987 // now dump materials in the file
988 // printf("DUMPING %i materials\n", nfmater);
989 for (i=0; i<nfmater; i++) {
990 mat = (TGeoMaterial*)listfluka->At(i);
991 out << setw(10) << "MATERIAL ";
992 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
993 // matname = mat->GetName();
994 objstr = (TObjString*)listflukanames->At(i);
995 matname = objstr->GetString();
996 ToFlukaString(matname);
998 if (zmat-Int_t(zmat)>0.01) {
999 if (zmat-Int_t(zmat)>0.5) zmat = Int_t(zmat)+1.;
1000 else zmat = Int_t(zmat);
1003 rhomat = mat->GetDensity();
1004 // write material card
1005 if (mat->IsMixture()) {
1006 out << setw(10) << " ";
1007 out << setw(10) << " ";
1008 mix = (TGeoMixture*)mat;
1010 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << zmat;
1011 out << setw(10) << setprecision(3) << amat;
1013 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1014 out << setw(10) << setiosflags(ios::scientific) << setprecision(3) << rhomat;
1015 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1016 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(i+3);
1017 out << setw(10) << " ";
1018 out << setw(10) << " ";
1019 out << setw(8) << matname.Data() << endl;
1021 // write mixture header
1022 PrintHeader(out, "COMPOUNDS");
1024 TGeoMaterial *element;
1025 for (i=0; i<nfmater; i++) {
1026 mat = (TGeoMaterial*)listfluka->At(i);
1027 if (!mat->IsMixture()) continue;
1028 mix = (TGeoMixture*)mat;
1030 out << setw(10) << "COMPOUND ";
1031 nelem = mix->GetNelements();
1032 objstr = (TObjString*)listflukanames->At(i);
1033 matname = objstr->GetString();
1034 // printf("MIXTURE %s with index %i having %i elements\n", matname.Data(), mat->GetIndex(),nelem);
1035 for (j=0; j<nelem; j++) {
1036 // dump mixture cards
1037 // printf(" #elem %i: Z=%g, A=%g, W=%g\n", j, (mix->GetZmixt())[j],
1038 // (mix->GetAmixt())[j],(mix->GetWmixt())[j]);
1039 wel = (mix->GetWmixt())[j];
1040 zel = (mix->GetZmixt())[j];
1041 ael = (mix->GetAmixt())[j];
1042 if (zel-Int_t(zel)>0.01) {
1043 // loop the temporary list
1046 for (Int_t imat=0; imat<i; imat++) {
1047 mat1 = (TGeoMaterial*)listfluka->At(imat);
1048 if (TMath::Abs(mat1->GetZ()-zel)>1E-4) continue;
1049 if (TMath::Abs(mat1->GetA()-ael)>1E-4) continue;
1054 memcpy(elname, &elNames[2*Int_t(zel-1)], 2);
1055 element = (TGeoMaterial*)listfluka->FindObject(elname);
1058 Error("CreateFlukaMatFile", "Element Z=%g %s not found", zel, elname);
1061 idmat = element->GetIndex();
1062 // printf("element %s , index=%i\n", element->GetName(), idmat);
1063 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1064 out << setw(10) << setiosflags(ios::fixed) << setprecision(6) << -wel;
1065 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1066 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(idmat);
1068 if (counttothree == 3) {
1069 out << matname.Data();
1071 if ( (j+1) != nelem) out << setw(10) << "COMPOUND ";
1075 //Unless we have 3, 6, 9... submaterials we need to put some empty
1076 //space and the compound name
1078 for (j=0; j<(3-(nelem%3)); j++)
1079 out << setw(10) << " " << setw(10) << " ";
1080 out << matname.Data();
1085 // Now print the list of regions (volumes in TGeo)
1086 Int_t nvols = gGeoManager->GetListOfUVolumes()->GetEntriesFast()-1;
1089 PrintHeader(out, "TGEO VOLUMES");
1090 for (i=1; i<=nvols; i++) {
1091 vol = gGeoManager->GetVolume(i);
1092 out.setf(std::ios::left, std::ios::adjustfield);
1093 out << setw(10) << i;
1094 out << setw(20) << vol->GetName() << endl;
1097 // Now print the material assignments
1099 PrintHeader(out, "TGEO MATERIAL ASSIGNMENTS");
1100 for (i=1; i<=nvols; i++) {
1101 vol = gGeoManager->GetVolume(i);
1102 mat = vol->GetMedium()->GetMaterial();
1103 idmat = mat->GetIndex();
1104 // flagfield = (vol->GetField())?1.:0.;
1106 out << setw(10) << "ASSIGNMAT ";
1107 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
1108 out << setw(10) << setiosflags(ios::fixed) << Double_t(idmat);
1109 out << setw(10) << setiosflags(ios::fixed) << Double_t(i);
1110 out << setw(10) << "0.0";
1111 out << setw(10) << "0.0";
1112 out << setw(10) << setiosflags(ios::fixed) << flagfield;
1113 out << setw(10) << "0.0";
1117 listflukanames->Delete();
1118 delete listflukanames;
1120 fLastMaterial = nfmater+2;
1123 //_____________________________________________________________________________
1124 void TFlukaMCGeometry::PrintHeader(ofstream &out, const char *text) const
1126 // Print a FLUKA header.
1127 out << "*\n" << "*\n" << "*\n";
1128 out << "********************* " << text << " *********************\n"
1130 out << "*...+....1....+....2....+....3....+....4....+....5....+....6....+....7..."
1135 //_____________________________________________________________________________
1136 Int_t TFlukaMCGeometry::RegionId() const
1138 // Returns current region id <-> TGeo node id
1139 if (gGeoManager->IsOutside()) return 0;
1140 return gGeoManager->GetCurrentNode()->GetUniqueID();
1143 //_____________________________________________________________________________
1144 void TFlukaMCGeometry::ToFlukaString(TString &str) const
1146 // ToFlukaString converts an string to something usefull in FLUKA:
1147 // * Capital letters
1149 // * Replace ' ' by '_'
1150 if (str.Length()<8) {
1155 for (ilast=7; ilast>0; ilast--) if (str(ilast)!=' ') break;
1157 for (Int_t pos=0; pos<ilast; pos++)
1158 if (str(pos)==' ') str.Replace(pos,1,"_",1);
1161 //______________________________________________________________________________
1162 void TFlukaMCGeometry::Vname(const char *name, char *vname) const
1165 // convert name to upper case. Make vname at least 4 chars
1167 Int_t l = strlen(name);
1170 for (i=0;i<l;i++) vname[i] = toupper(name[i]);
1171 for (i=l;i<4;i++) vname[i] = ' ';
1176 // FLUKA GEOMETRY WRAPPERS - to replace FLUGG wrappers
1178 //_____________________________________________________________________________
1179 Int_t idnrwr(const Int_t & /*nreg*/, const Int_t & /*mlat*/)
1182 // Wrapper for setting DNEAR option on fluka side. Must return 0
1183 // if user doesn't want Fluka to use DNEAR to compute the
1184 // step (the same effect is obtained with the GLOBAL (WHAT(3)=-1)
1185 // card in fluka input), returns 1 if user wants Fluka always to
1186 // use DNEAR (in this case, be sure that GEANT4 DNEAR is unique,
1187 // coming from all directions!!!)
1188 printf("========== Dummy IDNRWR\n");
1192 //_____________________________________________________________________________
1193 void g1wr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1194 Double_t *pV, Int_t &oldReg , const Int_t &oldLttc, Double_t & propStep,
1195 Int_t & /*nascFlag*/, Double_t &retStep, Int_t &newReg,
1196 Double_t &saf, Int_t &newLttc, Int_t <tcFlag,
1197 Double_t *sLt, Int_t *jrLt)
1200 // Wrapper for geometry tracking: returns approved step of
1201 // particle and all variables that fluka G1 computes.
1203 // Initialize current point/direction
1204 printf("========== Inside G1WR\n");
1205 printf(" point/dir:(%g, %g, %g, %g, %g, %g)\n", pSx,pSy,pSz,pV[0],pV[1],pV[2]);
1206 gGeoManager->SetCurrentPoint(pSx, pSy, pSz);
1207 gGeoManager->SetCurrentDirection(pV);
1208 printf(" oldReg=%i oldLttc=%i pstep=%f\n",oldReg, oldLttc, propStep);
1209 Int_t curLttc = gGeoManager->GetCurrentNodeId()+1;
1210 Int_t curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1211 printf(" curReg=%i curLttc=%i curPath=%s\n", curreg, curLttc, gGeoManager->GetPath());
1212 Bool_t regsame = (curreg==oldReg)?kTRUE:kFALSE;
1213 if (!regsame) printf(" REGIONS DOES NOT MATCH\n");
1214 if (oldLttc != curLttc) {
1215 printf(" HISTORIES DOES NOT MATCH\n");
1216 gGeoManager->CdNode(oldLttc-1);
1217 curLttc = gGeoManager->GetCurrentNodeId()+1;
1218 curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1219 printf(" re-initialized point: curReg=%i curLttc=%i curPath=%s\n", curreg, curLttc, gGeoManager->GetPath());
1223 jrLt[lttcFlag] = curLttc;
1224 // now 'oldregion' contains the real region, matching or not the old history
1226 // Compute geometry step/safety within physical step limit
1227 // newReg = oldregion;
1228 Double_t *point = gGeoManager->GetCurrentPoint();
1229 Double_t *dir = gGeoManager->GetCurrentDirection();
1230 Double_t steptot = 0.;
1231 Double_t snext = 0.;
1233 Bool_t done = kFALSE;
1236 gGeoManager->FindNextBoundary(-propStep);
1237 snext = gGeoManager->GetStep();
1238 printf(" FindNextBoundary(%g) snext=%g\n", propStep, snext);
1240 saf = gGeoManager->GetSafeDistance();
1241 printf(" Safety: %g\n", saf);
1243 sLt[lttcFlag] = propStep;
1244 jrLt[lttcFlag] = gGeoManager->GetCurrentNodeId()+1;
1248 if (snext<propStep) {
1249 // There is a boundary on the way.
1250 // Make a step=snext+1E-6 to force boundary crossing
1253 sLt[lttcFlag] = snext;
1256 // make the step to get into the next region
1257 for (i=0;i<3;i++) point[i]+=(snext+1E-6)*dir[i];
1258 gGeoManager->FindNode();
1260 printf(" boundary: step made %g\n", snext);
1261 while (gGeoManager->IsSameLocation() && steptot<propStep) {
1263 printf("Geometry error: could not cross boundary after extra 10 microns\n");
1266 for (i=0;i<3;i++) point[i]+=1E-6*dir[i];
1267 gGeoManager->FindNode();
1268 sLt[lttcFlag] += 1E-6;
1269 retStep = sLt[lttcFlag];
1274 if (steptot>propStep) {printf("Error\n");return;}
1275 // we managed to cross the boundary -> in which region
1276 newReg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1277 sLt[lttcFlag] = propStep-steptot;
1278 newLttc = (gGeoManager->IsOutside())?999999999:gGeoManager->GetCurrentNodeId()+1;
1279 jrLt[lttcFlag] = newLttc;
1280 if (!gGeoManager->IsOutside()) {
1282 printf(" ENTERED region %i, newLttc=%i in: %s\n", newReg,newLttc,gGeoManager->GetPath());
1283 } else printf(" EXIT GEOMETRY: BLKHOLE reg=%i\n", newReg);
1285 // no boundary within proposed step
1289 printf("=> newReg=%i newLttc=%i lttcFlag=%i\n", newReg, newLttc, lttcFlag);
1290 printf("=> snext=%g safe=%g\n", snext, saf);
1291 for (Int_t i=0; i<lttcFlag+1; i++) printf(" jrLt[%i]=%i sLt[%i]=%g\n", i,jrLt[i],i,sLt[i]);
1292 if (newLttc!=oldLttc) {
1293 if (gGeoManager->IsOutside()) {
1294 gGeoManager->SetOutside(kFALSE);
1295 gGeoManager->CdTop();
1297 gGeoManager->CdNode(oldLttc-1);
1299 printf("<= G1WR (in: %s)\n", gGeoManager->GetPath());
1302 //_____________________________________________________________________________
1305 printf("========== Dummy G1RTWR\n");
1308 //_____________________________________________________________________________
1309 void conhwr(Int_t & /*intHist*/, Int_t * /*incrCount*/)
1311 printf("========== Dummy CONHWR\n");
1314 //_____________________________________________________________________________
1315 void inihwr(Int_t &intHist)
1317 printf("========== Inside INIHWR -> reinitializing history: %i\n", intHist);
1318 if (gGeoManager->IsOutside()) gGeoManager->CdTop();
1320 // printf("=== wrong history number\n");
1323 if (intHist==0) gGeoManager->CdTop();
1324 else gGeoManager->CdNode(intHist-1);
1325 printf(" --- current path: %s\n", gGeoManager->GetPath());
1326 printf("<= INIHWR\n");
1329 //_____________________________________________________________________________
1330 void jomiwr(const Int_t & /*nge*/, const Int_t & /*lin*/, const Int_t & /*lou*/,
1333 // Geometry initialization wrapper called by FLUKAM. Provides to FLUKA the
1334 // number of regions (volumes in TGeo)
1335 // build application geometry
1336 printf("========== Inside JOMIWR\n");
1337 flukaReg = gGeoManager->GetListOfUVolumes()->GetEntriesFast();
1338 printf("<= JOMIWR: last region=%i\n", flukaReg);
1341 //_____________________________________________________________________________
1342 void lkdbwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1343 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1344 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1346 printf("========== Inside LKDBWR (%f, %f, %f)\n",pSx, pSy, pSz);
1347 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1348 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1349 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1350 if (gGeoManager->IsOutside()) {
1351 newReg = mcgeom->NofVolumes()+1;
1352 newLttc = gGeoManager->GetCurrentNodeId();
1354 newReg = node->GetVolume()->GetNumber();
1355 newLttc = gGeoManager->GetCurrentNodeId()+1;
1357 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1358 printf("<= LKDBWR\n");
1361 //_____________________________________________________________________________
1362 void lkfxwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1363 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1364 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1366 printf("========== Inside LKFXWR (%f, %f, %f)\n",pSx, pSy, pSz);
1367 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1368 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1369 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1370 if (gGeoManager->IsOutside()) {
1371 newReg = mcgeom->NofVolumes()+1;
1372 newLttc = gGeoManager->GetCurrentNodeId();
1374 newReg = node->GetVolume()->GetNumber();
1375 newLttc = gGeoManager->GetCurrentNodeId()+1;
1377 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1378 printf("<= LKFXWR\n");
1381 //_____________________________________________________________________________
1382 void lkmgwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1383 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1384 Int_t &flagErr, Int_t &newReg, Int_t &newLttc)
1386 printf("========== Inside LKMGWR (%f, %f, %f)\n",pSx, pSy, pSz);
1387 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1388 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1389 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1390 if (gGeoManager->IsOutside()) {
1391 newReg = mcgeom->NofVolumes()+1;
1392 newLttc = gGeoManager->GetCurrentNodeId();
1394 newReg = node->GetVolume()->GetNumber();
1395 newLttc = gGeoManager->GetCurrentNodeId()+1;
1397 printf(" out: newReg=%i newLttc=%i\n", newReg, newLttc);
1398 printf("<= LKMGWR\n");
1401 //_____________________________________________________________________________
1402 void lkwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1403 Double_t * /*pV*/, const Int_t &oldReg, const Int_t &oldLttc,
1404 Int_t &newReg, Int_t &flagErr, Int_t &newLttc)
1406 printf("========== Inside LKWR (%f, %f, %f)\n",pSx, pSy, pSz);
1407 // printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
1408 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1409 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1410 if (gGeoManager->IsOutside()) {
1411 newReg = mcgeom->NofVolumes()+1;
1412 newLttc = gGeoManager->GetCurrentNodeId();
1414 newReg = node->GetVolume()->GetNumber();
1415 newLttc = gGeoManager->GetCurrentNodeId()+1;
1417 printf(" out: newReg=%i newLttc=%i in %s\n", newReg, newLttc, gGeoManager->GetPath());
1418 printf("<= LKWR\n");
1421 //_____________________________________________________________________________
1422 void nrmlwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1423 Double_t &pVx, Double_t &pVy, Double_t &pVz,
1424 Double_t *norml, const Int_t &oldReg,
1425 const Int_t &newReg, Int_t &flagErr)
1427 printf("========== Inside NRMLWR (%g, %g, %g, %g, %g, %g)\n", pSx,pSy,pSz,pVx,pVy,pVz);
1428 printf(" oldReg=%i, newReg=%i\n", oldReg,newReg);
1429 Int_t curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1430 Int_t curLttc = gGeoManager->GetCurrentNodeId()+1;
1431 printf(" curReg=%i, curLttc=%i in: %s\n", curreg, curLttc, gGeoManager->GetPath());
1432 Bool_t regsame = (curreg==oldReg)?kTRUE:kFALSE;
1433 gGeoManager->SetCurrentPoint(pSx, pSy, pSz);
1434 gGeoManager->SetCurrentDirection(pVx,pVy,pVz);
1436 printf(" REGIONS DOEN NOT MATCH\n");
1437 gGeoManager->FindNode();
1438 curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1439 curLttc = gGeoManager->GetCurrentNodeId()+1;
1440 printf(" re-initialized point: curReg=%i curLttc=%i curPath=%s\n", curreg, curLttc, gGeoManager->GetPath());
1442 Double_t *dnorm = gGeoManager->FindNormalFast();
1445 printf(" ERROR: Cannot compute fast normal\n");
1451 norml[0] = -dnorm[0];
1452 norml[1] = -dnorm[1];
1453 norml[2] = -dnorm[2];
1454 printf(" normal to boundary: (%g, %g, %g)\n", norml[0], norml[1], norml[2]);
1455 curreg = (gGeoManager->IsOutside())?(mcgeom->NofVolumes()+1):gGeoManager->GetCurrentVolume()->GetNumber();
1456 curLttc = gGeoManager->GetCurrentNodeId()+1;
1457 printf(" final location: curReg=%i, curLttc=%i in %s\n", curreg,curLttc,gGeoManager->GetPath());
1458 printf("<= NRMLWR\n");
1461 //_____________________________________________________________________________
1462 void rgrpwr(const Int_t & /*flukaReg*/, const Int_t & /*ptrLttc*/, Int_t & /*g4Reg*/,
1463 Int_t * /*indMother*/, Int_t * /*repMother*/, Int_t & /*depthFluka*/)
1465 printf("=> Dummy RGRPWR\n");
1468 //_____________________________________________________________________________
1469 Int_t isvhwr(const Int_t &check, const Int_t & intHist)
1472 // Wrapper for saving current navigation history (fCheck=default)
1473 // and returning its pointer. If fCheck=-1 copy of history pointed
1474 // by intHist is made in NavHistWithCount object, and its pointer
1475 // is returned. fCheck=1 and fCheck=2 cases are only in debugging
1476 // version: an array is created by means of FGeometryInit functions
1477 // (but could be a static int * ptrArray = new int[10000] with
1478 // file scope as well) that stores a flag for deleted/undeleted
1479 // histories and at the end of event is checked to verify that
1480 // all saved history objects have been deleted.
1482 // For TGeo, just return the current node ID. No copy need to be made.
1484 printf("=> Inside ISVHWR\n");
1485 if (check<0) return intHist;
1486 Int_t histInt = gGeoManager->GetCurrentNodeId()+1;
1487 printf("<= ISVHWR: history is: %i in: %s\n", histInt, gGeoManager->GetPath());