Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:21:18

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0014 
0015 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
0016 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0017 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0018 
0019 #include <CLHEP/Units/GlobalPhysicalConstants.h>
0020 #include <CLHEP/Units/SystemOfUnits.h>
0021 
0022 #include <TH1F.h>
0023 
0024 #include <string>
0025 #include <vector>
0026 
0027 class ZDCSimHitStudy : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0028 public:
0029   ZDCSimHitStudy(const edm::ParameterSet &ps);
0030   ~ZDCSimHitStudy() override = default;
0031   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0032 
0033 protected:
0034   void beginJob() override;
0035   void endJob() override {}
0036   void analyze(const edm::Event &e, const edm::EventSetup &c) override;
0037 
0038   void analyzeHits(const std::vector<PCaloHit> &);
0039 
0040 private:
0041   const std::string g4Label_;
0042   const std::string hitLab_;
0043   const double maxEnergy_, tCut_;
0044   const bool verbose_;
0045   const edm::EDGetTokenT<edm::PCaloHitContainer> toks_calo_;
0046   TH1F *hit_, *eTot_, *eTotT_, *edep_, *time_, *indx_;
0047 };
0048 
0049 ZDCSimHitStudy::ZDCSimHitStudy(const edm::ParameterSet &ps)
0050     : g4Label_(ps.getParameter<std::string>("ModuleLabel")),
0051       hitLab_(ps.getParameter<std::string>("HitCollection")),
0052       maxEnergy_(ps.getParameter<double>("MaxEnergy")),
0053       tCut_(ps.getParameter<double>("TimeCut")),
0054       verbose_(ps.getParameter<bool>("Verbose")),
0055       toks_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag{g4Label_, hitLab_})) {
0056   usesResource(TFileService::kSharedResource);
0057 
0058   edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Module Label: " << g4Label_ << "   Hits: " << hitLab_
0059                                << "   MaxEnergy: " << maxEnergy_ << " time Cut " << tCut_;
0060 }
0061 
0062 void ZDCSimHitStudy::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0063   edm::ParameterSetDescription desc;
0064   desc.add<std::string>("ModuleLabel", "g4SimHits");
0065   desc.add<std::string>("HitCollection", "ZDCHITS");
0066   desc.add<double>("MaxEnergy", 50.0);
0067   desc.add<double>("TimeCut", 2000.0);
0068   desc.add<bool>("Verbose", false);
0069   descriptions.add("zdcSimHitStudy", desc);
0070 }
0071 
0072 void ZDCSimHitStudy::beginJob() {
0073   edm::Service<TFileService> tfile;
0074 
0075   if (!tfile.isAvailable())
0076     throw cms::Exception("BadConfig") << "TFileService unavailable: "
0077                                       << "please add it to config file";
0078   double ymax = maxEnergy_;
0079   hit_ = tfile->make<TH1F>("Hits", "Number of Hits", 100, 0., 100);
0080   edep_ = tfile->make<TH1F>("Edep", "Deposited Energy (GeV)", 1000, 0., ymax);
0081   eTot_ = tfile->make<TH1F>("ETot", "Total Energy in a time window (GeV)", 1000, 0., ymax);
0082   eTotT_ = tfile->make<TH1F>("ETotT", "Total Energy (GeV)", 1000, 0., ymax);
0083   time_ = tfile->make<TH1F>("Time", "Hit Time (ns)", 2000, 0., 2000);
0084   indx_ = tfile->make<TH1F>("Indx", "Hit ID", 100, 0., 100);
0085 }
0086 
0087 void ZDCSimHitStudy::analyze(const edm::Event &e, const edm::EventSetup &) {
0088   edm::LogVerbatim("HitStudy") << "ZDCSimHitStudy::Run = " << e.id().run() << " Event = " << e.id().event();
0089 
0090   const edm::Handle<edm::PCaloHitContainer> &hitsCalo = e.getHandle(toks_calo_);
0091   bool getHits = (hitsCalo.isValid());
0092   edm::LogVerbatim("HitStudy") << "HOSimHitStudy::Input flag " << hitLab_ << " getHits flag " << getHits;
0093 
0094   std::vector<PCaloHit> zdcHits;
0095   if (getHits) {
0096     zdcHits.insert(zdcHits.end(), hitsCalo->begin(), hitsCalo->end());
0097     unsigned int isiz = zdcHits.size();
0098     edm::LogVerbatim("HitStudy") << "ZDCSimHitStudy:: Hit buffer for " << hitLab_ << " has " << isiz << " hits";
0099   }
0100   analyzeHits(zdcHits);
0101 }
0102 
0103 void ZDCSimHitStudy::analyzeHits(const std::vector<PCaloHit> &zdcHits) {
0104   //initialize
0105   double etot(0), etotT(0);
0106   int nHit = zdcHits.size();
0107   for (int i = 0; i < nHit; i++) {
0108     double edep = zdcHits[i].energy();
0109     double time = zdcHits[i].time();
0110     uint32_t id = zdcHits[i].id();
0111     int indx = (id & 0xFF);
0112     etotT += edep;
0113     if (time < tCut_)
0114       etot += edep;
0115     if (verbose_)
0116       edm::LogVerbatim("HitStudy") << "ZDCSimHitStudy:: Hit " << i << " Section:" << HcalZDCDetId(id).section()
0117                                    << " zside:" << HcalZDCDetId(id).zside() << " depth:" << HcalZDCDetId(id).depth()
0118                                    << " channel:" << HcalZDCDetId(id).channel()
0119                                    << " dense:" << HcalZDCDetId(id).denseIndex() << " edep:" << edep
0120                                    << " time:" << time;
0121     time_->Fill(time);
0122     edep_->Fill(edep);
0123     indx_->Fill(indx);
0124   }
0125   eTot_->Fill(etot);
0126   eTotT_->Fill(etotT);
0127   hit_->Fill(nHit);
0128 
0129   if (verbose_)
0130     edm::LogVerbatim("HitStudy") << "ZDCSimHitStudy::analyzeHits: Hits in ZDC " << nHit << " Energy deposits " << etot
0131                                  << ":" << etotT;
0132 }
0133 
0134 //define this as a plug-in
0135 DEFINE_FWK_MODULE(ZDCSimHitStudy);