Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:09

0001 /*
0002  * "Unembed" the pizeros in a reco::PFTau.
0003  *
0004  * This converts a collection of PFTaus which have their PiZeros stored
0005  * as std::vector<RecoTauPiZeros>s to an output collection which has
0006  * the PiZeros stored in a separate product, with the PiZeros stored as Refs
0007  * within the tau.  This will improve the de-serialization speed of the taus.
0008  *
0009  * Author: Evan K. Friis, UW Madison
0010  *
0011  */
0012 
0013 #include "FWCore/Framework/interface/Frameworkfwd.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/Framework/interface/stream/EDProducer.h"
0018 
0019 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0020 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0021 
0022 #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h"
0023 
0024 #include "DataFormats/TauReco/interface/PFTau.h"
0025 #include "DataFormats/TauReco/interface/PFTauFwd.h"
0026 #include "DataFormats/TauReco/interface/RecoTauPiZero.h"
0027 #include "DataFormats/TauReco/interface/RecoTauPiZeroFwd.h"
0028 
0029 class RecoTauPiZeroUnembedder : public edm::stream::EDProducer<> {
0030 public:
0031   RecoTauPiZeroUnembedder(const edm::ParameterSet& pset);
0032   ~RecoTauPiZeroUnembedder() override {}
0033   void produce(edm::Event& evt, const edm::EventSetup& es) override;
0034   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0035 
0036 private:
0037   edm::InputTag src_;
0038   edm::EDGetTokenT<reco::CandidateView> token;
0039 };
0040 
0041 RecoTauPiZeroUnembedder::RecoTauPiZeroUnembedder(const edm::ParameterSet& pset) {
0042   src_ = pset.getParameter<edm::InputTag>("src");
0043   token = consumes<reco::CandidateView>(src_);
0044   produces<reco::RecoTauPiZeroCollection>("pizeros");
0045   produces<reco::PFTauCollection>();
0046 }
0047 void RecoTauPiZeroUnembedder::produce(edm::Event& evt, const edm::EventSetup& es) {
0048   auto piZerosOut = std::make_unique<reco::RecoTauPiZeroCollection>();
0049   auto tausOut = std::make_unique<reco::PFTauCollection>();
0050 
0051   edm::Handle<reco::CandidateView> tauView;
0052   evt.getByToken(token, tauView);
0053 
0054   reco::PFTauRefVector taus = reco::tau::castView<reco::PFTauRefVector>(tauView);
0055 
0056   // Get the reference to the product of where the final pizeros will end up
0057   reco::RecoTauPiZeroRefProd piZeroProd = evt.getRefBeforePut<reco::RecoTauPiZeroCollection>("pizeros");
0058 
0059   for (size_t iTau = 0; iTau < taus.size(); ++iTau) {
0060     // Make a copy
0061     reco::PFTau myTau = *taus[iTau];
0062     // The ref vectors that will be filled
0063     reco::RecoTauPiZeroRefVector signalPiZeroRefs;
0064     reco::RecoTauPiZeroRefVector isolationPiZeroRefs;
0065 
0066     // Copy the PiZeros into the new vector, while updating what refs they will
0067     // have
0068     const reco::RecoTauPiZeroCollection& signalPiZeros = myTau.signalPiZeroCandidates();
0069 
0070     for (size_t iPiZero = 0; iPiZero < signalPiZeros.size(); ++iPiZero) {
0071       piZerosOut->push_back(signalPiZeros[iPiZero]);
0072       // Figure out what the ref for this pizero will be in the new coll.
0073       signalPiZeroRefs.push_back(reco::RecoTauPiZeroRef(piZeroProd, piZerosOut->size() - 1));
0074     }
0075 
0076     const reco::RecoTauPiZeroCollection& isolationPiZeroCandidates = myTau.isolationPiZeroCandidates();
0077     for (size_t iPiZero = 0; iPiZero < isolationPiZeroCandidates.size(); ++iPiZero) {
0078       piZerosOut->push_back(isolationPiZeroCandidates[iPiZero]);
0079       // Figure out what the ref for this pizero will be in the new coll.
0080       isolationPiZeroRefs.push_back(reco::RecoTauPiZeroRef(piZeroProd, piZerosOut->size() - 1));
0081     }
0082 
0083     myTau.setSignalPiZeroCandidatesRefs(signalPiZeroRefs);
0084     myTau.setIsolationPiZeroCandidatesRefs(isolationPiZeroRefs);
0085 
0086     tausOut->push_back(myTau);
0087   }
0088 
0089   evt.put(std::move(piZerosOut), "pizeros");
0090   evt.put(std::move(tausOut));
0091 }
0092 
0093 void RecoTauPiZeroUnembedder::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0094   // RecoTauPiZeroUnembedder
0095   edm::ParameterSetDescription desc;
0096   desc.add<edm::InputTag>("src", edm::InputTag("hpsPFTauProducerSansRefs"));
0097   descriptions.add("RecoTauPiZeroUnembedder", desc);
0098 }
0099 
0100 #include "FWCore/Framework/interface/MakerMacros.h"
0101 DEFINE_FWK_MODULE(RecoTauPiZeroUnembedder);