CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCHaloAlgo.cc
Go to the documentation of this file.
3 /*
4  [class]: CSCHaloAlgo
5  [authors]: R. Remington, The University of Florida
6  [description]: See CSCHaloAlgo.h
7  [date]: October 15, 2009
8 */
9 using namespace reco;
10 using namespace std;
11 using namespace edm;
12 #include "TMath.h"
13 
15 {
16  deta_threshold = 0.;
17  min_inner_radius = 0.;
18  max_inner_radius = 9999.;
19  min_outer_radius = 0.;
20  max_outer_radius = 9999.;
21  dphi_threshold = 999.;
22  norm_chi2_threshold = 999.;
23  recHit_t0=200;
24  recHit_twindow=500;
25  expected_BX=3;
26 
27  min_outer_theta = 0.;
28  max_outer_theta = TMath::Pi();
29 
30  matching_dphi_threshold = 0.18; //radians
31  matching_deta_threshold = 0.4;
32  matching_dwire_threshold = 5.;
33 }
34 
38  edm::Handle<CSCSegmentCollection>& TheCSCSegments,
41  edm::Handle<edm::TriggerResults>& TheHLTResults,
42  const edm::TriggerNames * triggerNames, const edm::Handle<CSCALCTDigiCollection>& TheALCTs)
43 {
44  reco::CSCHaloData TheCSCHaloData;
45  if( TheCSCTracks.isValid() )
46  {
47  for( reco::TrackCollection::const_iterator iTrack = TheCSCTracks->begin() ; iTrack != TheCSCTracks->end() ; iTrack++ )
48  {
49  bool StoreTrack = false;
50  // Calculate global phi coordinate for central most rechit in the track
51  float innermost_global_z = 1500.;
52  float outermost_global_z = 0.;
53  GlobalPoint InnerMostGlobalPosition(0.,0.,0.); // smallest abs(z)
54  GlobalPoint OuterMostGlobalPosition(0.,0.,0.); // largest abs(z)
55  int nCSCHits = 0;
56  for(unsigned int j = 0 ; j < iTrack->extra()->recHits().size(); j++ )
57  {
58  edm::Ref<TrackingRecHitCollection> hit( iTrack->extra()->recHits(), j );
59  if( !hit->isValid() ) continue;
60  DetId TheDetUnitId(hit->geographicalId());
61  if( TheDetUnitId.det() != DetId::Muon ) continue;
62  if( TheDetUnitId.subdetId() != MuonSubdetId::CSC ) continue;
63 
64  const GeomDetUnit *TheUnit = TheCSCGeometry.idToDetUnit(TheDetUnitId);
65  LocalPoint TheLocalPosition = hit->localPosition();
66  const BoundPlane& TheSurface = TheUnit->surface();
67  const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
68 
69  float z = TheGlobalPosition.z();
70  if( TMath::Abs(z) < innermost_global_z )
71  {
72  innermost_global_z = TMath::Abs(z);
73  InnerMostGlobalPosition = GlobalPoint( TheGlobalPosition);
74  }
75  if( TMath::Abs(z) > outermost_global_z )
76  {
77  outermost_global_z = TMath::Abs(z);
78  OuterMostGlobalPosition = GlobalPoint( TheGlobalPosition );
79  }
80  nCSCHits ++;
81  }
82 
83  if( nCSCHits < 3 ) continue; // This needs to be optimized, but is the minimum
84 
85  if( OuterMostGlobalPosition.x() == 0. || OuterMostGlobalPosition.y() == 0. || OuterMostGlobalPosition.z() == 0. )
86  continue;
87  if( InnerMostGlobalPosition.x() == 0. || InnerMostGlobalPosition.y() == 0. || InnerMostGlobalPosition.z() == 0. )
88  continue;
89 
90  //Its a CSC Track,store it if it passes halo selection
91  StoreTrack = true;
92 
93  float deta = TMath::Abs( OuterMostGlobalPosition.eta() - InnerMostGlobalPosition.eta() );
94  float dphi = TMath::ACos( TMath::Cos( OuterMostGlobalPosition.phi() - InnerMostGlobalPosition.phi() ) ) ;
95  float theta = iTrack->outerMomentum().theta();
96  float innermost_x = InnerMostGlobalPosition.x() ;
97  float innermost_y = InnerMostGlobalPosition.y();
98  float outermost_x = OuterMostGlobalPosition.x();
99  float outermost_y = OuterMostGlobalPosition.y();
100  float innermost_r = TMath::Sqrt(innermost_x *innermost_x + innermost_y * innermost_y );
101  float outermost_r = TMath::Sqrt(outermost_x *outermost_x + outermost_y * outermost_y );
102 
103  if( deta < deta_threshold )
104  StoreTrack = false;
105  if( theta > min_outer_theta && theta < max_outer_theta )
106  StoreTrack = false;
107  if( dphi > dphi_threshold )
108  StoreTrack = false;
109  if( innermost_r < min_inner_radius )
110  StoreTrack = false;
111  if( innermost_r > max_inner_radius )
112  StoreTrack = false;
113  if( outermost_r < min_outer_radius )
114  StoreTrack = false;
115  if( outermost_r > max_outer_radius )
116  StoreTrack = false;
117  if( iTrack->normalizedChi2() > norm_chi2_threshold )
118  StoreTrack = false;
119 
120 
121 
122  if( StoreTrack )
123  {
124  TheCSCHaloData.GetCSCTrackImpactPositions().push_back( InnerMostGlobalPosition );
125 
126  edm::Ref<TrackCollection> TheTrackRef( TheCSCTracks, iTrack - TheCSCTracks->begin() ) ;
127  TheCSCHaloData.GetTracks().push_back( TheTrackRef );
128  }
129  }
130  }
131 
132  if( TheHLTResults.isValid() )
133  {
134  bool EventPasses = false;
135  for( unsigned int index = 0 ; index < vIT_HLTBit.size(); index++)
136  {
137  if( vIT_HLTBit[index].label().size() )
138  {
139  //Get the HLT bit and check to make sure it is valid
140  unsigned int bit = triggerNames->triggerIndex( vIT_HLTBit[index].label().c_str());
141  if( bit < TheHLTResults->size() )
142  {
143  //If any of the HLT names given by the user accept, then the event passes
144  if( TheHLTResults->accept( bit ) && !TheHLTResults->error( bit ) )
145  {
146  EventPasses = true;
147  }
148  }
149  }
150  }
151  if( EventPasses )
152  TheCSCHaloData.SetHLTBit(true);
153  else
154  TheCSCHaloData.SetHLTBit(false);
155  }
156 
157  if( TheL1GMTReadout.isValid() )
158  {
159  L1MuGMTReadoutCollection const *gmtrc = TheL1GMTReadout.product ();
160  std::vector < L1MuGMTReadoutRecord > gmt_records = gmtrc->getRecords ();
161  std::vector < L1MuGMTReadoutRecord >::const_iterator igmtrr;
162 
163  int icsc = 0;
164  int PlusZ = 0 ;
165  int MinusZ = 0 ;
166  // Check to see if CSC BeamHalo trigger is tripped
167  for (igmtrr = gmt_records.begin (); igmtrr != gmt_records.end (); igmtrr++)
168  {
169  std::vector < L1MuRegionalCand >::const_iterator iter1;
170  std::vector < L1MuRegionalCand > rmc;
171  rmc = igmtrr->getCSCCands ();
172  for (iter1 = rmc.begin (); iter1 != rmc.end (); iter1++)
173  {
174  if (!(*iter1).empty ())
175  {
176  if ((*iter1).isFineHalo ())
177  {
178  float halophi = iter1->phiValue();
179  halophi = halophi > TMath::Pi() ? halophi - 2.*TMath::Pi() : halophi;
180  float haloeta = iter1->etaValue();
181  bool HaloIsGood = true;
182  // Check if halo trigger is faked by any collision muons
183  if( TheMuons.isValid() )
184  {
185  float dphi = 9999.;
186  float deta = 9999.;
187  for( reco::MuonCollection::const_iterator mu = TheMuons->begin(); mu != TheMuons->end() && HaloIsGood ; mu++ )
188  {
189  // Don't match with SA-only muons
190  if( mu->isStandAloneMuon() && !mu->isTrackerMuon() && !mu->isGlobalMuon() ) continue;
191 
192  /*
193  if(!mu->isTrackerMuon())
194  {
195  if( mu->isStandAloneMuon() )
196  {
197  //make sure that this SA muon is not actually a halo-like muon
198  float theta = mu->outerTrack()->outerMomentum().theta();
199  float deta = TMath::Abs(mu->outerTrack()->outerPosition().eta() - mu->outerTrack()->innerPosition().eta());
200  if( theta < min_outer_theta || theta > max_outer_theta ) //halo-like
201  continue;
202  else if ( deta > deta_threshold ) //halo-like
203  continue;
204  }
205  }
206  */
207 
208  const std::vector<MuonChamberMatch> chambers = mu->matches();
209  for(std::vector<MuonChamberMatch>::const_iterator iChamber = chambers.begin();
210  iChamber != chambers.end() ; iChamber ++ )
211  {
212  if( iChamber->detector() != MuonSubdetId::CSC ) continue;
213  for( std::vector<reco::MuonSegmentMatch>::const_iterator iSegment = iChamber->segmentMatches.begin() ;
214  iSegment != iChamber->segmentMatches.end(); ++iSegment )
215  {
216  edm::Ref<CSCSegmentCollection> cscSegment = iSegment->cscSegmentRef;
217  std::vector<CSCRecHit2D> hits = cscSegment -> specificRecHits();
218  for( std::vector<CSCRecHit2D>::iterator iHit = hits.begin();
219  iHit != hits.end() ; iHit++ )
220  {
221  DetId TheDetUnitId(iHit->cscDetId());
222  const GeomDetUnit *TheUnit = TheCSCGeometry.idToDetUnit(TheDetUnitId);
223  LocalPoint TheLocalPosition = iHit->localPosition();
224  const BoundPlane& TheSurface = TheUnit->surface();
225  GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
226 
227  float phi_ = TheGlobalPosition.phi();
228  float eta_ = TheGlobalPosition.eta();
229  deta = deta < TMath::Abs( eta_ - haloeta ) ? deta : TMath::Abs( eta_ - haloeta );
230  dphi = dphi < TMath::Abs( phi_ - halophi ) ? dphi : TMath::Abs( phi_ - halophi );
231  }
232  }
233  }
234  if ( dphi < matching_dphi_threshold && deta < matching_deta_threshold)
235  HaloIsGood = false; // i.e., collision muon likely faked halo trigger
236  }
237  }
238  if( !HaloIsGood )
239  continue;
240  if( (*iter1).etaValue() > 0 )
241  PlusZ++;
242  else
243  MinusZ++;
244  }
245  else
246  icsc++;
247  }
248  }
249  }
250  TheCSCHaloData.SetNumberOfHaloTriggers(PlusZ, MinusZ);
251  }
252 
253  // Loop over CSCALCTDigi collection to look for out-of-time chamber triggers
254  // A collision muon in real data should only have ALCTDigi::getBX() = 3 ( in MC, it will be 6 )
255  // Note that there could be two ALCTs per chamber
256  short int n_alctsP=0;
257  short int n_alctsM=0;
258  if(TheALCTs.isValid())
259  {
260  for (CSCALCTDigiCollection::DigiRangeIterator j=TheALCTs->begin(); j!=TheALCTs->end(); j++)
261  {
262  const CSCALCTDigiCollection::Range& range =(*j).second;
263  CSCDetId detId((*j).first.rawId());
264  for (CSCALCTDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt)
265  {
266  if( (*digiIt).isValid() && ( (*digiIt).getBX() < expected_BX ) )
267  {
268  int digi_endcap = detId.endcap();
269  int digi_station = detId.station();
270  int digi_ring = detId.ring();
271  int digi_chamber = detId.chamber();
272  int digi_wire = digiIt->getKeyWG();
273  if( digi_station == 1 && digi_ring == 4 ) //hack
274  digi_ring = 1;
275 
276  bool DigiIsGood = true;
277  int dwire = 999.;
278  if( TheMuons.isValid() )
279  {
280  //Check if there are any collision muons with hits in the vicinity of the digi
281  for(reco::MuonCollection::const_iterator mu = TheMuons->begin(); mu!= TheMuons->end() && DigiIsGood ; mu++ )
282  {
283  if( !mu->isTrackerMuon() && !mu->isGlobalMuon() && mu->isStandAloneMuon() ) continue;
284  /*
285  if(!mu->isTrackerMuon())
286  {
287  if( mu->isStandAloneMuon() )
288  {
289  //make sure that this SA muon is not actually a halo-like muon
290  float theta = mu->outerTrack()->outerMomentum().theta();
291  float deta = TMath::Abs(mu->outerTrack()->outerPosition().eta() - mu->outerTrack()->innerPosition().eta());
292  if( theta < min_outer_theta || theta > max_outer_theta ) //halo-like
293  continue;
294  else if ( deta > deta_threshold ) //halo-like
295  continue;
296  }
297  }
298  */
299 
300  const std::vector<MuonChamberMatch> chambers = mu->matches();
301  for(std::vector<MuonChamberMatch>::const_iterator iChamber = chambers.begin();
302  iChamber != chambers.end(); iChamber ++ )
303  {
304  if( iChamber->detector() != MuonSubdetId::CSC ) continue;
305  for( std::vector<reco::MuonSegmentMatch>::const_iterator iSegment = iChamber->segmentMatches.begin();
306  iSegment != iChamber->segmentMatches.end(); iSegment++ )
307  {
308  edm::Ref<CSCSegmentCollection> cscSegRef = iSegment->cscSegmentRef;
309  std::vector<CSCRecHit2D> hits = cscSegRef->specificRecHits();
310  for( std::vector<CSCRecHit2D>::iterator iHit = hits.begin();
311  iHit != hits.end(); iHit++ )
312  {
313  if( iHit->cscDetId().endcap() != digi_endcap ) continue;
314  if( iHit->cscDetId().station() != digi_station ) continue;
315  if( iHit->cscDetId().ring() != digi_ring ) continue;
316  if( iHit->cscDetId().chamber() != digi_chamber ) continue;
317  CSCRecHit2D::ChannelContainer hitwires = iHit->wgroups();
318  int nwires = hitwires.size();
319  int center_id = nwires/2 + 1;
320  int hit_wire = hitwires[center_id -1 ];
321  dwire = dwire < TMath::Abs(hit_wire - digi_wire)? dwire : TMath::Abs(hit_wire - digi_wire );
322  }
323  }
324  }
325  if( dwire <= matching_dwire_threshold )
326  DigiIsGood = false; // collision-like muon is close to this digi
327  }
328  }
329  // only count out of time digis if they are not matched to collision muons
330  if( DigiIsGood )
331  {
332  if( detId.endcap() == 1 )
333  n_alctsP++;
334  else if ( detId.endcap() == 2)
335  n_alctsM++;
336  }
337  }
338  }
339  }
340  }
341  TheCSCHaloData.SetNOutOfTimeTriggers(n_alctsP,n_alctsM);
342 
343  // Loop over the CSCRecHit2D collection to look for out-of-time recHits
344  // Out-of-time is defined as tpeak outside [t_0 + TOF - t_window, t_0 + TOF + t_window]
345  // where t_0 and t_window are configurable parameters
346  short int n_recHitsP = 0;
347  short int n_recHitsM = 0;
348  if( TheCSCRecHits.isValid() )
349  {
351  for (dRHIter = TheCSCRecHits->begin(); dRHIter != TheCSCRecHits->end(); dRHIter++)
352  {
353  if ( !((*dRHIter).isValid()) ) continue; // only interested in valid hits
354  CSCDetId idrec = (CSCDetId)(*dRHIter).cscDetId();
355  float RHTime = (*dRHIter).tpeak();
356  LocalPoint rhitlocal = (*dRHIter).localPosition();
357  const CSCChamber* chamber = TheCSCGeometry.chamber(idrec);
358  GlobalPoint globalPosition = chamber->toGlobal(rhitlocal);
359  float globZ = globalPosition.z();
360  if ( RHTime < (recHit_t0 - recHit_twindow) )
361  {
362  if( globZ > 0 )
363  n_recHitsP++;
364  else
365  n_recHitsM++;
366  }
367 
368  /*
369 
370  float globX = globalPosition.x();
371  float globY = globalPosition.y();
372  float globZ = globalPosition.z();
373  float TOF = (sqrt(globX*globX+ globY*globY + globZ*globZ))/29.9792458 ; //cm -> ns
374  if ( (RHTime < (recHit_t0 + TOF - recHit_twindow)) || (RHTime > (recHit_t0 + TOF + recHit_twindow)) )
375  {
376  if( globZ > 0 )
377  n_recHitsP++;
378  else
379  n_recHitsM++;
380  }
381  */
382  }
383  }
384  TheCSCHaloData.SetNOutOfTimeHits(n_recHitsP+n_recHitsM);
385 
386  return TheCSCHaloData;
387 }
388 
389 
const double Pi
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
const std::string & label
Definition: MVAComputer.cc:186
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:57
static char chambers[TOTALCHAMBERS][20]
Definition: ReadPGInfo.cc:243
double double double z
int endcap() const
Definition: CSCDetId.h:95
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:46
static const int CSC
Definition: MuonSubdetId.h:15
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:87
T z() const
Definition: PV3DBase.h:58
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
Definition: CSCHaloData.h:66
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:76
std::vector< L1MuGMTReadoutRecord > getRecords() const
void SetHLTBit(bool status)
Definition: CSCHaloData.h:62
Definition: DetId.h:20
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:117
void SetNumberOfHaloTriggers(int PlusZ, int MinusZ)
Definition: CSCHaloData.h:54
std::vector< DigiType >::const_iterator const_iterator
T const * product() const
Definition: Handle.h:74
T eta() const
Definition: PV3DBase.h:70
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:60
void SetNOutOfTimeHits(short int num)
Definition: CSCHaloData.h:59
std::pair< const_iterator, const_iterator > Range
void SetNOutOfTimeTriggers(short int PlusZ, short int MinusZ)
Definition: CSCHaloData.h:57
reco::CSCHaloData Calculate(const CSCGeometry &TheCSCGeometry, edm::Handle< reco::TrackCollection > &TheCSCTracks, edm::Handle< reco::MuonCollection > &TheMuons, edm::Handle< CSCSegmentCollection > &TheCSCSegments, edm::Handle< CSCRecHit2DCollection > &TheCSCRecHits, edm::Handle< L1MuGMTReadoutCollection > &TheL1GMTReadout, edm::Handle< edm::TriggerResults > &TheHLTResults, const edm::TriggerNames *triggerNames, const edm::Handle< CSCALCTDigiCollection > &TheALCTs)
Definition: CSCHaloAlgo.cc:35
T x() const
Definition: PV3DBase.h:56
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
tuple size
Write out results.
std::vector< int > ChannelContainer
Definition: CSCRecHit2D.h:22
edm::RefVector< reco::TrackCollection > & GetTracks()
Definition: CSCHaloData.h:50