89 bool calomatched =
false;
95 bool trkmuunvetoisdefault =
false;
101 short int n_tracks_small_beta=0;
102 short int n_tracks_small_dT=0;
103 short int n_tracks_small_dT_and_beta=0;
104 for( reco::MuonCollection::const_iterator iMuon = TheCosmicMuons->begin() ; iMuon != TheCosmicMuons->end() ; iMuon++, imucount++ )
109 bool StoreTrack =
false;
111 float innermost_global_z = 1500.;
112 float outermost_global_z = 0.;
116 for(
unsigned int j = 0 ;
j < Track->extra()->recHitsSize();
j++ )
118 auto hit = Track->extra()->recHitRef(
j);
119 if( !
hit->isValid() )
continue;
120 DetId TheDetUnitId(
hit->geographicalId());
127 const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
129 float z = TheGlobalPosition.
z();
130 if(
abs(z) < innermost_global_z )
132 innermost_global_z =
abs(z);
133 InnerMostGlobalPosition =
GlobalPoint( TheGlobalPosition);
135 if(
abs(z) > outermost_global_z )
137 outermost_global_z =
abs(z);
138 OuterMostGlobalPosition =
GlobalPoint( TheGlobalPosition );
143 std::vector<const CSCSegment*> MatchedSegments = TheMatcher->
matchCSC(*Track,TheEvent);
146 float InnerSegmentTime[2] = {0,0};
147 float OuterSegmentTime[2] = {0,0};
148 float innermost_seg_z[2] = {1500,1500};
149 float outermost_seg_z[2] = {0,0};
150 for (std::vector<const CSCSegment*>::const_iterator segment =MatchedSegments.begin();
151 segment != MatchedSegments.end(); ++segment)
153 CSCDetId TheCSCDetId((*segment)->cscDetId());
155 LocalPoint TheLocalPosition = (*segment)->localPosition();
156 const GlobalPoint TheGlobalPosition = TheCSCChamber->toGlobal(TheLocalPosition);
157 float z = TheGlobalPosition.
z();
158 int TheEndcap = TheCSCDetId.endcap();
159 if(
abs(z) < innermost_seg_z[TheEndcap-1] )
161 innermost_seg_z[TheEndcap-1] =
abs(z);
162 InnerSegmentTime[TheEndcap-1] = (*segment)->time();
164 if(
abs(z) > outermost_seg_z[TheEndcap-1] )
166 outermost_seg_z[TheEndcap-1] =
abs(z);
167 OuterSegmentTime[TheEndcap-1] = (*segment)->time();
171 if( nCSCHits < 3 )
continue;
173 float dT_Segment = 0;
175 if( innermost_seg_z[0] < outermost_seg_z[0])
176 dT_Segment = OuterSegmentTime[0]-InnerSegmentTime[0];
177 if( innermost_seg_z[1] < outermost_seg_z[1])
181 if (dT_Segment == 0.0 || OuterSegmentTime[1]-InnerSegmentTime[1] < dT_Segment)
182 dT_Segment = OuterSegmentTime[1]-InnerSegmentTime[1] ;
185 if( OuterMostGlobalPosition.x() == 0. || OuterMostGlobalPosition.y() == 0. || OuterMostGlobalPosition.z() == 0. )
187 if( InnerMostGlobalPosition.x() == 0. || InnerMostGlobalPosition.y() == 0. || InnerMostGlobalPosition.z() == 0. )
193 float deta =
abs( OuterMostGlobalPosition.eta() - InnerMostGlobalPosition.eta() );
194 float dphi =
abs(
deltaPhi( OuterMostGlobalPosition.phi() , InnerMostGlobalPosition.phi() )) ;
195 float theta = Track->outerMomentum().theta();
196 float innermost_x = InnerMostGlobalPosition.x() ;
197 float innermost_y = InnerMostGlobalPosition.y();
198 float outermost_x = OuterMostGlobalPosition.x();
199 float outermost_y = OuterMostGlobalPosition.y();
200 float innermost_r = TMath::Sqrt(innermost_x *innermost_x + innermost_y * innermost_y );
201 float outermost_r = TMath::Sqrt(outermost_x *outermost_x + outermost_y * outermost_y );
237 n_tracks_small_beta++;
239 n_tracks_small_dT_and_beta++;
243 static std::atomic<bool> MuonTimeFail{
false};
244 bool expected =
false;
245 if( MuonTimeFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
247 edm::LogWarning (
"InvalidInputTag") <<
"The MuonTimeExtraMap does not appear to be in the event. Some beam halo "
248 <<
" identification variables will be empty" ;
252 TheCSCHaloData.
SetNIncomingTracks(n_tracks_small_dT,n_tracks_small_beta,n_tracks_small_dT_and_beta);
256 static std::atomic<bool> CosmicFail{
false};
257 bool expected =
false;
258 if( CosmicFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
260 edm::LogWarning (
"InvalidInputTag") <<
" The Cosmic Muon collection does not appear to be in the event. These beam halo "
261 <<
" identification variables will be empty" ;
267 bool EventPasses =
false;
274 if( bit < TheHLTResults->
size() )
277 if( TheHLTResults->accept( bit ) && !TheHLTResults->error( bit ) )
291 static std::atomic<bool> HLTFail{
false};
292 bool expected =
false;
293 if( HLTFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
295 edm::LogWarning (
"InvalidInputTag") <<
"The HLT results do not appear to be in the event. The beam halo HLT trigger "
296 <<
"decision will not be used in the halo identification";
300 if( TheL1GMTReadout.
isValid() )
303 std::vector < L1MuGMTReadoutRecord > gmt_records = gmtrc->
getRecords ();
304 std::vector < L1MuGMTReadoutRecord >::const_iterator igmtrr;
313 for (igmtrr = gmt_records.begin (); igmtrr != gmt_records.end (); igmtrr++)
315 std::vector < L1MuRegionalCand >::const_iterator iter1;
316 std::vector < L1MuRegionalCand > rmc;
317 rmc = igmtrr->getCSCCands ();
318 for (iter1 = rmc.begin (); iter1 != rmc.end (); iter1++)
320 if (!(*iter1).empty ())
322 if ((*iter1).isFineHalo ())
324 float halophi = iter1->phiValue();
326 float haloeta = iter1->etaValue();
327 bool HaloIsGood =
true;
328 bool HaloIsGood_alt =
true;
334 for( reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu != TheMuons->end() && (HaloIsGood ||!trkmuunvetoisdefault) ;
mu++ )
337 bool lowpttrackmu =
false;
338 if(
mu->isStandAloneMuon() && !
mu->isTrackerMuon() && !
mu->isGlobalMuon() )
continue;
339 if( !
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt()<3 && trkmuunvetoisdefault)
continue;
340 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 iChamber = chambers.begin();
360 iChamber != chambers.end() ; iChamber ++ )
363 for( std::vector<reco::MuonSegmentMatch>::const_iterator iSegment = iChamber->segmentMatches.begin() ;
364 iSegment != iChamber->segmentMatches.end(); ++iSegment )
367 std::vector<CSCRecHit2D> hits = cscSegment -> specificRecHits();
368 for( std::vector<CSCRecHit2D>::iterator iHit = hits.begin();
369 iHit != hits.end() ; iHit++ )
371 DetId TheDetUnitId(iHit->cscDetId());
373 LocalPoint TheLocalPosition = iHit->localPosition();
374 const BoundPlane& TheSurface = TheUnit->surface();
375 GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
377 float phi_ = TheGlobalPosition.
phi();
378 float eta_ = TheGlobalPosition.
eta();
380 deta = deta <
abs( eta_ - haloeta ) ? deta :
abs( eta_ - haloeta );
387 if(!lowpttrackmu)HaloIsGood_alt =
false;
392 if( (*iter1).etaValue() > 0 )
397 if( HaloIsGood_alt ){
398 if( (*iter1).etaValue() > 0 )
415 static std::atomic<bool> L1Fail{
false};
416 bool expected =
false;
417 if( L1Fail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
419 edm::LogWarning (
"InvalidInputTag") <<
"The L1MuGMTReadoutCollection does not appear to be in the event. The L1 beam halo trigger "
420 <<
"decision will not be used in the halo identification";
427 short int n_alctsP=0;
428 short int n_alctsM=0;
437 if( (*digiIt).isValid() && ( (*digiIt).getBX() <
expected_BX ) )
439 int digi_endcap = detId.
endcap();
440 int digi_station = detId.station();
441 int digi_ring = detId.ring();
442 int digi_chamber = detId.chamber();
443 int digi_wire = digiIt->getKeyWG();
444 if( digi_station == 1 && digi_ring == 4 )
447 bool DigiIsGood =
true;
452 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && DigiIsGood ;
mu++ )
455 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
456 if( !
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt()<3 &&trkmuunvetoisdefault)
continue;
457 const std::vector<MuonChamberMatch> chambers =
mu->matches();
458 for(std::vector<MuonChamberMatch>::const_iterator iChamber = chambers.begin();
459 iChamber != chambers.end(); iChamber ++ )
462 for( std::vector<reco::MuonSegmentMatch>::const_iterator iSegment = iChamber->segmentMatches.begin();
463 iSegment != iChamber->segmentMatches.end(); iSegment++ )
466 std::vector<CSCRecHit2D> hits = cscSegRef->specificRecHits();
467 for( std::vector<CSCRecHit2D>::iterator iHit = hits.begin();
468 iHit != hits.end(); iHit++ )
470 if( iHit->cscDetId().endcap() != digi_endcap )
continue;
471 if( iHit->cscDetId().station() != digi_station )
continue;
472 if( iHit->cscDetId().ring() != digi_ring )
continue;
473 if( iHit->cscDetId().chamber() != digi_chamber )
continue;
474 int hit_wire = iHit->hitWire();
475 dwire = dwire <
abs(hit_wire - digi_wire)? dwire :
abs(hit_wire - digi_wire );
486 if( detId.endcap() == 1 )
488 else if ( detId.endcap() == 2)
497 static std::atomic<bool> DigiFail{
false};
498 bool expected =
false;
499 if (DigiFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel)){
500 edm::LogWarning (
"InvalidInputTag") <<
"The CSCALCTDigiCollection does not appear to be in the event. The ALCT Digis will "
501 <<
" not be used in the halo identification";
509 short int n_recHitsP = 0;
510 short int n_recHitsM = 0;
514 for (dRHIter = TheCSCRecHits->begin(); dRHIter != TheCSCRecHits->end(); dRHIter++)
516 if ( !((*dRHIter).isValid()) )
continue;
518 float RHTime = (*dRHIter).tpeak();
519 LocalPoint rhitlocal = (*dRHIter).localPosition();
522 float globZ = globalPosition.
z();
549 static std::atomic<bool> RecHitFail{
false};
550 bool expected =
false;
551 if( RecHitFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
553 edm::LogWarning (
"InvalidInputTag") <<
"The requested CSCRecHit2DCollection does not appear to be in the event. The CSC RecHit "
554 <<
" variables used for halo identification will not be calculated or stored";
561 short int maxNSegments = 0;
562 bool plus_endcap =
false;
563 bool minus_endcap =
false;
564 bool both_endcaps =
false;
565 bool both_endcaps_loose =
false;
568 short int maxNSegments_alt = 0;
569 bool both_endcaps_alt =
false;
570 bool both_endcaps_loose_alt =
false;
571 bool both_endcaps_loose_dtcut_alt =
false;
574 if (TheCSCSegments.
isValid()) {
576 iSegment != TheCSCSegments->end();
579 CSCDetId iCscDetID = iSegment->cscDetId();
580 bool Segment1IsGood=
true;
581 bool Segment1IsGood_alt=
true;
586 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && (Segment1IsGood||!trkmuunvetoisdefault) ;
mu++ )
588 bool lowpttrackmu=
false;
589 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
590 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon()&&trkmuunvetoisdefault)
continue;
591 if( !
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt()<3) lowpttrackmu=
true;
592 const std::vector<MuonChamberMatch> chambers =
mu->matches();
593 for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
594 kChamber != chambers.end(); kChamber ++ )
597 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
598 kSegment != kChamber->segmentMatches.end(); kSegment++ )
601 CSCDetId kCscDetID = cscSegRef->cscDetId();
603 if( kCscDetID == iCscDetID )
605 Segment1IsGood =
false;
606 if(!lowpttrackmu) Segment1IsGood_alt=
false;
612 if(!Segment1IsGood&&!Segment1IsGood_alt)
continue;
616 LocalPoint iLocalPosition = iSegment->localPosition();
617 LocalVector iLocalDirection = iSegment->localDirection();
622 float iTheta = iGlobalDirection.
theta();
625 float iPhi = iGlobalPosition.
phi();
626 float iR = TMath::Sqrt(iGlobalPosition.
x()*iGlobalPosition.
x() + iGlobalPosition.
y()*iGlobalPosition.
y());
627 float iZ = iGlobalPosition.
z();
628 float iT = iSegment->time();
633 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);
634 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);
635 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);
636 calomatched = calomatched?
true: (hbhematched|| ebmatched|| eematched);
640 short int nSegs_alt = 0;
643 jSegment != TheCSCSegments->end();
645 if (jSegment == iSegment)
continue;
646 bool Segment2IsGood =
true;
647 bool Segment2IsGood_alt =
true;
648 LocalPoint jLocalPosition = jSegment->localPosition();
649 LocalVector jLocalDirection = jSegment->localDirection();
650 CSCDetId jCscDetID = jSegment->cscDetId();
653 float jTheta = jGlobalDirection.
theta();
654 float jPhi = jGlobalPosition.
phi();
655 float jR = TMath::Sqrt(jGlobalPosition.
x()*jGlobalPosition.
x() + jGlobalPosition.
y()*jGlobalPosition.
y());
656 float jZ = jGlobalPosition.
z() ;
657 float jT = jSegment->time();
663 && (
abs(jR - iR)<0.03*
abs(jZ - iZ))
669 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && (Segment2IsGood||!trkmuunvetoisdefault) ;
mu++ ) {
670 bool lowpttrackmu=
false;
671 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
672 if( !
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt()<3) lowpttrackmu=
true;
673 const std::vector<MuonChamberMatch> chambers =
mu->matches();
674 for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
675 kChamber != chambers.end(); kChamber ++ ) {
677 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
678 kSegment != kChamber->segmentMatches.end(); kSegment++ ) {
680 CSCDetId kCscDetID = cscSegRef->cscDetId();
682 if( kCscDetID == jCscDetID ) {
683 Segment2IsGood =
false;
684 if(!lowpttrackmu) Segment2IsGood_alt=
false;
690 if(Segment1IsGood && Segment2IsGood) {
692 minus_endcap = iGlobalPosition.
z() < 0 || jGlobalPosition.
z() < 0;
693 plus_endcap = iGlobalPosition.
z() > 0 || jGlobalPosition.
z() > 0;
696 if(Segment1IsGood_alt && Segment2IsGood_alt) {
698 minus_endcap = iGlobalPosition.
z() < 0 || jGlobalPosition.
z() < 0;
699 plus_endcap = iGlobalPosition.
z() > 0 || jGlobalPosition.
z() > 0;
701 abs(jT-iT)<0.05*
sqrt( (jR-iR)*(jR-iR)+(jZ-iZ)*(jZ-iZ) ) &&
702 abs(jT-iT)> 0.02*
sqrt( (jR-iR)*(jR-iR)+(jZ-iZ)*(jZ-iZ) ) &&
704 minus_endcap&&plus_endcap ) both_endcaps_loose_dtcut_alt =
true;
710 if (nSegs > 0) nSegs++;
713 if (nSegs > 0) both_endcaps_loose = both_endcaps_loose ? both_endcaps_loose : minus_endcap && plus_endcap;
714 if (nSegs_alt > 0) nSegs_alt++;
715 if (nSegs_alt > 0) both_endcaps_loose_alt = both_endcaps_loose_alt ? both_endcaps_loose_alt : minus_endcap && plus_endcap;
718 if (nSegs > maxNSegments) {
722 maxNSegments = nSegs;
723 both_endcaps = both_endcaps ? both_endcaps : minus_endcap && plus_endcap;
726 if (nSegs_alt > maxNSegments_alt) {
727 maxNSegments_alt = nSegs_alt;
728 both_endcaps_alt = both_endcaps_alt ? both_endcaps_alt : minus_endcap && plus_endcap;
740 return TheCSCHaloData;
float dt_lowthresh_segvsrh_hbhe
void SetNFlatHaloSegments_TrkMuUnVeto(short int nSegments)
float dr_lowthresh_segvsrh_hbhe
float dr_highthresh_segvsrh_ee
float dt_highthresh_segvsrh_eb
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
float dt_highthresh_segvsrh_hbhe
void SetSegmentsBothEndcaps_Loose_TrkMuUnVeto(bool b)
Geom::Phi< T > phi() const
Global3DPoint GlobalPoint
Geom::Theta< T > theta() const
std::vector< const CSCSegment * > matchCSC(const reco::Track &muon, const edm::Event &event)
const Plane & surface() const
The nominal surface of the GeomDet.
float matching_dphi_threshold
Geom::Theta< T > theta() const
float matching_deta_threshold
std::vector< edm::InputTag > vIT_HLTBit
float dr_lowthresh_segvsrh_ee
float dt_lowthresh_segvsrh_ee
unsigned int triggerIndex(std::string const &name) const
float max_dt_muon_segment
float dphi_thresh_segvsrh_ee
float dt_highthresh_segvsrh_ee
void SetSegmentIsCaloMatched(bool b)
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
Abs< T >::type abs(const T &t)
void SetSegmentsBothEndcaps(bool b)
float dphi_thresh_segvsrh_hbhe
void SetHLTBit(bool status)
void SetNFlatHaloSegments(short int nSegments)
float dr_highthresh_segvsrh_hbhe
T const * product() const
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.
T const * product() const
void SetNumberOfHaloTriggers(int PlusZ, int MinusZ)
std::vector< CSCALCTDigi >::const_iterator const_iterator
float max_free_inverse_beta
int matching_dwire_threshold
float norm_chi2_threshold
float dt_lowthresh_segvsrh_eb
std::vector< L1MuGMTReadoutRecord > const & getRecords() const
void SetSegmentsBothEndcaps_Loose_dTcut_TrkMuUnVeto(bool b)
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
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)
void SetNOutOfTimeHits(short int num)
std::pair< const_iterator, const_iterator > Range
virtual const GeomDetUnit * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
void SetNumberOfHaloTriggers_TrkMuUnVeto(int PlusZ, int MinusZ)
void SetNOutOfTimeTriggers(short int PlusZ, short int MinusZ)
static char chambers[264][20]
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)
tuple size
Write out results.
float dr_highthresh_segvsrh_eb
float dr_lowthresh_segvsrh_eb
edm::RefVector< reco::TrackCollection > & GetTracks()
float dphi_thresh_segvsrh_eb