Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 private:
0022   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0023   void endRun(const edm::Run&, const edm::EventSetup&) override;
0024 
0025   ///Produce the PFRecTrack collection
0026   void produce(edm::Event&, const edm::EventSetup&) override;
0027 
0028   ///PFTrackTransformer
0029   PFTrackTransformer* pfTransformer_;
0030   std::vector<edm::EDGetTokenT<reco::VertexCompositeCandidateCollection> > V0list_;
0031 
0032   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0033 };
0034 
0035 #include "FWCore/Framework/interface/MakerMacros.h"
0036 DEFINE_FWK_MODULE(PFV0Producer);
0037 
0038 using namespace std;
0039 using namespace edm;
0040 using namespace reco;
0041 PFV0Producer::PFV0Producer(const ParameterSet& iConfig)
0042     : pfTransformer_(nullptr), magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()) {
0043   produces<reco::PFV0Collection>();
0044   produces<reco::PFRecTrackCollection>();
0045 
0046   std::vector<edm::InputTag> tags = iConfig.getParameter<vector<InputTag> >("V0List");
0047 
0048   for (unsigned int i = 0; i < tags.size(); ++i)
0049     V0list_.push_back(consumes<reco::VertexCompositeCandidateCollection>(tags[i]));
0050 }
0051 
0052 PFV0Producer::~PFV0Producer() { delete pfTransformer_; }
0053 
0054 void PFV0Producer::produce(Event& iEvent, const EventSetup& iSetup) {
0055   LogDebug("PFV0Producer") << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run();
0056   //create the empty collections
0057   auto pfV0Coll = std::make_unique<PFV0Collection>();
0058 
0059   auto pfV0RecTrackColl = std::make_unique<reco::PFRecTrackCollection>();
0060 
0061   reco::PFRecTrackRefProd pfTrackRefProd = iEvent.getRefBeforePut<reco::PFRecTrackCollection>();
0062   int idx = 0;
0063 
0064   for (unsigned int il = 0; il < V0list_.size(); il++) {
0065     Handle<VertexCompositeCandidateCollection> V0coll;
0066     iEvent.getByToken(V0list_[il], V0coll);
0067     LogDebug("PFV0Producer") << "V0list_[" << il << "] contains " << V0coll->size() << " V0 candidates ";
0068     for (unsigned int iv = 0; iv < V0coll->size(); iv++) {
0069       VertexCompositeCandidateRef V0(V0coll, iv);
0070       vector<TrackRef> Tracks;
0071       vector<PFRecTrackRef> PFTracks;
0072       for (unsigned int ndx = 0; ndx < V0->numberOfDaughters(); ndx++) {
0073         Tracks.push_back((dynamic_cast<const RecoChargedCandidate*>(V0->daughter(ndx)))->track());
0074         TrackRef trackRef = (dynamic_cast<const RecoChargedCandidate*>(V0->daughter(ndx)))->track();
0075 
0076         reco::PFRecTrack pfRecTrack(trackRef->charge(), reco::PFRecTrack::KF, trackRef.key(), trackRef);
0077 
0078         Trajectory FakeTraj;
0079         bool valid = pfTransformer_->addPoints(pfRecTrack, *trackRef, FakeTraj);
0080         if (valid) {
0081           PFTracks.push_back(reco::PFRecTrackRef(pfTrackRefProd, idx++));
0082           pfV0RecTrackColl->push_back(pfRecTrack);
0083         }
0084       }
0085       if ((PFTracks.size() == 2) && (Tracks.size() == 2)) {
0086         pfV0Coll->push_back(PFV0(V0, PFTracks, Tracks));
0087       }
0088     }
0089   }
0090 
0091   iEvent.put(std::move(pfV0Coll));
0092   iEvent.put(std::move(pfV0RecTrackColl));
0093 }
0094 
0095 // ------------ method called once each job just before starting event loop  ------------
0096 void PFV0Producer::beginRun(const edm::Run& run, const EventSetup& iSetup) {
0097   auto const& magneticField = &iSetup.getData(magneticFieldToken_);
0098   pfTransformer_ = new PFTrackTransformer(math::XYZVector(magneticField->inTesla(GlobalPoint(0, 0, 0))));
0099   pfTransformer_->OnlyProp();
0100 }
0101 
0102 // ------------ method called once each job just after ending the event loop  ------------
0103 void PFV0Producer::endRun(const edm::Run& run, const EventSetup& iSetup) {
0104   delete pfTransformer_;
0105   pfTransformer_ = nullptr;
0106 }