00001
00010 #include "Alignment/MuonStandaloneAlgorithm/interface/PointForAlignment.h"
00011 #include "TMath.h"
00012
00013 PointForAlignment::PointForAlignment(){}
00014
00015 void PointForAlignment::setPointForAlignment(long rawId_, int subDet_M, int station_M, GlobalPoint globalPosition_M, GlobalVector globalDirection_M, LocalPoint localPosition_M, LocalError localPositionError_M, LocalVector localDirection_M, LocalError localDirectionError_M, GlobalPoint globalPosition_P, GlobalVector globalDirection_P, LocalPoint localPosition_P, LocalVector localDirection_P,TMatrixD theDerivatives_, TMatrixD CovMatrix_m) {
00016
00017
00018 theRawId = rawId_;
00019 subDet = subDet_M;
00020 station = station_M;
00021
00022
00023 theGlobalPosition = globalPosition_M;
00024 theGlobalDirection = globalDirection_M;
00025 theLocalPosition = localPosition_M;
00026 theLocalPositionError = localPositionError_M;
00027 theLocalDirection = localDirection_M;
00028 theLocalDirectionError = localDirectionError_M;
00029
00030 thePredictedGlobalPosition = globalPosition_P;
00031 thePredictedGlobalDirection = globalDirection_P;
00032 thePredictedLocalPosition = localPosition_P;
00033 thePredictedLocalDirection = localDirection_P;
00034
00035
00036 theDerivatives.ResizeTo(theDerivatives_.GetNrows(), theDerivatives_.GetNcols());
00037 theDerivatives = theDerivatives_;
00038
00039
00040 CovMatrixInit.ResizeTo(CovMatrix_m.GetNrows(), CovMatrix_m.GetNcols());
00041 CovMatrixInit = CovMatrix_m;
00042
00043 calculateErrors();
00044 calculateResiduals();
00045 calculateAlignmentCoeff();
00046
00047 if(TMath::Abs(theResiduals(0,0)) < 5.0 && TMath::Abs(theResiduals(1,0)) < 8.0 && TMath::Abs(theResiduals(2,0)) < 1.0 && TMath::Abs(theResiduals(3,0) < 1.0)) {
00048 validPoint = true;
00049 } else {
00050 validPoint = false;
00051 }
00052
00053 if(TMath::Abs(theDerivatives(1,0)/theDerivatives(0,0)) > 0.1 ||
00054 TMath::Abs(theDerivatives(1,1)/theDerivatives(0,1)) > 0.1 ||
00055 TMath::Abs(theDerivatives(1,3)/theDerivatives(0,3)) > 0.1 ||
00056 TMath::Abs(theDerivatives(0,2)/theDerivatives(1,2)) > 0.1 ||
00057 TMath::Abs(theDerivatives(0,4)/theDerivatives(1,4)) > 0.1) validPoint = false;
00058 }
00059
00060 PointForAlignment::~PointForAlignment(){}
00061
00062 long PointForAlignment::rawId(){return theRawId;}
00063
00064 GlobalPoint PointForAlignment::globalPosition(){return theGlobalPosition;}
00065
00066 GlobalVector PointForAlignment::globalDirection(){return theGlobalDirection;}
00067
00068 LocalPoint PointForAlignment::localPosition(){return theLocalPosition;}
00069
00070 LocalVector PointForAlignment::localDirection(){return theLocalDirection;}
00071
00072 GlobalPoint PointForAlignment::predictedGlobalPosition(){return thePredictedGlobalPosition;}
00073
00074 GlobalVector PointForAlignment::predictedGlobalDirection(){return thePredictedGlobalDirection;}
00075
00076 LocalPoint PointForAlignment::predictedLocalPosition(){return thePredictedLocalPosition;}
00077
00078 LocalVector PointForAlignment::predictedLocalDirection(){return thePredictedLocalDirection;}
00079
00080 TMatrixD PointForAlignment::derivatives(){return theDerivatives;}
00081
00082 TMatrixD PointForAlignment::residual() {return theResiduals;}
00083
00084 TMatrixD PointForAlignment::errors() {return theErrors;}
00085
00086 TMatrixD PointForAlignment::alignmentMatrix() {return theAlignmentMatrix;}
00087
00088 double PointForAlignment::residualRPhi(){return theResidualRPhi;}
00089
00090 double PointForAlignment::residualZ(){return theResidualZ;}
00091
00092 double PointForAlignment::residualPhi(){return theResidualPhi;}
00093
00094 double PointForAlignment::residualTheta(){return theResidualTheta;}
00095
00096
00097 void PointForAlignment::calculateResiduals() {
00098
00099
00100 if(station != 4 && subDet == 1) {
00101 theResidualRPhi = localPosition().x() - predictedLocalPosition().x();
00102 theResidualZ = localPosition().y()-predictedLocalPosition().y();
00103 theResidualPhi = TMath::ATan2(localDirection().z(),localDirection().x())-TMath::ATan2(predictedLocalDirection().z(),predictedLocalDirection().x());
00104 theResidualTheta = TMath::ATan2(localDirection().z(), localDirection().y())-TMath::ATan2(predictedLocalDirection().z(), predictedLocalDirection().y());
00105 } else {
00106 theResidualRPhi = localPosition().x() - predictedLocalPosition().x();
00107 theResidualZ = 0;
00108 theResidualPhi = TMath::ATan2(localDirection().z(),localDirection().x())-TMath::ATan2(predictedLocalDirection().z(),predictedLocalDirection().x());
00109 theResidualTheta = 0;
00110 }
00111
00112 theResiduals.ResizeTo(NDOFCoor,1);
00113 theResiduals(0,0) = residualRPhi();
00114 theResiduals(1,0) = residualZ();
00115 theResiduals(2,0) = residualPhi();
00116 theResiduals(3,0) = residualTheta();
00117
00118 }
00119
00120 void PointForAlignment::calculateErrors() {
00121
00122 theErrors.ResizeTo(NDOFCoor, NDOFCoor);
00123 CovMatrix.ResizeTo(NDOFCoor, NDOFCoor);
00124 TMatrixD unit(NDOFCoor, NDOFCoor);
00125 unit.UnitMatrix();
00126 TMatrixD comparison(NDOFCoor, NDOFCoor);
00127 double crosscheck;
00128 double det;
00129 if(station != 4 && subDet == 1) {
00130 CovMatrix = CovMatrixInit;
00131 theErrors = CovMatrix;
00132 theErrors.Invert(&det);
00133 comparison = unit - CovMatrix*theErrors;
00134 crosscheck = comparison.E2Norm();
00135 } else {
00136 CovMatrix.ResizeTo(NDOFCoor/2, NDOFCoor/2);
00137 TMatrixD checkMatrix(NDOFCoor/2, NDOFCoor/2);
00138 CovMatrix(0,0) = CovMatrixInit(0,0);
00139 CovMatrix(0,1) = CovMatrixInit(0,2);
00140 CovMatrix(1,0) = CovMatrixInit(2,0);
00141 CovMatrix(1,1) = CovMatrixInit(2,2);
00142 checkMatrix = CovMatrix;
00143 CovMatrix.Invert(&det);
00144 comparison.ResizeTo(NDOFCoor/2, NDOFCoor/2);
00145 unit.ResizeTo(NDOFCoor/2, NDOFCoor/2);
00146 unit.UnitMatrix();
00147 theErrors(0,0) = CovMatrix(0,0);
00148 theErrors(0,2) = CovMatrix(0,1);
00149 theErrors(2,0) = CovMatrix(1,0);
00150 theErrors(2,2) = CovMatrix(1,1);
00151 comparison = unit - CovMatrix*checkMatrix;
00152 crosscheck = comparison.E2Norm();
00153 }
00154 if(TMath::Abs(det) < 1.e-30 || crosscheck > 1.0e-15) {
00155 validPoint = false;
00156 std::cout << "<PointForAlignment> Not valid point" << std::endl;
00157 }
00158 }
00159
00160 void PointForAlignment::calculateAlignmentCoeff() {
00161
00162 double tanphi = localDirection().z()/localDirection().x();
00163 double phi = TMath::ATan2(localDirection().z(),localDirection().x());
00164 double cosphi = TMath::Cos(phi);
00165 double sinphi = TMath::Sin(phi);
00166 double tantheta = localDirection().z()/localDirection().y();
00167 double theta = TMath::ATan2(localDirection().z(),localDirection().y());
00168 double costheta = TMath::Cos(theta);
00169 double sintheta = TMath::Sin(theta);
00170 theAlignmentMatrix.ResizeTo(NDOFCoor, NDOFAlign);
00171 if(station != 4 && subDet == 1) {
00172 if(tanphi == 0.0 || tantheta == 0.0) {
00173 validPoint = false;
00174 return;
00175 }
00176
00177 theAlignmentMatrix(0,0) = 1.0;
00178 theAlignmentMatrix(0,1) = 0.0;
00179 theAlignmentMatrix(0,2) = -1.0/tanphi;
00180 theAlignmentMatrix(0,3) = -localPosition().y();
00181 theAlignmentMatrix(0,4) = localPosition().x()/tanphi;
00182 theAlignmentMatrix(0,5) = -1.0/tanphi*localPosition().y();
00183
00184 theAlignmentMatrix(1,0) = 0.0;
00185 theAlignmentMatrix(1,1) = 1.0;
00186 theAlignmentMatrix(1,2) = -1.0/tantheta;
00187 theAlignmentMatrix(1,3) = localPosition().x();
00188 theAlignmentMatrix(1,4) = localPosition().x()/tantheta;
00189 theAlignmentMatrix(1,5) = -localPosition().y()/tantheta;
00190
00191 theAlignmentMatrix(2,0) = 0.0; theAlignmentMatrix(2,1) = 0.0;
00192 theAlignmentMatrix(2,2) = 0.0; theAlignmentMatrix(2,3) = 0.0;
00193 theAlignmentMatrix(2,4) = cosphi*cosphi; theAlignmentMatrix(2,5) = cosphi*sinphi/tantheta;
00194
00195 theAlignmentMatrix(3,0) = 0.0; theAlignmentMatrix(3,1) = 0.0;
00196 theAlignmentMatrix(3,2) = 0.0; theAlignmentMatrix(3,3) = 0.0;
00197 theAlignmentMatrix(3,4) = costheta*sintheta/tanphi; theAlignmentMatrix(3,5) = costheta*costheta;
00198 } else {
00199 if(tanphi == 0.0) {
00200 validPoint = false;
00201 return;
00202 }
00203
00204 theAlignmentMatrix(0,0) = 1.0;
00205 theAlignmentMatrix(0,1) = 0.0;
00206 theAlignmentMatrix(0,2) = -1.0/tanphi;
00207 theAlignmentMatrix(0,3) = 0.0;
00208 theAlignmentMatrix(0,4) = localPosition().x()/tanphi;
00209 theAlignmentMatrix(0,5) = 0.0;
00210
00211 theAlignmentMatrix(1,0) = 0.0;
00212 theAlignmentMatrix(1,1) = 0.0;
00213 theAlignmentMatrix(1,2) = 0.0;
00214 theAlignmentMatrix(1,3) = 0.0;
00215 theAlignmentMatrix(1,4) = 0.0;
00216 theAlignmentMatrix(1,5) = 0.0;
00217
00218 theAlignmentMatrix(2,0) = 0.0; theAlignmentMatrix(2,1) = 0.0;
00219 theAlignmentMatrix(2,2) = 0.0; theAlignmentMatrix(2,3) = 0.0;
00220 theAlignmentMatrix(2,4) = cosphi*cosphi; theAlignmentMatrix(2,5) = 0.0;
00221
00222 theAlignmentMatrix(3,0) = 0.0; theAlignmentMatrix(3,1) = 0.0;
00223 theAlignmentMatrix(3,2) = 0.0; theAlignmentMatrix(3,3) = 0.0;
00224 theAlignmentMatrix(3,4) = 0.0; theAlignmentMatrix(3,5) = 0.0;
00225 }
00226 }
00227
00228
00229 bool PointForAlignment::pointIsValid() {return validPoint;}
00230
00231
00232
00233