13#include <FieldManager.h>
33#include <MaterialEffects.h>
35#include <RKTrackRep.h>
37#include <TGeoMaterialInterface.h>
39#include <TApplication.h>
41#include <TDatabasePDG.h>
42#include <TEveManager.h>
43#include <TGeoManager.h>
53#include "TDatabasePDG.h"
63 size = backtrace(array, 10);
66 fprintf(stderr,
"Error: signal %d:\n", sig);
67 backtrace_symbols_fd(array, size, 2);
74 switch(
int(gRandom->Uniform(8))) {
98 if (gRandom->Uniform(1) > 0.5)
104bool compareMatrices(
const TMatrixTBase<double>& A,
const TMatrixTBase<double>& B,
double maxRelErr) {
109 for (
int i=0; i<A.GetNrows(); ++i) {
110 for (
int j=0; j<A.GetNcols(); ++j) {
111 if (fabs(A(i,j)) > max)
116 double maxAbsErr = maxRelErr*max;
118 for (
int i=0; i<A.GetNrows(); ++i) {
119 for (
int j=0; j<A.GetNcols(); ++j) {
120 double absErr = A(i,j) - B(i,j);
121 if ( fabs(absErr) > maxAbsErr ) {
122 double relErr = A(i,j)/B(i,j) - 1;
123 if ( fabs(relErr) > maxRelErr ) {
124 std::cout <<
"compareMatrices: A("<<i<<
","<<j<<
") = " << A(i,j) <<
" B("<<i<<
","<<j<<
") = " << B(i,j) <<
" absErr = " << absErr <<
" relErr = " << relErr <<
"\n";
135 if (!(cov.IsSymmetric())) {
136 std::cout <<
"isCovMatrix: not symmetric\n";
140 for (
int i=0; i<cov.GetNrows(); ++i) {
141 for (
int j=0; j<cov.GetNcols(); ++j) {
142 if (isnan(cov(i,j))) {
143 std::cout <<
"isCovMatrix: element isnan\n";
146 if (i==j && cov(i,j) < 0) {
147 std::cout <<
"isCovMatrix: negative diagonal element\n";
160 double epsilonLen = 1.E-10;
161 double epsilonMom = 1.E-10;
168 TVector3 pos(gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1));
169 TVector3 mom(0,0.5,gRandom->Gaus(0,0.3));
180 const TVector3& u = plane->getU();
181 const TVector3& v = plane->getV();
184 pos += gRandom->Gaus() * u;
185 pos += gRandom->Gaus() * v;
188 mom.SetXYZ(0,0.5,gRandom->Gaus(0,0.3));
196 std::cout <<
"plane has changed unexpectedly! \n";
204 if ((pos - rep->
getPos(state)).Mag() > epsilonLen ||
205 (mom - rep->
getMom(state)).Mag() > epsilonMom) {
209 std::cout <<
"pos difference = " << (pos - rep->
getPos(state)).Mag() <<
"\n";
210 std::cout <<
"mom difference = " << (mom - rep->
getMom(state)).Mag() <<
"\n";
212 std::cout << std::endl;
226 double epsilonLen = 5.E-5;
227 double epsilonMom = 1.E-4;
234 TVector3 pos(gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1));
235 TVector3 mom(0,0.5,gRandom->Gaus(0,0.3));
254 std::cerr << e.
what();
261 double backExtrapLen(0);
266 std::cerr << e.
what();
273 if ((rep->
getPos(origState) - rep->
getPos(state)).Mag() > epsilonLen ||
274 (rep->
getMom(origState) - rep->
getMom(state)).Mag() > epsilonMom ||
275 fabs(extrapLen + backExtrapLen) > epsilonLen) {
280 std::cout <<
"pos difference = " << (rep->
getPos(origState) - rep->
getPos(state)).Mag() <<
"\n";
281 std::cout <<
"mom difference = " << (rep->
getMom(origState) - rep->
getMom(state)).Mag() <<
"\n";
282 std::cout <<
"len difference = " << extrapLen + backExtrapLen <<
"\n";
284 std::cout << std::endl;
303 double deltaJac = 0.005;
304 double deltaNoise = 0.00001;
305 double deltaState = 3.E-6;
319 TVector3 pos(gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1));
320 TVector3 mom(0, 0.5, gRandom->Gaus(0, 1));
322 mom.SetMag(gRandom->Uniform(2)+0.3);
325 TMatrixD jac_f, jac_fi, jac_b, jac_bi;
326 TMatrixDSym noise_f, noise_fi, noise_b, noise_bi;
327 TVectorD c_f, c_fi, c_b, c_bi;
328 TVectorD state_man, stateOrig_man;
334 static const double smear = 0.2;
335 TVector3 normal(mom);
337 normal.SetXYZ(gRandom->Gaus(normal.X(), smear),
338 gRandom->Gaus(normal.Y(), smear),
339 gRandom->Gaus(normal.Z(), smear));
342 double rotAngleOrig = gRandom->Uniform(2.*TMath::Pi());
343 origPlanePtr->
rotate(rotAngleOrig);
354 normal.SetXYZ(gRandom->Gaus(normal.X(), smear),
355 gRandom->Gaus(normal.Y(), smear),
356 gRandom->Gaus(normal.Z(), smear));
361 double rotAngle = gRandom->Uniform(2.*TMath::Pi());
362 planePtr->
rotate(rotAngle);
382 extrapolatedState = state;
387 std::cerr << e.
what();
403 std::cerr << e.
what();
413 std::cout <<
"(origState.getState() - state.getState()) ";
420 if (!((jac_f * origState.
getState() + c_f - extrapolatedState.
getState()).Abs() < deltaState) ||
421 !((jac_bi * origState.
getState() + c_bi - extrapolatedState.
getState()).Abs() < deltaState) ||
422 !((jac_b * extrapolatedState.
getState() + c_b - origState.
getState()).Abs() < deltaState) ||
423 !((jac_fi * extrapolatedState.
getState() + c_fi - origState.
getState()).Abs() < deltaState) ) {
425 std::cout <<
"(jac_f * origState.getState() + c_f - extrapolatedState.getState()) ";
426 (jac_f * origState.
getState() + c_f - extrapolatedState.
getState()).Print();
427 std::cout <<
"(jac_bi * origState.getState() + c_bi - extrapolatedState.getState()) ";
428 (jac_bi * origState.
getState() + c_bi - extrapolatedState.
getState()).Print();
429 std::cout <<
"(jac_b * extrapolatedState.getState() + c_b - origState.getState()) ";
430 (jac_b * extrapolatedState.
getState() + c_b - origState.
getState()).Print();
431 std::cout <<
"(jac_fi * extrapolatedState.getState() + c_fi - origState.getState()) ";
432 (jac_fi * extrapolatedState.
getState() + c_fi - origState.
getState()).Print();
444 std::cout <<
"jac_f = "; jac_f.Print();
445 std::cout <<
"jac_bi = "; jac_bi.Print();
446 std::cout << std::endl;
453 std::cout <<
"jac_b = "; jac_b.Print();
454 std::cout <<
"jac_fi = "; jac_fi.Print();
455 std::cout << std::endl;
462 std::cout <<
"noise_f = "; noise_f.Print();
463 std::cout <<
"noise_bi = "; noise_bi.Print();
464 std::cout << std::endl;
471 std::cout <<
"noise_b = "; noise_b.Print();
472 std::cout <<
"noise_fi = "; noise_fi.Print();
473 std::cout << std::endl;
482 std::cout <<
"jac_f = "; jac_f.Print();
483 std::cout <<
"jac_f_num = "; jac_f_num.Print();
484 std::cout << std::endl;
499 double epsilonLen = 1.E-4;
502 double matRadius(1.);
509 TVector3 pos(gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1));
510 TVector3 mom(0,0.5,gRandom->Gaus(0,0.1));
527 std::cerr << e.
what();
535 if (fabs(rep->
getPos(state).Perp() - matRadius) > epsilonLen) {
540 std::cerr <<
"radius difference = " << rep->
getPos(state).Perp() - matRadius <<
"\n";
542 std::cerr << std::endl;
564 TVector3 pos(gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1));
565 TVector3 mom(0,0.5,gRandom->Gaus(0,0.1));
582 std::cerr << e.
what();
607 double epsilonLen = 1.E-4;
608 double epsilonMom = 1.E-5;
615 TVector3 pos(0+gRandom->Gaus(0,0.1),0+gRandom->Gaus(0,0.1),0+gRandom->Gaus(0,0.1));
616 TVector3 mom(0,0.5,0.);
626 TVector3 linePoint(gRandom->Gaus(),
randomSign()*10+gRandom->Gaus(),gRandom->Gaus());
627 TVector3 lineDirection(gRandom->Gaus(),gRandom->Gaus(),
randomSign()*10+gRandom->Gaus());
634 std::cerr << e.
what();
642 if (fabs(state.
getPlane()->distance(linePoint)) > epsilonLen ||
643 fabs(state.
getPlane()->distance(linePoint+lineDirection)) > epsilonLen ||
644 (rep->
getMom(state).Unit() * state.
getPlane()->getNormal()) > epsilonMom) {
649 std::cout <<
"distance of linePoint to plane = " << state.
getPlane()->distance(linePoint) <<
"\n";
650 std::cout <<
"distance of linePoint+lineDirection to plane = " << state.
getPlane()->distance(linePoint+lineDirection) <<
"\n";
651 std::cout <<
"direction * plane normal = " << rep->
getMom(state).Unit() * state.
getPlane()->getNormal() <<
"\n";
665 double epsilonLen = 1.E-4;
666 double epsilonMom = 1.E-5;
673 TVector3 pos(gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1),gRandom->Gaus(0,0.1));
674 TVector3 mom(0,0.5,gRandom->Gaus(0,0.1));
684 TVector3 point(gRandom->Gaus(),
randomSign()*10+gRandom->Gaus(),gRandom->Gaus());
691 std::cerr << e.
what();
699 if (fabs(state.
getPlane()->distance(point)) > epsilonLen ||
700 fabs((rep->
getMom(state).Unit() * state.
getPlane()->getNormal())) - 1 > epsilonMom) {
705 std::cout <<
"distance of point to plane = " << state.
getPlane()->distance(point) <<
"\n";
706 std::cout <<
"direction * plane normal = " << rep->
getMom(state).Unit() * state.
getPlane()->getNormal() <<
"\n";
720 double epsilonLen = 1.E-4;
728 TVector3 pos(0+gRandom->Gaus(0,0.1),0+gRandom->Gaus(0,0.1),0+gRandom->Gaus(0,0.1));
729 TVector3 mom(0,0.5,0.);
739 const TVector3 linePoint(gRandom->Gaus(0,5), gRandom->Gaus(0,5), gRandom->Gaus(0,5));
740 const TVector3 lineDirection(gRandom->Gaus(),gRandom->Gaus(),2+gRandom->Gaus());
741 const double radius = gRandom->Uniform(10);
748 std::cerr << e.
what();
752 static const char* bla =
"cannot solve";
753 const char* what = e.
what();
754 if (strstr(what, bla))
759 TVector3 pocaOnLine(lineDirection);
760 double t = 1./(pocaOnLine.Mag2()) * ((rep->
getPos(state)*pocaOnLine) - (linePoint*pocaOnLine));
762 pocaOnLine += linePoint;
764 TVector3 radiusVec = rep->
getPos(state) - pocaOnLine;
767 if (fabs(state.
getPlane()->getNormal()*radiusVec.Unit())-1 > epsilonLen ||
768 fabs(lineDirection*radiusVec) > epsilonLen ||
769 fabs(radiusVec.Mag()-radius) > epsilonLen) {
774 std::cout <<
"lineDirection*radiusVec = " << lineDirection*radiusVec <<
"\n";
775 std::cout <<
"radiusVec.Mag()-radius = " << radiusVec.Mag()-radius <<
"\n";
789 double epsilonLen = 1.E-4;
797 TVector3 pos(0+gRandom->Gaus(0,0.1),0+gRandom->Gaus(0,0.1),0+gRandom->Gaus(0,0.1));
798 TVector3 mom(0,0.5,0.);
808 const TVector3 centerPoint(gRandom->Gaus(0,10), gRandom->Gaus(0,10), gRandom->Gaus(0,10));
809 const double radius = gRandom->Uniform(10);
816 std::cerr << e.
what();
820 static const char* bla =
"cannot solve";
821 const char* what = e.
what();
822 if (strstr(what, bla))
828 TVector3 radiusVec = rep->
getPos(state) - centerPoint;
831 if (fabs(state.
getPlane()->getNormal()*radiusVec.Unit())-1 > epsilonLen ||
832 fabs(radiusVec.Mag()-radius) > epsilonLen) {
837 std::cout <<
"state.getPlane()->getNormal()*radiusVec = " << state.
getPlane()->getNormal()*radiusVec <<
"\n";
838 std::cout <<
"radiusVec.Mag()-radius = " << radiusVec.Mag()-radius <<
"\n";
852 double epsilonLen = 1.E-3;
859 TVector3 pos(0+gRandom->Gaus(0,0.1),0+gRandom->Gaus(0,0.1),0+gRandom->Gaus(0,0.1));
860 TVector3 mom(0,0.5,0.);
867 TVector3 posOrig(state.
getPos());
872 double step = gRandom->Uniform(-15.,15.);
873 double extrapolatedLen(0);
883 TVector3 posExt(state.
getPos());
889 if (fabs(extrapolatedLen-step) > epsilonLen ||
890 (posOrig - posExt).Mag() > fabs(step)) {
895 std::cout <<
"extrapolatedLen-step = " << extrapolatedLen-step <<
"\n";
896 std::cout <<
"started extrapolation from: "; posOrig.Print();
897 std::cout <<
"extrapolated to "; posExt.Print();
898 std::cout <<
"difference = " << (posOrig - posExt).Mag() <<
"; step = " << step <<
"\n";
916 const double BField = 15.;
919 gRandom->SetSeed(10);
923 new TGeoManager(
"Geometry",
"Geane geometry");
924 TGeoManager::Import(
"genfitGeom.root");
928 TDatabasePDG::Instance()->GetParticle(211);
931 unsigned int nFailed(0);
932 const unsigned int nTests(100);
934 for (
unsigned int i=0; i<nTests; ++i) {
937 std::cout <<
"failed checkSetGetPosMom nr" << i <<
"\n";
942 std::cout <<
"failed compareForthBackExtrapolation nr" << i <<
"\n";
947 std::cout <<
"failed checkStopAtBoundary nr" << i <<
"\n";
952 std::cout <<
"failed checkErrorPropagation nr" << i <<
"\n";
957 std::cout <<
"failed checkExtrapolateToLine nr" << i <<
"\n";
962 std::cout <<
"failed checkExtrapolateToPoint nr" << i <<
"\n";
967 std::cout <<
"failed checkExtrapolateToCylinder nr" << i <<
"\n";
972 std::cout <<
"failed checkExtrapolateToSphere nr" << i <<
"\n";
977 std::cout <<
"failed checkExtrapolateBy nr" << i <<
"\n";
982 std::cout <<
"failed compareForthBackJacNoise nr" << i <<
"\n";
988 std::cout <<
"failed " << nFailed <<
" of " << nTests <<
" Tests." << std::endl;
990 std::cout <<
"passed all tests!" << std::endl;
Abstract base class for a track representation.
virtual double extrapolateToPlane(StateOnPlane &state, const genfit::SharedPlanePtr &plane, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to plane, and returns the extrapolation length and, via reference,...
virtual double extrapolateToCylinder(StateOnPlane &state, double radius, const TVector3 &linePoint=TVector3(0., 0., 0.), const TVector3 &lineDirection=TVector3(0., 0., 1.), bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to the cylinder surface, and returns the extrapolation length and,...
virtual double extrapolateToLine(StateOnPlane &state, const TVector3 &linePoint, const TVector3 &lineDirection, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to the POCA to a line, and returns the extrapolation length and,...
void calcJacobianNumerically(const genfit::StateOnPlane &origState, const genfit::SharedPlanePtr destPlane, TMatrixD &jacobian) const
Calculate Jacobian of transportation numerically. Slow but accurate. Can be used to validate (semi)an...
virtual TVector3 getMom(const StateOnPlane &state) const =0
Get the cartesian momentum vector of a state.
virtual void setPosMom(StateOnPlane &state, const TVector3 &pos, const TVector3 &mom) const =0
Set position and momentum of state.
virtual double extrapolateToSphere(StateOnPlane &state, double radius, const TVector3 &point=TVector3(0., 0., 0.), bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to the sphere surface, and returns the extrapolation length and,...
virtual TVector3 getPos(const StateOnPlane &state) const =0
Get the cartesian position of a state.
virtual void getForwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const =0
Get the jacobian and noise matrix of the last extrapolation.
virtual void getBackwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const =0
Get the jacobian and noise matrix of the last extrapolation if it would have been done in opposite di...
virtual double extrapolateToPoint(StateOnPlane &state, const TVector3 &point, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to the POCA to a point, and returns the extrapolation length and,...
virtual double extrapolateBy(StateOnPlane &state, double step, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state by step (cm) and returns the extrapolation length and, via reference,...
void rotate(double angle)
rotate u and v around normal. Angle is in rad. More for debugging than for actual use.
Exception class for error handling in GENFIT (provides storage for diagnostic information)
virtual const char * what() const
Standard error message handling for exceptions. use like "std::cerr << e.what();".
void init(AbsBField *b)
set the magnetic field here. Magnetic field classes must be derived from AbsBField.
static FieldManager * getInstance()
Get singleton instance.
void setNoEffects(bool opt=true)
static MaterialEffects * getInstance()
void init(AbsMaterialInterface *matIfc)
set the material interface here. Material interface classes must be derived from AbsMaterialInterface...
StateOnPlane with additional covariance matrix.
const TMatrixDSym & getCov() const
virtual void Print(Option_t *option="") const
AbsTrackRep with 5D track parameterization in plane coordinates: (q/p, u', v', u, v)
A state with arbitrary dimension defined in a DetPlane.
const TVectorD & getState() const
virtual void Print(Option_t *option="") const
const SharedPlanePtr & getPlane() const
AbsMaterialInterface implementation for use with ROOT's TGeoManager.
boost::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.
bool isCovMatrix(TMatrixTBase< double > &cov)
bool compareMatrices(const TMatrixTBase< double > &A, const TMatrixTBase< double > &B, double maxRelErr)
bool checkStopAtBoundary()
bool checkExtrapolateToLine()
bool checkExtrapolateToPoint()
bool compareForthBackJacNoise()
bool checkExtrapolateToCylinder()
bool checkErrorPropagation()
bool checkExtrapolateToSphere()
bool checkExtrapolateBy()
bool compareForthBackExtrapolation()