CMS 3D CMS Logo

LowPtGsfElectronSeedValueMapsProducer.cc
Go to the documentation of this file.
19 
20 #include <vector>
21 #include <string>
22 
24 public:
26 
27  void produce(edm::Event&, const edm::EventSetup&) override;
28 
30 
31 private:
34  std::vector<std::string> names_;
35  const bool rekey_;
37  std::vector<edm::EDGetTokenT<edm::ValueMap<float> > > floatValueMaps_;
38 };
39 
41 //
43  : gsfTracks_(),
44  preIdsValueMap_(),
45  names_(),
46  rekey_(conf.getParameter<bool>("rekey")),
47  gsfElectrons_(),
48  floatValueMaps_() {
49  if (rekey_) {
50  gsfElectrons_ = consumes<reco::GsfElectronCollection>(conf.getParameter<edm::InputTag>("gsfElectrons"));
51  std::vector<edm::InputTag> tags = conf.getParameter<std::vector<edm::InputTag> >("floatValueMaps");
52  for (const auto& tag : tags) {
54  tags, [this](edm::InputTag const& tag) { return consumes<edm::ValueMap<float> >(tag); });
55  names_.push_back(tag.instance());
56  produces<edm::ValueMap<float> >(tag.instance());
57  }
58  } else {
59  gsfTracks_ = consumes<reco::GsfTrackCollection>(conf.getParameter<edm::InputTag>("gsfTracks"));
60  preIdsValueMap_ = consumes<edm::ValueMap<reco::PreIdRef> >(conf.getParameter<edm::InputTag>("preIdsValueMap"));
61  names_ = conf.getParameter<std::vector<std::string> >("ModelNames");
62  for (const auto& name : names_) {
63  produces<edm::ValueMap<float> >(name);
64  }
65  }
66 }
67 
69 //
71  if (rekey_ == false) {
72  // TRANSFORM VALUEMAP OF PREID OBJECTS KEYED BY KF TRACK ...
73  // .. INTO VALUEMAP OF FLOATS (BDT SCORE) KEYED BY GSF TRACK ...
74 
75  // Retrieve GsfTracks from Event
76  auto gsfTracks = event.getHandle(gsfTracks_);
77 
78  // Retrieve PreIds from Event
79  auto preIdsValueMap = event.getHandle(preIdsValueMap_);
80 
81  // Iterate through GsfTracks, extract BDT output, and store result in ValueMap for each model
82  std::vector<std::vector<float> > output;
83  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
84  output.push_back(std::vector<float>(gsfTracks->size(), -999.));
85  }
86  auto const& gsfTracksV = *gsfTracks;
87  for (unsigned int igsf = 0; igsf < gsfTracksV.size(); igsf++) {
88  const reco::GsfTrack& gsf = gsfTracksV[igsf];
89  if (gsf.extra().isNonnull() && gsf.extra()->seedRef().isNonnull()) {
90  reco::ElectronSeedRef seed = gsf.extra()->seedRef().castTo<reco::ElectronSeedRef>();
91  if (seed.isNonnull() && seed->ctfTrack().isNonnull()) {
92  const reco::PreIdRef preid = (*preIdsValueMap)[seed->ctfTrack()];
93  if (preid.isNonnull()) {
94  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
95  output[iname][igsf] = preid->mva(iname);
96  }
97  }
98  }
99  }
100  }
101 
102  // Create and put ValueMap in Event
103  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
104  auto ptr = std::make_unique<edm::ValueMap<float> >(edm::ValueMap<float>());
106  filler.insert(gsfTracks, output[iname].begin(), output[iname].end());
107  filler.fill();
108  event.put(std::move(ptr), names_[iname]);
109  }
110 
111  } else {
112  // TRANSFORM VALUEMAP OF FLOATS (BDT SCORE) KEYED BY GSF TRACK ...
113  // .. INTO VALUEMAP OF FLOATS (BDT SCORE) KEYED BY GSF ELECTRON ...
114 
115  // Retrieve GsfElectrons from Event
116  auto gsfElectrons = event.getHandle(gsfElectrons_);
117 
118  // Retrieve float ValueMaps from Event
119  for (unsigned int idx = 0; idx < names_.size(); ++idx) {
120  // Extract ValueMap from Event
121  auto const& floatValueMap = event.get(floatValueMaps_[idx]);
122 
123  // Store BDT scores in vector
124  std::vector<float> output(gsfElectrons->size(), -99.);
125  auto const& gsfElectronsV = *gsfElectrons;
126  for (unsigned int iele = 0; iele < gsfElectronsV.size(); iele++) {
127  const reco::GsfElectron& ele = gsfElectronsV[iele];
129  output[iele] = floatValueMap[gsf];
130  }
131  // Create and put ValueMap in Event
132  auto ptr = std::make_unique<edm::ValueMap<float> >(edm::ValueMap<float>());
134  filler.insert(gsfElectrons, output.begin(), output.end());
135  filler.fill();
136  event.put(std::move(ptr), names_[idx]);
137  }
138  }
139 }
140 
142 //
145  desc.add<edm::InputTag>("gsfTracks", edm::InputTag("lowPtGsfEleGsfTracks"));
146  desc.add<edm::InputTag>("preIdsValueMap", edm::InputTag("lowPtGsfElectronSeeds"));
147  desc.add<std::vector<std::string> >("ModelNames", {"unbiased", "ptbiased"});
148  desc.add<bool>("rekey", false);
149  desc.add<edm::InputTag>("gsfElectrons", edm::InputTag());
150  desc.add<std::vector<edm::InputTag> >("floatValueMaps", std::vector<edm::InputTag>());
151  descriptions.add("lowPtGsfElectronSeedValueMaps", desc);
152 }
153 
155 //
ConfigurationDescriptions.h
LowPtGsfElectronSeedValueMapsProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:70
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
reco::GsfElectron::gsfTrack
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:163
LowPtGsfElectronSeedValueMapsProducer::preIdsValueMap_
edm::EDGetTokenT< edm::ValueMap< reco::PreIdRef > > preIdsValueMap_
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:33
GsfTrackExtra.h
MessageLogger.h
ESHandle.h
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
edm::EDGetTokenT< reco::GsfTrackCollection >
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
LowPtGsfElectronSeedValueMapsProducer::LowPtGsfElectronSeedValueMapsProducer
LowPtGsfElectronSeedValueMapsProducer(const edm::ParameterSet &)
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:42
LowPtGsfElectronSeedValueMapsProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:143
electronIsolatorFromEffectiveArea_cfi.gsfElectrons
gsfElectrons
Definition: electronIsolatorFromEffectiveArea_cfi.py:4
LowPtGsfElectronSeedValueMapsProducer::rekey_
const bool rekey_
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:35
ElectronSeedFwd.h
edm::Ref< ElectronSeedCollection >
PreId.h
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
fileCollector.seed
seed
Definition: fileCollector.py:127
reco::GsfTrack
Definition: GsfTrack.h:12
MakerMacros.h
LowPtGsfElectronSeedValueMapsProducer::names_
std::vector< std::string > names_
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:34
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
LowPtGsfElectronSeedValueMapsProducer::gsfElectrons_
edm::EDGetTokenT< reco::GsfElectronCollection > gsfElectrons_
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:36
mps_fire.end
end
Definition: mps_fire.py:242
reco::GsfElectron
Definition: GsfElectron.h:34
ecalDrivenGsfElectronCoresFromMultiCl_cff.gsfTracks
gsfTracks
Definition: ecalDrivenGsfElectronCoresFromMultiCl_cff.py:4
ParameterSetDescription.h
GsfElectron.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::vector_transform
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
LowPtGsfElectronSeedValueMapsProducer::floatValueMaps_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > floatValueMaps_
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:37
edm::ParameterSet
Definition: ParameterSet.h:47
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
GsfTrack.h
edm::stream::EDProducer
Definition: EDProducer.h:38
ntupleEnum.gsf
gsf
Definition: ntupleEnum.py:49
edm::EventSetup
Definition: EventSetup.h:58
PreIdFwd.h
LowPtGsfElectronSeedValueMapsProducer
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:23
InputTag.h
ValueMap.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
GsfTrackFwd.h
transform.h
edm::ValueMap< float >
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
triggerMatcherToHLTDebug_cfi.tags
tags
Definition: triggerMatcherToHLTDebug_cfi.py:9
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
ElectronSeed.h
LowPtGsfElectronSeedValueMapsProducer::gsfTracks_
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTracks_
Definition: LowPtGsfElectronSeedValueMapsProducer.cc:32