CMS 3D CMS Logo

TTTrackAssociator.cc
Go to the documentation of this file.
1 
11 
13 template <>
16  if (iEvent.isRealData())
17  return;
18 
21  iEvent.getByToken(TTClusterTruthToken, TTClusterAssociationMapHandle);
23  iEvent.getByToken(TTStubTruthToken, TTStubAssociationMapHandle);
24 
25  int ncont1 = 0;
26 
28  for (auto iTag = TTTracksTokens.begin(); iTag != TTTracksTokens.end(); iTag++) {
30  auto associationMapForOutput = std::make_unique<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>();
31 
34  iEvent.getByToken(*iTag, TTTrackHandle);
35 
37  std::map<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>, edm::Ptr<TrackingParticle>> trackToTrackingParticleMap;
38  std::map<edm::Ptr<TrackingParticle>, std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>>>
39  trackingParticleToTrackVectorMap;
40  trackToTrackingParticleMap.clear();
41  trackingParticleToTrackVectorMap.clear();
42 
43  // Start the loop on tracks
44 
45  unsigned int j = 0;
46  typename std::vector<TTTrack<Ref_Phase2TrackerDigi_>>::const_iterator inputIter;
47  for (inputIter = TTTrackHandle->begin(); inputIter != TTTrackHandle->end(); ++inputIter) {
49  edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>> tempTrackPtr(TTTrackHandle, j++);
50 
52  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
53  theseStubs = tempTrackPtr->getStubRefs();
54 
56  std::map<const TrackingParticle*, edm::Ptr<TrackingParticle>> auxMap;
57  auxMap.clear();
58  int mayCombinUnknown = 0;
59 
61  for (unsigned int is = 0; is < theseStubs.size(); is++) {
62  // std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > theseClusters = theseStubs.at(is)->getClusterRefs();
63  for (unsigned int ic = 0; ic < 2; ic++) {
64  std::vector<edm::Ptr<TrackingParticle>> tempTPs =
65  TTClusterAssociationMapHandle->findTrackingParticlePtrs(theseStubs.at(is)->clusterRef(ic));
66  for (unsigned int itp = 0; itp < tempTPs.size(); itp++) // List of TPs linked to stub clusters
67  {
68  edm::Ptr<TrackingParticle> testTP = tempTPs.at(itp);
69 
70  if (testTP.isNull()) // No TP linked to this cluster
71  continue;
72 
74  if (trackingParticleToTrackVectorMap.find(testTP) == trackingParticleToTrackVectorMap.end()) {
75  std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>> trackVector;
76  trackVector.clear();
77  trackingParticleToTrackVectorMap.insert(std::make_pair(testTP, trackVector));
78  }
79  trackingParticleToTrackVectorMap.find(testTP)->second.push_back(tempTrackPtr);
80 
82  if (auxMap.find(testTP.get()) == auxMap.end()) {
83  auxMap.insert(std::make_pair(testTP.get(), testTP));
84  }
85  }
86  }
87 
89  if (TTStubAssociationMapHandle->isUnknown(theseStubs.at(is)))
90  ++mayCombinUnknown;
91 
92  }
93 
96  if (mayCombinUnknown >= 2)
97  continue;
98 
103 
104  std::vector<const TrackingParticle*> tpInAllStubs;
105 
106  std::map<const TrackingParticle*, edm::Ptr<TrackingParticle>>::const_iterator iterAuxMap;
107  for (iterAuxMap = auxMap.begin(); iterAuxMap != auxMap.end(); ++iterAuxMap) {
109  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
110  tempStubs = TTStubAssociationMapHandle->findTTStubRefs(iterAuxMap->second);
111 
112  int nnotfound = 0;
113  //bool allFound = true;
115  // for ( unsigned int js = 0; js < theseStubs.size() && allFound; js++ )
116  for (unsigned int js = 0; js < theseStubs.size(); js++) {
121  if (std::find(tempStubs.begin(), tempStubs.end(), theseStubs.at(js)) == tempStubs.end()) {
122  // allFound = false;
123  ++nnotfound;
124  }
125  }
126 
129  if (nnotfound > 1)
130  //if (!allFound)
131  continue;
132 
136  tpInAllStubs.push_back(iterAuxMap->first);
137  }
138 
140  std::sort(tpInAllStubs.begin(), tpInAllStubs.end());
141  tpInAllStubs.erase(std::unique(tpInAllStubs.begin(), tpInAllStubs.end()), tpInAllStubs.end());
142  unsigned int nTPs = tpInAllStubs.size();
143 
146  if (nTPs != 1)
147  continue;
148 
151  trackToTrackingParticleMap.insert(std::make_pair(tempTrackPtr, auxMap.find(tpInAllStubs.at(0))->second));
152 
153  }
154 
157  typename std::map<edm::Ptr<TrackingParticle>, std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>>>::iterator
158  iterMapToClean;
159  for (iterMapToClean = trackingParticleToTrackVectorMap.begin();
160  iterMapToClean != trackingParticleToTrackVectorMap.end();
161  ++iterMapToClean) {
163  std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>> tempVector = iterMapToClean->second;
164 
166  std::sort(tempVector.begin(), tempVector.end());
167  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
168 
169  iterMapToClean->second = tempVector;
170  }
171 
173  edm::RefProd<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> theStubAssoMap(TTStubAssociationMapHandle);
174 
176  associationMapForOutput->setTTTrackToTrackingParticleMap(trackToTrackingParticleMap);
177  associationMapForOutput->setTrackingParticleToTTTracksMap(trackingParticleToTrackVectorMap);
178  associationMapForOutput->setTTStubAssociationMap(theStubAssoMap);
179  associationMapForOutput->setAllowOneFalse2SStub(TTTrackAllowOneFalse2SStub);
180 
182  iEvent.put(std::move(associationMapForOutput), TTTracksInputTags.at(ncont1).instance());
183 
184  ++ncont1;
185  }
186 }
edm::RefProd
Definition: EDProductfwd.h:25
TTTrackAssociator::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
edm::Ptr::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle
Definition: AssociativeIterator.h:50
TTStub
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
TTTrackAssociation_cfi.TTTrackAllowOneFalse2SStub
TTTrackAllowOneFalse2SStub
Definition: TTTrackAssociation_cfi.py:9
TTTrackAssociator.h
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
edm::Ptr< TrackingParticle >
eostools.move
def move(src, dest)
Definition: eostools.py:511
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
edm::Ptr::isNull
bool isNull() const
Checks for null.
Definition: Ptr.h:142