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.;
29 max_dt_muon_segment=-10.0;
30 max_free_inverse_beta=0.0;
35 matching_dphi_threshold = 0.18;
36 matching_deta_threshold = 0.4;
37 matching_dwire_threshold = 5.;
44 dphi_thresh_segvsrh_hbhe=0.05;
45 dphi_thresh_segvsrh_eb=0.05;
46 dphi_thresh_segvsrh_ee=0.05;
48 dr_lowthresh_segvsrh_hbhe=-20;
49 dr_lowthresh_segvsrh_eb=-20;
50 dr_lowthresh_segvsrh_ee=-20;
52 dr_highthresh_segvsrh_hbhe=20;
53 dr_highthresh_segvsrh_eb=20;
54 dr_highthresh_segvsrh_ee=20;
56 dt_lowthresh_segvsrh_hbhe=5;
57 dt_lowthresh_segvsrh_eb=5;
58 dt_lowthresh_segvsrh_ee=5;
60 dt_highthresh_segvsrh_hbhe=30;
61 dt_highthresh_segvsrh_eb=30;
62 dt_highthresh_segvsrh_ee=30;
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() );
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 );
209 if( deta < deta_threshold )
211 if( theta > min_outer_theta && theta < max_outer_theta )
213 if( dphi > dphi_threshold )
215 if( innermost_r < min_inner_radius )
217 if( innermost_r > max_inner_radius )
219 if( outermost_r < min_outer_radius )
221 if( outermost_r > max_outer_radius )
223 if( Track->normalizedChi2() > norm_chi2_threshold )
240 if (dT_Segment < max_dt_muon_segment )
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++;
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();
289 if ( RHTime < (recHit_t0 - recHit_twindow) )
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();
389 if (iTheta > max_segment_theta && iTheta <
TMath::Pi() - max_segment_theta)
continue;
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)
431 && (
std::abs(jR - iR) <= max_segment_r_diff || jZ*iZ < 0)
432 && (jTheta < max_segment_theta || jTheta >
TMath::Pi() - max_segment_theta)) {
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;
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){
532 for(
size_t ihit = 0; ihit< rechitcoll->
size(); ++ ihit){
533 const HBHERecHit & rechit = (*rechitcoll)[ ihit ];
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;
541 (rhpos.z()*iZ<0||
abs(rhpos.z())<200)&&
543 dphi_rhseg < dphi_thresh_segvsrh &&
544 dr_rhseg < dr_highthresh_segvsrh && dr_rhseg> dr_lowthresh_segvsrh &&
545 dtcorr_rhseg> dt_lowthresh_segvsrh && dtcorr_rhseg< dt_highthresh_segvsrh
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 ){
553 for(
size_t ihit = 0; ihit<rechitcoll->
size(); ++ ihit){
554 const EcalRecHit & rechit = (*rechitcoll)[ ihit ];
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;
561 ( rechit.
time()<-1)&&
562 (rhpos.z()*iZ<0||
abs(rhpos.z())<200)&&
564 dphi_rhseg < dphi_thresh_segvsrh &&
565 dr_rhseg < dr_highthresh_segvsrh && dr_rhseg> dr_lowthresh_segvsrh &&
566 dtcorr_rhseg> dt_lowthresh_segvsrh && dtcorr_rhseg< dr_highthresh_segvsrh
void SetNFlatHaloSegments_TrkMuUnVeto(short int nSegments)
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)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
void SetSegmentIsEECaloMatched(bool b)
HcalDetId id() const
get the id
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.
Geom::Theta< T > theta() const
void SetSegmentIsCaloMatched(bool b)
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
Abs< T >::type abs(const T &t)
void SetSegmentsBothEndcaps(bool b)
math::XYZPoint Point
point in the space
void SetHLTBit(bool status)
double deltaPhi(double phi1, double phi2)
void SetNFlatHaloSegments(short int nSegments)
const GeomDetUnit * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
DetId id() const
get the id
XYZPointD XYZPoint
point in space with cartesian internal representation
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)
void SetSegmentIsHCaloMatched(bool b)
math::XYZPoint getPosition(const DetId &id, reco::Vertex::Point vtx)
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
edm::RefVector< reco::TrackCollection > & GetTracks()