Ions have to be added to root particle database.
[u/mrichter/AliRoot.git] / TFluka / TFlukaMCGeometry.cxx
CommitLineData
e2e989f9 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$
c1a0a2f0 17
18// Class TFlukaMCGeometry
19// --------------------
20// Implementation of the TVirtualMCGeometry interface
21// for defining and using TGeo geometry with FLUKA.
22// This allows the FLUKA MonteCarlo to run with the TGeo
23// geometrical modeller
8495a208 24// Author: Andrei Gheata 10/07/2003
25
c1a0a2f0 26#include "Riostream.h"
c1a0a2f0 27#include "TCallf77.h"
89125dc7 28#include "TFluka.h"
8495a208 29#include "TFlukaMCGeometry.h"
6d184c54 30#include "TFlukaConfigOption.h"
8495a208 31#include "TGeoManager.h"
32#include "TGeoVolume.h"
c1a0a2f0 33#include "TObjString.h"
81f1d030 34#include "Fsourcm.h"
aae6bcdd 35#include "Ftrackr.h"
3860051a 36
8495a208 37#ifndef WIN32
38# define idnrwr idnrwr_
39# define g1wr g1wr_
40# define g1rtwr g1rtwr_
41# define conhwr conhwr_
42# define inihwr inihwr_
43# define jomiwr jomiwr_
44# define lkdbwr lkdbwr_
45# define lkfxwr lkfxwr_
46# define lkmgwr lkmgwr_
47# define lkwr lkwr_
48# define magfld magfld_
49# define nrmlwr nrmlwr_
50# define rgrpwr rgrpwr_
51# define isvhwr isvhwr_
52
53#else
54
55# define idnrwr IDNRWR
56# define g1wr G1WR
57# define g1rtwr G1RTWR
58# define conhwr CONHWR
59# define inihwr INIHWR
60# define jomiwr JOMIWR
61# define lkdbwr LKDBWR
62# define lkfxwr LKFXWR
63# define lkmgwr LKMGWR
64# define lkwr LKWR
65# define magfld MAGFLD
66# define nrmlwr NRMLWR
67# define rgrpwr RGRPWR
68# define isvhwr ISVHWR
69
70#endif
71
72//____________________________________________________________________________
73extern "C"
74{
75 //
76 // Prototypes for FLUKA navigation methods
77 //
78 Int_t type_of_call idnrwr(const Int_t & /*nreg*/, const Int_t & /*mlat*/);
79 void type_of_call g1wr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
80 Double_t * /*pV*/, Int_t & /*oldReg*/ , const Int_t & /*oldLttc*/, Double_t & /*propStep*/,
81 Int_t & /*nascFlag*/, Double_t & /*retStep*/, Int_t & /*newReg*/,
82 Double_t & /*saf*/, Int_t & /*newLttc*/, Int_t & /*LttcFlag*/,
83 Double_t *s /*Lt*/, Int_t * /*jrLt*/);
84
85 void type_of_call g1rtwr();
86 void type_of_call conhwr(Int_t & /*intHist*/, Int_t * /*incrCount*/);
87 void type_of_call inihwr(Int_t & /*intHist*/);
88 void type_of_call jomiwr(const Int_t & /*nge*/, const Int_t & /*lin*/, const Int_t & /*lou*/,
89 Int_t & /*flukaReg*/);
90 void type_of_call lkdbwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
91 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
aae6bcdd 92 Int_t & /*flagErr*/, Int_t & /*newReg*/, Int_t & /*newLttc*/);
8495a208 93 void type_of_call lkfxwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
94 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
aae6bcdd 95 Int_t & /*flagErr*/, Int_t & /*newReg*/, Int_t & /*newLttc*/);
8495a208 96 void type_of_call lkmgwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
97 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
98 Int_t & /*flagErr*/, Int_t & /*newReg*/, Int_t & /*newLttc*/);
99 void type_of_call lkwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
100 Double_t * /*pV*/, const Int_t & /*oldReg*/, const Int_t & /*oldLttc*/,
aae6bcdd 101 Int_t & /*flagErr*/, Int_t & /*newReg*/, Int_t & /*newLttc*/);
efde9b4d 102// void type_of_call magfld(const Double_t & /*pX*/, const Double_t & /*pY*/, const Double_t & /*pZ*/,
103// Double_t & /*cosBx*/, Double_t & /*cosBy*/, Double_t & /*cosBz*/,
104// Double_t & /*Bmag*/, Int_t & /*reg*/, Int_t & /*idiscflag*/);
8495a208 105 void type_of_call nrmlwr(Double_t & /*pSx*/, Double_t & /*pSy*/, Double_t & /*pSz*/,
106 Double_t & /*pVx*/, Double_t & /*pVy*/, Double_t & /*pVz*/,
107 Double_t * /*norml*/, const Int_t & /*oldReg*/,
108 const Int_t & /*newReg*/, Int_t & /*flagErr*/);
109 void type_of_call rgrpwr(const Int_t & /*flukaReg*/, const Int_t & /*ptrLttc*/, Int_t & /*g4Reg*/,
110 Int_t * /*indMother*/, Int_t * /*repMother*/, Int_t & /*depthFluka*/);
111 Int_t type_of_call isvhwr(const Int_t & /*fCheck*/, const Int_t & /*intHist*/);
8be76537 112}
8495a208 113
114// TFluka global pointer
89125dc7 115TFluka *gFluka = 0;
116TFlukaMCGeometry *gMCGeom = 0;
6f5667d1 117Int_t gNstep = 0;
8495a208 118
119ClassImp(TFlukaMCGeometry)
120
81f1d030 121TFlukaMCGeometry* TFlukaMCGeometry::fgInstance= NULL;
8495a208 122
123//_____________________________________________________________________________
124TFlukaMCGeometry::TFlukaMCGeometry(const char *name, const char *title)
89125dc7 125 : TNamed(name, title)
8495a208 126{
127 //
128 // Standard constructor
129 //
2bc4c610 130 fDebug = kFALSE;
efde9b4d 131 fLastMaterial = 0;
81f1d030 132 fCurrentRegion = 0;
133 fCurrentLattice = 0;
aae6bcdd 134 fDummyRegion = 0;
b1536e91 135 fNextRegion = 0;
136 fNextLattice = 0;
137 fRegionList = 0;
81f1d030 138 fIndmat = 0;
89125dc7 139 gFluka = (TFluka*)gMC;
140 gMCGeom = this;
6f5667d1 141 gNstep = 0;
89125dc7 142 fMatList = new TObjArray(256);
143 fMatNames = new TObjArray(256);
8495a208 144}
145
146//_____________________________________________________________________________
147TFlukaMCGeometry::TFlukaMCGeometry()
8495a208 148{
149 //
150 // Default constructor
151 //
2bc4c610 152 fDebug = kFALSE;
efde9b4d 153 fLastMaterial = 0;
81f1d030 154 fCurrentRegion = 0;
155 fCurrentLattice = 0;
aae6bcdd 156 fDummyRegion = 0;
b1536e91 157 fNextRegion = 0;
158 fNextLattice = 0;
159 fRegionList = 0;
81f1d030 160 fIndmat = 0;
89125dc7 161 gFluka = (TFluka*)gMC;
162 gMCGeom = this;
6f5667d1 163 gNstep = 0;
89125dc7 164 fMatList = 0;
165 fMatNames = 0;
8495a208 166}
167
168//_____________________________________________________________________________
169TFlukaMCGeometry::~TFlukaMCGeometry()
170{
171 //
172 // Destructor
173 //
174 fgInstance=0;
b1536e91 175 if (fRegionList) delete [] fRegionList;
89125dc7 176 if (fMatList) delete fMatList;
177 if (fMatNames) {fMatNames->Delete(); delete fMatNames;}
8495a208 178 if (gGeoManager) delete gGeoManager;
179}
180
181//
182// private methods
183//
184//_____________________________________________________________________________
185TFlukaMCGeometry::TFlukaMCGeometry(const TFlukaMCGeometry &)
89125dc7 186 : TNamed()
8495a208 187{
188 //
189 // Copy constructor
190 //
191}
192
193//_____________________________________________________________________________
194Double_t* TFlukaMCGeometry::CreateDoubleArray(Float_t* array, Int_t size) const
195{
196// Converts Float_t* array to Double_t*,
197// !! The new array has to be deleted by user.
198// ---
199
200 Double_t* doubleArray;
201 if (size>0) {
202 doubleArray = new Double_t[size];
203 for (Int_t i=0; i<size; i++) doubleArray[i] = array[i];
204 }
205 else {
206 //doubleArray = 0;
207 doubleArray = new Double_t[1];
208 }
209 return doubleArray;
210}
211//
212// public methods
8495a208 213
8495a208 214
215//_____________________________________________________________________________
8495a208 216Int_t TFlukaMCGeometry::GetMedium() const
217{
218// Get current medium number
219 Int_t imed = 0;
220 TGeoNode *node = gGeoManager->GetCurrentNode();
221 if (!node) imed = gGeoManager->GetTopNode()->GetVolume()->GetMedium()->GetId();
222 else imed = node->GetVolume()->GetMedium()->GetId();
2bc4c610 223 if (fDebug) printf("GetMedium=%i\n", imed);
8495a208 224 return imed;
225}
226
227//_____________________________________________________________________________
0bc73b6c 228Int_t TFlukaMCGeometry::GetFlukaMaterial(Int_t imed) const
229{
230// Returns FLUKA material index for medium IMED
81f1d030 231 TGeoMedium *med = (TGeoMedium*)gGeoManager->GetListOfMedia()->At(imed-1);
0bc73b6c 232 if (!med) {
233 Error("GetFlukaMaterial", "MEDIUM %i nor found", imed);
234 return -1;
235 }
81f1d030 236 TGeoMaterial* mat = med->GetMaterial();
237 if (!mat->IsUsed()) return -1;
0bc73b6c 238 Int_t imatfl = med->GetMaterial()->GetIndex();
239 return imatfl;
240}
241
242//_____________________________________________________________________________
b1536e91 243Int_t *TFlukaMCGeometry::GetRegionList(Int_t imed, Int_t &nreg)
244{
245// Get an ordered list of regions matching a given medium number
246 nreg = 0;
247 if (!fRegionList) fRegionList = new Int_t[NofVolumes()+1];
248 TIter next(gGeoManager->GetListOfUVolumes());
249 TGeoVolume *vol;
250 Int_t imedium, ireg;
251 while ((vol = (TGeoVolume*)next())) {
252 imedium = vol->GetMedium()->GetId();
253 if (imedium == imed) {
254 ireg = vol->GetNumber();
255 fRegionList[nreg++] = ireg;
256 }
257 }
258 return fRegionList;
259}
260
261//_____________________________________________________________________________
262Int_t *TFlukaMCGeometry::GetMaterialList(Int_t imat, Int_t &nreg)
263{
264// Get an ordered list of regions matching a given medium number
265 nreg = 0;
266 if (!fRegionList) fRegionList = new Int_t[NofVolumes()+1];
267 TIter next(gGeoManager->GetListOfUVolumes());
268 TGeoVolume *vol;
269 Int_t imaterial, ireg;
270 while ((vol = (TGeoVolume*)next())) {
271 imaterial = vol->GetMedium()->GetMaterial()->GetIndex();
272 if (imaterial == imat) {
273 ireg = vol->GetNumber();
274 fRegionList[nreg++] = ireg;
275 }
276 }
277 return fRegionList;
278}
8495a208 279
280//_____________________________________________________________________________
8495a208 281Int_t TFlukaMCGeometry::NofVolumes() const
282{
283 //
284 // Return total number of volumes in the geometry
285 //
286
287 return gGeoManager->GetListOfUVolumes()->GetEntriesFast()-1;
288}
8495a208 289
290//_____________________________________________________________________________
89125dc7 291TGeoMaterial * TFlukaMCGeometry::GetMakeWrongMaterial(Double_t z)
292{
293// Try to replace a wrongly-defined material
294 static Double_t kz[23] = {7.3, 17.8184, 7.2167, 10.856, 8.875, 8.9, 7.177,
295 25.72, 6.2363, 7.1315, 47.7056, 10.6467, 7.8598, 2.10853, 10.6001, 9.1193,
296 15.3383, 4.55, 9.6502, 6.4561, 21.7963, 29.8246, 15.4021};
297
298 Int_t ind;
299 Double_t dz;
300 for (ind=0; ind<23; ind++) {
301 dz = TMath::Abs(z-kz[ind]);
302 if (dz<1E-4) break;
303 }
304 if (ind>22) {
305 printf("Cannot patch material with Z=%g\n", z);
306 return 0;
307 }
308 TGeoMixture *mix = 0;
309 TGeoElement *element;
81f1d030 310 TGeoElementTable *table = gGeoManager->GetElementTable();
89125dc7 311 switch (ind) {
312 case 0: // AIR
81f1d030 313 mix = new TGeoMixture("TPC_AIR", 4, 0.001205);
89125dc7 314 element = table->GetElement(6); // C
315 mix->DefineElement(0, element, 0.000124);
316 element = table->GetElement(7); // N
317 mix->DefineElement(1, element, 0.755267);
318 element = table->GetElement(8); // O
319 mix->DefineElement(2, element, 0.231781);
320 element = table->GetElement(18); // AR
321 mix->DefineElement(3, element, 0.012827);
322 break;
323 case 1: //SDD SI CHIP
81f1d030 324 mix = new TGeoMixture("ITS_SDD_SI", 6, 2.4485);
89125dc7 325 element = table->GetElement(1);
326 mix->DefineElement(0, element, 0.004367771);
327 element = table->GetElement(6);
328 mix->DefineElement(1, element, 0.039730642);
329 element = table->GetElement(7);
330 mix->DefineElement(2, element, 0.001396798);
331 element = table->GetElement(8);
332 mix->DefineElement(3, element, 0.01169634);
333 element = table->GetElement(14);
334 mix->DefineElement(4, element, 0.844665);
335 element = table->GetElement(47);
336 mix->DefineElement(5, element, 0.09814344903);
337 break;
338 case 2: // WATER
81f1d030 339 mix = new TGeoMixture("ITS_WATER", 2, 1.0);
89125dc7 340 element = table->GetElement(1);
341 mix->DefineElement(0, element, 0.111898344);
342 element = table->GetElement(8);
343 mix->DefineElement(1, element, 0.888101656);
344 break;
345 case 3: // CERAMICS
81f1d030 346 mix = new TGeoMixture("ITS_CERAMICS", 5, 3.6);
89125dc7 347 element = table->GetElement(8);
348 mix->DefineElement(0, element, 0.59956);
349 element = table->GetElement(13);
350 mix->DefineElement(1, element, 0.3776);
351 element = table->GetElement(14);
352 mix->DefineElement(2, element, 0.00933);
353 element = table->GetElement(24);
354 mix->DefineElement(3, element, 0.002);
355 element = table->GetElement(25);
356 mix->DefineElement(4, element, 0.0115);
357 break;
358 case 4: // EPOXY
81f1d030 359 mix = new TGeoMixture("MUON_G10FR4", 4, 1.8);
89125dc7 360 element = table->GetElement(1);
361 mix->DefineElement(0, element, 0.19);
362 element = table->GetElement(6);
363 mix->DefineElement(1, element, 0.18);
364 element = table->GetElement(8);
365 mix->DefineElement(2, element, 0.35);
366 element = table->GetElement(14);
367 mix->DefineElement(3, element, 0.28);
368 break;
369 case 5: // EPOXY
370 mix = new TGeoMixture("G10FR4", 4, 1.8);
371 element = table->GetElement(1);
372 mix->DefineElement(0, element, 0.19);
373 element = table->GetElement(6);
374 mix->DefineElement(1, element, 0.18);
375 element = table->GetElement(8);
376 mix->DefineElement(2, element, 0.35);
377 element = table->GetElement(14);
378 mix->DefineElement(3, element, 0.28);
379 break;
380 case 6: // KAPTON
81f1d030 381 mix = new TGeoMixture("ITS_KAPTON", 4, 1.3);
89125dc7 382 element = table->GetElement(1);
383 mix->DefineElement(0, element, 0.026363415);
384 element = table->GetElement(6);
385 mix->DefineElement(1, element, 0.6911272);
386 element = table->GetElement(7);
387 mix->DefineElement(2, element, 0.073271325);
388 element = table->GetElement(8);
389 mix->DefineElement(3, element, 0.209238060);
390 break;
391 case 7: // INOX
81f1d030 392 mix = new TGeoMixture("ITS_INOX", 9, 7.9);
89125dc7 393 element = table->GetElement(6);
394 mix->DefineElement(0, element, 0.0003);
395 element = table->GetElement(14);
396 mix->DefineElement(1, element, 0.01);
397 element = table->GetElement(15);
398 mix->DefineElement(2, element, 0.00045);
399 element = table->GetElement(16);
400 mix->DefineElement(3, element, 0.0003);
401 element = table->GetElement(24);
402 mix->DefineElement(4, element, 0.17);
403 element = table->GetElement(25);
404 mix->DefineElement(5, element, 0.02);
405 element = table->GetElement(26);
406 mix->DefineElement(6, element, 0.654);
407 element = table->GetElement(28);
408 mix->DefineElement(7, element, 0.12);
409 element = table->GetElement(42);
410 mix->DefineElement(8, element, 0.025);
411 break;
412 case 8: // ROHACELL
413 mix = new TGeoMixture("ROHACELL", 4, 0.05);
414 element = table->GetElement(1);
415 mix->DefineElement(0, element, 0.07836617);
416 element = table->GetElement(6);
417 mix->DefineElement(1, element, 0.64648941);
418 element = table->GetElement(7);
419 mix->DefineElement(2, element, 0.08376983);
420 element = table->GetElement(8);
421 mix->DefineElement(3, element, 0.19137459);
422 break;
423 case 9: // SDD-C-AL
81f1d030 424 mix = new TGeoMixture("ITS_SDD-C-AL", 5, 1.9837);
89125dc7 425 element = table->GetElement(1);
426 mix->DefineElement(0, element, 0.022632);
427 element = table->GetElement(6);
428 mix->DefineElement(1, element, 0.8176579);
429 element = table->GetElement(7);
430 mix->DefineElement(2, element, 0.0093488);
431 element = table->GetElement(8);
432 mix->DefineElement(3, element, 0.0503618);
433 element = table->GetElement(13);
434 mix->DefineElement(4, element, 0.1);
435 break;
436 case 10: // X7R-CAP
81f1d030 437 mix = new TGeoMixture("ITS_X7R-CAP", 7, 6.72);
89125dc7 438 element = table->GetElement(8);
439 mix->DefineElement(0, element, 0.085975822);
440 element = table->GetElement(22);
441 mix->DefineElement(1, element, 0.084755042);
442 element = table->GetElement(28);
443 mix->DefineElement(2, element, 0.038244751);
444 element = table->GetElement(29);
445 mix->DefineElement(3, element, 0.009471271);
446 element = table->GetElement(50);
447 mix->DefineElement(4, element, 0.321736471);
448 element = table->GetElement(56);
449 mix->DefineElement(5, element, 0.251639432);
450 element = table->GetElement(82);
451 mix->DefineElement(6, element, 0.2081768);
452 break;
453 case 11: // SDD ruby sph. Al2O3
81f1d030 454 mix = new TGeoMixture("ITS_AL2O3", 2, 3.97);
89125dc7 455 element = table->GetElement(8);
456 mix->DefineElement(0, element, 0.5293);
457 element = table->GetElement(13);
458 mix->DefineElement(1, element, 0.4707);
459 break;
460 case 12: // SDD HV microcable
81f1d030 461 mix = new TGeoMixture("ITS_HV-CABLE", 5, 1.6087);
89125dc7 462 element = table->GetElement(1);
463 mix->DefineElement(0, element, 0.01983871336);
464 element = table->GetElement(6);
465 mix->DefineElement(1, element, 0.520088819984);
466 element = table->GetElement(7);
467 mix->DefineElement(2, element, 0.0551367996);
468 element = table->GetElement(8);
469 mix->DefineElement(3, element, 0.157399667056);
470 element = table->GetElement(13);
471 mix->DefineElement(4, element, 0.247536);
472 break;
473 case 13: //SDD LV+signal cable
81f1d030 474 mix = new TGeoMixture("ITS_LV-CABLE", 5, 2.1035);
89125dc7 475 element = table->GetElement(1);
476 mix->DefineElement(0, element, 0.0082859922);
477 element = table->GetElement(6);
478 mix->DefineElement(1, element, 0.21722436468);
479 element = table->GetElement(7);
480 mix->DefineElement(2, element, 0.023028867);
481 element = table->GetElement(8);
482 mix->DefineElement(3, element, 0.06574077612);
483 element = table->GetElement(13);
484 mix->DefineElement(4, element, 0.68572);
485 break;
486 case 14: //SDD hybrid microcab
81f1d030 487 mix = new TGeoMixture("ITS_HYB-CAB", 5, 2.0502);
89125dc7 488 element = table->GetElement(1);
489 mix->DefineElement(0, element, 0.00926228815);
490 element = table->GetElement(6);
491 mix->DefineElement(1, element, 0.24281879711);
492 element = table->GetElement(7);
493 mix->DefineElement(2, element, 0.02574224025);
494 element = table->GetElement(8);
495 mix->DefineElement(3, element, 0.07348667449);
496 element = table->GetElement(13);
497 mix->DefineElement(4, element, 0.64869);
498 break;
499 case 15: //SDD anode microcab
81f1d030 500 mix = new TGeoMixture("ITS_ANOD-CAB", 5, 1.7854);
89125dc7 501 element = table->GetElement(1);
502 mix->DefineElement(0, element, 0.0128595919215);
503 element = table->GetElement(6);
504 mix->DefineElement(1, element, 0.392653705471);
505 element = table->GetElement(7);
506 mix->DefineElement(2, element, 0.041626868025);
507 element = table->GetElement(8);
508 mix->DefineElement(3, element, 0.118832707289);
509 element = table->GetElement(13);
510 mix->DefineElement(4, element, 0.431909);
511 break;
512 case 16: // inox/alum
81f1d030 513 mix = new TGeoMixture("ITS_INOX-AL", 5, 3.0705);
89125dc7 514 element = table->GetElement(13);
515 mix->DefineElement(0, element, 0.816164);
516 element = table->GetElement(14);
517 mix->DefineElement(1, element, 0.000919182);
518 element = table->GetElement(24);
519 mix->DefineElement(2, element, 0.0330906);
520 element = table->GetElement(26);
521 mix->DefineElement(3, element, 0.131443);
522 element = table->GetElement(28);
523 mix->DefineElement(4, element, 0.0183836);
524 case 17: // MYLAR
81f1d030 525 mix = new TGeoMixture("TPC_MYLAR", 3, 1.39);
89125dc7 526 element = table->GetElement(1);
527 mix->DefineElement(0, element, 0.0416667);
528 element = table->GetElement(6);
529 mix->DefineElement(1, element, 0.625);
530 element = table->GetElement(8);
531 mix->DefineElement(2, element, 0.333333);
532 break;
533 case 18: // SPDBUS(AL+KPT+EPOX) - unknown composition
81f1d030 534 mix = new TGeoMixture("ITS_SPDBUS", 1, 1.906);
89125dc7 535 element = table->GetElement(9);
536 mix->DefineElement(0, element, 1.);
95161cd7 537 z = element->Z();
89125dc7 538 break;
539 case 19: // SDD/SSD rings - unknown composition
81f1d030 540 mix = new TGeoMixture("ITS_SDDRINGS", 1, 1.8097);
89125dc7 541 element = table->GetElement(6);
542 mix->DefineElement(0, element, 1.);
95161cd7 543 z = element->Z();
89125dc7 544 break;
545 case 20: // SPD end ladder - unknown composition
81f1d030 546 mix = new TGeoMixture("ITS_SPDEL", 1, 3.6374);
89125dc7 547 element = table->GetElement(22);
548 mix->DefineElement(0, element, 1.);
95161cd7 549 z = element->Z();
89125dc7 550 break;
551 case 21: // SDD end ladder - unknown composition
81f1d030 552 mix = new TGeoMixture("ITS_SDDEL", 1, 0.3824);
89125dc7 553 element = table->GetElement(30);
554 mix->DefineElement(0, element, 1.);
95161cd7 555 z = element->Z();
89125dc7 556 break;
557 case 22: // SSD end ladder - unknown composition
81f1d030 558 mix = new TGeoMixture("ITS_SSDEL", 1, 0.68);
89125dc7 559 element = table->GetElement(16);
560 mix->DefineElement(0, element, 1.);
95161cd7 561 z = element->Z();
89125dc7 562 break;
563 }
564 mix->SetZ(z);
565 printf("Patched with mixture %s\n", mix->GetName());
566 return mix;
8495a208 567}
568
569//_____________________________________________________________________________
efde9b4d 570void TFlukaMCGeometry::CreateFlukaMatFile(const char *fname)
8495a208 571{
572 // ==== from FLUGG ====
573 // NAMES OF ELEMENTS AND COMPOUNDS: the names must be written in upper case,
574 // according to the fluka standard. In addition,. they must be equal to the
575 // names of the fluka materials - see fluka manual - in order that the
576 // program load the right cross sections, and equal to the names included in
577 // the .pemf. Otherwise the user must define the LOW-MAT CARDS, and make his
578 // own .pemf, in order to get the right cross sections loaded in memory.
89125dc7 579
580
8495a208 581 TString sname;
582 gGeoManager->Export("flgeom.root");
583 if (fname) sname = fname;
584 else sname = "flukaMat.inp";
585 ofstream out;
586 out.open(sname.Data(), ios::out);
587 if (!out.good()) {
588 Fatal("CreateFlukaMatFile", "could not open file %s for writing", sname.Data());
589 return;
590 }
591 PrintHeader(out, "MATERIALS AND COMPOUNDS");
592 PrintHeader(out, "MATERIALS");
89125dc7 593 Int_t i,j,idmat;
594 Int_t counttothree, nelem;
595 Double_t a,z,rho, w;
81f1d030 596 TGeoElementTable *table = gGeoManager->GetElementTable();
89125dc7 597 TGeoElement *element;
598 element = table->GetElement(13);
599 element->SetTitle("ALUMINUM"); // this is how FLUKA likes it ...
600 element = table->GetElement(15);
601 element->SetTitle("PHOSPHO"); // same story ...
602// element = table->GetElement(10);
603// element->SetTitle("ARGON"); // NEON not in neutron xsec table
604 Int_t nelements = table->GetNelements();
8495a208 605 TList *matlist = gGeoManager->GetListOfMaterials();
95161cd7 606// TList *medlist = gGeoManager->GetListOfMedia();
607// Int_t nmed = medlist->GetSize();
8495a208 608 TIter next(matlist);
609 Int_t nmater = matlist->GetSize();
610 Int_t nfmater = 0;
89125dc7 611 TGeoMaterial *mat;
8495a208 612 TGeoMixture *mix = 0;
613 TString matname;
89125dc7 614 TObjString *objstr;
615 // Create all needed elements
616 for (Int_t i=1; i<nelements; i++) {
617 element = table->GetElement(i);
618 // skip elements which are not defined
619 if (!element->IsUsed() && !element->IsDefined()) continue;
620 matname = element->GetTitle();
621 ToFlukaString(matname);
622 rho = 0.999;
3860051a 623
89125dc7 624 mat = new TGeoMaterial(matname, element->A(), element->Z(), rho);
625 mat->SetIndex(nfmater+3);
626 mat->SetUsed(kTRUE);
627 fMatList->Add(mat);
628 objstr = new TObjString(matname.Data());
629 fMatNames->Add(objstr);
630 nfmater++;
631 }
6d184c54 632
633 fIndmat = nfmater;
95161cd7 634// TGeoMedium *med;
89125dc7 635 // Adjust material names and add them to FLUKA list
8495a208 636 for (i=0; i<nmater; i++) {
637 mat = (TGeoMaterial*)matlist->At(i);
81f1d030 638 if (!mat->IsUsed()) continue;
89125dc7 639 z = mat->GetZ();
640 a = mat->GetA();
641 rho = mat->GetDensity();
642 if (mat->GetZ()<0.001) {
efde9b4d 643 mat->SetIndex(2); // vacuum, built-in inside FLUKA
644 continue;
89125dc7 645 }
646 matname = mat->GetName();
647 FlukaMatName(matname);
81f1d030 648
89125dc7 649 mat->SetIndex(nfmater+3);
650 objstr = new TObjString(matname.Data());
651 fMatList->Add(mat);
652 fMatNames->Add(objstr);
653 nfmater++;
654 }
655
656 // Dump all elements with MATERIAL cards
8495a208 657 for (i=0; i<nfmater; i++) {
89125dc7 658 mat = (TGeoMaterial*)fMatList->At(i);
659// mat->SetUsed(kFALSE);
660 mix = 0;
8495a208 661 out << setw(10) << "MATERIAL ";
662 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
89125dc7 663 objstr = (TObjString*)fMatNames->At(i);
b0853588 664 matname = objstr->GetString();
89125dc7 665 z = mat->GetZ();
666 a = mat->GetA();
667 rho = mat->GetDensity();
8495a208 668 if (mat->IsMixture()) {
669 out << setw(10) << " ";
670 out << setw(10) << " ";
671 mix = (TGeoMixture*)mat;
672 } else {
89125dc7 673 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << z;
674 out << setw(10) << setprecision(3) << a;
8495a208 675 }
676 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
89125dc7 677 out << setw(10) << setiosflags(ios::scientific) << setprecision(3) << rho;
8495a208 678 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
89125dc7 679 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(mat->GetIndex());
8495a208 680 out << setw(10) << " ";
efde9b4d 681 out << setw(10) << " ";
682 out << setw(8) << matname.Data() << endl;
89125dc7 683 if (!mix) {
684 // add LOW-MAT card for NEON to associate with ARGON neutron xsec
95161cd7 685 if (z==10) {
89125dc7 686 out << setw(10) << "LOW-MAT ";
687 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
688 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(mat->GetIndex());
689 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << 18.;
690 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << -2.;
691 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << 293.;
692 out << setw(10) << " ";
693 out << setw(10) << " ";
694// out << setw(8) << matname.Data() << endl;
695 out << setw(8) << " " << endl;
95161cd7 696 }
697 else {
698 element = table->GetElement((int)z);
699 TString elename = element->GetTitle();
700 ToFlukaString(elename);
701 if( matname.CompareTo( elename ) != 0 ) {
702 out << setw(10) << "LOW-MAT ";
703 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
704 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(mat->GetIndex());
705 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << z;
706 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << " ";
707 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << " ";
708 out << setw(10) << " ";
709 out << setw(10) << " ";
710 // missing material at Low Energy Cross Section Table
711 if( (int)z==10 || (int)z==21 || (int)z==34 || (int)z==37 || (int)z==39 || (int)z==44 ||
712 (int)z==45 || (int)z==46 || (int)z==52 || (int)z==57 || (int)z==59 || (int)z==60 ||
713 (int)z==61 || (int)z==65 || (int)z==66 || (int)z==67 || (int)z==68 || (int)z==69 ||
714 (int)z==70 || (int)z==71 || (int)z==72 || (int)z==76 || (int)z==77 || (int)z==78 ||
715 (int)z==81 || (int)z==84 || (int)z==85 || (int)z==86 || (int)z==87 || (int)z==88 ||
716 (int)z==89 || (int)z==91 )
717 out << setw(8) << "UNKNOWN " << endl;
718 else
719 out << setw(8) << elename.Data() << endl;
720 // out << setw(8) << " " << endl;
721 }
722 }
89125dc7 723 continue;
d11bf3ca 724 }
8495a208 725 counttothree = 0;
726 out << setw(10) << "COMPOUND ";
727 nelem = mix->GetNelements();
89125dc7 728 objstr = (TObjString*)fMatNames->At(i);
8495a208 729 matname = objstr->GetString();
8495a208 730 for (j=0; j<nelem; j++) {
89125dc7 731 w = (mix->GetWmixt())[j];
732 if (w<0.00001) w=0.00001;
733 z = (mix->GetZmixt())[j];
734 a = (mix->GetAmixt())[j];
735 idmat = GetElementIndex(Int_t(z));
736 if (!idmat) Error("CreateFlukaMatFile", "element with Z=%f not found", z);
8495a208 737 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
89125dc7 738 out << setw(10) << setiosflags(ios::fixed) << setprecision(6) << -w;
8495a208 739 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
740 out << setw(10) << setiosflags(ios::fixed) << setprecision(1) << Double_t(idmat);
741 counttothree++;
742 if (counttothree == 3) {
743 out << matname.Data();
744 out << endl;
745 if ( (j+1) != nelem) out << setw(10) << "COMPOUND ";
746 counttothree = 0;
89125dc7 747 }
748 }
8495a208 749 if (nelem%3) {
750 for (j=0; j<(3-(nelem%3)); j++)
751 out << setw(10) << " " << setw(10) << " ";
752 out << matname.Data();
753 out << endl;
89125dc7 754 }
755 }
8495a208 756 Int_t nvols = gGeoManager->GetListOfUVolumes()->GetEntriesFast()-1;
757 TGeoVolume *vol;
8495a208 758 // Now print the material assignments
d11bf3ca 759 Double_t flagfield = 0.;
760 printf("#############################################################\n");
89125dc7 761 if (gFluka->IsFieldEnabled()) {
d11bf3ca 762 flagfield = 1.;
763 printf("Magnetic field enabled\n");
764 } else printf("Magnetic field disabled\n");
765 printf("#############################################################\n");
766
8495a208 767 PrintHeader(out, "TGEO MATERIAL ASSIGNMENTS");
768 for (i=1; i<=nvols; i++) {
3860051a 769
8495a208 770 vol = gGeoManager->GetVolume(i);
771 mat = vol->GetMedium()->GetMaterial();
772 idmat = mat->GetIndex();
89125dc7 773 for (Int_t j=0; j<nfmater; j++) {
774 mat = (TGeoMaterial*)fMatList->At(j);
775 if (mat->GetIndex() == idmat) mat->SetUsed(kTRUE);
776 }
3860051a 777
778 Float_t hasfield = (vol->GetMedium()->GetParam(1) > 0) ? flagfield : 0.;
89aa6d28 779 out << "* Assigning material: " << vol->GetMedium()->GetMaterial()->GetName() << " to Volume: " << vol->GetName();
780 out << endl;
781
8495a208 782 out << setw(10) << "ASSIGNMAT ";
783 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
784 out << setw(10) << setiosflags(ios::fixed) << Double_t(idmat);
785 out << setw(10) << setiosflags(ios::fixed) << Double_t(i);
786 out << setw(10) << "0.0";
b0853588 787 out << setw(10) << "0.0";
3860051a 788 out << setw(10) << setiosflags(ios::fixed) << hasfield;
b0853588 789 out << setw(10) << "0.0";
8495a208 790 out << endl;
791 }
aae6bcdd 792 // dummy region
793 idmat = 2; // vacuum
794 fDummyRegion = nvols+1;
795 out << "* Dummy region: " << endl;
796 out << setw(10) << "ASSIGNMAT ";
797 out.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
798 out << setw(10) << setiosflags(ios::fixed) << idmat;
799 out << setw(10) << setiosflags(ios::fixed) << fDummyRegion;
800 out << setw(10) << "0.0";
801 out << setw(10) << "0.0";
802 out << setw(10) << "0.0";
803 out << setw(10) << "0.0" << endl;
8495a208 804 out.close();
efde9b4d 805 fLastMaterial = nfmater+2;
6d184c54 806}
807
808void TFlukaMCGeometry::CreatePemfFile()
809{
810 //
811 // Steering routine to write and process peg files producing the pemf input
812 //
813 char number[20];
814 Int_t countMatOK = 0;
815 Int_t countElemError = 0;
816 Int_t countNoStern = 0;
817 Int_t countMixError = 0;
818 Int_t countGas = 0;
819 Int_t countPemfError = 0;
820 Int_t i;
821 TGeoMaterial* mat = 0x0;
822 TString sname;
823
824 for (i = fIndmat; i < fLastMaterial - 2; i++) {
825 printf("Write Peg Files %d\n", i);
826
827 mat = (TGeoMaterial*)fMatList->At(i);
828 if (!mat->IsUsed()) continue;
829 sname = "mat";
830 sprintf(number, "%d", i);
831 sname.Append(number);
832 cout << endl;
833 cout << endl;
834 cout << "******************************************************************************" << endl;
835 cout << "******************************************************************************" << endl;
836 cout << endl;
837 WritePegFile(i, &countNoStern, &countElemError, &countMixError, &countGas);
838 sname.Prepend("$FLUPRO/pemf/rpemf peg/");
839 gSystem->Exec(sname.Data());
840
841 // check if the pemf file was created
842 TString sname = Form("peg/mat%d.pemf", i);
843 ifstream in( sname.Data() );
844 if ( in ) {
845 countMatOK++;
846 in.close();
847 } else {
848 cout << "ERROR Fail to create the pemf file " << sname << endl;
849 countPemfError++;
850 }
851 }
852 cout << "Materials (pemf created) " << countMatOK << endl;
853 cout << "Not Sternheimer par. found " << countNoStern << endl;
854 cout << "Elements with error definitions (Z not integer) " << countElemError << endl;
855 cout << "Mixtures with error definitions (Z not integer) " << countMixError << endl;
856 cout << "Posible Gas (rho < 0.01) " << countGas << endl;
857 // cout << "Posible Gas (without pressure information) " << countGasError << endl;
95161cd7 858 cout << "Pemf files Error " << countPemfError << endl;
6d184c54 859 cout << endl << endl;
860
861 sname = "cat peg/*.pemf > peg/FlukaVmc.pemf";
862 gSystem->Exec(sname.Data());
863 sname = "mv peg/FlukaVmc.pemf FlukaVmc.pemf";
864 gSystem->Exec(sname.Data());
89125dc7 865}
866
867//_____________________________________________________________________________
95161cd7 868void TFlukaMCGeometry::WritePegFile(Int_t imat, Int_t *NoStern, Int_t *ElemError,
869 Int_t *MixError, Int_t *countGas) const
89125dc7 870{
95161cd7 871 // Write the .peg file for one material
872
89125dc7 873 TGeoMaterial *mat = (TGeoMaterial*)fMatList->At(imat);
874 TString name = ((TObjString*)fMatNames->At(imat))->GetString();
875 TString line;
876 char number[20];
877 TGeoElement *elem = mat->GetElement();
878 name = name.Strip();
879 TString sname = "mat";
880 sprintf(number, "%d", imat);
881 sname.Append(number);
882 sname.Append(".peg");
883 sname.Prepend("peg/");
884 ofstream out;
885 out.open(sname.Data(), ios::out);
886 if (!out.good()) return;
887 Double_t dens = mat->GetDensity();
888 TGeoMixture *mix = 0;
889 Int_t nel = 1;
890 Int_t i;
891 if (mat->IsMixture()) {
892 mix = (TGeoMixture*)mat;
893 nel = mix->GetNelements();
95161cd7 894 }
895
89125dc7 896 if (nel==1) {
95161cd7 897 cout << "( Element ) " << name << " Z=" << mat->GetZ() << " Rho " << mat->GetDensity() << endl;
898
899 Double_t zel = mat->GetZ();
900 if( (zel-Int_t(zel))>0.001 || zel < 1 ) {
901 cout << " ERROR: A Element with not integer Z=" << zel << endl;
902 cout << endl;
903 (*ElemError)++;
904 return;
905 }
906
89125dc7 907 out << "ELEM" << endl;
908 out << " &INP IRAYL=1, RHO=" << dens << ", " << endl;
95161cd7 909
910 // check for the Sternheimer parameters
911 Double_t *issb_parm = GetISSB( mat->GetDensity(), 1, &zel, 0 );
912 if( issb_parm[0] > 0 && issb_parm[1] > 0 ) {
913 cout << "Sternheimer parameters found" << endl;
914 out << ", ISSB=1, IEV=" << issb_parm[0] << ", CBAR=" << issb_parm[1]
915 << ", X0=" << issb_parm[2] << "," << endl;
916 out << "X1=" <<issb_parm[3] <<", AFACT="<<issb_parm[4] <<", SK="
917 << issb_parm[5] << ", DELTA0=" << issb_parm[6];
918 }
919 else {
920 cout << "WARNING: Strange element, Sternheimer parameters not found" << endl;
921 (*NoStern)++;
922 }
923
924 if (dens<0.01) {
925 (*countGas)++;
926 out << " GASP=1." << endl;
927 }
928
89125dc7 929 out << " &END" << endl;
930 out << name.Data() << endl;
931 out << elem->GetName() << endl;
95161cd7 932
933 }
934 else {
935
936 cout << "( Mixture ) " << name << " Rho " << dens << " nElem " << nel << endl;
937
938 Double_t *zt = new Double_t[nel];
939 Double_t *wt = new Double_t[nel];
940 for (int j=0; j<nel; j++) {
941 zt[j] = (mix->GetZmixt())[j];
942 wt[j] = (mix->GetWmixt())[j];
943 if( (zt[j]-Int_t(zt[j])) > 0.001 || zt[j] < 1 ) {
944 cout << "ERROR Mixture " << name << " with an element with not integer Z=" << zt[j] << endl;
945 cout << endl;
946 (*MixError)++;
947 // just continue since the mixtures are not patch,
948 // but the final release should include the return
949 // return;
950 }
951 }
952 Double_t *issb_parm = GetISSB( mat->GetDensity(), nel, zt, wt );
89125dc7 953 out << "MIXT" << endl;
95161cd7 954 out << " &INP IRAYL=1, NE=" << nel << ", RHOZ=" << wt[0] << ",";
955 line = Form(" &INP IRAYL=1, NE=%d RHOZ=%g", nel, wt[0]);
956 for(int j=1; j<nel; j++) {
957 out << " " << wt[j] << ",";
958 line += Form(" %g,", wt[j] );
959 if( line.Length() > 60 ) { out << endl; line = ""; }
89125dc7 960 }
95161cd7 961 out << " RHO=" << mat->GetDensity() << ", ";
962 line += Form(" RHO=%g, ", mat->GetDensity());
963 if( line.Length() > 60 ) { out << endl; line = ""; }
964
965 if( issb_parm[0] > 0 && issb_parm[1] > 0 ) {
966 cout << "Sternheimer parameters found" << endl;
967 out << " ISSB=1, IEV=" << issb_parm[0] << ",";
968 line += Form(" ISSB=1, IEV=%g,", issb_parm[0]);
969 if( line.Length() > 60 ) { out << endl; line = ""; }
970 out << " CBAR=" << issb_parm[1] << ",";
971 line += Form(" CBAR=%g,",issb_parm[1]);
972 if( line.Length() > 60 ) { out << endl; line = ""; }
973 out << " X0=" << issb_parm[2] << ",";
974 line += Form(" X0=%g,", issb_parm[2]);
975 if( line.Length() > 60 ) { out << endl; line = ""; }
976 out << " X1=" << issb_parm[3] << ",";
977 line += Form(" X1=%g,", issb_parm[3]);
978 if( line.Length() > 60 ) { out << endl; line = ""; }
979 out << " AFACT="<< issb_parm[4] << ",";
980 line += Form(" AFACT=%g,", issb_parm[4]);
981 if( line.Length() > 60 ) { out << endl; line = ""; }
982 out << " SK=" << issb_parm[5] << ",";
983 line += Form(" SK=%g,", issb_parm[5]);
984 if( line.Length() > 60 ) { out << endl; line = ""; }
985 }
986 else {
987 cout << "Sternheimer parameters not found" << endl;
988 (*NoStern)++;
989 }
990
991 if (dens<0.01){
992 (*countGas)++;
993 out << " GASP=1." << endl;
994 }
995
996 out << " &END" << endl;
89125dc7 997 out << name.Data() << endl;
998 for (i=0; i<nel; i++) {
999 elem = mix->GetElement(i);
1000 line = elem->GetName();
1001 if (line.Length()==1) line.Append(" ");
1002 out << line.Data() << " ";
1003 }
1004 out << endl;
95161cd7 1005
1006 delete [] zt;
1007 delete [] wt;
89125dc7 1008 }
95161cd7 1009
6d184c54 1010 Double_t ue = 3000000.; // [MeV]
1011 Double_t up = 3000000.; // [MeV]
1012 Double_t ae = -1.;
1013 Double_t ap = -1.;
1014
1015
1016 TObjArray* cutList = ((TFluka*) gMC)->GetListOfUserConfigs();
1017 TIter next(cutList);
1018 TFlukaConfigOption* proc;
1019
1020 while((proc = (TFlukaConfigOption*)next()))
1021 {
1022 if (proc->Medium() == mat->GetIndex()) {
1023 ap = proc->Cut(kCUTGAM);
1024 ae = proc->Cut(kCUTELE);
1025 if (ap == -1.) ap = TFlukaConfigOption::DefaultCut(kCUTGAM);
1026 if (ae == -1.) ae = TFlukaConfigOption::DefaultCut(kCUTELE);
1027 break;
1028 }
1029 }
1030
1031 if (ap == -1.) ap = TFlukaConfigOption::DefaultCut(kCUTGAM);
1032 if (ae == -1.) ae = TFlukaConfigOption::DefaultCut(kCUTELE);
1033
1034 ap *= 1000.; // [MeV]
1035 ae = (ae + 0.00051099906) * 1000.; // [MeV]
1036
89125dc7 1037 out << "ENER" << endl;
6d184c54 1038 out << " $INP AE=" << ae << ", UE=" << ue <<", AP=" << ap << ", UP=" << up << " $END" << endl;
89125dc7 1039 out << "PWLF" << endl;
1040 out << " $INP NALE=300, NALG=400, NALR=100 $END" << endl;
1041 out << "DECK" << endl;
1042 out << " $INP $END" << endl;
1043 out << "TEST" << endl;
1044 out << " $INP $END" << endl;
1045 out.close();
8495a208 1046}
1047
95161cd7 1048Double_t * TFlukaMCGeometry::GetISSB(Double_t rho, Int_t nElem, Double_t *zelem, Double_t *welem ) const
1049{
1050 // Read the density effect parameters
1051 // from R.M. Sternheimer et al. Atomic Data
1052 // and Nuclear Data Tables, Vol. 30 No. 2
1053 //
1054 // return the parameters if the element/mixture match with one of the list
1055 // otherwise returns the parameters set to 0
1056
1057 struct sternheimerData {
1058 TString longname; // element/mixture name
1059 Int_t nelems; // number of constituents N
1060 Int_t Z[20]; //[nelems] Z
1061 Double_t wt[20]; //[nelems] weight fraction
1062 Double_t density; // g/cm3
1063 Double_t iev; // Average Ion potential (eV)
6d184c54 1064 // **** Sternheimer parameters ****
95161cd7 1065 Double_t cbar; // CBAR
1066 Double_t x0; // X0
1067 Double_t x1; // X1
1068 Double_t afact; // AFACT
1069 Double_t sk; // SK
1070 Double_t delta0; // DELTA0
1071 };
1072
1073 TString shortname;
1074 TString formula;
1075 Int_t num;
1076 char state;
1077
1078 static Double_t parameters[7];
1079 memset( parameters, 0, sizeof(Double_t) );
1080
1081 static sternheimerData sternDataArray[300];
1082 static Bool_t isFileRead = kFALSE;
1083
1084 // Read the data file if is needed
1085 if( isFileRead == kFALSE ) {
1086 TString sSternheimerInp = getenv("ALICE_ROOT");
1087 sSternheimerInp +="/TFluka/input/Sternheimer.data";
1088
1089 ifstream in(sSternheimerInp);
1090 char line[100];
1091 in.getline(line, 100);
1092 in.getline(line, 100);
1093 in.getline(line, 100);
1094 in.getline(line, 100);
1095 in.getline(line, 100);
1096 in.getline(line, 100);
1097
1098
1099 Int_t is = 0;
1100 while( !in.eof() ) {
1101 in >> shortname >> num >> sternDataArray[is].nelems
1102 >> sternDataArray[is].longname >> formula >> state;
1103 if( in.eof() ) break;
1104 for(int i=0; i<sternDataArray[is].nelems; i++) {
1105 in >> sternDataArray[is].Z[i] >> sternDataArray[is].wt[i];
1106 }
1107 in >> sternDataArray[is].density;
1108 in >> sternDataArray[is].iev;
1109 in >> sternDataArray[is].cbar;
1110 in >> sternDataArray[is].x0;
1111 in >> sternDataArray[is].x1;
1112 in >> sternDataArray[is].afact;
1113 in >> sternDataArray[is].sk;
1114 if( sternDataArray[is].nelems == 1 ) in >> sternDataArray[is].delta0;
1115 is++;
1116 }
1117 isFileRead = kTRUE;
1118 in.close();
1119 }
1120
1121 Int_t is = 0;
1122 while( is < 280 ) {
1123
1124 // check for elements
1125 if( sternDataArray[is].nelems == 1 && nElem == 1
1126 && sternDataArray[is].Z[0] == Int_t(*zelem)
1127 && TMath::Abs( (sternDataArray[is].density - rho)/sternDataArray[is].density ) < 0.1 ) {
1128 cout << sternDataArray[is].longname << " #elems:" << sternDataArray[is].nelems << " Rho:"
1129 << sternDataArray[is].density << endl;
1130 cout << sternDataArray[is].iev << " "
1131 << sternDataArray[is].cbar << " "
1132 << sternDataArray[is].x0 << " "
1133 << sternDataArray[is].x1 << " "
1134 << sternDataArray[is].afact << " "
1135 << sternDataArray[is].sk << " "
1136 << sternDataArray[is].delta0 << endl;
1137
1138 parameters[0] = sternDataArray[is].iev;
1139 parameters[1] = sternDataArray[is].cbar;
1140 parameters[2] = sternDataArray[is].x0;
1141 parameters[3] = sternDataArray[is].x1;
1142 parameters[4] = sternDataArray[is].afact;
1143 parameters[5] = sternDataArray[is].sk;
1144 parameters[6] = sternDataArray[is].delta0;
1145 return parameters;
1146 }
1147
1148 // check for mixture
1149 int nmatch = 0;
1150 if( sternDataArray[is].nelems > 1 && sternDataArray[is].nelems == nElem ) {
1151 for(int j=0; j<sternDataArray[is].nelems; j++) {
1152 if( sternDataArray[is].Z[j] == Int_t(zelem[j]) &&
1153 TMath::Abs( (sternDataArray[is].wt[j] - welem[j])/sternDataArray[is].wt[j] ) < 0.1 )
1154 nmatch++;
1155 }
1156 }
1157
1158 if( sternDataArray[is].nelems > 1 &&
1159 TMath::Abs( (sternDataArray[is].density - rho)/sternDataArray[is].density ) < 0.1
1160 && nmatch == sternDataArray[is].nelems ) {
1161 cout << sternDataArray[is].longname << " #elem:" << sternDataArray[is].nelems << " Rho:"
1162 << sternDataArray[is].density << endl;
1163 cout << sternDataArray[is].iev << " "
1164 << sternDataArray[is].cbar << " "
1165 << sternDataArray[is].x0 << " "
1166 << sternDataArray[is].x1 << " "
1167 << sternDataArray[is].afact << " "
1168 << sternDataArray[is].sk << " "
1169 << sternDataArray[is].delta0 << endl;
1170
1171 parameters[0] = sternDataArray[is].iev;
1172 parameters[1] = sternDataArray[is].cbar;
1173 parameters[2] = sternDataArray[is].x0;
1174 parameters[3] = sternDataArray[is].x1;
1175 parameters[4] = sternDataArray[is].afact;
1176 parameters[5] = sternDataArray[is].sk;
1177 parameters[6] = 0;
1178 return parameters;
1179 }
1180 is++;
1181 }
1182 return parameters;
1183}
1184
8495a208 1185//_____________________________________________________________________________
1186void TFlukaMCGeometry::PrintHeader(ofstream &out, const char *text) const
1187{
1188// Print a FLUKA header.
1189 out << "*\n" << "*\n" << "*\n";
1190 out << "********************* " << text << " *********************\n"
1191 << "*\n";
1192 out << "*...+....1....+....2....+....3....+....4....+....5....+....6....+....7..."
1193 << endl;
1194 out << "*" << endl;
1195}
1196
1197//_____________________________________________________________________________
1198Int_t TFlukaMCGeometry::RegionId() const
1199{
1200// Returns current region id <-> TGeo node id
1201 if (gGeoManager->IsOutside()) return 0;
1202 return gGeoManager->GetCurrentNode()->GetUniqueID();
1203}
89125dc7 1204
1205//_____________________________________________________________________________
1206Int_t TFlukaMCGeometry::GetElementIndex(Int_t z) const
1207{
6f5667d1 1208// Get index of a material having a given Z element.
89125dc7 1209 TIter next(fMatList);
1210 TGeoMaterial *mat;
1211 Int_t index = 0;
1212 while ((mat=(TGeoMaterial*)next())) {
1213 if (mat->IsMixture()) continue;
1214 if (mat->GetElement()->Z() == z) return mat->GetIndex();
1215 }
1216 return index;
1217}
1218
05265ca9 1219//_____________________________________________________________________________
aae6bcdd 1220void TFlukaMCGeometry::SetMreg(Int_t mreg, Int_t lttc)
05265ca9 1221{
1222// Update if needed next history;
aae6bcdd 1223// if (gFluka->GetDummyBoundary()==2) {
1224// gGeoManager->CdNode(fNextLattice-1);
1225// return;
1226// }
1227 if (lttc == TFlukaMCGeometry::kLttcOutside) {
1228 fCurrentRegion = NofVolumes()+2;
1229 fCurrentLattice = lttc;
1230 gGeoManager->CdTop();
1231 gGeoManager->SetOutside(kTRUE);
1232 }
1233 if (lttc == TFlukaMCGeometry::kLttcVirtual) return;
1234 if (lttc <=0) {
1235 Error("TFlukaMCGeometry::SetMreg","Invalide lattice %i",lttc);
05265ca9 1236 return;
aae6bcdd 1237 }
1238 fCurrentRegion = mreg;
1239 fCurrentLattice = lttc;
1240
1241 Int_t crtlttc = gGeoManager->GetCurrentNodeId()+1;
1242 if (crtlttc == lttc) return;
1243 gGeoManager->CdNode(lttc-1);
05265ca9 1244}
1245
1246//_____________________________________________________________________________
d11bf3ca 1247void TFlukaMCGeometry::SetCurrentRegion(Int_t mreg, Int_t latt)
1248{
1249// Set index/history for next entered region
1250 fCurrentRegion = mreg;
1251 fCurrentLattice = latt;
1252}
1253
1254//_____________________________________________________________________________
05265ca9 1255void TFlukaMCGeometry::SetNextRegion(Int_t mreg, Int_t latt)
1256{
1257// Set index/history for next entered region
1258 fNextRegion = mreg;
1259 fNextLattice = latt;
1260}
8495a208 1261
1262//_____________________________________________________________________________
1263void TFlukaMCGeometry::ToFlukaString(TString &str) const
1264{
1265// ToFlukaString converts an string to something usefull in FLUKA:
1266// * Capital letters
1267// * Only 8 letters
1268// * Replace ' ' by '_'
1269 if (str.Length()<8) {
1270 str += " ";
1271 }
1272 str.Remove(8);
1273 Int_t ilast;
1274 for (ilast=7; ilast>0; ilast--) if (str(ilast)!=' ') break;
1275 str.ToUpper();
1276 for (Int_t pos=0; pos<ilast; pos++)
1277 if (str(pos)==' ') str.Replace(pos,1,"_",1);
1278 return;
1279}
89125dc7 1280
1281//_____________________________________________________________________________
1282void TFlukaMCGeometry::FlukaMatName(TString &str) const
1283{
81f1d030 1284// Strip the detector name
1285
1286 TObjArray * tokens = str.Tokenize("_");
1287 Int_t ntok = tokens->GetEntries();
1288 if (ntok > 0) {
1289 TString head = ((TObjString*) tokens->At(0))->GetString();
1290 Int_t nhead = head.Length();
1291 str = str.Remove(0, nhead + 1);
1292 }
1293 tokens->Clear();
1294 delete tokens;
1295
6f5667d1 1296// Convert a name to upper case 8 chars.
89125dc7 1297 ToFlukaString(str);
1298 Int_t ilast;
1299 for (ilast=7; ilast>0; ilast--) if (str(ilast)!=' ') break;
1300 if (ilast>5) ilast = 5;
1301 char number[3];
1302 TIter next(fMatNames);
1303 TObjString *objstr;
1304 TString matname;
1305 Int_t index = 0;
1306 while ((objstr=(TObjString*)next())) {
1307 matname = objstr->GetString();
1308 if (matname == str) {
1309 index++;
1310 if (index<10) {
1311 number[0] = '0';
1312 sprintf(&number[1], "%d", index);
1313 } else if (index<100) {
1314 sprintf(number, "%d", index);
1315 } else {
1316 Error("FlukaMatName", "Too many materials %s", str.Data());
1317 return;
1318 }
1319 str.Replace(ilast+1, 2, number);
1320 str.Remove(8);
1321 }
1322 }
1323}
1324
8495a208 1325//______________________________________________________________________________
1326void TFlukaMCGeometry::Vname(const char *name, char *vname) const
1327{
1328 //
1329 // convert name to upper case. Make vname at least 4 chars
1330 //
1331 Int_t l = strlen(name);
1332 Int_t i;
1333 l = l < 4 ? l : 4;
1334 for (i=0;i<l;i++) vname[i] = toupper(name[i]);
1335 for (i=l;i<4;i++) vname[i] = ' ';
1336 vname[4] = 0;
1337}
1338
1339
81f1d030 1340
8495a208 1341// FLUKA GEOMETRY WRAPPERS - to replace FLUGG wrappers
1342
1343//_____________________________________________________________________________
8495a208 1344Int_t idnrwr(const Int_t & /*nreg*/, const Int_t & /*mlat*/)
1345{
1346// from FLUGG:
1347// Wrapper for setting DNEAR option on fluka side. Must return 0
1348// if user doesn't want Fluka to use DNEAR to compute the
1349// step (the same effect is obtained with the GLOBAL (WHAT(3)=-1)
1350// card in fluka input), returns 1 if user wants Fluka always to
1351// use DNEAR (in this case, be sure that GEANT4 DNEAR is unique,
1352// coming from all directions!!!)
89125dc7 1353 if (gMCGeom->IsDebugging()) printf("========== Dummy IDNRWR\n");
8495a208 1354 return 0;
1355}
1356
1357//_____________________________________________________________________________
8495a208 1358void g1wr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
d11bf3ca 1359 Double_t *pV, Int_t &oldReg , const Int_t &oldLttc, Double_t &propStep,
cefd9d9b 1360 Int_t &/*nascFlag*/, Double_t &retStep, Int_t &newReg,
2573ac89 1361 Double_t &saf, Int_t &newLttc, Int_t &lttcFlag,
8495a208 1362 Double_t *sLt, Int_t *jrLt)
d11bf3ca 1363
8495a208 1364{
d11bf3ca 1365 // Initialize FLUKa point and direction;
6f5667d1 1366 gNstep++;
784c3bdd 1367 NORLAT.xn[0] = pSx;
1368 NORLAT.xn[1] = pSy;
1369 NORLAT.xn[2] = pSz;
8495a208 1370
a940d455 1371 Int_t olttc = oldLttc;
81f1d030 1372 if (oldLttc<=0) {
a940d455 1373 gGeoManager->FindNode(pSx,pSy,pSz);
1374 olttc = gGeoManager->GetCurrentNodeId()+1;
2bc4c610 1375 }
81f1d030 1376 Int_t ccreg,cclat;
1377 gMCGeom->GetCurrentRegion(ccreg,cclat);
aae6bcdd 1378 Bool_t crossed = (ccreg==oldReg && cclat==oldLttc)?kFALSE:kTRUE;
a940d455 1379 gMCGeom->SetCurrentRegion(oldReg, olttc);
d11bf3ca 1380 // Initialize default return values
1381 lttcFlag = 0;
a940d455 1382 jrLt[lttcFlag] = olttc;
d11bf3ca 1383 sLt[lttcFlag] = propStep;
1384 jrLt[lttcFlag+1] = -1;
1385 sLt[lttcFlag+1] = 0.;
1386 newReg = oldReg;
a940d455 1387 newLttc = olttc;
aae6bcdd 1388 Bool_t crossedDummy = (oldReg == gFluka->GetDummyRegion())?kTRUE:kFALSE;
d11bf3ca 1389 Int_t curLttc, curReg;
aae6bcdd 1390 if (crossedDummy) {
1391 // FLUKA crossed the dummy boundary - update new region/history
1392 retStep = TGeoShape::Tolerance();
1393 saf = 0.;
1394 gMCGeom->GetNextRegion(newReg, newLttc);
1395 gMCGeom->SetMreg(newReg, newLttc);
1396 sLt[lttcFlag] = TGeoShape::Tolerance(); // null step in current region
1397 lttcFlag++;
1398 jrLt[lttcFlag] = newLttc;
1399 sLt[lttcFlag] = TGeoShape::Tolerance(); // null step in next region
1400 jrLt[lttcFlag+1] = -1;
1401 sLt[lttcFlag+1] = 0.; // null step in next region;
1402 return;
d11bf3ca 1403 }
1404
1405 // Reset outside flag
cefd9d9b 1406 gGeoManager->SetOutside(kFALSE);
d11bf3ca 1407
d11bf3ca 1408 curLttc = gGeoManager->GetCurrentNodeId()+1;
1409 curReg = gGeoManager->GetCurrentVolume()->GetNumber();
a940d455 1410 if (olttc != curLttc) {
d11bf3ca 1411 // FLUKA crossed the boundary : we trust that the given point is really there,
1412 // so we just update TGeo state
a940d455 1413 gGeoManager->CdNode(olttc-1);
2573ac89 1414 curLttc = gGeoManager->GetCurrentNodeId()+1;
d11bf3ca 1415 curReg = gGeoManager->GetCurrentVolume()->GetNumber();
d11bf3ca 1416 }
784c3bdd 1417 // Now the current TGeo state reflects the FLUKA state
784c3bdd 1418
aae6bcdd 1419 gGeoManager->SetCurrentPoint(pSx, pSy, pSz);
cefd9d9b 1420 gGeoManager->SetCurrentDirection(pV);
aae6bcdd 1421
1422 if (crossed) {
1423 gGeoManager->FindNextBoundaryAndStep(propStep);
1424 saf = 0.0;
1425 } else {
1426 gGeoManager->FindNextBoundaryAndStep(propStep, kTRUE);
1427 saf = gGeoManager->GetSafeDistance();
1428 if (saf<0) saf=0.0;
1429 saf -= saf*3.0e-09;
1430 }
1431
d11bf3ca 1432 Double_t snext = gGeoManager->GetStep();
784c3bdd 1433
aae6bcdd 1434 if (snext<=0.0) snext = TGeoShape::Tolerance();
1435
81f1d030 1436 PAREM.dist = snext;
784c3bdd 1437 NORLAT.distn = snext;
1438 NORLAT.xn[0] += snext*pV[0];
1439 NORLAT.xn[1] += snext*pV[1];
1440 NORLAT.xn[2] += snext*pV[2];
aae6bcdd 1441 if (!gGeoManager->IsOnBoundary()) {
d11bf3ca 1442 // Next boundary further than proposed step, which is approved
aae6bcdd 1443 if (saf>propStep) saf = propStep;
d11bf3ca 1444 retStep = propStep;
1445 sLt[lttcFlag] = propStep;
1446 return;
1447 }
aae6bcdd 1448 if (saf>snext) saf = snext; // Safety should be less than the proposed step if a boundary will be crossed
cefd9d9b 1449 gGeoManager->SetCurrentPoint(pSx,pSy,pSz);
d11bf3ca 1450 newLttc = (gGeoManager->IsOutside())?(TFlukaMCGeometry::kLttcOutside):gGeoManager->GetCurrentNodeId()+1;
aae6bcdd 1451 newReg = (gGeoManager->IsOutside())?(gMCGeom->NofVolumes()+2):gGeoManager->GetCurrentVolume()->GetNumber();
89125dc7 1452 if (gMCGeom->IsDebugging()) printf(" newReg=%i newLttc=%i\n", newReg, newLttc);
d11bf3ca 1453
1454 // We really crossed the boundary, but is it the same region ?
89125dc7 1455 gMCGeom->SetNextRegion(newReg, newLttc);
aae6bcdd 1456
1457 Int_t pid = TRACKR.jtrack;
1458 if (newReg==oldReg && newLttc!=olttc && pid!=-1) {
d11bf3ca 1459 // Virtual boundary between replicants
aae6bcdd 1460 newReg = gFluka->GetDummyRegion();
d11bf3ca 1461 newLttc = TFlukaMCGeometry::kLttcVirtual;
d11bf3ca 1462 }
aae6bcdd 1463
d11bf3ca 1464 retStep = snext;
1465 sLt[lttcFlag] = snext;
1466 lttcFlag++;
1467 jrLt[lttcFlag] = newLttc;
1468 sLt[lttcFlag] = snext;
1469 jrLt[lttcFlag+1] = -1;
1470 sLt[lttcFlag+1] = 0.;
aae6bcdd 1471 if (gGeoManager->IsOutside()) gGeoManager->SetOutside(kFALSE);
89125dc7 1472 if (gMCGeom->IsDebugging()) {
d11bf3ca 1473 printf("=> snext=%g safe=%g\n", snext, saf);
1474 for (Int_t i=0; i<lttcFlag+1; i++) printf(" jrLt[%i]=%i sLt[%i]=%g\n", i,jrLt[i],i,sLt[i]);
1475 }
8495a208 1476}
1477
efde9b4d 1478//_____________________________________________________________________________
1479void g1rtwr()
1480{
89125dc7 1481 if (gMCGeom->IsDebugging()) printf("========== Dummy G1RTWR\n");
efde9b4d 1482}
1483
1484//_____________________________________________________________________________
1485void conhwr(Int_t & /*intHist*/, Int_t * /*incrCount*/)
1486{
89125dc7 1487 if (gMCGeom->IsDebugging()) printf("========== Dummy CONHWR\n");
efde9b4d 1488}
1489
1490//_____________________________________________________________________________
2573ac89 1491void inihwr(Int_t &intHist)
efde9b4d 1492{
89125dc7 1493 if (gMCGeom->IsDebugging()) printf("========== Inside INIHWR -> reinitializing history: %i\n", intHist);
2573ac89 1494 if (gGeoManager->IsOutside()) gGeoManager->CdTop();
1495 if (intHist<=0) {
1496// printf("=== wrong history number\n");
1497 return;
1498 }
1499 if (intHist==0) gGeoManager->CdTop();
1500 else gGeoManager->CdNode(intHist-1);
89125dc7 1501 if (gMCGeom->IsDebugging()) {
2bc4c610 1502 printf(" --- current path: %s\n", gGeoManager->GetPath());
1503 printf("<= INIHWR\n");
1504 }
efde9b4d 1505}
1506
1507//_____________________________________________________________________________
1508void jomiwr(const Int_t & /*nge*/, const Int_t & /*lin*/, const Int_t & /*lou*/,
1509 Int_t &flukaReg)
1510{
1511// Geometry initialization wrapper called by FLUKAM. Provides to FLUKA the
1512// number of regions (volumes in TGeo)
1513 // build application geometry
89125dc7 1514 if (gMCGeom->IsDebugging()) printf("========== Inside JOMIWR\n");
aae6bcdd 1515 flukaReg = gGeoManager->GetListOfUVolumes()->GetEntriesFast()+1;
89125dc7 1516 if (gMCGeom->IsDebugging()) printf("<= JOMIWR: last region=%i\n", flukaReg);
efde9b4d 1517}
1518
1519//_____________________________________________________________________________
1520void lkdbwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
784c3bdd 1521 Double_t *pV, const Int_t &oldReg, const Int_t &oldLttc,
aae6bcdd 1522 Int_t &flagErr, Int_t &newReg, Int_t &newLttc)
efde9b4d 1523{
89125dc7 1524 if (gMCGeom->IsDebugging()) {
2bc4c610 1525 printf("========== Inside LKDBWR (%f, %f, %f)\n",pSx, pSy, pSz);
784c3bdd 1526 printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
2bc4c610 1527 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1528 }
aae6bcdd 1529 lkwr(pSx,pSy,pSz,pV,oldReg,oldLttc,flagErr,newReg,newLttc);
efde9b4d 1530}
1531
1532//_____________________________________________________________________________
1533void lkfxwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
784c3bdd 1534 Double_t *pV, const Int_t &oldReg, const Int_t &oldLttc,
aae6bcdd 1535 Int_t &flagErr, Int_t &newReg, Int_t &newLttc)
efde9b4d 1536{
89125dc7 1537 if (gMCGeom->IsDebugging()) {
2bc4c610 1538 printf("========== Inside LKFXWR (%f, %f, %f)\n",pSx, pSy, pSz);
784c3bdd 1539 printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
2bc4c610 1540 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1541 }
aae6bcdd 1542 lkwr(pSx,pSy,pSz,pV,oldReg,oldLttc,flagErr,newReg,newLttc);
efde9b4d 1543}
1544
1545//_____________________________________________________________________________
1546void lkmgwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
784c3bdd 1547 Double_t *pV, const Int_t &oldReg, const Int_t &oldLttc,
efde9b4d 1548 Int_t &flagErr, Int_t &newReg, Int_t &newLttc)
1549{
89125dc7 1550 if (gMCGeom->IsDebugging()) {
2bc4c610 1551 printf("========== Inside LKMGWR (%f, %f, %f)\n",pSx, pSy, pSz);
784c3bdd 1552 printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
2bc4c610 1553 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1554 }
aae6bcdd 1555 lkwr(pSx,pSy,pSz,pV,oldReg,oldLttc,flagErr,newReg,newLttc);
efde9b4d 1556}
1557
1558//_____________________________________________________________________________
1559void lkwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
784c3bdd 1560 Double_t *pV, const Int_t &oldReg, const Int_t &oldLttc,
aae6bcdd 1561 Int_t &flagErr, Int_t &newReg, Int_t &newLttc)
efde9b4d 1562{
89125dc7 1563 if (gMCGeom->IsDebugging()) {
2bc4c610 1564 printf("========== Inside LKWR (%f, %f, %f)\n",pSx, pSy, pSz);
784c3bdd 1565 printf(" in: pV=(%f, %f, %f)\n", pV[0], pV[1], pV[2]);
2bc4c610 1566 printf(" in: oldReg=%i oldLttc=%i\n", oldReg, oldLttc);
1567 }
aae6bcdd 1568 flagErr = 0;
efde9b4d 1569 TGeoNode *node = gGeoManager->FindNode(pSx, pSy, pSz);
1570 if (gGeoManager->IsOutside()) {
aae6bcdd 1571 newReg = gMCGeom->NofVolumes()+2;
1572 newLttc = TFlukaMCGeometry::kLttcOutside;
05265ca9 1573 return;
efde9b4d 1574 }
1575 newReg = node->GetVolume()->GetNumber();
d11bf3ca 1576 newLttc = gGeoManager->GetCurrentNodeId()+1;
aae6bcdd 1577 if (oldLttc==TFlukaMCGeometry::kLttcOutside || oldLttc==0) return;
1578
1579 Int_t dummy = gFluka->GetDummyRegion();
1580 if (oldReg==dummy) {
1581 Int_t newreg1, newlttc1;
1582 gMCGeom->GetNextRegion(newreg1, newlttc1);
1583 if (newreg1==newReg && newlttc1==newLttc) {
1584 newReg = dummy;
1585 newLttc = TFlukaMCGeometry::kLttcVirtual;
1586 }
1587 return;
1588 }
1589
1590 if (oldReg==newReg && oldLttc!=newLttc) {
1591 newReg = gFluka->GetDummyRegion();
1592 newLttc = TFlukaMCGeometry::kLttcVirtual;
1593 }
1594
89125dc7 1595 if (gMCGeom->IsDebugging()) {
aae6bcdd 1596 printf(" LKWR: newReg=%i newLttc=%i\n", newReg, newLttc);
2bc4c610 1597 }
efde9b4d 1598}
1599
1600//_____________________________________________________________________________
2573ac89 1601void nrmlwr(Double_t &pSx, Double_t &pSy, Double_t &pSz,
1602 Double_t &pVx, Double_t &pVy, Double_t &pVz,
1603 Double_t *norml, const Int_t &oldReg,
1604 const Int_t &newReg, Int_t &flagErr)
efde9b4d 1605{
89125dc7 1606 if (gMCGeom->IsDebugging()) {
2bc4c610 1607 printf("========== Inside NRMLWR (%g, %g, %g, %g, %g, %g)\n", pSx,pSy,pSz,pVx,pVy,pVz);
1608 printf(" oldReg=%i, newReg=%i\n", oldReg,newReg);
1609 }
784c3bdd 1610 gGeoManager->SetCurrentPoint(NORLAT.xn[0], NORLAT.xn[1], NORLAT.xn[2]);
aae6bcdd 1611 gGeoManager->SetCurrentDirection(pVx, pVy, pVz);
2573ac89 1612 Double_t *dnorm = gGeoManager->FindNormalFast();
1613 flagErr = 0;
1614 if (!dnorm) {
1615 printf(" ERROR: Cannot compute fast normal\n");
1616 flagErr = 1;
1617 norml[0] = -pVx;
1618 norml[1] = -pVy;
1619 norml[2] = -pVz;
aae6bcdd 1620 } else {
1621 norml[0] = -dnorm[0];
1622 norml[1] = -dnorm[1];
1623 norml[2] = -dnorm[2];
1624 }
89125dc7 1625 if (gMCGeom->IsDebugging()) {
784c3bdd 1626 printf(" normal to boundary: (%g, %g, %g)\n", norml[0], norml[1], norml[2]);
2bc4c610 1627 printf("<= NRMLWR\n");
1628 }
efde9b4d 1629}
1630
1631//_____________________________________________________________________________
1632void rgrpwr(const Int_t & /*flukaReg*/, const Int_t & /*ptrLttc*/, Int_t & /*g4Reg*/,
1633 Int_t * /*indMother*/, Int_t * /*repMother*/, Int_t & /*depthFluka*/)
1634{
89125dc7 1635 if (gMCGeom->IsDebugging()) printf("=> Dummy RGRPWR\n");
efde9b4d 1636}
1637
1638//_____________________________________________________________________________
1639Int_t isvhwr(const Int_t &check, const Int_t & intHist)
1640{
1641// from FLUGG:
1642// Wrapper for saving current navigation history (fCheck=default)
1643// and returning its pointer. If fCheck=-1 copy of history pointed
1644// by intHist is made in NavHistWithCount object, and its pointer
1645// is returned. fCheck=1 and fCheck=2 cases are only in debugging
1646// version: an array is created by means of FGeometryInit functions
1647// (but could be a static int * ptrArray = new int[10000] with
1648// file scope as well) that stores a flag for deleted/undeleted
1649// histories and at the end of event is checked to verify that
1650// all saved history objects have been deleted.
1651
1652// For TGeo, just return the current node ID. No copy need to be made.
1653
89125dc7 1654 if (gMCGeom->IsDebugging()) printf("=> Inside ISVHWR\n");
efde9b4d 1655 if (check<0) return intHist;
2573ac89 1656 Int_t histInt = gGeoManager->GetCurrentNodeId()+1;
89125dc7 1657 if (gMCGeom->IsDebugging()) printf("<= ISVHWR: history is: %i in: %s\n", histInt, gGeoManager->GetPath());
efde9b4d 1658 return histInt;
1659}
1660
1661
8495a208 1662
1663