CMS 3D CMS Logo

TTStubBuilder.cc
Go to the documentation of this file.
1 
13 
15 template< >
17 {
18  //Retrieve tracker topology from geometry
20  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
21  const TrackerTopology* const tTopo = tTopoHandle.product();
23  iSetup.get< TrackerDigiGeometryRecord >().get( tGeomHandle );
24  const TrackerGeometry* const theTrackerGeom = tGeomHandle.product();
25 
27  auto ttClusterDSVForOutput = std::make_unique<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_>>>();
28  auto ttStubDSVForOutputTemp = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
29  auto ttStubDSVForOutputAccepted = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
30  auto ttStubDSVForOutputRejected = std::make_unique<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>>();
31 
34  iEvent.getByToken( clustersToken, clusterHandle );
35 
36  int nmod=-1;
37 
38  // Loop over all the tracker elements
39 
40  // for (auto gd=theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++)
41  for (const auto& gd : theTrackerGeom->dets())
42  {
43  DetId detid = (*gd).geographicalId();
44  if(detid.subdetId()!=StripSubdetector::TOB && detid.subdetId()!=StripSubdetector::TID ) continue; // only run on OT
45  if(!tTopo->isLower(detid) ) continue; // loop on the stacks: choose the lower arbitrarily
46  DetId lowerDetid = detid;
47  DetId upperDetid = tTopo->partnerDetId(detid);
48  DetId stackDetid = tTopo->stack(detid);
49  bool isPS = (theTrackerGeom->getDetectorType(stackDetid)==TrackerGeometry::ModuleType::Ph2PSP);
50 
51  bool is10G_PS = false;
52 
53  // Determine if this module is a 10G transmission scheme module
54  //
55  // sviret comment (221217): this info should be made available in conddb at some point
56  // not in TrackerTopology as some modules may switch between 10G and 5G transmission
57  // schemes during running period
58 
59  if (detid.subdetId()==StripSubdetector::TOB)
60  {
61  if (tTopo->layer(detid)==1) is10G_PS = true;
62  }
63  else if (detid.subdetId()==StripSubdetector::TID)
64  {
65  if (tTopo->tidRing(detid)<=high_rate_max_ring[tTopo->tidWheel(detid)-1]) is10G_PS = true;
66  }
67 
68 
69  ++nmod;
70 
71  unsigned int maxStubs;
72  std::vector< std::pair< unsigned int, double > > bendMap;
73 
75  if ( clusterHandle->find( lowerDetid ) == clusterHandle->end() ||
76  clusterHandle->find( upperDetid ) == clusterHandle->end() )
77  continue;
78 
80  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > lowerClusters = (*clusterHandle)[ lowerDetid ];
81  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > upperClusters = (*clusterHandle)[ upperDetid ];
82 
86  if ( lowerClusters.empty() || upperClusters.empty() )
87  continue;
88 
90  std::vector< TTCluster< Ref_Phase2TrackerDigi_ > > tempInner;
91  std::vector< TTCluster< Ref_Phase2TrackerDigi_ > > tempOuter;
92  std::vector< TTStub< Ref_Phase2TrackerDigi_ > > tempAccepted;
93  tempInner.clear();
94  tempOuter.clear();
95  tempAccepted.clear();
96 
98  int chipSize = 127;
99  if (isPS) chipSize = 120;
100 
102  for ( auto lowerClusterIter = lowerClusters.begin();
103  lowerClusterIter != lowerClusters.end();
104  ++lowerClusterIter ) {
105 
108  std::vector< TTStub< Ref_Phase2TrackerDigi_ > > tempOutput;
109 
110  for ( auto upperClusterIter = upperClusters.begin();
111  upperClusterIter != upperClusters.end();
112  ++upperClusterIter ) {
113 
115  TTStub< Ref_Phase2TrackerDigi_ > tempTTStub( stackDetid );
116  tempTTStub.addClusterRef( edmNew::makeRefTo( clusterHandle, lowerClusterIter ) );
117  tempTTStub.addClusterRef( edmNew::makeRefTo( clusterHandle, upperClusterIter ) );
118 
120  bool thisConfirmation = false;
121  int thisDisplacement = 999999;
122  int thisOffset = 0;
123  float thisROffset = 0;
124  float thisHardBend = 0;
125 
126  theStubFindingAlgoHandle->PatternHitCorrelation( thisConfirmation, thisDisplacement, thisOffset, thisROffset, thisHardBend, tempTTStub );
127 
129  if ( thisConfirmation )
130  {
131  tempTTStub.setTriggerDisplacement( thisDisplacement );
132  tempTTStub.setTriggerOffset( thisOffset );
133  tempTTStub.setRealTriggerOffset( thisROffset );
134  tempTTStub.setHardwareBend( thisHardBend );
135  tempOutput.push_back( tempTTStub );
136  }
137  }
138 
141  if ( ForbidMultipleStubs && tempOutput.size() > 1 )
142  {
144  std::sort( tempOutput.begin(), tempOutput.end(), TTStubBuilder< Ref_Phase2TrackerDigi_ >::SortStubsBend );
145 
147  typename std::vector< TTStub< Ref_Phase2TrackerDigi_ > >::iterator tempIter = tempOutput.begin();
148  ++tempIter;
149 
151 
153  tempOutput.erase( tempIter, tempOutput.end() );
154  }
155 
158 
160  for ( unsigned int iTempStub = 0; iTempStub < tempOutput.size(); ++iTempStub )
161  {
163  const TTStub< Ref_Phase2TrackerDigi_ >& tempTTStub = tempOutput[iTempStub];
164 
165  // A temporary stub, for FE problems
166  TTStub< Ref_Phase2TrackerDigi_ > tempTTStub2( tempTTStub.getDetId() );
167 
168  tempTTStub2.addClusterRef( (tempTTStub.getClusterRef(0)) );
169  tempTTStub2.addClusterRef( (tempTTStub.getClusterRef(1)) );
170  tempTTStub2.setTriggerDisplacement( 2.*tempTTStub.getTriggerDisplacement() );
171  tempTTStub2.setTriggerOffset( 2.*tempTTStub.getTriggerOffset() );
172  tempTTStub2.setRealTriggerOffset( 2.*tempTTStub.getRealTriggerOffset() );
173  tempTTStub2.setHardwareBend( tempTTStub.getHardwareBend() );
174 
175 
177  if ( !applyFE ) // No dynamic inefficiencies (DEFAULT)
178  {
180  tempInner.push_back( *(tempTTStub.getClusterRef(0)) );
181  tempOuter.push_back( *(tempTTStub.getClusterRef(1)) );
182  tempAccepted.push_back( tempTTStub );
183  }
184  else
185  {
186  bool FEreject = false;
189  MeasurementPoint mp0 = tempTTStub.getClusterRef(0)->findAverageLocalCoordinates();
190  int seg = static_cast<int>(mp0.y());
191  if (isPS) seg = seg/16;
192  int chip = 1000*nmod+10*int(tempTTStub.getTriggerPosition()/chipSize)+seg;
193  int CIC_chip = 10*nmod+seg;
194 
195  // First look is the stub is passing trough the very front end (CBC/MPA)
196  (isPS)
197  ? maxStubs = maxStubs_PS
198  : maxStubs = maxStubs_2S;
199 
200  if (isPS) // MPA
201  {
202  if ( moduleStubs_MPA.find( chip ) == moduleStubs_MPA.end() )
203  {
205  moduleStubs_MPA.emplace(chip,1);
206  }
207  else
208  {
209  if ( moduleStubs_MPA[chip] < int(maxStubs) )
210  {
211  ++moduleStubs_MPA[chip];
212  }
213  else
214  {
215  FEreject = true;
216  }
217  }
218  }
219  else // CBC
220  {
221  if ( moduleStubs_CBC.find( chip ) == moduleStubs_CBC.end() )
222  {
224  moduleStubs_CBC.emplace(chip,1);
225  }
226  else
227  {
228  if ( moduleStubs_CBC[chip] < int(maxStubs) )
229  {
230  ++moduleStubs_CBC[chip];
231  }
232  else
233  {
234  FEreject = true;
235  }
236  }
237  }
238 
239  // End of the MPA/CBC loop
240 
241  // If the stub has been already thrown out, there is no reason to include it into the CIC stream
242  // We keep is in the stub final container tough, but flagged as reject by FE
243 
244  if (FEreject)
245  {
246  tempTTStub2.setTriggerDisplacement( 500+2.*tempTTStub.getTriggerDisplacement() );
247  tempTTStub2.setTriggerOffset( 500+2.*tempTTStub.getTriggerOffset() );
248  tempTTStub2.setRealTriggerOffset( 500+2.*tempTTStub.getRealTriggerOffset() );
249 
250  tempInner.push_back( *(tempTTStub2.getClusterRef(0)) );
251  tempOuter.push_back( *(tempTTStub2.getClusterRef(1)) );
252  tempAccepted.push_back( tempTTStub2 );
253  continue;
254  }
255 
256  (isPS)
257  ? maxStubs = maxStubs_PS_CIC_5
258  : maxStubs = maxStubs_2S_CIC_5;
259 
260  if (is10G_PS) maxStubs = maxStubs_PS_CIC_10;
261 
262  if ( moduleStubs_CIC.find( CIC_chip ) == moduleStubs_CIC.end() )
263  {
265  std::vector< TTStub< Ref_Phase2TrackerDigi_ > > tempStubs(1,tempTTStub);
266  moduleStubs_CIC.emplace(CIC_chip,tempStubs);
267  tempInner.push_back( *(tempTTStub.getClusterRef(0)) );
268  tempOuter.push_back( *(tempTTStub.getClusterRef(1)) );
269  tempAccepted.push_back( tempTTStub ); // The stub is added
270  }
271  else
272  {
273  bool CIC_reject=true;
274 
275  if ( moduleStubs_CIC[CIC_chip].size() < maxStubs )
276  {
277  moduleStubs_CIC[CIC_chip].push_back( tempTTStub ); //We add the new stub
278  tempInner.push_back( *(tempTTStub.getClusterRef(0)) );
279  tempOuter.push_back( *(tempTTStub.getClusterRef(1)) );
280  tempAccepted.push_back( tempTTStub ); // The stub is added
281  }
282  else
283  {
284  moduleStubs_CIC[CIC_chip].push_back( tempTTStub ); //We add the new stub
285 
287  bendMap.clear();
288  bendMap.reserve(moduleStubs_CIC[CIC_chip].size());
289 
290  for ( unsigned int i = 0; i < moduleStubs_CIC[CIC_chip].size(); ++i )
291  {
292  bendMap.emplace_back(i,moduleStubs_CIC[CIC_chip].at(i).getTriggerBend());
293  }
294 
295  std::sort( bendMap.begin(), bendMap.end(), TTStubBuilder< Ref_Phase2TrackerDigi_ >::SortStubBendPairs );
296 
297  // bendMap contains link over all the stubs included in moduleStubs_CIC[CIC_chip]
298 
299  for ( unsigned int i = 0; i < maxStubs; ++i )
300  {
301  // The stub we have added is among the first ones, add it
302  if (bendMap[i].first==moduleStubs_CIC[CIC_chip].size()-1)
303  {
304  CIC_reject=false;
305  }
306  }
307 
308  if (CIC_reject) // The stub added does not pass the cut
309  {
310  tempTTStub2.setTriggerDisplacement( 1000+2.*tempTTStub.getTriggerDisplacement() );
311  tempTTStub2.setTriggerOffset( 1000+2.*tempTTStub.getTriggerOffset() );
312  tempTTStub2.setRealTriggerOffset( 1000+2.*tempTTStub.getRealTriggerOffset() );
313 
314  tempInner.push_back( *(tempTTStub2.getClusterRef(0)) );
315  tempOuter.push_back( *(tempTTStub2.getClusterRef(1)) );
316  tempAccepted.push_back( tempTTStub2 );
317  }
318  else
319  {
320  tempInner.push_back( *(tempTTStub.getClusterRef(0)) );
321  tempOuter.push_back( *(tempTTStub.getClusterRef(1)) );
322  tempAccepted.push_back( tempTTStub ); // The stub is added
323  }
324  }
325  }
326  }
327  }
328  }
329 
331  if ( !tempInner.empty() )
332  {
333  typename edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >::FastFiller lowerOutputFiller( *ttClusterDSVForOutput, lowerDetid );
334  for ( unsigned int m = 0; m < tempInner.size(); m++ )
335  {
336  lowerOutputFiller.push_back( tempInner.at(m) );
337  }
338  if ( lowerOutputFiller.empty() )
339  lowerOutputFiller.abort();
340  }
341 
342  if ( !tempOuter.empty() )
343  {
344  typename edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >::FastFiller upperOutputFiller( *ttClusterDSVForOutput, upperDetid );
345  for ( unsigned int m = 0; m < tempOuter.size(); m++ )
346  {
347  upperOutputFiller.push_back( tempOuter.at(m) );
348  }
349  if ( upperOutputFiller.empty() )
350  upperOutputFiller.abort();
351  }
352 
353  if ( !tempAccepted.empty() )
354  {
355  typename edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >::FastFiller tempAcceptedFiller( *ttStubDSVForOutputTemp, stackDetid);
356  for ( unsigned int m = 0; m < tempAccepted.size(); m++ )
357  {
358  tempAcceptedFiller.push_back( tempAccepted.at(m) );
359  }
360  if ( tempAcceptedFiller.empty() )
361  tempAcceptedFiller.abort();
362  }
363 
364  }
365 
368  edm::OrphanHandle< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > > > ttClusterAcceptedHandle = iEvent.put( std::move(ttClusterDSVForOutput), "ClusterAccepted" );
369 
371  typename edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >::const_iterator stubDetIter;
372 
373  for ( stubDetIter = ttStubDSVForOutputTemp->begin();
374  stubDetIter != ttStubDSVForOutputTemp->end();
375  ++stubDetIter ) {
377  DetId thisStackedDetId = stubDetIter->id();
378  typename edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >::FastFiller acceptedOutputFiller( *ttStubDSVForOutputAccepted, thisStackedDetId );
379 
382  DetId lowerDetid = thisStackedDetId+1;
383  DetId upperDetid = thisStackedDetId+2;
384 
386  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > lowerClusters = (*ttClusterAcceptedHandle)[ lowerDetid ];
387  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > upperClusters = (*ttClusterAcceptedHandle)[ upperDetid ];
388 
390  edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > > theseStubs = (*ttStubDSVForOutputTemp)[ thisStackedDetId ];
391 
394  typename edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > >::iterator clusterIter;
395  typename edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > >::iterator stubIter;
396  for ( stubIter = theseStubs.begin();
397  stubIter != theseStubs.end();
398  ++stubIter ) {
400  TTStub< Ref_Phase2TrackerDigi_ > tempTTStub( stubIter->getDetId() );
401 
403  const edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > >& lowerClusterToBeReplaced = stubIter->getClusterRef(0);
404  const edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > >& upperClusterToBeReplaced = stubIter->getClusterRef(1);
405 
406  bool lowerOK = false;
407  bool upperOK = false;
408 
409  for ( clusterIter = lowerClusters.begin();
410  clusterIter != lowerClusters.end() && !lowerOK;
411  ++clusterIter ) {
412  if ( clusterIter->getHits() == lowerClusterToBeReplaced->getHits() ) {
413  tempTTStub.addClusterRef( edmNew::makeRefTo( ttClusterAcceptedHandle, clusterIter ) );
414  lowerOK = true;
415  }
416  }
417 
418  for ( clusterIter = upperClusters.begin();
419  clusterIter != upperClusters.end() && !upperOK;
420  ++clusterIter ) {
421  if ( clusterIter->getHits() == upperClusterToBeReplaced->getHits() ) {
422  tempTTStub.addClusterRef( edmNew::makeRefTo( ttClusterAcceptedHandle, clusterIter ) );
423  upperOK = true;
424  }
425  }
426 
428  if ( !lowerOK || !upperOK ) continue;
429 
430  tempTTStub.setTriggerDisplacement( 2.*stubIter->getTriggerDisplacement() );
431  tempTTStub.setTriggerOffset( 2.*stubIter->getTriggerOffset() );
432  tempTTStub.setRealTriggerOffset( 2.*stubIter->getRealTriggerOffset() );
433  tempTTStub.setHardwareBend( stubIter->getHardwareBend() );
434 
435  acceptedOutputFiller.push_back( tempTTStub );
436 
437  }
438 
439  if ( acceptedOutputFiller.empty() )
440  acceptedOutputFiller.abort();
441 
442  }
443 
445  iEvent.put( std::move(ttStubDSVForOutputAccepted), "StubAccepted" );
446  iEvent.put( std::move(ttStubDSVForOutputRejected), "StubRejected" );
447 
448  ++ievt;
449  if (ievt%8==0) moduleStubs_CIC.clear(); // Everything is cleared up after 8BX
450  if (ievt%2==0) moduleStubs_MPA.clear(); // Everything is cleared up after 2BX
451  moduleStubs_CBC.clear(); // Everything is cleared up after everyBX
452 
453 }
454 
455 
size
Write out results.
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)
const_iterator end(bool update=false) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
T y() const
Definition: PV2DBase.h:46
unsigned int tidRing(const DetId &id) const
Item & push_back(id_type iid)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
unsigned int tidWheel(const DetId &id) const
DetId getDetId() const
Detector element.
Definition: TTStub.h:40
id_type id(size_t cell) const
DetId partnerDetId(const DetId &id) const
double getHardwareBend() const
In FULL-STRIP units!
Definition: TTStub.h:168
bool isLower(const DetId &id) const
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
void setHardwareBend(float aBend)
In FULL-STRIP units!
Definition: TTStub.h:148
int iEvent
Definition: GenABIO.cc:230
void setTriggerDisplacement(int aDisplacement)
In FULL-STRIP units! (hence, not implemented herein)
Definition: TTStub.h:133
double getTriggerOffset() const
In HALF-STRIP units!
Definition: TTStub.h:136
bool empty() const
Definition: DetSetNew.h:90
ModuleType getDetectorType(DetId) const
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
double getTriggerDisplacement() const
Trigger information.
Definition: TTStub.h:130
Definition: DetId.h:18
void setTriggerOffset(int anOffset)
In FULL-STRIP units! (hence, not implemented herein)
Definition: TTStub.h:139
NOTE: this is needed even if it seems not.
Definition: TTCluster.h:27
uint32_t stack(const DetId &id) const
const T & get() const
Definition: EventSetup.h:55
void addClusterRef(edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > aTTCluster)
Definition: TTStub.h:122
unsigned int layer(const DetId &id) const
iterator end()
Definition: DetSetNew.h:70
void setRealTriggerOffset(float anOffset)
In FULL-STRIP units! (hence, not implemented herein)
Definition: TTStub.h:145
double getRealTriggerOffset() const
In HALF-STRIP units!
Definition: TTStub.h:142
double getTriggerPosition() const
In HALF-STRIP units!
Definition: TTStub.h:153
const edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > & getClusterRef(unsigned int hitIdentifier) const
Clusters composing the Stub.
Definition: TTStub.h:116
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
const_iterator begin(bool update=false) const
Plugin to load the Stub finding algorithm and produce the collection of Stubs that goes in the event ...
Definition: TTStubBuilder.h:43
iterator begin()
Definition: DetSetNew.h:67