Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:31

0001 // Author: Marco Rovere, marco.rovere@cern.ch
0002 // Date: 05/2019
0003 //
0004 #include <memory>  // unique_ptr
0005 
0006 #include "FWCore/Framework/interface/stream/EDProducer.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/Utilities/interface/ESGetToken.h"
0011 
0012 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
0013 #include "DataFormats/HGCalReco/interface/TICLLayerTile.h"
0014 
0015 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0016 
0017 class TICLLayerTileProducer : public edm::stream::EDProducer<> {
0018 public:
0019   explicit TICLLayerTileProducer(const edm::ParameterSet &ps);
0020   ~TICLLayerTileProducer() override {}
0021   void beginRun(edm::Run const &, edm::EventSetup const &) override;
0022   void produce(edm::Event &, const edm::EventSetup &) override;
0023   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0024 
0025 private:
0026   edm::EDGetTokenT<std::vector<reco::CaloCluster>> clusters_token_;
0027   edm::EDGetTokenT<std::vector<reco::CaloCluster>> clusters_HFNose_token_;
0028   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometry_token_;
0029   hgcal::RecHitTools rhtools_;
0030   std::string detector_;
0031   bool doNose_;
0032 };
0033 
0034 TICLLayerTileProducer::TICLLayerTileProducer(const edm::ParameterSet &ps)
0035     : detector_(ps.getParameter<std::string>("detector")) {
0036   geometry_token_ = esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>();
0037 
0038   doNose_ = (detector_ == "HFNose");
0039 
0040   if (doNose_) {
0041     clusters_HFNose_token_ =
0042         consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_HFNose_clusters"));
0043     produces<TICLLayerTilesHFNose>();
0044   } else {
0045     clusters_token_ = consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_clusters"));
0046     produces<TICLLayerTiles>();
0047   }
0048 }
0049 
0050 void TICLLayerTileProducer::beginRun(edm::Run const &, edm::EventSetup const &es) {
0051   edm::ESHandle<CaloGeometry> geom = es.getHandle(geometry_token_);
0052   rhtools_.setGeometry(*geom);
0053 }
0054 
0055 void TICLLayerTileProducer::produce(edm::Event &evt, const edm::EventSetup &) {
0056   std::unique_ptr<TICLLayerTilesHFNose> resultHFNose;
0057   std::unique_ptr<TICLLayerTiles> result;
0058   if (doNose_) {
0059     resultHFNose = std::make_unique<TICLLayerTilesHFNose>();
0060   } else {
0061     result = std::make_unique<TICLLayerTiles>();
0062   }
0063 
0064   edm::Handle<std::vector<reco::CaloCluster>> cluster_h;
0065   if (doNose_)
0066     evt.getByToken(clusters_HFNose_token_, cluster_h);
0067   else
0068     evt.getByToken(clusters_token_, cluster_h);
0069 
0070   const auto &layerClusters = *cluster_h;
0071   int lcId = 0;
0072   for (auto const &lc : layerClusters) {
0073     const auto firstHitDetId = lc.hitsAndFractions()[0].first;
0074     int layer = rhtools_.getLayerWithOffset(firstHitDetId) +
0075                 rhtools_.lastLayer(doNose_) * ((rhtools_.zside(firstHitDetId) + 1) >> 1) - 1;
0076 
0077     assert(layer >= 0);
0078 
0079     if (doNose_) {
0080       resultHFNose->fill(layer, lc.eta(), lc.phi(), lcId);
0081     } else {
0082       result->fill(layer, lc.eta(), lc.phi(), lcId);
0083       LogDebug("TICLLayerTileProducer") << "Adding layerClusterId: " << lcId << " into bin [eta,phi]: [ "
0084                                         << (*result)[layer].etaBin(lc.eta()) << ", "
0085                                         << (*result)[layer].phiBin(lc.phi()) << "] for layer: " << layer << std::endl;
0086     }
0087     lcId++;
0088   }
0089   if (doNose_)
0090     evt.put(std::move(resultHFNose));
0091   else
0092     evt.put(std::move(result));
0093 }
0094 
0095 void TICLLayerTileProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0096   edm::ParameterSetDescription desc;
0097   desc.add<std::string>("detector", "HGCAL");
0098   desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalMergeLayerClusters"));
0099   desc.add<edm::InputTag>("layer_HFNose_clusters", edm::InputTag("hgcalLayerClustersHFNose"));
0100   descriptions.add("ticlLayerTileProducer", desc);
0101 }
0102 
0103 #include "FWCore/Framework/interface/MakerMacros.h"
0104 DEFINE_FWK_MODULE(TICLLayerTileProducer);