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