File indexing completed on 2024-04-06 12:27:24
0001 #ifndef __PFClusterTimeAssigner__
0002 #define __PFClusterTimeAssigner__
0003
0004
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/stream/EDProducer.h"
0007
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0013
0014 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
0015 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
0016
0017 #include "DataFormats/Common/interface/ValueMap.h"
0018
0019 class PFClusterTimeAssigner : public edm::stream::EDProducer<> {
0020 public:
0021 PFClusterTimeAssigner(const edm::ParameterSet& conf) {
0022 const edm::InputTag& clusters = conf.getParameter<edm::InputTag>("src");
0023 clustersTok_ = consumes<reco::PFClusterCollection>(clusters);
0024
0025 const edm::InputTag& times = conf.getParameter<edm::InputTag>("timeSrc");
0026 timesTok_ = consumes<edm::ValueMap<float> >(times);
0027
0028 const edm::InputTag& timeResos = conf.getParameter<edm::InputTag>("timeResoSrc");
0029 timeResosTok_ = consumes<edm::ValueMap<float> >(timeResos);
0030
0031 produces<reco::PFClusterCollection>();
0032 }
0033
0034 void produce(edm::Event& e, const edm::EventSetup& es) override;
0035 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0036
0037 private:
0038 edm::EDGetTokenT<reco::PFClusterCollection> clustersTok_;
0039 edm::EDGetTokenT<edm::ValueMap<float> > timesTok_;
0040 edm::EDGetTokenT<edm::ValueMap<float> > timeResosTok_;
0041 };
0042
0043 DEFINE_FWK_MODULE(PFClusterTimeAssigner);
0044
0045 void PFClusterTimeAssigner::produce(edm::Event& e, const edm::EventSetup& es) {
0046 auto clusters_out = std::make_unique<reco::PFClusterCollection>();
0047
0048 edm::Handle<reco::PFClusterCollection> clustersH;
0049 e.getByToken(clustersTok_, clustersH);
0050 edm::Handle<edm::ValueMap<float> > timesH, timeResosH;
0051 e.getByToken(timesTok_, timesH);
0052 e.getByToken(timeResosTok_, timeResosH);
0053
0054 auto const& clusters = *clustersH;
0055 auto const& times = *timesH;
0056 auto const& timeResos = *timeResosH;
0057
0058 clusters_out->reserve(clusters.size());
0059 clusters_out->insert(clusters_out->end(), clusters.begin(), clusters.end());
0060
0061
0062 auto& out = *clusters_out;
0063 for (unsigned i = 0; i < out.size(); ++i) {
0064 edm::Ref<reco::PFClusterCollection> clusterRef(clustersH, i);
0065 const float time = times[clusterRef];
0066 const float timeReso = timeResos[clusterRef];
0067 out[i].setTime(time, timeReso);
0068 }
0069
0070 e.put(std::move(clusters_out));
0071 }
0072
0073 void PFClusterTimeAssigner::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0074 edm::ParameterSetDescription desc;
0075 desc.add<edm::InputTag>("src", edm::InputTag("particleFlowClusterECALUncorrected"));
0076 desc.add<edm::InputTag>("timeSrc", edm::InputTag("ecalBarrelClusterFastTimer"));
0077 desc.add<edm::InputTag>("timeResoSrc", edm::InputTag("ecalBarrelClusterFastTimer"));
0078 descriptions.add("particleFlowClusterTimeAssignerDefault", desc);
0079 }
0080
0081 #endif