18 const std::shared_ptr<const PedeLabelerBase>&
pedeLabeler,
19 const std::shared_ptr<const AlignPCLThresholdsHG>& theThresholds,
20 const std::shared_ptr<const PixelTopologyMap>& pixelTopologyMap,
21 const std::shared_ptr<const SiPixelQuality>& pixelQualityMap)
23 theThresholds_(theThresholds),
24 pixelTopologyMap_(pixelTopologyMap),
25 ignoreInactiveAlignables_(
config.getParameter<
bool>(
"ignoreInactiveAlignables")),
26 quality_(pixelQualityMap),
28 millePedeEndFile_(
config.getParameter<
std::
string>(
"millePedeEndFile")),
29 millePedeLogFile_(
config.getParameter<
std::
string>(
"millePedeLogFile")),
30 millePedeResFile_(
config.getParameter<
std::
string>(
"millePedeResFile")),
51 std::ifstream endFile;
54 if (endFile.is_open()) {
55 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede end-file";
57 getline(endFile,
line);
59 if (
line.find(
"-1") != std::string::npos) {
60 getline(endFile,
line);
62 std::istringstream iss(
line);
68 std::istringstream iss(
line);
74 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede end-file.";
84 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede log-file";
91 if (
line.find(Nrec_string) != std::string::npos) {
92 std::istringstream iss(
line);
94 iss >> trash >> trash >>
Nrec_;
96 if (Nrec_ < theThresholds_->getNrecords()) {
98 <<
"Number of records used " <<
theThresholds_->getNrecords() << std::endl;
103 if (
line.find(Binaries_string) != std::string::npos) {
108 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede log-file.";
117 std::map<std::string, std::array<float, 6> > cutoffs_;
118 std::map<std::string, std::array<float, 6> > significances_;
119 std::map<std::string, std::array<float, 6> > thresholds_;
120 std::map<std::string, std::array<float, 6> > errors_;
121 std::map<std::string, std::array<float, 6> > fractions_;
123 std::map<std::string, std::array<int, 6> > countsAbove_;
124 std::map<std::string, std::array<int, 6> > countsTotal_;
128 std::vector<std::string> alignables_ =
theThresholds_->getAlignableList();
129 for (
auto& ali : alignables_) {
137 countsAbove_[ali] = {{0, 0, 0, 0, 0, 0}};
138 countsTotal_[ali] = {{0, 0, 0, 0, 0, 0}};
144 std::ifstream resFile;
147 if (resFile.is_open()) {
148 edm::LogInfo(
"MillePedeFileReader") <<
"Reading millepede result-file";
151 getline(resFile,
line);
153 while (getline(resFile,
line)) {
154 std::istringstream iss(
line);
156 std::vector<std::string> tokens;
158 while (iss >>
token) {
159 tokens.push_back(
token);
162 auto alignableLabel = std::stoul(tokens[0]);
163 const auto alignable =
pedeLabeler_->alignableFromLabel(alignableLabel);
164 auto det =
getHLS(alignable);
167 int detIndex =
static_cast<int>(det);
168 auto alignableIndex = alignableLabel % 10 - 1;
175 if (tokens.size() > 4 ) {
176 countsTotal_[
detLabel][alignableIndex]++;
177 const auto paramNum =
pedeLabeler_->paramNumFromLabel(alignableLabel);
181 double ObsMove = std::stof(tokens[3]) *
multiplier_[alignableIndex];
182 double ObsErr = std::stof(tokens[4]) *
multiplier_[alignableIndex];
190 Xobs_[detIndex] = ObsMove;
194 Yobs_[detIndex] = ObsMove;
198 Zobs_[detIndex] = ObsMove;
202 tXobs_[detIndex] = ObsMove;
206 tYobs_[detIndex] = ObsMove;
210 tZobs_[detIndex] = ObsMove;
214 edm::LogError(
"MillePedeFileReader") <<
"Currently not able to handle DOF " << coord << std::endl;
245 edm::LogError(
"MillePedeFileReader") <<
"Currently not able to handle DOF " << coord << std::endl;
252 <<
"Currently not able to handle coordinate: " << coord <<
" (" << paramNum <<
") " 253 << Form(
" %s with ID %d (subdet %d)", alignableObjectId.idToString(
type),
id,
DetId(
id).
subdetId())
259 <<
" alignableLabel: " << alignableLabel <<
" with alignableIndex " << alignableIndex <<
" detIndex " 261 <<
" i.e. detLabel: " <<
detLabel <<
" (" << coord <<
")\n" 262 <<
" has movement: " << ObsMove <<
" +/- " << ObsErr <<
"\n" 263 <<
" cutoff (cutoffs_[" <<
detLabel <<
"][" << coord <<
"]): " << cutoffs_[
detLabel][alignableIndex] <<
"\n" 264 <<
" significance (significances_[" <<
detLabel <<
"][" << coord
265 <<
"]): " << significances_[
detLabel][alignableIndex] <<
"\n" 266 <<
" error thresolds (errors_[" <<
detLabel <<
"][" << coord <<
"]): " << errors_[
detLabel][alignableIndex]
268 <<
" max movement (thresholds_[" <<
detLabel <<
"][" << coord
269 <<
"]): " << thresholds_[
detLabel][alignableIndex] <<
"\n" 270 <<
" fraction (fractions_[" <<
detLabel <<
"][" << coord <<
"]): " << fractions_[
detLabel][alignableIndex]
272 <<
"=============" << std::endl;
277 <<
"Aborting payload creation." 278 <<
" Exceeding maximum thresholds for movement: " <<
std::abs(ObsMove) <<
" for " <<
detLabel <<
" (" 285 <<
" Exceeding maximum thresholds for movement: " <<
std::abs(ObsMove) <<
" for " <<
detLabel <<
" (" 286 << coord <<
") but continuing as the alignable is inactive!";
294 <<
" Exceeding maximum thresholds for error: " <<
std::abs(ObsErr)
295 <<
" for" <<
detLabel <<
"(" << coord <<
")";
300 if (
std::abs(ObsMove / ObsErr) < significances_[
detLabel][alignableIndex]) {
308 <<
"This correction: " << ObsMove <<
"+/-" << ObsErr <<
" for " <<
detLabel <<
"(" << coord
309 <<
") will trigger a new Tracker Alignment payload!";
311 countsAbove_[
detLabel][alignableIndex]++;
316 edm::LogError(
"MillePedeFileReader") <<
"Could not read millepede result-file.";
324 std::stringstream
ss;
325 for (
auto& ali : alignables_) {
326 ss << ali << std::endl;
327 for (
long unsigned int i = 0;
i < countsTotal_[ali].size();
i++) {
328 if (countsTotal_[ali][
i] != 0 && fractions_[ali][
i] != -1) {
329 float fraction_ = countsAbove_[ali][
i] / (1.0 * countsTotal_[ali][
i]);
330 ss << static_cast<AlignPCLThresholdsHG::coordType>(
i) <<
": Fraction = " << fraction_
331 <<
" Fraction Threshold = " << fractions_[ali][
i];
332 if (fraction_ >= fractions_[ali][
i]) {
334 ss <<
" above fraction threshold" << std::endl;
341 ss <<
"No entries available or no fraction thresholds defined" << std::endl;
343 ss <<
"===================" << std::endl;
346 ss <<
"Alignment will be updated" << std::endl;
348 ss <<
"Alignment will NOT be updated" << std::endl;
355 const std::shared_ptr<const SiPixelQuality>& pixelQual) {
356 std::vector<DetId> detIds;
362 for (
const auto& component : deepComponents) {
365 detIds.push_back(
detId);
370 int badModuleCount = 0;
371 int totalDetIds = detIds.size();
373 const auto& theDisabledModules = pixelQual->getBadComponentList();
374 std::vector<SiPixelQuality::disabledModuleType> theDisabledModuleInAlignable;
375 for (
const auto&
mod : theDisabledModules) {
376 if (
std::find(detIds.begin(), detIds.end(),
mod.DetID) != detIds.end()) {
377 theDisabledModuleInAlignable.push_back(
mod);
382 if (theDisabledModuleInAlignable.empty()) {
388 std::stringstream
out;
389 for (
const auto&
mod : theDisabledModuleInAlignable) {
393 bool isBad = pixelQual->IsModuleBad(
mod.DetID);
394 std::bitset<16> bad_rocs(
mod.BadRocs);
395 if (isBad || bad_rocs.all()) {
398 out <<
" " <<
mod.DetID <<
" (" << (isBad || bad_rocs.all()) <<
") , " << bad_rocs;
402 if (badModuleCount > 0) {
403 out <<
" " << badModuleCount <<
" modules are bad out of " << totalDetIds << std::endl;
408 if (badModuleCount >= (totalDetIds + 1) / 2) {
420 const auto& tns =
pedeLabeler_->alignableTracker()->trackerNameSpace();
425 switch (tns.tpb().halfBarrelNumber(
id)) {
432 <<
"@SUB=MillePedeFileReader::getHLS\n" 433 <<
"Found a pixel half-barrel number that should not exist: " << tns.tpb().halfBarrelNumber(
id);
436 switch (tns.tpe().endcapNumber(
id)) {
438 switch (tns.tpe().halfCylinderNumber(
id)) {
445 <<
"@SUB=MillePedeFileReader::getHLS\n" 446 <<
"Found a pixel half-cylinder number that should not exist: " << tns.tpe().halfCylinderNumber(
id);
449 switch (tns.tpe().halfCylinderNumber(
id)) {
456 <<
"@SUB=MillePedeFileReader::getHLS\n" 457 <<
"Found a pixel half-cylinder number that should not exist: " << tns.tpe().halfCylinderNumber(
id);
461 <<
"@SUB=MillePedeFileReader::getHLS\n" 462 <<
"Found a pixel endcap number that should not exist: " << tns.tpe().endcapNumber(
id);
465 switch (tns.tpb().layerNumber(
id)) {
476 <<
"@SUB=MillePedeFileReader::getHLS\n" 477 <<
"Found a pixel layer number that should not exist: " << tns.tpb().layerNumber(
id);
480 switch (static_cast<signed int>((tns.tpe().endcapNumber(
id) == 1) ? -1 * tns.tpe().halfDiskNumber(
id)
481 : tns.tpe().halfDiskNumber(
id))) {
496 <<
"@SUB=MillePedeFileReader::getHLS\n" 497 <<
"Found a pixel disk number that should not exist: " 498 <<
static_cast<signed int>((tns.tpe().endcapNumber(
id) == 1) ? -1 * tns.tpe().halfDiskNumber(
id)
499 : tns.tpe().halfDiskNumber(
id));
509 return "TPBHalfBarrelXminus";
511 return "TPBHalfBarrelXplus";
513 return "TPEHalfCylinderXminusZminus";
515 return "TPEHalfCylinderXplusZminus";
517 return "TPEHalfCylinderXminusZplus";
519 return "TPEHalfCylinderXplusZplus";
521 return "TPBLadderLayer1";
523 return "TPBLadderLayer2";
525 return "TPBLadderLayer3";
527 return "TPBLadderLayer4";
529 return "TPEPanelDisk1";
531 return "TPEPanelDisk2";
533 return "TPEPanelDisk3";
535 return "TPEPanelDiskM1";
537 return "TPEPanelDiskM2";
539 return "TPEPanelDiskM3";
543 <<
"@SUB=MillePedeFileReader::getStringFromHLS\n" 544 <<
"Found an alignable structure not possible to map in the default AlignPCLThresholdsHG partitions";
552 std::make_pair(currentSum, currentSum +
pixelTopologyMap_->getPXBLadders(1) / 2);
555 std::make_pair(currentSum, currentSum +
pixelTopologyMap_->getPXBLadders(2) / 2);
558 std::make_pair(currentSum, currentSum +
pixelTopologyMap_->getPXBLadders(3) / 2);
561 std::make_pair(currentSum, currentSum +
pixelTopologyMap_->getPXBLadders(4) / 2);
579 const auto& tns =
pedeLabeler_->alignableTracker()->trackerNameSpace();
583 return (tns.tpb().halfBarrelNumber(
id) == 1) ? tns.tpb().ladderNumber(
id) +
indexHelper[HLS].first
584 : tns.tpb().ladderNumber(
id) +
indexHelper[HLS].second;
586 return (tns.tpb().halfBarrelNumber(
id) == 1) ? tns.tpb().ladderNumber(
id) +
indexHelper[HLS].first
587 : tns.tpb().ladderNumber(
id) +
indexHelper[HLS].second;
589 return (tns.tpb().halfBarrelNumber(
id) == 1) ? tns.tpb().ladderNumber(
id) +
indexHelper[HLS].first
590 : tns.tpb().ladderNumber(
id) +
indexHelper[HLS].second;
592 return (tns.tpb().halfBarrelNumber(
id) == 1) ? tns.tpb().ladderNumber(
id) +
indexHelper[HLS].first
593 : tns.tpb().ladderNumber(
id) +
indexHelper[HLS].second;
595 return (tns.tpe().halfCylinderNumber(
id) == 1)
596 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
597 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
599 return (tns.tpe().halfCylinderNumber(
id) == 1)
600 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
601 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
603 return (tns.tpe().halfCylinderNumber(
id) == 1)
604 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
605 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
607 return (tns.tpe().halfCylinderNumber(
id) == 1)
608 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
609 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
611 return (tns.tpe().halfCylinderNumber(
id) == 1)
612 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
613 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
615 return (tns.tpe().halfCylinderNumber(
id) == 1)
616 ? (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].first
617 : (tns.tpe().bladeNumber(
id) * 2 - (tns.tpe().panelNumber(
id) % 2)) +
indexHelper[HLS].second;
630 desc.add<
bool>(
"ignoreInactiveAlignables",
true);
634 desc.add<
bool>(
"isHG",
false);
std::array< double, SIZE_LG_STRUCTS > Zobs_
Log< level::Info, true > LogVerbatim
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_
const std::shared_ptr< const SiPixelQuality > quality_
PclHLS getHLS(const Alignable *)
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const Alignables & deepComponents() const
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_
static void fillPSetDescription(edm::ParameterSetDescription &desc)
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) ...
Log< level::Warning, true > LogPrint
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_
const bool ignoreInactiveAlignables_
std::unordered_map< PclHLS, std::pair< int, int > > indexHelper
MillePedeFileReader(const edm::ParameterSet &, const std::shared_ptr< const PedeLabelerBase > &, const std::shared_ptr< const AlignPCLThresholdsHG > &, const std::shared_ptr< const PixelTopologyMap > &, const std::shared_ptr< const SiPixelQuality > &)
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_
bool isAlignableActive(const Alignable *alignable, const std::shared_ptr< const SiPixelQuality > &pixelQual)
std::map< std::string, std::array< bool, 6 > > fractionExceeded_
Log< level::Warning, false > LogWarning
T mod(const T &a, const T &b)
std::array< double, SIZE_LG_STRUCTS > ZobsErr_
std::array< double, SIZE_HG_STRUCTS > tYobsErr_HG_