CMS 3D CMS Logo

TTClusterAssociator.cc
Go to the documentation of this file.
1 
11 
13 template <>
16  if (iEvent.isRealData())
17  return;
18 
20  iEvent.getByToken(digisimLinkToken, thePixelDigiSimLinkHandle);
21 
23 
24  iEvent.getByToken(tpToken, TrackingParticleHandle);
25 
26  // const TrackerTopology* const tTopo = theTrackerTopology.product();
27  const TrackerGeometry* const theTrackerGeom = theTrackerGeometry.product();
28 
31  std::map<std::pair<unsigned int, EncodedEventId>, edm::Ptr<TrackingParticle>> simTrackUniqueToTPMap;
32  simTrackUniqueToTPMap.clear();
33 
34  if (!TrackingParticleHandle->empty()) {
36  unsigned int tpCnt = 0;
37  std::vector<TrackingParticle>::const_iterator iterTPart;
38  for (iterTPart = TrackingParticleHandle->begin(); iterTPart != TrackingParticleHandle->end(); ++iterTPart) {
40  edm::Ptr<TrackingParticle> tempTPPtr(TrackingParticleHandle, tpCnt++);
41 
43  EncodedEventId eventId = EncodedEventId(tempTPPtr->eventId());
44 
46  std::vector<SimTrack>::const_iterator iterSimTrack;
47  for (iterSimTrack = tempTPPtr->g4Tracks().begin(); iterSimTrack != tempTPPtr->g4Tracks().end(); ++iterSimTrack) {
49  std::pair<unsigned int, EncodedEventId> simTrackUniqueId(iterSimTrack->trackId(), eventId);
50  simTrackUniqueToTPMap.insert(std::make_pair(simTrackUniqueId, tempTPPtr));
51  }
52  }
53  }
54 
56 
57  int ncont1 = 0;
58 
59  for (auto iTag = TTClustersTokens.begin(); iTag != TTClustersTokens.end(); iTag++) {
61  auto associationMapForOutput = std::make_unique<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>>();
62 
65 
66  iEvent.getByToken(*iTag, TTClusterHandle);
67 
69  std::map<edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>, TTCluster<Ref_Phase2TrackerDigi_>>,
70  std::vector<edm::Ptr<TrackingParticle>>>
71  clusterToTrackingParticleVectorMap;
72  std::map<edm::Ptr<TrackingParticle>,
73  std::vector<
75  trackingParticleToClusterVectorMap;
76  clusterToTrackingParticleVectorMap.clear();
77  trackingParticleToClusterVectorMap.clear();
78 
80  for (auto gd = theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++) {
81  DetId detid = (*gd)->geographicalId();
82  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
83  continue; // only run on OT
84 
85  if (TTClusterHandle->find(detid) == TTClusterHandle->end())
86  continue;
87 
90 
91  for (auto contentIter = clusters.begin(); contentIter != clusters.end(); ++contentIter) {
94  edmNew::makeRefTo(TTClusterHandle, contentIter);
95 
97  if (clusterToTrackingParticleVectorMap.find(tempCluRef) == clusterToTrackingParticleVectorMap.end()) {
98  std::vector<edm::Ptr<TrackingParticle>> tpVector;
99  tpVector.clear();
100  clusterToTrackingParticleVectorMap.insert(std::make_pair(tempCluRef, tpVector));
101  }
102 
105  if (thePixelDigiSimLinkHandle->find(detid) == thePixelDigiSimLinkHandle->end()) {
108 
110  std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
111  for (unsigned int i = 0; i < theseHits.size(); i++) {
114  edm::Ptr<TrackingParticle> tempTPPtr; // = new edm::Ptr< TrackingParticle >();
115  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
116  }
117 
119  continue;
120  }
121 
122  edm::DetSet<PixelDigiSimLink> thisDigiSimLink = (*(thePixelDigiSimLinkHandle))[detid];
124 
126  std::vector<Ref_Phase2TrackerDigi_> theseHits = tempCluRef->getHits();
127  for (unsigned int i = 0; i < theseHits.size(); i++) {
129  for (iterSimLink = thisDigiSimLink.data.begin(); iterSimLink != thisDigiSimLink.data.end(); iterSimLink++) {
131  if (static_cast<int>(iterSimLink->channel()) != static_cast<int>(theseHits.at(i)->channel()))
132  continue;
133 
135  unsigned int curSimTrkId = iterSimLink->SimTrackId();
136  EncodedEventId curSimEvId = iterSimLink->eventId();
137 
139  std::pair<unsigned int, EncodedEventId> thisUniqueId = std::make_pair(curSimTrkId, curSimEvId);
140 
142  if (simTrackUniqueToTPMap.find(thisUniqueId) != simTrackUniqueToTPMap.end()) {
143  edm::Ptr<TrackingParticle> thisTrackingParticle = simTrackUniqueToTPMap.find(thisUniqueId)->second;
144 
146  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(thisTrackingParticle);
147 
149  if (trackingParticleToClusterVectorMap.find(thisTrackingParticle) ==
150  trackingParticleToClusterVectorMap.end()) {
151  std::vector<
153  clusterVector;
154  clusterVector.clear();
155  trackingParticleToClusterVectorMap.insert(std::make_pair(thisTrackingParticle, clusterVector));
156  }
157  trackingParticleToClusterVectorMap.find(thisTrackingParticle)
158  ->second.push_back(tempCluRef);
159  } else {
161 
162  edm::Ptr<TrackingParticle> tempTPPtr; // = new edm::Ptr< TrackingParticle >();
163  clusterToTrackingParticleVectorMap.find(tempCluRef)->second.push_back(tempTPPtr);
164  }
165  }
166  }
167 
169  std::vector<edm::Ptr<TrackingParticle>> theseClusterTrackingParticlePtrs =
170  clusterToTrackingParticleVectorMap.find(tempCluRef)->second;
171  bool allOfThemAreNull = true;
172  for (unsigned int tpi = 0; tpi < theseClusterTrackingParticlePtrs.size() && allOfThemAreNull; tpi++) {
173  if (theseClusterTrackingParticlePtrs.at(tpi).isNull() == false)
174  allOfThemAreNull = false;
175  }
176 
177  if (allOfThemAreNull) {
179  clusterToTrackingParticleVectorMap.erase(tempCluRef);
180  }
181  }
182  }
183 
186  std::map<edm::Ptr<TrackingParticle>,
187  std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>,
188  TTCluster<Ref_Phase2TrackerDigi_>>>>::iterator iterMapToClean;
189  for (iterMapToClean = trackingParticleToClusterVectorMap.begin();
190  iterMapToClean != trackingParticleToClusterVectorMap.end();
191  ++iterMapToClean) {
193  std::vector<edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>, TTCluster<Ref_Phase2TrackerDigi_>>>
194  tempVector = iterMapToClean->second;
195 
197  std::sort(tempVector.begin(), tempVector.end());
198  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
199  iterMapToClean->second = tempVector;
200  }
201 
203  associationMapForOutput->setTTClusterToTrackingParticlesMap(clusterToTrackingParticleVectorMap);
204  associationMapForOutput->setTrackingParticleToTTClustersMap(trackingParticleToClusterVectorMap);
205 
207  // iEvent.put( associationMapForOutput, (*iTag).instance() );
208  iEvent.put(std::move(associationMapForOutput), TTClustersInputTags.at(ncont1).instance());
209 
210  ++ncont1;
211 
212  }
213 }
mps_fire.i
i
Definition: mps_fire.py:355
edm::DetSet
Definition: DetSet.h:23
TTClusterAssociator::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
edmNew::makeRefTo
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)
Definition: DetSetVectorNew.h:735
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref
Definition: AssociativeIterator.h:58
EncodedEventId
Definition: EncodedEventId.h:11
DetId
Definition: DetId.h:17
edmNew::DetSet
Definition: DetSetNew.h:22
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
TrackingParticle::eventId
EncodedEventId eventId() const
Signal source, crossing number.
Definition: TrackingParticle.h:72
edm::Ptr< TrackingParticle >
eostools.move
def move(src, dest)
Definition: eostools.py:511
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
edm::DetSet::data
collection_type data
Definition: DetSet.h:80
TTCluster
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
edm::Event
Definition: Event.h:73
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
TTClusterAssociator.h
TrackerGeometry
Definition: TrackerGeometry.h:14
TrackingParticle::g4Tracks
const std::vector< SimTrack > & g4Tracks() const
Definition: TrackingParticle.h:89
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31