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