Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-16 01:13:29

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0008 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0009 
0010 #include "DataFormats/Common/interface/ValueMap.h"
0011 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0012 #include "DataFormats/Provenance/interface/ProductID.h"
0013 #include "DataFormats/Common/interface/ContainerMask.h"
0014 
0015 #include "DataFormats/DetId/interface/DetId.h"
0016 
0017 #include "DataFormats/TrackerRecHit2D/interface/ClusterRemovalInfo.h"
0018 
0019 #include "DataFormats/SiStripCluster/interface/SiStripClusterTools.h"
0020 #include "RecoLocalTracker/SiStripClusterizer/interface/ClusterChargeCut.h"
0021 
0022 namespace {
0023 
0024   class ClusterChargeMasker : public edm::stream::EDProducer<> {
0025   public:
0026     ClusterChargeMasker(const edm::ParameterSet& iConfig);
0027     ~ClusterChargeMasker() override {}
0028     void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0029 
0030   private:
0031     using PixelMaskContainer = edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>;
0032     using StripMaskContainer = edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>;
0033 
0034     bool mergeOld_;
0035     float minGoodStripCharge_;
0036 
0037     edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster>> pixelClusters_;
0038     edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster>> stripClusters_;
0039 
0040     edm::EDGetTokenT<PixelMaskContainer> oldPxlMaskToken_;
0041     edm::EDGetTokenT<StripMaskContainer> oldStrMaskToken_;
0042   };
0043 
0044   ClusterChargeMasker::ClusterChargeMasker(const edm::ParameterSet& iConfig)
0045       : mergeOld_(iConfig.exists("oldClusterRemovalInfo")), minGoodStripCharge_(clusterChargeCut(iConfig)) {
0046     produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster>>>();
0047     produces<edm::ContainerMask<edmNew::DetSetVector<SiStripCluster>>>();
0048 
0049     pixelClusters_ =
0050         consumes<edmNew::DetSetVector<SiPixelCluster>>(iConfig.getParameter<edm::InputTag>("pixelClusters"));
0051     stripClusters_ =
0052         consumes<edmNew::DetSetVector<SiStripCluster>>(iConfig.getParameter<edm::InputTag>("stripClusters"));
0053 
0054     if (mergeOld_) {
0055       oldPxlMaskToken_ = consumes<PixelMaskContainer>(iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo"));
0056       oldStrMaskToken_ = consumes<StripMaskContainer>(iConfig.getParameter<edm::InputTag>("oldClusterRemovalInfo"));
0057     }
0058   }
0059 
0060   void ClusterChargeMasker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0061     edm::Handle<edmNew::DetSetVector<SiPixelCluster>> pixelClusters;
0062     iEvent.getByToken(pixelClusters_, pixelClusters);
0063     edm::Handle<edmNew::DetSetVector<SiStripCluster>> stripClusters;
0064     iEvent.getByToken(stripClusters_, stripClusters);
0065 
0066     std::vector<bool> collectedStrips;
0067     std::vector<bool> collectedPixels;
0068 
0069     if (mergeOld_) {
0070       edm::Handle<PixelMaskContainer> oldPxlMask;
0071       edm::Handle<StripMaskContainer> oldStrMask;
0072       iEvent.getByToken(oldPxlMaskToken_, oldPxlMask);
0073       iEvent.getByToken(oldStrMaskToken_, oldStrMask);
0074       LogDebug("ClusterChargeMasker") << "to merge in, " << oldStrMask->size() << " strp and " << oldPxlMask->size()
0075                                       << " pxl";
0076       oldStrMask->copyMaskTo(collectedStrips);
0077       oldPxlMask->copyMaskTo(collectedPixels);
0078       assert(stripClusters->dataSize() >= collectedStrips.size());
0079       collectedStrips.resize(stripClusters->dataSize(), false);
0080     } else {
0081       collectedStrips.resize(stripClusters->dataSize(), false);
0082       collectedPixels.resize(pixelClusters->dataSize(), false);
0083     }
0084 
0085     auto const& clusters = stripClusters->data();
0086     for (auto const& item : stripClusters->ids()) {
0087       if (!item.isValid())
0088         continue;  // not umpacked  (hlt only)
0089 
0090       auto detid = item.id;
0091 
0092       for (int i = item.offset; i < item.offset + int(item.size); ++i) {
0093         auto clusCharge = siStripClusterTools::chargePerCM(detid, clusters[i]);
0094         if (clusCharge < minGoodStripCharge_)
0095           collectedStrips[i] = true;
0096       }
0097     }
0098 
0099     LogDebug("ClusterChargeMasker") << "total strip to skip: "
0100                                     << std::count(collectedStrips.begin(), collectedStrips.end(), true);
0101     // std::cout << "ClusterChargeMasker " <<"total strip to skip: "<<std::count(collectedStrips.begin(),collectedStrips.end(),true)
0102     //          << " for CCC " << minGoodStripCharge_ <<std::endl;
0103     iEvent.put(std::make_unique<StripMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiStripCluster>>(stripClusters),
0104                                                     collectedStrips));
0105 
0106     LogDebug("ClusterChargeMasker") << "total pxl to skip: "
0107                                     << std::count(collectedPixels.begin(), collectedPixels.end(), true);
0108     iEvent.put(std::make_unique<PixelMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiPixelCluster>>(pixelClusters),
0109                                                     collectedPixels));
0110   }
0111 
0112 }  // namespace
0113 
0114 #include "FWCore/PluginManager/interface/ModuleDef.h"
0115 #include "FWCore/Framework/interface/MakerMacros.h"
0116 DEFINE_FWK_MODULE(ClusterChargeMasker);