CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PFECALSuperClusterProducer.cc
Go to the documentation of this file.
1 
38 
39 #include "TVector2.h"
40 
41 #include <memory>
42 #include <vector>
43 
45 public:
47  ~PFECALSuperClusterProducer() override;
48 
49  void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override;
50  void produce(edm::Event&, const edm::EventSetup&) override;
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  // ----------member data ---------------------------
56 
61 
62  std::shared_ptr<PFEnergyCalibration> thePFEnergyCalibration_;
63 
65  bool verbose_;
66 
75 
76  // OOT photons
78 };
79 
82 
83 using namespace std;
84 using namespace edm;
85 
86 namespace {
87  const std::string ClusterType__BOX("Box");
88  const std::string ClusterType__Mustache("Mustache");
89 
90  const std::string EnergyWeight__Raw("Raw");
91  const std::string EnergyWeight__CalibratedNoPS("CalibratedNoPS");
92  const std::string EnergyWeight__CalibratedTotal("CalibratedTotal");
93 } // namespace
94 
96  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
97 
98  superClusterAlgo_.setUseRegression(iConfig.getParameter<bool>("useRegression"));
99 
100  isOOTCollection_ = iConfig.getParameter<bool>("isOOTCollection");
101  superClusterAlgo_.setIsOOTCollection(isOOTCollection_);
102 
103  std::string _typename = iConfig.getParameter<std::string>("ClusteringType");
104  if (_typename == ClusterType__BOX) {
105  _theclusteringtype = PFECALSuperClusterAlgo::kBOX;
106  } else if (_typename == ClusterType__Mustache) {
107  _theclusteringtype = PFECALSuperClusterAlgo::kMustache;
108  } else {
109  throw cms::Exception("InvalidClusteringType") << "You have not chosen a valid clustering type,"
110  << " please choose from \"Box\" or \"Mustache\"!";
111  }
112  superClusterAlgo_.setClusteringType(_theclusteringtype);
113  superClusterAlgo_.setUseDynamicDPhi(iConfig.getParameter<bool>("useDynamicDPhiWindow"));
114  // clusteringType and useDynamicDPhi need to be defined before setting the tokens in order to esConsume only the necessary records
115  superClusterAlgo_.setTokens(iConfig, consumesCollector());
116 
117  std::string _weightname = iConfig.getParameter<std::string>("EnergyWeight");
118  if (_weightname == EnergyWeight__Raw) {
119  _theenergyweight = PFECALSuperClusterAlgo::kRaw;
120  } else if (_weightname == EnergyWeight__CalibratedNoPS) {
121  _theenergyweight = PFECALSuperClusterAlgo::kCalibratedNoPS;
122  } else if (_weightname == EnergyWeight__CalibratedTotal) {
123  _theenergyweight = PFECALSuperClusterAlgo::kCalibratedTotal;
124  } else {
125  throw cms::Exception("InvalidClusteringType") << "You have not chosen a valid energy weighting scheme,"
126  << " please choose from \"Raw\", \"CalibratedNoPS\", or"
127  << " \"CalibratedTotal\"!";
128  }
129 
130  // parameters for clustering
131  bool seedThresholdIsET = iConfig.getParameter<bool>("seedThresholdIsET");
132 
133  double threshPFClusterSeedBarrel = iConfig.getParameter<double>("thresh_PFClusterSeedBarrel");
134  double threshPFClusterBarrel = iConfig.getParameter<double>("thresh_PFClusterBarrel");
135 
136  double threshPFClusterSeedEndcap = iConfig.getParameter<double>("thresh_PFClusterSeedEndcap");
137  double threshPFClusterEndcap = iConfig.getParameter<double>("thresh_PFClusterEndcap");
138 
139  double phiwidthSuperClusterBarrel = iConfig.getParameter<double>("phiwidth_SuperClusterBarrel");
140  double etawidthSuperClusterBarrel = iConfig.getParameter<double>("etawidth_SuperClusterBarrel");
141 
142  double phiwidthSuperClusterEndcap = iConfig.getParameter<double>("phiwidth_SuperClusterEndcap");
143  double etawidthSuperClusterEndcap = iConfig.getParameter<double>("etawidth_SuperClusterEndcap");
144 
145  double doSatelliteClusterMerge = iConfig.getParameter<bool>("doSatelliteClusterMerge");
146  double satelliteClusterSeedThreshold = iConfig.getParameter<double>("satelliteClusterSeedThreshold");
147  double satelliteMajorityFraction = iConfig.getParameter<double>("satelliteMajorityFraction");
148  bool dropUnseedable = iConfig.getParameter<bool>("dropUnseedable");
149 
150  superClusterAlgo_.setVerbosityLevel(verbose_);
151  superClusterAlgo_.setEnergyWeighting(_theenergyweight);
152  superClusterAlgo_.setUseETForSeeding(seedThresholdIsET);
153 
154  superClusterAlgo_.setThreshSuperClusterEt(iConfig.getParameter<double>("thresh_SCEt"));
155 
156  superClusterAlgo_.setThreshPFClusterSeedBarrel(threshPFClusterSeedBarrel);
157  superClusterAlgo_.setThreshPFClusterBarrel(threshPFClusterBarrel);
158 
159  superClusterAlgo_.setThreshPFClusterSeedEndcap(threshPFClusterSeedEndcap);
160  superClusterAlgo_.setThreshPFClusterEndcap(threshPFClusterEndcap);
161 
162  superClusterAlgo_.setPhiwidthSuperClusterBarrel(phiwidthSuperClusterBarrel);
163  superClusterAlgo_.setEtawidthSuperClusterBarrel(etawidthSuperClusterBarrel);
164 
165  superClusterAlgo_.setPhiwidthSuperClusterEndcap(phiwidthSuperClusterEndcap);
166  superClusterAlgo_.setEtawidthSuperClusterEndcap(etawidthSuperClusterEndcap);
167 
168  superClusterAlgo_.setSatelliteMerging(doSatelliteClusterMerge);
169  superClusterAlgo_.setSatelliteThreshold(satelliteClusterSeedThreshold);
170  superClusterAlgo_.setMajorityFraction(satelliteMajorityFraction);
171  superClusterAlgo_.setDropUnseedable(dropUnseedable);
172 
173  //Load the ECAL energy calibration
174  thePFEnergyCalibration_ = std::make_shared<PFEnergyCalibration>();
175  superClusterAlgo_.setPFClusterCalibration(thePFEnergyCalibration_);
176 
177  bool applyCrackCorrections_ = iConfig.getParameter<bool>("applyCrackCorrections");
178  superClusterAlgo_.setCrackCorrections(applyCrackCorrections_);
179 
180  PFBasicClusterCollectionBarrel_ = iConfig.getParameter<string>("PFBasicClusterCollectionBarrel");
181  PFSuperClusterCollectionBarrel_ = iConfig.getParameter<string>("PFSuperClusterCollectionBarrel");
182 
183  PFBasicClusterCollectionEndcap_ = iConfig.getParameter<string>("PFBasicClusterCollectionEndcap");
184  PFSuperClusterCollectionEndcap_ = iConfig.getParameter<string>("PFSuperClusterCollectionEndcap");
185 
186  PFBasicClusterCollectionPreshower_ = iConfig.getParameter<string>("PFBasicClusterCollectionPreshower");
187  PFSuperClusterCollectionEndcapWithPreshower_ =
188  iConfig.getParameter<string>("PFSuperClusterCollectionEndcapWithPreshower");
189 
190  PFClusterAssociationEBEE_ = "PFClusterAssociationEBEE";
191  PFClusterAssociationES_ = "PFClusterAssociationES";
192 
193  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionBarrel_);
194  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionEndcapWithPreshower_);
195  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionBarrel_);
196  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionEndcap_);
197  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionPreshower_);
198  produces<edm::ValueMap<reco::CaloClusterPtr>>(PFClusterAssociationEBEE_);
199  produces<edm::ValueMap<reco::CaloClusterPtr>>(PFClusterAssociationES_);
200 }
201 
203 
205  superClusterAlgo_.update(iE);
206 }
207 
209  // update SC parameters
210  superClusterAlgo_.updateSCParams(iSetup);
211  // do clustering
212  superClusterAlgo_.loadAndSortPFClusters(iEvent);
213  superClusterAlgo_.run();
214 
215  //build collections of output CaloClusters from the used PFClusters
216  auto caloClustersEB = std::make_unique<reco::CaloClusterCollection>();
217  auto caloClustersEE = std::make_unique<reco::CaloClusterCollection>();
218  auto caloClustersES = std::make_unique<reco::CaloClusterCollection>();
219 
220  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEB; //maps of pfclusters to caloclusters
221  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEE;
222  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapES;
223 
224  //fill calocluster collections and maps
225  for (const auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection())) {
226  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus != ebsc.clustersEnd(); ++pfclus) {
227  if (!pfClusterMapEB.count(*pfclus)) {
228  reco::CaloCluster caloclus(**pfclus);
229  caloClustersEB->push_back(caloclus);
230  pfClusterMapEB[*pfclus] = caloClustersEB->size() - 1;
231  } else {
232  throw cms::Exception("PFECALSuperClusterProducer::produce")
233  << "Found an EB pfcluster matched to more than one EB supercluster!" << std::dec << std::endl;
234  }
235  }
236  }
237  for (const auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection())) {
238  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus != eesc.clustersEnd(); ++pfclus) {
239  if (!pfClusterMapEE.count(*pfclus)) {
240  reco::CaloCluster caloclus(**pfclus);
241  caloClustersEE->push_back(caloclus);
242  pfClusterMapEE[*pfclus] = caloClustersEE->size() - 1;
243  } else {
244  throw cms::Exception("PFECALSuperClusterProducer::produce")
245  << "Found an EE pfcluster matched to more than one EE supercluster!" << std::dec << std::endl;
246  }
247  }
248  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus != eesc.preshowerClustersEnd();
249  ++pfclus) {
250  if (!pfClusterMapES.count(*pfclus)) {
251  reco::CaloCluster caloclus(**pfclus);
252  caloClustersES->push_back(caloclus);
253  pfClusterMapES[*pfclus] = caloClustersES->size() - 1;
254  } else {
255  throw cms::Exception("PFECALSuperClusterProducer::produce")
256  << "Found an ES pfcluster matched to more than one EE supercluster!" << std::dec << std::endl;
257  }
258  }
259  }
260 
261  //create ValueMaps from output CaloClusters back to original PFClusters
262  auto pfClusterAssociationEBEE = std::make_unique<edm::ValueMap<reco::CaloClusterPtr>>();
263  auto pfClusterAssociationES = std::make_unique<edm::ValueMap<reco::CaloClusterPtr>>();
264 
265  //vectors to fill ValueMaps
266  std::vector<reco::CaloClusterPtr> clusptrsEB(caloClustersEB->size());
267  std::vector<reco::CaloClusterPtr> clusptrsEE(caloClustersEE->size());
268  std::vector<reco::CaloClusterPtr> clusptrsES(caloClustersES->size());
269 
270  //put calocluster output collections in event and get orphan handles to create ptrs
271  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleEB =
272  iEvent.put(std::move(caloClustersEB), PFBasicClusterCollectionBarrel_);
273  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleEE =
274  iEvent.put(std::move(caloClustersEE), PFBasicClusterCollectionEndcap_);
275  const edm::OrphanHandle<reco::CaloClusterCollection>& caloClusHandleES =
276  iEvent.put(std::move(caloClustersES), PFBasicClusterCollectionPreshower_);
277 
278  //relink superclusters to output caloclusters and fill vectors for ValueMaps
279  for (auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection())) {
280  reco::CaloClusterPtr seedptr(caloClusHandleEB, pfClusterMapEB[ebsc.seed()]);
281  ebsc.setSeed(seedptr);
282 
284  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus != ebsc.clustersEnd(); ++pfclus) {
285  int caloclusidx = pfClusterMapEB[*pfclus];
286  reco::CaloClusterPtr clusptr(caloClusHandleEB, caloclusidx);
287  clusters.push_back(clusptr);
288  clusptrsEB[caloclusidx] = *pfclus;
289  }
290  ebsc.setClusters(clusters);
291  }
292  for (auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection())) {
293  reco::CaloClusterPtr seedptr(caloClusHandleEE, pfClusterMapEE[eesc.seed()]);
294  eesc.setSeed(seedptr);
295 
297  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus != eesc.clustersEnd(); ++pfclus) {
298  int caloclusidx = pfClusterMapEE[*pfclus];
299  reco::CaloClusterPtr clusptr(caloClusHandleEE, caloclusidx);
300  clusters.push_back(clusptr);
301  clusptrsEE[caloclusidx] = *pfclus;
302  }
303  eesc.setClusters(clusters);
304 
305  reco::CaloClusterPtrVector psclusters;
306  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus != eesc.preshowerClustersEnd();
307  ++pfclus) {
308  int caloclusidx = pfClusterMapES[*pfclus];
309  reco::CaloClusterPtr clusptr(caloClusHandleES, caloclusidx);
310  psclusters.push_back(clusptr);
311  clusptrsES[caloclusidx] = *pfclus;
312  }
313  eesc.setPreshowerClusters(psclusters);
314  }
315 
316  //fill association maps from output CaloClusters back to original PFClusters
317  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerEBEE(*pfClusterAssociationEBEE);
318  fillerEBEE.insert(caloClusHandleEB, clusptrsEB.begin(), clusptrsEB.end());
319  fillerEBEE.insert(caloClusHandleEE, clusptrsEE.begin(), clusptrsEE.end());
320  fillerEBEE.fill();
321 
322  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerES(*pfClusterAssociationES);
323  fillerES.insert(caloClusHandleES, clusptrsES.begin(), clusptrsES.end());
324  fillerES.fill();
325 
326  //store in the event
327  iEvent.put(std::move(pfClusterAssociationEBEE), PFClusterAssociationEBEE_);
328  iEvent.put(std::move(pfClusterAssociationES), PFClusterAssociationES_);
329  iEvent.put(std::move(superClusterAlgo_.getEBOutputSCCollection()), PFSuperClusterCollectionBarrel_);
330  iEvent.put(std::move(superClusterAlgo_.getEEOutputSCCollection()), PFSuperClusterCollectionEndcapWithPreshower_);
331 }
332 
335  desc.add<std::string>("PFSuperClusterCollectionEndcap", "particleFlowSuperClusterECALEndcap");
336  desc.add<bool>("doSatelliteClusterMerge", false);
337  desc.add<double>("thresh_PFClusterBarrel", 0.0);
338  desc.add<std::string>("PFBasicClusterCollectionBarrel", "particleFlowBasicClusterECALBarrel");
339  desc.add<bool>("useRegression", true);
340  desc.add<double>("satelliteMajorityFraction", 0.5);
341  desc.add<double>("thresh_PFClusterEndcap", 0.0);
342  desc.add<edm::InputTag>("ESAssociation", edm::InputTag("particleFlowClusterECAL"));
343  desc.add<std::string>("PFBasicClusterCollectionPreshower", "particleFlowBasicClusterECALPreshower");
344  desc.add<bool>("use_preshower", true);
345  desc.addUntracked<bool>("verbose", false);
346  desc.add<double>("thresh_SCEt", 4.0);
347  desc.add<double>("etawidth_SuperClusterEndcap", 0.04);
348  desc.add<double>("phiwidth_SuperClusterEndcap", 0.6);
349  desc.add<bool>("useDynamicDPhiWindow", true);
350  desc.add<std::string>("PFSuperClusterCollectionBarrel", "particleFlowSuperClusterECALBarrel");
352  desc.add<bool>("applyCrackCorrections", false);
353  desc.add<double>("satelliteClusterSeedThreshold", 50.0);
354  desc.add<double>("etawidth_SuperClusterBarrel", 0.04);
355  desc.add<std::string>("PFBasicClusterCollectionEndcap", "particleFlowBasicClusterECALEndcap");
356  desc.add<edm::InputTag>("PFClusters", edm::InputTag("particleFlowClusterECAL"));
357  desc.add<double>("thresh_PFClusterSeedBarrel", 1.0);
358  desc.add<std::string>("ClusteringType", "Mustache");
359  desc.add<std::string>("EnergyWeight", "Raw");
360  desc.add<edm::InputTag>("BeamSpot", edm::InputTag("offlineBeamSpot"));
361  desc.add<double>("thresh_PFClusterSeedEndcap", 1.0);
362  desc.add<double>("phiwidth_SuperClusterBarrel", 0.6);
363  desc.add<double>("thresh_PFClusterES", 0.0);
364  desc.add<bool>("seedThresholdIsET", true);
365  desc.add<bool>("isOOTCollection", false);
366  desc.add<edm::InputTag>("barrelRecHits", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
367  desc.add<edm::InputTag>("endcapRecHits", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
368  desc.add<std::string>("PFSuperClusterCollectionEndcapWithPreshower",
369  "particleFlowSuperClusterECALEndcapWithPreshower");
370  desc.add<bool>("dropUnseedable", false);
371  descriptions.add("particleFlowSuperClusterECALMustache", desc);
372 }
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
PFECALSuperClusterAlgo::clustering_type _theclusteringtype
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::shared_ptr< PFEnergyCalibration > thePFEnergyCalibration_
tuple satelliteMajorityFraction
tuple dropUnseedable
tuple doSatelliteClusterMerge
int iEvent
Definition: GenABIO.cc:224
PFECALSuperClusterProducer(const edm::ParameterSet &)
PFECALSuperClusterAlgo superClusterAlgo_
clustering algorithm
def move
Definition: eostools.py:511
tuple seedThresholdIsET
ParameterDescriptionBase * add(U const &iLabel, T const &value)
PFECALSuperClusterAlgo::energy_weight _theenergyweight
static edm::ParameterSetDescription makePSetDescription()
void produce(edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
\ Algorithm for box particle flow super clustering in the ECAL
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
tuple satelliteClusterSeedThreshold