CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoJets/JetProducers/src/JetMuonHitsIDHelper.cc

Go to the documentation of this file.
00001 #include "RecoJets/JetProducers/interface/JetMuonHitsIDHelper.h"
00002 
00003 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include "DataFormats/JetReco/interface/JetTracksAssociation.h"
00007 #include "TrackingTools/TrackAssociator/interface/MuonDetIdAssociator.h"
00008 #include "TrackingTools/TrackAssociator/interface/DetIdAssociator.h"
00009 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
00010 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00011 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
00012 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00013 #include "DataFormats/JetReco/interface/CaloJet.h"
00014 #include "DataFormats/TrackReco/interface/Track.h"
00015 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00016 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00017 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00018 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00019 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00020 #include "DataFormats/MuonReco/interface/Muon.h"
00021 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00022 #include "DataFormats/Math/interface/deltaR.h"
00023 
00024 #include "TMath.h"
00025 #include <vector>
00026 #include <iostream>
00027 
00028 using namespace std;
00029 
00030 
00031 reco::helper::JetMuonHitsIDHelper::JetMuonHitsIDHelper( edm::ParameterSet const & pset )
00032 {
00033   isRECO_ = true; // This will be "true" initially, then if the product isn't found, set to false once
00034   numberOfHits1RPC_ = 0;
00035   numberOfHits2RPC_ = 0;
00036   numberOfHits3RPC_ = 0;
00037   numberOfHits4RPC_ = 0;
00038   numberOfHitsRPC_ = 0;
00039   rpcRecHits_ = pset.getParameter<edm::InputTag>("rpcRecHits");
00040  
00041 }
00042 
00043 
00044 
00045 
00046 void reco::helper::JetMuonHitsIDHelper::calculate( const edm::Event& event, const edm::EventSetup & iSetup, 
00047                                                    const reco::Jet &jet, const int iDbg )
00048 {
00049 
00050   // initialize
00051   numberOfHits1RPC_ = 0;
00052   numberOfHits2RPC_ = 0;
00053   numberOfHits3RPC_ = 0;
00054   numberOfHits4RPC_ = 0;
00055   numberOfHitsRPC_ = 0;
00056 
00057 
00058   if ( isRECO_ ) { // This will be "true" initially, then if the product isn't found, set to false once
00059 
00060     // Get tracking geometry
00061     edm::ESHandle<GlobalTrackingGeometry> trackingGeometry;
00062     iSetup.get<GlobalTrackingGeometryRecord> ().get(trackingGeometry);
00063     
00064     //####READ RPC RecHits Collection########
00065     //#In config: RpcRecHits     = cms.InputTag("rpcRecHits")
00066     edm::Handle<RPCRecHitCollection> rpcRecHits_handle;
00067     event.getByLabel(rpcRecHits_, rpcRecHits_handle);
00068 
00069 
00070     if ( ! rpcRecHits_handle.isValid()  ) {
00071       // don't throw exception if not running on RECO
00072       edm::LogWarning("DataNotAvailable") << "JetMuonHitsIDHelper will not be run at all, this is not a RECO file.";
00073       isRECO_ = false;
00074       return;
00075     }
00076 
00077     //####calculate rpc  variables for each jet########
00078     
00079     for (  RPCRecHitCollection::const_iterator itRPC = rpcRecHits_handle->begin(),
00080              itRPCBegin = rpcRecHits_handle->begin(),
00081              itRPCEnd = rpcRecHits_handle->end();
00082            itRPC != itRPCEnd; ++itRPC) {
00083       RPCRecHit const & hit = *itRPC;
00084       DetId detid = hit.geographicalId();
00085       LocalPoint lp = hit.localPosition();
00086       const GeomDet* gd = trackingGeometry->idToDet(detid);
00087       GlobalPoint gp = gd->toGlobal(lp);
00088       double dR2 = reco::deltaR(jet.eta(), jet.phi(), 
00089                                 static_cast<double>( gp.eta() ), static_cast<double>(gp.phi()) );
00090       if (dR2 < 0.5) {
00091         RPCDetId rpcChamberId = (RPCDetId) detid;
00092         numberOfHitsRPC_++;
00093         if (rpcChamberId.station() == 1)
00094           numberOfHits1RPC_++;
00095         if (rpcChamberId.station() == 2)
00096           numberOfHits2RPC_++;
00097         if (rpcChamberId.station() == 3)
00098           numberOfHits3RPC_++;
00099         if (rpcChamberId.station() == 4)
00100           numberOfHits4RPC_++;
00101       }
00102     }
00103   }
00104 }