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
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

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<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache 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

Definition at line 43 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 87 of file TTClusterAssociator.h.

87  {
89  consumes<edm::DetSetVector<PixelDigiSimLink> >(iConfig.getParameter<edm::InputTag>("digiSimLinks"));
90  tpToken = consumes<std::vector<TrackingParticle> >(iConfig.getParameter<edm::InputTag>("trackingParts"));
91 
92  TTClustersInputTags = iConfig.getParameter<std::vector<edm::InputTag> >("TTClusters");
93 
94  for (auto iTag = TTClustersInputTags.begin(); iTag != TTClustersInputTags.end(); iTag++) {
95  TTClustersTokens.push_back(consumes<edmNew::DetSetVector<TTCluster<T> > >(*iTag));
96 
97  produces<TTClusterAssociationMap<T> >((*iTag).instance());
98  }
99 }

References edm::ParameterSet::getParameter().

◆ ~TTClusterAssociator()

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

Destructor.

Definition at line 103 of file TTClusterAssociator.h.

103 {}

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

107  {
111 
113  edm::LogInfo("TTClusterAssociator< ") << templateNameFinder<T>() << " > loaded.";
114 }

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

118 {}

◆ 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

Build 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>, edm::Ptr<TrackingParticle>> simTrackUniqueToTPMap;
32  simTrackUniqueToTPMap.clear();
33 
34  if (!TrackingParticleHandle->empty()) {
36  unsigned int tpCnt = 0;
37  std::vector<TrackingParticle>::const_iterator iterTPart;
38  for (iterTPart = TrackingParticleHandle->begin(); iterTPart != TrackingParticleHandle->end(); ++iterTPart) {
41 
43  EncodedEventId eventId = EncodedEventId(tempTPPtr->eventId());
44 
46  std::vector<SimTrack>::const_iterator iterSimTrack;
47  for (iterSimTrack = tempTPPtr->g4Tracks().begin(); iterSimTrack != tempTPPtr->g4Tracks().end(); ++iterSimTrack) {
49  std::pair<unsigned int, EncodedEventId> simTrackUniqueId(iterSimTrack->trackId(), eventId);
50  simTrackUniqueToTPMap.insert(std::make_pair(simTrackUniqueId, tempTPPtr));
51  }
52  }
53  }
54 
56 
57  int ncont1 = 0;
58 
59  for (auto iTag = TTClustersTokens.begin(); iTag != TTClustersTokens.end(); iTag++) {
61  auto associationMapForOutput = std::make_unique<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>();
62 
65 
66  iEvent.getByToken(*iTag, TTClusterHandle);
67 
69  std::map<edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>, TTCluster<Ref_Phase2TrackerDigi_>>,
70  std::vector<edm::Ptr<TrackingParticle>>>
71  clusterToTrackingParticleVectorMap;
72  std::map<edm::Ptr<TrackingParticle>,
73  std::vector<
75  trackingParticleToClusterVectorMap;
76  clusterToTrackingParticleVectorMap.clear();
77  trackingParticleToClusterVectorMap.clear();
78 
80  for (auto gd = theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++) {
81  DetId detid = (*gd)->geographicalId();
82  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
83  continue; // only run on OT
84 
85  if (TTClusterHandle->find(detid) == TTClusterHandle->end())
86  continue;
87 
90 
91  for (auto contentIter = clusters.begin(); contentIter != clusters.end(); ++contentIter) {
94  edmNew::makeRefTo(TTClusterHandle, contentIter);
95 
97  if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) {
98  std::vector<edm::Ptr<TrackingParticle>> tpVector;
99  tpVector.clear();
100  clusterToTrackingParticleVectorMap.insert(std::make_pair(tempCluRef, tpVector));
101  }
102 
105  if (thePixelDigiSimLinkHandle->find(detid) == thePixelDigiSimLinkHandle->end()) {
108 
110  std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
111  for (unsigned int i = 0; i < theseHits.size(); i++) {
114  edm::Ptr<TrackingParticle> tempTPPtr; // = new edm::Ptr< TrackingParticle >();
115  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
116  }
117 
119  continue;
120  }
121 
122  edm::DetSet<PixelDigiSimLink> thisDigiSimLink = (*(thePixelDigiSimLinkHandle))[detid];
124 
126  std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
127  for (unsigned int i = 0; i < theseHits.size(); i++) {
129  for (iterSimLink = thisDigiSimLink.data.begin(); iterSimLink != thisDigiSimLink.data.end(); iterSimLink++) {
131  if (static_cast<int>(iterSimLink->channel()) != static_cast<int>(theseHits.at(i)->channel()))
132  continue;
133 
135  unsigned int curSimTrkId = iterSimLink->SimTrackId();
136  EncodedEventId curSimEvId = iterSimLink->eventId();
137 
139  std::pair<unsigned int, EncodedEventId> thisUniqueId = std::make_pair(curSimTrkId, curSimEvId);
140 
142  if (simTrackUniqueToTPMap.find(thisUniqueId) != simTrackUniqueToTPMap.end()) {
143  edm::Ptr<TrackingParticle> thisTrackingParticle = simTrackUniqueToTPMap.find(thisUniqueId)->second;
144 
146  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(thisTrackingParticle);
147 
149  if (trackingParticleToClusterVectorMap.find(thisTrackingParticle) ==
150  trackingParticleToClusterVectorMap.end()) {
151  std::vector<
153  clusterVector;
154  clusterVector.clear();
155  trackingParticleToClusterVectorMap.insert(std::make_pair(thisTrackingParticle, clusterVector));
156  }
157  trackingParticleToClusterVectorMap.find(thisTrackingParticle)
158  ->second.push_back(tempCluRef);
159  } else {
161 
162  edm::Ptr<TrackingParticle> tempTPPtr; // = new edm::Ptr< TrackingParticle >();
163  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
164  }
165  }
166  }
167 
169  std::vector<edm::Ptr<TrackingParticle>> theseClusterTrackingParticlePtrs =
170  clusterToTrackingParticleVectorMap.find(tempCluRef)->second;
171  bool allOfThemAreNull = true;
172  for (unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++) {
173  if (theseClusterTrackingParticlePtrs.at(tpi).isNull() == false)
174  allOfThemAreNull = false;
175  }
176 
177  if (allOfThemAreNull) {
179  clusterToTrackingParticleVectorMap.erase(tempCluRef);
180  }
181  }
182  }
183 
186  std::map<edm::Ptr<TrackingParticle>,
187  std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>,
188  TTCluster<Ref_Phase2TrackerDigi_>>>>::iterator iterMapToClean;
189  for (iterMapToClean = trackingParticleToClusterVectorMap.begin();
190  iterMapToClean != trackingParticleToClusterVectorMap.end();
191  ++iterMapToClean) {
193  std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>, TTCluster<Ref_Phase2TrackerDigi_>>>
194  tempVector = iterMapToClean->second;
195 
197  std::sort(tempVector.begin(), tempVector.end());
198  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
199  iterMapToClean->second = tempVector;
200  }
201 
203  associationMapForOutput->setTTClusterToTrackingParticlesMap(clusterToTrackingParticleVectorMap);
204  associationMapForOutput->setTrackingParticleToTTClustersMap(trackingParticleToClusterVectorMap);
205 
207  // iEvent.put( associationMapForOutput, (*iTag).instance() );
208  iEvent.put(std::move(associationMapForOutput), TTClustersInputTags.at(ncont1).instance());
209 
210  ++ncont1;
211 
212  }
213 }

References bsc_activity_cfg::clusters, edm::DetSet< T >::data, TrackerGeometry::dets(), TrackingParticle::eventId(), TrackingParticle::g4Tracks(), mps_fire::i, iEvent, edmNew::makeRefTo(), eostools::move(), 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 60 of file TTClusterAssociator.h.

◆ thePixelDigiSimLinkHandle

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

Data members.

Definition at line 55 of file TTClusterAssociator.h.

◆ theTrackerGeometry

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

Definition at line 68 of file TTClusterAssociator.h.

◆ theTrackerTopology

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

Definition at line 69 of file TTClusterAssociator.h.

◆ tpToken

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

Definition at line 61 of file TTClusterAssociator.h.

◆ TrackingParticleHandle

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

Definition at line 56 of file TTClusterAssociator.h.

◆ TTClustersInputTags

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

Definition at line 58 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
mps_fire.i
i
Definition: mps_fire.py:355
TTClusterAssociator::TrackingParticleHandle
edm::Handle< std::vector< TrackingParticle > > TrackingParticleHandle
Definition: TTClusterAssociator.h:56
TTClusterAssociator::TTClustersInputTags
std::vector< edm::InputTag > TTClustersInputTags
Definition: TTClusterAssociator.h:58
TTClusterAssociator::theTrackerTopology
edm::ESHandle< TrackerTopology > theTrackerTopology
Definition: TTClusterAssociator.h:69
edm::DetSet
Definition: DetSet.h:23
edm::LogInfo
Definition: MessageLogger.h:254
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:735
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref
Definition: AssociativeIterator.h:58
EncodedEventId
Definition: EncodedEventId.h:11
DetId
Definition: DetId.h:17
TTClusterAssociator::thePixelDigiSimLinkHandle
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > thePixelDigiSimLinkHandle
Data members.
Definition: TTClusterAssociator.h:55
TTClusterAssociator::tpToken
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken
Definition: TTClusterAssociator.h:61
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
TTClusterAssociator::digisimLinkToken
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken
Definition: TTClusterAssociator.h:60
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
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
iEvent
int iEvent
Definition: GenABIO.cc:224
TTClusterAssociator::theTrackerGeometry
edm::ESHandle< TrackerGeometry > theTrackerGeometry
Definition: TTClusterAssociator.h:68
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 >
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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
TTCluster
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
TTClusterAssociator::TTClustersTokens
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > TTClustersTokens
Definition: TTClusterAssociator.h:63
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
edm::InputTag
Definition: InputTag.h:15
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