CMS 3D CMS Logo

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