CMS 3D CMS Logo

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

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

#include <TTStubAssociator.h>

Inheritance diagram for TTStubAssociator< T >:
edm::stream::EDProducer<>

Public Member Functions

 TTStubAssociator (const edm::ParameterSet &iConfig)
 Constructors. More...
 
 ~TTStubAssociator () 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::ESHandle< TrackerGeometrytheTrackerGeometry
 
edm::ESHandle< TrackerTopologytheTrackerTopology
 
std::vector< edm::InputTagTTClusterTruthInputTags
 
std::vector< edm::EDGetTokenT< TTClusterAssociationMap< T > > > TTClusterTruthTokens
 
std::vector< edm::InputTagTTStubsInputTags
 Data members. More...
 
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTStub< T > > > > TTStubsTokens
 

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 TTStubAssociator< T >

Plugin to create the MC truth for TTStubs.

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 TTStubAssociator.h.

Constructor & Destructor Documentation

template<typename T >
TTStubAssociator< T >::TTStubAssociator ( 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 TTStubAssociator.h.

References edm::ParameterSet::getParameter(), TTStubAssociator< T >::TTClusterTruthInputTags, TTStubAssociator< T >::TTClusterTruthTokens, TTStubAssociator< T >::TTStubsInputTags, and TTStubAssociator< T >::TTStubsTokens.

83 {
84  TTStubsInputTags = iConfig.getParameter< std::vector< edm::InputTag > >( "TTStubs" );
85  TTClusterTruthInputTags = iConfig.getParameter< std::vector< edm::InputTag > >( "TTClusterTruth" );
86 
87 
88  for ( auto iTag = TTClusterTruthInputTags.begin(); iTag!= TTClusterTruthInputTags.end(); iTag++ )
89  {
90  TTClusterTruthTokens.push_back(consumes< TTClusterAssociationMap< T > >(*iTag));
91  }
92 
93  for ( auto iTag = TTStubsInputTags.begin(); iTag!= TTStubsInputTags.end(); iTag++ )
94  {
95  TTStubsTokens.push_back(consumes< edmNew::DetSetVector< TTStub< T > > >(*iTag));
96 
97  produces< TTStubAssociationMap< T > >( (*iTag).instance() );
98  }
99 }
T getParameter(std::string const &) const
std::vector< edm::EDGetTokenT< TTClusterAssociationMap< T > > > TTClusterTruthTokens
NOTE: this is needed even if it seems not.
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTStub< T > > > > TTStubsTokens
std::vector< edm::InputTag > TTClusterTruthInputTags
std::vector< edm::InputTag > TTStubsInputTags
Data members.
template<typename T >
TTStubAssociator< T >::~TTStubAssociator ( )
override

Destructor.

Definition at line 103 of file TTStubAssociator.h.

103 {}

Member Function Documentation

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

Mandatory methods.

Begin run.

Print some information when loaded

Definition at line 107 of file TTStubAssociator.h.

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

108 {
110  edm::LogInfo("TTStubAssociator< ") << templateNameFinder< T >() << " > loaded.";
111 
114 }
edm::ESHandle< TrackerGeometry > theTrackerGeometry
T get() const
Definition: EventSetup.h:71
edm::ESHandle< TrackerTopology > theTrackerTopology
template<typename T >
void TTStubAssociator< T >::endRun ( const edm::Run run,
const edm::EventSetup iSetup 
)
overrideprivate

End run.

Definition at line 118 of file TTStubAssociator.h.

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

118 {}
template<>
void TTStubAssociator< 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

Exit if the vectors are uncorrectly dimensioned

Loop over the InputTags to handle multiple collections

Prepare output

Get the Stubs already stored away

Get the Cluster MC truth

Prepare the necessary maps

Loop over the input Stubs

Get the DetSets of the Clusters

Make the reference to be put in the map

Get the two clusters

Fill the inclusive map which is careless of the stub classification

Prepare the maps wrt TrackingParticle

Fill the auxiliary map

GENUINE for clusters means not combinatoric and not unknown: same MC truth content MUST be found in both clusters composing the stub

If at least one cluster is unknown, it means either unknown, either combinatoric Do nothing, and go to the next Stub

Here both are clusters are genuine/combinatoric If both clusters have some known SimTrack content they must be compared to each other

If both clusters are genuine, they must be associated to the same TrackingParticle in order to return a genuine stub. Period. Note we can perform safely this comparison because, if both clusters are genuine, their TrackingParticle shall NEVER be NULL

Two genuine clusters with same SimTrack content mean genuine

Fill the map: by construction, this will always be the first time the stub is inserted into the map: no need for "find"

At this point, go to the next Stub

It means combinatoric

End of two genuine clusters

Here, at least one cluster is combinatoric

Skip NULL pointers

Skip NULL pointers

Same SimTrack is present in both clusters

If two different SimTracks are found in both clusters, then the stub is for sure combinatoric

End of double loop over SimTracks of both clusters

If two different SimTracks are found in both clusters, go to the next stub

No SimTracks were found to be in both clusters

Only one SimTrack was found to be present in both clusters even if one of the clusters (or both) are combinatoric: this means there is only one track that participates in both clusters, hence the stub is genuine

Fill the map: by construction, this will always be the first time the stub is inserted into the map: no need for "find"

At this point, go to the next Stub

End of one single SimTrack in both clusters

End of "at least one cluster is combinatoric"

End of "both clusters are known, somehow..."

End of loop over Stubs

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

Get the vector of references to TTStub

Sort and remove duplicates

Put the vector in the output map

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 TTStubAssociator.cc.

References edmNew::DetSet< T >::begin(), TrackerGeometry::dets(), edmNew::DetSet< T >::end(), PhysicsTools::escape(), edm::Event::getByToken(), mps_fire::i, TrackerTopology::isLower(), edm::Ptr< T >::isNull(), edm::EventBase::isRealData(), gen::k, edmNew::makeRefTo(), eostools::move(), edm::Event::put(), jetUpdater_cfi::sort, TrackerTopology::stack(), DetId::subdetId(), StripSubdetector::TID, StripSubdetector::TOB, and tier0::unique().

15 {
17  if ( iEvent.isRealData() )
18  return;
19 
21  if ( TTClusterTruthInputTags.size() != TTStubsInputTags.size() )
22  {
23  edm::LogError("TTStubAsso ") << "E R R O R! the InputTag vectors have different size!";
24  return;
25  }
26 
27  int ncont1=0;
28 
29  const TrackerGeometry* const theTrackerGeom = theTrackerGeometry.product();
30  const TrackerTopology* const tTopo = theTrackerTopology.product();
31 
33 
34  for ( auto iTag = TTStubsTokens.begin(); iTag!= TTStubsTokens.end(); iTag++ )
35  {
37  auto associationMapForOutput = std::make_unique<TTStubAssociationMap<Ref_Phase2TrackerDigi_>>();
38 
41  iEvent.getByToken( *iTag, TTStubHandle );
42 
45  iEvent.getByToken( TTClusterTruthTokens.at(ncont1), TTClusterAssociationMapHandle );
46 
48  std::map< edm::Ref< edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >, TTStub< Ref_Phase2TrackerDigi_ > >, edm::Ptr< TrackingParticle > > stubToTrackingParticleMap;
49  std::map< edm::Ptr< TrackingParticle >, std::vector< edm::Ref< edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >, TTStub< Ref_Phase2TrackerDigi_ > > > > trackingParticleToStubVectorMap;
50  stubToTrackingParticleMap.clear();
51  trackingParticleToStubVectorMap.clear();
52 
54 
55  if ( !TTStubHandle->empty() )
56  {
57  for (auto gd=theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++)
58  {
59  DetId detid = (*gd)->geographicalId();
60  if(detid.subdetId()!=StripSubdetector::TOB && detid.subdetId()!=StripSubdetector::TID ) continue; // only run on OT
61 
62  if(!tTopo->isLower(detid) ) continue; // loop on the stacks: choose the lower arbitrarily
63 
64  DetId stackDetid = tTopo->stack(detid); // Stub module detid
65 
66  if (TTStubHandle->find( stackDetid ) == TTStubHandle->end() ) continue;
67 
69  edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > > stubs = (*TTStubHandle)[ stackDetid ];
70 
71  for ( auto contentIter = stubs.begin();contentIter != stubs.end();++contentIter )
72  {
74  edm::Ref< edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >, TTStub< Ref_Phase2TrackerDigi_ > > tempStubRef = edmNew::makeRefTo( TTStubHandle, contentIter );
75 
77  // std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > theseClusters = tempStubRef->getClusterRefs();
78 
80  for ( unsigned int ic = 0; ic < 2; ic++ )
81  {
82  std::vector< edm::Ptr< TrackingParticle > > tempTPs = TTClusterAssociationMapHandle->findTrackingParticlePtrs( tempStubRef->getClusterRef(ic) );
83 
84  for ( unsigned int itp = 0; itp < tempTPs.size(); itp++ )
85  {
86  edm::Ptr< TrackingParticle > testTP = tempTPs.at(itp);
87 
88  if ( testTP.isNull() )
89  continue;
90 
92  if ( trackingParticleToStubVectorMap.find( testTP ) == trackingParticleToStubVectorMap.end() )
93  {
94  std::vector< edm::Ref< edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >, TTStub< Ref_Phase2TrackerDigi_ > > > stubVector;
95  stubVector.clear();
96  trackingParticleToStubVectorMap.insert( std::make_pair( testTP, stubVector ) );
97  }
98  trackingParticleToStubVectorMap.find( testTP )->second.push_back( tempStubRef );
99  }
100  }
101 
105  if ( TTClusterAssociationMapHandle->isUnknown( tempStubRef->getClusterRef(0) ) ||
106  TTClusterAssociationMapHandle->isUnknown( tempStubRef->getClusterRef(1) ) )
107  {
111  continue;
112  }
113  else
114  {
118  if ( TTClusterAssociationMapHandle->isGenuine( tempStubRef->getClusterRef(0) ) &&
119  TTClusterAssociationMapHandle->isGenuine( tempStubRef->getClusterRef(1) ) )
120  {
124  if ( TTClusterAssociationMapHandle->findTrackingParticlePtr( tempStubRef->getClusterRef(0) ).get() ==
125  TTClusterAssociationMapHandle->findTrackingParticlePtr( tempStubRef->getClusterRef(1) ).get() )
126  {
128  edm::Ptr< TrackingParticle > testTP = TTClusterAssociationMapHandle->findTrackingParticlePtr( tempStubRef->getClusterRef(0) );
129 
132  stubToTrackingParticleMap.insert( std::make_pair( tempStubRef, testTP ) );
133 
135  continue;
136  }
137  else
138  {
140  continue;
141  }
142  }
143  else
144  {
146  TrackingParticle* prevTPAddress = nullptr;
147  unsigned int whichTP = 0;
148 
149  std::vector< edm::Ptr< TrackingParticle > > trackingParticles0 = TTClusterAssociationMapHandle->findTrackingParticlePtrs( tempStubRef->getClusterRef(0) );
150  std::vector< edm::Ptr< TrackingParticle > > trackingParticles1 = TTClusterAssociationMapHandle->findTrackingParticlePtrs( tempStubRef->getClusterRef(1) );
151 
152  bool escape = false;
153 
154  for ( unsigned int i = 0; i < trackingParticles0.size() && !escape; i++ )
155  {
157  if ( trackingParticles0.at(i).isNull() )
158  continue;
159 
160  for ( unsigned int k = 0; k < trackingParticles1.size() && !escape; k++ )
161  {
163  if ( trackingParticles1.at(k).isNull() )
164  continue;
165 
166  if ( trackingParticles0.at(i).get() == trackingParticles1.at(k).get() )
167  {
169  if ( prevTPAddress == nullptr )
170  {
171  prevTPAddress = const_cast< TrackingParticle* >(trackingParticles1.at(k).get());
172  whichTP = k;
173  }
174 
177  if ( prevTPAddress != const_cast< TrackingParticle* >(trackingParticles1.at(k).get()) )
178  {
179  escape = true;
180  continue;
181  }
182  }
183  }
184  }
185 
188  if ( escape )
189  continue;
190 
191  if ( prevTPAddress == nullptr )
192  {
194  continue;
195  }
196  else
197  {
202  edm::Ptr< TrackingParticle > testTP = trackingParticles1.at(whichTP);
203 
206  stubToTrackingParticleMap.insert( std::make_pair( tempStubRef, testTP ) );
207 
209  continue;
210  }
211  }
212  }
213  }
214  }
215 
216  }
217 
220  typename std::map< edm::Ptr< TrackingParticle >, std::vector< edm::Ref< edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >, TTStub< Ref_Phase2TrackerDigi_ > > > >::iterator iterMapToClean;
221  for ( iterMapToClean = trackingParticleToStubVectorMap.begin();
222  iterMapToClean != trackingParticleToStubVectorMap.end();
223  ++iterMapToClean )
224  {
226  std::vector< edm::Ref< edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >, TTStub< Ref_Phase2TrackerDigi_ > > > tempVector = iterMapToClean->second;
227 
229  std::sort( tempVector.begin(), tempVector.end() );
230  tempVector.erase( std::unique( tempVector.begin(), tempVector.end() ), tempVector.end() );
231 
233  iterMapToClean->second = tempVector;
234  }
235 
237  edm::RefProd< TTClusterAssociationMap< Ref_Phase2TrackerDigi_ > > theCluAssoMap( TTClusterAssociationMapHandle );
238 
240  associationMapForOutput->setTTStubToTrackingParticleMap( stubToTrackingParticleMap );
241  associationMapForOutput->setTrackingParticleToTTStubsMap( trackingParticleToStubVectorMap );
242  associationMapForOutput->setTTClusterAssociationMap( theCluAssoMap );
243 
245  iEvent.put( std::move(associationMapForOutput), TTStubsInputTags.at(ncont1).instance() );
246 
247  ++ncont1;
248  }
249 }
static std::string escape(const std::string &in)
Definition: MVATrainer.cc:403
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:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< edm::EDGetTokenT< TTClusterAssociationMap< T > > > TTClusterTruthTokens
bool isRealData() const
Definition: EventBase.h:62
bool isLower(const DetId &id) const
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
edm::ESHandle< TrackerGeometry > theTrackerGeometry
def unique(seq, keepstr=True)
Definition: tier0.py:25
bool isNull() const
Checks for null.
Definition: Ptr.h:164
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTStub< T > > > > TTStubsTokens
int k[5][pyjets_maxn]
Definition: DetId.h:18
uint32_t stack(const DetId &id) const
std::vector< edm::InputTag > TTClusterTruthInputTags
iterator end()
Definition: DetSetNew.h:70
std::vector< edm::InputTag > TTStubsInputTags
Data members.
edm::ESHandle< TrackerTopology > theTrackerTopology
Monte Carlo truth information used for tracking validation.
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
iterator begin()
Definition: DetSetNew.h:67
template<typename T >
void TTStubAssociator< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate
template<>
void TTStubAssociator< Ref_Phase2TrackerDigi_ >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Implement the producer.

Member Data Documentation

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

Definition at line 63 of file TTStubAssociator.h.

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

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

Definition at line 64 of file TTStubAssociator.h.

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

template<typename T >
std::vector< edm::InputTag > TTStubAssociator< T >::TTClusterTruthInputTags
private

Definition at line 58 of file TTStubAssociator.h.

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

template<typename T >
std::vector<edm::EDGetTokenT< TTClusterAssociationMap< T > > > TTStubAssociator< T >::TTClusterTruthTokens
private

Definition at line 61 of file TTStubAssociator.h.

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

template<typename T >
std::vector< edm::InputTag > TTStubAssociator< T >::TTStubsInputTags
private

Data members.

Definition at line 57 of file TTStubAssociator.h.

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

template<typename T >
std::vector<edm::EDGetTokenT< edmNew::DetSetVector< TTStub< T > > > > TTStubAssociator< T >::TTStubsTokens
private

Definition at line 60 of file TTStubAssociator.h.

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