88 bool calomatched =
false;
89 bool ECALBmatched =
false;
90 bool ECALEmatched =
false;
91 bool HCALmatched =
false;
99 bool trkmuunvetoisdefault =
false;
105 short int n_tracks_small_beta=0;
106 short int n_tracks_small_dT=0;
107 short int n_tracks_small_dT_and_beta=0;
108 for( reco::MuonCollection::const_iterator iMuon = TheCosmicMuons->begin() ; iMuon != TheCosmicMuons->end() ; iMuon++, imucount++ )
113 bool StoreTrack =
false;
115 float innermost_global_z = 1500.;
116 float outermost_global_z = 0.;
120 for(
unsigned int j = 0 ; j < Track->extra()->recHitsSize(); j++ )
122 auto hit = Track->extra()->recHitRef(j);
123 if( !
hit->isValid() )
continue;
124 DetId TheDetUnitId(
hit->geographicalId());
131 const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
133 float z = TheGlobalPosition.
z();
134 if(
abs(z) < innermost_global_z )
136 innermost_global_z =
abs(z);
137 InnerMostGlobalPosition =
GlobalPoint( TheGlobalPosition);
139 if(
abs(z) > outermost_global_z )
141 outermost_global_z =
abs(z);
142 OuterMostGlobalPosition =
GlobalPoint( TheGlobalPosition );
147 std::vector<const CSCSegment*> MatchedSegments = TheMatcher->
matchCSC(*Track,TheEvent);
150 float InnerSegmentTime[2] = {0,0};
151 float OuterSegmentTime[2] = {0,0};
152 float innermost_seg_z[2] = {1500,1500};
153 float outermost_seg_z[2] = {0,0};
154 for (std::vector<const CSCSegment*>::const_iterator segment =MatchedSegments.begin();
155 segment != MatchedSegments.end(); ++segment)
157 CSCDetId TheCSCDetId((*segment)->cscDetId());
159 LocalPoint TheLocalPosition = (*segment)->localPosition();
160 const GlobalPoint TheGlobalPosition = TheCSCChamber->toGlobal(TheLocalPosition);
161 float z = TheGlobalPosition.
z();
162 int TheEndcap = TheCSCDetId.endcap();
163 if(
abs(z) < innermost_seg_z[TheEndcap-1] )
165 innermost_seg_z[TheEndcap-1] =
abs(z);
166 InnerSegmentTime[TheEndcap-1] = (*segment)->time();
168 if(
abs(z) > outermost_seg_z[TheEndcap-1] )
170 outermost_seg_z[TheEndcap-1] =
abs(z);
171 OuterSegmentTime[TheEndcap-1] = (*segment)->time();
175 if( nCSCHits < 3 )
continue;
177 float dT_Segment = 0;
179 if( innermost_seg_z[0] < outermost_seg_z[0])
180 dT_Segment = OuterSegmentTime[0]-InnerSegmentTime[0];
181 if( innermost_seg_z[1] < outermost_seg_z[1])
185 if (dT_Segment == 0.0 || OuterSegmentTime[1]-InnerSegmentTime[1] < dT_Segment)
186 dT_Segment = OuterSegmentTime[1]-InnerSegmentTime[1] ;
189 if( OuterMostGlobalPosition.
x() == 0. || OuterMostGlobalPosition.
y() == 0. || OuterMostGlobalPosition.
z() == 0. )
191 if( InnerMostGlobalPosition.
x() == 0. || InnerMostGlobalPosition.
y() == 0. || InnerMostGlobalPosition.
z() == 0. )
197 float deta =
abs( OuterMostGlobalPosition.
eta() - InnerMostGlobalPosition.
eta() );
199 float theta = Track->outerMomentum().theta();
200 float innermost_x = InnerMostGlobalPosition.
x() ;
201 float innermost_y = InnerMostGlobalPosition.
y();
202 float outermost_x = OuterMostGlobalPosition.
x();
203 float outermost_y = OuterMostGlobalPosition.
y();
204 float innermost_r = TMath::Sqrt(innermost_x *innermost_x + innermost_y * innermost_y );
205 float outermost_r = TMath::Sqrt(outermost_x *outermost_x + outermost_y * outermost_y );
241 n_tracks_small_beta++;
243 n_tracks_small_dT_and_beta++;
247 static std::atomic<bool> MuonTimeFail{
false};
248 bool expected =
false;
249 if( MuonTimeFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
251 edm::LogWarning (
"InvalidInputTag") <<
"The MuonTimeExtraMap does not appear to be in the event. Some beam halo " 252 <<
" identification variables will be empty" ;
256 TheCSCHaloData.
SetNIncomingTracks(n_tracks_small_dT,n_tracks_small_beta,n_tracks_small_dT_and_beta);
260 static std::atomic<bool> CosmicFail{
false};
261 bool expected =
false;
262 if( CosmicFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
264 edm::LogWarning (
"InvalidInputTag") <<
" The Cosmic Muon collection does not appear to be in the event. These beam halo " 265 <<
" identification variables will be empty" ;
273 short int n_recHitsP = 0;
274 short int n_recHitsM = 0;
278 for (dRHIter = TheCSCRecHits->begin(); dRHIter != TheCSCRecHits->end(); dRHIter++)
280 if ( !((*dRHIter).isValid()) )
continue;
282 float RHTime = (*dRHIter).tpeak();
283 LocalPoint rhitlocal = (*dRHIter).localPosition();
286 float globZ = globalPosition.
z();
313 static std::atomic<bool> RecHitFail{
false};
314 bool expected =
false;
315 if( RecHitFail.compare_exchange_strong(expected,
true,std::memory_order_acq_rel) )
317 edm::LogWarning (
"InvalidInputTag") <<
"The requested CSCRecHit2DCollection does not appear to be in the event. The CSC RecHit " 318 <<
" variables used for halo identification will not be calculated or stored";
325 short int maxNSegments = 0;
326 bool plus_endcap =
false;
327 bool minus_endcap =
false;
328 bool both_endcaps =
false;
329 bool both_endcaps_loose =
false;
332 short int maxNSegments_alt = 0;
333 bool both_endcaps_alt =
false;
334 bool both_endcaps_loose_alt =
false;
335 bool both_endcaps_loose_dtcut_alt =
false;
338 if (TheCSCSegments.
isValid()) {
340 iSegment != TheCSCSegments->end();
343 CSCDetId iCscDetID = iSegment->cscDetId();
344 bool Segment1IsGood=
true;
345 bool Segment1IsGood_alt=
true;
350 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && (Segment1IsGood||!trkmuunvetoisdefault) ;
mu++ )
352 bool lowpttrackmu=
false;
353 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
354 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon()&&trkmuunvetoisdefault)
continue;
355 if( !
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt()<3) lowpttrackmu=
true;
356 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
357 for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
358 kChamber != chambers.end(); kChamber ++ )
361 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
362 kSegment != kChamber->segmentMatches.end(); kSegment++ )
365 CSCDetId kCscDetID = cscSegRef->cscDetId();
367 if( kCscDetID == iCscDetID )
369 Segment1IsGood =
false;
370 if(!lowpttrackmu) Segment1IsGood_alt=
false;
376 if(!Segment1IsGood&&!Segment1IsGood_alt)
continue;
380 LocalPoint iLocalPosition = iSegment->localPosition();
381 LocalVector iLocalDirection = iSegment->localDirection();
386 float iTheta = iGlobalDirection.
theta();
389 float iPhi = iGlobalPosition.
phi();
390 float iR = TMath::Sqrt(iGlobalPosition.
x()*iGlobalPosition.
x() + iGlobalPosition.
y()*iGlobalPosition.
y());
391 float iZ = iGlobalPosition.
z();
392 float iT = iSegment->time();
397 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);
398 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);
399 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);
400 calomatched |= (hbhematched || ebmatched || eematched);
401 HCALmatched |= hbhematched;
402 ECALBmatched |= ebmatched;
403 ECALEmatched |= eematched;
406 short int nSegs_alt = 0;
409 jSegment != TheCSCSegments->end();
411 if (jSegment == iSegment)
continue;
412 bool Segment2IsGood =
true;
413 bool Segment2IsGood_alt =
true;
414 LocalPoint jLocalPosition = jSegment->localPosition();
415 LocalVector jLocalDirection = jSegment->localDirection();
416 CSCDetId jCscDetID = jSegment->cscDetId();
419 float jTheta = jGlobalDirection.
theta();
420 float jPhi = jGlobalPosition.
phi();
421 float jR = TMath::Sqrt(jGlobalPosition.
x()*jGlobalPosition.
x() + jGlobalPosition.
y()*jGlobalPosition.
y());
422 float jZ = jGlobalPosition.
z() ;
423 float jT = jSegment->time();
427 && ( (jR - iR) >-0.02*
std::abs(jZ - iZ) || iT>jT || jZ*iZ>0)
428 && ( (iR - jR) >-0.02*
std::abs(jZ - iZ) || iT<jT || jZ*iZ>0)
433 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && (Segment2IsGood||!trkmuunvetoisdefault) ;
mu++ ) {
434 bool lowpttrackmu=
false;
435 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
436 if( !
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt()<3) lowpttrackmu=
true;
437 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
438 for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
439 kChamber != chambers.end(); kChamber ++ ) {
441 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
442 kSegment != kChamber->segmentMatches.end(); kSegment++ ) {
444 CSCDetId kCscDetID = cscSegRef->cscDetId();
446 if( kCscDetID == jCscDetID ) {
447 Segment2IsGood =
false;
448 if(!lowpttrackmu) Segment2IsGood_alt=
false;
454 if(Segment1IsGood && Segment2IsGood) {
456 minus_endcap = iGlobalPosition.
z() < 0 || jGlobalPosition.
z() < 0;
457 plus_endcap = iGlobalPosition.
z() > 0 || jGlobalPosition.
z() > 0;
460 if(Segment1IsGood_alt && Segment2IsGood_alt) {
462 minus_endcap = iGlobalPosition.
z() < 0 || jGlobalPosition.
z() < 0;
463 plus_endcap = iGlobalPosition.
z() > 0 || jGlobalPosition.
z() > 0;
464 double iTBX = iT+
sqrt(iGlobalPosition.
mag2())/c_cm_per_ns;
465 double jTBX = jT+
sqrt(jGlobalPosition.
mag2())/c_cm_per_ns;
466 double truedt = (iTBX>jTBX)? iTBX-jTBX-
std::abs(iZ-jZ)/c_cm_per_ns : jTBX-iTBX-
std::abs(iZ-jZ)/c_cm_per_ns;
470 minus_endcap&&plus_endcap ) both_endcaps_loose_dtcut_alt =
true;
476 if (nSegs > 0) nSegs++;
479 if (nSegs > 0) both_endcaps_loose = both_endcaps_loose ? both_endcaps_loose : minus_endcap && plus_endcap;
480 if (nSegs_alt > 0) nSegs_alt++;
481 if (nSegs_alt > 0) both_endcaps_loose_alt = both_endcaps_loose_alt ? both_endcaps_loose_alt : minus_endcap && plus_endcap;
484 if (nSegs > maxNSegments) {
488 maxNSegments = nSegs;
489 both_endcaps = both_endcaps ? both_endcaps : minus_endcap && plus_endcap;
492 if (nSegs_alt > maxNSegments_alt) {
493 maxNSegments_alt = nSegs_alt;
494 both_endcaps_alt = both_endcaps_alt ? both_endcaps_alt : minus_endcap && plus_endcap;
517 return TheCSCHaloData;
528 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){
530 for(
size_t ihit = 0; ihit< rechitcoll->
size(); ++ ihit){
531 const HBHERecHit & rechit = (*rechitcoll)[ ihit ];
533 double rhet = rechit.
energy()/cosh(rhpos.eta());
534 double dphi_rhseg =
abs(
deltaPhi(rhpos.phi(),iPhi));
535 double dr_rhseg =
sqrt(rhpos.x()*rhpos.x()+rhpos.y()*rhpos.y()) - iR;
536 double dtcorr_rhseg = rechit.
time()-
abs(rhpos.z()-iZ)/30- iT;
539 (rhpos.z()*iZ<0||
abs(rhpos.z())<200)&&
541 dphi_rhseg < dphi_thresh_segvsrh &&
542 dr_rhseg < dr_highthresh_segvsrh && dr_rhseg> dr_lowthresh_segvsrh &&
543 dtcorr_rhseg> dt_lowthresh_segvsrh && dtcorr_rhseg< dt_highthresh_segvsrh
549 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 ){
551 for(
size_t ihit = 0; ihit<rechitcoll->
size(); ++ ihit){
552 const EcalRecHit & rechit = (*rechitcoll)[ ihit ];
554 double rhet = rechit.
energy()/cosh(rhpos.eta());
555 double dphi_rhseg =
abs(
deltaPhi(rhpos.phi(),iPhi));
556 double dr_rhseg =
sqrt(rhpos.x()*rhpos.x()+rhpos.y()*rhpos.y()) - iR;
557 double dtcorr_rhseg = rechit.
time()-
abs(rhpos.z()-iZ)/30- iT;
559 ( rechit.
time()<-1)&&
560 (rhpos.z()*iZ<0||
abs(rhpos.z())<200)&&
562 dphi_rhseg < dphi_thresh_segvsrh &&
563 dr_rhseg < dr_highthresh_segvsrh && dr_rhseg> dr_lowthresh_segvsrh &&
564 dtcorr_rhseg> dt_lowthresh_segvsrh && dtcorr_rhseg< dr_highthresh_segvsrh
constexpr float energy() const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
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
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.
float dt_highthresh_segvsrh_hbhe
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.
float max_segment_phi_diff
float matching_dphi_threshold
Geom::Theta< T > theta() const
float matching_deta_threshold
const CaloGeometry * geo_
C::const_iterator const_iterator
constant access iterator type
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)
constexpr float time() const
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Abs< T >::type abs(const T &t)
void SetSegmentsBothEndcaps(bool b)
float dphi_thresh_segvsrh_hbhe
math::XYZPoint Point
point in the space
const HcalGeometry * hgeo_
GlobalPoint getPosition(const DetId &id) const
void SetHLTBit(bool status)
void SetNFlatHaloSegments(short int nSegments)
float dr_highthresh_segvsrh_hbhe
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)
float max_free_inverse_beta
void SetSegmentIsHCaloMatched(bool b)
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
int matching_dwire_threshold
float norm_chi2_threshold
float dt_lowthresh_segvsrh_eb
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
float dr_highthresh_segvsrh_eb
float dr_lowthresh_segvsrh_eb
edm::RefVector< reco::TrackCollection > & GetTracks()
float dphi_thresh_segvsrh_eb