Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-18 09:15:18

0001 #ifndef RecoParticleFlow_PFClusterProducer_PFEcalBarrelRecHitCreator_h
0002 #define RecoParticleFlow_PFClusterProducer_PFEcalBarrelRecHitCreator_h
0003 
0004 #include "RecoParticleFlow/PFClusterProducer/interface/PFRecHitCreatorBase.h"
0005 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0006 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0007 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0008 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0009 
0010 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0011 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0012 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0013 
0014 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0015 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0016 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0017 #include "Geometry/CaloGeometry/interface/TruncatedPyramid.h"
0018 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0019 
0020 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0021 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
0022 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
0023 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
0024 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
0025 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0026 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
0027 
0028 class PFEcalBarrelRecHitCreator : public PFRecHitCreatorBase {
0029 public:
0030   PFEcalBarrelRecHitCreator(const edm::ParameterSet& iConfig, edm::ConsumesCollector& cc)
0031       : PFRecHitCreatorBase(iConfig, cc),
0032         recHitToken_(cc.consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("src"))),
0033         triggerTowerMap_(nullptr),
0034         geomToken_(cc.esConsumes()),
0035         towerToken_(cc.esConsumes<edm::Transition::BeginLuminosityBlock>()) {
0036     auto srF = iConfig.getParameter<edm::InputTag>("srFlags");
0037     if (not srF.label().empty())
0038       srFlagToken_ = cc.consumes<EBSrFlagCollection>(srF);
0039   }
0040 
0041   void importRecHits(std::unique_ptr<reco::PFRecHitCollection>& out,
0042                      std::unique_ptr<reco::PFRecHitCollection>& cleaned,
0043                      const edm::Event& iEvent,
0044                      const edm::EventSetup& iSetup) override {
0045     beginEvent(iEvent, iSetup);
0046 
0047     edm::Handle<EcalRecHitCollection> recHitHandle;
0048 
0049     edm::ESHandle<CaloGeometry> geoHandle = iSetup.getHandle(geomToken_);
0050 
0051     bool useSrF = false;
0052     if (not srFlagToken_.isUninitialized()) {
0053       iEvent.getByToken(srFlagToken_, srFlagHandle_);
0054       useSrF = true;
0055     }
0056 
0057     // get the ecal geometry
0058     const CaloSubdetectorGeometry* gTmp = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
0059 
0060     const EcalBarrelGeometry* ecalGeo = dynamic_cast<const EcalBarrelGeometry*>(gTmp);
0061 
0062     iEvent.getByToken(recHitToken_, recHitHandle);
0063     for (const auto& erh : *recHitHandle) {
0064       const DetId& detid = erh.detid();
0065       auto energy = erh.energy();
0066       auto time = erh.time();
0067       auto flags = erh.flagsBits();
0068       bool hi = (useSrF ? isHighInterest(detid) : true);
0069 
0070       const auto thisCell = ecalGeo->getGeometry(detid);
0071 
0072       // find rechit geometry
0073       if (!thisCell) {
0074         throw cms::Exception("PFEcalBarrelRecHitCreator") << "detid " << detid.rawId() << "not found in geometry";
0075       }
0076 
0077       out->emplace_back(thisCell, detid.rawId(), PFLayer::ECAL_BARREL, energy, flags);
0078 
0079       auto& rh = out->back();
0080 
0081       bool rcleaned = false;
0082       bool keep = true;
0083 
0084       //Apply Q tests
0085       for (const auto& qtest : qualityTests_) {
0086         if (!qtest->test(rh, erh, rcleaned, hi)) {
0087           keep = false;
0088         }
0089       }
0090 
0091       if (keep) {
0092         rh.setTime(time);
0093         rh.setDepth(1);
0094       } else {
0095         if (rcleaned)
0096           cleaned->push_back(std::move(out->back()));
0097         out->pop_back();
0098       }
0099     }
0100   }
0101 
0102   void init(const edm::EventSetup& es) override { triggerTowerMap_ = &es.getData(towerToken_); }
0103 
0104 protected:
0105   bool isHighInterest(const EBDetId& detid) {
0106     bool result = false;
0107     auto srf = srFlagHandle_->find(readOutUnitOf(detid));
0108     if (srf == srFlagHandle_->end())
0109       return false;
0110     else
0111       result = ((srf->value() & ~EcalSrFlag::SRF_FORCED_MASK) == EcalSrFlag::SRF_FULL);
0112     return result;
0113   }
0114 
0115   EcalTrigTowerDetId readOutUnitOf(const EBDetId& detid) const { return triggerTowerMap_->towerOf(detid); }
0116 
0117   edm::EDGetTokenT<EcalRecHitCollection> recHitToken_;
0118   edm::EDGetTokenT<EBSrFlagCollection> srFlagToken_;
0119 
0120   // ECAL trigger tower mapping
0121   const EcalTrigTowerConstituentsMap* triggerTowerMap_;
0122   // selective readout flags collection
0123   edm::Handle<EBSrFlagCollection> srFlagHandle_;
0124 
0125 private:
0126   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0127   edm::ESGetToken<EcalTrigTowerConstituentsMap, IdealGeometryRecord> towerToken_;
0128 };
0129 
0130 #endif