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) {
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 
222 
224  tempOutput.erase(tempIter, tempOutput.end());
225  }
226 
229 
231 
232  for (auto& tempTTStub : tempOutput) {
234  if (not applyFE) // No dynamic inefficiencies
235  {
237  tempClusLowerAcc.push_back(*(tempTTStub.clusterRef(0)));
238  tempClusUpperAcc.push_back(*(tempTTStub.clusterRef(1)));
239  tempStubAcc.push_back(tempTTStub);
240  } else {
241  bool FEreject = false;
242 
244  MeasurementPoint mp0 = tempTTStub.clusterRef(0)->findAverageLocalCoordinates();
245  int seg = static_cast<int>(mp0.y()); // Identifies which half of module
246  if (isPS)
247  seg = seg / numMacroPixels;
249  int chip = 1000 * nmod + 10 * int(tempTTStub.innerClusterPosition() / chipSize) + seg;
251  int CIC_chip = 10 * nmod + seg;
252 
253  // First look is the stub is passing trough the very front end (CBC/MPA)
254  maxStubs = isPS ? maxStubs_PS : maxStubs_2S;
255 
256  if (isPS) // MPA
257  {
258  if (moduleStubs_MPA[chip] < int(maxStubs)) {
259  moduleStubs_MPA[chip]++;
260  } else {
261  FEreject = true;
262  }
263  } else // CBC
264  {
265  if (moduleStubs_CBC[chip] < int(maxStubs)) {
266  moduleStubs_CBC[chip]++;
267  } else {
268  FEreject = true;
269  }
270  }
271 
272  // End of the MPA/CBC loop
273 
274  // If the stub has been already thrown out, there is no reason to include it into the CIC stream
275  // We put it in the rejected container, flagged with offset to indicate reason.
276 
277  if (FEreject) {
278  tempTTStub.setRawBend(CBCFailOffset + 2. * tempTTStub.rawBend());
279  tempTTStub.setBendOffset(CBCFailOffset + 2. * tempTTStub.bendOffset());
280  tempClusLowerRej.push_back(*(tempTTStub.clusterRef(0)));
281  tempClusUpperRej.push_back(*(tempTTStub.clusterRef(1)));
282  tempStubRej.push_back(tempTTStub);
283  continue;
284  }
285 
286  maxStubs = isPS ? maxStubs_PS_CIC_5 : maxStubs_2S_CIC_5;
287 
288  if (is10G_PS)
289  maxStubs = maxStubs_PS_CIC_10;
290 
291  bool CIC_reject = true;
292 
293  moduleStubs_CIC[CIC_chip].push_back(tempTTStub); //We temporarily add the new stub
294 
295  if (moduleStubs_CIC[CIC_chip].size() <= maxStubs) {
296  tempClusLowerAcc.push_back(*(tempTTStub.clusterRef(0)));
297  tempClusUpperAcc.push_back(*(tempTTStub.clusterRef(1)));
298  tempStubAcc.push_back(tempTTStub); // The stub is kept
299 
300  } else {
304 
306  bendMap.clear();
307  bendMap.reserve(moduleStubs_CIC[CIC_chip].size());
308 
309  for (unsigned int i = 0; i < moduleStubs_CIC[CIC_chip].size(); ++i) {
310  bendMap.emplace_back(i, moduleStubs_CIC[CIC_chip].at(i).bendFE());
311  }
312 
313  std::sort(bendMap.begin(), bendMap.end(), TTStubBuilder<Ref_Phase2TrackerDigi_>::SortStubBendPairs);
314 
315  // bendMap contains link over all the stubs included in moduleStubs_CIC[CIC_chip]
316 
317  for (unsigned int i = 0; i < maxStubs; ++i) {
318  // The stub we have just added is amongst those with smallest |bend| so keep it.
319  if (bendMap[i].first == moduleStubs_CIC[CIC_chip].size() - 1) {
320  CIC_reject = false;
321  }
322  }
323 
324  if (CIC_reject) // The stub added does not pass the cut
325  {
326  tempTTStub.setRawBend(CICFailOffset + 2. * tempTTStub.rawBend());
327  tempTTStub.setBendOffset(CICFailOffset + 2. * tempTTStub.bendOffset());
328  tempClusLowerRej.push_back(*(tempTTStub.clusterRef(0)));
329  tempClusUpperRej.push_back(*(tempTTStub.clusterRef(1)));
330  tempStubRej.push_back(tempTTStub);
331  } else {
332  tempClusLowerAcc.push_back(*(tempTTStub.clusterRef(0)));
333  tempClusUpperAcc.push_back(*(tempTTStub.clusterRef(1)));
334  tempStubAcc.push_back(tempTTStub); // The stub is added
335  }
336  }
337  }
338  }
339  }
340 
342  if (not tempClusLowerAcc.empty())
343  this->fill(*ttClusterDSVForOutputAcc, lowerDetid, tempClusLowerAcc);
344  if (not tempClusLowerRej.empty())
345  this->fill(*ttClusterDSVForOutputRej, lowerDetid, tempClusLowerRej);
346  if (not tempClusUpperAcc.empty())
347  this->fill(*ttClusterDSVForOutputAcc, upperDetid, tempClusUpperAcc);
348  if (not tempClusUpperRej.empty())
349  this->fill(*ttClusterDSVForOutputRej, upperDetid, tempClusUpperRej);
350  if (not tempStubAcc.empty())
351  this->fill(*ttStubDSVForOutputAccTemp, stackDetid, tempStubAcc);
352  if (not tempStubRej.empty())
353  this->fill(*ttStubDSVForOutputRejTemp, stackDetid, tempStubRej);
354 
355  }
356 
357  // Store the subset of clusters associated to stubs.
358 
360  iEvent.put(std::move(ttClusterDSVForOutputAcc), "ClusterAccepted");
362  iEvent.put(std::move(ttClusterDSVForOutputRej), "ClusterRejected");
363 
367 
368  this->updateStubs(ttClusterAccHandle, *ttStubDSVForOutputAccTemp, *ttStubDSVForOutputAcc);
369  this->updateStubs(ttClusterRejHandle, *ttStubDSVForOutputRejTemp, *ttStubDSVForOutputRej);
370 
372  iEvent.put(std::move(ttStubDSVForOutputAcc), "StubAccepted");
373  iEvent.put(std::move(ttStubDSVForOutputRej), "StubRejected");
374 
375  ++ievt;
376  if (ievt % 8 == 0)
377  moduleStubs_CIC.clear(); // Everything is cleared up after 8BX
378  if (ievt % 2 == 0)
379  moduleStubs_MPA.clear(); // Everything is cleared up after 2BX
380  moduleStubs_CBC.clear(); // Everything is cleared up after everyBX
381 }
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:689
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
dqmdumpme.first
first
Definition: dqmdumpme.py:55
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
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
edmNew::DetSetVector::push_back
Item & push_back(id_type iid)
Definition: DetSetVectorNew.h:467
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:148
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
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
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