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>
35 #include "TFlukaCodes.h"
36 #include "TCallf77.h" //For the fortran calls
37 #include "Fdblprc.h" //(DBLPRC) fluka common
38 #include "Fsourcm.h" //(SOURCM) fluka common
39 #include "Fgenstk.h" //(GENSTK) fluka common
40 #include "Fiounit.h" //(IOUNIT) fluka common
41 #include "Fpaprop.h" //(PAPROP) fluka common
42 #include "Fpart.h" //(PART) fluka common
43 #include "Ftrackr.h" //(TRACKR) fluka common
44 #include "Fpaprop.h" //(PAPROP) fluka common
45 #include "Ffheavy.h" //(FHEAVY) fluka common
46 #include "Fopphst.h" //(OPPHST) fluka common
47 #include "Fflkstk.h" //(FLKSTK) fluka common
48 #include "Fstepsz.h" //(STEPSZ) fluka common
49 #include "Fopphst.h" //(OPPHST) fluka common
50 #include "Fltclcm.h" //(LTCLCM) fluka common
52 #include "TVirtualMC.h"
53 #include "TMCProcess.h"
54 #include "TGeoManager.h"
55 #include "TGeoMaterial.h"
56 #include "TGeoMedium.h"
57 #include "TFlukaMCGeometry.h"
58 #include "TGeoMCGeometry.h"
59 #include "TFlukaCerenkov.h"
60 #include "TFlukaConfigOption.h"
61 #include "TFlukaScoringOption.h"
62 #include "TLorentzVector.h"
65 #include "TDatabasePDG.h"
67 // Fluka methods that may be needed.
69 # define flukam flukam_
70 # define fluka_openinp fluka_openinp_
71 # define fluka_openout fluka_openout_
72 # define fluka_closeinp fluka_closeinp_
73 # define mcihad mcihad_
74 # define mpdgha mpdgha_
75 # define newplo newplo_
77 # define flukam FLUKAM
78 # define fluka_openinp FLUKA_OPENINP
79 # define fluka_openout FLUKA_OPENOUT
80 # define fluka_closeinp FLUKA_CLOSEINP
81 # define mcihad MCIHAD
82 # define mpdgha MPDGHA
83 # define newplo NEWPLO
89 // Prototypes for FLUKA functions
91 void type_of_call flukam(const int&);
92 void type_of_call newplo();
93 void type_of_call fluka_openinp(const int&, DEFCHARA);
94 void type_of_call fluka_openout(const int&, DEFCHARA);
95 void type_of_call fluka_closeinp(const int&);
96 int type_of_call mcihad(const int&);
97 int type_of_call mpdgha(const int&);
101 // Class implementation for ROOT
106 //----------------------------------------------------------------------------
107 // TFluka constructors and destructors.
108 //______________________________________________________________________________
117 // Default constructor
119 fGeneratePemf = kFALSE;
121 fCurrentFlukaRegion = -1;
134 //______________________________________________________________________________
135 TFluka::TFluka(const char *title, Int_t verbosity, Bool_t isRootGeometrySupported)
136 :TVirtualMC("TFluka",title, isRootGeometrySupported),
137 fVerbosityLevel(verbosity),
142 fUserConfig(new TObjArray(100)),
143 fUserScore(new TObjArray(100))
145 // create geometry interface
146 if (fVerbosityLevel >=3)
147 cout << "<== TFluka::TFluka(" << title << ") constructor called." << endl;
148 SetCoreInputFileName();
150 SetGeneratePemf(kFALSE);
152 fCurrentFlukaRegion = -1;
156 fGeneratePemf = kFALSE;
157 fMCGeo = new TGeoMCGeometry("MCGeo", "TGeo Implementation of VirtualMCGeometry", kFALSE);
158 fGeom = new TFlukaMCGeometry("geom", "FLUKA VMC Geometry");
159 if (verbosity > 2) fGeom->SetDebugMode(kTRUE);
168 //______________________________________________________________________________
171 if (fVerbosityLevel >=3)
172 cout << "<== TFluka::~TFluka() destructor called." << endl;
178 fUserConfig->Delete();
183 fUserScore->Delete();
189 //______________________________________________________________________________
190 // TFluka control methods
191 //______________________________________________________________________________
192 void TFluka::Init() {
194 // Geometry initialisation
196 if (fVerbosityLevel >=3) cout << "==> TFluka::Init() called." << endl;
198 if (!gGeoManager) new TGeoManager("geom", "FLUKA geometry");
199 fApplication->ConstructGeometry();
200 if (!gGeoManager->IsClosed()) {
201 TGeoVolume *top = (TGeoVolume*)gGeoManager->GetListOfVolumes()->First();
202 gGeoManager->SetTopVolume(top);
203 gGeoManager->CloseGeometry("di");
205 TGeoNodeCache *cache = gGeoManager->GetCache();
206 if (!cache->HasIdArray()) {
207 Warning("Init", "Node ID tracking must be enabled with TFluka: enabling...\n");
208 cache->BuildIdArray();
211 fNVolumes = fGeom->NofVolumes();
212 fGeom->CreateFlukaMatFile("flukaMat.inp");
213 if (fVerbosityLevel >=3) {
214 printf("== Number of volumes: %i\n ==", fNVolumes);
215 cout << "\t* InitPhysics() - Prepare input file to be called" << endl;
218 fApplication->InitGeometry();
221 // Add ions to PDG Data base
223 AddParticlesToPdgDataBase();
227 //______________________________________________________________________________
228 void TFluka::FinishGeometry() {
230 // Build-up table with region to medium correspondance
232 if (fVerbosityLevel >=3) {
233 cout << "==> TFluka::FinishGeometry() called." << endl;
234 printf("----FinishGeometry - nothing to do with TGeo\n");
235 cout << "<== TFluka::FinishGeometry() called." << endl;
239 //______________________________________________________________________________
240 void TFluka::BuildPhysics() {
242 // Prepare FLUKA input files and call FLUKA physics initialisation
245 if (fVerbosityLevel >=3)
246 cout << "==> TFluka::BuildPhysics() called." << endl;
249 if (fVerbosityLevel >=3) {
250 TList *medlist = gGeoManager->GetListOfMedia();
252 TGeoMedium* med = 0x0;
253 TGeoMaterial* mat = 0x0;
256 while((med = (TGeoMedium*)next()))
258 mat = med->GetMaterial();
259 printf("Medium %5d %12s %5d %5d\n", ic, (med->GetName()), med->GetId(), mat->GetIndex());
265 // At this stage we have the information on materials and cuts available.
266 // Now create the pemf file
268 if (fGeneratePemf) fGeom->CreatePemfFile();
271 // Prepare input file with the current physics settings
274 // Open fortran files
275 const char* fname = fInputFileName;
276 fluka_openinp(lunin, PASSCHARA(fname));
277 fluka_openout(11, PASSCHARA("fluka.out"));
279 GLOBAL.lfdrtr = true;
282 fluka_closeinp(lunin);
287 //______________________________________________________________________________
288 void TFluka::ProcessEvent() {
293 Warning("ProcessEvent", "User Run Abortion: No more events handled !\n");
298 if (fVerbosityLevel >=3)
299 cout << "==> TFluka::ProcessEvent() called." << endl;
300 fApplication->GeneratePrimaries();
301 SOURCM.lsouit = true;
303 if (fVerbosityLevel >=3)
304 cout << "<== TFluka::ProcessEvent() called." << endl;
306 // Increase event number
311 //______________________________________________________________________________
312 Bool_t TFluka::ProcessRun(Int_t nevent) {
317 if (fVerbosityLevel >=3)
318 cout << "==> TFluka::ProcessRun(" << nevent << ") called."
321 if (fVerbosityLevel >=2) {
322 cout << "\t* GLOBAL.fdrtr = " << (GLOBAL.lfdrtr?'T':'F') << endl;
323 cout << "\t* Calling flukam again..." << endl;
326 Int_t todo = TMath::Abs(nevent);
327 for (Int_t ev = 0; ev < todo; ev++) {
328 fApplication->BeginEvent();
330 fApplication->FinishEvent();
333 if (fVerbosityLevel >=3)
334 cout << "<== TFluka::ProcessRun(" << nevent << ") called."
336 // Write fluka specific scoring output
342 //_____________________________________________________________________________
343 // methods for building/management of geometry
345 // functions from GCONS
346 //____________________________________________________________________________
347 void TFluka::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,
348 Float_t &dens, Float_t &radl, Float_t &absl,
349 Float_t* /*ubuf*/, Int_t& /*nbuf*/) {
352 TIter next (gGeoManager->GetListOfMaterials());
353 while ((mat = (TGeoMaterial*)next())) {
354 if (mat->GetUniqueID() == (UInt_t)imat) break;
357 Error("Gfmate", "no material with index %i found", imat);
360 sprintf(name, "%s", mat->GetName());
363 dens = mat->GetDensity();
364 radl = mat->GetRadLen();
365 absl = mat->GetIntLen();
368 //______________________________________________________________________________
369 void TFluka::Gfmate(Int_t imat, char *name, Double_t &a, Double_t &z,
370 Double_t &dens, Double_t &radl, Double_t &absl,
371 Double_t* /*ubuf*/, Int_t& /*nbuf*/) {
374 TIter next (gGeoManager->GetListOfMaterials());
375 while ((mat = (TGeoMaterial*)next())) {
376 if (mat->GetUniqueID() == (UInt_t)imat) break;
379 Error("Gfmate", "no material with index %i found", imat);
382 sprintf(name, "%s", mat->GetName());
385 dens = mat->GetDensity();
386 radl = mat->GetRadLen();
387 absl = mat->GetIntLen();
390 // detector composition
391 //______________________________________________________________________________
392 void TFluka::Material(Int_t& kmat, const char* name, Double_t a,
393 Double_t z, Double_t dens, Double_t radl, Double_t absl,
394 Float_t* buf, Int_t nwbuf) {
396 Double_t* dbuf = fGeom->CreateDoubleArray(buf, nwbuf);
397 Material(kmat, name, a, z, dens, radl, absl, dbuf, nwbuf);
401 //______________________________________________________________________________
402 void TFluka::Material(Int_t& kmat, const char* name, Double_t a,
403 Double_t z, Double_t dens, Double_t radl, Double_t absl,
404 Double_t* /*buf*/, Int_t /*nwbuf*/) {
408 kmat = gGeoManager->GetListOfMaterials()->GetSize();
409 if ((z-Int_t(z)) > 1E-3) {
410 mat = fGeom->GetMakeWrongMaterial(z);
412 mat->SetRadLen(radl,absl);
413 mat->SetUniqueID(kmat);
417 gGeoManager->Material(name, a, z, dens, kmat, radl, absl);
420 //______________________________________________________________________________
421 void TFluka::Mixture(Int_t& kmat, const char *name, Float_t *a,
422 Float_t *z, Double_t dens, Int_t nlmat, Float_t *wmat) {
424 // Define a material mixture
426 Double_t* da = fGeom->CreateDoubleArray(a, TMath::Abs(nlmat));
427 Double_t* dz = fGeom->CreateDoubleArray(z, TMath::Abs(nlmat));
428 Double_t* dwmat = fGeom->CreateDoubleArray(wmat, TMath::Abs(nlmat));
430 Mixture(kmat, name, da, dz, dens, nlmat, dwmat);
431 for (Int_t i=0; i<nlmat; i++) {
432 a[i] = da[i]; z[i] = dz[i]; wmat[i] = dwmat[i];
440 //______________________________________________________________________________
441 void TFluka::Mixture(Int_t& kmat, const char *name, Double_t *a,
442 Double_t *z, Double_t dens, Int_t nlmat, Double_t *wmat) {
444 // Defines mixture OR COMPOUND IMAT as composed by
445 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
447 // If NLMAT > 0 then wmat contains the proportion by
448 // weights of each basic material in the mixture.
450 // If nlmat < 0 then WMAT contains the number of atoms
451 // of a given kind into the molecule of the COMPOUND
452 // In this case, WMAT in output is changed to relative
459 for (i=0;i<nlmat;i++) {
460 amol += a[i]*wmat[i];
462 for (i=0;i<nlmat;i++) {
463 wmat[i] *= a[i]/amol;
466 kmat = gGeoManager->GetListOfMaterials()->GetSize();
467 // Check if we have elements with fractional Z
468 TGeoMaterial *mat = 0;
469 TGeoMixture *mix = 0;
470 Bool_t mixnew = kFALSE;
471 for (i=0; i<nlmat; i++) {
472 if (z[i]-Int_t(z[i]) < 1E-3) continue;
473 // We have found an element with fractional Z -> loop mixtures to look for it
474 for (j=0; j<kmat; j++) {
475 mat = (TGeoMaterial*)gGeoManager->GetListOfMaterials()->At(j);
477 if (!mat->IsMixture()) continue;
478 mix = (TGeoMixture*)mat;
479 if (TMath::Abs(z[i]-mix->GetZ()) >1E-3) continue;
483 if (!mixnew) Warning("Mixture","%s : cannot find component %i with fractional Z=%f\n", name, i, z[i]);
487 Int_t nlmatnew = nlmat+mix->GetNelements()-1;
488 Double_t *anew = new Double_t[nlmatnew];
489 Double_t *znew = new Double_t[nlmatnew];
490 Double_t *wmatnew = new Double_t[nlmatnew];
492 for (j=0; j<nlmat; j++) {
496 wmatnew[ind] = wmat[j];
499 for (j=0; j<mix->GetNelements(); j++) {
500 anew[ind] = mix->GetAmixt()[j];
501 znew[ind] = mix->GetZmixt()[j];
502 wmatnew[ind] = wmat[i]*mix->GetWmixt()[j];
505 Mixture(kmat, name, anew, znew, dens, nlmatnew, wmatnew);
511 // Now we need to compact identical elements within the mixture
512 // First check if this happens
514 for (i=0; i<nlmat-1; i++) {
515 for (j=i+1; j<nlmat; j++) {
525 Double_t *anew = new Double_t[nlmat];
526 Double_t *znew = new Double_t[nlmat];
527 memset(znew, 0, nlmat*sizeof(Double_t));
528 Double_t *wmatnew = new Double_t[nlmat];
530 for (i=0; i<nlmat; i++) {
532 for (j=0; j<nlmatnew; j++) {
534 wmatnew[j] += wmat[i];
540 anew[nlmatnew] = a[i];
541 znew[nlmatnew] = z[i];
542 wmatnew[nlmatnew] = wmat[i];
545 Mixture(kmat, name, anew, znew, dens, nlmatnew, wmatnew);
551 gGeoManager->Mixture(name, a, z, dens, nlmat, wmat, kmat);
554 //______________________________________________________________________________
555 void TFluka::Medium(Int_t& kmed, const char *name, Int_t nmat,
556 Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd,
557 Double_t stemax, Double_t deemax, Double_t epsil,
558 Double_t stmin, Float_t* ubuf, Int_t nbuf) {
561 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
562 fMCGeo->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
563 epsil, stmin, ubuf, nbuf);
566 //______________________________________________________________________________
567 void TFluka::Medium(Int_t& kmed, const char *name, Int_t nmat,
568 Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd,
569 Double_t stemax, Double_t deemax, Double_t epsil,
570 Double_t stmin, Double_t* ubuf, Int_t nbuf) {
573 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
574 fMCGeo->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
575 epsil, stmin, ubuf, nbuf);
578 //______________________________________________________________________________
579 void TFluka::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
580 Double_t thetaY, Double_t phiY, Double_t thetaZ,
583 krot = gGeoManager->GetListOfMatrices()->GetEntriesFast();
584 fMCGeo->Matrix(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
587 //______________________________________________________________________________
588 void TFluka::Gstpar(Int_t itmed, const char* param, Double_t parval) {
592 Bool_t process = kFALSE;
593 if (strncmp(param, "DCAY", 4) == 0 ||
594 strncmp(param, "PAIR", 4) == 0 ||
595 strncmp(param, "COMP", 4) == 0 ||
596 strncmp(param, "PHOT", 4) == 0 ||
597 strncmp(param, "PFIS", 4) == 0 ||
598 strncmp(param, "DRAY", 4) == 0 ||
599 strncmp(param, "ANNI", 4) == 0 ||
600 strncmp(param, "BREM", 4) == 0 ||
601 strncmp(param, "MUNU", 4) == 0 ||
602 strncmp(param, "CKOV", 4) == 0 ||
603 strncmp(param, "HADR", 4) == 0 ||
604 strncmp(param, "LOSS", 4) == 0 ||
605 strncmp(param, "MULS", 4) == 0 ||
606 strncmp(param, "RAYL", 4) == 0)
612 SetProcess(param, Int_t (parval), itmed);
614 SetCut(param, parval, itmed);
618 // functions from GGEOM
619 //_____________________________________________________________________________
620 void TFluka::Gsatt(const char *name, const char *att, Int_t val)
622 // Set visualisation attributes for one volume
624 fGeom->Vname(name,vname);
626 fGeom->Vname(att,vatt);
627 gGeoManager->SetVolumeAttribute(vname, vatt, val);
630 //______________________________________________________________________________
631 Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
632 Float_t *upar, Int_t np) {
634 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
637 //______________________________________________________________________________
638 Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
639 Double_t *upar, Int_t np) {
641 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
644 //______________________________________________________________________________
645 void TFluka::Gsdvn(const char *name, const char *mother, Int_t ndiv,
648 fMCGeo->Gsdvn(name, mother, ndiv, iaxis);
651 //______________________________________________________________________________
652 void TFluka::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
653 Int_t iaxis, Double_t c0i, Int_t numed) {
655 fMCGeo->Gsdvn2(name, mother, ndiv, iaxis, c0i, numed);
658 //______________________________________________________________________________
659 void TFluka::Gsdvt(const char *name, const char *mother, Double_t step,
660 Int_t iaxis, Int_t numed, Int_t ndvmx) {
662 fMCGeo->Gsdvt(name, mother, step, iaxis, numed, ndvmx);
665 //______________________________________________________________________________
666 void TFluka::Gsdvt2(const char *name, const char *mother, Double_t step,
667 Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx) {
669 fMCGeo->Gsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
672 //______________________________________________________________________________
673 void TFluka::Gsord(const char * /*name*/, Int_t /*iax*/) {
675 // Nothing to do with TGeo
678 //______________________________________________________________________________
679 void TFluka::Gspos(const char *name, Int_t nr, const char *mother,
680 Double_t x, Double_t y, Double_t z, Int_t irot,
683 fMCGeo->Gspos(name, nr, mother, x, y, z, irot, konly);
686 //______________________________________________________________________________
687 void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
688 Double_t x, Double_t y, Double_t z, Int_t irot,
689 const char *konly, Float_t *upar, Int_t np) {
691 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
694 //______________________________________________________________________________
695 void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
696 Double_t x, Double_t y, Double_t z, Int_t irot,
697 const char *konly, Double_t *upar, Int_t np) {
699 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
702 //______________________________________________________________________________
703 void TFluka::Gsbool(const char* /*onlyVolName*/, const char* /*manyVolName*/) {
705 // Nothing to do with TGeo
708 //______________________________________________________________________
709 Bool_t TFluka::GetTransformation(const TString &volumePath,TGeoHMatrix &mat)
711 // Returns the Transformation matrix between the volume specified
712 // by the path volumePath and the Top or mater volume. The format
713 // of the path volumePath is as follows (assuming ALIC is the Top volume)
714 // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
715 // or master volume which has only 1 instance of. Of all of the daughter
716 // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
717 // the daughter volume of DDIP is S05I copy #2 and so on.
719 // TString& volumePath The volume path to the specific volume
720 // for which you want the matrix. Volume name
721 // hierarchy is separated by "/" while the
722 // copy number is appended using a "_".
724 // TGeoHMatrix &mat A matrix with its values set to those
725 // appropriate to the Local to Master transformation
727 // A logical value if kFALSE then an error occurred and no change to
730 // We have to preserve the modeler state
731 return fMCGeo->GetTransformation(volumePath, mat);
734 //______________________________________________________________________
735 Bool_t TFluka::GetShape(const TString &volumePath,TString &shapeType,
738 // Returns the shape and its parameters for the volume specified
741 // TString& volumeName The volume name
743 // TString &shapeType Shape type
744 // TArrayD &par A TArrayD of parameters with all of the
745 // parameters of the specified shape.
747 // A logical indicating whether there was an error in getting this
749 return fMCGeo->GetShape(volumePath, shapeType, par);
752 //______________________________________________________________________
753 Bool_t TFluka::GetMaterial(const TString &volumeName,
754 TString &name,Int_t &imat,
755 Double_t &a,Double_t &z,Double_t &dens,
756 Double_t &radl,Double_t &inter,TArrayD &par)
758 // Returns the Material and its parameters for the volume specified
760 // Note, Geant3 stores and uses mixtures as an element with an effective
761 // Z and A. Consequently, if the parameter Z is not integer, then
762 // this material represents some sort of mixture.
764 // TString& volumeName The volume name
766 // TSrting &name Material name
767 // Int_t &imat Material index number
768 // Double_t &a Average Atomic mass of material
769 // Double_t &z Average Atomic number of material
770 // Double_t &dens Density of material [g/cm^3]
771 // Double_t &radl Average radiation length of material [cm]
772 // Double_t &inter Average interaction length of material [cm]
773 // TArrayD &par A TArrayD of user defined parameters.
775 // kTRUE if no errors
776 return fMCGeo->GetMaterial(volumeName,name,imat,a,z,dens,radl,inter,par);
779 //______________________________________________________________________
780 Bool_t TFluka::GetMedium(const TString &volumeName,TString &name,
781 Int_t &imed,Int_t &nmat,Int_t &isvol,Int_t &ifield,
782 Double_t &fieldm,Double_t &tmaxfd,Double_t &stemax,
783 Double_t &deemax,Double_t &epsil, Double_t &stmin,
786 // Returns the Medium and its parameters for the volume specified
789 // TString& volumeName The volume name.
791 // TString &name Medium name
792 // Int_t &nmat Material number defined for this medium
793 // Int_t &imed The medium index number
794 // Int_t &isvol volume number defined for this medium
795 // Int_t &iflield Magnetic field flag
796 // Double_t &fieldm Magnetic field strength
797 // Double_t &tmaxfd Maximum angle of deflection per step
798 // Double_t &stemax Maximum step size
799 // Double_t &deemax Maximum fraction of energy allowed to be lost
800 // to continuous process.
801 // Double_t &epsil Boundary crossing precision
802 // Double_t &stmin Minimum step size allowed
803 // TArrayD &par A TArrayD of user parameters with all of the
804 // parameters of the specified medium.
806 // kTRUE if there where no errors
807 return fMCGeo->GetMedium(volumeName,name,imed,nmat,isvol,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin,par);
810 //______________________________________________________________________________
811 void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
812 Float_t* absco, Float_t* effic, Float_t* rindex) {
814 // Set Cerenkov properties for medium itmed
816 // npckov: number of sampling points
817 // ppckov: energy values
818 // absco: absorption length
819 // effic: quantum efficiency
820 // rindex: refraction index
824 // Create object holding Cerenkov properties
826 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex);
828 // Pass object to medium
829 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
830 medium->SetCerenkovProperties(cerenkovProperties);
833 void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
834 Float_t* absco, Float_t* effic, Float_t* rindex, Float_t* rfl) {
836 // Set Cerenkov properties for medium itmed
838 // npckov: number of sampling points
839 // ppckov: energy values
840 // absco: absorption length
841 // effic: quantum efficiency
842 // rindex: refraction index
843 // rfl: reflectivity for boundary to medium itmed
846 // Create object holding Cerenkov properties
848 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex, rfl);
850 // Pass object to medium
851 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
852 medium->SetCerenkovProperties(cerenkovProperties);
856 //______________________________________________________________________________
857 void TFluka::SetCerenkov(Int_t /*itmed*/, Int_t /*npckov*/, Double_t * /*ppckov*/,
858 Double_t * /*absco*/, Double_t * /*effic*/, Double_t * /*rindex*/) {
860 // Double_t version not implemented
863 void TFluka::SetCerenkov(Int_t /*itmed*/, Int_t /*npckov*/, Double_t* /*ppckov*/,
864 Double_t* /*absco*/, Double_t* /*effic*/, Double_t* /*rindex*/, Double_t* /*rfl*/) {
866 // // Double_t version not implemented
870 //______________________________________________________________________________
871 void TFluka::WriteEuclid(const char* /*fileName*/, const char* /*topVol*/,
872 Int_t /*number*/, Int_t /*nlevel*/) {
875 Warning("WriteEuclid", "Not implemented !");
880 //_____________________________________________________________________________
881 // methods needed by the stepping
882 //____________________________________________________________________________
884 Int_t TFluka::GetMedium() const {
886 // Get the medium number for the current fluka region
888 return fGeom->GetMedium(); // this I need to check due to remapping !!!
891 //____________________________________________________________________________
892 Int_t TFluka::GetDummyRegion() const
894 // Returns index of the dummy region.
895 return fGeom->GetDummyRegion();
898 //____________________________________________________________________________
899 Int_t TFluka::GetDummyLattice() const
901 // Returns index of the dummy lattice.
902 return fGeom->GetDummyLattice();
905 //____________________________________________________________________________
906 // particle table usage
907 // ID <--> PDG transformations
908 //_____________________________________________________________________________
909 Int_t TFluka::IdFromPDG(Int_t pdg) const
912 // Return Fluka code from PDG and pseudo ENDF code
914 // Catch the feedback photons
915 if (pdg == 50000051) return (kFLUKAoptical);
916 // MCIHAD() goes from pdg to fluka internal.
917 Int_t intfluka = mcihad(pdg);
918 // KPTOIP array goes from internal to official
919 return GetFlukaKPTOIP(intfluka);
922 //______________________________________________________________________________
923 Int_t TFluka::PDGFromId(Int_t id) const
926 // Return PDG code and pseudo ENDF code from Fluka code
927 // Alpha He3 Triton Deuteron gen. ion opt. photon
928 Int_t idSpecial[6] = {10020040, 10020030, 10010030, 10010020, 10000000, 50000050};
929 // IPTOKP array goes from official to internal
931 if (id == kFLUKAoptical) {
933 if (fVerbosityLevel >= 3)
934 printf("\n PDGFromId: Cerenkov Photon \n");
938 if (id == 0 || id < kFLUKAcodemin || id > kFLUKAcodemax) {
939 if (fVerbosityLevel >= 3)
940 printf("PDGFromId: Error id = 0\n");
945 Int_t intfluka = GetFlukaIPTOKP(id);
947 if (fVerbosityLevel >= 3)
948 printf("PDGFromId: Error intfluka = 0: %d\n", id);
950 } else if (intfluka < 0) {
951 if (fVerbosityLevel >= 3)
952 printf("PDGFromId: Error intfluka < 0: %d\n", id);
955 // if (fVerbosityLevel >= 3)
956 // printf("mpdgha called with %d %d \n", id, intfluka);
957 return mpdgha(intfluka);
959 // ions and optical photons
960 return idSpecial[id - kFLUKAcodemin];
964 void TFluka::StopTrack()
966 // Set stopping conditions
967 // Works for photons and charged particles
971 //_____________________________________________________________________________
972 // methods for physics management
973 //____________________________________________________________________________
978 void TFluka::SetProcess(const char* flagName, Int_t flagValue, Int_t imed)
980 // Set process user flag for material imat
983 // Update if already in the list
985 TIter next(fUserConfig);
986 TFlukaConfigOption* proc;
987 while((proc = (TFlukaConfigOption*)next()))
989 if (proc->Medium() == imed) {
990 proc->SetProcess(flagName, flagValue);
994 proc = new TFlukaConfigOption(imed);
995 proc->SetProcess(flagName, flagValue);
996 fUserConfig->Add(proc);
999 //______________________________________________________________________________
1000 Bool_t TFluka::SetProcess(const char* flagName, Int_t flagValue)
1002 // Set process user flag
1005 SetProcess(flagName, flagValue, -1);
1009 //______________________________________________________________________________
1010 void TFluka::SetCut(const char* cutName, Double_t cutValue, Int_t imed)
1012 // Set user cut value for material imed
1014 TIter next(fUserConfig);
1015 TFlukaConfigOption* proc;
1016 while((proc = (TFlukaConfigOption*)next()))
1018 if (proc->Medium() == imed) {
1019 proc->SetCut(cutName, cutValue);
1024 proc = new TFlukaConfigOption(imed);
1025 proc->SetCut(cutName, cutValue);
1026 fUserConfig->Add(proc);
1029 //______________________________________________________________________________
1030 Bool_t TFluka::SetCut(const char* cutName, Double_t cutValue)
1032 // Set user cut value
1035 SetCut(cutName, cutValue, -1);
1040 void TFluka::SetUserScoring(const char* option, Int_t npr, char* outfile, Float_t* what)
1043 // Adds a user scoring option to the list
1045 TFlukaScoringOption* opt = new TFlukaScoringOption(option, "User Scoring", npr,outfile,what);
1046 fUserScore->Add(opt);
1048 //______________________________________________________________________________
1049 void TFluka::SetUserScoring(const char* option, Int_t npr, char* outfile, Float_t* what, const char* det1, const char* det2, const char* det3)
1052 // Adds a user scoring option to the list
1054 TFlukaScoringOption* opt = new TFlukaScoringOption(option, "User Scoring", npr, outfile, what, det1, det2, det3);
1055 fUserScore->Add(opt);
1058 //______________________________________________________________________________
1059 Double_t TFluka::Xsec(char*, Double_t, Int_t, Int_t)
1061 Warning("Xsec", "Not yet implemented.!\n"); return -1.;
1065 //______________________________________________________________________________
1066 void TFluka::InitPhysics()
1069 // Physics initialisation with preparation of FLUKA input cards
1071 // Construct file names
1072 FILE *pFlukaVmcCoreInp, *pFlukaVmcFlukaMat, *pFlukaVmcInp;
1073 TString sFlukaVmcCoreInp = getenv("ALICE_ROOT");
1074 sFlukaVmcCoreInp +="/TFluka/input/";
1075 TString sFlukaVmcTmp = "flukaMat.inp";
1076 TString sFlukaVmcInp = GetInputFileName();
1077 sFlukaVmcCoreInp += GetCoreInputFileName();
1080 if ((pFlukaVmcCoreInp = fopen(sFlukaVmcCoreInp.Data(),"r")) == NULL) {
1081 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcCoreInp.Data());
1084 if ((pFlukaVmcFlukaMat = fopen(sFlukaVmcTmp.Data(),"r")) == NULL) {
1085 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcTmp.Data());
1088 if ((pFlukaVmcInp = fopen(sFlukaVmcInp.Data(),"w")) == NULL) {
1089 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcInp.Data());
1093 // Copy core input file
1095 Float_t fEventsPerRun;
1097 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
1098 if (strncmp(sLine,"GEOEND",6) != 0)
1099 fprintf(pFlukaVmcInp,"%s",sLine); // copy until GEOEND card
1101 fprintf(pFlukaVmcInp,"GEOEND\n"); // add GEOEND card
1104 } // end of while until GEOEND card
1108 while ((fgets(sLine,255,pFlukaVmcFlukaMat)) != NULL) { // copy flukaMat.inp file
1109 fprintf(pFlukaVmcInp,"%s\n",sLine);
1112 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
1113 if (strncmp(sLine,"START",5) != 0)
1114 fprintf(pFlukaVmcInp,"%s\n",sLine);
1116 sscanf(sLine+10,"%10f",&fEventsPerRun);
1119 } //end of while until START card
1124 // Pass information to configuration objects
1126 Float_t fLastMaterial = fGeom->GetLastMaterialIndex();
1127 TFlukaConfigOption::SetStaticInfo(pFlukaVmcInp, 3, fLastMaterial, fGeom);
1129 TIter next(fUserConfig);
1130 TFlukaConfigOption* proc;
1131 while((proc = dynamic_cast<TFlukaConfigOption*> (next()))) proc->WriteFlukaInputCards();
1133 // Process Fluka specific scoring options
1135 TFlukaScoringOption::SetStaticInfo(pFlukaVmcInp, fGeom);
1136 Float_t loginp = 49.0;
1138 Int_t nscore = fUserScore->GetEntries();
1140 TFlukaScoringOption *mopo = 0;
1141 TFlukaScoringOption *mopi = 0;
1143 for (Int_t isc = 0; isc < nscore; isc++)
1145 mopo = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isc));
1146 char* fileName = mopo->GetFileName();
1147 Int_t size = strlen(fileName);
1150 // Check if new output file has to be opened
1151 for (Int_t isci = 0; isci < isc; isci++) {
1154 mopi = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isci));
1155 if(strncmp(mopi->GetFileName(), fileName, size)==0) {
1157 // No, the file already exists
1158 lun = mopi->GetLun();
1165 // Open new output file
1167 mopo->SetLun(loginp + inp);
1168 mopo->WriteOpenFlukaFile();
1170 mopo->WriteFlukaInputCards();
1173 // Add RANDOMIZ card
1174 fprintf(pFlukaVmcInp,"RANDOMIZ %10.1f%10.0f\n", 1., Float_t(gRandom->GetSeed()));
1175 // Add START and STOP card
1176 fprintf(pFlukaVmcInp,"START %10.1f\n",fEventsPerRun);
1177 fprintf(pFlukaVmcInp,"STOP \n");
1181 fclose(pFlukaVmcCoreInp);
1182 fclose(pFlukaVmcFlukaMat);
1183 fclose(pFlukaVmcInp);
1187 // Initialisation needed for Cerenkov photon production and transport
1188 TObjArray *matList = GetFlukaMaterials();
1189 Int_t nmaterial = matList->GetEntriesFast();
1190 fMaterials = new Int_t[nmaterial+3];
1192 for (Int_t im = 0; im < nmaterial; im++)
1194 TGeoMaterial* material = dynamic_cast<TGeoMaterial*> (matList->At(im));
1195 Int_t idmat = material->GetIndex();
1196 fMaterials[idmat] = im;
1198 } // end of InitPhysics
1201 //______________________________________________________________________________
1202 void TFluka::SetMaxStep(Double_t step)
1204 // Set the maximum step size
1205 if (step > 1.e4) return;
1208 fGeom->GetCurrentRegion(mreg, latt);
1209 STEPSZ.stepmx[mreg - 1] = step;
1213 Double_t TFluka::MaxStep() const
1215 // Return the maximum for current medium
1217 fGeom->GetCurrentRegion(mreg, latt);
1218 return (STEPSZ.stepmx[mreg - 1]);
1221 //______________________________________________________________________________
1222 void TFluka::SetMaxNStep(Int_t)
1224 // SetMaxNStep is dummy procedure in TFluka !
1225 if (fVerbosityLevel >=3)
1226 cout << "SetMaxNStep is dummy procedure in TFluka !" << endl;
1229 //______________________________________________________________________________
1230 void TFluka::SetUserDecay(Int_t)
1232 // SetUserDecay is dummy procedure in TFluka !
1233 if (fVerbosityLevel >=3)
1234 cout << "SetUserDecay is dummy procedure in TFluka !" << endl;
1238 // dynamic properties
1240 //______________________________________________________________________________
1241 void TFluka::TrackPosition(TLorentzVector& position) const
1243 // Return the current position in the master reference frame of the
1244 // track being transported
1245 // TRACKR.atrack = age of the particle
1246 // TRACKR.xtrack = x-position of the last point
1247 // TRACKR.ytrack = y-position of the last point
1248 // TRACKR.ztrack = z-position of the last point
1249 FlukaCallerCode_t caller = GetCaller();
1250 if (caller == kENDRAW || caller == kUSDRAW ||
1251 caller == kBXExiting || caller == kBXEntering ||
1252 caller == kUSTCKV) {
1253 position.SetX(GetXsco());
1254 position.SetY(GetYsco());
1255 position.SetZ(GetZsco());
1256 position.SetT(TRACKR.atrack);
1258 else if (caller == kMGDRAW) {
1259 position.SetX(TRACKR.xtrack[TRACKR.ntrack]);
1260 position.SetY(TRACKR.ytrack[TRACKR.ntrack]);
1261 position.SetZ(TRACKR.ztrack[TRACKR.ntrack]);
1262 position.SetT(TRACKR.atrack);
1264 else if (caller == kSODRAW) {
1265 position.SetX(TRACKR.xtrack[TRACKR.ntrack]);
1266 position.SetY(TRACKR.ytrack[TRACKR.ntrack]);
1267 position.SetZ(TRACKR.ztrack[TRACKR.ntrack]);
1269 } else if (caller == kMGResumedTrack) {
1270 position.SetX(TRACKR.spausr[0]);
1271 position.SetY(TRACKR.spausr[1]);
1272 position.SetZ(TRACKR.spausr[2]);
1273 position.SetT(TRACKR.spausr[3]);
1276 Warning("TrackPosition","position not available");
1279 //______________________________________________________________________________
1280 void TFluka::TrackPosition(Double_t& x, Double_t& y, Double_t& z) const
1282 // Return the current position in the master reference frame of the
1283 // track being transported
1284 // TRACKR.atrack = age of the particle
1285 // TRACKR.xtrack = x-position of the last point
1286 // TRACKR.ytrack = y-position of the last point
1287 // TRACKR.ztrack = z-position of the last point
1288 FlukaCallerCode_t caller = GetCaller();
1289 if (caller == kENDRAW || caller == kUSDRAW ||
1290 caller == kBXExiting || caller == kBXEntering ||
1291 caller == kUSTCKV) {
1296 else if (caller == kMGDRAW || caller == kSODRAW) {
1297 x = TRACKR.xtrack[TRACKR.ntrack];
1298 y = TRACKR.ytrack[TRACKR.ntrack];
1299 z = TRACKR.ztrack[TRACKR.ntrack];
1301 else if (caller == kMGResumedTrack) {
1302 x = TRACKR.spausr[0];
1303 y = TRACKR.spausr[1];
1304 z = TRACKR.spausr[2];
1307 Warning("TrackPosition","position not available");
1310 //______________________________________________________________________________
1311 void TFluka::TrackMomentum(TLorentzVector& momentum) const
1313 // Return the direction and the momentum (GeV/c) of the track
1314 // currently being transported
1315 // TRACKR.ptrack = momentum of the particle (not always defined, if
1316 // < 0 must be obtained from etrack)
1317 // TRACKR.cx,y,ztrck = direction cosines of the current particle
1318 // TRACKR.etrack = total energy of the particle
1319 // TRACKR.jtrack = identity number of the particle
1320 // PAPROP.am[TRACKR.jtrack] = particle mass in gev
1321 FlukaCallerCode_t caller = GetCaller();
1322 FlukaProcessCode_t icode = GetIcode();
1324 if (caller != kEEDRAW && caller != kMGResumedTrack &&
1325 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
1326 if (TRACKR.ptrack >= 0) {
1327 momentum.SetPx(TRACKR.ptrack*TRACKR.cxtrck);
1328 momentum.SetPy(TRACKR.ptrack*TRACKR.cytrck);
1329 momentum.SetPz(TRACKR.ptrack*TRACKR.cztrck);
1330 momentum.SetE(TRACKR.etrack);
1334 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
1335 momentum.SetPx(p*TRACKR.cxtrck);
1336 momentum.SetPy(p*TRACKR.cytrck);
1337 momentum.SetPz(p*TRACKR.cztrck);
1338 momentum.SetE(TRACKR.etrack);
1341 } else if (caller == kMGResumedTrack) {
1342 momentum.SetPx(TRACKR.spausr[4]);
1343 momentum.SetPy(TRACKR.spausr[5]);
1344 momentum.SetPz(TRACKR.spausr[6]);
1345 momentum.SetE (TRACKR.spausr[7]);
1347 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1351 momentum.SetE(TrackMass());
1354 Warning("TrackMomentum","momentum not available");
1357 //______________________________________________________________________________
1358 void TFluka::TrackMomentum(Double_t& px, Double_t& py, Double_t& pz, Double_t& e) const
1360 // Return the direction and the momentum (GeV/c) of the track
1361 // currently being transported
1362 // TRACKR.ptrack = momentum of the particle (not always defined, if
1363 // < 0 must be obtained from etrack)
1364 // TRACKR.cx,y,ztrck = direction cosines of the current particle
1365 // TRACKR.etrack = total energy of the particle
1366 // TRACKR.jtrack = identity number of the particle
1367 // PAPROP.am[TRACKR.jtrack] = particle mass in gev
1368 FlukaCallerCode_t caller = GetCaller();
1369 FlukaProcessCode_t icode = GetIcode();
1370 if (caller != kEEDRAW && caller != kMGResumedTrack &&
1371 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
1372 if (TRACKR.ptrack >= 0) {
1373 px = TRACKR.ptrack*TRACKR.cxtrck;
1374 py = TRACKR.ptrack*TRACKR.cytrck;
1375 pz = TRACKR.ptrack*TRACKR.cztrck;
1380 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
1381 px = p*TRACKR.cxtrck;
1382 py = p*TRACKR.cytrck;
1383 pz = p*TRACKR.cztrck;
1387 } else if (caller == kMGResumedTrack) {
1388 px = TRACKR.spausr[4];
1389 py = TRACKR.spausr[5];
1390 pz = TRACKR.spausr[6];
1391 e = TRACKR.spausr[7];
1393 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1400 Warning("TrackMomentum","momentum not available");
1403 //______________________________________________________________________________
1404 Double_t TFluka::TrackStep() const
1406 // Return the length in centimeters of the current step
1407 // TRACKR.ctrack = total curved path
1408 FlukaCallerCode_t caller = GetCaller();
1409 if (caller == kBXEntering || caller == kBXExiting ||
1410 caller == kENDRAW || caller == kUSDRAW ||
1411 caller == kUSTCKV || caller == kMGResumedTrack)
1413 else if (caller == kMGDRAW)
1414 return TRACKR.ctrack;
1416 Warning("TrackStep", "track step not available");
1421 //______________________________________________________________________________
1422 Double_t TFluka::TrackLength() const
1424 // TRACKR.cmtrck = cumulative curved path since particle birth
1425 FlukaCallerCode_t caller = GetCaller();
1426 if (caller == kBXEntering || caller == kBXExiting ||
1427 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1429 return TRACKR.cmtrck;
1430 else if (caller == kMGResumedTrack)
1431 return TRACKR.spausr[8];
1433 Warning("TrackLength", "track length not available");
1438 //______________________________________________________________________________
1439 Double_t TFluka::TrackTime() const
1441 // Return the current time of flight of the track being transported
1442 // TRACKR.atrack = age of the particle
1443 FlukaCallerCode_t caller = GetCaller();
1444 if (caller == kBXEntering || caller == kBXExiting ||
1445 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1447 return TRACKR.atrack;
1448 else if (caller == kMGResumedTrack)
1449 return TRACKR.spausr[3];
1451 Warning("TrackTime", "track time not available");
1456 //______________________________________________________________________________
1457 Double_t TFluka::Edep() const
1459 // Energy deposition
1460 // if TRACKR.ntrack = 0, TRACKR.mtrack = 0:
1461 // -->local energy deposition (the value and the point are not recorded in TRACKR)
1462 // but in the variable "rull" of the procedure "endraw.cxx"
1463 // if TRACKR.ntrack > 0, TRACKR.mtrack = 0:
1464 // -->no energy loss along the track
1465 // if TRACKR.ntrack > 0, TRACKR.mtrack > 0:
1466 // -->energy loss distributed along the track
1467 // TRACKR.dtrack = energy deposition of the jth deposition event
1469 // If coming from bxdraw we have 2 steps of 0 length and 0 edep
1470 // If coming from usdraw we just signal particle production - no edep
1471 // If just first time after resuming, no edep for the primary
1472 FlukaCallerCode_t caller = GetCaller();
1473 if (caller == kBXExiting || caller == kBXEntering ||
1474 caller == kUSDRAW || caller == kMGResumedTrack) return 0.0;
1476 for ( Int_t j=0;j<TRACKR.mtrack;j++) {
1477 sum +=TRACKR.dtrack[j];
1479 if (TRACKR.ntrack == 0 && TRACKR.mtrack == 0)
1486 //______________________________________________________________________________
1487 Int_t TFluka::CorrectFlukaId() const
1489 // since we don't put photons and e- created bellow transport cut on the vmc stack
1490 // and there is a call to endraw for energy deposition for each of them
1491 // and they have the track number of their parent, but different identity (pdg)
1492 // so we want to assign also their parent identity also.
1493 if( (IsTrackStop() )
1494 && TRACKR.ispusr[mkbmx2 - 4] == TRACKR.ispusr[mkbmx2 - 1]
1495 && TRACKR.jtrack != TRACKR.ispusr[mkbmx2 - 3] ) {
1496 if (fVerbosityLevel >=3)
1497 cout << "CorrectFlukaId() for icode=" << GetIcode()
1498 << " track=" << TRACKR.ispusr[mkbmx2 - 1]
1499 << " current PDG=" << PDGFromId(TRACKR.jtrack)
1500 << " assign parent PDG=" << PDGFromId(TRACKR.ispusr[mkbmx2 - 3]) << endl;
1501 return TRACKR.ispusr[mkbmx2 - 3]; // assign parent identity
1503 return TRACKR.jtrack;
1507 //______________________________________________________________________________
1508 Int_t TFluka::TrackPid() const
1510 // Return the id of the particle transported
1511 // TRACKR.jtrack = identity number of the particle
1512 FlukaCallerCode_t caller = GetCaller();
1513 if (caller != kEEDRAW) {
1514 return PDGFromId( CorrectFlukaId() );
1520 //______________________________________________________________________________
1521 Double_t TFluka::TrackCharge() const
1523 // Return charge of the track currently transported
1524 // PAPROP.ichrge = electric charge of the particle
1525 // TRACKR.jtrack = identity number of the particle
1526 FlukaCallerCode_t caller = GetCaller();
1527 if (caller != kEEDRAW)
1528 return PAPROP.ichrge[CorrectFlukaId()+6];
1533 //______________________________________________________________________________
1534 Double_t TFluka::TrackMass() const
1536 // PAPROP.am = particle mass in GeV
1537 // TRACKR.jtrack = identity number of the particle
1538 FlukaCallerCode_t caller = GetCaller();
1539 if (caller != kEEDRAW)
1540 return PAPROP.am[CorrectFlukaId()+6];
1545 //______________________________________________________________________________
1546 Double_t TFluka::Etot() const
1548 // TRACKR.etrack = total energy of the particle
1549 FlukaCallerCode_t caller = GetCaller();
1550 if (caller != kEEDRAW)
1551 return TRACKR.etrack;
1559 //______________________________________________________________________________
1560 Bool_t TFluka::IsNewTrack() const
1562 // Return true for the first call of Stepping()
1566 void TFluka::SetTrackIsNew(Bool_t flag)
1568 // Return true for the first call of Stepping()
1574 //______________________________________________________________________________
1575 Bool_t TFluka::IsTrackInside() const
1577 // True if the track is not at the boundary of the current volume
1578 // In Fluka a step is always inside one kind of material
1579 // If the step would go behind the region of one material,
1580 // it will be shortened to reach only the boundary.
1581 // Therefore IsTrackInside() is always true.
1582 FlukaCallerCode_t caller = GetCaller();
1583 if (caller == kBXEntering || caller == kBXExiting)
1589 //______________________________________________________________________________
1590 Bool_t TFluka::IsTrackEntering() const
1592 // True if this is the first step of the track in the current volume
1594 FlukaCallerCode_t caller = GetCaller();
1595 if (caller == kBXEntering)
1600 //______________________________________________________________________________
1601 Bool_t TFluka::IsTrackExiting() const
1603 // True if track is exiting volume
1605 FlukaCallerCode_t caller = GetCaller();
1606 if (caller == kBXExiting)
1611 //______________________________________________________________________________
1612 Bool_t TFluka::IsTrackOut() const
1614 // True if the track is out of the setup
1616 FlukaProcessCode_t icode = GetIcode();
1618 if (icode == kKASKADescape ||
1619 icode == kEMFSCOescape ||
1620 icode == kKASNEUescape ||
1621 icode == kKASHEAescape ||
1622 icode == kKASOPHescape)
1627 //______________________________________________________________________________
1628 Bool_t TFluka::IsTrackDisappeared() const
1630 // All inelastic interactions and decays
1631 // fIcode from usdraw
1632 FlukaProcessCode_t icode = GetIcode();
1633 if (icode == kKASKADinelint || // inelastic interaction
1634 icode == kKASKADdecay || // particle decay
1635 icode == kKASKADdray || // delta ray generation by hadron
1636 icode == kKASKADpair || // direct pair production
1637 icode == kKASKADbrems || // bremsstrahlung (muon)
1638 icode == kEMFSCObrems || // bremsstrahlung (electron)
1639 icode == kEMFSCOmoller || // Moller scattering
1640 icode == kEMFSCObhabha || // Bhaba scattering
1641 icode == kEMFSCOanniflight || // in-flight annihilation
1642 icode == kEMFSCOannirest || // annihilation at rest
1643 icode == kEMFSCOpair || // pair production
1644 icode == kEMFSCOcompton || // Compton scattering
1645 icode == kEMFSCOphotoel || // Photoelectric effect
1646 icode == kKASNEUhadronic || // hadronic interaction
1647 icode == kKASHEAdray // delta-ray
1652 //______________________________________________________________________________
1653 Bool_t TFluka::IsTrackStop() const
1655 // True if the track energy has fallen below the threshold
1656 // means stopped by signal or below energy threshold
1657 FlukaProcessCode_t icode = GetIcode();
1658 if (icode == kKASKADstopping || // stopping particle
1659 icode == kKASKADtimekill || // time kill
1660 icode == kEMFSCOstopping1 || // below user-defined cut-off
1661 icode == kEMFSCOstopping2 || // below user cut-off
1662 icode == kEMFSCOtimekill || // time kill
1663 icode == kKASNEUstopping || // neutron below threshold
1664 icode == kKASNEUtimekill || // time kill
1665 icode == kKASHEAtimekill || // time kill
1666 icode == kKASOPHtimekill) return 1; // time kill
1670 //______________________________________________________________________________
1671 Bool_t TFluka::IsTrackAlive() const
1673 // means not disappeared or not out
1674 if (IsTrackDisappeared() || IsTrackOut() ) return 0;
1682 //______________________________________________________________________________
1683 Int_t TFluka::NSecondaries() const
1686 // Number of secondary particles generated in the current step
1687 // GENSTK.np = number of secondaries except light and heavy ions
1688 // FHEAVY.npheav = number of secondaries for light and heavy secondary ions
1689 FlukaCallerCode_t caller = GetCaller();
1690 if (caller == kUSDRAW) // valid only after usdraw
1691 return GENSTK.np + FHEAVY.npheav;
1692 else if (caller == kUSTCKV) {
1693 // Cerenkov Photon production
1697 } // end of NSecondaries
1699 //______________________________________________________________________________
1700 void TFluka::GetSecondary(Int_t isec, Int_t& particleId,
1701 TLorentzVector& position, TLorentzVector& momentum)
1703 // Copy particles from secondary stack to vmc stack
1706 FlukaCallerCode_t caller = GetCaller();
1707 if (caller == kUSDRAW) { // valid only after usdraw
1708 if (GENSTK.np > 0) {
1709 // Hadronic interaction
1710 if (isec >= 0 && isec < GENSTK.np) {
1711 particleId = PDGFromId(GENSTK.kpart[isec]);
1712 position.SetX(fXsco);
1713 position.SetY(fYsco);
1714 position.SetZ(fZsco);
1715 position.SetT(TRACKR.atrack);
1716 momentum.SetPx(GENSTK.plr[isec]*GENSTK.cxr[isec]);
1717 momentum.SetPy(GENSTK.plr[isec]*GENSTK.cyr[isec]);
1718 momentum.SetPz(GENSTK.plr[isec]*GENSTK.czr[isec]);
1719 momentum.SetE(GENSTK.tki[isec] + PAPROP.am[GENSTK.kpart[isec]+6]);
1721 else if (isec >= GENSTK.np && isec < GENSTK.np + FHEAVY.npheav) {
1722 Int_t jsec = isec - GENSTK.np;
1723 particleId = FHEAVY.kheavy[jsec]; // this is Fluka id !!!
1724 position.SetX(fXsco);
1725 position.SetY(fYsco);
1726 position.SetZ(fZsco);
1727 position.SetT(TRACKR.atrack);
1728 momentum.SetPx(FHEAVY.pheavy[jsec]*FHEAVY.cxheav[jsec]);
1729 momentum.SetPy(FHEAVY.pheavy[jsec]*FHEAVY.cyheav[jsec]);
1730 momentum.SetPz(FHEAVY.pheavy[jsec]*FHEAVY.czheav[jsec]);
1731 if (FHEAVY.tkheav[jsec] >= 3 && FHEAVY.tkheav[jsec] <= 6)
1732 momentum.SetE(FHEAVY.tkheav[jsec] + PAPROP.am[jsec+6]);
1733 else if (FHEAVY.tkheav[jsec] > 6)
1734 momentum.SetE(FHEAVY.tkheav[jsec] + FHEAVY.amnhea[jsec]); // to be checked !!!
1737 Warning("GetSecondary","isec out of range");
1739 } else if (caller == kUSTCKV) {
1740 Int_t index = OPPHST.lstopp - isec;
1741 position.SetX(OPPHST.xoptph[index]);
1742 position.SetY(OPPHST.yoptph[index]);
1743 position.SetZ(OPPHST.zoptph[index]);
1744 position.SetT(OPPHST.agopph[index]);
1745 Double_t p = OPPHST.poptph[index];
1747 momentum.SetPx(p * OPPHST.txopph[index]);
1748 momentum.SetPy(p * OPPHST.tyopph[index]);
1749 momentum.SetPz(p * OPPHST.tzopph[index]);
1753 Warning("GetSecondary","no secondaries available");
1755 } // end of GetSecondary
1758 //______________________________________________________________________________
1759 TMCProcess TFluka::ProdProcess(Int_t) const
1762 // Name of the process that has produced the secondary particles
1763 // in the current step
1765 Int_t mugamma = (TRACKR.jtrack == kFLUKAphoton ||
1766 TRACKR.jtrack == kFLUKAmuplus ||
1767 TRACKR.jtrack == kFLUKAmuminus);
1768 FlukaProcessCode_t icode = GetIcode();
1770 if (icode == kKASKADdecay) return kPDecay;
1771 else if (icode == kKASKADpair || icode == kEMFSCOpair) return kPPair;
1772 else if (icode == kEMFSCOcompton) return kPCompton;
1773 else if (icode == kEMFSCOphotoel) return kPPhotoelectric;
1774 else if (icode == kKASKADbrems || icode == kEMFSCObrems) return kPBrem;
1775 else if (icode == kKASKADdray || icode == kKASHEAdray) return kPDeltaRay;
1776 else if (icode == kEMFSCOmoller || icode == kEMFSCObhabha) return kPDeltaRay;
1777 else if (icode == kEMFSCOanniflight || icode == kEMFSCOannirest) return kPAnnihilation;
1778 else if (icode == kKASKADinelint) {
1779 if (!mugamma) return kPHadronic;
1780 else if (TRACKR.jtrack == kFLUKAphoton) return kPPhotoFission;
1781 else return kPMuonNuclear;
1783 else if (icode == kEMFSCOrayleigh) return kPRayleigh;
1784 // Fluka codes 100, 300 and 400 still to be investigasted
1785 else return kPNoProcess;
1789 Int_t TFluka::StepProcesses(TArrayI &proc) const
1792 // Return processes active in the current step
1794 FlukaProcessCode_t icode = GetIcode();
1798 case kKASKADtimekill:
1799 case kEMFSCOtimekill:
1800 case kKASNEUtimekill:
1801 case kKASHEAtimekill:
1802 case kKASOPHtimekill:
1805 case kKASKADstopping:
1807 case kEMFSCOstopping1:
1808 case kEMFSCOstopping2:
1810 case kKASNEUstopping:
1816 case kKASOPHabsorption:
1817 iproc = kPLightAbsorption;
1819 case kKASOPHrefraction:
1820 iproc = kPLightRefraction;
1821 case kEMSCOlocaledep :
1822 iproc = kPPhotoelectric;
1825 iproc = ProdProcess(0);
1830 //______________________________________________________________________________
1831 Int_t TFluka::VolId2Mate(Int_t id) const
1834 // Returns the material number for a given volume ID
1836 return fMCGeo->VolId2Mate(id);
1839 //______________________________________________________________________________
1840 const char* TFluka::VolName(Int_t id) const
1843 // Returns the volume name for a given volume ID
1845 return fMCGeo->VolName(id);
1848 //______________________________________________________________________________
1849 Int_t TFluka::VolId(const Text_t* volName) const
1852 // Converts from volume name to volume ID.
1853 // Time consuming. (Only used during set-up)
1854 // Could be replaced by hash-table
1858 strncpy(sname, volName, len = strlen(volName));
1860 while (sname[len - 1] == ' ') sname[--len] = 0;
1861 return fMCGeo->VolId(sname);
1864 //______________________________________________________________________________
1865 Int_t TFluka::CurrentVolID(Int_t& copyNo) const
1868 // Return the logical id and copy number corresponding to the current fluka region
1870 if (gGeoManager->IsOutside()) return 0;
1871 TGeoNode *node = gGeoManager->GetCurrentNode();
1872 copyNo = node->GetNumber();
1873 Int_t id = node->GetVolume()->GetNumber();
1877 //______________________________________________________________________________
1878 Int_t TFluka::CurrentVolOffID(Int_t off, Int_t& copyNo) const
1881 // Return the logical id and copy number of off'th mother
1882 // corresponding to the current fluka region
1884 if (off<0 || off>gGeoManager->GetLevel()) return 0;
1885 if (off==0) return CurrentVolID(copyNo);
1886 TGeoNode *node = gGeoManager->GetMother(off);
1887 if (!node) return 0;
1888 copyNo = node->GetNumber();
1889 return node->GetVolume()->GetNumber();
1892 //______________________________________________________________________________
1893 const char* TFluka::CurrentVolName() const
1896 // Return the current volume name
1898 if (gGeoManager->IsOutside()) return 0;
1899 return gGeoManager->GetCurrentVolume()->GetName();
1902 //______________________________________________________________________________
1903 const char* TFluka::CurrentVolOffName(Int_t off) const
1906 // Return the volume name of the off'th mother of the current volume
1908 if (off<0 || off>gGeoManager->GetLevel()) return 0;
1909 if (off==0) return CurrentVolName();
1910 TGeoNode *node = gGeoManager->GetMother(off);
1911 if (!node) return 0;
1912 return node->GetVolume()->GetName();
1915 const char* TFluka::CurrentVolPath() {
1916 // Return the current volume path
1917 return gGeoManager->GetPath();
1919 //______________________________________________________________________________
1920 Int_t TFluka::CurrentMaterial(Float_t & a, Float_t & z,
1921 Float_t & dens, Float_t & radl, Float_t & absl) const
1924 // Return the current medium number and material properties
1927 Int_t id = TFluka::CurrentVolID(copy);
1928 Int_t med = TFluka::VolId2Mate(id);
1929 TGeoVolume* vol = gGeoManager->GetCurrentVolume();
1930 TGeoMaterial* mat = vol->GetMaterial();
1933 dens = mat->GetDensity();
1934 radl = mat->GetRadLen();
1935 absl = mat->GetIntLen();
1940 //______________________________________________________________________________
1941 void TFluka::Gmtod(Float_t* xm, Float_t* xd, Int_t iflag)
1943 // Transforms a position from the world reference frame
1944 // to the current volume reference frame.
1946 // Geant3 desription:
1947 // ==================
1948 // Computes coordinates XD (in DRS)
1949 // from known coordinates XM in MRS
1950 // The local reference system can be initialized by
1951 // - the tracking routines and GMTOD used in GUSTEP
1952 // - a call to GMEDIA(XM,NUMED)
1953 // - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
1954 // (inverse routine is GDTOM)
1956 // If IFLAG=1 convert coordinates
1957 // IFLAG=2 convert direction cosinus
1960 Double_t xmL[3], xdL[3];
1962 for (i=0;i<3;i++) xmL[i]=xm[i];
1963 if (iflag == 1) gGeoManager->MasterToLocal(xmL,xdL);
1964 else gGeoManager->MasterToLocalVect(xmL,xdL);
1965 for (i=0;i<3;i++) xd[i] = xdL[i];
1968 //______________________________________________________________________________
1969 void TFluka::Gmtod(Double_t* xm, Double_t* xd, Int_t iflag)
1972 // See Gmtod(Float_t*, Float_t*, Int_t)
1974 if (iflag == 1) gGeoManager->MasterToLocal(xm,xd);
1975 else gGeoManager->MasterToLocalVect(xm,xd);
1978 //______________________________________________________________________________
1979 void TFluka::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag)
1981 // Transforms a position from the current volume reference frame
1982 // to the world reference frame.
1984 // Geant3 desription:
1985 // ==================
1986 // Computes coordinates XM (Master Reference System
1987 // knowing the coordinates XD (Detector Ref System)
1988 // The local reference system can be initialized by
1989 // - the tracking routines and GDTOM used in GUSTEP
1990 // - a call to GSCMED(NLEVEL,NAMES,NUMBER)
1991 // (inverse routine is GMTOD)
1993 // If IFLAG=1 convert coordinates
1994 // IFLAG=2 convert direction cosinus
1997 Double_t xmL[3], xdL[3];
1999 for (i=0;i<3;i++) xdL[i] = xd[i];
2000 if (iflag == 1) gGeoManager->LocalToMaster(xdL,xmL);
2001 else gGeoManager->LocalToMasterVect(xdL,xmL);
2002 for (i=0;i<3;i++) xm[i]=xmL[i];
2005 //______________________________________________________________________________
2006 void TFluka::Gdtom(Double_t* xd, Double_t* xm, Int_t iflag)
2009 // See Gdtom(Float_t*, Float_t*, Int_t)
2011 if (iflag == 1) gGeoManager->LocalToMaster(xd,xm);
2012 else gGeoManager->LocalToMasterVect(xd,xm);
2015 //______________________________________________________________________________
2016 TObjArray *TFluka::GetFlukaMaterials()
2019 // Get array of Fluka materials
2020 return fGeom->GetMatList();
2023 //______________________________________________________________________________
2024 void TFluka::SetMreg(Int_t l, Int_t lttc)
2026 // Set current fluka region
2027 fCurrentFlukaRegion = l;
2028 fGeom->SetMreg(l,lttc);
2034 TString TFluka::ParticleName(Int_t pdg) const
2036 // Return particle name for particle with pdg code pdg.
2037 Int_t ifluka = IdFromPDG(pdg);
2038 return TString((CHPPRP.btype[ifluka - kFLUKAcodemin]), 8);
2042 Double_t TFluka::ParticleMass(Int_t pdg) const
2044 // Return particle mass for particle with pdg code pdg.
2045 Int_t ifluka = IdFromPDG(pdg);
2046 return (PAPROP.am[ifluka - kFLUKAcodemin]);
2049 Double_t TFluka::ParticleMassFPC(Int_t fpc) const
2051 // Return particle mass for particle with Fluka particle code fpc
2052 return (PAPROP.am[fpc - kFLUKAcodemin]);
2055 Double_t TFluka::ParticleCharge(Int_t pdg) const
2057 // Return particle charge for particle with pdg code pdg.
2058 Int_t ifluka = IdFromPDG(pdg);
2059 return Double_t(PAPROP.ichrge[ifluka - kFLUKAcodemin]);
2062 Double_t TFluka::ParticleLifeTime(Int_t pdg) const
2064 // Return particle lifetime for particle with pdg code pdg.
2065 Int_t ifluka = IdFromPDG(pdg);
2066 return (PAPROP.tmnlf[ifluka - kFLUKAcodemin]);
2069 void TFluka::Gfpart(Int_t pdg, char* name, Int_t& type, Float_t& mass, Float_t& charge, Float_t& tlife)
2071 // Retrieve particle properties for particle with pdg code pdg.
2073 strcpy(name, ParticleName(pdg).Data());
2074 type = ParticleMCType(pdg);
2075 mass = ParticleMass(pdg);
2076 charge = ParticleCharge(pdg);
2077 tlife = ParticleLifeTime(pdg);
2080 void TFluka::PrintHeader()
2086 printf("------------------------------------------------------------------------------\n");
2087 printf("- You are using the TFluka Virtual Monte Carlo Interface to FLUKA. -\n");
2088 printf("- Please see the file fluka.out for FLUKA output and licensing information. -\n");
2089 printf("------------------------------------------------------------------------------\n");
2095 #define pshckp pshckp_
2096 #define ustckv ustckv_
2100 void pshckp(Double_t & px, Double_t & py, Double_t & pz, Double_t & e,
2101 Double_t & vx, Double_t & vy, Double_t & vz, Double_t & tof,
2102 Double_t & polx, Double_t & poly, Double_t & polz, Double_t & wgt, Int_t& ntr)
2105 // Pushes one cerenkov photon to the stack
2108 TFluka* fluka = (TFluka*) gMC;
2109 TVirtualMCStack* cppstack = fluka->GetStack();
2110 Int_t parent = TRACKR.ispusr[mkbmx2-1];
2111 cppstack->PushTrack(0, parent, 50000050,
2115 kPCerenkov, ntr, wgt, 0);
2118 void ustckv(Int_t & nphot, Int_t & mreg, Double_t & x, Double_t & y, Double_t & z)
2121 // Calls stepping in order to signal cerenkov production
2123 TFluka *fluka = (TFluka*)gMC;
2124 fluka->SetMreg(mreg,LTCLCM.mlatm1);
2128 fluka->SetNCerenkov(nphot);
2129 fluka->SetCaller(kUSTCKV);
2130 if (fluka->GetVerbosityLevel() >= 3)
2131 (TVirtualMCApplication::Instance())->Stepping();
2136 void TFluka::AddParticlesToPdgDataBase() const
2140 // Add particles to the PDG data base
2142 TDatabasePDG *pdgDB = TDatabasePDG::Instance();
2144 const Int_t kion=10000000;
2146 const Double_t kAu2Gev = 0.9314943228;
2147 const Double_t khSlash = 1.0545726663e-27;
2148 const Double_t kErg2Gev = 1/1.6021773349e-3;
2149 const Double_t khShGev = khSlash*kErg2Gev;
2150 const Double_t kYear2Sec = 3600*24*365.25;
2155 pdgDB->AddParticle("Deuteron","Deuteron",2*kAu2Gev+8.071e-3,kTRUE,
2156 0,3,"Ion",kion+10020);
2157 pdgDB->AddParticle("Triton","Triton",3*kAu2Gev+14.931e-3,kFALSE,
2158 khShGev/(12.33*kYear2Sec),3,"Ion",kion+10030);
2159 pdgDB->AddParticle("Alpha","Alpha",4*kAu2Gev+2.424e-3,kTRUE,
2160 khShGev/(12.33*kYear2Sec),6,"Ion",kion+20040);
2161 pdgDB->AddParticle("HE3","HE3",3*kAu2Gev+14.931e-3,kFALSE,
2162 0,6,"Ion",kion+20030);