Go to the documentation of this file.00001 #include <memory>
00002 #include "RecoParticleFlow/PFTracking/interface/PFTrackProducer.h"
00003 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
00004 #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h"
00005 #include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h"
00006 #include "DataFormats/TrackReco/interface/Track.h"
00007 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00008 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00009 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
00010 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
00011 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
00012 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "MagneticField/Engine/interface/MagneticField.h"
00015 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00016 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00017 #include "DataFormats/MuonReco/interface/Muon.h"
00018
00019
00020 using namespace std;
00021 using namespace edm;
00022 using namespace reco;
00023 PFTrackProducer::PFTrackProducer(const ParameterSet& iConfig):
00024 pfTransformer_(0)
00025 {
00026 produces<reco::PFRecTrackCollection>();
00027
00028 tracksContainers_ =
00029 iConfig.getParameter< vector < InputTag > >("TkColList");
00030
00031 useQuality_ = iConfig.getParameter<bool>("UseQuality");
00032
00033 gsfTrackLabel_ = iConfig.getParameter<InputTag>
00034 ("GsfTrackModuleLabel");
00035
00036 trackQuality_=reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"));
00037
00038 muonColl_ = iConfig.getParameter< InputTag >("MuColl");
00039
00040 trajinev_ = iConfig.getParameter<bool>("TrajInEvents");
00041
00042 gsfinev_ = iConfig.getParameter<bool>("GsfTracksInEvents");
00043
00044 }
00045
00046 PFTrackProducer::~PFTrackProducer()
00047 {
00048 delete pfTransformer_;
00049 }
00050
00051 void
00052 PFTrackProducer::produce(Event& iEvent, const EventSetup& iSetup)
00053 {
00054
00055
00056 auto_ptr< reco::PFRecTrackCollection >
00057 PfTrColl (new reco::PFRecTrackCollection);
00058
00059
00060 Handle<GsfTrackCollection> gsftrackcoll;
00061 bool foundgsf = iEvent.getByLabel(gsfTrackLabel_,gsftrackcoll);
00062 GsfTrackCollection gsftracks;
00063 if(gsfinev_) {
00064 if(!foundgsf )
00065 LogError("PFTrackProducer")
00066 <<" cannot get GsfTracks (probably in HI events): "
00067 << " please set GsfTracksInEvents = False in RecoParticleFlow/PFTracking/python/pfTrack_cfi.py" << endl;
00068 else
00069 gsftracks = *(gsftrackcoll.product());
00070 }
00071
00072
00073 Handle< reco::MuonCollection > recMuons;
00074 iEvent.getByLabel(muonColl_, recMuons);
00075
00076
00077 for (unsigned int istr=0; istr<tracksContainers_.size();istr++){
00078
00079
00080 Handle<reco::TrackCollection> tkRefCollection;
00081 iEvent.getByLabel(tracksContainers_[istr], tkRefCollection);
00082 reco::TrackCollection Tk=*(tkRefCollection.product());
00083
00084 vector<Trajectory> Tj(0);
00085 if(trajinev_) {
00086
00087 Handle<vector<Trajectory> > tjCollection;
00088 bool found = iEvent.getByLabel(tracksContainers_[istr], tjCollection);
00089 if(!found )
00090 LogError("PFTrackProducer")
00091 <<" cannot get Trajectories of: "
00092 << tracksContainers_[istr]
00093 << " please set TrajInEvents = False in RecoParticleFlow/PFTracking/python/pfTrack_cfi.py" << endl;
00094
00095 Tj =*(tjCollection.product());
00096 }
00097
00098
00099 for(unsigned int i=0;i<Tk.size();i++){
00100
00101 reco::TrackRef trackRef(tkRefCollection, i);
00102
00103 if (useQuality_ &&
00104 (!(Tk[i].quality(trackQuality_)))){
00105
00106 bool isMuCandidate = false;
00107
00108
00109
00110 if(recMuons.isValid() ) {
00111 for(unsigned j=0;j<recMuons->size(); j++) {
00112 reco::MuonRef muonref( recMuons, j );
00113 if (muonref->track().isNonnull())
00114 if( muonref->track() == trackRef && muonref->isGlobalMuon()){
00115 isMuCandidate=true;
00116
00117 break;
00118 }
00119 }
00120 }
00121
00122 if(!isMuCandidate){
00123 continue;
00124 }
00125
00126 }
00127
00128
00129
00130 bool preId = false;
00131 if(foundgsf) {
00132 for (unsigned int igsf=0; igsf<gsftracks.size();igsf++) {
00133 GsfTrackRef gsfTrackRef(gsftrackcoll, igsf);
00134 if (gsfTrackRef->seedRef().isNull()) continue;
00135 ElectronSeedRef ElSeedRef= gsfTrackRef->extra()->seedRef().castTo<ElectronSeedRef>();
00136 if (ElSeedRef->ctfTrack().isNonnull()) {
00137 if(ElSeedRef->ctfTrack() == trackRef) preId = true;
00138 }
00139 }
00140 }
00141 if(preId) {
00142
00143 reco::PFRecTrack pftrack( trackRef->charge(),
00144 reco::PFRecTrack::KF_ELCAND,
00145 i, trackRef );
00146
00147 bool valid = false;
00148 if(trajinev_) {
00149 valid = pfTransformer_->addPoints( pftrack, *trackRef, Tj[i]);
00150 }
00151 else {
00152 Trajectory FakeTraj;
00153 valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
00154 }
00155 if(valid) {
00156 PfTrColl->push_back(pftrack);
00157 }
00158
00159 }
00160 else {
00161 reco::PFRecTrack pftrack( trackRef->charge(),
00162 reco::PFRecTrack::KF,
00163 i, trackRef );
00164 bool valid = false;
00165 if(trajinev_) {
00166 valid = pfTransformer_->addPoints( pftrack, *trackRef, Tj[i]);
00167 }
00168 else {
00169 Trajectory FakeTraj;
00170 valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
00171 }
00172
00173 if(valid) {
00174 PfTrColl->push_back(pftrack);
00175 }
00176 }
00177 }
00178 }
00179 iEvent.put(PfTrColl);
00180 }
00181
00182
00183 void
00184 PFTrackProducer::beginRun(edm::Run& run,
00185 const EventSetup& iSetup)
00186 {
00187 ESHandle<MagneticField> magneticField;
00188 iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
00189 pfTransformer_= new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0))));
00190 if(!trajinev_)
00191 pfTransformer_->OnlyProp();
00192 }
00193
00194
00195 void
00196 PFTrackProducer::endRun() {
00197 delete pfTransformer_;
00198 }