17 const std::shared_ptr<const PedeLabelerBase>&
pedeLabeler,
18 const std::shared_ptr<const AlignPCLThresholdsHG>& theThresholds,
19 const std::shared_ptr<const PixelTopologyMap>& pixelTopologyMap)
21 theThresholds_(theThresholds),
22 pixelTopologyMap_(pixelTopologyMap),
24 millePedeEndFile_(
config.getParameter<
std::
string>(
"millePedeEndFile")),
25 millePedeLogFile_(
config.getParameter<
std::
string>(
"millePedeLogFile")),
26 millePedeResFile_(
config.getParameter<
std::
string>(
"millePedeResFile")),
47 std::ifstream endFile;
50 if (endFile.is_open()) {
51 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede end-file";
53 getline(endFile,
line);
55 if (
line.find(
"-1") != std::string::npos) {
56 getline(endFile,
line);
58 std::istringstream iss(
line);
64 std::istringstream iss(
line);
70 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede end-file.";
80 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede log-file";
87 if (
line.find(Nrec_string) != std::string::npos) {
88 std::istringstream iss(
line);
90 iss >> trash >> trash >>
Nrec_;
92 if (Nrec_ < theThresholds_->getNrecords()) {
94 <<
"Number of records used " <<
theThresholds_->getNrecords() << std::endl;
99 if (
line.find(Binaries_string) != std::string::npos) {
104 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede log-file.";
113 std::map<std::string, std::array<float, 6> > cutoffs_;
114 std::map<std::string, std::array<float, 6> > significances_;
115 std::map<std::string, std::array<float, 6> > thresholds_;
116 std::map<std::string, std::array<float, 6> > errors_;
117 std::map<std::string, std::array<float, 6> > fractions_;
119 std::map<std::string, std::array<int, 6> > countsAbove_;
120 std::map<std::string, std::array<int, 6> > countsTotal_;
124 std::vector<std::string> alignables_ =
theThresholds_->getAlignableList();
125 for (
auto& ali : alignables_) {
133 countsAbove_[ali] = {{0, 0, 0, 0, 0, 0}};
134 countsTotal_[ali] = {{0, 0, 0, 0, 0, 0}};
140 std::ifstream resFile;
143 if (resFile.is_open()) {
144 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede result-file";
147 getline(resFile,
line);
149 while (getline(resFile,
line)) {
150 std::istringstream iss(
line);
152 std::vector<std::string> tokens;
154 while (iss >>
token) {
155 tokens.push_back(
token);
158 auto alignableLabel = std::stoul(tokens[0]);
159 const auto alignable =
pedeLabeler_->alignableFromLabel(alignableLabel);
160 auto det =
getHLS(alignable);
161 int detIndex =
static_cast<int>(det);
162 auto alignableIndex = alignableLabel % 10 - 1;
165 if (tokens.size() > 4 ) {
166 countsTotal_[
detLabel][alignableIndex]++;
167 const auto paramNum =
pedeLabeler_->paramNumFromLabel(alignableLabel);
171 double ObsMove = std::stof(tokens[3]) *
multiplier_[alignableIndex];
172 double ObsErr = std::stof(tokens[4]) *
multiplier_[alignableIndex];
180 Xobs_[detIndex] = ObsMove;
184 Yobs_[detIndex] = ObsMove;
188 Zobs_[detIndex] = ObsMove;
192 tXobs_[detIndex] = ObsMove;
196 tYobs_[detIndex] = ObsMove;
200 tZobs_[detIndex] = ObsMove;
204 edm::LogError(
"MillePedeFileReader") <<
"Currently not able to handle DOF " << coord << std::endl;
235 edm::LogError(
"MillePedeFileReader") <<
"Currently not able to handle DOF " << coord << std::endl;
242 <<
"Currently not able to handle coordinate: " << coord <<
" (" << paramNum <<
") " 243 << Form(
" %s with ID %d (subdet %d)", alignableObjectId.idToString(
type),
id,
DetId(
id).
subdetId())
249 <<
" alignableLabel: " << alignableLabel <<
" with alignableIndex " << alignableIndex <<
" detIndex " 251 <<
" i.e. detLabel: " <<
detLabel <<
" (" << coord <<
")\n" 252 <<
" has movement: " << ObsMove <<
" +/- " << ObsErr <<
"\n" 253 <<
" cutoff (cutoffs_[" <<
detLabel <<
"][" << coord <<
"]): " << cutoffs_[
detLabel][alignableIndex] <<
"\n" 254 <<
" significance (significances_[" <<
detLabel <<
"][" << coord
255 <<
"]): " << significances_[
detLabel][alignableIndex] <<
"\n" 256 <<
" error thresolds (errors_[" <<
detLabel <<
"][" << coord <<
"]): " << errors_[
detLabel][alignableIndex]
258 <<
" max movement (thresholds_[" <<
detLabel <<
"][" << coord
259 <<
"]): " << thresholds_[
detLabel][alignableIndex] <<
"\n" 260 <<
" fraction (fractions_[" <<
detLabel <<
"][" << coord <<
"]): " << fractions_[
detLabel][alignableIndex]
262 <<
"=============" << std::endl;
266 <<
" Exceeding maximum thresholds for movement: " <<
std::abs(ObsMove)
267 <<
" for" <<
detLabel <<
"(" << coord <<
")";
277 <<
" Exceeding maximum thresholds for error: " <<
std::abs(ObsErr)
278 <<
" for" <<
detLabel <<
"(" << coord <<
")";
283 if (
std::abs(ObsMove / ObsErr) < significances_[
detLabel][alignableIndex]) {
291 <<
"This correction: " << ObsMove <<
"+/-" << ObsErr <<
" for " <<
detLabel <<
"(" << coord
292 <<
") will trigger a new Tracker Alignment payload!";
294 countsAbove_[
detLabel][alignableIndex]++;
299 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede result-file.";
307 std::stringstream
ss;
308 for (
auto& ali : alignables_) {
309 ss << ali << std::endl;
310 for (
long unsigned int i = 0;
i < countsTotal_[ali].size();
i++) {
311 if (countsTotal_[ali][
i] != 0 && fractions_[ali][
i] != -1) {
312 float fraction_ = countsAbove_[ali][
i] / (1.0 * countsTotal_[ali][
i]);
313 ss << static_cast<AlignPCLThresholdsHG::coordType>(
i) <<
": Fraction = " << fraction_
314 <<
" Fraction Threshold = " << fractions_[ali][
i];
315 if (fraction_ >= fractions_[ali][
i]) {
317 ss <<
" above fraction threshold" << std::endl;
324 ss <<
"No entries available or no fraction thresholds defined" << std::endl;
326 ss <<
"===================" << std::endl;
329 ss <<
"Alignment will be updated" << std::endl;
331 ss <<
"Alignment will NOT be updated" << std::endl;
341 const auto& tns =
pedeLabeler_->alignableTracker()->trackerNameSpace();
346 switch (tns.tpb().halfBarrelNumber(
id)) {
353 <<
"@SUB=MillePedeFileReader::getHLS\n" 354 <<
"Found a pixel half-barrel number that should not exist: " << tns.tpb().halfBarrelNumber(
id);
357 switch (tns.tpe().endcapNumber(
id)) {
359 switch (tns.tpe().halfCylinderNumber(
id)) {
366 <<
"@SUB=MillePedeFileReader::getHLS\n" 367 <<
"Found a pixel half-cylinder number that should not exist: " << tns.tpe().halfCylinderNumber(
id);
370 switch (tns.tpe().halfCylinderNumber(
id)) {
377 <<
"@SUB=MillePedeFileReader::getHLS\n" 378 <<
"Found a pixel half-cylinder number that should not exist: " << tns.tpe().halfCylinderNumber(
id);
382 <<
"@SUB=MillePedeFileReader::getHLS\n" 383 <<
"Found a pixel endcap number that should not exist: " << tns.tpe().endcapNumber(
id);
386 switch (tns.tpb().layerNumber(
id)) {
397 <<
"@SUB=MillePedeFileReader::getHLS\n" 398 <<
"Found a pixel layer number that should not exist: " << tns.tpb().layerNumber(
id);
401 switch (static_cast<signed int>((tns.tpe().endcapNumber(
id) == 1) ? -1 * tns.tpe().halfDiskNumber(
id)
402 : tns.tpe().halfDiskNumber(
id))) {
417 <<
"@SUB=MillePedeFileReader::getHLS\n" 418 <<
"Found a pixel disk number that should not exist: " 419 <<
static_cast<signed int>((tns.tpe().endcapNumber(
id) == 1) ? -1 * tns.tpe().halfDiskNumber(
id)
420 : tns.tpe().halfDiskNumber(
id));
430 return "TPBHalfBarrelXminus";
432 return "TPBHalfBarrelXplus";
434 return "TPEHalfCylinderXminusZminus";
436 return "TPEHalfCylinderXplusZminus";
438 return "TPEHalfCylinderXminusZplus";
440 return "TPEHalfCylinderXplusZplus";
442 return "TPBLadderLayer1";
444 return "TPBLadderLayer2";
446 return "TPBLadderLayer3";
448 return "TPBLadderLayer4";
450 return "TPEPanelDisk1";
452 return "TPEPanelDisk2";
454 return "TPEPanelDisk3";
456 return "TPEPanelDiskM1";
458 return "TPEPanelDiskM2";
460 return "TPEPanelDiskM3";
464 <<
"@SUB=MillePedeFileReader::getStringFromHLS\n" 465 <<
"Found an alignable structure not possible to map in the default AlignPCLThresholdsHG partitions";
473 std::make_pair(currentSum, currentSum +
pixelTopologyMap_->getPXBLadders(1) / 2);
476 std::make_pair(currentSum, currentSum +
pixelTopologyMap_->getPXBLadders(2) / 2);
479 std::make_pair(currentSum, currentSum +
pixelTopologyMap_->getPXBLadders(3) / 2);
482 std::make_pair(currentSum, currentSum +
pixelTopologyMap_->getPXBLadders(4) / 2);
500 const auto& tns =
pedeLabeler_->alignableTracker()->trackerNameSpace();
504 return (tns.tpb().halfBarrelNumber(
id) == 1) ? tns.tpb().ladderNumber(
id) +
indexHelper[HLS].first
505 : tns.tpb().ladderNumber(
id) +
indexHelper[HLS].second;
507 return (tns.tpb().halfBarrelNumber(
id) == 1) ? tns.tpb().ladderNumber(
id) +
indexHelper[HLS].first
508 : tns.tpb().ladderNumber(
id) +
indexHelper[HLS].second;
510 return (tns.tpb().halfBarrelNumber(
id) == 1) ? tns.tpb().ladderNumber(
id) +
indexHelper[HLS].first
511 : tns.tpb().ladderNumber(
id) +
indexHelper[HLS].second;
513 return (tns.tpb().halfBarrelNumber(
id) == 1) ? tns.tpb().ladderNumber(
id) +
indexHelper[HLS].first
514 : tns.tpb().ladderNumber(
id) +
indexHelper[HLS].second;
516 return (tns.tpe().halfCylinderNumber(
id) == 1)
517 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
518 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
520 return (tns.tpe().halfCylinderNumber(
id) == 1)
521 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
522 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
524 return (tns.tpe().halfCylinderNumber(
id) == 1)
525 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
526 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
528 return (tns.tpe().halfCylinderNumber(
id) == 1)
529 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
530 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
532 return (tns.tpe().halfCylinderNumber(
id) == 1)
533 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
534 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
536 return (tns.tpe().halfCylinderNumber(
id) == 1)
537 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
538 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
std::array< double, SIZE_LG_STRUCTS > Zobs_
Log< level::Info, true > LogVerbatim
MillePedeFileReader(const edm::ParameterSet &, const std::shared_ptr< const PedeLabelerBase > &, const std::shared_ptr< const AlignPCLThresholdsHG > &, const std::shared_ptr< const PixelTopologyMap > &)
std::array< double, SIZE_HG_STRUCTS > tXobs_HG_
std::array< double, SIZE_LG_STRUCTS > tYobs_
std::array< double, SIZE_LG_STRUCTS > tZobsErr_
std::array< double, SIZE_LG_STRUCTS > Yobs_
const std::shared_ptr< const AlignPCLThresholdsHG > theThresholds_
std::array< double, SIZE_HG_STRUCTS > XobsErr_HG_
std::bitset< 4 > updateBits_
std::array< double, SIZE_LG_STRUCTS > YobsErr_
std::array< double, SIZE_HG_STRUCTS > YobsErr_HG_
const std::shared_ptr< const PixelTopologyMap > pixelTopologyMap_
PclHLS getHLS(const Alignable *)
Log< level::Error, false > LogError
void readMillePedeLogFile()
std::array< double, SIZE_HG_STRUCTS > Zobs_HG_
std::array< double, SIZE_LG_STRUCTS > Xobs_
static constexpr std::array< double, 6 > multiplier_
std::array< double, SIZE_HG_STRUCTS > Xobs_HG_
std::array< double, SIZE_HG_STRUCTS > tYobs_HG_
const std::string millePedeLogFile_
std::array< double, SIZE_LG_STRUCTS > tXobs_
void initializeIndexHelper()
void readMillePedeResultFile()
std::array< double, SIZE_LG_STRUCTS > tYobsErr_
std::array< double, SIZE_HG_STRUCTS > ZobsErr_HG_
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
Abs< T >::type abs(const T &t)
std::array< double, SIZE_HG_STRUCTS > tZobs_HG_
Allows conversion between type and name, and vice-versa.
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::string getStringFromHLS(PclHLS HLS)
Log< level::Info, false > LogInfo
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
const std::string millePedeResFile_
std::array< double, SIZE_LG_STRUCTS > tXobsErr_
std::unordered_map< PclHLS, std::pair< int, int > > indexHelper
std::array< double, SIZE_HG_STRUCTS > tZobsErr_HG_
std::array< double, SIZE_LG_STRUCTS > XobsErr_
int getIndexForHG(align::ID id, PclHLS HLS)
const std::shared_ptr< const PedeLabelerBase > pedeLabeler_
const std::string millePedeEndFile_
std::array< double, SIZE_HG_STRUCTS > tXobsErr_HG_
std::array< double, SIZE_HG_STRUCTS > Yobs_HG_
void readMillePedeEndFile()
std::array< double, SIZE_LG_STRUCTS > tZobs_
std::map< std::string, std::array< bool, 6 > > fractionExceeded_
Log< level::Warning, false > LogWarning
std::array< double, SIZE_LG_STRUCTS > ZobsErr_
std::array< double, SIZE_HG_STRUCTS > tYobsErr_HG_