Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-24 01:11:20

0001 #include <string>
0002 #include <iostream>
0003 #include <map>
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 #include "FWCore/Framework/interface/ESHandle.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
0012 #include "CondFormats/DataRecord/interface/SiPixelQualityFromDbRcd.h"
0013 #include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h"
0014 #include "CondFormats/DataRecord/interface/SiPixelStatusScenariosRcd.h"
0015 #include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h"
0016 #include "CondFormats/DataRecord/interface/SiPixelStatusScenarioProbabilityRcd.h"
0017 
0018 class SiPixelBadFEDChannelSimulationSanityChecker : public edm::one::EDAnalyzer<> {
0019 public:
0020   explicit SiPixelBadFEDChannelSimulationSanityChecker(edm::ParameterSet const& p);
0021   ~SiPixelBadFEDChannelSimulationSanityChecker() override;
0022 
0023   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0024 
0025 private:
0026   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0027 
0028   // ----------member data ---------------------------
0029   const edm::ESGetToken<SiPixelFEDChannelContainer, SiPixelStatusScenariosRcd> siPixelBadFEDChToken_;
0030   const edm::ESGetToken<SiPixelQualityProbabilities, SiPixelStatusScenarioProbabilityRcd> siPixelQPToken_;
0031   const bool printdebug_;
0032 };
0033 
0034 SiPixelBadFEDChannelSimulationSanityChecker::SiPixelBadFEDChannelSimulationSanityChecker(edm::ParameterSet const& p)
0035     : siPixelBadFEDChToken_(esConsumes()),
0036       siPixelQPToken_(esConsumes()),
0037       printdebug_(p.getUntrackedParameter<bool>("printDebug", true)) {
0038   edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker")
0039       << "SiPixelBadFEDChannelSimulationSanityChecker" << std::endl;
0040 }
0041 
0042 SiPixelBadFEDChannelSimulationSanityChecker::~SiPixelBadFEDChannelSimulationSanityChecker() {
0043   edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker")
0044       << "~SiPixelBadFEDChannelSimulationSanityChecker " << std::endl;
0045 }
0046 
0047 void SiPixelBadFEDChannelSimulationSanityChecker::analyze(const edm::Event& e, const edm::EventSetup& context) {
0048   edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker")
0049       << "### SiPixelBadFEDChannelSimulationSanityChecker::analyze  ###" << std::endl;
0050   edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0051   edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker") << " ---EVENT NUMBER " << e.id().event() << std::endl;
0052 
0053   edm::eventsetup::EventSetupRecordKey recordKey(
0054       edm::eventsetup::EventSetupRecordKey::TypeTag::findType("SiPixelStatusScenariosRcd"));
0055   if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0056     //record not found
0057     edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker") << "Record \"SiPixelStatusScenariosRcd"
0058                                                                 << "\" does not exist " << std::endl;
0059   }
0060 
0061   //this part gets the handle of the event source and the record (i.e. the Database)
0062   const SiPixelFEDChannelContainer* quality_map = &context.getData(siPixelBadFEDChToken_);
0063 
0064   edm::eventsetup::EventSetupRecordKey recordKey2(
0065       edm::eventsetup::EventSetupRecordKey::TypeTag::findType("SiPixelStatusScenarioProbabilityRcd>"));
0066 
0067   if (recordKey2.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0068     //record not found
0069     edm::LogWarning("SiPixelQualityProbabilitiesTestReader") << "Record \"SiPixelStatusScenarioProbabilityRcd>"
0070                                                              << "\" does not exist " << std::endl;
0071   }
0072 
0073   //this part gets the handle of the event source and the record (i.e. the Database)
0074   const SiPixelQualityProbabilities* myProbabilities = &context.getData(siPixelQPToken_);
0075 
0076   SiPixelFEDChannelContainer::SiPixelBadFEDChannelsScenarioMap m_qualities = quality_map->getScenarioMap();
0077   SiPixelQualityProbabilities::probabilityMap m_probabilities = myProbabilities->getProbability_Map();
0078 
0079   std::vector<std::string> allScenarios = quality_map->getScenarioList();
0080   std::vector<std::string> allScenariosInProb;
0081 
0082   for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
0083     //int PUbin = it->first;
0084     for (const auto& entry : it->second) {
0085       auto scenario = entry.first;
0086       auto probability = entry.second;
0087       if (probability != 0) {
0088         if (std::find(allScenariosInProb.begin(), allScenariosInProb.end(), scenario) == allScenariosInProb.end()) {
0089           allScenariosInProb.push_back(scenario);
0090         }
0091 
0092         // if(m_qualities.find(scenario) == m_qualities.end()){
0093         //   edm::LogWarning("SiPixelBadFEDChannelSimulationSanityChecker") <<"Pretty worrying! the scenario: " << scenario << " (prob:" << probability << ") is not found in the map!!"<<std::endl;
0094         // } else {
0095         //   edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker") << "scenario: "<< scenario << " is in the map! (all is good)"<< std::endl;
0096         // }
0097 
0098       }  // if prob!=0
0099     }    // loop on the scenarios for that PU bin
0100   }      // loop on PU bins
0101 
0102   std::vector<std::string> notFound;
0103   std::copy_if(allScenariosInProb.begin(),
0104                allScenariosInProb.end(),
0105                std::back_inserter(notFound),
0106                [&allScenarios](const std::string& arg) {
0107                  return (std::find(allScenarios.begin(), allScenarios.end(), arg) == allScenarios.end());
0108                });
0109 
0110   if (!notFound.empty()) {
0111     for (const auto& entry : notFound) {
0112       edm::LogWarning("SiPixelBadFEDChannelSimulationSanityChecker")
0113           << "Pretty worrying! the scenario: " << entry << "  is not found in the map!!" << std::endl;
0114 
0115       if (printdebug_) {
0116         edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker") << " This scenario is found in: " << std::endl;
0117         for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
0118           int PUbin = it->first;
0119 
0120           for (const auto& pair : it->second) {
0121             if (pair.first == entry) {
0122               edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker")
0123                   << " - PU bin " << PUbin << " with probability: " << pair.second << std::endl;
0124             }  // if the scenario matches
0125           }    // loop on scenarios
0126         }      // loop on PU
0127       }        // if printdebug
0128       edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker")
0129           << "==============================================" << std::endl;
0130     }  // loop on scenarios not found
0131 
0132     edm::LogWarning("SiPixelBadFEDChannelSimulationSanityChecker")
0133         << " ====> A total of " << notFound.size() << " scenarios are not found in the map!" << std::endl;
0134 
0135   } else {
0136     edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker")
0137         << "=================================================================================" << std::endl;
0138     edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker")
0139         << " All scenarios in probability record are found in the scenario map, (all is good)!" << std::endl;
0140     edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker")
0141         << "=================================================================================" << std::endl;
0142   }
0143 }
0144 
0145 void SiPixelBadFEDChannelSimulationSanityChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0146   edm::ParameterSetDescription desc;
0147   desc.setComment("Tries sanity of Pixel Stuck TBM simulation");
0148   desc.addUntracked<bool>("printDebug", true);
0149   descriptions.add("SiPixelBadFEDChannelSimulationSanityChecker", desc);
0150 }
0151 
0152 DEFINE_FWK_MODULE(SiPixelBadFEDChannelSimulationSanityChecker);