Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-04 02:53:15

0001 /** Compares RecHits to SimHit
0002 
0003   \Author P. Katsas, Univ. of Athens
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/CastorSim/interface/CastorHitFilter.h"
0015 #include "SimCalorimetry/CastorSim/interface/CastorSimParameterMap.h"
0016 
0017 #include <iostream>
0018 #include <string>
0019 
0020 class CastorHitAnalyzer : public edm::one::EDAnalyzer<> {
0021 public:
0022   explicit CastorHitAnalyzer(edm::ParameterSet const &conf);
0023   void analyze(edm::Event const &e, edm::EventSetup const &c) override;
0024 
0025 private:
0026   std::string hitReadoutName_;
0027   CastorSimParameterMap simParameterMap_;
0028   CastorHitFilter castorFilter_;
0029   CaloHitAnalyzer castorAnalyzer_;
0030   const edm::EDGetTokenT<CastorRecHitCollection> castorRecHitToken_;
0031   const edm::EDGetTokenT<CrossingFrame<PCaloHit>> castorcfToken_;
0032 };
0033 
0034 CastorHitAnalyzer::CastorHitAnalyzer(edm::ParameterSet const &conf)
0035     : hitReadoutName_("CastorHits"),
0036       simParameterMap_(),
0037       castorFilter_(),
0038       castorAnalyzer_("CASTOR", 1., &simParameterMap_, &castorFilter_),
0039       castorRecHitToken_(
0040           consumes<CastorRecHitCollection>(conf.getParameter<edm::InputTag>("castorRecHitCollectionTag"))),
0041       castorcfToken_(consumes<CrossingFrame<PCaloHit>>(edm::InputTag("mix", "g4SimHitsCastorFI"))) {}
0042 
0043 namespace CastorHitAnalyzerImpl {
0044   template <class Collection>
0045   void analyze(edm::Event const &e, CaloHitAnalyzer &analyzer, const edm::EDGetTokenT<Collection> &token) {
0046     const edm::Handle<Collection> &recHits = e.getHandle(token);
0047     if (!recHits.isValid()) {
0048       edm::LogError("CastorHitAnalyzer") << "Could not find Castor RecHitContainer ";
0049     } else {
0050       for (unsigned i = 0; i < recHits->size(); ++i) {
0051         analyzer.analyze((*recHits)[i].id().rawId(), (*recHits)[i].energy());
0052       }
0053     }
0054   }
0055 }  // namespace CastorHitAnalyzerImpl
0056 
0057 void CastorHitAnalyzer::analyze(edm::Event const &e, edm::EventSetup const &c) {
0058   const edm::Handle<CrossingFrame<PCaloHit>> &castorcf = e.getHandle(castorcfToken_);
0059 
0060   // access to SimHits
0061   std::unique_ptr<MixCollection<PCaloHit>> hits(new MixCollection<PCaloHit>(castorcf.product()));
0062   castorAnalyzer_.fillHits(*hits);
0063   CastorHitAnalyzerImpl::analyze<CastorRecHitCollection>(e, castorAnalyzer_, castorRecHitToken_);
0064 }
0065 
0066 #include "FWCore/Framework/interface/MakerMacros.h"
0067 
0068 DEFINE_FWK_MODULE(CastorHitAnalyzer);