CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MillePedeFileReader.cc
Go to the documentation of this file.
1 /*** Header file ***/
3 
4 /*** system includes ***/
5 #include <cmath> // include floating-point std::abs functions
6 #include <fstream>
7 
8 /*** core framework functionality ***/
10 
11 /*** Alignment ***/
13 
14 
15 //=============================================================================
16 //=== PUBLIC METHOD IMPLEMENTATION ===
17 //=============================================================================
18 
21  const std::shared_ptr<const PedeLabelerBase>& pedeLabeler) :
22  pedeLabeler_(pedeLabeler),
23  millePedeLogFile_(config.getParameter<std::string>("millePedeLogFile")),
24  millePedeResFile_(config.getParameter<std::string>("millePedeResFile")),
25 
26  sigCut_ (config.getParameter<double>("sigCut")),
27  Xcut_ (config.getParameter<double>("Xcut")),
28  tXcut_ (config.getParameter<double>("tXcut")),
29  Ycut_ (config.getParameter<double>("Ycut")),
30  tYcut_ (config.getParameter<double>("tYcut")),
31  Zcut_ (config.getParameter<double>("Zcut")),
32  tZcut_ (config.getParameter<double>("tZcut")),
33  maxMoveCut_ (config.getParameter<double>("maxMoveCut")),
34  maxErrorCut_(config.getParameter<double>("maxErrorCut"))
35 {
36 }
37 
39 ::read() {
40  readMillePedeLogFile();
41  readMillePedeResultFile();
42 }
43 
46  return updateDB_;
47 }
48 
49 
50 
51 //=============================================================================
52 //=== PRIVATE METHOD IMPLEMENTATION ===
53 //=============================================================================
54 
57 {
58  std::ifstream logFile;
59  logFile.open(millePedeLogFile_.c_str());
60 
61  if (logFile.is_open()) {
62  edm::LogInfo("MillePedeFileReader") << "Reading millepede log-file";
64 
65  while (getline(logFile, line)) {
66  std::string Nrec_string = "NREC =";
67 
68  if (line.find(Nrec_string) != std::string::npos) {
69  std::istringstream iss(line);
70  std::string trash;
71  iss >> trash >> trash >> Nrec_;
72 
73  if (Nrec_ < 25000) {
74  updateDB_ = false;
75  }
76  }
77  }
78 
79  } else {
80  edm::LogError("MillePedeFileReader") << "Could not read millepede log-file.";
81 
82  updateDB_ = false;
83  Nrec_ = 0;
84  }
85 }
86 
89 {
90  updateDB_ = false;
91  std::ifstream resFile;
92  resFile.open(millePedeResFile_.c_str());
93 
94  if (resFile.is_open()) {
95  edm::LogInfo("MillePedeFileReader") << "Reading millepede result-file";
96 
98  getline(resFile, line); // drop first line
99 
100  while (getline(resFile, line)) {
101  std::istringstream iss(line);
102 
103  std::vector<std::string> tokens;
105  while (iss >> token) {
106  tokens.push_back(token);
107  }
108 
109  if (tokens.size() > 4 /*3*/) {
110 
111  auto alignableLabel = std::stoul(tokens[0]);
112  auto alignableIndex = alignableLabel % 10 - 1;
113  const auto alignable = pedeLabeler_->alignableFromLabel(alignableLabel);
114 
115  double ObsMove = std::stof(tokens[3]) * multiplier_[alignableIndex];
116  double ObsErr = std::stof(tokens[4]) * multiplier_[alignableIndex];
117 
118  auto det = getHLS(alignable);
119 
120  if (det != PclHLS::NotInPCL) {
121  switch (alignableIndex) {
122  case 0:
123  Xobs_[static_cast<int>(det)] = ObsMove;
124  XobsErr_[static_cast<int>(det)] = ObsErr;
125  break;
126  case 1:
127  Yobs_[static_cast<int>(det)] = ObsMove;
128  YobsErr_[static_cast<int>(det)] = ObsErr;
129  break;
130  case 2:
131  Zobs_[static_cast<int>(det)] = ObsMove;
132  ZobsErr_[static_cast<int>(det)] = ObsErr;
133  break;
134  case 3:
135  tXobs_[static_cast<int>(det)] = ObsMove;
136  tXobsErr_[static_cast<int>(det)] = ObsErr;
137  break;
138  case 4:
139  tYobs_[static_cast<int>(det)] = ObsMove;
140  tYobsErr_[static_cast<int>(det)] = ObsErr;
141  break;
142  case 5:
143  tZobs_[static_cast<int>(det)] = ObsMove;
144  tZobsErr_[static_cast<int>(det)] = ObsErr;
145  break;
146  }
147  } else {
148  continue;
149  }
150 
151  if (std::abs(ObsMove) > maxMoveCut_) {
152  updateDB_ = false;
153  break;
154 
155  } else if (std::abs(ObsMove) > cutoffs_[alignableIndex]) {
156 
157  if (std::abs(ObsErr) > maxErrorCut_) {
158  updateDB_ = false;
159  break;
160  } else {
161  if (std::abs(ObsMove/ObsErr) < sigCut_) {
162  continue;
163  }
164  }
165  updateDB_ = true;
166  }
167  }
168  }
169  } else {
170  edm::LogError("MillePedeFileReader") << "Could not read millepede result-file.";
171 
172  updateDB_ = false;
173  Nrec_ = 0;
174  }
175 }
176 
177 
179 ::getHLS(const Alignable* alignable) {
180  if (!alignable) return PclHLS::NotInPCL;
181 
182  const auto& tns = pedeLabeler_->alignableTracker()->trackerNameSpace();
183 
184  switch (alignable->alignableObjectId()) {
186  switch (tns.tpb().halfBarrelNumber(alignable->id())) {
187  case 1: return PclHLS::TPBHalfBarrelXminus;
188  case 2: return PclHLS::TPBHalfBarrelXplus;
189  default:
190  throw cms::Exception("LogicError")
191  << "@SUB=MillePedeFileReader::getHLS\n"
192  << "Found a pixel half-barrel number that should not exist: "
193  << tns.tpb().halfBarrelNumber(alignable->id());
194  }
196  switch (tns.tpe().endcapNumber(alignable->id())) {
197  case 1:
198  switch (tns.tpe().halfCylinderNumber(alignable->id())) {
199  case 1: return PclHLS::TPEHalfCylinderXminusZminus;
200  case 2: return PclHLS::TPEHalfCylinderXplusZminus;
201  default:
202  throw cms::Exception("LogicError")
203  << "@SUB=MillePedeFileReader::getHLS\n"
204  << "Found a pixel half-cylinder number that should not exist: "
205  << tns.tpe().halfCylinderNumber(alignable->id());
206  }
207  case 2:
208  switch (tns.tpe().halfCylinderNumber(alignable->id())) {
209  case 1: return PclHLS::TPEHalfCylinderXminusZplus;
210  case 2: return PclHLS::TPEHalfCylinderXplusZplus;
211  default:
212  throw cms::Exception("LogicError")
213  << "@SUB=MillePedeFileReader::getHLS\n"
214  << "Found a pixel half-cylinder number that should not exist: "
215  << tns.tpe().halfCylinderNumber(alignable->id());
216  }
217  default:
218  throw cms::Exception("LogicError")
219  << "@SUB=MillePedeFileReader::getHLS\n"
220  << "Found a pixel endcap number that should not exist: "
221  << tns.tpe().endcapNumber(alignable->id());
222  }
223  default: return PclHLS::NotInPCL;
224  }
225 }
226 
227 //=============================================================================
228 //=== STATIC CONST MEMBER DEFINITION ===
229 //=============================================================================
230 constexpr std::array<double, 6> MillePedeFileReader::multiplier_;
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:185
PclHLS getHLS(const Alignable *)
#define constexpr
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MillePedeFileReader(const edm::ParameterSet &, const std::shared_ptr< const PedeLabelerBase > &)
tuple logFile
Definition: heppy_check.py:39
static std::array< double, 6 > multiplier_