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 **************************************************************************/
18 Revision 1.16 2003/03/26 13:30:35 morsch
19 SetTrackIsExiting, SetTrackIsEntering, SetTrackIsInside added.
21 Revision 1.15 2003/02/18 16:12:17 morsch
22 Protect mpdgha against negative argument.
24 Revision 1.14 2003/02/18 12:47:59 morsch
25 Gmtod and Gdtom added.
27 Revision 1.13 2003/01/31 14:01:51 morsch
29 - Getters related to geometry.
30 - Communication with run manager (event steering)
32 Revision 1.12 2003/01/31 12:18:53 morsch
33 Corrected indices. (E. Futo)
35 Revision 1.9 2002/12/06 12:41:29 morsch
36 Mess from last merge cleaned up.
38 Revision 1.8 2002/12/06 12:28:44 morsch
39 Region to media mapping corrected and improved.
41 Revision 1.7 2002/12/06 12:21:32 morsch
42 User stepping methods added (E. Futo)
44 Revision 1.6 2002/11/21 18:40:06 iglez2
47 Revision 1.5 2002/11/07 17:59:10 iglez2
48 Included the geometry through geant4_vmc/FLUGG
50 Revision 1.4 2002/11/04 16:00:46 iglez2
51 The conversion between ID and PDG now uses Fluka routines and arrays which is more consistent.
53 Revision 1.3 2002/10/22 15:12:14 alibrary
54 Introducing Riostream.h
56 Revision 1.2 2002/10/14 14:57:40 hristov
57 Merging the VirtualMC branch to the main development branch (HEAD)
59 Revision 1.1.2.8 2002/10/08 16:33:17 iglez2
60 LSOUIT is set to true before the second call to flukam.
62 Revision 1.1.2.7 2002/10/08 09:30:37 iglez2
63 Solved stupid missing ;
65 Revision 1.1.2.6 2002/10/07 13:40:22 iglez2
66 First implementations of the PDG <--> Fluka Id conversion routines
68 Revision 1.1.2.5 2002/09/26 16:26:03 iglez2
70 Call to gAlice->Generator()->Generate()
72 Revision 1.1.2.4 2002/09/26 13:22:23 iglez2
73 Naive implementation of ProcessRun and ProcessEvent
74 Opening/Closing of input file (fInputFileName) with FORTRAN unit 5 before/after the first call to flukam inside Init()
76 Revision 1.1.2.3 2002/09/20 15:35:51 iglez2
77 Modification of LFDRTR. Value is passed to FLUKA !!!
79 Revision 1.1.2.2 2002/09/18 14:34:44 iglez2
80 Revised version with all pure virtual methods implemented
82 Revision 1.1.2.1 2002/07/24 08:49:41 alibrary
83 Adding TFluka to VirtualMC
85 Revision 1.1 2002/07/05 13:10:07 morsch
86 First commit of Fluka interface.
90 #include <Riostream.h>
92 #include "TClonesArray.h"
94 #include "TCallf77.h" //For the fortran calls
95 #include "Fdblprc.h" //(DBLPRC) fluka common
96 #include "Fepisor.h" //(EPISOR) fluka common
97 #include "Ffinuc.h" //(FINUC) fluka common
98 #include "Fiounit.h" //(IOUNIT) fluka common
99 #include "Fpaprop.h" //(PAPROP) fluka common
100 #include "Fpart.h" //(PART) fluka common
101 #include "Ftrackr.h" //(TRACKR) fluka common
102 #include "Fpaprop.h" //(PAPROP) fluka common
103 #include "Ffheavy.h" //(FHEAVY) fluka common
105 #include "TVirtualMC.h"
106 #include "TG4GeometryManager.h" //For the geometry management
107 #include "TG4DetConstruction.h" //For the detector construction
109 #include "FGeometryInit.hh"
110 #include "TLorentzVector.h"
111 #include "FlukaVolume.h"
113 // Fluka methods that may be needed.
115 # define flukam flukam_
116 # define fluka_openinp fluka_openinp_
117 # define fluka_closeinp fluka_closeinp_
118 # define mcihad mcihad_
119 # define mpdgha mpdgha_
121 # define flukam FLUKAM
122 # define fluka_openinp FLUKA_OPENINP
123 # define fluka_closeinp FLUKA_CLOSEINP
124 # define mcihad MCIHAD
125 # define mpdgha MPDGHA
131 // Prototypes for FLUKA functions
133 void type_of_call flukam(const int&);
134 void type_of_call fluka_openinp(const int&, DEFCHARA);
135 void type_of_call fluka_closeinp(const int&);
136 int type_of_call mcihad(const int&);
137 int type_of_call mpdgha(const int&);
141 // Class implementation for ROOT
146 //----------------------------------------------------------------------------
147 // TFluka constructors and destructors.
148 //____________________________________________________________________________
154 fCurrentFlukaRegion(-1)
157 // Default constructor
161 TFluka::TFluka(const char *title, Int_t verbosity)
162 :TVirtualMC("TFluka",title),
163 fVerbosityLevel(verbosity),
168 fCurrentFlukaRegion(-1)
170 if (fVerbosityLevel >=3)
171 cout << "==> TFluka::TFluka(" << title << ") constructor called." << endl;
174 // create geometry manager
175 if (fVerbosityLevel >=2)
176 cout << "\t* Creating G4 Geometry manager..." << endl;
177 fGeometryManager = new TG4GeometryManager();
178 if (fVerbosityLevel >=2)
179 cout << "\t* Creating G4 Detector..." << endl;
180 fDetector = new TG4DetConstruction();
181 FGeometryInit* geominit = FGeometryInit::GetInstance();
183 geominit->setDetConstruction(fDetector);
185 cerr << "ERROR: Could not create FGeometryInit!" << endl;
186 cerr << " Exiting!!!" << endl;
190 if (fVerbosityLevel >=3)
191 cout << "<== TFluka::TFluka(" << title << ") constructor called." << endl;
193 fVolumeMediaMap = new TClonesArray("FlukaVolume",1000);
199 if (fVerbosityLevel >=3)
200 cout << "==> TFluka::~TFluka() destructor called." << endl;
202 delete fGeometryManager;
203 fVolumeMediaMap->Delete();
204 delete fVolumeMediaMap;
207 if (fVerbosityLevel >=3)
208 cout << "<== TFluka::~TFluka() destructor called." << endl;
212 //_____________________________________________________________________________
213 // TFluka control methods
214 //____________________________________________________________________________
215 void TFluka::Init() {
216 if (fVerbosityLevel >=3)
217 cout << "==> TFluka::Init() called." << endl;
219 if (fVerbosityLevel >=2)
220 cout << "\t* Changing lfdrtr = (" << (GLOBAL.lfdrtr?'T':'F')
221 << ") in fluka..." << endl;
222 GLOBAL.lfdrtr = true;
224 if (fVerbosityLevel >=2)
225 cout << "\t* Opening file " << fInputFileName << endl;
226 const char* fname = fInputFileName;
227 fluka_openinp(lunin, PASSCHARA(fname));
229 if (fVerbosityLevel >=2)
230 cout << "\t* Calling flukam..." << endl;
233 if (fVerbosityLevel >=2)
234 cout << "\t* Closing file " << fInputFileName << endl;
235 fluka_closeinp(lunin);
237 if (fVerbosityLevel >=3)
238 cout << "<== TFluka::Init() called." << endl;
244 void TFluka::FinishGeometry() {
246 // Build-up table with region to medium correspondance
250 if (fVerbosityLevel >=3)
251 cout << "==> TFluka::FinishGeometry() called." << endl;
253 // fGeometryManager->Ggclos();
255 FGeometryInit* flugg = FGeometryInit::GetInstance();
257 fMediaByRegion = new Int_t[fNVolumes+2];
258 for (Int_t i = 0; i < fNVolumes; i++)
260 FlukaVolume* vol = dynamic_cast<FlukaVolume*>((*fVolumeMediaMap)[i]);
261 TString volName = vol->GetName();
262 Int_t media = vol->GetMedium();
263 if (fVerbosityLevel >= 3)
264 printf("Finish Geometry: volName, media %d %s %d \n", i, volName.Data(), media);
265 strcpy(tmp, volName.Data());
267 flugg->SetMediumFromName(tmp, media, i+1);
268 fMediaByRegion[i] = media;
271 flugg->BuildMediaMap();
273 if (fVerbosityLevel >=3)
274 cout << "<== TFluka::FinishGeometry() called." << endl;
277 void TFluka::BuildPhysics() {
278 if (fVerbosityLevel >=3)
279 cout << "==> TFluka::BuildPhysics() called." << endl;
282 if (fVerbosityLevel >=3)
283 cout << "<== TFluka::BuildPhysics() called." << endl;
286 void TFluka::ProcessEvent() {
287 if (fVerbosityLevel >=3)
288 cout << "==> TFluka::ProcessEvent() called." << endl;
289 fApplication->GeneratePrimaries();
290 EPISOR.lsouit = true;
292 if (fVerbosityLevel >=3)
293 cout << "<== TFluka::ProcessEvent() called." << endl;
297 void TFluka::ProcessRun(Int_t nevent) {
298 if (fVerbosityLevel >=3)
299 cout << "==> TFluka::ProcessRun(" << nevent << ") called."
302 if (fVerbosityLevel >=2) {
303 cout << "\t* GLOBAL.fdrtr = " << (GLOBAL.lfdrtr?'T':'F') << endl;
304 cout << "\t* Calling flukam again..." << endl;
306 fApplication->InitGeometry();
307 fApplication->BeginEvent();
309 fApplication->FinishEvent();
310 if (fVerbosityLevel >=3)
311 cout << "<== TFluka::ProcessRun(" << nevent << ") called."
316 //_____________________________________________________________________________
317 // methods for building/management of geometry
318 //____________________________________________________________________________
319 // functions from GCONS
320 void TFluka::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,
321 Float_t &dens, Float_t &radl, Float_t &absl,
322 Float_t* ubuf, Int_t& nbuf) {
324 fGeometryManager->Gfmate(imat, name, a, z, dens, radl, absl, ubuf, nbuf);
327 void TFluka::Gfmate(Int_t imat, char *name, Double_t &a, Double_t &z,
328 Double_t &dens, Double_t &radl, Double_t &absl,
329 Double_t* ubuf, Int_t& nbuf) {
331 fGeometryManager->Gfmate(imat, name, a, z, dens, radl, absl, ubuf, nbuf);
334 // detector composition
335 void TFluka::Material(Int_t& kmat, const char* name, Double_t a,
336 Double_t z, Double_t dens, Double_t radl, Double_t absl,
337 Float_t* buf, Int_t nwbuf) {
340 ->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
342 void TFluka::Material(Int_t& kmat, const char* name, Double_t a,
343 Double_t z, Double_t dens, Double_t radl, Double_t absl,
344 Double_t* buf, Int_t nwbuf) {
347 ->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
350 void TFluka::Mixture(Int_t& kmat, const char *name, Float_t *a,
351 Float_t *z, Double_t dens, Int_t nlmat, Float_t *wmat) {
354 ->Mixture(kmat, name, a, z, dens, nlmat, wmat);
356 void TFluka::Mixture(Int_t& kmat, const char *name, Double_t *a,
357 Double_t *z, Double_t dens, Int_t nlmat, Double_t *wmat) {
360 ->Mixture(kmat, name, a, z, dens, nlmat, wmat);
363 void TFluka::Medium(Int_t& kmed, const char *name, Int_t nmat,
364 Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd,
365 Double_t stemax, Double_t deemax, Double_t epsil,
366 Double_t stmin, Float_t* ubuf, Int_t nbuf) {
369 ->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
370 epsil, stmin, ubuf, nbuf);
372 void TFluka::Medium(Int_t& kmed, const char *name, Int_t nmat,
373 Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd,
374 Double_t stemax, Double_t deemax, Double_t epsil,
375 Double_t stmin, Double_t* ubuf, Int_t nbuf) {
378 ->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
379 epsil, stmin, ubuf, nbuf);
382 void TFluka::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
383 Double_t thetaY, Double_t phiY, Double_t thetaZ,
387 ->Matrix(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
390 void TFluka::Gstpar(Int_t itmed, const char *param, Double_t parval) {
392 fGeometryManager->Gstpar(itmed, param, parval);
395 // functions from GGEOM
396 Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
397 Float_t *upar, Int_t np) {
399 // fVolumeMediaMap[TString(name)] = nmed;
400 if (fVerbosityLevel >= 3)
401 printf("TFluka::Gsvolu() name = %s, nmed = %d\n", name, nmed);
403 TClonesArray &lvols = *fVolumeMediaMap;
404 new(lvols[fNVolumes++])
405 FlukaVolume(name, nmed);
406 return fGeometryManager->Gsvolu(name, shape, nmed, upar, np);
408 Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
409 Double_t *upar, Int_t np) {
411 TClonesArray &lvols = *fVolumeMediaMap;
412 new(lvols[fNVolumes++])
413 FlukaVolume(name, nmed);
415 return fGeometryManager->Gsvolu(name, shape, nmed, upar, np);
418 void TFluka::Gsdvn(const char *name, const char *mother, Int_t ndiv,
421 // The medium of the daughter is the one of the mother
422 Int_t volid = TFluka::VolId(mother);
423 Int_t med = TFluka::VolId2Mate(volid);
424 TClonesArray &lvols = *fVolumeMediaMap;
425 new(lvols[fNVolumes++])
426 FlukaVolume(name, med);
427 fGeometryManager->Gsdvn(name, mother, ndiv, iaxis);
430 void TFluka::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
431 Int_t iaxis, Double_t c0i, Int_t numed) {
433 TClonesArray &lvols = *fVolumeMediaMap;
434 new(lvols[fNVolumes++])
435 FlukaVolume(name, numed);
436 fGeometryManager->Gsdvn2(name, mother, ndiv, iaxis, c0i, numed);
439 void TFluka::Gsdvt(const char *name, const char *mother, Double_t step,
440 Int_t iaxis, Int_t numed, Int_t ndvmx) {
442 TClonesArray &lvols = *fVolumeMediaMap;
443 new(lvols[fNVolumes++])
444 FlukaVolume(name, numed);
445 fGeometryManager->Gsdvt(name, mother, step, iaxis, numed, ndvmx);
448 void TFluka::Gsdvt2(const char *name, const char *mother, Double_t step,
449 Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx) {
451 TClonesArray &lvols = *fVolumeMediaMap;
452 new(lvols[fNVolumes++])
453 FlukaVolume(name, numed);
454 fGeometryManager->Gsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
457 void TFluka::Gsord(const char *name, Int_t iax) {
459 fGeometryManager->Gsord(name, iax);
462 void TFluka::Gspos(const char *name, Int_t nr, const char *mother,
463 Double_t x, Double_t y, Double_t z, Int_t irot,
466 fGeometryManager->Gspos(name, nr, mother, x, y, z, irot, konly);
469 void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
470 Double_t x, Double_t y, Double_t z, Int_t irot,
471 const char *konly, Float_t *upar, Int_t np) {
473 fGeometryManager->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
475 void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
476 Double_t x, Double_t y, Double_t z, Int_t irot,
477 const char *konly, Double_t *upar, Int_t np) {
479 fGeometryManager->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
482 void TFluka::Gsbool(const char* onlyVolName, const char* manyVolName) {
484 fGeometryManager->Gsbool(onlyVolName, manyVolName);
487 void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t *ppckov,
488 Float_t *absco, Float_t *effic, Float_t *rindex) {
490 fGeometryManager->SetCerenkov(itmed, npckov, ppckov, absco, effic, rindex);
492 void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Double_t *ppckov,
493 Double_t *absco, Double_t *effic, Double_t *rindex) {
495 fGeometryManager->SetCerenkov(itmed, npckov, ppckov, absco, effic, rindex);
499 void TFluka::WriteEuclid(const char* fileName, const char* topVol,
500 Int_t number, Int_t nlevel) {
502 fGeometryManager->WriteEuclid(fileName, topVol, number, nlevel);
507 //_____________________________________________________________________________
508 // methods needed by the stepping
509 //____________________________________________________________________________
511 Int_t TFluka::GetMedium() const {
513 // Get the medium number for the current fluka region
515 FGeometryInit* flugg = FGeometryInit::GetInstance();
516 return flugg->GetMedium(fCurrentFlukaRegion);
521 //____________________________________________________________________________
522 // ID <--> PDG transformations
523 //_____________________________________________________________________________
524 Int_t TFluka::IdFromPDG(Int_t pdg) const
527 // Return Fluka code from PDG and pseudo ENDF code
529 // MCIHAD() goes from pdg to fluka internal.
530 Int_t intfluka = mcihad(pdg);
531 // KPTOIP array goes from internal to official
532 return GetFlukaKPTOIP(intfluka);
535 Int_t TFluka::PDGFromId(Int_t id) const
538 // Return PDG code and pseudo ENDF code from Fluka code
540 //IPTOKP array goes from official to internal
542 if (fVerbosityLevel >= 1)
543 printf("PDGFromId: Error id = 0");
547 Int_t intfluka = GetFlukaIPTOKP(id);
549 if (fVerbosityLevel >= 1)
550 printf("PDGFromId: Error intfluka = 0");
552 } else if (intfluka < 0) {
553 if (fVerbosityLevel >= 1)
554 printf("PDGFromId: Error intfluka < 0");
557 if (fVerbosityLevel >= 3)
558 printf("mpdgha called with %d %d \n", id, intfluka);
559 return mpdgha(intfluka);
562 //_____________________________________________________________________________
563 // methods for step management
564 //____________________________________________________________________________
568 void TFluka::SetMaxStep(Double_t)
570 // SetMaxStep is dummy procedure in TFluka !
571 if (fVerbosityLevel >=3)
572 cout << "SetMaxStep is dummy procedure in TFluka !" << endl;
575 void TFluka::SetMaxNStep(Int_t)
577 // SetMaxNStep is dummy procedure in TFluka !
578 if (fVerbosityLevel >=3)
579 cout << "SetMaxNStep is dummy procedure in TFluka !" << endl;
582 void TFluka::SetUserDecay(Int_t)
584 // SetUserDecay is dummy procedure in TFluka !
585 if (fVerbosityLevel >=3)
586 cout << "SetUserDecay is dummy procedure in TFluka !" << endl;
590 // dynamic properties
592 void TFluka::TrackPosition(TLorentzVector& position) const
594 // Return the current position in the master reference frame of the
595 // track being transported
596 // TRACKR.atrack = age of the particle
597 // TRACKR.xtrack = x-position of the last point
598 // TRACKR.ytrack = y-position of the last point
599 // TRACKR.ztrack = z-position of the last point
600 position.SetX(TRACKR.xtrack[TRACKR.ntrack]);
601 position.SetY(TRACKR.ytrack[TRACKR.ntrack]);
602 position.SetZ(TRACKR.ztrack[TRACKR.ntrack]);
603 position.SetT(TRACKR.atrack);
610 void TFluka::TrackMomentum(TLorentzVector& momentum) const
612 // Return the direction and the momentum (GeV/c) of the track
613 // currently being transported
614 // TRACKR.ptrack = momentum of the particle (not always defined, if
615 // < 0 must be obtained from etrack)
616 // TRACKR.cx,y,ztrck = direction cosines of the current particle
617 // TRACKR.etrack = total energy of the particle
618 // TRACKR.jtrack = identity number of the particle
619 // PAPROP.am[TRACKR.jtrack] = particle mass in gev
620 if (TRACKR.ptrack >= 0) {
621 momentum.SetPx(TRACKR.ptrack*TRACKR.cxtrck);
622 momentum.SetPy(TRACKR.ptrack*TRACKR.cytrck);
623 momentum.SetPz(TRACKR.ptrack*TRACKR.cztrck);
624 momentum.SetE(TRACKR.etrack);
628 Double_t p = sqrt(TRACKR.etrack*TRACKR.etrack - PAPROP.am[TRACKR.jtrack+6]*PAPROP.am[TRACKR.jtrack+6]);
629 momentum.SetPx(p*TRACKR.cxtrck);
630 momentum.SetPy(p*TRACKR.cytrck);
631 momentum.SetPz(p*TRACKR.cztrck);
632 momentum.SetE(TRACKR.etrack);
637 Double_t TFluka::TrackStep() const
639 // Return the length in centimeters of the current step
640 // TRACKR.ctrack = total curved path
641 return TRACKR.ctrack;
644 Double_t TFluka::TrackLength() const
647 // This is the sum of substeps !!!
648 // TRACKR.ctrack = total curved path of the current step
649 // Sum of the substeps is identical to TRACKR.ctrack if the is no mag. field
650 // The sum of all step length starting from the beginning of the track
651 // for the time being returns only the length in centimeters of the current step
653 for ( Int_t j=0;j<TRACKR.ntrack;j++) {
654 sum +=TRACKR.ttrack[j];
659 Double_t TFluka::TrackTime() const
661 // Return the current time of flight of the track being transported
662 // TRACKR.atrack = age of the particle
663 return TRACKR.atrack;
666 Double_t TFluka::Edep() const
669 // if TRACKR.ntrack = 0, TRACKR.mtrack = 0:
670 // -->local energy deposition (the value and the point are not recorded in TRACKR)
671 // but in the variable "rull" of the procedure "endraw.cxx"
672 // if TRACKR.ntrack > 0, TRACKR.mtrack = 0:
673 // -->no energy loss along the track
674 // if TRACKR.ntrack > 0, TRACKR.mtrack > 0:
675 // -->energy loss distributed along the track
676 // TRACKR.dtrack = energy deposition of the jth deposition even
677 if (TRACKR.ntrack == 0 && TRACKR.mtrack == 0)
681 for ( Int_t j=0;j<TRACKR.mtrack;j++) {
682 sum +=TRACKR.dtrack[j];
688 Int_t TFluka::TrackPid() const
690 // Return the id of the particle transported
691 // TRACKR.jtrack = identity number of the particle
692 return PDGFromId(TRACKR.jtrack);
695 Double_t TFluka::TrackCharge() const
697 // Return charge of the track currently transported
698 // PAPROP.ichrge = electric charge of the particle
699 // TRACKR.jtrack = identity number of the particle
700 return PAPROP.ichrge[TRACKR.jtrack+6];
703 Double_t TFluka::TrackMass() const
705 // PAPROP.am = particle mass in GeV
706 // TRACKR.jtrack = identity number of the particle
707 return PAPROP.am[TRACKR.jtrack+6];
710 Double_t TFluka::Etot() const
712 // TRACKR.etrack = total energy of the particle
713 return TRACKR.etrack;
719 Bool_t TFluka::IsNewTrack() const
722 // True if the track is not at the boundary of the current volume
723 // Not true in some cases in bxdraw - to be solved
727 Bool_t TFluka::IsTrackInside() const
729 // True if the track is not at the boundary of the current volume
730 // In Fluka a step is always inside one kind of material
731 // If the step would go behind the region of one material,
732 // it will be shortened to reach only the boundary.
733 // Therefore IsTrackInside() is always true.
734 // Not true in some cases in bxdraw - to be solved
738 Bool_t TFluka::IsTrackEntering() const
740 // True if this is the first step of the track in the current volume
741 // Boundary- (X) crossing
742 // Icode = 19: boundary crossing - call from Kaskad
743 // Icode = 29: boundary crossing - call from Emfsco
744 // Icode = 39: boundary crossing - call from Kasneu
745 // Icode = 49: boundary crossing - call from Kashea
746 // Icode = 59: boundary crossing - call from Kasoph
752 fTrackIsEntering) return 1;
756 Bool_t TFluka::IsTrackExiting() const
758 // True if this is the last step of the track in the current volume
759 // Boundary- (X) crossing
760 // Icode = 19: boundary crossing - call from Kaskad
761 // Icode = 29: boundary crossing - call from Emfsco
762 // Icode = 39: boundary crossing - call from Kasneu
763 // Icode = 49: boundary crossing - call from Kashea
764 // Icode = 59: boundary crossing - call from Kasoph
770 fTrackIsExiting) return 1;
774 Bool_t TFluka::IsTrackOut() const
776 // True if the track is out of the setup
778 // Icode = 14: escape - call from Kaskad
779 // Icode = 23: escape - call from Emfsco
780 // Icode = 32: escape - call from Kasneu
781 // Icode = 40: escape - call from Kashea
782 // Icode = 51: escape - call from Kasoph
787 fIcode == 51) return 1;
791 Bool_t TFluka::IsTrackDisappeared() const
793 // means all inelastic interactions and decays
794 // fIcode from usdraw
795 if (fIcode == 101 || // inelastic interaction
796 fIcode == 102 || // particle decay
797 fIcode == 214 || // in-flight annihilation
798 fIcode == 215 || // annihilation at rest
799 fIcode == 217 || // pair production
800 fIcode == 221) return 1;
804 Bool_t TFluka::IsTrackStop() const
806 // True if the track energy has fallen below the threshold
807 // means stopped by signal or below energy threshold
808 // Icode = 12: stopping particle - call from Kaskad
809 // Icode = 15: time kill - call from Kaskad
810 // Icode = 21: below threshold, iarg=1 - call from Emfsco
811 // Icode = 22: below threshold, iarg=2 - call from Emfsco
812 // Icode = 24: time kill - call from Emfsco
813 // Icode = 31: below threshold - call from Kasneu
814 // Icode = 33: time kill - call from Kasneu
815 // Icode = 41: time kill - call from Kashea
816 // Icode = 52: time kill - call from Kasoph
825 fIcode == 52) return 1;
829 Bool_t TFluka::IsTrackAlive() const
831 // means not disappeared or not out
832 if (IsTrackDisappeared() || IsTrackOut() ) return 0;
840 Int_t TFluka::NSecondaries() const
841 // Number of secondary particles generated in the current step
842 // FINUC.np = number of secondaries except light and heavy ions
843 // FHEAVY.npheav = number of secondaries for light and heavy secondary ions
845 return FINUC.np + FHEAVY.npheav;
848 void TFluka::GetSecondary(Int_t isec, Int_t& particleId,
849 TLorentzVector& position, TLorentzVector& momentum)
851 if (isec >= 0 && isec < FINUC.np) {
852 // more fine condition depending on icode
870 particleId = PDGFromId(FINUC.kpart[isec]);
871 position.SetX(fXsco);
872 position.SetY(fYsco);
873 position.SetZ(fZsco);
874 position.SetT(TRACKR.atrack);
875 // position.SetT(TRACKR.atrack+FINUC.agesec[isec]); //not yet implem.
876 momentum.SetPx(FINUC.plr[isec]*FINUC.cxr[isec]);
877 momentum.SetPy(FINUC.plr[isec]*FINUC.cyr[isec]);
878 momentum.SetPz(FINUC.plr[isec]*FINUC.czr[isec]);
879 momentum.SetE(FINUC.tki[isec] + PAPROP.am[FINUC.kpart[isec]+6]);
881 if (isec >= FINUC.np && isec < FINUC.np + FHEAVY.npheav) {
882 Int_t jsec = isec - FINUC.np;
883 particleId = FHEAVY.kheavy[jsec]; // this is Fluka id !!!
884 position.SetX(fXsco);
885 position.SetY(fYsco);
886 position.SetZ(fZsco);
887 position.SetT(TRACKR.atrack);
888 // position.SetT(TRACKR.atrack+FHEAVY.agheav[jsec]); //not yet implem.
889 momentum.SetPx(FHEAVY.pheavy[jsec]*FHEAVY.cxheav[jsec]);
890 momentum.SetPy(FHEAVY.pheavy[jsec]*FHEAVY.cyheav[jsec]);
891 momentum.SetPz(FHEAVY.pheavy[jsec]*FHEAVY.czheav[jsec]);
892 if (FHEAVY.tkheav[jsec] >= 3 && FHEAVY.tkheav[jsec] <= 6)
893 momentum.SetE(FHEAVY.tkheav[jsec] + PAPROP.am[jsec+6]);
894 else if (FHEAVY.tkheav[jsec] > 6)
895 momentum.SetE(FHEAVY.tkheav[jsec] + FHEAVY.amnhea[jsec]); // to be checked !!!
899 TMCProcess TFluka::ProdProcess(Int_t isec) const
900 // Name of the process that has produced the secondary particles
901 // in the current step
903 const TMCProcess kIpNoProc = kPNoProcess;
904 const TMCProcess kIpPDecay = kPDecay;
905 const TMCProcess kIpPPair = kPPair;
906 //const TMCProcess kIpPPairFromPhoton = kPPairFromPhoton;
907 //const TMCProcess kIpPPairFromVirtualPhoton = kPPairFromVirtualPhoton;
908 const TMCProcess kIpPCompton = kPCompton;
909 const TMCProcess kIpPPhotoelectric = kPPhotoelectric;
910 const TMCProcess kIpPBrem = kPBrem;
911 //const TMCProcess kIpPBremFromHeavy = kPBremFromHeavy;
912 //const TMCProcess kIpPBremFromElectronOrPositron = kPBremFromElectronOrPositron;
913 const TMCProcess kIpPDeltaRay = kPDeltaRay;
914 //const TMCProcess kIpPMoller = kPMoller;
915 //const TMCProcess kIpPBhabha = kPBhabha;
916 const TMCProcess kIpPAnnihilation = kPAnnihilation;
917 //const TMCProcess kIpPAnnihilInFlight = kPAnnihilInFlight;
918 //const TMCProcess kIpPAnnihilAtRest = kPAnnihilAtRest;
919 const TMCProcess kIpPHadronic = kPHadronic;
920 const TMCProcess kIpPMuonNuclear = kPMuonNuclear;
921 const TMCProcess kIpPPhotoFission = kPPhotoFission;
922 const TMCProcess kIpPRayleigh = kPRayleigh;
923 // const TMCProcess kIpPCerenkov = kPCerenkov;
924 // const TMCProcess kIpPSynchrotron = kPSynchrotron;
926 Int_t mugamma = TRACKR.jtrack == 7 || TRACKR.jtrack == 10 || TRACKR.jtrack == 11;
927 if (fIcode == 102) return kIpPDecay;
928 else if (fIcode == 104 || fIcode == 217) return kIpPPair;
929 //else if (fIcode == 104) return kIpPairFromPhoton;
930 //else if (fIcode == 217) return kIpPPairFromVirtualPhoton;
931 else if (fIcode == 219) return kIpPCompton;
932 else if (fIcode == 221) return kIpPPhotoelectric;
933 else if (fIcode == 105 || fIcode == 208) return kIpPBrem;
934 //else if (fIcode == 105) return kIpPBremFromHeavy;
935 //else if (fIcode == 208) return kPBremFromElectronOrPositron;
936 else if (fIcode == 103 || fIcode == 400) return kIpPDeltaRay;
937 else if (fIcode == 210 || fIcode == 212) return kIpPDeltaRay;
938 //else if (fIcode == 210) return kIpPMoller;
939 //else if (fIcode == 212) return kIpPBhabha;
940 else if (fIcode == 214 || fIcode == 215) return kIpPAnnihilation;
941 //else if (fIcode == 214) return kIpPAnnihilInFlight;
942 //else if (fIcode == 215) return kIpPAnnihilAtRest;
943 else if (fIcode == 101) return kIpPHadronic;
944 else if (fIcode == 101) {
945 if (!mugamma) return kIpPHadronic;
946 else if (TRACKR.jtrack == 7) return kIpPPhotoFission;
947 else return kIpPMuonNuclear;
949 else if (fIcode == 225) return kIpPRayleigh;
950 // Fluka codes 100, 300 and 400 still to be investigasted
951 else return kIpNoProc;
954 //Int_t StepProcesses(TArrayI &proc) const
955 // Return processes active in the current step
957 //ck = total energy of the particl ????????????????
961 Int_t TFluka::VolId2Mate(Int_t id) const
964 // Returns the material number for a given volume ID
966 if (fVerbosityLevel >= 3)
967 printf("VolId2Mate %d %d\n", id, fMediaByRegion[id]);
968 return fMediaByRegion[id-1];
971 const char* TFluka::VolName(Int_t id) const
974 // Returns the volume name for a given volume ID
976 FlukaVolume* vol = dynamic_cast<FlukaVolume*>((*fVolumeMediaMap)[id-1]);
977 const char* name = vol->GetName();
978 if (fVerbosityLevel >= 3)
979 printf("VolName %d %s \n", id, name);
983 Int_t TFluka::VolId(const Text_t* volName) const
986 // Converts from volume name to volume ID.
987 // Time consuming. (Only used during set-up)
988 // Could be replaced by hash-table
992 for (i = 0; i < fNVolumes; i++)
994 FlukaVolume* vol = dynamic_cast<FlukaVolume*>((*fVolumeMediaMap)[i]);
995 TString name = vol->GetName();
996 strcpy(tmp, name.Data());
998 if (!strcmp(tmp, volName)) break;
1006 Int_t TFluka::CurrentVolID(Int_t& copyNo) const
1009 // Return the logical id and copy number corresponding to the current fluka region
1011 int ir = fCurrentFlukaRegion;
1012 int id = (FGeometryInit::GetInstance())->CurrentVolID(ir, copyNo);
1013 if (fVerbosityLevel >= 3)
1014 printf("CurrentVolID: %d %d %d \n", ir, id, copyNo);
1019 Int_t TFluka::CurrentVolOffID(Int_t off, Int_t& copyNo) const
1022 // Return the logical id and copy number of off'th mother
1023 // corresponding to the current fluka region
1026 return CurrentVolID(copyNo);
1028 int ir = fCurrentFlukaRegion;
1029 int id = (FGeometryInit::GetInstance())->CurrentVolOffID(ir, off, copyNo);
1030 if (fVerbosityLevel >= 3)
1031 printf("CurrentVolOffID: %d %d %d \n", ir, id, copyNo);
1033 if (fVerbosityLevel >= 0)
1034 printf("CurrentVolOffID: Warning Mother not found !!!\n");
1039 const char* TFluka::CurrentVolName() const
1042 // Return the current volume name
1045 Int_t id = TFluka::CurrentVolID(copy);
1046 const char* name = TFluka::VolName(id);
1047 if (fVerbosityLevel >= 3)
1048 printf("CurrentVolumeName: %d %s \n", fCurrentFlukaRegion, name);
1052 const char* TFluka::CurrentVolOffName(Int_t off) const
1055 // Return the volume name of the off'th mother of the current volume
1058 Int_t id = TFluka::CurrentVolOffID(off, copy);
1059 const char* name = TFluka::VolName(id);
1060 if (fVerbosityLevel >= 3)
1061 printf("CurrentVolumeOffName: %d %s \n", fCurrentFlukaRegion, name);
1065 Int_t TFluka::CurrentMaterial(Float_t &a, Float_t &z,
1066 Float_t &dens, Float_t &radl, Float_t &absl) const
1069 // Return the current medium number
1072 Int_t id = TFluka::CurrentVolID(copy);
1073 Int_t med = TFluka::VolId2Mate(id);
1074 if (fVerbosityLevel >= 3)
1075 printf("CurrentMaterial: %d %d \n", fCurrentFlukaRegion, med);
1079 void TFluka::Gmtod(Float_t* xm, Float_t* xd, Int_t iflag)
1081 // Transforms a position from the world reference frame
1082 // to the current volume reference frame.
1084 // Geant3 desription:
1085 // ==================
1086 // Computes coordinates XD (in DRS)
1087 // from known coordinates XM in MRS
1088 // The local reference system can be initialized by
1089 // - the tracking routines and GMTOD used in GUSTEP
1090 // - a call to GMEDIA(XM,NUMED)
1091 // - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
1092 // (inverse routine is GDTOM)
1094 // If IFLAG=1 convert coordinates
1095 // IFLAG=2 convert direction cosinus
1098 Double_t xmD[3], xdD[3];
1099 xmD[0] = xm[0]; xmD[1] = xm[1]; xmD[2] = xm[2];
1100 (FGeometryInit::GetInstance())->Gmtod(xmD, xdD, iflag);
1101 xd[0] = xdD[0]; xd[1] = xdD[1]; xd[2] = xdD[2];
1105 void TFluka::Gmtod(Double_t* xm, Double_t* xd, Int_t iflag)
1107 // Transforms a position from the world reference frame
1108 // to the current volume reference frame.
1110 // Geant3 desription:
1111 // ==================
1112 // Computes coordinates XD (in DRS)
1113 // from known coordinates XM in MRS
1114 // The local reference system can be initialized by
1115 // - the tracking routines and GMTOD used in GUSTEP
1116 // - a call to GMEDIA(XM,NUMED)
1117 // - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
1118 // (inverse routine is GDTOM)
1120 // If IFLAG=1 convert coordinates
1121 // IFLAG=2 convert direction cosinus
1124 Double_t xmD[3], xdD[3];
1125 xdD[0] = xd[0]; xdD[1] = xd[1]; xdD[2] = xd[2];
1126 (FGeometryInit::GetInstance())->Gdtom(xmD, xdD, iflag);
1127 xm[0] = xmD[0]; xm[1] = xmD[1]; xm[2] = xmD[2];
1130 void TFluka::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag)
1132 // Transforms a position from the current volume reference frame
1133 // to the world reference frame.
1135 // Geant3 desription:
1136 // ==================
1137 // Computes coordinates XM (Master Reference System
1138 // knowing the coordinates XD (Detector Ref System)
1139 // The local reference system can be initialized by
1140 // - the tracking routines and GDTOM used in GUSTEP
1141 // - a call to GSCMED(NLEVEL,NAMES,NUMBER)
1142 // (inverse routine is GMTOD)
1144 // If IFLAG=1 convert coordinates
1145 // IFLAG=2 convert direction cosinus
1151 void TFluka::Gdtom(Double_t* xd, Double_t* xm, Int_t iflag)
1153 // Transforms a position from the current volume reference frame
1154 // to the world reference frame.
1156 // Geant3 desription:
1157 // ==================
1158 // Computes coordinates XM (Master Reference System
1159 // knowing the coordinates XD (Detector Ref System)
1160 // The local reference system can be initialized by
1161 // - the tracking routines and GDTOM used in GUSTEP
1162 // - a call to GSCMED(NLEVEL,NAMES,NUMBER)
1163 // (inverse routine is GMTOD)
1165 // If IFLAG=1 convert coordinates
1166 // IFLAG=2 convert direction cosinus
1170 (FGeometryInit::GetInstance())->Gdtom(xm, xd, iflag);
1173 // ===============================================================
1174 void TFluka::FutoTest()
1176 Int_t icode, mreg, newreg, particleId;
1177 Double_t rull, xsco, ysco, zsco;
1178 TLorentzVector position, momentum;
1181 if (fVerbosityLevel >=3)
1182 cout << " icode=" << icode << endl;
1183 } else if (icode > 0 && icode <= 5) {
1186 if (fVerbosityLevel >=3)
1187 cout << " icode=" << icode
1190 TrackPosition(position);
1191 TrackMomentum(momentum);
1192 if (fVerbosityLevel >=3) {
1193 cout << "TLorentzVector positionX=" << position.X()
1194 << "positionY=" << position.Y()
1195 << "positionZ=" << position.Z()
1196 << "timeT=" << position.T() << endl;
1197 cout << "TLorentzVector momentumX=" << momentum.X()
1198 << "momentumY=" << momentum.Y()
1199 << "momentumZ=" << momentum.Z()
1200 << "energyE=" << momentum.E() << endl;
1201 cout << "TrackStep=" << TrackStep() << endl;
1202 cout << "TrackLength=" << TrackLength() << endl;
1203 cout << "TrackTime=" << TrackTime() << endl;
1204 cout << "Edep=" << Edep() << endl;
1205 cout << "TrackPid=" << TrackPid() << endl;
1206 cout << "TrackCharge=" << TrackCharge() << endl;
1207 cout << "TrackMass=" << TrackMass() << endl;
1208 cout << "Etot=" << Etot() << endl;
1209 cout << "IsNewTrack=" << IsNewTrack() << endl;
1210 cout << "IsTrackInside=" << IsTrackInside() << endl;
1211 cout << "IsTrackEntering=" << IsTrackEntering() << endl;
1212 cout << "IsTrackExiting=" << IsTrackExiting() << endl;
1213 cout << "IsTrackOut=" << IsTrackOut() << endl;
1214 cout << "IsTrackDisappeared=" << IsTrackDisappeared() << endl;
1215 cout << "IsTrackAlive=" << IsTrackAlive() << endl;
1218 Float_t x = position.X();
1219 Float_t y = position.Y();
1220 Float_t z = position.Z();
1223 xm[0] = x; xm[1] = y; xm[2] = z;
1224 if (fVerbosityLevel >= 3)
1225 printf("Global trackPosition: %f %f %f \n", x, y, z);
1227 if (fVerbosityLevel >= 3)
1228 printf("Local trackPosition: %f %f %f \n", xd[0], xd[1], xd[2]);
1230 if (fVerbosityLevel >= 3)
1231 printf("New trackPosition: %f %f %f \n", xm[0], xm[1], xm[2]);
1232 } else if((icode >= 10 && icode <= 15) ||
1233 (icode >= 20 && icode <= 24) ||
1234 (icode >= 30 && icode <= 33) ||
1235 (icode >= 40 && icode <= 41) ||
1236 (icode >= 50 && icode <= 52)) {
1244 if (fVerbosityLevel >=3) {
1245 cout << " icode=" << icode
1250 << " zsco=" << zsco << endl;
1252 TrackPosition(position);
1253 TrackMomentum(momentum);
1254 if (fVerbosityLevel >=3) {
1255 cout << "Edep=" << Edep() << endl;
1256 cout << "Etot=" << Etot() << endl;
1257 cout << "TrackPid=" << TrackPid() << endl;
1258 cout << "TrackCharge=" << TrackCharge() << endl;
1259 cout << "TrackMass=" << TrackMass() << endl;
1260 cout << "IsTrackOut=" << IsTrackOut() << endl;
1261 cout << "IsTrackDisappeared=" << IsTrackDisappeared() << endl;
1262 cout << "IsTrackStop=" << IsTrackStop() << endl;
1263 cout << "IsTrackAlive=" << IsTrackAlive() << endl;
1265 } else if((icode >= 100 && icode <= 105) ||
1269 (icode >= 214 && icode <= 215) ||
1282 if (fVerbosityLevel >=3) {
1283 cout << " icode=" << icode
1287 << " zsco=" << zsco << endl;
1288 cout << "TrackPid=" << TrackPid() << endl;
1289 cout << "NSecondaries=" << NSecondaries() << endl;
1292 for (Int_t isec=0; isec< NSecondaries(); isec++) {
1293 TFluka::GetSecondary(isec, particleId, position, momentum);
1294 if (fVerbosityLevel >=3) {
1295 cout << "TLorentzVector positionX=" << position.X()
1296 << "positionY=" << position.Y()
1297 << "positionZ=" << position.Z()
1298 << "timeT=" << position.T() << endl;
1299 cout << "TLorentzVector momentumX=" << momentum.X()
1300 << "momentumY=" << momentum.Y()
1301 << "momentumZ=" << momentum.Z()
1302 << "energyE=" << momentum.E() << endl;
1303 cout << "TrackPid=" << particleId << endl;
1306 } else if((icode == 19) ||
1312 newreg = GetNewreg();
1316 if (fVerbosityLevel >=3) {
1317 cout << " icode=" << icode
1319 << " newreg=" << newreg
1322 << " zsco=" << zsco << endl;
1325 } // end of FutoTest