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