Back to home page

Project CMSSW displayed by LXR

 
 

    


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   @class SiStripNoisesDQMService
0005   @author M. De Mattia, S. Dutta, D. Giordano
0006 
0007   @popcon::PopConSourceHandler to extract noise values the DQM as bad and write in the database.
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   // interface methods: implemented in template
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   // getter.cd(iConfig_.getUntrackedParameter<std::string>("ME_DIR"));
0050   getter.cd();
0051 
0052   uint32_t stripsPerApv = 128;
0053 
0054   // Get the full list of monitoring elements
0055   // const std::vector<MonitorElement*>& MEs = getter.getAllContents(iConfig_.getUntrackedParameter<std::string>("ME_DIR","DQMData"));
0056 
0057   // Take a copy of the vector
0058   std::vector<MonitorElement*> MEs = getter.getAllContents(MEDir_);
0059   // Remove all but the MEs we are using
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   // The histograms are one per DetId, loop on all the DetIds and extract the corresponding histogram
0068   for (const auto& detInfo : detInfo.getAllData()) {
0069     SiStripNoises::InputVector theSiStripVector;
0070 
0071     // Take the path for each DetId and build the complete path + histogram name
0072 
0073     // MonitorElement * mE = getModuleHistogram(detInfo.first, "PedsPerStrip");
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     // find( MEs.begin(), MEs.end(), "PedsPerStrip__det__"+std::to_string(detInfo.first), findMEbyName() );
0084     // MonitorElement * mE = *(find( MEs.begin(), MEs.end(), findMEbyName("PedsPerStrip__det__"+std::to_string(detInfo.first)) ));
0085     if (mE) {
0086       TH1F* histo = mE->getTH1F();
0087       if (histo != nullptr) {
0088         // Read the noise from the histograms
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         // std::cout << "Bin 0 = " << histo->GetBinContent(0) << std::endl;
0097         // TH1 bins start from 1, 0 is the underflow, nBinsX+1 the overflow.
0098         for (uint32_t iBin = 1; iBin <= nBinsX; ++iBin) {
0099           // encode the pedestal value and put it in the vector (push_back)
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     // If the ME was absent fill the vector with 50 (we want a high noise to avoid these modules being considered good by mistake)
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);