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/SiStripPedestals.h"
0003 
0004 /**
0005   @class SiStripPopConPedestalsHandlerFromDQM
0006   @author M. De Mattia, S. Dutta, D. Giordano
0007 
0008   @popcon::PopConSourceHandler to extract pedestal values the DQM as bad and write in the database.
0009 */
0010 class SiStripPopConPedestalsHandlerFromDQM : public SiStripDQMPopConSourceHandler<SiStripPedestals> {
0011 public:
0012   typedef dqm::legacy::MonitorElement MonitorElement;
0013   typedef dqm::legacy::DQMStore DQMStore;
0014 
0015   explicit SiStripPopConPedestalsHandlerFromDQM(const edm::ParameterSet& iConfig, edm::ConsumesCollector&&);
0016   ~SiStripPopConPedestalsHandlerFromDQM() override;
0017   // interface methods: implemented in template
0018   void dqmEndJob(DQMStore::IBooker& booker, DQMStore::IGetter& getter) override;
0019   SiStripPedestals* getObj() const override;
0020 
0021 private:
0022   edm::FileInPath fp_;
0023   std::string MEDir_;
0024   SiStripPedestals m_obj;
0025 };
0026 
0027 #include "DQMServices/Core/interface/DQMStore.h"
0028 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0029 
0030 SiStripPopConPedestalsHandlerFromDQM::SiStripPopConPedestalsHandlerFromDQM(const edm::ParameterSet& iConfig,
0031                                                                            edm::ConsumesCollector&&)
0032     : SiStripDQMPopConSourceHandler<SiStripPedestals>(iConfig),
0033       fp_{iConfig.getUntrackedParameter<edm::FileInPath>("file",
0034                                                          edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))},
0035       MEDir_{iConfig.getUntrackedParameter<std::string>("ME_DIR", "DQMData")} {
0036   edm::LogInfo("SiStripPedestalsDQMService") << "[SiStripPedestalsDQMService::SiStripPedestalsDQMService]";
0037 }
0038 
0039 SiStripPopConPedestalsHandlerFromDQM::~SiStripPopConPedestalsHandlerFromDQM() {
0040   edm::LogInfo("SiStripPedestalsDQMService") << "[SiStripPedestalsDQMService::~SiStripPedestalsDQMService]";
0041 }
0042 
0043 void SiStripPopConPedestalsHandlerFromDQM::dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter& getter) {
0044   std::cout << "SiStripPedestalsDQMService::readPedestals" << std::endl;
0045 
0046   m_obj = SiStripPedestals();
0047 
0048   const auto detInfo = SiStripDetInfoFileReader::read(fp_.fullPath());
0049 
0050   // getter.cd(iConfig_.getUntrackedParameter<std::string>("ME_DIR"));
0051   getter.cd();
0052 
0053   uint32_t stripsPerApv = 128;
0054 
0055   // Get the full list of monitoring elements
0056   // const std::vector<MonitorElement*>& MEs = getter.getAllContents(iConfig_.getUntrackedParameter<std::string>("ME_DIR","DQMData"));
0057 
0058   // Take a copy of the vector
0059   std::vector<MonitorElement*> MEs = getter.getAllContents(MEDir_);
0060   // Remove all but the MEs we are using
0061   MEs.erase(std::remove_if(MEs.begin(),
0062                            MEs.end(),
0063                            [](const MonitorElement* ME) -> bool {
0064                              return std::string::npos == ME->getName().find("PedsPerStrip__det__");
0065                            }),
0066             MEs.end());
0067 
0068   // The histograms are one per DetId, loop on all the DetIds and extract the corresponding histogram
0069   for (const auto& detInfo : detInfo.getAllData()) {
0070     SiStripPedestals::InputVector theSiStripVector;
0071 
0072     // Take the path for each DetId and build the complete path + histogram name
0073 
0074     // MonitorElement * mE = getModuleHistogram(detInfo.first, "PedsPerStrip");
0075     const MonitorElement* mE{nullptr};
0076     std::string MEname("PedsPerStrip__det__" + std::to_string(detInfo.first));
0077     for (const MonitorElement* ime : MEs) {
0078       if (ime->getName() == MEname) {
0079         mE = ime;
0080         break;
0081       }
0082     }
0083 
0084     // find( MEs.begin(), MEs.end(), "PedsPerStrip__det__"+std::to_string(detInfo.first), findMEbyName() );
0085     // MonitorElement * mE = *(find( MEs.begin(), MEs.end(), findMEbyName("PedsPerStrip__det__"+std::to_string(detInfo.first)) ));
0086 
0087     if (mE) {
0088       TH1F* histo = mE->getTH1F();
0089       if (histo) {
0090         // Read the pedestals from the histograms
0091         uint32_t nBinsX = histo->GetXaxis()->GetNbins();
0092 
0093         if (nBinsX != stripsPerApv * (detInfo.second.nApvs)) {
0094           std::cout << "ERROR: number of bin = " << nBinsX
0095                     << " != number of strips = " << stripsPerApv * (detInfo.second.nApvs) << std::endl;
0096         }
0097 
0098         // std::cout << "Bin 0 = " << histo->GetBinContent(0) << std::endl;
0099         // TH1 bins start from 1, 0 is the underflow, nBinsX+1 the overflow.
0100         for (uint32_t iBin = 1; iBin <= nBinsX; ++iBin) {
0101           // encode the pedestal value and put it in the vector (push_back)
0102           m_obj.setData(histo->GetBinContent(iBin), theSiStripVector);
0103         }
0104       } else {
0105         std::cout << "ERROR: histo = " << histo << std::endl;
0106       }
0107     } else {
0108       std::cout << "ERROR: ME = " << mE << std::endl;
0109     }
0110     // If the ME was absent fill the vector with 0
0111     if (theSiStripVector.empty()) {
0112       for (unsigned short j = 0; j < 128 * detInfo.second.nApvs; ++j) {
0113         m_obj.setData(0, theSiStripVector);
0114       }
0115     }
0116 
0117     if (!m_obj.put(detInfo.first, theSiStripVector))
0118       edm::LogError("SiStripPedestalsFakeESSource::produce ") << " detid already exists" << std::endl;
0119   }
0120   getter.cd();
0121 }
0122 
0123 SiStripPedestals* SiStripPopConPedestalsHandlerFromDQM::getObj() const { return new SiStripPedestals(m_obj); }
0124 
0125 #include "FWCore/Framework/interface/MakerMacros.h"
0126 #include "DQMOffline/CalibTracker/plugins/SiStripPopConDQMEDHarvester.h"
0127 using SiStripPopConPedestalsDQM = SiStripPopConDQMEDHarvester<SiStripPopConPedestalsHandlerFromDQM>;
0128 DEFINE_FWK_MODULE(SiStripPopConPedestalsDQM);