CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
template<>
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 

Private Attributes

edm::EDGetTokenT
< edm::DetSetVector
< PixelDigiSimLink > > 
digisimLinkToken_
 
edm::Handle< edm::DetSetVector
< PixelDigiSimLink > > 
thePixelDigiSimLinkHandle_
 Data members. More...
 
edm::ESGetToken
< TrackerGeometry,
TrackerDigiGeometryRecord
theTrackerGeometryToken_
 
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 43 of file TTClusterAssociator.h.

Constructor & Destructor Documentation

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 82 of file TTClusterAssociator.h.

References DeDxTools::esConsumes(), and edm::ParameterSet::getParameter().

82  {
84  consumes<edm::DetSetVector<PixelDigiSimLink> >(iConfig.getParameter<edm::InputTag>("digiSimLinks"));
85  tpToken_ = consumes<std::vector<TrackingParticle> >(iConfig.getParameter<edm::InputTag>("trackingParts"));
86 
87  ttClustersInputTags_ = iConfig.getParameter<std::vector<edm::InputTag> >("TTClusters");
88 
89  for (const auto& iTag : ttClustersInputTags_) {
90  ttClustersTokens_.push_back(consumes<edmNew::DetSetVector<TTCluster<T> > >(iTag));
91 
92  produces<TTClusterAssociationMap<T> >(iTag.instance());
93  }
94 
96 }
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > ttClustersTokens_
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken_
std::vector< edm::InputTag > ttClustersInputTags_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > theTrackerGeometryToken_
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
template<typename T >
TTClusterAssociator< T >::~TTClusterAssociator ( )
override

Destructor.

Definition at line 100 of file TTClusterAssociator.h.

100 {}

Member Function Documentation

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

Mandatory methods.

Begin run.

Print some information when loaded

Definition at line 104 of file TTClusterAssociator.h.

104  {
106  edm::LogInfo("TTClusterAssociator< ") << templateNameFinder<T>() << " > loaded.";
107 }
Log< level::Info, false > LogInfo
template<typename T >
void TTClusterAssociator< T >::endRun ( const edm::Run run,
const edm::EventSetup iSetup 
)
overrideprivate

End run.

Definition at line 111 of file TTClusterAssociator.h.

111 {}
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 19Implement 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.

References edmNew::DetSet< T >::begin(), HLT_FULL_cff::clusters, edm::DetSet< T >::data, TrackerGeometry::dets(), edmNew::DetSet< T >::end(), edm::Event::getByToken(), edm::EventSetup::getData(), mps_fire::i, edm::EventBase::isRealData(), edmNew::makeRefTo(), eostools::move(), AlCaHLTBitMon_ParallelJobs::p, edm::Event::put(), cscDigiValidation_cfi::simTrack, DetId::subdetId(), StripSubdetector::TID, StripSubdetector::TOB, and tier0::unique().

14  {
16  if (iEvent.isRealData())
17  return;
18 
21 
23 
25 
26  // const TrackerTopology* const tTopo = theTrackerTopology_.product();
27  const TrackerGeometry* const theTrackerGeom = &iSetup.getData(theTrackerGeometryToken_);
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 }
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)
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > ttClustersTokens_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
iterator find(det_id_type id)
Definition: DetSetVector.h:264
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken_
def unique
Definition: tier0.py:24
std::vector< edm::InputTag > ttClustersInputTags_
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
bool isRealData() const
Definition: EventBase.h:62
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > thePixelDigiSimLinkHandle_
Data members.
bool getData(T &iHolder) const
Definition: EventSetup.h:128
edm::Handle< std::vector< TrackingParticle > > trackingParticleHandle_
def move
Definition: eostools.py:511
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto TOB
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
Definition: DetId.h:17
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > theTrackerGeometryToken_
collection_type data
Definition: DetSet.h:80
iterator end()
Definition: DetSetNew.h:56
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken_
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
static constexpr auto TID
iterator begin()
Definition: DetSetNew.h:54
template<typename T >
void TTClusterAssociator< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate
template<>
void TTClusterAssociator< Ref_Phase2TrackerDigi_ >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Member Data Documentation

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

Definition at line 60 of file TTClusterAssociator.h.

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

Data members.

Definition at line 55 of file TTClusterAssociator.h.

template<typename T >
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> TTClusterAssociator< T >::theTrackerGeometryToken_
private

Definition at line 64 of file TTClusterAssociator.h.

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

Definition at line 61 of file TTClusterAssociator.h.

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

Definition at line 56 of file TTClusterAssociator.h.

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

Definition at line 58 of file TTClusterAssociator.h.

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

Definition at line 62 of file TTClusterAssociator.h.