CMS 3D CMS Logo

TTStubBuilder.cc
Go to the documentation of this file.
1 
13 
15 template <>
17  //Retrieve tracker topology from geometry
19  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
20  const TrackerTopology* const tTopo = tTopoHandle.product();
22  iSetup.get<TrackerDigiGeometryRecord>().get(tGeomHandle);
23  const TrackerGeometry* const theTrackerGeom = tGeomHandle.product();
24 
26  auto ttClusterDSVForOutput = std::make_unique<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>>();
27  auto ttStubDSVForOutputTemp = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
28  auto ttStubDSVForOutputAccepted = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
29  auto ttStubDSVForOutputRejected = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
30 
31  static constexpr int CBCFailOffset = 500;
32  static constexpr int CICFailOffset = 1000;
33 
36  iEvent.getByToken(clustersToken, clusterHandle);
37 
38  int nmod = -1;
39 
40  // Loop over all the tracker elements
41 
42  // for (auto gd=theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++)
43  for (const auto& gd : theTrackerGeom->dets()) {
44  DetId detid = (*gd).geographicalId();
45  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
46  continue; // only run on OT
47  if (!tTopo->isLower(detid))
48  continue; // loop on the stacks: choose the lower arbitrarily
49  DetId lowerDetid = detid;
50  DetId upperDetid = tTopo->partnerDetId(detid);
51  DetId stackDetid = tTopo->stack(detid);
52  bool isPS = (theTrackerGeom->getDetectorType(stackDetid) == TrackerGeometry::ModuleType::Ph2PSP);
53 
54  bool is10G_PS = false;
55 
56  // Determine if this module is a 10G transmission scheme module
57  //
58  // sviret comment (221217): this info should be made available in conddb at some point
59  // not in TrackerTopology as some modules may switch between 10G and 5G transmission
60  // schemes during running period
61 
62  if (detid.subdetId() == StripSubdetector::TOB) {
63  if (tTopo->layer(detid) == 1)
64  is10G_PS = true;
65  } else if (detid.subdetId() == StripSubdetector::TID) {
66  if (tTopo->tidRing(detid) <= high_rate_max_ring[tTopo->tidWheel(detid) - 1])
67  is10G_PS = true;
68  }
69 
70  ++nmod;
71 
72  unsigned int maxStubs;
73  std::vector<std::pair<unsigned int, double>> bendMap;
74 
76  if (clusterHandle->find(lowerDetid) == clusterHandle->end() ||
77  clusterHandle->find(upperDetid) == clusterHandle->end())
78  continue;
79 
81  edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> lowerClusters = (*clusterHandle)[lowerDetid];
82  edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> upperClusters = (*clusterHandle)[upperDetid];
83 
87  if (lowerClusters.empty() || upperClusters.empty())
88  continue;
89 
91  std::vector<TTCluster<Ref_Phase2TrackerDigi_>> tempInner;
92  std::vector<TTCluster<Ref_Phase2TrackerDigi_>> tempOuter;
93  std::vector<TTStub<Ref_Phase2TrackerDigi_>> tempAccepted;
94  tempInner.clear();
95  tempOuter.clear();
96  tempAccepted.clear();
97 
99  int chipSize = 127;
100  if (isPS)
101  chipSize = 120;
102 
104  for (auto lowerClusterIter = lowerClusters.begin(); lowerClusterIter != lowerClusters.end(); ++lowerClusterIter) {
107  std::vector<TTStub<Ref_Phase2TrackerDigi_>> tempOutput;
108 
109  for (auto upperClusterIter = upperClusters.begin(); upperClusterIter != upperClusters.end(); ++upperClusterIter) {
111  TTStub<Ref_Phase2TrackerDigi_> tempTTStub(stackDetid);
112  tempTTStub.addClusterRef(edmNew::makeRefTo(clusterHandle, lowerClusterIter));
113  tempTTStub.addClusterRef(edmNew::makeRefTo(clusterHandle, upperClusterIter));
114  tempTTStub.setModuleTypePS(isPS);
115 
117  bool thisConfirmation = false;
118  int thisDisplacement = 999999;
119  int thisOffset = 0;
120  float thisHardBend = 0;
121 
122  theStubFindingAlgoHandle->PatternHitCorrelation(
123  thisConfirmation, thisDisplacement, thisOffset, thisHardBend, tempTTStub);
124  // Removed real offset. Ivan Reid 10/2019
125 
127  if (thisConfirmation) {
128  tempTTStub.setRawBend(thisDisplacement);
129  tempTTStub.setBendOffset(thisOffset);
130  tempTTStub.setBendBE(thisHardBend);
131  tempOutput.push_back(tempTTStub);
132  }
133  }
134 
137  if (ForbidMultipleStubs && tempOutput.size() > 1) {
139  std::sort(tempOutput.begin(), tempOutput.end(), TTStubBuilder<Ref_Phase2TrackerDigi_>::SortStubsBend);
140 
142  typename std::vector<TTStub<Ref_Phase2TrackerDigi_>>::iterator tempIter = tempOutput.begin();
143  ++tempIter;
144 
146 
148  tempOutput.erase(tempIter, tempOutput.end());
149  }
150 
153 
155  for (unsigned int iTempStub = 0; iTempStub < tempOutput.size(); ++iTempStub) {
157  const TTStub<Ref_Phase2TrackerDigi_>& tempTTStub = tempOutput[iTempStub];
158 
159  // A temporary stub, for FE problems
160  TTStub<Ref_Phase2TrackerDigi_> tempTTStub2(tempTTStub.getDetId());
161 
162  tempTTStub2.addClusterRef((tempTTStub.clusterRef(0)));
163  tempTTStub2.addClusterRef((tempTTStub.clusterRef(1)));
164  tempTTStub2.setRawBend(2. * tempTTStub.rawBend());
165  tempTTStub2.setBendOffset(2. * tempTTStub.bendOffset());
166  tempTTStub2.setBendBE(tempTTStub.bendBE());
167  tempTTStub2.setModuleTypePS(tempTTStub.moduleTypePS());
168 
170  if (!applyFE) // No dynamic inefficiencies (DEFAULT)
171  {
173  tempInner.push_back(*(tempTTStub.clusterRef(0)));
174  tempOuter.push_back(*(tempTTStub.clusterRef(1)));
175  tempAccepted.push_back(tempTTStub);
176  } else {
177  bool FEreject = false;
180  MeasurementPoint mp0 = tempTTStub.clusterRef(0)->findAverageLocalCoordinates();
181  int seg = static_cast<int>(mp0.y());
182  if (isPS)
183  seg = seg / 16;
184  int chip = 1000 * nmod + 10 * int(tempTTStub.innerClusterPosition() / chipSize) +
185  seg;
186  int CIC_chip = 10 * nmod + seg;
187 
188  // First look is the stub is passing trough the very front end (CBC/MPA)
189  (isPS) ? maxStubs = maxStubs_PS : maxStubs = maxStubs_2S;
190 
191  if (isPS) // MPA
192  {
193  if (moduleStubs_MPA.find(chip) == moduleStubs_MPA.end())
194  {
196  moduleStubs_MPA.emplace(chip, 1);
197  } else {
198  if (moduleStubs_MPA[chip] < int(maxStubs)) {
199  ++moduleStubs_MPA[chip];
200  } else {
201  FEreject = true;
202  }
203  }
204  } else // CBC
205  {
206  if (moduleStubs_CBC.find(chip) == moduleStubs_CBC.end())
207  {
209  moduleStubs_CBC.emplace(chip, 1);
210  } else {
211  if (moduleStubs_CBC[chip] < int(maxStubs)) {
212  ++moduleStubs_CBC[chip];
213  } else {
214  FEreject = true;
215  }
216  }
217  }
218 
219  // End of the MPA/CBC loop
220 
221  // If the stub has been already thrown out, there is no reason to include it into the CIC stream
222  // We keep is in the stub final container tough, but flagged as reject by FE
223 
224  if (FEreject) {
225  tempTTStub2.setRawBend(CBCFailOffset + 2. * tempTTStub.rawBend());
226  tempTTStub2.setBendOffset(CBCFailOffset + 2. * tempTTStub.bendOffset());
227 
228  tempInner.push_back(*(tempTTStub2.clusterRef(0)));
229  tempOuter.push_back(*(tempTTStub2.clusterRef(1)));
230  tempAccepted.push_back(tempTTStub2);
231  continue;
232  }
233 
234  maxStubs = isPS ? maxStubs_PS_CIC_5 : maxStubs_2S_CIC_5;
235 
236  if (is10G_PS)
237  maxStubs = maxStubs_PS_CIC_10;
238 
239  if (moduleStubs_CIC.find(CIC_chip) == moduleStubs_CIC.end())
240  {
241  if (moduleStubs_MPA.find(chip) == moduleStubs_MPA.end())
242  {
244  moduleStubs_MPA.emplace(chip, 1);
245  } else {
246  if (moduleStubs_MPA[chip] < int(maxStubs)) {
247  ++moduleStubs_MPA[chip];
248  } else {
249  FEreject = true;
250  }
251  }
252  } else // CBC
253  {
254  if (moduleStubs_CBC.find(chip) == moduleStubs_CBC.end())
255  {
257  moduleStubs_CBC.emplace(chip, 1);
258  } else {
259  if (moduleStubs_CBC[chip] < int(maxStubs)) {
260  ++moduleStubs_CBC[chip];
261  } else {
262  FEreject = true;
263  }
264  }
265  }
266 
267  // End of the MPA/CBC loop
268 
269  // If the stub has been already thrown out, there is no reason to include it into the CIC stream
270  // We keep is in the stub final container tough, but flagged as reject by FE
271 
272  if (FEreject) {
273  tempTTStub2.setRawBend(CBCFailOffset + 2. * tempTTStub.rawBend());
274  tempTTStub2.setBendOffset(CBCFailOffset + 2. * tempTTStub.bendOffset());
275 
276  tempInner.push_back(*(tempTTStub2.clusterRef(0)));
277  tempOuter.push_back(*(tempTTStub2.clusterRef(1)));
278  tempAccepted.push_back(tempTTStub2);
279  continue;
280  }
281 
282  (isPS) ? maxStubs = maxStubs_PS_CIC_5 : maxStubs = maxStubs_2S_CIC_5;
283 
284  if (is10G_PS)
285  maxStubs = maxStubs_PS_CIC_10;
286 
287  if (moduleStubs_CIC.find(CIC_chip) == moduleStubs_CIC.end())
288  {
289  bool CIC_reject = true;
290 
291  if (moduleStubs_CIC[CIC_chip].size() < maxStubs) {
292  moduleStubs_CIC[CIC_chip].push_back(tempTTStub); //We add the new stub
293  tempInner.push_back(*(tempTTStub.clusterRef(0)));
294  tempOuter.push_back(*(tempTTStub.clusterRef(1)));
295  tempAccepted.push_back(tempTTStub); // The stub is added
296  } else {
297  moduleStubs_CIC[CIC_chip].push_back(tempTTStub); //We add the new stub
298 
300  bendMap.clear();
301  bendMap.reserve(moduleStubs_CIC[CIC_chip].size());
302 
303  for (unsigned int i = 0; i < moduleStubs_CIC[CIC_chip].size(); ++i) {
304  bendMap.emplace_back(i, moduleStubs_CIC[CIC_chip].at(i).bendFE());
305  }
306 
307  std::sort(bendMap.begin(), bendMap.end(), TTStubBuilder<Ref_Phase2TrackerDigi_>::SortStubBendPairs);
308 
309  // bendMap contains link over all the stubs included in moduleStubs_CIC[CIC_chip]
310 
311  for (unsigned int i = 0; i < maxStubs; ++i) {
312  // The stub we have added is among the first ones, add it
313  if (bendMap[i].first == moduleStubs_CIC[CIC_chip].size() - 1) {
314  CIC_reject = false;
315  }
316  }
317 
318  if (CIC_reject) // The stub added does not pass the cut
319  {
320  tempTTStub2.setRawBend(CICFailOffset + 2. * tempTTStub.rawBend());
321  tempTTStub2.setBendOffset(CICFailOffset + 2. * tempTTStub.bendOffset());
322 
323  tempInner.push_back(*(tempTTStub2.clusterRef(0)));
324  tempOuter.push_back(*(tempTTStub2.clusterRef(1)));
325  tempAccepted.push_back(tempTTStub2);
326  } else {
327  tempInner.push_back(*(tempTTStub.clusterRef(0)));
328  tempOuter.push_back(*(tempTTStub.clusterRef(1)));
329  tempAccepted.push_back(tempTTStub); // The stub is added
330  }
331  }
332  }
333  }
334  }
335  }
336 
338  if (!tempInner.empty()) {
339  typename edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>::FastFiller lowerOutputFiller(
340  *ttClusterDSVForOutput, lowerDetid);
341  for (unsigned int m = 0; m < tempInner.size(); m++) {
342  lowerOutputFiller.push_back(tempInner.at(m));
343  }
344  if (lowerOutputFiller.empty())
345  lowerOutputFiller.abort();
346  }
347 
348  if (!tempOuter.empty()) {
349  typename edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>::FastFiller upperOutputFiller(
350  *ttClusterDSVForOutput, upperDetid);
351  for (unsigned int m = 0; m < tempOuter.size(); m++) {
352  upperOutputFiller.push_back(tempOuter.at(m));
353  }
354  if (upperOutputFiller.empty())
355  upperOutputFiller.abort();
356  }
357 
358  if (!tempAccepted.empty()) {
359  typename edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>::FastFiller tempAcceptedFiller(
360  *ttStubDSVForOutputTemp, stackDetid);
361  for (unsigned int m = 0; m < tempAccepted.size(); m++) {
362  tempAcceptedFiller.push_back(tempAccepted.at(m));
363  }
364  if (tempAcceptedFiller.empty())
365  tempAcceptedFiller.abort();
366  }
367 
368  }
369 
373  iEvent.put(std::move(ttClusterDSVForOutput), "ClusterAccepted");
374 
376  typename edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>::const_iterator stubDetIter;
377 
378  for (stubDetIter = ttStubDSVForOutputTemp->begin(); stubDetIter != ttStubDSVForOutputTemp->end(); ++stubDetIter) {
380  DetId thisStackedDetId = stubDetIter->id();
381  typename edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>::FastFiller acceptedOutputFiller(
382  *ttStubDSVForOutputAccepted, thisStackedDetId);
383 
386  DetId lowerDetid = thisStackedDetId + 1;
387  DetId upperDetid = thisStackedDetId + 2;
388 
390  edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> lowerClusters = (*ttClusterAcceptedHandle)[lowerDetid];
391  edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>> upperClusters = (*ttClusterAcceptedHandle)[upperDetid];
392 
394  edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_>> theseStubs = (*ttStubDSVForOutputTemp)[thisStackedDetId];
395 
398  typename edmNew::DetSet<TTCluster<Ref_Phase2TrackerDigi_>>::iterator clusterIter;
399  typename edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_>>::iterator stubIter;
400  for (stubIter = theseStubs.begin(); stubIter != theseStubs.end(); ++stubIter) {
402  TTStub<Ref_Phase2TrackerDigi_> tempTTStub(stubIter->getDetId());
403 
406  lowerClusterToBeReplaced = stubIter->clusterRef(0);
408  upperClusterToBeReplaced = stubIter->clusterRef(1);
409 
410  bool lowerOK = false;
411  bool upperOK = false;
412 
413  for (clusterIter = lowerClusters.begin(); clusterIter != lowerClusters.end() && !lowerOK; ++clusterIter) {
414  if (clusterIter->getHits() == lowerClusterToBeReplaced->getHits()) {
415  tempTTStub.addClusterRef(edmNew::makeRefTo(ttClusterAcceptedHandle, clusterIter));
416  lowerOK = true;
417  }
418  }
419 
420  for (clusterIter = upperClusters.begin(); clusterIter != upperClusters.end() && !upperOK; ++clusterIter) {
421  if (clusterIter->getHits() == upperClusterToBeReplaced->getHits()) {
422  tempTTStub.addClusterRef(edmNew::makeRefTo(ttClusterAcceptedHandle, clusterIter));
423  upperOK = true;
424  }
425  }
426 
428  if (!lowerOK || !upperOK)
429  continue;
430 
431  tempTTStub.setRawBend(2. * stubIter->rawBend());
432  tempTTStub.setBendOffset(
433  2. * stubIter->bendOffset());
434  tempTTStub.setBendBE(stubIter->bendBE());
435  tempTTStub.setModuleTypePS(stubIter->moduleTypePS());
436 
437  acceptedOutputFiller.push_back(tempTTStub);
438 
439  }
440 
441  if (acceptedOutputFiller.empty())
442  acceptedOutputFiller.abort();
443 
444  }
445 
447  iEvent.put(std::move(ttStubDSVForOutputAccepted), "StubAccepted");
448  iEvent.put(std::move(ttStubDSVForOutputRejected), "StubRejected");
449 
450  ++ievt;
451  if (ievt % 8 == 0)
452  moduleStubs_CIC.clear(); // Everything is cleared up after 8BX
453  if (ievt % 2 == 0)
454  moduleStubs_MPA.clear(); // Everything is cleared up after 2BX
455  moduleStubs_CBC.clear(); // Everything is cleared up after everyBX
456 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
Point2DBase
Definition: Point2DBase.h:9
mps_fire.i
i
Definition: mps_fire.py:355
edmNew::DetSetVector::id
id_type id(size_t cell) const
Definition: DetSetVectorNew.h:606
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:735
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
edmNew::DetSetVector::begin
const_iterator begin(bool update=false) const
Definition: DetSetVectorNew.h:572
TrackerTopology::stack
uint32_t stack(const DetId &id) const
Definition: TrackerTopology.cc:104
TTStub::rawBend
double rawBend() const
Trigger info.
Definition: TTStub.h:165
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
dqmdumpme.first
first
Definition: dqmdumpme.py:55
TrackerTopology::tidRing
unsigned int tidRing(const DetId &id) const
Definition: TrackerTopology.h:218
TTStub::bendBE
double bendBE() const
BendBE(): In FULL-STRIP units! Reduced resolution from BE boards. Rename of getHardwareBend()
Definition: TTStub.h:211
TTStubBuilder
Plugin to load the Stub finding algorithm and produce the collection of Stubs that goes in the event ...
Definition: TTStubBuilder.h:43
edm::Ref
Definition: AssociativeIterator.h:58
TrackerTopology::tidWheel
unsigned int tidWheel(const DetId &id) const
Definition: TrackerTopology.h:201
TTStub::bendOffset
double bendOffset() const
Definition: TTStub.h:175
TTStub::clusterRef
const edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > & clusterRef(unsigned int hitStackMember) const
Clusters composing the Stub – see https://twiki.cern.ch/twiki/bin/viewauth/CMS/SLHCTrackerTriggerSWTo...
Definition: TTStub.h:150
DetId
Definition: DetId.h:17
edmNew::DetSet::end
iterator end()
Definition: DetSetNew.h:56
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
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
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
TTStub::moduleTypePS
bool moduleTypePS() const
check if a PS module
Definition: TTStub.h:194
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
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
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
TTStub::getDetId
DetId getDetId() const
Detector element.
Definition: TTStub.h:44
PV2DBase::y
T y() const
Definition: PV2DBase.h:44
edmNew::DetSetVector::empty
bool empty() const
Definition: DetSetVectorNew.h:592
edmNew::DetSetVector::push_back
Item & push_back(id_type iid)
Definition: DetSetVectorNew.h:509
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edmNew::DetSet::begin
iterator begin()
Definition: DetSetNew.h:54
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
get
#define get
TTStubBuilder::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
TTStubBuilder.h
edmNew::DetSetVector
Definition: DetSetNew.h:13
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::OrphanHandle
Definition: EDProductfwd.h:39
edmNew::DetSetVector::end
const_iterator end(bool update=false) const
Definition: DetSetVectorNew.h:577
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
TTCluster
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
TTStub::innerClusterPosition
double innerClusterPosition() const
Definition: TTStub.h:198
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
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