File indexing completed on 2024-04-06 12:02:00
0001 #include <stdexcept>
0002 #include <string>
0003 #include <iostream>
0004 #include <fstream>
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Utilities/interface/ESGetToken.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014
0015 #include "CondFormats/CSCObjects/interface/CSCDBNoiseMatrix.h"
0016 #include "CondFormats/DataRecord/interface/CSCDBNoiseMatrixRcd.h"
0017 #include "DataFormats/MuonDetId/interface/CSCIndexer.h"
0018
0019 namespace edmtest {
0020 class CSCNoiseMatrixDBReadAnalyzer : public edm::one::EDAnalyzer<> {
0021 public:
0022 explicit CSCNoiseMatrixDBReadAnalyzer(edm::ParameterSet const& p) : token_{esConsumes()} {}
0023 ~CSCNoiseMatrixDBReadAnalyzer() override {}
0024 void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0025
0026 private:
0027 edm::ESGetToken<CSCDBNoiseMatrix, CSCDBNoiseMatrixRcd> token_;
0028 };
0029
0030 void CSCNoiseMatrixDBReadAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0031 std::ofstream DBNoiseMatrixFile("dbmatrix.dat", std::ios::out);
0032 int counter = 0;
0033 using namespace edm::eventsetup;
0034
0035 edm::LogSystem log("CSCDBNoiseMatrix");
0036
0037 log << " Run# " << e.id().run() << std::endl;
0038 log << " Event# " << e.id().event() << std::endl;
0039 log << " Matrix values are written to file dbmatrix.dat & errors are written to cerr." << std::endl;
0040
0041 const CSCDBNoiseMatrix* myNoiseMatrix = &context.getData(token_);
0042 log << " Scale factor for conversion to int was " << myNoiseMatrix->factor_noise << std::endl;
0043
0044 CSCIndexer indexer;
0045
0046 std::vector<CSCDBNoiseMatrix::Item>::const_iterator it;
0047
0048 for (it = myNoiseMatrix->matrix.begin(); it != myNoiseMatrix->matrix.end(); ++it) {
0049 ++counter;
0050 std::pair<CSCDetId, CSCIndexer::IndexType> thePair = indexer.detIdFromStripChannelIndex(counter);
0051 DBNoiseMatrixFile << counter << " " << thePair.first << " chan " << thePair.second << " " << it->elem33 << " "
0052 << it->elem34 << " " << it->elem44 << " " << it->elem35 << " " << it->elem45 << " "
0053 << it->elem55 << " " << it->elem46 << " " << it->elem56 << " " << it->elem66 << " "
0054 << it->elem57 << " " << it->elem67 << " " << it->elem77 << std::endl;
0055 if (it->elem33 < 0) {
0056 std::cerr << " 33(1) negative: " << it->elem33 << std::endl;
0057 }
0058 if (it->elem44 < 0) {
0059 std::cerr << " 44(3) negative: " << it->elem44 << std::endl;
0060 }
0061 if (it->elem55 < 0) {
0062 std::cerr << " 55(6) negative: " << it->elem55 << std::endl;
0063 }
0064 if (it->elem66 < 0) {
0065 std::cerr << " 66(9) negative: " << it->elem66 << std::endl;
0066 }
0067 if (it->elem77 < 0) {
0068 std::cerr << " 77(12) negative: " << it->elem77 << std::endl;
0069 }
0070 }
0071 }
0072 DEFINE_FWK_MODULE(CSCNoiseMatrixDBReadAnalyzer);
0073 }