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 threshPFClusterMustacheOutBarrel = iConfig.getParameter<double>("thresh_PFClusterMustacheOutBarrel");
103  //double threshPFClusterMustacheOutEndcap = iConfig.getParameter<double>("thresh_PFClusterMustacheOutEndcap");
104 
105  double doSatelliteClusterMerge =
106  iConfig.getParameter<bool>("doSatelliteClusterMerge");
108  iConfig.getParameter<double>("satelliteClusterSeedThreshold");
109  double satelliteMajorityFraction =
110  iConfig.getParameter<double>("satelliteMajorityFraction");
111  bool dropUnseedable = iConfig.getParameter<bool>("dropUnseedable");
112 
113  superClusterAlgo_.setVerbosityLevel(verbose_);
114  superClusterAlgo_.setClusteringType(_theclusteringtype);
115  superClusterAlgo_.setEnergyWeighting(_theenergyweight);
116  superClusterAlgo_.setUseETForSeeding(seedThresholdIsET);
117  superClusterAlgo_.setUseDynamicDPhi(useDynamicDPhi);
118 
119  superClusterAlgo_.setThreshSuperClusterEt( iConfig.getParameter<double>("thresh_SCEt") );
120 
121  superClusterAlgo_.setThreshPFClusterSeedBarrel( threshPFClusterSeedBarrel );
122  superClusterAlgo_.setThreshPFClusterBarrel( threshPFClusterBarrel );
123 
124  superClusterAlgo_.setThreshPFClusterSeedEndcap( threshPFClusterSeedEndcap );
125  superClusterAlgo_.setThreshPFClusterEndcap( threshPFClusterEndcap );
126 
127  superClusterAlgo_.setPhiwidthSuperClusterBarrel( phiwidthSuperClusterBarrel );
128  superClusterAlgo_.setEtawidthSuperClusterBarrel( etawidthSuperClusterBarrel );
129 
130  superClusterAlgo_.setPhiwidthSuperClusterEndcap( phiwidthSuperClusterEndcap );
131  superClusterAlgo_.setEtawidthSuperClusterEndcap( etawidthSuperClusterEndcap );
132 
133  superClusterAlgo_.setSatelliteMerging( doSatelliteClusterMerge );
134  superClusterAlgo_.setSatelliteThreshold( satelliteClusterSeedThreshold );
135  superClusterAlgo_.setMajorityFraction( satelliteMajorityFraction );
136  superClusterAlgo_.setDropUnseedable( dropUnseedable );
137  //superClusterAlgo_.setThreshPFClusterMustacheOutBarrel( threshPFClusterMustacheOutBarrel );
138  //superClusterAlgo_.setThreshPFClusterMustacheOutEndcap( threshPFClusterMustacheOutEndcap );
139 
140  //Load the ECAL energy calibration
141  thePFEnergyCalibration_ =
142  std::make_shared<PFEnergyCalibration>();
143  superClusterAlgo_.setPFClusterCalibration(thePFEnergyCalibration_);
144 
145  bool applyCrackCorrections_ = iConfig.getParameter<bool>("applyCrackCorrections");
146  superClusterAlgo_.setCrackCorrections(applyCrackCorrections_);
147 
148  PFBasicClusterCollectionBarrel_ = iConfig.getParameter<string>("PFBasicClusterCollectionBarrel");
149  PFSuperClusterCollectionBarrel_ = iConfig.getParameter<string>("PFSuperClusterCollectionBarrel");
150 
151  PFBasicClusterCollectionEndcap_ = iConfig.getParameter<string>("PFBasicClusterCollectionEndcap");
152  PFSuperClusterCollectionEndcap_ = iConfig.getParameter<string>("PFSuperClusterCollectionEndcap");
153 
154  PFBasicClusterCollectionPreshower_ = iConfig.getParameter<string>("PFBasicClusterCollectionPreshower");
155  PFSuperClusterCollectionEndcapWithPreshower_ = iConfig.getParameter<string>("PFSuperClusterCollectionEndcapWithPreshower");
156 
157  PFClusterAssociationEBEE_ = "PFClusterAssociationEBEE";
158  PFClusterAssociationES_ = "PFClusterAssociationES";
159 
160  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionBarrel_);
161  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionEndcapWithPreshower_);
162  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionBarrel_);
163  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionEndcap_);
164  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionPreshower_);
165  produces<edm::ValueMap<reco::CaloClusterPtr> >(PFClusterAssociationEBEE_);
166  produces<edm::ValueMap<reco::CaloClusterPtr> >(PFClusterAssociationES_);
167 }
168 
169 
170 
172 
175  superClusterAlgo_.update(iE);
176 }
177 
178 
180  const edm::EventSetup& iSetup) {
181 
182  // do clustering
183  superClusterAlgo_.loadAndSortPFClusters(iEvent);
184  superClusterAlgo_.run();
185 
186  //build collections of output CaloClusters from the used PFClusters
187  auto caloClustersEB = std::make_unique<reco::CaloClusterCollection>();
188  auto caloClustersEE = std::make_unique<reco::CaloClusterCollection>();
189  auto caloClustersES = std::make_unique<reco::CaloClusterCollection>();
190 
191  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEB; //maps of pfclusters to caloclusters
192  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEE;
193  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapES;
194 
195  //fill calocluster collections and maps
196  for( const auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection()) ) {
197  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus!=ebsc.clustersEnd(); ++pfclus) {
198  if (!pfClusterMapEB.count(*pfclus)) {
199  reco::CaloCluster caloclus(**pfclus);
200  caloClustersEB->push_back(caloclus);
201  pfClusterMapEB[*pfclus] = caloClustersEB->size() - 1;
202  }
203  else {
204  throw cms::Exception("PFECALSuperClusterProducer::produce")
205  << "Found an EB pfcluster matched to more than one EB supercluster!"
206  << std::dec << std::endl;
207  }
208  }
209  }
210  for( const auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection()) ) {
211  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus!=eesc.clustersEnd(); ++pfclus) {
212  if (!pfClusterMapEE.count(*pfclus)) {
213  reco::CaloCluster caloclus(**pfclus);
214  caloClustersEE->push_back(caloclus);
215  pfClusterMapEE[*pfclus] = caloClustersEE->size() - 1;
216  }
217  else {
218  throw cms::Exception("PFECALSuperClusterProducer::produce")
219  << "Found an EE pfcluster matched to more than one EE supercluster!"
220  << std::dec << std::endl;
221  }
222  }
223  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus!=eesc.preshowerClustersEnd(); ++pfclus) {
224  if (!pfClusterMapES.count(*pfclus)) {
225  reco::CaloCluster caloclus(**pfclus);
226  caloClustersES->push_back(caloclus);
227  pfClusterMapES[*pfclus] = caloClustersES->size() - 1;
228  }
229  else {
230  throw cms::Exception("PFECALSuperClusterProducer::produce")
231  << "Found an ES pfcluster matched to more than one EE supercluster!"
232  << std::dec << std::endl;
233  }
234  }
235  }
236 
237  //create ValueMaps from output CaloClusters back to original PFClusters
238  auto pfClusterAssociationEBEE = std::make_unique<edm::ValueMap<reco::CaloClusterPtr>>();
239  auto pfClusterAssociationES = std::make_unique<edm::ValueMap<reco::CaloClusterPtr>>();
240 
241  //vectors to fill ValueMaps
242  std::vector<reco::CaloClusterPtr> clusptrsEB(caloClustersEB->size());
243  std::vector<reco::CaloClusterPtr> clusptrsEE(caloClustersEE->size());
244  std::vector<reco::CaloClusterPtr> clusptrsES(caloClustersES->size());
245 
246  //put calocluster output collections in event and get orphan handles to create ptrs
247  const edm::OrphanHandle<reco::CaloClusterCollection> &caloClusHandleEB = iEvent.put(std::move(caloClustersEB),PFBasicClusterCollectionBarrel_);
248  const edm::OrphanHandle<reco::CaloClusterCollection> &caloClusHandleEE = iEvent.put(std::move(caloClustersEE),PFBasicClusterCollectionEndcap_);
249  const edm::OrphanHandle<reco::CaloClusterCollection> &caloClusHandleES = iEvent.put(std::move(caloClustersES),PFBasicClusterCollectionPreshower_);
250 
251  //relink superclusters to output caloclusters and fill vectors for ValueMaps
252  for( auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection()) ) {
253  reco::CaloClusterPtr seedptr(caloClusHandleEB,pfClusterMapEB[ebsc.seed()]);
254  ebsc.setSeed(seedptr);
255 
257  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus!=ebsc.clustersEnd(); ++pfclus) {
258  int caloclusidx = pfClusterMapEB[*pfclus];
259  reco::CaloClusterPtr clusptr(caloClusHandleEB,caloclusidx);
260  clusters.push_back(clusptr);
261  clusptrsEB[caloclusidx] = *pfclus;
262  }
263  ebsc.setClusters(clusters);
264  }
265  for( auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection()) ) {
266  reco::CaloClusterPtr seedptr(caloClusHandleEE,pfClusterMapEE[eesc.seed()]);
267  eesc.setSeed(seedptr);
268 
270  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus!=eesc.clustersEnd(); ++pfclus) {
271  int caloclusidx = pfClusterMapEE[*pfclus];
272  reco::CaloClusterPtr clusptr(caloClusHandleEE,caloclusidx);
273  clusters.push_back(clusptr);
274  clusptrsEE[caloclusidx] = *pfclus;
275  }
276  eesc.setClusters(clusters);
277 
278  reco::CaloClusterPtrVector psclusters;
279  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus!=eesc.preshowerClustersEnd(); ++pfclus) {
280  int caloclusidx = pfClusterMapES[*pfclus];
281  reco::CaloClusterPtr clusptr(caloClusHandleES,caloclusidx);
282  psclusters.push_back(clusptr);
283  clusptrsES[caloclusidx] = *pfclus;
284  }
285  eesc.setPreshowerClusters(psclusters);
286  }
287 
288  //fill association maps from output CaloClusters back to original PFClusters
289  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerEBEE(*pfClusterAssociationEBEE);
290  fillerEBEE.insert(caloClusHandleEB, clusptrsEB.begin(), clusptrsEB.end());
291  fillerEBEE.insert(caloClusHandleEE, clusptrsEE.begin(), clusptrsEE.end());
292  fillerEBEE.fill();
293 
294  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerES(*pfClusterAssociationES);
295  fillerES.insert(caloClusHandleES, clusptrsES.begin(), clusptrsES.end());
296  fillerES.fill();
297 
298  //store in the event
299  iEvent.put(std::move(pfClusterAssociationEBEE),PFClusterAssociationEBEE_);
300  iEvent.put(std::move(pfClusterAssociationES),PFClusterAssociationES_);
301  iEvent.put(std::move(superClusterAlgo_.getEBOutputSCCollection()),
302  PFSuperClusterCollectionBarrel_);
303  iEvent.put(std::move(superClusterAlgo_.getEEOutputSCCollection()),
304  PFSuperClusterCollectionEndcapWithPreshower_);
305 }
306 
309  desc.add<std::string>("PFSuperClusterCollectionEndcap","particleFlowSuperClusterECALEndcap");
310  desc.add<bool>("doSatelliteClusterMerge",false);
311  desc.add<double>("thresh_PFClusterBarrel",0.0);
312  desc.add<std::string>("PFBasicClusterCollectionBarrel","particleFlowBasicClusterECALBarrel");
313  desc.add<bool>("useRegression",true);
314  desc.add<double>("satelliteMajorityFraction",0.5);
315  desc.add<double>("thresh_PFClusterEndcap",0.0);
316  desc.add<edm::InputTag>("ESAssociation",edm::InputTag("particleFlowClusterECAL"));
317  desc.add<std::string>("PFBasicClusterCollectionPreshower","particleFlowBasicClusterECALPreshower");
318  desc.add<bool>("use_preshower",true);
319  desc.addUntracked<bool>("verbose",false);
320  desc.add<double>("thresh_SCEt",4.0);
321  desc.add<double>("etawidth_SuperClusterEndcap",0.04);
322  desc.add<double>("phiwidth_SuperClusterEndcap",0.6);
323  desc.add<bool>("useDynamicDPhiWindow",true);
324  desc.add<std::string>("PFSuperClusterCollectionBarrel","particleFlowSuperClusterECALBarrel");
325  {
327  psd0.add<bool>("isHLT", false);
328  psd0.add<bool>("applySigmaIetaIphiBug", false);
329  psd0.add<edm::InputTag>("ecalRecHitsEE",edm::InputTag("ecalRecHit","EcalRecHitsEE"));
330  psd0.add<edm::InputTag>("ecalRecHitsEB",edm::InputTag("ecalRecHit","EcalRecHitsEB"));
331  psd0.add<std::string>("regressionKeyEB","pfscecal_EBCorrection_offline_v1");
332  psd0.add<std::string>("regressionKeyEE","pfscecal_EECorrection_offline_v1");
333  psd0.add<std::string>("uncertaintyKeyEB","pfscecal_EBUncertainty_offline_v1");
334  psd0.add<std::string>("uncertaintyKeyEE","pfscecal_EEUncertainty_offline_v1");
335  psd0.add<edm::InputTag>("vertexCollection",edm::InputTag("offlinePrimaryVertices"));
336  psd0.add<double>("eRecHitThreshold", 1.);
337  desc.add<edm::ParameterSetDescription>("regressionConfig",psd0);
338  }
339  desc.add<bool>("applyCrackCorrections",false);
340  desc.add<double>("satelliteClusterSeedThreshold",50.0);
341  desc.add<double>("etawidth_SuperClusterBarrel",0.04);
342  desc.add<std::string>("PFBasicClusterCollectionEndcap","particleFlowBasicClusterECALEndcap");
343  desc.add<edm::InputTag>("PFClusters",edm::InputTag("particleFlowClusterECAL"));
344  desc.add<double>("thresh_PFClusterSeedBarrel",1.0);
345  desc.add<std::string>("ClusteringType","Mustache");
346  desc.add<std::string>("EnergyWeight","Raw");
347  desc.add<edm::InputTag>("BeamSpot",edm::InputTag("offlineBeamSpot"));
348  desc.add<double>("thresh_PFClusterSeedEndcap",1.0);
349  desc.add<double>("phiwidth_SuperClusterBarrel",0.6);
350  desc.add<double>("thresh_PFClusterES",0.0);
351  desc.add<bool>("seedThresholdIsET",true);
352  desc.add<bool>("isOOTCollection",false);
353  desc.add<edm::InputTag>("barrelRecHits",edm::InputTag("ecalRecHit","EcalRecHitsEE"));
354  desc.add<edm::InputTag>("endcapRecHits",edm::InputTag("ecalRecHit","EcalRecHitsEB"));
355  desc.add<std::string>("PFSuperClusterCollectionEndcapWithPreshower","particleFlowSuperClusterECALEndcapWithPreshower");
356  desc.add<bool>("dropUnseedable",false);
357  descriptions.add("particleFlowSuperClusterECALMustache",desc);
358 }
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:125
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:224
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:511