Go to the documentation of this file.00001
00018
00019 #include "FWCore/Framework/interface/EDProducer.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/EventSetup.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "DataFormats/Common/interface/Handle.h"
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025
00026 #include "RecoMuon/L3MuonProducer/src/L3MuonCandidateProducer.h"
00027
00028 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00029 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00030 #include "DataFormats/Math/interface/deltaR.h"
00031
00032
00033 #include "DataFormats/TrackReco/interface/Track.h"
00034 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00035 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00036 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00037
00038 #include <string>
00039 #include <algorithm>
00040
00041 using namespace edm;
00042 using namespace std;
00043 using namespace reco;
00044
00045 static const char category[] = "Muon|RecoMuon|L3MuonCandidateProducer";
00046
00048 L3MuonCandidateProducer::L3MuonCandidateProducer(const ParameterSet& parameterSet){
00049 LogTrace(category)<<" constructor called";
00050
00051
00052 theL3CollectionLabel = parameterSet.getParameter<InputTag>("InputObjects");
00053
00054
00055 theUseLinks = parameterSet.existsAs<InputTag>("InputLinksObjects");
00056 if (theUseLinks) {
00057 theL3LinksLabel = parameterSet.getParameter<InputTag>("InputLinksObjects");
00058 if (theL3LinksLabel.label() == "" or theL3LinksLabel.label() == "unused")
00059 theUseLinks = false;
00060 }
00061
00062
00063 const std::string & muon_track_for_momentum = parameterSet.existsAs<std::string>("MuonPtOption") ? parameterSet.getParameter<std::string>("MuonPtOption") : "Global";
00064 if (muon_track_for_momentum == std::string("Tracker"))
00065 theType=InnerTrack;
00066 else if (muon_track_for_momentum == std::string("Standalone"))
00067 theType=OuterTrack;
00068 else if (muon_track_for_momentum == std::string("Global"))
00069 theType=CombinedTrack;
00070 else {
00071 LogError(category)<<"invalid value for MuonPtOption, please choose among 'Tracker', 'Standalone', 'Global'";
00072 theType=CombinedTrack;
00073 }
00074
00075 produces<RecoChargedCandidateCollection>();
00076 }
00077
00079 L3MuonCandidateProducer::~L3MuonCandidateProducer(){
00080 LogTrace(category)<<" L3MuonCandidateProducer destructor called";
00081 }
00082
00083
00085 void L3MuonCandidateProducer::produce(Event& event, const EventSetup& eventSetup){
00086
00087 LogTrace(category)<<" Taking the L3/GLB muons: "<<theL3CollectionLabel.label();
00088 Handle<TrackCollection> tracks;
00089 event.getByLabel(theL3CollectionLabel,tracks);
00090
00091 edm::Handle<reco::MuonTrackLinksCollection> links;
00092 if (theUseLinks)
00093 event.getByLabel(theL3LinksLabel, links);
00094
00095
00096 LogTrace(category)<<" Creating the RecoChargedCandidate collection";
00097 auto_ptr<RecoChargedCandidateCollection> candidates( new RecoChargedCandidateCollection());
00098 LogDebug(category) << " size = " << tracks->size();
00099 for (unsigned int i=0; i<tracks->size(); i++) {
00100 TrackRef inRef(tracks,i);
00101 TrackRef tkRef = TrackRef();
00102
00103 if (theUseLinks) {
00104 for(reco::MuonTrackLinksCollection::const_iterator link = links->begin();
00105 link != links->end(); ++link){ LogDebug(category) << " i = " << i;
00106
00107 if (not link->trackerTrack().isNull()) LogTrace(category) << " link tk pt " << link->trackerTrack()->pt();
00108 if (not link->standAloneTrack().isNull()) LogTrace(category) << " sta pt " << link->standAloneTrack()->pt();
00109 if (not link->globalTrack().isNull()) LogTrace(category) << " global pt " << link->globalTrack()->pt();
00110 if (not inRef.isNull()) LogTrace(category) << " inRef pt " << inRef->pt();
00111
00112 if (link->globalTrack().isNull()) {
00113 edm::LogError(category) << "null reference to the global track";
00114
00115 continue;
00116 }
00117
00118 float dR = deltaR(inRef->eta(),inRef->phi(),link->globalTrack()->eta(),link->globalTrack()->phi());
00119 float dPt = abs(inRef->pt() - link->globalTrack()->pt())/inRef->pt();
00120 if (dR < 0.02 and dPt < 0.001) {
00121 LogTrace(category) << " *** pt matches *** ";
00122 switch(theType) {
00123 case InnerTrack: tkRef = link->trackerTrack(); break;
00124 case OuterTrack: tkRef = link->standAloneTrack(); break;
00125 case CombinedTrack: tkRef = link->globalTrack(); break;
00126 default: tkRef = link->globalTrack(); break;
00127 }
00128 }
00129 }
00130 if (tkRef.isNull()) {
00131 edm::LogWarning(category) << "null reference to the linked track, reverting to old behaviour";
00132 tkRef = inRef;
00133 }
00134 } else {
00135
00136 tkRef = inRef;
00137 }
00138 LogDebug(category) << "tkRef Used For Momentum pt " << tkRef->pt() << " inRef from the input collection pt " << inRef->pt();
00139
00140 Particle::Charge q = tkRef->charge();
00141 Particle::LorentzVector p4(tkRef->px(), tkRef->py(), tkRef->pz(), tkRef->p());
00142 Particle::Point vtx(tkRef->vx(),tkRef->vy(), tkRef->vz());
00143
00144 int pid = 13;
00145 if(abs(q)==1) pid = q < 0 ? 13 : -13;
00146 else LogWarning(category) << "L3MuonCandidate has charge = "<<q;
00147 RecoChargedCandidate cand(q, p4, vtx, pid);
00148
00149
00150
00151 cand.setTrack(inRef);
00152 candidates->push_back(cand);
00153 }
00154
00155 event.put(candidates);
00156
00157 LogTrace(category)<<" Event loaded"
00158 <<"================================";
00159 }
00160