Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:40

0001 // system include files
0002 #include <iostream>
0003 #include <memory>
0004 
0005 // user include files
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h"
0016 #include "DataFormats/GEMRecHit/interface/ME0RecHitCollection.h"
0017 //
0018 // class declaration
0019 //
0020 
0021 class GEMDetIdAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0022 public:
0023   explicit GEMDetIdAnalyzer(const edm::ParameterSet&);
0024   ~GEMDetIdAnalyzer() override {}
0025 
0026   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0027 
0028 protected:
0029   void beginJob() override {}
0030   void beginRun(edm::Run const&, edm::EventSetup const&) override {}
0031   void analyze(edm::Event const&, edm::EventSetup const&) override;
0032   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0033 
0034 private:
0035   const edm::EDGetToken gemRecHit_, me0RecHit_;
0036   const bool newGEM_;
0037 };
0038 
0039 GEMDetIdAnalyzer::GEMDetIdAnalyzer(const edm::ParameterSet& iConfig)
0040     : gemRecHit_(consumes<GEMRecHitCollection>(iConfig.getParameter<edm::InputTag>("gemInputLabel"))),
0041       me0RecHit_(consumes<ME0RecHitCollection>(iConfig.getParameter<edm::InputTag>("me0InputLabel"))),
0042       newGEM_(iConfig.getParameter<bool>("newGEMDetID")) {}
0043 
0044 void GEMDetIdAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0045   edm::ParameterSetDescription desc;
0046   desc.add<edm::InputTag>("gemInputLabel", edm::InputTag("gemRecHits"));
0047   desc.add<edm::InputTag>("me0InputLabel", edm::InputTag("me0RecHits"));
0048   desc.add<bool>("newGEMDetID", true);
0049   descriptions.add("gemDetIdAnalyzer", desc);
0050 }
0051 
0052 void GEMDetIdAnalyzer::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0053   const edm::Handle<GEMRecHitCollection>& gemRecHits = iEvent.getHandle(gemRecHit_);
0054   if (!gemRecHits.isValid()) {
0055     edm::LogError("GEMAnalysis") << "GEM RecHit is not valid";
0056   } else {
0057     edm::LogVerbatim("GEMAnalysis") << "GEMRecHit collection with " << gemRecHits.product()->size() << " hits";
0058     unsigned int k(0);
0059     for (const auto& hit : *(gemRecHits.product())) {
0060       GEMDetId id = hit.gemId();
0061       edm::LogVerbatim("GEMAnalysis") << "Hit[" << k << "] " << std::hex << id.rawId() << std::dec << " " << id;
0062       ++k;
0063     }
0064   }
0065 
0066   const edm::Handle<ME0RecHitCollection>& me0RecHits = iEvent.getHandle(me0RecHit_);
0067   if (!me0RecHits.isValid()) {
0068     edm::LogError("GEMAnalysis") << "ME0 RecHit is not valid";
0069   } else {
0070     edm::LogVerbatim("GEMAnalysis") << "ME0RecHit collection with " << me0RecHits.product()->size() << " hits";
0071     unsigned int k(0);
0072     for (const auto& hit : *(me0RecHits.product())) {
0073       ME0DetId id = hit.me0Id();
0074       edm::LogVerbatim("GEMAnalysis") << "Hit[" << k << "] " << std::hex << id.rawId() << std::dec << " " << id;
0075       if (newGEM_) {
0076         GEMDetId idx(id.rawId());
0077         edm::LogVerbatim("GEMAnalysis") << "for GEM " << std::hex << idx.rawId() << std::dec << " " << idx;
0078       }
0079 
0080       ++k;
0081     }
0082   }
0083 }
0084 
0085 //define this as a plug-in
0086 DEFINE_FWK_MODULE(GEMDetIdAnalyzer);