Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-11 03:57:27

0001 #ifndef TrackerHitAssociator_h
0002 #define TrackerHitAssociator_h
0003 
0004 /* \class TrackerHitAssociator
0005  *
0006  ** Associates SimHits and RecHits based on information produced during
0007  *  digitisation (StripDigiSimLinks).
0008  *  The association works in both ways: from a SimHit to RecHits and
0009  *  from a RecHit to SimHits.
0010  *
0011  * \author Patrizia Azzi (INFN PD), Vincenzo Chiochia (Uni Zuerich)
0012  *
0013  * \version   1st version: April 2006. Add configurable switch: August 2006   
0014  *
0015  *
0016  ************************************************************/
0017 
0018 //#include <vector>
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "DataFormats/Common/interface/Handle.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/Framework/interface/ConsumesCollector.h"
0024 #include "FWCore/Utilities/interface/EDGetToken.h"
0025 
0026 //--- for SimHit
0027 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0028 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0029 
0030 #include "DataFormats/Common/interface/DetSetVector.h"
0031 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0032 #include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h"
0033 #include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
0034 
0035 //--- for RecHit
0036 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0037 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
0038 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0039 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
0040 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
0041 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
0042 #include "DataFormats/TrackerRecHit2D/interface/Phase2TrackerRecHit1D.h"
0043 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
0044 #include "DataFormats/TrackerRecHit2D/interface/SiTrackerMultiRecHit.h"
0045 #include "DataFormats/TrackerRecHit2D/interface/FastTrackerRecHit.h"
0046 
0047 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
0048 
0049 #include <string>
0050 #include <vector>
0051 
0052 typedef std::pair<uint32_t, EncodedEventId> SimHitIdpr;
0053 class TrackerHitAssociator {
0054 public:
0055   struct Config {
0056     Config() {}
0057     Config(const edm::ParameterSet& conf, edm::ConsumesCollector&& iC);
0058     Config(edm::ConsumesCollector&& iC);
0059     bool doPixel_, doStrip_, useOTph2_, doTrackAssoc_, assocHitbySimTrack_;
0060     edm::EDGetTokenT<edm::DetSetVector<StripDigiSimLink> > stripToken_;
0061     edm::EDGetTokenT<edm::DetSetVector<PixelDigiSimLink> > pixelToken_, ph2OTrToken_;
0062     std::vector<edm::EDGetTokenT<CrossingFrame<PSimHit> > > cfTokens_;
0063     std::vector<edm::EDGetTokenT<std::vector<PSimHit> > > simHitTokens_;
0064   };
0065 
0066   // The constructor supporting the consumes interface and tokens
0067   TrackerHitAssociator(const edm::Event& e, const Config& config);
0068 
0069   // Destructor
0070   virtual ~TrackerHitAssociator() {}
0071 
0072   typedef std::pair<unsigned int, unsigned int> simhitAddr, subDetTofBin;
0073   typedef unsigned int simHitCollectionID;
0074 
0075   std::vector<PSimHit> associateHit(const TrackingRecHit& thit) const;
0076   //for PU events
0077   std::vector<SimHitIdpr> associateHitId(const TrackingRecHit& thit) const;
0078   void associateHitId(const TrackingRecHit& thit,
0079                       std::vector<SimHitIdpr>& simhitid,
0080                       std::vector<simhitAddr>* simhitCFPos = nullptr) const;
0081   template <typename T>
0082   void associateSiStripRecHit(const T* simplerechit,
0083                               std::vector<SimHitIdpr>& simtrackid,
0084                               std::vector<simhitAddr>* simhitCFPos = nullptr) const;
0085 
0086   // Method for obtaining simTracks and simHits from a cluster
0087   void associateCluster(const SiStripCluster* clust,
0088                         const DetId& detid,
0089                         std::vector<SimHitIdpr>& simtrackid,
0090                         std::vector<PSimHit>& simhit) const;
0091 
0092   // Obtain simTracks, and optionally simHit addresses, from a cluster
0093   void associateSimpleRecHitCluster(const SiStripCluster* clust,
0094                                     const DetId& detid,
0095                                     std::vector<SimHitIdpr>& simtrackid,
0096                                     std::vector<simhitAddr>* simhitCFPos = nullptr) const;
0097 
0098   std::vector<SimHitIdpr> associateMatchedRecHit(const SiStripMatchedRecHit2D* matchedrechit,
0099                                                  std::vector<simhitAddr>* simhitCFPos = nullptr) const;
0100   std::vector<SimHitIdpr> associateProjectedRecHit(const ProjectedSiStripRecHit2D* projectedrechit,
0101                                                    std::vector<simhitAddr>* simhitCFPos = nullptr) const;
0102   void associatePhase2TrackerRecHit(const Phase2TrackerRecHit1D* rechit,
0103                                     std::vector<SimHitIdpr>& simtrackid,
0104                                     std::vector<simhitAddr>* simhitCFPos = nullptr) const;
0105   void associatePixelRecHit(const SiPixelRecHit* pixelrechit,
0106                             std::vector<SimHitIdpr>& simtrackid,
0107                             std::vector<simhitAddr>* simhitCFPos = nullptr) const;
0108   std::vector<SimHitIdpr> associateFastRecHit(const FastTrackerRecHit* rechit) const;
0109   std::vector<SimHitIdpr> associateMultiRecHitId(const SiTrackerMultiRecHit* multirechit,
0110                                                  std::vector<simhitAddr>* simhitCFPos = nullptr) const;
0111   std::vector<PSimHit> associateMultiRecHit(const SiTrackerMultiRecHit* multirechit) const;
0112 
0113   typedef std::map<unsigned int, std::vector<PSimHit> > simhit_map;
0114   simhit_map SimHitMap;
0115   typedef std::map<subDetTofBin, unsigned int> simhit_collectionMap;
0116   simhit_collectionMap SimHitCollMap;
0117 
0118 private:
0119   typedef std::vector<std::string> vstring;
0120 
0121   void makeMaps(const edm::Event& theEvent, const Config& config);
0122   inline std::string printDetBnchEvtTrk(const DetId& detid,
0123                                         const uint32_t& detID,
0124                                         std::vector<SimHitIdpr>& simtrackid) const;
0125   edm::Handle<edm::DetSetVector<StripDigiSimLink> > stripdigisimlink;
0126   edm::Handle<edm::DetSetVector<PixelDigiSimLink> > pixeldigisimlink;
0127   edm::Handle<edm::DetSetVector<PixelDigiSimLink> > ph2trackerdigisimlink;
0128   bool doPixel_, doStrip_, useOTph2_, doTrackAssoc_, assocHitbySimTrack_;
0129 };
0130 
0131 #endif