CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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("photonsHGC"));
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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< HGCalEgammaIDHelper > phoIDHelper_
void produce(edm::Event &, const edm::EventSetup &) override
HGCalPhotonIDValueMapProducer(const edm::ParameterSet &)
void beginStream(edm::StreamID) override
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
int iEvent
Definition: GenABIO.cc:224
def move
Definition: eostools.py:511
tuple key
prepare the HTCondor submission files and eventually submit them
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static const std::vector< std::string > valuesProduced_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< edm::View< reco::Photon > > photonsToken_
std::map< const std::string, std::vector< float > > maps_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)