Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-28 22:48:48

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     pset.add<double>("qoverpError_max", 1.0e+7);
0086 
0087     desc.add<edm::ParameterSetDescription>("tracksSelectorParameters", pset);
0088   }
0089   descriptions.add("particleFlowDisplacedVertexCandidate", desc);
0090 }
0091 
0092 using namespace std;
0093 using namespace edm;
0094 
0095 PFDisplacedVertexCandidateProducer::PFDisplacedVertexCandidateProducer(const edm::ParameterSet& iConfig)
0096     : magneticFieldToken_(esConsumes()) {
0097   // --- Setup input collection names --- //
0098   inputTagTracks_ = consumes<reco::TrackCollection>(iConfig.getParameter<InputTag>("trackCollection"));
0099 
0100   inputTagMainVertex_ = consumes<reco::VertexCollection>(iConfig.getParameter<InputTag>("mainVertexLabel"));
0101 
0102   inputTagBeamSpot_ = consumes<reco::BeamSpot>(iConfig.getParameter<InputTag>("offlineBeamSpotLabel"));
0103 
0104   verbose_ = iConfig.getUntrackedParameter<bool>("verbose");
0105 
0106   bool debug = iConfig.getUntrackedParameter<bool>("debug");
0107 
0108   // ------ Algo Parameters ------ //
0109 
0110   // Distance of minimal approach below which
0111   // two tracks are considered as linked together
0112   double dcaCut = iConfig.getParameter<double>("dcaCut");
0113 
0114   // Do not reconstruct vertices wich are
0115   // too close to the beam pipe
0116   double primaryVertexCut = iConfig.getParameter<double>("primaryVertexCut");
0117 
0118   //maximum distance between the DCA Point and the inner hit of the track
0119   double dcaPInnerHitCut = iConfig.getParameter<double>("dcaPInnerHitCut");
0120 
0121   edm::ParameterSet ps_trk = iConfig.getParameter<edm::ParameterSet>("tracksSelectorParameters");
0122 
0123   // Collection to be produced
0124   produces<reco::PFDisplacedVertexCandidateCollection>();
0125 
0126   // Vertex Finder parameters  -----------------------------------
0127   pfDisplacedVertexCandidateFinder_.setDebug(debug);
0128   pfDisplacedVertexCandidateFinder_.setParameters(dcaCut, primaryVertexCut, dcaPInnerHitCut, ps_trk);
0129 }
0130 
0131 PFDisplacedVertexCandidateProducer::~PFDisplacedVertexCandidateProducer() {}
0132 
0133 void PFDisplacedVertexCandidateProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0134   LogDebug("PFDisplacedVertexCandidateProducer")
0135       << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
0136 
0137   // Prepare and fill useful event information for the Finder
0138   auto const& theMagField = &iSetup.getData(magneticFieldToken_);
0139 
0140   Handle<reco::TrackCollection> trackCollection;
0141   iEvent.getByToken(inputTagTracks_, trackCollection);
0142 
0143   Handle<reco::VertexCollection> mainVertexHandle;
0144   iEvent.getByToken(inputTagMainVertex_, mainVertexHandle);
0145 
0146   Handle<reco::BeamSpot> beamSpotHandle;
0147   iEvent.getByToken(inputTagBeamSpot_, beamSpotHandle);
0148 
0149   pfDisplacedVertexCandidateFinder_.setPrimaryVertex(mainVertexHandle, beamSpotHandle);
0150   pfDisplacedVertexCandidateFinder_.setInput(trackCollection, theMagField);
0151 
0152   // Run the finder
0153   pfDisplacedVertexCandidateFinder_.findDisplacedVertexCandidates();
0154 
0155   if (verbose_) {
0156     ostringstream str;
0157     str << pfDisplacedVertexCandidateFinder_ << endl;
0158     cout << pfDisplacedVertexCandidateFinder_ << endl;
0159     LogInfo("PFDisplacedVertexCandidateProducer") << str.str() << endl;
0160   }
0161 
0162   std::unique_ptr<reco::PFDisplacedVertexCandidateCollection> pOutputDisplacedVertexCandidateCollection(
0163       pfDisplacedVertexCandidateFinder_.transferVertexCandidates());
0164 
0165   iEvent.put(std::move(pOutputDisplacedVertexCandidateCollection));
0166 
0167   LogDebug("PFDisplacedVertexCandidateProducer")
0168       << "STOP event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
0169 }