Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:21

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/PatCandidates/interface/Tau.h"
0007 #include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"  //MB: can use CompositePtrCandidate, but dictionaries not defined
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 
0011 class PATTauSignalCandidatesProducer : public edm::stream::EDProducer<> {
0012 public:
0013   explicit PATTauSignalCandidatesProducer(const edm::ParameterSet&);
0014   ~PATTauSignalCandidatesProducer() override {}
0015 
0016   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0017   void produce(edm::Event&, const edm::EventSetup&) override;
0018 
0019 private:
0020   //--- configuration parameters
0021   edm::EDGetTokenT<pat::TauCollection> tausToken_;
0022   const bool storeLostTracks_;
0023 };
0024 
0025 PATTauSignalCandidatesProducer::PATTauSignalCandidatesProducer(const edm::ParameterSet& cfg)
0026     : tausToken_(consumes<pat::TauCollection>(cfg.getParameter<edm::InputTag>("src"))),
0027       storeLostTracks_(cfg.getParameter<bool>("storeLostTracks")) {
0028   produces<std::vector<reco::VertexCompositePtrCandidate>>();
0029 }
0030 
0031 void PATTauSignalCandidatesProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0032   // Get the vector of taus
0033   edm::Handle<pat::TauCollection> inputTaus;
0034   evt.getByToken(tausToken_, inputTaus);
0035 
0036   auto outputCands = std::make_unique<std::vector<reco::VertexCompositePtrCandidate>>();
0037   outputCands->reserve(inputTaus->size() * 3);  //avarage number of tau signal cands
0038   for (size_t iTau = 0; iTau < inputTaus->size(); ++iTau) {
0039     for (const auto& cand : (*inputTaus)[iTau].signalCands()) {
0040       reco::VertexCompositePtrCandidate outCand(*cand);
0041       outCand.setStatus(iTau);  //trick to store index of the mother tau to be used in NanoAOD
0042       outCand.addDaughter(cand);
0043       outputCands->push_back(outCand);
0044     }
0045     if (storeLostTracks_) {
0046       for (const auto& cand : (*inputTaus)[iTau].signalLostTracks()) {
0047         reco::VertexCompositePtrCandidate outCand(*cand);
0048         outCand.setStatus(iTau);  //trick to store index of the mother tau to be used in NanoAOD
0049         auto pdgId = cand->pdgId();
0050         outCand.setPdgId(
0051             pdgId + 10000 * ((pdgId >= 0) -
0052                              (pdgId < 0)));  // increase abs(pdgId) by 10000 to distingish from "true" signal candidates
0053         outCand.addDaughter(cand);
0054         outputCands->push_back(outCand);
0055       }
0056     }
0057   }
0058 
0059   evt.put(std::move(outputCands));
0060 }
0061 
0062 void PATTauSignalCandidatesProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0063   // patTauDecayCandidatesProducer
0064   edm::ParameterSetDescription desc;
0065 
0066   desc.add<edm::InputTag>("src", edm::InputTag("slimmedTaus"));
0067   desc.add<bool>("storeLostTracks", true)
0068       ->setComment("If true, lostTracks will be stored together with other candidates with pdgId=+-10211");
0069 
0070   descriptions.addWithDefaultLabel(desc);
0071 }
0072 
0073 #include "FWCore/Framework/interface/MakerMacros.h"
0074 
0075 DEFINE_FWK_MODULE(PATTauSignalCandidatesProducer);