Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:32

0001 /** Compares HCAL RecHits to SimHit
0002 
0003   \Author Rick Wilkinson, Caltech
0004 */
0005 
0006 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "SimCalorimetry/CaloSimAlgos/interface/CaloHitAnalyzer.h"
0014 #include "SimCalorimetry/HcalSimAlgos/interface/HcalHitFilter.h"
0015 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameterMap.h"
0016 #include "SimCalorimetry/HcalSimAlgos/interface/ZDCHitFilter.h"
0017 
0018 #include <iostream>
0019 #include <string>
0020 
0021 class HcalHitAnalyzer : public edm::one::EDAnalyzer<> {
0022 public:
0023   explicit HcalHitAnalyzer(edm::ParameterSet const &conf);
0024   void analyze(edm::Event const &e, edm::EventSetup const &c) override;
0025 
0026 private:
0027   HcalSimParameterMap simParameterMap_;
0028   HBHEHitFilter hbheFilter_;
0029   HOHitFilter hoFilter_;
0030   HFHitFilter hfFilter_;
0031   ZDCHitFilter zdcFilter_;
0032   CaloHitAnalyzer hbheAnalyzer_;
0033   CaloHitAnalyzer hoAnalyzer_;
0034   CaloHitAnalyzer hfAnalyzer_;
0035   CaloHitAnalyzer zdcAnalyzer_;
0036 
0037   const edm::InputTag hbheRecHitCollectionTag_;
0038   const edm::InputTag hoRecHitCollectionTag_;
0039   const edm::InputTag hfRecHitCollectionTag_;
0040   const edm::EDGetTokenT<HBHERecHitCollection> hbheRecHitCollectionToken_;
0041   const edm::EDGetTokenT<HORecHitCollection> hoRecHitCollectionToken_;
0042   const edm::EDGetTokenT<HFRecHitCollection> hfRecHitCollectionToken_;
0043   const edm::EDGetTokenT<CrossingFrame<PCaloHit>> cfToken_;
0044   const edm::EDGetTokenT<CrossingFrame<PCaloHit>> zdccfToken_;
0045 };
0046 
0047 HcalHitAnalyzer::HcalHitAnalyzer(edm::ParameterSet const &conf)
0048     : simParameterMap_(conf),
0049       hbheFilter_(),
0050       hoFilter_(),
0051       hfFilter_(),
0052       zdcFilter_(),
0053       hbheAnalyzer_("HBHE", 1., &simParameterMap_, &hbheFilter_),
0054       hoAnalyzer_("HO", 1., &simParameterMap_, &hoFilter_),
0055       hfAnalyzer_("HF", 1., &simParameterMap_, &hfFilter_),
0056       zdcAnalyzer_("ZDC", 1., &simParameterMap_, &zdcFilter_),
0057       hbheRecHitCollectionTag_(conf.getParameter<edm::InputTag>("hbheRecHitCollectionTag")),
0058       hoRecHitCollectionTag_(conf.getParameter<edm::InputTag>("hoRecHitCollectionTag")),
0059       hfRecHitCollectionTag_(conf.getParameter<edm::InputTag>("hfRecHitCollectionTag")),
0060       hbheRecHitCollectionToken_(consumes(hbheRecHitCollectionTag_)),
0061       hoRecHitCollectionToken_(consumes(hoRecHitCollectionTag_)),
0062       hfRecHitCollectionToken_(consumes(hfRecHitCollectionTag_)),
0063       cfToken_(consumes(edm::InputTag("mix", "HcalHits"))),
0064       zdccfToken_(consumes(edm::InputTag("mix", "ZDCHits"))) {}
0065 
0066 namespace HcalHitAnalyzerImpl {
0067   template <class Collection>
0068   void analyze(edm::Event const &e, CaloHitAnalyzer &analyzer, edm::EDGetTokenT<Collection> const &token) {
0069     const edm::Handle<Collection> &recHits = e.getHandle(token);
0070     for (unsigned i = 0; i < recHits->size(); ++i) {
0071       analyzer.analyze((*recHits)[i].id().rawId(), (*recHits)[i].energy());
0072     }
0073   }
0074 }  // namespace HcalHitAnalyzerImpl
0075 
0076 void HcalHitAnalyzer::analyze(edm::Event const &e, edm::EventSetup const &c) {
0077   // Step A: Get Inputs
0078   const edm::Handle<CrossingFrame<PCaloHit>> &cf = e.getHandle(cfToken_);
0079   //const edm::Handle<CrossingFrame<PCaloHit>>& zdccf = e.getHandle(zdccfToken_);
0080 
0081   // test access to SimHits for HcalHits and ZDC hits
0082   std::unique_ptr<MixCollection<PCaloHit>> hits(new MixCollection<PCaloHit>(cf.product()));
0083   // std::unique_ptr<MixCollection<PCaloHit> > zdcHits(new MixCollection<PCaloHit>(zdccf.product()));
0084   hbheAnalyzer_.fillHits(*hits);
0085   // hoAnalyzer_.fillHits(*hits);
0086   // hfAnalyzer_.fillHits(*hits);
0087   // zdcAnalyzer_.fillHits(*hits);
0088   HcalHitAnalyzerImpl::analyze<HBHERecHitCollection>(e, hbheAnalyzer_, hbheRecHitCollectionToken_);
0089   HcalHitAnalyzerImpl::analyze<HORecHitCollection>(e, hoAnalyzer_, hoRecHitCollectionToken_);
0090   HcalHitAnalyzerImpl::analyze<HFRecHitCollection>(e, hfAnalyzer_, hfRecHitCollectionToken_);
0091   // HcalHitAnalyzerImpl::analyze<ZDCRecHitCollection>(e, zdcAnalyzer_);
0092 }
0093 
0094 #include "FWCore/Framework/interface/MakerMacros.h"
0095 
0096 DEFINE_FWK_MODULE(HcalHitAnalyzer);