00001 #include <fstream>
00002
00003 #include "Alignment/SurveyAnalysis/interface/DTSurveyChamber.h"
00004 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00007 #include "Geometry/DTGeometry/interface/DTChamber.h"
00008
00009 #include "Alignment/SurveyAnalysis/interface/DTSurvey.h"
00010 #include <iostream>
00011
00012 DTSurvey::DTSurvey(const std::string& Wheel, const std::string& Chambers, int n) {
00013
00014 nameOfWheelInfoFile = Wheel;
00015 nameOfChamberInfoFile = Chambers;
00016 id = n;
00017
00018 FillWheelInfo();
00019 }
00020
00021
00022 DTSurvey::~DTSurvey() {
00023 delete [] chambers;
00024 }
00025
00026
00027 void DTSurvey::CalculateChambers() {
00028 for(int stationCounter = 0; stationCounter < 4; stationCounter++) {
00029 for(int sectorCounter = 0; sectorCounter < 14; sectorCounter++) {
00030 if(chambers[stationCounter][sectorCounter]->getNumberPoints() > 2) {
00031 chambers[stationCounter][sectorCounter]->compute();
00032 }
00033 }
00034 }
00035 }
00036
00037
00038 const DTSurveyChamber * DTSurvey::getChamber(int station, int sector) const {return chambers[station][sector];}
00039
00040 void DTSurvey::ReadChambers(edm::ESHandle<DTGeometry> pDD) {
00041
00042
00043 chambers = new DTSurveyChamber ** [4];
00044 for (int cont_stat = 0; cont_stat < 4; cont_stat++) {
00045 chambers[cont_stat] = new DTSurveyChamber * [14];
00046 for(int cont_sect = 0; cont_sect < 14; cont_sect++) {
00047 DTChamberId mId(id, cont_stat+1, cont_sect+1);
00048 chambers[cont_stat][cont_sect] = new DTSurveyChamber(id, cont_stat+1, cont_sect+1, mId.rawId());
00049 }
00050 }
00051
00052 std::cout << nameOfChamberInfoFile << std::endl;
00053 std::ifstream file(nameOfChamberInfoFile.c_str());
00054 while(!file.eof()) {
00055 int code, station, sector;
00056 double x, y, z, rms, dx, dy, dz;
00057 file >> code >> x >> y >> z >> rms >> dx >> dy >> dz;
00058 if(file.eof()) break;
00059 x = x/10.0; y=y/10.0; z=z/10.0; dx=dx/10.0; dy=dy/10.0; dz=dz/10.0;rms=rms/10.0;
00060 station = code/10000 - 1;
00061 sector = (code-(station+1)*10000)/100 - 1;
00062
00063 TMatrixD r(3,1);
00064 r(0,0) = x; r(1,0) = y;r(2,0) = z+OffsetZ;
00065 TMatrixD disp(3,1);
00066 disp(0,0) = dx; disp(1,0) = dy; disp(2,0) = dz;
00067 TMatrixD rp = Rot*r-delta;
00068 disp = disp-r+rp;
00069
00070 GlobalPoint rg(r(0,0), r(1,0), r(2,0));
00071 GlobalPoint rt(r(0,0)-disp(0,0), r(1,0)-disp(1,0), r(2,0)-disp(2,0));
00072 DTChamberId mId(id, station+1, sector+1);
00073 const DTChamber *mChamber = static_cast<const DTChamber *>(pDD->idToDet(mId));
00074 LocalPoint rl = mChamber->toLocal(rg);
00075 LocalPoint rtl = mChamber->toLocal(rt);
00076 TMatrixD rLocal(3,1);
00077 rLocal(0,0) = rl.x(); rLocal(1,0) = rl.y(); rLocal(2,0) = rl.z();
00078 TMatrixD rTeo(3,1);
00079 rTeo(0,0) = rtl.x(); rTeo(1,0) = rtl.y(); rTeo(2,0) = rtl.z();
00080 TMatrixD diff = rLocal-rTeo;
00081 TMatrixD errors(3,1);
00082 errors(0,0) = rms; errors(1,0) = rms; errors(2,0) = rms;
00083 chambers[station][sector]->addPoint(code, rLocal, diff, errors);
00084 }
00085 file.close();
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 void DTSurvey::FillWheelInfo() {
00111
00112 std::ifstream wheeltowheel(nameOfWheelInfoFile.c_str());
00113 float zOffset, deltax, deltay, deltaz, alpha, beta, gamma;
00114 wheeltowheel >> zOffset >> deltax >> deltay >> deltaz >> alpha >> beta >> gamma;
00115 wheeltowheel.close();
00116
00117 OffsetZ = zOffset;
00118
00119
00120 delta.ResizeTo(3,1);
00121 delta(0,0) = deltax/10.0;
00122 delta(1,0) = deltay/10.0;
00123 delta(2,0) = deltaz/10.0;
00124
00125
00126 Rot.ResizeTo(3,3);
00127 TMatrixD alpha_m(3,3);
00128 TMatrixD beta_m(3,3);
00129 TMatrixD gamma_m(3,3);
00130 alpha_m.Zero();
00131 beta_m.Zero();
00132 gamma_m.Zero();
00133 for(int k = 0; k < 3; k++) {
00134 alpha_m(k,k) = 1.0;
00135 beta_m(k,k) = 1.0;
00136 gamma_m(k,k) = 1.0;
00137 }
00138 alpha /= 1000.0;
00139 beta /= 1000.0;
00140 gamma /= 1000.0;
00141 alpha_m(1,1) = cos(alpha);
00142 alpha_m(1,2) = sin(alpha);
00143 alpha_m(2,1) = -sin(alpha);
00144 alpha_m(2,2) = cos(alpha);
00145 beta_m(0,0) = cos(beta);
00146 beta_m(0,2) = -sin(beta);
00147 beta_m(2,0) = sin(beta);
00148 beta_m(2,2) = cos(beta);
00149 gamma_m(0,0) = cos(gamma);
00150 gamma_m(0,1) = sin(gamma);
00151 gamma_m(1,0) = -sin(gamma);
00152 gamma_m(1,1) = cos(gamma);
00153 Rot = alpha_m*beta_m*gamma_m;
00154 }
00155
00156
00157 std::ostream &operator<<(std::ostream & flux, const DTSurvey& obj) {
00158
00159 for(int stationCounter = 0; stationCounter < 4; stationCounter++) {
00160 for(int sectorCounter = 0; sectorCounter < 14; sectorCounter++) {
00161 if(obj.getChamber(stationCounter,sectorCounter)->getNumberPoints() > 2) {
00162 const DTSurveyChamber *m_chamber = obj.getChamber(stationCounter, sectorCounter);
00163 flux << *m_chamber;
00164 }
00165 }
00166 }
00167 return flux;
00168 }