Skip to content

Commit

Permalink
Merge pull request #37265 from mmusich/introduceAbstractionsSiStripPI…
Browse files Browse the repository at this point in the history
…_Rebased_12_4_X

Introduce generalized abstraction for Strip Payload Inspector
  • Loading branch information
cmsbuild authored Mar 24, 2022
2 parents bad8990 + d4b6d65 commit 960064d
Show file tree
Hide file tree
Showing 16 changed files with 2,035 additions and 50 deletions.
1,007 changes: 1,007 additions & 0 deletions CondCore/SiStripPlugins/interface/SiStripCondObjectRepresent.h

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions CondCore/SiStripPlugins/interface/SiStripPayloadInspectorHelper.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#ifndef CONDCORE_SISTRIPPLUGINS_SISTRIPPAYLOADINSPECTORHELPER_H
#define CONDCORE_SISTRIPPLUGINS_SISTRIPPAYLOADINSPECTORHELPER_H

#include <vector>
// system includes
#include <numeric>
#include <string>
#include "TH1.h"
#include "TH2.h"
#include "TPaveText.h"
#include "TStyle.h"
#include <vector>

// user includes
#include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
#include "CondFormats/SiStripObjects/interface/SiStripSummary.h"
#include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
#include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
#include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"

#include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
#include "CondFormats/SiStripObjects/interface/SiStripSummary.h"
#include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h" /* for STRIPS_PER_APV*/
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"

// ROOT includes
#include "TH1.h"
#include "TH2.h"
#include "TPaveText.h"
#include "TStyle.h"

namespace SiStripPI {

Expand Down Expand Up @@ -566,7 +571,7 @@ namespace SiStripPI {
int nAPVs = detInfo.getNumberOfApvsAndStripLength(det.first).first;
// one fiber connects to 2 APVs
int nFibers = nAPVs / 2;
int nStrips = (128 * detInfo.getNumberOfApvsAndStripLength(det.first).first);
int nStrips = (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det.first).first);
NTkComponents[0]++;
NTkComponents[1] += nFibers;
NTkComponents[2] += nAPVs;
Expand Down Expand Up @@ -719,7 +724,7 @@ namespace SiStripPI {
percentage += range;
}
if (percentage != 0)
percentage /= 128. * detInfo.getNumberOfApvsAndStripLength(detid).first;
percentage /= sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(detid).first;
if (percentage > 1)
edm::LogError("SiStripBadStrip_PayloadInspector")
<< "PROBLEM detid " << detid << " value " << percentage << std::endl;
Expand Down
199 changes: 199 additions & 0 deletions CondCore/SiStripPlugins/plugins/SiStripApvGain_PayloadInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

// auxilliary functions
#include "CondCore/SiStripPlugins/interface/SiStripPayloadInspectorHelper.h"
#include "CondCore/SiStripPlugins/interface/SiStripCondObjectRepresent.h"
#include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"

#include <memory>
Expand All @@ -42,6 +43,199 @@ namespace {

using namespace cond::payloadInspector;

class SiStripApvGainContainer : public SiStripCondObjectRepresent::SiStripDataContainer<SiStripApvGain, float> {
public:
SiStripApvGainContainer(std::shared_ptr<SiStripApvGain> payload, unsigned int run, std::string hash)
: SiStripCondObjectRepresent::SiStripDataContainer<SiStripApvGain, float>(payload, run, hash) {
payloadType_ = "SiStripApvGain";
setGranularity(SiStripCondObjectRepresent::PERAPV);
}

void allValues() override {
std::vector<uint32_t> detid;
payload_->getDetIds(detid);

for (const auto& d : detid) {
SiStripApvGain::Range range = payload_->getRange(d);
for (int it = 0; it < range.second - range.first; it++) {
// to be used to fill the histogram
SiStripCondData_.fillByPushBack(d, payload_->getApvGain(it, range));
}
}
}
};

/************************************************
testing the machinery
************************************************/
class SiStripApvGainTest : public cond::payloadInspector::Histogram1D<SiStripApvGain, SINGLE_IOV> {
public:
SiStripApvGainTest()
: cond::payloadInspector::Histogram1D<SiStripApvGain, SINGLE_IOV>(
"SiStrip ApvGain values", "SiStrip ApvGain values", 1, 0.0, 1.) {}

bool fill() override {
auto tag = PlotBase::getTag<0>();
for (auto const& iov : tag.iovs) {
std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload(std::get<1>(iov));
if (payload.get()) {
SiStripApvGainContainer* objContainer =
new SiStripApvGainContainer(payload, std::get<0>(iov), std::get<1>(iov));
objContainer->printAll();

} // payload
} // iovs
return true;
} // fill
};

class SiStripApvGainByPartition : public cond::payloadInspector::PlotImage<SiStripApvGain> {
public:
SiStripApvGainByPartition() : cond::payloadInspector::PlotImage<SiStripApvGain>("SiStrip ApvGains By Partition") {
setSingleIov(true);
}

bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
auto iov = iovs.front();
std::shared_ptr<SiStripApvGain> payload = fetchPayload(std::get<1>(iov));
if (payload.get()) {
SiStripApvGainContainer* objContainer =
new SiStripApvGainContainer(payload, std::get<0>(iov), std::get<1>(iov));
//objContainer->printAll();

TCanvas canvas("Partition summary", "partition summary", 1400, 1000);
objContainer->fillByPartition(canvas, 100, 0., 2.);

std::string fileName(m_imageFileName);
canvas.SaveAs(fileName.c_str());

} // payload
return true;
} // fill
};

class SiStripApvGainCompareByPartition : public cond::payloadInspector::PlotImage<SiStripApvGain> {
public:
SiStripApvGainCompareByPartition()
: cond::payloadInspector::PlotImage<SiStripApvGain>("SiStrip Compare ApvGains By Partition") {
setSingleIov(false);
}

bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
std::vector<std::tuple<cond::Time_t, cond::Hash>> sorted_iovs = iovs;

// make absolute sure the IOVs are sortd by since
std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const& t1, auto const& t2) {
return std::get<0>(t1) < std::get<0>(t2);
});

auto firstiov = sorted_iovs.front();
auto lastiov = sorted_iovs.back();

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

SiStripApvGainContainer* l_objContainer =
new SiStripApvGainContainer(last_payload, std::get<0>(lastiov), std::get<1>(lastiov));
SiStripApvGainContainer* f_objContainer =
new SiStripApvGainContainer(first_payload, std::get<0>(firstiov), std::get<1>(firstiov));

l_objContainer->compare(f_objContainer);

//l_objContainer->printAll();

TCanvas canvas("Partition summary", "partition summary", 1400, 1000);
l_objContainer->fillByPartition(canvas, 100, 0.5, 1.5);

std::string fileName(m_imageFileName);
canvas.SaveAs(fileName.c_str());

return true;
} // fill
};

class SiStripApvGainRatioByPartition : public cond::payloadInspector::PlotImage<SiStripApvGain> {
public:
SiStripApvGainRatioByPartition()
: cond::payloadInspector::PlotImage<SiStripApvGain>("SiStrip Ratio ApvGains By Partition") {
setSingleIov(false);
}

bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
std::vector<std::tuple<cond::Time_t, cond::Hash>> sorted_iovs = iovs;

// make absolute sure the IOVs are sortd by since
std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const& t1, auto const& t2) {
return std::get<0>(t1) < std::get<0>(t2);
});

auto firstiov = sorted_iovs.front();
auto lastiov = sorted_iovs.back();

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

SiStripApvGainContainer* l_objContainer =
new SiStripApvGainContainer(last_payload, std::get<0>(lastiov), std::get<1>(lastiov));
SiStripApvGainContainer* f_objContainer =
new SiStripApvGainContainer(first_payload, std::get<0>(firstiov), std::get<1>(firstiov));

l_objContainer->divide(f_objContainer);

//l_objContainer->printAll();

TCanvas canvas("Partition summary", "partition summary", 1400, 1000);
l_objContainer->fillByPartition(canvas, 200, 0., 2.);
for (int i = 1; i <= 4; i++)
canvas.cd(i)->SetLogy();

std::string fileName(m_imageFileName);
canvas.SaveAs(fileName.c_str());

return true;
} // fill
};

class SiStripApvGainDiffByPartition : public cond::payloadInspector::PlotImage<SiStripApvGain> {
public:
SiStripApvGainDiffByPartition()
: cond::payloadInspector::PlotImage<SiStripApvGain>("SiStrip Diff ApvGains By Partition") {
setSingleIov(false);
}

bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
std::vector<std::tuple<cond::Time_t, cond::Hash>> sorted_iovs = iovs;

// make absolute sure the IOVs are sortd by since
std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const& t1, auto const& t2) {
return std::get<0>(t1) < std::get<0>(t2);
});

auto firstiov = sorted_iovs.front();
auto lastiov = sorted_iovs.back();

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

SiStripApvGainContainer* l_objContainer =
new SiStripApvGainContainer(last_payload, std::get<0>(lastiov), std::get<1>(lastiov));
SiStripApvGainContainer* f_objContainer =
new SiStripApvGainContainer(first_payload, std::get<0>(firstiov), std::get<1>(firstiov));

l_objContainer->Subtract(f_objContainer);

//l_objContainer->printAll();

TCanvas canvas("Partition summary", "partition summary", 1400, 1000);
l_objContainer->fillByPartition(canvas, 100, -0.1, 0.1);

std::string fileName(m_imageFileName);
canvas.SaveAs(fileName.c_str());

return true;
} // fill
};

/************************************************
1d histogram of SiStripApvGains of 1 IOV
*************************************************/
Expand Down Expand Up @@ -2073,6 +2267,11 @@ namespace {
// Register the classes as boost python plugin
PAYLOAD_INSPECTOR_MODULE(SiStripApvGain) {
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsValue);
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainTest);
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainByPartition);
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainCompareByPartition);
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainRatioByPartition);
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainDiffByPartition);
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsTest);
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsByRegion);
PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsComparatorSingleTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ namespace {
badStripsPerDetId[d] += payload->decode(*badStrip).range;
//ss << "DetId="<< d << " Strip=" << payload->decode(*badStrip).firstStrip <<":"<< payload->decode(*badStrip).range << " flag="<< payload->decode(*badStrip).flag << std::endl;
}
float fraction = badStripsPerDetId[d] / (128. * detInfo.getNumberOfApvsAndStripLength(d).first);
float fraction =
badStripsPerDetId[d] / (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(d).first);
tmap->fill(d, fraction);
} // loop over detIds

Expand Down Expand Up @@ -227,7 +228,8 @@ namespace {
for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
badStripsPerDetId[d] += payload->decode(*badStrip).range;
}
float fraction = badStripsPerDetId[d] / (128. * detInfo.getNumberOfApvsAndStripLength(d).first);
float fraction =
badStripsPerDetId[d] / (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(d).first);
if (fraction > 0.) {
myMap.fill(d, fraction);
}
Expand Down Expand Up @@ -276,7 +278,7 @@ namespace {
float numerator(0.), denominator(0.);
std::vector<uint32_t> all_detids = detInfo.getAllDetIds();
for (const auto& det : all_detids) {
denominator += 128. * detInfo.getNumberOfApvsAndStripLength(det).first;
denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
if (badStripsPerDetId.count(det) != 0)
numerator += badStripsPerDetId[det];
}
Expand Down Expand Up @@ -321,7 +323,7 @@ namespace {
int subid = DetId(det).subdetId();
if (subid != StripSubdetector::TIB)
continue;
denominator += 128. * detInfo.getNumberOfApvsAndStripLength(det).first;
denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
if (badStripsPerDetId.count(det) != 0)
numerator += badStripsPerDetId[det];
}
Expand Down Expand Up @@ -366,7 +368,7 @@ namespace {
int subid = DetId(det).subdetId();
if (subid != StripSubdetector::TOB)
continue;
denominator += 128. * detInfo.getNumberOfApvsAndStripLength(det).first;
denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
if (badStripsPerDetId.count(det) != 0)
numerator += badStripsPerDetId[det];
}
Expand Down Expand Up @@ -411,7 +413,7 @@ namespace {
int subid = DetId(det).subdetId();
if (subid != StripSubdetector::TID)
continue;
denominator += 128. * detInfo.getNumberOfApvsAndStripLength(det).first;
denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
if (badStripsPerDetId.count(det) != 0)
numerator += badStripsPerDetId[det];
}
Expand Down Expand Up @@ -456,7 +458,7 @@ namespace {
int subid = DetId(det).subdetId();
if (subid != StripSubdetector::TEC)
continue;
denominator += 128. * detInfo.getNumberOfApvsAndStripLength(det).first;
denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
if (badStripsPerDetId.count(det) != 0)
numerator += badStripsPerDetId[det];
}
Expand Down Expand Up @@ -880,7 +882,7 @@ namespace {
LastFractionPerDetId[d] += last_payload->decode(*badStrip).range;
}
// normalize to the number of strips per module
LastFractionPerDetId[d] /= (128. * detInfo.getNumberOfApvsAndStripLength(d).first);
LastFractionPerDetId[d] /= (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(d).first);
} // loop over detIds

std::vector<uint32_t> detid2;
Expand All @@ -894,7 +896,7 @@ namespace {
FirstFractionPerDetId[d] += first_payload->decode(*badStrip).range;
}
// normalize to the number of strips per module
FirstFractionPerDetId[d] /= (128. * detInfo.getNumberOfApvsAndStripLength(d).first);
FirstFractionPerDetId[d] /= (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(d).first);
} // loop over detIds

std::vector<uint32_t> allDetIds = detInfo.getAllDetIds();
Expand Down
Loading

0 comments on commit 960064d

Please sign in to comment.