CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SurveyDataReader.cc
Go to the documentation of this file.
1 // System
2 #include <fstream>
3 #include <iostream>
4 
6 
9 // #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
10 
12 
13 using namespace std;
14 using namespace edm;
15 
16 //__________________________________________________________________________________________________
17 void SurveyDataReader::readFile( const std::string& textFileName, const std::string& fileType, const TrackerTopology* tTopo) {
18 
19  std::ifstream myfile( textFileName.c_str() );
20  if ( !myfile.is_open() )
21  throw cms::Exception("FileAccess") << "Unable to open input text file for " << fileType.c_str();
22 
23  int nErrors = 0;
24  align::ID m_detId = 0;
25  int NINPUTS_align = 30;
26  int NINPUTS_detId = 6;
27  if (fileType == "TID") NINPUTS_detId++;
28 
29  std::vector<int> d_inputs;
30  align::Scalars a_inputs;
31  align::Scalars a_outputs;
32  int itmpInput;
33  float tmpInput;
34 
35  while ( !myfile.eof() && myfile.good() )
36  {
37  d_inputs.clear();
38  a_inputs.clear();
39  a_outputs.clear();
40 
41  if (fileType == "TIB") {
42  itmpInput = int(StripSubdetector::TIB) ;
43  } else {
44  itmpInput = int(StripSubdetector::TID) ;
45  }
46 
47  d_inputs.push_back( itmpInput );
48 
49  for ( int i=0; i<NINPUTS_detId; i++ )
50  {
51  myfile >> itmpInput;
52  d_inputs.push_back( itmpInput );
53  }
54 
55  // Calculate DetId(s)
56  int ster = 0; // if module is single-sided, take the module
57  // if double-sided get the glued module
58 
59  if (fileType == "TID") {
60 
61  m_detId = tTopo->tidDetId(d_inputs[2], d_inputs[3], d_inputs[4], d_inputs[5], d_inputs[6], ster);
62  }
63  else if (fileType == "TIB") {
64 
65  m_detId = tTopo->tibDetId(d_inputs[2], d_inputs[3], d_inputs[4], d_inputs[5], d_inputs[6], ster);
66  }
67 
68  if (abs(int(m_detId) - int(d_inputs[1])) > 2) { // Check DetId calculation ...
69  std::cout << "ERROR : DetId - detector position mismatch! Found " << nErrors << std::endl;
70  nErrors++;
71  }
72 
73  // std::cout << m_detId << " " << d_inputs[1] << std::endl;
74  // m_detId = d_inputs[1];
75  for ( int j=0; j<NINPUTS_align; j++ )
76  {
77  myfile >> tmpInput;
78  a_inputs.push_back( tmpInput );
79  }
80 
81  // Check if read succeeded (otherwise, we are at eof)
82  if ( myfile.fail() ) break;
83 
84  a_outputs = convertToAlignableCoord( a_inputs );
85 
86  theOriginalMap.insert( PairTypeOr( d_inputs, a_inputs ));
87  theMap.insert( PairType( m_detId, a_outputs ));
88 
89  }
90 
91 }
92 //__________________________________________________________________________________________________
95 {
96  align::Scalars align_outputs;
97 
98  // Convert to coordinates that TrackerAlignment can read in
99 
100  // Center of sensor
101  AlgebraicVector geomCent(3);
102  AlgebraicVector surCent(3);
103  for (int ii = 0; ii < 3; ii++) {
104  geomCent[ii] = align_params[ii];
105  surCent[ii] = align_params[ii+15];
106  }
107  surCent -= geomCent;
108 
109  align_outputs.push_back( surCent[0] );
110  align_outputs.push_back( surCent[1] );
111  align_outputs.push_back( surCent[2] );
112 
113  // Rotation matrices
114  for (int ii = 3; ii < 12; ii++) {
115  align_outputs.push_back( align_params[ii] );
116  }
117  for (int ii = 18; ii < 27; ii++) {
118  align_outputs.push_back( align_params[ii] );
119  }
120 
121  return align_outputs;
122 }
int i
Definition: DBlmapReader.cc:9
uint32_t ID
Definition: Definitions.h:26
int ii
Definition: cuy.py:588
std::pair< align::ID, align::Scalars > PairType
std::vector< Scalar > Scalars
Definition: Utilities.h:22
std::pair< std::vector< int >, align::Scalars > PairTypeOr
DetId tidDetId(uint32_t side, uint32_t wheel, uint32_t ring, uint32_t module_fw_bw, uint32_t module, uint32_t ster) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
CLHEP::HepVector AlgebraicVector
DetId tibDetId(uint32_t layer, uint32_t str_fw_bw, uint32_t str_int_ext, uint32_t str, uint32_t module, uint32_t ster) const
void readFile(const std::string &textFileName, const std::string &fileType, const TrackerTopology *tTopo)
Read given text file.
align::Scalars convertToAlignableCoord(const align::Scalars &align_params)
tuple cout
Definition: gather_cfg.py:121