File indexing completed on 2024-04-06 11:58:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/stream/EDProducer.h"
0026 #include "FWCore/Framework/interface/ConsumesCollector.h"
0027
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032
0033 #include "DataFormats/Common/interface/ValueMap.h"
0034 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0035
0036
0037
0038
0039
0040
0041 class ValueMapTraslator : public edm::stream::EDProducer<> {
0042 typedef double value_t;
0043 typedef edm::ValueMap<value_t> Map_t;
0044
0045 public:
0046 explicit ValueMapTraslator(const edm::ParameterSet&);
0047 ~ValueMapTraslator() override;
0048
0049 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050
0051 private:
0052 void produce(edm::Event&, const edm::EventSetup&) override;
0053
0054
0055 edm::InputTag referenceCollectionTAG, oldreferenceCollectionTAG;
0056 edm::InputTag inputCollectionTAG;
0057 std::string outputCollectionName;
0058
0059 edm::EDGetTokenT<reco::GsfElectronCollection> referenceToken_;
0060 edm::EDGetTokenT<reco::GsfElectronCollection> oldreferenceToken_;
0061 edm::EDGetTokenT<Map_t> inputToken_;
0062 };
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 ValueMapTraslator::ValueMapTraslator(const edm::ParameterSet& iConfig)
0076 : referenceCollectionTAG(iConfig.getParameter<edm::InputTag>("referenceCollection")),
0077 oldreferenceCollectionTAG(iConfig.getParameter<edm::InputTag>("oldreferenceCollection")),
0078 inputCollectionTAG(iConfig.getParameter<edm::InputTag>("inputCollection")),
0079 outputCollectionName(iConfig.getParameter<std::string>("outputCollection")) {
0080
0081 referenceToken_ = consumes<reco::GsfElectronCollection>(referenceCollectionTAG);
0082 oldreferenceToken_ = consumes<reco::GsfElectronCollection>(oldreferenceCollectionTAG);
0083 inputToken_ = consumes<Map_t>(inputCollectionTAG);
0084
0085 produces<Map_t>(outputCollectionName);
0086 }
0087
0088 ValueMapTraslator::~ValueMapTraslator() {
0089
0090
0091 }
0092
0093
0094
0095
0096
0097
0098 void ValueMapTraslator::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0099 using namespace edm;
0100 std::vector<value_t> valueVector;
0101 auto valueVectorPtr = std::make_unique<Map_t>();
0102
0103
0104 Handle<reco::GsfElectronCollection> referenceHandle;
0105 Handle<reco::GsfElectronCollection> oldreferenceHandle;
0106 Handle<Map_t> inputHandle;
0107
0108 iEvent.getByToken(referenceToken_, referenceHandle);
0109 iEvent.getByToken(oldreferenceToken_, oldreferenceHandle);
0110 iEvent.getByToken(inputToken_, inputHandle);
0111
0112 for (Map_t::const_iterator valueMap_itr = inputHandle->begin(); valueMap_itr != inputHandle->end(); valueMap_itr++) {
0113 for (unsigned int i = 0; i < valueMap_itr.size(); i++) {
0114 #ifdef DEBUG
0115 std::cout << valueMap_itr[i] << std::endl;
0116 #endif
0117
0118 }
0119 break;
0120 }
0121
0122 #ifdef DEBUG
0123 std::cout << "Size: " << referenceHandle->size() << "\t" << oldreferenceHandle->size() << "\t" << inputHandle->size()
0124 << "\t" << valueVector.size() << std::endl;
0125 #endif
0126 for (reco::GsfElectronCollection::const_iterator electronNew = referenceHandle->begin();
0127 electronNew != referenceHandle->end();
0128 electronNew++) {
0129 for (reco::GsfElectronCollection::const_iterator electron = oldreferenceHandle->begin();
0130 electron != oldreferenceHandle->end();
0131 electron++) {
0132
0133 if (electron->gsfTrack() != electronNew->gsfTrack())
0134 continue;
0135
0136
0137
0138 reco::GsfElectronRef eleRef(oldreferenceHandle, electron - oldreferenceHandle->begin());
0139 reco::GsfElectronRef eleRef2(referenceHandle, electronNew - referenceHandle->begin());
0140
0141 #ifdef DEBUG
0142 std::cout << eleRef->eta() << "\t" << eleRef2->eta() << "\t" << eleRef->phi() << "\t" << eleRef2->phi() << "\t"
0143 << eleRef->energy() << "\t" << eleRef2->energy() << "\t" << (eleRef->gsfTrack() == eleRef2->gsfTrack())
0144 << "\t" << (eleRef == eleRef2) << "\t" << (*inputHandle)[eleRef] << std::endl;
0145 #endif
0146 valueVector.push_back((*inputHandle)[eleRef]);
0147 }
0148 }
0149
0150 Map_t::Filler filler(*valueVectorPtr);
0151 filler.insert(referenceHandle, valueVector.begin(), valueVector.end());
0152 filler.fill();
0153
0154 iEvent.put(std::move(valueVectorPtr));
0155 }
0156
0157
0158 void ValueMapTraslator::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0159
0160
0161 edm::ParameterSetDescription desc;
0162 desc.setUnknown();
0163 descriptions.addDefault(desc);
0164 }
0165
0166
0167 DEFINE_FWK_MODULE(ValueMapTraslator);