First implementation. Needs cleanup.
[u/mrichter/AliRoot.git] / Flugg / WrapLookFX.cxx
CommitLineData
26911512 1
2// Flugg tag
3
4///////////////////////////////////////////////////////////////////
5//
6// WrapLookFX.hh - Sara Vanini - 24/III/00
7//
8// Wrapper for localisation of particle to fix particular conditions.
9// At the moment is the same as WrapLookZ.hh.
10//
11// modified 24.10.01: by I. Hrivnacova
12// functions declarations separated from implementation
13// (moved to Wrappers.hh);
14// modified 17/06/02: by I. Gonzalez. STL migration
15//
16//////////////////////////////////////////////////////////////////
17
18
19#include "Wrappers.hh"
20#include "FGeometryInit.hh"
21#include "G4VPhysicalVolume.hh"
22#include "FluggNavigator.hh"
23#include "G4ThreeVector.hh"
24#include "G4PhysicalVolumeStore.hh"
25#include "globals.hh"
26
27#define G4GEOMETRY_DEBUG 1
28
29void lkfxwr(G4double& pSx, G4double& pSy, G4double& pSz,
30 G4double* pV, const G4int& oldReg, const G4int& oldLttc,
31 G4int& newReg, G4int& flagErr, G4int& newLttc)
32{
33 //flag
34#ifdef G4GEOMETRY_DEBUG
35 G4cout << "======= LKFXWR =======" << G4endl;
36#endif
37
38 //FGeometryInit, navigator, volumeStore pointers
39 static FGeometryInit * ptrGeoInit = FGeometryInit::GetInstance();
40 FluggNavigator * ptrNavig = ptrGeoInit->getNavigatorForTracking();
41 G4PhysicalVolumeStore * pVolStore = G4PhysicalVolumeStore::GetInstance();
42
43 //coordinates in mm.
44 G4ThreeVector pSource(pSx,pSy,pSz);
45 pSource *= 10.0; //in millimeters!
46
47 //locate point and update histories
48 G4TouchableHistory * ptrTouchableHistory =
49 ptrGeoInit->GetTouchableHistory();
50 ptrNavig->LocateGlobalPointAndUpdateTouchable(pSource,0,
51 ptrTouchableHistory,true);
52 //updating tmp but not old histories, they are useful in
53 //case of RGRPWR call, or when fluka, after a LOOKZ call,
54 //descards step for multiple scattering and returns to old history
55 //NO, after lattice-fix we don't need old history anymore!
56
57 ptrGeoInit->UpdateHistories(ptrTouchableHistory->GetHistory(),0);
58 G4VPhysicalVolume * located = ptrTouchableHistory->GetVolume();
59
60 //if volume not found, out of mother volume: returns "number of volumes"+1
61 if(!located) {
62#ifdef G4GEOMETRY_DEBUG
63 G4cout << "Out of mother volume!";
64#endif
65 G4int numVol = G4int(pVolStore->size());
66 newReg = numVol + 1;
67 }
68 else {
69#ifdef G4GEOMETRY_DEBUG
70 G4cout << "* ISVHWR call to store current NavHistWithCount in jrLtGeant"
71 << G4endl;
72#endif
73
74 //save history in jrLtGeant and increment counter
75 G4int * jrLtGeant = ptrGeoInit->GetJrLtGeantArray();
76 G4int LttcFlagGeant = ptrGeoInit->GetLttcFlagGeant();
77 LttcFlagGeant += 1;
78 jrLtGeant[LttcFlagGeant] = isvhwr(0,0);
79
80#ifdef G4GEOMETRY_DEBUG
81 G4cout << "* CONHWR call to increment counter" << G4endl;
82#endif
83 G4int incrCount=1;
84 conhwr(jrLtGeant[LttcFlagGeant],&incrCount);
85
86 //update LttcFlagGeant
87 ptrGeoInit->SetLttcFlagGeant(LttcFlagGeant);
88
89 //return region number and dummy variables
90 G4int volIndex = ~0;
91 for (unsigned int i=0; i<pVolStore->size(); i++)
92 if ((*pVolStore)[i] == located)
93 volIndex = i;
94 // G4int volIndex=G4int(pVolStore->index(located));
95 if (volIndex==(~0)) {
96 G4cerr << "FLUGG: Problem in file WrapLookFX trying to find volume after step" << G4endl;
97 exit(-999);
98 }
99 //G4int volIndex=G4int(pVolStore->index(located));
100 newReg=volIndex+1;
101 newLttc=jrLtGeant[LttcFlagGeant];
102 flagErr=newReg;
103#ifdef G4GEOMETRY_DEBUG
104 G4cout << "LKFXWR Located Physical volume = ";
105 G4cout << located->GetName() << G4endl;
106#endif
107 }
108}
109
110
111
112