CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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(d_inputs[2], d_inputs[3], d_inputs[4], d_inputs[5], d_inputs[6], ster);
00062             m_detId = myTDI.rawId();
00063           }
00064           else if (fileType == "TIB") {
00065             TIBDetId myTBI(d_inputs[2], d_inputs[3], d_inputs[4], d_inputs[5], d_inputs[6], ster); 
00066             m_detId = myTBI.rawId();
00067           }
00068 
00069           if (abs(int(m_detId) - int(d_inputs[1])) > 2) {  // Check DetId calculation ...
00070             std::cout << "ERROR : DetId - detector position mismatch! Found " << nErrors << std::endl;
00071             nErrors++;
00072           }
00073 
00074           // std::cout << m_detId << " " << d_inputs[1] << std::endl;
00075           // m_detId = d_inputs[1];
00076           for ( int j=0; j<NINPUTS_align; j++ )
00077                 {
00078                   myfile >> tmpInput;
00079                   a_inputs.push_back( tmpInput );
00080                 }
00081 
00082           // Check if read succeeded (otherwise, we are at eof)
00083           if ( myfile.fail() ) break;
00084 
00085           a_outputs = convertToAlignableCoord( a_inputs );
00086 
00087           theOriginalMap.insert( PairTypeOr( d_inputs, a_inputs ));
00088           theMap.insert( PairType( m_detId, a_outputs ));
00089          
00090         }
00091 
00092 }
00093 //__________________________________________________________________________________________________
00094 align::Scalars 
00095 SurveyDataReader::convertToAlignableCoord( const align::Scalars& align_params ) 
00096 {
00097       align::Scalars align_outputs;
00098 
00099       // Convert to coordinates that TrackerAlignment can read in
00100      
00101       // Center of sensor 
00102       AlgebraicVector geomCent(3);
00103       AlgebraicVector surCent(3);
00104       for (int ii = 0; ii < 3; ii++) {
00105         geomCent[ii] = align_params[ii];
00106         surCent[ii] = align_params[ii+15];
00107       }
00108       surCent -= geomCent;
00109                  
00110       align_outputs.push_back( surCent[0] ); 
00111       align_outputs.push_back( surCent[1] );   
00112       align_outputs.push_back( surCent[2] );   
00113       
00114       // Rotation matrices
00115       for (int ii = 3; ii < 12; ii++) { 
00116           align_outputs.push_back( align_params[ii] );
00117       }
00118       for (int ii = 18; ii < 27; ii++) { 
00119           align_outputs.push_back( align_params[ii] );
00120       } 
00121            
00122       return align_outputs; 
00123 }