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<edm::View<reco::Photon>>(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_.reset(new HGCalEgammaIDHelper(iConfig, consumesCollector()));
83 }
84 
86 
87 // ------------ method called to produce the data ------------
89  using namespace edm;
90 
92  iEvent.getByToken(photonsToken_, photonsH);
93 
94  // Clear previous map
95  for (auto&& kv : maps_) {
96  kv.second.clear();
97  kv.second.reserve(photonsH->size());
98  }
99 
100  // Set up helper tool
101  phoIDHelper_->eventInit(iEvent, iSetup);
102 
103  for (const auto& pho : *photonsH) {
104  if (pho.isEB()) {
105  // Fill some dummy value
106  for (auto&& kv : maps_) {
107  kv.second.push_back(0.);
108  }
109  } else {
110  phoIDHelper_->computeHGCAL(pho, radius_);
111 
112  // check the PCA has worked out
113  if (phoIDHelper_->sigmaUU() == -1) {
114  for (auto&& kv : maps_) {
115  kv.second.push_back(0.);
116  }
117  continue;
118  }
119 
120  hgcal::LongDeps ld(phoIDHelper_->energyPerLayer(radius_, true));
121  float measuredDepth, expectedDepth, expectedSigma;
122  float depthCompatibility =
123  phoIDHelper_->clusterDepthCompatibility(ld, measuredDepth, expectedDepth, expectedSigma);
124 
125  // Fill here all the ValueMaps from their appropriate functions
126 
127  // energies calculated in an cylinder around the axis of the pho cluster
128  float seed_tot_energy = ld.energyEE() + ld.energyFH() + ld.energyBH();
129  const double div_cosh_eta =
130  pho.superCluster()->seed()->position().rho() / pho.superCluster()->seed()->position().r();
131  maps_["seedEt"].push_back(seed_tot_energy * div_cosh_eta);
132  maps_["seedEnergy"].push_back(seed_tot_energy);
133  maps_["seedEnergyEE"].push_back(ld.energyEE());
134  maps_["seedEnergyFH"].push_back(ld.energyFH());
135  maps_["seedEnergyBH"].push_back(ld.energyBH());
136 
137  // Cluster shapes
138  // PCA related
139  maps_["pcaEig1"].push_back(phoIDHelper_->eigenValues()(0));
140  maps_["pcaEig2"].push_back(phoIDHelper_->eigenValues()(1));
141  maps_["pcaEig3"].push_back(phoIDHelper_->eigenValues()(2));
142  maps_["pcaSig1"].push_back(phoIDHelper_->sigmas()(0));
143  maps_["pcaSig2"].push_back(phoIDHelper_->sigmas()(1));
144  maps_["pcaSig3"].push_back(phoIDHelper_->sigmas()(2));
145 
146  // transverse shapes
147  maps_["sigmaUU"].push_back(phoIDHelper_->sigmaUU());
148  maps_["sigmaVV"].push_back(phoIDHelper_->sigmaVV());
149  maps_["sigmaEE"].push_back(phoIDHelper_->sigmaEE());
150  maps_["sigmaPP"].push_back(phoIDHelper_->sigmaPP());
151 
152  // long profile
153  maps_["nLayers"].push_back(ld.nLayers());
154  maps_["firstLayer"].push_back(ld.firstLayer());
155  maps_["lastLayer"].push_back(ld.lastLayer());
156  maps_["e4oEtot"].push_back(ld.e4oEtot());
157  maps_["layerEfrac10"].push_back(ld.layerEfrac10());
158  maps_["layerEfrac90"].push_back(ld.layerEfrac90());
159 
160  // depth
161  maps_["measuredDepth"].push_back(measuredDepth);
162  maps_["expectedDepth"].push_back(expectedDepth);
163  maps_["expectedSigma"].push_back(expectedSigma);
164  maps_["depthCompatibility"].push_back(depthCompatibility);
165 
166  // Isolation
167  maps_["caloIsoRing0"].push_back(phoIDHelper_->getIsolationRing(0));
168  maps_["caloIsoRing1"].push_back(phoIDHelper_->getIsolationRing(1));
169  maps_["caloIsoRing2"].push_back(phoIDHelper_->getIsolationRing(2));
170  maps_["caloIsoRing3"].push_back(phoIDHelper_->getIsolationRing(3));
171  maps_["caloIsoRing4"].push_back(phoIDHelper_->getIsolationRing(4));
172  }
173  }
174 
175  // Check we didn't make up a new variable and forget it in the constructor
176  // (or some other pathology)
177  if (maps_.size() != valuesProduced_.size()) {
178  throw cms::Exception("HGCalPhotonIDValueMapProducer")
179  << "We have a miscoded value map producer, since map size changed";
180  }
181 
182  for (auto&& kv : maps_) {
183  // Check we didn't forget any values
184  if (kv.second.size() != photonsH->size()) {
185  throw cms::Exception("HGCalPhotonIDValueMapProducer")
186  << "We have a miscoded value map producer, since the variable " << kv.first << " wasn't filled.";
187  }
188  // Do the filling
189  auto out = std::make_unique<edm::ValueMap<float>>();
191  filler.insert(photonsH, kv.second.begin(), kv.second.end());
192  filler.fill();
193  // and put it into the event
194  iEvent.put(std::move(out), kv.first);
195  }
196 }
197 
198 // ------------ method called once each stream before processing any runs, lumis or events ------------
200 
201 // ------------ method called once each stream after processing all runs, lumis and events ------------
203 
204 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
206  // hgcalPhotonIDValueMap
208  desc.add<edm::InputTag>("photons", edm::InputTag("photonsFromMultiCl"));
209  desc.add<double>("pcaRadius", 3.0);
210  desc.add<std::vector<std::string>>("variables", valuesProduced_);
211  desc.add<std::vector<double>>("dEdXWeights")
212  ->setComment("This must be copied from dEdX_weights in RecoLocalCalo.HGCalRecProducers.HGCalRecHit_cfi");
213  desc.add<unsigned int>("isoNRings", 5);
214  desc.add<double>("isoDeltaR", 0.15);
215  desc.add<double>("isoDeltaRmin", 0.0);
216  desc.add<edm::InputTag>("EERecHits", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
217  desc.add<edm::InputTag>("FHRecHits", edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
218  desc.add<edm::InputTag>("BHRecHits", edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
219  descriptions.add("hgcalPhotonIDValueMap", desc);
220 }
221 
222 //define this as a plug-in
edm::StreamID
Definition: StreamID.h:30
HGCalEgammaIDHelper
Definition: HGCalEgammaIDHelper.h:31
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
HGCalEgammaIDHelper.h
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
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
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
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:199
HGCalPhotonIDValueMapProducer
Definition: HGCalPhotonIDValueMapProducer.cc:40
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
hgcal::LongDeps
Definition: LongDeps.h:14
Photon
Definition: Photon.py:1
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
HGCalPhotonIDValueMapProducer::valuesProduced_
static const std::vector< std::string > valuesProduced_
Definition: HGCalPhotonIDValueMapProducer.cc:56
ValueMap.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
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:202
HGCalPhotonIDValueMapProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HGCalPhotonIDValueMapProducer.cc:205