CMS 3D CMS Logo

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