Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-16 00:33:27

0001 // system include files
0002 #include <iostream>
0003 #include <fstream>
0004 #include <vector>
0005 #include <map>
0006 #include <string>
0007 
0008 // user include files
0009 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0010 #include "DataFormats/ForwardDetId/interface/FastTimeDetId.h"
0011 
0012 #include "FWCore/Framework/interface/Frameworkfwd.h"
0013 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "FWCore/ServiceRegistry/interface/Service.h"
0021 
0022 #include "Geometry/HGCalCommonData/interface/FastTimeDDDConstants.h"
0023 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0024 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0025 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0026 
0027 // Root objects
0028 #include "TROOT.h"
0029 #include "TSystem.h"
0030 #include "TFile.h"
0031 #include "TH1.h"
0032 #include "TH2.h"
0033 
0034 class FTSimHitTest : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
0035 public:
0036   explicit FTSimHitTest(const edm::ParameterSet& ps);
0037   ~FTSimHitTest() override {}
0038 
0039   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0040 
0041 protected:
0042   void beginJob() override {}
0043   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0044   void endRun(edm::Run const&, edm::EventSetup const&) override {}
0045   void analyze(edm::Event const&, edm::EventSetup const&) override;
0046   void plotHits(const edm::Handle<edm::PSimHitContainer>&, const int);
0047 
0048 private:
0049   const std::string g4Label_, barrelHit_, endcapHit_;
0050   const edm::ESGetToken<FastTimeDDDConstants, IdealGeometryRecord> tok_ftg_;
0051   const FastTimeDDDConstants* ftcons_;
0052   edm::EDGetTokenT<edm::PSimHitContainer> tok_hitBarrel_, tok_hitEndcap_;
0053   TH1D *hsimE_[2], *hsimT_[2], *hcell_[2];
0054   TH2D *hsimP_[2], *hsimM_[2];
0055 };
0056 
0057 FTSimHitTest::FTSimHitTest(const edm::ParameterSet& ps)
0058     : g4Label_(ps.getUntrackedParameter<std::string>("ModuleLabel", "g4SimHits")),
0059       barrelHit_(ps.getUntrackedParameter<std::string>("HitCollection", "FastTimerHitsBarrel")),
0060       endcapHit_(ps.getUntrackedParameter<std::string>("HitCollection", "FastTimerHitsEndcap")),
0061       tok_ftg_(esConsumes<FastTimeDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{})),
0062       ftcons_(nullptr) {
0063   usesResource(TFileService::kSharedResource);
0064 
0065   tok_hitBarrel_ = consumes<edm::PSimHitContainer>(edm::InputTag(g4Label_, barrelHit_));
0066   tok_hitEndcap_ = consumes<edm::PSimHitContainer>(edm::InputTag(g4Label_, endcapHit_));
0067   edm::LogVerbatim("HGCalValidation") << "FTSimHitTest::i/p for Barrel SimHit:" << edm::InputTag(g4Label_, barrelHit_)
0068                                       << " and Endcap:" << edm::InputTag(g4Label_, endcapHit_);
0069 }
0070 
0071 void FTSimHitTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0072   edm::ParameterSetDescription desc;
0073   desc.addUntracked<std::string>("ModuleLabel", "g4SimHits");
0074   desc.addUntracked<std::string>("HitBarrelLabel", "FastTimerHitsBarrel");
0075   desc.addUntracked<std::string>("HitEndcapLabel", "FastTimerHitsEndcap");
0076   descriptions.add("ftSimHitTest", desc);
0077 }
0078 
0079 void FTSimHitTest::beginRun(edm::Run const&, edm::EventSetup const& es) {
0080   ftcons_ = &es.getData(tok_ftg_);
0081 
0082   //Histograms for Sim Hits
0083   std::string detector[2] = {"Barrel", "Endcap"};
0084   char name[80], title[120];
0085   edm::Service<TFileService> fs;
0086   for (unsigned int k = 0; k < 2; ++k) {
0087     sprintf(name, "SimHitEn%d", k);
0088     sprintf(title, "Sim Hit Energy (%s)", detector[k].c_str());
0089     hsimE_[k] = fs->make<TH1D>(name, title, 1000, 0.0, 1.0);
0090     sprintf(name, "SimHitTm%d", k);
0091     sprintf(title, "Sim Hit Time (%s)", detector[k].c_str());
0092     hsimT_[k] = fs->make<TH1D>(name, title, 1000, 0.0, 500.0);
0093     sprintf(name, "SimHitOc%d", k);
0094     sprintf(title, "# Cells with Sim Hit (%s)", detector[k].c_str());
0095     hcell_[k] = fs->make<TH1D>(name, title, 1000, 0.0, 1000.0);
0096     sprintf(name, "SimHitPos%d", k);
0097     sprintf(title, "Sim Hit Eta(z)-Phi (%s) for +z", detector[k].c_str());
0098     hsimP_[k] = fs->make<TH2D>(name, title, 200, 0, 400.0, 360, 0, 720.0);
0099     sprintf(name, "SimHitNeg%d", k);
0100     sprintf(title, "Sim Hit Eta(z)-Phi (%s) for -z", detector[k].c_str());
0101     hsimM_[k] = fs->make<TH2D>(name, title, 200, 0, 400.0, 360, 0, 720.0);
0102   }
0103 }
0104 
0105 void FTSimHitTest::analyze(const edm::Event& e, const edm::EventSetup&) {
0106   edm::LogVerbatim("HGCalValidation") << "FTSimHitTest:Run = " << e.id().run() << " Event = " << e.id().event();
0107 
0108   //Barrel
0109   edm::Handle<edm::PSimHitContainer> hits;
0110   e.getByToken(tok_hitBarrel_, hits);
0111   edm::LogVerbatim("HGCalValidation") << "FTSimHitTest.: PSimHitContainer for "
0112                                       << "Barrel obtained with flag " << hits.isValid();
0113   if (hits.isValid()) {
0114     edm::LogVerbatim("HGCalValidation") << "FTSimHitTest: PSimHit buffer for "
0115                                         << "Barrel " << hits->size();
0116     plotHits(hits, 0);
0117   }
0118 
0119   //Endcap
0120   e.getByToken(tok_hitEndcap_, hits);
0121   edm::LogVerbatim("HGCalValidation") << "FTSimHitTest.: PSimHitContainer for "
0122                                       << "Endcap obtained with flag " << hits.isValid();
0123   if (hits.isValid()) {
0124     edm::LogVerbatim("HGCalValidation") << "FTSimHitTest: PSimHit buffer for "
0125                                         << "Endcap " << hits->size();
0126     plotHits(hits, 1);
0127   }
0128 }
0129 
0130 void FTSimHitTest::plotHits(const edm::Handle<edm::PSimHitContainer>& hits, const int indx) {
0131   unsigned kount(0);
0132   std::vector<unsigned int> ids;
0133   for (edm::PSimHitContainer::const_iterator it = hits->begin(); it != hits->end(); ++it) {
0134     unsigned int id = it->detUnitId();
0135     double energy = it->energyLoss();
0136     double time = it->tof();
0137     int etaz = FastTimeDetId(id).ieta();
0138     int phi = FastTimeDetId(id).iphi();
0139     int zside = FastTimeDetId(id).zside();
0140     hsimE_[indx]->Fill(energy);
0141     hsimT_[indx]->Fill(time);
0142     if (zside > 0)
0143       hsimP_[indx]->Fill(etaz, phi);
0144     else
0145       hsimM_[indx]->Fill(etaz, phi);
0146     if (std::find(ids.begin(), ids.end(), id) == ids.end())
0147       ids.push_back(id);
0148     ++kount;
0149     edm::LogVerbatim("HGCalValidation") << "FTSimHitTest[" << kount << "] ID " << std::hex << " " << id << std::dec
0150                                         << " " << FastTimeDetId(id) << " E " << energy << " time " << time;
0151   }
0152   hcell_[indx]->Fill(double(ids.size()));
0153   edm::LogVerbatim("HGCalValidation") << "FTSimHitTest: " << ids.size() << " cells fired for type " << indx;
0154 }
0155 
0156 DEFINE_FWK_MODULE(FTSimHitTest);