Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-08 03:36:25

0001 // -*- C++ -*-
0002 //
0003 // Package:    ​RecoBTag/​SecondaryVertex
0004 // Class:      DeepNNTagInfoProducer
0005 //
0006 /**\class DeepNNTagInfoProducer DeepNNTagInfoProducer.cc ​RecoBTag/DeepFlavour/plugins/DeepNNTagInfoProducer.cc
0007  *
0008  * Description: EDProducer that produces collection of DeepNNTagInfos
0009  *
0010  * Implementation:
0011  *    A collection of CandIPTagInfo and CandSecondaryVertexTagInfo and a CombinedSVComputer ESHandle is taken as input and a collection of DeepNNTagInfos
0012  *    is produced as output.
0013  */
0014 //
0015 // Original Author:  Mauro Verzetti (U. Rochester)
0016 // Added templated functionality : Praveen C Tiwari & Jyothsna Komaragiri (IISc)
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
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 // TemplatedDeepNNTagInfoProducer
0042 //
0043 // class declaration
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   // ----------member data ---------------------------
0059   const edm::EDGetTokenT<std::vector<SVTag> > svSrc_;
0060   CombinedSVComputer computer_;
0061 };
0062 
0063 //
0064 // constructors and destructor
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 // member functions
0075 //
0076 
0077 // ------------ method called to produce the data  ------------
0078 template <typename IPTag, typename SVTag>
0079 void TemplatedDeepNNTagInfoProducer<IPTag, SVTag>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0080   // get input TagInfos
0081   edm::Handle<std::vector<SVTag> > svTagInfos;
0082   iEvent.getByToken(svSrc_, svTagInfos);
0083 
0084   // create the output collection
0085   auto tagInfos = std::make_unique<std::vector<reco::ShallowTagInfo> >();
0086 
0087   // loop over TagInfos
0088   for (auto iterTI = svTagInfos->begin(); iterTI != svTagInfos->end(); ++iterTI) {
0089     // get TagInfos
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();  //fix the TaggingVariableList, nothing should be added/removed
0099 
0100     //If not SV found set it to 0, not to non-existent
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   // put the output in the event
0110   iEvent.put(std::move(tagInfos));
0111 }
0112 
0113 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
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   // Define the computer parameter using CombinedSVComputer
0120   edm::ParameterSetDescription computerDesc;
0121   CombinedSVComputer::fillPSetDescription(computerDesc);
0122   desc.add<edm::ParameterSetDescription>("computer", computerDesc);
0123 
0124   descriptions.addWithDefaultLabel(desc);
0125 }
0126 
0127 //define this as a plug-in
0128 //For PFJets
0129 typedef TemplatedDeepNNTagInfoProducer<reco::CandIPTagInfo, reco::CandSecondaryVertexTagInfo> DeepNNTagInfoProducer;
0130 //For CaloJets
0131 typedef TemplatedDeepNNTagInfoProducer<reco::TrackIPTagInfo, reco::SecondaryVertexTagInfo> TrackDeepNNTagInfoProducer;
0132 DEFINE_FWK_MODULE(DeepNNTagInfoProducer);
0133 DEFINE_FWK_MODULE(TrackDeepNNTagInfoProducer);