Double_t version of SetCerenkov.
[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
209 delete fGeom;
210 delete fMCGeo;
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();
a9923346 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 ||
ea262cc6 654 strncmp(param, "RAYL", 4) == 0)
829fb838 655 {
656 process = kTRUE;
657 }
81f1d030 658
acf2e119 659 if (strncmp(param, "PRIMIO_N", 8) == 0 ||
660 strncmp(param, "PRIMIO_E", 8) == 0)
661 {
662 modelp = kTRUE;
663 }
664
829fb838 665 if (process) {
acf2e119 666 // Process switch
81f1d030 667 SetProcess(param, Int_t (parval), itmed);
acf2e119 668 } else if (modelp) {
669 // Model parameters
670 SetModelParameter(param, parval, itmed);
829fb838 671 } else {
acf2e119 672 // Cuts
81f1d030 673 SetCut(param, parval, itmed);
829fb838 674 }
acf2e119 675
676
829fb838 677}
678
679// functions from GGEOM
680//_____________________________________________________________________________
681void TFluka::Gsatt(const char *name, const char *att, Int_t val)
682{
6f5667d1 683 // Set visualisation attributes for one volume
829fb838 684 char vname[5];
685 fGeom->Vname(name,vname);
686 char vatt[5];
687 fGeom->Vname(att,vatt);
688 gGeoManager->SetVolumeAttribute(vname, vatt, val);
689}
690
691//______________________________________________________________________________
692Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
4aba9d66 693 Float_t *upar, Int_t np) {
829fb838 694//
695 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
696}
697
698//______________________________________________________________________________
699Int_t TFluka::Gsvolu(const char *name, const char *shape, Int_t nmed,
4aba9d66 700 Double_t *upar, Int_t np) {
829fb838 701//
702 return fMCGeo->Gsvolu(name, shape, nmed, upar, np);
703}
704
705//______________________________________________________________________________
706void TFluka::Gsdvn(const char *name, const char *mother, Int_t ndiv,
4aba9d66 707 Int_t iaxis) {
829fb838 708//
709 fMCGeo->Gsdvn(name, mother, ndiv, iaxis);
710}
711
712//______________________________________________________________________________
713void TFluka::Gsdvn2(const char *name, const char *mother, Int_t ndiv,
4aba9d66 714 Int_t iaxis, Double_t c0i, Int_t numed) {
829fb838 715//
716 fMCGeo->Gsdvn2(name, mother, ndiv, iaxis, c0i, numed);
717}
718
719//______________________________________________________________________________
720void TFluka::Gsdvt(const char *name, const char *mother, Double_t step,
4aba9d66 721 Int_t iaxis, Int_t numed, Int_t ndvmx) {
722//
829fb838 723 fMCGeo->Gsdvt(name, mother, step, iaxis, numed, ndvmx);
724}
725
726//______________________________________________________________________________
727void TFluka::Gsdvt2(const char *name, const char *mother, Double_t step,
4aba9d66 728 Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx) {
829fb838 729//
730 fMCGeo->Gsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
731}
732
733//______________________________________________________________________________
734void TFluka::Gsord(const char * /*name*/, Int_t /*iax*/) {
735//
736// Nothing to do with TGeo
737}
738
739//______________________________________________________________________________
740void TFluka::Gspos(const char *name, Int_t nr, const char *mother,
4aba9d66 741 Double_t x, Double_t y, Double_t z, Int_t irot,
742 const char *konly) {
829fb838 743//
744 fMCGeo->Gspos(name, nr, mother, x, y, z, irot, konly);
745}
746
747//______________________________________________________________________________
748void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
4aba9d66 749 Double_t x, Double_t y, Double_t z, Int_t irot,
750 const char *konly, Float_t *upar, Int_t np) {
829fb838 751 //
752 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
753}
754
755//______________________________________________________________________________
756void TFluka::Gsposp(const char *name, Int_t nr, const char *mother,
4aba9d66 757 Double_t x, Double_t y, Double_t z, Int_t irot,
758 const char *konly, Double_t *upar, Int_t np) {
829fb838 759 //
760 fMCGeo->Gsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
761}
762
763//______________________________________________________________________________
764void TFluka::Gsbool(const char* /*onlyVolName*/, const char* /*manyVolName*/) {
765//
766// Nothing to do with TGeo
767}
768
a9ea1616 769//______________________________________________________________________
770Bool_t TFluka::GetTransformation(const TString &volumePath,TGeoHMatrix &mat)
771{
772 // Returns the Transformation matrix between the volume specified
773 // by the path volumePath and the Top or mater volume. The format
774 // of the path volumePath is as follows (assuming ALIC is the Top volume)
775 // "/ALIC_1/DDIP_1/S05I_2/S05H_1/S05G_3". Here ALIC is the top most
776 // or master volume which has only 1 instance of. Of all of the daughter
777 // volumes of ALICE, DDIP volume copy #1 is indicated. Similarly for
778 // the daughter volume of DDIP is S05I copy #2 and so on.
779 // Inputs:
780 // TString& volumePath The volume path to the specific volume
781 // for which you want the matrix. Volume name
782 // hierarchy is separated by "/" while the
783 // copy number is appended using a "_".
784 // Outputs:
785 // TGeoHMatrix &mat A matrix with its values set to those
786 // appropriate to the Local to Master transformation
787 // Return:
788 // A logical value if kFALSE then an error occurred and no change to
789 // mat was made.
790
791 // We have to preserve the modeler state
792 return fMCGeo->GetTransformation(volumePath, mat);
793}
794
795//______________________________________________________________________
796Bool_t TFluka::GetShape(const TString &volumePath,TString &shapeType,
797 TArrayD &par)
798{
799 // Returns the shape and its parameters for the volume specified
800 // by volumeName.
801 // Inputs:
802 // TString& volumeName The volume name
803 // Outputs:
804 // TString &shapeType Shape type
805 // TArrayD &par A TArrayD of parameters with all of the
806 // parameters of the specified shape.
807 // Return:
808 // A logical indicating whether there was an error in getting this
809 // information
810 return fMCGeo->GetShape(volumePath, shapeType, par);
811}
812
813//______________________________________________________________________
814Bool_t TFluka::GetMaterial(const TString &volumeName,
815 TString &name,Int_t &imat,
816 Double_t &a,Double_t &z,Double_t &dens,
817 Double_t &radl,Double_t &inter,TArrayD &par)
818{
819 // Returns the Material and its parameters for the volume specified
820 // by volumeName.
821 // Note, Geant3 stores and uses mixtures as an element with an effective
822 // Z and A. Consequently, if the parameter Z is not integer, then
823 // this material represents some sort of mixture.
824 // Inputs:
825 // TString& volumeName The volume name
826 // Outputs:
827 // TSrting &name Material name
828 // Int_t &imat Material index number
829 // Double_t &a Average Atomic mass of material
830 // Double_t &z Average Atomic number of material
831 // Double_t &dens Density of material [g/cm^3]
832 // Double_t &radl Average radiation length of material [cm]
833 // Double_t &inter Average interaction length of material [cm]
834 // TArrayD &par A TArrayD of user defined parameters.
835 // Return:
836 // kTRUE if no errors
837 return fMCGeo->GetMaterial(volumeName,name,imat,a,z,dens,radl,inter,par);
838}
839
840//______________________________________________________________________
841Bool_t TFluka::GetMedium(const TString &volumeName,TString &name,
842 Int_t &imed,Int_t &nmat,Int_t &isvol,Int_t &ifield,
843 Double_t &fieldm,Double_t &tmaxfd,Double_t &stemax,
844 Double_t &deemax,Double_t &epsil, Double_t &stmin,
845 TArrayD &par)
846{
847 // Returns the Medium and its parameters for the volume specified
848 // by volumeName.
849 // Inputs:
850 // TString& volumeName The volume name.
851 // Outputs:
852 // TString &name Medium name
853 // Int_t &nmat Material number defined for this medium
854 // Int_t &imed The medium index number
855 // Int_t &isvol volume number defined for this medium
856 // Int_t &iflield Magnetic field flag
857 // Double_t &fieldm Magnetic field strength
858 // Double_t &tmaxfd Maximum angle of deflection per step
859 // Double_t &stemax Maximum step size
860 // Double_t &deemax Maximum fraction of energy allowed to be lost
861 // to continuous process.
862 // Double_t &epsil Boundary crossing precision
863 // Double_t &stmin Minimum step size allowed
864 // TArrayD &par A TArrayD of user parameters with all of the
865 // parameters of the specified medium.
866 // Return:
867 // kTRUE if there where no errors
868 return fMCGeo->GetMedium(volumeName,name,imed,nmat,isvol,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin,par);
869}
870
829fb838 871//______________________________________________________________________________
872void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
4aba9d66 873 Float_t* absco, Float_t* effic, Float_t* rindex) {
829fb838 874//
875// Set Cerenkov properties for medium itmed
876//
877// npckov: number of sampling points
878// ppckov: energy values
879// absco: absorption length
880// effic: quantum efficiency
881// rindex: refraction index
882//
883//
884//
885// Create object holding Cerenkov properties
b6a89226 886//
887
829fb838 888 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex);
889//
890// Pass object to medium
891 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
892 medium->SetCerenkovProperties(cerenkovProperties);
893}
894
b2be0e73 895void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Float_t* ppckov,
4aba9d66 896 Float_t* absco, Float_t* effic, Float_t* rindex, Float_t* rfl) {
b2be0e73 897//
898// Set Cerenkov properties for medium itmed
899//
900// npckov: number of sampling points
901// ppckov: energy values
902// absco: absorption length
903// effic: quantum efficiency
904// rindex: refraction index
905// rfl: reflectivity for boundary to medium itmed
906//
907//
908// Create object holding Cerenkov properties
909//
910 TFlukaCerenkov* cerenkovProperties = new TFlukaCerenkov(npckov, ppckov, absco, effic, rindex, rfl);
911//
912// Pass object to medium
913 TGeoMedium* medium = gGeoManager->GetMedium(itmed);
914 medium->SetCerenkovProperties(cerenkovProperties);
915}
916
917
829fb838 918//______________________________________________________________________________
b6a89226 919void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Double_t *ppckov,
920 Double_t *absco, Double_t *effic, Double_t *rindex) {
921//
922// Set Cerenkov properties for medium itmed
829fb838 923//
b6a89226 924// npckov: number of sampling points
925// ppckov: energy values
926// absco: absorption length
927// effic: quantum efficiency
928// rindex: refraction index
929//
930
931//
932// Double_t version
933 Float_t* fppckov = CreateFloatArray(ppckov, npckov);
934 Float_t* fabsco = CreateFloatArray(absco, npckov);
935 Float_t* feffic = CreateFloatArray(effic, npckov);
936 Float_t* frindex = CreateFloatArray(rindex, npckov);
937
938 SetCerenkov(itmed, npckov, fppckov, fabsco, feffic, frindex);
939
940 delete [] fppckov;
941 delete [] fabsco;
942 delete [] feffic;
943 delete [] frindex;
829fb838 944}
b2be0e73 945
b6a89226 946void TFluka::SetCerenkov(Int_t itmed, Int_t npckov, Double_t* ppckov,
947 Double_t* absco, Double_t* effic, Double_t* rindex, Double_t* rfl) {
b2be0e73 948//
b6a89226 949// Set Cerenkov properties for medium itmed
950//
951// npckov: number of sampling points
952// ppckov: energy values
953// absco: absorption length
954// effic: quantum efficiency
955// rindex: refraction index
956// rfl: reflectivity for boundary to medium itmed
957//
958
959//
960// // Double_t version
961 Float_t* fppckov = CreateFloatArray(ppckov, npckov);
962 Float_t* fabsco = CreateFloatArray(absco, npckov);
963 Float_t* feffic = CreateFloatArray(effic, npckov);
964 Float_t* frindex = CreateFloatArray(rindex, npckov);
965 Float_t* frfl = CreateFloatArray(rfl, npckov);
966
967 SetCerenkov(itmed, npckov, fppckov, fabsco, feffic, frindex, frfl);
968
969 delete [] fppckov;
970 delete [] fabsco;
971 delete [] feffic;
972 delete [] frindex;
973 delete [] frfl;
b2be0e73 974}
975
829fb838 976// Euclid
977//______________________________________________________________________________
978void TFluka::WriteEuclid(const char* /*fileName*/, const char* /*topVol*/,
979 Int_t /*number*/, Int_t /*nlevel*/) {
980//
981// Not with TGeo
a9ea1616 982 Warning("WriteEuclid", "Not implemented !");
829fb838 983}
984
985
986
987//_____________________________________________________________________________
988// methods needed by the stepping
989//____________________________________________________________________________
990
991Int_t TFluka::GetMedium() const {
992//
993// Get the medium number for the current fluka region
994//
995 return fGeom->GetMedium(); // this I need to check due to remapping !!!
996}
997
a9ea1616 998//____________________________________________________________________________
999Int_t TFluka::GetDummyRegion() const
1000{
1001// Returns index of the dummy region.
1002 return fGeom->GetDummyRegion();
1003}
829fb838 1004
a9ea1616 1005//____________________________________________________________________________
1006Int_t TFluka::GetDummyLattice() const
1007{
1008// Returns index of the dummy lattice.
1009 return fGeom->GetDummyLattice();
1010}
829fb838 1011
1012//____________________________________________________________________________
1013// particle table usage
1014// ID <--> PDG transformations
1015//_____________________________________________________________________________
1016Int_t TFluka::IdFromPDG(Int_t pdg) const
1017{
1018 //
1019 // Return Fluka code from PDG and pseudo ENDF code
1020
1021 // Catch the feedback photons
a9ea1616 1022 if (pdg == 50000051) return (kFLUKAoptical);
829fb838 1023 // MCIHAD() goes from pdg to fluka internal.
1024 Int_t intfluka = mcihad(pdg);
1025 // KPTOIP array goes from internal to official
1026 return GetFlukaKPTOIP(intfluka);
1027}
1028
1029//______________________________________________________________________________
1030Int_t TFluka::PDGFromId(Int_t id) const
1031{
1032 //
1033 // Return PDG code and pseudo ENDF code from Fluka code
f926898e 1034 // Alpha He3 Triton Deuteron gen. ion opt. photon
13858fbd 1035 Int_t idSpecial[6] = {GetIonPdg(2,4), GetIonPdg(2, 3), GetIonPdg(1,3), GetIonPdg(1,2), GetIonPdg(0,0), 50000050};
829fb838 1036 // IPTOKP array goes from official to internal
1037
a9ea1616 1038 if (id == kFLUKAoptical) {
829fb838 1039// Cerenkov photon
4aba9d66 1040// if (fVerbosityLevel >= 3)
1041// printf("\n PDGFromId: Cerenkov Photon \n");
1042 return 50000050;
829fb838 1043 }
1044// Error id
ece92b30 1045 if (id == 0 || id < kFLUKAcodemin || id > kFLUKAcodemax) {
66e5eb54 1046 if (fVerbosityLevel >= 3)
a9923346 1047 printf("PDGFromId: Error id = 0 %5d %5d\n", id, fCaller);
4aba9d66 1048 return -1;
829fb838 1049 }
1050// Good id
f926898e 1051 if (id > 0) {
4aba9d66 1052 Int_t intfluka = GetFlukaIPTOKP(id);
1053 if (intfluka == 0) {
1054 if (fVerbosityLevel >= 3)
1055 printf("PDGFromId: Error intfluka = 0: %d\n", id);
1056 return -1;
1057 } else if (intfluka < 0) {
1058 if (fVerbosityLevel >= 3)
1059 printf("PDGFromId: Error intfluka < 0: %d\n", id);
1060 return -1;
1061 }
1062// if (fVerbosityLevel >= 3)
1063// printf("mpdgha called with %d %d \n", id, intfluka);
1064 return mpdgha(intfluka);
f926898e 1065 } else {
4aba9d66 1066 // ions and optical photons
1067 return idSpecial[id - kFLUKAcodemin];
829fb838 1068 }
829fb838 1069}
1070
bd3d5c8a 1071void TFluka::StopTrack()
1072{
1073 // Set stopping conditions
1074 // Works for photons and charged particles
1075 fStopped = kTRUE;
1076}
1077
829fb838 1078//_____________________________________________________________________________
1079// methods for physics management
1080//____________________________________________________________________________
1081//
1082// set methods
1083//
1084
1df5fa54 1085void TFluka::SetProcess(const char* flagName, Int_t flagValue, Int_t imed)
829fb838 1086{
1087// Set process user flag for material imat
1088//
1df5fa54 1089//
1090// Update if already in the list
1091//
fb2cbbec 1092 TIter next(fUserConfig);
1df5fa54 1093 TFlukaConfigOption* proc;
1094 while((proc = (TFlukaConfigOption*)next()))
1095 {
4aba9d66 1096 if (proc->Medium() == imed) {
1097 proc->SetProcess(flagName, flagValue);
1098 return;
1099 }
1df5fa54 1100 }
fb2cbbec 1101 proc = new TFlukaConfigOption(imed);
1102 proc->SetProcess(flagName, flagValue);
1103 fUserConfig->Add(proc);
1104}
1105
1106//______________________________________________________________________________
1107Bool_t TFluka::SetProcess(const char* flagName, Int_t flagValue)
1108{
1109// Set process user flag
1df5fa54 1110//
1df5fa54 1111//
fb2cbbec 1112 SetProcess(flagName, flagValue, -1);
1df5fa54 1113 return kTRUE;
829fb838 1114}
1115
1116//______________________________________________________________________________
1117void TFluka::SetCut(const char* cutName, Double_t cutValue, Int_t imed)
1118{
1119// Set user cut value for material imed
1120//
fb2cbbec 1121 TIter next(fUserConfig);
1122 TFlukaConfigOption* proc;
1123 while((proc = (TFlukaConfigOption*)next()))
1124 {
4aba9d66 1125 if (proc->Medium() == imed) {
1126 proc->SetCut(cutName, cutValue);
1127 return;
1128 }
fb2cbbec 1129 }
1130
1131 proc = new TFlukaConfigOption(imed);
1132 proc->SetCut(cutName, cutValue);
1133 fUserConfig->Add(proc);
829fb838 1134}
1135
acf2e119 1136
1137//______________________________________________________________________________
1138void TFluka::SetModelParameter(const char* parName, Double_t parValue, Int_t imed)
1139{
1140// Set model parameter for material imed
1141//
1142 TIter next(fUserConfig);
1143 TFlukaConfigOption* proc;
1144 while((proc = (TFlukaConfigOption*)next()))
1145 {
4aba9d66 1146 if (proc->Medium() == imed) {
1147 proc->SetModelParameter(parName, parValue);
1148 return;
1149 }
acf2e119 1150 }
1151
1152 proc = new TFlukaConfigOption(imed);
1153 proc->SetModelParameter(parName, parValue);
1154 fUserConfig->Add(proc);
1155}
1156
829fb838 1157//______________________________________________________________________________
1158Bool_t TFluka::SetCut(const char* cutName, Double_t cutValue)
1159{
1160// Set user cut value
1161//
1df5fa54 1162//
fb2cbbec 1163 SetCut(cutName, cutValue, -1);
1164 return kTRUE;
829fb838 1165}
1166
f450e9d0 1167
6f1aaa8e 1168void TFluka::SetUserScoring(const char* option, const char* sdum, Int_t npr, char* outfile, Float_t* what)
b496f27c 1169{
1170//
f450e9d0 1171// Adds a user scoring option to the list
b496f27c 1172//
6f1aaa8e 1173 TFlukaScoringOption* opt = new TFlukaScoringOption(option, sdum, npr,outfile,what);
f450e9d0 1174 fUserScore->Add(opt);
1175}
1176//______________________________________________________________________________
6f1aaa8e 1177void TFluka::SetUserScoring(const char* option, const char* sdum, Int_t npr, char* outfile, Float_t* what,
1178 const char* det1, const char* det2, const char* det3)
f450e9d0 1179{
1180//
1181// Adds a user scoring option to the list
1182//
6f1aaa8e 1183 TFlukaScoringOption* opt = new TFlukaScoringOption(option, sdum, npr, outfile, what, det1, det2, det3);
b496f27c 1184 fUserScore->Add(opt);
1185}
b496f27c 1186
829fb838 1187//______________________________________________________________________________
1188Double_t TFluka::Xsec(char*, Double_t, Int_t, Int_t)
1189{
a9ea1616 1190 Warning("Xsec", "Not yet implemented.!\n"); return -1.;
829fb838 1191}
1192
1193
1194//______________________________________________________________________________
1195void TFluka::InitPhysics()
1196{
1197//
1198// Physics initialisation with preparation of FLUKA input cards
1199//
fb2cbbec 1200// Construct file names
1201 FILE *pFlukaVmcCoreInp, *pFlukaVmcFlukaMat, *pFlukaVmcInp;
1202 TString sFlukaVmcCoreInp = getenv("ALICE_ROOT");
1203 sFlukaVmcCoreInp +="/TFluka/input/";
1204 TString sFlukaVmcTmp = "flukaMat.inp";
1205 TString sFlukaVmcInp = GetInputFileName();
1206 sFlukaVmcCoreInp += GetCoreInputFileName();
1207
1208// Open files
1209 if ((pFlukaVmcCoreInp = fopen(sFlukaVmcCoreInp.Data(),"r")) == NULL) {
4aba9d66 1210 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcCoreInp.Data());
1211 exit(1);
fb2cbbec 1212 }
1213 if ((pFlukaVmcFlukaMat = fopen(sFlukaVmcTmp.Data(),"r")) == NULL) {
4aba9d66 1214 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcTmp.Data());
1215 exit(1);
fb2cbbec 1216 }
1217 if ((pFlukaVmcInp = fopen(sFlukaVmcInp.Data(),"w")) == NULL) {
4aba9d66 1218 Warning("InitPhysics", "\nCannot open file %s\n",sFlukaVmcInp.Data());
1219 exit(1);
fb2cbbec 1220 }
829fb838 1221
fb2cbbec 1222// Copy core input file
1223 Char_t sLine[255];
1224 Float_t fEventsPerRun;
829fb838 1225
fb2cbbec 1226 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
4aba9d66 1227 if (strncmp(sLine,"GEOEND",6) != 0)
1228 fprintf(pFlukaVmcInp,"%s",sLine); // copy until GEOEND card
1229 else {
1230 fprintf(pFlukaVmcInp,"GEOEND\n"); // add GEOEND card
1231 goto flukamat;
1232 }
fb2cbbec 1233 } // end of while until GEOEND card
1234
829fb838 1235
fb2cbbec 1236 flukamat:
1237 while ((fgets(sLine,255,pFlukaVmcFlukaMat)) != NULL) { // copy flukaMat.inp file
4aba9d66 1238 fprintf(pFlukaVmcInp,"%s\n",sLine);
fb2cbbec 1239 }
1240
1241 while ((fgets(sLine,255,pFlukaVmcCoreInp)) != NULL) {
8fc475a1 1242 if (strncmp(sLine,"START",5) != 0)
4aba9d66 1243 fprintf(pFlukaVmcInp,"%s\n",sLine);
1244 else {
1245 sscanf(sLine+10,"%10f",&fEventsPerRun);
1246 goto fin;
1247 }
8fc475a1 1248 } //end of while until START card
fb2cbbec 1249
1250 fin:
829fb838 1251
f450e9d0 1252
1253// Pass information to configuration objects
829fb838 1254
fb2cbbec 1255 Float_t fLastMaterial = fGeom->GetLastMaterialIndex();
1256 TFlukaConfigOption::SetStaticInfo(pFlukaVmcInp, 3, fLastMaterial, fGeom);
1257
1258 TIter next(fUserConfig);
1259 TFlukaConfigOption* proc;
f450e9d0 1260 while((proc = dynamic_cast<TFlukaConfigOption*> (next()))) proc->WriteFlukaInputCards();
1261//
1262// Process Fluka specific scoring options
1263//
1264 TFlukaScoringOption::SetStaticInfo(pFlukaVmcInp, fGeom);
0bb2c369 1265 Float_t loginp = -49.0;
f450e9d0 1266 Int_t inp = 0;
1267 Int_t nscore = fUserScore->GetEntries();
1268
a9ea1616 1269 TFlukaScoringOption *mopo = 0;
1270 TFlukaScoringOption *mopi = 0;
fb2cbbec 1271
f450e9d0 1272 for (Int_t isc = 0; isc < nscore; isc++)
1273 {
4aba9d66 1274 mopo = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isc));
1275 char* fileName = mopo->GetFileName();
1276 Int_t size = strlen(fileName);
1277 Float_t lun = -1.;
f450e9d0 1278//
1279// Check if new output file has to be opened
4aba9d66 1280 for (Int_t isci = 0; isci < isc; isci++) {
1281
1282
1283 mopi = dynamic_cast<TFlukaScoringOption*> (fUserScore->At(isci));
1284 if(strncmp(mopi->GetFileName(), fileName, size)==0) {
1285 //
1286 // No, the file already exists
1287 lun = mopi->GetLun();
1288 mopo->SetLun(lun);
1289 break;
1290 }
1291 } // inner loop
1292
1293 if (lun == -1.) {
1294 // Open new output file
1295 inp++;
1296 mopo->SetLun(loginp + inp);
1297 mopo->WriteOpenFlukaFile();
1298 }
1299 mopo->WriteFlukaInputCards();
f450e9d0 1300 }
b8a8a88c 1301
1302// Add RANDOMIZ card
1303 fprintf(pFlukaVmcInp,"RANDOMIZ %10.1f%10.0f\n", 1., Float_t(gRandom->GetSeed()));
8fc475a1 1304// Add START and STOP card
1305 fprintf(pFlukaVmcInp,"START %10.1f\n",fEventsPerRun);
f450e9d0 1306 fprintf(pFlukaVmcInp,"STOP \n");
829fb838 1307
1308
1309// Close files
3b8c325d 1310 fclose(pFlukaVmcCoreInp);
1311 fclose(pFlukaVmcFlukaMat);
1312 fclose(pFlukaVmcInp);
fb2cbbec 1313
1314
1315//
1316// Initialisation needed for Cerenkov photon production and transport
1317 TObjArray *matList = GetFlukaMaterials();
1318 Int_t nmaterial = matList->GetEntriesFast();
9968e86c 1319 fMaterials = new Int_t[nmaterial+25];
fb2cbbec 1320
1321 for (Int_t im = 0; im < nmaterial; im++)
1322 {
4aba9d66 1323 TGeoMaterial* material = dynamic_cast<TGeoMaterial*> (matList->At(im));
1324 Int_t idmat = material->GetIndex();
1325 fMaterials[idmat] = im;
fb2cbbec 1326 }
829fb838 1327} // end of InitPhysics
1328
1329
1330//______________________________________________________________________________
07f5b33e 1331void TFluka::SetMaxStep(Double_t step)
829fb838 1332{
07f5b33e 1333// Set the maximum step size
4aba9d66 1334// if (step > 1.e4) return;
07f5b33e 1335
4aba9d66 1336// Int_t mreg=0, latt=0;
1337// fGeom->GetCurrentRegion(mreg, latt);
1338 Int_t mreg = fGeom->GetCurrentRegion();
9c0c08ce 1339 STEPSZ.stepmx[mreg - 1] = step;
829fb838 1340}
1341
2f09b80e 1342
1343Double_t TFluka::MaxStep() const
1344{
1345// Return the maximum for current medium
1346 Int_t mreg, latt;
1347 fGeom->GetCurrentRegion(mreg, latt);
1348 return (STEPSZ.stepmx[mreg - 1]);
1349}
1350
829fb838 1351//______________________________________________________________________________
1352void TFluka::SetMaxNStep(Int_t)
1353{
1354// SetMaxNStep is dummy procedure in TFluka !
1355 if (fVerbosityLevel >=3)
1356 cout << "SetMaxNStep is dummy procedure in TFluka !" << endl;
1357}
1358
1359//______________________________________________________________________________
1360void TFluka::SetUserDecay(Int_t)
1361{
1362// SetUserDecay is dummy procedure in TFluka !
1363 if (fVerbosityLevel >=3)
1364 cout << "SetUserDecay is dummy procedure in TFluka !" << endl;
1365}
1366
1367//
1368// dynamic properties
1369//
1370//______________________________________________________________________________
1371void TFluka::TrackPosition(TLorentzVector& position) const
1372{
1373// Return the current position in the master reference frame of the
1374// track being transported
1375// TRACKR.atrack = age of the particle
1376// TRACKR.xtrack = x-position of the last point
1377// TRACKR.ytrack = y-position of the last point
1378// TRACKR.ztrack = z-position of the last point
a9ea1616 1379 FlukaCallerCode_t caller = GetCaller();
1380 if (caller == kENDRAW || caller == kUSDRAW ||
1381 caller == kBXExiting || caller == kBXEntering ||
1382 caller == kUSTCKV) {
42b936d1 1383 position.SetX(GetXsco());
1384 position.SetY(GetYsco());
1385 position.SetZ(GetZsco());
1386 position.SetT(TRACKR.atrack);
829fb838 1387 }
5125d6e5 1388 else if (caller == kMGDRAW) {
1389 Int_t i = -1;
1390 if ((i = fPrimaryElectronIndex) > -1) {
1391 // Primary Electron Ionisation
1392 Double_t x, y, z;
1393 GetPrimaryElectronPosition(i, x, y, z);
1394 position.SetX(x);
1395 position.SetY(y);
1396 position.SetZ(z);
1397 position.SetT(TRACKR.atrack);
1398 } else {
1399 position.SetX(TRACKR.xtrack[TRACKR.ntrack]);
1400 position.SetY(TRACKR.ytrack[TRACKR.ntrack]);
1401 position.SetZ(TRACKR.ztrack[TRACKR.ntrack]);
1402 position.SetT(TRACKR.atrack);
1403 }
829fb838 1404 }
a9ea1616 1405 else if (caller == kSODRAW) {
42b936d1 1406 Int_t ist = FLKSTK.npflka;
1407 position.SetX(FLKSTK.xflk[ist]);
1408 position.SetY(FLKSTK.yflk[ist]);
1409 position.SetZ(FLKSTK.zflk[ist]);
1410 position.SetT(FLKSTK.agestk[ist]);
a9ea1616 1411 } else if (caller == kMGResumedTrack) {
42b936d1 1412 position.SetX(TRACKR.spausr[0]);
1413 position.SetY(TRACKR.spausr[1]);
1414 position.SetZ(TRACKR.spausr[2]);
1415 position.SetT(TRACKR.spausr[3]);
829fb838 1416 }
1417 else
42b936d1 1418 Warning("TrackPosition","position not available");
829fb838 1419}
1420
1421//______________________________________________________________________________
1422void TFluka::TrackPosition(Double_t& x, Double_t& y, Double_t& z) const
1423{
1424// Return the current position in the master reference frame of the
1425// track being transported
1426// TRACKR.atrack = age of the particle
1427// TRACKR.xtrack = x-position of the last point
1428// TRACKR.ytrack = y-position of the last point
1429// TRACKR.ztrack = z-position of the last point
a9ea1616 1430 FlukaCallerCode_t caller = GetCaller();
1431 if (caller == kENDRAW || caller == kUSDRAW ||
1432 caller == kBXExiting || caller == kBXEntering ||
1433 caller == kUSTCKV) {
5125d6e5 1434 x = GetXsco();
1435 y = GetYsco();
1436 z = GetZsco();
829fb838 1437 }
42b936d1 1438 else if (caller == kMGDRAW) {
5125d6e5 1439 Int_t i = -1;
1440 if ((i = fPrimaryElectronIndex) > -1) {
1441 GetPrimaryElectronPosition(i, x, y, z);
1442 } else {
1443 x = TRACKR.xtrack[TRACKR.ntrack];
1444 y = TRACKR.ytrack[TRACKR.ntrack];
1445 z = TRACKR.ztrack[TRACKR.ntrack];
1446 }
829fb838 1447 }
42b936d1 1448 else if (caller == kSODRAW) {
1449 Int_t ist = FLKSTK.npflka;
1450 x = FLKSTK.xflk[ist];
1451 y = FLKSTK.yflk[ist];
1452 z = FLKSTK.zflk[ist];
1453 }
a9ea1616 1454 else if (caller == kMGResumedTrack) {
42b936d1 1455 x = TRACKR.spausr[0];
1456 y = TRACKR.spausr[1];
1457 z = TRACKR.spausr[2];
5d80a015 1458 }
829fb838 1459 else
42b936d1 1460 Warning("TrackPosition","position not available");
829fb838 1461}
1462
1463//______________________________________________________________________________
1464void TFluka::TrackMomentum(TLorentzVector& momentum) const
1465{
1466// Return the direction and the momentum (GeV/c) of the track
1467// currently being transported
1468// TRACKR.ptrack = momentum of the particle (not always defined, if
1469// < 0 must be obtained from etrack)
1470// TRACKR.cx,y,ztrck = direction cosines of the current particle
1471// TRACKR.etrack = total energy of the particle
1472// TRACKR.jtrack = identity number of the particle
1473// PAPROP.am[TRACKR.jtrack] = particle mass in gev
a9ea1616 1474 FlukaCallerCode_t caller = GetCaller();
1475 FlukaProcessCode_t icode = GetIcode();
1476
82a3f706 1477 if (caller != kEEDRAW &&
1478 caller != kMGResumedTrack &&
1479 caller != kSODRAW &&
1480 caller != kUSDRAW &&
a9ea1616 1481 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
42b936d1 1482 if (TRACKR.ptrack >= 0) {
1483 momentum.SetPx(TRACKR.ptrack*TRACKR.cxtrck);
1484 momentum.SetPy(TRACKR.ptrack*TRACKR.cytrck);
1485 momentum.SetPz(TRACKR.ptrack*TRACKR.cztrck);
1486 momentum.SetE(TRACKR.etrack);
1487 return;
1488 }
1489 else {
1490 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
1491 momentum.SetPx(p*TRACKR.cxtrck);
1492 momentum.SetPy(p*TRACKR.cytrck);
1493 momentum.SetPz(p*TRACKR.cztrck);
1494 momentum.SetE(TRACKR.etrack);
1495 return;
1496 }
a9ea1616 1497 } else if (caller == kMGResumedTrack) {
42b936d1 1498 momentum.SetPx(TRACKR.spausr[4]);
1499 momentum.SetPy(TRACKR.spausr[5]);
1500 momentum.SetPz(TRACKR.spausr[6]);
1501 momentum.SetE (TRACKR.spausr[7]);
1502 return;
a9ea1616 1503 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1504 momentum.SetPx(0.);
1505 momentum.SetPy(0.);
1506 momentum.SetPz(0.);
1507 momentum.SetE(TrackMass());
42b936d1 1508
1509 } else if (caller == kSODRAW) {
1510 Int_t ist = FLKSTK.npflka;
1511 Double_t p = FLKSTK.pmoflk[ist];
1512 Int_t ifl = FLKSTK.iloflk[ist];
1513 Double_t m = PAPROP.am[ifl + 6];
1514 Double_t e = TMath::Sqrt(p * p + m * m);
1515 momentum.SetPx(p * FLKSTK.txflk[ist]);
1516 momentum.SetPy(p * FLKSTK.tyflk[ist]);
1517 momentum.SetPz(p * FLKSTK.tzflk[ist]);
1518 momentum.SetE(e);
82a3f706 1519 } else if (caller == kUSDRAW) {
1520 if (icode == 208 || icode == 210 || icode == 212 || icode == 219) {
1521 momentum.SetPx(fPint[0]);
1522 momentum.SetPy(fPint[1]);
1523 momentum.SetPz(fPint[2]);
1524 momentum.SetE(fPint[3]);
1525 } else {
1526 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
1527 momentum.SetPx(p*TRACKR.cxtrck);
1528 momentum.SetPy(p*TRACKR.cytrck);
1529 momentum.SetPz(p*TRACKR.cztrck);
1530 momentum.SetE(TRACKR.etrack);
1531 }
829fb838 1532 }
1533 else
1534 Warning("TrackMomentum","momentum not available");
1535}
1536
1537//______________________________________________________________________________
1538void TFluka::TrackMomentum(Double_t& px, Double_t& py, Double_t& pz, Double_t& e) const
1539{
1540// Return the direction and the momentum (GeV/c) of the track
1541// currently being transported
1542// TRACKR.ptrack = momentum of the particle (not always defined, if
1543// < 0 must be obtained from etrack)
1544// TRACKR.cx,y,ztrck = direction cosines of the current particle
1545// TRACKR.etrack = total energy of the particle
1546// TRACKR.jtrack = identity number of the particle
1547// PAPROP.am[TRACKR.jtrack] = particle mass in gev
a9ea1616 1548 FlukaCallerCode_t caller = GetCaller();
1549 FlukaProcessCode_t icode = GetIcode();
42b936d1 1550 if (caller != kEEDRAW &&
1551 caller != kMGResumedTrack &&
1552 caller != kSODRAW &&
82a3f706 1553 caller != kUSDRAW &&
a9ea1616 1554 (caller != kENDRAW || (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2))) {
829fb838 1555 if (TRACKR.ptrack >= 0) {
1556 px = TRACKR.ptrack*TRACKR.cxtrck;
1557 py = TRACKR.ptrack*TRACKR.cytrck;
1558 pz = TRACKR.ptrack*TRACKR.cztrck;
a9ea1616 1559 e = TRACKR.etrack;
829fb838 1560 return;
1561 }
1562 else {
ece92b30 1563 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
829fb838 1564 px = p*TRACKR.cxtrck;
1565 py = p*TRACKR.cytrck;
1566 pz = p*TRACKR.cztrck;
a9ea1616 1567 e = TRACKR.etrack;
829fb838 1568 return;
1569 }
a9ea1616 1570 } else if (caller == kMGResumedTrack) {
5d80a015 1571 px = TRACKR.spausr[4];
1572 py = TRACKR.spausr[5];
1573 pz = TRACKR.spausr[6];
1574 e = TRACKR.spausr[7];
0773d0ac 1575 return;
a9ea1616 1576 } else if (caller == kENDRAW && (icode == kEMFSCOstopping1 || icode == kEMFSCOstopping2)) {
1577 px = 0.;
1578 py = 0.;
1579 pz = 0.;
1580 e = TrackMass();
42b936d1 1581 } else if (caller == kSODRAW) {
1582 Int_t ist = FLKSTK.npflka;
1583 Double_t p = FLKSTK.pmoflk[ist];
1584 Int_t ifl = FLKSTK.iloflk[ist];
1585 Double_t m = PAPROP.am[ifl + 6];
1586 e = TMath::Sqrt(p * p + m * m);
1587 px = p * FLKSTK.txflk[ist];
1588 py = p * FLKSTK.tyflk[ist];
1589 pz = p * FLKSTK.tzflk[ist];
82a3f706 1590 } else if (caller == kUSDRAW) {
1591 if (icode == 208 || icode == 210 || icode == 212 || icode == 219) {
1592 px = fPint[0];
1593 py = fPint[1];
1594 pz = fPint[2];
1595 e = fPint[3];
1596 } else {
1597 Double_t p = sqrt(TRACKR.etrack * TRACKR.etrack - ParticleMassFPC(TRACKR.jtrack) * ParticleMassFPC(TRACKR.jtrack));
1598 px = p*TRACKR.cxtrck;
1599 py = p*TRACKR.cytrck;
1600 pz = p*TRACKR.cztrck;
1601 e = TRACKR.etrack;
1602 }
829fb838 1603 }
1604 else
42b936d1 1605 Warning("TrackMomentum","momentum not available");
829fb838 1606}
1607
1608//______________________________________________________________________________
1609Double_t TFluka::TrackStep() const
1610{
1611// Return the length in centimeters of the current step
1612// TRACKR.ctrack = total curved path
42b936d1 1613 FlukaCallerCode_t caller = GetCaller();
1614 if (caller == kBXEntering || caller == kBXExiting ||
1615 caller == kENDRAW || caller == kUSDRAW ||
1616 caller == kUSTCKV || caller == kMGResumedTrack ||
1617 caller == kSODRAW)
1618 return 0.0;
a9ea1616 1619 else if (caller == kMGDRAW)
829fb838 1620 return TRACKR.ctrack;
669cede4 1621 else {
1622 Warning("TrackStep", "track step not available");
1623 return 0.0;
1624 }
829fb838 1625}
1626
1627//______________________________________________________________________________
1628Double_t TFluka::TrackLength() const
1629{
1630// TRACKR.cmtrck = cumulative curved path since particle birth
a9ea1616 1631 FlukaCallerCode_t caller = GetCaller();
1632 if (caller == kBXEntering || caller == kBXExiting ||
1633 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1634 caller == kUSTCKV)
829fb838 1635 return TRACKR.cmtrck;
a9ea1616 1636 else if (caller == kMGResumedTrack)
5d80a015 1637 return TRACKR.spausr[8];
82a3f706 1638 else if (caller == kSODRAW)
1639 return 0.0;
669cede4 1640 else {
82a3f706 1641 Warning("TrackLength", "track length not available for caller %5d \n", caller);
669cede4 1642 return 0.0;
1643 }
829fb838 1644}
1645
1646//______________________________________________________________________________
1647Double_t TFluka::TrackTime() const
1648{
1649// Return the current time of flight of the track being transported
1650// TRACKR.atrack = age of the particle
a9ea1616 1651 FlukaCallerCode_t caller = GetCaller();
1652 if (caller == kBXEntering || caller == kBXExiting ||
1653 caller == kENDRAW || caller == kUSDRAW || caller == kMGDRAW ||
1654 caller == kUSTCKV)
829fb838 1655 return TRACKR.atrack;
a9ea1616 1656 else if (caller == kMGResumedTrack)
5d80a015 1657 return TRACKR.spausr[3];
42b936d1 1658 else if (caller == kSODRAW) {
1659 return (FLKSTK.agestk[FLKSTK.npflka]);
1660 }
669cede4 1661 else {
1662 Warning("TrackTime", "track time not available");
1663 return 0.0;
1664 }
829fb838 1665}
1666
1667//______________________________________________________________________________
1668Double_t TFluka::Edep() const
1669{
1670// Energy deposition
1671// if TRACKR.ntrack = 0, TRACKR.mtrack = 0:
1672// -->local energy deposition (the value and the point are not recorded in TRACKR)
1673// but in the variable "rull" of the procedure "endraw.cxx"
1674// if TRACKR.ntrack > 0, TRACKR.mtrack = 0:
1675// -->no energy loss along the track
1676// if TRACKR.ntrack > 0, TRACKR.mtrack > 0:
1677// -->energy loss distributed along the track
07f5b33e 1678// TRACKR.dtrack = energy deposition of the jth deposition event
829fb838 1679
1680 // If coming from bxdraw we have 2 steps of 0 length and 0 edep
669cede4 1681 // If coming from usdraw we just signal particle production - no edep
1682 // If just first time after resuming, no edep for the primary
a9ea1616 1683 FlukaCallerCode_t caller = GetCaller();
ada781c7 1684
a9ea1616 1685 if (caller == kBXExiting || caller == kBXEntering ||
42b936d1 1686 caller == kUSDRAW || caller == kMGResumedTrack ||
1687 caller == kSODRAW)
1688 return 0.0;
829fb838 1689 Double_t sum = 0;
5125d6e5 1690 Int_t i = -1;
09cdde8a 1691
ada781c7 1692 // Material with primary ionisation activated but number of primary electrons nprim = 0
1693 if (fPrimaryElectronIndex == -2) return 0.0;
1694 // nprim > 0
5125d6e5 1695 if ((i = fPrimaryElectronIndex) > -1) {
1696 // Primary ionisation
ada781c7 1697 sum = GetPrimaryElectronKineticEnergy(i);
1698 if (sum > 100.) {
1699 printf("edep > 100. %d %d %f \n", i, ALLDLT.nalldl, sum);
1700 }
1701 return sum;
5125d6e5 1702 } else {
1703 // Normal ionisation
1704 if (TRACKR.mtrack > 1) printf("Edep: %6d\n", TRACKR.mtrack);
1705
1706 for ( Int_t j=0;j<TRACKR.mtrack;j++) {
1707 sum +=TRACKR.dtrack[j];
1708 }
1709 if (TRACKR.ntrack == 0 && TRACKR.mtrack == 0)
1710 return fRull + sum;
1711 else {
1712 return sum;
1713 }
829fb838 1714 }
1715}
1716
1717//______________________________________________________________________________
18e0cabb 1718Int_t TFluka::CorrectFlukaId() const
1719{
1720 // since we don't put photons and e- created bellow transport cut on the vmc stack
1721 // and there is a call to endraw for energy deposition for each of them
1722 // and they have the track number of their parent, but different identity (pdg)
4aba9d66 1723 // so we want to assign also their parent identity.
cc7af78a 1724
a9923346 1725 if( (IsTrackStop())
18e0cabb 1726 && TRACKR.ispusr[mkbmx2 - 4] == TRACKR.ispusr[mkbmx2 - 1]
1727 && TRACKR.jtrack != TRACKR.ispusr[mkbmx2 - 3] ) {
1728 if (fVerbosityLevel >=3)
1729 cout << "CorrectFlukaId() for icode=" << GetIcode()
1730 << " track=" << TRACKR.ispusr[mkbmx2 - 1]
1731 << " current PDG=" << PDGFromId(TRACKR.jtrack)
1732 << " assign parent PDG=" << PDGFromId(TRACKR.ispusr[mkbmx2 - 3]) << endl;
1733 return TRACKR.ispusr[mkbmx2 - 3]; // assign parent identity
1734 }
13858fbd 1735 if (TRACKR.jtrack <= 64){
cc7af78a 1736 return TRACKR.jtrack;
1737 } else {
1738 return TRACKR.j0trck;
1739 }
18e0cabb 1740}
1741
1742
1743//______________________________________________________________________________
829fb838 1744Int_t TFluka::TrackPid() const
1745{
1746// Return the id of the particle transported
1747// TRACKR.jtrack = identity number of the particle
a9ea1616 1748 FlukaCallerCode_t caller = GetCaller();
42b936d1 1749 if (caller != kEEDRAW && caller != kSODRAW) {
18e0cabb 1750 return PDGFromId( CorrectFlukaId() );
f926898e 1751 }
42b936d1 1752 else if (caller == kSODRAW) {
1753 return PDGFromId(FLKSTK.iloflk[FLKSTK.npflka]);
1754 }
829fb838 1755 else
1756 return -1000;
1757}
1758
1759//______________________________________________________________________________
1760Double_t TFluka::TrackCharge() const
1761{
1762// Return charge of the track currently transported
1763// PAPROP.ichrge = electric charge of the particle
1764// TRACKR.jtrack = identity number of the particle
13858fbd 1765
a9ea1616 1766 FlukaCallerCode_t caller = GetCaller();
42b936d1 1767 if (caller != kEEDRAW && caller != kSODRAW)
1768 return PAPROP.ichrge[CorrectFlukaId() + 6];
1769 else if (caller == kSODRAW) {
1770 Int_t ifl = PDGFromId(FLKSTK.iloflk[FLKSTK.npflka]);
1771 return PAPROP.ichrge[ifl + 6];
1772 }
829fb838 1773 else
1774 return -1000.0;
1775}
1776
1777//______________________________________________________________________________
1778Double_t TFluka::TrackMass() const
1779{
1780// PAPROP.am = particle mass in GeV
1781// TRACKR.jtrack = identity number of the particle
a9ea1616 1782 FlukaCallerCode_t caller = GetCaller();
42b936d1 1783 if (caller != kEEDRAW && caller != kSODRAW)
18e0cabb 1784 return PAPROP.am[CorrectFlukaId()+6];
42b936d1 1785 else if (caller == kSODRAW) {
82a3f706 1786 Int_t ifl = FLKSTK.iloflk[FLKSTK.npflka];
42b936d1 1787 return PAPROP.am[ifl + 6];
1788 }
829fb838 1789 else
1790 return -1000.0;
1791}
1792
1793//______________________________________________________________________________
1794Double_t TFluka::Etot() const
1795{
1796// TRACKR.etrack = total energy of the particle
a9ea1616 1797 FlukaCallerCode_t caller = GetCaller();
42b936d1 1798 if (caller != kEEDRAW && caller != kSODRAW)
829fb838 1799 return TRACKR.etrack;
42b936d1 1800 else if (caller == kSODRAW) {
1801 Int_t ist = FLKSTK.npflka;
1802 Double_t p = FLKSTK.pmoflk[ist];
1803 Int_t ifl = FLKSTK.iloflk[ist];
1804 Double_t m = PAPROP.am[ifl + 6];
1805 Double_t e = TMath::Sqrt(p * p + m * m);
1806 return e;
1807 }
829fb838 1808 else
1809 return -1000.0;
1810}
1811
1812//
1813// track status
1814//
1815//______________________________________________________________________________
1816Bool_t TFluka::IsNewTrack() const
1817{
1818// Return true for the first call of Stepping()
1819 return fTrackIsNew;
1820}
1821
0dabe425 1822void TFluka::SetTrackIsNew(Bool_t flag)
1823{
1824// Return true for the first call of Stepping()
1825 fTrackIsNew = flag;
1826
1827}
1828
1829
829fb838 1830//______________________________________________________________________________
1831Bool_t TFluka::IsTrackInside() const
1832{
1833// True if the track is not at the boundary of the current volume
1834// In Fluka a step is always inside one kind of material
1835// If the step would go behind the region of one material,
1836// it will be shortened to reach only the boundary.
1837// Therefore IsTrackInside() is always true.
a9ea1616 1838 FlukaCallerCode_t caller = GetCaller();
1839 if (caller == kBXEntering || caller == kBXExiting)
829fb838 1840 return 0;
1841 else
1842 return 1;
1843}
1844
1845//______________________________________________________________________________
1846Bool_t TFluka::IsTrackEntering() const
1847{
1848// True if this is the first step of the track in the current volume
1849
a9ea1616 1850 FlukaCallerCode_t caller = GetCaller();
1851 if (caller == kBXEntering)
829fb838 1852 return 1;
1853 else return 0;
1854}
1855
1856//______________________________________________________________________________
1857Bool_t TFluka::IsTrackExiting() const
1858{
1859// True if track is exiting volume
1860//
a9ea1616 1861 FlukaCallerCode_t caller = GetCaller();
1862 if (caller == kBXExiting)
829fb838 1863 return 1;
1864 else return 0;
1865}
1866
1867//______________________________________________________________________________
1868Bool_t TFluka::IsTrackOut() const
1869{
1870// True if the track is out of the setup
1871// means escape
a9ea1616 1872 FlukaProcessCode_t icode = GetIcode();
1873
1874 if (icode == kKASKADescape ||
1875 icode == kEMFSCOescape ||
1876 icode == kKASNEUescape ||
1877 icode == kKASHEAescape ||
1878 icode == kKASOPHescape)
1879 return 1;
829fb838 1880 else return 0;
1881}
1882
1883//______________________________________________________________________________
1884Bool_t TFluka::IsTrackDisappeared() const
1885{
a9ea1616 1886// All inelastic interactions and decays
829fb838 1887// fIcode from usdraw
a9ea1616 1888 FlukaProcessCode_t icode = GetIcode();
1889 if (icode == kKASKADinelint || // inelastic interaction
1890 icode == kKASKADdecay || // particle decay
1891 icode == kKASKADdray || // delta ray generation by hadron
1892 icode == kKASKADpair || // direct pair production
1893 icode == kKASKADbrems || // bremsstrahlung (muon)
1894 icode == kEMFSCObrems || // bremsstrahlung (electron)
1895 icode == kEMFSCOmoller || // Moller scattering
1896 icode == kEMFSCObhabha || // Bhaba scattering
1897 icode == kEMFSCOanniflight || // in-flight annihilation
1898 icode == kEMFSCOannirest || // annihilation at rest
1899 icode == kEMFSCOpair || // pair production
1900 icode == kEMFSCOcompton || // Compton scattering
1901 icode == kEMFSCOphotoel || // Photoelectric effect
1902 icode == kKASNEUhadronic || // hadronic interaction
2047b055 1903 icode == kKASHEAdray // delta-ray
0dabe425 1904 ) return 1;
829fb838 1905 else return 0;
1906}
1907
1908//______________________________________________________________________________
1909Bool_t TFluka::IsTrackStop() const
1910{
1911// True if the track energy has fallen below the threshold
1912// means stopped by signal or below energy threshold
a9ea1616 1913 FlukaProcessCode_t icode = GetIcode();
18e0cabb 1914 if (icode == kKASKADstopping || // stopping particle
1915 icode == kKASKADtimekill || // time kill
1916 icode == kEMFSCOstopping1 || // below user-defined cut-off
1917 icode == kEMFSCOstopping2 || // below user cut-off
1918 icode == kEMFSCOtimekill || // time kill
1919 icode == kKASNEUstopping || // neutron below threshold
1920 icode == kKASNEUtimekill || // time kill
1921 icode == kKASHEAtimekill || // time kill
1922 icode == kKASOPHtimekill) return 1; // time kill
829fb838 1923 else return 0;
1924}
1925
1926//______________________________________________________________________________
1927Bool_t TFluka::IsTrackAlive() const
1928{
1929// means not disappeared or not out
ea262cc6 1930 if (IsTrackDisappeared() || IsTrackOut() ) return 0;
1931 else return 1;
829fb838 1932}
1933
1934//
1935// secondaries
1936//
1937
1938//______________________________________________________________________________
1939Int_t TFluka::NSecondaries() const
1940
1941{
1942// Number of secondary particles generated in the current step
81f1d030 1943// GENSTK.np = number of secondaries except light and heavy ions
829fb838 1944// FHEAVY.npheav = number of secondaries for light and heavy secondary ions
a9ea1616 1945 FlukaCallerCode_t caller = GetCaller();
1946 if (caller == kUSDRAW) // valid only after usdraw
4aba9d66 1947 return GENSTK.np + FHEAVY.npheav;
a9ea1616 1948 else if (caller == kUSTCKV) {
4aba9d66 1949 // Cerenkov Photon production
1950 return fNCerenkov;
7b203b6e 1951 }
829fb838 1952 return 0;
1953} // end of NSecondaries
1954
1955//______________________________________________________________________________
1956void TFluka::GetSecondary(Int_t isec, Int_t& particleId,
4aba9d66 1957 TLorentzVector& position, TLorentzVector& momentum)
829fb838 1958{
1959// Copy particles from secondary stack to vmc stack
1960//
1961
a9ea1616 1962 FlukaCallerCode_t caller = GetCaller();
1963 if (caller == kUSDRAW) { // valid only after usdraw
4aba9d66 1964 if (GENSTK.np > 0) {
1965 // Hadronic interaction
1966 if (isec >= 0 && isec < GENSTK.np) {
1967 particleId = PDGFromId(GENSTK.kpart[isec]);
1968 position.SetX(fXsco);
1969 position.SetY(fYsco);
1970 position.SetZ(fZsco);
1971 position.SetT(TRACKR.atrack);
1972 momentum.SetPx(GENSTK.plr[isec]*GENSTK.cxr[isec]);
1973 momentum.SetPy(GENSTK.plr[isec]*GENSTK.cyr[isec]);
1974 momentum.SetPz(GENSTK.plr[isec]*GENSTK.czr[isec]);
1975 momentum.SetE(GENSTK.tki[isec] + PAPROP.am[GENSTK.kpart[isec]+6]);
1976 }
1977 else if (isec >= GENSTK.np && isec < GENSTK.np + FHEAVY.npheav) {
1978 Int_t jsec = isec - GENSTK.np;
1979 particleId = FHEAVY.kheavy[jsec]; // this is Fluka id !!!
1980 position.SetX(fXsco);
1981 position.SetY(fYsco);
1982 position.SetZ(fZsco);
1983 position.SetT(TRACKR.atrack);
1984 momentum.SetPx(FHEAVY.pheavy[jsec]*FHEAVY.cxheav[jsec]);
1985 momentum.SetPy(FHEAVY.pheavy[jsec]*FHEAVY.cyheav[jsec]);
1986 momentum.SetPz(FHEAVY.pheavy[jsec]*FHEAVY.czheav[jsec]);
1987 if (FHEAVY.tkheav[jsec] >= 3 && FHEAVY.tkheav[jsec] <= 6)
1988 momentum.SetE(FHEAVY.tkheav[jsec] + PAPROP.am[jsec+6]);
1989 else if (FHEAVY.tkheav[jsec] > 6)
1990 momentum.SetE(FHEAVY.tkheav[jsec] + FHEAVY.amnhea[jsec]); // to be checked !!!
1991 }
1992 else
1993 Warning("GetSecondary","isec out of range");
1994 }
a9ea1616 1995 } else if (caller == kUSTCKV) {
4aba9d66 1996 Int_t index = OPPHST.lstopp - isec;
1997 position.SetX(OPPHST.xoptph[index]);
1998 position.SetY(OPPHST.yoptph[index]);
1999 position.SetZ(OPPHST.zoptph[index]);
2000 position.SetT(OPPHST.agopph[index]);
2001 Double_t p = OPPHST.poptph[index];
2002
2003 momentum.SetPx(p * OPPHST.txopph[index]);
2004 momentum.SetPy(p * OPPHST.tyopph[index]);
2005 momentum.SetPz(p * OPPHST.tzopph[index]);
2006 momentum.SetE(p);
829fb838 2007 }
2008 else
4aba9d66 2009 Warning("GetSecondary","no secondaries available");
7b203b6e 2010
829fb838 2011} // end of GetSecondary
2012
7b203b6e 2013
829fb838 2014//______________________________________________________________________________
2015TMCProcess TFluka::ProdProcess(Int_t) const
2016
2017{
2018// Name of the process that has produced the secondary particles
2019// in the current step
0dabe425 2020
a9ea1616 2021 Int_t mugamma = (TRACKR.jtrack == kFLUKAphoton ||
4aba9d66 2022 TRACKR.jtrack == kFLUKAmuplus ||
2023 TRACKR.jtrack == kFLUKAmuminus);
a9ea1616 2024 FlukaProcessCode_t icode = GetIcode();
2025
2026 if (icode == kKASKADdecay) return kPDecay;
2027 else if (icode == kKASKADpair || icode == kEMFSCOpair) return kPPair;
2028 else if (icode == kEMFSCOcompton) return kPCompton;
2029 else if (icode == kEMFSCOphotoel) return kPPhotoelectric;
2030 else if (icode == kKASKADbrems || icode == kEMFSCObrems) return kPBrem;
2031 else if (icode == kKASKADdray || icode == kKASHEAdray) return kPDeltaRay;
2032 else if (icode == kEMFSCOmoller || icode == kEMFSCObhabha) return kPDeltaRay;
2033 else if (icode == kEMFSCOanniflight || icode == kEMFSCOannirest) return kPAnnihilation;
2034 else if (icode == kKASKADinelint) {
4aba9d66 2035 if (!mugamma) return kPHadronic;
2036 else if (TRACKR.jtrack == kFLUKAphoton) return kPPhotoFission;
2037 else return kPMuonNuclear;
829fb838 2038 }
a9ea1616 2039 else if (icode == kEMFSCOrayleigh) return kPRayleigh;
829fb838 2040// Fluka codes 100, 300 and 400 still to be investigasted
a9ea1616 2041 else return kPNoProcess;
829fb838 2042}
2043
829fb838 2044
b496f27c 2045Int_t TFluka::StepProcesses(TArrayI &proc) const
2046{
2047 //
2048 // Return processes active in the current step
2049 //
e71bcde8 2050 FlukaProcessCode_t icode = GetIcode();
2051 FlukaCallerCode_t caller = GetCaller();
2052
b496f27c 2053 proc.Set(1);
2054 TMCProcess iproc;
82a3f706 2055 if (caller == kBXEntering || caller == kBXExiting || caller == kEEDRAW) {
e71bcde8 2056 iproc = kPTransportation;
2057 } else {
2058 switch (icode) {
2059 case kEMFSCO:
82a3f706 2060 if (Edep() > 0.) {
2061 iproc = kPEnergyLoss;
2062 } else {
2063 iproc = kPTransportation;
2064 }
e71bcde8 2065 break;
2066 case kKASKADtimekill:
2067 case kEMFSCOtimekill:
2068 case kKASNEUtimekill:
2069 case kKASHEAtimekill:
2070 case kKASOPHtimekill:
2071 iproc = kPTOFlimit;
2072 break;
2073 case kKASKADstopping:
2074 case kKASKADescape:
2075 case kEMFSCOstopping1:
2076 case kEMFSCOstopping2:
2077 case kEMFSCOescape:
2078 case kKASNEUstopping:
2079 case kKASNEUescape:
2080 case kKASHEAescape:
2081 case kKASOPHescape:
2082 iproc = kPStop;
2083 break;
2084 case kKASOPHabsorption:
2085 iproc = kPLightAbsorption;
2086 break;
2087 case kKASOPHrefraction:
2088 iproc = kPLightRefraction;
2089 case kEMFSCOlocaldep :
2090 iproc = kPPhotoelectric;
2091 break;
2092 default:
2093 iproc = ProdProcess(0);
2094 }
b496f27c 2095 }
e71bcde8 2096
07f5b33e 2097 proc[0] = iproc;
b496f27c 2098 return 1;
2099}
829fb838 2100//______________________________________________________________________________
2101Int_t TFluka::VolId2Mate(Int_t id) const
2102{
2103//
2104// Returns the material number for a given volume ID
2105//
2106 return fMCGeo->VolId2Mate(id);
2107}
2108
2109//______________________________________________________________________________
2110const char* TFluka::VolName(Int_t id) const
2111{
2112//
2113// Returns the volume name for a given volume ID
2114//
2115 return fMCGeo->VolName(id);
2116}
2117
a8e4986c 2118Int_t TFluka::MediumId(const Text_t* mediumName) const
2119{
2120 //
2121 // Return the unique medium id for medium with name mediumName
2122 TList *medlist = gGeoManager->GetListOfMedia();
2123 TGeoMedium* med = (TGeoMedium*) medlist->FindObject(mediumName);
2124 if (med) {
2125 return (med->GetId());
2126 } else {
2127 return (-1);
2128 }
2129}
2130
829fb838 2131//______________________________________________________________________________
2132Int_t TFluka::VolId(const Text_t* volName) const
2133{
2134//
2135// Converts from volume name to volume ID.
2136// Time consuming. (Only used during set-up)
2137// Could be replaced by hash-table
2138//
09cd6497 2139 char sname[20];
2140 Int_t len;
2141 strncpy(sname, volName, len = strlen(volName));
2142 sname[len] = 0;
2143 while (sname[len - 1] == ' ') sname[--len] = 0;
2144 return fMCGeo->VolId(sname);
829fb838 2145}
2146
2147//______________________________________________________________________________
2148Int_t TFluka::CurrentVolID(Int_t& copyNo) const
2149{
2150//
2151// Return the logical id and copy number corresponding to the current fluka region
2152//
2153 if (gGeoManager->IsOutside()) return 0;
2154 TGeoNode *node = gGeoManager->GetCurrentNode();
2155 copyNo = node->GetNumber();
2156 Int_t id = node->GetVolume()->GetNumber();
2157 return id;
2158}
2159
2160//______________________________________________________________________________
2161Int_t TFluka::CurrentVolOffID(Int_t off, Int_t& copyNo) const
2162{
2163//
2164// Return the logical id and copy number of off'th mother
2165// corresponding to the current fluka region
2166//
2167 if (off<0 || off>gGeoManager->GetLevel()) return 0;
2168 if (off==0) return CurrentVolID(copyNo);
2169 TGeoNode *node = gGeoManager->GetMother(off);
2170 if (!node) return 0;
2171 copyNo = node->GetNumber();
2172 return node->GetVolume()->GetNumber();
2173}
2174
2175//______________________________________________________________________________
2176const char* TFluka::CurrentVolName() const
2177{
2178//
2179// Return the current volume name
2180//
4678abb9 2181 if (gGeoManager->IsOutside()) return "Outside FLUKA Geometry !";
829fb838 2182 return gGeoManager->GetCurrentVolume()->GetName();
2183}
2184
2185//______________________________________________________________________________
2186const char* TFluka::CurrentVolOffName(Int_t off) const
2187{
2188//
2189// Return the volume name of the off'th mother of the current volume
2190//
2191 if (off<0 || off>gGeoManager->GetLevel()) return 0;
2192 if (off==0) return CurrentVolName();
2193 TGeoNode *node = gGeoManager->GetMother(off);
2194 if (!node) return 0;
2195 return node->GetVolume()->GetName();
2196}
2197
d59acfe7 2198const char* TFluka::CurrentVolPath() {
2199 // Return the current volume path
2200 return gGeoManager->GetPath();
2201}
829fb838 2202//______________________________________________________________________________
a60813de 2203Int_t TFluka::CurrentMaterial(Float_t & a, Float_t & z,
4aba9d66 2204 Float_t & dens, Float_t & radl, Float_t & absl) const
829fb838 2205{
2206//
a60813de 2207// Return the current medium number and material properties
829fb838 2208//
2209 Int_t copy;
2210 Int_t id = TFluka::CurrentVolID(copy);
2211 Int_t med = TFluka::VolId2Mate(id);
a60813de 2212 TGeoVolume* vol = gGeoManager->GetCurrentVolume();
2213 TGeoMaterial* mat = vol->GetMaterial();
2214 a = mat->GetA();
2215 z = mat->GetZ();
2216 dens = mat->GetDensity();
2217 radl = mat->GetRadLen();
2218 absl = mat->GetIntLen();
2219
829fb838 2220 return med;
2221}
2222
2223//______________________________________________________________________________
2224void TFluka::Gmtod(Float_t* xm, Float_t* xd, Int_t iflag)
2225{
2226// Transforms a position from the world reference frame
2227// to the current volume reference frame.
2228//
2229// Geant3 desription:
2230// ==================
2231// Computes coordinates XD (in DRS)
2232// from known coordinates XM in MRS
2233// The local reference system can be initialized by
2234// - the tracking routines and GMTOD used in GUSTEP
2235// - a call to GMEDIA(XM,NUMED)
2236// - a call to GLVOLU(NLEVEL,NAMES,NUMBER,IER)
2237// (inverse routine is GDTOM)
2238//
2239// If IFLAG=1 convert coordinates
2240// IFLAG=2 convert direction cosinus
2241//
2242// ---
2243 Double_t xmL[3], xdL[3];
2244 Int_t i;
2245 for (i=0;i<3;i++) xmL[i]=xm[i];
2246 if (iflag == 1) gGeoManager->MasterToLocal(xmL,xdL);
2247 else gGeoManager->MasterToLocalVect(xmL,xdL);
2248 for (i=0;i<3;i++) xd[i] = xdL[i];
2249}
2250
2251//______________________________________________________________________________
2252void TFluka::Gmtod(Double_t* xm, Double_t* xd, Int_t iflag)
2253{
2047b055 2254//
2255// See Gmtod(Float_t*, Float_t*, Int_t)
2256//
829fb838 2257 if (iflag == 1) gGeoManager->MasterToLocal(xm,xd);
2258 else gGeoManager->MasterToLocalVect(xm,xd);
2259}
2260
2261//______________________________________________________________________________
2262void TFluka::Gdtom(Float_t* xd, Float_t* xm, Int_t iflag)
2263{
2264// Transforms a position from the current volume reference frame
2265// to the world reference frame.
2266//
2267// Geant3 desription:
2268// ==================
2269// Computes coordinates XM (Master Reference System
2270// knowing the coordinates XD (Detector Ref System)
2271// The local reference system can be initialized by
2272// - the tracking routines and GDTOM used in GUSTEP
2273// - a call to GSCMED(NLEVEL,NAMES,NUMBER)
2274// (inverse routine is GMTOD)
2275//
2276// If IFLAG=1 convert coordinates
2277// IFLAG=2 convert direction cosinus
2278//
2279// ---
2280 Double_t xmL[3], xdL[3];
2281 Int_t i;
2282 for (i=0;i<3;i++) xdL[i] = xd[i];
2283 if (iflag == 1) gGeoManager->LocalToMaster(xdL,xmL);
2284 else gGeoManager->LocalToMasterVect(xdL,xmL);
2285 for (i=0;i<3;i++) xm[i]=xmL[i];
2286}
2287
2288//______________________________________________________________________________
2289void TFluka::Gdtom(Double_t* xd, Double_t* xm, Int_t iflag)
2290{
2047b055 2291//
2292// See Gdtom(Float_t*, Float_t*, Int_t)
2293//
829fb838 2294 if (iflag == 1) gGeoManager->LocalToMaster(xd,xm);
2295 else gGeoManager->LocalToMasterVect(xd,xm);
2296}
2297
2298//______________________________________________________________________________
2299TObjArray *TFluka::GetFlukaMaterials()
2300{
2047b055 2301//
2302// Get array of Fluka materials
829fb838 2303 return fGeom->GetMatList();
2304}
2305
2306//______________________________________________________________________________
a9ea1616 2307void TFluka::SetMreg(Int_t l, Int_t lttc)
829fb838 2308{
2309// Set current fluka region
2310 fCurrentFlukaRegion = l;
a9ea1616 2311 fGeom->SetMreg(l,lttc);
829fb838 2312}
2313
2314
b496f27c 2315
2316
4aba9d66 2317//______________________________________________________________________________
b496f27c 2318TString TFluka::ParticleName(Int_t pdg) const
2319{
2320 // Return particle name for particle with pdg code pdg.
2321 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2322 return TString((CHPPRP.btype[ifluka - kFLUKAcodemin]), 8);
b496f27c 2323}
2324
2325
4aba9d66 2326//______________________________________________________________________________
b496f27c 2327Double_t TFluka::ParticleMass(Int_t pdg) const
2328{
2329 // Return particle mass for particle with pdg code pdg.
2330 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2331 return (PAPROP.am[ifluka - kFLUKAcodemin]);
2332}
2333
4aba9d66 2334//______________________________________________________________________________
ece92b30 2335Double_t TFluka::ParticleMassFPC(Int_t fpc) const
2336{
2337 // Return particle mass for particle with Fluka particle code fpc
2338 return (PAPROP.am[fpc - kFLUKAcodemin]);
b496f27c 2339}
2340
4aba9d66 2341//______________________________________________________________________________
b496f27c 2342Double_t TFluka::ParticleCharge(Int_t pdg) const
2343{
2344 // Return particle charge for particle with pdg code pdg.
2345 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2346 return Double_t(PAPROP.ichrge[ifluka - kFLUKAcodemin]);
b496f27c 2347}
2348
4aba9d66 2349//______________________________________________________________________________
b496f27c 2350Double_t TFluka::ParticleLifeTime(Int_t pdg) const
2351{
2352 // Return particle lifetime for particle with pdg code pdg.
2353 Int_t ifluka = IdFromPDG(pdg);
ece92b30 2354 return (PAPROP.tmnlf[ifluka - kFLUKAcodemin]);
b496f27c 2355}
2356
4aba9d66 2357//______________________________________________________________________________
b496f27c 2358void TFluka::Gfpart(Int_t pdg, char* name, Int_t& type, Float_t& mass, Float_t& charge, Float_t& tlife)
2359{
2360 // Retrieve particle properties for particle with pdg code pdg.
2361
2362 strcpy(name, ParticleName(pdg).Data());
2363 type = ParticleMCType(pdg);
2364 mass = ParticleMass(pdg);
2365 charge = ParticleCharge(pdg);
2366 tlife = ParticleLifeTime(pdg);
2367}
2368
4aba9d66 2369//______________________________________________________________________________
8e5bf079 2370void TFluka::PrintHeader()
2371{
2372 //
2373 // Print a header
2374 printf("\n");
2375 printf("\n");
2376 printf("------------------------------------------------------------------------------\n");
2377 printf("- You are using the TFluka Virtual Monte Carlo Interface to FLUKA. -\n");
2378 printf("- Please see the file fluka.out for FLUKA output and licensing information. -\n");
2379 printf("------------------------------------------------------------------------------\n");
2380 printf("\n");
2381 printf("\n");
2382}
2383
b496f27c 2384
81f1d030 2385#define pshckp pshckp_
2386#define ustckv ustckv_
3a625972 2387
2388
2389extern "C" {
81f1d030 2390 void pshckp(Double_t & px, Double_t & py, Double_t & pz, Double_t & e,
4aba9d66 2391 Double_t & vx, Double_t & vy, Double_t & vz, Double_t & tof,
2392 Double_t & polx, Double_t & poly, Double_t & polz, Double_t & wgt, Int_t& ntr)
81f1d030 2393 {
2394 //
2395 // Pushes one cerenkov photon to the stack
2396 //
2397
2398 TFluka* fluka = (TFluka*) gMC;
2399 TVirtualMCStack* cppstack = fluka->GetStack();
2400 Int_t parent = TRACKR.ispusr[mkbmx2-1];
2401 cppstack->PushTrack(0, parent, 50000050,
4aba9d66 2402 px, py, pz, e,
2403 vx, vy, vz, tof,
2404 polx, poly, polz,
2405 kPCerenkov, ntr, wgt, 0);
2406 if (fluka->GetVerbosityLevel() >= 3)
2407 printf("pshckp: track=%d parent=%d lattc=%d %s\n", ntr, parent, TRACKR.lt1trk, fluka->CurrentVolName());
81f1d030 2408 }
2409
2410 void ustckv(Int_t & nphot, Int_t & mreg, Double_t & x, Double_t & y, Double_t & z)
7b203b6e 2411 {
4aba9d66 2412 //
2413 // Calls stepping in order to signal cerenkov production
2414 //
2415 TFluka *fluka = (TFluka*)gMC;
2416 fluka->SetMreg(mreg, TRACKR.lt1trk); //LTCLCM.mlatm1);
2417 fluka->SetXsco(x);
2418 fluka->SetYsco(y);
2419 fluka->SetZsco(z);
2420 fluka->SetNCerenkov(nphot);
2421 fluka->SetCaller(kUSTCKV);
2422 if (fluka->GetVerbosityLevel() >= 3)
2423 printf("ustckv: %10d mreg=%d lattc=%d newlat=%d (%f, %f, %f) edep=%f vol=%s\n",
2424 nphot, mreg, TRACKR.lt1trk, LTCLCM.newlat, x, y, z, fluka->Edep(), fluka->CurrentVolName());
2425
2426 // check region lattice consistency (debug Ernesto)
2427 // *****************************************************
2428 Int_t nodeId;
2429 Int_t volId = fluka->CurrentVolID(nodeId);
2430 Int_t crtlttc = gGeoManager->GetCurrentNodeId()+1;
2431
2432 if( mreg != volId && !gGeoManager->IsOutside() ) {
2433 cout << " ustckv: track=" << TRACKR.ispusr[mkbmx2-1] << " pdg=" << fluka->PDGFromId(TRACKR.jtrack)
2434 << " icode=" << fluka->GetIcode() << " gNstep=" << fluka->GetNstep() << endl
2435 << " fluka mreg=" << mreg << " mlttc=" << TRACKR.lt1trk << endl
2436 << " TGeo volId=" << volId << " crtlttc=" << crtlttc << endl
2437 << " common TRACKR lt1trk=" << TRACKR.lt1trk << " lt2trk=" << TRACKR.lt2trk << endl
2438 << " common LTCLCM newlat=" << LTCLCM.newlat << " mlatld=" << LTCLCM.mlatld << endl
2439 << " mlatm1=" << LTCLCM.mlatm1 << " mltsen=" << LTCLCM.mltsen << endl
2440 << " mltsm1=" << LTCLCM.mltsm1 << " mlattc=" << LTCLCM.mlattc << endl;
2441 if( TRACKR.lt1trk == crtlttc ) cout << " *************************************************************" << endl;
2442 }
2443 // *****************************************************
2444
2445
2446
2447 (TVirtualMCApplication::Instance())->Stepping();
7b203b6e 2448 }
3a625972 2449}
a9ea1616 2450
4aba9d66 2451//______________________________________________________________________________
78df7be0 2452void TFluka::AddParticlesToPdgDataBase() const
2453{
2454
2455//
2456// Add particles to the PDG data base
2457
2458 TDatabasePDG *pdgDB = TDatabasePDG::Instance();
2459
78df7be0 2460 const Double_t kAu2Gev = 0.9314943228;
2461 const Double_t khSlash = 1.0545726663e-27;
2462 const Double_t kErg2Gev = 1/1.6021773349e-3;
2463 const Double_t khShGev = khSlash*kErg2Gev;
2464 const Double_t kYear2Sec = 3600*24*365.25;
2465//
2466// Ions
2467//
78df7be0 2468 pdgDB->AddParticle("Deuteron","Deuteron",2*kAu2Gev+8.071e-3,kTRUE,
13858fbd 2469 0,3,"Ion",GetIonPdg(1,2));
78df7be0 2470 pdgDB->AddParticle("Triton","Triton",3*kAu2Gev+14.931e-3,kFALSE,
13858fbd 2471 khShGev/(12.33*kYear2Sec),3,"Ion",GetIonPdg(1,3));
78df7be0 2472 pdgDB->AddParticle("Alpha","Alpha",4*kAu2Gev+2.424e-3,kTRUE,
13858fbd 2473 khShGev/(12.33*kYear2Sec),6,"Ion",GetIonPdg(2,4));
78df7be0 2474 pdgDB->AddParticle("HE3","HE3",3*kAu2Gev+14.931e-3,kFALSE,
13858fbd 2475 0,6,"Ion",GetIonPdg(2,3));
78df7be0 2476}
2477
4aba9d66 2478//
2479// Info about primary ionization electrons
2480//
2481
2482//______________________________________________________________________________
2483Int_t TFluka::GetNPrimaryElectrons()
f2a98602 2484{
2485 // Get number of primary electrons
2486 return ALLDLT.nalldl;
2487}
2488
4aba9d66 2489//______________________________________________________________________________
5125d6e5 2490Double_t TFluka::GetPrimaryElectronKineticEnergy(Int_t i) const
f2a98602 2491{
2492 // Returns kinetic energy of primary electron i
5125d6e5 2493
2494 Double_t ekin = -1.;
ea262cc6 2495
f2a98602 2496 if (i >= 0 && i < ALLDLT.nalldl) {
6c854012 2497 ekin = ALLDLT.talldl[i];
f2a98602 2498 } else {
4aba9d66 2499 Warning("GetPrimaryElectronKineticEnergy",
2500 "Primary electron index out of range %d %d \n",
2501 i, ALLDLT.nalldl);
f2a98602 2502 }
f0734960 2503 return ekin;
f2a98602 2504}
5125d6e5 2505
2506void TFluka::GetPrimaryElectronPosition(Int_t i, Double_t& x, Double_t& y, Double_t& z) const
2507{
2508 // Returns position of primary electron i
2509 if (i >= 0 && i < ALLDLT.nalldl) {
6c854012 2510 x = ALLDLT.xalldl[i];
2511 y = ALLDLT.yalldl[i];
2512 z = ALLDLT.zalldl[i];
5125d6e5 2513 return;
2514 } else {
2515 Warning("GetPrimaryElectronPosition",
2516 "Primary electron index out of range %d %d \n",
2517 i, ALLDLT.nalldl);
2518 return;
2519 }
2520 return;
2521}
2522
13858fbd 2523Int_t TFluka::GetIonPdg(Int_t z, Int_t a, Int_t i) const
2524{
2525// Acording to
2526// http://cepa.fnal.gov/psm/stdhep/pdg/montecarlorpp-2006.pdf
5125d6e5 2527
13858fbd 2528 return 1000000000 + 10*1000*z + 10*a + i;
2529}
2530
ea262cc6 2531void TFluka::PrimaryIonisationStepping(Int_t nprim)
2532{
2533// Call Stepping for primary ionisation electrons
2534 Int_t i;
2535// Protection against nprim > mxalld
2536
2537// Multiple steps for nprim > 0
2538 if (nprim > 0) {
2539 for (i = 0; i < nprim; i++) {
2540 SetCurrentPrimaryElectronIndex(i);
2541 (TVirtualMCApplication::Instance())->Stepping();
2542 if (i == 0) SetTrackIsNew(kFALSE);
2543 }
2544 } else {
2545 // No primary electron ionisation
2546 // Call Stepping anyway but flag nprim = 0 as index = -2
2547 SetCurrentPrimaryElectronIndex(-2);
2548 (TVirtualMCApplication::Instance())->Stepping();
2549 }
2550 // Reset the index
2551 SetCurrentPrimaryElectronIndex(-1);
2552}
b6a89226 2553
2554//______________________________________________________________________
2555Float_t* TFluka::CreateFloatArray(Double_t* array, Int_t size) const
2556{
2557// Converts Double_t* array to Float_t*,
2558// !! The new array has to be deleted by user.
2559// ---
2560
2561 Float_t* floatArray;
2562 if (size>0) {
2563 floatArray = new Float_t[size];
2564 for (Int_t i=0; i<size; i++)
2565 if (array[i] >= FLT_MAX )
2566 floatArray[i] = FLT_MAX/100.;
2567 else
2568 floatArray[i] = array[i];
2569 }
2570 else {
2571 //floatArray = 0;
2572 floatArray = new Float_t[1];
2573 }
2574 return floatArray;
2575}