Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-14 23:24:28

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/stream/EDProducer.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Utilities/interface/InputTag.h"
0006 
0007 #include "DataFormats/Phase2TrackerCluster/interface/Phase2TrackerCluster1D.h"
0008 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0009 
0010 #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h"
0011 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0012 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0013 #include "DataFormats/TrackerRecHit2D/interface/VectorHit.h"
0014 
0015 #include "DataFormats/Common/interface/Handle.h"
0016 #include "DataFormats/Common/interface/DetSetVector.h"
0017 #include "DataFormats/Common/interface/ValueMap.h"
0018 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0019 #include "DataFormats/Provenance/interface/ProductID.h"
0020 #include "DataFormats/Common/interface/ContainerMask.h"
0021 
0022 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0023 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0024 
0025 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0026 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0027 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0028 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
0029 
0030 //
0031 // class decleration
0032 //
0033 
0034 class SeedClusterRemoverPhase2 : public edm::stream::EDProducer<> {
0035 public:
0036   SeedClusterRemoverPhase2(const edm::ParameterSet &iConfig);
0037   void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
0038 
0039 private:
0040   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> const tTrackerGeom_;
0041   bool doOuterTracker_, doPixel_;
0042   bool mergeOld_;
0043   typedef edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > PixelMaskContainer;
0044   typedef edm::ContainerMask<edmNew::DetSetVector<Phase2TrackerCluster1D> > Phase2OTMaskContainer;
0045   edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster> > pixelClusters_;
0046   edm::EDGetTokenT<edmNew::DetSetVector<Phase2TrackerCluster1D> > phase2OTClusters_;
0047   edm::EDGetTokenT<PixelMaskContainer> oldPxlMaskToken_;
0048   edm::EDGetTokenT<Phase2OTMaskContainer> oldPh2OTMaskToken_;
0049   edm::EDGetTokenT<TrajectorySeedCollection> trajectories_;
0050 
0051   std::vector<uint8_t> pixels, OTs;                            // avoid unneed alloc/dealloc of this
0052   edm::ProductID pixelSourceProdID, outerTrackerSourceProdID;  // ProdIDs refs must point to (for consistency tests)
0053 
0054   inline void process(const TrackingRecHit *hit, float chi2, const TrackerGeometry *tg);
0055 
0056   std::vector<bool> collectedOuterTrackers_;
0057   std::vector<bool> collectedPixels_;
0058 };
0059 
0060 using namespace std;
0061 using namespace edm;
0062 
0063 SeedClusterRemoverPhase2::SeedClusterRemoverPhase2(const ParameterSet &iConfig)
0064     : tTrackerGeom_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord>()),
0065       doOuterTracker_(iConfig.existsAs<bool>("doOuterTracker") ? iConfig.getParameter<bool>("doOuterTracker") : true),
0066       doPixel_(iConfig.existsAs<bool>("doPixel") ? iConfig.getParameter<bool>("doPixel") : true),
0067       mergeOld_(iConfig.exists("oldClusterRemovalInfo")) {
0068   produces<edm::ContainerMask<edmNew::DetSetVector<SiPixelCluster> > >();
0069   produces<edm::ContainerMask<edmNew::DetSetVector<Phase2TrackerCluster1D> > >();
0070 
0071   trajectories_ = consumes<TrajectorySeedCollection>(iConfig.getParameter<InputTag>("trajectories"));
0072   if (doPixel_)
0073     pixelClusters_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<InputTag>("pixelClusters"));
0074   if (doOuterTracker_)
0075     phase2OTClusters_ =
0076         consumes<edmNew::DetSetVector<Phase2TrackerCluster1D> >(iConfig.getParameter<InputTag>("phase2OTClusters"));
0077   if (mergeOld_) {
0078     oldPxlMaskToken_ = consumes<PixelMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
0079     oldPh2OTMaskToken_ = consumes<Phase2OTMaskContainer>(iConfig.getParameter<InputTag>("oldClusterRemovalInfo"));
0080   }
0081 }
0082 
0083 void SeedClusterRemoverPhase2::process(const TrackingRecHit *hit, float chi2, const TrackerGeometry *tg) {
0084   DetId detid = hit->geographicalId();
0085   uint32_t subdet = detid.subdetId();
0086 
0087   assert(subdet > 0);
0088 
0089   const type_info &hitType = typeid(*hit);
0090   if (hitType == typeid(SiPixelRecHit)) {
0091     if (!doPixel_)
0092       return;
0093 
0094     const SiPixelRecHit *pixelHit = static_cast<const SiPixelRecHit *>(hit);
0095     SiPixelRecHit::ClusterRef cluster = pixelHit->cluster();
0096     LogDebug("SeedClusterRemoverPhase2") << "Plain Pixel RecHit in det " << detid.rawId();
0097 
0098     if (cluster.id() != pixelSourceProdID)
0099       throw cms::Exception("Inconsistent Data")
0100           << "SeedClusterRemoverPhase2: pixel cluster ref from Product ID = " << cluster.id()
0101           << " does not match with source cluster collection (ID = " << pixelSourceProdID << ")\n.";
0102 
0103     assert(cluster.id() == pixelSourceProdID);
0104 
0105     // mark as used
0106     pixels[cluster.key()] = false;
0107 
0108     assert(collectedPixels_.size() > cluster.key());
0109     collectedPixels_[cluster.key()] = true;
0110 
0111   } else if (hitType == typeid(Phase2TrackerRecHit1D)) {
0112     if (!doOuterTracker_)
0113       return;
0114 
0115     const Phase2TrackerRecHit1D *ph2OThit = static_cast<const Phase2TrackerRecHit1D *>(hit);
0116     LogDebug("SeedClusterRemoverPhase2") << "Plain Phase2TrackerRecHit1D in det " << detid.rawId();
0117 
0118     Phase2TrackerRecHit1D::CluRef cluster = ph2OThit->cluster();
0119     if (cluster.id() != outerTrackerSourceProdID)
0120       throw cms::Exception("Inconsistent Data")
0121           << "SeedClusterRemoverPhase2: strip cluster ref from Product ID = " << cluster.id()
0122           << " does not match with source cluster collection (ID = " << outerTrackerSourceProdID << ")\n.";
0123 
0124     assert(cluster.id() == outerTrackerSourceProdID);
0125 
0126     OTs[cluster.key()] = false;
0127     assert(collectedOuterTrackers_.size() > cluster.key());
0128     collectedOuterTrackers_[cluster.key()] = true;
0129 
0130   } else if (hitType == typeid(VectorHit)) {
0131     if (!doOuterTracker_)
0132       return;
0133 
0134     const VectorHit *vhit = static_cast<const VectorHit *>(hit);
0135     LogDebug("SeedClusterRemoverPhase2") << "Plain VectorHit in det " << detid.rawId();
0136 
0137     //lower cluster
0138     Phase2TrackerRecHit1D::CluRef cluster = vhit->lowerCluster();
0139     if (cluster.id() != outerTrackerSourceProdID)
0140       throw cms::Exception("Inconsistent Data")
0141           << "SeedClusterRemoverPhase2: strip cluster ref from Product ID = " << cluster.id()
0142           << " does not match with source cluster collection (ID = " << outerTrackerSourceProdID << ")\n.";
0143 
0144     OTs[cluster.key()] = false;
0145     assert(collectedOuterTrackers_.size() > cluster.key());
0146     collectedOuterTrackers_[cluster.key()] = true;
0147 
0148     // upper cluster
0149     cluster = vhit->upperCluster();
0150     if (cluster.id() != outerTrackerSourceProdID)
0151       throw cms::Exception("Inconsistent Data")
0152           << "SeedClusterRemoverPhase2: strip cluster ref from Product ID = " << cluster.id()
0153           << " does not match with source cluster collection (ID = " << outerTrackerSourceProdID << ")\n.";
0154 
0155     OTs[cluster.key()] = false;
0156     assert(collectedOuterTrackers_.size() > cluster.key());
0157     collectedOuterTrackers_[cluster.key()] = true;
0158   } else
0159     throw cms::Exception("NOT IMPLEMENTED")
0160         << "I received a hit that was neither SiPixelRecHit nor Phase2TrackerRecHit1D but " << hitType.name()
0161         << " on detid " << detid.rawId() << "\n";
0162 }
0163 
0164 void SeedClusterRemoverPhase2::produce(Event &iEvent, const EventSetup &iSetup) {
0165   ProductID pixelOldProdID, stripOldProdID;
0166 
0167   const auto &tgh = &iSetup.getData(tTrackerGeom_);
0168 
0169   Handle<edmNew::DetSetVector<SiPixelCluster> > pixelClusters;
0170   if (doPixel_) {
0171     iEvent.getByToken(pixelClusters_, pixelClusters);
0172     pixelSourceProdID = pixelClusters.id();
0173   }
0174   LogDebug("SeedClusterRemoverPhase2") << "Read pixel with id " << pixelSourceProdID << std::endl;
0175 
0176   Handle<edmNew::DetSetVector<Phase2TrackerCluster1D> > phase2OTClusters;
0177   if (doOuterTracker_) {
0178     iEvent.getByToken(phase2OTClusters_, phase2OTClusters);
0179     outerTrackerSourceProdID = phase2OTClusters.id();
0180   }
0181   LogDebug("SeedClusterRemoverPhase2") << "Read OT cluster with id " << outerTrackerSourceProdID << std::endl;
0182 
0183   if (doOuterTracker_) {
0184     OTs.resize(phase2OTClusters->dataSize());
0185     fill(OTs.begin(), OTs.end(), true);
0186   }
0187   if (doPixel_) {
0188     pixels.resize(pixelClusters->dataSize());
0189     fill(pixels.begin(), pixels.end(), true);
0190   }
0191   if (mergeOld_) {
0192     edm::Handle<PixelMaskContainer> oldPxlMask;
0193     edm::Handle<Phase2OTMaskContainer> oldPh2OTMask;
0194     iEvent.getByToken(oldPxlMaskToken_, oldPxlMask);
0195     iEvent.getByToken(oldPh2OTMaskToken_, oldPh2OTMask);
0196     LogDebug("SeedClusterRemoverPhase2") << "to merge in, " << oldPh2OTMask->size() << " strp and "
0197                                          << oldPxlMask->size() << " pxl";
0198     oldPh2OTMask->copyMaskTo(collectedOuterTrackers_);
0199     oldPxlMask->copyMaskTo(collectedPixels_);
0200     assert(phase2OTClusters->dataSize() >= collectedOuterTrackers_.size());
0201     collectedOuterTrackers_.resize(phase2OTClusters->dataSize(), false);  // for ondemand
0202   } else {
0203     collectedOuterTrackers_.resize(phase2OTClusters->dataSize(), false);
0204     collectedPixels_.resize(pixelClusters->dataSize(), false);
0205   }
0206 
0207   edm::Handle<TrajectorySeedCollection> seeds;
0208   iEvent.getByToken(trajectories_, seeds);
0209 
0210   for (auto const &seed : (*seeds)) {
0211     for (auto const &hit : seed.recHits()) {
0212       if (!hit.isValid())
0213         continue;
0214       process(&hit, 0., tgh);
0215     }
0216   }
0217 
0218   pixels.clear();
0219   OTs.clear();
0220 
0221   LogDebug("SeedClusterRemoverPhase2") << "total strip to skip: "
0222                                        << std::count(
0223                                               collectedOuterTrackers_.begin(), collectedOuterTrackers_.end(), true);
0224   iEvent.put(std::make_unique<Phase2OTMaskContainer>(
0225       edm::RefProd<edmNew::DetSetVector<Phase2TrackerCluster1D> >(phase2OTClusters), collectedOuterTrackers_));
0226 
0227   LogDebug("SeedClusterRemoverPhase2") << "total pxl to skip: "
0228                                        << std::count(collectedPixels_.begin(), collectedPixels_.end(), true);
0229   iEvent.put(std::make_unique<PixelMaskContainer>(edm::RefProd<edmNew::DetSetVector<SiPixelCluster> >(pixelClusters),
0230                                                   collectedPixels_));
0231 
0232   collectedOuterTrackers_.clear();
0233   collectedPixels_.clear();
0234 }
0235 
0236 #include "FWCore/PluginManager/interface/ModuleDef.h"
0237 #include "FWCore/Framework/interface/MakerMacros.h"
0238 DEFINE_FWK_MODULE(SeedClusterRemoverPhase2);