Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:18

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/global/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/SiStripCluster/interface/SiStripCluster.h"
0008 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0009 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
0010 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
0011 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
0012 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0013 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0014 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
0015 #include "DataFormats/Common/interface/Handle.h"
0016 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0017 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0018 #include "DataFormats/Common/interface/DetSetVector.h"
0019 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0020 #include "DataFormats/Provenance/interface/ProductID.h"
0021 
0022 #include "DataFormats/TrackReco/interface/Track.h"
0023 #include "DataFormats/TrackerRecHit2D/interface/ClusterRemovalInfo.h"
0024 
0025 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0026 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0027 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0028 //
0029 // class decleration
0030 //
0031 
0032 class TopBottomClusterInfoProducer : public edm::global::EDProducer<> {
0033 public:
0034   TopBottomClusterInfoProducer(const edm::ParameterSet& iConfig);
0035   ~TopBottomClusterInfoProducer() override;
0036   void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0037 
0038 private:
0039   edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster> > pixelClustersOld_;
0040   edm::EDGetTokenT<edmNew::DetSetVector<SiPixelCluster> > pixelClustersNew_;
0041   edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > stripClustersOld_;
0042   edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > stripClustersNew_;
0043 };
0044 
0045 using namespace std;
0046 using namespace edm;
0047 using namespace reco;
0048 
0049 TopBottomClusterInfoProducer::TopBottomClusterInfoProducer(const ParameterSet& iConfig) {
0050   pixelClustersOld_ =
0051       consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<edm::InputTag>("stripClustersOld"));
0052   stripClustersOld_ =
0053       consumes<edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<edm::InputTag>("pixelClustersOld"));
0054   pixelClustersNew_ =
0055       consumes<edmNew::DetSetVector<SiPixelCluster> >(iConfig.getParameter<edm::InputTag>("stripClustersNew"));
0056   stripClustersNew_ =
0057       consumes<edmNew::DetSetVector<SiStripCluster> >(iConfig.getParameter<edm::InputTag>("pixelClustersNew"));
0058   produces<ClusterRemovalInfo>();
0059 }
0060 
0061 TopBottomClusterInfoProducer::~TopBottomClusterInfoProducer() {}
0062 
0063 void TopBottomClusterInfoProducer::produce(edm::StreamID, Event& iEvent, const EventSetup& iSetup) const {
0064   Handle<edmNew::DetSetVector<SiPixelCluster> > pixelClustersOld;
0065   iEvent.getByToken(pixelClustersOld_, pixelClustersOld);
0066   Handle<edmNew::DetSetVector<SiStripCluster> > stripClustersOld;
0067   iEvent.getByToken(stripClustersOld_, stripClustersOld);
0068 
0069   Handle<edmNew::DetSetVector<SiPixelCluster> > pixelClustersNew;
0070   iEvent.getByToken(pixelClustersNew_, pixelClustersNew);
0071   Handle<edmNew::DetSetVector<SiStripCluster> > stripClustersNew;
0072   iEvent.getByToken(stripClustersNew_, stripClustersNew);
0073 
0074   auto cri = std::make_unique<ClusterRemovalInfo>(pixelClustersOld, stripClustersOld);
0075   ClusterRemovalInfo::Indices& pixelInd = cri->pixelIndices();
0076   ClusterRemovalInfo::Indices& stripInd = cri->stripIndices();
0077   stripInd.reserve(stripClustersNew->size());
0078   pixelInd.reserve(pixelClustersNew->size());
0079 
0080   //const SiStripCluster * firstOffsetStripNew = & stripClustersNew->data().front();
0081   for (edmNew::DetSetVector<SiStripCluster>::const_iterator itdetNew = stripClustersNew->begin();
0082        itdetNew != stripClustersNew->end();
0083        ++itdetNew) {
0084     edmNew::DetSet<SiStripCluster> oldDSstripNew = *itdetNew;
0085     if (oldDSstripNew.empty())
0086       continue;  // skip empty detsets
0087     for (edmNew::DetSet<SiStripCluster>::const_iterator clNew = oldDSstripNew.begin(); clNew != oldDSstripNew.end();
0088          ++clNew) {
0089       uint16_t firstStripNew = clNew->firstStrip();
0090       uint32_t idStripNew = itdetNew->id();
0091       //uint32_t keyNew = ((&*clNew) - firstOffsetStripNew);
0092       //cout << "new strip index=" << keyNew << endl;
0093       uint32_t keyOld = 99999;
0094 
0095       const SiStripCluster* firstOffsetStripOld = &stripClustersOld->data().front();
0096       edmNew::DetSetVector<SiStripCluster>::const_iterator itdetOld = stripClustersOld->find(itdetNew->id());
0097       if (itdetOld != stripClustersOld->end()) {
0098         edmNew::DetSet<SiStripCluster> oldDSstripOld = *itdetOld;
0099         if (oldDSstripOld.empty())
0100           continue;  // skip empty detsets
0101         for (edmNew::DetSet<SiStripCluster>::const_iterator clOld = oldDSstripOld.begin(); clOld != oldDSstripOld.end();
0102              ++clOld) {
0103           uint16_t firstStripOld = clOld->firstStrip();
0104           uint32_t idStripOld = itdetOld->id();
0105           if (idStripNew == idStripOld && firstStripNew == firstStripOld) {
0106             keyOld = ((&*clOld) - firstOffsetStripOld);
0107             //cout << "old strip index=" << keyOld << endl;
0108             break;
0109           }
0110         }
0111       }
0112       //assert(keyOld!=99999);
0113       //cout << "push back strip index=" << keyOld << endl;
0114       stripInd.push_back(keyOld);
0115     }
0116   }
0117 
0118   //const SiPixelCluster * firstOffsetPixelNew = & pixelClustersNew->data().front();
0119   for (edmNew::DetSetVector<SiPixelCluster>::const_iterator itdetNew = pixelClustersNew->begin();
0120        itdetNew != pixelClustersNew->end();
0121        ++itdetNew) {
0122     edmNew::DetSet<SiPixelCluster> oldDSpixelNew = *itdetNew;
0123     if (oldDSpixelNew.empty())
0124       continue;  // skip empty detsets
0125     for (edmNew::DetSet<SiPixelCluster>::const_iterator clNew = oldDSpixelNew.begin(); clNew != oldDSpixelNew.end();
0126          ++clNew) {
0127       int minPixelRowNew = clNew->minPixelRow();
0128       //uint32_t keyNew = ((&*clNew) - firstOffsetPixelNew);
0129       //cout << "new pixel index=" << keyNew << endl;
0130       uint32_t keyOld = 99999;
0131 
0132       const SiPixelCluster* firstOffsetPixelOld = &pixelClustersOld->data().front();
0133       edmNew::DetSetVector<SiPixelCluster>::const_iterator itdetOld = pixelClustersOld->find(oldDSpixelNew.detId());
0134       if (itdetOld != pixelClustersOld->end()) {
0135         edmNew::DetSet<SiPixelCluster> oldDSpixelOld = *itdetOld;
0136         if (oldDSpixelOld.empty())
0137           continue;  // skip empty detsets
0138         for (edmNew::DetSet<SiPixelCluster>::const_iterator clOld = oldDSpixelOld.begin(); clOld != oldDSpixelOld.end();
0139              ++clOld) {
0140           int minPixelRowOld = clOld->minPixelRow();
0141           if (minPixelRowNew == minPixelRowOld) {
0142             keyOld = ((&*clOld) - firstOffsetPixelOld);
0143             //cout << "old pixel index=" << keyOld << endl;
0144             break;
0145           }
0146         }
0147       }
0148       assert(keyOld != 99999);
0149       //cout << "push back pixel index=" << keyOld << endl;
0150       pixelInd.push_back(keyOld);
0151     }
0152   }
0153 
0154   //cout << "pixelInd size" << pixelInd.size() << endl;
0155   //cout << "stripInd size" << stripInd.size() << endl;
0156 
0157   cri->setNewPixelClusters(
0158       edm::OrphanHandle<SiPixelClusterCollectionNew>(pixelClustersNew.product(), pixelClustersNew.id()));
0159   cri->setNewStripClusters(
0160       edm::OrphanHandle<edmNew::DetSetVector<SiStripCluster> >(stripClustersNew.product(), stripClustersNew.id()));
0161 
0162   iEvent.put(std::move(cri));
0163 }
0164 
0165 #include "FWCore/PluginManager/interface/ModuleDef.h"
0166 #include "FWCore/Framework/interface/MakerMacros.h"
0167 DEFINE_FWK_MODULE(TopBottomClusterInfoProducer);