CMS 3D CMS Logo

PFECALSuperClusterProducer.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 
6 
8 
10 
15 
19 
22 
25 
28 
30 
31 #include "TVector2.h"
33 
34 using namespace std;
35 using namespace edm;
36 
37 namespace {
38  const std::string ClusterType__BOX("Box");
39  const std::string ClusterType__Mustache("Mustache");
40 
41  const std::string EnergyWeight__Raw("Raw");
42  const std::string EnergyWeight__CalibratedNoPS("CalibratedNoPS");
43  const std::string EnergyWeight__CalibratedTotal("CalibratedTotal");
44 } // namespace
45 
47  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
48 
49  superClusterAlgo_.setUseRegression(iConfig.getParameter<bool>("useRegression"));
50 
51  isOOTCollection_ = iConfig.getParameter<bool>("isOOTCollection");
52  superClusterAlgo_.setIsOOTCollection(isOOTCollection_);
53 
54  superClusterAlgo_.setTokens(iConfig, consumesCollector());
55 
56  std::string _typename = iConfig.getParameter<std::string>("ClusteringType");
57  if (_typename == ClusterType__BOX) {
58  _theclusteringtype = PFECALSuperClusterAlgo::kBOX;
59  } else if (_typename == ClusterType__Mustache) {
60  _theclusteringtype = PFECALSuperClusterAlgo::kMustache;
61  } else {
62  throw cms::Exception("InvalidClusteringType") << "You have not chosen a valid clustering type,"
63  << " please choose from \"Box\" or \"Mustache\"!";
64  }
65 
66  std::string _weightname = iConfig.getParameter<std::string>("EnergyWeight");
67  if (_weightname == EnergyWeight__Raw) {
68  _theenergyweight = PFECALSuperClusterAlgo::kRaw;
69  } else if (_weightname == EnergyWeight__CalibratedNoPS) {
70  _theenergyweight = PFECALSuperClusterAlgo::kCalibratedNoPS;
71  } else if (_weightname == EnergyWeight__CalibratedTotal) {
73  } else {
74  throw cms::Exception("InvalidClusteringType") << "You have not chosen a valid energy weighting scheme,"
75  << " please choose from \"Raw\", \"CalibratedNoPS\", or"
76  << " \"CalibratedTotal\"!";
77  }
78 
79  // parameters for clustering
80  bool seedThresholdIsET = iConfig.getParameter<bool>("seedThresholdIsET");
81 
82  bool useDynamicDPhi = iConfig.getParameter<bool>("useDynamicDPhiWindow");
83 
84  double threshPFClusterSeedBarrel = iConfig.getParameter<double>("thresh_PFClusterSeedBarrel");
85  double threshPFClusterBarrel = iConfig.getParameter<double>("thresh_PFClusterBarrel");
86 
87  double threshPFClusterSeedEndcap = iConfig.getParameter<double>("thresh_PFClusterSeedEndcap");
88  double threshPFClusterEndcap = iConfig.getParameter<double>("thresh_PFClusterEndcap");
89 
90  double phiwidthSuperClusterBarrel = iConfig.getParameter<double>("phiwidth_SuperClusterBarrel");
91  double etawidthSuperClusterBarrel = iConfig.getParameter<double>("etawidth_SuperClusterBarrel");
92 
93  double phiwidthSuperClusterEndcap = iConfig.getParameter<double>("phiwidth_SuperClusterEndcap");
94  double etawidthSuperClusterEndcap = iConfig.getParameter<double>("etawidth_SuperClusterEndcap");
95 
96  //double threshPFClusterMustacheOutBarrel = iConfig.getParameter<double>("thresh_PFClusterMustacheOutBarrel");
97  //double threshPFClusterMustacheOutEndcap = iConfig.getParameter<double>("thresh_PFClusterMustacheOutEndcap");
98 
99  double doSatelliteClusterMerge = iConfig.getParameter<bool>("doSatelliteClusterMerge");
100  double satelliteClusterSeedThreshold = iConfig.getParameter<double>("satelliteClusterSeedThreshold");
101  double satelliteMajorityFraction = iConfig.getParameter<double>("satelliteMajorityFraction");
102  bool dropUnseedable = iConfig.getParameter<bool>("dropUnseedable");
103 
104  superClusterAlgo_.setVerbosityLevel(verbose_);
105  superClusterAlgo_.setClusteringType(_theclusteringtype);
106  superClusterAlgo_.setEnergyWeighting(_theenergyweight);
107  superClusterAlgo_.setUseETForSeeding(seedThresholdIsET);
108  superClusterAlgo_.setUseDynamicDPhi(useDynamicDPhi);
109 
110  superClusterAlgo_.setThreshSuperClusterEt(iConfig.getParameter<double>("thresh_SCEt"));
111 
112  superClusterAlgo_.setThreshPFClusterSeedBarrel(threshPFClusterSeedBarrel);
113  superClusterAlgo_.setThreshPFClusterBarrel(threshPFClusterBarrel);
114 
115  superClusterAlgo_.setThreshPFClusterSeedEndcap(threshPFClusterSeedEndcap);
116  superClusterAlgo_.setThreshPFClusterEndcap(threshPFClusterEndcap);
117 
118  superClusterAlgo_.setPhiwidthSuperClusterBarrel(phiwidthSuperClusterBarrel);
119  superClusterAlgo_.setEtawidthSuperClusterBarrel(etawidthSuperClusterBarrel);
120 
121  superClusterAlgo_.setPhiwidthSuperClusterEndcap(phiwidthSuperClusterEndcap);
122  superClusterAlgo_.setEtawidthSuperClusterEndcap(etawidthSuperClusterEndcap);
123 
124  superClusterAlgo_.setSatelliteMerging(doSatelliteClusterMerge);
125  superClusterAlgo_.setSatelliteThreshold(satelliteClusterSeedThreshold);
126  superClusterAlgo_.setMajorityFraction(satelliteMajorityFraction);
127  superClusterAlgo_.setDropUnseedable(dropUnseedable);
128  //superClusterAlgo_.setThreshPFClusterMustacheOutBarrel( threshPFClusterMustacheOutBarrel );
129  //superClusterAlgo_.setThreshPFClusterMustacheOutEndcap( threshPFClusterMustacheOutEndcap );
130 
131  //Load the ECAL energy calibration
132  thePFEnergyCalibration_ = std::make_shared<PFEnergyCalibration>();
133  superClusterAlgo_.setPFClusterCalibration(thePFEnergyCalibration_);
134 
135  bool applyCrackCorrections_ = iConfig.getParameter<bool>("applyCrackCorrections");
136  superClusterAlgo_.setCrackCorrections(applyCrackCorrections_);
137 
138  PFBasicClusterCollectionBarrel_ = iConfig.getParameter<string>("PFBasicClusterCollectionBarrel");
139  PFSuperClusterCollectionBarrel_ = iConfig.getParameter<string>("PFSuperClusterCollectionBarrel");
140 
141  PFBasicClusterCollectionEndcap_ = iConfig.getParameter<string>("PFBasicClusterCollectionEndcap");
142  PFSuperClusterCollectionEndcap_ = iConfig.getParameter<string>("PFSuperClusterCollectionEndcap");
143 
144  PFBasicClusterCollectionPreshower_ = iConfig.getParameter<string>("PFBasicClusterCollectionPreshower");
145  PFSuperClusterCollectionEndcapWithPreshower_ =
146  iConfig.getParameter<string>("PFSuperClusterCollectionEndcapWithPreshower");
147 
148  PFClusterAssociationEBEE_ = "PFClusterAssociationEBEE";
149  PFClusterAssociationES_ = "PFClusterAssociationES";
150 
151  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionBarrel_);
152  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionEndcapWithPreshower_);
153  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionBarrel_);
154  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionEndcap_);
155  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionPreshower_);
156  produces<edm::ValueMap<reco::CaloClusterPtr>>(PFClusterAssociationEBEE_);
157  produces<edm::ValueMap<reco::CaloClusterPtr>>(PFClusterAssociationES_);
158 }
159 
161 
163  superClusterAlgo_.update(iE);
164 }
165 
167  // update SC parameters
168  superClusterAlgo_.updateSCParams(iSetup);
169  // do clustering
170  superClusterAlgo_.loadAndSortPFClusters(iEvent);
171  superClusterAlgo_.run();
172 
173  //build collections of output CaloClusters from the used PFClusters
174  auto caloClustersEB = std::make_unique<reco::CaloClusterCollection>();
175  auto caloClustersEE = std::make_unique<reco::CaloClusterCollection>();
176  auto caloClustersES = std::make_unique<reco::CaloClusterCollection>();
177 
178  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEB; //maps of pfclusters to caloclusters
179  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEE;
180  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapES;
181 
182  //fill calocluster collections and maps
183  for (const auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection())) {
184  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus != ebsc.clustersEnd(); ++pfclus) {
185  if (!pfClusterMapEB.count(*pfclus)) {
186  reco::CaloCluster caloclus(**pfclus);
187  caloClustersEB->push_back(caloclus);
188  pfClusterMapEB[*pfclus] = caloClustersEB->size() - 1;
189  } else {
190  throw cms::Exception("PFECALSuperClusterProducer::produce")
191  << "Found an EB pfcluster matched to more than one EB supercluster!" << std::dec << std::endl;
192  }
193  }
194  }
195  for (const auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection())) {
196  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus != eesc.clustersEnd(); ++pfclus) {
197  if (!pfClusterMapEE.count(*pfclus)) {
198  reco::CaloCluster caloclus(**pfclus);
199  caloClustersEE->push_back(caloclus);
200  pfClusterMapEE[*pfclus] = caloClustersEE->size() - 1;
201  } else {
202  throw cms::Exception("PFECALSuperClusterProducer::produce")
203  << "Found an EE pfcluster matched to more than one EE supercluster!" << std::dec << std::endl;
204  }
205  }
206  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus != eesc.preshowerClustersEnd();
207  ++pfclus) {
208  if (!pfClusterMapES.count(*pfclus)) {
209  reco::CaloCluster caloclus(**pfclus);
210  caloClustersES->push_back(caloclus);
211  pfClusterMapES[*pfclus] = caloClustersES->size() - 1;
212  } else {
213  throw cms::Exception("PFECALSuperClusterProducer::produce")
214  << "Found an ES pfcluster matched to more than one EE supercluster!" << std::dec << std::endl;
215  }
216  }
217  }
218 
219  //create ValueMaps from output CaloClusters back to original PFClusters
220  auto pfClusterAssociationEBEE = std::make_unique<edm::ValueMap<reco::CaloClusterPtr>>();
221  auto pfClusterAssociationES = std::make_unique<edm::ValueMap<reco::CaloClusterPtr>>();
222 
223  //vectors to fill ValueMaps
224  std::vector<reco::CaloClusterPtr> clusptrsEB(caloClustersEB->size());
225  std::vector<reco::CaloClusterPtr> clusptrsEE(caloClustersEE->size());
226  std::vector<reco::CaloClusterPtr> clusptrsES(caloClustersES->size());
227 
228  //put calocluster output collections in event and get orphan handles to create ptrs
229  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleEB =
230  iEvent.put(std::move(caloClustersEB), PFBasicClusterCollectionBarrel_);
231  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleEE =
232  iEvent.put(std::move(caloClustersEE), PFBasicClusterCollectionEndcap_);
233  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleES =
234  iEvent.put(std::move(caloClustersES), PFBasicClusterCollectionPreshower_);
235 
236  //relink superclusters to output caloclusters and fill vectors for ValueMaps
237  for (auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection())) {
238  reco::CaloClusterPtr seedptr(caloClusHandleEB, pfClusterMapEB[ebsc.seed()]);
239  ebsc.setSeed(seedptr);
240 
242  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus != ebsc.clustersEnd(); ++pfclus) {
243  int caloclusidx = pfClusterMapEB[*pfclus];
244  reco::CaloClusterPtr clusptr(caloClusHandleEB, caloclusidx);
245  clusters.push_back(clusptr);
246  clusptrsEB[caloclusidx] = *pfclus;
247  }
248  ebsc.setClusters(clusters);
249  }
250  for (auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection())) {
251  reco::CaloClusterPtr seedptr(caloClusHandleEE, pfClusterMapEE[eesc.seed()]);
252  eesc.setSeed(seedptr);
253 
255  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus != eesc.clustersEnd(); ++pfclus) {
256  int caloclusidx = pfClusterMapEE[*pfclus];
257  reco::CaloClusterPtr clusptr(caloClusHandleEE, caloclusidx);
258  clusters.push_back(clusptr);
259  clusptrsEE[caloclusidx] = *pfclus;
260  }
261  eesc.setClusters(clusters);
262 
263  reco::CaloClusterPtrVector psclusters;
264  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus != eesc.preshowerClustersEnd();
265  ++pfclus) {
266  int caloclusidx = pfClusterMapES[*pfclus];
267  reco::CaloClusterPtr clusptr(caloClusHandleES, caloclusidx);
268  psclusters.push_back(clusptr);
269  clusptrsES[caloclusidx] = *pfclus;
270  }
271  eesc.setPreshowerClusters(psclusters);
272  }
273 
274  //fill association maps from output CaloClusters back to original PFClusters
275  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerEBEE(*pfClusterAssociationEBEE);
276  fillerEBEE.insert(caloClusHandleEB, clusptrsEB.begin(), clusptrsEB.end());
277  fillerEBEE.insert(caloClusHandleEE, clusptrsEE.begin(), clusptrsEE.end());
278  fillerEBEE.fill();
279 
280  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerES(*pfClusterAssociationES);
281  fillerES.insert(caloClusHandleES, clusptrsES.begin(), clusptrsES.end());
282  fillerES.fill();
283 
284  //store in the event
285  iEvent.put(std::move(pfClusterAssociationEBEE), PFClusterAssociationEBEE_);
286  iEvent.put(std::move(pfClusterAssociationES), PFClusterAssociationES_);
287  iEvent.put(std::move(superClusterAlgo_.getEBOutputSCCollection()), PFSuperClusterCollectionBarrel_);
288  iEvent.put(std::move(superClusterAlgo_.getEEOutputSCCollection()), PFSuperClusterCollectionEndcapWithPreshower_);
289 }
290 
293  desc.add<std::string>("PFSuperClusterCollectionEndcap", "particleFlowSuperClusterECALEndcap");
294  desc.add<bool>("doSatelliteClusterMerge", false);
295  desc.add<double>("thresh_PFClusterBarrel", 0.0);
296  desc.add<std::string>("PFBasicClusterCollectionBarrel", "particleFlowBasicClusterECALBarrel");
297  desc.add<bool>("useRegression", true);
298  desc.add<double>("satelliteMajorityFraction", 0.5);
299  desc.add<double>("thresh_PFClusterEndcap", 0.0);
300  desc.add<edm::InputTag>("ESAssociation", edm::InputTag("particleFlowClusterECAL"));
301  desc.add<std::string>("PFBasicClusterCollectionPreshower", "particleFlowBasicClusterECALPreshower");
302  desc.add<bool>("use_preshower", true);
303  desc.addUntracked<bool>("verbose", false);
304  desc.add<double>("thresh_SCEt", 4.0);
305  desc.add<double>("etawidth_SuperClusterEndcap", 0.04);
306  desc.add<double>("phiwidth_SuperClusterEndcap", 0.6);
307  desc.add<bool>("useDynamicDPhiWindow", true);
308  desc.add<std::string>("PFSuperClusterCollectionBarrel", "particleFlowSuperClusterECALBarrel");
309  {
311  psd0.add<bool>("isHLT", false);
312  psd0.add<bool>("applySigmaIetaIphiBug", false);
313  psd0.add<edm::InputTag>("ecalRecHitsEE", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
314  psd0.add<edm::InputTag>("ecalRecHitsEB", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
315  psd0.add<std::string>("regressionKeyEB", "pfscecal_EBCorrection_offline_v2");
316  psd0.add<std::string>("regressionKeyEE", "pfscecal_EECorrection_offline_v2");
317  psd0.add<std::string>("uncertaintyKeyEB", "pfscecal_EBUncertainty_offline_v2");
318  psd0.add<std::string>("uncertaintyKeyEE", "pfscecal_EEUncertainty_offline_v2");
319  psd0.add<edm::InputTag>("vertexCollection", edm::InputTag("offlinePrimaryVertices"));
320  psd0.add<double>("eRecHitThreshold", 1.);
321  desc.add<edm::ParameterSetDescription>("regressionConfig", psd0);
322  }
323  desc.add<bool>("applyCrackCorrections", false);
324  desc.add<double>("satelliteClusterSeedThreshold", 50.0);
325  desc.add<double>("etawidth_SuperClusterBarrel", 0.04);
326  desc.add<std::string>("PFBasicClusterCollectionEndcap", "particleFlowBasicClusterECALEndcap");
327  desc.add<edm::InputTag>("PFClusters", edm::InputTag("particleFlowClusterECAL"));
328  desc.add<double>("thresh_PFClusterSeedBarrel", 1.0);
329  desc.add<std::string>("ClusteringType", "Mustache");
330  desc.add<std::string>("EnergyWeight", "Raw");
331  desc.add<edm::InputTag>("BeamSpot", edm::InputTag("offlineBeamSpot"));
332  desc.add<double>("thresh_PFClusterSeedEndcap", 1.0);
333  desc.add<double>("phiwidth_SuperClusterBarrel", 0.6);
334  desc.add<double>("thresh_PFClusterES", 0.0);
335  desc.add<bool>("seedThresholdIsET", true);
336  desc.add<bool>("isOOTCollection", false);
337  desc.add<edm::InputTag>("barrelRecHits", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
338  desc.add<edm::InputTag>("endcapRecHits", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
339  desc.add<std::string>("PFSuperClusterCollectionEndcapWithPreshower",
340  "particleFlowSuperClusterECALEndcapWithPreshower");
341  desc.add<bool>("dropUnseedable", false);
342  descriptions.add("particleFlowSuperClusterECALMustache", desc);
343 }
ConfigurationDescriptions.h
PFECALSuperClusterProducer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
Definition: PFECALSuperClusterProducer.cc:162
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
MessageLogger.h
ESHandle.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm
HLT enums.
Definition: AlignableModifier.h:19
GBRWrapperRcd.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::PtrVectorItr
Definition: PtrVector.h:51
HLT_FULL_cff.satelliteClusterSeedThreshold
satelliteClusterSeedThreshold
Definition: HLT_FULL_cff.py:14980
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
PFECALSuperClusterProducer::PFECALSuperClusterProducer
PFECALSuperClusterProducer(const edm::ParameterSet &)
Definition: PFECALSuperClusterProducer.cc:46
GBRForest.h
PFECALSuperClusterAlgo.h
PFECALSuperClusterAlgo::kMustache
Definition: PFECALSuperClusterAlgo.h:53
PFRecHit.h
HLT_FULL_cff.dropUnseedable
dropUnseedable
Definition: HLT_FULL_cff.py:14987
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::PtrVector< CaloCluster >
reco::CaloCluster
Definition: CaloCluster.h:31
CaloClusterFwd.h
PFECALSuperClusterProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFECALSuperClusterProducer.cc:166
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
PFECALSuperClusterAlgo::kRaw
Definition: PFECALSuperClusterAlgo.h:54
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
edm::PtrVector::push_back
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
PFECALSuperClusterProducer::~PFECALSuperClusterProducer
~PFECALSuperClusterProducer() override
Definition: PFECALSuperClusterProducer.cc:160
edm::ParameterSet
Definition: ParameterSet.h:47
PFECALSuperClusterProducer.h
PFECALSuperClusterProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PFECALSuperClusterProducer.cc:291
deltaR.h
iEvent
int iEvent
Definition: GenABIO.cc:224
PFClusterFwd.h
edm::EventSetup
Definition: EventSetup.h:57
EcalRecHit.h
edm::Ptr< CaloCluster >
ValueMap.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
PFECALSuperClusterAlgo::kCalibratedTotal
Definition: PFECALSuperClusterAlgo.h:54
edm::OrphanHandle
Definition: EDProductfwd.h:39
SuperClusterFwd.h
HLT_FULL_cff.seedThresholdIsET
seedThresholdIsET
Definition: HLT_FULL_cff.py:14993
SuperCluster.h
Exception
Definition: hltDiff.cc:246
HLT_FULL_cff.satelliteMajorityFraction
satelliteMajorityFraction
Definition: HLT_FULL_cff.py:14957
PFECALSuperClusterAlgo::kBOX
Definition: PFECALSuperClusterAlgo.h:53
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::helper::Filler
Definition: ValueMap.h:22
HLT_FULL_cff.doSatelliteClusterMerge
doSatelliteClusterMerge
Definition: HLT_FULL_cff.py:14953
edm::Event
Definition: Event.h:73
PFECALSuperClusterAlgo::kCalibratedNoPS
Definition: PFECALSuperClusterAlgo.h:54
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::InputTag
Definition: InputTag.h:15
CaloCluster.h