00001 #include "Alignment/MuonAlignmentAlgorithms/interface/DTMuonSLToSL.h"
00002
00003
00004 DTMuonSLToSL::DTMuonSLToSL(std::string path, int n_files, float MaxPt, float MinPt, TFile *f_) {
00005
00006 ntuplePath = path;
00007 numberOfRootFiles = n_files;
00008
00009 f = f_;
00010
00011 ptMax = MaxPt;
00012 ptMin = MinPt;
00013
00014 setBranchTree();
00015
00016 initNTuples(0);
00017
00018 calculationSLToSL();
00019
00020 }
00021
00022 DTMuonSLToSL::~DTMuonSLToSL() {}
00023
00024
00025
00026 void DTMuonSLToSL::calculationSLToSL() {
00027
00028
00029 TMatrixD ****C13 = new TMatrixD ***[5];
00030 TMatrixD ****b13 = new TMatrixD ***[5];
00031 TMatrixD ****C31 = new TMatrixD ***[5];
00032 TMatrixD ****b31 = new TMatrixD ***[5];
00033
00034 for(int whI = -2; whI < 3; ++whI) {
00035 C13[whI+2] = new TMatrixD **[4];
00036 b13[whI+2] = new TMatrixD **[4];
00037 C31[whI+2] = new TMatrixD **[4];
00038 b31[whI+2] = new TMatrixD **[4];
00039 for(int stI = 1; stI < 5; ++stI) {
00040 C13[whI+2][stI-1] = new TMatrixD * [14];
00041 b13[whI+2][stI-1] = new TMatrixD * [14];
00042 C31[whI+2][stI-1] = new TMatrixD * [14];
00043 b31[whI+2][stI-1] = new TMatrixD * [14];
00044 for(int seI = 1; seI < 15; ++seI) {
00045 if(seI > 12 && stI != 4) continue;
00046 C13[whI+2][stI-1][seI-1] = new TMatrixD(3,3);
00047 b13[whI+2][stI-1][seI-1] = new TMatrixD(3,1);
00048 C31[whI+2][stI-1][seI-1] = new TMatrixD(3,3);
00049 b31[whI+2][stI-1][seI-1] = new TMatrixD(3,1);
00050 }
00051 }
00052 }
00053
00054
00055 Int_t nentries = (Int_t)tali->GetEntries();
00056 for (Int_t i=0;i<nentries;i++) {
00057 tali->GetEntry(i);
00058
00059 if(pt > ptMax || pt < ptMin) continue;
00060
00061 bool repeatedHits = false;
00062 for(int counter = 0; counter < nseg; ++counter) {
00063
00064 for(int counterHi = 0; counterHi < nhits[counter]; counterHi++) {
00065 for(int counterHj = 0; counterHj < nhits[counter]; counterHj++) {
00066 if(counterHi == counterHj) continue;
00067 if(zc[counter][counterHi] == zc[counter][counterHj]) {
00068 repeatedHits = true;
00069 }
00070 }
00071 }
00072 if(repeatedHits == true) continue;
00073
00074 float x_13 = xSlSL3[counter]; float xp_13 = xSL1SL3[counter];
00075 float x_31 = xSlSL1[counter]; float xp_31 = xSL3SL1[counter];
00076
00077 float tanphi_13 = dxdzSlSL1[counter];
00078 float tanphi_31 = dxdzSlSL3[counter];
00079 int wheel = wh[counter];
00080 int station = st[counter];
00081 int sector = sr[counter];
00082
00083 if(fabs(x_13-xp_13)< 3 && fabs(x_31-xp_31) && fabs(tanphi_13-tanphi_31)<0.06) {
00084
00085 *(C13[wheel+2][station-1][sector-1]) += returnCSLMatrix(x_13, xp_13, tanphi_13);
00086 *(b13[wheel+2][station-1][sector-1]) += returnbSLMatrix(x_13, xp_13, tanphi_13);
00087
00088 *(C31[wheel+2][station-1][sector-1]) += returnCSLMatrix(x_31, xp_31, tanphi_31);
00089 *(b31[wheel+2][station-1][sector-1]) += returnbSLMatrix(x_31, xp_31, tanphi_31);
00090 }
00091 }
00092 }
00093
00094 for(int wheel = -2; wheel < 3; ++wheel) {
00095 for(int station = 1; station < 5; ++station) {
00096 for(int sector = 1; sector < 15; ++sector) {
00097 if(sector > 12 && station != 4) continue;
00098 TMatrixD solution13(3,1);
00099 TMatrixD solution31(3,1);
00100 TMatrixD C31_copy = *(C31[wheel+2][station-1][sector-1]);
00101 TMatrixD C13_copy = *(C13[wheel+2][station-1][sector-1]);
00102 TMatrixD b31_copy = *(b31[wheel+2][station-1][sector-1]);
00103 TMatrixD b13_copy = *(b13[wheel+2][station-1][sector-1]);
00104
00105 C31_copy.Invert();
00106 C13_copy.Invert();
00107 solution13 = C13_copy * b13_copy;
00108 solution31 = C31_copy * b31_copy;
00109 whC = wheel; stC = station; srC = sector;
00110 dx = solution13(0,0); dz = solution13(1,0);
00111 phiy = solution13(2,0);
00112 for(int c = 0; c < 3; ++c) {
00113 for(int s = 0; s < 3; ++s) {
00114 cov[c][s] = C13_copy(c, s);
00115 }
00116 }
00117 ttreeOutput->Fill();
00118 }
00119 }
00120 }
00121 f->Write();
00122 }
00123
00124
00125
00126 TMatrixD DTMuonSLToSL::returnCSLMatrix(float x, float xp, float tanphi) {
00127
00128 TMatrixD matrix(3,3);
00129
00130 matrix(0,0) = 1.0;
00131 matrix(1,0) = tanphi;
00132 matrix(0,1) = tanphi;
00133 matrix(1,1) = tanphi*tanphi;
00134 matrix(0,2) = tanphi*xp;
00135 matrix(2,0) = tanphi*xp;
00136 matrix(2,2) = tanphi*tanphi*xp*xp;
00137 matrix(2,1) = tanphi*tanphi*xp;
00138 matrix(1,2) = tanphi*tanphi*xp;
00139
00140 return matrix;
00141
00142 }
00143
00144
00145 TMatrixD DTMuonSLToSL::returnbSLMatrix(float x, float xp, float tanphi) {
00146
00147 TMatrixD matrix(3,1);
00148
00149 matrix(0,0) = -(x-xp);
00150 matrix(1,0) = -(x-xp)*tanphi;
00151 matrix(2,0) = -(x-xp)*tanphi*xp;
00152
00153 return matrix;
00154
00155 }
00156
00157
00158 void DTMuonSLToSL::setBranchTree() {
00159
00160 ttreeOutput = new TTree("DTSLToSLResult", "DTSLToSLResult");
00161
00162 ttreeOutput->Branch("wh", &whC, "wh/F");
00163 ttreeOutput->Branch("st", &stC, "st/F");
00164 ttreeOutput->Branch("sr", &srC, "sr/F");
00165 ttreeOutput->Branch("dx", &dx, "dx/F");
00166 ttreeOutput->Branch("dz", &dz, "dz/F");
00167 ttreeOutput->Branch("phiy", &phiy, "phiy/F");
00168 ttreeOutput->Branch("cov", cov, "cov[3][3]/F");
00169
00170 }
00171
00172
00173