Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:36

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 "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031 
0032 #include "DataFormats/BTauReco/interface/CandIPTagInfo.h"
0033 #include "DataFormats/BTauReco/interface/CandSecondaryVertexTagInfo.h"
0034 #include "DataFormats/BTauReco/interface/ShallowTagInfo.h"
0035 #include "DataFormats/BTauReco/interface/TaggingVariable.h"
0036 #include "RecoBTag/SecondaryVertex/interface/CombinedSVComputer.h"
0037 
0038 #include "DataFormats/BTauReco/interface/TrackIPTagInfo.h"
0039 #include "DataFormats/BTauReco/interface/SecondaryVertexTagInfo.h"
0040 
0041 #include <map>
0042 
0043 ////////////////////////////////////////////////////////////
0044 //
0045 // TemplatedDeepNNTagInfoProducer
0046 //
0047 // class declaration
0048 //
0049 template <typename IPTag, typename SVTag>
0050 class TemplatedDeepNNTagInfoProducer : public edm::stream::EDProducer<> {
0051 public:
0052   explicit TemplatedDeepNNTagInfoProducer(const edm::ParameterSet&);
0053   ~TemplatedDeepNNTagInfoProducer() override;
0054 
0055   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0056 
0057 private:
0058   void beginStream(edm::StreamID) override {}
0059   void produce(edm::Event&, const edm::EventSetup&) override;
0060   void endStream() override {}
0061 
0062   // ----------member data ---------------------------
0063   const edm::EDGetTokenT<std::vector<SVTag> > svSrc_;
0064   CombinedSVComputer computer_;
0065 };
0066 
0067 //
0068 // constants, enums and typedefs
0069 //
0070 
0071 //
0072 // static data member definitions
0073 //
0074 
0075 //
0076 // constructors and destructor
0077 //
0078 template <typename IPTag, typename SVTag>
0079 TemplatedDeepNNTagInfoProducer<IPTag, SVTag>::TemplatedDeepNNTagInfoProducer(const edm::ParameterSet& iConfig)
0080     : svSrc_(consumes<std::vector<SVTag> >(iConfig.getParameter<edm::InputTag>("svTagInfos"))),
0081       computer_(iConfig.getParameter<edm::ParameterSet>("computer")) {
0082   produces<std::vector<reco::ShallowTagInfo> >();
0083 }
0084 
0085 template <typename IPTag, typename SVTag>
0086 TemplatedDeepNNTagInfoProducer<IPTag, SVTag>::~TemplatedDeepNNTagInfoProducer() {
0087   // do anything here that needs to be done at destruction time
0088   // (e.g. close files, deallocate resources etc.)
0089 }
0090 
0091 //
0092 // member functions
0093 //
0094 
0095 // ------------ method called to produce the data  ------------
0096 template <typename IPTag, typename SVTag>
0097 void TemplatedDeepNNTagInfoProducer<IPTag, SVTag>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0098   // get input TagInfos
0099   edm::Handle<std::vector<SVTag> > svTagInfos;
0100   iEvent.getByToken(svSrc_, svTagInfos);
0101 
0102   // create the output collection
0103   auto tagInfos = std::make_unique<std::vector<reco::ShallowTagInfo> >();
0104 
0105   // loop over TagInfos
0106   for (auto iterTI = svTagInfos->begin(); iterTI != svTagInfos->end(); ++iterTI) {
0107     // get TagInfos
0108     const SVTag& svTagInfo = *(iterTI);
0109     const IPTag& ipInfo = *(iterTI->trackIPTagInfoRef().get());
0110 
0111     reco::TaggingVariableList vars = computer_(ipInfo, svTagInfo);
0112     std::vector<float> tagValList = vars.getList(reco::btau::trackEtaRel, false);
0113     vars.insert(reco::btau::jetNTracksEtaRel, tagValList.size());
0114     tagValList = vars.getList(reco::btau::trackSip2dSig, false);
0115     vars.insert(reco::btau::jetNSelectedTracks, tagValList.size());
0116     vars.finalize();  //fix the TaggingVariableList, nothing should be added/removed
0117 
0118     //If not SV found set it to 0, not to non-existent
0119     if (!vars.checkTag(reco::btau::jetNSecondaryVertices))
0120       vars.insert(reco::btau::jetNSecondaryVertices, 0);
0121     if (!vars.checkTag(reco::btau::vertexNTracks))
0122       vars.insert(reco::btau::vertexNTracks, 0);
0123 
0124     tagInfos->emplace_back(vars, svTagInfo.jet());
0125   }
0126 
0127   // put the output in the event
0128   iEvent.put(std::move(tagInfos));
0129 }
0130 
0131 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0132 template <typename IPTag, typename SVTag>
0133 void TemplatedDeepNNTagInfoProducer<IPTag, SVTag>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0134   //The following says we do not know what parameters are allowed so do no validation
0135   // Please change this to state exactly what you do use, even if it is no parameters
0136   edm::ParameterSetDescription desc;
0137   desc.setUnknown();
0138   descriptions.addDefault(desc);
0139 }
0140 
0141 //define this as a plug-in
0142 //For PFJets
0143 typedef TemplatedDeepNNTagInfoProducer<reco::CandIPTagInfo, reco::CandSecondaryVertexTagInfo> DeepNNTagInfoProducer;
0144 //For CaloJets
0145 typedef TemplatedDeepNNTagInfoProducer<reco::TrackIPTagInfo, reco::SecondaryVertexTagInfo> TrackDeepNNTagInfoProducer;
0146 DEFINE_FWK_MODULE(DeepNNTagInfoProducer);
0147 DEFINE_FWK_MODULE(TrackDeepNNTagInfoProducer);