Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:38

0001 // -*- C++ -*-
0002 //
0003 // Package:    ValueMapTraslator
0004 // Class:      ValueMapTraslator
0005 //
0006 /**\class ValueMapTraslator ValueMapTraslator.cc Calibration/ValueMapTraslator/src/ValueMapTraslator.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Shervin Nourbakhsh,32 4-C03,+41227672087,
0015 //         Created:  Sat Jul 13 15:40:56 CEST 2013
0016 // $Id$
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
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 //#define DEBUG
0037 //
0038 // class declaration
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   // ----------member data ---------------------------
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 // constants, enums and typedefs
0066 //
0067 
0068 //
0069 // static data member definitions
0070 //
0071 
0072 //
0073 // constructors and destructor
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   //now do what ever other initialization is needed
0081   referenceToken_ = consumes<reco::GsfElectronCollection>(referenceCollectionTAG);
0082   oldreferenceToken_ = consumes<reco::GsfElectronCollection>(oldreferenceCollectionTAG);
0083   inputToken_ = consumes<Map_t>(inputCollectionTAG);
0084   /// \todo outputCollectionName = inputCollection+postfix
0085   produces<Map_t>(outputCollectionName);
0086 }
0087 
0088 ValueMapTraslator::~ValueMapTraslator() {
0089   // do anything here that needs to be done at desctruction time
0090   // (e.g. close files, deallocate resources etc.)
0091 }
0092 
0093 //
0094 // member functions
0095 //
0096 
0097 // ------------ method called to produce the data  ------------
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       //       valueVector.push_back((valueMap_itr[i])); //valueMap_itr-inputHandle->begin()]));
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       //if(electronNew->GsfTrackF
0133       if (electron->gsfTrack() != electronNew->gsfTrack())
0134         continue;  ///< requires that the track is the same, so I'm sure the electron object is the same. This to avoid the case when two electrons have the same eta and phi at the vtx
0135       //if(fabs(electronNew->eta() - electron->eta())>0.0001) continue;
0136       //if(fabs(electronNew->phi() - electron->phi())>0.0001) continue;
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]);  //valueMap_itr-inputHandle->begin()]));
0147     }
0148   }
0149   //#endif
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 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0158 void ValueMapTraslator::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0159   //The following says we do not know what parameters are allowed so do no validation
0160   // Please change this to state exactly what you do use, even if it is no parameters
0161   edm::ParameterSetDescription desc;
0162   desc.setUnknown();
0163   descriptions.addDefault(desc);
0164 }
0165 
0166 //define this as a plug-in
0167 DEFINE_FWK_MODULE(ValueMapTraslator);