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 hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () 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::EDGetTokenT< edm::SimTrackContainersimTrackToken
 
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > thePixelDigiSimLinkHandle
 Data members. More...
 
edm::Handle< edm::SimTrackContainertheSimTrackHandle
 
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 44 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 93 of file TTClusterAssociator.h.

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

94 {
95  simTrackToken = consumes< edm::SimTrackContainer >(iConfig.getParameter< edm::InputTag >( "simTrackHits" ));
96  digisimLinkToken = consumes< edm::DetSetVector< PixelDigiSimLink > >(iConfig.getParameter< edm::InputTag >( "digiSimLinks" ));
97  tpToken = consumes< std::vector< TrackingParticle > >(iConfig.getParameter< edm::InputTag >( "trackingParts" ));
98 
99 
100  TTClustersInputTags = iConfig.getParameter< std::vector< edm::InputTag > >( "TTClusters" );
101 
102  for ( auto iTag = TTClustersInputTags.begin(); iTag!= TTClustersInputTags.end(); iTag++ )
103  {
104  TTClustersTokens.push_back(consumes< edmNew::DetSetVector< TTCluster< T > > >(*iTag));
105 
106  produces< TTClusterAssociationMap< T > >( (*iTag).instance() );
107  }
108 }
T getParameter(std::string const &) const
std::vector< edm::InputTag > TTClustersInputTags
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > TTClustersTokens
edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken
template<typename T >
TTClusterAssociator< T >::~TTClusterAssociator ( )
override

Destructor.

Definition at line 112 of file TTClusterAssociator.h.

112 {}

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

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

117 {
121 
123  edm::LogInfo("TTClusterAssociator< ") << templateNameFinder< T >() << " > loaded.";
124 }
const T & get() const
Definition: EventSetup.h:59
edm::ESHandle< TrackerTopology > theTrackerTopology
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 128 of file TTClusterAssociator.h.

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

128 {}
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(), fastPrimaryVertexProducer_cfi::clusters, edm::DetSet< T >::data, TrackerGeometry::dets(), edmNew::DetSet< T >::end(), TrackingParticle::eventId(), funct::false, 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().

15 {
17  if ( iEvent.isRealData() )
18  return;
19 
22 
24 
26 
27  // const TrackerTopology* const tTopo = theTrackerTopology.product();
28  const TrackerGeometry* const theTrackerGeom = theTrackerGeometry.product();
29 
30 
33  std::map< std::pair< unsigned int, EncodedEventId >, edm::Ptr< TrackingParticle > > simTrackUniqueToTPMap;
34  simTrackUniqueToTPMap.clear();
35 
36  if ( !TrackingParticleHandle->empty() )
37  {
39  unsigned int tpCnt = 0;
40  std::vector< TrackingParticle >::const_iterator iterTPart;
41  for ( iterTPart = TrackingParticleHandle->begin();
42  iterTPart != TrackingParticleHandle->end();
43  ++iterTPart )
44  {
47 
49  EncodedEventId eventId = EncodedEventId( tempTPPtr->eventId() );
50 
52  std::vector< SimTrack >::const_iterator iterSimTrack;
53  for ( iterSimTrack = tempTPPtr->g4Tracks().begin();
54  iterSimTrack != tempTPPtr->g4Tracks().end();
55  ++iterSimTrack )
56  {
58  std::pair< unsigned int, EncodedEventId > simTrackUniqueId( iterSimTrack->trackId(), eventId );
59  simTrackUniqueToTPMap.insert( std::make_pair( simTrackUniqueId, tempTPPtr ) );
60  }
61  }
62  }
63 
65 
66  int ncont1=0;
67 
68  for ( auto iTag = TTClustersTokens.begin(); iTag!= TTClustersTokens.end(); iTag++ )
69  {
70 
72  auto associationMapForOutput = std::make_unique<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>();
73 
76 
77  iEvent.getByToken( *iTag, TTClusterHandle );
78 
80  std::map< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > >, std::vector< edm::Ptr< TrackingParticle > > > clusterToTrackingParticleVectorMap;
81  std::map< edm::Ptr< TrackingParticle >, std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > > trackingParticleToClusterVectorMap;
82  clusterToTrackingParticleVectorMap.clear();
83  trackingParticleToClusterVectorMap.clear();
84 
86  for (auto gd=theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++)
87  {
88  DetId detid = (*gd)->geographicalId();
89  if(detid.subdetId()!=StripSubdetector::TOB && detid.subdetId()!=StripSubdetector::TID ) continue; // only run on OT
90 
91  if (TTClusterHandle->find( detid ) == TTClusterHandle->end() ) continue;
92 
94  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > clusters = (*TTClusterHandle)[ detid ];
95 
96  for ( auto contentIter = clusters.begin();contentIter != clusters.end();++contentIter )
97  {
99  edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > tempCluRef = edmNew::makeRefTo( TTClusterHandle, contentIter );
100 
102  if ( clusterToTrackingParticleVectorMap.find( tempCluRef ) == clusterToTrackingParticleVectorMap.end() )
103  {
104  std::vector< edm::Ptr< TrackingParticle > > tpVector;
105  tpVector.clear();
106  clusterToTrackingParticleVectorMap.insert( std::make_pair( tempCluRef, tpVector ) );
107  }
108 
111  if ( thePixelDigiSimLinkHandle->find(detid) == thePixelDigiSimLinkHandle->end() )
112  {
115 
117  std::vector< Ref_Phase2TrackerDigi_ > theseHits = tempCluRef->getHits();
118  for ( unsigned int i = 0; i < theseHits.size(); i++ )
119  {
122  edm::Ptr< TrackingParticle > tempTPPtr; // = new edm::Ptr< TrackingParticle >();
123  clusterToTrackingParticleVectorMap.find( tempCluRef )->second.push_back( tempTPPtr );
124  }
125 
127  continue;
128  }
129 
130  edm::DetSet<PixelDigiSimLink> thisDigiSimLink = (*(thePixelDigiSimLinkHandle) )[detid];
132 
134  std::vector< Ref_Phase2TrackerDigi_ > theseHits = tempCluRef->getHits();
135  for ( unsigned int i = 0; i < theseHits.size(); i++ )
136  {
138  for ( iterSimLink = thisDigiSimLink.data.begin();
139  iterSimLink != thisDigiSimLink.data.end();
140  iterSimLink++ )
141  {
143  if ( static_cast<int>(iterSimLink->channel()) != static_cast<int>(theseHits.at(i)->channel()) )
144  continue;
145 
147  unsigned int curSimTrkId = iterSimLink->SimTrackId();
148  EncodedEventId curSimEvId = iterSimLink->eventId();
149 
151  std::pair< unsigned int, EncodedEventId > thisUniqueId = std::make_pair( curSimTrkId, curSimEvId );
152 
154  if ( simTrackUniqueToTPMap.find( thisUniqueId ) != simTrackUniqueToTPMap.end() )
155  {
156  edm::Ptr< TrackingParticle > thisTrackingParticle = simTrackUniqueToTPMap.find( thisUniqueId )->second;
157 
159  clusterToTrackingParticleVectorMap.find( tempCluRef )->second.push_back( thisTrackingParticle );
160 
162  if ( trackingParticleToClusterVectorMap.find( thisTrackingParticle ) == trackingParticleToClusterVectorMap.end() )
163  {
164  std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > clusterVector;
165  clusterVector.clear();
166  trackingParticleToClusterVectorMap.insert( std::make_pair( thisTrackingParticle, clusterVector ) );
167  }
168  trackingParticleToClusterVectorMap.find( thisTrackingParticle )->second.push_back( tempCluRef );
169  }
170  else
171  {
173 
174  edm::Ptr< TrackingParticle > tempTPPtr; // = new edm::Ptr< TrackingParticle >();
175  clusterToTrackingParticleVectorMap.find( tempCluRef )->second.push_back( tempTPPtr );
176  }
177  }
178  }
179 
181  std::vector< edm::Ptr< TrackingParticle > > theseClusterTrackingParticlePtrs = clusterToTrackingParticleVectorMap.find( tempCluRef )->second;
182  bool allOfThemAreNull = true;
183  for ( unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++ )
184  {
185  if ( theseClusterTrackingParticlePtrs.at(tpi).isNull() == false )
186  allOfThemAreNull = false;
187  }
188 
189  if ( allOfThemAreNull )
190  {
192  clusterToTrackingParticleVectorMap.erase( tempCluRef );
193  }
194 
195  }
196  }
197 
200  std::map< edm::Ptr< TrackingParticle >, std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > >::iterator iterMapToClean;
201  for ( iterMapToClean = trackingParticleToClusterVectorMap.begin();
202  iterMapToClean != trackingParticleToClusterVectorMap.end();
203  ++iterMapToClean )
204  {
206  std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > tempVector = iterMapToClean->second;
207 
209  std::sort( tempVector.begin(), tempVector.end() );
210  tempVector.erase( std::unique( tempVector.begin(), tempVector.end() ), tempVector.end() );
211  iterMapToClean->second = tempVector;
212  }
213 
215  associationMapForOutput->setTTClusterToTrackingParticlesMap( clusterToTrackingParticleVectorMap );
216  associationMapForOutput->setTrackingParticleToTTClustersMap( trackingParticleToClusterVectorMap );
217 
219  // iEvent.put( associationMapForOutput, (*iTag).instance() );
220  iEvent.put( std::move(associationMapForOutput), TTClustersInputTags.at(ncont1).instance() );
221 
222  ++ncont1;
223 
224  }
225 }
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:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > thePixelDigiSimLinkHandle
Data members.
edm::Handle< std::vector< TrackingParticle > > TrackingParticleHandle
bool isRealData() const
Definition: EventBase.h:64
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
def unique(seq, keepstr=True)
Definition: tier0.py:24
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
std::vector< edm::InputTag > TTClustersInputTags
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTCluster< T > > > > TTClustersTokens
Definition: DetId.h:18
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
edm::EDGetTokenT< std::vector< TrackingParticle > > tpToken
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > digisimLinkToken
collection_type data
Definition: DetSet.h:78
iterator end()
Definition: DetSetNew.h:70
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
T const * product() const
Definition: ESHandle.h:86
edm::ESHandle< TrackerGeometry > theTrackerGeometry
def move(src, dest)
Definition: eostools.py:510
iterator begin()
Definition: DetSetNew.h:67
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 63 of file TTClusterAssociator.h.

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

template<typename T >
edm::EDGetTokenT< edm::SimTrackContainer > TTClusterAssociator< T >::simTrackToken
private

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

template<typename T >
edm::Handle< edm::SimTrackContainer > TTClusterAssociator< T >::theSimTrackHandle
private

Definition at line 58 of file TTClusterAssociator.h.

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

Definition at line 73 of file TTClusterAssociator.h.

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

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

Definition at line 74 of file TTClusterAssociator.h.

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

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

Definition at line 65 of file TTClusterAssociator.h.

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

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

Definition at line 59 of file TTClusterAssociator.h.

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

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

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