CMS 3D CMS Logo

TrackForAlignment.cc

Go to the documentation of this file.
00001 
00011 #include "Alignment/MuonStandaloneAlgorithm/interface/TrackForAlignment.h"
00012 #include "DataFormats/DetId/interface/DetId.h"
00013 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00014 #include "TMath.h"
00015 #include <iostream>
00016 
00017 
00018 
00019 TrackForAlignment::TrackForAlignment(){}
00020 
00021 std::vector<PointForAlignment> TrackForAlignment::pointsAlignment() const {return thePoints;}
00022 
00023 void TrackForAlignment::setP(double p_, double pt_) {
00024   thep = p_;
00025   thept = pt_;
00026 }
00027 
00028 void TrackForAlignment::setPerigeeParameters(double transverseCurvature_, double theta_, double phi_, double trans_, double longi_) {
00029  
00030   theTransverseCurvature = transverseCurvature_;
00031   theTheta = theta_;
00032   thePhi = phi_;
00033   theTrans = trans_;
00034   theLongi = longi_;
00035   
00036 }
00037 
00038 void TrackForAlignment::insert(PointForAlignment a) {thePoints.push_back(a);}
00039 
00040 int TrackForAlignment::pointNumber(){return thePoints.size();}
00041 
00042 double TrackForAlignment::p(){return thep;}
00043 
00044 double TrackForAlignment::pt(){return thept;}
00045 
00046 double TrackForAlignment::transverseCurvature() {return theTransverseCurvature;}
00047 
00048 double TrackForAlignment::theta() {return theTheta;}
00049 
00050 double TrackForAlignment::phi() {return thePhi;}
00051 
00052 double TrackForAlignment::trans() {return theTrans;}
00053 
00054 double TrackForAlignment::longi() {return theLongi;}
00055 
00056 TMatrixD TrackForAlignment::CpMatrix() const {return Cp;}
00057 
00058 TMatrixD TrackForAlignment::BMatrix() const {return b;}
00059 
00060 void TrackForAlignment::isValid() {
00061   
00062   bool zerowheel = true;
00063   
00064   if(thePoints.size() != NDOFChamber) {
00065     trackValid = false;
00066     return;
00067   }     
00068   
00069   std::vector<PointForAlignment> mPoints = this->pointsAlignment();
00070 
00071   int counter = 0;
00072   int quality = 0;
00073   //std::cout << "---------------Beginning of track-------------------" << std::endl;
00074   for(std::vector<PointForAlignment>::iterator points = mPoints.begin(); points != mPoints.end(); ++points) {
00075     if(!(*points).pointIsValid()) {
00076       trackValid = false;
00077       return;
00078     }
00079     DetId myDet((*points).rawId());
00080     if(myDet.subdetId() == 1) {
00081       DTChamberId myChamber((*points).rawId());
00082       if(counter == 0 && myChamber.station() == 1) {
00083         quality++;
00084       } else if(counter == 1 && myChamber.station() == 2) {
00085       quality++;
00086       } else if(counter == 2 && myChamber.station() == 3) {
00087         quality++;
00088       } else if(counter == 3 && myChamber.station() == 4) {
00089         quality++;
00090       }
00091     } else {
00092       zerowheel = false;
00093       break;
00094     }
00095     counter++;
00096   }     
00097   if(zerowheel == true && quality == NDOFChamber) {
00098     trackValid = true;
00099     return;
00100   }
00101   
00102   trackValid = false;
00103   return;
00104 }
00105 
00106 
00107 void TrackForAlignment::CalculateCoeffMatrices () {
00108   
00109   B.ResizeTo(NDOFChamber*NDOFCoor, NDOFAlign*NDOFChamber);
00110   Bt.ResizeTo(NDOFChamber*NDOFCoor, NDOFAlign*NDOFChamber);
00111   A.ResizeTo(NDOFChamber*NDOFCoor, NDOFTrack);
00112   At.ResizeTo(NDOFChamber*NDOFCoor, NDOFTrack);
00113   E.ResizeTo(NDOFChamber*NDOFCoor, NDOFChamber*NDOFCoor);
00114   R.ResizeTo(NDOFChamber*NDOFCoor, 1);
00115   
00116   int counter = 0;
00117   std::vector<PointForAlignment> mPoints = this->pointsAlignment();
00118   for(std::vector<PointForAlignment>::iterator points = mPoints.begin(); points != mPoints.end(); ++points) {
00119     TMatrixD Errors = (*points).errors();
00120     TMatrixD Jacobian = (*points).derivatives();
00121     TMatrixD Residuals = (*points).residual();
00122     TMatrixD AlignmentMatrix = (*points).alignmentMatrix();
00123     for(int coor = 0; coor < NDOFCoor; ++coor) {
00124       R(counter*NDOFCoor+coor, 0) = Residuals(coor, 0);
00125       for(int track = 0; track < NDOFTrack; ++track) {
00126         A(counter*NDOFCoor+coor, track) = Jacobian(coor, track);
00127       }
00128       for(int alig = 0; alig < NDOFAlign; ++alig) {
00129         B(counter*NDOFCoor+coor, counter*NDOFAlign+alig) = AlignmentMatrix(coor, alig);
00130       }
00131       for(int coor2 = 0; coor2 < NDOFCoor; ++coor2) {
00132         E(counter*NDOFCoor+coor, counter*NDOFCoor+coor2) = Errors(coor, coor2);
00133       }
00134     }
00135     counter++;
00136   }
00137   
00138   Bt = B;
00139   Bt.T();
00140   At = A;
00141   At.T();
00142   
00143 }
00144 
00145 
00146 
00147 void TrackForAlignment::CalculateC() {
00148 
00149   C.ResizeTo(NDOFChamber*NDOFAlign,NDOFChamber*NDOFAlign);
00150   C = Bt*E*B;
00151   
00152 }
00153 
00154 
00155 
00156 void TrackForAlignment::CalculateG() {
00157   
00158   G.ResizeTo(NDOFChamber*NDOFAlign, NDOFTrack);
00159   Gt.ResizeTo(NDOFChamber*NDOFAlign, NDOFTrack);
00160   G = Bt*E*A; 
00161   Gt = G;
00162   Gt.T();
00163 }
00164 
00165 
00166 void TrackForAlignment::CalculateGamma() {
00167   
00168   TMatrixD kk;
00169   kk.ResizeTo(NDOFTrack, NDOFTrack); 
00170   Gamma.ResizeTo(NDOFTrack,NDOFTrack);
00171   Gamma = At*E*A;
00172   kk = Gamma;
00173   Gamma.Invert();
00174   TMatrixD unit, unit2;
00175   unit.ResizeTo(NDOFTrack, NDOFTrack);
00176   unit2.ResizeTo(NDOFTrack, NDOFTrack);
00177   unit2.UnitMatrix();
00178   unit = unit2-kk*Gamma;
00179   //std::cout << "Inversion check partial: " << unit.E2Norm();
00180  
00181 }
00182 
00183 
00184 void TrackForAlignment::printMatrix(TMatrixD &m, char *name) {
00185 
00186   std::cout << "Matrix: " << name << std::endl;
00187   for(int n = 0; n < m.GetNrows(); n++) {
00188     for(int s = 0; s < m.GetNcols(); s++) {
00189       std::cout << m(n,s) << " ";
00190     }
00191     std::cout << std::endl;
00192   }
00193   
00194 }
00195 
00196 
00197 void TrackForAlignment::CalculateCp() {
00198   Cp.ResizeTo(C.GetNrows(), C.GetNcols());
00199   Cp = C - G*Gamma*Gt;
00200 } 
00201 
00202 
00203 void TrackForAlignment::CalculateB(){
00204   
00205   b.ResizeTo(NDOFChamber*NDOFAlign,1);
00206   b = Bt*E*(R-A*Gamma*At*E*R);
00207 }
00208 
00209 
00210 void TrackForAlignment::CalculateMatrizes() {
00211  
00212   CalculateCoeffMatrices();
00213   CalculateC();
00214   CalculateG();
00215   CalculateGamma();
00216   CalculateCp();  
00217   CalculateB();  
00218 
00219   //C.Print("CMatrix");
00220   //b.Print("bMatrix");
00221   //A.Print("A");
00222   //B.Print("B");
00223   //E.Print("E");
00224   //R.Print("R");
00225 
00226  
00227 }
00228 
00229 
00230 
00231 

Generated on Tue Jun 9 17:24:51 2009 for CMSSW by  doxygen 1.5.4