1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 // Realisation of the TVirtualMC interface for the FLUKA code
20 // (See official web side http://www.fluka.org/).
22 // This implementation makes use of the TGeo geometry modeller.
23 // User configuration is via automatic generation of FLUKA input cards.
32 #include <Riostream.h>
36 #include "TFlukaCodes.h"
37 #include "TCallf77.h" //For the fortran calls
38 #include "Fdblprc.h" //(DBLPRC) fluka common
39 #include "Fsourcm.h" //(SOURCM) fluka common
40 #include "Fgenstk.h" //(GENSTK) fluka common
41 #include "Fiounit.h" //(IOUNIT) fluka common
42 #include "Fpaprop.h" //(PAPROP) fluka common
43 #include "Fpart.h" //(PART) fluka common
44 #include "Ftrackr.h" //(TRACKR) fluka common
45 #include "Fpaprop.h" //(PAPROP) fluka common
46 #include "Ffheavy.h" //(FHEAVY) fluka common
47 #include "Fopphst.h" //(OPPHST) fluka common
48 #include "Fflkstk.h" //(FLKSTK) fluka common
49 #include "Fstepsz.h" //(STEPSZ) fluka common
50 #include "Fopphst.h" //(OPPHST) fluka common
51 #include "Fltclcm.h" //(LTCLCM) fluka common
52 #include "Falldlt.h" //(ALLDLT) fluka common
54 #include "TVirtualMC.h"
55 #include "TMCProcess.h"
56 #include "TGeoManager.h"
57 #include "TGeoMaterial.h"
58 #include "TGeoMedium.h"
59 #include "TFlukaMCGeometry.h"
60 #include "TGeoMCGeometry.h"
61 #include "TFlukaCerenkov.h"
62 #include "TFlukaConfigOption.h"
63 #include "TFlukaScoringOption.h"
64 #include "TLorentzVector.h"
67 #include "TDatabasePDG.h"
68 #include "TStopwatch.h"
71 // Fluka methods that may be needed.
73 # define flukam flukam_
74 # define fluka_openinp fluka_openinp_
75 # define fluka_openout fluka_openout_
76 # define fluka_closeinp fluka_closeinp_
77 # define mcihad mcihad_
78 # define mpdgha mpdgha_
79 # define newplo newplo_
80 # define genout genout_
81 # define flkend flkend_
83 # define flukam FLUKAM
84 # define fluka_openinp FLUKA_OPENINP
85 # define fluka_openout FLUKA_OPENOUT
86 # define fluka_closeinp FLUKA_CLOSEINP
87 # define mcihad MCIHAD
88 # define mpdgha MPDGHA
89 # define newplo NEWPLO
90 # define genout GENOUT
91 # define flkend FLKEND
97 // Prototypes for FLUKA functions
99 void type_of_call flukam(const int&);
100 void type_of_call newplo();
101 void type_of_call genout();
102 void type_of_call flkend();
103 void type_of_call fluka_openinp(const int&, DEFCHARA);
104 void type_of_call fluka_openout(const int&, DEFCHARA);
105 void type_of_call fluka_closeinp(const int&);
106 int type_of_call mcihad(const int&);
107 int type_of_call mpdgha(const int&);
111 // Class implementation for ROOT
116 //----------------------------------------------------------------------------
117 // TFluka constructors and destructors.
118 //______________________________________________________________________________
124 fCoreInputFileName(""),
132 fTrackIsEntering(kFALSE),
133 fTrackIsExiting(kFALSE),
136 fDummyBoundary(kFALSE),
140 fPrimaryElectronIndex(-1),
143 fCurrentFlukaRegion(-1),
151 // Default constructor
153 for (Int_t i = 0; i < 4; i++) fPint[i] = 0.;
156 //______________________________________________________________________________
157 TFluka::TFluka(const char *title, Int_t verbosity, Bool_t isRootGeometrySupported)
158 :TVirtualMC("TFluka",title, isRootGeometrySupported),
159 fVerbosityLevel(verbosity),
162 fCoreInputFileName(""),
170 fTrackIsEntering(kFALSE),
171 fTrackIsExiting(kFALSE),
174 fDummyBoundary(kFALSE),
178 fPrimaryElectronIndex(-1),
181 fCurrentFlukaRegion(-1),
185 fUserConfig(new TObjArray(100)),
186 fUserScore(new TObjArray(100))
188 // create geometry interface
189 for (Int_t i = 0; i < 4; i++) fPint[i] = 0.;
191 if (fVerbosityLevel >=3)
192 cout << "<== TFluka::TFluka(" << title << ") constructor called." << endl;
193 SetCoreInputFileName();
195 fMCGeo = new TGeoMCGeometry("MCGeo", "TGeo Implementation of VirtualMCGeometry", kFALSE);
196 fGeom = new TFlukaMCGeometry("geom", "FLUKA VMC Geometry");
197 if (verbosity > 2) fGeom->SetDebugMode(kTRUE);
201 //______________________________________________________________________________
205 if (fVerbosityLevel >=3)
206 cout << "<== TFluka::~TFluka() destructor called." << endl;
207 if (fMaterials) delete [] fMaterials;
213 fUserConfig->Delete();
218 fUserScore->Delete();
224 //______________________________________________________________________________
225 // TFluka control methods
226 //______________________________________________________________________________
227 void TFluka::Init() {
229 // Geometry initialisation
231 if (fVerbosityLevel >=3) cout << "==> TFluka::Init() called." << endl;
233 if (!gGeoManager) new TGeoManager("geom", "FLUKA geometry");
234 fApplication->ConstructGeometry();
235 if (!gGeoManager->IsClosed()) {
236 TGeoVolume *top = (TGeoVolume*)gGeoManager->GetListOfVolumes()->First();
237 gGeoManager->SetTopVolume(top);
238 gGeoManager->CloseGeometry("di");
240 TGeoNodeCache *cache = gGeoManager->GetCache();
241 if (!cache->HasIdArray()) {
242 Warning("Init", "Node ID tracking must be enabled with TFluka: enabling...\n");
243 cache->BuildIdArray();
246 fNVolumes = fGeom->NofVolumes();
247 fGeom->CreateFlukaMatFile("flukaMat.inp");
248 if (fVerbosityLevel >=3) {
249 printf("== Number of volumes: %i\n ==", fNVolumes);
250 cout << "\t* InitPhysics() - Prepare input file to be called" << endl;
253 fApplication->InitGeometry();
254 fApplication->ConstructOpGeometry();
256 // Add ions to PDG Data base
258 AddParticlesToPdgDataBase();
263 //______________________________________________________________________________
264 void TFluka::FinishGeometry() {
266 // Build-up table with region to medium correspondance
268 if (fVerbosityLevel >=3) {
269 cout << "==> TFluka::FinishGeometry() called." << endl;
270 printf("----FinishGeometry - applying misalignment if any\n");
271 cout << "<== TFluka::FinishGeometry() called." << endl;
273 TVirtualMCApplication::Instance()->MisalignGeometry();
276 //______________________________________________________________________________
277 void TFluka::BuildPhysics() {
279 // Prepare FLUKA input files and call FLUKA physics initialisation
282 if (fVerbosityLevel >=3)
283 cout << "==> TFluka::BuildPhysics() called." << endl;
286 if (fVerbosityLevel >=3) {
287 TList *medlist = gGeoManager->GetListOfMedia();
289 TGeoMedium* med = 0x0;
290 TGeoMaterial* mat = 0x0;
293 while((med = (TGeoMedium*)next()))
295 mat = med->GetMaterial();
296 printf("Medium %5d %12s %5d %5d\n", ic, (med->GetName()), med->GetId(), mat->GetIndex());
302 // Prepare input file with the current physics settings
305 // Open fortran files
306 const char* fname = fInputFileName;
307 fluka_openinp(lunin, PASSCHARA(fname));
308 fluka_openout(11, PASSCHARA("fluka.out"));
310 cout << "==> TFluka::BuildPhysics() Read input cards." << endl;
313 GLOBAL.lfdrtr = true;
315 cout << "<== TFluka::BuildPhysics() Read input cards End"
316 << Form(" R:%.2fs C:%.2fs", timer.RealTime(),timer.CpuTime()) << endl;
318 fluka_closeinp(lunin);
323 //______________________________________________________________________________
324 void TFluka::ProcessEvent() {
329 Warning("ProcessEvent", "User Run Abortion: No more events handled !\n");
334 if (fVerbosityLevel >=3)
335 cout << "==> TFluka::ProcessEvent() called." << endl;
336 fApplication->GeneratePrimaries();
337 SOURCM.lsouit = true;
339 if (fVerbosityLevel >=3)
340 cout << "<== TFluka::ProcessEvent() called." << endl;
342 // Increase event number
347 //______________________________________________________________________________
348 Bool_t TFluka::ProcessRun(Int_t nevent) {
353 if (fVerbosityLevel >=3)
354 cout << "==> TFluka::ProcessRun(" << nevent << ") called."
357 if (fVerbosityLevel >=2) {
358 cout << "\t* GLOBAL.fdrtr = " << (GLOBAL.lfdrtr?'T':'F') << endl;
359 cout << "\t* Calling flukam again..." << endl;
362 Int_t todo = TMath::Abs(nevent);
363 for (Int_t ev = 0; ev < todo; ev++) {
366 fApplication->BeginEvent();
368 fApplication->FinishEvent();
369 cout << "Event: "<< ev
370 << Form(" R:%.2fs C:%.2fs", timer.RealTime(),timer.CpuTime()) << endl;
373 if (fVerbosityLevel >=3)
374 cout << "<== TFluka::ProcessRun(" << nevent << ") called."
377 // Write fluka specific scoring output
385 //_____________________________________________________________________________
386 // methods for building/management of geometry
388 // functions from GCONS
389 //____________________________________________________________________________
390 void TFluka::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,
391 Float_t &dens, Float_t &radl, Float_t &absl,
392 Float_t* /*ubuf*/, Int_t& /*nbuf*/) {
395 TIter next (gGeoManager->GetListOfMaterials());
396 while ((mat = (TGeoMaterial*)next())) {
397 if (mat->GetUniqueID() == (UInt_t)imat) break;
400 Error("Gfmate", "no material with index %i found", imat);
403 sprintf(name, "%s", mat->GetName());
406 dens = mat->GetDensity();
407 radl = mat->GetRadLen();
408 absl = mat->GetIntLen();
411 //______________________________________________________________________________
412 void TFluka::Gfmate(Int_t imat, char *name, Double_t &a, Double_t &z,
413 Double_t &dens, Double_t &radl, Double_t &absl,
414 Double_t* /*ubuf*/, Int_t& /*nbuf*/) {
417 TIter next (gGeoManager->GetListOfMaterials());
418 while ((mat = (TGeoMaterial*)next())) {
419 if (mat->GetUniqueID() == (UInt_t)imat) break;
422 Error("Gfmate", "no material with index %i found", imat);
425 sprintf(name, "%s", mat->GetName());
428 dens = mat->GetDensity();
429 radl = mat->GetRadLen();
430 absl = mat->GetIntLen();
433 // detector composition
434 //______________________________________________________________________________
435 void TFluka::Material(Int_t& kmat, const char* name, Double_t a,
436 Double_t z, Double_t dens, Double_t radl, Double_t absl,
437 Float_t* buf, Int_t nwbuf) {
439 Double_t* dbuf = fGeom->CreateDoubleArray(buf, nwbuf);
440 Material(kmat, name, a, z, dens, radl, absl, dbuf, nwbuf);
444 //______________________________________________________________________________
445 void TFluka::Material(Int_t& kmat, const char* name, Double_t a,
446 Double_t z, Double_t dens, Double_t radl, Double_t absl,
447 Double_t* /*buf*/, Int_t /*nwbuf*/) {
451 kmat = gGeoManager->GetListOfMaterials()->GetSize();
452 if ((z-Int_t(z)) > 1E-3) {
453 mat = fGeom->GetMakeWrongMaterial(z);
455 mat->SetRadLen(radl,absl);
456 mat->SetUniqueID(kmat);
460 gGeoManager->Material(name, a, z, dens, kmat, radl, absl);
463 //______________________________________________________________________________
464 void TFluka::Mixture(Int_t& kmat, const char *name, Float_t *a,
465 Float_t *z, Double_t dens, Int_t nlmat, Float_t *wmat) {
467 // Define a material mixture
469 Double_t* da = fGeom->CreateDoubleArray(a, TMath::Abs(nlmat));
470 Double_t* dz = fGeom->CreateDoubleArray(z, TMath::Abs(nlmat));
471 Double_t* dwmat = fGeom->CreateDoubleArray(wmat, TMath::Abs(nlmat));
473 Mixture(kmat, name, da, dz, dens, nlmat, dwmat);
474 for (Int_t i=0; i<nlmat; i++) {
475 a[i] = da[i]; z[i] = dz[i]; wmat[i] = dwmat[i];
483 //______________________________________________________________________________
484 void TFluka::Mixture(Int_t& kmat, const char *name, Double_t *a,
485 Double_t *z, Double_t dens, Int_t nlmat, Double_t *wmat) {
487 // Defines mixture OR COMPOUND IMAT as composed by
488 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
490 // If NLMAT > 0 then wmat contains the proportion by
491 // weights of each basic material in the mixture.
493 // If nlmat < 0 then WMAT contains the number of atoms
494 // of a given kind into the molecule of the COMPOUND
495 // In this case, WMAT in output is changed to relative
498 printf("Mixture %5d %10s %5d \n", kmat, name, nlmat);
504 for (i=0;i<nlmat;i++) {
505 amol += a[i]*wmat[i];
507 for (i=0;i<nlmat;i++) {
508 wmat[i] *= a[i]/amol;
511 kmat = gGeoManager->GetListOfMaterials()->GetSize();
512 // Check if we have elements with fractional Z
513 TGeoMaterial *mat = 0;
514 TGeoMixture *mix = 0;
515 Bool_t mixnew = kFALSE;
516 for (i=0; i<nlmat; i++) {
517 if (z[i]-Int_t(z[i]) < 1E-3) continue;
518 // We have found an element with fractional Z -> loop mixtures to look for it
519 for (j=0; j<kmat; j++) {
520 mat = (TGeoMaterial*)gGeoManager->GetListOfMaterials()->At(j);
522 if (!mat->IsMixture()) continue;
523 mix = (TGeoMixture*)mat;
524 if (TMath::Abs(z[i]-mix->GetZ()) >1E-3) continue;
528 if (!mixnew) Warning("Mixture","%s : cannot find component %i with fractional Z=%f\n", name, i, z[i]);
532 Int_t nlmatnew = nlmat+mix->GetNelements()-1;
533 Double_t *anew = new Double_t[nlmatnew];
534 Double_t *znew = new Double_t[nlmatnew];
535 Double_t *wmatnew = new Double_t[nlmatnew];
537 for (j=0; j<nlmat; j++) {
541 wmatnew[ind] = wmat[j];
544 for (j=0; j<mix->GetNelements(); j++) {
545 anew[ind] = mix->GetAmixt()[j];
546 znew[ind] = mix->GetZmixt()[j];
547 wmatnew[ind] = wmat[i]*mix->GetWmixt()[j];
550 Mixture(kmat, name, anew, znew, dens, nlmatnew, wmatnew);
556 // Now we need to compact identical elements within the mixture
557 // First check if this happens
559 for (i=0; i<nlmat-1; i++) {
560 for (j=i+1; j<nlmat; j++) {
570 Double_t *anew = new Double_t[nlmat];
571 Double_t *znew = new Double_t[nlmat];
572 memset(znew, 0, nlmat*sizeof(Double_t));
573 Double_t *wmatnew = new Double_t[nlmat];
575 for (i=0; i<nlmat; i++) {
577 for (j=0; j<nlmatnew; j++) {
579 wmatnew[j] += wmat[i];
585 anew[nlmatnew] = a[i];
586 znew[nlmatnew] = z[i];
587 wmatnew[nlmatnew] = wmat[i];
590 Mixture(kmat, name, anew, znew, dens, nlmatnew, wmatnew);
596 printf("Mixture (2) %5d %10s %5d \n", kmat, name, nlmat);
597 gGeoManager->Mixture(name, a, z, dens, nlmat, wmat, kmat);
600 //______________________________________________________________________________
601 void TFluka::Medium(Int_t& kmed, const char *name, Int_t nmat,
602 Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd,
603 Double_t stemax, Double_t deemax, Double_t epsil,
604 Double_t stmin, Float_t* ubuf, Int_t nbuf) {
607 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
608 fMCGeo->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
609 epsil, stmin, ubuf, nbuf);
612 //______________________________________________________________________________
613 void TFluka::Medium(Int_t& kmed, const char *name, Int_t nmat,
614 Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd,
615 Double_t stemax, Double_t deemax, Double_t epsil,
616 Double_t stmin, Double_t* ubuf, Int_t nbuf) {
619 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
620 fMCGeo->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
621 epsil, stmin, ubuf, nbuf);
624 //______________________________________________________________________________
625 void TFluka::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
626 Double_t thetaY, Double_t phiY, Double_t thetaZ,
629 krot = gGeoManager->GetListOfMatrices()->GetEntriesFast();
630 fMCGeo->Matrix(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
633 //______________________________________________________________________________
634 void TFluka::Gstpar(Int_t itmed, const char* param, Double_t parval) {
638 Bool_t process = kFALSE;
639 Bool_t modelp = kFALSE;
641 if (strncmp(param, "DCAY", 4) == 0 ||
642 strncmp(param, "PAIR", 4) == 0 ||
643 strncmp(param, "COMP", 4) == 0 ||
644 strncmp(param, "PHOT", 4) == 0 ||
645 strncmp(param, "PFIS", 4) == 0 ||
646 strncmp(param, "DRAY", 4) == 0 ||
647 strncmp(param, "ANNI", 4) == 0 ||
648 strncmp(param, "BREM", 4) == 0 ||
649 strncmp(param, "MUNU", 4) == 0 ||
650 strncmp(param, "CKOV", 4) == 0 ||
651 strncmp(param, "HADR", 4) == 0 ||
652 strncmp(param, "LOSS", 4) == 0 ||
653 strncmp(param, "MULS", 4) == 0 ||
654 strncmp(param, "RAYL", 4) == 0)
659 if (strncmp(param, "PRIMIO_N", 8) == 0 ||
660 strncmp(param, "PRIMIO_E", 8) == 0)
667 SetProcess(param, Int_t (parval), itmed);
670 SetModelParameter(param, parval, itmed);
673 SetCut(param, parval, itmed);
679 // functions from GGEOM
680 //_____________________________________________________________________________
681 void TFluka::Gsatt(const char *name, const char *att, Int_t val)
683 // Set visualisation attributes for one volume
685 fGeom->Vname(name,vname);
687 fGeom->Vname(att,vatt);
688 gGeoManager->SetVolumeAttribute(vname, vatt, val);
691 //______________________________________________________________________________
692 Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
693 Float_t *upar, Int_t np) {
695 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
698 //______________________________________________________________________________
699 Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
700 Double_t *upar, Int_t np) {
702 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
705 //______________________________________________________________________________
706 void TFluka::Gsdvn(const char *name, const char *mother, Int_t ndiv,
709 fMCGeo->Gsdvn(name, mother, ndiv, iaxis);
712 //______________________________________________________________________________
713 void TFluka::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
714 Int_t iaxis, Double_t c0i, Int_t numed) {
716 fMCGeo->Gsdvn2(name, mother, ndiv, iaxis, c0i, numed);
719 //______________________________________________________________________________
720 void TFluka::Gsdvt(const char *name, const char *mother, Double_t step,
721 Int_t iaxis, Int_t numed, Int_t ndvmx) {
723 fMCGeo->Gsdvt(name, mother, step, iaxis, numed, ndvmx);
726 //______________________________________________________________________________
727 void TFluka::Gsdvt2(const char *name, const char *mother, Double_t step,
728 Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx) {
730 fMCGeo->Gsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
733 //______________________________________________________________________________
734 void TFluka::Gsord(const char * /*name*/, Int_t /*iax*/) {
736 // Nothing to do with TGeo
739 //______________________________________________________________________________
740 void TFluka::Gspos(const char *name, Int_t nr, const char *mother,
741 Double_t x, Double_t y, Double_t z, Int_t irot,
744 fMCGeo->Gspos(name, nr, mother, x, y, z, irot, konly);
747 //______________________________________________________________________________
748 void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
749 Double_t x, Double_t y, Double_t z, Int_t irot,
750 const char *konly, Float_t *upar, Int_t np) {
752 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
755 //______________________________________________________________________________
756 void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
757 Double_t x, Double_t y, Double_t z, Int_t irot,
758 const char *konly, Double_t *upar, Int_t np) {
760 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
763 //______________________________________________________________________________
764 void TFluka::Gsbool(const char* /*onlyVolName*/, const char* /*manyVolName*/) {
766 // Nothing to do with TGeo
769 //______________________________________________________________________
770 Bool_t TFluka::GetTransformation(const TString &volumePath,TGeoHMatrix &mat)
772 // Returns the Transformation matrix between the volume specified
773 // by the path volumePath and the Top or mater volume. The format
774 // of the path volumePath is as follows (assuming ALIC is the Top volume)
775 // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
776 // or master volume which has only 1 instance of. Of all of the daughter
777 // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
778 // the daughter volume of DDIP is S05I copy #2 and so on.
780 // TString& volumePath The volume path to the specific volume
781 // for which you want the matrix. Volume name
782 // hierarchy is separated by "/" while the
783 // copy number is appended using a "_".
785 // TGeoHMatrix &mat A matrix with its values set to those
786 // appropriate to the Local to Master transformation
788 // A logical value if kFALSE then an error occurred and no change to
791 // We have to preserve the modeler state
792 return fMCGeo->GetTransformation(volumePath, mat);
795 //______________________________________________________________________
796 Bool_t TFluka::GetShape(const TString &volumePath,TString &shapeType,
799 // Returns the shape and its parameters for the volume specified
802 // TString& volumeName The volume name
804 // TString &shapeType Shape type
805 // TArrayD &par A TArrayD of parameters with all of the
806 // parameters of the specified shape.
808 // A logical indicating whether there was an error in getting this
810 return fMCGeo->GetShape(volumePath, shapeType, par);
813 //______________________________________________________________________
814 Bool_t TFluka::GetMaterial(const TString &volumeName,
815 TString &name,Int_t &imat,
816 Double_t &a,Double_t &z,Double_t &dens,
817 Double_t &radl,Double_t &inter,TArrayD &par)
819 // Returns the Material and its parameters for the volume specified
821 // Note, Geant3 stores and uses mixtures as an element with an effective
822 // Z and A. Consequently, if the parameter Z is not integer, then
823 // this material represents some sort of mixture.
825 // TString& volumeName The volume name
827 // TSrting &name Material name
828 // Int_t &imat Material index number
829 // Double_t &a Average Atomic mass of material
830 // Double_t &z Average Atomic number of material
831 // Double_t &dens Density of material [g/cm^3]
832 // Double_t &radl Average radiation length of material [cm]
833 // Double_t &inter Average interaction length of material [cm]
834 // TArrayD &par A TArrayD of user defined parameters.
836 // kTRUE if no errors
837 return fMCGeo->GetMaterial(volumeName,name,imat,a,z,dens,radl,inter,par);
840 //______________________________________________________________________
841 Bool_t TFluka::GetMedium(const TString &volumeName,TString &name,
842 Int_t &imed,Int_t &nmat,Int_t &isvol,Int_t &ifield,
843 Double_t &fieldm,Double_t &tmaxfd,Double_t &stemax,
844 Double_t &deemax,Double_t &epsil, Double_t &stmin,
847 // Returns the Medium and its parameters for the volume specified
850 // TString& volumeName The volume name.
852 // TString &name Medium name
853 // Int_t &nmat Material number defined for this medium
854 // Int_t &imed The medium index number
855 // Int_t &isvol volume number defined for this medium
856 // Int_t &iflield Magnetic field flag
857 // Double_t &fieldm Magnetic field strength
858 // Double_t &tmaxfd Maximum angle of deflection per step
859 // Double_t &stemax Maximum step size
860 // Double_t &deemax Maximum fraction of energy allowed to be lost
861 // to continuous process.
862 // Double_t &epsil Boundary crossing precision
863 // Double_t &stmin Minimum step size allowed
864 // TArrayD &par A TArrayD of user parameters with all of the
865 // parameters of the specified medium.
867 // kTRUE if there where no errors
868 return fMCGeo->GetMedium(volumeName,name,imed,nmat,isvol,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin,par);
871 //______________________________________________________________________________
872 void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
873 Float_t* absco, Float_t* effic, Float_t* rindex) {
875 // Set Cerenkov properties for medium itmed
877 // npckov: number of sampling points
878 // ppckov: energy values
879 // absco: absorption length
880 // effic: quantum efficiency
881 // rindex: refraction index
885 // Create object holding Cerenkov properties
888 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex);
890 // Pass object to medium
891 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
892 medium->SetCerenkovProperties(cerenkovProperties);
895 void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
896 Float_t* absco, Float_t* effic, Float_t* rindex, Float_t* rfl) {
898 // Set Cerenkov properties for medium itmed
900 // npckov: number of sampling points
901 // ppckov: energy values
902 // absco: absorption length
903 // effic: quantum efficiency
904 // rindex: refraction index
905 // rfl: reflectivity for boundary to medium itmed
908 // Create object holding Cerenkov properties
910 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex, rfl);
912 // Pass object to medium
913 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
914 medium->SetCerenkovProperties(cerenkovProperties);
918 //______________________________________________________________________________
919 void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Double_t *ppckov,
920 Double_t *absco, Double_t *effic, Double_t *rindex) {
922 // Set Cerenkov properties for medium itmed
924 // npckov: number of sampling points
925 // ppckov: energy values
926 // absco: absorption length
927 // effic: quantum efficiency
928 // rindex: refraction index
933 Float_t* fppckov = CreateFloatArray(ppckov, npckov);
934 Float_t* fabsco = CreateFloatArray(absco, npckov);
935 Float_t* feffic = CreateFloatArray(effic, npckov);
936 Float_t* frindex = CreateFloatArray(rindex, npckov);
938 SetCerenkov(itmed, npckov, fppckov, fabsco, feffic, frindex);
946 void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Double_t* ppckov,
947 Double_t* absco, Double_t* effic, Double_t* rindex, Double_t* rfl) {
949 // Set Cerenkov properties for medium itmed
951 // npckov: number of sampling points
952 // ppckov: energy values
953 // absco: absorption length
954 // effic: quantum efficiency
955 // rindex: refraction index
956 // rfl: reflectivity for boundary to medium itmed
960 // // Double_t version
961 Float_t* fppckov = CreateFloatArray(ppckov, npckov);
962 Float_t* fabsco = CreateFloatArray(absco, npckov);
963 Float_t* feffic = CreateFloatArray(effic, npckov);
964 Float_t* frindex = CreateFloatArray(rindex, npckov);
965 Float_t* frfl = CreateFloatArray(rfl, npckov);
967 SetCerenkov(itmed, npckov, fppckov, fabsco, feffic, frindex, frfl);
977 //______________________________________________________________________________
978 void TFluka::WriteEuclid(const char* /*fileName*/, const char* /*topVol*/,
979 Int_t /*number*/, Int_t /*nlevel*/) {
982 Warning("WriteEuclid", "Not implemented !");
987 //_____________________________________________________________________________
988 // methods needed by the stepping
989 //____________________________________________________________________________
991 Int_t TFluka::GetMedium() const {
993 // Get the medium number for the current fluka region
995 if (gGeoManager->IsOutside()) {
998 return (fGeom->GetMedium()); // this I need to check due to remapping !!!
1002 //____________________________________________________________________________
1003 Int_t TFluka::GetDummyRegion() const
1005 // Returns index of the dummy region.
1006 return fGeom->GetDummyRegion();
1009 //____________________________________________________________________________
1010 Int_t TFluka::GetDummyLattice() const
1012 // Returns index of the dummy lattice.
1013 return fGeom->GetDummyLattice();
1016 //____________________________________________________________________________
1017 // particle table usage
1018 // ID <--> PDG transformations
1019 //_____________________________________________________________________________
1020 Int_t TFluka::IdFromPDG(Int_t pdg) const
1023 // Return Fluka code from PDG and pseudo ENDF code
1025 // Catch the feedback photons
1026 if (pdg == 50000051) return (kFLUKAoptical);
1027 // MCIHAD() goes from pdg to fluka internal.
1028 Int_t intfluka = mcihad(pdg);
1029 // KPTOIP array goes from internal to official
1030 return GetFlukaKPTOIP(intfluka);
1033 //______________________________________________________________________________
1034 Int_t TFluka::PDGFromId(Int_t id) const
1037 // Return PDG code and pseudo ENDF code from Fluka code
1038 // Alpha He3 Triton Deuteron gen. ion opt. photon
1039 Int_t idSpecial[6] = {GetIonPdg(2,4), GetIonPdg(2, 3), GetIonPdg(1,3), GetIonPdg(1,2), GetIonPdg(0,0), 50000050};
1040 // IPTOKP array goes from official to internal
1042 if (id == kFLUKAoptical) {
1044 // if (fVerbosityLevel >= 3)
1045 // printf("\n PDGFromId: Cerenkov Photon \n");
1049 if (id == 0 || id < kFLUKAcodemin || id > kFLUKAcodemax) {
1050 if (fVerbosityLevel >= 3)
1051 printf("PDGFromId: Error id = 0 %5d %5d\n", id, fCaller);
1056 Int_t intfluka = GetFlukaIPTOKP(id);
1057 if (intfluka == 0) {
1058 if (fVerbosityLevel >= 3)
1059 printf("PDGFromId: Error intfluka = 0: %d\n", id);
1061 } else if (intfluka < 0) {
1062 if (fVerbosityLevel >= 3)
1063 printf("PDGFromId: Error intfluka < 0: %d\n", id);
1066 // if (fVerbosityLevel >= 3)
1067 // printf("mpdgha called with %d %d \n", id, intfluka);
1068 return mpdgha(intfluka);
1070 // ions and optical photons
1071 return idSpecial[id - kFLUKAcodemin];
1075 void TFluka::StopTrack()
1077 // Set stopping conditions
1078 // Works for photons and charged particles
1082 //_____________________________________________________________________________
1083 // methods for physics management
1084 //____________________________________________________________________________
1089 void TFluka::SetProcess(const char* flagName, Int_t flagValue, Int_t imed)
1091 // Set process user flag for material imat
1094 // Update if already in the list
1096 TIter next(fUserConfig);
1097 TFlukaConfigOption* proc;
1098 while((proc = (TFlukaConfigOption*)next()))
1100 if (proc->Medium() == imed) {
1101 proc->SetProcess(flagName, flagValue);
1105 proc = new TFlukaConfigOption(imed);
1106 proc->SetProcess(flagName, flagValue);
1107 fUserConfig->Add(proc);
1110 //______________________________________________________________________________
1111 Bool_t TFluka::SetProcess(const char* flagName, Int_t flagValue)
1113 // Set process user flag
1116 SetProcess(flagName, flagValue, -1);
1120 //______________________________________________________________________________
1121 void TFluka::SetCut(const char* cutName, Double_t cutValue, Int_t imed)
1123 // Set user cut value for material imed
1125 TIter next(fUserConfig);
1126 TFlukaConfigOption* proc;
1127 while((proc = (TFlukaConfigOption*)next()))
1129 if (proc->Medium() == imed) {
1130 proc->SetCut(cutName, cutValue);
1135 proc = new TFlukaConfigOption(imed);
1136 proc->SetCut(cutName, cutValue);
1137 fUserConfig->Add(proc);
1141 //______________________________________________________________________________
1142 void TFluka::SetModelParameter(const char* parName, Double_t parValue, Int_t imed)
1144 // Set model parameter for material imed
1146 TIter next(fUserConfig);
1147 TFlukaConfigOption* proc;
1148 while((proc = (TFlukaConfigOption*)next()))
1150 if (proc->Medium() == imed) {
1151 proc->SetModelParameter(parName, parValue);
1156 proc = new TFlukaConfigOption(imed);
1157 proc->SetModelParameter(parName, parValue);
1158 fUserConfig->Add(proc);
1161 //______________________________________________________________________________
1162 Bool_t TFluka::SetCut(const char* cutName, Double_t cutValue)
1164 // Set user cut value
1167 SetCut(cutName, cutValue, -1);
1172 void TFluka::SetUserScoring(const char* option, const char* sdum, Int_t npr, char* outfile, Float_t* what)
1175 // Adds a user scoring option to the list
1177 TFlukaScoringOption* opt = new TFlukaScoringOption(option, sdum, npr,outfile,what);
1178 fUserScore->Add(opt);
1180 //______________________________________________________________________________
1181 void TFluka::SetUserScoring(const char* option, const char* sdum, Int_t npr, char* outfile, Float_t* what,
1182 const char* det1, const char* det2, const char* det3)
1185 // Adds a user scoring option to the list
1187 TFlukaScoringOption* opt = new TFlukaScoringOption(option, sdum, npr, outfile, what, det1, det2, det3);
1188 fUserScore->Add(opt);
1191 //______________________________________________________________________________
1192 Double_t TFluka::Xsec(char*, Double_t, Int_t, Int_t)
1194 Warning("Xsec", "Not yet implemented.!\n"); return -1.;
1198 //______________________________________________________________________________
1199 void TFluka::InitPhysics()
1202 // Physics initialisation with preparation of FLUKA input cards
1204 // Construct file names
1205 FILE *pFlukaVmcCoreInp, *pFlukaVmcFlukaMat, *pFlukaVmcInp;
1206 TString sFlukaVmcCoreInp = getenv("ALICE_ROOT");
1207 sFlukaVmcCoreInp +="/TFluka/input/";
1208 TString sFlukaVmcTmp = "flukaMat.inp";
1209 TString sFlukaVmcInp = GetInputFileName();
1210 sFlukaVmcCoreInp += GetCoreInputFileName();
1213 if ((pFlukaVmcCoreInp = fopen(sFlukaVmcCoreInp.Data(),"r")) == NULL) {
1214 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcCoreInp.Data());
1217 if ((pFlukaVmcFlukaMat = fopen(sFlukaVmcTmp.Data(),"r")) == NULL) {
1218 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcTmp.Data());
1221 if ((pFlukaVmcInp = fopen(sFlukaVmcInp.Data(),"w")) == NULL) {
1222 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcInp.Data());
1226 // Copy core input file
1228 Float_t fEventsPerRun;
1230 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
1231 if (strncmp(sLine,"GEOEND",6) != 0)
1232 fprintf(pFlukaVmcInp,"%s",sLine); // copy until GEOEND card
1234 fprintf(pFlukaVmcInp,"GEOEND\n"); // add GEOEND card
1237 } // end of while until GEOEND card
1241 while ((fgets(sLine,255,pFlukaVmcFlukaMat)) != NULL) { // copy flukaMat.inp file
1242 fprintf(pFlukaVmcInp,"%s\n",sLine);
1245 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
1246 if (strncmp(sLine,"START",5) != 0)
1247 fprintf(pFlukaVmcInp,"%s\n",sLine);
1249 sscanf(sLine+10,"%10f",&fEventsPerRun);
1252 } //end of while until START card
1257 // Pass information to configuration objects
1259 Float_t fLastMaterial = fGeom->GetLastMaterialIndex();
1260 TFlukaConfigOption::SetStaticInfo(pFlukaVmcInp, 3, fLastMaterial, fGeom);
1262 TIter next(fUserConfig);
1263 TFlukaConfigOption* proc;
1264 while((proc = dynamic_cast<TFlukaConfigOption*> (next()))) proc->WriteFlukaInputCards();
1266 // Process Fluka specific scoring options
1268 TFlukaScoringOption::SetStaticInfo(pFlukaVmcInp, fGeom);
1269 Float_t loginp = -49.0;
1271 Int_t nscore = fUserScore->GetEntries();
1273 TFlukaScoringOption *mopo = 0;
1274 TFlukaScoringOption *mopi = 0;
1276 for (Int_t isc = 0; isc < nscore; isc++)
1278 mopo = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isc));
1279 char* fileName = mopo->GetFileName();
1280 Int_t size = strlen(fileName);
1283 // Check if new output file has to be opened
1284 for (Int_t isci = 0; isci < isc; isci++) {
1287 mopi = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isci));
1288 if(strncmp(mopi->GetFileName(), fileName, size)==0) {
1290 // No, the file already exists
1291 lun = mopi->GetLun();
1298 // Open new output file
1300 mopo->SetLun(loginp + inp);
1301 mopo->WriteOpenFlukaFile();
1303 mopo->WriteFlukaInputCards();
1306 // Add RANDOMIZ card
1307 fprintf(pFlukaVmcInp,"RANDOMIZ %10.1f%10.0f\n", 1., Float_t(gRandom->GetSeed()));
1308 // Add START and STOP card
1309 fprintf(pFlukaVmcInp,"START %10.1f\n",fEventsPerRun);
1310 fprintf(pFlukaVmcInp,"STOP \n");
1314 fclose(pFlukaVmcCoreInp);
1315 fclose(pFlukaVmcFlukaMat);
1316 fclose(pFlukaVmcInp);
1320 // Initialisation needed for Cerenkov photon production and transport
1321 TObjArray *matList = GetFlukaMaterials();
1322 Int_t nmaterial = matList->GetEntriesFast();
1323 fMaterials = new Int_t[nmaterial+25];
1325 for (Int_t im = 0; im < nmaterial; im++)
1327 TGeoMaterial* material = dynamic_cast<TGeoMaterial*> (matList->At(im));
1328 Int_t idmat = material->GetIndex();
1329 fMaterials[idmat] = im;
1331 } // end of InitPhysics
1334 //______________________________________________________________________________
1335 void TFluka::SetMaxStep(Double_t step)
1337 // Set the maximum step size
1338 // if (step > 1.e4) return;
1340 // Int_t mreg=0, latt=0;
1341 // fGeom->GetCurrentRegion(mreg, latt);
1342 Int_t mreg = fGeom->GetCurrentRegion();
1343 STEPSZ.stepmx[mreg - 1] = step;
1347 Double_t TFluka::MaxStep() const
1349 // Return the maximum for current medium
1351 fGeom->GetCurrentRegion(mreg, latt);
1352 return (STEPSZ.stepmx[mreg - 1]);
1355 //______________________________________________________________________________
1356 void TFluka::SetMaxNStep(Int_t)
1358 // SetMaxNStep is dummy procedure in TFluka !
1359 if (fVerbosityLevel >=3)
1360 cout << "SetMaxNStep is dummy procedure in TFluka !" << endl;
1363 //______________________________________________________________________________
1364 void TFluka::SetUserDecay(Int_t)
1366 // SetUserDecay is dummy procedure in TFluka !
1367 if (fVerbosityLevel >=3)
1368 cout << "SetUserDecay is dummy procedure in TFluka !" << endl;
1372 // dynamic properties
1374 //______________________________________________________________________________
1375 void TFluka::TrackPosition(TLorentzVector& position) const
1377 // Return the current position in the master reference frame of the
1378 // track being transported
1379 // TRACKR.atrack = age of the particle
1380 // TRACKR.xtrack = x-position of the last point
1381 // TRACKR.ytrack = y-position of the last point
1382 // TRACKR.ztrack = z-position of the last point
1383 FlukaCallerCode_t caller = GetCaller();
1384 if (caller == kENDRAW || caller == kUSDRAW ||
1385 caller == kBXExiting || caller == kBXEntering ||
1386 caller == kUSTCKV) {
1387 position.SetX(GetXsco());
1388 position.SetY(GetYsco());
1389 position.SetZ(GetZsco());
1390 position.SetT(TRACKR.atrack);
1392 else if (caller == kMGDRAW) {
1394 if ((i = fPrimaryElectronIndex) > -1) {
1395 // Primary Electron Ionisation
1397 GetPrimaryElectronPosition(i, x, y, z);
1401 position.SetT(TRACKR.atrack);
1403 position.SetX(TRACKR.xtrack[TRACKR.ntrack]);
1404 position.SetY(TRACKR.ytrack[TRACKR.ntrack]);
1405 position.SetZ(TRACKR.ztrack[TRACKR.ntrack]);
1406 position.SetT(TRACKR.atrack);
1409 else if (caller == kSODRAW) {
1410 Int_t ist = FLKSTK.npflka;
1411 position.SetX(FLKSTK.xflk[ist]);
1412 position.SetY(FLKSTK.yflk[ist]);
1413 position.SetZ(FLKSTK.zflk[ist]);
1414 position.SetT(FLKSTK.agestk[ist]);
1415 } else if (caller == kMGResumedTrack) {
1416 position.SetX(TRACKR.spausr[0]);
1417 position.SetY(TRACKR.spausr[1]);
1418 position.SetZ(TRACKR.spausr[2]);
1419 position.SetT(TRACKR.spausr[3]);
1422 Warning("TrackPosition","position not available");
1425 //______________________________________________________________________________
1426 void TFluka::TrackPosition(Double_t& x, Double_t& y, Double_t& z) const
1428 // Return the current position in the master reference frame of the
1429 // track being transported
1430 // TRACKR.atrack = age of the particle
1431 // TRACKR.xtrack = x-position of the last point
1432 // TRACKR.ytrack = y-position of the last point
1433 // TRACKR.ztrack = z-position of the last point
1434 FlukaCallerCode_t caller = GetCaller();
1435 if (caller == kENDRAW || caller == kUSDRAW ||
1436 caller == kBXExiting || caller == kBXEntering ||
1437 caller == kUSTCKV) {
1442 else if (caller == kMGDRAW) {
1444 if ((i = fPrimaryElectronIndex) > -1) {
1445 GetPrimaryElectronPosition(i, x, y, z);
1447 x = TRACKR.xtrack[TRACKR.ntrack];
1448 y = TRACKR.ytrack[TRACKR.ntrack];
1449 z = TRACKR.ztrack[TRACKR.ntrack];
1452 else if (caller == kSODRAW) {
1453 Int_t ist = FLKSTK.npflka;
1454 x = FLKSTK.xflk[ist];
1455 y = FLKSTK.yflk[ist];
1456 z = FLKSTK.zflk[ist];
1458 else if (caller == kMGResumedTrack) {
1459 x = TRACKR.spausr[0];
1460 y = TRACKR.spausr[1];
1461 z = TRACKR.spausr[2];
1464 Warning("TrackPosition","position not available");
1467 //______________________________________________________________________________
1468 void TFluka::TrackMomentum(TLorentzVector& momentum) const
1470 // Return the direction and the momentum (GeV/c) of the track
1471 // currently being transported
1472 // TRACKR.ptrack = momentum of the particle (not always defined, if
1473 // < 0 must be obtained from etrack)
1474 // TRACKR.cx,y,ztrck = direction cosines of the current particle
1475 // TRACKR.etrack = total energy of the particle
1476 // TRACKR.jtrack = identity number of the particle
1477 // PAPROP.am[TRACKR.jtrack] = particle mass in gev
1478 FlukaCallerCode_t caller = GetCaller();
1479 FlukaProcessCode_t icode = GetIcode();
1481 if (caller != kEEDRAW &&
1482 caller != kMGResumedTrack &&
1483 caller != kSODRAW &&
1484 caller != kUSDRAW &&
1485 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
1486 if (TRACKR.ptrack >= 0) {
1487 momentum.SetPx(TRACKR.ptrack*TRACKR.cxtrck);
1488 momentum.SetPy(TRACKR.ptrack*TRACKR.cytrck);
1489 momentum.SetPz(TRACKR.ptrack*TRACKR.cztrck);
1490 momentum.SetE(TRACKR.etrack);
1494 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
1495 momentum.SetPx(p*TRACKR.cxtrck);
1496 momentum.SetPy(p*TRACKR.cytrck);
1497 momentum.SetPz(p*TRACKR.cztrck);
1498 momentum.SetE(TRACKR.etrack);
1501 } else if (caller == kMGResumedTrack) {
1502 momentum.SetPx(TRACKR.spausr[4]);
1503 momentum.SetPy(TRACKR.spausr[5]);
1504 momentum.SetPz(TRACKR.spausr[6]);
1505 momentum.SetE (TRACKR.spausr[7]);
1507 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1511 momentum.SetE(TrackMass());
1513 } else if (caller == kSODRAW) {
1514 Int_t ist = FLKSTK.npflka;
1515 Double_t p = FLKSTK.pmoflk[ist];
1516 Int_t ifl = FLKSTK.iloflk[ist];
1517 Double_t m = PAPROP.am[ifl + 6];
1518 Double_t e = TMath::Sqrt(p * p + m * m);
1519 momentum.SetPx(p * FLKSTK.txflk[ist]);
1520 momentum.SetPy(p * FLKSTK.tyflk[ist]);
1521 momentum.SetPz(p * FLKSTK.tzflk[ist]);
1523 } else if (caller == kUSDRAW) {
1524 if (icode == kEMFSCObrems ||
1525 icode == kEMFSCOmoller ||
1526 icode == kEMFSCObhabha ||
1527 icode == kEMFSCOcompton )
1529 momentum.SetPx(fPint[0]);
1530 momentum.SetPy(fPint[1]);
1531 momentum.SetPz(fPint[2]);
1532 momentum.SetE(fPint[3]);
1533 } else if (icode == kKASKADdray ||
1534 icode == kKASKADbrems ||
1535 icode == kKASKADpair) {
1536 momentum.SetPx(GENSTK.plr[0] * GENSTK.cxr[0]);
1537 momentum.SetPy(GENSTK.plr[0] * GENSTK.cyr[0]);
1538 momentum.SetPz(GENSTK.plr[0] * GENSTK.czr[0]);
1539 momentum.SetE (GENSTK.tki[0] + PAPROP.am[GENSTK.kpart[0]+6]);
1541 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack
1542 - ParticleMassFPC(TRACKR.jtrack)
1543 * ParticleMassFPC(TRACKR.jtrack));
1544 momentum.SetPx(p*TRACKR.cxtrck);
1545 momentum.SetPy(p*TRACKR.cytrck);
1546 momentum.SetPz(p*TRACKR.cztrck);
1547 momentum.SetE(TRACKR.etrack);
1551 Warning("TrackMomentum","momentum not available");
1554 //______________________________________________________________________________
1555 void TFluka::TrackMomentum(Double_t& px, Double_t& py, Double_t& pz, Double_t& e) const
1557 // Return the direction and the momentum (GeV/c) of the track
1558 // currently being transported
1559 // TRACKR.ptrack = momentum of the particle (not always defined, if
1560 // < 0 must be obtained from etrack)
1561 // TRACKR.cx,y,ztrck = direction cosines of the current particle
1562 // TRACKR.etrack = total energy of the particle
1563 // TRACKR.jtrack = identity number of the particle
1564 // PAPROP.am[TRACKR.jtrack] = particle mass in gev
1565 FlukaCallerCode_t caller = GetCaller();
1566 FlukaProcessCode_t icode = GetIcode();
1567 if (caller != kEEDRAW &&
1568 caller != kMGResumedTrack &&
1569 caller != kSODRAW &&
1570 caller != kUSDRAW &&
1571 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
1572 if (TRACKR.ptrack >= 0) {
1573 px = TRACKR.ptrack*TRACKR.cxtrck;
1574 py = TRACKR.ptrack*TRACKR.cytrck;
1575 pz = TRACKR.ptrack*TRACKR.cztrck;
1580 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
1581 px = p*TRACKR.cxtrck;
1582 py = p*TRACKR.cytrck;
1583 pz = p*TRACKR.cztrck;
1587 } else if (caller == kMGResumedTrack) {
1588 px = TRACKR.spausr[4];
1589 py = TRACKR.spausr[5];
1590 pz = TRACKR.spausr[6];
1591 e = TRACKR.spausr[7];
1593 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1598 } else if (caller == kSODRAW) {
1599 Int_t ist = FLKSTK.npflka;
1600 Double_t p = FLKSTK.pmoflk[ist];
1601 Int_t ifl = FLKSTK.iloflk[ist];
1602 Double_t m = PAPROP.am[ifl + 6];
1603 e = TMath::Sqrt(p * p + m * m);
1604 px = p * FLKSTK.txflk[ist];
1605 py = p * FLKSTK.tyflk[ist];
1606 pz = p * FLKSTK.tzflk[ist];
1607 } else if (caller == kUSDRAW) {
1608 if (icode == kEMFSCObrems ||
1609 icode == kEMFSCOmoller ||
1610 icode == kEMFSCObhabha ||
1611 icode == kEMFSCOcompton )
1617 } else if (icode == kKASKADdray ||
1618 icode == kKASKADbrems ||
1619 icode == kKASKADpair) {
1620 px = GENSTK.plr[0] * GENSTK.cxr[0];
1621 py = GENSTK.plr[0] * GENSTK.cyr[0];
1622 pz = GENSTK.plr[0] * GENSTK.czr[0];
1623 e = GENSTK.tki[0] + PAPROP.am[GENSTK.kpart[0]+6];
1625 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
1626 px = p*TRACKR.cxtrck;
1627 py = p*TRACKR.cytrck;
1628 pz = p*TRACKR.cztrck;
1633 Warning("TrackMomentum","momentum not available");
1636 //______________________________________________________________________________
1637 Double_t TFluka::TrackStep() const
1639 // Return the length in centimeters of the current step
1640 // TRACKR.ctrack = total curved path
1641 FlukaCallerCode_t caller = GetCaller();
1642 if (caller == kBXEntering || caller == kBXExiting ||
1643 caller == kENDRAW || caller == kUSDRAW ||
1644 caller == kUSTCKV || caller == kMGResumedTrack ||
1647 else if (caller == kMGDRAW)
1648 return TRACKR.ctrack;
1650 Warning("TrackStep", "track step not available");
1655 //______________________________________________________________________________
1656 Double_t TFluka::TrackLength() const
1658 // TRACKR.cmtrck = cumulative curved path since particle birth
1659 FlukaCallerCode_t caller = GetCaller();
1660 if (caller == kBXEntering || caller == kBXExiting ||
1661 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1663 return TRACKR.cmtrck;
1664 else if (caller == kMGResumedTrack)
1665 return TRACKR.spausr[8];
1666 else if (caller == kSODRAW)
1669 Warning("TrackLength", "track length not available for caller %5d \n", caller);
1674 //______________________________________________________________________________
1675 Double_t TFluka::TrackTime() const
1677 // Return the current time of flight of the track being transported
1678 // TRACKR.atrack = age of the particle
1679 FlukaCallerCode_t caller = GetCaller();
1680 if (caller == kBXEntering || caller == kBXExiting ||
1681 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1683 return TRACKR.atrack;
1684 else if (caller == kMGResumedTrack)
1685 return TRACKR.spausr[3];
1686 else if (caller == kSODRAW) {
1687 return (FLKSTK.agestk[FLKSTK.npflka]);
1690 Warning("TrackTime", "track time not available");
1695 //______________________________________________________________________________
1696 Double_t TFluka::Edep() const
1698 // Energy deposition
1699 // if TRACKR.ntrack = 0, TRACKR.mtrack = 0:
1700 // -->local energy deposition (the value and the point are not recorded in TRACKR)
1701 // but in the variable "rull" of the procedure "endraw.cxx"
1702 // if TRACKR.ntrack > 0, TRACKR.mtrack = 0:
1703 // -->no energy loss along the track
1704 // if TRACKR.ntrack > 0, TRACKR.mtrack > 0:
1705 // -->energy loss distributed along the track
1706 // TRACKR.dtrack = energy deposition of the jth deposition event
1708 // If coming from bxdraw we have 2 steps of 0 length and 0 edep
1709 // If coming from usdraw we just signal particle production - no edep
1710 // If just first time after resuming, no edep for the primary
1711 FlukaCallerCode_t caller = GetCaller();
1713 if (caller == kBXExiting || caller == kBXEntering ||
1714 caller == kUSDRAW || caller == kMGResumedTrack ||
1720 // Material with primary ionisation activated but number of primary electrons nprim = 0
1721 if (fPrimaryElectronIndex == -2) return 0.0;
1723 if ((i = fPrimaryElectronIndex) > -1) {
1724 // Primary ionisation
1725 sum = GetPrimaryElectronKineticEnergy(i);
1727 printf("edep > 100. %d %d %f \n", i, ALLDLT.nalldl, sum);
1731 // Normal ionisation
1732 if (TRACKR.mtrack > 1) printf("Edep: %6d\n", TRACKR.mtrack);
1734 for ( Int_t j=0;j<TRACKR.mtrack;j++) {
1735 sum +=TRACKR.dtrack[j];
1737 if (TRACKR.ntrack == 0 && TRACKR.mtrack == 0)
1745 //______________________________________________________________________________
1746 Int_t TFluka::CorrectFlukaId() const
1748 // since we don't put photons and e- created bellow transport cut on the vmc stack
1749 // and there is a call to endraw for energy deposition for each of them
1750 // and they have the track number of their parent, but different identity (pdg)
1751 // so we want to assign also their parent identity.
1754 && TRACKR.ispusr[mkbmx2 - 4] == TRACKR.ispusr[mkbmx2 - 1]
1755 && TRACKR.jtrack != TRACKR.ispusr[mkbmx2 - 3] ) {
1756 if (fVerbosityLevel >=3)
1757 cout << "CorrectFlukaId() for icode=" << GetIcode()
1758 << " track=" << TRACKR.ispusr[mkbmx2 - 1]
1759 << " current PDG=" << PDGFromId(TRACKR.jtrack)
1760 << " assign parent PDG=" << PDGFromId(TRACKR.ispusr[mkbmx2 - 3]) << endl;
1761 return TRACKR.ispusr[mkbmx2 - 3]; // assign parent identity
1763 if (TRACKR.jtrack <= 64){
1764 return TRACKR.jtrack;
1766 return TRACKR.j0trck;
1771 //______________________________________________________________________________
1772 Int_t TFluka::TrackPid() const
1774 // Return the id of the particle transported
1775 // TRACKR.jtrack = identity number of the particle
1776 FlukaCallerCode_t caller = GetCaller();
1777 if (caller != kEEDRAW && caller != kSODRAW) {
1778 return PDGFromId( CorrectFlukaId() );
1780 else if (caller == kSODRAW) {
1781 return PDGFromId(FLKSTK.iloflk[FLKSTK.npflka]);
1787 //______________________________________________________________________________
1788 Double_t TFluka::TrackCharge() const
1790 // Return charge of the track currently transported
1791 // PAPROP.ichrge = electric charge of the particle
1792 // TRACKR.jtrack = identity number of the particle
1794 FlukaCallerCode_t caller = GetCaller();
1795 if (caller != kEEDRAW && caller != kSODRAW)
1796 return PAPROP.ichrge[CorrectFlukaId() + 6];
1797 else if (caller == kSODRAW) {
1798 Int_t ifl = PDGFromId(FLKSTK.iloflk[FLKSTK.npflka]);
1799 return PAPROP.ichrge[ifl + 6];
1805 //______________________________________________________________________________
1806 Double_t TFluka::TrackMass() const
1808 // PAPROP.am = particle mass in GeV
1809 // TRACKR.jtrack = identity number of the particle
1810 FlukaCallerCode_t caller = GetCaller();
1811 if (caller != kEEDRAW && caller != kSODRAW)
1812 return PAPROP.am[CorrectFlukaId()+6];
1813 else if (caller == kSODRAW) {
1814 Int_t ifl = FLKSTK.iloflk[FLKSTK.npflka];
1815 return PAPROP.am[ifl + 6];
1821 //______________________________________________________________________________
1822 Double_t TFluka::Etot() const
1824 // TRACKR.etrack = total energy of the particle
1825 FlukaCallerCode_t caller = GetCaller();
1826 FlukaProcessCode_t icode = GetIcode();
1827 if (caller != kEEDRAW && caller != kSODRAW && caller != kUSDRAW)
1829 return TRACKR.etrack;
1830 } else if (caller == kUSDRAW) {
1831 if (icode == kEMFSCObrems ||
1832 icode == kEMFSCOmoller ||
1833 icode == kEMFSCObhabha ||
1834 icode == kEMFSCOcompton ) {
1837 else if (icode == kKASKADdray ||
1838 icode == kKASKADbrems ||
1839 icode == kKASKADpair) {
1840 return (GENSTK.tki[0] + PAPROP.am[GENSTK.kpart[0]+6]);
1843 else if (caller == kSODRAW) {
1844 Int_t ist = FLKSTK.npflka;
1845 Double_t p = FLKSTK.pmoflk[ist];
1846 Int_t ifl = FLKSTK.iloflk[ist];
1847 Double_t m = PAPROP.am[ifl + 6];
1848 Double_t e = TMath::Sqrt(p * p + m * m);
1858 //______________________________________________________________________________
1859 Bool_t TFluka::IsNewTrack() const
1861 // Return true for the first call of Stepping()
1865 void TFluka::SetTrackIsNew(Bool_t flag)
1867 // Return true for the first call of Stepping()
1873 //______________________________________________________________________________
1874 Bool_t TFluka::IsTrackInside() const
1876 // True if the track is not at the boundary of the current volume
1877 // In Fluka a step is always inside one kind of material
1878 // If the step would go behind the region of one material,
1879 // it will be shortened to reach only the boundary.
1880 // Therefore IsTrackInside() is always true.
1881 FlukaCallerCode_t caller = GetCaller();
1882 if (caller == kBXEntering || caller == kBXExiting)
1888 //______________________________________________________________________________
1889 Bool_t TFluka::IsTrackEntering() const
1891 // True if this is the first step of the track in the current volume
1893 FlukaCallerCode_t caller = GetCaller();
1894 if (caller == kBXEntering)
1899 //______________________________________________________________________________
1900 Bool_t TFluka::IsTrackExiting() const
1902 // True if track is exiting volume
1904 FlukaCallerCode_t caller = GetCaller();
1905 if (caller == kBXExiting)
1910 //______________________________________________________________________________
1911 Bool_t TFluka::IsTrackOut() const
1913 // True if the track is out of the setup
1915 FlukaProcessCode_t icode = GetIcode();
1917 if (icode == kKASKADescape ||
1918 icode == kEMFSCOescape ||
1919 icode == kKASNEUescape ||
1920 icode == kKASHEAescape ||
1921 icode == kKASOPHescape)
1926 //______________________________________________________________________________
1927 Bool_t TFluka::IsTrackDisappeared() const
1929 // All inelastic interactions and decays
1930 // fIcode from usdraw
1931 FlukaProcessCode_t icode = GetIcode();
1932 if (icode == kKASKADinelint || // inelastic interaction
1933 icode == kKASKADdecay || // particle decay
1934 icode == kKASKADdray || // delta ray generation by hadron
1935 icode == kKASKADpair || // direct pair production
1936 icode == kKASKADbrems || // bremsstrahlung (muon)
1937 icode == kEMFSCObrems || // bremsstrahlung (electron)
1938 icode == kEMFSCOmoller || // Moller scattering
1939 icode == kEMFSCObhabha || // Bhaba scattering
1940 icode == kEMFSCOanniflight || // in-flight annihilation
1941 icode == kEMFSCOannirest || // annihilation at rest
1942 icode == kEMFSCOpair || // pair production
1943 icode == kEMFSCOcompton || // Compton scattering
1944 icode == kEMFSCOphotoel || // Photoelectric effect
1945 icode == kKASNEUhadronic || // hadronic interaction
1946 icode == kKASHEAdray // delta-ray
1951 //______________________________________________________________________________
1952 Bool_t TFluka::IsTrackStop() const
1954 // True if the track energy has fallen below the threshold
1955 // means stopped by signal or below energy threshold
1956 FlukaProcessCode_t icode = GetIcode();
1957 if (icode == kKASKADstopping || // stopping particle
1958 icode == kKASKADtimekill || // time kill
1959 icode == kEMFSCOstopping1 || // below user-defined cut-off
1960 icode == kEMFSCOstopping2 || // below user cut-off
1961 icode == kEMFSCOtimekill || // time kill
1962 icode == kKASNEUstopping || // neutron below threshold
1963 icode == kKASNEUtimekill || // time kill
1964 icode == kKASHEAtimekill || // time kill
1965 icode == kKASOPHtimekill) return 1; // time kill
1969 //______________________________________________________________________________
1970 Bool_t TFluka::IsTrackAlive() const
1972 // means not disappeared or not out
1973 if (IsTrackDisappeared() || IsTrackOut() ) return 0;
1981 //______________________________________________________________________________
1982 Int_t TFluka::NSecondaries() const
1985 // Number of secondary particles generated in the current step
1986 // GENSTK.np = number of secondaries except light and heavy ions
1987 // FHEAVY.npheav = number of secondaries for light and heavy secondary ions
1988 FlukaCallerCode_t caller = GetCaller();
1989 if (caller == kUSDRAW) // valid only after usdraw
1990 return GENSTK.np + FHEAVY.npheav;
1991 else if (caller == kUSTCKV) {
1992 // Cerenkov Photon production
1996 } // end of NSecondaries
1998 //______________________________________________________________________________
1999 void TFluka::GetSecondary(Int_t isec, Int_t& particleId,
2000 TLorentzVector& position, TLorentzVector& momentum)
2002 // Copy particles from secondary stack to vmc stack
2005 FlukaCallerCode_t caller = GetCaller();
2006 if (caller == kUSDRAW) { // valid only after usdraw
2007 if (GENSTK.np > 0) {
2008 // Hadronic interaction
2009 if (isec >= 0 && isec < GENSTK.np) {
2010 particleId = PDGFromId(GENSTK.kpart[isec]);
2011 position.SetX(fXsco);
2012 position.SetY(fYsco);
2013 position.SetZ(fZsco);
2014 position.SetT(TRACKR.atrack);
2015 momentum.SetPx(GENSTK.plr[isec]*GENSTK.cxr[isec]);
2016 momentum.SetPy(GENSTK.plr[isec]*GENSTK.cyr[isec]);
2017 momentum.SetPz(GENSTK.plr[isec]*GENSTK.czr[isec]);
2018 momentum.SetE(GENSTK.tki[isec] + PAPROP.am[GENSTK.kpart[isec]+6]);
2020 else if (isec >= GENSTK.np && isec < GENSTK.np + FHEAVY.npheav) {
2021 Int_t jsec = isec - GENSTK.np;
2022 particleId = FHEAVY.kheavy[jsec]; // this is Fluka id !!!
2023 position.SetX(fXsco);
2024 position.SetY(fYsco);
2025 position.SetZ(fZsco);
2026 position.SetT(TRACKR.atrack);
2027 momentum.SetPx(FHEAVY.pheavy[jsec]*FHEAVY.cxheav[jsec]);
2028 momentum.SetPy(FHEAVY.pheavy[jsec]*FHEAVY.cyheav[jsec]);
2029 momentum.SetPz(FHEAVY.pheavy[jsec]*FHEAVY.czheav[jsec]);
2030 if (FHEAVY.tkheav[jsec] >= 3 && FHEAVY.tkheav[jsec] <= 6)
2031 momentum.SetE(FHEAVY.tkheav[jsec] + PAPROP.am[jsec+6]);
2032 else if (FHEAVY.tkheav[jsec] > 6)
2033 momentum.SetE(FHEAVY.tkheav[jsec] + FHEAVY.amnhea[jsec]); // to be checked !!!
2036 Warning("GetSecondary","isec out of range");
2038 } else if (caller == kUSTCKV) {
2039 Int_t index = OPPHST.lstopp - isec;
2040 position.SetX(OPPHST.xoptph[index]);
2041 position.SetY(OPPHST.yoptph[index]);
2042 position.SetZ(OPPHST.zoptph[index]);
2043 position.SetT(OPPHST.agopph[index]);
2044 Double_t p = OPPHST.poptph[index];
2046 momentum.SetPx(p * OPPHST.txopph[index]);
2047 momentum.SetPy(p * OPPHST.tyopph[index]);
2048 momentum.SetPz(p * OPPHST.tzopph[index]);
2052 Warning("GetSecondary","no secondaries available");
2054 } // end of GetSecondary
2057 //______________________________________________________________________________
2058 TMCProcess TFluka::ProdProcess(Int_t) const
2061 // Name of the process that has produced the secondary particles
2062 // in the current step
2064 Int_t mugamma = (TRACKR.jtrack == kFLUKAphoton ||
2065 TRACKR.jtrack == kFLUKAmuplus ||
2066 TRACKR.jtrack == kFLUKAmuminus);
2067 FlukaProcessCode_t icode = GetIcode();
2069 if (icode == kKASKADdecay) return kPDecay;
2070 else if (icode == kKASKADpair || icode == kEMFSCOpair) return kPPair;
2071 else if (icode == kEMFSCOcompton) return kPCompton;
2072 else if (icode == kEMFSCOphotoel) return kPPhotoelectric;
2073 else if (icode == kKASKADbrems || icode == kEMFSCObrems) return kPBrem;
2074 else if (icode == kKASKADdray || icode == kKASHEAdray) return kPDeltaRay;
2075 else if (icode == kEMFSCOmoller || icode == kEMFSCObhabha) return kPDeltaRay;
2076 else if (icode == kEMFSCOanniflight || icode == kEMFSCOannirest) return kPAnnihilation;
2077 else if (icode == kKASKADinelint) {
2078 if (!mugamma) return kPHadronic;
2079 else if (TRACKR.jtrack == kFLUKAphoton) return kPPhotoFission;
2080 else return kPMuonNuclear;
2082 else if (icode == kEMFSCOrayleigh) return kPRayleigh;
2083 // Fluka codes 100, 300 and 400 still to be investigasted
2084 else return kPNoProcess;
2088 Int_t TFluka::StepProcesses(TArrayI &proc) const
2091 // Return processes active in the current step
2093 FlukaProcessCode_t icode = GetIcode();
2094 FlukaCallerCode_t caller = GetCaller();
2098 if (caller == kBXEntering || caller == kBXExiting || caller == kEEDRAW) {
2099 iproc = kPTransportation;
2104 iproc = kPEnergyLoss;
2106 iproc = kPTransportation;
2111 iproc = kPEnergyLoss;
2113 iproc = kPTransportation;
2116 case kKASKADtimekill:
2117 case kEMFSCOtimekill:
2118 case kKASNEUtimekill:
2119 case kKASHEAtimekill:
2120 case kKASOPHtimekill:
2123 case kKASKADstopping:
2125 case kEMFSCOstopping1:
2126 case kEMFSCOstopping2:
2128 case kKASNEUstopping:
2134 case kKASOPHabsorption:
2135 iproc = kPLightAbsorption;
2137 case kKASOPHrefraction:
2138 iproc = kPLightRefraction;
2139 case kEMFSCOlocaldep :
2140 iproc = kPPhotoelectric;
2143 iproc = ProdProcess(0);
2150 //______________________________________________________________________________
2151 Int_t TFluka::VolId2Mate(Int_t id) const
2154 // Returns the material number for a given volume ID
2156 return fMCGeo->VolId2Mate(id);
2159 //______________________________________________________________________________
2160 const char* TFluka::VolName(Int_t id) const
2163 // Returns the volume name for a given volume ID
2165 return fMCGeo->VolName(id);
2168 Int_t TFluka::MediumId(const Text_t* mediumName) const
2171 // Return the unique medium id for medium with name mediumName
2172 TList *medlist = gGeoManager->GetListOfMedia();
2173 TGeoMedium* med = (TGeoMedium*) medlist->FindObject(mediumName);
2175 return (med->GetId());
2181 //______________________________________________________________________________
2182 Int_t TFluka::VolId(const Text_t* volName) const
2185 // Converts from volume name to volume ID.
2186 // Time consuming. (Only used during set-up)
2187 // Could be replaced by hash-table
2191 strncpy(sname, volName, len = strlen(volName));
2193 while (sname[len - 1] == ' ') sname[--len] = 0;
2194 return fMCGeo->VolId(sname);
2197 //______________________________________________________________________________
2198 Int_t TFluka::CurrentVolID(Int_t& copyNo) const
2201 // Return the logical id and copy number corresponding to the current fluka region
2203 if (gGeoManager->IsOutside()) return 0;
2204 TGeoNode *node = gGeoManager->GetCurrentNode();
2205 copyNo = node->GetNumber();
2206 Int_t id = node->GetVolume()->GetNumber();
2210 //______________________________________________________________________________
2211 Int_t TFluka::CurrentVolOffID(Int_t off, Int_t& copyNo) const
2214 // Return the logical id and copy number of off'th mother
2215 // corresponding to the current fluka region
2217 if (off<0 || off>gGeoManager->GetLevel()) return 0;
2218 if (off==0) return CurrentVolID(copyNo);
2219 TGeoNode *node = gGeoManager->GetMother(off);
2220 if (!node) return 0;
2221 copyNo = node->GetNumber();
2222 return node->GetVolume()->GetNumber();
2225 //______________________________________________________________________________
2226 const char* TFluka::CurrentVolName() const
2229 // Return the current volume name
2231 if (gGeoManager->IsOutside()) return "OutOfWorld";
2232 return gGeoManager->GetCurrentVolume()->GetName();
2235 //______________________________________________________________________________
2236 const char* TFluka::CurrentVolOffName(Int_t off) const
2239 // Return the volume name of the off'th mother of the current volume
2241 if (off<0 || off>gGeoManager->GetLevel()) return 0;
2242 if (off==0) return CurrentVolName();
2243 TGeoNode *node = gGeoManager->GetMother(off);
2244 if (!node) return 0;
2245 return node->GetVolume()->GetName();
2248 const char* TFluka::CurrentVolPath() {
2249 // Return the current volume path
2250 return gGeoManager->GetPath();
2252 //______________________________________________________________________________
2253 Int_t TFluka::CurrentMaterial(Float_t & a, Float_t & z,
2254 Float_t & dens, Float_t & radl, Float_t & absl) const
2257 // Return the current medium number and material properties
2260 Int_t id = TFluka::CurrentVolID(copy);
2261 Int_t med = TFluka::VolId2Mate(id);
2262 TGeoVolume* vol = gGeoManager->GetCurrentVolume();
2263 TGeoMaterial* mat = vol->GetMaterial();
2266 dens = mat->GetDensity();
2267 radl = mat->GetRadLen();
2268 absl = mat->GetIntLen();
2273 //______________________________________________________________________________
2274 void TFluka::Gmtod(Float_t* xm, Float_t* xd, Int_t iflag)
2276 // Transforms a position from the world reference frame
2277 // to the current volume reference frame.
2279 // Geant3 desription:
2280 // ==================
2281 // Computes coordinates XD (in DRS)
2282 // from known coordinates XM in MRS
2283 // The local reference system can be initialized by
2284 // - the tracking routines and GMTOD used in GUSTEP
2285 // - a call to GMEDIA(XM,NUMED)
2286 // - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
2287 // (inverse routine is GDTOM)
2289 // If IFLAG=1 convert coordinates
2290 // IFLAG=2 convert direction cosinus
2293 Double_t xmL[3], xdL[3];
2295 for (i=0;i<3;i++) xmL[i]=xm[i];
2296 if (iflag == 1) gGeoManager->MasterToLocal(xmL,xdL);
2297 else gGeoManager->MasterToLocalVect(xmL,xdL);
2298 for (i=0;i<3;i++) xd[i] = xdL[i];
2301 //______________________________________________________________________________
2302 void TFluka::Gmtod(Double_t* xm, Double_t* xd, Int_t iflag)
2305 // See Gmtod(Float_t*, Float_t*, Int_t)
2307 if (iflag == 1) gGeoManager->MasterToLocal(xm,xd);
2308 else gGeoManager->MasterToLocalVect(xm,xd);
2311 //______________________________________________________________________________
2312 void TFluka::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag)
2314 // Transforms a position from the current volume reference frame
2315 // to the world reference frame.
2317 // Geant3 desription:
2318 // ==================
2319 // Computes coordinates XM (Master Reference System
2320 // knowing the coordinates XD (Detector Ref System)
2321 // The local reference system can be initialized by
2322 // - the tracking routines and GDTOM used in GUSTEP
2323 // - a call to GSCMED(NLEVEL,NAMES,NUMBER)
2324 // (inverse routine is GMTOD)
2326 // If IFLAG=1 convert coordinates
2327 // IFLAG=2 convert direction cosinus
2330 Double_t xmL[3], xdL[3];
2332 for (i=0;i<3;i++) xdL[i] = xd[i];
2333 if (iflag == 1) gGeoManager->LocalToMaster(xdL,xmL);
2334 else gGeoManager->LocalToMasterVect(xdL,xmL);
2335 for (i=0;i<3;i++) xm[i]=xmL[i];
2338 //______________________________________________________________________________
2339 void TFluka::Gdtom(Double_t* xd, Double_t* xm, Int_t iflag)
2342 // See Gdtom(Float_t*, Float_t*, Int_t)
2344 if (iflag == 1) gGeoManager->LocalToMaster(xd,xm);
2345 else gGeoManager->LocalToMasterVect(xd,xm);
2348 //______________________________________________________________________________
2349 TObjArray *TFluka::GetFlukaMaterials()
2352 // Get array of Fluka materials
2353 return fGeom->GetMatList();
2356 //______________________________________________________________________________
2357 void TFluka::SetMreg(Int_t l, Int_t lttc)
2359 // Set current fluka region
2360 fCurrentFlukaRegion = l;
2361 fGeom->SetMreg(l,lttc);
2367 //______________________________________________________________________________
2368 TString TFluka::ParticleName(Int_t pdg) const
2370 // Return particle name for particle with pdg code pdg.
2371 Int_t ifluka = IdFromPDG(pdg);
2372 return TString((CHPPRP.btype[ifluka - kFLUKAcodemin]), 8);
2376 //______________________________________________________________________________
2377 Double_t TFluka::ParticleMass(Int_t pdg) const
2379 // Return particle mass for particle with pdg code pdg.
2380 Int_t ifluka = IdFromPDG(pdg);
2381 return (PAPROP.am[ifluka - kFLUKAcodemin]);
2384 //______________________________________________________________________________
2385 Double_t TFluka::ParticleMassFPC(Int_t fpc) const
2387 // Return particle mass for particle with Fluka particle code fpc
2388 return (PAPROP.am[fpc - kFLUKAcodemin]);
2391 //______________________________________________________________________________
2392 Double_t TFluka::ParticleCharge(Int_t pdg) const
2394 // Return particle charge for particle with pdg code pdg.
2395 Int_t ifluka = IdFromPDG(pdg);
2396 return Double_t(PAPROP.ichrge[ifluka - kFLUKAcodemin]);
2399 //______________________________________________________________________________
2400 Double_t TFluka::ParticleLifeTime(Int_t pdg) const
2402 // Return particle lifetime for particle with pdg code pdg.
2403 Int_t ifluka = IdFromPDG(pdg);
2404 return (PAPROP.tmnlf[ifluka - kFLUKAcodemin]);
2407 //______________________________________________________________________________
2408 void TFluka::Gfpart(Int_t pdg, char* name, Int_t& type, Float_t& mass, Float_t& charge, Float_t& tlife)
2410 // Retrieve particle properties for particle with pdg code pdg.
2412 strcpy(name, ParticleName(pdg).Data());
2413 type = ParticleMCType(pdg);
2414 mass = ParticleMass(pdg);
2415 charge = ParticleCharge(pdg);
2416 tlife = ParticleLifeTime(pdg);
2419 //______________________________________________________________________________
2420 void TFluka::PrintHeader()
2426 printf("------------------------------------------------------------------------------\n");
2427 printf("- You are using the TFluka Virtual Monte Carlo Interface to FLUKA. -\n");
2428 printf("- Please see the file fluka.out for FLUKA output and licensing information. -\n");
2429 printf("------------------------------------------------------------------------------\n");
2435 #define pshckp pshckp_
2436 #define ustckv ustckv_
2440 void pshckp(Double_t & px, Double_t & py, Double_t & pz, Double_t & e,
2441 Double_t & vx, Double_t & vy, Double_t & vz, Double_t & tof,
2442 Double_t & polx, Double_t & poly, Double_t & polz, Double_t & wgt, Int_t& ntr)
2445 // Pushes one cerenkov photon to the stack
2448 TFluka* fluka = (TFluka*) gMC;
2449 TVirtualMCStack* cppstack = fluka->GetStack();
2450 Int_t parent = TRACKR.ispusr[mkbmx2-1];
2451 cppstack->PushTrack(0, parent, 50000050,
2455 kPCerenkov, ntr, wgt, 0);
2456 if (fluka->GetVerbosityLevel() >= 3)
2457 printf("pshckp: track=%d parent=%d lattc=%d %s\n", ntr, parent, TRACKR.lt1trk, fluka->CurrentVolName());
2460 void ustckv(Int_t & nphot, Int_t & mreg, Double_t & x, Double_t & y, Double_t & z)
2463 // Calls stepping in order to signal cerenkov production
2465 TFluka *fluka = (TFluka*)gMC;
2466 fluka->SetMreg(mreg, TRACKR.lt1trk); //LTCLCM.mlatm1);
2470 fluka->SetNCerenkov(nphot);
2471 fluka->SetCaller(kUSTCKV);
2472 if (fluka->GetVerbosityLevel() >= 3)
2473 printf("ustckv: %10d mreg=%d lattc=%d newlat=%d (%f, %f, %f) edep=%f vol=%s\n",
2474 nphot, mreg, TRACKR.lt1trk, LTCLCM.newlat, x, y, z, fluka->Edep(), fluka->CurrentVolName());
2476 // check region lattice consistency (debug Ernesto)
2477 // *****************************************************
2479 Int_t volId = fluka->CurrentVolID(nodeId);
2480 Int_t crtlttc = gGeoManager->GetCurrentNodeId()+1;
2482 if( mreg != volId && !gGeoManager->IsOutside() ) {
2483 cout << " ustckv: track=" << TRACKR.ispusr[mkbmx2-1] << " pdg=" << fluka->PDGFromId(TRACKR.jtrack)
2484 << " icode=" << fluka->GetIcode() << " gNstep=" << fluka->GetNstep() << endl
2485 << " fluka mreg=" << mreg << " mlttc=" << TRACKR.lt1trk << endl
2486 << " TGeo volId=" << volId << " crtlttc=" << crtlttc << endl
2487 << " common TRACKR lt1trk=" << TRACKR.lt1trk << " lt2trk=" << TRACKR.lt2trk << endl
2488 << " common LTCLCM newlat=" << LTCLCM.newlat << " mlatld=" << LTCLCM.mlatld << endl
2489 << " mlatm1=" << LTCLCM.mlatm1 << " mltsen=" << LTCLCM.mltsen << endl
2490 << " mltsm1=" << LTCLCM.mltsm1 << " mlattc=" << LTCLCM.mlattc << endl;
2491 if( TRACKR.lt1trk == crtlttc ) cout << " *************************************************************" << endl;
2493 // *****************************************************
2497 (TVirtualMCApplication::Instance())->Stepping();
2501 //______________________________________________________________________________
2502 void TFluka::AddParticlesToPdgDataBase() const
2506 // Add particles to the PDG data base
2508 TDatabasePDG *pdgDB = TDatabasePDG::Instance();
2510 const Double_t kAu2Gev = 0.9314943228;
2511 const Double_t khSlash = 1.0545726663e-27;
2512 const Double_t kErg2Gev = 1/1.6021773349e-3;
2513 const Double_t khShGev = khSlash*kErg2Gev;
2514 const Double_t kYear2Sec = 3600*24*365.25;
2518 pdgDB->AddParticle("Deuteron","Deuteron",2*kAu2Gev+8.071e-3,kTRUE,
2519 0,3,"Ion",GetIonPdg(1,2));
2520 pdgDB->AddParticle("Triton","Triton",3*kAu2Gev+14.931e-3,kFALSE,
2521 khShGev/(12.33*kYear2Sec),3,"Ion",GetIonPdg(1,3));
2522 pdgDB->AddParticle("Alpha","Alpha",4*kAu2Gev+2.424e-3,kTRUE,
2523 khShGev/(12.33*kYear2Sec),6,"Ion",GetIonPdg(2,4));
2524 pdgDB->AddParticle("HE3","HE3",3*kAu2Gev+14.931e-3,kFALSE,
2525 0,6,"Ion",GetIonPdg(2,3));
2529 // Info about primary ionization electrons
2532 //______________________________________________________________________________
2533 Int_t TFluka::GetNPrimaryElectrons()
2535 // Get number of primary electrons
2536 return ALLDLT.nalldl;
2539 //______________________________________________________________________________
2540 Double_t TFluka::GetPrimaryElectronKineticEnergy(Int_t i) const
2542 // Returns kinetic energy of primary electron i
2544 Double_t ekin = -1.;
2546 if (i >= 0 && i < ALLDLT.nalldl) {
2547 ekin = ALLDLT.talldl[i];
2549 Warning("GetPrimaryElectronKineticEnergy",
2550 "Primary electron index out of range %d %d \n",
2556 void TFluka::GetPrimaryElectronPosition(Int_t i, Double_t& x, Double_t& y, Double_t& z) const
2558 // Returns position of primary electron i
2559 if (i >= 0 && i < ALLDLT.nalldl) {
2560 x = ALLDLT.xalldl[i];
2561 y = ALLDLT.yalldl[i];
2562 z = ALLDLT.zalldl[i];
2565 Warning("GetPrimaryElectronPosition",
2566 "Primary electron index out of range %d %d \n",
2573 Int_t TFluka::GetIonPdg(Int_t z, Int_t a, Int_t i) const
2576 // http://cepa.fnal.gov/psm/stdhep/pdg/montecarlorpp-2006.pdf
2578 return 1000000000 + 10*1000*z + 10*a + i;
2581 void TFluka::PrimaryIonisationStepping(Int_t nprim)
2583 // Call Stepping for primary ionisation electrons
2585 // Protection against nprim > mxalld
2587 // Multiple steps for nprim > 0
2589 for (i = 0; i < nprim; i++) {
2590 SetCurrentPrimaryElectronIndex(i);
2591 (TVirtualMCApplication::Instance())->Stepping();
2592 if (i == 0) SetTrackIsNew(kFALSE);
2595 // No primary electron ionisation
2596 // Call Stepping anyway but flag nprim = 0 as index = -2
2597 SetCurrentPrimaryElectronIndex(-2);
2598 (TVirtualMCApplication::Instance())->Stepping();
2601 SetCurrentPrimaryElectronIndex(-1);
2604 //______________________________________________________________________
2605 Float_t* TFluka::CreateFloatArray(Double_t* array, Int_t size) const
2607 // Converts Double_t* array to Float_t*,
2608 // !! The new array has to be deleted by user.
2611 Float_t* floatArray;
2613 floatArray = new Float_t[size];
2614 for (Int_t i=0; i<size; i++)
2615 if (array[i] >= FLT_MAX )
2616 floatArray[i] = FLT_MAX/100.;
2618 floatArray[i] = array[i];
2622 floatArray = new Float_t[1];