Go to the documentation of this file.00001 #include <memory>
00002 #include "RecoParticleFlow/PFTracking/plugins/PFDisplacedTrackerVertexProducer.h"
00003 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
00004 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedTrackerVertex.h"
00005 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "MagneticField/Engine/interface/MagneticField.h"
00008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00009 using namespace std;
00010 using namespace edm;
00011 PFDisplacedTrackerVertexProducer::PFDisplacedTrackerVertexProducer(const ParameterSet& iConfig):
00012 pfTransformer_(0)
00013 {
00014 produces<reco::PFRecTrackCollection>();
00015 produces<reco::PFDisplacedTrackerVertexCollection>();
00016
00017 pfDisplacedVertexContainer_ =
00018 iConfig.getParameter< InputTag >("displacedTrackerVertexColl");
00019
00020 pfTrackContainer_ =
00021 iConfig.getParameter< InputTag >("trackColl");
00022
00023 }
00024
00025 PFDisplacedTrackerVertexProducer::~PFDisplacedTrackerVertexProducer()
00026 {
00027 delete pfTransformer_;
00028 }
00029
00030 void
00031 PFDisplacedTrackerVertexProducer::produce(Event& iEvent, const EventSetup& iSetup)
00032 {
00033
00034
00035 auto_ptr< reco::PFDisplacedTrackerVertexCollection >
00036 pfDisplacedTrackerVertexColl (new reco::PFDisplacedTrackerVertexCollection);
00037 auto_ptr< reco::PFRecTrackCollection >
00038 pfRecTrackColl (new reco::PFRecTrackCollection);
00039
00040 reco::PFRecTrackRefProd pfTrackRefProd = iEvent.getRefBeforePut<reco::PFRecTrackCollection>();
00041
00042
00043
00044 Handle<reco::PFDisplacedVertexCollection> nuclCollH;
00045 iEvent.getByLabel(pfDisplacedVertexContainer_, nuclCollH);
00046 const reco::PFDisplacedVertexCollection& nuclColl = *(nuclCollH.product());
00047
00048 Handle<reco::TrackCollection> trackColl;
00049 iEvent.getByLabel(pfTrackContainer_, trackColl);
00050
00051 int idx = 0;
00052
00053
00054
00055
00056
00057 for( unsigned int icoll=0; icoll < nuclColl.size(); icoll++) {
00058
00059 reco::PFRecTrackRefVector pfRecTkcoll;
00060
00061 std::vector<reco::Track> refittedTracks = nuclColl[icoll].refittedTracks();
00062
00063
00064 for(unsigned it = 0; it < refittedTracks.size(); it++){
00065
00066 reco::TrackBaseRef trackBaseRef = nuclColl[icoll].originalTrack(refittedTracks[it]);
00067
00068
00069
00070 reco::TrackRef trackRef(trackColl, trackBaseRef.key());
00071
00072
00073
00074
00075 reco::PFRecTrack pfRecTrack( trackBaseRef->charge(),
00076 reco::PFRecTrack::KF,
00077 trackBaseRef.key(),
00078 trackRef );
00079
00080
00081
00082 Trajectory FakeTraj;
00083 bool valid = pfTransformer_->addPoints( pfRecTrack, *trackBaseRef, FakeTraj);
00084 if(valid) {
00085 pfRecTkcoll.push_back(reco::PFRecTrackRef( pfTrackRefProd, idx++));
00086 pfRecTrackColl->push_back(pfRecTrack);
00087
00088
00089 }
00090 }
00091 reco::PFDisplacedVertexRef niRef(nuclCollH, icoll);
00092 pfDisplacedTrackerVertexColl->push_back( reco::PFDisplacedTrackerVertex( niRef, pfRecTkcoll ));
00093 }
00094
00095 iEvent.put(pfRecTrackColl);
00096 iEvent.put(pfDisplacedTrackerVertexColl);
00097 }
00098
00099
00100 void
00101 PFDisplacedTrackerVertexProducer::beginRun(edm::Run& run,
00102 const EventSetup& iSetup)
00103 {
00104 ESHandle<MagneticField> magneticField;
00105 iSetup.get<IdealMagneticFieldRecord>().get(magneticField);
00106 pfTransformer_= new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0,0,0))));
00107 pfTransformer_->OnlyProp();
00108 }
00109
00110
00111 void
00112 PFDisplacedTrackerVertexProducer::endRun() {
00113 delete pfTransformer_;
00114 }