Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-22 02:24:10

0001 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
0002 #include "DataFormats/ParticleFlowReco/interface/PFV0.h"
0003 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/stream/EDProducer.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "MagneticField/Engine/interface/MagneticField.h"
0009 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0010 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
0011 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0012 
0013 class PFV0Producer : public edm::stream::EDProducer<> {
0014 public:
0015   ///Constructor
0016   explicit PFV0Producer(const edm::ParameterSet&);
0017 
0018   ///Destructor
0019   ~PFV0Producer() override;
0020 
0021   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0022 
0023 private:
0024   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0025   void endRun(const edm::Run&, const edm::EventSetup&) override;
0026 
0027   ///Produce the PFRecTrack collection
0028   void produce(edm::Event&, const edm::EventSetup&) override;
0029 
0030   ///PFTrackTransformer
0031   PFTrackTransformer* pfTransformer_;
0032   std::vector<edm::EDGetTokenT<reco::VertexCompositeCandidateCollection>> V0list_;
0033 
0034   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0035 };
0036 
0037 #include "FWCore/Framework/interface/MakerMacros.h"
0038 DEFINE_FWK_MODULE(PFV0Producer);
0039 
0040 void PFV0Producer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0041   edm::ParameterSetDescription desc;
0042   desc.add<std::vector<edm::InputTag>>(
0043       "V0List", {edm::InputTag("generalV0Candidates", "Kshort"), edm::InputTag("generalV0Candidates", "Lambda")});
0044   descriptions.add("pfV0", desc);
0045 }
0046 
0047 using namespace std;
0048 using namespace edm;
0049 using namespace reco;
0050 PFV0Producer::PFV0Producer(const ParameterSet& iConfig)
0051     : pfTransformer_(nullptr), magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()) {
0052   produces<reco::PFV0Collection>();
0053   produces<reco::PFRecTrackCollection>();
0054 
0055   std::vector<edm::InputTag> tags = iConfig.getParameter<vector<InputTag>>("V0List");
0056 
0057   for (unsigned int i = 0; i < tags.size(); ++i)
0058     V0list_.push_back(consumes<reco::VertexCompositeCandidateCollection>(tags[i]));
0059 }
0060 
0061 PFV0Producer::~PFV0Producer() { delete pfTransformer_; }
0062 
0063 void PFV0Producer::produce(Event& iEvent, const EventSetup& iSetup) {
0064   LogDebug("PFV0Producer") << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run();
0065   //create the empty collections
0066   auto pfV0Coll = std::make_unique<PFV0Collection>();
0067 
0068   auto pfV0RecTrackColl = std::make_unique<reco::PFRecTrackCollection>();
0069 
0070   reco::PFRecTrackRefProd pfTrackRefProd = iEvent.getRefBeforePut<reco::PFRecTrackCollection>();
0071   int idx = 0;
0072 
0073   for (unsigned int il = 0; il < V0list_.size(); il++) {
0074     Handle<VertexCompositeCandidateCollection> V0coll;
0075     iEvent.getByToken(V0list_[il], V0coll);
0076     LogDebug("PFV0Producer") << "V0list_[" << il << "] contains " << V0coll->size() << " V0 candidates ";
0077     for (unsigned int iv = 0; iv < V0coll->size(); iv++) {
0078       VertexCompositeCandidateRef V0(V0coll, iv);
0079       vector<TrackRef> Tracks;
0080       vector<PFRecTrackRef> PFTracks;
0081       for (unsigned int ndx = 0; ndx < V0->numberOfDaughters(); ndx++) {
0082         Tracks.push_back((dynamic_cast<const RecoChargedCandidate*>(V0->daughter(ndx)))->track());
0083         TrackRef trackRef = (dynamic_cast<const RecoChargedCandidate*>(V0->daughter(ndx)))->track();
0084 
0085         reco::PFRecTrack pfRecTrack(trackRef->charge(), reco::PFRecTrack::KF, trackRef.key(), trackRef);
0086 
0087         Trajectory FakeTraj;
0088         bool valid = pfTransformer_->addPoints(pfRecTrack, *trackRef, FakeTraj);
0089         if (valid) {
0090           PFTracks.push_back(reco::PFRecTrackRef(pfTrackRefProd, idx++));
0091           pfV0RecTrackColl->push_back(pfRecTrack);
0092         }
0093       }
0094       if ((PFTracks.size() == 2) && (Tracks.size() == 2)) {
0095         pfV0Coll->push_back(PFV0(V0, PFTracks, Tracks));
0096       }
0097     }
0098   }
0099 
0100   iEvent.put(std::move(pfV0Coll));
0101   iEvent.put(std::move(pfV0RecTrackColl));
0102 }
0103 
0104 // ------------ method called once each job just before starting event loop  ------------
0105 void PFV0Producer::beginRun(const edm::Run& run, const EventSetup& iSetup) {
0106   auto const& magneticField = &iSetup.getData(magneticFieldToken_);
0107   pfTransformer_ = new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0, 0, 0))));
0108   pfTransformer_->OnlyProp();
0109 }
0110 
0111 // ------------ method called once each job just after ending the event loop  ------------
0112 void PFV0Producer::endRun(const edm::Run& run, const EventSetup& iSetup) {
0113   delete pfTransformer_;
0114   pfTransformer_ = nullptr;
0115 }