Go to the documentation of this file.00001 #include "RecoMuon/L3MuonProducer/src/QuarkoniaTrackSelector.h"
00002
00003 #include "FWCore/Framework/interface/Frameworkfwd.h"
00004
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/MakerMacros.h"
00007 #include "DataFormats/Common/interface/Handle.h"
00008
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00011
00012 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00013 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00014 #include "DataFormats/TrackReco/interface/Track.h"
00015 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00016
00017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00018
00019 #include <memory>
00020 #include <iostream>
00021 #include <sstream>
00022
00023 QuarkoniaTrackSelector::QuarkoniaTrackSelector(const edm::ParameterSet& iConfig) :
00024 muonTag_(iConfig.getParameter<edm::InputTag>("muonCandidates")),
00025 trackTag_(iConfig.getParameter<edm::InputTag>("tracks")),
00026 minMasses_(iConfig.getParameter< std::vector<double> >("MinMasses")),
00027 maxMasses_(iConfig.getParameter< std::vector<double> >("MaxMasses")),
00028 checkCharge_(iConfig.getParameter<bool>("checkCharge")),
00029 minTrackPt_(iConfig.getParameter<double>("MinTrackPt")),
00030 minTrackP_(iConfig.getParameter<double>("MinTrackP")),
00031 maxTrackEta_(iConfig.getParameter<double>("MaxTrackEta"))
00032 {
00033
00034 produces<reco::TrackCollection>();
00035
00036
00037
00038 bool massesValid = minMasses_.size()==maxMasses_.size();
00039 if ( massesValid ) {
00040 for ( size_t i=0; i<minMasses_.size(); ++i ) {
00041 if ( minMasses_[i]<0 || maxMasses_[i]<0 ||
00042 minMasses_[i]>maxMasses_[i] ) massesValid = false;
00043 }
00044 }
00045 if ( !massesValid ) {
00046 edm::LogError("QuarkoniaTrackSelector") << "Inconsistency in definition of mass windows, "
00047 << "no track will be selected";
00048 minMasses_.clear();
00049 maxMasses_.clear();
00050 }
00051
00052 std::ostringstream stream;
00053 stream << "instantiated with parameters\n"
00054 << " muonTag = " << muonTag_ << "\n"
00055 << " trackTag = " << trackTag_ << "\n";
00056 stream << " mass windows =";
00057 for ( size_t i=0; i<minMasses_.size(); ++i )
00058 stream << " (" << minMasses_[i] << "," << maxMasses_[i] << ")";
00059 stream << "\n";
00060 stream << " checkCharge = " << checkCharge_ << "\n";
00061 stream << " MinTrackPt = " << minTrackPt_ << "\n";
00062 stream << " MinTrackP = " << minTrackP_ << "\n";
00063 stream << " MaxTrackEta = " << maxTrackEta_;
00064 LogDebug("QuarkoniaTrackSelector") << stream.str();
00065 }
00066
00067
00068 void
00069 QuarkoniaTrackSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00070 {
00071
00072
00073
00074 std::auto_ptr<reco::TrackCollection> product(new reco::TrackCollection);
00075
00076
00077
00078 edm::Handle<reco::RecoChargedCandidateCollection> muonHandle;
00079 iEvent.getByLabel(muonTag_,muonHandle);
00080
00081
00082
00083 edm::Handle<reco::TrackCollection> trackHandle;
00084 iEvent.getByLabel(trackTag_,trackHandle);
00085
00086
00087
00088 if ( !muonHandle.isValid() || !trackHandle.isValid() || minMasses_.empty() ) {
00089 iEvent.put(product);
00090 return;
00091 }
00092
00093
00094
00095 if ( edm::isDebugEnabled() ) {
00096 std::ostringstream stream;
00097 stream << "\nInput muons: # / q / pt / p / eta\n";
00098 for ( size_t im=0; im<muonHandle->size(); ++im ) {
00099 const reco::RecoChargedCandidate& muon = (*muonHandle)[im];
00100 stream << " " << im << " "
00101 << muon.charge() << " " << muon.pt() << " "
00102 << muon.p() << " " << muon.eta() << "\n";
00103 }
00104 stream << "Input tracks: # / q / pt / p / eta\n";
00105 for ( size_t it=0; it<trackHandle->size(); ++it ) {
00106 const reco::Track& track = (*trackHandle)[it];
00107 stream << " " << it << " "
00108 << track.charge() << " " << track.pt() << " "
00109 << track.p() << " " << track.eta() << "\n";
00110 }
00111 LogDebug("QuarkoniaTrackSelector") << stream.str();
00112 }
00113
00114
00115
00116
00117 unsigned int nQ(0);
00118 unsigned int nComb(0);
00119 std::vector<size_t> selectedTrackIndices;
00120 selectedTrackIndices.reserve(muonHandle->size());
00121 reco::Particle::LorentzVector p4Muon;
00122 reco::Particle::LorentzVector p4JPsi;
00123
00124 for ( size_t im=0; im<muonHandle->size(); ++im ) {
00125 const reco::RecoChargedCandidate& muon = (*muonHandle)[im];
00126 int qMuon = muon.charge();
00127 p4Muon = muon.p4();
00128
00129 for ( size_t it=0; it<trackHandle->size(); ++it ) {
00130 const reco::Track& track = (*trackHandle)[it];
00131 if ( track.pt()<minTrackPt_ || track.p()<minTrackP_ ||
00132 fabs(track.eta())>maxTrackEta_ ) continue;
00133 if ( checkCharge_ && track.charge()!=-qMuon ) continue;
00134 ++nQ;
00135 reco::Particle::LorentzVector p4Track(track.px(),track.py(),track.pz(),
00136 sqrt(track.p()*track.p()+0.0111636));
00137
00138 double mass = (p4Muon+p4Track).mass();
00139
00140
00141
00142 for ( size_t j=0; j<minMasses_.size(); ++j ) {
00143 if ( mass>minMasses_[j] && mass<maxMasses_[j] ) {
00144 ++nComb;
00145 if ( find(selectedTrackIndices.begin(),selectedTrackIndices.end(),it)==
00146 selectedTrackIndices.end() ) selectedTrackIndices.push_back(it);
00147
00148 break;
00149 }
00150 }
00151 }
00152 }
00153
00154
00155
00156
00157 for ( size_t i=0; i<selectedTrackIndices.size(); ++i )
00158 product->push_back((*trackHandle)[selectedTrackIndices[i]]);
00159
00160
00161
00162 if ( edm::isDebugEnabled() ) {
00163 std::ostringstream stream;
00164 stream << "Total number of combinations = " << muonHandle->size()*trackHandle->size()
00165 << " , after charge " << nQ << " , after mass " << nComb << std::endl;
00166 stream << "Selected " << product->size() << " tracks with # / q / pt / eta\n";
00167 for ( size_t i=0; i<product->size(); ++i ) {
00168 const reco::Track& track = (*product)[i];
00169 stream << " " << i << " " << track.charge() << " "
00170 << track.pt() << " " << track.eta() << "\n";
00171 }
00172 LogDebug("QuarkoniaTrackSelector") << stream.str();
00173 }
00174
00175 iEvent.put(product);
00176 }
00177
00178
00179
00180 DEFINE_FWK_MODULE(QuarkoniaTrackSelector);