CMS 3D CMS Logo

TTStubAssociator.cc
Go to the documentation of this file.
1 
11 
13 template< >
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->size() > 0 )
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 = NULL;
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 == NULL )
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 == NULL )
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 }
250 
251 
static std::string escape(const std::string &in)
Definition: MVATrainer.cc:405
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:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
#define NULL
Definition: scimark2.h:8
bool isRealData() const
Definition: EventBase.h:64
bool isLower(const DetId &id) const
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
int iEvent
Definition: GenABIO.cc:230
def unique(seq, keepstr=True)
Definition: tier0.py:24
bool isNull() const
Checks for null.
Definition: Ptr.h:164
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int k[5][pyjets_maxn]
Definition: DetId.h:18
uint32_t stack(const DetId &id) const
iterator end()
Definition: DetSetNew.h:70
Monte Carlo truth information used for tracking validation.
def move(src, dest)
Definition: eostools.py:510
iterator begin()
Definition: DetSetNew.h:67