Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-02 03:38:57

0001 #include <stdexcept>
0002 #include <string>
0003 #include <iostream>
0004 #include <fstream>
0005 #include <string>
0006 #include <vector>
0007 #include <bitset>
0008 
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Utilities/interface/ESGetToken.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 
0019 #include "CondFormats/CSCObjects/interface/CSCBadChambers.h"
0020 #include "CondFormats/DataRecord/interface/CSCBadChambersRcd.h"
0021 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0022 #include "DataFormats/MuonDetId/interface/CSCIndexer.h"
0023 
0024 namespace edmtest {
0025   class CSCReadBadChambersAnalyzer : public edm::one::EDAnalyzer<> {
0026   public:
0027     explicit CSCReadBadChambersAnalyzer(edm::ParameterSet const& ps)
0028         : chambersToken_{esConsumes()},
0029           outputToFile_(ps.getParameter<bool>("outputToFile")),
0030           readBadChambers_(ps.getParameter<bool>("readBadChambers")),
0031           me42installed_(ps.getParameter<bool>("me42installed")) {}
0032 
0033     ~CSCReadBadChambersAnalyzer() override {}
0034 
0035     void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0036 
0037   private:
0038     const edm::ESGetToken<CSCBadChambers, CSCBadChambersRcd> chambersToken_;
0039     const bool outputToFile_;
0040     const bool readBadChambers_;  // flag whether or not to even attempt reading bad channel info from db
0041     const bool me42installed_;    // flag whether ME42 chambers are installed in the geometry
0042   };
0043 
0044   void CSCReadBadChambersAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0045     using namespace edm::eventsetup;
0046 
0047     edm::LogSystem log("CSCBadChambers");
0048 
0049     int counter = 0;
0050     log << " RUN# " << e.id().run() << std::endl;
0051     log << " EVENT# " << e.id().event() << std::endl;
0052 
0053     auto theBadChambers = &context.getData(chambersToken_);
0054 
0055     CSCIndexer indexer;  // just to build a CSCDetId from chamber index
0056 
0057     log << "Bad Chambers:" << std::endl;
0058 
0059     int nbad = theBadChambers->numberOfChambers();
0060     log << "No. in list = " << nbad << std::endl;
0061 
0062     // Iterate over all chambers via their linear index
0063 
0064     int countbad = 0;
0065     int countgood = 0;
0066 
0067     // One more than total number of chambers
0068     // Last chamber is already in ME4 but could be 41 or 42
0069     int lastRing = 1;
0070     if (me42installed_)
0071       lastRing = 2;
0072     int totalc = indexer.startChamberIndexInEndcap(2, 4, lastRing) + indexer.chambersInRingOfStation(4, lastRing);
0073 
0074     for (int indexc = 1; indexc != totalc; ++indexc) {
0075       counter++;
0076 
0077       CSCDetId id = indexer.detIdFromChamberIndex(indexc);
0078       bool bbad = theBadChambers->isInBadChamber(id);
0079       std::string bbads = "LIVE";
0080       if (bbad) {
0081         bbads = "DEAD";
0082         ++countbad;
0083       } else {
0084         ++countgood;
0085       }
0086       log << counter << "  " << indexc << " " << id << " In bad list? " << bbads << std::endl;
0087     }
0088 
0089     log << "Total number of chambers      = " << counter << std::endl;
0090     log << "Total number of good chambers = " << countgood << std::endl;
0091     log << "Total number of bad chambers  = " << countbad << std::endl;
0092 
0093     if (outputToFile_) {
0094       std::ofstream BadChamberFile("dbBadChamber.dat", std::ios::app);
0095       std::vector<int> badChambers = theBadChambers->container();
0096       counter = 0;
0097       std::vector<int>::const_iterator itcham;
0098 
0099       for (itcham = badChambers.begin(); itcham != badChambers.end(); ++itcham) {
0100         counter++;
0101         BadChamberFile << counter << "  " << *itcham << std::endl;
0102       }
0103     }
0104   }
0105 
0106   DEFINE_FWK_MODULE(CSCReadBadChambersAnalyzer);
0107 }  // namespace edmtest