CMS 3D CMS Logo

Public Member Functions | Private Attributes

CaloMuonMerger Class Reference

Merges reco::CaloMuons, reco::Muons and optionally reco::Tracks avoiding innerTrack duplications in a single reco::Muon collection. More...

#include "RecoMuon/MuonIdentification/plugins/CaloMuonMerger.cc"

Inheritance diagram for CaloMuonMerger:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 CaloMuonMerger (const edm::ParameterSet &iConfig)
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual ~CaloMuonMerger ()

Private Attributes

edm::InputTag caloMuons_
StringCutObjectSelector
< reco::CaloMuon, false > 
caloMuonsCut_
bool mergeCaloMuons_
bool mergeTracks_
double minCaloCompatibility_
edm::InputTag muons_
StringCutObjectSelector
< reco::Muon, false > 
muonsCut_
edm::InputTag tracks_
StringCutObjectSelector
< reco::TrackRef, false > 
tracksCut_

Detailed Description

Merges reco::CaloMuons, reco::Muons and optionally reco::Tracks avoiding innerTrack duplications in a single reco::Muon collection.

Author:
Giovanni Petrucciani
Version:
Id:
CaloMuonMerger.cc,v 1.6 2011/01/06 13:26:53 gpetrucc Exp

Definition at line 25 of file CaloMuonMerger.cc.


Constructor & Destructor Documentation

CaloMuonMerger::CaloMuonMerger ( const edm::ParameterSet iConfig) [explicit]

Definition at line 45 of file CaloMuonMerger.cc.

                                                              :
    muons_(iConfig.getParameter<edm::InputTag>("muons")),
    muonsCut_(iConfig.existsAs<std::string>("muonsCut") ? iConfig.getParameter<std::string>("muonsCut") : ""),
    mergeCaloMuons_(iConfig.existsAs<bool>("mergeCaloMuons") ? iConfig.getParameter<bool>("mergeCaloMuons") : true),
    caloMuons_(iConfig.getParameter<edm::InputTag>("caloMuons")),
    caloMuonsCut_(iConfig.existsAs<std::string>("caloMuonsCut") ? iConfig.getParameter<std::string>("caloMuonsCut") : ""),
    minCaloCompatibility_(mergeCaloMuons_ ? iConfig.getParameter<double>("minCaloCompatibility") : 0),
    mergeTracks_(iConfig.existsAs<bool>("mergeTracks") ? iConfig.getParameter<bool>("mergeTracks") : false),
    tracks_(mergeTracks_ ? iConfig.getParameter<edm::InputTag>("tracks") : edm::InputTag()),
    tracksCut_(iConfig.existsAs<std::string>("tracksCut") ? iConfig.getParameter<std::string>("tracksCut") : "")
{
    produces<std::vector<reco::Muon> >();
}
virtual CaloMuonMerger::~CaloMuonMerger ( ) [inline, virtual]

Definition at line 28 of file CaloMuonMerger.cc.

{ }

Member Function Documentation

void CaloMuonMerger::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 60 of file CaloMuonMerger.cc.

References reco::Muon::caloCompatibility(), reco::Muon::CaloMuon, caloMuons_, caloMuonsCut_, relval_parameters_module::energy, reco::LeafCandidate::eta(), Exception, edm::Event::getByLabel(), i, reco::Muon::isCaloCompatibilityValid(), reco::isMuon(), mergeCaloMuons_, mergeTracks_, minCaloCompatibility_, metsig::muon, ExpressReco_HICollisions_FallBack::muons, muons_, muonsCut_, dbtoconf::out, p4, reco::LeafCandidate::pt(), edm::Event::put(), reco::Muon::setCalEnergy(), reco::Muon::setCaloCompatibility(), reco::Muon::setInnerTrack(), reco::Muon::setType(), mathSSE::sqrt(), reco::Muon::track(), ExpressReco_HICollisions_FallBack::track, testEve_cfg::tracks, tracks_, tracksCut_, and reco::Muon::type().

                                                                       {
    edm::Handle<std::vector<reco::Muon> > muons;
    edm::Handle<std::vector<reco::CaloMuon> > caloMuons;
    edm::Handle<std::vector<reco::Track> > tracks;

    iEvent.getByLabel(muons_, muons);
    if(mergeCaloMuons_) iEvent.getByLabel(caloMuons_, caloMuons);
    if(mergeTracks_) iEvent.getByLabel(tracks_, tracks);

    std::auto_ptr<std::vector<reco::Muon> >  out(new std::vector<reco::Muon>());
    out->reserve(muons->size() + (mergeTracks_?tracks->size():0));

    // copy reco::Muons, turning on the CaloCompatibility flag if enabled and possible
    for (std::vector<reco::Muon>::const_iterator it = muons->begin(), ed = muons->end(); it != ed; ++it) {
        if(!muonsCut_(*it)) continue;
        out->push_back(*it);
        reco::Muon & mu = out->back();
        if (mergeCaloMuons_ && mu.track().isNonnull()) {
            if (mu.isCaloCompatibilityValid()) {
                if (mu.caloCompatibility() >= minCaloCompatibility_) {
                    mu.setType(mu.type() | reco::Muon::CaloMuon);
                }
            } else throw cms::Exception("Boh") << "Muon with track and no CaloCompatibility; pt = " << mu.pt() << ", eta = " << mu.eta() << ", type = " << mu.type() << "\n";
        }
    }

    if (mergeCaloMuons_) {
        // copy reco::CaloMuon 
        for (std::vector<reco::CaloMuon>::const_iterator it = caloMuons->begin(), ed = caloMuons->end(); it != ed; ++it) {
            if(!caloMuonsCut_(*it)) continue;
            // make a reco::Muon
            reco::TrackRef track = it->track();
            double energy = sqrt(track->p() * track->p() + 0.011163691);
            math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
            out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
            reco::Muon & mu = out->back();
            // fill info 
            mu.setCalEnergy( it->calEnergy() );
            mu.setCaloCompatibility( it->caloCompatibility() );
            mu.setInnerTrack( track );
            mu.setType( reco::Muon::CaloMuon );
        }
    }

    // merge reco::Track avoiding duplication of innerTracks
    if(mergeTracks_){
        for (size_t i = 0; i < tracks->size(); i++) {
            reco::TrackRef track(tracks, i);
            if(!tracksCut_(track)) continue;
            // check if it is a muon or calomuon
            bool isMuon = false;
            for(std::vector<reco::Muon>::const_iterator muon = muons->begin(); muon < muons->end(); muon++){
                if(muon->innerTrack() == track){
                    isMuon = true;
                    break;
                }
            }
            if(isMuon) continue;
            if (mergeCaloMuons_) {
                bool isCaloMuon = false;
                for(std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon < caloMuons->end(); muon++){
                    if(muon->innerTrack() == track){
                        isCaloMuon = true;
                        break;
                    }
                }
                if(isCaloMuon) continue;
            }
            // make a reco::Muon
            double energy = sqrt(track->p() * track->p() + 0.011163691);
            math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
            out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
            reco::Muon & mu = out->back();
            // fill info 
            mu.setInnerTrack( track );
        }
    }

    iEvent.put(out);
}

Member Data Documentation

Definition at line 36 of file CaloMuonMerger.cc.

Referenced by produce().

Definition at line 37 of file CaloMuonMerger.cc.

Referenced by produce().

Definition at line 35 of file CaloMuonMerger.cc.

Referenced by produce().

Definition at line 39 of file CaloMuonMerger.cc.

Referenced by produce().

Definition at line 38 of file CaloMuonMerger.cc.

Referenced by produce().

Definition at line 33 of file CaloMuonMerger.cc.

Referenced by produce().

Definition at line 34 of file CaloMuonMerger.cc.

Referenced by produce().

Definition at line 40 of file CaloMuonMerger.cc.

Referenced by produce().

Definition at line 41 of file CaloMuonMerger.cc.

Referenced by produce().