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());
80 const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
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 );
190 n_tracks_small_beta++;
192 n_tracks_small_dT_and_beta++;
196 static std::atomic<bool> MuonTimeFail{
false};
197 bool expected =
false;
198 if( MuonTimeFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
200 edm::LogWarning (
"InvalidInputTag") <<
"The MuonTimeExtraMap does not appear to be in the event. Some beam halo "
201 <<
" identification variables will be empty" ;
205 TheCSCHaloData.
SetNIncomingTracks(n_tracks_small_dT,n_tracks_small_beta,n_tracks_small_dT_and_beta);
209 static std::atomic<bool> CosmicFail{
false};
210 bool expected =
false;
211 if( CosmicFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
213 edm::LogWarning (
"InvalidInputTag") <<
" The Cosmic Muon collection does not appear to be in the event. These beam halo "
214 <<
" identification variables will be empty" ;
220 bool EventPasses =
false;
227 if( bit < TheHLTResults->
size() )
230 if( TheHLTResults->accept( bit ) && !TheHLTResults->error( bit ) )
244 static std::atomic<bool> HLTFail{
false};
245 bool expected =
false;
246 if( HLTFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
248 edm::LogWarning (
"InvalidInputTag") <<
"The HLT results do not appear to be in the event. The beam halo HLT trigger "
249 <<
"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();
321 GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
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));
337 if( (*iter1).etaValue() > 0 )
351 static std::atomic<bool> L1Fail{
false};
352 bool expected =
false;
353 if( L1Fail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
355 edm::LogWarning (
"InvalidInputTag") <<
"The L1MuGMTReadoutCollection does not appear to be in the event. The L1 beam halo trigger "
356 <<
"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 );
421 if( detId.endcap() == 1 )
423 else if ( detId.endcap() == 2)
432 static std::atomic<bool> DigiFail{
false};
433 bool expected =
false;
434 if (DigiFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel)){
435 edm::LogWarning (
"InvalidInputTag") <<
"The CSCALCTDigiCollection does not appear to be in the event. The ALCT Digis will "
436 <<
" 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();
484 static std::atomic<bool> RecHitFail{
false};
485 bool expected =
false;
486 if( RecHitFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
488 edm::LogWarning (
"InvalidInputTag") <<
"The requested CSCRecHit2DCollection does not appear to be in the event. The CSC RecHit "
489 <<
" 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();
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());
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 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
std::vector< const CSCSegment * > matchCSC(const reco::Track &muon, const edm::Event &event)
const Plane & surface() const
The nominal surface of the GeomDet.
float max_segment_phi_diff
float matching_dphi_threshold
Geom::Theta< T > theta() const
float matching_deta_threshold
std::vector< edm::InputTag > vIT_HLTBit
unsigned int triggerIndex(std::string const &name) const
float max_dt_muon_segment
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
void SetSegmentsBothEndcaps(bool b)
void SetHLTBit(bool status)
void SetNFlatHaloSegments(short int nSegments)
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.
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
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
virtual const GeomDetUnit * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
void SetNOutOfTimeTriggers(short int PlusZ, short int MinusZ)
static char chambers[264][20]
tuple size
Write out results.
edm::RefVector< reco::TrackCollection > & GetTracks()