Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-18 03:27:33

0001 /*
0002  * =============================================================================
0003  *       Filename:  PFRecoTauLostTrackPlugin.cc
0004  *
0005  *    Description: Add references to tracks of tau-charged-hadrons built on 
0006  *                 top of a track
0007  *
0008  *        Created:  25/04/2022
0009  *
0010  *         Authors:  Michal Bluj (NCBJ, Warsaw)
0011  *
0012  * =============================================================================
0013  */
0014 
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 
0017 #include "RecoTauTag/RecoTau/interface/RecoTauBuilderPlugins.h"
0018 #include "DataFormats/TauReco/interface/PFTau.h"
0019 #include "DataFormats/TauReco/interface/PFRecoTauChargedHadron.h"
0020 #include "DataFormats/TauReco/interface/PFRecoTauChargedHadronFwd.h"
0021 
0022 namespace reco {
0023   namespace tau {
0024 
0025     class PFRecoTauLostTrackPlugin : public RecoTauModifierPlugin {
0026     public:
0027       explicit PFRecoTauLostTrackPlugin(const edm::ParameterSet&, edm::ConsumesCollector&& iC);
0028       ~PFRecoTauLostTrackPlugin() override = default;
0029       void operator()(PFTau&) const override;
0030       void beginEvent() override;
0031       void endEvent() override;
0032 
0033     private:
0034       edm::Handle<reco::TrackCollection> tracks_;
0035       const edm::EDGetTokenT<reco::TrackCollection> track_token_;
0036       const int verbosity_;
0037     };
0038 
0039     PFRecoTauLostTrackPlugin::PFRecoTauLostTrackPlugin(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
0040         : RecoTauModifierPlugin(cfg, std::move(iC)),
0041           track_token_(iC.consumes(cfg.getParameter<edm::InputTag>("trackSrc"))),
0042           verbosity_(cfg.getParameter<int>("verbosity")) {}
0043 
0044     void PFRecoTauLostTrackPlugin::beginEvent() { evt()->getByToken(track_token_, tracks_); }
0045 
0046     void PFRecoTauLostTrackPlugin::operator()(PFTau& tau) const {
0047       if (!tracks_.isValid()) {  //track collection not available in the event
0048         if (verbosity_) {
0049           edm::LogPrint("<PFRecoTauLostTrackPlugin::operator()>:")
0050               << " Track collection " << tracks_.provenance() << " is not valid."
0051               << " No tracks will be added to tau.";
0052         }
0053         return;
0054       }
0055       reco::TrackRefVector lostTracks;
0056       const PFRecoTauChargedHadronCollection& chargedHadrons = tau.signalTauChargedHadronCandidates();
0057       for (const auto& chargedHadron : chargedHadrons) {
0058         if (chargedHadron.algoIs(PFRecoTauChargedHadron::kTrack) && chargedHadron.getTrack().isNonnull()) {
0059           reco::TrackRef trackRef(tracks_, chargedHadron.getTrack().key());
0060           lostTracks.push_back(trackRef);
0061         }
0062       }
0063       if (verbosity_) {
0064         edm::LogPrint("<PFRecoTauLostTrackPlugin::operator()>:")
0065             << " tau: Pt = " << tau.pt() << ", eta = " << tau.eta() << ", phi = " << tau.phi()
0066             << ", mass = " << tau.mass() << " (decayMode = " << tau.decayMode() << ")"
0067             << ", nChHadrs = " << chargedHadrons.size() << ", nLostTracks = " << lostTracks.size();
0068       }
0069       if (!lostTracks.empty())
0070         tau.setsignalTracks(lostTracks);
0071     }
0072 
0073     void PFRecoTauLostTrackPlugin::endEvent() {}
0074 
0075   }  // namespace tau
0076 }  // namespace reco
0077 
0078 #include "FWCore/Framework/interface/MakerMacros.h"
0079 
0080 DEFINE_EDM_PLUGIN(RecoTauModifierPluginFactory, reco::tau::PFRecoTauLostTrackPlugin, "PFRecoTauLostTrackPlugin");