Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-13 03:16:25

0001 #ifndef HitPixelLayersTrackSelection_h
0002 #define HitPixelLayersTrackSelection_h
0003 
0004 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0005 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
0006 
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/ConsumesCollector.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0012 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0013 
0014 /**
0015  Selector to select only tracking particles that leave hits in three pixel layers
0016  Additional selection done on pt, rapidity, impact parameter, min hits, pdg id, etc.
0017 
0018  Inspired by CommonTools.RecoAlgos.TrackingParticleSelector.h
0019 **/
0020 
0021 class HitPixelLayersTPSelector {
0022 public:
0023   // input collection type
0024   typedef TrackingParticleCollection collection;
0025 
0026   // output collection type
0027   typedef TrackingParticleRefVector container;
0028 
0029   // iterator over result collection type.
0030   typedef container::const_iterator const_iterator;
0031 
0032   // constructor from parameter set configurability
0033   HitPixelLayersTPSelector(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC)
0034       : tripletSeedOnly_(iConfig.getParameter<bool>("tripletSeedOnly")),
0035         ptMin_(iConfig.getParameter<double>("ptMin")),
0036         minRapidity_(iConfig.getParameter<double>("minRapidity")),
0037         maxRapidity_(iConfig.getParameter<double>("maxRapidity")),
0038         tip_(iConfig.getParameter<double>("tip")),
0039         lip_(iConfig.getParameter<double>("lip")),
0040         minHit_(iConfig.getParameter<int>("minHit")),
0041         signalOnly_(iConfig.getParameter<bool>("signalOnly")),
0042         chargedOnly_(iConfig.getParameter<bool>("chargedOnly")),
0043         primaryOnly_(iConfig.getParameter<bool>("primaryOnly")),
0044         tpStatusBased_(iConfig.getParameter<bool>("tpStatusBased")),
0045         pdgId_(iConfig.getParameter<std::vector<int> >("pdgId")),
0046         tTopoToken_(iC.esConsumes()){};
0047 
0048   // select object from a collection and
0049   // possibly event content
0050   void select(const edm::Handle<collection>& TPCH, const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0051     selected_.clear();
0052     //Retrieve tracker topology from geometry
0053     const TrackerTopology* tTopo = &iSetup.getData(tTopoToken_);
0054 
0055     const collection& tpc = *(TPCH.product());
0056 
0057     for (TrackingParticleCollection::size_type i = 0; i < tpc.size(); i++) {
0058       TrackingParticleRef tpr(TPCH, i);
0059 
0060       // quickly reject if it is from pile-up
0061       if (signalOnly_ && !(tpr->eventId().bunchCrossing() == 0 && tpr->eventId().event() == 0))
0062         continue;
0063       if (chargedOnly_ && tpr->charge() == 0)
0064         continue;  //select only if charge!=0
0065       if (tpStatusBased_ && primaryOnly_ && tpr->status() != 1)
0066         continue;  // TP status based sel primary
0067       if ((!tpStatusBased_) && primaryOnly_ && tpr->parentVertex()->nSourceTracks() != 0)
0068         continue;  // vertex based sel for primary
0069 
0070       // loop over specified PID values
0071       bool testId = false;
0072       unsigned int idSize = pdgId_.size();
0073       if (idSize == 0)
0074         testId = true;
0075       else
0076         for (unsigned int it = 0; it != idSize; ++it) {
0077           if (tpr->pdgId() == pdgId_[it])
0078             testId = true;
0079         }
0080 
0081       // selection criteria
0082       if (tpr->numberOfTrackerLayers() >= minHit_ && sqrt(tpr->momentum().perp2()) >= ptMin_ &&
0083           tpr->momentum().eta() >= minRapidity_ && tpr->momentum().eta() <= maxRapidity_ &&
0084           sqrt(tpr->vertex().perp2()) <= tip_ && fabs(tpr->vertex().z()) <= lip_ && testId) {
0085         if (tripletSeedOnly_ && !goodHitPattern(pixelHitPattern(tpr, tTopo)))
0086           continue;  //findable triplet seed
0087         selected_.push_back(tpr);
0088       }
0089     }
0090   }
0091 
0092   // return pixel layer hit pattern
0093   std::vector<bool> pixelHitPattern(const TrackingParticleRef& simTrack, const TrackerTopology* tTopo) {
0094     std::vector<bool> hitpattern(5, false);  // PXB 0,1,2  PXF 0,1
0095     // This currently will always return false, since we can no loger use the sim hits to check for triplets.  This would need to be fixed if we want to enable this feature, but it's not being used at the moment, since tripletSeedOnly is always set to False  - Matt Nguyen, 24/7/2013
0096 
0097     return hitpattern;
0098   }
0099 
0100   // test whether hit pattern would give a pixel triplet seed
0101   bool goodHitPattern(const std::vector<bool>& hitpattern) {
0102     if ((hitpattern[0] && hitpattern[1] && hitpattern[2]) || (hitpattern[0] && hitpattern[1] && hitpattern[3]) ||
0103         (hitpattern[0] && hitpattern[3] && hitpattern[4]))
0104       return true;
0105     else
0106       return false;
0107   }
0108 
0109   // iterators over selected objects: collection begin
0110   const_iterator begin() const { return selected_.begin(); }
0111 
0112   // iterators over selected objects: collection end
0113   const_iterator end() const { return selected_.end(); }
0114 
0115   // true if no object has been selected
0116   size_t size() const { return selected_.size(); }
0117 
0118   //private:
0119 
0120   container selected_;
0121   bool tripletSeedOnly_;
0122   double ptMin_;
0123   double minRapidity_;
0124   double maxRapidity_;
0125   double tip_;
0126   double lip_;
0127   int minHit_;
0128   bool signalOnly_;
0129   bool chargedOnly_;
0130   bool primaryOnly_;
0131   bool tpStatusBased_;
0132   std::vector<int> pdgId_;
0133   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0134 };
0135 
0136 #endif