Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-18 08:23:52

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(hitLab_,
0043                                       [this](const std::string& name) {
0044                                         return consumes<edm::PCaloHitContainer>(edm::InputTag{g4Label_, name});
0045                                       })},
0046       types_(ps.getParameter<std::vector<int>>("CollectionTypes")),
0047       maxEvent_(ps.getParameter<int>("MaxEvent")),
0048       kount_(0) {
0049   edm::LogVerbatim("HitStudy") << "Module Label: " << g4Label_ << "   with " << hitLab_.size()
0050                                << " collections and maxEvent = " << maxEvent_;
0051   for (unsigned int k = 0; k < hitLab_.size(); ++k)
0052     edm::LogVerbatim("HitStudy") << "[" << k << "] Type " << types_[k] << " Label " << hitLab_[k];
0053 }
0054 
0055 void EcalSimHitDump::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0056   edm::ParameterSetDescription desc;
0057   std::vector<std::string> coll = {"EcalHitsEB", "EcalHitsEE", "EcalHitsES"};
0058   std::vector<int> type = {0, 1, 2};
0059   desc.add<std::string>("ModuleLabel", "g4SimHits");
0060   desc.add<std::vector<std::string>>("HitCollections", coll);
0061   desc.add<std::vector<int>>("CollectionTypes", type);
0062   desc.add<int>("MaxEvent", 10);
0063   descriptions.add("ecalSimHitDump", desc);
0064 }
0065 
0066 void EcalSimHitDump::analyze(const edm::Event& e, const edm::EventSetup&) {
0067   ++kount_;
0068   edm::LogVerbatim("HitStudy") << "[" << kount_ << "] Run = " << e.id().run() << " Event = " << e.id().event();
0069 
0070   if ((kount_ <= maxEvent_) || (maxEvent_ <= 0)) {
0071     for (unsigned int k = 0; k < toksCalo_.size(); ++k) {
0072       const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(toksCalo_[k]);
0073       if (hitsCalo.isValid())
0074         edm::LogVerbatim("HitStudy") << "EcalSimHitDump: Input " << hitsCalo->size() << " hits of type " << types_[k];
0075       unsigned int i(0);
0076       for (auto const& hit : *hitsCalo) {
0077         double edep = hit.energy();
0078         double time = hit.time();
0079         unsigned int id = hit.id();
0080         if (types_[k] == 0)
0081           edm::LogVerbatim("HitStudy") << "[" << i << "] " << EBDetId(id) << " E" << edep << " T " << time;
0082         else if (types_[k] == 1)
0083           edm::LogVerbatim("HitStudy") << "[" << i << "] " << EEDetId(id) << " E" << edep << " T " << time;
0084         else
0085           edm::LogVerbatim("HitStudy") << "[" << i << "] " << ESDetId(id) << " E" << edep << " T " << time;
0086         ++i;
0087       }
0088     }
0089   }
0090 }
0091 
0092 //define this as a plug-in
0093 DEFINE_FWK_MODULE(EcalSimHitDump);