CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GlobalHaloAlgo.cc
Go to the documentation of this file.
2 /*
3  [class]: GlobalHaloAlgo
4  [authors]: R. Remington, The University of Florida
5  [description]: See GlobalHaloAlgo.h
6  [date]: October 15, 2009
7 */
8 using namespace std;
9 using namespace edm;
10 using namespace reco;
11 
12 int Phi_To_HcaliPhi(float phi)
13 {
14  phi = phi < 0 ? phi + 2.*TMath::Pi() : phi ;
15  float phi_degrees = phi * (360.) / ( 2. * TMath::Pi() ) ;
16  int iPhi = (int) ( ( phi_degrees/5. ) + 1.);
17 
18  return iPhi < 73 ? iPhi : 73 ;
19 }
20 
21 int Phi_To_EcaliPhi(float phi)
22 {
23  phi = phi < 0 ? phi + 2.*TMath::Pi() : phi ;
24  float phi_degrees = phi * (360.) / ( 2. * TMath::Pi() ) ;
25  int iPhi = (int) ( phi_degrees + 1.);
26 
27  return iPhi < 361 ? iPhi : 360 ;
28 }
29 
31 {
32  // Defaults are "loose"
33  Ecal_R_Min = 110.; // Tight: 200.
34  Ecal_R_Max = 330.; // Tight: 250.
35  Hcal_R_Min = 110.; // Tight: 220.
36  Hcal_R_Max = 490.; // Tight: 350.
37 
38 }
39 
40 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, const CSCHaloData& TheCSCHaloData, const EcalHaloData& TheEcalHaloData, const HcalHaloData& TheHcalHaloData)
41 {
42 
43  GlobalHaloData TheGlobalHaloData;
44  float METOverSumEt = TheCaloMET.sumEt() ? TheCaloMET.pt() / TheCaloMET.sumEt() : 0 ;
45  TheGlobalHaloData.SetMETOverSumEt(METOverSumEt);
46 
47  //int EcalOverlapping_CSCRecHits[73];
48  //int EcalOverlapping_CSCSegments[73];
49 
50  int EcalOverlapping_CSCRecHits[361];
51  int EcalOverlapping_CSCSegments[361];
52  int HcalOverlapping_CSCRecHits[73];
53  int HcalOverlapping_CSCSegments[73];
54 
55  if( TheCSCSegments.isValid() )
56  {
57  for(CSCSegmentCollection::const_iterator iSegment = TheCSCSegments->begin(); iSegment != TheCSCSegments->end(); iSegment++)
58  {
59  bool EcalOverlap[361];
60  bool HcalOverlap[73];
61  for( int i = 0 ; i < 361 ; i++ )
62  {
63  EcalOverlap[i] = false;
64  if( i < 73 ) HcalOverlap[i] = false;
65  }
66 
67  std::vector<CSCRecHit2D> Hits = iSegment->specificRecHits() ;
68  for(std::vector<CSCRecHit2D>::iterator iHit = Hits.begin() ; iHit != Hits.end(); iHit++ )
69  {
70  DetId TheDetUnitId(iHit->geographicalId());
71  if( TheDetUnitId.det() != DetId::Muon ) continue;
72  if( TheDetUnitId.subdetId() != MuonSubdetId::CSC ) continue;
73 
74  const GeomDetUnit *TheUnit = TheCSCGeometry.idToDetUnit(TheDetUnitId);
75  LocalPoint TheLocalPosition = iHit->localPosition();
76  const BoundPlane& TheSurface = TheUnit->surface();
77  const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
78 
79  int Hcal_iphi = Phi_To_HcaliPhi( TheGlobalPosition.phi() ) ;
80  int Ecal_iphi = Phi_To_EcaliPhi( TheGlobalPosition.phi() ) ;
81  float x = TheGlobalPosition.x();
82  float y = TheGlobalPosition.y();
83 
84  float r = TMath::Sqrt( x*x + y*y);
85 
86  if( r < Ecal_R_Max && r > Ecal_R_Min )
87  EcalOverlap[Ecal_iphi] = true;
88  if( r < Hcal_R_Max && r > Hcal_R_Max )
89  HcalOverlap[Hcal_iphi] = true;
90  }
91  for( int i = 0 ; i < 361 ; i++ )
92  {
93  if( EcalOverlap[i] ) EcalOverlapping_CSCSegments[i]++;
94  if( i < 73 && HcalOverlap[i] )
95  HcalOverlapping_CSCSegments[i]++;
96  }
97  }
98  }
99  if( TheCSCRecHits.isValid() )
100  {
101  for(CSCRecHit2DCollection::const_iterator iCSCRecHit = TheCSCRecHits->begin(); iCSCRecHit != TheCSCRecHits->end(); iCSCRecHit++ )
102  {
103 
104  DetId TheDetUnitId(iCSCRecHit->geographicalId());
105  if( TheDetUnitId.det() != DetId::Muon ) continue;
106  if( TheDetUnitId.subdetId() != MuonSubdetId::CSC ) continue;
107 
108  const GeomDetUnit *TheUnit = TheCSCGeometry.idToDetUnit(TheDetUnitId);
109  LocalPoint TheLocalPosition = iCSCRecHit->localPosition();
110  const BoundPlane& TheSurface = TheUnit->surface();
111  const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
112 
113  int Hcaliphi = Phi_To_HcaliPhi( TheGlobalPosition.phi() ) ;
114  int Ecaliphi = Phi_To_EcaliPhi( TheGlobalPosition.phi() ) ;
115  float x = TheGlobalPosition.x();
116  float y = TheGlobalPosition.y();
117 
118  float r = TMath::Sqrt(x*x + y*y);
119 
120  if( r < Ecal_R_Max && r > Ecal_R_Min )
121  EcalOverlapping_CSCRecHits[Ecaliphi] ++;
122  if( r < Hcal_R_Max && r > Hcal_R_Max )
123  HcalOverlapping_CSCRecHits[Hcaliphi] ++ ;
124  }
125  }
126 
127  // In development....
128  // Get Ecal Wedges
129  std::vector<PhiWedge> EcalWedges = TheEcalHaloData.GetPhiWedges();
130 
131  // Get Hcal Wedges
132  std::vector<PhiWedge> HcalWedges = TheHcalHaloData.GetPhiWedges();
133 
134  //Get Ref to CSC Tracks
135  //edm::RefVector<reco::TrackCollection> TheCSCTracks = TheCSCHaloData.GetTracks();
136  //for(unsigned int i = 0 ; i < TheCSCTracks.size() ; i++ )
137  //edm::Ref<reco::TrackCollection> iTrack( TheCSCTracks, i );
138 
139  // Get global positions of central most rechit of CSC Halo tracks
140  std::vector<GlobalPoint> TheGlobalPositions = TheCSCHaloData.GetCSCTrackImpactPositions();
141 
142  // Container to store Ecal/Hcal iPhi values matched to impact point of CSC tracks
143  std::vector<int> vEcaliPhi, vHcaliPhi;
144 
145  // Keep track of number of calo pointing CSC halo tracks that do not match to Phi wedges
146  int N_Unmatched_Tracks = 0;
147 
148  for( std::vector<GlobalPoint>::iterator Pos = TheGlobalPositions.begin() ; Pos != TheGlobalPositions.end() ; Pos ++ )
149  {
150  // Calculate global phi coordinate for central most rechit in the track
151  float global_phi = Pos->phi();
152  float global_r = TMath::Sqrt(Pos->x()*Pos->x() + Pos->y()*Pos->y());
153 
154  // Convert global phi to iPhi
155  int global_EcaliPhi = Phi_To_EcaliPhi( global_phi );
156  int global_HcaliPhi = Phi_To_HcaliPhi( global_phi );
157  bool MATCHED = false;
158 
159  //Loop over Ecal Phi Wedges
160  for( std::vector<PhiWedge>::iterator iWedge = EcalWedges.begin() ; iWedge != EcalWedges.end() ; iWedge++ )
161  {
162  if( (TMath::Abs( global_EcaliPhi - iWedge->iPhi() ) <= 5 ) && (global_r > Ecal_R_Min && global_r < Ecal_R_Max ) )
163  {
164  bool StoreWedge = true;
165  for( unsigned int i = 0 ; i< vEcaliPhi.size() ; i++ ) if ( vEcaliPhi[i] == iWedge->iPhi() ) StoreWedge = false;
166 
167  if( StoreWedge )
168  {
169  PhiWedge NewWedge(*iWedge);
170  NewWedge.SetOverlappingCSCSegments( EcalOverlapping_CSCSegments[iWedge->iPhi()] );
171  NewWedge.SetOverlappingCSCRecHits( EcalOverlapping_CSCRecHits[iWedge->iPhi()] );
172  vEcaliPhi.push_back( iWedge->iPhi() );
173  TheGlobalHaloData.GetMatchedEcalPhiWedges().push_back( NewWedge );
174  }
175  MATCHED = true;
176  }
177  }
178  //Loop over Hcal Phi Wedges
179  for( std::vector<PhiWedge>::iterator iWedge = HcalWedges.begin() ; iWedge != HcalWedges.end() ; iWedge++ )
180  {
181  if( (TMath::Abs( global_HcaliPhi - iWedge->iPhi() ) <= 2 ) && (global_r > Hcal_R_Min && global_r < Hcal_R_Max ) )
182  {
183  bool StoreWedge = true;
184  for( unsigned int i = 0 ; i < vHcaliPhi.size() ; i++ ) if( vHcaliPhi[i] == iWedge->iPhi() ) StoreWedge = false;
185 
186  if( StoreWedge )
187  {
188  vHcaliPhi.push_back( iWedge->iPhi() ) ;
189  PhiWedge NewWedge(*iWedge);
190  NewWedge.SetOverlappingCSCSegments( HcalOverlapping_CSCSegments[iWedge->iPhi()] );
191  NewWedge.SetOverlappingCSCRecHits( HcalOverlapping_CSCRecHits[iWedge->iPhi()] );
192  PhiWedge wedge(*iWedge);
193  TheGlobalHaloData.GetMatchedHcalPhiWedges().push_back( NewWedge ) ;
194  }
195  MATCHED = true;
196  }
197  }
198  if( !MATCHED ) N_Unmatched_Tracks ++;
199  }
200 
201  // Corrections to MEx, MEy
202  float dMEx = 0.;
203  float dMEy = 0.;
204  // Loop over calotowers and correct the MET for the towers that lie in the trajectory of the CSC Halo Tracks
205  for( edm::View<Candidate>::const_iterator iCandidate = TheCaloTowers->begin() ; iCandidate != TheCaloTowers->end() ; iCandidate++ )
206  {
207  const Candidate* c = &(*iCandidate);
208  if ( c )
209  {
210  const CaloTower* iTower = dynamic_cast<const CaloTower*> (c);
211  if( iTower->et() < TowerEtThreshold ) continue;
212  if( abs(iTower->ieta()) > 24 ) continue; // not in barrel/endcap
213  int iphi = iTower->iphi();
214  for( unsigned int x = 0 ; x < vEcaliPhi.size() ; x++ )
215  {
216  if( iphi == vEcaliPhi[x] )
217  {
218  dMEx += ( TMath::Cos(iTower->phi())*iTower->emEt() );
219  dMEy += ( TMath::Sin(iTower->phi())*iTower->emEt() );
220  }
221  }
222  for( unsigned int x = 0 ; x < vHcaliPhi.size() ; x++ )
223  {
224  if( iphi == vHcaliPhi[x] )
225  {
226  dMEx += ( TMath::Cos(iTower->phi() )*iTower->hadEt() ) ;
227  dMEy += ( TMath::Sin(iTower->phi() )*iTower->hadEt() ) ;
228  }
229  }
230  }
231  }
232 
233  TheGlobalHaloData.SetMETCorrections(dMEx, dMEy);
234  return TheGlobalHaloData;
235 }
const double Pi
int i
Definition: DBlmapReader.cc:9
const std::vector< PhiWedge > & GetPhiWedges() const
Definition: EcalHaloData.h:32
int ieta() const
Definition: CaloTower.h:169
double hadEt() const
Definition: CaloTower.h:100
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
void SetMETOverSumEt(float x)
int iphi() const
Definition: CaloTower.h:171
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, const reco::CSCHaloData &TheCSCHaloData, const reco::EcalHaloData &TheEcalHaloData, const reco::HcalHaloData &TheHcalHaloData)
std::vector< PhiWedge > & GetMatchedEcalPhiWedges()
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
virtual double pt() const
transverse momentum
double sumEt() const
Definition: MET.h:56
static const int CSC
Definition: MuonSubdetId.h:13
int Phi_To_HcaliPhi(float phi)
T Abs(T a)
Definition: MathUtil.h:49
const std::vector< GlobalPoint > & GetCSCTrackImpactPositions() const
Definition: CSCHaloData.h:78
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:75
Definition: DetId.h:18
void SetMETCorrections(float x, float y)
void SetOverlappingCSCRecHits(int x)
Definition: PhiWedge.h:64
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
std::vector< PhiWedge > & GetMatchedHcalPhiWedges()
void SetOverlappingCSCSegments(int x)
Definition: PhiWedge.h:63
int Phi_To_EcaliPhi(float phi)
const std::vector< PhiWedge > & GetPhiWedges() const
Definition: HcalHaloData.h:21
double et(double vtxZ) const
Definition: CaloTower.h:116
virtual const GeomDetUnit * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:93
Definition: DDAxes.h:10
T x() const
Definition: PV3DBase.h:62
virtual double phi() const
momentum azimuthal angle
double emEt() const
Definition: CaloTower.h:99
Definition: DDAxes.h:10