]> git.uio.no Git - u/mrichter/AliRoot.git/blob - Flugg/source/Wrappers/src/WrapLookZ.cc
1965ea5963e1d8fca0f4959f7c4b2eeb1111a662
[u/mrichter/AliRoot.git] / Flugg / source / Wrappers / src / WrapLookZ.cc
1 // $Id$
2 // Flugg tag $Name$
3
4 ///////////////////////////////////////////////////////////////////
5 //
6 // WrapLookZ.hh - Sara Vanini 
7 //
8 // Wrapper for localisation of starting point of particle.
9 //
10 // modified 20/III/00: history initialization moved to ISVHWR
11 // modified 13/IV/00: located history saved in jrLtcGeant and 
12 //                    incremented
13 // modified 24.10.01: by I. Hrivnacova
14 //   functions declarations separated from implementation
15 //   (moved to Wrappers.hh);
16 //
17 //////////////////////////////////////////////////////////////////
18
19
20 #include "Wrappers.hh"
21 #include "FGeometryInit.hh"
22 #include "G4VPhysicalVolume.hh"
23 #include "G4Navigator.hh"
24 #include "G4ThreeVector.hh"
25 #include "G4PhysicalVolumeStore.hh"
26 #include "globals.hh"
27
28 void lkwr(G4double& pSx, G4double& pSy, G4double& pSz,
29           G4double* pV, const G4int& oldReg, const G4int& oldLttc,
30           G4int& newReg, G4int& flagErr, G4int& newLttc)
31 {
32 //flag
33 #ifdef G4GEOMETRY_DEBUG
34     G4cout<<"======= LKWR ======="<<G4endl;
35 #endif
36
37 //FGeometryInit, navigator, volumeStore  pointers
38     static FGeometryInit * ptrGeoInit = FGeometryInit::GetInstance();
39     G4Navigator * ptrNavig = ptrGeoInit->getNavigatorForTracking();
40     G4PhysicalVolumeStore * pVolStore = G4PhysicalVolumeStore::GetInstance();
41
42 //coordinates in mm.
43     G4ThreeVector pSource(pSx,pSy,pSz);
44     pSource *= 10.0; //in millimeters!
45
46 //locate point and update histories
47     G4TouchableHistory * ptrTouchableHistory = 
48                   ptrGeoInit->GetTouchableHistory();
49     ptrNavig->LocateGlobalPointAndUpdateTouchable(pSource,0,
50                                                   ptrTouchableHistory,true);
51     //updating tmp but not old histories, they are useful in 
52     //case of RGRPWR call, or when fluka, after a LOOKZ call, 
53     //descards step for multiple scattering and returns to old history
54     //NO, after lattice-fix we don't need old history anymore!
55
56     ptrGeoInit->UpdateHistories(ptrTouchableHistory->GetHistory(),0);
57     G4VPhysicalVolume * located = ptrTouchableHistory->GetVolume();
58
59 //if volume not found, out of mother volume: returns "number of volumes"+1
60     if(!located)
61       {
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       { 
70 #ifdef G4GEOMETRY_DEBUG
71         G4cout<<"* ISVHWR call to store current NavHistWithCount in jrLtGeant"
72           <<G4endl;
73 #endif 
74
75         //save history in jrLtGeant and increment counter  
76         G4int * jrLtGeant = ptrGeoInit->GetJrLtGeantArray();
77         G4int LttcFlagGeant = ptrGeoInit->GetLttcFlagGeant();
78         LttcFlagGeant += 1;
79         jrLtGeant[LttcFlagGeant] = isvhwr(0,0);
80
81 #ifdef G4GEOMETRY_DEBUG
82         G4cout<<"* CONHWR call to increment counter"<<G4endl;
83 #endif 
84         G4int incrCount=1;
85         conhwr(jrLtGeant[LttcFlagGeant],&incrCount);
86
87         //update LttcFlagGeant
88         ptrGeoInit->SetLttcFlagGeant(LttcFlagGeant);
89
90         //return region number and dummy variables
91         G4int volIndex = 0;
92         for (G4int i=0; i<pVolStore->size(); i++)
93           if ((*pVolStore)[i] == located) volIndex = i;
94         //G4int volIndex=G4int(pVolStore->index(located));
95         newReg=volIndex+1;   
96         newLttc=jrLtGeant[LttcFlagGeant];
97         flagErr=newReg;
98 #ifdef G4GEOMETRY_DEBUG
99         G4cout << "Located Physical volume = ";
100         G4cout << located->GetName() << G4endl;
101 #endif
102       }
103 }
104
105
106
107