Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:58

0001 /**  \class L3MuonCandidateProducerFromMuons
0002  * 
0003  *   This class takes reco::Muons and creates
0004  *   the correspondent reco::RecoChargedCandidate.
0005  *
0006  */
0007 
0008 // Framework
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 #include "RecoMuon/L3MuonProducer/src/L3MuonCandidateProducerFromMuons.h"
0017 
0018 // Input and output collections
0019 #include "DataFormats/TrackReco/interface/Track.h"
0020 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0021 
0022 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0023 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0024 
0025 #include <string>
0026 
0027 using namespace edm;
0028 using namespace std;
0029 using namespace reco;
0030 
0031 static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons");
0032 
0033 /// constructor with config
0034 L3MuonCandidateProducerFromMuons::L3MuonCandidateProducerFromMuons(const ParameterSet& parameterSet)
0035     : m_L3CollectionLabel(parameterSet.getParameter<InputTag>("InputObjects")),  // standAlone Collection Label
0036       m_muonToken(consumes(m_L3CollectionLabel)),
0037       m_displacedReco(parameterSet.getParameter<bool>("DisplacedReconstruction")) {
0038   LogTrace(category) << " constructor called";
0039   produces<RecoChargedCandidateCollection>();
0040 }
0041 
0042 /// destructor
0043 L3MuonCandidateProducerFromMuons::~L3MuonCandidateProducerFromMuons() {
0044   LogTrace(category) << " L3MuonCandidateProducerFromMuons destructor called";
0045 }
0046 
0047 void L3MuonCandidateProducerFromMuons::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0048   edm::ParameterSetDescription desc;
0049   desc.add<edm::InputTag>("InputObjects", edm::InputTag("hltL3Muons"));
0050   desc.add<bool>("DisplacedReconstruction", false);
0051   descriptions.addWithDefaultLabel(desc);
0052 }
0053 
0054 /// reconstruct muons
0055 void L3MuonCandidateProducerFromMuons::produce(StreamID, Event& event, const EventSetup& eventSetup) const {
0056   // Create a RecoChargedCandidate collection
0057   LogTrace(category) << " Creating the RecoChargedCandidate collection";
0058   auto candidates = std::make_unique<RecoChargedCandidateCollection>();
0059 
0060   // Take the L3 container
0061   LogTrace(category) << " Taking the L3/GLB muons: " << m_L3CollectionLabel.label();
0062   Handle<reco::MuonCollection> muons;
0063   event.getByToken(m_muonToken, muons);
0064 
0065   if (not muons.isValid()) {
0066     LogError(category) << muons.whyFailed()->what();
0067   } else {
0068     for (unsigned int i = 0; i < muons->size(); i++) {
0069       // avoids crashing in case the muon is SA only.
0070       TrackRef tkref;
0071       if (m_displacedReco) {
0072         tkref = (*muons)[i].isGlobalMuon() ? (*muons)[i].globalTrack() : (*muons)[i].muonBestTrack();
0073       } else {
0074         tkref = (*muons)[i].innerTrack().isNonnull() ? (*muons)[i].innerTrack() : (*muons)[i].muonBestTrack();
0075       }
0076       Particle::Charge q = tkref->charge();
0077       Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
0078       Particle::Point vtx(tkref->vx(), tkref->vy(), tkref->vz());
0079 
0080       int pid = 13;
0081       if (abs(q) == 1)
0082         pid = q < 0 ? 13 : -13;
0083       else
0084         LogWarning(category) << "L3MuonCandidate has charge = " << q;
0085       RecoChargedCandidate cand(q, p4, vtx, pid);
0086 
0087       cand.setTrack(tkref);
0088       candidates->push_back(cand);
0089     }
0090   }
0091   event.put(std::move(candidates));
0092 }