CMS 3D CMS Logo

TTStubAssociator.cc
Go to the documentation of this file.
1 
11 
13 template <>
16  if (iEvent.isRealData())
17  return;
18 
20  if (ttClusterTruthInputTags_.size() != ttStubsInputTags_.size()) {
21  edm::LogError("TTStubAsso ") << "E R R O R! the InputTag vectors have different size!";
22  return;
23  }
24 
25  int ncont1 = 0;
26 
27  const TrackerGeometry* const theTrackerGeom = theTrackerGeometry_.product();
28  const TrackerTopology* const tTopo = theTrackerTopology_.product();
29 
31 
32  for (const auto& iTag : ttStubsTokens_) {
34  auto associationMapForOutput = std::make_unique<TTStubAssociationMap<Ref_Phase2TrackerDigi_>>();
35 
37  edm::Handle<TTStubDetSetVec> ttStubHandle;
38  iEvent.getByToken(iTag, ttStubHandle);
39 
42  iEvent.getByToken(ttClusterTruthTokens_.at(ncont1), ttClusterAssociationMapHandle);
43 
45  std::map<TTStubRef, TrackingParticlePtr> stubToTrackingParticleMap;
46  std::map<TrackingParticlePtr, std::vector<TTStubRef>> trackingParticleToStubVectorMap;
47 
49 
50  if (not ttStubHandle->empty()) {
51  for (const auto& gd : theTrackerGeom->dets()) {
52  DetId detid = gd->geographicalId();
53  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
54  continue; // only run on OT
55 
56  if (!tTopo->isLower(detid))
57  continue; // loop on the stacks: choose the lower arbitrarily
58 
59  DetId stackDetid = tTopo->stack(detid); // Stub module detid
60 
61  if (ttStubHandle->find(stackDetid) == ttStubHandle->end())
62  continue;
63 
65  edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_>> stubs = (*ttStubHandle)[stackDetid];
66 
67  for (auto contentIter = stubs.begin(); contentIter != stubs.end(); ++contentIter) {
69  TTStubRef tempStubRef = edmNew::makeRefTo(ttStubHandle, contentIter);
70 
72  for (unsigned int ic = 0; ic < 2; ic++) {
73  const std::vector<TrackingParticlePtr>& tempTPs =
74  ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(ic));
75 
76  for (const TrackingParticlePtr& testTP : tempTPs) {
77  if (testTP.isNull())
78  continue;
79 
81  if (trackingParticleToStubVectorMap.find(testTP) == trackingParticleToStubVectorMap.end()) {
82  std::vector<TTStubRef> stubVector;
83  trackingParticleToStubVectorMap.emplace(testTP, stubVector);
84  }
85  trackingParticleToStubVectorMap.find(testTP)->second.push_back(tempStubRef);
86  }
87  }
88 
92  if (ttClusterAssociationMapHandle->isUnknown(tempStubRef->clusterRef(0)) ||
93  ttClusterAssociationMapHandle->isUnknown(tempStubRef->clusterRef(1))) {
97  continue;
98  } else {
102  if (ttClusterAssociationMapHandle->isGenuine(tempStubRef->clusterRef(0)) &&
103  ttClusterAssociationMapHandle->isGenuine(tempStubRef->clusterRef(1))) {
107  if (ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0)).get() ==
108  ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(1)).get()) {
110  const TrackingParticlePtr& testTP =
111  ttClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0));
112 
115  stubToTrackingParticleMap.emplace(tempStubRef, testTP);
116 
118  continue;
119  } else {
121  continue;
122  }
123  }
124  else {
126  TrackingParticle* prevTPAddress = nullptr;
127  unsigned int whichTP = 0;
128 
129  const std::vector<TrackingParticlePtr>& trackingParticles0 =
130  ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(0));
131  const std::vector<TrackingParticlePtr>& trackingParticles1 =
132  ttClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(1));
133 
134  bool escape = false;
135 
136  for (unsigned int i = 0; i < trackingParticles0.size() && !escape; i++) {
138  if (trackingParticles0.at(i).isNull())
139  continue;
140 
141  for (unsigned int k = 0; k < trackingParticles1.size() && !escape; k++) {
143  if (trackingParticles1.at(k).isNull())
144  continue;
145 
146  if (trackingParticles0.at(i).get() == trackingParticles1.at(k).get()) {
148  if (prevTPAddress == nullptr) {
149  prevTPAddress = const_cast<TrackingParticle*>(trackingParticles1.at(k).get());
150  whichTP = k;
151  }
152 
155  if (prevTPAddress != const_cast<TrackingParticle*>(trackingParticles1.at(k).get())) {
156  escape = true;
157  continue;
158  }
159  }
160  }
161  }
162 
165  if (escape)
166  continue;
167 
168  if (prevTPAddress == nullptr) {
170  continue;
171  } else {
176  TrackingParticlePtr testTP = trackingParticles1.at(whichTP);
177 
180  stubToTrackingParticleMap.emplace(tempStubRef, testTP);
181 
183  continue;
184  }
185  }
186  }
187  }
188  }
189  }
190 
193  for (auto& p : trackingParticleToStubVectorMap) {
195  std::vector<TTStubRef>& tempVector = p.second;
196 
198  std::sort(tempVector.begin(), tempVector.end());
199  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
200  }
201 
203  edm::RefProd<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>> theCluAssoMap(ttClusterAssociationMapHandle);
204 
206  associationMapForOutput->setTTStubToTrackingParticleMap(stubToTrackingParticleMap);
207  associationMapForOutput->setTrackingParticleToTTStubsMap(trackingParticleToStubVectorMap);
208  associationMapForOutput->setTTClusterAssociationMap(theCluAssoMap);
209 
211  iEvent.put(std::move(associationMapForOutput), ttStubsInputTags_.at(ncont1).instance());
212 
213  ++ncont1;
214  }
215 }
edm::RefProd
Definition: EDProductfwd.h:25
mps_fire.i
i
Definition: mps_fire.py:428
TTStubAssociator.h
TrackerTopology::isLower
bool isLower(const DetId &id) const
Definition: TrackerTopology.cc:195
TrackerTopology
Definition: TrackerTopology.h:16
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:689
TrackerTopology::stack
uint32_t stack(const DetId &id) const
Definition: TrackerTopology.cc:104
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref
Definition: AssociativeIterator.h:58
DetId
Definition: DetId.h:17
edmNew::DetSet::end
iterator end()
Definition: DetSetNew.h:56
TrackingParticle
Monte Carlo truth information used for tracking validation.
Definition: TrackingParticle.h:29
edmNew::DetSet
Definition: DetSetNew.h:22
dqmdumpme.k
k
Definition: dqmdumpme.py:60
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
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
iEvent
int iEvent
Definition: GenABIO.cc:224
edmNew::DetSet::begin
iterator begin()
Definition: DetSetNew.h:54
edm::EventSetup
Definition: EventSetup.h:58
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
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::Event
Definition: Event.h:73
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
TTStubAssociator::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
TrackerGeometry
Definition: TrackerGeometry.h:14