CMS 3D CMS Logo

ValueMapTraslator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ValueMapTraslator
4 // Class: ValueMapTraslator
5 //
13 //
14 // Original Author: Shervin Nourbakhsh,32 4-C03,+41227672087,
15 // Created: Sat Jul 13 15:40:56 CEST 2013
16 // $Id$
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
27 
30 
32 
35 
36 //#define DEBUG
37 //
38 // class declaration
39 //
40 
42  typedef double value_t;
44 
45 public:
46  explicit ValueMapTraslator(const edm::ParameterSet&);
47  ~ValueMapTraslator() override;
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51 private:
52  void produce(edm::Event&, const edm::EventSetup&) override;
53 
54  // ----------member data ---------------------------
58 
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 //
69 // static data member definitions
70 //
71 
72 //
73 // constructors and destructor
74 //
76  : referenceCollectionTAG(iConfig.getParameter<edm::InputTag>("referenceCollection")),
77  oldreferenceCollectionTAG(iConfig.getParameter<edm::InputTag>("oldreferenceCollection")),
78  inputCollectionTAG(iConfig.getParameter<edm::InputTag>("inputCollection")),
79  outputCollectionName(iConfig.getParameter<std::string>("outputCollection")) {
80  //now do what ever other initialization is needed
81  referenceToken_ = consumes<reco::GsfElectronCollection>(referenceCollectionTAG);
82  oldreferenceToken_ = consumes<reco::GsfElectronCollection>(oldreferenceCollectionTAG);
83  inputToken_ = consumes<Map_t>(inputCollectionTAG);
85  produces<Map_t>(outputCollectionName);
86 }
87 
89  // do anything here that needs to be done at desctruction time
90  // (e.g. close files, deallocate resources etc.)
91 }
92 
93 //
94 // member functions
95 //
96 
97 // ------------ method called to produce the data ------------
99  using namespace edm;
100  std::vector<value_t> valueVector;
101  auto valueVectorPtr = std::make_unique<Map_t>();
102 
103  //------------------------------
104  Handle<reco::GsfElectronCollection> referenceHandle;
105  Handle<reco::GsfElectronCollection> oldreferenceHandle;
106  Handle<Map_t> inputHandle;
107 
108  iEvent.getByToken(referenceToken_, referenceHandle);
109  iEvent.getByToken(oldreferenceToken_, oldreferenceHandle);
110  iEvent.getByToken(inputToken_, inputHandle);
111 
112  for (Map_t::const_iterator valueMap_itr = inputHandle->begin(); valueMap_itr != inputHandle->end(); valueMap_itr++) {
113  for (unsigned int i = 0; i < valueMap_itr.size(); i++) {
114 #ifdef DEBUG
115  std::cout << valueMap_itr[i] << std::endl;
116 #endif
117  // valueVector.push_back((valueMap_itr[i])); //valueMap_itr-inputHandle->begin()]));
118  }
119  break;
120  }
121 
122 #ifdef DEBUG
123  std::cout << "Size: " << referenceHandle->size() << "\t" << oldreferenceHandle->size() << "\t" << inputHandle->size()
124  << "\t" << valueVector.size() << std::endl;
125 #endif
126  for (reco::GsfElectronCollection::const_iterator electronNew = referenceHandle->begin();
127  electronNew != referenceHandle->end();
128  electronNew++) {
129  for (reco::GsfElectronCollection::const_iterator electron = oldreferenceHandle->begin();
130  electron != oldreferenceHandle->end();
131  electron++) {
132  //if(electronNew->GsfTrackF
133  if (electron->gsfTrack() != electronNew->gsfTrack())
134  continue;
135  //if(fabs(electronNew->eta() - electron->eta())>0.0001) continue;
136  //if(fabs(electronNew->phi() - electron->phi())>0.0001) continue;
137 
138  reco::GsfElectronRef eleRef(oldreferenceHandle, electron - oldreferenceHandle->begin());
139  reco::GsfElectronRef eleRef2(referenceHandle, electronNew - referenceHandle->begin());
140 
141 #ifdef DEBUG
142  std::cout << eleRef->eta() << "\t" << eleRef2->eta() << "\t" << eleRef->phi() << "\t" << eleRef2->phi() << "\t"
143  << eleRef->energy() << "\t" << eleRef2->energy() << "\t" << (eleRef->gsfTrack() == eleRef2->gsfTrack())
144  << "\t" << (eleRef == eleRef2) << "\t" << (*inputHandle)[eleRef] << std::endl;
145 #endif
146  valueVector.push_back((*inputHandle)[eleRef]); //valueMap_itr-inputHandle->begin()]));
147  }
148  }
149  //#endif
150  Map_t::Filler filler(*valueVectorPtr);
151  filler.insert(referenceHandle, valueVector.begin(), valueVector.end());
152  filler.fill();
153 
154  iEvent.put(std::move(valueVectorPtr));
155 }
156 
157 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
159  //The following says we do not know what parameters are allowed so do no validation
160  // Please change this to state exactly what you do use, even if it is no parameters
162  desc.setUnknown();
163  descriptions.addDefault(desc);
164 }
165 
166 //define this as a plug-in
ValueMapTraslator::referenceCollectionTAG
edm::InputTag referenceCollectionTAG
Definition: ValueMapTraslator.cc:55
mps_fire.i
i
Definition: mps_fire.py:428
EDProducer.h
edm::EDGetTokenT< reco::GsfElectronCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ValueMapTraslator::ValueMapTraslator
ValueMapTraslator(const edm::ParameterSet &)
Definition: ValueMapTraslator.cc:75
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
ValueMapTraslator::~ValueMapTraslator
~ValueMapTraslator() override
Definition: ValueMapTraslator.cc:88
ValueMapTraslator::Map_t
edm::ValueMap< value_t > Map_t
Definition: ValueMapTraslator.cc:43
edm::Handle< reco::GsfElectronCollection >
edm::Ref
Definition: AssociativeIterator.h:58
ValueMapTraslator::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ValueMapTraslator.cc:98
MakerMacros.h
edm::ValueMap::const_iterator
Definition: ValueMap.h:170
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
metsig::electron
Definition: SignAlgoResolutions.h:48
ValueMapTraslator::outputCollectionName
std::string outputCollectionName
Definition: ValueMapTraslator.cc:57
ValueMapTraslator::inputCollectionTAG
edm::InputTag inputCollectionTAG
Definition: ValueMapTraslator.cc:56
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ValueMapTraslator::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ValueMapTraslator.cc:158
ValueMapTraslator
Definition: ValueMapTraslator.cc:41
GsfElectronFwd.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
iEvent
int iEvent
Definition: GenABIO.cc:224
ValueMapTraslator::oldreferenceToken_
edm::EDGetTokenT< reco::GsfElectronCollection > oldreferenceToken_
Definition: ValueMapTraslator.cc:60
ValueMapTraslator::referenceToken_
edm::EDGetTokenT< reco::GsfElectronCollection > referenceToken_
Definition: ValueMapTraslator.cc:59
edm::EventSetup
Definition: EventSetup.h:57
ValueMap.h
ValueMapTraslator::oldreferenceCollectionTAG
edm::InputTag oldreferenceCollectionTAG
Definition: ValueMapTraslator.cc:55
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
edm::ValueMap
Definition: ValueMap.h:107
edm::EDProducer
Definition: EDProducer.h:35
Phase1L1TJetCalibrator_cfi.outputCollectionName
outputCollectionName
Definition: Phase1L1TJetCalibrator_cfi.py:782
ConsumesCollector.h
edm::helper::Filler
Definition: ValueMap.h:22
ValueMapTraslator::value_t
double value_t
Definition: ValueMapTraslator.cc:42
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
ValueMapTraslator::inputToken_
edm::EDGetTokenT< Map_t > inputToken_
Definition: ValueMapTraslator.cc:61
edm::InputTag
Definition: InputTag.h:15