CMS 3D CMS Logo

TTStubBuilder.cc
Go to the documentation of this file.
1 
14 
16 
17 template <>
23  for (const auto& module : inputEDstubs) {
25  DetId thisStackedDetId = module.id();
26  typename edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>::FastFiller outputFiller(outputEDstubs,
27  thisStackedDetId);
28 
31  DetId lowerDetid = thisStackedDetId + 1;
32  DetId upperDetid = thisStackedDetId + 2;
33 
35  edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> lowerClusters = (*clusterHandle)[lowerDetid];
36  edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> upperClusters = (*clusterHandle)[upperDetid];
37 
39  edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_>> theseStubs = inputEDstubs[thisStackedDetId];
40 
43  typename edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>>::const_iterator clusterIter;
44  for (const auto& stub : theseStubs) {
46  TTStub<Ref_Phase2TrackerDigi_> tempTTStub(stub.getDetId());
47 
50  lowerClusterToBeReplaced = stub.clusterRef(0);
52  upperClusterToBeReplaced = stub.clusterRef(1);
53 
54  bool lowerOK = false;
55  bool upperOK = false;
56 
57  for (clusterIter = lowerClusters.begin(); clusterIter != lowerClusters.end() && !lowerOK; ++clusterIter) {
58  if (clusterIter->getHits() == lowerClusterToBeReplaced->getHits()) {
59  tempTTStub.addClusterRef(edmNew::makeRefTo(clusterHandle, clusterIter));
60  lowerOK = true;
61  }
62  }
63 
64  for (clusterIter = upperClusters.begin(); clusterIter != upperClusters.end() && !upperOK; ++clusterIter) {
65  if (clusterIter->getHits() == upperClusterToBeReplaced->getHits()) {
66  tempTTStub.addClusterRef(edmNew::makeRefTo(clusterHandle, clusterIter));
67  upperOK = true;
68  }
69  }
70 
72  if (!lowerOK || !upperOK)
73  continue;
74 
76  tempTTStub.setRawBend(2. * stub.rawBend());
77  tempTTStub.setBendOffset(2. * stub.bendOffset());
78  tempTTStub.setBendBE(stub.bendBE());
79  tempTTStub.setModuleTypePS(stub.moduleTypePS());
80 
81  outputFiller.push_back(tempTTStub);
82 
83  }
84  }
85 }
86 
88 
89 template <>
91  //Retrieve tracker topology from geometry
92  edm::ESHandle<TrackerTopology> tTopoHandle = iSetup.getHandle(tTopoToken);
93  const TrackerTopology* const tTopo = tTopoHandle.product();
94  edm::ESHandle<TrackerGeometry> tGeomHandle = iSetup.getHandle(tGeomToken);
95  const TrackerGeometry* const theTrackerGeom = tGeomHandle.product();
96 
99  auto ttClusterDSVForOutputAcc = std::make_unique<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>>();
100  auto ttClusterDSVForOutputRej = std::make_unique<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>>();
102  auto ttStubDSVForOutputAccTemp = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
103  auto ttStubDSVForOutputRejTemp = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
105  auto ttStubDSVForOutputAcc = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
106  auto ttStubDSVForOutputRej = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
107 
110  iEvent.getByToken(clustersToken, clusterHandle);
111 
112  int nmod = -1;
113 
114  // Loop over all the tracker elements
115 
116  for (const auto& gd : theTrackerGeom->dets()) {
117  DetId detid = (*gd).geographicalId();
118  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
119  continue; // only run on OT
120  if (!tTopo->isLower(detid))
121  continue; // loop on the stacks: choose the lower sensor
122  DetId lowerDetid = detid;
123  DetId upperDetid = tTopo->partnerDetId(detid);
124  DetId stackDetid = tTopo->stack(detid);
125  bool isPS = (theTrackerGeom->getDetectorType(stackDetid) == TrackerGeometry::ModuleType::Ph2PSP);
126 
127  bool is10G_PS = false;
128 
129  // Determine if this module is a 10G transmission scheme module
130  //
131  // TO FIX: take this info from Tracker -> DTC cabling map.
132 
133  if (detid.subdetId() == StripSubdetector::TOB) {
134  if (tTopo->layer(detid) <= high_rate_max_layer)
135  is10G_PS = true;
136  } else if (detid.subdetId() == StripSubdetector::TID) {
137  if (tTopo->tidRing(detid) <= high_rate_max_ring[tTopo->tidWheel(detid) - 1])
138  is10G_PS = true;
139  }
140 
141  ++nmod;
142 
143  unsigned int maxStubs;
144  std::vector<std::pair<unsigned int, double>> bendMap;
145 
147  if (clusterHandle->find(lowerDetid) == clusterHandle->end() ||
148  clusterHandle->find(upperDetid) == clusterHandle->end())
149  continue;
150 
152  edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> lowerClusters = (*clusterHandle)[lowerDetid];
153  edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> upperClusters = (*clusterHandle)[upperDetid];
154 
157  if (lowerClusters.empty() || upperClusters.empty())
158  continue;
159 
161  std::vector<TTCluster<Ref_Phase2TrackerDigi_>> tempClusLowerAcc;
162  std::vector<TTCluster<Ref_Phase2TrackerDigi_>> tempClusLowerRej;
163  std::vector<TTCluster<Ref_Phase2TrackerDigi_>> tempClusUpperAcc;
164  std::vector<TTCluster<Ref_Phase2TrackerDigi_>> tempClusUpperRej;
165  std::vector<TTStub<Ref_Phase2TrackerDigi_>> tempStubAcc;
166  std::vector<TTStub<Ref_Phase2TrackerDigi_>> tempStubRej;
167  tempClusLowerAcc.clear();
168  tempClusLowerRej.clear();
169  tempClusUpperAcc.clear();
170  tempClusUpperRej.clear();
171  tempStubAcc.clear();
172  tempStubRej.clear();
173 
176  const int chipSize = isPS ? 120 : 127;
177  // No. of macro pixels along local y in each half of 2S module.
178  constexpr int numMacroPixels = 16;
179 
181  for (auto lowerClusterIter = lowerClusters.begin(); lowerClusterIter != lowerClusters.end(); ++lowerClusterIter) {
183  std::vector<TTStub<Ref_Phase2TrackerDigi_>> tempOutput;
184 
185  for (auto upperClusterIter = upperClusters.begin(); upperClusterIter != upperClusters.end(); ++upperClusterIter) {
187  TTStub<Ref_Phase2TrackerDigi_> tempTTStub(stackDetid);
188  tempTTStub.addClusterRef(edmNew::makeRefTo(clusterHandle, lowerClusterIter));
189  tempTTStub.addClusterRef(edmNew::makeRefTo(clusterHandle, upperClusterIter));
190  tempTTStub.setModuleTypePS(isPS);
191 
193  bool thisConfirmation = false;
194  int thisDisplacement = 999999;
195  int thisOffset = 0;
196  float thisHardBend = 0;
197 
198  theStubFindingAlgoHandle->PatternHitCorrelation(
199  thisConfirmation, thisDisplacement, thisOffset, thisHardBend, tempTTStub);
200  // Removed real offset. Ivan Reid 10/2019
201 
203  if (thisConfirmation) {
204  tempTTStub.setRawBend(thisDisplacement);
205  tempTTStub.setBendOffset(thisOffset);
206  tempTTStub.setBendBE(thisHardBend);
207  tempOutput.push_back(tempTTStub);
208  }
209  }
210 
213  if (ForbidMultipleStubs && tempOutput.size() > 1 + static_cast<unsigned int>(isPS)) {
215  std::sort(tempOutput.begin(), tempOutput.end(), TTStubBuilder<Ref_Phase2TrackerDigi_>::SortStubsBend);
216 
218  typename std::vector<TTStub<Ref_Phase2TrackerDigi_>>::iterator tempIter = tempOutput.begin();
219  ++tempIter;
220  if (isPS)
221  ++tempIter; // PS module case
223 
225  tempOutput.erase(tempIter, tempOutput.end());
226  }
227 
230 
232 
233  for (auto& tempTTStub : tempOutput) {
235  if (not applyFE) // No dynamic inefficiencies
236  {
238  tempClusLowerAcc.push_back(*(tempTTStub.clusterRef(0)));
239  tempClusUpperAcc.push_back(*(tempTTStub.clusterRef(1)));
240  tempStubAcc.push_back(tempTTStub);
241  } else {
242  bool FEreject = false;
243 
245  MeasurementPoint mp0 = tempTTStub.clusterRef(0)->findAverageLocalCoordinates();
246  int seg = static_cast<int>(mp0.y()); // Identifies which half of module
247  if (isPS)
248  seg = seg / numMacroPixels;
250  int chip = 1000 * nmod + 10 * int(tempTTStub.innerClusterPosition() / chipSize) + seg;
252  int CIC_chip = 10 * nmod + seg;
253 
254  // First look is the stub is passing trough the very front end (CBC/MPA)
255  maxStubs = isPS ? maxStubs_PS : maxStubs_2S;
256 
257  if (isPS) // MPA
258  {
259  if (moduleStubs_MPA[chip] < int(maxStubs)) {
260  moduleStubs_MPA[chip]++;
261  } else {
262  FEreject = true;
263  }
264  } else // CBC
265  {
266  if (moduleStubs_CBC[chip] < int(maxStubs)) {
267  moduleStubs_CBC[chip]++;
268  } else {
269  FEreject = true;
270  }
271  }
272 
273  // End of the MPA/CBC loop
274 
275  // If the stub has been already thrown out, there is no reason to include it into the CIC stream
276  // We put it in the rejected container, flagged with offset to indicate reason.
277 
278  if (FEreject) {
279  tempTTStub.setRawBend(CBCFailOffset + 2. * tempTTStub.rawBend());
280  tempTTStub.setBendOffset(CBCFailOffset + 2. * tempTTStub.bendOffset());
281  tempClusLowerRej.push_back(*(tempTTStub.clusterRef(0)));
282  tempClusUpperRej.push_back(*(tempTTStub.clusterRef(1)));
283  tempStubRej.push_back(tempTTStub);
284  continue;
285  }
286 
287  maxStubs = isPS ? maxStubs_PS_CIC_5 : maxStubs_2S_CIC_5;
288 
289  if (is10G_PS)
290  maxStubs = maxStubs_PS_CIC_10;
291 
292  bool CIC_reject = true;
293 
294  moduleStubs_CIC[CIC_chip].push_back(tempTTStub); //We temporarily add the new stub
295 
296  if (moduleStubs_CIC[CIC_chip].size() <= maxStubs) {
297  tempClusLowerAcc.push_back(*(tempTTStub.clusterRef(0)));
298  tempClusUpperAcc.push_back(*(tempTTStub.clusterRef(1)));
299  tempStubAcc.push_back(tempTTStub); // The stub is kept
300 
301  } else {
305 
307  bendMap.clear();
308  bendMap.reserve(moduleStubs_CIC[CIC_chip].size());
309 
310  for (unsigned int i = 0; i < moduleStubs_CIC[CIC_chip].size(); ++i) {
311  bendMap.emplace_back(i, moduleStubs_CIC[CIC_chip].at(i).bendFE());
312  }
313 
315 
316  // bendMap contains link over all the stubs included in moduleStubs_CIC[CIC_chip]
317 
318  for (unsigned int i = 0; i < maxStubs; ++i) {
319  // The stub we have just added is amongst those with smallest |bend| so keep it.
320  if (bendMap[i].first == moduleStubs_CIC[CIC_chip].size() - 1) {
321  CIC_reject = false;
322  }
323  }
324 
325  if (CIC_reject) // The stub added does not pass the cut
326  {
327  tempTTStub.setRawBend(CICFailOffset + 2. * tempTTStub.rawBend());
328  tempTTStub.setBendOffset(CICFailOffset + 2. * tempTTStub.bendOffset());
329  tempClusLowerRej.push_back(*(tempTTStub.clusterRef(0)));
330  tempClusUpperRej.push_back(*(tempTTStub.clusterRef(1)));
331  tempStubRej.push_back(tempTTStub);
332  } else {
333  tempClusLowerAcc.push_back(*(tempTTStub.clusterRef(0)));
334  tempClusUpperAcc.push_back(*(tempTTStub.clusterRef(1)));
335  tempStubAcc.push_back(tempTTStub); // The stub is added
336  }
337  }
338  }
339  }
340  }
341 
343  if (not tempClusLowerAcc.empty())
344  this->fill(*ttClusterDSVForOutputAcc, lowerDetid, tempClusLowerAcc);
345  if (not tempClusLowerRej.empty())
346  this->fill(*ttClusterDSVForOutputRej, lowerDetid, tempClusLowerRej);
347  if (not tempClusUpperAcc.empty())
348  this->fill(*ttClusterDSVForOutputAcc, upperDetid, tempClusUpperAcc);
349  if (not tempClusUpperRej.empty())
350  this->fill(*ttClusterDSVForOutputRej, upperDetid, tempClusUpperRej);
351  if (not tempStubAcc.empty())
352  this->fill(*ttStubDSVForOutputAccTemp, stackDetid, tempStubAcc);
353  if (not tempStubRej.empty())
354  this->fill(*ttStubDSVForOutputRejTemp, stackDetid, tempStubRej);
355 
356  }
357 
358  // Store the subset of clusters associated to stubs.
359 
361  iEvent.put(std::move(ttClusterDSVForOutputAcc), "ClusterAccepted");
363  iEvent.put(std::move(ttClusterDSVForOutputRej), "ClusterRejected");
364 
368 
369  this->updateStubs(ttClusterAccHandle, *ttStubDSVForOutputAccTemp, *ttStubDSVForOutputAcc);
370  this->updateStubs(ttClusterRejHandle, *ttStubDSVForOutputRejTemp, *ttStubDSVForOutputRej);
371 
373  iEvent.put(std::move(ttStubDSVForOutputAcc), "StubAccepted");
374  iEvent.put(std::move(ttStubDSVForOutputRej), "StubRejected");
375 
376  ++ievt;
377  if (ievt % 8 == 0)
378  moduleStubs_CIC.clear(); // Everything is cleared up after 8BX
379  if (ievt % 2 == 0)
380  moduleStubs_MPA.clear(); // Everything is cleared up after 2BX
381  moduleStubs_CBC.clear(); // Everything is cleared up after everyBX
382 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
Point2DBase
Definition: Point2DBase.h:9
mps_fire.i
i
Definition: mps_fire.py:428
TrackerTopology::isLower
bool isLower(const DetId &id) const
Definition: TrackerTopology.cc:195
TTStub::setRawBend
void setRawBend(int aDisplacement)
Definition: TTStub.h:170
TrackerTopology
Definition: TrackerTopology.h:16
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:704
TTStubBuilder::updateStubs
void updateStubs(const edm::OrphanHandle< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ >>> &clusterHandle, const edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ >> &inputEDstubs, edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ >> &outputEDstubs) const
Update output stubs with Refs to cluster collection that is associated to stubs.
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
TrackerTopology::stack
uint32_t stack(const DetId &id) const
Definition: TrackerTopology.cc:104
auxiliaryParams.maxStubs
maxStubs
Definition: auxiliaryParams.py:44
TTStub::setModuleTypePS
void setModuleTypePS(bool isPSModule)
set whether this is a PS module or not;
Definition: TTStub.h:190
TTStub::setBendOffset
void setBendOffset(int anOffset)
Definition: TTStub.h:180
TrackerGeometry::getDetectorType
ModuleType getDetectorType(DetId) const
Definition: TrackerGeometry.cc:247
edm::Handle
Definition: AssociativeIterator.h:50
TrackerTopology::tidRing
unsigned int tidRing(const DetId &id) const
Definition: TrackerTopology.h:218
TTStubBuilder
Plugin to load the Stub finding algorithm and produce the collection of Stubs that goes in the event ...
Definition: TTStubBuilder.h:45
edm::Ref
Definition: AssociativeIterator.h:58
TrackerTopology::tidWheel
unsigned int tidWheel(const DetId &id) const
Definition: TrackerTopology.h:201
DetId
Definition: DetId.h:17
edmNew::DetSet::end
iterator end()
Definition: DetSetNew.h:56
TTStub::addClusterRef
void addClusterRef(edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > aTTCluster)
Add a cluster reference, depending on which stack member it is on (inner = 0, outer = 1)
Definition: TTStub.h:156
TTStub::setBendBE
void setBendBE(float aBend)
setBendBE(): In HALF-STRIP units! Reduced resolution in BE boards. Rename of setHardwareBend()
Definition: TTStub.h:185
TTStub
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
edm::ESHandle< TrackerTopology >
edmNew::DetSet
Definition: DetSetNew.h:22
TrackerTopology::partnerDetId
DetId partnerDetId(const DetId &id) const
Definition: TrackerTopology.cc:233
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
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
TTStubBuilder::FEreject
FEreject
Definition: TTStubBuilder.h:54
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
PV2DBase::y
T y() const
Definition: PV2DBase.h:44
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
edmNew::DetSetVector::push_back
Item & push_back(id_type iid)
Definition: DetSetVectorNew.h:482
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
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
TTStubBuilder::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
TTStubBuilder.h
callgraph.module
module
Definition: callgraph.py:61
edmNew::DetSetVector
Definition: DetSetNew.h:13
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::OrphanHandle
Definition: EDProductfwd.h:39
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
TTCluster
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
edm::Event
Definition: Event.h:73
edmNew::DetSet::empty
bool empty() const
Definition: DetSetNew.h:70
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
TrackerGeometry::ModuleType::Ph2PSP
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
TrackerGeometry
Definition: TrackerGeometry.h:14