Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0032 
0033 private:
0034   /// Reco Tracks used to spot the nuclear interactions
0035   edm::EDGetTokenT<reco::TrackCollection> inputTagTracks_;
0036 
0037   /// Input tag for main vertex to cut of dxy of secondary tracks
0038   edm::EDGetTokenT<reco::VertexCollection> inputTagMainVertex_;
0039   edm::EDGetTokenT<reco::BeamSpot> inputTagBeamSpot_;
0040 
0041   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0042 
0043   /// verbose ?
0044   bool verbose_;
0045 
0046   /// Displaced Vertex Candidates finder
0047   PFDisplacedVertexCandidateFinder pfDisplacedVertexCandidateFinder_;
0048 };
0049 
0050 #include "FWCore/Framework/interface/MakerMacros.h"
0051 DEFINE_FWK_MODULE(PFDisplacedVertexCandidateProducer);
0052 
0053 void PFDisplacedVertexCandidateProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0054   edm::ParameterSetDescription desc;
0055   // The track collection use for the fitting. May be any collection.
0056   // The only condition is that it shall contain the hit pattern information
0057   desc.add<edm::InputTag>("trackCollection", {"generalTracks"});
0058   // verbosity
0059   desc.addUntracked<bool>("verbose", false);
0060   // Debug flag
0061   desc.addUntracked<bool>("debug", false);
0062   // maximum dca distance for two tracks to be linked
0063   desc.add<double>("dcaCut", 0.5);
0064   // minimum distance of secondary vertex with respect to the primary
0065   desc.add<double>("primaryVertexCut", 1.8);
0066   // maximum distance between the DCA Point and the inner hit of the track
0067   // not used for the moment
0068   desc.add<double>("dcaPInnerHitCut", 1000.0);
0069   // Primary vertex information used for dxy calculation
0070   desc.add<edm::InputTag>("mainVertexLabel", {"offlinePrimaryVertices", ""});
0071   desc.add<edm::InputTag>("offlineBeamSpotLabel", {"offlineBeamSpot", ""});
0072   // Tracks preselection to reduce the combinatorics in PFDisplacedVertexCandidates
0073   // this cuts are repeated then in a smarter way in the PFDisplacedVertexFinder
0074   // be sure you are consistent between them.
0075   {
0076     edm::ParameterSetDescription pset;
0077     // selection parameters for secondary tracks
0078     pset.add<double>("nChi2_max", 5.);
0079     pset.add<double>("pt_min", 0.2);
0080     // if the tracks is not a good candidate to be a secondary (dxy cut) restrict in minimal pt
0081     // this cut reduce drastically the combinatorics. It is very useful to reduce the
0082     // PFDisplacedVertex timing
0083     pset.add<double>("pt_min_prim", 0.8);
0084     pset.add<double>("dxy", 0.2);
0085     desc.add<edm::ParameterSetDescription>("tracksSelectorParameters", pset);
0086   }
0087   descriptions.add("particleFlowDisplacedVertexCandidate", desc);
0088 }
0089 
0090 using namespace std;
0091 using namespace edm;
0092 
0093 PFDisplacedVertexCandidateProducer::PFDisplacedVertexCandidateProducer(const edm::ParameterSet& iConfig)
0094     : magneticFieldToken_(esConsumes()) {
0095   // --- Setup input collection names --- //
0096   inputTagTracks_ = consumes<reco::TrackCollection>(iConfig.getParameter<InputTag>("trackCollection"));
0097 
0098   inputTagMainVertex_ = consumes<reco::VertexCollection>(iConfig.getParameter<InputTag>("mainVertexLabel"));
0099 
0100   inputTagBeamSpot_ = consumes<reco::BeamSpot>(iConfig.getParameter<InputTag>("offlineBeamSpotLabel"));
0101 
0102   verbose_ = iConfig.getUntrackedParameter<bool>("verbose");
0103 
0104   bool debug = iConfig.getUntrackedParameter<bool>("debug");
0105 
0106   // ------ Algo Parameters ------ //
0107 
0108   // Distance of minimal approach below which
0109   // two tracks are considered as linked together
0110   double dcaCut = iConfig.getParameter<double>("dcaCut");
0111 
0112   // Do not reconstruct vertices wich are
0113   // too close to the beam pipe
0114   double primaryVertexCut = iConfig.getParameter<double>("primaryVertexCut");
0115 
0116   //maximum distance between the DCA Point and the inner hit of the track
0117   double dcaPInnerHitCut = iConfig.getParameter<double>("dcaPInnerHitCut");
0118 
0119   edm::ParameterSet ps_trk = iConfig.getParameter<edm::ParameterSet>("tracksSelectorParameters");
0120 
0121   // Collection to be produced
0122   produces<reco::PFDisplacedVertexCandidateCollection>();
0123 
0124   // Vertex Finder parameters  -----------------------------------
0125   pfDisplacedVertexCandidateFinder_.setDebug(debug);
0126   pfDisplacedVertexCandidateFinder_.setParameters(dcaCut, primaryVertexCut, dcaPInnerHitCut, ps_trk);
0127 }
0128 
0129 PFDisplacedVertexCandidateProducer::~PFDisplacedVertexCandidateProducer() {}
0130 
0131 void PFDisplacedVertexCandidateProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0132   LogDebug("PFDisplacedVertexCandidateProducer")
0133       << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
0134 
0135   // Prepare and fill useful event information for the Finder
0136   auto const& theMagField = &iSetup.getData(magneticFieldToken_);
0137 
0138   Handle<reco::TrackCollection> trackCollection;
0139   iEvent.getByToken(inputTagTracks_, trackCollection);
0140 
0141   Handle<reco::VertexCollection> mainVertexHandle;
0142   iEvent.getByToken(inputTagMainVertex_, mainVertexHandle);
0143 
0144   Handle<reco::BeamSpot> beamSpotHandle;
0145   iEvent.getByToken(inputTagBeamSpot_, beamSpotHandle);
0146 
0147   pfDisplacedVertexCandidateFinder_.setPrimaryVertex(mainVertexHandle, beamSpotHandle);
0148   pfDisplacedVertexCandidateFinder_.setInput(trackCollection, theMagField);
0149 
0150   // Run the finder
0151   pfDisplacedVertexCandidateFinder_.findDisplacedVertexCandidates();
0152 
0153   if (verbose_) {
0154     ostringstream str;
0155     str << pfDisplacedVertexCandidateFinder_ << endl;
0156     cout << pfDisplacedVertexCandidateFinder_ << endl;
0157     LogInfo("PFDisplacedVertexCandidateProducer") << str.str() << endl;
0158   }
0159 
0160   std::unique_ptr<reco::PFDisplacedVertexCandidateCollection> pOutputDisplacedVertexCandidateCollection(
0161       pfDisplacedVertexCandidateFinder_.transferVertexCandidates());
0162 
0163   iEvent.put(std::move(pOutputDisplacedVertexCandidateCollection));
0164 
0165   LogDebug("PFDisplacedVertexCandidateProducer")
0166       << "STOP event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
0167 }