CMS 3D CMS Logo

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 /*** Alignment ***/
10 
11 //=============================================================================
12 //=== PUBLIC METHOD IMPLEMENTATION ===
13 //=============================================================================
14 
16  const std::shared_ptr<const PedeLabelerBase>& pedeLabeler,
17  const std::shared_ptr<const AlignPCLThresholds>& theThresholds)
18  : pedeLabeler_(pedeLabeler),
19  theThresholds_(theThresholds),
20  millePedeEndFile_(config.getParameter<std::string>("millePedeEndFile")),
21  millePedeLogFile_(config.getParameter<std::string>("millePedeLogFile")),
22  millePedeResFile_(config.getParameter<std::string>("millePedeResFile")) {}
23 
28 }
29 
31 
32 //=============================================================================
33 //=== PRIVATE METHOD IMPLEMENTATION ===
34 //=============================================================================
36  std::ifstream endFile;
37  endFile.open(millePedeEndFile_.c_str());
38 
39  if (endFile.is_open()) {
40  edm::LogInfo("MillePedeFileReader") << "Reading millepede end-file";
42  getline(endFile, line);
43  std::string trash;
44  if (line.find("-1") != std::string::npos) {
45  getline(endFile, line);
47  std::istringstream iss(line);
48  iss >> exitCode_ >> trash;
49  edm::LogInfo("MillePedeFileReader")
50  << " Pede exit code is: " << exitCode_ << " (" << exitMessage_ << ")" << std::endl;
51  } else {
53  std::istringstream iss(line);
54  iss >> exitCode_ >> trash;
55  edm::LogInfo("MillePedeFileReader")
56  << " Pede exit code is: " << exitCode_ << " (" << exitMessage_ << ")" << std::endl;
57  }
58  } else {
59  edm::LogError("MillePedeFileReader") << "Could not read millepede end-file.";
60  exitMessage_ = "no exit code found";
61  }
62 }
63 
65  std::ifstream logFile;
66  logFile.open(millePedeLogFile_.c_str());
67 
68  if (logFile.is_open()) {
69  edm::LogInfo("MillePedeFileReader") << "Reading millepede log-file";
71 
72  while (getline(logFile, line)) {
73  std::string Nrec_string = "NREC =";
74  std::string Binaries_string = "C_binary";
75 
76  if (line.find(Nrec_string) != std::string::npos) {
77  std::istringstream iss(line);
78  std::string trash;
79  iss >> trash >> trash >> Nrec_;
80 
81  if (Nrec_ < theThresholds_->getNrecords()) {
82  edm::LogInfo("MillePedeFileReader")
83  << "Number of records used " << theThresholds_->getNrecords() << std::endl;
84  updateDB_ = false;
85  }
86  }
87 
88  if (line.find(Binaries_string) != std::string::npos) {
89  binariesAmount_ += 1;
90  }
91  }
92  } else {
93  edm::LogError("MillePedeFileReader") << "Could not read millepede log-file.";
94 
95  updateDB_ = false;
96  Nrec_ = 0;
97  }
98 }
99 
101  // cutoffs by coordinate and by alignable
102  std::map<std::string, std::array<float, 6> > cutoffs_;
103  std::map<std::string, std::array<float, 6> > significances_;
104  std::map<std::string, std::array<float, 6> > thresholds_;
105  std::map<std::string, std::array<float, 6> > errors_;
106 
107  std::vector<std::string> alignables_ = theThresholds_->getAlignableList();
108  for (auto& ali : alignables_) {
109  cutoffs_[ali] = theThresholds_->getCut(ali);
110  significances_[ali] = theThresholds_->getSigCut(ali);
111  thresholds_[ali] = theThresholds_->getMaxMoveCut(ali);
112  errors_[ali] = theThresholds_->getMaxErrorCut(ali);
113  }
114 
115  updateDB_ = false;
116  vetoUpdateDB_ = false;
117  std::ifstream resFile;
118  resFile.open(millePedeResFile_.c_str());
119 
120  if (resFile.is_open()) {
121  edm::LogInfo("MillePedeFileReader") << "Reading millepede result-file";
122 
124  getline(resFile, line); // drop first line
125 
126  while (getline(resFile, line)) {
127  std::istringstream iss(line);
128 
129  std::vector<std::string> tokens;
131  while (iss >> token) {
132  tokens.push_back(token);
133  }
134 
135  if (tokens.size() > 4 /*3*/) {
136  auto alignableLabel = std::stoul(tokens[0]);
137  auto alignableIndex = alignableLabel % 10 - 1;
138  const auto alignable = pedeLabeler_->alignableFromLabel(alignableLabel);
139 
140  double ObsMove = std::stof(tokens[3]) * multiplier_[alignableIndex];
141  double ObsErr = std::stof(tokens[4]) * multiplier_[alignableIndex];
142 
143  auto det = getHLS(alignable);
144  int detIndex = static_cast<int>(det);
145  auto coord = static_cast<AlignPCLThresholds::coordType>(alignableIndex);
147 
148  if (det != PclHLS::NotInPCL) {
149  switch (coord) {
151  Xobs_[detIndex] = ObsMove;
152  XobsErr_[detIndex] = ObsErr;
153  break;
155  Yobs_[detIndex] = ObsMove;
156  YobsErr_[detIndex] = ObsErr;
157  break;
159  Zobs_[detIndex] = ObsMove;
160  ZobsErr_[detIndex] = ObsErr;
161  break;
163  tXobs_[detIndex] = ObsMove;
164  tXobsErr_[detIndex] = ObsErr;
165  break;
167  tYobs_[detIndex] = ObsMove;
168  tYobsErr_[detIndex] = ObsErr;
169  break;
171  tZobs_[detIndex] = ObsMove;
172  tZobsErr_[detIndex] = ObsErr;
173  break;
174  default:
175  edm::LogError("MillePedeFileReader") << "Currently not able to handle DOF " << coord << std::endl;
176  break;
177  }
178  } else {
179  continue;
180  }
181 
182  edm::LogVerbatim("MillePedeFileReader")
183  << " alignableLabel: " << alignableLabel << " with alignableIndex " << alignableIndex << " detIndex"
184  << detIndex << "\n"
185  << " i.e. detLabel: " << detLabel << " (" << coord << ")\n"
186  << " has movement: " << ObsMove << " +/- " << ObsErr << "\n"
187  << " cutoff (cutoffs_[" << detLabel << "][" << coord << "]): " << cutoffs_[detLabel][alignableIndex] << "\n"
188  << " significance (significances_[" << detLabel << "][" << coord
189  << "]): " << significances_[detLabel][alignableIndex] << "\n"
190  << " error thresolds (errors_[" << detLabel << "][" << coord << "]): " << errors_[detLabel][alignableIndex]
191  << "\n"
192  << " max movement (thresholds_[" << detLabel << "][" << coord
193  << "]): " << thresholds_[detLabel][alignableIndex] << "\n"
194  << "=============" << std::endl;
195 
196  if (std::abs(ObsMove) > thresholds_[detLabel][alignableIndex]) {
197  edm::LogWarning("MillePedeFileReader") << "Aborting payload creation."
198  << " Exceeding maximum thresholds for movement: " << std::abs(ObsMove)
199  << " for" << detLabel << "(" << coord << ")";
200  updateBits_.set(0);
201  vetoUpdateDB_ = true;
202  continue;
203 
204  } else if (std::abs(ObsMove) > cutoffs_[detLabel][alignableIndex]) {
205  updateBits_.set(1);
206 
207  if (std::abs(ObsErr) > errors_[detLabel][alignableIndex]) {
208  edm::LogWarning("MillePedeFileReader") << "Aborting payload creation."
209  << " Exceeding maximum thresholds for error: " << std::abs(ObsErr)
210  << " for" << detLabel << "(" << coord << ")";
211  updateBits_.set(2);
212  vetoUpdateDB_ = true;
213  continue;
214  } else {
215  if (std::abs(ObsMove / ObsErr) < significances_[detLabel][alignableIndex]) {
216  updateBits_.set(3);
217  continue;
218  }
219  }
220  updateDB_ = true;
221  edm::LogInfo("MillePedeFileReader")
222  << "This correction: " << ObsMove << "+/-" << ObsErr << " for " << detLabel << "(" << coord
223  << ") will trigger a new Tracker Alignment payload!";
224  }
225  }
226  }
227  } else {
228  edm::LogError("MillePedeFileReader") << "Could not read millepede result-file.";
229 
230  updateDB_ = false;
231  Nrec_ = 0;
232  }
233 }
234 
236  if (!alignable)
237  return PclHLS::NotInPCL;
238 
239  const auto& tns = pedeLabeler_->alignableTracker()->trackerNameSpace();
240 
241  switch (alignable->alignableObjectId()) {
243  switch (tns.tpb().halfBarrelNumber(alignable->id())) {
244  case 1:
246  case 2:
248  default:
249  throw cms::Exception("LogicError") << "@SUB=MillePedeFileReader::getHLS\n"
250  << "Found a pixel half-barrel number that should not exist: "
251  << tns.tpb().halfBarrelNumber(alignable->id());
252  }
254  switch (tns.tpe().endcapNumber(alignable->id())) {
255  case 1:
256  switch (tns.tpe().halfCylinderNumber(alignable->id())) {
257  case 1:
259  case 2:
261  default:
262  throw cms::Exception("LogicError") << "@SUB=MillePedeFileReader::getHLS\n"
263  << "Found a pixel half-cylinder number that should not exist: "
264  << tns.tpe().halfCylinderNumber(alignable->id());
265  }
266  case 2:
267  switch (tns.tpe().halfCylinderNumber(alignable->id())) {
268  case 1:
270  case 2:
272  default:
273  throw cms::Exception("LogicError") << "@SUB=MillePedeFileReader::getHLS\n"
274  << "Found a pixel half-cylinder number that should not exist: "
275  << tns.tpe().halfCylinderNumber(alignable->id());
276  }
277  default:
278  throw cms::Exception("LogicError")
279  << "@SUB=MillePedeFileReader::getHLS\n"
280  << "Found a pixel endcap number that should not exist: " << tns.tpe().endcapNumber(alignable->id());
281  }
282  default:
283  return PclHLS::NotInPCL;
284  }
285 }
286 
288  switch (HLS) {
290  return "TPBHalfBarrelXminus";
292  return "TPBHalfBarrelXplus";
294  return "TPEHalfCylinderXminusZminus";
296  return "TPEHalfCylinderXplusZminus";
298  return "TPEHalfCylinderXminusZplus";
300  return "TPEHalfCylinderXplusZplus";
301  default:
302  throw cms::Exception("LogicError")
303  << "@SUB=MillePedeFileReader::getStringFromHLS\n"
304  << "Found an alignable structure not possible to map in the default AlignPCLThresholds partitions";
305  }
306 }
307 
308 //=============================================================================
309 //=== STATIC CONST MEMBER DEFINITION ===
310 //=============================================================================
311 constexpr std::array<double, 6> MillePedeFileReader::multiplier_;
MillePedeFileReader::readMillePedeLogFile
void readMillePedeLogFile()
Definition: MillePedeFileReader.cc:64
AlignPCLThresholds::theta_Y
Definition: AlignPCLThresholds.h:14
align::TPBHalfBarrel
Definition: StructureType.h:26
MillePedeFileReader::PclHLS
PclHLS
Definition: MillePedeFileReader.h:96
MillePedeFileReader::storeAlignments
bool storeAlignments()
Definition: MillePedeFileReader.cc:30
MillePedeFileReader::binariesAmount_
int binariesAmount_
Definition: MillePedeFileReader.h:148
MillePedeFileReader::multiplier_
static constexpr std::array< double, 6 > multiplier_
Definition: MillePedeFileReader.h:130
MillePedeFileReader::read
void read()
Definition: MillePedeFileReader.cc:24
MillePedeFileReader::updateBits_
std::bitset< 4 > updateBits_
Definition: MillePedeFileReader.h:145
Alignable
Definition: Alignable.h:27
MillePedeFileReader::PclHLS::TPEHalfCylinderXplusZplus
edm::LogInfo
Definition: MessageLogger.h:254
MillePedeFileReader::Nrec_
int Nrec_
Definition: MillePedeFileReader.h:150
AlignPCLThresholds::X
Definition: AlignPCLThresholds.h:14
AlignPCLThresholds::theta_Z
Definition: AlignPCLThresholds.h:14
MillePedeFileReader::tZobs_
std::array< double, 6 > tZobs_
Definition: MillePedeFileReader.h:166
config
Definition: config.py:1
MillePedeFileReader::exitCode_
int exitCode_
Definition: MillePedeFileReader.h:151
MillePedeFileReader::ZobsErr_
std::array< double, 6 > ZobsErr_
Definition: MillePedeFileReader.h:165
Alignable::alignableObjectId
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
MillePedeFileReader::pedeLabeler_
const std::shared_ptr< const PedeLabelerBase > pedeLabeler_
Definition: MillePedeFileReader.h:119
MillePedeFileReader::PclHLS::NotInPCL
MillePedeFileReader::millePedeLogFile_
const std::string millePedeLogFile_
Definition: MillePedeFileReader.h:126
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
MillePedeFileReader::tYobsErr_
std::array< double, 6 > tYobsErr_
Definition: MillePedeFileReader.h:162
MillePedeFileReader::PclHLS::TPEHalfCylinderXminusZplus
edm::ParameterSet
Definition: ParameterSet.h:36
MillePedeAlignmentAlgorithm_cfi.pedeLabeler
pedeLabeler
Definition: MillePedeAlignmentAlgorithm_cfi.py:38
edm::LogError
Definition: MessageLogger.h:183
MillePedeFileReader::tYobs_
std::array< double, 6 > tYobs_
Definition: MillePedeFileReader.h:161
align::TPEHalfCylinder
Definition: StructureType.h:34
MillePedeFileReader::readMillePedeResultFile
void readMillePedeResultFile()
Definition: MillePedeFileReader.cc:100
Alignable::id
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
Definition: Alignable.h:180
MillePedeFileReader::tZobsErr_
std::array< double, 6 > tZobsErr_
Definition: MillePedeFileReader.h:167
MillePedeFileReader::PclHLS::TPEHalfCylinderXminusZminus
MillePedeFileReader::PclHLS::TPBHalfBarrelXminus
MillePedeFileReader::millePedeEndFile_
const std::string millePedeEndFile_
Definition: MillePedeFileReader.h:125
MillePedeFileReader::PclHLS::TPEHalfCylinderXplusZminus
MillePedeFileReader::updateDB_
bool updateDB_
Definition: MillePedeFileReader.h:137
MillePedeFileReader::millePedeResFile_
const std::string millePedeResFile_
Definition: MillePedeFileReader.h:127
AlignPCLThresholds::Z
Definition: AlignPCLThresholds.h:14
edm::LogVerbatim
Definition: MessageLogger.h:297
MillePedeFileReader::YobsErr_
std::array< double, 6 > YobsErr_
Definition: MillePedeFileReader.h:160
MillePedeFileReader::tXobsErr_
std::array< double, 6 > tXobsErr_
Definition: MillePedeFileReader.h:157
AlignPCLThresholds::Y
Definition: AlignPCLThresholds.h:14
MillePedeFileReader::MillePedeFileReader
MillePedeFileReader(const edm::ParameterSet &, const std::shared_ptr< const PedeLabelerBase > &, const std::shared_ptr< const AlignPCLThresholds > &)
Definition: MillePedeFileReader.cc:15
MillePedeFileReader::PclHLS::TPBHalfBarrelXplus
MillePedeFileReader::tXobs_
std::array< double, 6 > tXobs_
Definition: MillePedeFileReader.h:156
MillePedeFileReader::getStringFromHLS
std::string getStringFromHLS(PclHLS HLS)
Definition: MillePedeFileReader.cc:287
clustersummarymultiplicityprod_cfi.detLabel
detLabel
Definition: clustersummarymultiplicityprod_cfi.py:6
std
Definition: JetResolutionObject.h:76
MillePedeFileReader::readMillePedeEndFile
void readMillePedeEndFile()
Definition: MillePedeFileReader.cc:35
MillePedeFileReader::Xobs_
std::array< double, 6 > Xobs_
Definition: MillePedeFileReader.h:154
MillePedeFileReader::Zobs_
std::array< double, 6 > Zobs_
Definition: MillePedeFileReader.h:164
Exception
Definition: hltDiff.cc:246
AlignPCLThresholds::theta_X
Definition: AlignPCLThresholds.h:14
MillePedeFileReader.h
MillePedeFileReader::theThresholds_
const std::shared_ptr< const AlignPCLThresholds > theThresholds_
Definition: MillePedeFileReader.h:122
heppy_check.logFile
logFile
Definition: heppy_check.py:40
AlignableTracker.h
MillePedeFileReader::XobsErr_
std::array< double, 6 > XobsErr_
Definition: MillePedeFileReader.h:155
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
mps_splice.line
line
Definition: mps_splice.py:76
MillePedeFileReader::Yobs_
std::array< double, 6 > Yobs_
Definition: MillePedeFileReader.h:159
MillePedeFileReader::exitMessage_
std::string exitMessage_
Definition: MillePedeFileReader.h:152
MillePedeFileReader::vetoUpdateDB_
bool vetoUpdateDB_
Definition: MillePedeFileReader.h:138
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316
MillePedeFileReader::getHLS
PclHLS getHLS(const Alignable *)
Definition: MillePedeFileReader.cc:235