Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /**\class PFDisplacedVertexCandidateProducer 
0002 \brief Producer for DisplacedVertices 
0003 
0004 This producer makes use of DisplacedVertexCandidateFinder. This Finder
0005 loop recursively over reco::Tracks to find those which are linked 
0006 together by the criterion which is by default the minimal approach distance. 
0007 
0008 \author Maxime Gouzevitch
0009 \date   November 2009
0010 */
0011 
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/stream/EDProducer.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/FileInPath.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/Utilities/interface/Exception.h"
0020 #include "MagneticField/Engine/interface/MagneticField.h"
0021 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0022 #include "RecoParticleFlow/PFTracking/interface/PFDisplacedVertexCandidateFinder.h"
0023 
0024 class PFDisplacedVertexCandidateProducer : public edm::stream::EDProducer<> {
0025 public:
0026   explicit PFDisplacedVertexCandidateProducer(const edm::ParameterSet&);
0027 
0028   ~PFDisplacedVertexCandidateProducer() override;
0029 
0030   void produce(edm::Event&, const edm::EventSetup&) override;
0031 
0032 private:
0033   /// Reco Tracks used to spot the nuclear interactions
0034   edm::EDGetTokenT<reco::TrackCollection> inputTagTracks_;
0035 
0036   /// Input tag for main vertex to cut of dxy of secondary tracks
0037   edm::EDGetTokenT<reco::VertexCollection> inputTagMainVertex_;
0038   edm::EDGetTokenT<reco::BeamSpot> inputTagBeamSpot_;
0039 
0040   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0041 
0042   /// verbose ?
0043   bool verbose_;
0044 
0045   /// Displaced Vertex Candidates finder
0046   PFDisplacedVertexCandidateFinder pfDisplacedVertexCandidateFinder_;
0047 };
0048 
0049 #include "FWCore/Framework/interface/MakerMacros.h"
0050 DEFINE_FWK_MODULE(PFDisplacedVertexCandidateProducer);
0051 
0052 using namespace std;
0053 using namespace edm;
0054 
0055 PFDisplacedVertexCandidateProducer::PFDisplacedVertexCandidateProducer(const edm::ParameterSet& iConfig)
0056     : magneticFieldToken_(esConsumes()) {
0057   // --- Setup input collection names --- //
0058   inputTagTracks_ = consumes<reco::TrackCollection>(iConfig.getParameter<InputTag>("trackCollection"));
0059 
0060   inputTagMainVertex_ = consumes<reco::VertexCollection>(iConfig.getParameter<InputTag>("mainVertexLabel"));
0061 
0062   inputTagBeamSpot_ = consumes<reco::BeamSpot>(iConfig.getParameter<InputTag>("offlineBeamSpotLabel"));
0063 
0064   verbose_ = iConfig.getUntrackedParameter<bool>("verbose");
0065 
0066   bool debug = iConfig.getUntrackedParameter<bool>("debug");
0067 
0068   // ------ Algo Parameters ------ //
0069 
0070   // Distance of minimal approach below which
0071   // two tracks are considered as linked together
0072   double dcaCut = iConfig.getParameter<double>("dcaCut");
0073 
0074   // Do not reconstruct vertices wich are
0075   // too close to the beam pipe
0076   double primaryVertexCut = iConfig.getParameter<double>("primaryVertexCut");
0077 
0078   //maximum distance between the DCA Point and the inner hit of the track
0079   double dcaPInnerHitCut = iConfig.getParameter<double>("dcaPInnerHitCut");
0080 
0081   edm::ParameterSet ps_trk = iConfig.getParameter<edm::ParameterSet>("tracksSelectorParameters");
0082 
0083   // Collection to be produced
0084   produces<reco::PFDisplacedVertexCandidateCollection>();
0085 
0086   // Vertex Finder parameters  -----------------------------------
0087   pfDisplacedVertexCandidateFinder_.setDebug(debug);
0088   pfDisplacedVertexCandidateFinder_.setParameters(dcaCut, primaryVertexCut, dcaPInnerHitCut, ps_trk);
0089 }
0090 
0091 PFDisplacedVertexCandidateProducer::~PFDisplacedVertexCandidateProducer() {}
0092 
0093 void PFDisplacedVertexCandidateProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0094   LogDebug("PFDisplacedVertexCandidateProducer")
0095       << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
0096 
0097   // Prepare and fill useful event information for the Finder
0098   auto const& theMagField = &iSetup.getData(magneticFieldToken_);
0099 
0100   Handle<reco::TrackCollection> trackCollection;
0101   iEvent.getByToken(inputTagTracks_, trackCollection);
0102 
0103   Handle<reco::VertexCollection> mainVertexHandle;
0104   iEvent.getByToken(inputTagMainVertex_, mainVertexHandle);
0105 
0106   Handle<reco::BeamSpot> beamSpotHandle;
0107   iEvent.getByToken(inputTagBeamSpot_, beamSpotHandle);
0108 
0109   pfDisplacedVertexCandidateFinder_.setPrimaryVertex(mainVertexHandle, beamSpotHandle);
0110   pfDisplacedVertexCandidateFinder_.setInput(trackCollection, theMagField);
0111 
0112   // Run the finder
0113   pfDisplacedVertexCandidateFinder_.findDisplacedVertexCandidates();
0114 
0115   if (verbose_) {
0116     ostringstream str;
0117     str << pfDisplacedVertexCandidateFinder_ << endl;
0118     cout << pfDisplacedVertexCandidateFinder_ << endl;
0119     LogInfo("PFDisplacedVertexCandidateProducer") << str.str() << endl;
0120   }
0121 
0122   std::unique_ptr<reco::PFDisplacedVertexCandidateCollection> pOutputDisplacedVertexCandidateCollection(
0123       pfDisplacedVertexCandidateFinder_.transferVertexCandidates());
0124 
0125   iEvent.put(std::move(pOutputDisplacedVertexCandidateCollection));
0126 
0127   LogDebug("PFDisplacedVertexCandidateProducer")
0128       << "STOP event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
0129 }