Belle II Software  release-08-01-10
TGeoMaterialInterface Class Reference

AbsMaterialInterface implementation for use with ROOT's TGeoManager. More...

#include <TGeoMaterialInterface.h>

Inheritance diagram for TGeoMaterialInterface:
Collaboration diagram for TGeoMaterialInterface:

Public Member Functions

bool initTrack (double posX, double posY, double posZ, double dirX, double dirY, double dirZ) override
 Initialize the navigator at given position and with given direction. More...
 
Material getMaterialParameters () override
 
double findNextBoundary (const RKTrackRep *rep, const M1x7 &state7, double sMax, bool varField=true) override
 Make a step (following the curvature) until step length sMax or the next boundary is reached. More...
 
virtual void setDebugLvl (unsigned int lvl=1)
 

Protected Attributes

unsigned int debugLvl_
 

Detailed Description

AbsMaterialInterface implementation for use with ROOT's TGeoManager.

Definition at line 35 of file TGeoMaterialInterface.h.

Member Function Documentation

◆ findNextBoundary()

double findNextBoundary ( const RKTrackRep rep,
const M1x7 state7,
double  sMax,
bool  varField = true 
)
overridevirtual

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.

Implements AbsMaterialInterface.

Definition at line 70 of file TGeoMaterialInterface.cc.

74 {
75  const double delta(1.E-2); // cm, distance limit beneath which straight-line steps are taken.
76  const double epsilon(1.E-1); // cm, allowed upper bound on arch
77  // deviation from straight line
78 
79  M1x3 SA;
80  M1x7 state7, oldState7;
81  oldState7 = stateOrig;
82 
83  int stepSign(sMax < 0 ? -1 : 1);
84 
85  double s = 0; // trajectory length to boundary
86 
87  const unsigned maxIt = 300;
88  unsigned it = 0;
89 
90  // Initialize the geometry to the current location (set by caller).
91  gGeoManager->FindNextBoundary(fabs(sMax) - s);
92  double safety = gGeoManager->GetSafeDistance(); // >= 0
93  double slDist = gGeoManager->GetStep();
94 
95  // this should not happen, but it happens sometimes.
96  // The reason are probably overlaps in the geometry.
97  // Without this "hack" many small steps with size of minStep will be made,
98  // until eventually the maximum number of iterations are exceeded and the extrapolation fails
99  if (slDist < safety)
100  slDist = safety;
101  double step = slDist;
102 
103  if (debugLvl_ > 0)
104  debugOut << " safety = " << safety << "; step, slDist = " << step << "\n";
105 
106  while (1) {
107  if (++it > maxIt){
108  Exception exc("TGeoMaterialInterface::findNextBoundary ==> maximum number of iterations exceeded",__LINE__,__FILE__);
109  exc.setFatal();
110  throw exc;
111  }
112 
113  // No boundary in sight?
114  if (s + safety > fabs(sMax)) {
115  if (debugLvl_ > 0)
116  debugOut << " next boundary is further away than sMax \n";
117  return stepSign*(s + safety); //sMax;
118  }
119 
120  // Are we at the boundary?
121  if (slDist < delta) {
122  if (debugLvl_ > 0)
123  debugOut << " very close to the boundary -> return"
124  << " stepSign*(s + slDist) = "
125  << stepSign << "*(" << s + slDist << ")\n";
126  return stepSign*(s + slDist);
127  }
128 
129  // We have to find whether there's any boundary on our path.
130 
131  // Follow curved arch, then see if we may have missed a boundary.
132  // Always propagate complete way from original start to avoid
133  // inconsistent extrapolations.
134  state7 = stateOrig;
135  rep->RKPropagate(state7, nullptr, SA, stepSign*(s + step), varField);
136 
137  // Straight line distance² between extrapolation finish and
138  // the end of the previously determined safe segment.
139  double dist2 = (pow(state7[0] - oldState7[0], 2)
140  + pow(state7[1] - oldState7[1], 2)
141  + pow(state7[2] - oldState7[2], 2));
142  // Maximal lateral deviation².
143  double maxDeviation2 = 0.25*(step*step - dist2);
144 
145  if (step > safety
146  && maxDeviation2 > epsilon*epsilon) {
147  // Need to take a shorter step to reliably estimate material,
148  // but only if we didn't move by safety. In order to avoid
149  // issues with roundoff we check 'step > safety' instead of
150  // 'step != safety'. If we moved by safety, there couldn't have
151  // been a boundary that we missed along the path, but we could
152  // be on the boundary.
153 
154  // Take a shorter step, but never shorter than safety.
155  step = std::max(step / 2, safety);
156  } else {
157  gGeoManager->PushPoint();
158  bool volChanged = initTrack(state7[0], state7[1], state7[2],
159  stepSign*state7[3], stepSign*state7[4],
160  stepSign*state7[5]);
161 
162  if (volChanged) {
163  if (debugLvl_ > 0)
164  debugOut << " volChanged\n";
165  // Move back to start.
166  gGeoManager->PopPoint();
167 
168  // Extrapolation may not take the exact step length we asked
169  // for, so it can happen that a requested step < safety takes
170  // us across the boundary. This is then the best estimate we
171  // can get of the distance to the boundary with the stepper.
172  if (step <= safety) {
173  if (debugLvl_ > 0)
174  debugOut << " step <= safety, return stepSign*(s + step) = " << stepSign*(s + step) << "\n";
175  return stepSign*(s + step);
176  }
177 
178  // Volume changed during the extrapolation. Take a shorter
179  // step, but never shorter than safety.
180  step = std::max(step / 2, safety);
181  } else {
182  // we're in the new place, the step was safe, advance
183  s += step;
184 
185  oldState7 = state7;
186  gGeoManager->PopDummy(); // Pop stack, but stay in place.
187 
188  gGeoManager->FindNextBoundary(fabs(sMax) - s);
189  safety = gGeoManager->GetSafeDistance();
190  slDist = gGeoManager->GetStep();
191 
192  // this should not happen, but it happens sometimes.
193  // The reason are probably overlaps in the geometry.
194  // Without this "hack" many small steps with size of minStep will be made,
195  // until eventually the maximum number of iterations are exceeded and the extrapolation fails
196  if (slDist < safety)
197  slDist = safety;
198  step = slDist;
199  if (debugLvl_ > 0)
200  debugOut << " safety = " << safety << "; step, slDist = " << step << "\n";
201  }
202  }
203  }
204 }
bool initTrack(double posX, double posY, double posZ, double dirX, double dirY, double dirZ) override
Initialize the navigator at given position and with given direction.
std::ostream debugOut
Default stream for debug output.

◆ initTrack()

bool initTrack ( double  posX,
double  posY,
double  posZ,
double  dirX,
double  dirY,
double  dirZ 
)
overridevirtual

Initialize the navigator at given position and with given direction.

Returns true if the volume changed.

Implements AbsMaterialInterface.

Definition at line 38 of file TGeoMaterialInterface.cc.


The documentation for this class was generated from the following files: