Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-03 02:56:59

0001 /// Stand-alone test of bad strip channels testing via CSCRecoConditions
0002 /// Tim Cox - 07-Oct-2014 - now using MessageLogger
0003 
0004 #include <string>
0005 #include <vector>
0006 
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Utilities/interface/ESGetToken.h"
0016 
0017 #include "CalibMuon/CSCCalibration/interface/CSCIndexerBase.h"
0018 #include "CalibMuon/CSCCalibration/interface/CSCIndexerRecord.h"
0019 #include "CalibMuon/CSCCalibration/interface/CSCChannelMapperBase.h"
0020 #include "CalibMuon/CSCCalibration/interface/CSCChannelMapperRecord.h"
0021 
0022 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
0023 
0024 #include <Geometry/Records/interface/MuonGeometryRecord.h>
0025 #include <Geometry/CSCGeometry/interface/CSCGeometry.h>
0026 #include <Geometry/CSCGeometry/interface/CSCLayer.h>
0027 
0028 #include <RecoLocalMuon/CSCRecHitD/src/CSCRecoConditions.h>
0029 
0030 class CSCRecoBadChannelsAnalyzer : public edm::one::EDAnalyzer<> {
0031 public:
0032   explicit CSCRecoBadChannelsAnalyzer(edm::ParameterSet const& ps)
0033       : dashedLineWidth_(80),
0034         dashedLine_(std::string(dashedLineWidth_, '-')),
0035         myName_("CSCRecoBadChannelsAnalyzer"),
0036         readBadChannels_(ps.getParameter<bool>("readBadChannels")),
0037         recoConditions_(new CSCRecoConditions(ps, consumesCollector())),
0038         indexerToken_(esConsumes<CSCIndexerBase, CSCIndexerRecord>()),
0039         mapperToken_(esConsumes<CSCChannelMapperBase, CSCChannelMapperRecord>()),
0040         geometryToken_(esConsumes<CSCGeometry, MuonGeometryRecord>()) {}
0041 
0042   ~CSCRecoBadChannelsAnalyzer() override { delete recoConditions_; }
0043   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0044 
0045   /// did we request reading bad channel info from db?
0046   bool readBadChannels() const { return readBadChannels_; }
0047   const std::string& myName() { return myName_; }
0048 
0049 private:
0050   const int dashedLineWidth_;
0051   const std::string dashedLine_;
0052   const std::string myName_;
0053 
0054   bool readBadChannels_;
0055   CSCRecoConditions* recoConditions_;
0056   edm::ESGetToken<CSCIndexerBase, CSCIndexerRecord> indexerToken_;
0057   edm::ESGetToken<CSCChannelMapperBase, CSCChannelMapperRecord> mapperToken_;
0058   edm::ESGetToken<CSCGeometry, MuonGeometryRecord> geometryToken_;
0059 };
0060 
0061 void CSCRecoBadChannelsAnalyzer::analyze(const edm::Event& ev, const edm::EventSetup& evsetup) {
0062   using namespace edm::eventsetup;
0063 
0064   edm::LogVerbatim("CSCBadChannels") << myName() << "::analyze running...";
0065   edm::LogVerbatim("CSCBadChannels") << "start " << dashedLine_;
0066 
0067   edm::LogVerbatim("CSCBadChannels") << "RUN# " << ev.id().run();
0068   edm::LogVerbatim("CSCBadChannels") << "EVENT# " << ev.id().event();
0069 
0070   edm::ESHandle<CSCIndexerBase> theIndexer = evsetup.getHandle(indexerToken_);
0071 
0072   edm::LogVerbatim("CSCBadChannels") << myName() << "::analyze sees indexer " << theIndexer->name()
0073                                      << " in Event Setup";
0074 
0075   edm::ESHandle<CSCChannelMapperBase> theMapper = evsetup.getHandle(mapperToken_);
0076 
0077   edm::LogVerbatim("CSCBadChannels") << myName() << "::analyze sees mapper " << theMapper->name() << " in Event Setup";
0078 
0079   edm::ESHandle<CSCGeometry> theGeometry = evsetup.getHandle(geometryToken_);
0080 
0081   edm::LogVerbatim("CSCBadChannels") << " Geometry node for CSCGeom is  " << &(*theGeometry);
0082   edm::LogVerbatim("CSCBadChannels") << " There are " << theGeometry->dets().size() << " dets";
0083   edm::LogVerbatim("CSCBadChannels") << " There are " << theGeometry->detTypes().size() << " types"
0084                                      << "\n";
0085 
0086   // INITIALIZE CSCConditions
0087   recoConditions_->initializeEvent(evsetup);
0088 
0089   // HERE NEED TO ITERATE OVER ALL CSCDetId
0090 
0091   edm::LogVerbatim("CSCBadChannels") << myName() << ": Begin iteration over geometry...";
0092 
0093   const CSCGeometry::LayerContainer& vecOfLayers = theGeometry->layers();
0094   edm::LogVerbatim("CSCBadChannels") << "There are " << vecOfLayers.size() << " layers";
0095 
0096   edm::LogVerbatim("CSCBadChannels") << dashedLine_;
0097 
0098   int ibadchannels = 0;  // COUNT OF BAD STRIP CHANNELS
0099   int ibadlayers = 0;    //COUNT OF LAYERS WITH BAD STRIP CHANNELS
0100 
0101   for (auto it = vecOfLayers.begin(); it != vecOfLayers.end(); ++it) {
0102     const CSCLayer* layer = *it;
0103 
0104     if (layer) {
0105       CSCDetId id = layer->id();
0106       int nstrips = layer->geometry()->numberOfStrips();
0107       edm::LogVerbatim("CSCBadChannels") << "Layer " << id << " has " << nstrips << " strips";
0108 
0109       // GET BAD CHANNELS FOR THIS LAYER
0110 
0111       recoConditions_->fillBadChannelWords(id);
0112 
0113       // SEARCH FOR BAD STRIP CHANNELS IN THIS LAYER - GEOMETRIC STRIP INPUT!!
0114 
0115       bool layerhasbadchannels = false;
0116       for (short is = 1; is <= nstrips; ++is) {
0117         if (recoConditions_->badStrip(id, is, nstrips)) {
0118           ++ibadchannels;
0119           layerhasbadchannels = true;
0120           edm::LogVerbatim("CSCBadChannels") << id << " strip " << is << " is bad";
0121         }
0122       }
0123 
0124       for (short is = 1; is <= nstrips; ++is) {
0125         if (recoConditions_->nearBadStrip(id, is, nstrips)) {
0126           edm::LogVerbatim("CSCBadChannels") << id << " strip " << is << " is a neighbor of a bad strip";
0127         }
0128       }
0129 
0130       if (layerhasbadchannels)
0131         ++ibadlayers;
0132 
0133     } else {
0134       edm::LogVerbatim("CSCBadChannels") << "WEIRD ERROR: a null CSCLayer* was seen";
0135     }
0136   }
0137 
0138   edm::LogVerbatim("CSCBadChannels") << "No. of layers with bad strip channels = " << ibadlayers;
0139   edm::LogVerbatim("CSCBadChannels") << "No. of bad strip channels seen = " << ibadchannels;
0140 
0141   edm::LogVerbatim("CSCBadChannels") << dashedLine_ << " end";
0142 }
0143 
0144 DEFINE_FWK_MODULE(CSCRecoBadChannelsAnalyzer);