CMS 3D CMS Logo

TTTrackAssociator.cc
Go to the documentation of this file.
1 
11 
13 template< >
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 }
198 
199 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
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
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
def unique(seq, keepstr=True)
Definition: tier0.py:25
bool isNull() const
Checks for null.
Definition: Ptr.h:164
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
def move(src, dest)
Definition: eostools.py:511