CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/SurveyAnalysis/src/SurveyDataReader.cc

Go to the documentation of this file.
00001 // System
00002 #include <fstream>
00003 #include <iostream>
00004 
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00008 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00009 // #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00010 
00011 #include "Alignment/SurveyAnalysis/interface/SurveyDataReader.h"
00012 
00013 using namespace std;
00014 using namespace edm;
00015 
00016 //__________________________________________________________________________________________________
00017 void SurveyDataReader::readFile( const std::string& textFileName ,const std::string& fileType )
00018 {
00019   
00020   std::ifstream myfile( textFileName.c_str() );
00021   if ( !myfile.is_open() ) 
00022     throw cms::Exception("FileAccess") << "Unable to open input text file for " << fileType.c_str();
00023 
00024   int nErrors = 0;
00025   align::ID m_detId = 0;
00026   int NINPUTS_align = 30;
00027   int NINPUTS_detId = 6;
00028   if (fileType == "TID") NINPUTS_detId++;
00029 
00030   std::vector<int> d_inputs;
00031   align::Scalars a_inputs;
00032   align::Scalars a_outputs;
00033   int itmpInput;
00034   float tmpInput; 
00035 
00036   while ( !myfile.eof() && myfile.good() )
00037         {
00038           d_inputs.clear();
00039           a_inputs.clear();
00040           a_outputs.clear();
00041 
00042           if (fileType == "TIB") {
00043             itmpInput = int(StripSubdetector::TIB) ; 
00044           } else {
00045             itmpInput = int(StripSubdetector::TID) ;
00046           }
00047 
00048           d_inputs.push_back( itmpInput );
00049 
00050           for ( int i=0; i<NINPUTS_detId; i++ )
00051                 {
00052                   myfile >> itmpInput;
00053                   d_inputs.push_back( itmpInput );
00054                 }
00055             
00056           // Calculate DetId(s)
00057           int ster = 0;  // if module is single-sided, take the module
00058                          // if double-sided get the glued module
00059 
00060           if (fileType == "TID") {
00061             TIDDetId *myTDI; 
00062             myTDI = new TIDDetId( d_inputs[2], d_inputs[3], d_inputs[4], d_inputs[5], d_inputs[6], ster);
00063             m_detId = myTDI->rawId();
00064           }
00065           else if (fileType == "TIB") {
00066             TIBDetId *myTBI = new TIBDetId( d_inputs[2], d_inputs[3], d_inputs[4], d_inputs[5], d_inputs[6], ster); 
00067             m_detId = myTBI->rawId();
00068           }
00069 
00070           if (abs(int(m_detId) - int(d_inputs[1])) > 2) {  // Check DetId calculation ...
00071             std::cout << "ERROR : DetId - detector position mismatch! Found " << nErrors << std::endl;
00072             nErrors++;
00073           }
00074 
00075           // std::cout << m_detId << " " << d_inputs[1] << std::endl;
00076           // m_detId = d_inputs[1];
00077           for ( int j=0; j<NINPUTS_align; j++ )
00078                 {
00079                   myfile >> tmpInput;
00080                   a_inputs.push_back( tmpInput );
00081                 }
00082 
00083           // Check if read succeeded (otherwise, we are at eof)
00084           if ( myfile.fail() ) break;
00085 
00086           a_outputs = convertToAlignableCoord( a_inputs );
00087 
00088           theOriginalMap.insert( PairTypeOr( d_inputs, a_inputs ));
00089           theMap.insert( PairType( m_detId, a_outputs ));
00090          
00091         }
00092 
00093 }
00094 //__________________________________________________________________________________________________
00095 align::Scalars 
00096 SurveyDataReader::convertToAlignableCoord( const align::Scalars& align_params ) 
00097 {
00098       align::Scalars align_outputs;
00099 
00100       // Convert to coordinates that TrackerAlignment can read in
00101      
00102       // Center of sensor 
00103       AlgebraicVector geomCent(3);
00104       AlgebraicVector surCent(3);
00105       for (int ii = 0; ii < 3; ii++) {
00106         geomCent[ii] = align_params[ii];
00107         surCent[ii] = align_params[ii+15];
00108       }
00109       surCent -= geomCent;
00110                  
00111       align_outputs.push_back( surCent[0] ); 
00112       align_outputs.push_back( surCent[1] );   
00113       align_outputs.push_back( surCent[2] );   
00114       
00115       // Rotation matrices
00116       for (int ii = 3; ii < 12; ii++) { 
00117           align_outputs.push_back( align_params[ii] );
00118       }
00119       for (int ii = 18; ii < 27; ii++) { 
00120           align_outputs.push_back( align_params[ii] );
00121       } 
00122            
00123       return align_outputs; 
00124 }