diff --git a/CondCore/SiStripPlugins/plugins/SiStripApvGain_PayloadInspector.cc b/CondCore/SiStripPlugins/plugins/SiStripApvGain_PayloadInspector.cc index bbca836291442..980944be212af 100644 --- a/CondCore/SiStripPlugins/plugins/SiStripApvGain_PayloadInspector.cc +++ b/CondCore/SiStripPlugins/plugins/SiStripApvGain_PayloadInspector.cc @@ -682,8 +682,10 @@ namespace { sumOfGains += payload->getApvGain(it, range); } // loop over APVs // fill the tracker map taking the average gain on a single DetId - store[d] = (sumOfGains / nAPVsPerModule); - tmap->fill(d, (sumOfGains / nAPVsPerModule)); + if (nAPVsPerModule != 0.) { + store[d] = (sumOfGains / nAPVsPerModule); + tmap->fill(d, (sumOfGains / nAPVsPerModule)); + } } // loop over detIds //========================= @@ -1583,9 +1585,9 @@ namespace { temp->SetMarkerSize(1.3); if (part == "TEC") - scatters[part]->Draw("P"); + scatters[part]->Draw("SCAT"); else - scatters[part]->Draw("Psame"); + scatters[part]->Draw("SCATsame"); legend2.AddEntry(temp, part.c_str(), "P"); } @@ -1896,16 +1898,14 @@ namespace { TPad pad1("pad1", "pad1", 0, 0.3, 1, 1.0); pad1.SetBottomMargin(0.02); // Upper and lower plot are joined - pad1.SetTopMargin(0.07); + pad1.SetTopMargin(0.1); pad1.SetRightMargin(0.05); pad1.SetLeftMargin(0.15); pad1.Draw(); // Draw the upper pad: pad1 pad1.cd(); // pad1 becomes the current pad - auto h_firstGains = - std::make_shared("hFirstGains", "SiStrip APV gains values; APV Gains;n. APVs", 200, 0.2, 1.8); - auto h_lastGains = - std::make_shared("hLastGains", "SiStrip APV gains values; APV Gains;n. APVs", 200, 0.2, 1.8); + auto h_firstGains = std::make_shared("hFirstGains", ";SiStrip APV Gains;n. APVs", 200, 0.2, 1.8); + auto h_lastGains = std::make_shared("hLastGains", ";SiStrip APV Gains;n. APVs", 200, 0.2, 1.8); for (const auto& item : firstmap) { h_firstGains->Fill(item.second); @@ -1929,8 +1929,8 @@ namespace { h_firstGains->SetMarkerSize(1.); h_lastGains->SetMarkerSize(1.); - h_firstGains->SetLineWidth(1); - h_lastGains->SetLineWidth(1); + h_firstGains->SetLineWidth(2); + h_lastGains->SetLineWidth(2); h_firstGains->SetMarkerStyle(20); h_lastGains->SetMarkerStyle(21); @@ -1938,15 +1938,35 @@ namespace { h_firstGains->GetXaxis()->SetLabelOffset(2.); h_lastGains->GetXaxis()->SetLabelOffset(2.); + float max = (h_firstGains->GetMaximum() > h_lastGains->GetMaximum()) ? h_firstGains->GetMaximum() + : h_lastGains->GetMaximum(); + + h_firstGains->GetYaxis()->SetRangeUser(0., std::max(0., max * 1.20)); + h_firstGains->Draw("HIST"); h_lastGains->Draw("HISTsame"); - TLegend legend = TLegend(0.70, 0.7, 0.95, 0.9); - legend.SetHeader("Gain Comparison", "C"); // option "C" allows to center the header - legend.AddEntry(h_firstGains.get(), ("IOV: " + std::to_string(std::get<0>(firstiov))).c_str(), "PL"); - legend.AddEntry(h_lastGains.get(), ("IOV: " + std::to_string(std::get<0>(lastiov))).c_str(), "PL"); + TLegend legend = TLegend(0.30, 0.78, 0.95, 0.9); + legend.SetHeader("#font[22]{SiStrip APV Gains Comparison}", "C"); // option "C" allows to center the header + legend.AddEntry(h_firstGains.get(), ("payload: #color[2]{" + std::get<1>(firstiov) + "}").c_str(), "F"); + legend.AddEntry(h_lastGains.get(), ("payload: #color[4]{" + std::get<1>(lastiov) + "}").c_str(), "F"); + legend.SetTextSize(0.025); legend.Draw("same"); + auto ltx = TLatex(); + ltx.SetTextFont(62); + ltx.SetTextSize(0.037); + ltx.SetTextAlign(11); + std::string ltxText; + if (this->m_plotAnnotations.ntags == 2) { + ltxText = fmt::sprintf( + "#splitline{#color[2]{%s, %s} vs}{#color[4]{%s, %s}}", tagname1, firstIOVsince, tagname2, lastIOVsince); + } else { + ltxText = fmt::sprintf( + "#splitline{%s}{IOV: #color[2]{%s} vs IOV: #color[4]{%s}}", tagname1, firstIOVsince, lastIOVsince); + } + ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.04, ltxText.c_str()); + // lower plot will be in pad canvas.cd(); // Go back to the main canvas before defining pad2 TPad pad2("pad2", "pad2", 0, 0.005, 1, 0.3); diff --git a/CondTools/SiStrip/plugins/SiStripApvGainFromDeDxCalibration.cc b/CondTools/SiStrip/plugins/SiStripApvGainFromDeDxCalibration.cc new file mode 100644 index 0000000000000..ee3a00bc02408 --- /dev/null +++ b/CondTools/SiStrip/plugins/SiStripApvGainFromDeDxCalibration.cc @@ -0,0 +1,107 @@ +// system include files +#include +#include + +// user include files +#include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h" +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "CondFormats/SiStripObjects/interface/SiStripApvGain.h" +#include "CondFormats/PhysicsToolsObjects/interface/DeDxCalibration.h" +#include "CondFormats/DataRecord/interface/DeDxCalibrationRcd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/ParameterSet/interface/FileInPath.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Utilities/interface/Exception.h" + +class SiStripApvGainFromDeDxCalibration : public edm::one::EDAnalyzer<> { +public: + explicit SiStripApvGainFromDeDxCalibration(const edm::ParameterSet& iConfig); + + ~SiStripApvGainFromDeDxCalibration() override = default; + + void analyze(const edm::Event&, const edm::EventSetup&) override; + + static void fillDescriptions(edm::ConfigurationDescriptions&); + + typedef std::pair ChipId; + +private: + const edm::ESGetToken dedxCalibToken_; + const edm::FileInPath fp_; + const bool printdebug_; +}; + +SiStripApvGainFromDeDxCalibration::SiStripApvGainFromDeDxCalibration(const edm::ParameterSet& iConfig) + : dedxCalibToken_(esConsumes()), + fp_(iConfig.getUntrackedParameter("file", + edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))), + printdebug_(iConfig.getUntrackedParameter("printDebug", 1)) {} + +void SiStripApvGainFromDeDxCalibration::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) { + unsigned int run = evt.id().run(); + + edm::LogInfo("SiStripApvGainFromDeDxCalibration") + << "... creating dummy SiStripApvGain Data for Run " << run << "\n " << std::endl; + + SiStripApvGain obj; + + const auto& reader = SiStripDetInfoFileReader::read(fp_.fullPath()); + const auto& DetInfos = reader.getAllData(); + const auto& dedxCalib = iSetup.getData(dedxCalibToken_); + + int count = -1; + for (const auto& it : DetInfos) { + const auto& nAPVs = it.second.nApvs; + count++; + //Generate Gain for det detid + std::vector theSiStripVector; + for (unsigned short j = 0; j < nAPVs; j++) { + const auto& chipId = ChipId(it.first, j); + const auto& g = dedxCalib.gain().find(chipId); + + if (g == dedxCalib.gain().end()) + continue; + + if (count < printdebug_) + edm::LogInfo("SiStripApvGainFromDeDxCalibration") << "detid " << it.first << " \t" + << " apv " << j << " \t" << g->second << " \t" << std::endl; + theSiStripVector.push_back(g->second); + } + + SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end()); + if (!obj.put(it.first, range)) + edm::LogError("SiStripApvGainFromDeDxCalibration") + << "[SiStripApvGainFromDeDxCalibration::analyze] detid already exists" << std::endl; + } + + //End now write sistripnoises data in DB + edm::Service mydbservice; + + if (mydbservice.isAvailable()) { + if (mydbservice->isNewTagRequest("SiStripApvGainRcd")) { + mydbservice->createOneIOV(obj, mydbservice->beginOfTime(), "SiStripApvGainRcd"); + } else { + mydbservice->appendOneIOV(obj, mydbservice->currentTime(), "SiStripApvGainRcd"); + } + } else { + edm::LogError("SiStripApvGainFromDeDxCalibration") << "Service is unavailable" << std::endl; + } +} + +void SiStripApvGainFromDeDxCalibration::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.addUntracked("file", edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile)); + desc.addUntracked("printDebug", 1); + descriptions.addWithDefaultLabel(desc); +} + +#include "FWCore/PluginManager/interface/ModuleDef.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +DEFINE_FWK_MODULE(SiStripApvGainFromDeDxCalibration); diff --git a/CondTools/SiStrip/test/SiStripApvGainFromDeDxCalibration_cfg.py b/CondTools/SiStrip/test/SiStripApvGainFromDeDxCalibration_cfg.py new file mode 100644 index 0000000000000..70b9caacfd9c7 --- /dev/null +++ b/CondTools/SiStrip/test/SiStripApvGainFromDeDxCalibration_cfg.py @@ -0,0 +1,65 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("ICALIB") +process.source = cms.Source("EmptyIOVSource", + firstValue = cms.uint64(1), + lastValue = cms.uint64(1), + timetype = cms.string('runnumber'), + interval = cms.uint64(1) +) + +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.cerr.enable = False +process.MessageLogger.SiStripApvGainFromDeDxCalibration=dict() +process.MessageLogger.cout = cms.untracked.PSet( + enable = cms.untracked.bool(True), + threshold = cms.untracked.string("DEBUG"), + default = cms.untracked.PSet(limit = cms.untracked.int32(0)), + FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1), + reportEvery = cms.untracked.int32(1000) + ), + SiStripApvGainFromDeDxCalibration = cms.untracked.PSet( limit = cms.untracked.int32(-1)), + enableStatistics = cms.untracked.bool(True) + ) + + +process.load("Configuration.Geometry.GeometryExtended2024_cff") +process.load("Geometry.TrackerGeometryBuilder.trackerParameters_cfi") +process.TrackerTopologyEP = cms.ESProducer("TrackerTopologyEP") + +#Setup the SiSTripFedCabling and the SiStripDetCabling +process.load("CondCore.CondDB.CondDB_cfi") +process.CondDB.connect='frontier://FrontierProd/CMS_CONDITIONS' + +process.poolDBESSource = cms.ESSource('PoolDBESSource', + process.CondDB, + BlobStreamerName = cms.untracked.string('TBufferBlobStreamingService'), + toGet = cms.VPSet( cms.PSet(record = cms.string('DeDxCalibrationRcd'), + tag = cms.string('DeDxCalibration_HI_2024_prompt_v2') + ) + ) + ) + +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(1) +) + +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + BlobStreamerName = cms.untracked.string('TBufferBlobStreamingService'), + DBParameters = cms.PSet( + authenticationPath = cms.untracked.string('/afs/cern.ch/cms/DB/conddb') + ), + timetype = cms.untracked.string('runnumber'), + connect = cms.string('sqlite_file:SiStripApvGainFromDeDxCalibration_HI_2024_prompt_v2.db'), + toPut = cms.VPSet(cms.PSet( + record = cms.string('SiStripApvGainRcd'), + tag = cms.string('SiStripApvGainFromDeDxCalibration_HI_2024_prompt_v2') + )) +) + +from CondTools.SiStrip.siStripApvGainFromDeDxCalibration_cfi import siStripApvGainFromDeDxCalibration +process.prod = siStripApvGainFromDeDxCalibration.clone( + file = cms.untracked.FileInPath('CalibTracker/SiStripCommon/data/SiStripDetInfo.dat'), + printDebug = cms.untracked.uint32(100) +) +process.p = cms.Path(process.prod)