File indexing completed on 2023-03-17 11:24:38
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(hitLab_,
0045 [this](const std::string& name) {
0046 return consumes<edm::PSimHitContainer>(edm::InputTag{g4Label_, name});
0047 })},
0048 types_(ps.getParameter<std::vector<int>>("CollectionTypes")),
0049 maxEvent_(ps.getParameter<int>("MaxEvent")),
0050 kount_(0) {
0051 edm::LogVerbatim("HitStudy") << "Module Label: " << g4Label_ << " with " << hitLab_.size()
0052 << " collections and maxEvent = " << maxEvent_;
0053 for (unsigned int k = 0; k < hitLab_.size(); ++k)
0054 edm::LogVerbatim("HitStudy") << "[" << k << "] Type " << types_[k] << " Label " << hitLab_[k];
0055 }
0056
0057 void MuonSimHitDump::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0058 edm::ParameterSetDescription desc;
0059 std::vector<std::string> coll = {"MuonDTHits", "MuonCSCHits", "MuonRPCHits", "MuonGEMHits"};
0060 std::vector<int> type = {0, 1, 2, 3};
0061 desc.add<std::string>("ModuleLabel", "g4SimHits");
0062 desc.add<std::vector<std::string>>("HitCollections", coll);
0063 desc.add<std::vector<int>>("CollectionTypes", type);
0064 desc.add<int>("MaxEvent", 10);
0065 descriptions.add("muonSimHitDump", desc);
0066 }
0067
0068 void MuonSimHitDump::analyze(const edm::Event& e, const edm::EventSetup&) {
0069 ++kount_;
0070 edm::LogVerbatim("HitStudy") << "[" << kount_ << "] Run = " << e.id().run() << " Event = " << e.id().event();
0071 std::vector<std::string> dets = {"DT", "CSC", "RPC", "GEM", "ME0"};
0072 if ((kount_ <= maxEvent_) || (maxEvent_ <= 0)) {
0073 for (unsigned int k = 0; k < toksMuon_.size(); ++k) {
0074 const edm::Handle<edm::PSimHitContainer>& hitsMuon = e.getHandle(toksMuon_[k]);
0075 if (hitsMuon.isValid())
0076 edm::LogVerbatim("HitStudy") << "MuonSimHitDump: Input " << hitsMuon->size() << " hits of type " << types_[k]
0077 << " (" << dets[k] << ")";
0078 unsigned int i(0);
0079 for (auto const& hit : *hitsMuon) {
0080 auto entry = hit.entryPoint();
0081 auto exit = hit.exitPoint();
0082 auto p = hit.pabs();
0083 auto tof = hit.tof();
0084 auto edep = hit.energyLoss();
0085 unsigned int track = hit.trackId();
0086 unsigned int id = hit.detUnitId();
0087 if (types_[k] == 0)
0088 edm::LogVerbatim("HitStudy") << "[" << i << "] " << DTWireId(id) << " Trk " << track << " p " << p << " dE "
0089 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0090 else if (types_[k] == 1)
0091 edm::LogVerbatim("HitStudy") << "[" << i << "] " << CSCDetId(id) << " Trk " << track << " p " << p << " dE "
0092 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0093 else if (types_[k] == 2)
0094 edm::LogVerbatim("HitStudy") << "[" << i << "] " << RPCDetId(id) << " Trk " << track << " p " << p << " dE "
0095 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0096 else if (types_[k] == 3)
0097 edm::LogVerbatim("HitStudy") << "[" << i << "] " << GEMDetId(id) << " Trk " << track << " p " << p << " dE "
0098 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0099 else
0100 edm::LogVerbatim("HitStudy") << "[" << i << "] " << ME0DetId(id) << " Trk " << track << " p " << p << " dE "
0101 << edep << " T " << tof << " Enetry " << entry << " Exit " << exit;
0102 ++i;
0103 }
0104 }
0105 }
0106 }
0107
0108
0109 DEFINE_FWK_MODULE(MuonSimHitDump);