CMS 3D CMS Logo

PFECALSuperClusterProducer.cc
Go to the documentation of this file.
1 
34 #include "TVector2.h"
35 
36 #include <memory>
37 #include <vector>
38 
39 /*
40  * class PFECALSuperClusterProducer
41  * author Nicolas Chanon
42  * Additional authors for Mustache: Y. Gershtein, R. Patel, L. Gray
43  * Additional authors for DeepSC: D.Valsecchi, B.Marzocchi
44  * date July 2012
45  * updates Feb 2022
46  */
47 
48 class PFECALSuperClusterProducer : public edm::stream::EDProducer<edm::GlobalCache<reco::SCProducerCache>> {
49 public:
51  ~PFECALSuperClusterProducer() override;
52 
53  void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override;
54  void produce(edm::Event&, const edm::EventSetup&) override;
55 
56  static std::unique_ptr<reco::SCProducerCache> initializeGlobalCache(const edm::ParameterSet& config) {
57  return std::make_unique<reco::SCProducerCache>(config);
58  }
59 
60  static void globalEndJob(const reco::SCProducerCache*){};
61 
62  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
63 
64 private:
65  // ----------member data ---------------------------
66 
71 
72  std::shared_ptr<PFEnergyCalibration> thePFEnergyCalibration_;
73 
75  bool verbose_;
76 
85 
86  // OOT photons
88 };
89 
92 
93 using namespace std;
94 
95 using namespace edm;
96 
97 namespace {
98  const std::string ClusterType__BOX("Box");
99  const std::string ClusterType__Mustache("Mustache");
100  const std::string ClusterType__DeepSC("DeepSC");
101 
102  const std::string EnergyWeight__Raw("Raw");
103  const std::string EnergyWeight__CalibratedNoPS("CalibratedNoPS");
104  const std::string EnergyWeight__CalibratedTotal("CalibratedTotal");
105 } // namespace
106 
108  const reco::SCProducerCache* gcache)
109  : superClusterAlgo_(gcache) {
110  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
111 
112  superClusterAlgo_.setUseRegression(iConfig.getParameter<bool>("useRegression"));
113 
114  isOOTCollection_ = iConfig.getParameter<bool>("isOOTCollection");
116 
117  std::string _typename = iConfig.getParameter<std::string>("ClusteringType");
118  if (_typename == ClusterType__BOX) {
120  } else if (_typename == ClusterType__Mustache) {
122  } else if (_typename == ClusterType__DeepSC) {
124  } else {
125  throw cms::Exception("InvalidClusteringType") << "You have not chosen a valid clustering type,"
126  << " please choose from \"Box\" or \"Mustache\" or \"DeepSC\"!";
127  }
128 
129  std::string _weightname = iConfig.getParameter<std::string>("EnergyWeight");
130  if (_weightname == EnergyWeight__Raw) {
132  } else if (_weightname == EnergyWeight__CalibratedNoPS) {
134  } else if (_weightname == EnergyWeight__CalibratedTotal) {
136  } else {
137  throw cms::Exception("InvalidClusteringType") << "You have not chosen a valid energy weighting scheme,"
138  << " please choose from \"Raw\", \"CalibratedNoPS\", or"
139  << " \"CalibratedTotal\"!";
140  }
141 
142  // parameters for clustering
143  bool seedThresholdIsET = iConfig.getParameter<bool>("seedThresholdIsET");
144 
145  bool useDynamicDPhi = iConfig.getParameter<bool>("useDynamicDPhiWindow");
146 
147  double threshPFClusterSeedBarrel = iConfig.getParameter<double>("thresh_PFClusterSeedBarrel");
148  double threshPFClusterBarrel = iConfig.getParameter<double>("thresh_PFClusterBarrel");
149 
150  double threshPFClusterSeedEndcap = iConfig.getParameter<double>("thresh_PFClusterSeedEndcap");
151  double threshPFClusterEndcap = iConfig.getParameter<double>("thresh_PFClusterEndcap");
152 
153  double phiwidthSuperClusterBarrel = iConfig.getParameter<double>("phiwidth_SuperClusterBarrel");
154  double etawidthSuperClusterBarrel = iConfig.getParameter<double>("etawidth_SuperClusterBarrel");
155 
156  double phiwidthSuperClusterEndcap = iConfig.getParameter<double>("phiwidth_SuperClusterEndcap");
157  double etawidthSuperClusterEndcap = iConfig.getParameter<double>("etawidth_SuperClusterEndcap");
158 
159  double doSatelliteClusterMerge = iConfig.getParameter<bool>("doSatelliteClusterMerge");
160  double satelliteClusterSeedThreshold = iConfig.getParameter<double>("satelliteClusterSeedThreshold");
161  double satelliteMajorityFraction = iConfig.getParameter<double>("satelliteMajorityFraction");
162  bool dropUnseedable = iConfig.getParameter<bool>("dropUnseedable");
163 
165  superClusterAlgo_.setUseDynamicDPhi(useDynamicDPhi);
166  // clusteringType and useDynamicDPhi need to be defined before setting the tokens in order to esConsume only the necessary records
167  superClusterAlgo_.setTokens(iConfig, consumesCollector());
168 
172 
173  superClusterAlgo_.setThreshSuperClusterEt(iConfig.getParameter<double>("thresh_SCEt"));
174 
175  superClusterAlgo_.setThreshPFClusterSeedBarrel(threshPFClusterSeedBarrel);
176  superClusterAlgo_.setThreshPFClusterBarrel(threshPFClusterBarrel);
177 
178  superClusterAlgo_.setThreshPFClusterSeedEndcap(threshPFClusterSeedEndcap);
179  superClusterAlgo_.setThreshPFClusterEndcap(threshPFClusterEndcap);
180 
181  superClusterAlgo_.setPhiwidthSuperClusterBarrel(phiwidthSuperClusterBarrel);
182  superClusterAlgo_.setEtawidthSuperClusterBarrel(etawidthSuperClusterBarrel);
183 
184  superClusterAlgo_.setPhiwidthSuperClusterEndcap(phiwidthSuperClusterEndcap);
185  superClusterAlgo_.setEtawidthSuperClusterEndcap(etawidthSuperClusterEndcap);
186 
191 
192  //Load the ECAL energy calibration
193  thePFEnergyCalibration_ = std::make_shared<PFEnergyCalibration>();
195 
196  bool applyCrackCorrections_ = iConfig.getParameter<bool>("applyCrackCorrections");
197  superClusterAlgo_.setCrackCorrections(applyCrackCorrections_);
198 
199  PFBasicClusterCollectionBarrel_ = iConfig.getParameter<string>("PFBasicClusterCollectionBarrel");
200  PFSuperClusterCollectionBarrel_ = iConfig.getParameter<string>("PFSuperClusterCollectionBarrel");
201 
202  PFBasicClusterCollectionEndcap_ = iConfig.getParameter<string>("PFBasicClusterCollectionEndcap");
203  PFSuperClusterCollectionEndcap_ = iConfig.getParameter<string>("PFSuperClusterCollectionEndcap");
204 
205  PFBasicClusterCollectionPreshower_ = iConfig.getParameter<string>("PFBasicClusterCollectionPreshower");
207  iConfig.getParameter<string>("PFSuperClusterCollectionEndcapWithPreshower");
208 
209  PFClusterAssociationEBEE_ = "PFClusterAssociationEBEE";
210  PFClusterAssociationES_ = "PFClusterAssociationES";
211 
212  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionBarrel_);
213  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionEndcapWithPreshower_);
214  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionBarrel_);
215  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionEndcap_);
216  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionPreshower_);
217  produces<edm::ValueMap<reco::CaloClusterPtr>>(PFClusterAssociationEBEE_);
218  produces<edm::ValueMap<reco::CaloClusterPtr>>(PFClusterAssociationES_);
219 }
220 
222 
225 }
226 
228  // update SC parameters
230  // do clustering
233 
234  //build collections of output CaloClusters from the used PFClusters
235  auto caloClustersEB = std::make_unique<reco::CaloClusterCollection>();
236  auto caloClustersEE = std::make_unique<reco::CaloClusterCollection>();
237  auto caloClustersES = std::make_unique<reco::CaloClusterCollection>();
238 
239  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEB; //maps of pfclusters to caloclusters
240  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEE;
241  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapES;
242 
243  //fill calocluster collections and maps
244  for (const auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection())) {
245  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus != ebsc.clustersEnd(); ++pfclus) {
246  if (!pfClusterMapEB.count(*pfclus)) {
247  reco::CaloCluster caloclus(**pfclus);
248  caloClustersEB->push_back(caloclus);
249  pfClusterMapEB[*pfclus] = caloClustersEB->size() - 1;
250  } else {
251  throw cms::Exception("PFECALSuperClusterProducer::produce")
252  << "Found an EB pfcluster matched to more than one EB supercluster!" << std::dec << std::endl;
253  }
254  }
255  }
256  for (const auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection())) {
257  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus != eesc.clustersEnd(); ++pfclus) {
258  if (!pfClusterMapEE.count(*pfclus)) {
259  reco::CaloCluster caloclus(**pfclus);
260  caloClustersEE->push_back(caloclus);
261  pfClusterMapEE[*pfclus] = caloClustersEE->size() - 1;
262  } else {
263  throw cms::Exception("PFECALSuperClusterProducer::produce")
264  << "Found an EE pfcluster matched to more than one EE supercluster!" << std::dec << std::endl;
265  }
266  }
267  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus != eesc.preshowerClustersEnd();
268  ++pfclus) {
269  if (!pfClusterMapES.count(*pfclus)) {
270  reco::CaloCluster caloclus(**pfclus);
271  caloClustersES->push_back(caloclus);
272  pfClusterMapES[*pfclus] = caloClustersES->size() - 1;
273  } else {
274  throw cms::Exception("PFECALSuperClusterProducer::produce")
275  << "Found an ES pfcluster matched to more than one EE supercluster!" << std::dec << std::endl;
276  }
277  }
278  }
279 
280  //create ValueMaps from output CaloClusters back to original PFClusters
281  auto pfClusterAssociationEBEE = std::make_unique<edm::ValueMap<reco::CaloClusterPtr>>();
282  auto pfClusterAssociationES = std::make_unique<edm::ValueMap<reco::CaloClusterPtr>>();
283 
284  //vectors to fill ValueMaps
285  std::vector<reco::CaloClusterPtr> clusptrsEB(caloClustersEB->size());
286  std::vector<reco::CaloClusterPtr> clusptrsEE(caloClustersEE->size());
287  std::vector<reco::CaloClusterPtr> clusptrsES(caloClustersES->size());
288 
289  //put calocluster output collections in event and get orphan handles to create ptrs
290  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleEB =
291  iEvent.put(std::move(caloClustersEB), PFBasicClusterCollectionBarrel_);
292  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleEE =
293  iEvent.put(std::move(caloClustersEE), PFBasicClusterCollectionEndcap_);
294  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleES =
296 
297  //relink superclusters to output caloclusters and fill vectors for ValueMaps
298  for (auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection())) {
299  reco::CaloClusterPtr seedptr(caloClusHandleEB, pfClusterMapEB[ebsc.seed()]);
300  ebsc.setSeed(seedptr);
301 
303  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus != ebsc.clustersEnd(); ++pfclus) {
304  int caloclusidx = pfClusterMapEB[*pfclus];
305  reco::CaloClusterPtr clusptr(caloClusHandleEB, caloclusidx);
306  clusters.push_back(clusptr);
307  clusptrsEB[caloclusidx] = *pfclus;
308  }
309  ebsc.setClusters(clusters);
310  }
311  for (auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection())) {
312  reco::CaloClusterPtr seedptr(caloClusHandleEE, pfClusterMapEE[eesc.seed()]);
313  eesc.setSeed(seedptr);
314 
316  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus != eesc.clustersEnd(); ++pfclus) {
317  int caloclusidx = pfClusterMapEE[*pfclus];
318  reco::CaloClusterPtr clusptr(caloClusHandleEE, caloclusidx);
319  clusters.push_back(clusptr);
320  clusptrsEE[caloclusidx] = *pfclus;
321  }
322  eesc.setClusters(clusters);
323 
324  reco::CaloClusterPtrVector psclusters;
325  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus != eesc.preshowerClustersEnd();
326  ++pfclus) {
327  int caloclusidx = pfClusterMapES[*pfclus];
328  reco::CaloClusterPtr clusptr(caloClusHandleES, caloclusidx);
329  psclusters.push_back(clusptr);
330  clusptrsES[caloclusidx] = *pfclus;
331  }
332  eesc.setPreshowerClusters(psclusters);
333  }
334 
335  //fill association maps from output CaloClusters back to original PFClusters
336  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerEBEE(*pfClusterAssociationEBEE);
337  fillerEBEE.insert(caloClusHandleEB, clusptrsEB.begin(), clusptrsEB.end());
338  fillerEBEE.insert(caloClusHandleEE, clusptrsEE.begin(), clusptrsEE.end());
339  fillerEBEE.fill();
340 
341  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerES(*pfClusterAssociationES);
342  fillerES.insert(caloClusHandleES, clusptrsES.begin(), clusptrsES.end());
343  fillerES.fill();
344 
345  //store in the event
346  iEvent.put(std::move(pfClusterAssociationEBEE), PFClusterAssociationEBEE_);
347  iEvent.put(std::move(pfClusterAssociationES), PFClusterAssociationES_);
350 }
351 
354  desc.add<std::string>("PFSuperClusterCollectionEndcap", "particleFlowSuperClusterECALEndcap");
355  desc.add<bool>("doSatelliteClusterMerge", false);
356  desc.add<double>("thresh_PFClusterBarrel", 0.0);
357  desc.add<std::string>("PFBasicClusterCollectionBarrel", "particleFlowBasicClusterECALBarrel");
358  desc.add<bool>("useRegression", true);
359  desc.add<double>("satelliteMajorityFraction", 0.5);
360  desc.add<double>("thresh_PFClusterEndcap", 0.0);
361  desc.add<edm::InputTag>("ESAssociation", edm::InputTag("particleFlowClusterECAL"));
362  desc.add<std::string>("PFBasicClusterCollectionPreshower", "particleFlowBasicClusterECALPreshower");
363  desc.addUntracked<bool>("verbose", false);
364  desc.add<double>("thresh_SCEt", 4.0);
365  desc.add<double>("etawidth_SuperClusterEndcap", 0.04);
366  desc.add<double>("phiwidth_SuperClusterEndcap", 0.6);
367  desc.add<bool>("useDynamicDPhiWindow", true);
368  desc.add<std::string>("PFSuperClusterCollectionBarrel", "particleFlowSuperClusterECALBarrel");
370  desc.add<bool>("applyCrackCorrections", false);
371  desc.add<double>("satelliteClusterSeedThreshold", 50.0);
372  desc.add<double>("etawidth_SuperClusterBarrel", 0.04);
373  desc.add<std::string>("PFBasicClusterCollectionEndcap", "particleFlowBasicClusterECALEndcap");
374  desc.add<edm::InputTag>("PFClusters", edm::InputTag("particleFlowClusterECAL"));
375  desc.add<double>("thresh_PFClusterSeedBarrel", 1.0);
376  desc.add<std::string>("EnergyWeight", "Raw");
377  desc.add<edm::InputTag>("BeamSpot", edm::InputTag("offlineBeamSpot"));
378  desc.add<double>("thresh_PFClusterSeedEndcap", 1.0);
379  desc.add<double>("phiwidth_SuperClusterBarrel", 0.6);
380  desc.add<double>("thresh_PFClusterES", 0.0);
381  desc.add<bool>("seedThresholdIsET", true);
382  desc.add<bool>("isOOTCollection", false);
383  desc.add<edm::InputTag>("barrelRecHits", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
384  desc.add<edm::InputTag>("endcapRecHits", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
385  desc.add<std::string>("PFSuperClusterCollectionEndcapWithPreshower",
386  "particleFlowSuperClusterECALEndcapWithPreshower");
387  desc.add<bool>("dropUnseedable", false);
388 
389  edm::ParameterSetDescription deepSCParams;
390  deepSCParams.add<std::string>("modelFile", "");
391  deepSCParams.add<std::string>("configFileClusterFeatures", "");
392  deepSCParams.add<std::string>("configFileWindowFeatures", "");
393  deepSCParams.add<std::string>("configFileHitsFeatures", "");
394  deepSCParams.add<uint>("nClusterFeatures", 12);
395  deepSCParams.add<uint>("nWindowFeatures", 18);
396  deepSCParams.add<uint>("nHitsFeatures", 4);
397  deepSCParams.add<uint>("maxNClusters", 40);
398  deepSCParams.add<uint>("maxNRechits", 40);
399  deepSCParams.add<uint>("batchSize", 64);
400  deepSCParams.add<std::string>("collectionStrategy", "Cascade");
401 
402  EmptyGroupDescription emptyGroup;
403 
404  // Add DeepSC parameters only to the specific ClusteringType
406  edm::ParameterDescription<std::string>("ClusteringType", ClusterType__Mustache, true),
407  ClusterType__Mustache >> emptyGroup or ClusterType__BOX >> emptyGroup or
408  ClusterType__DeepSC >>
409  edm::ParameterDescription<edm::ParameterSetDescription>("deepSuperClusterConfig", deepSCParams, true));
410  desc.addNode(switchNode);
411 
412  descriptions.add("particleFlowSuperClusterECALMustache", desc);
413 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::unique_ptr< reco::SuperClusterCollection > & getEEOutputSCCollection()
void setMajorityFraction(const double f)
void setSatelliteMerging(const bool doit)
void setThreshPFClusterSeedEndcap(double thresh)
PFECALSuperClusterAlgo::clustering_type _theclusteringtype
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:152
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
void setCrackCorrections(bool applyCrackCorrections)
void setThreshPFClusterBarrel(double thresh)
Definition: config.py:1
void setThreshSuperClusterEt(double thresh)
std::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration_
void setEtawidthSuperClusterBarrel(double etawidth)
void setClusteringType(clustering_type thetype)
T getUntrackedParameter(std::string const &, T const &) const
void setEtawidthSuperClusterEndcap(double etawidth)
void setPhiwidthSuperClusterBarrel(double phiwidth)
void setVerbosityLevel(bool verbose)
void loadAndSortPFClusters(const edm::Event &evt)
void update(const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:224
void setThreshPFClusterEndcap(double thresh)
void setTokens(const edm::ParameterSet &, edm::ConsumesCollector &&)
void setUseETForSeeding(bool useET)
PFECALSuperClusterAlgo superClusterAlgo_
clustering algorithm
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::unique_ptr< reco::SuperClusterCollection > & getEBOutputSCCollection()
static std::unique_ptr< reco::SCProducerCache > initializeGlobalCache(const edm::ParameterSet &config)
void setEnergyWeighting(energy_weight thetype)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setThreshPFClusterSeedBarrel(double thresh)
PFECALSuperClusterAlgo::energy_weight _theenergyweight
static edm::ParameterSetDescription makePSetDescription()
void produce(edm::Event &, const edm::EventSetup &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
void setUseDynamicDPhi(bool useit)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void setDropUnseedable(const bool d)
HLT enums.
void updateSCParams(const edm::EventSetup &)
void setPhiwidthSuperClusterEndcap(double phiwidth)
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30
void setUseRegression(bool useRegression)
void setSatelliteThreshold(const double t)
void setPFClusterCalibration(const std::shared_ptr< PFEnergyCalibration > &)
def move(src, dest)
Definition: eostools.py:511
static void globalEndJob(const reco::SCProducerCache *)
PFECALSuperClusterProducer(const edm::ParameterSet &, const reco::SCProducerCache *gcache)
void setIsOOTCollection(bool isOOTCollection)