Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-16 03:20:14

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   ///Constructor
0014   explicit PFDisplacedTrackerVertexProducer(const edm::ParameterSet&);
0015 
0016   ///Destructor
0017   ~PFDisplacedTrackerVertexProducer() override;
0018 
0019 private:
0020   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0021   void endRun(const edm::Run&, const edm::EventSetup&) override;
0022 
0023   ///Produce the PFRecTrack collection
0024   void produce(edm::Event&, const edm::EventSetup&) override;
0025 
0026   ///PFTrackTransformer
0027   PFTrackTransformer* pfTransformer_;
0028   edm::EDGetTokenT<reco::PFDisplacedVertexCollection> pfDisplacedVertexContainer_;
0029   edm::EDGetTokenT<reco::TrackCollection> pfTrackContainer_;
0030 
0031   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0032 };
0033 
0034 #include "FWCore/Framework/interface/MakerMacros.h"
0035 DEFINE_FWK_MODULE(PFDisplacedTrackerVertexProducer);
0036 
0037 using namespace std;
0038 using namespace edm;
0039 PFDisplacedTrackerVertexProducer::PFDisplacedTrackerVertexProducer(const ParameterSet& iConfig)
0040     : pfTransformer_(nullptr), magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()) {
0041   produces<reco::PFRecTrackCollection>();
0042   produces<reco::PFDisplacedTrackerVertexCollection>();
0043 
0044   pfDisplacedVertexContainer_ =
0045       consumes<reco::PFDisplacedVertexCollection>(iConfig.getParameter<InputTag>("displacedTrackerVertexColl"));
0046 
0047   pfTrackContainer_ = consumes<reco::TrackCollection>(iConfig.getParameter<InputTag>("trackColl"));
0048 }
0049 
0050 PFDisplacedTrackerVertexProducer::~PFDisplacedTrackerVertexProducer() { delete pfTransformer_; }
0051 
0052 void PFDisplacedTrackerVertexProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0053   //create the empty collections
0054   auto pfDisplacedTrackerVertexColl = std::make_unique<reco::PFDisplacedTrackerVertexCollection>();
0055   auto pfRecTrackColl = std::make_unique<reco::PFRecTrackCollection>();
0056 
0057   reco::PFRecTrackRefProd pfTrackRefProd = iEvent.getRefBeforePut<reco::PFRecTrackCollection>();
0058 
0059   Handle<reco::PFDisplacedVertexCollection> nuclCollH;
0060   iEvent.getByToken(pfDisplacedVertexContainer_, nuclCollH);
0061   const reco::PFDisplacedVertexCollection& nuclColl = *(nuclCollH.product());
0062 
0063   Handle<reco::TrackCollection> trackColl;
0064   iEvent.getByToken(pfTrackContainer_, trackColl);
0065 
0066   int idx = 0;
0067 
0068   //  cout << "Size of Displaced Vertices "
0069   //     <<  nuclColl.size() << endl;
0070 
0071   // loop on all NuclearInteraction
0072   for (unsigned int icoll = 0; icoll < nuclColl.size(); icoll++) {
0073     reco::PFRecTrackRefVector pfRecTkcoll;
0074 
0075     std::vector<reco::Track> refittedTracks = nuclColl[icoll].refittedTracks();
0076 
0077     // convert the secondary tracks
0078     for (unsigned it = 0; it < refittedTracks.size(); it++) {
0079       reco::TrackBaseRef trackBaseRef = nuclColl[icoll].originalTrack(refittedTracks[it]);
0080 
0081       //      cout << "track base pt = " << trackBaseRef->pt() << endl;
0082 
0083       reco::TrackRef trackRef(trackColl, trackBaseRef.key());
0084 
0085       //      cout << "track pt = " << trackRef->pt() << endl;
0086 
0087       reco::PFRecTrack pfRecTrack(trackBaseRef->charge(), reco::PFRecTrack::KF, trackBaseRef.key(), trackRef);
0088 
0089       // cout << pfRecTrack << endl;
0090 
0091       Trajectory FakeTraj;
0092       bool valid = pfTransformer_->addPoints(pfRecTrack, *trackBaseRef, FakeTraj);
0093       if (valid) {
0094         pfRecTkcoll.push_back(reco::PFRecTrackRef(pfTrackRefProd, idx++));
0095         pfRecTrackColl->push_back(pfRecTrack);
0096         //  cout << "after "<< pfRecTrack << endl;
0097       }
0098     }
0099     reco::PFDisplacedVertexRef niRef(nuclCollH, icoll);
0100     pfDisplacedTrackerVertexColl->push_back(reco::PFDisplacedTrackerVertex(niRef, pfRecTkcoll));
0101   }
0102 
0103   iEvent.put(std::move(pfRecTrackColl));
0104   iEvent.put(std::move(pfDisplacedTrackerVertexColl));
0105 }
0106 
0107 // ------------ method called once each job just before starting event loop  ------------
0108 void PFDisplacedTrackerVertexProducer::beginRun(const edm::Run& run, const EventSetup& iSetup) {
0109   auto const& magneticField = &iSetup.getData(magneticFieldToken_);
0110   pfTransformer_ = new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0, 0, 0))));
0111   pfTransformer_->OnlyProp();
0112 }
0113 
0114 // ------------ method called once each job just after ending the event loop  ------------
0115 void PFDisplacedTrackerVertexProducer::endRun(const edm::Run& run, const EventSetup& iSetup) {
0116   delete pfTransformer_;
0117   pfTransformer_ = nullptr;
0118 }