test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MBLTCollection.cc
Go to the documentation of this file.
1 //Authors:
2 // Carlo Battilana - Giuseppe Codispoti
3 
5 
9 
11 {
12  _wheel = dtId.wheel();
13  _sector = dtId.sector();
14  _station = dtId.station();
15 }
16 
18 {
19 
20  TriggerPrimitive::subsystem_type type = stub->subsystem();
21 
22  switch ( type ) {
23  case TriggerPrimitive::kDT :
24  _dtAssociatedStubs.push_back( stub );
25  break;
26  case TriggerPrimitive::kRPC : {
27  const RPCDetId & rpcId = stub->detId<RPCDetId>();
28 
29  if ( rpcId.region() ) { // endcap
30  throw cms::Exception("Invalid Subsytem")
31  << "The RPC stub is not in a barrel layer" << std::endl;
32  }
33 
34  if ( rpcId.layer() == 1 ) _rpcInAssociatedStubs.push_back( stub );
35  else if ( rpcId.layer() == 2 ) _rpcOutAssociatedStubs.push_back( stub );
36  else throw cms::Exception("Invalid Subsytem")
37  << "The RPC layer is not a barrel layer" << std::endl;
38  break;
39  }
40  default :
41  throw cms::Exception("Invalid Subsytem")
42  << "The specified subsystem for this track stub is out of range"
43  << std::endl;
44  }
45 }
46 
47 
48 
49 void L1TwinMux::MBLTCollection::associate( double minRpcPhi )
50 {
51 
52  size_t dtSize = _dtAssociatedStubs.size();
53  size_t rpcInSize = _rpcInAssociatedStubs.size();
54  size_t rpcOutSize = _rpcOutAssociatedStubs.size();
55  _dtMapAss.resize( dtSize );
56 
57 
58 // std::vector< std::map<double, size_t> > dtIdxIn;
59 // dtIdxIn.resize(rpcInSize);
60 // std::vector< std::map<double, size_t> > dtIdxOut;
61 // dtIdxOut.resize(rpcOutSize);
62 
63  std::vector< size_t > rpcInAss( rpcInSize, 0 );
64  std::vector< size_t > rpcOutAss( rpcOutSize, 0 );
65 
66  for ( size_t iDt = 0; iDt < dtSize; ++iDt ) {
67 
68  double phi = _dtAssociatedStubs.at(iDt)->getCMSGlobalPhi();
69  std::map< double, size_t > rpcInIdx;
70  std::map< double, size_t > rpcOutIdx;
71 
72  for ( size_t iIn = 0; iIn < rpcInSize; ++iIn ) {
73  double phiIn = _rpcInAssociatedStubs.at( iIn )->getCMSGlobalPhi();
74  double deltaPhiIn = fabs( reco::deltaPhi( phi, phiIn ) );
75  if ( deltaPhiIn < minRpcPhi ) {
76  rpcInIdx[ deltaPhiIn ] = iIn;
77  ++rpcInAss[iIn];
78 // dtIdxIn[iIn][ deltaPhiIn ] = iDt;
79  }
80  }
81 
82  for ( size_t iOut = 0; iOut < rpcOutSize; ++iOut ) {
83  double phiOut = _rpcOutAssociatedStubs.at( iOut )->getCMSGlobalPhi();
84  double deltaPhiOut = fabs( reco::deltaPhi( phi, phiOut ) );
85  if ( deltaPhiOut < minRpcPhi ) {
86  rpcOutIdx[ deltaPhiOut ] = iOut;
87  ++rpcOutAss[iOut];
88 // dtIdxOut[iOut][ deltaPhiOut ] = iDt;
89  }
90  }
91 
92  L1TwinMux::MBLTCollection::primitiveAssociation & dtAss = _dtMapAss.at(iDt);
93 
95  std::map< double, size_t >::const_iterator it = rpcInIdx.begin();
96  std::map< double, size_t >::const_iterator itend = rpcInIdx.end();
97  dtAss.rpcIn.reserve( rpcInIdx.size() );
98  for ( ; it != itend; ++it ) dtAss.rpcIn.push_back( it->second );
99 
101  it = rpcOutIdx.begin();
102  itend = rpcOutIdx.end();
103  dtAss.rpcOut.reserve( rpcOutIdx.size() );
104  for ( ; it != itend; ++it ) dtAss.rpcOut.push_back( it->second );
105 
106  }
107 
109  for ( size_t iIn = 0; iIn < rpcInSize; ++iIn ) {
110  if ( !rpcInAss.at(iIn) ) _rpcMapUnass.rpcIn.push_back(iIn);
111  }
112  if ( _rpcInAssociatedStubs.size() < _rpcMapUnass.rpcIn.size() )
113  throw cms::Exception("More unassociated IN hits than the total rpc IN hits") << std::endl;
114 
116  for ( size_t iOut = 0; iOut < rpcOutSize; ++iOut ) {
117  if ( !rpcOutAss.at(iOut) ) _rpcMapUnass.rpcOut.push_back(iOut);
118  }
119  if ( _rpcOutAssociatedStubs.size() < _rpcMapUnass.rpcOut.size() )
120  throw cms::Exception("More unassociated OUT hits than the total OUT rpc hits") << std::endl;
121 
122 }
123 
124 
126 {
127 
129 
130  try {
131  const primitiveAssociation & prim = _dtMapAss.at(dtIndex);
132  std::vector<size_t>::const_iterator it = prim.rpcIn.begin();
133  std::vector<size_t>::const_iterator itend = prim.rpcIn.end();
134 
135  for ( ; it != itend; ++it ) returnList.push_back( _rpcInAssociatedStubs.at( *it ) );
136 
137  } catch ( const std::out_of_range & e ) {
138  throw cms::Exception("DT Chamber Out of Range")
139  << "Requested DT primitive in position " << dtIndex << " out of " << _dtMapAss.size() << " total primitives"
140  << std::endl;
141  }
142 
143  return returnList;
144 
145 }
146 
147 
149 {
150 
152 
153  try {
154  const primitiveAssociation & prim = _dtMapAss.at(dtIndex);
155 
156  std::vector<size_t>::const_iterator it = prim.rpcOut.begin();
157  std::vector<size_t>::const_iterator itend = prim.rpcOut.end();
158 
159  for ( ; it != itend; ++it ) returnList.push_back( _rpcOutAssociatedStubs.at( *it ) );
160  } catch ( const std::out_of_range & e ) {
161  throw cms::Exception("DT Chamber Out of Range")
162  << "The number of dt primitives in sector are " << _dtMapAss.size()
163  << std::endl;
164  }
165 
166  return returnList;
167 
168 }
169 
170 
171 
172 
175 {
176 
178  std::vector<size_t>::const_iterator it = _rpcMapUnass.rpcIn.begin();
179  std::vector<size_t>::const_iterator itend = _rpcMapUnass.rpcIn.end();
180 
181  for ( ; it != itend; ++it )
182  returnList.push_back( _rpcInAssociatedStubs.at( *it ) );
183 
184  return returnList;
185 
186 }
187 
188 
191 {
192 
194  std::vector<size_t>::const_iterator it = _rpcMapUnass.rpcOut.begin();
195  std::vector<size_t>::const_iterator itend = _rpcMapUnass.rpcOut.end();
196 
197  for ( ; it != itend; ++it )
198  returnList.push_back( _rpcOutAssociatedStubs.at( *it ) );
199 
200  return returnList;
201 
202 }
203 
204 
205 
206 
208 {
209 
211 
212  if ( dt1 == dt2 ) {
213  throw cms::Exception("DT primitive compared to itself")
214  << "The two id passed refer to the same primitive"
215  << std::endl;
216  }
217 
218  try {
219  const primitiveAssociation & prim1 = _dtMapAss.at(dt1);
220  const primitiveAssociation & prim2 = _dtMapAss.at(dt2);
221 
222 // bool in_match = false;
223 // bool out_match = false;
224 
225 // size_t rpcInSize1 = prim1.rpcIn.size();
226 // size_t rpcInSize2 = prim2.rpcIn.size();
227 // for ( size_t i = 0; i < rpcInSize1; ++i )
228 // for ( size_t j = 0; j < rpcInSize2; ++j )
229 // if ( prim1.rpcIn[i] == prim1.rpcIn[j] ) {
230 // in_match = true;
231 // i = rpcInSize1;
232 // break;
233 // }
234 
235 // size_t rpcOutSize1 = prim1.rpcOut.size();
236 // size_t rpcOutSize2 = prim2.rpcOut.size();
237 // for ( size_t i = 0; i < rpcOutSize1; ++i )
238 // for ( size_t j = 0; j < rpcOutSize2; ++j )
239 // if ( prim1.rpcOut[i] == prim1.rpcOut[j] ) {
240 // out_match = true;
241 // i = rpcOutSize1;
242 // break;
243 // }
244 // if ( in_match && out_match ) return FULLMATCH;
245 // else if ( in_match ) return INMATCH;
246 // else if ( out_match ) return OUTMATCH;
247 // return NOMATCH;
248 
249 
250  if ( !prim1.rpcIn.empty() && !prim2.rpcIn.empty() ) {
251  if ( prim1.rpcIn.front() == prim2.rpcIn.front() ) {
252  ret_val = INMATCH;
253  }
254  }
255 
256  if ( !prim1.rpcOut.empty() && !prim2.rpcOut.empty() ) {
257  if ( prim1.rpcOut.front() == prim2.rpcOut.front() ) {
258  ret_val = ( ret_val == INMATCH ) ? FULLMATCH : OUTMATCH;
259  }
260  }
261  return ret_val;
262 
263  } catch ( const std::out_of_range & e ) {
264  throw cms::Exception("DT Chamber Out of Range")
265  << "The number of dt primitives in sector are " << _dtMapAss.size()
266  << std::endl;
267  }
268 
269  return ret_val;
270 
271 }
272 
273 
274 
276 bool
277 L1TwinMux::MBLTCollection::areCloseClusters( std::vector< size_t > & cluster1,
278  std::vector< size_t > & cluster2,
279  const L1TwinMux::TriggerPrimitiveList & rpcList1,
280  const L1TwinMux::TriggerPrimitiveList & rpcList2,
281  double minRpcPhi ) const
282 {
283 
284  size_t clSize1 = cluster1.size();
285  size_t clSize2 = cluster2.size();
286 
287  for ( size_t idx1 = 0; idx1 < clSize1; ++idx1 ) {
288 
289  size_t uidx1 = cluster1.at(idx1);
290  double phi1 = rpcList1.at( uidx1 )->getCMSGlobalPhi();
291 
292  for ( size_t idx2 = 0; idx2 < clSize2; ++idx2 ) {
293 
294  size_t uidx2 = cluster2.at(idx2);
295  double phi2 = rpcList2.at( uidx2 )->getCMSGlobalPhi();
296  double deltaPhiIn = fabs( reco::deltaPhi( phi1, phi2 ) );
297  if ( deltaPhiIn < minRpcPhi ) {
298  return true;
299  }
300  }
301  }
302 
303  return false;
304 
305 }
306 
307 
309 size_t
310 L1TwinMux::MBLTCollection::reduceRpcClusters( std::vector< std::vector <size_t> > & clusters,
311  const L1TwinMux::TriggerPrimitiveList & rpcList,
312  double minRpcPhi ) const
313 {
314 
315  size_t clusterSize = clusters.size();
316  if ( clusterSize < 2 ) return 0;
317 
318  std::vector<bool> pickUpClusterMap( clusterSize, true );
319 
320  size_t reduced = 0;
321  for ( size_t cidx1 = 0; cidx1 < clusterSize; ++cidx1 ) {
322 
323  if ( pickUpClusterMap.at(cidx1) ) {
324  for ( size_t cidx2 = cidx1+1; cidx2 < clusterSize; ++cidx2 ) {
325  if ( pickUpClusterMap.at(cidx2) &&
326  areCloseClusters( clusters.at(cidx1), clusters.at(cidx2),
327  rpcList, rpcList, minRpcPhi ) ) {
328 
329  clusters.at(cidx1).insert( clusters.at(cidx1).end(),
330  clusters.at(cidx2).begin(),
331  clusters.at(cidx2).end() );
332  pickUpClusterMap[cidx2] = false;
333  ++reduced;
334  }
335  }
336  }
337  }
338 
339  if ( reduced ) {
340  // std::cout << "### Reduce..." << std::endl; CB commented out, is it really needed?
341  std::vector< std::vector <size_t> > tmpClusters;
342  for ( size_t cidx = 0; cidx < clusterSize; ++cidx ) {
343  if ( pickUpClusterMap.at(cidx) ) {
344  tmpClusters.push_back( clusters.at(cidx) );
345  }
346  }
347  clusters = tmpClusters;
348  }
349 
350  return reduced;
351 }
352 
353 
355 void
356 L1TwinMux::MBLTCollection::getUnassociatedRpcClusters( const std::vector< size_t > & rpcUnass,
357  const L1TwinMux::TriggerPrimitiveList & rpcList,
358  double minRpcPhi,
359  std::vector< std::vector <size_t> > & clusters ) const
360 {
361 
362  if ( rpcUnass.empty() ) return;
363 
364  size_t rpcSizeU = rpcUnass.size();
365  std::vector<bool> pickUpMap( rpcSizeU, true );
366 
367  for ( size_t idx1 = 0; idx1 < rpcSizeU; ++idx1 ) {
368 
369  if ( pickUpMap.at(idx1) ) {
370 
372  size_t uidx1 = rpcUnass.at(idx1);
373 
374  std::vector<size_t> subCluster = { uidx1 };
375  double phi1 = rpcList.at( uidx1 )->getCMSGlobalPhi();
376 
377  for ( size_t idx2 = idx1+1; idx2 < rpcSizeU; ++idx2 ) {
378 
379  if ( pickUpMap.at(idx2) ) {
380 
382  size_t uidx2 = rpcUnass.at(idx2);
383 
384  double phi2 = rpcList.at( uidx2 )->getCMSGlobalPhi();
385  double deltaPhiIn = fabs( reco::deltaPhi( phi1, phi2 ) );
386  if ( deltaPhiIn < minRpcPhi ) {
387  subCluster.push_back( uidx2 );
388  pickUpMap[idx2] = false;
389  }
390  }
391  }
392  clusters.push_back( subCluster );
393  }
394  }
395 
396  size_t reduced = 0;
397  do {
398  reduced = reduceRpcClusters( clusters, rpcList, minRpcPhi );
399  } while ( reduced );
400 
401 }
402 
403 
404 
405 
407 std::vector< std::pair< L1TwinMux::TriggerPrimitiveList, L1TwinMux::TriggerPrimitiveList > >
409 {
410 
412 
413  std::vector< std::pair< L1TwinMux::TriggerPrimitiveList, L1TwinMux::TriggerPrimitiveList > > associated;
414 
415  if ( _rpcMapUnass.rpcIn.empty() && _rpcMapUnass.rpcOut.empty())
416  return associated;
419 
420  std::vector< std::vector <size_t> > inClusters;
421  try {
422  getUnassociatedRpcClusters( _rpcMapUnass.rpcIn, _rpcInAssociatedStubs,
423  minRpcPhi, inClusters );
424  } catch ( const std::out_of_range & e ) {
425  std::cout << " getUnassociatedRpcClusters " << e.what() << std::endl;
426  throw cms::Exception("RPC HIT Out of Range")<< std::endl;
427  }
428 
429  size_t rpcInClusterSize = inClusters.size();
430  std::vector< std::vector <size_t> > outClusters;
431  try {
432  getUnassociatedRpcClusters( _rpcMapUnass.rpcOut, _rpcOutAssociatedStubs,
433  minRpcPhi, outClusters );
434  } catch ( const std::out_of_range & e ) {
435  std::cout << " getUnassociatedRpcClusters " << e.what() << std::endl;
436  throw cms::Exception("RPC HIT Out of Range")<< std::endl;
437  }
438 
439  size_t rpcOutClusterSize = outClusters.size();
441 
442  std::vector<bool> spareInMap( rpcInClusterSize, true );
443  std::vector<bool> spareOutMap( rpcOutClusterSize, true );
444 
445  for ( size_t in = 0; in < rpcInClusterSize; ++in ) {
446  for ( size_t out = 0; out < rpcOutClusterSize; ++out ) {
447  if ( areCloseClusters( inClusters.at(in),
448  outClusters.at(out),
449  _rpcInAssociatedStubs,
450  _rpcOutAssociatedStubs,
451  minRpcPhi ) ) {
452 
454  std::vector<size_t>::const_iterator itIn = inClusters.at(in).begin();
455  std::vector<size_t>::const_iterator itInEnd = inClusters.at(in).end();
456  for ( ; itIn != itInEnd; ++itIn )
457  primIn.push_back( _rpcInAssociatedStubs.at(*itIn) );
458 
460  std::vector<size_t>::const_iterator itOut = outClusters.at(out).begin();
461  std::vector<size_t>::const_iterator itOutEnd = outClusters.at(out).end();
462  for ( ; itOut != itOutEnd; ++itOut )
463  primOut.push_back( _rpcOutAssociatedStubs.at(*itOut) );
464 
465  associated.push_back( std::pair< L1TwinMux::TriggerPrimitiveList, L1TwinMux::TriggerPrimitiveList >(primIn, primOut) );
466  spareInMap[in] = false;
467  spareOutMap[out] = false;
468  }
469  }
470  }
471 
472  for ( size_t in = 0; in < rpcInClusterSize; ++in ) {
473  if ( spareInMap[in] ) {
474 
476  std::vector<size_t>::const_iterator itIn = inClusters.at(in).begin();
477  std::vector<size_t>::const_iterator itInEnd = inClusters.at(in).end();
478  for ( ; itIn != itInEnd; ++itIn )
479  primIn.push_back( _rpcInAssociatedStubs.at(*itIn) );
480 
482  associated.push_back( std::pair< L1TwinMux::TriggerPrimitiveList, L1TwinMux::TriggerPrimitiveList >(primIn, primOut) );
483  }
484  }
485 
486  for ( size_t out = 0; out < rpcOutClusterSize; ++out ) {
487  if ( spareOutMap[out] ) {
488 
489 
492  std::vector<size_t>::const_iterator itOut = outClusters.at(out).begin();
493  std::vector<size_t>::const_iterator itOutEnd = outClusters.at(out).end();
494  for ( ; itOut != itOutEnd; ++itOut )
495  primOut.push_back( _rpcOutAssociatedStubs.at(*itOut) );
496 
497  associated.push_back( std::pair< L1TwinMux::TriggerPrimitiveList, L1TwinMux::TriggerPrimitiveList >(primIn, primOut) );
498  }
499  }
500 
501 
502  return associated;
503 
504 }
type
Definition: HCALResponse.h:21
TriggerPrimitiveList getRpcInUnassociatedStubs() const
rpc inner layer hits associated to a given dt station
bxMatch haveCommonRpc(size_t dt1, size_t dt2) const
std::vector< std::pair< TriggerPrimitiveList, TriggerPrimitiveList > > getUnassociatedRpcClusters(double minRpcPhi) const
RPC unassociated clusters.
int _wheel
space coordinates
const double NOMATCH
bool areCloseClusters(std::vector< size_t > &cluster1, std::vector< size_t > &cluster2, const TriggerPrimitiveList &rpcList1, const TriggerPrimitiveList &rpcList2, double minRpcPhi) const
TriggerPrimitiveList getRpcInAssociatedStubs(size_t dtIndex) const
rpc inner layer hits associated to a given dt station
structure for internal indexing
void addStub(const TriggerPrimitiveRef &stub)
size_t reduceRpcClusters(std::vector< std::vector< size_t > > &tmpClusters, const TriggerPrimitiveList &rpcList, double minRpcPhi) const
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
int layer() const
Definition: RPCDetId.h:108
std::vector< TriggerPrimitiveRef > TriggerPrimitiveList
Geom::Phi< T > phi() const
int sector() const
Definition: DTChamberId.h:61
tuple cout
Definition: gather_cfg.py:145
TriggerPrimitiveList getRpcOutAssociatedStubs(size_t dtIndex) const
rpc outer layer hits associated to a given dt station
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
MBLTCollection()
default constructor
TriggerPrimitiveList getRpcOutUnassociatedStubs() const
rpc outer layer hits associated to a given dt station
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63