First commit.
[u/mrichter/AliRoot.git] / TFluka / TFluka.cxx
CommitLineData
829fb838 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18//
19// Realisation of the TVirtualMC interface for the FLUKA code
20// (See official web side http://www.fluka.org/).
21//
22// This implementation makes use of the TGeo geometry modeller.
23// User configuration is via automatic generation of FLUKA input cards.
24//
25// Authors:
26// A. Fasso
27// E. Futo
28// A. Gheata
29// A. Morsch
30//
31
32#include <Riostream.h>
33
829fb838 34#include "TFluka.h"
a9ea1616 35#include "TFlukaCodes.h"
829fb838 36#include "TCallf77.h" //For the fortran calls
37#include "Fdblprc.h" //(DBLPRC) fluka common
81f1d030 38#include "Fsourcm.h" //(SOURCM) fluka common
39#include "Fgenstk.h" //(GENSTK) fluka common
829fb838 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
3a625972 46#include "Fopphst.h" //(OPPHST) fluka common
81f1d030 47#include "Fflkstk.h" //(FLKSTK) fluka common
07f5b33e 48#include "Fstepsz.h" //(STEPSZ) fluka common
7b203b6e 49#include "Fopphst.h" //(OPPHST) fluka common
a9ea1616 50#include "Fltclcm.h" //(LTCLCM) fluka common
829fb838 51
52#include "TVirtualMC.h"
3a625972 53#include "TMCProcess.h"
829fb838 54#include "TGeoManager.h"
55#include "TGeoMaterial.h"
56#include "TGeoMedium.h"
57#include "TFlukaMCGeometry.h"
6f5667d1 58#include "TGeoMCGeometry.h"
829fb838 59#include "TFlukaCerenkov.h"
1df5fa54 60#include "TFlukaConfigOption.h"
b496f27c 61#include "TFlukaScoringOption.h"
829fb838 62#include "TLorentzVector.h"
b496f27c 63#include "TArrayI.h"
a9ea1616 64#include "TArrayD.h"
78df7be0 65#include "TDatabasePDG.h"
829fb838 66
67// Fluka methods that may be needed.
68#ifndef WIN32
69# define flukam flukam_
70# define fluka_openinp fluka_openinp_
8e5bf079 71# define fluka_openout fluka_openout_
829fb838 72# define fluka_closeinp fluka_closeinp_
73# define mcihad mcihad_
74# define mpdgha mpdgha_
2047b055 75# define newplo newplo_
829fb838 76#else
77# define flukam FLUKAM
78# define fluka_openinp FLUKA_OPENINP
8e5bf079 79# define fluka_openout FLUKA_OPENOUT
829fb838 80# define fluka_closeinp FLUKA_CLOSEINP
81# define mcihad MCIHAD
82# define mpdgha MPDGHA
eea53470 83# define newplo NEWPLO
829fb838 84#endif
85
86extern "C"
87{
88 //
89 // Prototypes for FLUKA functions
90 //
91 void type_of_call flukam(const int&);
eea53470 92 void type_of_call newplo();
829fb838 93 void type_of_call fluka_openinp(const int&, DEFCHARA);
8e5bf079 94 void type_of_call fluka_openout(const int&, DEFCHARA);
829fb838 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&);
98}
99
100//
101// Class implementation for ROOT
102//
103ClassImp(TFluka)
104
105//
106//----------------------------------------------------------------------------
107// TFluka constructors and destructors.
108//______________________________________________________________________________
109TFluka::TFluka()
110 :TVirtualMC(),
111 fVerbosityLevel(0),
1df5fa54 112 fInputFileName(""),
fb2cbbec 113 fUserConfig(0),
1df5fa54 114 fUserScore(0)
829fb838 115{
116 //
117 // Default constructor
118 //
119 fGeneratePemf = kFALSE;
120 fNVolumes = 0;
121 fCurrentFlukaRegion = -1;
a9ea1616 122 fNewReg = -1;
829fb838 123 fGeom = 0;
124 fMCGeo = 0;
125 fMaterials = 0;
126 fDummyBoundary = 0;
127 fFieldFlag = 1;
bd3d5c8a 128 fStopped = 0;
b496f27c 129 fStopEvent = 0;
130 fStopRun = 0;
131 fNEvent = 0;
829fb838 132}
133
134//______________________________________________________________________________
135TFluka::TFluka(const char *title, Int_t verbosity, Bool_t isRootGeometrySupported)
136 :TVirtualMC("TFluka",title, isRootGeometrySupported),
137 fVerbosityLevel(verbosity),
138 fInputFileName(""),
139 fTrackIsEntering(0),
140 fTrackIsExiting(0),
1df5fa54 141 fTrackIsNew(0),
fb2cbbec 142 fUserConfig(new TObjArray(100)),
1df5fa54 143 fUserScore(new TObjArray(100))
829fb838 144{
145 // create geometry interface
7f13be31 146 if (fVerbosityLevel >=3)
147 cout << "<== TFluka::TFluka(" << title << ") constructor called." << endl;
148 SetCoreInputFileName();
149 SetInputFileName();
150 SetGeneratePemf(kFALSE);
829fb838 151 fNVolumes = 0;
152 fCurrentFlukaRegion = -1;
a9ea1616 153 fNewReg = -1;
829fb838 154 fDummyBoundary = 0;
155 fFieldFlag = 1;
156 fGeneratePemf = kFALSE;
11e4ab84 157 fMCGeo = new TGeoMCGeometry("MCGeo", "TGeo Implementation of VirtualMCGeometry", kFALSE);
fb2cbbec 158 fGeom = new TFlukaMCGeometry("geom", "FLUKA VMC Geometry");
829fb838 159 if (verbosity > 2) fGeom->SetDebugMode(kTRUE);
160 fMaterials = 0;
bd3d5c8a 161 fStopped = 0;
b496f27c 162 fStopEvent = 0;
163 fStopRun = 0;
164 fNEvent = 0;
8e5bf079 165 PrintHeader();
829fb838 166}
167
168//______________________________________________________________________________
169TFluka::~TFluka() {
170// Destructor
1df5fa54 171 if (fVerbosityLevel >=3)
172 cout << "<== TFluka::~TFluka() destructor called." << endl;
173
174 delete fGeom;
175 delete fMCGeo;
176
fb2cbbec 177 if (fUserConfig) {
178 fUserConfig->Delete();
179 delete fUserConfig;
1df5fa54 180 }
6d184c54 181
182 if (fUserScore) {
183 fUserScore->Delete();
184 delete fUserScore;
185 }
829fb838 186}
187
188//
189//______________________________________________________________________________
190// TFluka control methods
191//______________________________________________________________________________
192void TFluka::Init() {
193//
194// Geometry initialisation
195//
196 if (fVerbosityLevel >=3) cout << "==> TFluka::Init() called." << endl;
197
198 if (!gGeoManager) new TGeoManager("geom", "FLUKA geometry");
199 fApplication->ConstructGeometry();
d59acfe7 200 if (!gGeoManager->IsClosed()) {
201 TGeoVolume *top = (TGeoVolume*)gGeoManager->GetListOfVolumes()->First();
202 gGeoManager->SetTopVolume(top);
203 gGeoManager->CloseGeometry("di");
204 } else {
205 TGeoNodeCache *cache = gGeoManager->GetCache();
206 if (!cache->HasIdArray()) {
a9ea1616 207 Warning("Init", "Node ID tracking must be enabled with TFluka: enabling...\n");
d59acfe7 208 cache->BuildIdArray();
209 }
210 }
829fb838 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;
6d184c54 216 }
881cb248 217
218 fApplication->InitGeometry();
78df7be0 219
220 //
221 // Add ions to PDG Data base
222 //
223 AddParticlesToPdgDataBase();
829fb838 224}
225
226
227//______________________________________________________________________________
228void TFluka::FinishGeometry() {
229//
230// Build-up table with region to medium correspondance
231//
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;
236 }
237}
238
239//______________________________________________________________________________
240void TFluka::BuildPhysics() {
241//
242// Prepare FLUKA input files and call FLUKA physics initialisation
243//
244
245 if (fVerbosityLevel >=3)
246 cout << "==> TFluka::BuildPhysics() called." << endl;
6d184c54 247
248
249 if (fVerbosityLevel >=3) {
250 TList *medlist = gGeoManager->GetListOfMedia();
251 TIter next(medlist);
252 TGeoMedium* med = 0x0;
253 TGeoMaterial* mat = 0x0;
254 Int_t ic = 0;
255
256 while((med = (TGeoMedium*)next()))
257 {
258 mat = med->GetMaterial();
259 printf("Medium %5d %12s %5d %5d\n", ic, (med->GetName()), med->GetId(), mat->GetIndex());
260 ic++;
261 }
262 }
263
264 //
265 // At this stage we have the information on materials and cuts available.
266 // Now create the pemf file
267
268 if (fGeneratePemf) fGeom->CreatePemfFile();
269
270 //
271 // Prepare input file with the current physics settings
272
829fb838 273 InitPhysics();
b8a8a88c 274// Open fortran files
829fb838 275 const char* fname = fInputFileName;
276 fluka_openinp(lunin, PASSCHARA(fname));
8e5bf079 277 fluka_openout(11, PASSCHARA("fluka.out"));
b8a8a88c 278// Read input cards
279 GLOBAL.lfdrtr = true;
829fb838 280 flukam(1);
b8a8a88c 281// Close input file
829fb838 282 fluka_closeinp(lunin);
b8a8a88c 283// Finish geometry
829fb838 284 FinishGeometry();
829fb838 285}
286
287//______________________________________________________________________________
288void TFluka::ProcessEvent() {
289//
290// Process one event
291//
b496f27c 292 if (fStopRun) {
a9ea1616 293 Warning("ProcessEvent", "User Run Abortion: No more events handled !\n");
b496f27c 294 fNEvent += 1;
295 return;
296 }
297
298 if (fVerbosityLevel >=3)
299 cout << "==> TFluka::ProcessEvent() called." << endl;
300 fApplication->GeneratePrimaries();
81f1d030 301 SOURCM.lsouit = true;
b496f27c 302 flukam(1);
303 if (fVerbosityLevel >=3)
304 cout << "<== TFluka::ProcessEvent() called." << endl;
305 //
306 // Increase event number
307 //
308 fNEvent += 1;
829fb838 309}
310
311//______________________________________________________________________________
312Bool_t TFluka::ProcessRun(Int_t nevent) {
313//
314// Run steering
315//
316
317 if (fVerbosityLevel >=3)
318 cout << "==> TFluka::ProcessRun(" << nevent << ") called."
319 << endl;
320
321 if (fVerbosityLevel >=2) {
322 cout << "\t* GLOBAL.fdrtr = " << (GLOBAL.lfdrtr?'T':'F') << endl;
323 cout << "\t* Calling flukam again..." << endl;
324 }
325
829fb838 326 Int_t todo = TMath::Abs(nevent);
327 for (Int_t ev = 0; ev < todo; ev++) {
328 fApplication->BeginEvent();
329 ProcessEvent();
330 fApplication->FinishEvent();
331 }
332
333 if (fVerbosityLevel >=3)
334 cout << "<== TFluka::ProcessRun(" << nevent << ") called."
335 << endl;
eea53470 336 // Write fluka specific scoring output
337 newplo();
338
829fb838 339 return kTRUE;
340}
341
342//_____________________________________________________________________________
343// methods for building/management of geometry
344
345// functions from GCONS
346//____________________________________________________________________________
347void 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*/) {
350//
351 TGeoMaterial *mat;
352 TIter next (gGeoManager->GetListOfMaterials());
353 while ((mat = (TGeoMaterial*)next())) {
354 if (mat->GetUniqueID() == (UInt_t)imat) break;
355 }
356 if (!mat) {
357 Error("Gfmate", "no material with index %i found", imat);
358 return;
359 }
360 sprintf(name, "%s", mat->GetName());
361 a = mat->GetA();
362 z = mat->GetZ();
363 dens = mat->GetDensity();
364 radl = mat->GetRadLen();
365 absl = mat->GetIntLen();
366}
367
368//______________________________________________________________________________
369void 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*/) {
372//
373 TGeoMaterial *mat;
374 TIter next (gGeoManager->GetListOfMaterials());
375 while ((mat = (TGeoMaterial*)next())) {
376 if (mat->GetUniqueID() == (UInt_t)imat) break;
377 }
378 if (!mat) {
379 Error("Gfmate", "no material with index %i found", imat);
380 return;
381 }
382 sprintf(name, "%s", mat->GetName());
383 a = mat->GetA();
384 z = mat->GetZ();
385 dens = mat->GetDensity();
386 radl = mat->GetRadLen();
387 absl = mat->GetIntLen();
388}
389
390// detector composition
391//______________________________________________________________________________
392void 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) {
395//
396 Double_t* dbuf = fGeom->CreateDoubleArray(buf, nwbuf);
397 Material(kmat, name, a, z, dens, radl, absl, dbuf, nwbuf);
398 delete [] dbuf;
399}
400
401//______________________________________________________________________________
402void 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*/) {
405//
fb2cbbec 406// Define a material
829fb838 407 TGeoMaterial *mat;
408 kmat = gGeoManager->GetListOfMaterials()->GetSize();
409 if ((z-Int_t(z)) > 1E-3) {
410 mat = fGeom->GetMakeWrongMaterial(z);
411 if (mat) {
412 mat->SetRadLen(radl,absl);
413 mat->SetUniqueID(kmat);
414 return;
415 }
416 }
417 gGeoManager->Material(name, a, z, dens, kmat, radl, absl);
418}
419
420//______________________________________________________________________________
421void TFluka::Mixture(Int_t& kmat, const char *name, Float_t *a,
422 Float_t *z, Double_t dens, Int_t nlmat, Float_t *wmat) {
423//
fb2cbbec 424// Define a material mixture
425//
829fb838 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));
429
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];
433 }
434
435 delete [] da;
436 delete [] dz;
437 delete [] dwmat;
438}
439
440//______________________________________________________________________________
441void TFluka::Mixture(Int_t& kmat, const char *name, Double_t *a,
442 Double_t *z, Double_t dens, Int_t nlmat, Double_t *wmat) {
443//
444 // Defines mixture OR COMPOUND IMAT as composed by
445 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
446 //
447 // If NLMAT > 0 then wmat contains the proportion by
448 // weights of each basic material in the mixture.
449 //
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
453 // weigths.
454 //
455 Int_t i,j;
456 if (nlmat < 0) {
457 nlmat = - nlmat;
458 Double_t amol = 0;
459 for (i=0;i<nlmat;i++) {
460 amol += a[i]*wmat[i];
461 }
462 for (i=0;i<nlmat;i++) {
463 wmat[i] *= a[i]/amol;
464 }
465 }
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);
476 if (!mat) break;
477 if (!mat->IsMixture()) continue;
478 mix = (TGeoMixture*)mat;
479 if (TMath::Abs(z[i]-mix->GetZ()) >1E-3) continue;
829fb838 480 mixnew = kTRUE;
481 break;
482 }
483 if (!mixnew) Warning("Mixture","%s : cannot find component %i with fractional Z=%f\n", name, i, z[i]);
484 break;
485 }
486 if (mixnew) {
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];
491 Int_t ind=0;
492 for (j=0; j<nlmat; j++) {
493 if (j==i) continue;
494 anew[ind] = a[j];
495 znew[ind] = z[j];
496 wmatnew[ind] = wmat[j];
497 ind++;
498 }
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];
503 ind++;
504 }
505 Mixture(kmat, name, anew, znew, dens, nlmatnew, wmatnew);
506 delete [] anew;
507 delete [] znew;
508 delete [] wmatnew;
509 return;
510 }
511 // Now we need to compact identical elements within the mixture
512 // First check if this happens
513 mixnew = kFALSE;
514 for (i=0; i<nlmat-1; i++) {
515 for (j=i+1; j<nlmat; j++) {
516 if (z[i] == z[j]) {
517 mixnew = kTRUE;
518 break;
519 }
520 }
521 if (mixnew) break;
522 }
523 if (mixnew) {
524 Int_t nlmatnew = 0;
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];
529 Bool_t skipi;
530 for (i=0; i<nlmat; i++) {
531 skipi = kFALSE;
532 for (j=0; j<nlmatnew; j++) {
533 if (z[i] == z[j]) {
534 wmatnew[j] += wmat[i];
535 skipi = kTRUE;
536 break;
537 }
538 }
539 if (skipi) continue;
540 anew[nlmatnew] = a[i];
541 znew[nlmatnew] = z[i];
542 wmatnew[nlmatnew] = wmat[i];
543 nlmatnew++;
544 }
545 Mixture(kmat, name, anew, znew, dens, nlmatnew, wmatnew);
546 delete [] anew;
547 delete [] znew;
548 delete [] wmatnew;
549 return;
550 }
551 gGeoManager->Mixture(name, a, z, dens, nlmat, wmat, kmat);
552}
553
554//______________________________________________________________________________
555void 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) {
b2129742 559 // Define a medium
560 //
829fb838 561 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
562 fMCGeo->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
563 epsil, stmin, ubuf, nbuf);
564}
565
566//______________________________________________________________________________
567void 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) {
b2129742 571 // Define a medium
572 //
829fb838 573 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
574 fMCGeo->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
575 epsil, stmin, ubuf, nbuf);
576}
577
578//______________________________________________________________________________
579void TFluka::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
580 Double_t thetaY, Double_t phiY, Double_t thetaZ,
581 Double_t phiZ) {
582//
583 krot = gGeoManager->GetListOfMatrices()->GetEntriesFast();
584 fMCGeo->Matrix(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
585}
586
587//______________________________________________________________________________
588void TFluka::Gstpar(Int_t itmed, const char* param, Double_t parval) {
589//
590//
7b203b6e 591//
829fb838 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)
607 {
608 process = kTRUE;
609 }
81f1d030 610
829fb838 611 if (process) {
81f1d030 612 SetProcess(param, Int_t (parval), itmed);
829fb838 613 } else {
81f1d030 614 SetCut(param, parval, itmed);
829fb838 615 }
616}
617
618// functions from GGEOM
619//_____________________________________________________________________________
620void TFluka::Gsatt(const char *name, const char *att, Int_t val)
621{
6f5667d1 622 // Set visualisation attributes for one volume
829fb838 623 char vname[5];
624 fGeom->Vname(name,vname);
625 char vatt[5];
626 fGeom->Vname(att,vatt);
627 gGeoManager->SetVolumeAttribute(vname, vatt, val);
628}
629
630//______________________________________________________________________________
631Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
632 Float_t *upar, Int_t np) {
633//
634 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
635}
636
637//______________________________________________________________________________
638Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
639 Double_t *upar, Int_t np) {
640//
641 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
642}
643
644//______________________________________________________________________________
645void TFluka::Gsdvn(const char *name, const char *mother, Int_t ndiv,
646 Int_t iaxis) {
647//
648 fMCGeo->Gsdvn(name, mother, ndiv, iaxis);
649}
650
651//______________________________________________________________________________
652void TFluka::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
653 Int_t iaxis, Double_t c0i, Int_t numed) {
654//
655 fMCGeo->Gsdvn2(name, mother, ndiv, iaxis, c0i, numed);
656}
657
658//______________________________________________________________________________
659void TFluka::Gsdvt(const char *name, const char *mother, Double_t step,
660 Int_t iaxis, Int_t numed, Int_t ndvmx) {
661//
662 fMCGeo->Gsdvt(name, mother, step, iaxis, numed, ndvmx);
663}
664
665//______________________________________________________________________________
666void TFluka::Gsdvt2(const char *name, const char *mother, Double_t step,
667 Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx) {
668//
669 fMCGeo->Gsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
670}
671
672//______________________________________________________________________________
673void TFluka::Gsord(const char * /*name*/, Int_t /*iax*/) {
674//
675// Nothing to do with TGeo
676}
677
678//______________________________________________________________________________
679void TFluka::Gspos(const char *name, Int_t nr, const char *mother,
680 Double_t x, Double_t y, Double_t z, Int_t irot,
681 const char *konly) {
682//
683 fMCGeo->Gspos(name, nr, mother, x, y, z, irot, konly);
684}
685
686//______________________________________________________________________________
687void 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) {
690 //
691 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
692}
693
694//______________________________________________________________________________
695void 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) {
698 //
699 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
700}
701
702//______________________________________________________________________________
703void TFluka::Gsbool(const char* /*onlyVolName*/, const char* /*manyVolName*/) {
704//
705// Nothing to do with TGeo
706}
707
a9ea1616 708//______________________________________________________________________
709Bool_t TFluka::GetTransformation(const TString &volumePath,TGeoHMatrix &mat)
710{
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.
718 // Inputs:
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 "_".
723 // Outputs:
724 // TGeoHMatrix &mat A matrix with its values set to those
725 // appropriate to the Local to Master transformation
726 // Return:
727 // A logical value if kFALSE then an error occurred and no change to
728 // mat was made.
729
730 // We have to preserve the modeler state
731 return fMCGeo->GetTransformation(volumePath, mat);
732}
733
734//______________________________________________________________________
735Bool_t TFluka::GetShape(const TString &volumePath,TString &shapeType,
736 TArrayD &par)
737{
738 // Returns the shape and its parameters for the volume specified
739 // by volumeName.
740 // Inputs:
741 // TString& volumeName The volume name
742 // Outputs:
743 // TString &shapeType Shape type
744 // TArrayD &par A TArrayD of parameters with all of the
745 // parameters of the specified shape.
746 // Return:
747 // A logical indicating whether there was an error in getting this
748 // information
749 return fMCGeo->GetShape(volumePath, shapeType, par);
750}
751
752//______________________________________________________________________
753Bool_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)
757{
758 // Returns the Material and its parameters for the volume specified
759 // by volumeName.
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.
763 // Inputs:
764 // TString& volumeName The volume name
765 // Outputs:
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.
774 // Return:
775 // kTRUE if no errors
776 return fMCGeo->GetMaterial(volumeName,name,imat,a,z,dens,radl,inter,par);
777}
778
779//______________________________________________________________________
780Bool_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,
784 TArrayD &par)
785{
786 // Returns the Medium and its parameters for the volume specified
787 // by volumeName.
788 // Inputs:
789 // TString& volumeName The volume name.
790 // Outputs:
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.
805 // Return:
806 // kTRUE if there where no errors
807 return fMCGeo->GetMedium(volumeName,name,imed,nmat,isvol,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin,par);
808}
809
829fb838 810//______________________________________________________________________________
811void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
812 Float_t* absco, Float_t* effic, Float_t* rindex) {
813//
814// Set Cerenkov properties for medium itmed
815//
816// npckov: number of sampling points
817// ppckov: energy values
818// absco: absorption length
819// effic: quantum efficiency
820// rindex: refraction index
821//
822//
823//
824// Create object holding Cerenkov properties
825//
826 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex);
827//
828// Pass object to medium
829 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
830 medium->SetCerenkovProperties(cerenkovProperties);
831}
832
b2be0e73 833void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
834 Float_t* absco, Float_t* effic, Float_t* rindex, Float_t* rfl) {
835//
836// Set Cerenkov properties for medium itmed
837//
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
844//
845//
846// Create object holding Cerenkov properties
847//
848 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex, rfl);
849//
850// Pass object to medium
851 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
852 medium->SetCerenkovProperties(cerenkovProperties);
853}
854
855
829fb838 856//______________________________________________________________________________
857void TFluka::SetCerenkov(Int_t /*itmed*/, Int_t /*npckov*/, Double_t * /*ppckov*/,
858 Double_t * /*absco*/, Double_t * /*effic*/, Double_t * /*rindex*/) {
859//
b2be0e73 860// Double_t version not implemented
829fb838 861}
b2be0e73 862
863void TFluka::SetCerenkov(Int_t /*itmed*/, Int_t /*npckov*/, Double_t* /*ppckov*/,
864 Double_t* /*absco*/, Double_t* /*effic*/, Double_t* /*rindex*/, Double_t* /*rfl*/) {
865//
866// // Double_t version not implemented
867}
868
829fb838 869// Euclid
870//______________________________________________________________________________
871void TFluka::WriteEuclid(const char* /*fileName*/, const char* /*topVol*/,
872 Int_t /*number*/, Int_t /*nlevel*/) {
873//
874// Not with TGeo
a9ea1616 875 Warning("WriteEuclid", "Not implemented !");
829fb838 876}
877
878
879
880//_____________________________________________________________________________
881// methods needed by the stepping
882//____________________________________________________________________________
883
884Int_t TFluka::GetMedium() const {
885//
886// Get the medium number for the current fluka region
887//
888 return fGeom->GetMedium(); // this I need to check due to remapping !!!
889}
890
a9ea1616 891//____________________________________________________________________________
892Int_t TFluka::GetDummyRegion() const
893{
894// Returns index of the dummy region.
895 return fGeom->GetDummyRegion();
896}
829fb838 897
a9ea1616 898//____________________________________________________________________________
899Int_t TFluka::GetDummyLattice() const
900{
901// Returns index of the dummy lattice.
902 return fGeom->GetDummyLattice();
903}
829fb838 904
905//____________________________________________________________________________
906// particle table usage
907// ID <--> PDG transformations
908//_____________________________________________________________________________
909Int_t TFluka::IdFromPDG(Int_t pdg) const
910{
911 //
912 // Return Fluka code from PDG and pseudo ENDF code
913
914 // Catch the feedback photons
a9ea1616 915 if (pdg == 50000051) return (kFLUKAoptical);
829fb838 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);
920}
921
922//______________________________________________________________________________
923Int_t TFluka::PDGFromId(Int_t id) const
924{
925 //
926 // Return PDG code and pseudo ENDF code from Fluka code
f926898e 927 // Alpha He3 Triton Deuteron gen. ion opt. photon
928 Int_t idSpecial[6] = {10020040, 10020030, 10010030, 10010020, 10000000, 50000050};
829fb838 929 // IPTOKP array goes from official to internal
930
a9ea1616 931 if (id == kFLUKAoptical) {
829fb838 932// Cerenkov photon
bd3d5c8a 933 if (fVerbosityLevel >= 3)
829fb838 934 printf("\n PDGFromId: Cerenkov Photon \n");
935 return 50000050;
936 }
937// Error id
ece92b30 938 if (id == 0 || id < kFLUKAcodemin || id > kFLUKAcodemax) {
f926898e 939 if (fVerbosityLevel >= 3)
829fb838 940 printf("PDGFromId: Error id = 0\n");
941 return -1;
942 }
943// Good id
f926898e 944 if (id > 0) {
945 Int_t intfluka = GetFlukaIPTOKP(id);
946 if (intfluka == 0) {
947 if (fVerbosityLevel >= 3)
948 printf("PDGFromId: Error intfluka = 0: %d\n", id);
949 return -1;
950 } else if (intfluka < 0) {
951 if (fVerbosityLevel >= 3)
952 printf("PDGFromId: Error intfluka < 0: %d\n", id);
953 return -1;
954 }
18e0cabb 955// if (fVerbosityLevel >= 3)
956// printf("mpdgha called with %d %d \n", id, intfluka);
f926898e 957 return mpdgha(intfluka);
958 } else {
959 // ions and optical photons
ece92b30 960 return idSpecial[id - kFLUKAcodemin];
829fb838 961 }
829fb838 962}
963
bd3d5c8a 964void TFluka::StopTrack()
965{
966 // Set stopping conditions
967 // Works for photons and charged particles
968 fStopped = kTRUE;
969}
970
829fb838 971//_____________________________________________________________________________
972// methods for physics management
973//____________________________________________________________________________
974//
975// set methods
976//
977
1df5fa54 978void TFluka::SetProcess(const char* flagName, Int_t flagValue, Int_t imed)
829fb838 979{
980// Set process user flag for material imat
981//
1df5fa54 982//
983// Update if already in the list
984//
fb2cbbec 985 TIter next(fUserConfig);
1df5fa54 986 TFlukaConfigOption* proc;
987 while((proc = (TFlukaConfigOption*)next()))
988 {
fb2cbbec 989 if (proc->Medium() == imed) {
990 proc->SetProcess(flagName, flagValue);
991 return;
992 }
1df5fa54 993 }
fb2cbbec 994 proc = new TFlukaConfigOption(imed);
995 proc->SetProcess(flagName, flagValue);
996 fUserConfig->Add(proc);
997}
998
999//______________________________________________________________________________
1000Bool_t TFluka::SetProcess(const char* flagName, Int_t flagValue)
1001{
1002// Set process user flag
1df5fa54 1003//
1df5fa54 1004//
fb2cbbec 1005 SetProcess(flagName, flagValue, -1);
1df5fa54 1006 return kTRUE;
829fb838 1007}
1008
1009//______________________________________________________________________________
1010void TFluka::SetCut(const char* cutName, Double_t cutValue, Int_t imed)
1011{
1012// Set user cut value for material imed
1013//
fb2cbbec 1014 TIter next(fUserConfig);
1015 TFlukaConfigOption* proc;
1016 while((proc = (TFlukaConfigOption*)next()))
1017 {
1018 if (proc->Medium() == imed) {
1019 proc->SetCut(cutName, cutValue);
1020 return;
1021 }
1022 }
1023
1024 proc = new TFlukaConfigOption(imed);
1025 proc->SetCut(cutName, cutValue);
1026 fUserConfig->Add(proc);
829fb838 1027}
1028
1029//______________________________________________________________________________
1030Bool_t TFluka::SetCut(const char* cutName, Double_t cutValue)
1031{
1032// Set user cut value
1033//
1df5fa54 1034//
fb2cbbec 1035 SetCut(cutName, cutValue, -1);
1036 return kTRUE;
829fb838 1037}
1038
f450e9d0 1039
1040void TFluka::SetUserScoring(const char* option, Int_t npr, char* outfile, Float_t* what)
b496f27c 1041{
1042//
f450e9d0 1043// Adds a user scoring option to the list
b496f27c 1044//
f450e9d0 1045 TFlukaScoringOption* opt = new TFlukaScoringOption(option, "User Scoring", npr,outfile,what);
1046 fUserScore->Add(opt);
1047}
1048//______________________________________________________________________________
1049void TFluka::SetUserScoring(const char* option, Int_t npr, char* outfile, Float_t* what, const char* det1, const char* det2, const char* det3)
1050{
1051//
1052// Adds a user scoring option to the list
1053//
1054 TFlukaScoringOption* opt = new TFlukaScoringOption(option, "User Scoring", npr, outfile, what, det1, det2, det3);
b496f27c 1055 fUserScore->Add(opt);
1056}
b496f27c 1057
829fb838 1058//______________________________________________________________________________
1059Double_t TFluka::Xsec(char*, Double_t, Int_t, Int_t)
1060{
a9ea1616 1061 Warning("Xsec", "Not yet implemented.!\n"); return -1.;
829fb838 1062}
1063
1064
1065//______________________________________________________________________________
1066void TFluka::InitPhysics()
1067{
1068//
1069// Physics initialisation with preparation of FLUKA input cards
1070//
fb2cbbec 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();
1078
1079// Open files
1080 if ((pFlukaVmcCoreInp = fopen(sFlukaVmcCoreInp.Data(),"r")) == NULL) {
a9ea1616 1081 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcCoreInp.Data());
fb2cbbec 1082 exit(1);
1083 }
1084 if ((pFlukaVmcFlukaMat = fopen(sFlukaVmcTmp.Data(),"r")) == NULL) {
a9ea1616 1085 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcTmp.Data());
fb2cbbec 1086 exit(1);
1087 }
1088 if ((pFlukaVmcInp = fopen(sFlukaVmcInp.Data(),"w")) == NULL) {
a9ea1616 1089 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcInp.Data());
fb2cbbec 1090 exit(1);
1091 }
829fb838 1092
fb2cbbec 1093// Copy core input file
1094 Char_t sLine[255];
1095 Float_t fEventsPerRun;
829fb838 1096
fb2cbbec 1097 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
1098 if (strncmp(sLine,"GEOEND",6) != 0)
1099 fprintf(pFlukaVmcInp,"%s",sLine); // copy until GEOEND card
1100 else {
1101 fprintf(pFlukaVmcInp,"GEOEND\n"); // add GEOEND card
1102 goto flukamat;
829fb838 1103 }
fb2cbbec 1104 } // end of while until GEOEND card
1105
829fb838 1106
fb2cbbec 1107 flukamat:
1108 while ((fgets(sLine,255,pFlukaVmcFlukaMat)) != NULL) { // copy flukaMat.inp file
1109 fprintf(pFlukaVmcInp,"%s\n",sLine);
1110 }
1111
1112 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
1113 if (strncmp(sLine,"START",5) != 0)
1114 fprintf(pFlukaVmcInp,"%s\n",sLine);
1115 else {
1116 sscanf(sLine+10,"%10f",&fEventsPerRun);
1117 goto fin;
1118 }
1119 } //end of while until START card
1120
1121 fin:
829fb838 1122
f450e9d0 1123
1124// Pass information to configuration objects
829fb838 1125
fb2cbbec 1126 Float_t fLastMaterial = fGeom->GetLastMaterialIndex();
1127 TFlukaConfigOption::SetStaticInfo(pFlukaVmcInp, 3, fLastMaterial, fGeom);
1128
1129 TIter next(fUserConfig);
1130 TFlukaConfigOption* proc;
f450e9d0 1131 while((proc = dynamic_cast<TFlukaConfigOption*> (next()))) proc->WriteFlukaInputCards();
1132//
1133// Process Fluka specific scoring options
1134//
1135 TFlukaScoringOption::SetStaticInfo(pFlukaVmcInp, fGeom);
1136 Float_t loginp = 49.0;
1137 Int_t inp = 0;
1138 Int_t nscore = fUserScore->GetEntries();
1139
a9ea1616 1140 TFlukaScoringOption *mopo = 0;
1141 TFlukaScoringOption *mopi = 0;
fb2cbbec 1142
f450e9d0 1143 for (Int_t isc = 0; isc < nscore; isc++)
1144 {
1145 mopo = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isc));
1146 char* fileName = mopo->GetFileName();
1147 Int_t size = strlen(fileName);
1148 Float_t lun = -1.;
1149//
1150// Check if new output file has to be opened
1151 for (Int_t isci = 0; isci < isc; isci++) {
a9d74780 1152
1153
1154 mopi = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isci));
f450e9d0 1155 if(strncmp(mopi->GetFileName(), fileName, size)==0) {
1156 //
1157 // No, the file already exists
1158 lun = mopi->GetLun();
1159 mopo->SetLun(lun);
1160 break;
1161 }
1162 } // inner loop
1163
1164 if (lun == -1.) {
1165 // Open new output file
1166 inp++;
1167 mopo->SetLun(loginp + inp);
1168 mopo->WriteOpenFlukaFile();
1169 }
1170 mopo->WriteFlukaInputCards();
1171 }
b8a8a88c 1172
1173// Add RANDOMIZ card
1174 fprintf(pFlukaVmcInp,"RANDOMIZ %10.1f%10.0f\n", 1., Float_t(gRandom->GetSeed()));
829fb838 1175// Add START and STOP card
f450e9d0 1176 fprintf(pFlukaVmcInp,"START %10.1f\n",fEventsPerRun);
1177 fprintf(pFlukaVmcInp,"STOP \n");
829fb838 1178
1179
1180// Close files
3b8c325d 1181 fclose(pFlukaVmcCoreInp);
1182 fclose(pFlukaVmcFlukaMat);
1183 fclose(pFlukaVmcInp);
fb2cbbec 1184
1185
1186//
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];
1191
1192 for (Int_t im = 0; im < nmaterial; im++)
1193 {
1194 TGeoMaterial* material = dynamic_cast<TGeoMaterial*> (matList->At(im));
1195 Int_t idmat = material->GetIndex();
1196 fMaterials[idmat] = im;
1197 }
829fb838 1198} // end of InitPhysics
1199
1200
1201//______________________________________________________________________________
07f5b33e 1202void TFluka::SetMaxStep(Double_t step)
829fb838 1203{
07f5b33e 1204// Set the maximum step size
1205 if (step > 1.e4) return;
1206
1207 Int_t mreg, latt;
1208 fGeom->GetCurrentRegion(mreg, latt);
9c0c08ce 1209 STEPSZ.stepmx[mreg - 1] = step;
829fb838 1210}
1211
2f09b80e 1212
1213Double_t TFluka::MaxStep() const
1214{
1215// Return the maximum for current medium
1216 Int_t mreg, latt;
1217 fGeom->GetCurrentRegion(mreg, latt);
1218 return (STEPSZ.stepmx[mreg - 1]);
1219}
1220
829fb838 1221//______________________________________________________________________________
1222void TFluka::SetMaxNStep(Int_t)
1223{
1224// SetMaxNStep is dummy procedure in TFluka !
1225 if (fVerbosityLevel >=3)
1226 cout << "SetMaxNStep is dummy procedure in TFluka !" << endl;
1227}
1228
1229//______________________________________________________________________________
1230void TFluka::SetUserDecay(Int_t)
1231{
1232// SetUserDecay is dummy procedure in TFluka !
1233 if (fVerbosityLevel >=3)
1234 cout << "SetUserDecay is dummy procedure in TFluka !" << endl;
1235}
1236
1237//
1238// dynamic properties
1239//
1240//______________________________________________________________________________
1241void TFluka::TrackPosition(TLorentzVector& position) const
1242{
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
a9ea1616 1249 FlukaCallerCode_t caller = GetCaller();
1250 if (caller == kENDRAW || caller == kUSDRAW ||
1251 caller == kBXExiting || caller == kBXEntering ||
1252 caller == kUSTCKV) {
829fb838 1253 position.SetX(GetXsco());
1254 position.SetY(GetYsco());
1255 position.SetZ(GetZsco());
1256 position.SetT(TRACKR.atrack);
1257 }
a9ea1616 1258 else if (caller == kMGDRAW) {
829fb838 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);
1263 }
a9ea1616 1264 else if (caller == kSODRAW) {
829fb838 1265 position.SetX(TRACKR.xtrack[TRACKR.ntrack]);
1266 position.SetY(TRACKR.ytrack[TRACKR.ntrack]);
1267 position.SetZ(TRACKR.ztrack[TRACKR.ntrack]);
1268 position.SetT(0);
a9ea1616 1269 } else if (caller == kMGResumedTrack) {
5d80a015 1270 position.SetX(TRACKR.spausr[0]);
1271 position.SetY(TRACKR.spausr[1]);
1272 position.SetZ(TRACKR.spausr[2]);
1273 position.SetT(TRACKR.spausr[3]);
829fb838 1274 }
1275 else
1276 Warning("TrackPosition","position not available");
1277}
1278
1279//______________________________________________________________________________
1280void TFluka::TrackPosition(Double_t& x, Double_t& y, Double_t& z) const
1281{
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
a9ea1616 1288 FlukaCallerCode_t caller = GetCaller();
1289 if (caller == kENDRAW || caller == kUSDRAW ||
1290 caller == kBXExiting || caller == kBXEntering ||
1291 caller == kUSTCKV) {
829fb838 1292 x = GetXsco();
1293 y = GetYsco();
1294 z = GetZsco();
1295 }
a9ea1616 1296 else if (caller == kMGDRAW || caller == kSODRAW) {
829fb838 1297 x = TRACKR.xtrack[TRACKR.ntrack];
1298 y = TRACKR.ytrack[TRACKR.ntrack];
1299 z = TRACKR.ztrack[TRACKR.ntrack];
1300 }
a9ea1616 1301 else if (caller == kMGResumedTrack) {
5d80a015 1302 x = TRACKR.spausr[0];
1303 y = TRACKR.spausr[1];
1304 z = TRACKR.spausr[2];
1305 }
829fb838 1306 else
1307 Warning("TrackPosition","position not available");
1308}
1309
1310//______________________________________________________________________________
1311void TFluka::TrackMomentum(TLorentzVector& momentum) const
1312{
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
a9ea1616 1321 FlukaCallerCode_t caller = GetCaller();
1322 FlukaProcessCode_t icode = GetIcode();
1323
1324 if (caller != kEEDRAW && caller != kMGResumedTrack &&
1325 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
829fb838 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);
1331 return;
1332 }
1333 else {
ece92b30 1334 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
829fb838 1335 momentum.SetPx(p*TRACKR.cxtrck);
1336 momentum.SetPy(p*TRACKR.cytrck);
1337 momentum.SetPz(p*TRACKR.cztrck);
1338 momentum.SetE(TRACKR.etrack);
1339 return;
1340 }
a9ea1616 1341 } else if (caller == kMGResumedTrack) {
5d80a015 1342 momentum.SetPx(TRACKR.spausr[4]);
1343 momentum.SetPy(TRACKR.spausr[5]);
1344 momentum.SetPz(TRACKR.spausr[6]);
1345 momentum.SetE (TRACKR.spausr[7]);
1346 return;
a9ea1616 1347 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1348 momentum.SetPx(0.);
1349 momentum.SetPy(0.);
1350 momentum.SetPz(0.);
1351 momentum.SetE(TrackMass());
829fb838 1352 }
1353 else
1354 Warning("TrackMomentum","momentum not available");
1355}
1356
1357//______________________________________________________________________________
1358void TFluka::TrackMomentum(Double_t& px, Double_t& py, Double_t& pz, Double_t& e) const
1359{
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
a9ea1616 1368 FlukaCallerCode_t caller = GetCaller();
1369 FlukaProcessCode_t icode = GetIcode();
1370 if (caller != kEEDRAW && caller != kMGResumedTrack &&
1371 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
829fb838 1372 if (TRACKR.ptrack >= 0) {
1373 px = TRACKR.ptrack*TRACKR.cxtrck;
1374 py = TRACKR.ptrack*TRACKR.cytrck;
1375 pz = TRACKR.ptrack*TRACKR.cztrck;
a9ea1616 1376 e = TRACKR.etrack;
829fb838 1377 return;
1378 }
1379 else {
ece92b30 1380 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
829fb838 1381 px = p*TRACKR.cxtrck;
1382 py = p*TRACKR.cytrck;
1383 pz = p*TRACKR.cztrck;
a9ea1616 1384 e = TRACKR.etrack;
829fb838 1385 return;
1386 }
a9ea1616 1387 } else if (caller == kMGResumedTrack) {
5d80a015 1388 px = TRACKR.spausr[4];
1389 py = TRACKR.spausr[5];
1390 pz = TRACKR.spausr[6];
1391 e = TRACKR.spausr[7];
0773d0ac 1392 return;
a9ea1616 1393 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1394 px = 0.;
1395 py = 0.;
1396 pz = 0.;
1397 e = TrackMass();
829fb838 1398 }
1399 else
1400 Warning("TrackMomentum","momentum not available");
1401}
1402
1403//______________________________________________________________________________
1404Double_t TFluka::TrackStep() const
1405{
1406// Return the length in centimeters of the current step
1407// TRACKR.ctrack = total curved path
a9ea1616 1408 FlukaCallerCode_t caller = GetCaller();
1409 if (caller == kBXEntering || caller == kBXExiting ||
1410 caller == kENDRAW || caller == kUSDRAW ||
1411 caller == kUSTCKV || caller == kMGResumedTrack)
829fb838 1412 return 0.0;
a9ea1616 1413 else if (caller == kMGDRAW)
829fb838 1414 return TRACKR.ctrack;
669cede4 1415 else {
1416 Warning("TrackStep", "track step not available");
1417 return 0.0;
1418 }
829fb838 1419}
1420
1421//______________________________________________________________________________
1422Double_t TFluka::TrackLength() const
1423{
1424// TRACKR.cmtrck = cumulative curved path since particle birth
a9ea1616 1425 FlukaCallerCode_t caller = GetCaller();
1426 if (caller == kBXEntering || caller == kBXExiting ||
1427 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1428 caller == kUSTCKV)
829fb838 1429 return TRACKR.cmtrck;
a9ea1616 1430 else if (caller == kMGResumedTrack)
5d80a015 1431 return TRACKR.spausr[8];
669cede4 1432 else {
1433 Warning("TrackLength", "track length not available");
1434 return 0.0;
1435 }
829fb838 1436}
1437
1438//______________________________________________________________________________
1439Double_t TFluka::TrackTime() const
1440{
1441// Return the current time of flight of the track being transported
1442// TRACKR.atrack = age of the particle
a9ea1616 1443 FlukaCallerCode_t caller = GetCaller();
1444 if (caller == kBXEntering || caller == kBXExiting ||
1445 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1446 caller == kUSTCKV)
829fb838 1447 return TRACKR.atrack;
a9ea1616 1448 else if (caller == kMGResumedTrack)
5d80a015 1449 return TRACKR.spausr[3];
669cede4 1450 else {
1451 Warning("TrackTime", "track time not available");
1452 return 0.0;
1453 }
829fb838 1454}
1455
1456//______________________________________________________________________________
1457Double_t TFluka::Edep() const
1458{
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
07f5b33e 1467// TRACKR.dtrack = energy deposition of the jth deposition event
829fb838 1468
1469 // If coming from bxdraw we have 2 steps of 0 length and 0 edep
669cede4 1470 // If coming from usdraw we just signal particle production - no edep
1471 // If just first time after resuming, no edep for the primary
a9ea1616 1472 FlukaCallerCode_t caller = GetCaller();
1473 if (caller == kBXExiting || caller == kBXEntering ||
1474 caller == kUSDRAW || caller == kMGResumedTrack) return 0.0;
829fb838 1475 Double_t sum = 0;
1476 for ( Int_t j=0;j<TRACKR.mtrack;j++) {
b2be0e73 1477 sum +=TRACKR.dtrack[j];
829fb838 1478 }
1479 if (TRACKR.ntrack == 0 && TRACKR.mtrack == 0)
b2be0e73 1480 return fRull + sum;
829fb838 1481 else {
b2be0e73 1482 return sum;
829fb838 1483 }
1484}
1485
1486//______________________________________________________________________________
18e0cabb 1487Int_t TFluka::CorrectFlukaId() const
1488{
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
1502 }
1503 return TRACKR.jtrack;
1504}
1505
1506
1507//______________________________________________________________________________
829fb838 1508Int_t TFluka::TrackPid() const
1509{
1510// Return the id of the particle transported
1511// TRACKR.jtrack = identity number of the particle
a9ea1616 1512 FlukaCallerCode_t caller = GetCaller();
1513 if (caller != kEEDRAW) {
18e0cabb 1514 return PDGFromId( CorrectFlukaId() );
f926898e 1515 }
829fb838 1516 else
1517 return -1000;
1518}
1519
1520//______________________________________________________________________________
1521Double_t TFluka::TrackCharge() const
1522{
1523// Return charge of the track currently transported
1524// PAPROP.ichrge = electric charge of the particle
1525// TRACKR.jtrack = identity number of the particle
a9ea1616 1526 FlukaCallerCode_t caller = GetCaller();
1527 if (caller != kEEDRAW)
18e0cabb 1528 return PAPROP.ichrge[CorrectFlukaId()+6];
829fb838 1529 else
1530 return -1000.0;
1531}
1532
1533//______________________________________________________________________________
1534Double_t TFluka::TrackMass() const
1535{
1536// PAPROP.am = particle mass in GeV
1537// TRACKR.jtrack = identity number of the particle
a9ea1616 1538 FlukaCallerCode_t caller = GetCaller();
1539 if (caller != kEEDRAW)
18e0cabb 1540 return PAPROP.am[CorrectFlukaId()+6];
829fb838 1541 else
1542 return -1000.0;
1543}
1544
1545//______________________________________________________________________________
1546Double_t TFluka::Etot() const
1547{
1548// TRACKR.etrack = total energy of the particle
a9ea1616 1549 FlukaCallerCode_t caller = GetCaller();
1550 if (caller != kEEDRAW)
829fb838 1551 return TRACKR.etrack;
1552 else
1553 return -1000.0;
1554}
1555
1556//
1557// track status
1558//
1559//______________________________________________________________________________
1560Bool_t TFluka::IsNewTrack() const
1561{
1562// Return true for the first call of Stepping()
1563 return fTrackIsNew;
1564}
1565
0dabe425 1566void TFluka::SetTrackIsNew(Bool_t flag)
1567{
1568// Return true for the first call of Stepping()
1569 fTrackIsNew = flag;
1570
1571}
1572
1573
829fb838 1574//______________________________________________________________________________
1575Bool_t TFluka::IsTrackInside() const
1576{
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.
a9ea1616 1582 FlukaCallerCode_t caller = GetCaller();
1583 if (caller == kBXEntering || caller == kBXExiting)
829fb838 1584 return 0;
1585 else
1586 return 1;
1587}
1588
1589//______________________________________________________________________________
1590Bool_t TFluka::IsTrackEntering() const
1591{
1592// True if this is the first step of the track in the current volume
1593
a9ea1616 1594 FlukaCallerCode_t caller = GetCaller();
1595 if (caller == kBXEntering)
829fb838 1596 return 1;
1597 else return 0;
1598}
1599
1600//______________________________________________________________________________
1601Bool_t TFluka::IsTrackExiting() const
1602{
1603// True if track is exiting volume
1604//
a9ea1616 1605 FlukaCallerCode_t caller = GetCaller();
1606 if (caller == kBXExiting)
829fb838 1607 return 1;
1608 else return 0;
1609}
1610
1611//______________________________________________________________________________
1612Bool_t TFluka::IsTrackOut() const
1613{
1614// True if the track is out of the setup
1615// means escape
a9ea1616 1616 FlukaProcessCode_t icode = GetIcode();
1617
1618 if (icode == kKASKADescape ||
1619 icode == kEMFSCOescape ||
1620 icode == kKASNEUescape ||
1621 icode == kKASHEAescape ||
1622 icode == kKASOPHescape)
1623 return 1;
829fb838 1624 else return 0;
1625}
1626
1627//______________________________________________________________________________
1628Bool_t TFluka::IsTrackDisappeared() const
1629{
a9ea1616 1630// All inelastic interactions and decays
829fb838 1631// fIcode from usdraw
a9ea1616 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
2047b055 1647 icode == kKASHEAdray // delta-ray
0dabe425 1648 ) return 1;
829fb838 1649 else return 0;
1650}
1651
1652//______________________________________________________________________________
1653Bool_t TFluka::IsTrackStop() const
1654{
1655// True if the track energy has fallen below the threshold
1656// means stopped by signal or below energy threshold
a9ea1616 1657 FlukaProcessCode_t icode = GetIcode();
18e0cabb 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
829fb838 1667 else return 0;
1668}
1669
1670//______________________________________________________________________________
1671Bool_t TFluka::IsTrackAlive() const
1672{
1673// means not disappeared or not out
1674 if (IsTrackDisappeared() || IsTrackOut() ) return 0;
1675 else return 1;
1676}
1677
1678//
1679// secondaries
1680//
1681
1682//______________________________________________________________________________
1683Int_t TFluka::NSecondaries() const
1684
1685{
1686// Number of secondary particles generated in the current step
81f1d030 1687// GENSTK.np = number of secondaries except light and heavy ions
829fb838 1688// FHEAVY.npheav = number of secondaries for light and heavy secondary ions
a9ea1616 1689 FlukaCallerCode_t caller = GetCaller();
1690 if (caller == kUSDRAW) // valid only after usdraw
81f1d030 1691 return GENSTK.np + FHEAVY.npheav;
a9ea1616 1692 else if (caller == kUSTCKV) {
7b203b6e 1693 // Cerenkov Photon production
1694 return fNCerenkov;
1695 }
829fb838 1696 return 0;
1697} // end of NSecondaries
1698
1699//______________________________________________________________________________
1700void TFluka::GetSecondary(Int_t isec, Int_t& particleId,
1701 TLorentzVector& position, TLorentzVector& momentum)
1702{
1703// Copy particles from secondary stack to vmc stack
1704//
1705
a9ea1616 1706 FlukaCallerCode_t caller = GetCaller();
1707 if (caller == kUSDRAW) { // valid only after usdraw
81f1d030 1708 if (GENSTK.np > 0) {
7b203b6e 1709 // Hadronic interaction
81f1d030 1710 if (isec >= 0 && isec < GENSTK.np) {
1711 particleId = PDGFromId(GENSTK.kpart[isec]);
7b203b6e 1712 position.SetX(fXsco);
1713 position.SetY(fYsco);
1714 position.SetZ(fZsco);
1715 position.SetT(TRACKR.atrack);
81f1d030 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]);
7b203b6e 1720 }
81f1d030 1721 else if (isec >= GENSTK.np && isec < GENSTK.np + FHEAVY.npheav) {
1722 Int_t jsec = isec - GENSTK.np;
7b203b6e 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 !!!
1735 }
1736 else
1737 Warning("GetSecondary","isec out of range");
1738 }
a9ea1616 1739 } else if (caller == kUSTCKV) {
7b203b6e 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];
1746
1747 momentum.SetPx(p * OPPHST.txopph[index]);
1748 momentum.SetPy(p * OPPHST.tyopph[index]);
1749 momentum.SetPz(p * OPPHST.tzopph[index]);
1750 momentum.SetE(p);
829fb838 1751 }
1752 else
7b203b6e 1753 Warning("GetSecondary","no secondaries available");
1754
829fb838 1755} // end of GetSecondary
1756
7b203b6e 1757
829fb838 1758//______________________________________________________________________________
1759TMCProcess TFluka::ProdProcess(Int_t) const
1760
1761{
1762// Name of the process that has produced the secondary particles
1763// in the current step
0dabe425 1764
a9ea1616 1765 Int_t mugamma = (TRACKR.jtrack == kFLUKAphoton ||
1766 TRACKR.jtrack == kFLUKAmuplus ||
1767 TRACKR.jtrack == kFLUKAmuminus);
1768 FlukaProcessCode_t icode = GetIcode();
1769
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;
829fb838 1782 }
a9ea1616 1783 else if (icode == kEMFSCOrayleigh) return kPRayleigh;
829fb838 1784// Fluka codes 100, 300 and 400 still to be investigasted
a9ea1616 1785 else return kPNoProcess;
829fb838 1786}
1787
829fb838 1788
b496f27c 1789Int_t TFluka::StepProcesses(TArrayI &proc) const
1790{
1791 //
1792 // Return processes active in the current step
1793 //
a9ea1616 1794 FlukaProcessCode_t icode = GetIcode();
b496f27c 1795 proc.Set(1);
1796 TMCProcess iproc;
a9ea1616 1797 switch (icode) {
1798 case kKASKADtimekill:
1799 case kEMFSCOtimekill:
1800 case kKASNEUtimekill:
1801 case kKASHEAtimekill:
1802 case kKASOPHtimekill:
b496f27c 1803 iproc = kPTOFlimit;
1804 break;
a9ea1616 1805 case kKASKADstopping:
1806 case kKASKADescape:
1807 case kEMFSCOstopping1:
1808 case kEMFSCOstopping2:
1809 case kEMFSCOescape:
1810 case kKASNEUstopping:
1811 case kKASNEUescape:
1812 case kKASHEAescape:
1813 case kKASOPHescape:
6fd5baa4 1814 iproc = kPStop;
b496f27c 1815 break;
a9ea1616 1816 case kKASOPHabsorption:
b496f27c 1817 iproc = kPLightAbsorption;
1818 break;
a9ea1616 1819 case kKASOPHrefraction:
6fd5baa4 1820 iproc = kPLightRefraction;
a9ea1616 1821 case kEMSCOlocaledep :
b496f27c 1822 iproc = kPPhotoelectric;
1823 break;
1824 default:
1825 iproc = ProdProcess(0);
1826 }
07f5b33e 1827 proc[0] = iproc;
b496f27c 1828 return 1;
1829}
829fb838 1830//______________________________________________________________________________
1831Int_t TFluka::VolId2Mate(Int_t id) const
1832{
1833//
1834// Returns the material number for a given volume ID
1835//
1836 return fMCGeo->VolId2Mate(id);
1837}
1838
1839//______________________________________________________________________________
1840const char* TFluka::VolName(Int_t id) const
1841{
1842//
1843// Returns the volume name for a given volume ID
1844//
1845 return fMCGeo->VolName(id);
1846}
1847
1848//______________________________________________________________________________
1849Int_t TFluka::VolId(const Text_t* volName) const
1850{
1851//
1852// Converts from volume name to volume ID.
1853// Time consuming. (Only used during set-up)
1854// Could be replaced by hash-table
1855//
09cd6497 1856 char sname[20];
1857 Int_t len;
1858 strncpy(sname, volName, len = strlen(volName));
1859 sname[len] = 0;
1860 while (sname[len - 1] == ' ') sname[--len] = 0;
1861 return fMCGeo->VolId(sname);
829fb838 1862}
1863
1864//______________________________________________________________________________
1865Int_t TFluka::CurrentVolID(Int_t& copyNo) const
1866{
1867//
1868// Return the logical id and copy number corresponding to the current fluka region
1869//
1870 if (gGeoManager->IsOutside()) return 0;
1871 TGeoNode *node = gGeoManager->GetCurrentNode();
1872 copyNo = node->GetNumber();
1873 Int_t id = node->GetVolume()->GetNumber();
1874 return id;
1875}
1876
1877//______________________________________________________________________________
1878Int_t TFluka::CurrentVolOffID(Int_t off, Int_t& copyNo) const
1879{
1880//
1881// Return the logical id and copy number of off'th mother
1882// corresponding to the current fluka region
1883//
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();
1890}
1891
1892//______________________________________________________________________________
1893const char* TFluka::CurrentVolName() const
1894{
1895//
1896// Return the current volume name
1897//
1898 if (gGeoManager->IsOutside()) return 0;
1899 return gGeoManager->GetCurrentVolume()->GetName();
1900}
1901
1902//______________________________________________________________________________
1903const char* TFluka::CurrentVolOffName(Int_t off) const
1904{
1905//
1906// Return the volume name of the off'th mother of the current volume
1907//
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();
1913}
1914
d59acfe7 1915const char* TFluka::CurrentVolPath() {
1916 // Return the current volume path
1917 return gGeoManager->GetPath();
1918}
829fb838 1919//______________________________________________________________________________
a60813de 1920Int_t TFluka::CurrentMaterial(Float_t & a, Float_t & z,
1921 Float_t & dens, Float_t & radl, Float_t & absl) const
829fb838 1922{
1923//
a60813de 1924// Return the current medium number and material properties
829fb838 1925//
1926 Int_t copy;
1927 Int_t id = TFluka::CurrentVolID(copy);
1928 Int_t med = TFluka::VolId2Mate(id);
a60813de 1929 TGeoVolume* vol = gGeoManager->GetCurrentVolume();
1930 TGeoMaterial* mat = vol->GetMaterial();
1931 a = mat->GetA();
1932 z = mat->GetZ();
1933 dens = mat->GetDensity();
1934 radl = mat->GetRadLen();
1935 absl = mat->GetIntLen();
1936
829fb838 1937 return med;
1938}
1939
1940//______________________________________________________________________________
1941void TFluka::Gmtod(Float_t* xm, Float_t* xd, Int_t iflag)
1942{
1943// Transforms a position from the world reference frame
1944// to the current volume reference frame.
1945//
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)
1955//
1956// If IFLAG=1 convert coordinates
1957// IFLAG=2 convert direction cosinus
1958//
1959// ---
1960 Double_t xmL[3], xdL[3];
1961 Int_t i;
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];
1966}
1967
1968//______________________________________________________________________________
1969void TFluka::Gmtod(Double_t* xm, Double_t* xd, Int_t iflag)
1970{
2047b055 1971//
1972// See Gmtod(Float_t*, Float_t*, Int_t)
1973//
829fb838 1974 if (iflag == 1) gGeoManager->MasterToLocal(xm,xd);
1975 else gGeoManager->MasterToLocalVect(xm,xd);
1976}
1977
1978//______________________________________________________________________________
1979void TFluka::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag)
1980{
1981// Transforms a position from the current volume reference frame
1982// to the world reference frame.
1983//
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)
1992//
1993// If IFLAG=1 convert coordinates
1994// IFLAG=2 convert direction cosinus
1995//
1996// ---
1997 Double_t xmL[3], xdL[3];
1998 Int_t i;
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];
2003}
2004
2005//______________________________________________________________________________
2006void TFluka::Gdtom(Double_t* xd, Double_t* xm, Int_t iflag)
2007{
2047b055 2008//
2009// See Gdtom(Float_t*, Float_t*, Int_t)
2010//
829fb838 2011 if (iflag == 1) gGeoManager->LocalToMaster(xd,xm);
2012 else gGeoManager->LocalToMasterVect(xd,xm);
2013}
2014
2015//______________________________________________________________________________
2016TObjArray *TFluka::GetFlukaMaterials()
2017{
2047b055 2018//
2019// Get array of Fluka materials
829fb838 2020 return fGeom->GetMatList();
2021}
2022
2023//______________________________________________________________________________
a9ea1616 2024void TFluka::SetMreg(Int_t l, Int_t lttc)
829fb838 2025{
2026// Set current fluka region
2027 fCurrentFlukaRegion = l;
a9ea1616 2028 fGeom->SetMreg(l,lttc);
829fb838 2029}
2030
2031
b496f27c 2032
2033
2034TString TFluka::ParticleName(Int_t pdg) const
2035{
2036 // Return particle name for particle with pdg code pdg.
2037 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2038 return TString((CHPPRP.btype[ifluka - kFLUKAcodemin]), 8);
b496f27c 2039}
2040
2041
2042Double_t TFluka::ParticleMass(Int_t pdg) const
2043{
2044 // Return particle mass for particle with pdg code pdg.
2045 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2046 return (PAPROP.am[ifluka - kFLUKAcodemin]);
2047}
2048
2049Double_t TFluka::ParticleMassFPC(Int_t fpc) const
2050{
2051 // Return particle mass for particle with Fluka particle code fpc
2052 return (PAPROP.am[fpc - kFLUKAcodemin]);
b496f27c 2053}
2054
2055Double_t TFluka::ParticleCharge(Int_t pdg) const
2056{
2057 // Return particle charge for particle with pdg code pdg.
2058 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2059 return Double_t(PAPROP.ichrge[ifluka - kFLUKAcodemin]);
b496f27c 2060}
2061
2062Double_t TFluka::ParticleLifeTime(Int_t pdg) const
2063{
2064 // Return particle lifetime for particle with pdg code pdg.
2065 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2066 return (PAPROP.tmnlf[ifluka - kFLUKAcodemin]);
b496f27c 2067}
2068
2069void TFluka::Gfpart(Int_t pdg, char* name, Int_t& type, Float_t& mass, Float_t& charge, Float_t& tlife)
2070{
2071 // Retrieve particle properties for particle with pdg code pdg.
2072
2073 strcpy(name, ParticleName(pdg).Data());
2074 type = ParticleMCType(pdg);
2075 mass = ParticleMass(pdg);
2076 charge = ParticleCharge(pdg);
2077 tlife = ParticleLifeTime(pdg);
2078}
2079
8e5bf079 2080void TFluka::PrintHeader()
2081{
2082 //
2083 // Print a header
2084 printf("\n");
2085 printf("\n");
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");
2090 printf("\n");
2091 printf("\n");
2092}
2093
b496f27c 2094
81f1d030 2095#define pshckp pshckp_
2096#define ustckv ustckv_
3a625972 2097
2098
2099extern "C" {
81f1d030 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)
2103 {
2104 //
2105 // Pushes one cerenkov photon to the stack
2106 //
2107
2108 TFluka* fluka = (TFluka*) gMC;
2109 TVirtualMCStack* cppstack = fluka->GetStack();
2110 Int_t parent = TRACKR.ispusr[mkbmx2-1];
2111 cppstack->PushTrack(0, parent, 50000050,
2112 px, py, pz, e,
2113 vx, vy, vz, tof,
2114 polx, poly, polz,
2115 kPCerenkov, ntr, wgt, 0);
2116 }
2117
2118 void ustckv(Int_t & nphot, Int_t & mreg, Double_t & x, Double_t & y, Double_t & z)
7b203b6e 2119 {
2120 //
2121 // Calls stepping in order to signal cerenkov production
2122 //
2123 TFluka *fluka = (TFluka*)gMC;
a9ea1616 2124 fluka->SetMreg(mreg,LTCLCM.mlatm1);
7b203b6e 2125 fluka->SetXsco(x);
2126 fluka->SetYsco(y);
2127 fluka->SetZsco(z);
2128 fluka->SetNCerenkov(nphot);
a9ea1616 2129 fluka->SetCaller(kUSTCKV);
d59acfe7 2130 if (fluka->GetVerbosityLevel() >= 3)
7b203b6e 2131 (TVirtualMCApplication::Instance())->Stepping();
81f1d030 2132
7b203b6e 2133 }
3a625972 2134}
a9ea1616 2135
78df7be0 2136void TFluka::AddParticlesToPdgDataBase() const
2137{
2138
2139//
2140// Add particles to the PDG data base
2141
2142 TDatabasePDG *pdgDB = TDatabasePDG::Instance();
2143
2144 const Int_t kion=10000000;
2145
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;
2151//
2152// Ions
2153//
2154
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);
2163}
2164