Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-14 02:28:09

0001 /**  \class L2MuonCandidateProducer
0002  * 
0003  *   Intermediate step in the L2 muons selection.
0004  *   This class takes the L2 muons (which are reco::Tracks) 
0005  *   and creates the correspondent reco::RecoChargedCandidate.
0006  *
0007  *   Riccardo's comment:
0008  *   The separation between the L2MuonProducer and this class allows
0009  *   the interchangeability of the L2MuonProducer and the StandAloneMuonProducer
0010  *   This class is supposed to be removed once the
0011  *   L2/STA comparison will be done, then the RecoChargedCandidate
0012  *   production will be done into the L2MuonProducer class.
0013  *
0014  *
0015  *   \author  J.Alcaraz
0016  */
0017 
0018 #include <string>
0019 
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0022 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0023 #include "DataFormats/TrackReco/interface/Track.h"
0024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/EventSetup.h"
0027 #include "FWCore/Framework/interface/global/EDProducer.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/InputTag.h"
0031 
0032 class L2MuonCandidateProducer : public edm::global::EDProducer<> {
0033 public:
0034   /// constructor with config
0035   L2MuonCandidateProducer(const edm::ParameterSet&);
0036 
0037   /// destructor
0038   ~L2MuonCandidateProducer() override;
0039 
0040   /// produce candidates
0041   void produce(edm::StreamID sid, edm::Event& event, const edm::EventSetup&) const override;
0042 
0043 private:
0044   // StandAlone Collection Label
0045   edm::InputTag theSACollectionLabel;
0046   edm::EDGetTokenT<reco::TrackCollection> tracksToken;
0047 };
0048 
0049 /// constructor with config
0050 L2MuonCandidateProducer::L2MuonCandidateProducer(const edm::ParameterSet& parameterSet) {
0051   LogTrace("Muon|RecoMuon|L2MuonCandidateProducer") << " constructor called";
0052 
0053   // StandAlone Collection Label
0054   theSACollectionLabel = parameterSet.getParameter<edm::InputTag>("InputObjects");
0055   tracksToken = consumes<reco::TrackCollection>(theSACollectionLabel);
0056   produces<reco::RecoChargedCandidateCollection>();
0057 }
0058 
0059 /// destructor
0060 L2MuonCandidateProducer::~L2MuonCandidateProducer() {
0061   LogTrace("Muon|RecoMuon|L2MuonCandidateProducer") << " L2MuonCandidateProducer destructor called";
0062 }
0063 
0064 /// reconstruct muons
0065 void L2MuonCandidateProducer::produce(edm::StreamID sid, edm::Event& event, const edm::EventSetup& eventSetup) const {
0066   const std::string metname = "Muon|RecoMuon|L2MuonCandidateProducer";
0067 
0068   // Take the SA container
0069   LogTrace(metname) << " Taking the StandAlone muons: " << theSACollectionLabel;
0070   edm::Handle<reco::TrackCollection> tracks;
0071   event.getByToken(tracksToken, tracks);
0072 
0073   // Create a RecoChargedCandidate collection
0074   LogTrace(metname) << " Creating the RecoChargedCandidate collection";
0075   auto candidates = std::make_unique<reco::RecoChargedCandidateCollection>();
0076 
0077   for (unsigned int i = 0; i < tracks->size(); i++) {
0078     reco::TrackRef tkref(tracks, i);
0079     reco::Particle::Charge q = tkref->charge();
0080     reco::Particle::LorentzVector p4(tkref->px(), tkref->py(), tkref->pz(), tkref->p());
0081     reco::Particle::Point vtx(tkref->vx(), tkref->vy(), tkref->vz());
0082     int pid = 13;
0083     if (abs(q) == 1)
0084       pid = q < 0 ? 13 : -13;
0085     else
0086       edm::LogWarning(metname) << "L2MuonCandidate has charge = " << q;
0087     reco::RecoChargedCandidate cand(q, p4, vtx, pid);
0088     cand.setTrack(tkref);
0089     candidates->push_back(cand);
0090   }
0091 
0092   event.put(std::move(candidates));
0093 
0094   LogTrace(metname) << " Event loaded"
0095                     << "================================";
0096 }
0097 
0098 // declare as a framework plugin
0099 #include "FWCore/Framework/interface/MakerMacros.h"
0100 DEFINE_FWK_MODULE(L2MuonCandidateProducer);