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.;
26 max_dt_muon_segment=-10.0;
27 max_free_inverse_beta=0.0;
32 matching_dphi_threshold = 0.18;
33 matching_deta_threshold = 0.4;
34 matching_dwire_threshold = 5.;
54 short int n_tracks_small_beta=0;
55 short int n_tracks_small_dT=0;
56 short int n_tracks_small_dT_and_beta=0;
57 for( reco::MuonCollection::const_iterator iMuon = TheCosmicMuons->begin() ; iMuon != TheCosmicMuons->end() ; iMuon++, imucount++ )
62 bool StoreTrack =
false;
64 float innermost_global_z = 1500.;
65 float outermost_global_z = 0.;
69 for(
unsigned int j = 0 ;
j < Track->extra()->recHits().size();
j++ )
72 if( !
hit->isValid() )
continue;
73 DetId TheDetUnitId(
hit->geographicalId());
82 float z = TheGlobalPosition.
z();
83 if( TMath::Abs(z) < innermost_global_z )
85 innermost_global_z = TMath::Abs(z);
86 InnerMostGlobalPosition =
GlobalPoint( TheGlobalPosition);
88 if( TMath::Abs(z) > outermost_global_z )
90 outermost_global_z = TMath::Abs(z);
91 OuterMostGlobalPosition =
GlobalPoint( TheGlobalPosition );
96 std::vector<const CSCSegment*> MatchedSegments = TheMatcher->
matchCSC(*Track,TheEvent);
99 float InnerSegmentTime[2] = {0,0};
100 float OuterSegmentTime[2] = {0,0};
101 float innermost_seg_z[2] = {1500,1500};
102 float outermost_seg_z[2] = {0,0};
103 for (std::vector<const CSCSegment*>::const_iterator segment =MatchedSegments.begin();
104 segment != MatchedSegments.end(); ++segment)
106 CSCDetId TheCSCDetId((*segment)->cscDetId());
108 LocalPoint TheLocalPosition = (*segment)->localPosition();
109 const GlobalPoint TheGlobalPosition = TheCSCChamber->toGlobal(TheLocalPosition);
110 float z = TheGlobalPosition.
z();
111 int TheEndcap = TheCSCDetId.endcap();
112 if( TMath::Abs(z) < innermost_seg_z[TheEndcap-1] )
114 innermost_seg_z[TheEndcap-1] = TMath::Abs(z);
115 InnerSegmentTime[TheEndcap-1] = (*segment)->time();
117 if( TMath::Abs(z) > outermost_seg_z[TheEndcap-1] )
119 outermost_seg_z[TheEndcap-1] = TMath::Abs(z);
120 OuterSegmentTime[TheEndcap-1] = (*segment)->time();
124 if( nCSCHits < 3 )
continue;
126 float dT_Segment = 0;
128 if( innermost_seg_z[0] < outermost_seg_z[0])
129 dT_Segment = OuterSegmentTime[0]-InnerSegmentTime[0];
130 if( innermost_seg_z[1] < outermost_seg_z[1])
134 if (dT_Segment == 0.0 || OuterSegmentTime[1]-InnerSegmentTime[1] < dT_Segment)
135 dT_Segment = OuterSegmentTime[1]-InnerSegmentTime[1] ;
138 if( OuterMostGlobalPosition.
x() == 0. || OuterMostGlobalPosition.
y() == 0. || OuterMostGlobalPosition.
z() == 0. )
140 if( InnerMostGlobalPosition.
x() == 0. || InnerMostGlobalPosition.
y() == 0. || InnerMostGlobalPosition.
z() == 0. )
146 float deta = TMath::Abs( OuterMostGlobalPosition.
eta() - InnerMostGlobalPosition.
eta() );
147 float dphi = TMath::ACos( TMath::Cos( OuterMostGlobalPosition.
phi() - InnerMostGlobalPosition.
phi() ) ) ;
148 float theta = Track->outerMomentum().theta();
149 float innermost_x = InnerMostGlobalPosition.
x() ;
150 float innermost_y = InnerMostGlobalPosition.
y();
151 float outermost_x = OuterMostGlobalPosition.
x();
152 float outermost_y = OuterMostGlobalPosition.
y();
153 float innermost_r = TMath::Sqrt(innermost_x *innermost_x + innermost_y * innermost_y );
154 float outermost_r = TMath::Sqrt(outermost_x *outermost_x + outermost_y * outermost_y );
156 if( deta < deta_threshold )
158 if( theta > min_outer_theta && theta < max_outer_theta )
160 if( dphi > dphi_threshold )
162 if( innermost_r < min_inner_radius )
164 if( innermost_r > max_inner_radius )
166 if( outermost_r < min_outer_radius )
168 if( outermost_r > max_outer_radius )
170 if( Track->normalizedChi2() > norm_chi2_threshold )
187 if (dT_Segment < max_dt_muon_segment )
189 if (freeInverseBeta < max_free_inverse_beta)
190 n_tracks_small_beta++;
191 if ((dT_Segment < max_dt_muon_segment) && (freeInverseBeta < max_free_inverse_beta))
192 n_tracks_small_dT_and_beta++;
196 static bool MuonTimeFail =
false;
199 edm::LogWarning (
"InvalidInputTag") <<
"The MuonTimeExtraMap does not appear to be in the event. Some beam halo "
200 <<
" identification variables will be empty" ;
205 TheCSCHaloData.
SetNIncomingTracks(n_tracks_small_dT,n_tracks_small_beta,n_tracks_small_dT_and_beta);
209 static bool CosmicFail =
false;
212 edm::LogWarning (
"InvalidInputTag") <<
" The Cosmic Muon collection does not appear to be in the event. These beam halo "
213 <<
" identification variables will be empty" ;
220 bool EventPasses =
false;
227 if( bit < TheHLTResults->
size() )
230 if( TheHLTResults->accept( bit ) && !TheHLTResults->error( bit ) )
244 static bool HLTFail =
false;
247 edm::LogWarning (
"InvalidInputTag") <<
"The HLT results do not appear to be in the event. The beam halo HLT trigger "
248 <<
"decision will not be used in the halo identification";
253 if( TheL1GMTReadout.
isValid() )
256 std::vector < L1MuGMTReadoutRecord > gmt_records = gmtrc->
getRecords ();
257 std::vector < L1MuGMTReadoutRecord >::const_iterator igmtrr;
263 for (igmtrr = gmt_records.begin (); igmtrr != gmt_records.end (); igmtrr++)
265 std::vector < L1MuRegionalCand >::const_iterator iter1;
266 std::vector < L1MuRegionalCand > rmc;
267 rmc = igmtrr->getCSCCands ();
268 for (iter1 = rmc.begin (); iter1 != rmc.end (); iter1++)
270 if (!(*iter1).empty ())
272 if ((*iter1).isFineHalo ())
274 float halophi = iter1->phiValue();
276 float haloeta = iter1->etaValue();
277 bool HaloIsGood =
true;
283 for( reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu != TheMuons->end() && HaloIsGood ;
mu++ )
286 if(
mu->isStandAloneMuon() && !
mu->isTrackerMuon() && !
mu->isGlobalMuon() )
continue;
304 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
305 for(std::vector<MuonChamberMatch>::const_iterator iChamber = chambers.begin();
306 iChamber != chambers.end() ; iChamber ++ )
309 for( std::vector<reco::MuonSegmentMatch>::const_iterator iSegment = iChamber->segmentMatches.begin() ;
310 iSegment != iChamber->segmentMatches.end(); ++iSegment )
313 std::vector<CSCRecHit2D> hits = cscSegment -> specificRecHits();
314 for( std::vector<CSCRecHit2D>::iterator iHit = hits.begin();
315 iHit != hits.end() ; iHit++ )
317 DetId TheDetUnitId(iHit->cscDetId());
319 LocalPoint TheLocalPosition = iHit->localPosition();
320 const BoundPlane& TheSurface = TheUnit->surface();
323 float phi_ = TheGlobalPosition.
phi();
324 float eta_ = TheGlobalPosition.
eta();
326 deta = deta < TMath::Abs( eta_ - haloeta ) ? deta : TMath::Abs( eta_ - haloeta );
327 dphi = dphi < TMath::ACos(TMath::Cos(phi_ - halophi)) ? dphi : TMath::ACos(TMath::Cos(phi_ - halophi));
331 if ( dphi < matching_dphi_threshold && deta < matching_deta_threshold)
337 if( (*iter1).etaValue() > 0 )
351 static bool L1Fail =
false;
354 edm::LogWarning (
"InvalidInputTag") <<
"The L1MuGMTReadoutCollection does not appear to be in the event. The L1 beam halo trigger "
355 <<
"decision will not be used in the halo identification";
363 short int n_alctsP=0;
364 short int n_alctsM=0;
373 if( (*digiIt).isValid() && ( (*digiIt).getBX() < expected_BX ) )
375 int digi_endcap = detId.
endcap();
376 int digi_station = detId.station();
377 int digi_ring = detId.ring();
378 int digi_chamber = detId.chamber();
379 int digi_wire = digiIt->getKeyWG();
380 if( digi_station == 1 && digi_ring == 4 )
383 bool DigiIsGood =
true;
388 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && DigiIsGood ;
mu++ )
390 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
392 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
393 for(std::vector<MuonChamberMatch>::const_iterator iChamber = chambers.begin();
394 iChamber != chambers.end(); iChamber ++ )
397 for( std::vector<reco::MuonSegmentMatch>::const_iterator iSegment = iChamber->segmentMatches.begin();
398 iSegment != iChamber->segmentMatches.end(); iSegment++ )
401 std::vector<CSCRecHit2D> hits = cscSegRef->specificRecHits();
402 for( std::vector<CSCRecHit2D>::iterator iHit = hits.begin();
403 iHit != hits.end(); iHit++ )
405 if( iHit->cscDetId().endcap() != digi_endcap )
continue;
406 if( iHit->cscDetId().station() != digi_station )
continue;
407 if( iHit->cscDetId().ring() != digi_ring )
continue;
408 if( iHit->cscDetId().chamber() != digi_chamber )
continue;
409 int hit_wire = iHit->hitWire();
410 dwire = dwire < TMath::Abs(hit_wire - digi_wire)? dwire : TMath::Abs(hit_wire - digi_wire );
414 if( dwire <= matching_dwire_threshold )
421 if( detId.endcap() == 1 )
423 else if ( detId.endcap() == 2)
432 static bool DigiFail=
false;
434 edm::LogWarning (
"InvalidInputTag") <<
"The CSCALCTDigiCollection does not appear to be in the event. The ALCT Digis will "
435 <<
" not be used in the halo identification";
444 short int n_recHitsP = 0;
445 short int n_recHitsM = 0;
449 for (dRHIter = TheCSCRecHits->begin(); dRHIter != TheCSCRecHits->end(); dRHIter++)
451 if ( !((*dRHIter).isValid()) )
continue;
453 float RHTime = (*dRHIter).tpeak();
454 LocalPoint rhitlocal = (*dRHIter).localPosition();
457 float globZ = globalPosition.
z();
458 if ( RHTime < (recHit_t0 - recHit_twindow) )
484 static bool RecHitFail =
false;
487 edm::LogWarning (
"InvalidInputTag") <<
"The requested CSCRecHit2DCollection does not appear to be in the event. The CSC RecHit "
488 <<
" variables used for halo identification will not be calculated or stored";
496 short int maxNSegments = 0;
497 bool plus_endcap =
false;
498 bool minus_endcap =
false;
499 bool both_endcaps =
false;
501 if (TheCSCSegments.
isValid()) {
503 iSegment != TheCSCSegments->end();
506 CSCDetId iCscDetID = iSegment->cscDetId();
507 bool SegmentIsGood=
true;
511 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && SegmentIsGood ;
mu++ )
513 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
514 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
515 for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
516 kChamber != chambers.end(); kChamber ++ )
519 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
520 kSegment != kChamber->segmentMatches.end(); kSegment++ )
523 CSCDetId kCscDetID = cscSegRef->cscDetId();
525 if( kCscDetID == iCscDetID )
527 SegmentIsGood =
false;
533 if(!SegmentIsGood)
continue;
537 LocalPoint iLocalPosition = iSegment->localPosition();
538 LocalVector iLocalDirection = iSegment->localDirection();
543 float iTheta = iGlobalDirection.
theta();
544 if (iTheta > max_segment_theta && iTheta <
TMath::Pi() - max_segment_theta)
continue;
546 float iPhi = iGlobalPosition.
phi();
547 float iR = TMath::Sqrt(iGlobalPosition.
x()*iGlobalPosition.
x() + iGlobalPosition.
y()*iGlobalPosition.
y());
552 jSegment != TheCSCSegments->end();
554 if (jSegment == iSegment)
continue;
556 LocalPoint jLocalPosition = jSegment->localPosition();
557 LocalVector jLocalDirection = jSegment->localDirection();
558 CSCDetId jCscDetID = jSegment->cscDetId();
561 float jTheta = jGlobalDirection.
theta();
562 float jPhi = jGlobalPosition.
phi();
563 float jR = TMath::Sqrt(jGlobalPosition.
x()*jGlobalPosition.
x() + jGlobalPosition.
y()*jGlobalPosition.
y());
565 if (TMath::ACos(TMath::Cos(jPhi - iPhi)) <= max_segment_phi_diff
566 && TMath::Abs(jR - iR) <= max_segment_r_diff
567 && (jTheta < max_segment_theta || jTheta >
TMath::Pi() - max_segment_theta)) {
570 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && SegmentIsGood ;
mu++ ) {
571 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
572 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
573 for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
574 kChamber != chambers.end(); kChamber ++ ) {
576 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
577 kSegment != kChamber->segmentMatches.end(); kSegment++ ) {
579 CSCDetId kCscDetID = cscSegRef->cscDetId();
581 if( kCscDetID == jCscDetID ) {
582 SegmentIsGood =
false;
590 minus_endcap = iGlobalPosition.
z() < 0 || jGlobalPosition.
z() < 0;
591 plus_endcap = iGlobalPosition.
z() > 0 || jGlobalPosition.
z() > 0;
596 if (nSegs > 0) nSegs++;
597 if (nSegs > maxNSegments) {
601 maxNSegments = nSegs;
602 both_endcaps = both_endcaps ? both_endcaps : minus_endcap && plus_endcap;
610 return TheCSCHaloData;
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Geom::Phi< T > phi() const
Global3DPoint GlobalPoint
Geom::Theta< T > theta() const
static char chambers[TOTALCHAMBERS][20]
std::vector< const CSCSegment * > matchCSC(const reco::Track &muon, const edm::Event &event)
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< edm::TriggerResults > &TheHLTResults, const edm::TriggerNames *triggerNames, const edm::Handle< CSCALCTDigiCollection > &TheALCTs, MuonSegmentMatcher *TheMatcher, const edm::Event &TheEvent)
Geom::Theta< T > theta() const
C::const_iterator const_iterator
constant access iterator type
unsigned int triggerIndex(std::string const &name) const
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
void SetSegmentsBothEndcaps(bool b)
void SetHLTBit(bool status)
void SetNFlatHaloSegments(short int nSegments)
void SetNIncomingTracks(short int n_small_dT, short int n_small_beta, short int n_small_both)
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
void SetNumberOfHaloTriggers(int PlusZ, int MinusZ)
std::vector< DigiType >::const_iterator const_iterator
T const * product() const
const BoundPlane & surface() const
The nominal surface of the GeomDet.
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
void SetNOutOfTimeHits(short int num)
std::pair< const_iterator, const_iterator > Range
void SetNOutOfTimeTriggers(short int PlusZ, short int MinusZ)
tuple size
Write out results.
edm::RefVector< reco::TrackCollection > & GetTracks()