CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoMET/METAlgorithms/src/GlobalHaloAlgo.cc

Go to the documentation of this file.
00001 #include "RecoMET/METAlgorithms/interface/GlobalHaloAlgo.h"
00002 /*
00003   [class]:  GlobalHaloAlgo
00004   [authors]: R. Remington, The University of Florida
00005   [description]: See GlobalHaloAlgo.h
00006   [date]: October 15, 2009
00007 */
00008 using namespace std;
00009 using namespace edm;
00010 using namespace reco;
00011 
00012 int Phi_To_HcaliPhi(float phi) 
00013 {
00014   phi = phi < 0 ? phi + 2.*TMath::Pi() : phi ;
00015   float phi_degrees = phi * (360.) / ( 2. * TMath::Pi() ) ;
00016   int iPhi = (int) ( ( phi_degrees/5. ) + 1.);
00017    
00018   return iPhi < 73 ? iPhi : 73 ;
00019 }
00020 
00021 int Phi_To_EcaliPhi(float phi) 
00022 {
00023   phi = phi < 0 ? phi + 2.*TMath::Pi() : phi ;
00024   float phi_degrees = phi * (360.) / ( 2. * TMath::Pi() ) ;
00025   int iPhi = (int) (  phi_degrees  + 1.);
00026    
00027   return iPhi < 361 ? iPhi : 360 ;
00028 }
00029 
00030 GlobalHaloAlgo::GlobalHaloAlgo()
00031 {
00032   // Defaults are "loose"
00033   Ecal_R_Min = 110.;   // Tight: 200.
00034   Ecal_R_Max = 330.;   // Tight: 250. 
00035   Hcal_R_Min = 110.;   // Tight: 220.
00036   Hcal_R_Max = 490.;   // Tight: 350.
00037   
00038 }
00039 
00040 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)
00041 {
00042   
00043   GlobalHaloData TheGlobalHaloData;
00044   float METOverSumEt = TheCaloMET.sumEt() ? TheCaloMET.pt() / TheCaloMET.sumEt() : 0 ;
00045   TheGlobalHaloData.SetMETOverSumEt(METOverSumEt);
00046 
00047   //int EcalOverlapping_CSCRecHits[73];
00048   //int EcalOverlapping_CSCSegments[73];
00049 
00050   int EcalOverlapping_CSCRecHits[361];
00051   int EcalOverlapping_CSCSegments[361];
00052   int HcalOverlapping_CSCRecHits[73];
00053   int HcalOverlapping_CSCSegments[73];
00054 
00055   if( TheCSCSegments.isValid() )
00056     {
00057       for(CSCSegmentCollection::const_iterator iSegment = TheCSCSegments->begin(); iSegment != TheCSCSegments->end(); iSegment++) 
00058         {
00059           bool EcalOverlap[361];
00060           bool HcalOverlap[73];
00061           for( int i = 0 ; i < 361 ; i++ ) 
00062             {
00063               EcalOverlap[i] = false;
00064               if( i < 73 ) HcalOverlap[i] = false;
00065             }
00066           
00067           std::vector<CSCRecHit2D> Hits = iSegment->specificRecHits() ;
00068           for(std::vector<CSCRecHit2D>::iterator iHit = Hits.begin() ; iHit != Hits.end(); iHit++ )
00069             {
00070               DetId TheDetUnitId(iHit->geographicalId());
00071               if( TheDetUnitId.det() != DetId::Muon ) continue;
00072               if( TheDetUnitId.subdetId() != MuonSubdetId::CSC ) continue;
00073 
00074               const GeomDetUnit *TheUnit = TheCSCGeometry.idToDetUnit(TheDetUnitId);
00075               LocalPoint TheLocalPosition = iHit->localPosition();  
00076               const BoundPlane& TheSurface = TheUnit->surface();
00077               const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
00078 
00079               int Hcal_iphi = Phi_To_HcaliPhi( TheGlobalPosition.phi() ) ;
00080               int Ecal_iphi = Phi_To_EcaliPhi( TheGlobalPosition.phi() ) ;
00081               float x = TheGlobalPosition.x(); 
00082               float y = TheGlobalPosition.y();
00083               
00084               float r = TMath::Sqrt( x*x + y*y);
00085               
00086               if( r < Ecal_R_Max && r > Ecal_R_Min )
00087                 EcalOverlap[Ecal_iphi] = true;
00088               if( r < Hcal_R_Max && r > Hcal_R_Max ) 
00089                 HcalOverlap[Hcal_iphi] = true;
00090             }
00091           for( int i = 0 ; i < 361 ; i++ ) 
00092             {
00093               if( EcalOverlap[i] )  EcalOverlapping_CSCSegments[i]++;
00094               if( HcalOverlap[i] )
00095                 if( i < 73 ) 
00096                   HcalOverlapping_CSCSegments[i]++;
00097             }
00098         } 
00099     }
00100   if( TheCSCRecHits.isValid() )
00101     {
00102       for(CSCRecHit2DCollection::const_iterator iCSCRecHit = TheCSCRecHits->begin();   iCSCRecHit != TheCSCRecHits->end(); iCSCRecHit++ )
00103         {
00104           
00105           DetId TheDetUnitId(iCSCRecHit->geographicalId());
00106           if( TheDetUnitId.det() != DetId::Muon ) continue;
00107           if( TheDetUnitId.subdetId() != MuonSubdetId::CSC ) continue;
00108           
00109           const GeomDetUnit *TheUnit = TheCSCGeometry.idToDetUnit(TheDetUnitId);
00110           LocalPoint TheLocalPosition = iCSCRecHit->localPosition();  
00111           const BoundPlane& TheSurface = TheUnit->surface();
00112           const GlobalPoint TheGlobalPosition = TheSurface.toGlobal(TheLocalPosition);
00113           
00114           int Hcaliphi = Phi_To_HcaliPhi( TheGlobalPosition.phi() ) ;
00115           int Ecaliphi = Phi_To_EcaliPhi( TheGlobalPosition.phi() ) ;
00116           float x = TheGlobalPosition.x(); 
00117           float y = TheGlobalPosition.y();
00118           
00119           float r = TMath::Sqrt(x*x + y*y);
00120           
00121           if( r < Ecal_R_Max && r > Ecal_R_Min )
00122             EcalOverlapping_CSCRecHits[Ecaliphi] ++;
00123           if( r < Hcal_R_Max && r > Hcal_R_Max ) 
00124             HcalOverlapping_CSCRecHits[Hcaliphi] ++ ;
00125         }
00126     }  
00127 
00128   // In development....
00129   // Get Ecal Wedges
00130   std::vector<PhiWedge> EcalWedges = TheEcalHaloData.GetPhiWedges();
00131   
00132   // Get Hcal Wedges
00133   std::vector<PhiWedge> HcalWedges = TheHcalHaloData.GetPhiWedges();
00134   
00135   //Get Ref to CSC Tracks
00136   //edm::RefVector<reco::TrackCollection> TheCSCTracks = TheCSCHaloData.GetTracks();
00137   //for(unsigned int i = 0 ; i < TheCSCTracks.size() ; i++ )
00138   //edm::Ref<reco::TrackCollection> iTrack( TheCSCTracks, i );
00139   
00140   // Get global positions of central most rechit of CSC Halo tracks
00141   std::vector<GlobalPoint> TheGlobalPositions = TheCSCHaloData.GetCSCTrackImpactPositions();
00142 
00143   // Container to store Ecal/Hcal iPhi values matched to impact point of CSC tracks
00144   std::vector<int> vEcaliPhi, vHcaliPhi;
00145 
00146   // Keep track of number of calo pointing CSC halo tracks that do not match to Phi wedges
00147   int N_Unmatched_Tracks = 0;  
00148   
00149   for( std::vector<GlobalPoint>::iterator Pos = TheGlobalPositions.begin() ; Pos != TheGlobalPositions.end() ; Pos ++ ) 
00150     {
00151       // Calculate global phi coordinate for central most rechit in the track
00152       float global_phi = Pos->phi();
00153       float global_r = TMath::Sqrt(Pos->x()*Pos->x() + Pos->y()*Pos->y());
00154       
00155       // Convert global phi to iPhi
00156       int global_EcaliPhi = Phi_To_EcaliPhi( global_phi );
00157       int global_HcaliPhi = Phi_To_HcaliPhi( global_phi );
00158       bool MATCHED = false;
00159       
00160       //Loop over Ecal Phi Wedges 
00161       for( std::vector<PhiWedge>::iterator iWedge = EcalWedges.begin() ; iWedge != EcalWedges.end() ; iWedge++ )
00162         {
00163           if( (TMath::Abs( global_EcaliPhi - iWedge->iPhi() ) <= 5 ) && (global_r >  Ecal_R_Min && global_r < Ecal_R_Max ) )
00164             {
00165               bool StoreWedge = true;
00166               for( unsigned int i = 0 ; i< vEcaliPhi.size() ; i++ ) if ( vEcaliPhi[i] == iWedge->iPhi() ) StoreWedge = false;
00167               
00168               if( StoreWedge ) 
00169                 {
00170                   PhiWedge NewWedge(*iWedge);
00171                   NewWedge.SetOverlappingCSCSegments( EcalOverlapping_CSCSegments[iWedge->iPhi()] );
00172                   NewWedge.SetOverlappingCSCRecHits( EcalOverlapping_CSCRecHits[iWedge->iPhi()] );
00173                   vEcaliPhi.push_back( iWedge->iPhi() );
00174                   TheGlobalHaloData.GetMatchedEcalPhiWedges().push_back( NewWedge );
00175                 }
00176               MATCHED = true;
00177             }
00178         }
00179       //Loop over Hcal Phi Wedges 
00180       for( std::vector<PhiWedge>::iterator iWedge = HcalWedges.begin() ; iWedge != HcalWedges.end() ; iWedge++ )
00181         {
00182           if(  (TMath::Abs( global_HcaliPhi - iWedge->iPhi() ) <=  2 ) && (global_r > Hcal_R_Min && global_r < Hcal_R_Max ) )
00183             {
00184               bool StoreWedge  = true;
00185               for( unsigned int i = 0 ; i < vHcaliPhi.size() ; i++ ) if(  vHcaliPhi[i] == iWedge->iPhi() ) StoreWedge = false;
00186               
00187               if( StoreWedge ) 
00188                 {
00189                   vHcaliPhi.push_back( iWedge->iPhi() ) ;
00190                   PhiWedge NewWedge(*iWedge);
00191                   NewWedge.SetOverlappingCSCSegments( HcalOverlapping_CSCSegments[iWedge->iPhi()] );
00192                   NewWedge.SetOverlappingCSCRecHits(  HcalOverlapping_CSCRecHits[iWedge->iPhi()] );               
00193                   PhiWedge wedge(*iWedge);
00194                   TheGlobalHaloData.GetMatchedHcalPhiWedges().push_back( NewWedge ) ; 
00195                 }
00196               MATCHED = true;
00197             }
00198         }
00199       if( !MATCHED ) N_Unmatched_Tracks ++;
00200     }
00201   
00202   // Corrections to MEx, MEy
00203   float dMEx = 0.; 
00204   float dMEy = 0.;
00205   // Loop over calotowers and correct the MET for the towers that lie in the trajectory of the CSC Halo Tracks
00206   for( edm::View<Candidate>::const_iterator iCandidate = TheCaloTowers->begin() ; iCandidate != TheCaloTowers->end() ; iCandidate++ )
00207     {
00208       const Candidate* c = &(*iCandidate);
00209       if ( c )
00210         {
00211           const CaloTower* iTower = dynamic_cast<const CaloTower*> (c);
00212           if( iTower->et() < TowerEtThreshold ) continue;
00213           if( abs(iTower->ieta()) > 24 )  continue;   // not in barrel/endcap
00214           int iphi = iTower->iphi();
00215           for( unsigned int x = 0 ; x < vEcaliPhi.size() ; x++ )
00216             {
00217               if( iphi == vEcaliPhi[x] ) 
00218                 {
00219                   dMEx += ( TMath::Cos(iTower->phi())*iTower->emEt() );
00220                   dMEy += ( TMath::Sin(iTower->phi())*iTower->emEt() );
00221                 }
00222             }
00223           for( unsigned int x = 0 ; x < vHcaliPhi.size() ; x++ )
00224             {
00225               if( iphi == vHcaliPhi[x] ) 
00226                 {
00227                   dMEx += ( TMath::Cos(iTower->phi() )*iTower->hadEt() ) ;
00228                   dMEy += ( TMath::Sin(iTower->phi() )*iTower->hadEt() ) ;
00229                 }
00230             }
00231         }
00232     }
00233   
00234   TheGlobalHaloData.SetMETCorrections(dMEx, dMEy);
00235   return TheGlobalHaloData;
00236 }