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