Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:46:13

0001 // System
0002 #include <fstream>
0003 #include <iostream>
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0008 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0009 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0010 
0011 #include "Alignment/SurveyAnalysis/interface/SurveyDataReader.h"
0012 
0013 using namespace std;
0014 using namespace edm;
0015 
0016 //__________________________________________________________________________________________________
0017 void SurveyDataReader::readFile(const std::string& textFileName,
0018                                 const std::string& fileType,
0019                                 const TrackerTopology* tTopo) {
0020   std::ifstream myfile(textFileName.c_str());
0021   if (!myfile.is_open())
0022     throw cms::Exception("FileAccess") << "Unable to open input text file for " << fileType.c_str();
0023 
0024   int nErrors = 0;
0025   align::ID m_detId = 0;
0026   int NINPUTS_align = 30;
0027   int NINPUTS_detId = 6;
0028   if (fileType == "TID")
0029     NINPUTS_detId++;
0030 
0031   std::vector<int> d_inputs;
0032   align::Scalars a_inputs;
0033   align::Scalars a_outputs;
0034   int itmpInput;
0035   float tmpInput;
0036 
0037   while (!myfile.eof() && myfile.good()) {
0038     d_inputs.clear();
0039     a_inputs.clear();
0040     a_outputs.clear();
0041 
0042     if (fileType == "TIB") {
0043       itmpInput = int(StripSubdetector::TIB);
0044     } else {
0045       itmpInput = int(StripSubdetector::TID);
0046     }
0047 
0048     d_inputs.push_back(itmpInput);
0049 
0050     for (int i = 0; i < NINPUTS_detId; i++) {
0051       myfile >> itmpInput;
0052       d_inputs.push_back(itmpInput);
0053     }
0054 
0055     // Calculate DetId(s)
0056     int ster = 0;  // if module is single-sided, take the module
0057                    // if double-sided get the glued module
0058 
0059     if (fileType == "TID") {
0060       m_detId = tTopo->tidDetId(d_inputs[2], d_inputs[3], d_inputs[4], d_inputs[5], d_inputs[6], ster);
0061     } else if (fileType == "TIB") {
0062       m_detId = tTopo->tibDetId(d_inputs[2], d_inputs[3], d_inputs[4], d_inputs[5], d_inputs[6], ster);
0063     }
0064 
0065     if (abs(int(m_detId) - int(d_inputs[1])) > 2) {  // Check DetId calculation ...
0066       std::cout << "ERROR : DetId - detector position mismatch! Found " << nErrors << std::endl;
0067       nErrors++;
0068     }
0069 
0070     // std::cout << m_detId << " " << d_inputs[1] << std::endl;
0071     // m_detId = d_inputs[1];
0072     for (int j = 0; j < NINPUTS_align; j++) {
0073       myfile >> tmpInput;
0074       a_inputs.push_back(tmpInput);
0075     }
0076 
0077     // Check if read succeeded (otherwise, we are at eof)
0078     if (myfile.fail())
0079       break;
0080 
0081     a_outputs = convertToAlignableCoord(a_inputs);
0082 
0083     theOriginalMap.insert(PairTypeOr(d_inputs, a_inputs));
0084     theMap.insert(PairType(m_detId, a_outputs));
0085   }
0086 }
0087 //__________________________________________________________________________________________________
0088 align::Scalars SurveyDataReader::convertToAlignableCoord(const align::Scalars& align_params) {
0089   align::Scalars align_outputs;
0090 
0091   // Convert to coordinates that TrackerAlignment can read in
0092 
0093   // Center of sensor
0094   AlgebraicVector geomCent(3);
0095   AlgebraicVector surCent(3);
0096   for (int ii = 0; ii < 3; ii++) {
0097     geomCent[ii] = align_params[ii];
0098     surCent[ii] = align_params[ii + 15];
0099   }
0100   surCent -= geomCent;
0101 
0102   align_outputs.push_back(surCent[0]);
0103   align_outputs.push_back(surCent[1]);
0104   align_outputs.push_back(surCent[2]);
0105 
0106   // Rotation matrices
0107   for (int ii = 3; ii < 12; ii++) {
0108     align_outputs.push_back(align_params[ii]);
0109   }
0110   for (int ii = 18; ii < 27; ii++) {
0111     align_outputs.push_back(align_params[ii]);
0112   }
0113 
0114   return align_outputs;
0115 }