File indexing completed on 2025-04-30 22:24:39
0001
0002
0003
0004
0005
0006
0007
0008 #include <memory>
0009 #include <string>
0010
0011
0012 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/Framework/interface/global/EDProducer.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/Utilities/interface/EDGetToken.h"
0021 #include "SimDataFormats/Associations/interface/LayerClusterToSimClusterAssociator.h"
0022
0023
0024
0025
0026
0027 class LCToSCAssociatorEDProducer : public edm::global::EDProducer<> {
0028 public:
0029 explicit LCToSCAssociatorEDProducer(const edm::ParameterSet &);
0030 ~LCToSCAssociatorEDProducer() override = default;
0031
0032 static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0033
0034 private:
0035 void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0036
0037 edm::EDGetTokenT<SimClusterCollection> SCCollectionToken_;
0038 edm::EDGetTokenT<reco::CaloClusterCollection> LCCollectionToken_;
0039 edm::EDGetTokenT<ticl::LayerClusterToSimClusterAssociator> associatorToken_;
0040 };
0041
0042 LCToSCAssociatorEDProducer::LCToSCAssociatorEDProducer(const edm::ParameterSet &pset) {
0043 produces<ticl::SimToRecoCollectionWithSimClusters>();
0044 produces<ticl::RecoToSimCollectionWithSimClusters>();
0045
0046 SCCollectionToken_ = consumes<SimClusterCollection>(pset.getParameter<edm::InputTag>("label_scl"));
0047 LCCollectionToken_ = consumes<reco::CaloClusterCollection>(pset.getParameter<edm::InputTag>("label_lcl"));
0048 associatorToken_ = consumes<ticl::LayerClusterToSimClusterAssociator>(pset.getParameter<edm::InputTag>("associator"));
0049 }
0050
0051
0052
0053
0054
0055
0056 void LCToSCAssociatorEDProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0057 using namespace edm;
0058
0059 edm::Handle<ticl::LayerClusterToSimClusterAssociator> theAssociator;
0060 iEvent.getByToken(associatorToken_, theAssociator);
0061
0062 Handle<SimClusterCollection> SCCollection;
0063 iEvent.getByToken(SCCollectionToken_, SCCollection);
0064
0065 Handle<reco::CaloClusterCollection> LCCollection;
0066 iEvent.getByToken(LCCollectionToken_, LCCollection);
0067
0068
0069 if (!LCCollection.isValid()) {
0070 edm::LogWarning("LCToSCAssociatorEDProducer")
0071 << "CaloCluster collection is unavailable. Producing empty associations.";
0072
0073
0074 auto emptyRecSimColl = std::make_unique<ticl::RecoToSimCollectionWithSimClusters>();
0075 auto emptySimRecColl = std::make_unique<ticl::SimToRecoCollectionWithSimClusters>();
0076
0077 iEvent.put(std::move(emptyRecSimColl));
0078 iEvent.put(std::move(emptySimRecColl));
0079 return;
0080 }
0081
0082
0083 LogTrace("AssociatorValidator") << "Calling associateRecoToSim method\n";
0084 ticl::RecoToSimCollectionWithSimClusters recSimColl = theAssociator->associateRecoToSim(LCCollection, SCCollection);
0085
0086 LogTrace("AssociatorValidator") << "Calling associateSimToReco method\n";
0087 ticl::SimToRecoCollectionWithSimClusters simRecColl = theAssociator->associateSimToReco(LCCollection, SCCollection);
0088
0089 auto rts = std::make_unique<ticl::RecoToSimCollectionWithSimClusters>(recSimColl);
0090 auto str = std::make_unique<ticl::SimToRecoCollectionWithSimClusters>(simRecColl);
0091
0092 iEvent.put(std::move(rts));
0093 iEvent.put(std::move(str));
0094 }
0095
0096 void LCToSCAssociatorEDProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0097 edm::ParameterSetDescription desc;
0098 desc.add<edm::InputTag>("label_scl", edm::InputTag("scAssocByEnergyScoreProducer"));
0099 desc.add<edm::InputTag>("label_lcl", edm::InputTag("mix", "MergedCaloTruth"));
0100 desc.add<edm::InputTag>("associator", edm::InputTag("hgcalMergeLayerClusters"));
0101 descriptions.addWithDefaultLabel(desc);
0102 }
0103
0104
0105 DEFINE_FWK_MODULE(LCToSCAssociatorEDProducer);