CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/RecoParticleFlow/PFTracking/plugins/LightPFTrackProducer.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include "RecoParticleFlow/PFTracking/interface/LightPFTrackProducer.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 "TrackingTools/PatternTools/interface/Trajectory.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "MagneticField/Engine/interface/MagneticField.h"
00011 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00012 
00013 using namespace std;
00014 using namespace edm;
00015 LightPFTrackProducer::LightPFTrackProducer(const ParameterSet& iConfig):
00016   pfTransformer_(0)
00017 {
00018   produces<reco::PFRecTrackCollection>();
00019 
00020   tracksContainers_ = 
00021     iConfig.getParameter< vector < InputTag > >("TkColList");
00022 
00023 
00024   useQuality_   = iConfig.getParameter<bool>("UseQuality");
00025   trackQuality_=reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"));
00026 
00027 }
00028 
00029 LightPFTrackProducer::~LightPFTrackProducer()
00030 {
00031   delete pfTransformer_;
00032 }
00033 
00034 void
00035 LightPFTrackProducer::produce(Event& iEvent, const EventSetup& iSetup)
00036 {
00037 
00038   //create the empty collections 
00039   auto_ptr< reco::PFRecTrackCollection > 
00040     PfTrColl (new reco::PFRecTrackCollection);
00041   
00042   for (unsigned int istr=0; istr<tracksContainers_.size();istr++){
00043     
00044     //Track collection
00045     Handle<reco::TrackCollection> tkRefCollection;
00046     iEvent.getByLabel(tracksContainers_[istr], tkRefCollection);
00047     reco::TrackCollection  Tk=*(tkRefCollection.product());
00048     for(unsigned int i=0;i<Tk.size();i++){
00049       if (useQuality_ &&
00050           (!(Tk[i].quality(trackQuality_)))) continue;
00051      reco::TrackRef trackRef(tkRefCollection, i);
00052       reco::PFRecTrack pftrack( trackRef->charge(), 
00053                                 reco::PFRecTrack::KF, 
00054                                 i, trackRef );
00055       Trajectory FakeTraj;
00056       bool valid = pfTransformer_->addPoints( pftrack, *trackRef, FakeTraj);
00057       if(valid)
00058         PfTrColl->push_back(pftrack);           
00059 
00060     }
00061   }
00062   iEvent.put(PfTrColl);
00063 }
00064 
00065 // ------------ method called once each job just before starting event loop  ------------
00066 void 
00067 LightPFTrackProducer::beginRun(edm::Run& run,
00068                                const EventSetup& iSetup)
00069 {
00070   ESHandle<MagneticField> magneticField;
00071   iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
00072   pfTransformer_= new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0))));
00073   pfTransformer_->OnlyProp();
00074 }
00075 
00076 // ------------ method called once each job just after ending the event loop  ------------
00077 void 
00078 LightPFTrackProducer::endRun() {
00079   delete pfTransformer_;
00080 }