CMS 3D CMS Logo

SiPixelBadFEDChannelSimulationSanityChecker.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <map>
17 
19 public:
22 
23  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
24 
25 private:
26  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
27 
28  // ----------member data ---------------------------
31  const bool printdebug_;
32 };
33 
35  : siPixelBadFEDChToken_(esConsumes()),
36  siPixelQPToken_(esConsumes()),
37  printdebug_(p.getUntrackedParameter<bool>("printDebug", true)) {
38  edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker")
39  << "SiPixelBadFEDChannelSimulationSanityChecker" << std::endl;
40 }
41 
43  edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker")
44  << "~SiPixelBadFEDChannelSimulationSanityChecker " << std::endl;
45 }
46 
48  edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker")
49  << "### SiPixelBadFEDChannelSimulationSanityChecker::analyze ###" << std::endl;
50  edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
51  edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker") << " ---EVENT NUMBER " << e.id().event() << std::endl;
52 
54  edm::eventsetup::EventSetupRecordKey::TypeTag::findType("SiPixelStatusScenariosRcd"));
56  //record not found
57  edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker") << "Record \"SiPixelStatusScenariosRcd"
58  << "\" does not exist " << std::endl;
59  }
60 
61  //this part gets the handle of the event source and the record (i.e. the Database)
62  const SiPixelFEDChannelContainer* quality_map = &context.getData(siPixelBadFEDChToken_);
63 
65  edm::eventsetup::EventSetupRecordKey::TypeTag::findType("SiPixelStatusScenarioProbabilityRcd>"));
66 
68  //record not found
69  edm::LogWarning("SiPixelQualityProbabilitiesTestReader") << "Record \"SiPixelStatusScenarioProbabilityRcd>"
70  << "\" does not exist " << std::endl;
71  }
72 
73  //this part gets the handle of the event source and the record (i.e. the Database)
74  const SiPixelQualityProbabilities* myProbabilities = &context.getData(siPixelQPToken_);
75 
77  SiPixelQualityProbabilities::probabilityMap m_probabilities = myProbabilities->getProbability_Map();
78 
79  std::vector<std::string> allScenarios = quality_map->getScenarioList();
80  std::vector<std::string> allScenariosInProb;
81 
82  for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
83  //int PUbin = it->first;
84  for (const auto& entry : it->second) {
85  auto scenario = entry.first;
86  auto probability = entry.second;
87  if (probability != 0) {
88  if (std::find(allScenariosInProb.begin(), allScenariosInProb.end(), scenario) == allScenariosInProb.end()) {
89  allScenariosInProb.push_back(scenario);
90  }
91 
92  // if(m_qualities.find(scenario) == m_qualities.end()){
93  // edm::LogWarning("SiPixelBadFEDChannelSimulationSanityChecker") <<"Pretty worrying! the scenario: " << scenario << " (prob:" << probability << ") is not found in the map!!"<<std::endl;
94  // } else {
95  // edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker") << "scenario: "<< scenario << " is in the map! (all is good)"<< std::endl;
96  // }
97 
98  } // if prob!=0
99  } // loop on the scenarios for that PU bin
100  } // loop on PU bins
101 
102  std::vector<std::string> notFound;
103  std::copy_if(allScenariosInProb.begin(),
104  allScenariosInProb.end(),
105  std::back_inserter(notFound),
106  [&allScenarios](const std::string& arg) {
107  return (std::find(allScenarios.begin(), allScenarios.end(), arg) == allScenarios.end());
108  });
109 
110  if (!notFound.empty()) {
111  for (const auto& entry : notFound) {
112  edm::LogWarning("SiPixelBadFEDChannelSimulationSanityChecker")
113  << "Pretty worrying! the scenario: " << entry << " is not found in the map!!" << std::endl;
114 
115  if (printdebug_) {
116  edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker") << " This scenario is found in: " << std::endl;
117  for (auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
118  int PUbin = it->first;
119 
120  for (const auto& pair : it->second) {
121  if (pair.first == entry) {
122  edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker")
123  << " - PU bin " << PUbin << " with probability: " << pair.second << std::endl;
124  } // if the scenario matches
125  } // loop on scenarios
126  } // loop on PU
127  } // if printdebug
128  edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker")
129  << "==============================================" << std::endl;
130  } // loop on scenarios not found
131 
132  edm::LogWarning("SiPixelBadFEDChannelSimulationSanityChecker")
133  << " ====> A total of " << notFound.size() << " scenarios are not found in the map!" << std::endl;
134 
135  } else {
136  edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker")
137  << "=================================================================================" << std::endl;
138  edm::LogInfo("SiPixelBadFEDChannelSimulationSanityChecker")
139  << " All scenarios in probability record are found in the scenario map, (all is good)!" << std::endl;
140  edm::LogVerbatim("SiPixelBadFEDChannelSimulationSanityChecker")
141  << "=================================================================================" << std::endl;
142  }
143 }
144 
147  desc.setComment("Tries sanity of Pixel Stuck TBM simulation");
148  desc.addUntracked<bool>("printDebug", true);
149  descriptions.add("SiPixelBadFEDChannelSimulationSanityChecker", desc);
150 }
151 
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< SiPixelFEDChannelContainer, SiPixelStatusScenariosRcd > siPixelBadFEDChToken_
std::map< unsigned int, probabilityVec > probabilityMap
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void analyze(const edm::Event &e, const edm::EventSetup &c) override
const SiPixelBadFEDChannelsScenarioMap & getScenarioMap() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
A arg
Definition: Factorize.h:31
const edm::ESGetToken< SiPixelQualityProbabilities, SiPixelStatusScenarioProbabilityRcd > siPixelQPToken_
scenario
Definition: constants.h:173
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
const probabilityMap & getProbability_Map() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static const GlobalPoint notFound(0, 0, 0)
std::vector< std::string > getScenarioList() const
heterocontainer::HCTypeTag TypeTag
std::unordered_map< std::string, SiPixelFEDChannelCollection > SiPixelBadFEDChannelsScenarioMap
Log< level::Warning, false > LogWarning
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:121