Fixing a little bug
[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
f2a98602 51#include "Falldlt.h" //(ALLDLT) fluka common
829fb838 52
53#include "TVirtualMC.h"
3a625972 54#include "TMCProcess.h"
829fb838 55#include "TGeoManager.h"
56#include "TGeoMaterial.h"
57#include "TGeoMedium.h"
58#include "TFlukaMCGeometry.h"
6f5667d1 59#include "TGeoMCGeometry.h"
829fb838 60#include "TFlukaCerenkov.h"
1df5fa54 61#include "TFlukaConfigOption.h"
b496f27c 62#include "TFlukaScoringOption.h"
829fb838 63#include "TLorentzVector.h"
b496f27c 64#include "TArrayI.h"
a9ea1616 65#include "TArrayD.h"
78df7be0 66#include "TDatabasePDG.h"
829fb838 67
68// Fluka methods that may be needed.
69#ifndef WIN32
70# define flukam flukam_
71# define fluka_openinp fluka_openinp_
8e5bf079 72# define fluka_openout fluka_openout_
829fb838 73# define fluka_closeinp fluka_closeinp_
74# define mcihad mcihad_
75# define mpdgha mpdgha_
2047b055 76# define newplo newplo_
829fb838 77#else
78# define flukam FLUKAM
79# define fluka_openinp FLUKA_OPENINP
8e5bf079 80# define fluka_openout FLUKA_OPENOUT
829fb838 81# define fluka_closeinp FLUKA_CLOSEINP
82# define mcihad MCIHAD
83# define mpdgha MPDGHA
eea53470 84# define newplo NEWPLO
829fb838 85#endif
86
87extern "C"
88{
89 //
90 // Prototypes for FLUKA functions
91 //
92 void type_of_call flukam(const int&);
eea53470 93 void type_of_call newplo();
829fb838 94 void type_of_call fluka_openinp(const int&, DEFCHARA);
8e5bf079 95 void type_of_call fluka_openout(const int&, DEFCHARA);
829fb838 96 void type_of_call fluka_closeinp(const int&);
97 int type_of_call mcihad(const int&);
98 int type_of_call mpdgha(const int&);
99}
100
101//
102// Class implementation for ROOT
103//
104ClassImp(TFluka)
105
106//
107//----------------------------------------------------------------------------
108// TFluka constructors and destructors.
109//______________________________________________________________________________
110TFluka::TFluka()
111 :TVirtualMC(),
112 fVerbosityLevel(0),
1df5fa54 113 fInputFileName(""),
fb2cbbec 114 fUserConfig(0),
1df5fa54 115 fUserScore(0)
829fb838 116{
117 //
118 // Default constructor
119 //
120 fGeneratePemf = kFALSE;
121 fNVolumes = 0;
122 fCurrentFlukaRegion = -1;
a9ea1616 123 fNewReg = -1;
829fb838 124 fGeom = 0;
125 fMCGeo = 0;
126 fMaterials = 0;
127 fDummyBoundary = 0;
128 fFieldFlag = 1;
bd3d5c8a 129 fStopped = 0;
b496f27c 130 fStopEvent = 0;
131 fStopRun = 0;
132 fNEvent = 0;
829fb838 133}
134
135//______________________________________________________________________________
136TFluka::TFluka(const char *title, Int_t verbosity, Bool_t isRootGeometrySupported)
137 :TVirtualMC("TFluka",title, isRootGeometrySupported),
138 fVerbosityLevel(verbosity),
139 fInputFileName(""),
140 fTrackIsEntering(0),
141 fTrackIsExiting(0),
1df5fa54 142 fTrackIsNew(0),
fb2cbbec 143 fUserConfig(new TObjArray(100)),
1df5fa54 144 fUserScore(new TObjArray(100))
829fb838 145{
146 // create geometry interface
7f13be31 147 if (fVerbosityLevel >=3)
148 cout << "<== TFluka::TFluka(" << title << ") constructor called." << endl;
149 SetCoreInputFileName();
150 SetInputFileName();
151 SetGeneratePemf(kFALSE);
829fb838 152 fNVolumes = 0;
153 fCurrentFlukaRegion = -1;
a9ea1616 154 fNewReg = -1;
829fb838 155 fDummyBoundary = 0;
156 fFieldFlag = 1;
157 fGeneratePemf = kFALSE;
11e4ab84 158 fMCGeo = new TGeoMCGeometry("MCGeo", "TGeo Implementation of VirtualMCGeometry", kFALSE);
fb2cbbec 159 fGeom = new TFlukaMCGeometry("geom", "FLUKA VMC Geometry");
829fb838 160 if (verbosity > 2) fGeom->SetDebugMode(kTRUE);
161 fMaterials = 0;
bd3d5c8a 162 fStopped = 0;
b496f27c 163 fStopEvent = 0;
164 fStopRun = 0;
165 fNEvent = 0;
8e5bf079 166 PrintHeader();
829fb838 167}
168
169//______________________________________________________________________________
170TFluka::~TFluka() {
171// Destructor
1df5fa54 172 if (fVerbosityLevel >=3)
173 cout << "<== TFluka::~TFluka() destructor called." << endl;
174
175 delete fGeom;
176 delete fMCGeo;
177
fb2cbbec 178 if (fUserConfig) {
179 fUserConfig->Delete();
180 delete fUserConfig;
1df5fa54 181 }
6d184c54 182
183 if (fUserScore) {
184 fUserScore->Delete();
185 delete fUserScore;
186 }
829fb838 187}
188
189//
190//______________________________________________________________________________
191// TFluka control methods
192//______________________________________________________________________________
193void TFluka::Init() {
194//
195// Geometry initialisation
196//
197 if (fVerbosityLevel >=3) cout << "==> TFluka::Init() called." << endl;
198
199 if (!gGeoManager) new TGeoManager("geom", "FLUKA geometry");
200 fApplication->ConstructGeometry();
d59acfe7 201 if (!gGeoManager->IsClosed()) {
202 TGeoVolume *top = (TGeoVolume*)gGeoManager->GetListOfVolumes()->First();
203 gGeoManager->SetTopVolume(top);
204 gGeoManager->CloseGeometry("di");
205 } else {
206 TGeoNodeCache *cache = gGeoManager->GetCache();
207 if (!cache->HasIdArray()) {
a9ea1616 208 Warning("Init", "Node ID tracking must be enabled with TFluka: enabling...\n");
d59acfe7 209 cache->BuildIdArray();
210 }
211 }
829fb838 212 fNVolumes = fGeom->NofVolumes();
213 fGeom->CreateFlukaMatFile("flukaMat.inp");
214 if (fVerbosityLevel >=3) {
215 printf("== Number of volumes: %i\n ==", fNVolumes);
216 cout << "\t* InitPhysics() - Prepare input file to be called" << endl;
6d184c54 217 }
881cb248 218
219 fApplication->InitGeometry();
78df7be0 220
221 //
222 // Add ions to PDG Data base
223 //
224 AddParticlesToPdgDataBase();
829fb838 225}
226
227
228//______________________________________________________________________________
229void TFluka::FinishGeometry() {
230//
231// Build-up table with region to medium correspondance
232//
233 if (fVerbosityLevel >=3) {
234 cout << "==> TFluka::FinishGeometry() called." << endl;
235 printf("----FinishGeometry - nothing to do with TGeo\n");
236 cout << "<== TFluka::FinishGeometry() called." << endl;
237 }
238}
239
240//______________________________________________________________________________
241void TFluka::BuildPhysics() {
242//
243// Prepare FLUKA input files and call FLUKA physics initialisation
244//
245
246 if (fVerbosityLevel >=3)
247 cout << "==> TFluka::BuildPhysics() called." << endl;
6d184c54 248
249
250 if (fVerbosityLevel >=3) {
251 TList *medlist = gGeoManager->GetListOfMedia();
252 TIter next(medlist);
253 TGeoMedium* med = 0x0;
254 TGeoMaterial* mat = 0x0;
255 Int_t ic = 0;
256
257 while((med = (TGeoMedium*)next()))
258 {
259 mat = med->GetMaterial();
260 printf("Medium %5d %12s %5d %5d\n", ic, (med->GetName()), med->GetId(), mat->GetIndex());
261 ic++;
262 }
263 }
264
265 //
266 // At this stage we have the information on materials and cuts available.
267 // Now create the pemf file
268
269 if (fGeneratePemf) fGeom->CreatePemfFile();
270
271 //
272 // Prepare input file with the current physics settings
273
829fb838 274 InitPhysics();
b8a8a88c 275// Open fortran files
829fb838 276 const char* fname = fInputFileName;
277 fluka_openinp(lunin, PASSCHARA(fname));
8e5bf079 278 fluka_openout(11, PASSCHARA("fluka.out"));
b8a8a88c 279// Read input cards
280 GLOBAL.lfdrtr = true;
829fb838 281 flukam(1);
b8a8a88c 282// Close input file
829fb838 283 fluka_closeinp(lunin);
b8a8a88c 284// Finish geometry
829fb838 285 FinishGeometry();
829fb838 286}
287
288//______________________________________________________________________________
289void TFluka::ProcessEvent() {
290//
291// Process one event
292//
b496f27c 293 if (fStopRun) {
a9ea1616 294 Warning("ProcessEvent", "User Run Abortion: No more events handled !\n");
b496f27c 295 fNEvent += 1;
296 return;
297 }
298
299 if (fVerbosityLevel >=3)
300 cout << "==> TFluka::ProcessEvent() called." << endl;
301 fApplication->GeneratePrimaries();
81f1d030 302 SOURCM.lsouit = true;
b496f27c 303 flukam(1);
304 if (fVerbosityLevel >=3)
305 cout << "<== TFluka::ProcessEvent() called." << endl;
306 //
307 // Increase event number
308 //
309 fNEvent += 1;
829fb838 310}
311
312//______________________________________________________________________________
313Bool_t TFluka::ProcessRun(Int_t nevent) {
314//
315// Run steering
316//
317
318 if (fVerbosityLevel >=3)
319 cout << "==> TFluka::ProcessRun(" << nevent << ") called."
320 << endl;
321
322 if (fVerbosityLevel >=2) {
323 cout << "\t* GLOBAL.fdrtr = " << (GLOBAL.lfdrtr?'T':'F') << endl;
324 cout << "\t* Calling flukam again..." << endl;
325 }
326
829fb838 327 Int_t todo = TMath::Abs(nevent);
328 for (Int_t ev = 0; ev < todo; ev++) {
329 fApplication->BeginEvent();
330 ProcessEvent();
331 fApplication->FinishEvent();
332 }
333
334 if (fVerbosityLevel >=3)
335 cout << "<== TFluka::ProcessRun(" << nevent << ") called."
336 << endl;
eea53470 337 // Write fluka specific scoring output
338 newplo();
339
829fb838 340 return kTRUE;
341}
342
343//_____________________________________________________________________________
344// methods for building/management of geometry
345
346// functions from GCONS
347//____________________________________________________________________________
348void TFluka::Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z,
349 Float_t &dens, Float_t &radl, Float_t &absl,
350 Float_t* /*ubuf*/, Int_t& /*nbuf*/) {
351//
352 TGeoMaterial *mat;
353 TIter next (gGeoManager->GetListOfMaterials());
354 while ((mat = (TGeoMaterial*)next())) {
355 if (mat->GetUniqueID() == (UInt_t)imat) break;
356 }
357 if (!mat) {
358 Error("Gfmate", "no material with index %i found", imat);
359 return;
360 }
361 sprintf(name, "%s", mat->GetName());
362 a = mat->GetA();
363 z = mat->GetZ();
364 dens = mat->GetDensity();
365 radl = mat->GetRadLen();
366 absl = mat->GetIntLen();
367}
368
369//______________________________________________________________________________
370void TFluka::Gfmate(Int_t imat, char *name, Double_t &a, Double_t &z,
371 Double_t &dens, Double_t &radl, Double_t &absl,
372 Double_t* /*ubuf*/, Int_t& /*nbuf*/) {
373//
374 TGeoMaterial *mat;
375 TIter next (gGeoManager->GetListOfMaterials());
376 while ((mat = (TGeoMaterial*)next())) {
377 if (mat->GetUniqueID() == (UInt_t)imat) break;
378 }
379 if (!mat) {
380 Error("Gfmate", "no material with index %i found", imat);
381 return;
382 }
383 sprintf(name, "%s", mat->GetName());
384 a = mat->GetA();
385 z = mat->GetZ();
386 dens = mat->GetDensity();
387 radl = mat->GetRadLen();
388 absl = mat->GetIntLen();
389}
390
391// detector composition
392//______________________________________________________________________________
393void TFluka::Material(Int_t& kmat, const char* name, Double_t a,
394 Double_t z, Double_t dens, Double_t radl, Double_t absl,
395 Float_t* buf, Int_t nwbuf) {
396//
397 Double_t* dbuf = fGeom->CreateDoubleArray(buf, nwbuf);
398 Material(kmat, name, a, z, dens, radl, absl, dbuf, nwbuf);
399 delete [] dbuf;
400}
401
402//______________________________________________________________________________
403void TFluka::Material(Int_t& kmat, const char* name, Double_t a,
404 Double_t z, Double_t dens, Double_t radl, Double_t absl,
405 Double_t* /*buf*/, Int_t /*nwbuf*/) {
406//
fb2cbbec 407// Define a material
829fb838 408 TGeoMaterial *mat;
409 kmat = gGeoManager->GetListOfMaterials()->GetSize();
410 if ((z-Int_t(z)) > 1E-3) {
411 mat = fGeom->GetMakeWrongMaterial(z);
412 if (mat) {
413 mat->SetRadLen(radl,absl);
414 mat->SetUniqueID(kmat);
415 return;
416 }
417 }
418 gGeoManager->Material(name, a, z, dens, kmat, radl, absl);
419}
420
421//______________________________________________________________________________
422void TFluka::Mixture(Int_t& kmat, const char *name, Float_t *a,
423 Float_t *z, Double_t dens, Int_t nlmat, Float_t *wmat) {
424//
fb2cbbec 425// Define a material mixture
426//
829fb838 427 Double_t* da = fGeom->CreateDoubleArray(a, TMath::Abs(nlmat));
428 Double_t* dz = fGeom->CreateDoubleArray(z, TMath::Abs(nlmat));
429 Double_t* dwmat = fGeom->CreateDoubleArray(wmat, TMath::Abs(nlmat));
430
431 Mixture(kmat, name, da, dz, dens, nlmat, dwmat);
432 for (Int_t i=0; i<nlmat; i++) {
433 a[i] = da[i]; z[i] = dz[i]; wmat[i] = dwmat[i];
434 }
435
436 delete [] da;
437 delete [] dz;
438 delete [] dwmat;
439}
440
441//______________________________________________________________________________
442void TFluka::Mixture(Int_t& kmat, const char *name, Double_t *a,
443 Double_t *z, Double_t dens, Int_t nlmat, Double_t *wmat) {
444//
445 // Defines mixture OR COMPOUND IMAT as composed by
446 // THE BASIC NLMAT materials defined by arrays A,Z and WMAT
447 //
448 // If NLMAT > 0 then wmat contains the proportion by
449 // weights of each basic material in the mixture.
450 //
451 // If nlmat < 0 then WMAT contains the number of atoms
452 // of a given kind into the molecule of the COMPOUND
453 // In this case, WMAT in output is changed to relative
454 // weigths.
455 //
456 Int_t i,j;
457 if (nlmat < 0) {
458 nlmat = - nlmat;
459 Double_t amol = 0;
460 for (i=0;i<nlmat;i++) {
461 amol += a[i]*wmat[i];
462 }
463 for (i=0;i<nlmat;i++) {
464 wmat[i] *= a[i]/amol;
465 }
466 }
467 kmat = gGeoManager->GetListOfMaterials()->GetSize();
468 // Check if we have elements with fractional Z
469 TGeoMaterial *mat = 0;
470 TGeoMixture *mix = 0;
471 Bool_t mixnew = kFALSE;
472 for (i=0; i<nlmat; i++) {
473 if (z[i]-Int_t(z[i]) < 1E-3) continue;
474 // We have found an element with fractional Z -> loop mixtures to look for it
475 for (j=0; j<kmat; j++) {
476 mat = (TGeoMaterial*)gGeoManager->GetListOfMaterials()->At(j);
477 if (!mat) break;
478 if (!mat->IsMixture()) continue;
479 mix = (TGeoMixture*)mat;
480 if (TMath::Abs(z[i]-mix->GetZ()) >1E-3) continue;
829fb838 481 mixnew = kTRUE;
482 break;
483 }
484 if (!mixnew) Warning("Mixture","%s : cannot find component %i with fractional Z=%f\n", name, i, z[i]);
485 break;
486 }
487 if (mixnew) {
488 Int_t nlmatnew = nlmat+mix->GetNelements()-1;
489 Double_t *anew = new Double_t[nlmatnew];
490 Double_t *znew = new Double_t[nlmatnew];
491 Double_t *wmatnew = new Double_t[nlmatnew];
492 Int_t ind=0;
493 for (j=0; j<nlmat; j++) {
494 if (j==i) continue;
495 anew[ind] = a[j];
496 znew[ind] = z[j];
497 wmatnew[ind] = wmat[j];
498 ind++;
499 }
500 for (j=0; j<mix->GetNelements(); j++) {
501 anew[ind] = mix->GetAmixt()[j];
502 znew[ind] = mix->GetZmixt()[j];
503 wmatnew[ind] = wmat[i]*mix->GetWmixt()[j];
504 ind++;
505 }
506 Mixture(kmat, name, anew, znew, dens, nlmatnew, wmatnew);
507 delete [] anew;
508 delete [] znew;
509 delete [] wmatnew;
510 return;
511 }
512 // Now we need to compact identical elements within the mixture
513 // First check if this happens
514 mixnew = kFALSE;
515 for (i=0; i<nlmat-1; i++) {
516 for (j=i+1; j<nlmat; j++) {
517 if (z[i] == z[j]) {
518 mixnew = kTRUE;
519 break;
520 }
521 }
522 if (mixnew) break;
523 }
524 if (mixnew) {
525 Int_t nlmatnew = 0;
526 Double_t *anew = new Double_t[nlmat];
527 Double_t *znew = new Double_t[nlmat];
528 memset(znew, 0, nlmat*sizeof(Double_t));
529 Double_t *wmatnew = new Double_t[nlmat];
530 Bool_t skipi;
531 for (i=0; i<nlmat; i++) {
532 skipi = kFALSE;
533 for (j=0; j<nlmatnew; j++) {
534 if (z[i] == z[j]) {
535 wmatnew[j] += wmat[i];
536 skipi = kTRUE;
537 break;
538 }
539 }
540 if (skipi) continue;
541 anew[nlmatnew] = a[i];
542 znew[nlmatnew] = z[i];
543 wmatnew[nlmatnew] = wmat[i];
544 nlmatnew++;
545 }
546 Mixture(kmat, name, anew, znew, dens, nlmatnew, wmatnew);
547 delete [] anew;
548 delete [] znew;
549 delete [] wmatnew;
550 return;
551 }
552 gGeoManager->Mixture(name, a, z, dens, nlmat, wmat, kmat);
553}
554
555//______________________________________________________________________________
556void TFluka::Medium(Int_t& kmed, const char *name, Int_t nmat,
557 Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd,
558 Double_t stemax, Double_t deemax, Double_t epsil,
559 Double_t stmin, Float_t* ubuf, Int_t nbuf) {
b2129742 560 // Define a medium
561 //
829fb838 562 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
563 fMCGeo->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
564 epsil, stmin, ubuf, nbuf);
565}
566
567//______________________________________________________________________________
568void TFluka::Medium(Int_t& kmed, const char *name, Int_t nmat,
569 Int_t isvol, Int_t ifield, Double_t fieldm, Double_t tmaxfd,
570 Double_t stemax, Double_t deemax, Double_t epsil,
571 Double_t stmin, Double_t* ubuf, Int_t nbuf) {
b2129742 572 // Define a medium
573 //
829fb838 574 kmed = gGeoManager->GetListOfMedia()->GetSize()+1;
575 fMCGeo->Medium(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
576 epsil, stmin, ubuf, nbuf);
577}
578
579//______________________________________________________________________________
580void TFluka::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
581 Double_t thetaY, Double_t phiY, Double_t thetaZ,
582 Double_t phiZ) {
583//
584 krot = gGeoManager->GetListOfMatrices()->GetEntriesFast();
585 fMCGeo->Matrix(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
586}
587
588//______________________________________________________________________________
589void TFluka::Gstpar(Int_t itmed, const char* param, Double_t parval) {
590//
591//
7b203b6e 592//
829fb838 593 Bool_t process = kFALSE;
acf2e119 594 Bool_t modelp = kFALSE;
595
829fb838 596 if (strncmp(param, "DCAY", 4) == 0 ||
597 strncmp(param, "PAIR", 4) == 0 ||
598 strncmp(param, "COMP", 4) == 0 ||
599 strncmp(param, "PHOT", 4) == 0 ||
600 strncmp(param, "PFIS", 4) == 0 ||
601 strncmp(param, "DRAY", 4) == 0 ||
602 strncmp(param, "ANNI", 4) == 0 ||
603 strncmp(param, "BREM", 4) == 0 ||
604 strncmp(param, "MUNU", 4) == 0 ||
605 strncmp(param, "CKOV", 4) == 0 ||
606 strncmp(param, "HADR", 4) == 0 ||
607 strncmp(param, "LOSS", 4) == 0 ||
608 strncmp(param, "MULS", 4) == 0 ||
609 strncmp(param, "RAYL", 4) == 0)
610 {
611 process = kTRUE;
612 }
81f1d030 613
acf2e119 614 if (strncmp(param, "PRIMIO_N", 8) == 0 ||
615 strncmp(param, "PRIMIO_E", 8) == 0)
616 {
617 modelp = kTRUE;
618 }
619
829fb838 620 if (process) {
acf2e119 621 // Process switch
81f1d030 622 SetProcess(param, Int_t (parval), itmed);
acf2e119 623 } else if (modelp) {
624 // Model parameters
625 SetModelParameter(param, parval, itmed);
829fb838 626 } else {
acf2e119 627 // Cuts
81f1d030 628 SetCut(param, parval, itmed);
829fb838 629 }
acf2e119 630
631
829fb838 632}
633
634// functions from GGEOM
635//_____________________________________________________________________________
636void TFluka::Gsatt(const char *name, const char *att, Int_t val)
637{
6f5667d1 638 // Set visualisation attributes for one volume
829fb838 639 char vname[5];
640 fGeom->Vname(name,vname);
641 char vatt[5];
642 fGeom->Vname(att,vatt);
643 gGeoManager->SetVolumeAttribute(vname, vatt, val);
644}
645
646//______________________________________________________________________________
647Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
648 Float_t *upar, Int_t np) {
649//
650 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
651}
652
653//______________________________________________________________________________
654Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
655 Double_t *upar, Int_t np) {
656//
657 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
658}
659
660//______________________________________________________________________________
661void TFluka::Gsdvn(const char *name, const char *mother, Int_t ndiv,
662 Int_t iaxis) {
663//
664 fMCGeo->Gsdvn(name, mother, ndiv, iaxis);
665}
666
667//______________________________________________________________________________
668void TFluka::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
669 Int_t iaxis, Double_t c0i, Int_t numed) {
670//
671 fMCGeo->Gsdvn2(name, mother, ndiv, iaxis, c0i, numed);
672}
673
674//______________________________________________________________________________
675void TFluka::Gsdvt(const char *name, const char *mother, Double_t step,
676 Int_t iaxis, Int_t numed, Int_t ndvmx) {
677//
678 fMCGeo->Gsdvt(name, mother, step, iaxis, numed, ndvmx);
679}
680
681//______________________________________________________________________________
682void TFluka::Gsdvt2(const char *name, const char *mother, Double_t step,
683 Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx) {
684//
685 fMCGeo->Gsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
686}
687
688//______________________________________________________________________________
689void TFluka::Gsord(const char * /*name*/, Int_t /*iax*/) {
690//
691// Nothing to do with TGeo
692}
693
694//______________________________________________________________________________
695void TFluka::Gspos(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) {
698//
699 fMCGeo->Gspos(name, nr, mother, x, y, z, irot, konly);
700}
701
702//______________________________________________________________________________
703void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
704 Double_t x, Double_t y, Double_t z, Int_t irot,
705 const char *konly, Float_t *upar, Int_t np) {
706 //
707 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
708}
709
710//______________________________________________________________________________
711void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
712 Double_t x, Double_t y, Double_t z, Int_t irot,
713 const char *konly, Double_t *upar, Int_t np) {
714 //
715 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
716}
717
718//______________________________________________________________________________
719void TFluka::Gsbool(const char* /*onlyVolName*/, const char* /*manyVolName*/) {
720//
721// Nothing to do with TGeo
722}
723
a9ea1616 724//______________________________________________________________________
725Bool_t TFluka::GetTransformation(const TString &volumePath,TGeoHMatrix &mat)
726{
727 // Returns the Transformation matrix between the volume specified
728 // by the path volumePath and the Top or mater volume. The format
729 // of the path volumePath is as follows (assuming ALIC is the Top volume)
730 // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
731 // or master volume which has only 1 instance of. Of all of the daughter
732 // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
733 // the daughter volume of DDIP is S05I copy #2 and so on.
734 // Inputs:
735 // TString& volumePath The volume path to the specific volume
736 // for which you want the matrix. Volume name
737 // hierarchy is separated by "/" while the
738 // copy number is appended using a "_".
739 // Outputs:
740 // TGeoHMatrix &mat A matrix with its values set to those
741 // appropriate to the Local to Master transformation
742 // Return:
743 // A logical value if kFALSE then an error occurred and no change to
744 // mat was made.
745
746 // We have to preserve the modeler state
747 return fMCGeo->GetTransformation(volumePath, mat);
748}
749
750//______________________________________________________________________
751Bool_t TFluka::GetShape(const TString &volumePath,TString &shapeType,
752 TArrayD &par)
753{
754 // Returns the shape and its parameters for the volume specified
755 // by volumeName.
756 // Inputs:
757 // TString& volumeName The volume name
758 // Outputs:
759 // TString &shapeType Shape type
760 // TArrayD &par A TArrayD of parameters with all of the
761 // parameters of the specified shape.
762 // Return:
763 // A logical indicating whether there was an error in getting this
764 // information
765 return fMCGeo->GetShape(volumePath, shapeType, par);
766}
767
768//______________________________________________________________________
769Bool_t TFluka::GetMaterial(const TString &volumeName,
770 TString &name,Int_t &imat,
771 Double_t &a,Double_t &z,Double_t &dens,
772 Double_t &radl,Double_t &inter,TArrayD &par)
773{
774 // Returns the Material and its parameters for the volume specified
775 // by volumeName.
776 // Note, Geant3 stores and uses mixtures as an element with an effective
777 // Z and A. Consequently, if the parameter Z is not integer, then
778 // this material represents some sort of mixture.
779 // Inputs:
780 // TString& volumeName The volume name
781 // Outputs:
782 // TSrting &name Material name
783 // Int_t &imat Material index number
784 // Double_t &a Average Atomic mass of material
785 // Double_t &z Average Atomic number of material
786 // Double_t &dens Density of material [g/cm^3]
787 // Double_t &radl Average radiation length of material [cm]
788 // Double_t &inter Average interaction length of material [cm]
789 // TArrayD &par A TArrayD of user defined parameters.
790 // Return:
791 // kTRUE if no errors
792 return fMCGeo->GetMaterial(volumeName,name,imat,a,z,dens,radl,inter,par);
793}
794
795//______________________________________________________________________
796Bool_t TFluka::GetMedium(const TString &volumeName,TString &name,
797 Int_t &imed,Int_t &nmat,Int_t &isvol,Int_t &ifield,
798 Double_t &fieldm,Double_t &tmaxfd,Double_t &stemax,
799 Double_t &deemax,Double_t &epsil, Double_t &stmin,
800 TArrayD &par)
801{
802 // Returns the Medium and its parameters for the volume specified
803 // by volumeName.
804 // Inputs:
805 // TString& volumeName The volume name.
806 // Outputs:
807 // TString &name Medium name
808 // Int_t &nmat Material number defined for this medium
809 // Int_t &imed The medium index number
810 // Int_t &isvol volume number defined for this medium
811 // Int_t &iflield Magnetic field flag
812 // Double_t &fieldm Magnetic field strength
813 // Double_t &tmaxfd Maximum angle of deflection per step
814 // Double_t &stemax Maximum step size
815 // Double_t &deemax Maximum fraction of energy allowed to be lost
816 // to continuous process.
817 // Double_t &epsil Boundary crossing precision
818 // Double_t &stmin Minimum step size allowed
819 // TArrayD &par A TArrayD of user parameters with all of the
820 // parameters of the specified medium.
821 // Return:
822 // kTRUE if there where no errors
823 return fMCGeo->GetMedium(volumeName,name,imed,nmat,isvol,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin,par);
824}
825
829fb838 826//______________________________________________________________________________
827void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
828 Float_t* absco, Float_t* effic, Float_t* rindex) {
829//
830// Set Cerenkov properties for medium itmed
831//
832// npckov: number of sampling points
833// ppckov: energy values
834// absco: absorption length
835// effic: quantum efficiency
836// rindex: refraction index
837//
838//
839//
840// Create object holding Cerenkov properties
841//
842 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex);
843//
844// Pass object to medium
845 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
846 medium->SetCerenkovProperties(cerenkovProperties);
847}
848
b2be0e73 849void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
850 Float_t* absco, Float_t* effic, Float_t* rindex, Float_t* rfl) {
851//
852// Set Cerenkov properties for medium itmed
853//
854// npckov: number of sampling points
855// ppckov: energy values
856// absco: absorption length
857// effic: quantum efficiency
858// rindex: refraction index
859// rfl: reflectivity for boundary to medium itmed
860//
861//
862// Create object holding Cerenkov properties
863//
864 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex, rfl);
865//
866// Pass object to medium
867 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
868 medium->SetCerenkovProperties(cerenkovProperties);
869}
870
871
829fb838 872//______________________________________________________________________________
873void TFluka::SetCerenkov(Int_t /*itmed*/, Int_t /*npckov*/, Double_t * /*ppckov*/,
874 Double_t * /*absco*/, Double_t * /*effic*/, Double_t * /*rindex*/) {
875//
b2be0e73 876// Double_t version not implemented
829fb838 877}
b2be0e73 878
879void TFluka::SetCerenkov(Int_t /*itmed*/, Int_t /*npckov*/, Double_t* /*ppckov*/,
880 Double_t* /*absco*/, Double_t* /*effic*/, Double_t* /*rindex*/, Double_t* /*rfl*/) {
881//
882// // Double_t version not implemented
883}
884
829fb838 885// Euclid
886//______________________________________________________________________________
887void TFluka::WriteEuclid(const char* /*fileName*/, const char* /*topVol*/,
888 Int_t /*number*/, Int_t /*nlevel*/) {
889//
890// Not with TGeo
a9ea1616 891 Warning("WriteEuclid", "Not implemented !");
829fb838 892}
893
894
895
896//_____________________________________________________________________________
897// methods needed by the stepping
898//____________________________________________________________________________
899
900Int_t TFluka::GetMedium() const {
901//
902// Get the medium number for the current fluka region
903//
904 return fGeom->GetMedium(); // this I need to check due to remapping !!!
905}
906
a9ea1616 907//____________________________________________________________________________
908Int_t TFluka::GetDummyRegion() const
909{
910// Returns index of the dummy region.
911 return fGeom->GetDummyRegion();
912}
829fb838 913
a9ea1616 914//____________________________________________________________________________
915Int_t TFluka::GetDummyLattice() const
916{
917// Returns index of the dummy lattice.
918 return fGeom->GetDummyLattice();
919}
829fb838 920
921//____________________________________________________________________________
922// particle table usage
923// ID <--> PDG transformations
924//_____________________________________________________________________________
925Int_t TFluka::IdFromPDG(Int_t pdg) const
926{
927 //
928 // Return Fluka code from PDG and pseudo ENDF code
929
930 // Catch the feedback photons
a9ea1616 931 if (pdg == 50000051) return (kFLUKAoptical);
829fb838 932 // MCIHAD() goes from pdg to fluka internal.
933 Int_t intfluka = mcihad(pdg);
934 // KPTOIP array goes from internal to official
935 return GetFlukaKPTOIP(intfluka);
936}
937
938//______________________________________________________________________________
939Int_t TFluka::PDGFromId(Int_t id) const
940{
941 //
942 // Return PDG code and pseudo ENDF code from Fluka code
f926898e 943 // Alpha He3 Triton Deuteron gen. ion opt. photon
944 Int_t idSpecial[6] = {10020040, 10020030, 10010030, 10010020, 10000000, 50000050};
829fb838 945 // IPTOKP array goes from official to internal
946
a9ea1616 947 if (id == kFLUKAoptical) {
829fb838 948// Cerenkov photon
bd3d5c8a 949 if (fVerbosityLevel >= 3)
829fb838 950 printf("\n PDGFromId: Cerenkov Photon \n");
951 return 50000050;
952 }
953// Error id
ece92b30 954 if (id == 0 || id < kFLUKAcodemin || id > kFLUKAcodemax) {
f926898e 955 if (fVerbosityLevel >= 3)
829fb838 956 printf("PDGFromId: Error id = 0\n");
957 return -1;
958 }
959// Good id
f926898e 960 if (id > 0) {
961 Int_t intfluka = GetFlukaIPTOKP(id);
962 if (intfluka == 0) {
963 if (fVerbosityLevel >= 3)
964 printf("PDGFromId: Error intfluka = 0: %d\n", id);
965 return -1;
966 } else if (intfluka < 0) {
967 if (fVerbosityLevel >= 3)
968 printf("PDGFromId: Error intfluka < 0: %d\n", id);
969 return -1;
970 }
18e0cabb 971// if (fVerbosityLevel >= 3)
972// printf("mpdgha called with %d %d \n", id, intfluka);
f926898e 973 return mpdgha(intfluka);
974 } else {
975 // ions and optical photons
ece92b30 976 return idSpecial[id - kFLUKAcodemin];
829fb838 977 }
829fb838 978}
979
bd3d5c8a 980void TFluka::StopTrack()
981{
982 // Set stopping conditions
983 // Works for photons and charged particles
984 fStopped = kTRUE;
985}
986
829fb838 987//_____________________________________________________________________________
988// methods for physics management
989//____________________________________________________________________________
990//
991// set methods
992//
993
1df5fa54 994void TFluka::SetProcess(const char* flagName, Int_t flagValue, Int_t imed)
829fb838 995{
996// Set process user flag for material imat
997//
1df5fa54 998//
999// Update if already in the list
1000//
fb2cbbec 1001 TIter next(fUserConfig);
1df5fa54 1002 TFlukaConfigOption* proc;
1003 while((proc = (TFlukaConfigOption*)next()))
1004 {
fb2cbbec 1005 if (proc->Medium() == imed) {
1006 proc->SetProcess(flagName, flagValue);
1007 return;
1008 }
1df5fa54 1009 }
fb2cbbec 1010 proc = new TFlukaConfigOption(imed);
1011 proc->SetProcess(flagName, flagValue);
1012 fUserConfig->Add(proc);
1013}
1014
1015//______________________________________________________________________________
1016Bool_t TFluka::SetProcess(const char* flagName, Int_t flagValue)
1017{
1018// Set process user flag
1df5fa54 1019//
1df5fa54 1020//
fb2cbbec 1021 SetProcess(flagName, flagValue, -1);
1df5fa54 1022 return kTRUE;
829fb838 1023}
1024
1025//______________________________________________________________________________
1026void TFluka::SetCut(const char* cutName, Double_t cutValue, Int_t imed)
1027{
1028// Set user cut value for material imed
1029//
fb2cbbec 1030 TIter next(fUserConfig);
1031 TFlukaConfigOption* proc;
1032 while((proc = (TFlukaConfigOption*)next()))
1033 {
1034 if (proc->Medium() == imed) {
1035 proc->SetCut(cutName, cutValue);
1036 return;
1037 }
1038 }
1039
1040 proc = new TFlukaConfigOption(imed);
1041 proc->SetCut(cutName, cutValue);
1042 fUserConfig->Add(proc);
829fb838 1043}
1044
acf2e119 1045
1046//______________________________________________________________________________
1047void TFluka::SetModelParameter(const char* parName, Double_t parValue, Int_t imed)
1048{
1049// Set model parameter for material imed
1050//
1051 TIter next(fUserConfig);
1052 TFlukaConfigOption* proc;
1053 while((proc = (TFlukaConfigOption*)next()))
1054 {
1055 if (proc->Medium() == imed) {
1056 proc->SetModelParameter(parName, parValue);
1057 return;
1058 }
1059 }
1060
1061 proc = new TFlukaConfigOption(imed);
1062 proc->SetModelParameter(parName, parValue);
1063 fUserConfig->Add(proc);
1064}
1065
829fb838 1066//______________________________________________________________________________
1067Bool_t TFluka::SetCut(const char* cutName, Double_t cutValue)
1068{
1069// Set user cut value
1070//
1df5fa54 1071//
fb2cbbec 1072 SetCut(cutName, cutValue, -1);
1073 return kTRUE;
829fb838 1074}
1075
f450e9d0 1076
1077void TFluka::SetUserScoring(const char* option, Int_t npr, char* outfile, Float_t* what)
b496f27c 1078{
1079//
f450e9d0 1080// Adds a user scoring option to the list
b496f27c 1081//
f450e9d0 1082 TFlukaScoringOption* opt = new TFlukaScoringOption(option, "User Scoring", npr,outfile,what);
1083 fUserScore->Add(opt);
1084}
1085//______________________________________________________________________________
1086void TFluka::SetUserScoring(const char* option, Int_t npr, char* outfile, Float_t* what, const char* det1, const char* det2, const char* det3)
1087{
1088//
1089// Adds a user scoring option to the list
1090//
1091 TFlukaScoringOption* opt = new TFlukaScoringOption(option, "User Scoring", npr, outfile, what, det1, det2, det3);
b496f27c 1092 fUserScore->Add(opt);
1093}
b496f27c 1094
829fb838 1095//______________________________________________________________________________
1096Double_t TFluka::Xsec(char*, Double_t, Int_t, Int_t)
1097{
a9ea1616 1098 Warning("Xsec", "Not yet implemented.!\n"); return -1.;
829fb838 1099}
1100
1101
1102//______________________________________________________________________________
1103void TFluka::InitPhysics()
1104{
1105//
1106// Physics initialisation with preparation of FLUKA input cards
1107//
fb2cbbec 1108// Construct file names
1109 FILE *pFlukaVmcCoreInp, *pFlukaVmcFlukaMat, *pFlukaVmcInp;
1110 TString sFlukaVmcCoreInp = getenv("ALICE_ROOT");
1111 sFlukaVmcCoreInp +="/TFluka/input/";
1112 TString sFlukaVmcTmp = "flukaMat.inp";
1113 TString sFlukaVmcInp = GetInputFileName();
1114 sFlukaVmcCoreInp += GetCoreInputFileName();
1115
1116// Open files
1117 if ((pFlukaVmcCoreInp = fopen(sFlukaVmcCoreInp.Data(),"r")) == NULL) {
a9ea1616 1118 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcCoreInp.Data());
fb2cbbec 1119 exit(1);
1120 }
1121 if ((pFlukaVmcFlukaMat = fopen(sFlukaVmcTmp.Data(),"r")) == NULL) {
a9ea1616 1122 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcTmp.Data());
fb2cbbec 1123 exit(1);
1124 }
1125 if ((pFlukaVmcInp = fopen(sFlukaVmcInp.Data(),"w")) == NULL) {
a9ea1616 1126 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcInp.Data());
fb2cbbec 1127 exit(1);
1128 }
829fb838 1129
fb2cbbec 1130// Copy core input file
1131 Char_t sLine[255];
1132 Float_t fEventsPerRun;
829fb838 1133
fb2cbbec 1134 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
1135 if (strncmp(sLine,"GEOEND",6) != 0)
1136 fprintf(pFlukaVmcInp,"%s",sLine); // copy until GEOEND card
1137 else {
1138 fprintf(pFlukaVmcInp,"GEOEND\n"); // add GEOEND card
1139 goto flukamat;
829fb838 1140 }
fb2cbbec 1141 } // end of while until GEOEND card
1142
829fb838 1143
fb2cbbec 1144 flukamat:
1145 while ((fgets(sLine,255,pFlukaVmcFlukaMat)) != NULL) { // copy flukaMat.inp file
1146 fprintf(pFlukaVmcInp,"%s\n",sLine);
1147 }
1148
1149 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
1150 if (strncmp(sLine,"START",5) != 0)
1151 fprintf(pFlukaVmcInp,"%s\n",sLine);
1152 else {
1153 sscanf(sLine+10,"%10f",&fEventsPerRun);
1154 goto fin;
1155 }
1156 } //end of while until START card
1157
1158 fin:
829fb838 1159
f450e9d0 1160
1161// Pass information to configuration objects
829fb838 1162
fb2cbbec 1163 Float_t fLastMaterial = fGeom->GetLastMaterialIndex();
1164 TFlukaConfigOption::SetStaticInfo(pFlukaVmcInp, 3, fLastMaterial, fGeom);
1165
1166 TIter next(fUserConfig);
1167 TFlukaConfigOption* proc;
f450e9d0 1168 while((proc = dynamic_cast<TFlukaConfigOption*> (next()))) proc->WriteFlukaInputCards();
1169//
1170// Process Fluka specific scoring options
1171//
1172 TFlukaScoringOption::SetStaticInfo(pFlukaVmcInp, fGeom);
1173 Float_t loginp = 49.0;
1174 Int_t inp = 0;
1175 Int_t nscore = fUserScore->GetEntries();
1176
a9ea1616 1177 TFlukaScoringOption *mopo = 0;
1178 TFlukaScoringOption *mopi = 0;
fb2cbbec 1179
f450e9d0 1180 for (Int_t isc = 0; isc < nscore; isc++)
1181 {
1182 mopo = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isc));
1183 char* fileName = mopo->GetFileName();
1184 Int_t size = strlen(fileName);
1185 Float_t lun = -1.;
1186//
1187// Check if new output file has to be opened
1188 for (Int_t isci = 0; isci < isc; isci++) {
a9d74780 1189
1190
1191 mopi = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isci));
f450e9d0 1192 if(strncmp(mopi->GetFileName(), fileName, size)==0) {
1193 //
1194 // No, the file already exists
1195 lun = mopi->GetLun();
1196 mopo->SetLun(lun);
1197 break;
1198 }
1199 } // inner loop
1200
1201 if (lun == -1.) {
1202 // Open new output file
1203 inp++;
1204 mopo->SetLun(loginp + inp);
1205 mopo->WriteOpenFlukaFile();
1206 }
1207 mopo->WriteFlukaInputCards();
1208 }
b8a8a88c 1209
1210// Add RANDOMIZ card
1211 fprintf(pFlukaVmcInp,"RANDOMIZ %10.1f%10.0f\n", 1., Float_t(gRandom->GetSeed()));
829fb838 1212// Add START and STOP card
f450e9d0 1213 fprintf(pFlukaVmcInp,"START %10.1f\n",fEventsPerRun);
1214 fprintf(pFlukaVmcInp,"STOP \n");
829fb838 1215
1216
1217// Close files
3b8c325d 1218 fclose(pFlukaVmcCoreInp);
1219 fclose(pFlukaVmcFlukaMat);
1220 fclose(pFlukaVmcInp);
fb2cbbec 1221
1222
1223//
1224// Initialisation needed for Cerenkov photon production and transport
1225 TObjArray *matList = GetFlukaMaterials();
1226 Int_t nmaterial = matList->GetEntriesFast();
1227 fMaterials = new Int_t[nmaterial+3];
1228
1229 for (Int_t im = 0; im < nmaterial; im++)
1230 {
1231 TGeoMaterial* material = dynamic_cast<TGeoMaterial*> (matList->At(im));
1232 Int_t idmat = material->GetIndex();
1233 fMaterials[idmat] = im;
1234 }
829fb838 1235} // end of InitPhysics
1236
1237
1238//______________________________________________________________________________
07f5b33e 1239void TFluka::SetMaxStep(Double_t step)
829fb838 1240{
07f5b33e 1241// Set the maximum step size
1242 if (step > 1.e4) return;
1243
1244 Int_t mreg, latt;
1245 fGeom->GetCurrentRegion(mreg, latt);
9c0c08ce 1246 STEPSZ.stepmx[mreg - 1] = step;
829fb838 1247}
1248
2f09b80e 1249
1250Double_t TFluka::MaxStep() const
1251{
1252// Return the maximum for current medium
1253 Int_t mreg, latt;
1254 fGeom->GetCurrentRegion(mreg, latt);
1255 return (STEPSZ.stepmx[mreg - 1]);
1256}
1257
829fb838 1258//______________________________________________________________________________
1259void TFluka::SetMaxNStep(Int_t)
1260{
1261// SetMaxNStep is dummy procedure in TFluka !
1262 if (fVerbosityLevel >=3)
1263 cout << "SetMaxNStep is dummy procedure in TFluka !" << endl;
1264}
1265
1266//______________________________________________________________________________
1267void TFluka::SetUserDecay(Int_t)
1268{
1269// SetUserDecay is dummy procedure in TFluka !
1270 if (fVerbosityLevel >=3)
1271 cout << "SetUserDecay is dummy procedure in TFluka !" << endl;
1272}
1273
1274//
1275// dynamic properties
1276//
1277//______________________________________________________________________________
1278void TFluka::TrackPosition(TLorentzVector& position) const
1279{
1280// Return the current position in the master reference frame of the
1281// track being transported
1282// TRACKR.atrack = age of the particle
1283// TRACKR.xtrack = x-position of the last point
1284// TRACKR.ytrack = y-position of the last point
1285// TRACKR.ztrack = z-position of the last point
a9ea1616 1286 FlukaCallerCode_t caller = GetCaller();
1287 if (caller == kENDRAW || caller == kUSDRAW ||
1288 caller == kBXExiting || caller == kBXEntering ||
1289 caller == kUSTCKV) {
829fb838 1290 position.SetX(GetXsco());
1291 position.SetY(GetYsco());
1292 position.SetZ(GetZsco());
1293 position.SetT(TRACKR.atrack);
1294 }
a9ea1616 1295 else if (caller == kMGDRAW) {
829fb838 1296 position.SetX(TRACKR.xtrack[TRACKR.ntrack]);
1297 position.SetY(TRACKR.ytrack[TRACKR.ntrack]);
1298 position.SetZ(TRACKR.ztrack[TRACKR.ntrack]);
1299 position.SetT(TRACKR.atrack);
1300 }
a9ea1616 1301 else if (caller == kSODRAW) {
829fb838 1302 position.SetX(TRACKR.xtrack[TRACKR.ntrack]);
1303 position.SetY(TRACKR.ytrack[TRACKR.ntrack]);
1304 position.SetZ(TRACKR.ztrack[TRACKR.ntrack]);
1305 position.SetT(0);
a9ea1616 1306 } else if (caller == kMGResumedTrack) {
5d80a015 1307 position.SetX(TRACKR.spausr[0]);
1308 position.SetY(TRACKR.spausr[1]);
1309 position.SetZ(TRACKR.spausr[2]);
1310 position.SetT(TRACKR.spausr[3]);
829fb838 1311 }
1312 else
1313 Warning("TrackPosition","position not available");
1314}
1315
1316//______________________________________________________________________________
1317void TFluka::TrackPosition(Double_t& x, Double_t& y, Double_t& z) const
1318{
1319// Return the current position in the master reference frame of the
1320// track being transported
1321// TRACKR.atrack = age of the particle
1322// TRACKR.xtrack = x-position of the last point
1323// TRACKR.ytrack = y-position of the last point
1324// TRACKR.ztrack = z-position of the last point
a9ea1616 1325 FlukaCallerCode_t caller = GetCaller();
1326 if (caller == kENDRAW || caller == kUSDRAW ||
1327 caller == kBXExiting || caller == kBXEntering ||
1328 caller == kUSTCKV) {
829fb838 1329 x = GetXsco();
1330 y = GetYsco();
1331 z = GetZsco();
1332 }
a9ea1616 1333 else if (caller == kMGDRAW || caller == kSODRAW) {
829fb838 1334 x = TRACKR.xtrack[TRACKR.ntrack];
1335 y = TRACKR.ytrack[TRACKR.ntrack];
1336 z = TRACKR.ztrack[TRACKR.ntrack];
1337 }
a9ea1616 1338 else if (caller == kMGResumedTrack) {
5d80a015 1339 x = TRACKR.spausr[0];
1340 y = TRACKR.spausr[1];
1341 z = TRACKR.spausr[2];
1342 }
829fb838 1343 else
1344 Warning("TrackPosition","position not available");
1345}
1346
1347//______________________________________________________________________________
1348void TFluka::TrackMomentum(TLorentzVector& momentum) const
1349{
1350// Return the direction and the momentum (GeV/c) of the track
1351// currently being transported
1352// TRACKR.ptrack = momentum of the particle (not always defined, if
1353// < 0 must be obtained from etrack)
1354// TRACKR.cx,y,ztrck = direction cosines of the current particle
1355// TRACKR.etrack = total energy of the particle
1356// TRACKR.jtrack = identity number of the particle
1357// PAPROP.am[TRACKR.jtrack] = particle mass in gev
a9ea1616 1358 FlukaCallerCode_t caller = GetCaller();
1359 FlukaProcessCode_t icode = GetIcode();
1360
1361 if (caller != kEEDRAW && caller != kMGResumedTrack &&
1362 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
829fb838 1363 if (TRACKR.ptrack >= 0) {
1364 momentum.SetPx(TRACKR.ptrack*TRACKR.cxtrck);
1365 momentum.SetPy(TRACKR.ptrack*TRACKR.cytrck);
1366 momentum.SetPz(TRACKR.ptrack*TRACKR.cztrck);
1367 momentum.SetE(TRACKR.etrack);
1368 return;
1369 }
1370 else {
ece92b30 1371 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
829fb838 1372 momentum.SetPx(p*TRACKR.cxtrck);
1373 momentum.SetPy(p*TRACKR.cytrck);
1374 momentum.SetPz(p*TRACKR.cztrck);
1375 momentum.SetE(TRACKR.etrack);
1376 return;
1377 }
a9ea1616 1378 } else if (caller == kMGResumedTrack) {
5d80a015 1379 momentum.SetPx(TRACKR.spausr[4]);
1380 momentum.SetPy(TRACKR.spausr[5]);
1381 momentum.SetPz(TRACKR.spausr[6]);
1382 momentum.SetE (TRACKR.spausr[7]);
1383 return;
a9ea1616 1384 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1385 momentum.SetPx(0.);
1386 momentum.SetPy(0.);
1387 momentum.SetPz(0.);
1388 momentum.SetE(TrackMass());
829fb838 1389 }
1390 else
1391 Warning("TrackMomentum","momentum not available");
1392}
1393
1394//______________________________________________________________________________
1395void TFluka::TrackMomentum(Double_t& px, Double_t& py, Double_t& pz, Double_t& e) const
1396{
1397// Return the direction and the momentum (GeV/c) of the track
1398// currently being transported
1399// TRACKR.ptrack = momentum of the particle (not always defined, if
1400// < 0 must be obtained from etrack)
1401// TRACKR.cx,y,ztrck = direction cosines of the current particle
1402// TRACKR.etrack = total energy of the particle
1403// TRACKR.jtrack = identity number of the particle
1404// PAPROP.am[TRACKR.jtrack] = particle mass in gev
a9ea1616 1405 FlukaCallerCode_t caller = GetCaller();
1406 FlukaProcessCode_t icode = GetIcode();
1407 if (caller != kEEDRAW && caller != kMGResumedTrack &&
1408 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
829fb838 1409 if (TRACKR.ptrack >= 0) {
1410 px = TRACKR.ptrack*TRACKR.cxtrck;
1411 py = TRACKR.ptrack*TRACKR.cytrck;
1412 pz = TRACKR.ptrack*TRACKR.cztrck;
a9ea1616 1413 e = TRACKR.etrack;
829fb838 1414 return;
1415 }
1416 else {
ece92b30 1417 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
829fb838 1418 px = p*TRACKR.cxtrck;
1419 py = p*TRACKR.cytrck;
1420 pz = p*TRACKR.cztrck;
a9ea1616 1421 e = TRACKR.etrack;
829fb838 1422 return;
1423 }
a9ea1616 1424 } else if (caller == kMGResumedTrack) {
5d80a015 1425 px = TRACKR.spausr[4];
1426 py = TRACKR.spausr[5];
1427 pz = TRACKR.spausr[6];
1428 e = TRACKR.spausr[7];
0773d0ac 1429 return;
a9ea1616 1430 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1431 px = 0.;
1432 py = 0.;
1433 pz = 0.;
1434 e = TrackMass();
829fb838 1435 }
1436 else
1437 Warning("TrackMomentum","momentum not available");
1438}
1439
1440//______________________________________________________________________________
1441Double_t TFluka::TrackStep() const
1442{
1443// Return the length in centimeters of the current step
1444// TRACKR.ctrack = total curved path
a9ea1616 1445 FlukaCallerCode_t caller = GetCaller();
1446 if (caller == kBXEntering || caller == kBXExiting ||
1447 caller == kENDRAW || caller == kUSDRAW ||
1448 caller == kUSTCKV || caller == kMGResumedTrack)
829fb838 1449 return 0.0;
a9ea1616 1450 else if (caller == kMGDRAW)
829fb838 1451 return TRACKR.ctrack;
669cede4 1452 else {
1453 Warning("TrackStep", "track step not available");
1454 return 0.0;
1455 }
829fb838 1456}
1457
1458//______________________________________________________________________________
1459Double_t TFluka::TrackLength() const
1460{
1461// TRACKR.cmtrck = cumulative curved path since particle birth
a9ea1616 1462 FlukaCallerCode_t caller = GetCaller();
1463 if (caller == kBXEntering || caller == kBXExiting ||
1464 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1465 caller == kUSTCKV)
829fb838 1466 return TRACKR.cmtrck;
a9ea1616 1467 else if (caller == kMGResumedTrack)
5d80a015 1468 return TRACKR.spausr[8];
669cede4 1469 else {
1470 Warning("TrackLength", "track length not available");
1471 return 0.0;
1472 }
829fb838 1473}
1474
1475//______________________________________________________________________________
1476Double_t TFluka::TrackTime() const
1477{
1478// Return the current time of flight of the track being transported
1479// TRACKR.atrack = age of the particle
a9ea1616 1480 FlukaCallerCode_t caller = GetCaller();
1481 if (caller == kBXEntering || caller == kBXExiting ||
1482 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1483 caller == kUSTCKV)
829fb838 1484 return TRACKR.atrack;
a9ea1616 1485 else if (caller == kMGResumedTrack)
5d80a015 1486 return TRACKR.spausr[3];
669cede4 1487 else {
1488 Warning("TrackTime", "track time not available");
1489 return 0.0;
1490 }
829fb838 1491}
1492
1493//______________________________________________________________________________
1494Double_t TFluka::Edep() const
1495{
1496// Energy deposition
1497// if TRACKR.ntrack = 0, TRACKR.mtrack = 0:
1498// -->local energy deposition (the value and the point are not recorded in TRACKR)
1499// but in the variable "rull" of the procedure "endraw.cxx"
1500// if TRACKR.ntrack > 0, TRACKR.mtrack = 0:
1501// -->no energy loss along the track
1502// if TRACKR.ntrack > 0, TRACKR.mtrack > 0:
1503// -->energy loss distributed along the track
07f5b33e 1504// TRACKR.dtrack = energy deposition of the jth deposition event
829fb838 1505
1506 // If coming from bxdraw we have 2 steps of 0 length and 0 edep
669cede4 1507 // If coming from usdraw we just signal particle production - no edep
1508 // If just first time after resuming, no edep for the primary
a9ea1616 1509 FlukaCallerCode_t caller = GetCaller();
1510 if (caller == kBXExiting || caller == kBXEntering ||
1511 caller == kUSDRAW || caller == kMGResumedTrack) return 0.0;
829fb838 1512 Double_t sum = 0;
1513 for ( Int_t j=0;j<TRACKR.mtrack;j++) {
b2be0e73 1514 sum +=TRACKR.dtrack[j];
829fb838 1515 }
1516 if (TRACKR.ntrack == 0 && TRACKR.mtrack == 0)
b2be0e73 1517 return fRull + sum;
829fb838 1518 else {
b2be0e73 1519 return sum;
829fb838 1520 }
1521}
1522
1523//______________________________________________________________________________
18e0cabb 1524Int_t TFluka::CorrectFlukaId() const
1525{
1526 // since we don't put photons and e- created bellow transport cut on the vmc stack
1527 // and there is a call to endraw for energy deposition for each of them
1528 // and they have the track number of their parent, but different identity (pdg)
1529 // so we want to assign also their parent identity also.
1530 if( (IsTrackStop() )
1531 && TRACKR.ispusr[mkbmx2 - 4] == TRACKR.ispusr[mkbmx2 - 1]
1532 && TRACKR.jtrack != TRACKR.ispusr[mkbmx2 - 3] ) {
1533 if (fVerbosityLevel >=3)
1534 cout << "CorrectFlukaId() for icode=" << GetIcode()
1535 << " track=" << TRACKR.ispusr[mkbmx2 - 1]
1536 << " current PDG=" << PDGFromId(TRACKR.jtrack)
1537 << " assign parent PDG=" << PDGFromId(TRACKR.ispusr[mkbmx2 - 3]) << endl;
1538 return TRACKR.ispusr[mkbmx2 - 3]; // assign parent identity
1539 }
1540 return TRACKR.jtrack;
1541}
1542
1543
1544//______________________________________________________________________________
829fb838 1545Int_t TFluka::TrackPid() const
1546{
1547// Return the id of the particle transported
1548// TRACKR.jtrack = identity number of the particle
a9ea1616 1549 FlukaCallerCode_t caller = GetCaller();
1550 if (caller != kEEDRAW) {
18e0cabb 1551 return PDGFromId( CorrectFlukaId() );
f926898e 1552 }
829fb838 1553 else
1554 return -1000;
1555}
1556
1557//______________________________________________________________________________
1558Double_t TFluka::TrackCharge() const
1559{
1560// Return charge of the track currently transported
1561// PAPROP.ichrge = electric charge of the particle
1562// TRACKR.jtrack = identity number of the particle
a9ea1616 1563 FlukaCallerCode_t caller = GetCaller();
1564 if (caller != kEEDRAW)
18e0cabb 1565 return PAPROP.ichrge[CorrectFlukaId()+6];
829fb838 1566 else
1567 return -1000.0;
1568}
1569
1570//______________________________________________________________________________
1571Double_t TFluka::TrackMass() const
1572{
1573// PAPROP.am = particle mass in GeV
1574// TRACKR.jtrack = identity number of the particle
a9ea1616 1575 FlukaCallerCode_t caller = GetCaller();
1576 if (caller != kEEDRAW)
18e0cabb 1577 return PAPROP.am[CorrectFlukaId()+6];
829fb838 1578 else
1579 return -1000.0;
1580}
1581
1582//______________________________________________________________________________
1583Double_t TFluka::Etot() const
1584{
1585// TRACKR.etrack = total energy of the particle
a9ea1616 1586 FlukaCallerCode_t caller = GetCaller();
1587 if (caller != kEEDRAW)
829fb838 1588 return TRACKR.etrack;
1589 else
1590 return -1000.0;
1591}
1592
1593//
1594// track status
1595//
1596//______________________________________________________________________________
1597Bool_t TFluka::IsNewTrack() const
1598{
1599// Return true for the first call of Stepping()
1600 return fTrackIsNew;
1601}
1602
0dabe425 1603void TFluka::SetTrackIsNew(Bool_t flag)
1604{
1605// Return true for the first call of Stepping()
1606 fTrackIsNew = flag;
1607
1608}
1609
1610
829fb838 1611//______________________________________________________________________________
1612Bool_t TFluka::IsTrackInside() const
1613{
1614// True if the track is not at the boundary of the current volume
1615// In Fluka a step is always inside one kind of material
1616// If the step would go behind the region of one material,
1617// it will be shortened to reach only the boundary.
1618// Therefore IsTrackInside() is always true.
a9ea1616 1619 FlukaCallerCode_t caller = GetCaller();
1620 if (caller == kBXEntering || caller == kBXExiting)
829fb838 1621 return 0;
1622 else
1623 return 1;
1624}
1625
1626//______________________________________________________________________________
1627Bool_t TFluka::IsTrackEntering() const
1628{
1629// True if this is the first step of the track in the current volume
1630
a9ea1616 1631 FlukaCallerCode_t caller = GetCaller();
1632 if (caller == kBXEntering)
829fb838 1633 return 1;
1634 else return 0;
1635}
1636
1637//______________________________________________________________________________
1638Bool_t TFluka::IsTrackExiting() const
1639{
1640// True if track is exiting volume
1641//
a9ea1616 1642 FlukaCallerCode_t caller = GetCaller();
1643 if (caller == kBXExiting)
829fb838 1644 return 1;
1645 else return 0;
1646}
1647
1648//______________________________________________________________________________
1649Bool_t TFluka::IsTrackOut() const
1650{
1651// True if the track is out of the setup
1652// means escape
a9ea1616 1653 FlukaProcessCode_t icode = GetIcode();
1654
1655 if (icode == kKASKADescape ||
1656 icode == kEMFSCOescape ||
1657 icode == kKASNEUescape ||
1658 icode == kKASHEAescape ||
1659 icode == kKASOPHescape)
1660 return 1;
829fb838 1661 else return 0;
1662}
1663
1664//______________________________________________________________________________
1665Bool_t TFluka::IsTrackDisappeared() const
1666{
a9ea1616 1667// All inelastic interactions and decays
829fb838 1668// fIcode from usdraw
a9ea1616 1669 FlukaProcessCode_t icode = GetIcode();
1670 if (icode == kKASKADinelint || // inelastic interaction
1671 icode == kKASKADdecay || // particle decay
1672 icode == kKASKADdray || // delta ray generation by hadron
1673 icode == kKASKADpair || // direct pair production
1674 icode == kKASKADbrems || // bremsstrahlung (muon)
1675 icode == kEMFSCObrems || // bremsstrahlung (electron)
1676 icode == kEMFSCOmoller || // Moller scattering
1677 icode == kEMFSCObhabha || // Bhaba scattering
1678 icode == kEMFSCOanniflight || // in-flight annihilation
1679 icode == kEMFSCOannirest || // annihilation at rest
1680 icode == kEMFSCOpair || // pair production
1681 icode == kEMFSCOcompton || // Compton scattering
1682 icode == kEMFSCOphotoel || // Photoelectric effect
1683 icode == kKASNEUhadronic || // hadronic interaction
2047b055 1684 icode == kKASHEAdray // delta-ray
0dabe425 1685 ) return 1;
829fb838 1686 else return 0;
1687}
1688
1689//______________________________________________________________________________
1690Bool_t TFluka::IsTrackStop() const
1691{
1692// True if the track energy has fallen below the threshold
1693// means stopped by signal or below energy threshold
a9ea1616 1694 FlukaProcessCode_t icode = GetIcode();
18e0cabb 1695 if (icode == kKASKADstopping || // stopping particle
1696 icode == kKASKADtimekill || // time kill
1697 icode == kEMFSCOstopping1 || // below user-defined cut-off
1698 icode == kEMFSCOstopping2 || // below user cut-off
1699 icode == kEMFSCOtimekill || // time kill
1700 icode == kKASNEUstopping || // neutron below threshold
1701 icode == kKASNEUtimekill || // time kill
1702 icode == kKASHEAtimekill || // time kill
1703 icode == kKASOPHtimekill) return 1; // time kill
829fb838 1704 else return 0;
1705}
1706
1707//______________________________________________________________________________
1708Bool_t TFluka::IsTrackAlive() const
1709{
1710// means not disappeared or not out
1711 if (IsTrackDisappeared() || IsTrackOut() ) return 0;
1712 else return 1;
1713}
1714
1715//
1716// secondaries
1717//
1718
1719//______________________________________________________________________________
1720Int_t TFluka::NSecondaries() const
1721
1722{
1723// Number of secondary particles generated in the current step
81f1d030 1724// GENSTK.np = number of secondaries except light and heavy ions
829fb838 1725// FHEAVY.npheav = number of secondaries for light and heavy secondary ions
a9ea1616 1726 FlukaCallerCode_t caller = GetCaller();
1727 if (caller == kUSDRAW) // valid only after usdraw
81f1d030 1728 return GENSTK.np + FHEAVY.npheav;
a9ea1616 1729 else if (caller == kUSTCKV) {
7b203b6e 1730 // Cerenkov Photon production
1731 return fNCerenkov;
1732 }
829fb838 1733 return 0;
1734} // end of NSecondaries
1735
1736//______________________________________________________________________________
1737void TFluka::GetSecondary(Int_t isec, Int_t& particleId,
1738 TLorentzVector& position, TLorentzVector& momentum)
1739{
1740// Copy particles from secondary stack to vmc stack
1741//
1742
a9ea1616 1743 FlukaCallerCode_t caller = GetCaller();
1744 if (caller == kUSDRAW) { // valid only after usdraw
81f1d030 1745 if (GENSTK.np > 0) {
7b203b6e 1746 // Hadronic interaction
81f1d030 1747 if (isec >= 0 && isec < GENSTK.np) {
1748 particleId = PDGFromId(GENSTK.kpart[isec]);
7b203b6e 1749 position.SetX(fXsco);
1750 position.SetY(fYsco);
1751 position.SetZ(fZsco);
1752 position.SetT(TRACKR.atrack);
81f1d030 1753 momentum.SetPx(GENSTK.plr[isec]*GENSTK.cxr[isec]);
1754 momentum.SetPy(GENSTK.plr[isec]*GENSTK.cyr[isec]);
1755 momentum.SetPz(GENSTK.plr[isec]*GENSTK.czr[isec]);
1756 momentum.SetE(GENSTK.tki[isec] + PAPROP.am[GENSTK.kpart[isec]+6]);
7b203b6e 1757 }
81f1d030 1758 else if (isec >= GENSTK.np && isec < GENSTK.np + FHEAVY.npheav) {
1759 Int_t jsec = isec - GENSTK.np;
7b203b6e 1760 particleId = FHEAVY.kheavy[jsec]; // this is Fluka id !!!
1761 position.SetX(fXsco);
1762 position.SetY(fYsco);
1763 position.SetZ(fZsco);
1764 position.SetT(TRACKR.atrack);
1765 momentum.SetPx(FHEAVY.pheavy[jsec]*FHEAVY.cxheav[jsec]);
1766 momentum.SetPy(FHEAVY.pheavy[jsec]*FHEAVY.cyheav[jsec]);
1767 momentum.SetPz(FHEAVY.pheavy[jsec]*FHEAVY.czheav[jsec]);
1768 if (FHEAVY.tkheav[jsec] >= 3 && FHEAVY.tkheav[jsec] <= 6)
1769 momentum.SetE(FHEAVY.tkheav[jsec] + PAPROP.am[jsec+6]);
1770 else if (FHEAVY.tkheav[jsec] > 6)
1771 momentum.SetE(FHEAVY.tkheav[jsec] + FHEAVY.amnhea[jsec]); // to be checked !!!
1772 }
1773 else
1774 Warning("GetSecondary","isec out of range");
1775 }
a9ea1616 1776 } else if (caller == kUSTCKV) {
7b203b6e 1777 Int_t index = OPPHST.lstopp - isec;
1778 position.SetX(OPPHST.xoptph[index]);
1779 position.SetY(OPPHST.yoptph[index]);
1780 position.SetZ(OPPHST.zoptph[index]);
1781 position.SetT(OPPHST.agopph[index]);
1782 Double_t p = OPPHST.poptph[index];
1783
1784 momentum.SetPx(p * OPPHST.txopph[index]);
1785 momentum.SetPy(p * OPPHST.tyopph[index]);
1786 momentum.SetPz(p * OPPHST.tzopph[index]);
1787 momentum.SetE(p);
829fb838 1788 }
1789 else
7b203b6e 1790 Warning("GetSecondary","no secondaries available");
1791
829fb838 1792} // end of GetSecondary
1793
7b203b6e 1794
829fb838 1795//______________________________________________________________________________
1796TMCProcess TFluka::ProdProcess(Int_t) const
1797
1798{
1799// Name of the process that has produced the secondary particles
1800// in the current step
0dabe425 1801
a9ea1616 1802 Int_t mugamma = (TRACKR.jtrack == kFLUKAphoton ||
1803 TRACKR.jtrack == kFLUKAmuplus ||
1804 TRACKR.jtrack == kFLUKAmuminus);
1805 FlukaProcessCode_t icode = GetIcode();
1806
1807 if (icode == kKASKADdecay) return kPDecay;
1808 else if (icode == kKASKADpair || icode == kEMFSCOpair) return kPPair;
1809 else if (icode == kEMFSCOcompton) return kPCompton;
1810 else if (icode == kEMFSCOphotoel) return kPPhotoelectric;
1811 else if (icode == kKASKADbrems || icode == kEMFSCObrems) return kPBrem;
1812 else if (icode == kKASKADdray || icode == kKASHEAdray) return kPDeltaRay;
1813 else if (icode == kEMFSCOmoller || icode == kEMFSCObhabha) return kPDeltaRay;
1814 else if (icode == kEMFSCOanniflight || icode == kEMFSCOannirest) return kPAnnihilation;
1815 else if (icode == kKASKADinelint) {
1816 if (!mugamma) return kPHadronic;
1817 else if (TRACKR.jtrack == kFLUKAphoton) return kPPhotoFission;
1818 else return kPMuonNuclear;
829fb838 1819 }
a9ea1616 1820 else if (icode == kEMFSCOrayleigh) return kPRayleigh;
829fb838 1821// Fluka codes 100, 300 and 400 still to be investigasted
a9ea1616 1822 else return kPNoProcess;
829fb838 1823}
1824
829fb838 1825
b496f27c 1826Int_t TFluka::StepProcesses(TArrayI &proc) const
1827{
1828 //
1829 // Return processes active in the current step
1830 //
a9ea1616 1831 FlukaProcessCode_t icode = GetIcode();
b496f27c 1832 proc.Set(1);
1833 TMCProcess iproc;
a9ea1616 1834 switch (icode) {
1835 case kKASKADtimekill:
1836 case kEMFSCOtimekill:
1837 case kKASNEUtimekill:
1838 case kKASHEAtimekill:
1839 case kKASOPHtimekill:
b496f27c 1840 iproc = kPTOFlimit;
1841 break;
a9ea1616 1842 case kKASKADstopping:
1843 case kKASKADescape:
1844 case kEMFSCOstopping1:
1845 case kEMFSCOstopping2:
1846 case kEMFSCOescape:
1847 case kKASNEUstopping:
1848 case kKASNEUescape:
1849 case kKASHEAescape:
1850 case kKASOPHescape:
6fd5baa4 1851 iproc = kPStop;
b496f27c 1852 break;
a9ea1616 1853 case kKASOPHabsorption:
b496f27c 1854 iproc = kPLightAbsorption;
1855 break;
a9ea1616 1856 case kKASOPHrefraction:
6fd5baa4 1857 iproc = kPLightRefraction;
a9ea1616 1858 case kEMSCOlocaledep :
b496f27c 1859 iproc = kPPhotoelectric;
1860 break;
1861 default:
1862 iproc = ProdProcess(0);
1863 }
07f5b33e 1864 proc[0] = iproc;
b496f27c 1865 return 1;
1866}
829fb838 1867//______________________________________________________________________________
1868Int_t TFluka::VolId2Mate(Int_t id) const
1869{
1870//
1871// Returns the material number for a given volume ID
1872//
1873 return fMCGeo->VolId2Mate(id);
1874}
1875
1876//______________________________________________________________________________
1877const char* TFluka::VolName(Int_t id) const
1878{
1879//
1880// Returns the volume name for a given volume ID
1881//
1882 return fMCGeo->VolName(id);
1883}
1884
1885//______________________________________________________________________________
1886Int_t TFluka::VolId(const Text_t* volName) const
1887{
1888//
1889// Converts from volume name to volume ID.
1890// Time consuming. (Only used during set-up)
1891// Could be replaced by hash-table
1892//
09cd6497 1893 char sname[20];
1894 Int_t len;
1895 strncpy(sname, volName, len = strlen(volName));
1896 sname[len] = 0;
1897 while (sname[len - 1] == ' ') sname[--len] = 0;
1898 return fMCGeo->VolId(sname);
829fb838 1899}
1900
1901//______________________________________________________________________________
1902Int_t TFluka::CurrentVolID(Int_t& copyNo) const
1903{
1904//
1905// Return the logical id and copy number corresponding to the current fluka region
1906//
1907 if (gGeoManager->IsOutside()) return 0;
1908 TGeoNode *node = gGeoManager->GetCurrentNode();
1909 copyNo = node->GetNumber();
1910 Int_t id = node->GetVolume()->GetNumber();
1911 return id;
1912}
1913
1914//______________________________________________________________________________
1915Int_t TFluka::CurrentVolOffID(Int_t off, Int_t& copyNo) const
1916{
1917//
1918// Return the logical id and copy number of off'th mother
1919// corresponding to the current fluka region
1920//
1921 if (off<0 || off>gGeoManager->GetLevel()) return 0;
1922 if (off==0) return CurrentVolID(copyNo);
1923 TGeoNode *node = gGeoManager->GetMother(off);
1924 if (!node) return 0;
1925 copyNo = node->GetNumber();
1926 return node->GetVolume()->GetNumber();
1927}
1928
1929//______________________________________________________________________________
1930const char* TFluka::CurrentVolName() const
1931{
1932//
1933// Return the current volume name
1934//
1935 if (gGeoManager->IsOutside()) return 0;
1936 return gGeoManager->GetCurrentVolume()->GetName();
1937}
1938
1939//______________________________________________________________________________
1940const char* TFluka::CurrentVolOffName(Int_t off) const
1941{
1942//
1943// Return the volume name of the off'th mother of the current volume
1944//
1945 if (off<0 || off>gGeoManager->GetLevel()) return 0;
1946 if (off==0) return CurrentVolName();
1947 TGeoNode *node = gGeoManager->GetMother(off);
1948 if (!node) return 0;
1949 return node->GetVolume()->GetName();
1950}
1951
d59acfe7 1952const char* TFluka::CurrentVolPath() {
1953 // Return the current volume path
1954 return gGeoManager->GetPath();
1955}
829fb838 1956//______________________________________________________________________________
a60813de 1957Int_t TFluka::CurrentMaterial(Float_t & a, Float_t & z,
1958 Float_t & dens, Float_t & radl, Float_t & absl) const
829fb838 1959{
1960//
a60813de 1961// Return the current medium number and material properties
829fb838 1962//
1963 Int_t copy;
1964 Int_t id = TFluka::CurrentVolID(copy);
1965 Int_t med = TFluka::VolId2Mate(id);
a60813de 1966 TGeoVolume* vol = gGeoManager->GetCurrentVolume();
1967 TGeoMaterial* mat = vol->GetMaterial();
1968 a = mat->GetA();
1969 z = mat->GetZ();
1970 dens = mat->GetDensity();
1971 radl = mat->GetRadLen();
1972 absl = mat->GetIntLen();
1973
829fb838 1974 return med;
1975}
1976
1977//______________________________________________________________________________
1978void TFluka::Gmtod(Float_t* xm, Float_t* xd, Int_t iflag)
1979{
1980// Transforms a position from the world reference frame
1981// to the current volume reference frame.
1982//
1983// Geant3 desription:
1984// ==================
1985// Computes coordinates XD (in DRS)
1986// from known coordinates XM in MRS
1987// The local reference system can be initialized by
1988// - the tracking routines and GMTOD used in GUSTEP
1989// - a call to GMEDIA(XM,NUMED)
1990// - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
1991// (inverse routine is GDTOM)
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++) xmL[i]=xm[i];
2000 if (iflag == 1) gGeoManager->MasterToLocal(xmL,xdL);
2001 else gGeoManager->MasterToLocalVect(xmL,xdL);
2002 for (i=0;i<3;i++) xd[i] = xdL[i];
2003}
2004
2005//______________________________________________________________________________
2006void TFluka::Gmtod(Double_t* xm, Double_t* xd, Int_t iflag)
2007{
2047b055 2008//
2009// See Gmtod(Float_t*, Float_t*, Int_t)
2010//
829fb838 2011 if (iflag == 1) gGeoManager->MasterToLocal(xm,xd);
2012 else gGeoManager->MasterToLocalVect(xm,xd);
2013}
2014
2015//______________________________________________________________________________
2016void TFluka::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag)
2017{
2018// Transforms a position from the current volume reference frame
2019// to the world reference frame.
2020//
2021// Geant3 desription:
2022// ==================
2023// Computes coordinates XM (Master Reference System
2024// knowing the coordinates XD (Detector Ref System)
2025// The local reference system can be initialized by
2026// - the tracking routines and GDTOM used in GUSTEP
2027// - a call to GSCMED(NLEVEL,NAMES,NUMBER)
2028// (inverse routine is GMTOD)
2029//
2030// If IFLAG=1 convert coordinates
2031// IFLAG=2 convert direction cosinus
2032//
2033// ---
2034 Double_t xmL[3], xdL[3];
2035 Int_t i;
2036 for (i=0;i<3;i++) xdL[i] = xd[i];
2037 if (iflag == 1) gGeoManager->LocalToMaster(xdL,xmL);
2038 else gGeoManager->LocalToMasterVect(xdL,xmL);
2039 for (i=0;i<3;i++) xm[i]=xmL[i];
2040}
2041
2042//______________________________________________________________________________
2043void TFluka::Gdtom(Double_t* xd, Double_t* xm, Int_t iflag)
2044{
2047b055 2045//
2046// See Gdtom(Float_t*, Float_t*, Int_t)
2047//
829fb838 2048 if (iflag == 1) gGeoManager->LocalToMaster(xd,xm);
2049 else gGeoManager->LocalToMasterVect(xd,xm);
2050}
2051
2052//______________________________________________________________________________
2053TObjArray *TFluka::GetFlukaMaterials()
2054{
2047b055 2055//
2056// Get array of Fluka materials
829fb838 2057 return fGeom->GetMatList();
2058}
2059
2060//______________________________________________________________________________
a9ea1616 2061void TFluka::SetMreg(Int_t l, Int_t lttc)
829fb838 2062{
2063// Set current fluka region
2064 fCurrentFlukaRegion = l;
a9ea1616 2065 fGeom->SetMreg(l,lttc);
829fb838 2066}
2067
2068
b496f27c 2069
2070
2071TString TFluka::ParticleName(Int_t pdg) const
2072{
2073 // Return particle name for particle with pdg code pdg.
2074 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2075 return TString((CHPPRP.btype[ifluka - kFLUKAcodemin]), 8);
b496f27c 2076}
2077
2078
2079Double_t TFluka::ParticleMass(Int_t pdg) const
2080{
2081 // Return particle mass for particle with pdg code pdg.
2082 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2083 return (PAPROP.am[ifluka - kFLUKAcodemin]);
2084}
2085
2086Double_t TFluka::ParticleMassFPC(Int_t fpc) const
2087{
2088 // Return particle mass for particle with Fluka particle code fpc
2089 return (PAPROP.am[fpc - kFLUKAcodemin]);
b496f27c 2090}
2091
2092Double_t TFluka::ParticleCharge(Int_t pdg) const
2093{
2094 // Return particle charge for particle with pdg code pdg.
2095 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2096 return Double_t(PAPROP.ichrge[ifluka - kFLUKAcodemin]);
b496f27c 2097}
2098
2099Double_t TFluka::ParticleLifeTime(Int_t pdg) const
2100{
2101 // Return particle lifetime for particle with pdg code pdg.
2102 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2103 return (PAPROP.tmnlf[ifluka - kFLUKAcodemin]);
b496f27c 2104}
2105
2106void TFluka::Gfpart(Int_t pdg, char* name, Int_t& type, Float_t& mass, Float_t& charge, Float_t& tlife)
2107{
2108 // Retrieve particle properties for particle with pdg code pdg.
2109
2110 strcpy(name, ParticleName(pdg).Data());
2111 type = ParticleMCType(pdg);
2112 mass = ParticleMass(pdg);
2113 charge = ParticleCharge(pdg);
2114 tlife = ParticleLifeTime(pdg);
2115}
2116
8e5bf079 2117void TFluka::PrintHeader()
2118{
2119 //
2120 // Print a header
2121 printf("\n");
2122 printf("\n");
2123 printf("------------------------------------------------------------------------------\n");
2124 printf("- You are using the TFluka Virtual Monte Carlo Interface to FLUKA. -\n");
2125 printf("- Please see the file fluka.out for FLUKA output and licensing information. -\n");
2126 printf("------------------------------------------------------------------------------\n");
2127 printf("\n");
2128 printf("\n");
2129}
2130
b496f27c 2131
81f1d030 2132#define pshckp pshckp_
2133#define ustckv ustckv_
3a625972 2134
2135
2136extern "C" {
81f1d030 2137 void pshckp(Double_t & px, Double_t & py, Double_t & pz, Double_t & e,
2138 Double_t & vx, Double_t & vy, Double_t & vz, Double_t & tof,
2139 Double_t & polx, Double_t & poly, Double_t & polz, Double_t & wgt, Int_t& ntr)
2140 {
2141 //
2142 // Pushes one cerenkov photon to the stack
2143 //
2144
2145 TFluka* fluka = (TFluka*) gMC;
2146 TVirtualMCStack* cppstack = fluka->GetStack();
2147 Int_t parent = TRACKR.ispusr[mkbmx2-1];
2148 cppstack->PushTrack(0, parent, 50000050,
2149 px, py, pz, e,
2150 vx, vy, vz, tof,
2151 polx, poly, polz,
2152 kPCerenkov, ntr, wgt, 0);
2153 }
2154
2155 void ustckv(Int_t & nphot, Int_t & mreg, Double_t & x, Double_t & y, Double_t & z)
7b203b6e 2156 {
2157 //
2158 // Calls stepping in order to signal cerenkov production
2159 //
2160 TFluka *fluka = (TFluka*)gMC;
a9ea1616 2161 fluka->SetMreg(mreg,LTCLCM.mlatm1);
7b203b6e 2162 fluka->SetXsco(x);
2163 fluka->SetYsco(y);
2164 fluka->SetZsco(z);
2165 fluka->SetNCerenkov(nphot);
a9ea1616 2166 fluka->SetCaller(kUSTCKV);
d59acfe7 2167 if (fluka->GetVerbosityLevel() >= 3)
7b203b6e 2168 (TVirtualMCApplication::Instance())->Stepping();
81f1d030 2169
7b203b6e 2170 }
3a625972 2171}
a9ea1616 2172
78df7be0 2173void TFluka::AddParticlesToPdgDataBase() const
2174{
2175
2176//
2177// Add particles to the PDG data base
2178
2179 TDatabasePDG *pdgDB = TDatabasePDG::Instance();
2180
2181 const Int_t kion=10000000;
2182
2183 const Double_t kAu2Gev = 0.9314943228;
2184 const Double_t khSlash = 1.0545726663e-27;
2185 const Double_t kErg2Gev = 1/1.6021773349e-3;
2186 const Double_t khShGev = khSlash*kErg2Gev;
2187 const Double_t kYear2Sec = 3600*24*365.25;
2188//
2189// Ions
2190//
2191
2192 pdgDB->AddParticle("Deuteron","Deuteron",2*kAu2Gev+8.071e-3,kTRUE,
2193 0,3,"Ion",kion+10020);
2194 pdgDB->AddParticle("Triton","Triton",3*kAu2Gev+14.931e-3,kFALSE,
2195 khShGev/(12.33*kYear2Sec),3,"Ion",kion+10030);
2196 pdgDB->AddParticle("Alpha","Alpha",4*kAu2Gev+2.424e-3,kTRUE,
2197 khShGev/(12.33*kYear2Sec),6,"Ion",kion+20040);
2198 pdgDB->AddParticle("HE3","HE3",3*kAu2Gev+14.931e-3,kFALSE,
2199 0,6,"Ion",kion+20030);
2200}
2201
f2a98602 2202 //
2203 // Info about primary ionization electrons
2204 Int_t TFluka::GetNPrimaryElectrons()
2205{
2206 // Get number of primary electrons
2207 return ALLDLT.nalldl;
2208}
2209
2210Double_t GetPrimaryElectronKineticEnergy(Int_t i)
2211{
f0734960 2212 Double_t ekin = -1.;
f2a98602 2213 // Returns kinetic energy of primary electron i
2214 if (i >= 0 && i < ALLDLT.nalldl) {
f0734960 2215 ekin = ALLDLT.talldl[i];
f2a98602 2216 } else {
2217 Warning("GetPrimaryElectronKineticEnergy",
2218 "Primary electron index out of range %d %d \n",
2219 i, ALLDLT.nalldl);
2220 }
f0734960 2221 return ekin;
f2a98602 2222}