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