File indexing completed on 2024-07-28 22:48:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
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
0035 edm::EDGetTokenT<reco::TrackCollection> inputTagTracks_;
0036
0037
0038 edm::EDGetTokenT<reco::VertexCollection> inputTagMainVertex_;
0039 edm::EDGetTokenT<reco::BeamSpot> inputTagBeamSpot_;
0040
0041 const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
0042
0043
0044 bool verbose_;
0045
0046
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
0056
0057 desc.add<edm::InputTag>("trackCollection", {"generalTracks"});
0058
0059 desc.addUntracked<bool>("verbose", false);
0060
0061 desc.addUntracked<bool>("debug", false);
0062
0063 desc.add<double>("dcaCut", 0.5);
0064
0065 desc.add<double>("primaryVertexCut", 1.8);
0066
0067
0068 desc.add<double>("dcaPInnerHitCut", 1000.0);
0069
0070 desc.add<edm::InputTag>("mainVertexLabel", {"offlinePrimaryVertices", ""});
0071 desc.add<edm::InputTag>("offlineBeamSpotLabel", {"offlineBeamSpot", ""});
0072
0073
0074
0075 {
0076 edm::ParameterSetDescription pset;
0077
0078 pset.add<double>("nChi2_max", 5.);
0079 pset.add<double>("pt_min", 0.2);
0080
0081
0082
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
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
0109
0110
0111
0112 double dcaCut = iConfig.getParameter<double>("dcaCut");
0113
0114
0115
0116 double primaryVertexCut = iConfig.getParameter<double>("primaryVertexCut");
0117
0118
0119 double dcaPInnerHitCut = iConfig.getParameter<double>("dcaPInnerHitCut");
0120
0121 edm::ParameterSet ps_trk = iConfig.getParameter<edm::ParameterSet>("tracksSelectorParameters");
0122
0123
0124 produces<reco::PFDisplacedVertexCandidateCollection>();
0125
0126
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
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
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 }