15 constexpr
float c_cm_per_ns = 29.9792458;
82 bool calomatched =
false;
83 bool ECALBmatched =
false;
84 bool ECALEmatched =
false;
85 bool HCALmatched =
false;
93 bool trkmuunvetoisdefault =
false;
98 short int n_tracks_small_beta = 0;
99 short int n_tracks_small_dT = 0;
100 short int n_tracks_small_dT_and_beta = 0;
101 for (reco::MuonCollection::const_iterator iMuon = TheCosmicMuons->begin(); iMuon != TheCosmicMuons->end();
102 iMuon++, imucount++) {
107 bool StoreTrack =
false;
109 float innermost_global_z = 1500.;
110 float outermost_global_z = 0.;
114 for (
unsigned int j = 0;
j <
Track->
extra()->recHitsSize();
j++) {
118 DetId TheDetUnitId(
hit->geographicalId());
127 const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
129 float z = TheGlobalPosition.
z();
130 if (
abs(
z) < innermost_global_z) {
131 innermost_global_z =
abs(
z);
132 InnerMostGlobalPosition =
GlobalPoint(TheGlobalPosition);
134 if (
abs(
z) > outermost_global_z) {
135 outermost_global_z =
abs(
z);
136 OuterMostGlobalPosition =
GlobalPoint(TheGlobalPosition);
141 std::vector<const CSCSegment*> MatchedSegments = TheMatcher->
matchCSC(*
Track, TheEvent);
144 float InnerSegmentTime[2] = {0, 0};
145 float OuterSegmentTime[2] = {0, 0};
146 float innermost_seg_z[2] = {1500, 1500};
147 float outermost_seg_z[2] = {0, 0};
148 for (std::vector<const CSCSegment*>::const_iterator segment = MatchedSegments.begin();
149 segment != MatchedSegments.end();
151 CSCDetId TheCSCDetId((*segment)->cscDetId());
153 LocalPoint TheLocalPosition = (*segment)->localPosition();
154 const GlobalPoint TheGlobalPosition = TheCSCChamber->toGlobal(TheLocalPosition);
155 float z = TheGlobalPosition.
z();
156 int TheEndcap = TheCSCDetId.endcap();
157 if (
abs(
z) < innermost_seg_z[TheEndcap - 1]) {
158 innermost_seg_z[TheEndcap - 1] =
abs(
z);
159 InnerSegmentTime[TheEndcap - 1] = (*segment)->time();
161 if (
abs(
z) > outermost_seg_z[TheEndcap - 1]) {
162 outermost_seg_z[TheEndcap - 1] =
abs(
z);
163 OuterSegmentTime[TheEndcap - 1] = (*segment)->time();
170 float dT_Segment = 0;
172 if (innermost_seg_z[0] < outermost_seg_z[0])
173 dT_Segment = OuterSegmentTime[0] - InnerSegmentTime[0];
174 if (innermost_seg_z[1] < outermost_seg_z[1])
178 if (dT_Segment == 0.0 || OuterSegmentTime[1] - InnerSegmentTime[1] < dT_Segment)
179 dT_Segment = OuterSegmentTime[1] - InnerSegmentTime[1];
182 if (OuterMostGlobalPosition.
x() == 0. || OuterMostGlobalPosition.
y() == 0. || OuterMostGlobalPosition.
z() == 0.)
184 if (InnerMostGlobalPosition.
x() == 0. || InnerMostGlobalPosition.
y() == 0. || InnerMostGlobalPosition.
z() == 0.)
190 float deta =
abs(OuterMostGlobalPosition.
eta() - InnerMostGlobalPosition.
eta());
193 float innermost_x = InnerMostGlobalPosition.
x();
194 float innermost_y = InnerMostGlobalPosition.
y();
195 float outermost_x = OuterMostGlobalPosition.
x();
196 float outermost_y = OuterMostGlobalPosition.
y();
197 float innermost_r = TMath::Sqrt(innermost_x * innermost_x + innermost_y * innermost_y);
198 float outermost_r = TMath::Sqrt(outermost_x * outermost_x + outermost_y * outermost_y);
232 n_tracks_small_beta++;
234 n_tracks_small_dT_and_beta++;
236 static std::atomic<bool> MuonTimeFail{
false};
237 bool expected =
false;
238 if (MuonTimeFail.compare_exchange_strong(expected,
true, std::memory_order_acq_rel)) {
240 <<
"The MuonTimeExtraMap does not appear to be in the event. Some beam halo "
241 <<
" identification variables will be empty";
245 TheCSCHaloData.
SetNIncomingTracks(n_tracks_small_dT, n_tracks_small_beta, n_tracks_small_dT_and_beta);
248 static std::atomic<bool> CosmicFail{
false};
249 bool expected =
false;
250 if (CosmicFail.compare_exchange_strong(expected,
true, std::memory_order_acq_rel)) {
252 <<
" The Cosmic Muon collection does not appear to be in the event. These beam halo "
253 <<
" identification variables will be empty";
260 short int n_recHitsP = 0;
261 short int n_recHitsM = 0;
264 for (dRHIter = TheCSCRecHits->begin(); dRHIter != TheCSCRecHits->end(); dRHIter++) {
265 if (!((*dRHIter).isValid()))
268 float RHTime = (*dRHIter).tpeak();
269 LocalPoint rhitlocal = (*dRHIter).localPosition();
272 float globZ = globalPosition.
z();
296 static std::atomic<bool> RecHitFail{
false};
297 bool expected =
false;
298 if (RecHitFail.compare_exchange_strong(expected,
true, std::memory_order_acq_rel)) {
300 <<
"The requested CSCRecHit2DCollection does not appear to be in the event. The CSC RecHit "
301 <<
" variables used for halo identification will not be calculated or stored";
308 short int maxNSegments = 0;
309 bool plus_endcap =
false;
310 bool minus_endcap =
false;
311 bool both_endcaps =
false;
312 bool both_endcaps_loose =
false;
315 short int maxNSegments_alt = 0;
316 bool both_endcaps_alt =
false;
317 bool both_endcaps_loose_alt =
false;
318 bool both_endcaps_loose_dtcut_alt =
false;
321 if (TheCSCSegments.
isValid()) {
324 CSCDetId iCscDetID = iSegment->cscDetId();
325 bool Segment1IsGood =
true;
326 bool Segment1IsGood_alt =
true;
330 for (reco::MuonCollection::const_iterator
mu = TheMuons->begin();
331 mu != TheMuons->end() && (Segment1IsGood || !trkmuunvetoisdefault);
333 bool lowpttrackmu =
false;
334 if (!
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon())
336 if (!
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() && trkmuunvetoisdefault)
338 if (!
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt() < 3)
340 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
341 for (std::vector<MuonChamberMatch>::const_iterator kChamber =
chambers.begin(); kChamber !=
chambers.end();
345 for (std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
346 kSegment != kChamber->segmentMatches.end();
349 CSCDetId kCscDetID = cscSegRef->cscDetId();
351 if (kCscDetID == iCscDetID) {
352 Segment1IsGood =
false;
354 Segment1IsGood_alt =
false;
360 if (!Segment1IsGood && !Segment1IsGood_alt)
365 LocalPoint iLocalPosition = iSegment->localPosition();
366 LocalVector iLocalDirection = iSegment->localDirection();
371 float iTheta = iGlobalDirection.
theta();
375 float iPhi = iGlobalPosition.
phi();
376 float iR = TMath::Sqrt(iGlobalPosition.
x() * iGlobalPosition.
x() + iGlobalPosition.
y() * iGlobalPosition.
y());
377 float iZ = iGlobalPosition.
z();
378 float iT = iSegment->time();
416 calomatched |= (hbhematched || ebmatched || eematched);
417 HCALmatched |= hbhematched;
418 ECALBmatched |= ebmatched;
419 ECALEmatched |= eematched;
422 short int nSegs_alt = 0;
426 if (jSegment == iSegment)
428 bool Segment2IsGood =
true;
429 bool Segment2IsGood_alt =
true;
430 LocalPoint jLocalPosition = jSegment->localPosition();
431 LocalVector jLocalDirection = jSegment->localDirection();
432 CSCDetId jCscDetID = jSegment->cscDetId();
435 float jTheta = jGlobalDirection.
theta();
436 float jPhi = jGlobalPosition.
phi();
437 float jR = TMath::Sqrt(jGlobalPosition.
x() * jGlobalPosition.
x() + jGlobalPosition.
y() * jGlobalPosition.
y());
438 float jZ = jGlobalPosition.
z();
439 float jT = jSegment->time();
443 ((jR - iR) > -0.02 *
std::abs(jZ - iZ) || iT > jT || jZ * iZ > 0) &&
444 ((iR - jR) > -0.02 *
std::abs(jZ - iZ) || iT < jT || jZ * iZ > 0) &&
449 for (reco::MuonCollection::const_iterator
mu = TheMuons->begin();
450 mu != TheMuons->end() && (Segment2IsGood || !trkmuunvetoisdefault);
452 bool lowpttrackmu =
false;
453 if (!
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon())
455 if (!
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt() < 3)
457 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
458 for (std::vector<MuonChamberMatch>::const_iterator kChamber =
chambers.begin();
463 for (std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
464 kSegment != kChamber->segmentMatches.end();
467 CSCDetId kCscDetID = cscSegRef->cscDetId();
469 if (kCscDetID == jCscDetID) {
470 Segment2IsGood =
false;
472 Segment2IsGood_alt =
false;
478 if (Segment1IsGood && Segment2IsGood) {
480 minus_endcap = iGlobalPosition.
z() < 0 || jGlobalPosition.
z() < 0;
481 plus_endcap = iGlobalPosition.
z() > 0 || jGlobalPosition.
z() > 0;
484 if (Segment1IsGood_alt && Segment2IsGood_alt) {
486 minus_endcap = iGlobalPosition.
z() < 0 || jGlobalPosition.
z() < 0;
487 plus_endcap = iGlobalPosition.
z() > 0 || jGlobalPosition.
z() > 0;
488 double iTBX = iT +
sqrt(iGlobalPosition.
mag2()) / c_cm_per_ns;
489 double jTBX = jT +
sqrt(jGlobalPosition.
mag2()) / c_cm_per_ns;
490 double truedt = (iTBX > jTBX) ? iTBX - jTBX -
std::abs(iZ - jZ) / c_cm_per_ns
491 : jTBX - iTBX -
std::abs(iZ - jZ) / c_cm_per_ns;
492 if (
std::abs(truedt) < 15 && (iT > -15 || jT > -15) && minus_endcap && plus_endcap)
493 both_endcaps_loose_dtcut_alt =
true;
503 both_endcaps_loose = both_endcaps_loose ? both_endcaps_loose : minus_endcap && plus_endcap;
507 both_endcaps_loose_alt = both_endcaps_loose_alt ? both_endcaps_loose_alt : minus_endcap && plus_endcap;
510 if (nSegs > maxNSegments) {
514 maxNSegments = nSegs;
515 both_endcaps = both_endcaps ? both_endcaps : minus_endcap && plus_endcap;
518 if (nSegs_alt > maxNSegments_alt) {
519 maxNSegments_alt = nSegs_alt;
520 both_endcaps_alt = both_endcaps_alt ? both_endcaps_alt : minus_endcap && plus_endcap;
542 return TheCSCHaloData;
553 float dphi_thresh_segvsrh,
554 float dr_lowthresh_segvsrh,
555 float dr_highthresh_segvsrh,
556 float dt_lowthresh_segvsrh,
557 float dt_highthresh_segvsrh,
563 for (
size_t ihit = 0; ihit < rechitcoll->
size(); ++ihit) {
564 const HBHERecHit& rechit = (*rechitcoll)[ihit];
566 double rhet = rechit.
energy() / cosh(rhpos.eta());
567 double dphi_rhseg =
abs(
deltaPhi(rhpos.phi(), iPhi));
568 double dr_rhseg =
sqrt(rhpos.x() * rhpos.x() + rhpos.y() * rhpos.y()) - iR;
569 double dtcorr_rhseg = rechit.
time() -
abs(rhpos.z() - iZ) / 30 - iT;
570 if ((rechit.
time() < -3) && (rhpos.z() * iZ < 0 ||
abs(rhpos.z()) < 200) && rhet > et_thresh_rh &&
571 dphi_rhseg < dphi_thresh_segvsrh && dr_rhseg < dr_highthresh_segvsrh &&
572 dr_rhseg > dr_lowthresh_segvsrh &&
573 dtcorr_rhseg > dt_lowthresh_segvsrh && dtcorr_rhseg < dt_highthresh_segvsrh)
581 float dphi_thresh_segvsrh,
582 float dr_lowthresh_segvsrh,
583 float dr_highthresh_segvsrh,
584 float dt_lowthresh_segvsrh,
585 float dt_highthresh_segvsrh,
591 for (
size_t ihit = 0; ihit < rechitcoll->
size(); ++ihit) {
592 const EcalRecHit& rechit = (*rechitcoll)[ihit];
594 double rhet = rechit.
energy() / cosh(rhpos.eta());
595 double dphi_rhseg =
abs(
deltaPhi(rhpos.phi(), iPhi));
596 double dr_rhseg =
sqrt(rhpos.x() * rhpos.x() + rhpos.y() * rhpos.y()) - iR;
597 double dtcorr_rhseg = rechit.
time() -
abs(rhpos.z() - iZ) / 30 - iT;
598 if ((rechit.
time() < -1) && (rhpos.z() * iZ < 0 ||
abs(rhpos.z()) < 200) && rhet > et_thresh_rh &&
599 dphi_rhseg < dphi_thresh_segvsrh && dr_rhseg < dr_highthresh_segvsrh &&
600 dr_rhseg > dr_lowthresh_segvsrh &&
601 dtcorr_rhseg > dt_lowthresh_segvsrh && dtcorr_rhseg < dr_highthresh_segvsrh)