Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SiPixAli PCL DQM output #28318

Merged
merged 5 commits into from Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -8,11 +8,52 @@

/*** core framework functionality ***/
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

/*** Alignment ***/
#include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerBase.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"

struct mpPCLresults {
private:
bool m_isDBUpdated;
bool m_isDBUpdateVetoed;
int m_nRecords;
int m_exitCode;
std::string m_exitMessage;
std::bitset<4> m_updateBits;

public:
mpPCLresults(bool isDBUpdated,
bool isDBUpdateVetoed,
int nRecords,
int exitCode,
std::string exitMessage,
std::bitset<4> updateBits)
: m_isDBUpdated(isDBUpdated),
m_isDBUpdateVetoed(isDBUpdateVetoed),
m_nRecords(nRecords),
m_exitCode(exitCode),
m_exitMessage(exitMessage),
m_updateBits(updateBits) {}

const bool getDBUpdated() { return m_isDBUpdated; }
const bool getDBVetoed() { return m_isDBUpdateVetoed; }
const bool exceedsThresholds() { return m_updateBits.test(0); }
const bool exceedsCutoffs() { return m_updateBits.test(1); }
const bool exceedsMaxError() { return m_updateBits.test(2); }
const bool belowSignificance() { return m_updateBits.test(3); }
const int getNRecords() { return m_nRecords; }
const int getExitCode() { return m_exitCode; }
const std::string getExitMessage() { return m_exitMessage; }

void print() {
edm::LogInfo("MillePedeFileReader") << " is DB updated: " << m_isDBUpdated
<< " is DB update vetoed: " << m_isDBUpdateVetoed << " nRecords: " << m_nRecords
<< " exitCode: " << m_exitCode << " (" << m_exitMessage << ")" << std::endl;
}
};

class MillePedeFileReader {
//========================== PUBLIC METHODS ==================================
public: //====================================================================
Expand Down Expand Up @@ -42,6 +83,12 @@ class MillePedeFileReader {

const AlignPCLThresholds::threshold_map getThresholdMap() const { return theThresholds_.get()->getThreshold_Map(); }

const int binariesAmount() const { return binariesAmount_; }

const mpPCLresults getResults() const {
return mpPCLresults(updateDB_, vetoUpdateDB_, Nrec_, exitCode_, exitMessage_, updateBits_);
}

private:
//========================= PRIVATE ENUMS ====================================
//============================================================================
Expand All @@ -59,6 +106,7 @@ class MillePedeFileReader {
//========================= PRIVATE METHODS ==================================
//============================================================================

void readMillePedeEndFile();
void readMillePedeLogFile();
void readMillePedeResultFile();
PclHLS getHLS(const Alignable*);
Expand All @@ -74,6 +122,7 @@ class MillePedeFileReader {
const std::shared_ptr<const AlignPCLThresholds> theThresholds_;

// file-names
const std::string millePedeEndFile_;
const std::string millePedeLogFile_;
const std::string millePedeResFile_;

Expand All @@ -87,7 +136,20 @@ class MillePedeFileReader {

bool updateDB_{false};
bool vetoUpdateDB_{false};

// stores in a compact format the 4 decisions:
// 1st bit: exceeds maximum thresholds
// 2nd bit: exceeds cutoffs (significant movement)
// 3rd bit: exceeds maximum errors
// 4th bit: is below the significance
std::bitset<4> updateBits_;

// pede binaries available
int binariesAmount_{0};

int Nrec_{0};
int exitCode_{-1};
std::string exitMessage_{""};

std::array<double, 6> Xobs_ = {{0., 0., 0., 0., 0., 0.}};
std::array<double, 6> XobsErr_ = {{0., 0., 0., 0., 0., 0.}};
Expand Down
Expand Up @@ -52,6 +52,10 @@ void MillePedeDQMModule ::bookHistograms(DQMStore::IBooker& booker) {
h_zPos = booker.book1D("Zpos", "Alignment fit #DeltaZ;;#mum", 36, 0., 36.);
h_zRot = booker.book1D("Zrot", "Alignment fit #Delta#theta_{Z};;#murad", 36, 0., 36.);

statusResults = booker.book2D("statusResults", "Status of SiPixelAli PCL workflow;;", 6, 0., 6., 1, 0., 1.);
binariesAvalaible = booker.bookInt("BinariesFound");
exitCode = booker.bookString("PedeExitCode", "");

booker.cd();
}

Expand All @@ -64,6 +68,11 @@ void MillePedeDQMModule ::dqmEndJob(DQMStore::IBooker& booker, DQMStore::IGetter
<< "Try to read MillePede results before initializing MillePedeFileReader";
}
fillExpertHistos();
fillStatusHisto(statusResults);
binariesAvalaible->Fill(mpReader_->binariesAmount());
auto theResults = mpReader_->getResults();
std::string exitCodeStr = theResults.getExitMessage();
exitCode->Fill(exitCodeStr);
}

//=============================================================================
Expand Down Expand Up @@ -106,6 +115,24 @@ void MillePedeDQMModule ::beginRun(const edm::Run&, const edm::EventSetup& setup
mpReaderConfig_, pedeLabeler, std::shared_ptr<const AlignPCLThresholds>(myThresholds));
}

void MillePedeDQMModule ::fillStatusHisto(MonitorElement* statusHisto) {
TH2F* histo_status = statusHisto->getTH2F();
auto theResults = mpReader_->getResults();
theResults.print();
histo_status->SetBinContent(1, 1, theResults.getDBUpdated());
histo_status->GetXaxis()->SetBinLabel(1, "DB updated");
histo_status->SetBinContent(2, 1, theResults.exceedsCutoffs());
histo_status->GetXaxis()->SetBinLabel(2, "significant movement");
histo_status->SetBinContent(3, 1, theResults.getDBVetoed());
histo_status->GetXaxis()->SetBinLabel(3, "DB update vetoed");
histo_status->SetBinContent(4, 1, !theResults.exceedsThresholds());
histo_status->GetXaxis()->SetBinLabel(4, "within max movement");
histo_status->SetBinContent(5, 1, !theResults.exceedsMaxError());
histo_status->GetXaxis()->SetBinLabel(5, "within max error");
histo_status->SetBinContent(6, 1, !theResults.belowSignificance());
histo_status->GetXaxis()->SetBinLabel(6, "above significance");
}

void MillePedeDQMModule ::fillExpertHistos() {
std::array<double, 6> Xcut_, sigXcut_, maxMoveXcut_, maxErrorXcut_;
std::array<double, 6> tXcut_, sigtXcut_, maxMovetXcut_, maxErrortXcut_;
Expand Down
Expand Up @@ -50,6 +50,8 @@ class MillePedeDQMModule : public DQMEDHarvester {

void bookHistograms(DQMStore::IBooker&);

void fillStatusHisto(MonitorElement* statusHisto);

void fillExpertHistos();

void fillExpertHisto(MonitorElement* histo,
Expand Down Expand Up @@ -81,6 +83,10 @@ class MillePedeDQMModule : public DQMEDHarvester {
MonitorElement* h_yRot;
MonitorElement* h_zPos;
MonitorElement* h_zRot;

MonitorElement* statusResults;
MonitorElement* binariesAvalaible;
MonitorElement* exitCode;
};

// define this as a plug-in
Expand Down
@@ -1,6 +1,7 @@
import FWCore.ParameterSet.Config as cms

MillePedeFileReader = cms.PSet(
millePedeEndFile = cms.string('millepede.end'),
millePedeLogFile = cms.string('millepede.log'),
millePedeResFile = cms.string('millepede.res'),
millePedeResFile = cms.string('millepede.res')
)
44 changes: 40 additions & 4 deletions Alignment/MillePedeAlignmentAlgorithm/src/MillePedeFileReader.cc
Expand Up @@ -5,9 +5,6 @@
#include <cmath> // include floating-point std::abs functions
#include <fstream>

/*** core framework functionality ***/
#include "FWCore/MessageLogger/interface/MessageLogger.h"

/*** Alignment ***/
#include "Alignment/TrackerAlignment/interface/AlignableTracker.h"

Expand All @@ -20,10 +17,12 @@ MillePedeFileReader ::MillePedeFileReader(const edm::ParameterSet& config,
const std::shared_ptr<const AlignPCLThresholds>& theThresholds)
: pedeLabeler_(pedeLabeler),
theThresholds_(theThresholds),
millePedeEndFile_(config.getParameter<std::string>("millePedeEndFile")),
millePedeLogFile_(config.getParameter<std::string>("millePedeLogFile")),
millePedeResFile_(config.getParameter<std::string>("millePedeResFile")) {}

void MillePedeFileReader ::read() {
readMillePedeEndFile();
readMillePedeLogFile();
readMillePedeResultFile();
}
Expand All @@ -33,6 +32,34 @@ bool MillePedeFileReader ::storeAlignments() { return (updateDB_ && !vetoUpdateD
//=============================================================================
//=== PRIVATE METHOD IMPLEMENTATION ===
//=============================================================================
void MillePedeFileReader ::readMillePedeEndFile() {
std::ifstream endFile;
endFile.open(millePedeEndFile_.c_str());

if (endFile.is_open()) {
edm::LogInfo("MillePedeFileReader") << "Reading millepede end-file";
std::string line;
getline(endFile, line);
std::string trash;
if (line.find("-1") != std::string::npos) {
getline(endFile, line);
exitMessage_ = line;
std::istringstream iss(line);
iss >> exitCode_ >> trash;
edm::LogInfo("MillePedeFileReader")
<< " Pede exit code is: " << exitCode_ << " (" << exitMessage_ << ")" << std::endl;
} else {
exitMessage_ = line;
std::istringstream iss(line);
iss >> exitCode_ >> trash;
edm::LogInfo("MillePedeFileReader")
<< " Pede exit code is: " << exitCode_ << " (" << exitMessage_ << ")" << std::endl;
}
} else {
edm::LogError("MillePedeFileReader") << "Could not read millepede end-file.";
exitMessage_ = "no exit code found";
}
}

void MillePedeFileReader ::readMillePedeLogFile() {
std::ifstream logFile;
Expand All @@ -44,6 +71,7 @@ void MillePedeFileReader ::readMillePedeLogFile() {

while (getline(logFile, line)) {
std::string Nrec_string = "NREC =";
std::string Binaries_string = "C_binary";

if (line.find(Nrec_string) != std::string::npos) {
std::istringstream iss(line);
Expand All @@ -56,8 +84,11 @@ void MillePedeFileReader ::readMillePedeLogFile() {
updateDB_ = false;
}
}
}

if (line.find(Binaries_string) != std::string::npos) {
binariesAmount_ += 1;
}
}
} else {
edm::LogError("MillePedeFileReader") << "Could not read millepede log-file.";

Expand Down Expand Up @@ -166,18 +197,23 @@ void MillePedeFileReader ::readMillePedeResultFile() {
edm::LogWarning("MillePedeFileReader") << "Aborting payload creation."
<< " Exceeding maximum thresholds for movement: " << std::abs(ObsMove)
<< " for" << detLabel << "(" << coord << ")";
updateBits_.set(0);
vetoUpdateDB_ = true;
continue;

} else if (std::abs(ObsMove) > cutoffs_[detLabel][alignableIndex]) {
updateBits_.set(1);

if (std::abs(ObsErr) > errors_[detLabel][alignableIndex]) {
edm::LogWarning("MillePedeFileReader") << "Aborting payload creation."
<< " Exceeding maximum thresholds for error: " << std::abs(ObsErr)
<< " for" << detLabel << "(" << coord << ")";
updateBits_.set(2);
vetoUpdateDB_ = true;
continue;
} else {
if (std::abs(ObsMove / ObsErr) < significances_[detLabel][alignableIndex]) {
updateBits_.set(3);
continue;
}
}
Expand Down