Make a step (following the curvature) until step length sMax or the next boundary is reached. After making a step to a boundary, the position has to be beyond the boundary, i.e. the current material has to be that beyond the boundary. The actual step made is returned.
92{
93 const double delta(1.E-2);
94 const double epsilon(1.E-1);
95
96
98 M1x7 state7, oldState7;
99 memcpy(oldState7, stateOrig, sizeof(state7));
100
101 int stepSign(sMax < 0 ? -1 : 1);
102
104
105 const unsigned maxIt = 300;
106 unsigned it = 0;
107
108
109 gGeoManager->FindNextBoundary(fabs(sMax) - s);
110 double safety = gGeoManager->GetSafeDistance();
111 double slDist = gGeoManager->GetStep();
112 double step = slDist;
113
114 while (1) {
115 if (++it > maxIt){
116 Exception exc("TGeoMaterialInterface::findNextBoundary ==> maximum number of iterations exceeded",__LINE__,__FILE__);
117 exc.setFatal();
118 throw exc;
119 }
120
121
122 if (s + safety > fabs(sMax)) {
123 if (debug)
124 std::cout << " next boundary is further away than sMax \n";
125 return stepSign*(
s + safety);
126 }
127
128
129 if (slDist < delta) {
130 if (debug)
131 std::cout << " very close to the boundary -> return"
132 << " stepSign*(s + slDist) = "
133 << stepSign <<
"*(" <<
s + slDist <<
")\n";
134 return stepSign*(
s + slDist);
135 }
136
137
138
139
140
141
142 memcpy(state7, stateOrig, sizeof(state7));
143 rep->RKPropagate(state7, NULL, SA, stepSign*(s + step), varField);
144
145
146
147 double dist2 = (pow(state7[0] - oldState7[0], 2)
148 + pow(state7[1] - oldState7[1], 2)
149 + pow(state7[2] - oldState7[2], 2));
150
151 double maxDeviation2 = 0.25*(
step*
step - dist2);
152
153 if (step > safety
154 && maxDeviation2 > epsilon*epsilon) {
155
156
157
158
159
160
161
162
163 step = std::max(step / 2, safety);
164 } else {
165 gGeoManager->PushPoint();
166 bool volChanged =
initTrack(state7[0], state7[1], state7[2],
167 stepSign*state7[3], stepSign*state7[4],
168 stepSign*state7[5]);
169
170 if (volChanged) {
171
172 gGeoManager->PopPoint();
173
174
175
176
177
178 if (step <= safety)
179 return stepSign*(
s +
step);
180
181
182
183 step = std::max(step / 2, safety);
184 } else {
185
187
188 memcpy(oldState7, state7, sizeof(state7));
189 gGeoManager->PopDummy();
190
191 gGeoManager->FindNextBoundary(fabs(sMax) - s);
192 safety = gGeoManager->GetSafeDistance();
193 step = slDist = gGeoManager->GetStep();
194 }
195 }
196 }
197}
bool initTrack(double posX, double posY, double posZ, double dirX, double dirY, double dirZ)
Initialize the navigator at given position and with given direction. Returns true if the volume chang...