CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TTClusterAssociator< T > Class Template Reference

Plugin to create the MC truth for TTClusters. More...

#include <TTClusterAssociator.h>

Inheritance diagram for TTClusterAssociator< T >:
edm::stream::EDProducer<>

Public Member Functions

 TTClusterAssociator (const edm::ParameterSet &iConfig)
 Constructors. More...
 
 ~TTClusterAssociator () override
 Destructor. More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

void beginRun (const edm::Run &run, const edm::EventSetup &iSetup) override
 Mandatory methods. More...
 
void endRun (const edm::Run &run, const edm::EventSetup &iSetup) override
 End run. More...
 
template<>
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
More...
 
template<>
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 Implement the producer. More...
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 

Private Attributes

edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken_
 
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > thePixelDigiSimLinkHandle_
 Data members. More...
 
edm::ESHandle< TrackerGeometrytheTrackerGeometry_
 
edm::ESHandle< TrackerTopologytheTrackerTopology_
 
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken_
 
edm::Handle< std::vector< TrackingParticle > > trackingParticleHandle_
 
std::vector< edm::InputTagttClustersInputTags_
 
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > ttClustersTokens_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

template<typename T>
class TTClusterAssociator< T >

Plugin to create the MC truth for TTClusters.

After moving from SimDataFormats to DataFormats, the template structure of the class was maintained in order to accomodate any types other than PixelDigis in case there is such a need in the future.

Author
Nicola Pozzobon
Date
2013, Jul 19 (tidy up: Ian Tomalin, 2020)

Definition at line 44 of file TTClusterAssociator.h.

Constructor & Destructor Documentation

◆ TTClusterAssociator()

template<typename T >
TTClusterAssociator< T >::TTClusterAssociator ( const edm::ParameterSet iConfig)
explicit

Constructors.

Close class.

NOTE since pattern hit correlation must be performed within a stacked module, one must store Clusters in a proper way, providing easy access to them in a detector/member-wise way

Implementation of methods

Here, in the header file, the methods which do not depend on the specific type <T> that can fit the template. Other methods, with type-specific features, are implemented in the source file. Constructors

Definition at line 84 of file TTClusterAssociator.h.

84  {
86  consumes<edm::DetSetVector<PixelDigiSimLink> >(iConfig.getParameter<edm::InputTag>("digiSimLinks"));
87  tpToken_ = consumes<std::vector<TrackingParticle> >(iConfig.getParameter<edm::InputTag>("trackingParts"));
88 
89  ttClustersInputTags_ = iConfig.getParameter<std::vector<edm::InputTag> >("TTClusters");
90 
91  for (const auto& iTag : ttClustersInputTags_) {
92  ttClustersTokens_.push_back(consumes<edmNew::DetSetVector<TTCluster<T> > >(iTag));
93 
94  produces<TTClusterAssociationMap<T> >(iTag.instance());
95  }
96 }

References edm::ParameterSet::getParameter().

◆ ~TTClusterAssociator()

template<typename T >
TTClusterAssociator< T >::~TTClusterAssociator ( )
override

Destructor.

Definition at line 100 of file TTClusterAssociator.h.

100 {}

Member Function Documentation

◆ beginRun()

template<typename T >
void TTClusterAssociator< T >::beginRun ( const edm::Run run,
const edm::EventSetup iSetup 
)
overrideprivate

Mandatory methods.

Begin run.

Get the geometry

Print some information when loaded

Definition at line 104 of file TTClusterAssociator.h.

104  {
108 
110  edm::LogInfo("TTClusterAssociator< ") << templateNameFinder<T>() << " > loaded.";
111 }

References edm::EventSetup::get(), and get.

◆ endRun()

template<typename T >
void TTClusterAssociator< T >::endRun ( const edm::Run run,
const edm::EventSetup iSetup 
)
overrideprivate

End run.

Definition at line 115 of file TTClusterAssociator.h.

115 {}

◆ produce() [1/3]

template<>
void TTClusterAssociator< Ref_Phase2TrackerDigi_ >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
private


Here, in the source file, the methods which do depend on the specific type <T> that can fit the template.

Author
Nicola Pozzobon
Date
2013, Jul 19 Implement the producer

Exit if real data

Get the PixelDigiSimLink

Get the TrackingParticles

Preliminary task: map SimTracks by TrackingParticle Prepare the map

Loop over TrackingParticles

Make the pointer to the TrackingParticle

Get the EncodedEventId

Loop over SimTracks inside TrackingParticle

Use the unique SimTrack Id (which is SimTrack ID + EncodedEventId)

End of loop over TrackingParticles

Loop over InputTags to handle multiple collections

Prepare output

Get the Clusters already stored away

Prepare the necessary maps

Loop over the input Clusters

Get the DetSets of the Clusters

Make the reference to be put in the map

Prepare the maps wrt TTCluster

Get the PixelDigiSimLink Safety check added after new digitizer (Oct 2014)

Sensor is not found in DigiSimLink. Set MC truth to NULL for all hits in this sensor. Period.

Get the Digis and loop over them

No SimLink is found by definition Then store NULL MC truth for all the digis

Go to the next sensor

Get the Digis and loop over them

Loop over PixelDigiSimLink

Find the link and, if there's not, skip

Get SimTrack Id and type

Prepare the SimTrack Unique ID

Get the corresponding TrackingParticle

Store the TrackingParticle

Prepare the maps wrt TrackingParticle

Fill the auxiliary map

In case no TrackingParticle is found, store a NULL pointer

End of loop over PixelDigiSimLink

End of loop over all the hits composing the Cluster

Check that the cluster has a non-NULL TP pointer

In case no TrackingParticle is found at all, drop the map element

Use "erase by key"

End of loop over all the TTClusters of the event

Clean the maps that need cleaning Prepare the output map wrt TrackingParticle

Get the vector of references to TTCluster

Sort and remove duplicates

Put the maps in the association object

Put output in the event

End of loop over input tags

Definition at line 14 of file TTClusterAssociator.cc.

14  {
16  if (iEvent.isRealData())
17  return;
18 
21 
23 
25 
26  // const TrackerTopology* const tTopo = theTrackerTopology_.product();
27  const TrackerGeometry* const theTrackerGeom = theTrackerGeometry_.product();
28 
31  std::map<std::pair<unsigned int, EncodedEventId>, TrackingParticlePtr> simTrackUniqueToTPMap;
32 
33  if (not trackingParticleHandle_->empty()) {
35  for (unsigned int tpCnt = 0; tpCnt < trackingParticleHandle_->size(); tpCnt++) {
38 
40  EncodedEventId eventId = EncodedEventId(tempTPPtr->eventId());
41 
43  for (const auto& simTrack : tempTPPtr->g4Tracks()) {
45  simTrackUniqueToTPMap.emplace(std::make_pair(simTrack.trackId(), eventId), tempTPPtr);
46  }
47  }
48  }
49 
51 
52  int ncont1 = 0;
53 
54  for (const auto& iTag : ttClustersTokens_) {
56  auto associationMapForOutput = std::make_unique<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>();
57 
59  edm::Handle<TTClusterDetSetVec> TTClusterHandle;
60 
61  iEvent.getByToken(iTag, TTClusterHandle);
62 
64  std::map<TTClusterRef, std::vector<TrackingParticlePtr>> clusterToTrackingParticleVectorMap;
65  std::map<TrackingParticlePtr, std::vector<TTClusterRef>> trackingParticleToClusterVectorMap;
66 
68  for (const auto& gd : theTrackerGeom->dets()) {
69  DetId detid = gd->geographicalId();
70  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
71  continue; // only run on OT
72 
73  if (TTClusterHandle->find(detid) == TTClusterHandle->end())
74  continue;
75 
78 
79  for (auto contentIter = clusters.begin(); contentIter != clusters.end(); ++contentIter) {
81  TTClusterRef tempCluRef = edmNew::makeRefTo(TTClusterHandle, contentIter);
82 
84  if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) {
85  std::vector<TrackingParticlePtr> tpVector;
86  clusterToTrackingParticleVectorMap.emplace(tempCluRef, tpVector);
87  }
88 
94 
96  std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
97  for (unsigned int i = 0; i < theseHits.size(); i++) {
100  TrackingParticlePtr tempTPPtr;
101  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
102  }
103 
105  continue;
106  }
107 
108  edm::DetSet<PixelDigiSimLink> thisDigiSimLink = (*(thePixelDigiSimLinkHandle_))[detid];
110 
112  std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
113  for (unsigned int i = 0; i < theseHits.size(); i++) {
115  for (iterSimLink = thisDigiSimLink.data.begin(); iterSimLink != thisDigiSimLink.data.end(); iterSimLink++) {
117  if (static_cast<int>(iterSimLink->channel()) != static_cast<int>(theseHits.at(i)->channel()))
118  continue;
119 
121  unsigned int curSimTrkId = iterSimLink->SimTrackId();
122  EncodedEventId curSimEvId = iterSimLink->eventId();
123 
125  std::pair<unsigned int, EncodedEventId> thisUniqueId = std::make_pair(curSimTrkId, curSimEvId);
126 
128  if (simTrackUniqueToTPMap.find(thisUniqueId) != simTrackUniqueToTPMap.end()) {
129  TrackingParticlePtr thisTrackingParticle = simTrackUniqueToTPMap.find(thisUniqueId)->second;
130 
132  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(thisTrackingParticle);
133 
135  if (trackingParticleToClusterVectorMap.find(thisTrackingParticle) ==
136  trackingParticleToClusterVectorMap.end()) {
137  std::vector<TTClusterRef> clusterVector;
138  trackingParticleToClusterVectorMap.emplace(thisTrackingParticle, clusterVector);
139  }
140  trackingParticleToClusterVectorMap.find(thisTrackingParticle)
141  ->second.push_back(tempCluRef);
142  } else {
144 
145  TrackingParticlePtr tempTPPtr;
146  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
147  }
148  }
149  }
150 
152  const std::vector<TrackingParticlePtr>& theseClusterTrackingParticlePtrs =
153  clusterToTrackingParticleVectorMap.find(tempCluRef)->second;
154  bool allOfThemAreNull = true;
155  for (unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++) {
156  if (theseClusterTrackingParticlePtrs.at(tpi).isNull() == false)
157  allOfThemAreNull = false;
158  }
159 
160  if (allOfThemAreNull) {
162  clusterToTrackingParticleVectorMap.erase(tempCluRef);
163  }
164  }
165  }
166 
169  for (auto& p : trackingParticleToClusterVectorMap) {
171  std::vector<TTClusterRef>& tempVector = p.second;
172 
174  std::sort(tempVector.begin(), tempVector.end());
175  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
176  }
177 
179  associationMapForOutput->setTTClusterToTrackingParticlesMap(clusterToTrackingParticleVectorMap);
180  associationMapForOutput->setTrackingParticleToTTClustersMap(trackingParticleToClusterVectorMap);
181 
183  iEvent.put(std::move(associationMapForOutput), ttClustersInputTags_.at(ncont1).instance());
184 
185  ++ncont1;
186 
187  }
188 }

References bsc_activity_cfg::clusters, edm::DetSet< T >::data, TrackerGeometry::dets(), TrackingParticle::eventId(), TrackingParticle::g4Tracks(), mps_fire::i, iEvent, edmNew::makeRefTo(), eostools::move(), AlCaHLTBitMon_ParallelJobs::p, cscDigiValidation_cfi::simTrack, jetUpdater_cfi::sort, DetId::subdetId(), StripSubdetector::TID, StripSubdetector::TOB, and tier0::unique().

◆ produce() [2/3]

template<>
void TTClusterAssociator< Ref_Phase2TrackerDigi_ >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Implement the producer.

◆ produce() [3/3]

template<typename T >
void TTClusterAssociator< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Member Data Documentation

◆ digisimLinkToken_

template<typename T >
edm::EDGetTokenT<edm::DetSetVector<PixelDigiSimLink> > TTClusterAssociator< T >::digisimLinkToken_
private

Definition at line 61 of file TTClusterAssociator.h.

◆ thePixelDigiSimLinkHandle_

template<typename T >
edm::Handle<edm::DetSetVector<PixelDigiSimLink> > TTClusterAssociator< T >::thePixelDigiSimLinkHandle_
private

Data members.

Definition at line 56 of file TTClusterAssociator.h.

◆ theTrackerGeometry_

template<typename T >
edm::ESHandle<TrackerGeometry> TTClusterAssociator< T >::theTrackerGeometry_
private

Definition at line 65 of file TTClusterAssociator.h.

◆ theTrackerTopology_

template<typename T >
edm::ESHandle<TrackerTopology> TTClusterAssociator< T >::theTrackerTopology_
private

Definition at line 66 of file TTClusterAssociator.h.

◆ tpToken_

template<typename T >
edm::EDGetTokenT<std::vector<TrackingParticle> > TTClusterAssociator< T >::tpToken_
private

Definition at line 62 of file TTClusterAssociator.h.

◆ trackingParticleHandle_

template<typename T >
edm::Handle<std::vector<TrackingParticle> > TTClusterAssociator< T >::trackingParticleHandle_
private

Definition at line 57 of file TTClusterAssociator.h.

◆ ttClustersInputTags_

template<typename T >
std::vector<edm::InputTag> TTClusterAssociator< T >::ttClustersInputTags_
private

Definition at line 59 of file TTClusterAssociator.h.

◆ ttClustersTokens_

template<typename T >
std::vector<edm::EDGetTokenT<edmNew::DetSetVector<TTCluster<T> > > > TTClusterAssociator< T >::ttClustersTokens_
private

Definition at line 63 of file TTClusterAssociator.h.

edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
TTClusterAssociator::trackingParticleHandle_
edm::Handle< std::vector< TrackingParticle > > trackingParticleHandle_
Definition: TTClusterAssociator.h:57
cscDigiValidation_cfi.simTrack
simTrack
Definition: cscDigiValidation_cfi.py:29
mps_fire.i
i
Definition: mps_fire.py:428
edm::DetSetVector::end
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
edm::DetSet
Definition: DetSet.h:23
edmNew::makeRefTo
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
Definition: DetSetVectorNew.h:704
TTClusterAssociator::thePixelDigiSimLinkHandle_
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > thePixelDigiSimLinkHandle_
Data members.
Definition: TTClusterAssociator.h:56
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref
Definition: AssociativeIterator.h:58
EncodedEventId
Definition: EncodedEventId.h:11
DetId
Definition: DetId.h:17
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
TTClusterAssociator::ttClustersTokens_
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > ttClustersTokens_
Definition: TTClusterAssociator.h:63
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:16
edmNew::DetSet
Definition: DetSetNew.h:22
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
TTClusterAssociator::tpToken_
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken_
Definition: TTClusterAssociator.h:62
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
TTClusterAssociator::ttClustersInputTags_
std::vector< edm::InputTag > ttClustersInputTags_
Definition: TTClusterAssociator.h:59
edm::DetSetVector::find
iterator find(det_id_type id)
Definition: DetSetVector.h:264
iEvent
int iEvent
Definition: GenABIO.cc:224
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
get
#define get
edm::Ptr< TrackingParticle >
TTClusterAssociator::theTrackerTopology_
edm::ESHandle< TrackerTopology > theTrackerTopology_
Definition: TTClusterAssociator.h:66
edmNew::DetSetVector
Definition: DetSetNew.h:13
eostools.move
def move(src, dest)
Definition: eostools.py:511
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
edm::DetSet::data
collection_type data
Definition: DetSet.h:80
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TTCluster
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
TTClusterAssociator::theTrackerGeometry_
edm::ESHandle< TrackerGeometry > theTrackerGeometry_
Definition: TTClusterAssociator.h:65
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
edm::InputTag
Definition: InputTag.h:15
TTClusterAssociator::digisimLinkToken_
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken_
Definition: TTClusterAssociator.h:61
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
TrackerGeometry
Definition: TrackerGeometry.h:14
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31