Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef RecoParticleFlow_PFClusterProducer_PFEcalEndcapRecHitCreator_h
0002 #define RecoParticleFlow_PFClusterProducer_PFEcalEndcapRecHitCreator_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/EcalMapping/interface/EcalElectronicsMapping.h"
0021 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0022 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0023 #include "Geometry/EcalAlgo/interface/EcalBarrelGeometry.h"
0024 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0025 #include "Geometry/CaloTopology/interface/EcalEndcapTopology.h"
0026 #include "Geometry/CaloTopology/interface/EcalBarrelTopology.h"
0027 #include "Geometry/CaloTopology/interface/EcalPreshowerTopology.h"
0028 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
0029 
0030 class PFEcalEndcapRecHitCreator : public PFRecHitCreatorBase {
0031 public:
0032   PFEcalEndcapRecHitCreator(const edm::ParameterSet& iConfig, edm::ConsumesCollector& cc)
0033       : PFRecHitCreatorBase(iConfig, cc),
0034         recHitToken_(cc.consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("src"))),
0035         elecMap_(nullptr),
0036         geomToken_(cc.esConsumes()),
0037         mappingToken_(cc.esConsumes<edm::Transition::BeginLuminosityBlock>()) {
0038     auto srF = iConfig.getParameter<edm::InputTag>("srFlags");
0039     if (not srF.label().empty())
0040       srFlagToken_ = cc.consumes<EESrFlagCollection>(srF);
0041   }
0042 
0043   void importRecHits(std::unique_ptr<reco::PFRecHitCollection>& out,
0044                      std::unique_ptr<reco::PFRecHitCollection>& cleaned,
0045                      const edm::Event& iEvent,
0046                      const edm::EventSetup& iSetup) override {
0047     beginEvent(iEvent, iSetup);
0048 
0049     edm::Handle<EcalRecHitCollection> recHitHandle;
0050 
0051     edm::ESHandle<CaloGeometry> geoHandle = iSetup.getHandle(geomToken_);
0052 
0053     bool useSrF = false;
0054     if (not srFlagToken_.isUninitialized()) {
0055       iEvent.getByToken(srFlagToken_, srFlagHandle_);
0056       useSrF = true;
0057     }
0058 
0059     // get the ecal geometry
0060     const CaloSubdetectorGeometry* gTmp = geoHandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
0061 
0062     const EcalEndcapGeometry* ecalGeo = dynamic_cast<const EcalEndcapGeometry*>(gTmp);
0063 
0064     iEvent.getByToken(recHitToken_, recHitHandle);
0065     for (const auto& erh : *recHitHandle) {
0066       const DetId& detid = erh.detid();
0067       auto energy = erh.energy();
0068       auto time = erh.time();
0069 
0070       bool hi = (useSrF ? isHighInterest(detid) : true);
0071 
0072       std::shared_ptr<const CaloCellGeometry> thisCell = ecalGeo->getGeometry(detid);
0073 
0074       // find rechit geometry
0075       if (!thisCell) {
0076         throw cms::Exception("PFEcalEndcapRecHitCreator") << "detid " << detid.rawId() << "not found in geometry";
0077       }
0078 
0079       out->emplace_back(thisCell, detid.rawId(), PFLayer::ECAL_ENDCAP, energy);
0080 
0081       auto& rh = out->back();
0082 
0083       bool rcleaned = false;
0084       bool keep = true;
0085 
0086       //Apply Q tests
0087       for (const auto& qtest : qualityTests_) {
0088         if (!qtest->test(rh, erh, rcleaned, hi)) {
0089           keep = false;
0090         }
0091       }
0092 
0093       if (keep) {
0094         rh.setTime(time);
0095         rh.setDepth(1);
0096       } else {
0097         if (rcleaned)
0098           cleaned->push_back(std::move(out->back()));
0099         out->pop_back();
0100       }
0101     }
0102   }
0103 
0104   void init(const edm::EventSetup& es) override { elecMap_ = &es.getData(mappingToken_); }
0105 
0106 protected:
0107   bool isHighInterest(const EEDetId& detid) {
0108     bool result = false;
0109     auto srf = srFlagHandle_->find(readOutUnitOf(detid));
0110     if (srf == srFlagHandle_->end())
0111       return false;
0112     else
0113       result = ((srf->value() & ~EcalSrFlag::SRF_FORCED_MASK) == EcalSrFlag::SRF_FULL);
0114     return result;
0115   }
0116 
0117   EcalScDetId readOutUnitOf(const EEDetId& detid) const {
0118     const EcalElectronicsId& EcalElecId = elecMap_->getElectronicsId(detid);
0119     int iDCC = EcalElecId.dccId();
0120     int iDccChan = EcalElecId.towerId();
0121     const bool ignoreSingle = true;
0122     const std::vector<EcalScDetId> id = elecMap_->getEcalScDetId(iDCC, iDccChan, ignoreSingle);
0123     return !id.empty() ? id[0] : EcalScDetId();
0124   }
0125 
0126   edm::EDGetTokenT<EcalRecHitCollection> recHitToken_;
0127   edm::EDGetTokenT<EESrFlagCollection> srFlagToken_;
0128 
0129   const EcalTrigTowerConstituentsMap* eTTmap_;
0130 
0131   // Ecal electronics/geometrical mapping
0132   const EcalElectronicsMapping* elecMap_;
0133   // selective readout flags collection
0134   edm::Handle<EESrFlagCollection> srFlagHandle_;
0135 
0136 private:
0137   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0138   edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> mappingToken_;
0139 };
0140 
0141 #endif