CMS 3D CMS Logo

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

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

#include <TTTrackAssociator.h>

Inheritance diagram for TTTrackAssociator< T >:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 TTTrackAssociator (const edm::ParameterSet &iConfig)
 Constructors. More...
 
 ~TTTrackAssociator ()
 Destructor. More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Private Attributes

edm::EDGetTokenT< TTClusterAssociationMap< T > > TTClusterTruthToken
 
edm::EDGetTokenT< TTStubAssociationMap< T > > TTStubTruthToken
 
std::vector< edm::InputTagTTTracksInputTags
 Data members. More...
 
std::vector< edm::EDGetTokenT< std::vector< TTTrack< T > > > > TTTracksTokens
 

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
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

template<typename T>
class TTTrackAssociator< T >

Plugin to create the MC truth for TTTracks.

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 40 of file TTTrackAssociator.h.

Constructor & Destructor Documentation

template<typename T >
TTTrackAssociator< T >::TTTrackAssociator ( 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 80 of file TTTrackAssociator.h.

References edm::EDConsumerBase::consumes(), edm::ParameterSet::getParameter(), TTTrackAssociator< T >::TTClusterTruthToken, TTTrackAssociator< T >::TTStubTruthToken, TTTrackAssociator< T >::TTTracksInputTags, and TTTrackAssociator< T >::TTTracksTokens.

81 {
82  TTTracksInputTags = iConfig.getParameter< std::vector< edm::InputTag > >( "TTTracks" );
83  TTClusterTruthToken = consumes< TTClusterAssociationMap< T > >(iConfig.getParameter< edm::InputTag >( "TTClusterTruth" ));
84  TTStubTruthToken = consumes< TTStubAssociationMap< T > >(iConfig.getParameter< edm::InputTag >( "TTStubTruth" ));
85 
86  for ( auto iTag = TTTracksInputTags.begin(); iTag!= TTTracksInputTags.end(); iTag++ )
87  {
88  TTTracksTokens.push_back(consumes< std::vector< TTTrack< T > > >(*iTag));
89 
90  produces< TTTrackAssociationMap< T > >( (*iTag).instance() );
91  }
92 }
T getParameter(std::string const &) const
std::vector< edm::InputTag > TTTracksInputTags
Data members.
edm::EDGetTokenT< TTClusterAssociationMap< T > > TTClusterTruthToken
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::EDGetTokenT< std::vector< TTTrack< T > > > > TTTracksTokens
edm::EDGetTokenT< TTStubAssociationMap< T > > TTStubTruthToken
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:23
template<typename T >
TTTrackAssociator< T >::~TTTrackAssociator ( )

Destructor.

Definition at line 96 of file TTTrackAssociator.h.

96 {}

Member Function Documentation

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

Mandatory methods.

Begin run.

Print some information when loaded

Definition at line 100 of file TTTrackAssociator.h.

101 {
103  edm::LogInfo("TTStubAssociator< ") << "TTTrackAssociator< " << templateNameFinder< T >() << " > loaded.";
104 }
template<typename T >
void TTTrackAssociator< T >::endRun ( const edm::Run run,
const edm::EventSetup iSetup 
)
privatevirtual

End run.

Definition at line 108 of file TTTrackAssociator.h.

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

108 {}
template<>
void TTTrackAssociator< 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 Stub and Cluster MC truth

Loop over InputTags to handle multiple collections

Prepare output

Get the Tracks already stored away

Prepare the necessary maps

Counter needed to build the edm::Ptr to the TTTrack

Make the pointer to be put in the map

Get the stubs of the TTTrack (theseStubs)

Auxiliary map to store TP addresses and TP edm::Ptr

Fill the inclusive map which is careless of the stub classification

Prepare the maps wrt TrackingParticle

Fill the auxiliary map

Fill the other auxiliary map

End of loop over the clusters

Check if the stub is unknown

End of loop over the stubs

If there more than 2 unknown stubs, go to the next track as this track may be COMBINATORIC or UNKNOWN

If we are here, all the stubs are either combinatoric or genuine and there is no more than one fake stub in the track Loop over all the TrackingParticle which have been found in the track at some point (stored in auxMap)

Get all the stubs from this TrackingParticle

Loop over the stubs

We want that all the stubs of the track are included in the container of all the stubs produced by this particular TrackingParticle which we already know is one of the TrackingParticles that released hits in this track we are evaluating right now

If the TrackingParticle does not appear in all stubs but one then go to the next track

If we are here, it means that the TrackingParticle generates hits in all stubs but one of the current track so put it into the vector

Count how many TrackingParticles we do have

If only one TrackingParticle, GENUINE if different than one, COMBINATORIC

Here, the track may only be GENUINE Fill the map

End of loop over Tracks

Clean the only map that needs cleaning Prepare the output map wrt TrackingParticle

Get the vector of edm::Ptr< TTTrack >

Sort and remove duplicates

Also, create the pointer to the TTClusterAssociationMap

Put the maps in the association object

Put output in the event

End of loop over InputTags

Definition at line 14 of file TTTrackAssociator.cc.

References spr::find(), edm::Ptr< T >::get(), edm::Event::getByToken(), edm::Ptr< T >::isNull(), edm::EventBase::isRealData(), eostools::move(), edm::Event::put(), edm::second(), and tier0::unique().

15 {
17  if ( iEvent.isRealData() )
18  return;
19 
22  iEvent.getByToken( TTClusterTruthToken, TTClusterAssociationMapHandle );
24  iEvent.getByToken( TTStubTruthToken, TTStubAssociationMapHandle );
25 
26 
27  int ncont1=0;
28 
30  for ( auto iTag = TTTracksTokens.begin(); iTag!= TTTracksTokens.end(); iTag++ )
31  {
33  auto associationMapForOutput = std::make_unique<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>();
34 
37  iEvent.getByToken( *iTag, TTTrackHandle );
38 
40  std::map< edm::Ptr< TTTrack< Ref_Phase2TrackerDigi_ > >, edm::Ptr< TrackingParticle > > trackToTrackingParticleMap;
41  std::map< edm::Ptr< TrackingParticle >, std::vector< edm::Ptr< TTTrack< Ref_Phase2TrackerDigi_ > > > > trackingParticleToTrackVectorMap;
42  trackToTrackingParticleMap.clear();
43  trackingParticleToTrackVectorMap.clear();
44 
45 
46  // Start the loop on tracks
47 
48  unsigned int j = 0;
49  typename std::vector< TTTrack< Ref_Phase2TrackerDigi_ > >::const_iterator inputIter;
50  for ( inputIter = TTTrackHandle->begin();
51  inputIter != TTTrackHandle->end();
52  ++inputIter )
53  {
55  edm::Ptr< TTTrack< Ref_Phase2TrackerDigi_ > > tempTrackPtr( TTTrackHandle, j++ );
56 
58  std::vector< edm::Ref< edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >, TTStub< Ref_Phase2TrackerDigi_ > > > theseStubs = tempTrackPtr->getStubRefs();
59 
61  std::map< const TrackingParticle*, edm::Ptr< TrackingParticle > > auxMap;
62  auxMap.clear();
63  int mayCombinUnknown = 0;
64 
66  for ( unsigned int is = 0; is < theseStubs.size(); is++ )
67  {
68  // std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > theseClusters = theseStubs.at(is)->getClusterRefs();
69  for ( unsigned int ic = 0; ic < 2; ic++ )
70  {
71  std::vector< edm::Ptr< TrackingParticle > > tempTPs = TTClusterAssociationMapHandle->findTrackingParticlePtrs( theseStubs.at(is)->getClusterRef(ic) );
72  for ( unsigned int itp = 0; itp < tempTPs.size(); itp++ ) // List of TPs linked to stub clusters
73  {
74  edm::Ptr< TrackingParticle > testTP = tempTPs.at(itp);
75 
76  if ( testTP.isNull() ) // No TP linked to this cluster
77  continue;
78 
80  if ( trackingParticleToTrackVectorMap.find( testTP ) == trackingParticleToTrackVectorMap.end() )
81  {
82  std::vector< edm::Ptr< TTTrack< Ref_Phase2TrackerDigi_ > > > trackVector;
83  trackVector.clear();
84  trackingParticleToTrackVectorMap.insert( std::make_pair( testTP, trackVector ) );
85  }
86  trackingParticleToTrackVectorMap.find( testTP )->second.push_back( tempTrackPtr );
87 
89  if ( auxMap.find( testTP.get() ) == auxMap.end() )
90  {
91  auxMap.insert( std::make_pair( testTP.get(), testTP ) );
92  }
93 
94  }
95  }
96 
98  if ( TTStubAssociationMapHandle->isUnknown( theseStubs.at(is) ) )
99  ++mayCombinUnknown;
100 
101  }
102 
105  if ( mayCombinUnknown >= 2 )
106  continue;
107 
112 
113  std::vector< const TrackingParticle* > tpInAllStubs;
114 
115  std::map< const TrackingParticle*, edm::Ptr< TrackingParticle > >::const_iterator iterAuxMap;
116  for ( iterAuxMap = auxMap.begin();
117  iterAuxMap != auxMap.end();
118  ++iterAuxMap )
119  {
121  std::vector< edm::Ref< edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >, TTStub< Ref_Phase2TrackerDigi_ > > > tempStubs = TTStubAssociationMapHandle->findTTStubRefs( iterAuxMap->second );
122 
123  int nnotfound=0;
124  //bool allFound = true;
126  // for ( unsigned int js = 0; js < theseStubs.size() && allFound; js++ )
127  for ( unsigned int js = 0; js < theseStubs.size(); js++ )
128  {
133  if ( std::find( tempStubs.begin(), tempStubs.end(), theseStubs.at(js) ) == tempStubs.end() )
134  {
135  // allFound = false;
136  ++nnotfound;
137  }
138  }
139 
142  if (nnotfound>1)
143  //if (!allFound)
144  continue;
145 
149  tpInAllStubs.push_back( iterAuxMap->first );
150  }
151 
153  std::sort( tpInAllStubs.begin(), tpInAllStubs.end() );
154  tpInAllStubs.erase( std::unique( tpInAllStubs.begin(), tpInAllStubs.end() ), tpInAllStubs.end() );
155  unsigned int nTPs = tpInAllStubs.size();
156 
159  if ( nTPs != 1 ) continue;
160 
163  trackToTrackingParticleMap.insert( std::make_pair( tempTrackPtr, auxMap.find( tpInAllStubs.at(0) )->second ) );
164 
165  }
166 
169  typename std::map< edm::Ptr< TrackingParticle >, std::vector< edm::Ptr< TTTrack< Ref_Phase2TrackerDigi_ > > > >::iterator iterMapToClean;
170  for ( iterMapToClean = trackingParticleToTrackVectorMap.begin();
171  iterMapToClean != trackingParticleToTrackVectorMap.end();
172  ++iterMapToClean )
173  {
175  std::vector< edm::Ptr< TTTrack< Ref_Phase2TrackerDigi_ > > > tempVector = iterMapToClean->second;
176 
178  std::sort( tempVector.begin(), tempVector.end() );
179  tempVector.erase( std::unique( tempVector.begin(), tempVector.end() ), tempVector.end() );
180 
181  iterMapToClean->second = tempVector;
182  }
183 
185  edm::RefProd< TTStubAssociationMap< Ref_Phase2TrackerDigi_ > > theStubAssoMap( TTStubAssociationMapHandle );
186 
188  associationMapForOutput->setTTTrackToTrackingParticleMap( trackToTrackingParticleMap );
189  associationMapForOutput->setTrackingParticleToTTTracksMap( trackingParticleToTrackVectorMap );
190  associationMapForOutput->setTTStubAssociationMap( theStubAssoMap );
191 
193  iEvent.put( std::move(associationMapForOutput), TTTracksInputTags.at(ncont1).instance() );
194 
195  ++ncont1;
196  }
197 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:160
std::vector< edm::InputTag > TTTracksInputTags
Data members.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
bool isRealData() const
Definition: EventBase.h:64
edm::EDGetTokenT< TTClusterAssociationMap< T > > TTClusterTruthToken
U second(std::pair< T, U > const &p)
std::vector< edm::EDGetTokenT< std::vector< TTTrack< T > > > > TTTracksTokens
def unique(seq, keepstr=True)
Definition: tier0.py:24
bool isNull() const
Checks for null.
Definition: Ptr.h:165
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
edm::EDGetTokenT< TTStubAssociationMap< T > > TTStubTruthToken
def move(src, dest)
Definition: eostools.py:510
template<typename T >
virtual void TTTrackAssociator< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual
template<>
void TTTrackAssociator< Ref_Phase2TrackerDigi_ >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Implement the producer.

Member Data Documentation

template<typename T >
edm::EDGetTokenT< TTClusterAssociationMap< T > > TTTrackAssociator< T >::TTClusterTruthToken
private

Definition at line 59 of file TTTrackAssociator.h.

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

template<typename T >
edm::EDGetTokenT< TTStubAssociationMap< T > > TTTrackAssociator< T >::TTStubTruthToken
private

Definition at line 58 of file TTTrackAssociator.h.

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

template<typename T >
std::vector< edm::InputTag > TTTrackAssociator< T >::TTTracksInputTags
private

Data members.

Definition at line 53 of file TTTrackAssociator.h.

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

template<typename T >
std::vector<edm::EDGetTokenT< std::vector< TTTrack< T > > > > TTTrackAssociator< T >::TTTracksTokens
private

Definition at line 56 of file TTTrackAssociator.h.

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