CMS 3D CMS Logo

TTClusterAssociator.cc
Go to the documentation of this file.
1 
11 
13 template< >
15 {
17  if ( iEvent.isRealData() )
18  return;
19 
21  iEvent.getByToken(digisimLinkToken, thePixelDigiSimLinkHandle);
22 
24 
25  iEvent.getByToken(tpToken, TrackingParticleHandle );
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  {
46  edm::Ptr< TrackingParticle > tempTPPtr( TrackingParticleHandle, tpCnt++ );
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 }
226 
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
const std::vector< SimTrack > & g4Tracks() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
bool isRealData() const
Definition: EventBase.h:62
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
int iEvent
Definition: GenABIO.cc:224
def unique(seq, keepstr=True)
Definition: tier0.py:25
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Definition: DetId.h:18
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
EncodedEventId eventId() const
Signal source, crossing number.
collection_type data
Definition: DetSet.h:80
iterator end()
Definition: DetSetNew.h:70
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
def move(src, dest)
Definition: eostools.py:511
iterator begin()
Definition: DetSetNew.h:67