CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Alignment/SurveyAnalysis/src/DTSurvey.cc

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