90 bool calomatched =
false;
91 bool ECALBmatched =
false;
92 bool ECALEmatched =
false;
93 bool HCALmatched =
false;
101 bool trkmuunvetoisdefault =
false;
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++ )
115 bool StoreTrack =
false;
117 float innermost_global_z = 1500.;
118 float outermost_global_z = 0.;
122 for(
unsigned int j = 0 ; j < Track->extra()->recHitsSize(); j++ )
124 auto hit = Track->extra()->recHitRef(j);
125 if( !
hit->isValid() )
continue;
126 DetId TheDetUnitId(
hit->geographicalId());
133 const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
135 float z = TheGlobalPosition.
z();
136 if(
abs(z) < innermost_global_z )
138 innermost_global_z =
abs(z);
139 InnerMostGlobalPosition =
GlobalPoint( TheGlobalPosition);
141 if(
abs(z) > outermost_global_z )
143 outermost_global_z =
abs(z);
144 OuterMostGlobalPosition =
GlobalPoint( TheGlobalPosition );
149 std::vector<const CSCSegment*> MatchedSegments = TheMatcher->
matchCSC(*Track,TheEvent);
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)
159 CSCDetId TheCSCDetId((*segment)->cscDetId());
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] )
167 innermost_seg_z[TheEndcap-1] =
abs(z);
168 InnerSegmentTime[TheEndcap-1] = (*segment)->time();
170 if(
abs(z) > outermost_seg_z[TheEndcap-1] )
172 outermost_seg_z[TheEndcap-1] =
abs(z);
173 OuterSegmentTime[TheEndcap-1] = (*segment)->time();
177 if( nCSCHits < 3 )
continue;
179 float dT_Segment = 0;
181 if( innermost_seg_z[0] < outermost_seg_z[0])
182 dT_Segment = OuterSegmentTime[0]-InnerSegmentTime[0];
183 if( innermost_seg_z[1] < outermost_seg_z[1])
187 if (dT_Segment == 0.0 || OuterSegmentTime[1]-InnerSegmentTime[1] < dT_Segment)
188 dT_Segment = OuterSegmentTime[1]-InnerSegmentTime[1] ;
191 if( OuterMostGlobalPosition.x() == 0. || OuterMostGlobalPosition.y() == 0. || OuterMostGlobalPosition.z() == 0. )
193 if( InnerMostGlobalPosition.x() == 0. || InnerMostGlobalPosition.y() == 0. || InnerMostGlobalPosition.z() == 0. )
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 );
243 n_tracks_small_beta++;
245 n_tracks_small_dT_and_beta++;
249 static std::atomic<bool> MuonTimeFail{
false};
250 bool expected =
false;
251 if( MuonTimeFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
253 edm::LogWarning (
"InvalidInputTag") <<
"The MuonTimeExtraMap does not appear to be in the event. Some beam halo " 254 <<
" identification variables will be empty" ;
258 TheCSCHaloData.
SetNIncomingTracks(n_tracks_small_dT,n_tracks_small_beta,n_tracks_small_dT_and_beta);
262 static std::atomic<bool> CosmicFail{
false};
263 bool expected =
false;
264 if( CosmicFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
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" ;
275 short int n_recHitsP = 0;
276 short int n_recHitsM = 0;
280 for (dRHIter = TheCSCRecHits->begin(); dRHIter != TheCSCRecHits->end(); dRHIter++)
282 if ( !((*dRHIter).isValid()) )
continue;
284 float RHTime = (*dRHIter).tpeak();
285 LocalPoint rhitlocal = (*dRHIter).localPosition();
288 float globZ = globalPosition.
z();
315 static std::atomic<bool> RecHitFail{
false};
316 bool expected =
false;
317 if( RecHitFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
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";
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;
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;
340 if (TheCSCSegments.
isValid()) {
342 iSegment != TheCSCSegments->end();
345 CSCDetId iCscDetID = iSegment->cscDetId();
346 bool Segment1IsGood=
true;
347 bool Segment1IsGood_alt=
true;
352 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && (Segment1IsGood||!trkmuunvetoisdefault) ;
mu++ )
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 ++ )
363 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
364 kSegment != kChamber->segmentMatches.end(); kSegment++ )
367 CSCDetId kCscDetID = cscSegRef->cscDetId();
369 if( kCscDetID == iCscDetID )
371 Segment1IsGood =
false;
372 if(!lowpttrackmu) Segment1IsGood_alt=
false;
378 if(!Segment1IsGood&&!Segment1IsGood_alt)
continue;
382 LocalPoint iLocalPosition = iSegment->localPosition();
383 LocalVector iLocalDirection = iSegment->localDirection();
388 float iTheta = iGlobalDirection.
theta();
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();
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;
408 short int nSegs_alt = 0;
411 jSegment != TheCSCSegments->end();
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();
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();
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)
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 ++ ) {
443 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
444 kSegment != kChamber->segmentMatches.end(); kSegment++ ) {
446 CSCDetId kCscDetID = cscSegRef->cscDetId();
448 if( kCscDetID == jCscDetID ) {
449 Segment2IsGood =
false;
450 if(!lowpttrackmu) Segment2IsGood_alt=
false;
456 if(Segment1IsGood && Segment2IsGood) {
458 minus_endcap = iGlobalPosition.
z() < 0 || jGlobalPosition.
z() < 0;
459 plus_endcap = iGlobalPosition.
z() > 0 || jGlobalPosition.
z() > 0;
462 if(Segment1IsGood_alt && Segment2IsGood_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;
472 minus_endcap&&plus_endcap ) both_endcaps_loose_dtcut_alt =
true;
478 if (nSegs > 0) nSegs++;
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;
486 if (nSegs > maxNSegments) {
490 maxNSegments = nSegs;
491 both_endcaps = both_endcaps ? both_endcaps : minus_endcap && plus_endcap;
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;
519 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 SetSegmentIsEECaloMatched(bool b)
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 max_segment_phi_diff
Geom::Theta< T > theta() const
float dr_lowthresh_segvsrh_ee
float dt_lowthresh_segvsrh_ee
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
virtual const GeomDetUnit * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
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)
float max_free_inverse_beta
void SetSegmentIsHCaloMatched(bool b)
float norm_chi2_threshold
float dt_lowthresh_segvsrh_eb
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)
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)
void SetSegmentIsEBCaloMatched(bool b)
T const * product() const
float dr_highthresh_segvsrh_eb
float dr_lowthresh_segvsrh_eb
edm::RefVector< reco::TrackCollection > & GetTracks()
float dphi_thresh_segvsrh_eb