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 
38  // unsigned maxStubs = theStackedTracker->getCBC3MaxStubs();
39  unsigned maxStubs = 0; // 0 is default, cut is disabled
40 
41  for (auto gd=theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++) {
42  DetId detid = (*gd)->geographicalId();
43  if(detid.subdetId()!=StripSubdetector::TOB && detid.subdetId()!=StripSubdetector::TID ) continue; // only run on OT
44  if(!tTopo->isLower(detid) ) continue; // loop on the stacks: choose the lower arbitrarily
45  DetId lowerDetid = detid;
46  DetId upperDetid = tTopo->partnerDetId(detid);
47  DetId stackDetid = tTopo->stack(detid);
48 
50  if ( clusterHandle->find( lowerDetid ) == clusterHandle->end() ||
51  clusterHandle->find( upperDetid ) == clusterHandle->end() )
52  continue;
53 
55  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > lowerClusters = (*clusterHandle)[ lowerDetid ];
56  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > upperClusters = (*clusterHandle)[ upperDetid ];
57 
61  if ( lowerClusters.empty() || upperClusters.empty() )
62  continue;
63 
65  std::vector< TTCluster< Ref_Phase2TrackerDigi_ > > tempInner;
66  std::vector< TTCluster< Ref_Phase2TrackerDigi_ > > tempOuter;
67  std::vector< TTStub< Ref_Phase2TrackerDigi_ > > tempAccepted;
68  tempInner.clear();
69  tempOuter.clear();
70  tempAccepted.clear();
71 
73  const GeomDetUnit* det0 = theTrackerGeom->idToDetUnit( lowerDetid );
74  const PixelGeomDetUnit* pix0 = dynamic_cast< const PixelGeomDetUnit* >( det0 );
75  const PixelTopology* top0 = dynamic_cast< const PixelTopology* >( &(pix0->specificTopology()) );
76  const int chipSize = 2 * top0->rowsperroc();
77 
78  std::unordered_map< int, std::vector< TTStub< Ref_Phase2TrackerDigi_ > > > moduleStubs;
79 
81  for ( auto lowerClusterIter = lowerClusters.begin();
82  lowerClusterIter != lowerClusters.end();
83  ++lowerClusterIter ) {
84 
87  std::vector< TTStub< Ref_Phase2TrackerDigi_ > > tempOutput;
88  // tempOutput.clear();
89 
90  for ( auto upperClusterIter = upperClusters.begin();
91  upperClusterIter != upperClusters.end();
92  ++upperClusterIter ) {
93 
95  TTStub< Ref_Phase2TrackerDigi_ > tempTTStub( stackDetid );
96  tempTTStub.addClusterRef( edmNew::makeRefTo( clusterHandle, lowerClusterIter ) );
97  tempTTStub.addClusterRef( edmNew::makeRefTo( clusterHandle, upperClusterIter ) );
98 
100  bool thisConfirmation = false;
101  int thisDisplacement = 999999;
102  int thisOffset = 0;
103 
104  theStubFindingAlgoHandle->PatternHitCorrelation( thisConfirmation, thisDisplacement, thisOffset, tempTTStub );
105 
107  if ( thisConfirmation )
108  {
109  tempTTStub.setTriggerDisplacement( thisDisplacement );
110  tempTTStub.setTriggerOffset( thisOffset );
111  tempOutput.push_back( tempTTStub );
112  }
113  }
114 
117  if ( ForbidMultipleStubs && tempOutput.size() > 1 )
118  {
120  std::sort( tempOutput.begin(), tempOutput.end(), TTStubBuilder< Ref_Phase2TrackerDigi_ >::SortStubsBend );
121 
123  typename std::vector< TTStub< Ref_Phase2TrackerDigi_ > >::iterator tempIter = tempOutput.begin();
124  ++tempIter;
125 
127 
129  tempOutput.erase( tempIter, tempOutput.end() );
130  }
131 
134 
136  for ( unsigned int iTempStub = 0; iTempStub < tempOutput.size(); ++iTempStub )
137  {
139  const TTStub< Ref_Phase2TrackerDigi_ >& tempTTStub = tempOutput[iTempStub];
140 
142  if ( maxStubs == 0 )
143  {
145  tempInner.push_back( *(tempTTStub.getClusterRef(0)) );
146  tempOuter.push_back( *(tempTTStub.getClusterRef(1)) );
147  tempAccepted.push_back( tempTTStub );
148  }
149  else
150  {
153  int chip = tempTTStub.getTriggerPosition() / chipSize;
154  if ( moduleStubs.find( chip ) == moduleStubs.end() )
155  {
157  std::vector< TTStub< Ref_Phase2TrackerDigi_ > > tempStubs(1,tempTTStub);
158  //tempStubs.clear();
159  //tempStubs.push_back( tempTTStub );
160  moduleStubs.insert( std::pair< int, std::vector< TTStub< Ref_Phase2TrackerDigi_ > > >( chip, tempStubs ) );
161  }
162  else
163  {
165  moduleStubs[chip].push_back( tempTTStub );
166  }
167  }
168  }
169  }
170 
173  if ( moduleStubs.empty() == false )
174  {
177  for ( auto const & is : moduleStubs )
178  {
180  if ( is.second.size() <= maxStubs )
181  {
182  for ( auto const & ts: is.second )
183  {
184  tempInner.push_back( *(ts.getClusterRef(0)) );
185  tempOuter.push_back( *(ts.getClusterRef(1)) );
186  tempAccepted.push_back( ts );
187  }
188  }
189  else
190  {
192  std::vector< std::pair< unsigned int, double > > bendMap;
193  bendMap.reserve(is.second.size());
194  for ( unsigned int i = 0; i < is.second.size(); ++i )
195  {
196  bendMap.push_back( std::pair< unsigned int, double >( i, is.second[i].getTriggerBend() ) );
197  }
198  std::sort( bendMap.begin(), bendMap.end(), TTStubBuilder< Ref_Phase2TrackerDigi_ >::SortStubBendPairs );
199 
200  for ( unsigned int i = 0; i < maxStubs; ++i )
201  {
203  tempInner.push_back( *(is.second[bendMap[i].first].getClusterRef(0)) );
204  tempOuter.push_back( *(is.second[bendMap[i].first].getClusterRef(1)) );
205  tempAccepted.push_back( is.second[bendMap[i].first] );
206  }
207  }
208  }
209  }
210  if ( !tempInner.empty() )
212  {
213  typename edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >::FastFiller lowerOutputFiller( *ttClusterDSVForOutput, lowerDetid );
214  for ( unsigned int m = 0; m < tempInner.size(); m++ )
215  {
216  lowerOutputFiller.push_back( tempInner.at(m) );
217  }
218  if ( lowerOutputFiller.empty() )
219  lowerOutputFiller.abort();
220  }
221 
222  if ( !tempOuter.empty() )
223  {
224  typename edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >::FastFiller upperOutputFiller( *ttClusterDSVForOutput, upperDetid );
225  for ( unsigned int m = 0; m < tempOuter.size(); m++ )
226  {
227  upperOutputFiller.push_back( tempOuter.at(m) );
228  }
229  if ( upperOutputFiller.empty() )
230  upperOutputFiller.abort();
231  }
232 
233  if ( !tempAccepted.empty() )
234  {
235  typename edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >::FastFiller tempAcceptedFiller( *ttStubDSVForOutputTemp, stackDetid);
236  for ( unsigned int m = 0; m < tempAccepted.size(); m++ )
237  {
238  tempAcceptedFiller.push_back( tempAccepted.at(m) );
239  }
240  if ( tempAcceptedFiller.empty() )
241  tempAcceptedFiller.abort();
242  }
243 
244  }
245 
248  edm::OrphanHandle< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > > > ttClusterAcceptedHandle = iEvent.put( std::move(ttClusterDSVForOutput), "ClusterAccepted" );
249 
251  typename edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >::const_iterator stubDetIter;
252 
253  for ( stubDetIter = ttStubDSVForOutputTemp->begin();
254  stubDetIter != ttStubDSVForOutputTemp->end();
255  ++stubDetIter ) {
257  DetId thisStackedDetId = stubDetIter->id();
258  typename edmNew::DetSetVector< TTStub< Ref_Phase2TrackerDigi_ > >::FastFiller acceptedOutputFiller( *ttStubDSVForOutputAccepted, thisStackedDetId );
259 
262  DetId lowerDetid = thisStackedDetId+1;
263  DetId upperDetid = thisStackedDetId+2;
264 
266  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > lowerClusters = (*ttClusterAcceptedHandle)[ lowerDetid ];
267  edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > > upperClusters = (*ttClusterAcceptedHandle)[ upperDetid ];
268 
270  edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > > theseStubs = (*ttStubDSVForOutputTemp)[ thisStackedDetId ];
271 
274  typename edmNew::DetSet< TTCluster< Ref_Phase2TrackerDigi_ > >::iterator clusterIter;
275  typename edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > >::iterator stubIter;
276  for ( stubIter = theseStubs.begin();
277  stubIter != theseStubs.end();
278  ++stubIter ) {
280  TTStub< Ref_Phase2TrackerDigi_ > tempTTStub( stubIter->getDetId() );
281 
283  const edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > >& lowerClusterToBeReplaced = stubIter->getClusterRef(0);
284  const edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > >& upperClusterToBeReplaced = stubIter->getClusterRef(1);
285 
286  bool lowerOK = false;
287  bool upperOK = false;
288 
289  for ( clusterIter = lowerClusters.begin();
290  clusterIter != lowerClusters.end() && !lowerOK;
291  ++clusterIter ) {
292  if ( clusterIter->getHits() == lowerClusterToBeReplaced->getHits() ) {
293  tempTTStub.addClusterRef( edmNew::makeRefTo( ttClusterAcceptedHandle, clusterIter ) );
294  lowerOK = true;
295  }
296  }
297 
298  for ( clusterIter = upperClusters.begin();
299  clusterIter != upperClusters.end() && !upperOK;
300  ++clusterIter ) {
301  if ( clusterIter->getHits() == upperClusterToBeReplaced->getHits() ) {
302  tempTTStub.addClusterRef( edmNew::makeRefTo( ttClusterAcceptedHandle, clusterIter ) );
303  upperOK = true;
304  }
305  }
306 
308  if ( !lowerOK || !upperOK ) continue;
309 
310  tempTTStub.setTriggerDisplacement( 2.*stubIter->getTriggerDisplacement() );
311  tempTTStub.setTriggerOffset( 2.*stubIter->getTriggerOffset() );
312 
313  acceptedOutputFiller.push_back( tempTTStub );
314 
315  }
316 
317  if ( acceptedOutputFiller.empty() )
318  acceptedOutputFiller.abort();
319 
320  }
321 
323  iEvent.put( std::move(ttStubDSVForOutputAccepted), "StubAccepted" );
324  iEvent.put( std::move(ttStubDSVForOutputRejected), "StubRejected" );
325 }
326 
327 
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
virtual int rowsperroc() const =0
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
id_type id(size_t cell) const
DetId partnerDetId(const DetId &id) const
bool isLower(const DetId &id) const
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
int iEvent
Definition: GenABIO.cc:230
void setTriggerDisplacement(int aDisplacement)
In FULL-STRIP units! (hence, not implemented herein)
Definition: TTStub.h:120
bool empty() const
Definition: DetSetNew.h:90
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
Definition: DetId.h:18
void setTriggerOffset(int anOffset)
In FULL-STRIP units! (hence, not implemented herein)
Definition: TTStub.h:126
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
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
void addClusterRef(edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > aTTCluster)
Definition: TTStub.h:109
iterator end()
Definition: DetSetNew.h:70
double getTriggerPosition() const
In HALF-STRIP units!
Definition: TTStub.h:130
const edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > & getClusterRef(unsigned int hitIdentifier) const
Clusters composing the Stub.
Definition: TTStub.h:103
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