CMS 3D CMS Logo

HGCalPhotonIDValueMapProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoEgamma/EgammaTools
4 // Class: HGCalPhotonIDValueMapProducer
5 //
13 //
14 // Original Author: Nicholas Charles Smith
15 // Created: Wed, 05 Apr 2017 12:17:43 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
33 
36 
39 
41 public:
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47 private:
48  void beginStream(edm::StreamID) override;
49  void produce(edm::Event&, const edm::EventSetup&) override;
50  void endStream() override;
51 
52  // ----------member data ---------------------------
54  float radius_;
55 
56  static const std::vector<std::string> valuesProduced_;
57  std::map<const std::string, std::vector<float>> maps_;
58 
59  std::unique_ptr<HGCalEgammaIDHelper> phoIDHelper_;
60 };
61 
62 // All the ValueMap names to output are defined in the auto-generated python cfi
63 // so that potential consumers can configure themselves in a simple manner
64 // Would be cool to use compile-time validation, but need constexpr strings, e.g. std::string_view in C++17
65 const std::vector<std::string> HGCalPhotonIDValueMapProducer::valuesProduced_ = {
66  "seedEt", "seedEnergy", "seedEnergyEE", "seedEnergyFH", "seedEnergyBH",
67  "pcaEig1", "pcaEig2", "pcaEig3", "pcaSig1", "pcaSig2",
68  "pcaSig3", "sigmaUU", "sigmaVV", "sigmaEE", "sigmaPP",
69  "nLayers", "firstLayer", "lastLayer", "e4oEtot", "layerEfrac10",
70  "layerEfrac90", "measuredDepth", "expectedDepth", "expectedSigma", "depthCompatibility",
71  "caloIsoRing0", "caloIsoRing1", "caloIsoRing2", "caloIsoRing3", "caloIsoRing4",
72 };
73 
75  : photonsToken_(consumes(iConfig.getParameter<edm::InputTag>("photons"))),
76  radius_(iConfig.getParameter<double>("pcaRadius")) {
77  for (const auto& key : valuesProduced_) {
78  maps_[key] = {};
79  produces<edm::ValueMap<float>>(key);
80  }
81 
82  phoIDHelper_ = std::make_unique<HGCalEgammaIDHelper>(iConfig, consumesCollector());
83 }
84 
86 
87 // ------------ method called to produce the data ------------
89  using namespace edm;
90 
91  auto photonsH = iEvent.getHandle(photonsToken_);
92 
93  // Clear previous map
94  for (auto&& kv : maps_) {
95  kv.second.clear();
96  kv.second.reserve(photonsH->size());
97  }
98 
99  // Set up helper tool
100  phoIDHelper_->eventInit(iEvent, iSetup);
101 
102  for (const auto& pho : *photonsH) {
103  if (pho.isEB()) {
104  // Fill some dummy value
105  for (auto&& kv : maps_) {
106  kv.second.push_back(0.);
107  }
108  } else {
109  phoIDHelper_->computeHGCAL(pho, radius_);
110 
111  // check the PCA has worked out
112  if (phoIDHelper_->sigmaUU() == -1) {
113  for (auto&& kv : maps_) {
114  kv.second.push_back(0.);
115  }
116  continue;
117  }
118 
119  hgcal::LongDeps ld(phoIDHelper_->energyPerLayer(radius_, true));
120  float measuredDepth, expectedDepth, expectedSigma;
121  float depthCompatibility =
122  phoIDHelper_->clusterDepthCompatibility(ld, measuredDepth, expectedDepth, expectedSigma);
123 
124  // Fill here all the ValueMaps from their appropriate functions
125 
126  // energies calculated in an cylinder around the axis of the pho cluster
127  float seed_tot_energy = ld.energyEE() + ld.energyFH() + ld.energyBH();
128  const double div_cosh_eta =
129  pho.superCluster()->seed()->position().rho() / pho.superCluster()->seed()->position().r();
130  maps_["seedEt"].push_back(seed_tot_energy * div_cosh_eta);
131  maps_["seedEnergy"].push_back(seed_tot_energy);
132  maps_["seedEnergyEE"].push_back(ld.energyEE());
133  maps_["seedEnergyFH"].push_back(ld.energyFH());
134  maps_["seedEnergyBH"].push_back(ld.energyBH());
135 
136  // Cluster shapes
137  // PCA related
138  maps_["pcaEig1"].push_back(phoIDHelper_->eigenValues()(0));
139  maps_["pcaEig2"].push_back(phoIDHelper_->eigenValues()(1));
140  maps_["pcaEig3"].push_back(phoIDHelper_->eigenValues()(2));
141  maps_["pcaSig1"].push_back(phoIDHelper_->sigmas()(0));
142  maps_["pcaSig2"].push_back(phoIDHelper_->sigmas()(1));
143  maps_["pcaSig3"].push_back(phoIDHelper_->sigmas()(2));
144 
145  // transverse shapes
146  maps_["sigmaUU"].push_back(phoIDHelper_->sigmaUU());
147  maps_["sigmaVV"].push_back(phoIDHelper_->sigmaVV());
148  maps_["sigmaEE"].push_back(phoIDHelper_->sigmaEE());
149  maps_["sigmaPP"].push_back(phoIDHelper_->sigmaPP());
150 
151  // long profile
152  maps_["nLayers"].push_back(ld.nLayers());
153  maps_["firstLayer"].push_back(ld.firstLayer());
154  maps_["lastLayer"].push_back(ld.lastLayer());
155  maps_["e4oEtot"].push_back(ld.e4oEtot());
156  maps_["layerEfrac10"].push_back(ld.layerEfrac10());
157  maps_["layerEfrac90"].push_back(ld.layerEfrac90());
158 
159  // depth
160  maps_["measuredDepth"].push_back(measuredDepth);
161  maps_["expectedDepth"].push_back(expectedDepth);
162  maps_["expectedSigma"].push_back(expectedSigma);
163  maps_["depthCompatibility"].push_back(depthCompatibility);
164 
165  // Isolation
166  maps_["caloIsoRing0"].push_back(phoIDHelper_->getIsolationRing(0));
167  maps_["caloIsoRing1"].push_back(phoIDHelper_->getIsolationRing(1));
168  maps_["caloIsoRing2"].push_back(phoIDHelper_->getIsolationRing(2));
169  maps_["caloIsoRing3"].push_back(phoIDHelper_->getIsolationRing(3));
170  maps_["caloIsoRing4"].push_back(phoIDHelper_->getIsolationRing(4));
171  }
172  }
173 
174  // Check we didn't make up a new variable and forget it in the constructor
175  // (or some other pathology)
176  if (maps_.size() != valuesProduced_.size()) {
177  throw cms::Exception("HGCalPhotonIDValueMapProducer")
178  << "We have a miscoded value map producer, since map size changed";
179  }
180 
181  for (auto&& kv : maps_) {
182  // Check we didn't forget any values
183  if (kv.second.size() != photonsH->size()) {
184  throw cms::Exception("HGCalPhotonIDValueMapProducer")
185  << "We have a miscoded value map producer, since the variable " << kv.first << " wasn't filled.";
186  }
187  // Do the filling
188  auto out = std::make_unique<edm::ValueMap<float>>();
190  filler.insert(photonsH, kv.second.begin(), kv.second.end());
191  filler.fill();
192  // and put it into the event
193  iEvent.put(std::move(out), kv.first);
194  }
195 }
196 
197 // ------------ method called once each stream before processing any runs, lumis or events ------------
199 
200 // ------------ method called once each stream after processing all runs, lumis and events ------------
202 
203 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
205  // hgcalPhotonIDValueMap
207  desc.add<edm::InputTag>("photons", edm::InputTag("photonsFromMultiCl"));
208  desc.add<double>("pcaRadius", 3.0);
209  desc.add<std::vector<std::string>>("variables", valuesProduced_);
210  desc.add<std::vector<double>>("dEdXWeights")
211  ->setComment("This must be copied from dEdX_weights in RecoLocalCalo.HGCalRecProducers.HGCalRecHit_cfi");
212  desc.add<unsigned int>("isoNRings", 5);
213  desc.add<double>("isoDeltaR", 0.15);
214  desc.add<double>("isoDeltaRmin", 0.0);
215  desc.add<edm::InputTag>("EERecHits", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
216  desc.add<edm::InputTag>("FHRecHits", edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
217  desc.add<edm::InputTag>("BHRecHits", edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
218  desc.add<edm::InputTag>("hitMapTag", edm::InputTag("hgcalRecHitMapProducer"));
219  descriptions.add("hgcalPhotonIDValueMap", desc);
220 }
221 
222 //define this as a plug-in
edm::StreamID
Definition: StreamID.h:30
HGCalEgammaIDHelper.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HGCalPhotonIDValueMapProducer::radius_
float radius_
Definition: HGCalPhotonIDValueMapProducer.cc:54
HGCalPhotonIDValueMapProducer::phoIDHelper_
std::unique_ptr< HGCalEgammaIDHelper > phoIDHelper_
Definition: HGCalPhotonIDValueMapProducer.cc:59
EDProducer.h
LongDeps.h
PhotonFwd.h
HGCalPhotonIDValueMapProducer::~HGCalPhotonIDValueMapProducer
~HGCalPhotonIDValueMapProducer() override
Definition: HGCalPhotonIDValueMapProducer.cc:85
MakerMacros.h
Photon.h
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
HGCalPhotonIDValueMapProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HGCalPhotonIDValueMapProducer.cc:88
HGCalPhotonIDValueMapProducer::HGCalPhotonIDValueMapProducer
HGCalPhotonIDValueMapProducer(const edm::ParameterSet &)
Definition: HGCalPhotonIDValueMapProducer.cc:74
HGCalPhotonIDValueMapProducer::beginStream
void beginStream(edm::StreamID) override
Definition: HGCalPhotonIDValueMapProducer.cc:198
HGCalPhotonIDValueMapProducer
Definition: HGCalPhotonIDValueMapProducer.cc:40
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
hgcal::LongDeps
Definition: LongDeps.h:14
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
HGCalPhotonIDValueMapProducer::valuesProduced_
static const std::vector< std::string > valuesProduced_
Definition: HGCalPhotonIDValueMapProducer.cc:56
ValueMap.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
Exception
Definition: hltDiff.cc:245
HGCalPhotonIDValueMapProducer::maps_
std::map< const std::string, std::vector< float > > maps_
Definition: HGCalPhotonIDValueMapProducer.cc:57
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
StreamID.h
HGCalPhotonIDValueMapProducer::photonsToken_
edm::EDGetTokenT< edm::View< reco::Photon > > photonsToken_
Definition: HGCalPhotonIDValueMapProducer.cc:53
edm::InputTag
Definition: InputTag.h:15
HGCalPhotonIDValueMapProducer::endStream
void endStream() override
Definition: HGCalPhotonIDValueMapProducer.cc:201
HGCalPhotonIDValueMapProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HGCalPhotonIDValueMapProducer.cc:204