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)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
template<>
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 Implement the producer. More...
 

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

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.

References TTClusterAssociator< T >::digisimLinkToken, edm::ParameterSet::getParameter(), TTClusterAssociator< T >::tpToken, TTClusterAssociator< T >::TTClustersInputTags, and TTClusterAssociator< T >::TTClustersTokens.

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 }
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken
std::vector< edm::InputTag > TTClustersInputTags
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > TTClustersTokens
template<typename T >
TTClusterAssociator< T >::~TTClusterAssociator ( )
override

Destructor.

Definition at line 103 of file TTClusterAssociator.h.

103 {}

Member Function Documentation

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.

References edm::EventSetup::get(), TTClusterAssociator< T >::theTrackerGeometry, and TTClusterAssociator< T >::theTrackerTopology.

107  {
111 
113  edm::LogInfo("TTClusterAssociator< ") << templateNameFinder<T>() << " > loaded.";
114 }
edm::ESHandle< TrackerTopology > theTrackerTopology
T get() const
Definition: EventSetup.h:73
edm::ESHandle< TrackerGeometry > theTrackerGeometry
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.

References iEvent, and TTClusterAssociator< T >::produce().

118 {}
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

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.

References edmNew::DetSet< T >::begin(), bsc_activity_cfg::clusters, edm::DetSet< T >::data, TrackerGeometry::dets(), edmNew::DetSet< T >::end(), TrackingParticle::eventId(), TrackingParticle::g4Tracks(), edm::Event::getByToken(), mps_fire::i, edm::EventBase::isRealData(), edmNew::makeRefTo(), eostools::move(), edm::Event::put(), 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 = 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<
74  edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>, TTCluster<Ref_Phase2TrackerDigi_>>>>
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) {
93  edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>, TTCluster<Ref_Phase2TrackerDigi_>> tempCluRef =
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<
152  edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>, TTCluster<Ref_Phase2TrackerDigi_>>>
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 }
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)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > thePixelDigiSimLinkHandle
Data members.
bool isRealData() const
Definition: EventBase.h:62
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
edm::Handle< std::vector< TrackingParticle > > TrackingParticleHandle
def unique(seq, keepstr=True)
Definition: tier0.py:24
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken
static constexpr auto TOB
std::vector< edm::InputTag > TTClustersInputTags
Definition: DetId.h:17
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
collection_type data
Definition: DetSet.h:81
iterator end()
Definition: DetSetNew.h:56
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > TTClustersTokens
collection_type::const_iterator const_iterator
Definition: DetSet.h:32
static constexpr auto TID
T const * product() const
Definition: ESHandle.h:86
edm::ESHandle< TrackerGeometry > theTrackerGeometry
def move(src, dest)
Definition: eostools.py:511
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

Implement the producer.

Member Data Documentation

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

Definition at line 60 of file TTClusterAssociator.h.

Referenced by TTClusterAssociator< T >::TTClusterAssociator().

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::ESHandle<TrackerGeometry> TTClusterAssociator< T >::theTrackerGeometry
private

Definition at line 68 of file TTClusterAssociator.h.

Referenced by TTClusterAssociator< T >::beginRun().

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

Definition at line 69 of file TTClusterAssociator.h.

Referenced by TTClusterAssociator< T >::beginRun().

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

Definition at line 61 of file TTClusterAssociator.h.

Referenced by TTClusterAssociator< T >::TTClusterAssociator().

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.

Referenced by TTClusterAssociator< T >::TTClusterAssociator().

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

Definition at line 63 of file TTClusterAssociator.h.

Referenced by TTClusterAssociator< T >::TTClusterAssociator().