File indexing completed on 2024-04-06 12:01:10
0001
0002 #include <memory>
0003
0004
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/stream/EDProducer.h"
0007
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012
0013 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
0014 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0015
0016 #include "DataFormats/VertexReco/interface/Vertex.h"
0017 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0018
0019
0020
0021
0022 namespace {
0023 const float dummy = -9.;
0024 const GlobalPoint dummyGP(dummy, dummy, 0.);
0025 }
0026
0027 class VertexCompositeCandidateCollectionSelector : public edm::stream::EDProducer<> {
0028 public:
0029 explicit VertexCompositeCandidateCollectionSelector(const edm::ParameterSet&);
0030
0031 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0032
0033 private:
0034 void produce(edm::Event&, const edm::EventSetup&) override;
0035
0036
0037
0038 edm::EDGetTokenT<reco::VertexCompositeCandidateCollection> v0Token_;
0039 edm::EDGetTokenT<reco::BeamSpot> bsToken_;
0040 edm::EDGetTokenT<reco::VertexCollection> pvToken_;
0041
0042 int pvNDOF_;
0043
0044 std::string label_;
0045
0046
0047 float lxyCUT_;
0048 float lxyWRTbsCUT_;
0049 bool debug_;
0050 };
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 VertexCompositeCandidateCollectionSelector::VertexCompositeCandidateCollectionSelector(const edm::ParameterSet& iConfig)
0064 : v0Token_(consumes<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("v0"))),
0065 bsToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
0066 pvToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertex"))),
0067 pvNDOF_(iConfig.getParameter<int>("pvNDOF")),
0068 label_(iConfig.getParameter<edm::InputTag>("v0").instance()),
0069 lxyCUT_(iConfig.getParameter<double>("lxyCUT")),
0070 lxyWRTbsCUT_(iConfig.getParameter<double>("lxyWRTbsCUT")),
0071 debug_(iConfig.getUntrackedParameter<bool>("debug")) {
0072 if (debug_)
0073 std::cout << "VertexCompositeCandidateCollectionSelector::VertexCompositeCandidateCollectionSelector" << std::endl;
0074
0075 produces<reco::VertexCompositeCandidateCollection>();
0076
0077
0078 }
0079
0080
0081
0082
0083
0084
0085 void VertexCompositeCandidateCollectionSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0086 using namespace edm;
0087
0088 if (debug_)
0089 std::cout << "VertexCompositeCandidateCollectionSelector::produce" << std::endl;
0090
0091
0092 auto result = std::make_unique<reco::VertexCompositeCandidateCollection>();
0093
0094 edm::Handle<reco::BeamSpot> beamspotHandle;
0095 iEvent.getByToken(bsToken_, beamspotHandle);
0096 reco::BeamSpot const* bs = nullptr;
0097 if (beamspotHandle.isValid())
0098 bs = &(*beamspotHandle);
0099
0100 edm::Handle<reco::VertexCollection> pvHandle;
0101 iEvent.getByToken(pvToken_, pvHandle);
0102 reco::Vertex const* pv = nullptr;
0103 if (pvHandle.isValid()) {
0104 pv = &pvHandle->front();
0105
0106 if (pv->isFake() ||
0107 pv->tracksSize() == 0
0108
0109 || pv->ndof() < pvNDOF_ || pv->z() > 24.)
0110 pv = nullptr;
0111 }
0112
0113 edm::Handle<reco::VertexCompositeCandidateCollection> v0Handle;
0114 iEvent.getByToken(v0Token_, v0Handle);
0115 int n = (v0Handle.isValid() ? v0Handle->size() : -1);
0116 if (debug_)
0117 std::cout << "n: " << n << std::endl;
0118 if (n > 0) {
0119 auto const& v0s = *v0Handle.product();
0120 for (auto const& v0 : v0s) {
0121 GlobalPoint displacementFromPV2D =
0122 (pv == nullptr ? dummyGP : GlobalPoint((pv->x() - v0.vx()), (pv->y() - v0.vy()), 0.));
0123 GlobalPoint displacementFromBS2D =
0124 (bs == nullptr ? dummyGP : GlobalPoint(v0.vx() - bs->x(v0.vz()), v0.vy() - bs->y(v0.vz()), 0.));
0125 float abslxy = (pv == nullptr ? dummy : displacementFromPV2D.perp());
0126 float abslxyWRTbs = (bs == nullptr ? dummy : displacementFromBS2D.perp());
0127
0128 if (debug_)
0129 std::cout << "abslxy: " << abslxy << " w.r.t. " << lxyCUT_ << " ==> " << (abslxy >= lxyCUT_ ? "OK" : "KO")
0130 << std::endl;
0131 if (debug_)
0132 std::cout << "abslxyWRTbs: " << abslxyWRTbs << " w.r.t. " << lxyWRTbsCUT_ << " ==> "
0133 << (abslxyWRTbs >= lxyWRTbsCUT_ ? "OK" : "KO") << std::endl;
0134 if (abslxy < lxyCUT_)
0135 continue;
0136 if (abslxyWRTbs < lxyWRTbsCUT_)
0137 continue;
0138 result->push_back(v0);
0139 }
0140 }
0141
0142 if (debug_)
0143 std::cout << "result: " << result->size() << std::endl;
0144
0145
0146 result->shrink_to_fit();
0147 iEvent.put(std::move(result));
0148 }
0149
0150
0151 void VertexCompositeCandidateCollectionSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0152
0153
0154 edm::ParameterSetDescription desc;
0155 desc.add<edm::InputTag>("v0");
0156 desc.add<edm::InputTag>("beamSpot");
0157 desc.add<edm::InputTag>("primaryVertex");
0158 desc.add<int>("pvNDOF");
0159 desc.add<double>("lxyCUT", 16.);
0160 desc.add<double>("lxyWRTbsCUT", 0.);
0161 desc.addUntracked<bool>("debug", false);
0162 descriptions.add("VertexCompositeCandidateCollectionSelector", desc);
0163 }
0164
0165
0166 DEFINE_FWK_MODULE(VertexCompositeCandidateCollectionSelector);