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