Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h"
0002 #include "DataFormats/TrackReco/interface/Track.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/stream/EDProducer.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "MagneticField/Engine/interface/MagneticField.h"
0008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0009 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
0010 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0011 
0012 class LightPFTrackProducer : public edm::stream::EDProducer<> {
0013 public:
0014   ///Constructor
0015   explicit LightPFTrackProducer(const edm::ParameterSet&);
0016 
0017   ///Destructor
0018   ~LightPFTrackProducer() override;
0019 
0020 private:
0021   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0022   void endRun(const edm::Run&, const edm::EventSetup&) override;
0023 
0024   ///Produce the PFRecTrack collection
0025   void produce(edm::Event&, const edm::EventSetup&) override;
0026 
0027   ///PFTrackTransformer
0028   PFTrackTransformer* pfTransformer_;
0029   std::vector<edm::EDGetTokenT<reco::TrackCollection> > tracksContainers_;
0030 
0031   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0032   ///TRACK QUALITY
0033   bool useQuality_;
0034   reco::TrackBase::TrackQuality trackQuality_;
0035 };
0036 
0037 #include "FWCore/Framework/interface/MakerMacros.h"
0038 DEFINE_FWK_MODULE(LightPFTrackProducer);
0039 
0040 using namespace std;
0041 using namespace edm;
0042 LightPFTrackProducer::LightPFTrackProducer(const ParameterSet& iConfig)
0043     : pfTransformer_(nullptr), magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()) {
0044   produces<reco::PFRecTrackCollection>();
0045 
0046   std::vector<InputTag> tags = iConfig.getParameter<vector<InputTag> >("TkColList");
0047 
0048   for (unsigned int i = 0; i < tags.size(); ++i)
0049     tracksContainers_.push_back(consumes<reco::TrackCollection>(tags[i]));
0050 
0051   useQuality_ = iConfig.getParameter<bool>("UseQuality");
0052   trackQuality_ = reco::TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"));
0053 }
0054 
0055 LightPFTrackProducer::~LightPFTrackProducer() { delete pfTransformer_; }
0056 
0057 void LightPFTrackProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0058   //create the empty collections
0059   auto PfTrColl = std::make_unique<reco::PFRecTrackCollection>();
0060 
0061   for (unsigned int istr = 0; istr < tracksContainers_.size(); istr++) {
0062     //Track collection
0063     Handle<reco::TrackCollection> tkRefCollection;
0064     iEvent.getByToken(tracksContainers_[istr], tkRefCollection);
0065     reco::TrackCollection Tk = *(tkRefCollection.product());
0066     for (unsigned int i = 0; i < Tk.size(); i++) {
0067       if (useQuality_ && (!(Tk[i].quality(trackQuality_))))
0068         continue;
0069       reco::TrackRef trackRef(tkRefCollection, i);
0070       reco::PFRecTrack pftrack(trackRef->charge(), reco::PFRecTrack::KF, i, trackRef);
0071       Trajectory FakeTraj;
0072       bool mymsgwarning = false;
0073       bool valid = pfTransformer_->addPoints(pftrack, *trackRef, FakeTraj, mymsgwarning);
0074       if (valid)
0075         PfTrColl->push_back(pftrack);
0076     }
0077   }
0078   iEvent.put(std::move(PfTrColl));
0079 }
0080 
0081 // ------------ method called once each job just before starting event loop  ------------
0082 void LightPFTrackProducer::beginRun(const edm::Run& run, const EventSetup& iSetup) {
0083   auto const& magneticField = &iSetup.getData(magneticFieldToken_);
0084   pfTransformer_ = new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0, 0, 0))));
0085   pfTransformer_->OnlyProp();
0086 }
0087 
0088 // ------------ method called once each job just after ending the event loop  ------------
0089 void LightPFTrackProducer::endRun(const edm::Run& run, const EventSetup& iSetup) {
0090   delete pfTransformer_;
0091   pfTransformer_ = nullptr;
0092 }