QwAnalysis
QwMatrixLookup Class Reference

#include <QwMatrixLookup.h>

+ Inheritance diagram for QwMatrixLookup:
+ Collaboration diagram for QwMatrixLookup:

Public Member Functions

 QwMatrixLookup (QwOptions &options)
 Default constructor. More...
 
virtual ~QwMatrixLookup ()
 Destructor. More...
 
bool LoadTrajMatrix (const std::string filename)
 Load the trajectory matrix from disk. More...
 
bool WriteTrajMatrix (const std::string filename)
 Write the trajectory matrix to disk. More...
 
const QwTrackBridge (const QwPartialTrack *front, const QwPartialTrack *back)
 Bridge from the front to back partial track. More...
 
- Public Member Functions inherited from VQwBridgingMethod
 VQwBridgingMethod ()
 Default constructor. More...
 
virtual ~VQwBridgingMethod ()
 Destructor. More...
 

Private Attributes

double fFrontRefPlane
 Front and back reference planes. More...
 
double fBackRefPlane
 
std::vector< double > fMin
 Look-up table minimum, maximum and step size. More...
 
std::vector< double > fMax
 
std::vector< double > fStep
 
QwInterpolator< float, 4 > * fMatrix
 Look-up table. More...
 

Additional Inherited Members

- Protected Member Functions inherited from VQwBridgingMethod
virtual double EstimateInitialMomentum (const TVector3 &direction) const
 Estimate the momentum based only on the direction. More...
 

Detailed Description

Definition at line 27 of file QwMatrixLookup.h.

Constructor & Destructor Documentation

QwMatrixLookup::QwMatrixLookup ( QwOptions options)

Default constructor.

Constructor

Definition at line 28 of file QwMatrixLookup.cc.

References Qw::cm, Qw::deg, fBackRefPlane, fFrontRefPlane, fMatrix, fMax, fMin, fStep, kNearestNeighbor, Qw::MeV, QwInterpolator< value_t, value_n >::SetInterpolationMethod(), and QwInterpolator< value_t, value_n >::SetMinimumMaximumStep().

29 {
30  // Set the front and back reference plane locations for which the track
31  // parameters are stored in the trajectory matrix.
32  fFrontRefPlane = -250.0 * Qw::cm;
33  fBackRefPlane = 570.0 * Qw::cm;
34 
35  // Look-up table parameters, unless overriden when read in from file
36 
37  // Track momentum
38  double P_MAX = 1180.0 * Qw::MeV;
39  double P_MIN = 980.0 * Qw::MeV;
40  double DP = 10.0 * Qw::MeV;
41 
42  // Target vertex longitudinal position
43  // NOTE This is equivalent to the polar angle theta at the reference plane
44  double Z_MAX = -630.0 * Qw::cm;
45  double Z_MIN = -670.0 * Qw::cm;
46  double DZ = 2.0 * Qw::cm;
47 
48  // Position radius at front reference plane
49  double R_MAX = 100.0 * Qw::cm;
50  double R_MIN = 30.0 * Qw::cm;
51  double DR = 1.0 * Qw::cm;
52 
53  // Azimuthal angle at front reference plane
54  double PHI_MAX = 360.0 * Qw::deg;
55  double PHI_MIN = 0.0 * Qw::deg;
56  double DPHI = 1.0 * Qw::deg;
57 
58  // Create new interpolator from 4 float coordinates to 4 output values
61 
62  // The optimal storage is to have all momentum points close together (p < z < r < phi)
63  //fMin.push_back(P_MIN); fMax.push_back(P_MAX); fStep.push_back(DP);
64  //fMin.push_back(Z_MIN); fMax.push_back(Z_MAX); fStep.push_back(DZ);
65  //fMin.push_back(R_MIN); fMax.push_back(R_MAX); fStep.push_back(DR);
66  //fMin.push_back(PHI_MIN); fMax.push_back(PHI_MAX); fStep.push_back(DPHI);
67 
68  // But the ROOT file currently has this differently (z < phi < r < p)
69  fMin.push_back(Z_MIN); fMax.push_back(Z_MAX); fStep.push_back(DZ);
70  fMin.push_back(PHI_MIN); fMax.push_back(PHI_MAX); fStep.push_back(DPHI);
71  fMin.push_back(R_MIN); fMax.push_back(R_MAX); fStep.push_back(DR);
72  fMin.push_back(P_MIN); fMax.push_back(P_MAX); fStep.push_back(DP);
73 
75 }
double fBackRefPlane
std::vector< double > fStep
static const double deg
Definition: QwUnits.h:106
void SetInterpolationMethod(const EQwInterpolationMethod method)
Set the interpolation method.
QwInterpolator< float, 4 > * fMatrix
Look-up table.
std::vector< double > fMax
std::vector< double > fMin
Look-up table minimum, maximum and step size.
static const double MeV
Definition: QwUnits.h:94
double fFrontRefPlane
Front and back reference planes.
void SetMinimumMaximumStep(const coord_t min, const coord_t max, const coord_t step)
Set minimum, maximum, and step size to single values.
static const double cm
Length units: base unit is mm.
Definition: QwUnits.h:61

+ Here is the call graph for this function:

QwMatrixLookup::~QwMatrixLookup ( )
virtual

Destructor.

Destructor

Definition at line 80 of file QwMatrixLookup.cc.

References fMatrix.

81 {
82  delete fMatrix;
83 }
QwInterpolator< float, 4 > * fMatrix
Look-up table.

Member Function Documentation

const QwTrack * QwMatrixLookup::Bridge ( const QwPartialTrack front,
const QwPartialTrack back 
)
virtual

Bridge from the front to back partial track.

Bridge the front and back partial tracks using the momentum look-up table

Parameters
frontFront partial track
backBack partial tracks
Returns
List of reconstructed tracks

Implements VQwBridgingMethod.

Definition at line 323 of file QwMatrixLookup.cc.

References Qw::cm, Qw::deg, QwLog::endl(), fBackRefPlane, QwTrack::fEndDirectionActual, QwTrack::fEndDirectionGoal, QwTrack::fEndPositionActual, QwTrack::fEndPositionGoal, fFrontRefPlane, fMatrix, QwTrack::fMomentum, QwTrack::fStartDirection, QwTrack::fStartPosition, QwInterpolator< value_t, value_n >::GetMaximum(), QwInterpolator< value_t, value_n >::GetMinimum(), QwPartialTrack::GetMomentumDirection(), QwPartialTrack::GetPosition(), QwInterpolator< value_t, value_n >::GetStepSize(), QwInterpolator< value_t, value_n >::GetValue(), Qw::GeV, QwInterpolator< value_t, value_n >::InBounds(), QwDebug, and QwMessage.

Referenced by main().

326 {
327 #if ! defined __ROOT_HAS_MATHMORE || ROOT_VERSION_CODE < ROOT_VERSION(5,18,0)
328 
329  // Return immediately if there is no support for ROOT::Math::Interpolator
330  return 0;
331 
332 #endif
333 
334  // No track found yet
335  QwTrack* track = 0;
336 
337  // Return immediately if there is no look-up table
338  if (! fMatrix) return track;
339 
340 
341  // Front track position and direction at the front reference plane
342  TVector3 front_position = front->GetPosition(fFrontRefPlane);
343  TVector3 front_direction = front->GetMomentumDirection();
344  double front_position_r = front_position.Perp();
345  double front_position_phi = front_position.Phi();
346  // TODO this should be a method of the partial track
347  double vertex_z = fFrontRefPlane - front_position_r / tan(front->GetMomentumDirection().Theta());
348 
349  // Check whether this front track is in the look-up table
350  double momentum = 1.165 * Qw::GeV;
351  double coord[4] = {vertex_z, front_position_phi, front_position_r, momentum};
352  if (! fMatrix->InBounds(coord)) {
353  QwMessage << "vertex_z = " << vertex_z/Qw::cm << " cm" << QwLog::endl;
354  QwMessage << "front_position_r = " << front_position_r/Qw::cm << " cm" << QwLog::endl;
355  QwMessage << "front_position_phi = " << front_position_phi/Qw::deg << " deg" << QwLog::endl;
356  QwMessage << "This potential track is not listed in the table."<<QwLog::endl;
357  return track;
358  }
359 
360  // Back track position and direction at the back reference plane
361  TVector3 actual_back_position = back->GetPosition(fBackRefPlane);
362  TVector3 actual_back_direction = back->GetMomentumDirection();
363  double actual_back_position_r = actual_back_position.Perp();
364 
365  //
366  double p_min = fMatrix->GetMinimum(3);
367  double p_max = fMatrix->GetMaximum(3);
368  double dp = fMatrix->GetStepSize(3);
369  double np = (p_max - p_min) / dp + 1.0;
370 
371  // Build two subsets of the table
372  std::vector<double> iP; // hold momentum for interpolation
373  std::vector<double> iR; // hold radial position for interpolation
374 
375  iP.resize(np); iR.resize(np);
376 
377  // NOTE jpan: ROOT::Math::GSLInterpolator::Eval(double) requires that
378  // x values must be monotonically increasing.
379 
380  double value[4] = {0.0, 0.0, 0.0, 0.0};
381  unsigned int index = 0;
382  for (double p = p_max; p >= p_min; p -= dp) {
383 
384  coord[3] = p;
385  fMatrix->GetValue(coord, value);
386 
387  iP[index] = p;
388  iR[index] = value[0];
389  index++;
390  }
391 
392  // NOTE The dr/dp on focal plane is about 1 cm per 10 MeV
393 
394  if ( (iR.front() < actual_back_position_r) &&
395  (iR.back() > actual_back_position_r) ) {
396  QwDebug << "No match in look-up table!" << QwLog::endl;
397  return track;
398  }
399 
400  // The hit is within the momentum limits, do interpolation for momentum
401  momentum = 0.0;
402 
403  // We can choose among the following interpolation methods:
404  // LINEAR, POLYNOMIAL, CSPLINE, CSPLINE_PERIODIC, AKIMA, AKIMA_PERIODIC
405 
406  #if defined __ROOT_HAS_MATHMORE && ROOT_VERSION_CODE >= ROOT_VERSION(5,18,0)
407 
408  #if ROOT_VERSION_CODE >= ROOT_VERSION(5,22,0)
409  // Newer version of the MathMore plugin use kPOLYNOMIAL
410  UInt_t size = iP.size();
411  ROOT::Math::Interpolator inter(size, ROOT::Math::Interpolation::kPOLYNOMIAL);
412  #else
413  // Older version of the MathMore plugin use POLYNOMIAL
414  UInt_t size = iP.size();
415  ROOT::Math::Interpolator inter(size, ROOT::Math::Interpolation::POLYNOMIAL);
416  #endif
417 
418  inter.SetData(iR, iP);
419  momentum = inter.Eval(actual_back_position_r/Qw::cm); // + 0.0016; // [GeV]
420 
421  #else // ! defined __ROOT_HAS_MATHMORE || ROOT_VERSION_CODE < ROOT_VERSION(5,18,0)
422 
423  // Should never get here
424  momentum = 0.0;
425 
426  #endif // ! defined __ROOT_HAS_MATHMORE || ROOT_VERSION_CODE < ROOT_VERSION(5,18,0)
427 
428  QwMessage << momentum/Qw::GeV << " GeV" << QwLog::endl;
429 
430 
431  // take the track parameter from the nearest track
432  if (momentum < 0.98 * Qw::GeV || momentum > 1.165 * Qw::GeV) {
433  QwMessage << "Out of momentum range: determined momentum by looking up table: "
434  << momentum/Qw::GeV << " GeV" << QwLog::endl;
435  return track;
436  }
437 
438  // Get the values in the table (and assign units)
439  coord[3] = momentum;
440  fMatrix->GetValue(coord, value);
441  double& back_position_r = value[0]; back_position_r *= Qw::cm;
442  double& back_position_phi = value[1]; back_position_phi *= Qw::deg;
443  double& back_direction_theta = value[2]; back_direction_theta *= Qw::deg;
444  double& back_direction_phi = value[3]; back_direction_phi *= Qw::deg;
445 
446  // Get the hit parameters
447  double x = back_position_r * cos(back_position_phi);
448  double y = back_position_r * sin(back_position_phi);
449  TVector3 back_position = TVector3(x,y,fBackRefPlane);
450  TVector3 back_direction;
451  back_direction.SetMagThetaPhi(1.0, back_direction_theta, back_direction_phi);
452 
453  // Calculate the differences
454  double diff_position_r = actual_back_position.Perp() - back_position.Perp();
455  double diff_position_phi = actual_back_position.Phi() - back_position.Phi();
456  double diff_direction_phi = actual_back_direction.Phi() - back_direction.Phi();
457  double diff_direction_theta = actual_back_direction.Theta() - back_direction.Theta();
458  if (fabs(diff_position_r) > 2.0 * Qw::cm
459  || fabs(diff_position_phi) > 4.0 * Qw::deg
460  || fabs(diff_direction_phi) > 4.0 * Qw::deg
461  || fabs(diff_direction_theta) > 1.0 * Qw::deg ) {
462 
463  QwMessage << "Didn't find a good match in the look-up table" << QwLog::endl;
464  QwMessage << "diff_position_r = " << diff_position_r/Qw::cm << " cm" << QwLog::endl;
465  QwMessage << "diff_position_phi = " << diff_position_phi/Qw::deg << " deg" << QwLog::endl;
466  QwMessage << "diff_direction_phi = " << diff_direction_phi/Qw::deg << " deg" << QwLog::endl;
467  QwMessage << "diff_direction_theta = " << diff_direction_theta/Qw::deg << " deg" << QwLog::endl;
468  return track;
469  }
470 
471  track = new QwTrack(front,back);
472  track->fMomentum = momentum;
473 
474  track->fStartPosition = front_position;
475  track->fStartDirection = front_direction;
476  track->fEndPositionGoal = back_position;
477  track->fEndDirectionGoal = back_direction;
478  track->fEndPositionActual = actual_back_position;
479  track->fEndDirectionActual = actual_back_direction;
480 
481 
482 
483  //Int_t fMatchFlag; // MatchFlag = -2 : cannot match
484  // MatchFlag = -1 : potential track cannot pass through the filter
485  // MatchFlag = 0; : matched with look-up table
486  // MatchFlag = 1; : matched by using shooting method
487  // MatchFlag = 2; : potential track is forced to match
488 
489  return track;
490 }
double fBackRefPlane
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
static const double deg
Definition: QwUnits.h:106
TVector3 fStartPosition
Position and direction before and after swimming.
Definition: QwTrack.h:123
const TVector3 GetPosition(const double z) const
Return the vertex at position z.
coord_t GetMaximum(const unsigned int dim) const
Get maximum in dimension.
TVector3 fEndDirectionActual
Actual direction of track at back plane.
Definition: QwTrack.h:130
QwInterpolator< float, 4 > * fMatrix
Look-up table.
TVector3 fStartDirection
Start direction of front track.
Definition: QwTrack.h:124
#define QwDebug
Predefined log drain for debugging output.
Definition: QwLog.h:60
const TVector3 GetMomentumDirection() const
Return the direction.
TVector3 fEndPositionActual
Actual position of track at back plane.
Definition: QwTrack.h:129
Contains the complete track as a concatenation of partial tracks.
Definition: QwTrack.h:30
coord_t GetMinimum(const unsigned int dim) const
Get minimum in dimension.
TVector3 fEndDirectionGoal
Goal direction of back track.
Definition: QwTrack.h:127
static const double GeV
Definition: QwUnits.h:95
bool InBounds(const coord_t *coord) const
Return true if the coordinate is in bounds.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
TVector3 fEndPositionGoal
Goal position of back track.
Definition: QwTrack.h:126
coord_t GetStepSize(const unsigned int dim) const
Get minimum in dimension.
double fMomentum
Spectrometer momentum.
Definition: QwTrack.h:100
double fFrontRefPlane
Front and back reference planes.
value_t GetValue(const coord_t &coord) const
Get the interpolated value at coordinate (zero if out of bounds)
static const double cm
Length units: base unit is mm.
Definition: QwUnits.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool QwMatrixLookup::LoadTrajMatrix ( const std::string  filename)

Load the trajectory matrix from disk.

Load the trajectory matrix

Parameters
filenameFilename
Returns
True if successful

Definition at line 90 of file QwMatrixLookup.cc.

References QwLog::endl(), fMatrix, QwInterpolator< value_t, value_n >::GetCurrentEntries(), QwInterpolator< value_t, value_n >::GetMaximumEntries(), QwMessage, QwWarning, and QwInterpolator< value_t, value_n >::Set().

Referenced by main().

91 {
92 
93 #if ! defined __ROOT_HAS_MATHMORE || ROOT_VERSION_CODE < ROOT_VERSION(5,18,0)
94 
95  // No support for ROOT MathMore: warn user and return failure
96  QwWarning << "No support for ROOT::Math::Interpolator was found." << QwLog::endl;
97  QwWarning << "Without this support the faster momentum reconstruction method using "
98  << "a track look-up table will not work. The momentum reconstruction "
99  << "will always happen by slower swimming through the magnetic field."
100  << QwLog::endl;
101  QwWarning << "The necessary functionality is included in the ROOT MathMore plugin, "
102  << "which is included on JLab CUE2 systems in /apps/root/5.26-00."
103  << QwLog::endl;
104  QwWarning << "No momentum look-up table will be used for track reconstruction."
105  << QwLog::endl;
106  return false;
107 
108 #endif
109 
110  // Try to access the file
111  if (gSystem->AccessPathName(TString(filename))) {
112  QwWarning << "Could not find the momentum look-up table!" << QwLog::endl;
113  QwWarning << "Filename: " << filename << QwLog::endl;
114  QwWarning << "Without this file the faster momentum reconstruction method using "
115  << "a track look-up table will not work. The momentum reconstruction "
116  << "will always happen by slower swimming through the magnetic field."
117  << QwLog::endl;
118  QwWarning << "The necessary file is /group/qweak/QwAnalysis/datafiles/QwTrajMatrix.root"
119  << QwLog::endl;
120  QwWarning << "No momentum look-up table will be used for track reconstruction."
121  << QwLog::endl;
122  return false;
123  }
124 
125  // Try to open the file
126  TFile* rootfile = new TFile(TString(filename),"read");
127  if (! rootfile) {
128  QwWarning << "Could not open the momentum look-up table!" << QwLog::endl;
129  QwWarning << "Filename: " << filename << QwLog::endl;
130  QwWarning << "No momentum look-up table will be used for track reconstruction."
131  << QwLog::endl;
132  return false;
133  }
134  rootfile->cd();
135 
136  // Try to open the tree
137  TTree *momentum_tree = (TTree *)rootfile->Get("Momentum_Tree");
138  if (! momentum_tree) {
139  QwWarning << "Could not find momentum look-up table in file!" << QwLog::endl;
140  QwWarning << "Filename: " << filename << QwLog::endl;
141  QwWarning << "No momentum look-up table will be used for track reconstruction."
142  << QwLog::endl;
143  return false;
144  }
145 
146 
147  QwMessage << "------------------------------" << QwLog::endl;
148  QwMessage << " Loading lookup table " << QwLog::endl;
149  QwMessage << "------------------------------" << QwLog::endl;
150 
151  // Connect branches
152  Int_t index;
153  Double_t back_position_r, back_position_phi;
154  Double_t back_direction_theta, back_direction_phi;
155  momentum_tree->SetBranchAddress("index", &index);
156  momentum_tree->SetBranchAddress("position_r", &back_position_r);
157  momentum_tree->SetBranchAddress("position_phi", &back_position_phi);
158  momentum_tree->SetBranchAddress("direction_theta", &back_direction_theta);
159  momentum_tree->SetBranchAddress("direction_phi", &back_direction_phi);
160 
161  // Create value array and make references
162  float value[4] = {0.0, 0.0, 0.0, 0.0};
163 
164  // Loop over all entries
165  Int_t numberOfEntries = momentum_tree->GetEntries();
166  for (Int_t i = 0; i < numberOfEntries; i++) {
167 
168  // Get the entry from the tree
169  momentum_tree->GetEntry(i);
170 
171  // Fill the value array with stored back reference plane parameters
172  value[0] = back_position_r;
173  value[1] = back_position_phi;
174  value[2] = back_direction_theta;
175  value[3] = back_direction_phi;
176 
177  // Enter this into the interpolator
178  bool status = fMatrix->Set(i, value);
179  if (not status)
180  QwWarning << "Look-up table entry " << i << " could not be stored." << QwLog::endl;
181 
182  // Progress bar
183  if (fMatrix->GetCurrentEntries() % (fMatrix->GetMaximumEntries() / 10) == 0)
184  QwMessage << fMatrix->GetCurrentEntries() / (fMatrix->GetMaximumEntries() / 100) << "%" << std::flush;
185  if (fMatrix->GetCurrentEntries() % (fMatrix->GetMaximumEntries() / 10) != 0
186  && fMatrix->GetCurrentEntries() % (fMatrix->GetMaximumEntries() / 40) == 0)
187  QwMessage << "." << std::flush;
188  }
189  QwMessage << "... done." << QwLog::endl;
190 
191  // Close file
192  rootfile->Close();
193  delete rootfile;
194 
195  // Return successfully
196  return true;
197 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
unsigned int GetCurrentEntries() const
Get the current number of entries.
bool Set(const coord_t &coord, const value_t &value)
Set a single value at a coordinate (false if not possible)
QwInterpolator< float, 4 > * fMatrix
Look-up table.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
unsigned int GetMaximumEntries() const
Get the maximum number of entries.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool QwMatrixLookup::WriteTrajMatrix ( const std::string  filename)

Write the trajectory matrix to disk.

Generate a momentum look-up table indexed by momentum, position and direction: a family of trajectories starting from the target to endplane will be generated. Momentum and scattering direction vary for each trajectory. We record the inter- section position and direction at the focal plane (z=570 cm)

Z coordinate: Z0: start plane = -250 cm, Z1: endplane = +250 cm, Z2: focalplane = +570 cm B field values are available from z=-250 cm to z=250 cm

Definition at line 210 of file QwMatrixLookup.cc.

References Qw::cm, QwInterpolator< value_t, value_n >::Coord(), QwLog::endl(), fBackRefPlane, fFrontRefPlane, fMatrix, QwInterpolator< value_t, value_n >::GetCurrentEntries(), QwInterpolator< value_t, value_n >::GetMaximumEntries(), gQwOptions, QwRayTracer::IntegrateRK(), Qw::pi, QwMessage, and QwInterpolator< value_t, value_n >::Set().

211 {
212  Double_t position_r,position_phi; //z=570 cm plane
213  Double_t direction_theta,direction_phi;
214 
215  // Load the ray tracer
216  QwRayTracer* raytracer = new QwRayTracer(gQwOptions);
217  // Get the boundaries of the magnetic field
218  double magneticfield_min = -250.0 * Qw::cm;
219  double magneticfield_max = 250.0 * Qw::cm;
220 
221  //open file and set up output tree
222  TString rootfilename = TString(filename);
223  TFile* rootfile = new TFile(rootfilename,"RECREATE","Qweak momentum matrix");
224  rootfile->cd();
225 
226  TTree *momentum_tree = new TTree("Momentum_Tree","momentum data tree");
227 
228  // position and direction at focal plane
229  momentum_tree->Branch("position_r", &position_r, "position_r/D");
230  momentum_tree->Branch("position_phi", &position_phi, "position_phi/D");
231  momentum_tree->Branch("direction_theta",&direction_theta,"direction_theta/D");
232  momentum_tree->Branch("direction_phi",&direction_phi,"direction_phi/D");
233 
234 
235  // Create a timer
236  TStopwatch timer;
237  timer.Start();
238 
239  // Step size
240  Double_t step = 1.0 * Qw::cm;
241 
242  // Create coordinate and make references
243  double coord[4] = {0.0, 0.0, 0.0, 0.0};
244  double& z = coord[0];
245  double& phi = coord[1];
246  double& r = coord[2];
247  double& p = coord[3];
248 
249  // Calculate all trajectories for the look-up table
250  TVector3 position, direction;
251  for (unsigned int index = 0; index < fMatrix->GetMaximumEntries(); index++) {
252 
253  // Get the coordinates from the grid
254  fMatrix->Coord(index, coord);
255 
256  // Calculate the polar angle theta at the front reference plane
257  double theta = atan2(r,fFrontRefPlane - z);
258 
259  // Position of the track at the front reference plane
260  position.SetXYZ(r * cos(phi), r * sin(phi), fFrontRefPlane);
261  // Direction of the track at the front reference plane
262  direction.SetMagThetaPhi(1.0, theta, phi);
263 
264 
265  // Extend from the front reference plane to the magnetic field boundary
266  position += direction * (magneticfield_min - fFrontRefPlane);
267 
268  // Raytrace with momentum p from front to back of magnetic field
269  raytracer->IntegrateRK(position, direction, p, fBackRefPlane, 4, step);
270 
271  // Extend from the magnetic field boundary to the back reference plane
272  position += direction * (fBackRefPlane - magneticfield_max);
273 
274 
275  // Determine the back reference plane parameters
276  position_r = position.Perp();
277  position_phi = position.Phi();
278  if (position_phi < 0.0) position_phi += 2.0 * Qw::pi;
279  direction_phi = direction.Phi();
280  if (direction_phi < 0.0) direction_phi += 2.0 * Qw::pi;
281  direction_theta = direction.Theta();
282 
283  // Add the back reference plane parameters to the look-up table
284  float value[4] = {(float) position_r, (float) position_phi, (float) direction_phi, (float) direction_theta};
285  fMatrix->Set(coord, value);
286 
287  // Progress bar
288  if (fMatrix->GetCurrentEntries() % (fMatrix->GetMaximumEntries() / 10) == 0)
289  QwMessage << fMatrix->GetCurrentEntries() / (fMatrix->GetMaximumEntries() / 100) << "%" << std::flush;
290  if (fMatrix->GetCurrentEntries() % (fMatrix->GetMaximumEntries() / 10) != 0
291  && fMatrix->GetCurrentEntries() % (fMatrix->GetMaximumEntries() / 40) == 0)
292  QwMessage << "." << std::flush;
293  }
294  QwMessage << QwLog::endl;
295 
296  // Stop timer
297  timer.Stop();
298 
299  // Timing output
300  QwMessage << "CPU time used: " << timer.CpuTime() << " s "
301  << "(" << timer.CpuTime() / fMatrix->GetCurrentEntries() << " s per trajectory)" << QwLog::endl;
302  QwMessage << "Real time used: " << timer.RealTime() << " s "
303  << "(" << timer.RealTime() / fMatrix->GetCurrentEntries() << " s per trajectory)" << QwLog::endl;
304 
305  // Close file
306  rootfile->Write(0, TObject::kOverwrite);
307  rootfile->Close();
308 
309  delete rootfile;
310  delete raytracer;
311 
312  return true;
313 }
static const double pi
Angles: base unit is radian.
Definition: QwUnits.h:102
double fBackRefPlane
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
A logfile class.
Definition: QwLog.h:78
QwOptions gQwOptions
Definition: QwOptions.cc:27
QwInterpolator< float, 4 > * fMatrix
Look-up table.
void Coord(const unsigned int *cell_index, coord_t *coord) const
Return the coordinates based on the cell index (unchecked)
unsigned int GetMaximumEntries() const
Get the maximum number of entries.
usr bin c fPIC std
double fFrontRefPlane
Front and back reference planes.
int IntegrateRK(const TMatrixD &A, const TMatrixD &b, TVector3 &r, TVector3 &v, const double p, const double z, const double h, const double epsilon)
Runge-Kutta numerical integration by Butcher tableau.
Definition: QwRayTracer.cc:510
static const double cm
Length units: base unit is mm.
Definition: QwUnits.h:61

+ Here is the call graph for this function:

Field Documentation

double QwMatrixLookup::fBackRefPlane
private

Definition at line 48 of file QwMatrixLookup.h.

Referenced by Bridge(), QwMatrixLookup(), and WriteTrajMatrix().

double QwMatrixLookup::fFrontRefPlane
private

Front and back reference planes.

Definition at line 47 of file QwMatrixLookup.h.

Referenced by Bridge(), QwMatrixLookup(), and WriteTrajMatrix().

QwInterpolator<float,4>* QwMatrixLookup::fMatrix
private

Look-up table.

Definition at line 55 of file QwMatrixLookup.h.

Referenced by Bridge(), LoadTrajMatrix(), QwMatrixLookup(), WriteTrajMatrix(), and ~QwMatrixLookup().

std::vector<double> QwMatrixLookup::fMax
private

Definition at line 52 of file QwMatrixLookup.h.

Referenced by QwMatrixLookup().

std::vector<double> QwMatrixLookup::fMin
private

Look-up table minimum, maximum and step size.

Definition at line 51 of file QwMatrixLookup.h.

Referenced by QwMatrixLookup().

std::vector<double> QwMatrixLookup::fStep
private

Definition at line 53 of file QwMatrixLookup.h.

Referenced by QwMatrixLookup().


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