Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:39

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   clusters_HFNose_token_ =
0037       consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_HFNose_clusters"));
0038   clusters_token_ = consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_clusters"));
0039   geometry_token_ = esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>();
0040 
0041   doNose_ = (detector_ == "HFNose");
0042 
0043   if (doNose_)
0044     produces<TICLLayerTilesHFNose>();
0045   else
0046     produces<TICLLayerTiles>();
0047 }
0048 
0049 void TICLLayerTileProducer::beginRun(edm::Run const &, edm::EventSetup const &es) {
0050   edm::ESHandle<CaloGeometry> geom = es.getHandle(geometry_token_);
0051   rhtools_.setGeometry(*geom);
0052 }
0053 
0054 void TICLLayerTileProducer::produce(edm::Event &evt, const edm::EventSetup &) {
0055   auto result = std::make_unique<TICLLayerTiles>();
0056   auto resultHFNose = std::make_unique<TICLLayerTilesHFNose>();
0057 
0058   edm::Handle<std::vector<reco::CaloCluster>> cluster_h;
0059   if (doNose_)
0060     evt.getByToken(clusters_HFNose_token_, cluster_h);
0061   else
0062     evt.getByToken(clusters_token_, cluster_h);
0063 
0064   const auto &layerClusters = *cluster_h;
0065   int lcId = 0;
0066   for (auto const &lc : layerClusters) {
0067     const auto firstHitDetId = lc.hitsAndFractions()[0].first;
0068     int layer = rhtools_.getLayerWithOffset(firstHitDetId) +
0069                 rhtools_.lastLayer(doNose_) * ((rhtools_.zside(firstHitDetId) + 1) >> 1) - 1;
0070 
0071     assert(layer >= 0);
0072 
0073     if (doNose_)
0074       resultHFNose->fill(layer, lc.eta(), lc.phi(), lcId);
0075     else
0076       result->fill(layer, lc.eta(), lc.phi(), lcId);
0077     LogDebug("TICLLayerTileProducer") << "Adding layerClusterId: " << lcId << " into bin [eta,phi]: [ "
0078                                       << (*result)[layer].etaBin(lc.eta()) << ", " << (*result)[layer].phiBin(lc.phi())
0079                                       << "] for layer: " << layer << std::endl;
0080     lcId++;
0081   }
0082   if (doNose_)
0083     evt.put(std::move(resultHFNose));
0084   else
0085     evt.put(std::move(result));
0086 }
0087 
0088 void TICLLayerTileProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0089   edm::ParameterSetDescription desc;
0090   desc.add<std::string>("detector", "HGCAL");
0091   desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalLayerClusters"));
0092   desc.add<edm::InputTag>("layer_HFNose_clusters", edm::InputTag("hgcalLayerClustersHFNose"));
0093   descriptions.add("ticlLayerTileProducer", desc);
0094 }
0095 
0096 #include "FWCore/Framework/interface/MakerMacros.h"
0097 DEFINE_FWK_MODULE(TICLLayerTileProducer);