21 iEvent.
getByToken(digisimLinkToken, thePixelDigiSimLinkHandle);
25 iEvent.
getByToken(tpToken, TrackingParticleHandle );
28 const TrackerGeometry*
const theTrackerGeom = theTrackerGeometry.product();
34 simTrackUniqueToTPMap.clear();
36 if ( TrackingParticleHandle->size() != 0 )
39 unsigned int tpCnt = 0;
40 std::vector< TrackingParticle >::const_iterator iterTPart;
41 for ( iterTPart = TrackingParticleHandle->begin();
42 iterTPart != TrackingParticleHandle->end();
52 std::vector< SimTrack >::const_iterator iterSimTrack;
53 for ( iterSimTrack = tempTPPtr->
g4Tracks().begin();
54 iterSimTrack != tempTPPtr->
g4Tracks().end();
58 std::pair< unsigned int, EncodedEventId > simTrackUniqueId( iterSimTrack->trackId(), eventId );
59 simTrackUniqueToTPMap.insert( std::make_pair( simTrackUniqueId, tempTPPtr ) );
68 for (
auto iTag = TTClustersTokens.begin(); iTag!= TTClustersTokens.end(); iTag++ )
72 auto associationMapForOutput = std::make_unique<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>();
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();
86 for (
auto gd=theTrackerGeom->
dets().begin(); gd != theTrackerGeom->
dets().end(); gd++)
88 DetId detid = (*gd)->geographicalId();
91 if (TTClusterHandle->find( detid ) == TTClusterHandle->end() )
continue;
96 for (
auto contentIter = clusters.
begin();contentIter != clusters.
end();++contentIter )
102 if ( clusterToTrackingParticleVectorMap.find( tempCluRef ) == clusterToTrackingParticleVectorMap.end() )
104 std::vector< edm::Ptr< TrackingParticle > > tpVector;
106 clusterToTrackingParticleVectorMap.insert( std::make_pair( tempCluRef, tpVector ) );
111 if ( thePixelDigiSimLinkHandle->find(detid) == thePixelDigiSimLinkHandle->end() )
117 std::vector< Ref_Phase2TrackerDigi_ > theseHits = tempCluRef->getHits();
118 for (
unsigned int i = 0;
i < theseHits.size();
i++ )
123 clusterToTrackingParticleVectorMap.find( tempCluRef )->second.push_back( tempTPPtr );
134 std::vector< Ref_Phase2TrackerDigi_ > theseHits = tempCluRef->getHits();
135 for (
unsigned int i = 0;
i < theseHits.size();
i++ )
138 for ( iterSimLink = thisDigiSimLink.
data.begin();
139 iterSimLink != thisDigiSimLink.
data.end();
143 if ( static_cast<int>(iterSimLink->channel()) != static_cast<int>(theseHits.at(
i)->channel()) )
147 unsigned int curSimTrkId = iterSimLink->SimTrackId();
151 std::pair< unsigned int, EncodedEventId > thisUniqueId = std::make_pair( curSimTrkId, curSimEvId );
154 if ( simTrackUniqueToTPMap.find( thisUniqueId ) != simTrackUniqueToTPMap.end() )
159 clusterToTrackingParticleVectorMap.find( tempCluRef )->second.push_back( thisTrackingParticle );
162 if ( trackingParticleToClusterVectorMap.find( thisTrackingParticle ) == trackingParticleToClusterVectorMap.end() )
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 ) );
168 trackingParticleToClusterVectorMap.find( thisTrackingParticle )->second.push_back( tempCluRef );
175 clusterToTrackingParticleVectorMap.find( tempCluRef )->second.push_back( tempTPPtr );
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++ )
185 if ( theseClusterTrackingParticlePtrs.at(tpi).isNull() ==
false )
186 allOfThemAreNull =
false;
189 if ( allOfThemAreNull )
192 clusterToTrackingParticleVectorMap.erase( tempCluRef );
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();
206 std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > tempVector = iterMapToClean->second;
209 std::sort( tempVector.begin(), tempVector.end() );
210 tempVector.erase(
std::unique( tempVector.begin(), tempVector.end() ), tempVector.end() );
211 iterMapToClean->second = tempVector;
215 associationMapForOutput->setTTClusterToTrackingParticlesMap( clusterToTrackingParticleVectorMap );
216 associationMapForOutput->setTrackingParticleToTTClustersMap( trackingParticleToClusterVectorMap );
220 iEvent.
put(
std::move(associationMapForOutput), TTClustersInputTags.at(ncont1).instance() );
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.
const std::vector< SimTrack > & g4Tracks() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
def unique(seq, keepstr=True)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
NOTE: this is needed even if it seems not.
EncodedEventId eventId() const
Signal source, crossing number.
collection_type::const_iterator const_iterator
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)