File indexing completed on 2024-06-22 02:24:09
0001 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedTrackerVertex.h"
0002 #include "FWCore/Framework/interface/ESHandle.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/stream/EDProducer.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "MagneticField/Engine/interface/MagneticField.h"
0007 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0008 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
0009 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0010
0011 class PFDisplacedTrackerVertexProducer : public edm::stream::EDProducer<> {
0012 public:
0013
0014 explicit PFDisplacedTrackerVertexProducer(const edm::ParameterSet&);
0015
0016
0017 ~PFDisplacedTrackerVertexProducer() override;
0018
0019 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020
0021 private:
0022 void beginRun(const edm::Run&, const edm::EventSetup&) override;
0023 void endRun(const edm::Run&, const edm::EventSetup&) override;
0024
0025
0026 void produce(edm::Event&, const edm::EventSetup&) override;
0027
0028
0029 PFTrackTransformer* pfTransformer_;
0030 edm::EDGetTokenT<reco::PFDisplacedVertexCollection> pfDisplacedVertexContainer_;
0031 edm::EDGetTokenT<reco::TrackCollection> pfTrackContainer_;
0032
0033 const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0034 };
0035
0036 #include "FWCore/Framework/interface/MakerMacros.h"
0037 DEFINE_FWK_MODULE(PFDisplacedTrackerVertexProducer);
0038
0039 void PFDisplacedTrackerVertexProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0040 edm::ParameterSetDescription desc;
0041 desc.add<edm::InputTag>("displacedTrackerVertexColl", {"particleFlowDisplacedVertex"});
0042 desc.add<edm::InputTag>("trackColl", {"generalTracks"});
0043 descriptions.add("pfDisplacedTrackerVertex", desc);
0044 }
0045
0046 using namespace std;
0047 using namespace edm;
0048 PFDisplacedTrackerVertexProducer::PFDisplacedTrackerVertexProducer(const ParameterSet& iConfig)
0049 : pfTransformer_(nullptr), magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()) {
0050 produces<reco::PFRecTrackCollection>();
0051 produces<reco::PFDisplacedTrackerVertexCollection>();
0052
0053 pfDisplacedVertexContainer_ =
0054 consumes<reco::PFDisplacedVertexCollection>(iConfig.getParameter<InputTag>("displacedTrackerVertexColl"));
0055
0056 pfTrackContainer_ = consumes<reco::TrackCollection>(iConfig.getParameter<InputTag>("trackColl"));
0057 }
0058
0059 PFDisplacedTrackerVertexProducer::~PFDisplacedTrackerVertexProducer() { delete pfTransformer_; }
0060
0061 void PFDisplacedTrackerVertexProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0062
0063 auto pfDisplacedTrackerVertexColl = std::make_unique<reco::PFDisplacedTrackerVertexCollection>();
0064 auto pfRecTrackColl = std::make_unique<reco::PFRecTrackCollection>();
0065
0066 reco::PFRecTrackRefProd pfTrackRefProd = iEvent.getRefBeforePut<reco::PFRecTrackCollection>();
0067
0068 Handle<reco::PFDisplacedVertexCollection> nuclCollH;
0069 iEvent.getByToken(pfDisplacedVertexContainer_, nuclCollH);
0070 const reco::PFDisplacedVertexCollection& nuclColl = *(nuclCollH.product());
0071
0072 Handle<reco::TrackCollection> trackColl;
0073 iEvent.getByToken(pfTrackContainer_, trackColl);
0074
0075 int idx = 0;
0076
0077
0078
0079
0080
0081 for (unsigned int icoll = 0; icoll < nuclColl.size(); icoll++) {
0082 reco::PFRecTrackRefVector pfRecTkcoll;
0083
0084 std::vector<reco::Track> refittedTracks = nuclColl[icoll].refittedTracks();
0085
0086
0087 for (unsigned it = 0; it < refittedTracks.size(); it++) {
0088 reco::TrackBaseRef trackBaseRef = nuclColl[icoll].originalTrack(refittedTracks[it]);
0089
0090
0091
0092 reco::TrackRef trackRef(trackColl, trackBaseRef.key());
0093
0094
0095
0096 reco::PFRecTrack pfRecTrack(trackBaseRef->charge(), reco::PFRecTrack::KF, trackBaseRef.key(), trackRef);
0097
0098
0099
0100 Trajectory FakeTraj;
0101 bool valid = pfTransformer_->addPoints(pfRecTrack, *trackBaseRef, FakeTraj);
0102 if (valid) {
0103 pfRecTkcoll.push_back(reco::PFRecTrackRef(pfTrackRefProd, idx++));
0104 pfRecTrackColl->push_back(pfRecTrack);
0105
0106 }
0107 }
0108 reco::PFDisplacedVertexRef niRef(nuclCollH, icoll);
0109 pfDisplacedTrackerVertexColl->push_back(reco::PFDisplacedTrackerVertex(niRef, pfRecTkcoll));
0110 }
0111
0112 iEvent.put(std::move(pfRecTrackColl));
0113 iEvent.put(std::move(pfDisplacedTrackerVertexColl));
0114 }
0115
0116
0117 void PFDisplacedTrackerVertexProducer::beginRun(const edm::Run& run, const EventSetup& iSetup) {
0118 auto const& magneticField = &iSetup.getData(magneticFieldToken_);
0119 pfTransformer_ = new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0, 0, 0))));
0120 pfTransformer_->OnlyProp();
0121 }
0122
0123
0124 void PFDisplacedTrackerVertexProducer::endRun(const edm::Run& run, const EventSetup& iSetup) {
0125 delete pfTransformer_;
0126 pfTransformer_ = nullptr;
0127 }