CMS 3D CMS Logo

CaloMuonProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    CaloMuonProducer
00004 // Class:      CaloMuonProducer
00005 // 
00013 //
00014 // Original Author:  Dmytro Kovalskyi
00015 //         Created:  Wed Oct  3 16:29:03 CDT 2007
00016 // $Id: CaloMuonProducer.cc,v 1.3 2008/08/07 02:36:44 dmytro Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 
00033 #include "DataFormats/MuonReco/interface/Muon.h"
00034 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00035 #include "DataFormats/MuonReco/interface/CaloMuon.h"
00036 #include "RecoMuon/MuonIdentification/plugins/CaloMuonProducer.h"
00037 
00038 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00039 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00040 
00041 CaloMuonProducer::CaloMuonProducer(const edm::ParameterSet& iConfig)
00042 {
00043    produces<reco::CaloMuonCollection>();
00044    inputMuons_ = iConfig.getParameter<edm::InputTag>("inputMuons");
00045    inputTracks_ = iConfig.getParameter<edm::InputTag>("inputTracks");
00046    caloCut_ = iConfig.getParameter<double>("minCaloCompatibility");
00047 
00048    // Load TrackDetectorAssociator parameters
00049    edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
00050    parameters_.loadParameters( parameters );
00051    
00052    // Load MuonCaloCompatibility parameters
00053    parameters = iConfig.getParameter<edm::ParameterSet>("MuonCaloCompatibility");
00054    muonCaloCompatibility_.configure( parameters );
00055 }
00056 
00057 CaloMuonProducer::~CaloMuonProducer()
00058 {
00059 }
00060 
00061 reco::CaloMuon CaloMuonProducer::makeMuon( const edm::Event& iEvent, const edm::EventSetup& iSetup,
00062                                            const reco::TrackRef& track )
00063 {
00064    reco::CaloMuon aMuon;
00065    aMuon.setTrack( track );
00066    
00067    // propagation and association
00068    TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup, *(track.get()), parameters_);
00069    
00070    // energy
00071    reco::MuonEnergy muonEnergy;
00072    muonEnergy.em  = info.crossedEnergy(TrackDetMatchInfo::EcalRecHits);
00073    muonEnergy.had = info.crossedEnergy(TrackDetMatchInfo::HcalRecHits);
00074    muonEnergy.ho  = info.crossedEnergy(TrackDetMatchInfo::HORecHits);
00075    muonEnergy.emS9  = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits,1); // 3x3 energy
00076    muonEnergy.hadS9 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits,1); // 3x3 energy
00077    muonEnergy.hoS9  = info.nXnEnergy(TrackDetMatchInfo::HORecHits,1);   // 3x3 energy
00078    aMuon.setCalEnergy( muonEnergy );
00079    
00080    // make a temporary reco::Muon to evaluate calo compatibility
00081    double energy = sqrt(track->p() * track->p() + 0.011163691);
00082    math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
00083    reco::Muon tmpMuon( track->charge(), p4, track->vertex() );
00084    tmpMuon.setCalEnergy( aMuon.calEnergy() );
00085    tmpMuon.setInnerTrack( aMuon.track() );
00086    
00087    // get calo compatibility
00088    aMuon.setCaloCompatibility( muonCaloCompatibility_.evaluate(tmpMuon) );
00089    return aMuon;
00090 }
00091 
00092 
00093 void CaloMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00094 {
00095    using namespace edm;
00096    Handle<reco::MuonCollection> muons;
00097    iEvent.getByLabel(inputMuons_,muons);
00098    Handle<reco::TrackCollection> tracks;
00099    iEvent.getByLabel(inputTracks_,tracks);
00100 
00101    std::auto_ptr<reco::CaloMuonCollection> caloMuons( new reco::CaloMuonCollection );
00102    
00103    edm::ESHandle<Propagator> propagator;
00104    iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
00105    trackAssociator_.setPropagator(propagator.product());
00106    
00107    unsigned int i = 0;
00108    for ( reco::TrackCollection::const_iterator track = tracks->begin();
00109          track != tracks->end(); ++track, ++i )
00110      {
00111         bool usedTrack = false;
00112         if ( muons.isValid() )
00113           for ( reco::MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon )
00114             if ( muon->track().get() == &*track )
00115               {
00116                  usedTrack = true;
00117                  break;
00118               }
00119         if ( usedTrack ) continue;
00120         reco::CaloMuon caloMuon( makeMuon( iEvent, iSetup, reco::TrackRef( tracks, i ) ) );
00121         if ( ! caloMuon.isCaloCompatibilityValid() || caloMuon.caloCompatibility() < caloCut_ ) continue;
00122         caloMuons->push_back( caloMuon );
00123      }
00124    iEvent.put(caloMuons);
00125 }
00126 
00127 //define this as a plug-in
00128 DEFINE_FWK_MODULE(CaloMuonProducer);

Generated on Tue Jun 9 17:44:18 2009 for CMSSW by  doxygen 1.5.4