File indexing completed on 2025-01-08 03:36:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "DataFormats/BTauReco/interface/CandIPTagInfo.h"
0024 #include "DataFormats/BTauReco/interface/CandSecondaryVertexTagInfo.h"
0025 #include "DataFormats/BTauReco/interface/SecondaryVertexTagInfo.h"
0026 #include "DataFormats/BTauReco/interface/ShallowTagInfo.h"
0027 #include "DataFormats/BTauReco/interface/TaggingVariable.h"
0028 #include "DataFormats/BTauReco/interface/TrackIPTagInfo.h"
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/Frameworkfwd.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 #include "FWCore/Framework/interface/stream/EDProducer.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 #include "FWCore/Utilities/interface/StreamID.h"
0035 #include "RecoBTag/SecondaryVertex/interface/CombinedSVComputer.h"
0036
0037 #include <map>
0038
0039
0040
0041
0042
0043
0044
0045 template <typename IPTag, typename SVTag>
0046 class TemplatedDeepNNTagInfoProducer : public edm::stream::EDProducer<> {
0047 public:
0048 explicit TemplatedDeepNNTagInfoProducer(const edm::ParameterSet&);
0049 ~TemplatedDeepNNTagInfoProducer() override = default;
0050
0051 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052
0053 private:
0054 void beginStream(edm::StreamID) override {}
0055 void produce(edm::Event&, const edm::EventSetup&) override;
0056 void endStream() override {}
0057
0058
0059 const edm::EDGetTokenT<std::vector<SVTag> > svSrc_;
0060 CombinedSVComputer computer_;
0061 };
0062
0063
0064
0065
0066 template <typename IPTag, typename SVTag>
0067 TemplatedDeepNNTagInfoProducer<IPTag, SVTag>::TemplatedDeepNNTagInfoProducer(const edm::ParameterSet& iConfig)
0068 : svSrc_(consumes<std::vector<SVTag> >(iConfig.getParameter<edm::InputTag>("svTagInfos"))),
0069 computer_(iConfig.getParameter<edm::ParameterSet>("computer")) {
0070 produces<std::vector<reco::ShallowTagInfo> >();
0071 }
0072
0073
0074
0075
0076
0077
0078 template <typename IPTag, typename SVTag>
0079 void TemplatedDeepNNTagInfoProducer<IPTag, SVTag>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0080
0081 edm::Handle<std::vector<SVTag> > svTagInfos;
0082 iEvent.getByToken(svSrc_, svTagInfos);
0083
0084
0085 auto tagInfos = std::make_unique<std::vector<reco::ShallowTagInfo> >();
0086
0087
0088 for (auto iterTI = svTagInfos->begin(); iterTI != svTagInfos->end(); ++iterTI) {
0089
0090 const SVTag& svTagInfo = *(iterTI);
0091 const IPTag& ipInfo = *(iterTI->trackIPTagInfoRef().get());
0092
0093 reco::TaggingVariableList vars = computer_(ipInfo, svTagInfo);
0094 std::vector<float> tagValList = vars.getList(reco::btau::trackEtaRel, false);
0095 vars.insert(reco::btau::jetNTracksEtaRel, tagValList.size());
0096 tagValList = vars.getList(reco::btau::trackSip2dSig, false);
0097 vars.insert(reco::btau::jetNSelectedTracks, tagValList.size());
0098 vars.finalize();
0099
0100
0101 if (!vars.checkTag(reco::btau::jetNSecondaryVertices))
0102 vars.insert(reco::btau::jetNSecondaryVertices, 0);
0103 if (!vars.checkTag(reco::btau::vertexNTracks))
0104 vars.insert(reco::btau::vertexNTracks, 0);
0105
0106 tagInfos->emplace_back(vars, svTagInfo.jet());
0107 }
0108
0109
0110 iEvent.put(std::move(tagInfos));
0111 }
0112
0113
0114 template <typename IPTag, typename SVTag>
0115 void TemplatedDeepNNTagInfoProducer<IPTag, SVTag>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0116 edm::ParameterSetDescription desc;
0117 desc.add<edm::InputTag>("svTagInfos", edm::InputTag(""));
0118
0119
0120 edm::ParameterSetDescription computerDesc;
0121 CombinedSVComputer::fillPSetDescription(computerDesc);
0122 desc.add<edm::ParameterSetDescription>("computer", computerDesc);
0123
0124 descriptions.addWithDefaultLabel(desc);
0125 }
0126
0127
0128
0129 typedef TemplatedDeepNNTagInfoProducer<reco::CandIPTagInfo, reco::CandSecondaryVertexTagInfo> DeepNNTagInfoProducer;
0130
0131 typedef TemplatedDeepNNTagInfoProducer<reco::TrackIPTagInfo, reco::SecondaryVertexTagInfo> TrackDeepNNTagInfoProducer;
0132 DEFINE_FWK_MODULE(DeepNNTagInfoProducer);
0133 DEFINE_FWK_MODULE(TrackDeepNNTagInfoProducer);