18 phi = phi < 0 ? phi + 2.*
TMath::Pi() : phi ;
19 float phi_degrees = phi * (360.) / ( 2. *
TMath::Pi() ) ;
20 int iPhi = (
int) ( ( phi_degrees/5. ) + 1.);
22 return iPhi < 73 ? iPhi : 73 ;
27 phi = phi < 0 ? phi + 2.*
TMath::Pi() : phi ;
28 float phi_degrees = phi * (360.) / ( 2. *
TMath::Pi() ) ;
29 int iPhi = (
int) ( phi_degrees + 1.);
31 return iPhi < 361 ? iPhi : 360 ;
44 reco::GlobalHaloData GlobalHaloAlgo::Calculate(
const CaloGeometry& TheCaloGeometry,
const CSCGeometry& TheCSCGeometry,
const reco::CaloMET& TheCaloMET,
edm::Handle<
edm::View<Candidate> >& TheCaloTowers,
edm::Handle<CSCSegmentCollection>& TheCSCSegments,
edm::Handle<CSCRecHit2DCollection>& TheCSCRecHits,
edm::Handle<reco::MuonCollection>& TheMuons,
const CSCHaloData& TheCSCHaloData,
const EcalHaloData& TheEcalHaloData,
const HcalHaloData& TheHcalHaloData,
bool ishlt)
48 float METOverSumEt = TheCaloMET.
sumEt() ? TheCaloMET.
pt() / TheCaloMET.
sumEt() : 0 ;
51 int EcalOverlapping_CSCRecHits[361] = {};
52 int EcalOverlapping_CSCSegments[361] = {};
53 int HcalOverlapping_CSCRecHits[73] = {};
54 int HcalOverlapping_CSCSegments[73] = {};
60 bool EcalOverlap[361];
62 for(
int i = 0 ;
i < 361 ;
i++ )
64 EcalOverlap[
i] =
false;
65 if(
i < 73 ) HcalOverlap[
i] =
false;
68 std::vector<CSCRecHit2D> Hits = iSegment->specificRecHits() ;
69 for(std::vector<CSCRecHit2D>::iterator iHit = Hits.begin() ; iHit != Hits.end(); iHit++ )
71 DetId TheDetUnitId(iHit->geographicalId());
76 LocalPoint TheLocalPosition = iHit->localPosition();
78 const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
82 float x = TheGlobalPosition.
x();
83 float y = TheGlobalPosition.
y();
85 float r = TMath::Sqrt( x*x + y*y);
87 if( r < Ecal_R_Max && r > Ecal_R_Min )
88 EcalOverlap[Ecal_iphi] =
true;
89 if( r < Hcal_R_Max && r > Hcal_R_Max )
90 HcalOverlap[Hcal_iphi] =
true;
92 for(
int i = 0 ;
i < 361 ;
i++ )
94 if( EcalOverlap[
i] ) EcalOverlapping_CSCSegments[
i]++;
95 if( i < 73 && HcalOverlap[i] )
96 HcalOverlapping_CSCSegments[
i]++;
105 DetId TheDetUnitId(iCSCRecHit->geographicalId());
110 LocalPoint TheLocalPosition = iCSCRecHit->localPosition();
112 const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
116 float x = TheGlobalPosition.
x();
117 float y = TheGlobalPosition.
y();
119 float r = TMath::Sqrt(x*x + y*y);
121 if( r < Ecal_R_Max && r > Ecal_R_Min )
122 EcalOverlapping_CSCRecHits[Ecaliphi] ++;
123 if( r < Hcal_R_Max && r > Hcal_R_Max )
124 HcalOverlapping_CSCRecHits[Hcaliphi] ++ ;
130 std::vector<PhiWedge> EcalWedges = TheEcalHaloData.
GetPhiWedges();
133 std::vector<PhiWedge> HcalWedges = TheHcalHaloData.
GetPhiWedges();
144 std::vector<int> vEcaliPhi, vHcaliPhi;
147 int N_Unmatched_Tracks = 0;
149 for( std::vector<GlobalPoint>::iterator Pos = TheGlobalPositions.begin() ; Pos != TheGlobalPositions.end() ; Pos ++ )
152 float global_phi = Pos->phi();
153 float global_r = TMath::Sqrt(Pos->x()*Pos->x() + Pos->y()*Pos->y());
158 bool MATCHED =
false;
161 for( std::vector<PhiWedge>::iterator iWedge = EcalWedges.begin() ; iWedge != EcalWedges.end() ; iWedge++ )
163 if( (
TMath::Abs( global_EcaliPhi - iWedge->iPhi() ) <= 5 ) && (global_r > Ecal_R_Min && global_r < Ecal_R_Max ) )
165 bool StoreWedge =
true;
166 for(
unsigned int i = 0 ;
i< vEcaliPhi.size() ;
i++ )
if ( vEcaliPhi[
i] == iWedge->iPhi() ) StoreWedge =
false;
173 vEcaliPhi.push_back( iWedge->iPhi() );
180 for( std::vector<PhiWedge>::iterator iWedge = HcalWedges.begin() ; iWedge != HcalWedges.end() ; iWedge++ )
182 if( (
TMath::Abs( global_HcaliPhi - iWedge->iPhi() ) <= 2 ) && (global_r > Hcal_R_Min && global_r < Hcal_R_Max ) )
184 bool StoreWedge =
true;
185 for(
unsigned int i = 0 ;
i < vHcaliPhi.size() ;
i++ )
if( vHcaliPhi[
i] == iWedge->iPhi() ) StoreWedge =
false;
189 vHcaliPhi.push_back( iWedge->iPhi() ) ;
199 if( !MATCHED ) N_Unmatched_Tracks ++;
212 if( iTower->
et() < TowerEtThreshold )
continue;
213 if(
abs(iTower->
ieta()) > 24 )
continue;
214 int iphi = iTower->
iphi();
215 for(
unsigned int x = 0 ; x < vEcaliPhi.size() ; x++ )
217 if( iphi == vEcaliPhi[x] )
219 dMEx += ( TMath::Cos(iTower->
phi())*iTower->
emEt() );
220 dMEy += ( TMath::Sin(iTower->
phi())*iTower->
emEt() );
223 for(
unsigned int x = 0 ; x < vHcaliPhi.size() ; x++ )
225 if( iphi == vHcaliPhi[x] )
227 dMEx += ( TMath::Cos(iTower->
phi() )*iTower->
hadEt() ) ;
228 dMEy += ( TMath::Sin(iTower->
phi() )*iTower->
hadEt() ) ;
244 bool ECALBmatched(
false), ECALEmatched(
false),HCALBmatched(
false),HCALEmatched(
false);
246 if (TheCSCSegments.
isValid()) {
248 iSegment != TheCSCSegments->end();
251 CSCDetId iCscDetID = iSegment->cscDetId();
252 bool Segment1IsGood=
true;
258 for(reco::MuonCollection::const_iterator
mu = TheMuons->begin();
mu!= TheMuons->end() && (Segment1IsGood) ;
mu++ )
261 if( !
mu->isTrackerMuon() && !
mu->isGlobalMuon() &&
mu->isStandAloneMuon() )
continue;
262 if( !
mu->isGlobalMuon() &&
mu->isTrackerMuon() &&
mu->pt()<3)
continue;
263 const std::vector<MuonChamberMatch>
chambers =
mu->matches();
264 for(std::vector<MuonChamberMatch>::const_iterator kChamber = chambers.begin();
265 kChamber != chambers.end(); kChamber ++ )
268 for( std::vector<reco::MuonSegmentMatch>::const_iterator kSegment = kChamber->segmentMatches.begin();
269 kSegment != kChamber->segmentMatches.end(); kSegment++ )
272 CSCDetId kCscDetID = cscSegRef->cscDetId();
274 if( kCscDetID == iCscDetID )
276 Segment1IsGood =
false;
283 if(!Segment1IsGood)
continue;
287 LocalPoint iLocalPosition = iSegment->localPosition();
288 LocalVector iLocalDirection = iSegment->localDirection();
293 float iTheta = iGlobalDirection.
theta();
294 if (iTheta > max_segment_theta && iTheta <
TMath::Pi() - max_segment_theta)
continue;
296 float iPhi = iGlobalPosition.
phi();
297 float iR =
sqrt(iGlobalPosition.
perp2()) ;
298 float iZ = iGlobalPosition.
z();
299 float iT = iSegment->time();
306 bool ebmatched =SegmentMatchingEB(TheGlobalHaloData,hccandEB,iZ,iR,iT,iPhi,ishlt);
307 bool eematched =SegmentMatchingEE(TheGlobalHaloData,hccandEE,iZ,iR,iT,iPhi,ishlt);
308 bool hbmatched =SegmentMatchingHB(TheGlobalHaloData,hccandHB,iZ,iR,iT,iPhi,ishlt);
309 bool hematched =SegmentMatchingHE(TheGlobalHaloData,hccandHE,iZ,iR,iT,iPhi,ishlt);
311 ECALBmatched |= ebmatched;
312 ECALEmatched |= eematched;
313 HCALBmatched |= hbmatched;
314 HCALEmatched |= hematched;
330 bool HaloPatternFoundInEB =
false;
331 for(
auto & hcand : hccandEB){
332 if((hcand.getIsHaloFromPattern() &&!ishlt)||(hcand.getIsHaloFromPattern_HLT() &&ishlt)){
333 HaloPatternFoundInEB =
true;
335 AddtoBeamHaloEBEERechits(bhrhcandidates, TheGlobalHaloData,
true);
340 bool HaloPatternFoundInEE =
false;
341 for(
auto & hcand : hccandEE){
342 if((hcand.getIsHaloFromPattern() &&!ishlt)||(hcand.getIsHaloFromPattern_HLT() &&ishlt)){
343 HaloPatternFoundInEE =
true;
345 AddtoBeamHaloEBEERechits( bhrhcandidates, TheGlobalHaloData,
false);
350 bool HaloPatternFoundInHB =
false;
351 for(
auto & hcand : hccandHB){
352 if((hcand.getIsHaloFromPattern() &&!ishlt)||(hcand.getIsHaloFromPattern_HLT() &&ishlt)){
353 HaloPatternFoundInHB =
true;
355 AddtoBeamHaloHBHERechits(bhrhcandidates, TheGlobalHaloData);
360 bool HaloPatternFoundInHE =
false;
361 for(
auto & hcand : hccandHE){
362 if((hcand.getIsHaloFromPattern() &&!ishlt)||(hcand.getIsHaloFromPattern_HLT() &&ishlt)){
363 HaloPatternFoundInHE =
true;
365 AddtoBeamHaloHBHERechits(bhrhcandidates, TheGlobalHaloData);
373 return TheGlobalHaloData;
382 bool rhmatchingfound =
false;
384 for(
auto & hcand : haloclustercands){
386 if(!ApplyMatchingCuts(
EB,ishlt, hcand.getSeedEt(), iZ, hcand.getSeedZ(),iR, hcand.getSeedR(), iT,hcand.getSeedTime(), iPhi, hcand.getSeedPhi()))
continue;
388 rhmatchingfound=
true;
392 AddtoBeamHaloEBEERechits(bhrhcandidates, thehalodata,
true);
396 return rhmatchingfound;
401 bool rhmatchingfound =
false;
403 for(
auto & hcand : haloclustercands){
405 if(!ApplyMatchingCuts(
EE,ishlt, hcand.getSeedEt(), iZ, hcand.getSeedZ(),iR, hcand.getSeedR(), iT,hcand.getSeedTime(), iPhi, hcand.getSeedPhi()))
continue;
407 rhmatchingfound=
true;
411 AddtoBeamHaloEBEERechits(bhrhcandidates, thehalodata,
false);
415 return rhmatchingfound;
420 bool rhmatchingfound =
false;
422 for(
auto & hcand : haloclustercands){
424 if(!ApplyMatchingCuts(
HB,ishlt, hcand.getSeedEt(), iZ, hcand.getSeedZ(),iR, hcand.getSeedR(), iT,hcand.getSeedTime(), iPhi, hcand.getSeedPhi()))
continue;
426 rhmatchingfound=
true;
430 AddtoBeamHaloHBHERechits(bhrhcandidates, thehalodata);
434 return rhmatchingfound;
439 bool rhmatchingfound =
false;
441 for(
auto & hcand : haloclustercands){
443 if(!ApplyMatchingCuts(
HE,ishlt, hcand.getSeedEt(), iZ, hcand.getSeedZ(),iR, hcand.getSeedR(), iT,hcand.getSeedTime(), iPhi, hcand.getSeedPhi()))
continue;
445 rhmatchingfound=
true;
449 AddtoBeamHaloHBHERechits(bhrhcandidates, thehalodata);
453 return rhmatchingfound;
458 bool GlobalHaloAlgo::ApplyMatchingCuts(
int subdet,
bool ishlt,
double rhet,
double segZ,
double rhZ,
double segR,
double rhR,
double segT,
double rhT,
double segPhi,
double rhPhi){
460 double tBXrh = rhT+
sqrt(rhR*rhR+rhZ*rhZ)/c_cm_per_ns;
461 double tBXseg = segT+
sqrt(segR*segR+segZ*segZ)/c_cm_per_ns;
463 double tcorseg = tBXseg -
std::abs(segZ)/c_cm_per_ns;
464 double tcorsegincbh = tBXseg +
std::abs(segZ)/c_cm_per_ns;
465 double truedt[4]={1000,1000,1000,1000};
468 double twindow_seg = 15;
469 if(
std::abs(tcorsegincbh) <twindow_seg) truedt[0] = tBXrh -tBXseg -
std::abs(rhZ-segZ)/c_cm_per_ns;
471 if(
std::abs(tcorseg) < twindow_seg) truedt[1] = tBXseg -tBXrh -
std::abs(rhZ-segZ)/c_cm_per_ns;
473 if(tcorsegincbh> 25-twindow_seg&&
std::abs(tcorsegincbh) <25+twindow_seg) truedt[2] = tBXrh -tBXseg -
std::abs(rhZ-segZ)/c_cm_per_ns;
475 if(tcorseg >25-twindow_seg && tcorseg<25+twindow_seg) truedt[3] = tBXseg -tBXrh -
std::abs(rhZ-segZ)/c_cm_per_ns;
479 if(rhet< et_thresh_rh_eb)
return false;
480 if(rhet< 20&&ishlt)
return false;
482 if(rhR-segR< dr_lowthresh_segvsrh_eb)
return false;
483 if(rhR-segR> dr_highthresh_segvsrh_eb)
return false;
484 if(
std::abs(truedt[0])>dt_segvsrh_eb &&
std::abs(truedt[1])>dt_segvsrh_eb &&
std::abs(truedt[2])>dt_segvsrh_eb &&
std::abs(truedt[3])>dt_segvsrh_eb )
return false;
491 if(rhet< et_thresh_rh_ee)
return false;
492 if(rhet< 20&&ishlt)
return false;
494 if(rhR-segR< dr_lowthresh_segvsrh_ee)
return false;
495 if(rhR-segR> dr_highthresh_segvsrh_ee)
return false;
496 if(
std::abs(truedt[0])>dt_segvsrh_ee &&
std::abs(truedt[1])>dt_segvsrh_ee &&
std::abs(truedt[2])>dt_segvsrh_ee &&
std::abs(truedt[3])>dt_segvsrh_ee )
return false;
502 if(rhet< et_thresh_rh_hb)
return false;
503 if(rhet< 20&&ishlt)
return false;
505 if(rhR-segR< dr_lowthresh_segvsrh_hb)
return false;
506 if(rhR-segR> dr_highthresh_segvsrh_hb)
return false;
507 if(
std::abs(truedt[0])>dt_segvsrh_hb &&
std::abs(truedt[1])>dt_segvsrh_hb &&
std::abs(truedt[2])>dt_segvsrh_hb &&
std::abs(truedt[3])>dt_segvsrh_hb )
return false;
513 if(rhet< et_thresh_rh_he)
return false;
514 if(rhet< 20&&ishlt)
return false;
516 if(rhR-segR< dr_lowthresh_segvsrh_he)
return false;
517 if(rhR-segR> dr_highthresh_segvsrh_he)
return false;
518 if(
std::abs(truedt[0])>dt_segvsrh_he &&
std::abs(truedt[1])>dt_segvsrh_he &&
std::abs(truedt[2])>dt_segvsrh_he &&
std::abs(truedt[3])>dt_segvsrh_he )
return false;
529 for(
size_t ihit = 0; ihit<bhtaggedrechits.
size(); ++ ihit){
530 bool alreadyincl =
false;
535 for(
size_t jhit =0; jhit < refrhcoll.
size();jhit++){
537 if(rhitRef->detid() == rhRef->detid()) alreadyincl=
true;
538 if(rhitRef->detid() == rhRef->detid())
break;
540 if(!alreadyincl&&isbarrel)thehalodata.
GetEBRechits().push_back(rhRef);
541 if(!alreadyincl&&!isbarrel)thehalodata.
GetEERechits().push_back(rhRef);
547 for(
size_t ihit = 0; ihit<bhtaggedrechits.
size(); ++ ihit){
548 bool alreadyincl =
false;
552 for(
size_t jhit =0; jhit < refrhcoll.
size();jhit++){
554 if(rhitRef->detid() == rhRef->detid()) alreadyincl=
true;
555 if(rhitRef->detid() == rhRef->detid())
break;
const std::vector< HaloClusterCandidateHCAL > & getHaloClusterCandidatesHB() const
bool SegmentMatchingEE(reco::GlobalHaloData &thehalodata, const std::vector< reco::HaloClusterCandidateECAL > &haloclustercands, float iZ, float iR, float iT, float iPhi, bool ishlt)
void AddtoBeamHaloEBEERechits(edm::RefVector< EcalRecHitCollection > &bhtaggedrechits, reco::GlobalHaloData &thehalodata, bool isbarrel)
void SetSegmentIsEECaloMatched(bool b)
const std::vector< PhiWedge > & GetPhiWedges() const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Geom::Phi< T > phi() const
void SetMETOverSumEt(float x)
double pt() const final
transverse momentum
std::vector< PhiWedge > & GetMatchedEcalPhiWedges()
const Plane & surface() const
The nominal surface of the GeomDet.
void SetHaloPatternFoundHE(bool b)
Geom::Theta< T > theta() const
C::const_iterator const_iterator
constant access iterator type
const std::vector< HaloClusterCandidateECAL > & getHaloClusterCandidatesEB() const
int Phi_To_HcaliPhi(float phi)
void SetHaloPatternFoundEE(bool b)
edm::RefVector< HBHERecHitCollection > & GetHBHERechits()
void SetSegmentIsEBCaloMatched(bool b)
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
Abs< T >::type abs(const T &t)
reco::GlobalHaloData Calculate(const CaloGeometry &TheCaloGeometry, const CSCGeometry &TheCSCGeometry, const reco::CaloMET &TheCaloMET, edm::Handle< edm::View< reco::Candidate > > &TheCaloTowers, edm::Handle< CSCSegmentCollection > &TheCSCSegments, edm::Handle< CSCRecHit2DCollection > &TheCSCRecHits, edm::Handle< reco::MuonCollection > &TheMuons, const reco::CSCHaloData &TheCSCHaloData, const reco::EcalHaloData &TheEcalHaloData, const reco::HcalHaloData &TheHcalHaloData, bool ishlt=false)
bool SegmentMatchingHB(reco::GlobalHaloData &thehalodata, const std::vector< reco::HaloClusterCandidateHCAL > &haloclustercands, float iZ, float iR, float iT, float iPhi, bool ishlt)
bool SegmentMatchingEB(reco::GlobalHaloData &thehalodata, const std::vector< reco::HaloClusterCandidateECAL > &haloclustercands, float iZ, float iR, float iT, float iPhi, bool ishlt)
void AddtoBeamHaloHBHERechits(edm::RefVector< HBHERecHitCollection > &bhtaggedrechits, reco::GlobalHaloData &thehalodata)
void SetMETCorrections(float x, float y)
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
void SetOverlappingCSCRecHits(int x)
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
std::vector< PhiWedge > & GetMatchedHcalPhiWedges()
void SetOverlappingCSCSegments(int x)
const std::vector< HaloClusterCandidateHCAL > & getHaloClusterCandidatesHE() const
size_type size() const
Size of the RefVector.
bool SegmentMatchingHE(reco::GlobalHaloData &thehalodata, const std::vector< reco::HaloClusterCandidateHCAL > &haloclustercands, float iZ, float iR, float iT, float iPhi, bool ishlt)
int Phi_To_EcaliPhi(float phi)
const std::vector< PhiWedge > & GetPhiWedges() const
void SetSegmentIsHECaloMatched(bool b)
double et(double vtxZ) const
edm::RefVector< EcalRecHitCollection > & GetEBRechits()
void SetSegmentIsHBCaloMatched(bool b)
edm::RefVector< EcalRecHitCollection > & GetEERechits()
const std::vector< HaloClusterCandidateECAL > & getHaloClusterCandidatesEE() const
static char chambers[264][20]
bool ApplyMatchingCuts(int subdet, bool ishlt, double rhet, double segZ, double rhZ, double segR, double rhR, double segT, double rhT, double segPhi, double rhPhi)
double phi() const final
momentum azimuthal angle
void SetHaloPatternFoundHB(bool b)
void SetHaloPatternFoundEB(bool b)