File indexing completed on 2024-09-10 02:59:06
0001 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0002 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0003 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0004 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "FWCore/Utilities/interface/transform.h"
0015
0016 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0017 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0018
0019 #include <string>
0020 #include <vector>
0021
0022 class EcalSimHitDump : public edm::one::EDAnalyzer<> {
0023 public:
0024 EcalSimHitDump(const edm::ParameterSet& ps);
0025 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0026
0027 protected:
0028 void analyze(edm::Event const&, edm::EventSetup const&) override;
0029
0030 private:
0031 const std::string g4Label_;
0032 const std::vector<std::string> hitLab_;
0033 const std::vector<edm::EDGetTokenT<edm::PCaloHitContainer>> toksCalo_;
0034 const std::vector<int> types_;
0035 const int maxEvent_;
0036 int kount_;
0037 };
0038
0039 EcalSimHitDump::EcalSimHitDump(const edm::ParameterSet& ps)
0040 : g4Label_(ps.getParameter<std::string>("ModuleLabel")),
0041 hitLab_(ps.getParameter<std::vector<std::string>>("HitCollections")),
0042 toksCalo_{edm::vector_transform(
0043 hitLab_,
0044 [this](const std::string& name) { return consumes<edm::PCaloHitContainer>(edm::InputTag{g4Label_, name}); })},
0045 types_(ps.getParameter<std::vector<int>>("CollectionTypes")),
0046 maxEvent_(ps.getParameter<int>("MaxEvent")),
0047 kount_(0) {
0048 edm::LogVerbatim("HitStudy") << "Module Label: " << g4Label_ << " with " << hitLab_.size()
0049 << " collections and maxEvent = " << maxEvent_;
0050 for (unsigned int k = 0; k < hitLab_.size(); ++k)
0051 edm::LogVerbatim("HitStudy") << "[" << k << "] Type " << types_[k] << " Label " << hitLab_[k];
0052 }
0053
0054 void EcalSimHitDump::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0055 edm::ParameterSetDescription desc;
0056 std::vector<std::string> coll = {"EcalHitsEB", "EcalHitsEE", "EcalHitsES"};
0057 std::vector<int> type = {0, 1, 2};
0058 desc.add<std::string>("ModuleLabel", "g4SimHits");
0059 desc.add<std::vector<std::string>>("HitCollections", coll);
0060 desc.add<std::vector<int>>("CollectionTypes", type);
0061 desc.add<int>("MaxEvent", 10);
0062 descriptions.add("ecalSimHitDump", desc);
0063 }
0064
0065 void EcalSimHitDump::analyze(const edm::Event& e, const edm::EventSetup&) {
0066 ++kount_;
0067 edm::LogVerbatim("HitStudy") << "[" << kount_ << "] Run = " << e.id().run() << " Event = " << e.id().event();
0068
0069 if ((kount_ <= maxEvent_) || (maxEvent_ <= 0)) {
0070 for (unsigned int k = 0; k < toksCalo_.size(); ++k) {
0071 const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(toksCalo_[k]);
0072 if (hitsCalo.isValid())
0073 edm::LogVerbatim("HitStudy") << "EcalSimHitDump: Input " << hitsCalo->size() << " hits of type " << types_[k];
0074 unsigned int i(0);
0075 for (auto const& hit : *hitsCalo) {
0076 double edep = hit.energy();
0077 double time = hit.time();
0078 unsigned int id = hit.id();
0079 if (types_[k] == 0)
0080 edm::LogVerbatim("HitStudy") << "[" << i << "] " << EBDetId(id) << " E" << edep << " T " << time;
0081 else if (types_[k] == 1)
0082 edm::LogVerbatim("HitStudy") << "[" << i << "] " << EEDetId(id) << " E" << edep << " T " << time;
0083 else
0084 edm::LogVerbatim("HitStudy") << "[" << i << "] " << ESDetId(id) << " E" << edep << " T " << time;
0085 ++i;
0086 }
0087 }
0088 }
0089 }
0090
0091
0092 DEFINE_FWK_MODULE(EcalSimHitDump);