File indexing completed on 2024-09-10 02:59:07
0001 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0002 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0003 #include "DataFormats/MuonDetId/interface/GEMDetId.h"
0004 #include "DataFormats/MuonDetId/interface/ME0DetId.h"
0005 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0006 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0007
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/Utilities/interface/InputTag.h"
0016 #include "FWCore/Utilities/interface/transform.h"
0017
0018 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0019 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0020
0021 #include <string>
0022 #include <vector>
0023
0024 class MuonSimHitDump : public edm::one::EDAnalyzer<> {
0025 public:
0026 MuonSimHitDump(const edm::ParameterSet& ps);
0027 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0028
0029 protected:
0030 void analyze(edm::Event const&, edm::EventSetup const&) override;
0031
0032 private:
0033 const std::string g4Label_;
0034 const std::vector<std::string> hitLab_;
0035 const std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> toksMuon_;
0036 const std::vector<int> types_;
0037 const int maxEvent_;
0038 int kount_;
0039 };
0040
0041 MuonSimHitDump::MuonSimHitDump(const edm::ParameterSet& ps)
0042 : g4Label_(ps.getParameter<std::string>("ModuleLabel")),
0043 hitLab_(ps.getParameter<std::vector<std::string>>("HitCollections")),
0044 toksMuon_{edm::vector_transform(
0045 hitLab_,
0046 [this](const std::string& name) { return consumes<edm::PSimHitContainer>(edm::InputTag{g4Label_, name}); })},
0047 types_(ps.getParameter<std::vector<int>>("CollectionTypes")),
0048 maxEvent_(ps.getParameter<int>("MaxEvent")),
0049 kount_(0) {
0050 edm::LogVerbatim("HitStudy") << "Module Label: " << g4Label_ << " with " << hitLab_.size()
0051 << " collections and maxEvent = " << maxEvent_;
0052 for (unsigned int k = 0; k < hitLab_.size(); ++k)
0053 edm::LogVerbatim("HitStudy") << "[" << k << "] Type " << types_[k] << " Label " << hitLab_[k];
0054 }
0055
0056 void MuonSimHitDump::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0057 edm::ParameterSetDescription desc;
0058 std::vector<std::string> coll = {"MuonDTHits", "MuonCSCHits", "MuonRPCHits", "MuonGEMHits"};
0059 std::vector<int> type = {0, 1, 2, 3};
0060 desc.add<std::string>("ModuleLabel", "g4SimHits");
0061 desc.add<std::vector<std::string>>("HitCollections", coll);
0062 desc.add<std::vector<int>>("CollectionTypes", type);
0063 desc.add<int>("MaxEvent", 10);
0064 descriptions.add("muonSimHitDump", desc);
0065 }
0066
0067 void MuonSimHitDump::analyze(const edm::Event& e, const edm::EventSetup&) {
0068 ++kount_;
0069 edm::LogVerbatim("HitStudy") << "[" << kount_ << "] Run = " << e.id().run() << " Event = " << e.id().event();
0070 std::vector<std::string> dets = {"DT", "CSC", "RPC", "GEM", "ME0"};
0071 if ((kount_ <= maxEvent_) || (maxEvent_ <= 0)) {
0072 for (unsigned int k = 0; k < toksMuon_.size(); ++k) {
0073 const edm::Handle<edm::PSimHitContainer>& hitsMuon = e.getHandle(toksMuon_[k]);
0074 if (hitsMuon.isValid())
0075 edm::LogVerbatim("HitStudy") << "MuonSimHitDump: Input " << hitsMuon->size() << " hits of type " << types_[k]
0076 << " (" << dets[k] << ")";
0077 unsigned int i(0);
0078 for (auto const& hit : *hitsMuon) {
0079 auto entry = hit.entryPoint();
0080 auto exit = hit.exitPoint();
0081 auto p = hit.pabs();
0082 auto tof = hit.tof();
0083 auto edep = hit.energyLoss();
0084 unsigned int track = hit.trackId();
0085 unsigned int id = hit.detUnitId();
0086 if (types_[k] == 0)
0087 edm::LogVerbatim("HitStudy") << "[" << i << "] " << DTWireId(id) << " Trk " << track << " p " << p << " dE "
0088 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0089 else if (types_[k] == 1)
0090 edm::LogVerbatim("HitStudy") << "[" << i << "] " << CSCDetId(id) << " Trk " << track << " p " << p << " dE "
0091 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0092 else if (types_[k] == 2)
0093 edm::LogVerbatim("HitStudy") << "[" << i << "] " << RPCDetId(id) << " Trk " << track << " p " << p << " dE "
0094 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0095 else if (types_[k] == 3)
0096 edm::LogVerbatim("HitStudy") << "[" << i << "] " << GEMDetId(id) << " Trk " << track << " p " << p << " dE "
0097 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0098 else
0099 edm::LogVerbatim("HitStudy") << "[" << i << "] " << ME0DetId(id) << " Trk " << track << " p " << p << " dE "
0100 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0101 ++i;
0102 }
0103 }
0104 }
0105 }
0106
0107
0108 DEFINE_FWK_MODULE(MuonSimHitDump);