Skip to content

Commit

Permalink
Merge pull request #36866 from CMSTrackerDPG/addBPixMapsToLorentzAngl…
Browse files Browse the repository at this point in the history
…eHarvester_12_2_X

[12.2.X] Improvements on SiPixelLorentzAngle PCL workflow: layer-dependent cluster size cut and output maps
  • Loading branch information
cmsbuild authored Feb 3, 2022
2 parents 65d1df2 + 246ef92 commit d671910
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct SiPixelLorentzAngleCalibrationHistograms {

int nlay;
std::vector<int> nModules_;
std::vector<int> nLadders_;
std::vector<std::string> BPixnewmodulename_;
std::vector<unsigned int> BPixnewDetIds_;
std::vector<int> BPixnewModule_;
Expand All @@ -29,6 +30,7 @@ struct SiPixelLorentzAngleCalibrationHistograms {
MonitorMap h_drift_depth_;
MonitorMap h_mean_;

// track monitoring
dqm::reco::MonitorElement* h_tracks_;
dqm::reco::MonitorElement* h_trackEta_;
dqm::reco::MonitorElement* h_trackPhi_;
Expand All @@ -43,6 +45,10 @@ struct SiPixelLorentzAngleCalibrationHistograms {
dqm::reco::MonitorElement* h_bySectLA_;
dqm::reco::MonitorElement* h_bySectDeltaLA_;
dqm::reco::MonitorElement* h_bySectChi2_;

// ouput LA maps
std::vector<dqm::reco::MonitorElement*> h2_byLayerLA_;
std::vector<dqm::reco::MonitorElement*> h2_byLayerDiff_;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ class SiPixelLorentzAnglePCLHarvester : public DQMEDHarvester {

private:
void dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter&) override;
void endRun(const edm::Run&, const edm::EventSetup&) override;
void findMean(MonitorElement* h_drift_depth_adc_slice_, int i, int i_ring);
SiPixelLAHarvest::fitResults fitAndStore(std::shared_ptr<SiPixelLorentzAngle> theLA, int i_idx, int i_lay, int i_mod);

// es tokens
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomEsToken_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoEsToken_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoEsTokenBR_, topoEsTokenER_;
edm::ESGetToken<SiPixelLorentzAngle, SiPixelLorentzAngleRcd> siPixelLAEsToken_;
edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;

Expand All @@ -105,12 +106,14 @@ class SiPixelLorentzAnglePCLHarvester : public DQMEDHarvester {
SiPixelLorentzAngleCalibrationHistograms hists;
const SiPixelLorentzAngle* currentLorentzAngle;
const MagneticField* magField;
std::unique_ptr<TrackerTopology> theTrackerTopology;
};

//------------------------------------------------------------------------------
SiPixelLorentzAnglePCLHarvester::SiPixelLorentzAnglePCLHarvester(const edm::ParameterSet& iConfig)
: geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
topoEsToken_(esConsumes<edm::Transition::BeginRun>()),
topoEsTokenBR_(esConsumes<edm::Transition::BeginRun>()),
topoEsTokenER_(esConsumes<edm::Transition::EndRun>()),
siPixelLAEsToken_(esConsumes<edm::Transition::BeginRun>()),
magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()),
newmodulelist_(iConfig.getParameter<std::vector<std::string>>("newmodulelist")),
Expand All @@ -128,16 +131,18 @@ SiPixelLorentzAnglePCLHarvester::SiPixelLorentzAnglePCLHarvester(const edm::Para
void SiPixelLorentzAnglePCLHarvester::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
// geometry
const TrackerGeometry* geom = &iSetup.getData(geomEsToken_);
const TrackerTopology* tTopo = &iSetup.getData(topoEsToken_);
const TrackerTopology* tTopo = &iSetup.getData(topoEsTokenBR_);

magField = &iSetup.getData(magneticFieldToken_);
currentLorentzAngle = &iSetup.getData(siPixelLAEsToken_);

PixelTopologyMap map = PixelTopologyMap(geom, tTopo);
hists.nlay = geom->numberOfLayers(PixelSubdetector::PixelBarrel);
hists.nModules_.resize(hists.nlay);
hists.nLadders_.resize(hists.nlay);
for (int i = 0; i < hists.nlay; i++) {
hists.nModules_[i] = map.getPXBModules(i + 1);
hists.nLadders_[i] = map.getPXBLadders(i + 1);
}

// list of modules already filled, then return (we already entered here)
Expand Down Expand Up @@ -208,6 +213,13 @@ void SiPixelLorentzAnglePCLHarvester::beginRun(const edm::Run& iRun, const edm::
LogDebug("SiPixelLorentzAnglePCLHarvester") << "Stored a total of " << count << " detIds.";
}

//------------------------------------------------------------------------------
void SiPixelLorentzAnglePCLHarvester::endRun(edm::Run const& run, edm::EventSetup const& isetup) {
if (!theTrackerTopology) {
theTrackerTopology = std::make_unique<TrackerTopology>(isetup.getData(topoEsTokenER_));
}
}

//------------------------------------------------------------------------------
void SiPixelLorentzAnglePCLHarvester::dqmEndJob(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter) {
// go in the right directory
Expand Down Expand Up @@ -302,7 +314,7 @@ void SiPixelLorentzAnglePCLHarvester::dqmEndJob(DQMStore::IBooker& iBooker, DQMS

// book histogram of differences
MonitorElement* h_diffLA = iBooker.book1D(
"h_diffLA", "difference in #mu_{H}; #Delta #mu_{H}/#mu_{H} (old-new)/old [%];n. modules", 100, -3., 3.);
"h_diffLA", "difference in #mu_{H}; #Delta #mu_{H}/#mu_{H} (old-new)/old [%];n. modules", 100, -150, 150);

// retrieve the number of bins from the other monitoring histogram
const auto& maxSect = hists.h_bySectOccupancy_->getNbinsX();
Expand Down Expand Up @@ -335,6 +347,33 @@ void SiPixelLorentzAnglePCLHarvester::dqmEndJob(DQMStore::IBooker& iBooker, DQMS
hists.h_bySectChi2_->setBinLabel(bin, binName);
}

// this will be booked in the Harvesting folder
iBooker.setCurrentFolder(fmt::format("{}Harvesting/LorentzAngleMaps", dqmDir_));
for (int i = 0; i < hists.nlay; i++) {
std::string repName = "h2_byLayerLA_%i";
std::string repText = "BPix Layer %i tan#theta_{LA}/B;module number;ladder number;tan#theta_{LA}/B [1/T]";

hists.h2_byLayerLA_.emplace_back(iBooker.book2D(fmt::sprintf(repName, i + 1),
fmt::sprintf(repText, i + 1),
hists.nModules_[i],
0.5,
hists.nModules_[i] + 0.5,
hists.nLadders_[i],
0.5,
hists.nLadders_[i] + 0.5));

repName = "h2_byLayerDiff_%i";
repText = "BPix Layer %i #Delta#mu_{H}/#mu_{H};module number;ladder number;#Delta#mu_{H}/#mu_{H} [%%]";
hists.h2_byLayerDiff_.emplace_back(iBooker.book2D(fmt::sprintf(repName, i + 1),
fmt::sprintf(repText, i + 1),
hists.nModules_[i],
0.5,
hists.nModules_[i] + 0.5,
hists.nLadders_[i],
0.5,
hists.nLadders_[i] + 0.5));
}

// clang-format off
edm::LogPrint("LorentzAngle") << "module" << "\t" << "layer" << "\t"
<< "offset" << "\t" << "e0" << "\t"
Expand Down Expand Up @@ -448,14 +487,29 @@ void SiPixelLorentzAnglePCLHarvester::dqmEndJob(DQMStore::IBooker& iBooker, DQMS
float fPixLorentzAnglePerTesla_ = currentLorentzAngle->getLorentzAngle(id);
if (!LorentzAngle->putLorentzAngle(id, fPixLorentzAnglePerTesla_)) {
edm::LogError("SiPixelLorentzAnglePCLHarvester")
<< "[SiPixelLorentzAnglePCLHarvester::dqmEndRun] filling rest of payload: detid already exists";
<< "[SiPixelLorentzAnglePCLHarvester::dqmEndJob] filling rest of payload: detid already exists";
}
}

for (const auto& id : newLADets) {
float deltaMuHoverMuH = (currentLorentzAngle->getLorentzAngle(id) - LorentzAngle->getLorentzAngle(id)) /
currentLorentzAngle->getLorentzAngle(id);
h_diffLA->Fill(deltaMuHoverMuH);
h_diffLA->Fill(deltaMuHoverMuH * 100.f);
}

// fill the 2D output Lorentz Angle maps
for (const auto& [id, value] : LorentzAngle->getLorentzAngles()) {
DetId ID = DetId(id);
if (ID.subdetId() == PixelSubdetector::PixelBarrel) {
const auto& layer = theTrackerTopology->pxbLayer(id);
const auto& ladder = theTrackerTopology->pxbLadder(id);
const auto& module = theTrackerTopology->pxbModule(id);
hists.h2_byLayerLA_[layer - 1]->setBinContent(module, ladder, value);

float deltaMuHoverMuH =
(currentLorentzAngle->getLorentzAngle(id) - value) / currentLorentzAngle->getLorentzAngle(id);
hists.h2_byLayerDiff_[layer - 1]->setBinContent(module, ladder, deltaMuHoverMuH * 100.f);
}
}

// fill the DB object record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ class SiPixelLorentzAnglePCLWorker : public DQMEDAnalyzer {
// parameters from config file
double ptmin_;
double normChi2Max_;
int clustSizeYMin_;
int clustSizeYMinL4_;
std::vector<int> clustSizeYMin_;
int clustSizeXMax_;
double residualMax_;
double clustChargeMaxPerLength_;
Expand Down Expand Up @@ -207,8 +206,7 @@ SiPixelLorentzAnglePCLWorker::SiPixelLorentzAnglePCLWorker(const edm::ParameterS
newmodulelist_(iConfig.getParameter<std::vector<std::string>>("newmodulelist")),
ptmin_(iConfig.getParameter<double>("ptMin")),
normChi2Max_(iConfig.getParameter<double>("normChi2Max")),
clustSizeYMin_(iConfig.getParameter<int>("clustSizeYMin")),
clustSizeYMinL4_(iConfig.getParameter<int>("clustSizeYMinL4")),
clustSizeYMin_(iConfig.getParameter<std::vector<int>>("clustSizeYMin")),
clustSizeXMax_(iConfig.getParameter<int>("clustSizeXMax")),
residualMax_(iConfig.getParameter<double>("residualMax")),
clustChargeMaxPerLength_(iConfig.getParameter<double>("clustChargeMaxPerLength")),
Expand Down Expand Up @@ -443,7 +441,7 @@ void SiPixelLorentzAnglePCLWorker::analyze(edm::Event const& iEvent, edm::EventS
// get qScale_ = templ.qscale() and templ.r_qMeas_qTrue();
float cotalpha = trackdirection.x() / trackdirection.z();
float cotbeta = trackdirection.y() / trackdirection.z();
float cotbeta_min = clustSizeYMin_ * ypitch_ / width_;
float cotbeta_min = clustSizeYMin_[layer_ - 1] * ypitch_ / width_;
if (fabs(cotbeta) <= cotbeta_min)
continue;
double drdz = sqrt(1. + cotalpha * cotalpha + cotbeta * cotbeta);
Expand Down Expand Up @@ -504,7 +502,7 @@ void SiPixelLorentzAnglePCLWorker::analyze(edm::Event const& iEvent, edm::EventS
double ylim1 = trackhitCorrY_ - width_ * cotbeta / 2.;
double ylim2 = trackhitCorrY_ + width_ * cotbeta / 2.;

int clustSizeY_cut = layer_ < 4 ? clustSizeYMin_ : clustSizeYMinL4_;
int clustSizeY_cut = clustSizeYMin_[layer_ - 1];

if (!large_pix && (chi2_ / ndof_) < normChi2Max_ && cluster->sizeY() >= clustSizeY_cut &&
residualsq < residualMax_ * residualMax_ && cluster->charge() < clusterCharge_cut &&
Expand Down Expand Up @@ -867,8 +865,8 @@ void SiPixelLorentzAnglePCLWorker::fillDescriptions(edm::ConfigurationDescriptio
desc.add<edm::InputTag>("src", edm::InputTag("TrackRefitter"))->setComment("input track collections");
desc.add<double>("ptMin", 3.)->setComment("minimum pt on tracks");
desc.add<double>("normChi2Max", 2.)->setComment("maximum reduced chi squared");
desc.add<int>("clustSizeYMin", 4)->setComment("minimum cluster size on Y axis for Layer 1-3");
desc.add<int>("clustSizeYMinL4", 3)->setComment("minimum cluster size on Y axis for Layer 4");
desc.add<std::vector<int>>("clustSizeYMin", {4, 4, 3, 2})
->setComment("minimum cluster size on Y axis for all Barrel Layers");
desc.add<int>("clustSizeXMax", 5)->setComment("maximum cluster size on X axis");
desc.add<double>("residualMax", 0.005)->setComment("maximum residual");
desc.add<double>("clustChargeMaxPerLength", 50000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace SiPixelPI {
static const unsigned int phase0size = 1440;
static const unsigned int phase1size = 1856;
static const unsigned int phase2size = 3892;
static const unsigned int mismatched = 9999;

//============================================================================
// struct to store info useful to construct topology based on the detid list
Expand Down Expand Up @@ -789,7 +790,11 @@ namespace SiPixelPI {
t2.SetTextSize(0.1);
t2.SetTextAngle(45);
t2.SetTextColor(kRed);
t2.DrawLatexNDC(0.6, 0.50, Form("%s NOT SUPPORTED!", phase.c_str()));
if (size != SiPixelPI::mismatched) {
t2.DrawLatexNDC(0.6, 0.50, Form("%s NOT SUPPORTED!", phase.c_str()));
} else {
t2.DrawLatexNDC(0.6, 0.50, "MISMATCHED PAYLOAD SIZE!");
}
}

/*--------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,128 @@ namespace {
std::string label_;
};

/************************************************
Full Pixel Tracker Map for Comparison Base Class
*************************************************/
template <IOVMultiplicity nIOVs, int ntags>
class SiPixelLorentzAngleFullMapCompareBase : public PlotImage<SiPixelLorentzAngle, nIOVs, ntags> {
public:
SiPixelLorentzAngleFullMapCompareBase() : PlotImage<SiPixelLorentzAngle, nIOVs, ntags>("SiPixelLorentzAngle Map") {
label_ = "SiPixelLorentzAngleFullPixelMap";
payloadString = "Lorentz Angle";
}

bool fill() override {
gStyle->SetPalette(kBlueRedYellow);

// trick to deal with the multi-ioved tag and two tag case at the same time
auto theIOVs = PlotBase::getTag<0>().iovs;
auto f_tagname = PlotBase::getTag<0>().name;
std::string l_tagname = "";
auto firstiov = theIOVs.front();
std::tuple<cond::Time_t, cond::Hash> lastiov;

// we don't support (yet) comparison with more than 2 tags
assert(this->m_plotAnnotations.ntags < 3);

if (this->m_plotAnnotations.ntags == 2) {
auto tag2iovs = PlotBase::getTag<1>().iovs;
l_tagname = PlotBase::getTag<1>().name;
lastiov = tag2iovs.front();
} else {
lastiov = theIOVs.back();
}

std::shared_ptr<SiPixelLorentzAngle> last_payload = this->fetchPayload(std::get<1>(lastiov));
std::shared_ptr<SiPixelLorentzAngle> first_payload = this->fetchPayload(std::get<1>(firstiov));

if (first_payload.get() && last_payload.get()) {
// creat the base map
Phase1PixelSummaryMap fullMap("",
fmt::sprintf("%s Diff", payloadString),
fmt::sprintf("%s difference #Delta#mu_{H}/#mu_{H} [%%]", payloadString));
fullMap.createTrackerBaseMap();

std::map<uint32_t, float> l_LAMap_ = last_payload->getLorentzAngles();
std::map<uint32_t, float> f_LAMap_ = first_payload->getLorentzAngles();

std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
std::string firstIOVsince = std::to_string(std::get<0>(firstiov));

if (l_LAMap_.size() != f_LAMap_.size()) {
edm::LogError(label_) << "There are " << l_LAMap_.size() << "dets in payload" << std::get<1>(lastiov)
<< "and " << f_LAMap_.size() << " dets in payload" << std::get<1>(firstiov)
<< "display is not possible!";

TCanvas canvas("Canv", "Canv", 1200, 1000);
SiPixelPI::displayNotSupported(canvas, SiPixelPI::mismatched);
std::string fileName(this->m_imageFileName);
canvas.SaveAs(fileName.c_str());
return false;
}

if (l_LAMap_.size() == SiPixelPI::phase0size || l_LAMap_.size() > SiPixelPI::phase1size) {
edm::LogError(label_) << "There are " << l_LAMap_.size()
<< " DetIds in this payload. SiPixelLorentzAngleFullPixelMap maps are not supported "
"for non-Phase1 Pixel geometries !";
TCanvas canvas("Canv", "Canv", 1200, 1000);
SiPixelPI::displayNotSupported(canvas, l_LAMap_.size());
std::string fileName(this->m_imageFileName);
canvas.SaveAs(fileName.c_str());
return false;
} else {
if (l_LAMap_.size() < SiPixelPI::phase1size) {
edm::LogWarning(label_) << "\n ********* WARNING! ********* \n There are " << l_LAMap_.size()
<< " DetIds in this payload !"
<< "\n **************************** \n";
}
}

// fill the map
for (const auto &[id, value] : l_LAMap_) {
assert(value != 0.); // do not divide by 0
const auto &diff = (value - f_LAMap_[id]) * 100.f / value;
fullMap.fillTrackerMap(id, diff);
}

// print the map
TCanvas canvas("Canv", "Canv", 3000, 2000);
fullMap.printTrackerMap(canvas, 0.03); // is the top margin of the canvas

// take care of the legend
auto ltx = TLatex();
ltx.SetTextFont(62);
ltx.SetTextSize(0.025);
ltx.SetTextAlign(11);
std::string ltxText;
if (this->m_plotAnnotations.ntags == 2) {
ltxText = fmt::sprintf("#color[2]{%s, %s} vs #color[4]{%s, %s}",
f_tagname,
std::to_string(std::get<0>(firstiov)),
l_tagname,
std::to_string(std::get<0>(lastiov)));
} else {
ltxText = fmt::sprintf("%s IOV: #color[2]{%s} vs IOV: #color[4]{%s}",
f_tagname,
std::to_string(std::get<0>(firstiov)),
std::to_string(std::get<0>(lastiov)));
}
ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, ltxText.c_str());

std::string fileName(this->m_imageFileName);
canvas.SaveAs(fileName.c_str());
} // if has got the payloads
return true;
}

protected:
std::string payloadString;
std::string label_;
};

using SiPixelLorentzAngleFullMapCompareSingleTag = SiPixelLorentzAngleFullMapCompareBase<MULTI_IOV, 1>;
using SiPixelLorentzAngleFullMapCompareTwoTags = SiPixelLorentzAngleFullMapCompareBase<SINGLE_IOV, 2>;

} // namespace

PAYLOAD_INSPECTOR_MODULE(SiPixelLorentzAngle) {
Expand All @@ -965,4 +1087,6 @@ PAYLOAD_INSPECTOR_MODULE(SiPixelLorentzAngle) {
PAYLOAD_INSPECTOR_CLASS(SiPixelFPixLorentzAngleMap);
PAYLOAD_INSPECTOR_CLASS(SiPixelFullLorentzAngleMapByROC);
PAYLOAD_INSPECTOR_CLASS(SiPixelLorentzAngleFullPixelMap);
PAYLOAD_INSPECTOR_CLASS(SiPixelLorentzAngleFullMapCompareSingleTag);
PAYLOAD_INSPECTOR_CLASS(SiPixelLorentzAngleFullMapCompareTwoTags);
}
2 changes: 1 addition & 1 deletion DQM/TrackerRemapper/interface/Phase1PixelSummaryMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Phase1PixelSummaryMap {

void resetOption(const char* option);
void createTrackerBaseMap();
void printTrackerMap(TCanvas& canvas);
void printTrackerMap(TCanvas& canvas, const float topMargin = 0.02);
bool fillTrackerMap(unsigned int id, double value);

protected:
Expand Down
Loading

0 comments on commit d671910

Please sign in to comment.