CMS 3D CMS Logo

CSCHaloAlgo.cc
Go to the documentation of this file.
1 
4 /*
5  [class]: CSCHaloAlgo
6  [authors]: R. Remington, The University of Florida
7  [description]: See CSCHaloAlgo.h
8  [date]: October 15, 2009
9 */
10 using namespace reco;
11 using namespace std;
12 using namespace edm;
13 #include "TMath.h"
14 namespace {
15  constexpr float c_cm_per_ns = 29.9792458;
16 };
18 {
19  deta_threshold = 0.;
20  min_inner_radius = 0.;
21  max_inner_radius = 9999.;
22  min_outer_radius = 0.;
23  max_outer_radius = 9999.;
24  dphi_threshold = 999.;
25  norm_chi2_threshold = 999.;
26  recHit_t0=0.;
27  recHit_twindow=25.;
28  expected_BX=3;
29  max_dt_muon_segment=-10.0;
30  max_free_inverse_beta=0.0;
31 
32  min_outer_theta = 0.;
33  max_outer_theta = TMath::Pi();
34 
35  matching_dphi_threshold = 0.18; //radians
36  matching_deta_threshold = 0.4;
37  matching_dwire_threshold = 5.;
38 
39 
40  et_thresh_rh_hbhe=25; //GeV
41  et_thresh_rh_ee=10;
42  et_thresh_rh_eb=10;
43 
44  dphi_thresh_segvsrh_hbhe=0.05; //radians
45  dphi_thresh_segvsrh_eb=0.05;
46  dphi_thresh_segvsrh_ee=0.05;
47 
48  dr_lowthresh_segvsrh_hbhe=-20; //cm
49  dr_lowthresh_segvsrh_eb=-20;
50  dr_lowthresh_segvsrh_ee=-20;
51 
52  dr_highthresh_segvsrh_hbhe=20; //cm
53  dr_highthresh_segvsrh_eb=20;
54  dr_highthresh_segvsrh_ee=20;
55 
56  dt_lowthresh_segvsrh_hbhe=5;//ns
57  dt_lowthresh_segvsrh_eb=5;
58  dt_lowthresh_segvsrh_ee=5;
59 
60  dt_highthresh_segvsrh_hbhe=30;//ns
61  dt_highthresh_segvsrh_eb=30;
62  dt_highthresh_segvsrh_ee=30;
63 
64  geo = 0;
65 
66 
67 
68 }
69 
71  edm::Handle<reco::MuonCollection>& TheCosmicMuons,
72  const edm::Handle<reco::MuonTimeExtraMap> TheCSCTimeMap,
74  edm::Handle<CSCSegmentCollection>& TheCSCSegments,
80  edm::Handle<edm::TriggerResults>& TheHLTResults,
81  const edm::TriggerNames * triggerNames,
82  const edm::Handle<CSCALCTDigiCollection>& TheALCTs,
83  MuonSegmentMatcher *TheMatcher,
84  const edm::Event& TheEvent,
85  const edm::EventSetup& TheSetup)
86 {
87  reco::CSCHaloData TheCSCHaloData;
88  int imucount=0;
89 
90  bool calomatched =false;
91  bool ECALBmatched =false;
92  bool ECALEmatched =false;
93  bool HCALmatched =false;
94 
95  // if(!geo){
96  geo = 0;
98  TheSetup.get<CaloGeometryRecord>().get(pGeo);
99  geo = pGeo.product();
100  //}
101  bool trkmuunvetoisdefault = false; //Pb with low pt tracker muons that veto good csc segments/halo triggers.
102  //Test to "unveto" low pt trk muons.
103  //For now, we just recalculate everything without the veto and add an extra set of variables to the class CSCHaloData.
104  //If this is satisfactory, these variables can become the default ones by setting trkmuunvetoisdefault to true.
105  if( TheCosmicMuons.isValid() )
106  {
107  short int n_tracks_small_beta=0;
108  short int n_tracks_small_dT=0;
109  short int n_tracks_small_dT_and_beta=0;
110  for( reco::MuonCollection::const_iterator iMuon = TheCosmicMuons->begin() ; iMuon != TheCosmicMuons->end() ; iMuon++, imucount++ )
111  {
112  reco::TrackRef Track = iMuon->outerTrack();
113  if(!Track) continue;
114 
115  bool StoreTrack = false;
116  // Calculate global phi coordinate for central most rechit in the track
117  float innermost_global_z = 1500.;
118  float outermost_global_z = 0.;
119  GlobalPoint InnerMostGlobalPosition(0.,0.,0.); // smallest abs(z)
120  GlobalPoint OuterMostGlobalPosition(0.,0.,0.); // largest abs(z)
121  int nCSCHits = 0;
122  for(unsigned int j = 0 ; j < Track->extra()->recHitsSize(); j++ )
123  {
124  auto hit = Track->extra()->recHitRef(j);
125  if( !hit->isValid() ) continue;
126  DetId TheDetUnitId(hit->geographicalId());
127  if( TheDetUnitId.det() != DetId::Muon ) continue;
128  if( TheDetUnitId.subdetId() != MuonSubdetId::CSC ) continue;
129 
130  const GeomDetUnit *TheUnit = TheCSCGeometry.idToDetUnit(TheDetUnitId);
131  LocalPoint TheLocalPosition = hit->localPosition();
132  const BoundPlane& TheSurface = TheUnit->surface();
133  const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
134 
135  float z = TheGlobalPosition.z();
136  if( abs(z) < innermost_global_z )
137  {
138  innermost_global_z = abs(z);
139  InnerMostGlobalPosition = GlobalPoint( TheGlobalPosition);
140  }
141  if( abs(z) > outermost_global_z )
142  {
143  outermost_global_z = abs(z);
144  OuterMostGlobalPosition = GlobalPoint( TheGlobalPosition );
145  }
146  nCSCHits ++;
147  }
148 
149  std::vector<const CSCSegment*> MatchedSegments = TheMatcher->matchCSC(*Track,TheEvent);
150  // Find the inner and outer segments separately in case they don't agree completely with recHits
151  // Plan for the possibility segments in both endcaps
152  float InnerSegmentTime[2] = {0,0};
153  float OuterSegmentTime[2] = {0,0};
154  float innermost_seg_z[2] = {1500,1500};
155  float outermost_seg_z[2] = {0,0};
156  for (std::vector<const CSCSegment*>::const_iterator segment =MatchedSegments.begin();
157  segment != MatchedSegments.end(); ++segment)
158  {
159  CSCDetId TheCSCDetId((*segment)->cscDetId());
160  const CSCChamber* TheCSCChamber = TheCSCGeometry.chamber(TheCSCDetId);
161  LocalPoint TheLocalPosition = (*segment)->localPosition();
162  const GlobalPoint TheGlobalPosition = TheCSCChamber->toGlobal(TheLocalPosition);
163  float z = TheGlobalPosition.z();
164  int TheEndcap = TheCSCDetId.endcap();
165  if( abs(z) < innermost_seg_z[TheEndcap-1] )
166  {
167  innermost_seg_z[TheEndcap-1] = abs(z);
168  InnerSegmentTime[TheEndcap-1] = (*segment)->time();
169  }
170  if( abs(z) > outermost_seg_z[TheEndcap-1] )
171  {
172  outermost_seg_z[TheEndcap-1] = abs(z);
173  OuterSegmentTime[TheEndcap-1] = (*segment)->time();
174  }
175  }
176 
177  if( nCSCHits < 3 ) continue; // This needs to be optimized, but is the minimum
178 
179  float dT_Segment = 0; // default safe value, looks like collision muon
180 
181  if( innermost_seg_z[0] < outermost_seg_z[0]) // two segments in ME+
182  dT_Segment = OuterSegmentTime[0]-InnerSegmentTime[0];
183  if( innermost_seg_z[1] < outermost_seg_z[1]) // two segments in ME-
184  {
185  // replace the measurement if there weren't segments in ME+ or
186  // if the track in ME- has timing more consistent with an incoming particle
187  if (dT_Segment == 0.0 || OuterSegmentTime[1]-InnerSegmentTime[1] < dT_Segment)
188  dT_Segment = OuterSegmentTime[1]-InnerSegmentTime[1] ;
189  }
190 
191  if( OuterMostGlobalPosition.x() == 0. || OuterMostGlobalPosition.y() == 0. || OuterMostGlobalPosition.z() == 0. )
192  continue;
193  if( InnerMostGlobalPosition.x() == 0. || InnerMostGlobalPosition.y() == 0. || InnerMostGlobalPosition.z() == 0. )
194  continue;
195 
196  //Its a CSC Track,store it if it passes halo selection
197  StoreTrack = true;
198 
199  float deta = abs( OuterMostGlobalPosition.eta() - InnerMostGlobalPosition.eta() );
200  float dphi = abs(deltaPhi( OuterMostGlobalPosition.barePhi() , InnerMostGlobalPosition.barePhi() )) ;
201  float theta = Track->outerMomentum().theta();
202  float innermost_x = InnerMostGlobalPosition.x() ;
203  float innermost_y = InnerMostGlobalPosition.y();
204  float outermost_x = OuterMostGlobalPosition.x();
205  float outermost_y = OuterMostGlobalPosition.y();
206  float innermost_r = TMath::Sqrt(innermost_x *innermost_x + innermost_y * innermost_y );
207  float outermost_r = TMath::Sqrt(outermost_x *outermost_x + outermost_y * outermost_y );
208 
209  if( deta < deta_threshold )
210  StoreTrack = false;
211  if( theta > min_outer_theta && theta < max_outer_theta )
212  StoreTrack = false;
213  if( dphi > dphi_threshold )
214  StoreTrack = false;
215  if( innermost_r < min_inner_radius )
216  StoreTrack = false;
217  if( innermost_r > max_inner_radius )
218  StoreTrack = false;
219  if( outermost_r < min_outer_radius )
220  StoreTrack = false;
221  if( outermost_r > max_outer_radius )
222  StoreTrack = false;
223  if( Track->normalizedChi2() > norm_chi2_threshold )
224  StoreTrack = false;
225 
226  if( StoreTrack )
227  {
228  TheCSCHaloData.GetCSCTrackImpactPositions().push_back( InnerMostGlobalPosition );
229  TheCSCHaloData.GetTracks().push_back( Track );
230  }
231 
232  // Analyze the MuonTimeExtra information
233  if( TheCSCTimeMap.isValid() )
234  {
235  reco::MuonRef muonR(TheCosmicMuons,imucount);
236  const reco::MuonTimeExtraMap & timeMapCSC = *TheCSCTimeMap;
237  reco::MuonTimeExtra timecsc = timeMapCSC[muonR];
238  float freeInverseBeta = timecsc.freeInverseBeta();
239 
240  if (dT_Segment < max_dt_muon_segment )
241  n_tracks_small_dT++;
242  if (freeInverseBeta < max_free_inverse_beta)
243  n_tracks_small_beta++;
244  if ((dT_Segment < max_dt_muon_segment) && (freeInverseBeta < max_free_inverse_beta))
245  n_tracks_small_dT_and_beta++;
246  }
247  else
248  {
249  static std::atomic<bool> MuonTimeFail{false};
250  bool expected = false;
251  if( MuonTimeFail.compare_exchange_strong(expected,true,std::memory_order_acq_rel) )
252  {
253  edm::LogWarning ("InvalidInputTag") << "The MuonTimeExtraMap does not appear to be in the event. Some beam halo "
254  << " identification variables will be empty" ;
255  }
256  }
257  }
258  TheCSCHaloData.SetNIncomingTracks(n_tracks_small_dT,n_tracks_small_beta,n_tracks_small_dT_and_beta);
259  }
260  else // collection is invalid
261  {
262  static std::atomic<bool> CosmicFail{false};
263  bool expected = false;
264  if( CosmicFail.compare_exchange_strong(expected,true,std::memory_order_acq_rel) )
265  {
266  edm::LogWarning ("InvalidInputTag") << " The Cosmic Muon collection does not appear to be in the event. These beam halo "
267  << " identification variables will be empty" ;
268  }
269  }
270 
271 
272  // Loop over the CSCRecHit2D collection to look for out-of-time recHits
273  // Out-of-time is defined as tpeak outside [t_0 + TOF - t_window, t_0 + TOF + t_window]
274  // where t_0 and t_window are configurable parameters
275  short int n_recHitsP = 0;
276  short int n_recHitsM = 0;
277  if( TheCSCRecHits.isValid() )
278  {
280  for (dRHIter = TheCSCRecHits->begin(); dRHIter != TheCSCRecHits->end(); dRHIter++)
281  {
282  if ( !((*dRHIter).isValid()) ) continue; // only interested in valid hits
283  CSCDetId idrec = (CSCDetId)(*dRHIter).cscDetId();
284  float RHTime = (*dRHIter).tpeak();
285  LocalPoint rhitlocal = (*dRHIter).localPosition();
286  const CSCChamber* chamber = TheCSCGeometry.chamber(idrec);
287  GlobalPoint globalPosition = chamber->toGlobal(rhitlocal);
288  float globZ = globalPosition.z();
289  if ( RHTime < (recHit_t0 - recHit_twindow) )
290  {
291  if( globZ > 0 )
292  n_recHitsP++;
293  else
294  n_recHitsM++;
295  }
296 
297  /*
298 
299  float globX = globalPosition.x();
300  float globY = globalPosition.y();
301  float globZ = globalPosition.z();
302  float TOF = (sqrt(globX*globX+ globY*globY + globZ*globZ))/29.9792458 ; //cm -> ns
303  if ( (RHTime < (recHit_t0 + TOF - recHit_twindow)) || (RHTime > (recHit_t0 + TOF + recHit_twindow)) )
304  {
305  if( globZ > 0 )
306  n_recHitsP++;
307  else
308  n_recHitsM++;
309  }
310  */
311  }
312  }
313  else
314  {
315  static std::atomic<bool> RecHitFail{false};
316  bool expected = false;
317  if( RecHitFail.compare_exchange_strong(expected,true,std::memory_order_acq_rel) )
318  {
319  edm::LogWarning ("InvalidInputTag") << "The requested CSCRecHit2DCollection does not appear to be in the event. The CSC RecHit "
320  << " variables used for halo identification will not be calculated or stored";
321  }
322  }
323  TheCSCHaloData.SetNOutOfTimeHits(n_recHitsP+n_recHitsM);
324  // MLR
325  // Loop through CSCSegments and count the number of "flat" segments with the same (r,phi),
326  // saving the value in TheCSCHaloData.
327  short int maxNSegments = 0;
328  bool plus_endcap = false;
329  bool minus_endcap = false;
330  bool both_endcaps = false;
331  bool both_endcaps_loose = false;
332  // bool both_endcaps_dtcut = false;
333 
334  short int maxNSegments_alt = 0;
335  bool both_endcaps_alt = false;
336  bool both_endcaps_loose_alt = false;
337  bool both_endcaps_loose_dtcut_alt = false;
338 
339  //float r = 0., phi = 0.;
340  if (TheCSCSegments.isValid()) {
341  for(CSCSegmentCollection::const_iterator iSegment = TheCSCSegments->begin();
342  iSegment != TheCSCSegments->end();
343  iSegment++) {
344 
345  CSCDetId iCscDetID = iSegment->cscDetId();
346  bool Segment1IsGood=true;
347  bool Segment1IsGood_alt=true;
348 
349  //avoid segments from collision muons
350  if( TheMuons.isValid() )
351  {
352  for(reco::MuonCollection::const_iterator mu = TheMuons->begin(); mu!= TheMuons->end() && (Segment1IsGood||!trkmuunvetoisdefault) ; mu++ )
353  {
354  bool lowpttrackmu=false;
355  if( !mu->isTrackerMuon() && !mu->isGlobalMuon() && mu->isStandAloneMuon() ) continue;
356  if( !mu->isTrackerMuon() && !mu->isGlobalMuon() && mu->isStandAloneMuon()&&trkmuunvetoisdefault) continue;
357  if( !mu->isGlobalMuon() && mu->isTrackerMuon() && mu->pt()<3) lowpttrackmu=true;
358  const std::vector<MuonChamberMatch> chambers = mu->matches();
359  for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
360  kChamber != chambers.end(); kChamber ++ )
361  {
362  if( kChamber->detector() != MuonSubdetId::CSC ) continue;
363  for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
364  kSegment != kChamber->segmentMatches.end(); kSegment++ )
365  {
366  edm::Ref<CSCSegmentCollection> cscSegRef = kSegment->cscSegmentRef;
367  CSCDetId kCscDetID = cscSegRef->cscDetId();
368 
369  if( kCscDetID == iCscDetID )
370  {
371  Segment1IsGood = false;
372  if(!lowpttrackmu) Segment1IsGood_alt=false;
373  }
374  }
375  }
376  }
377  }
378  if(!Segment1IsGood&&!Segment1IsGood_alt) continue;
379 
380  // Get local direction vector; if direction runs parallel to beamline,
381  // count this segment as beam halo candidate.
382  LocalPoint iLocalPosition = iSegment->localPosition();
383  LocalVector iLocalDirection = iSegment->localDirection();
384 
385  GlobalPoint iGlobalPosition = TheCSCGeometry.chamber(iCscDetID)->toGlobal(iLocalPosition);
386  GlobalVector iGlobalDirection = TheCSCGeometry.chamber(iCscDetID)->toGlobal(iLocalDirection);
387 
388  float iTheta = iGlobalDirection.theta();
389  if (iTheta > max_segment_theta && iTheta < TMath::Pi() - max_segment_theta) continue;
390 
391  float iPhi = iGlobalPosition.phi();
392  float iR = TMath::Sqrt(iGlobalPosition.x()*iGlobalPosition.x() + iGlobalPosition.y()*iGlobalPosition.y());
393  float iZ = iGlobalPosition.z();
394  float iT = iSegment->time();
395 
396  // if(abs(iZ)<650&& TheEvent.id().run()< 251737) iT-= 25;
397  //Calo matching:
398 
399  bool hbhematched = HCALSegmentMatching(hbhehits,et_thresh_rh_hbhe,dphi_thresh_segvsrh_hbhe,dr_lowthresh_segvsrh_hbhe,dr_highthresh_segvsrh_hbhe,dt_lowthresh_segvsrh_hbhe,dt_highthresh_segvsrh_hbhe,iZ,iR,iT,iPhi);
400  bool ebmatched = ECALSegmentMatching(ecalebhits,et_thresh_rh_eb,dphi_thresh_segvsrh_eb,dr_lowthresh_segvsrh_eb,dr_highthresh_segvsrh_eb,dt_lowthresh_segvsrh_eb,dt_highthresh_segvsrh_eb,iZ,iR,iT,iPhi);
401  bool eematched = ECALSegmentMatching(ecaleehits,et_thresh_rh_ee,dphi_thresh_segvsrh_ee,dr_lowthresh_segvsrh_ee,dr_highthresh_segvsrh_ee,dt_lowthresh_segvsrh_ee,dt_highthresh_segvsrh_ee,iZ,iR,iT,iPhi);
402  calomatched |= (hbhematched || ebmatched || eematched);
403  HCALmatched |= hbhematched;
404  ECALBmatched |= ebmatched;
405  ECALEmatched |= eematched;
406 
407  short int nSegs = 0;
408  short int nSegs_alt = 0;
409  // Changed to loop over all Segments (so N^2) to catch as many segments as possible.
410  for (CSCSegmentCollection::const_iterator jSegment = TheCSCSegments->begin();
411  jSegment != TheCSCSegments->end();
412  jSegment++) {
413  if (jSegment == iSegment) continue;
414  bool Segment2IsGood = true;
415  bool Segment2IsGood_alt = true;
416  LocalPoint jLocalPosition = jSegment->localPosition();
417  LocalVector jLocalDirection = jSegment->localDirection();
418  CSCDetId jCscDetID = jSegment->cscDetId();
419  GlobalPoint jGlobalPosition = TheCSCGeometry.chamber(jCscDetID)->toGlobal(jLocalPosition);
420  GlobalVector jGlobalDirection = TheCSCGeometry.chamber(jCscDetID)->toGlobal(jLocalDirection);
421  float jTheta = jGlobalDirection.theta();
422  float jPhi = jGlobalPosition.phi();
423  float jR = TMath::Sqrt(jGlobalPosition.x()*jGlobalPosition.x() + jGlobalPosition.y()*jGlobalPosition.y());
424  float jZ = jGlobalPosition.z() ;
425  float jT = jSegment->time();
426  // if(abs(jZ)<650&& TheEvent.id().run() < 251737)jT-= 25;
427  if ( std::abs(deltaPhi(jPhi , iPhi)) <=max_segment_phi_diff
428  && ( std::abs(jR - iR) <0.05*std::abs(jZ - iZ)|| jZ*iZ>0 )
429  && ( (jR - iR) >-0.02*std::abs(jZ - iZ) || iT>jT || jZ*iZ>0)
430  && ( (iR - jR) >-0.02*std::abs(jZ - iZ) || iT<jT || jZ*iZ>0)
431  && (std::abs(jR - iR) <= max_segment_r_diff || jZ*iZ < 0)
432  && (jTheta < max_segment_theta || jTheta > TMath::Pi() - max_segment_theta)) {
434  if( TheMuons.isValid() ) {
435  for(reco::MuonCollection::const_iterator mu = TheMuons->begin(); mu!= TheMuons->end() && (Segment2IsGood||!trkmuunvetoisdefault) ; mu++ ) {
436  bool lowpttrackmu=false;
437  if( !mu->isTrackerMuon() && !mu->isGlobalMuon() && mu->isStandAloneMuon() ) continue;
438  if( !mu->isGlobalMuon() && mu->isTrackerMuon() && mu->pt()<3) lowpttrackmu= true;
439  const std::vector<MuonChamberMatch> chambers = mu->matches();
440  for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
441  kChamber != chambers.end(); kChamber ++ ) {
442  if( kChamber->detector() != MuonSubdetId::CSC ) continue;
443  for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
444  kSegment != kChamber->segmentMatches.end(); kSegment++ ) {
445  edm::Ref<CSCSegmentCollection> cscSegRef = kSegment->cscSegmentRef;
446  CSCDetId kCscDetID = cscSegRef->cscDetId();
447 
448  if( kCscDetID == jCscDetID ) {
449  Segment2IsGood = false;
450  if(!lowpttrackmu) Segment2IsGood_alt=false;
451  }
452  }
453  }
454  }
455  }
456  if(Segment1IsGood && Segment2IsGood) {
457  nSegs++;
458  minus_endcap = iGlobalPosition.z() < 0 || jGlobalPosition.z() < 0;
459  plus_endcap = iGlobalPosition.z() > 0 || jGlobalPosition.z() > 0;
460  // if( abs(jT-iT)/sqrt( (jR-iR)*(jR-iR)+(jZ-iZ)*(jZ-iZ) )<0.05 && abs(jT-iT)/sqrt( (jR-iR)*(jR-iR)+(jZ-iZ)*(jZ-iZ) )>0.02 && minus_endcap&&plus_endcap ) both_endcaps_dtcut =true;
461  }
462  if(Segment1IsGood_alt && Segment2IsGood_alt) {
463  nSegs_alt++;
464  minus_endcap = iGlobalPosition.z() < 0 || jGlobalPosition.z() < 0;
465  plus_endcap = iGlobalPosition.z() > 0 || jGlobalPosition.z() > 0;
466  double iTBX = iT+sqrt(iGlobalPosition.mag2())/c_cm_per_ns;
467  double jTBX = jT+sqrt(jGlobalPosition.mag2())/c_cm_per_ns;
468  double truedt = (iTBX>jTBX)? iTBX-jTBX-std::abs(iZ-jZ)/c_cm_per_ns : jTBX-iTBX-std::abs(iZ-jZ)/c_cm_per_ns;
469  if(
470  std::abs(truedt)<15 &&
471  (iT>-15 || jT>-15)&&
472  minus_endcap&&plus_endcap ) both_endcaps_loose_dtcut_alt =true;
473  }
474 
475  }
476  }
477  // Correct the fact that the way nSegs counts will always be short by 1
478  if (nSegs > 0) nSegs++;
479 
480  // The opposite endcaps segments do not need to belong to the longest chain.
481  if (nSegs > 0) both_endcaps_loose = both_endcaps_loose ? both_endcaps_loose : minus_endcap && plus_endcap;
482  if (nSegs_alt > 0) nSegs_alt++;
483  if (nSegs_alt > 0) both_endcaps_loose_alt = both_endcaps_loose_alt ? both_endcaps_loose_alt : minus_endcap && plus_endcap;
484 
485  // if (nSegs > 0) both_endcaps_dt20ns = both_endcaps_dt20ns ? both_endcaps_dt20ns : minus_endcap && plus_endcap &&dt20ns;
486  if (nSegs > maxNSegments) {
487  // Use value of r, phi to collect halo CSCSegments for examining timing (not coded yet...)
488  //r = iR;
489  //phi = iPhi;
490  maxNSegments = nSegs;
491  both_endcaps = both_endcaps ? both_endcaps : minus_endcap && plus_endcap;
492  }
493 
494  if (nSegs_alt > maxNSegments_alt) {
495  maxNSegments_alt = nSegs_alt;
496  both_endcaps_alt = both_endcaps_alt ? both_endcaps_alt : minus_endcap && plus_endcap;
497  }
498 
499  }
500  }
501 
502  //Deprecated methods, kept for backward compatibility
503  TheCSCHaloData.SetHLTBit(false);
504  TheCSCHaloData.SetNumberOfHaloTriggers(0,0);
505  TheCSCHaloData.SetNumberOfHaloTriggers_TrkMuUnVeto(0,0);
506  TheCSCHaloData.SetNOutOfTimeTriggers(0,0);
507 
508  //Current methods used
509  TheCSCHaloData.SetNFlatHaloSegments(maxNSegments);
510  TheCSCHaloData.SetSegmentsBothEndcaps(both_endcaps);
511  TheCSCHaloData.SetNFlatHaloSegments_TrkMuUnVeto(maxNSegments_alt);
512  TheCSCHaloData.SetSegmentsBothEndcaps_Loose_TrkMuUnVeto(both_endcaps_loose_alt);
513  TheCSCHaloData.SetSegmentsBothEndcaps_Loose_dTcut_TrkMuUnVeto(both_endcaps_loose_dtcut_alt);
514  TheCSCHaloData.SetSegmentIsCaloMatched(calomatched);
515  TheCSCHaloData.SetSegmentIsHCaloMatched(HCALmatched);
516  TheCSCHaloData.SetSegmentIsEBCaloMatched(ECALBmatched);
517  TheCSCHaloData.SetSegmentIsEECaloMatched(ECALEmatched);
518 
519  return TheCSCHaloData;
520 }
521 
523 
524  const GlobalPoint& pos=geo->getPosition(id);
525  math::XYZPoint posV(pos.x() - vtx.x(),pos.y() - vtx.y(),pos.z() - vtx.z());
526  return posV;
527 }
528 
529 
530 bool CSCHaloAlgo::HCALSegmentMatching(edm::Handle<HBHERecHitCollection>& rechitcoll, float et_thresh_rh, float dphi_thresh_segvsrh, float dr_lowthresh_segvsrh, float dr_highthresh_segvsrh, float dt_lowthresh_segvsrh, float dt_highthresh_segvsrh, float iZ, float iR, float iT, float iPhi){
531  reco::Vertex::Point vtx(0,0,0);
532  for(size_t ihit = 0; ihit< rechitcoll->size(); ++ ihit){
533  const HBHERecHit & rechit = (*rechitcoll)[ ihit ];
534  math::XYZPoint rhpos = getPosition(rechit.id(),vtx);
535  double rhet = rechit.energy()/cosh(rhpos.eta());
536  double dphi_rhseg = abs(deltaPhi(rhpos.phi(),iPhi));
537  double dr_rhseg = sqrt(rhpos.x()*rhpos.x()+rhpos.y()*rhpos.y()) - iR;
538  double dtcorr_rhseg = rechit.time()- abs(rhpos.z()-iZ)/30- iT;
539  if(
540  (rechit.time()<-3)&&
541  (rhpos.z()*iZ<0|| abs(rhpos.z())<200)&&
542  rhet> et_thresh_rh&&
543  dphi_rhseg < dphi_thresh_segvsrh &&
544  dr_rhseg < dr_highthresh_segvsrh && dr_rhseg> dr_lowthresh_segvsrh && //careful: asymmetric cut might not be the most appropriate thing
545  dtcorr_rhseg> dt_lowthresh_segvsrh && dtcorr_rhseg< dt_highthresh_segvsrh
546  ) return true;
547  }
548  return false;
549 }
550 
551 bool CSCHaloAlgo::ECALSegmentMatching(edm::Handle<EcalRecHitCollection>& rechitcoll, float et_thresh_rh, float dphi_thresh_segvsrh, float dr_lowthresh_segvsrh, float dr_highthresh_segvsrh, float dt_lowthresh_segvsrh,float dt_highthresh_segvsrh, float iZ, float iR, float iT, float iPhi ){
552  reco::Vertex::Point vtx(0,0,0);
553  for(size_t ihit = 0; ihit<rechitcoll->size(); ++ ihit){
554  const EcalRecHit & rechit = (*rechitcoll)[ ihit ];
555  math::XYZPoint rhpos = getPosition(rechit.id(),vtx);
556  double rhet = rechit.energy()/cosh(rhpos.eta());
557  double dphi_rhseg = abs(deltaPhi(rhpos.phi(),iPhi));
558  double dr_rhseg = sqrt(rhpos.x()*rhpos.x()+rhpos.y()*rhpos.y()) - iR;
559  double dtcorr_rhseg = rechit.time()- abs(rhpos.z()-iZ)/30- iT;
560  if(
561  ( rechit.time()<-1)&&
562  (rhpos.z()*iZ<0|| abs(rhpos.z())<200)&&
563  rhet> et_thresh_rh&&
564  dphi_rhseg < dphi_thresh_segvsrh &&
565  dr_rhseg < dr_highthresh_segvsrh && dr_rhseg> dr_lowthresh_segvsrh && //careful: asymmetric cut might not be the most appropriate thing
566  dtcorr_rhseg> dt_lowthresh_segvsrh && dtcorr_rhseg< dr_highthresh_segvsrh
567  ) return true;
568  }
569  return false;
570 }
const double Pi
T mag2() const
Definition: PV3DBase.h:66
void SetNFlatHaloSegments_TrkMuUnVeto(short int nSegments)
Definition: CSCHaloData.h:98
reco::CSCHaloData Calculate(const CSCGeometry &TheCSCGeometry, edm::Handle< reco::MuonCollection > &TheCosmicMuons, const edm::Handle< reco::MuonTimeExtraMap > TheCSCTimeMap, edm::Handle< reco::MuonCollection > &TheMuons, edm::Handle< CSCSegmentCollection > &TheCSCSegments, edm::Handle< CSCRecHit2DCollection > &TheCSCRecHits, edm::Handle< L1MuGMTReadoutCollection > &TheL1GMTReadout, edm::Handle< HBHERecHitCollection > &hbhehits, edm::Handle< EcalRecHitCollection > &ecalebhits, edm::Handle< EcalRecHitCollection > &ecaleehits, edm::Handle< edm::TriggerResults > &TheHLTResults, const edm::TriggerNames *triggerNames, const edm::Handle< CSCALCTDigiCollection > &TheALCTs, MuonSegmentMatcher *TheMatcher, const edm::Event &TheEvent, const edm::EventSetup &TheEventSetup)
Definition: CSCHaloAlgo.cc:70
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
void SetSegmentIsEECaloMatched(bool b)
Definition: CSCHaloData.h:104
HcalDetId id() const
get the id
Definition: HBHERecHit.h:25
void SetSegmentsBothEndcaps_Loose_TrkMuUnVeto(bool b)
Definition: CSCHaloData.h:99
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
std::vector< const CSCSegment * > matchCSC(const reco::Track &muon, const edm::Event &event)
float time() const
Definition: EcalRecHit.h:70
float time() const
Definition: CaloRecHit.h:19
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
#define constexpr
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
T barePhi() const
Definition: PV3DBase.h:68
static const int CSC
Definition: MuonSubdetId.h:13
float energy() const
Definition: CaloRecHit.h:17
T sqrt(T t)
Definition: SSEVec.h:18
void SetSegmentIsCaloMatched(bool b)
Definition: CSCHaloData.h:101
T z() const
Definition: PV3DBase.h:64
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
Definition: CSCHaloData.h:88
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void SetSegmentsBothEndcaps(bool b)
Definition: CSCHaloData.h:96
float energy() const
Definition: EcalRecHit.h:68
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
const int mu
Definition: Constants.h:22
bool isValid() const
Definition: HandleBase.h:74
void SetHLTBit(bool status)
Definition: CSCHaloData.h:84
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
Definition: DetId.h:18
void SetNFlatHaloSegments(short int nSegments)
Definition: CSCHaloData.h:95
const GeomDetUnit * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:93
DetId id() const
get the id
Definition: EcalRecHit.h:77
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
void SetNIncomingTracks(short int n_small_dT, short int n_small_beta, short int n_small_both)
Definition: CSCHaloData.h:80
const T & get() const
Definition: EventSetup.h:55
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:118
void SetNumberOfHaloTriggers(int PlusZ, int MinusZ)
Definition: CSCHaloData.h:73
void SetSegmentIsHCaloMatched(bool b)
Definition: CSCHaloData.h:102
T eta() const
Definition: PV3DBase.h:76
fixed size matrix
HLT enums.
math::XYZPoint getPosition(const DetId &id, reco::Vertex::Point vtx)
Definition: CSCHaloAlgo.cc:522
size_type size() const
float freeInverseBeta() const
Definition: MuonTimeExtra.h:36
void SetSegmentsBothEndcaps_Loose_dTcut_TrkMuUnVeto(bool b)
Definition: CSCHaloData.h:100
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
bool ECALSegmentMatching(edm::Handle< EcalRecHitCollection > &rechitcoll, float et_thresh_rh, float dphi_thresh_segvsrh, float dr_lowthresh_segvsrh, float dr_highthresh_segvsrh, float dt_lowthresh_segvsrh, float dt_highthresh_segvsrh, float iZ, float iR, float iT, float iPhi)
Definition: CSCHaloAlgo.cc:551
void SetNOutOfTimeHits(short int num)
Definition: CSCHaloData.h:78
void SetNumberOfHaloTriggers_TrkMuUnVeto(int PlusZ, int MinusZ)
Definition: CSCHaloData.h:74
void SetNOutOfTimeTriggers(short int PlusZ, short int MinusZ)
Definition: CSCHaloData.h:76
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
bool HCALSegmentMatching(edm::Handle< HBHERecHitCollection > &rechitcoll, float et_thresh_rh, float dphi_thresh_segvsrh, float dr_lowthresh_segvsrh, float dr_highthresh_segvsrh, float dt_lowthresh_segvsrh, float dt_highthresh_segvsrh, float iZ, float iR, float iT, float iPhi)
Definition: CSCHaloAlgo.cc:530
void SetSegmentIsEBCaloMatched(bool b)
Definition: CSCHaloData.h:103
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
edm::RefVector< reco::TrackCollection > & GetTracks()
Definition: CSCHaloData.h:69