File indexing completed on 2024-04-06 12:09:18
0001 #include "DQMOffline/CalibTracker/plugins/SiStripDQMPopConSourceHandler.h"
0002 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0003
0004
0005
0006
0007
0008
0009 class SiStripPopConNoisesHandlerFromDQM : public SiStripDQMPopConSourceHandler<SiStripNoises> {
0010 public:
0011 typedef dqm::legacy::MonitorElement MonitorElement;
0012 typedef dqm::legacy::DQMStore DQMStore;
0013
0014 explicit SiStripPopConNoisesHandlerFromDQM(const edm::ParameterSet& iConfig, edm::ConsumesCollector&&);
0015 ~SiStripPopConNoisesHandlerFromDQM() override;
0016
0017 void dqmEndJob(DQMStore::IBooker& booker, DQMStore::IGetter& getter) override;
0018 SiStripNoises* getObj() const override;
0019
0020 private:
0021 edm::FileInPath fp_;
0022 std::string MEDir_;
0023 SiStripNoises m_obj;
0024 };
0025
0026 #include "DQMServices/Core/interface/DQMStore.h"
0027 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0028
0029 SiStripPopConNoisesHandlerFromDQM::SiStripPopConNoisesHandlerFromDQM(const edm::ParameterSet& iConfig,
0030 edm::ConsumesCollector&&)
0031 : SiStripDQMPopConSourceHandler<SiStripNoises>(iConfig),
0032 fp_{iConfig.getUntrackedParameter<edm::FileInPath>("file",
0033 edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))},
0034 MEDir_{iConfig.getUntrackedParameter<std::string>("ME_DIR", "DQMData")} {
0035 edm::LogInfo("SiStripNoisesDQMService") << "[SiStripNoisesDQMService::SiStripNoisesDQMService]";
0036 }
0037
0038 SiStripPopConNoisesHandlerFromDQM::~SiStripPopConNoisesHandlerFromDQM() {
0039 edm::LogInfo("SiStripNoisesDQMService") << "[SiStripNoisesDQMService::~SiStripNoisesDQMService]";
0040 }
0041
0042 void SiStripPopConNoisesHandlerFromDQM::dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter& getter) {
0043 std::cout << "SiStripNoisesDQMService::readNoises" << std::endl;
0044
0045 m_obj = SiStripNoises();
0046
0047 const auto detInfo = SiStripDetInfoFileReader::read(fp_.fullPath());
0048
0049
0050 getter.cd();
0051
0052 uint32_t stripsPerApv = 128;
0053
0054
0055
0056
0057
0058 std::vector<MonitorElement*> MEs = getter.getAllContents(MEDir_);
0059
0060 MEs.erase(std::remove_if(MEs.begin(),
0061 MEs.end(),
0062 [](const MonitorElement* ME) -> bool {
0063 return std::string::npos == ME->getName().find("CMSubNoisePerStrip__det__");
0064 }),
0065 MEs.end());
0066
0067
0068 for (const auto& detInfo : detInfo.getAllData()) {
0069 SiStripNoises::InputVector theSiStripVector;
0070
0071
0072
0073
0074 const MonitorElement* mE{nullptr};
0075 std::string MEname("CMSubNoisePerStrip__det__" + std::to_string(detInfo.first));
0076 for (const MonitorElement* ime : MEs) {
0077 if (ime->getName() == MEname) {
0078 mE = ime;
0079 break;
0080 }
0081 }
0082
0083
0084
0085 if (mE) {
0086 TH1F* histo = mE->getTH1F();
0087 if (histo != nullptr) {
0088
0089 uint32_t nBinsX = histo->GetXaxis()->GetNbins();
0090
0091 if (nBinsX != stripsPerApv * (detInfo.second.nApvs)) {
0092 std::cout << "ERROR: number of bin = " << nBinsX
0093 << " != number of strips = " << stripsPerApv * (detInfo.second.nApvs) << std::endl;
0094 }
0095
0096
0097
0098 for (uint32_t iBin = 1; iBin <= nBinsX; ++iBin) {
0099
0100 m_obj.setData(histo->GetBinContent(iBin), theSiStripVector);
0101 }
0102 } else {
0103 std::cout << "ERROR: histo = " << histo << std::endl;
0104 }
0105 } else {
0106 std::cout << "ERROR: ME = " << mE << std::endl;
0107 }
0108
0109 if (theSiStripVector.empty()) {
0110 for (unsigned short j = 0; j < 128 * detInfo.second.nApvs; ++j) {
0111 m_obj.setData(50, theSiStripVector);
0112 }
0113 }
0114
0115 if (!m_obj.put(detInfo.first, theSiStripVector))
0116 edm::LogError("SiStripNoisesFakeESSource::produce ") << " detid already exists" << std::endl;
0117 }
0118 getter.cd();
0119 }
0120
0121 SiStripNoises* SiStripPopConNoisesHandlerFromDQM::getObj() const { return new SiStripNoises(m_obj); }
0122
0123 #include "FWCore/Framework/interface/MakerMacros.h"
0124 #include "DQMOffline/CalibTracker/plugins/SiStripPopConDQMEDHarvester.h"
0125 using SiStripPopConNoisesDQM = SiStripPopConDQMEDHarvester<SiStripPopConNoisesHandlerFromDQM>;
0126 DEFINE_FWK_MODULE(SiStripPopConNoisesDQM);