CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFECALSuperClusterProducer.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 
6 
8 
10 
15 
19 
22 
25 
27 
28 #include "TVector2.h"
30 
31 using namespace std;
32 using namespace edm;
33 
34 namespace {
35  const std::string ClusterType__BOX("Box");
36  const std::string ClusterType__Mustache("Mustache");
37 
38  const std::string EnergyWeight__Raw("Raw");
39  const std::string EnergyWeight__CalibratedNoPS("CalibratedNoPS");
40  const std::string EnergyWeight__CalibratedTotal("CalibratedTotal");
41 }
42 
44 {
45 
46  verbose_ =
47  iConfig.getUntrackedParameter<bool>("verbose",false);
48 
49  superClusterAlgo_.setUseRegression(iConfig.getParameter<bool>("useRegression"));
50 
51  superClusterAlgo_.setTokens(iConfig,consumesCollector());
52 
53  std::string _typename = iConfig.getParameter<std::string>("ClusteringType");
54  if( _typename == ClusterType__BOX ) {
55  _theclusteringtype = PFECALSuperClusterAlgo::kBOX;
56  } else if ( _typename == ClusterType__Mustache ) {
57  _theclusteringtype = PFECALSuperClusterAlgo::kMustache;
58  } else {
59  throw cms::Exception("InvalidClusteringType")
60  << "You have not chosen a valid clustering type,"
61  << " please choose from \"Box\" or \"Mustache\"!";
62  }
63 
64  std::string _weightname = iConfig.getParameter<std::string>("EnergyWeight");
65  if( _weightname == EnergyWeight__Raw ) {
66  _theenergyweight = PFECALSuperClusterAlgo::kRaw;
67  } else if ( _weightname == EnergyWeight__CalibratedNoPS ) {
68  _theenergyweight = PFECALSuperClusterAlgo::kCalibratedNoPS;
69  } else if ( _weightname == EnergyWeight__CalibratedTotal) {
71  } else {
72  throw cms::Exception("InvalidClusteringType")
73  << "You have not chosen a valid energy weighting scheme,"
74  << " please choose from \"Raw\", \"CalibratedNoPS\", or"
75  << " \"CalibratedTotal\"!";
76  }
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 threshPFClusterES = iConfig.getParameter<double>("thresh_PFClusterES");
97 
98  //double threshPFClusterMustacheOutBarrel = iConfig.getParameter<double>("thresh_PFClusterMustacheOutBarrel");
99  //double threshPFClusterMustacheOutEndcap = iConfig.getParameter<double>("thresh_PFClusterMustacheOutEndcap");
100 
101  double doSatelliteClusterMerge =
102  iConfig.getParameter<bool>("doSatelliteClusterMerge");
103  double satelliteClusterSeedThreshold =
104  iConfig.getParameter<double>("satelliteClusterSeedThreshold");
105  double satelliteMajorityFraction =
106  iConfig.getParameter<double>("satelliteMajorityFraction");
107 
108  superClusterAlgo_.setVerbosityLevel(verbose_);
109  superClusterAlgo_.setClusteringType(_theclusteringtype);
110  superClusterAlgo_.setEnergyWeighting(_theenergyweight);
111  superClusterAlgo_.setUseETForSeeding(seedThresholdIsET);
112  superClusterAlgo_.setUseDynamicDPhi(useDynamicDPhi);
113 
114  superClusterAlgo_.setThreshSuperClusterEt( iConfig.getParameter<double>("thresh_SCEt") );
115 
116  superClusterAlgo_.setThreshPFClusterSeedBarrel( threshPFClusterSeedBarrel );
117  superClusterAlgo_.setThreshPFClusterBarrel( threshPFClusterBarrel );
118 
119  superClusterAlgo_.setThreshPFClusterSeedEndcap( threshPFClusterSeedEndcap );
120  superClusterAlgo_.setThreshPFClusterEndcap( threshPFClusterEndcap );
121 
122  superClusterAlgo_.setPhiwidthSuperClusterBarrel( phiwidthSuperClusterBarrel );
123  superClusterAlgo_.setEtawidthSuperClusterBarrel( etawidthSuperClusterBarrel );
124 
125  superClusterAlgo_.setPhiwidthSuperClusterEndcap( phiwidthSuperClusterEndcap );
126  superClusterAlgo_.setEtawidthSuperClusterEndcap( etawidthSuperClusterEndcap );
127 
128  superClusterAlgo_.setThreshPFClusterES( threshPFClusterES );
129 
130  superClusterAlgo_.setSatelliteMerging( doSatelliteClusterMerge );
131  superClusterAlgo_.setSatelliteThreshold( satelliteClusterSeedThreshold );
132  superClusterAlgo_.setMajorityFraction( satelliteMajorityFraction );
133  //superClusterAlgo_.setThreshPFClusterMustacheOutBarrel( threshPFClusterMustacheOutBarrel );
134  //superClusterAlgo_.setThreshPFClusterMustacheOutEndcap( threshPFClusterMustacheOutEndcap );
135 
136  //Load the ECAL energy calibration
137  thePFEnergyCalibration_ =
138  std::shared_ptr<PFEnergyCalibration>(new PFEnergyCalibration());
139  superClusterAlgo_.setPFClusterCalibration(thePFEnergyCalibration_);
140  superClusterAlgo_.setUsePS(iConfig.getParameter<bool>("use_preshower"));
141 
142  bool applyCrackCorrections_ = iConfig.getParameter<bool>("applyCrackCorrections");
143  superClusterAlgo_.setCrackCorrections(applyCrackCorrections_);
144 
145  PFBasicClusterCollectionBarrel_ = iConfig.getParameter<string>("PFBasicClusterCollectionBarrel");
146  PFSuperClusterCollectionBarrel_ = iConfig.getParameter<string>("PFSuperClusterCollectionBarrel");
147 
148  PFBasicClusterCollectionEndcap_ = iConfig.getParameter<string>("PFBasicClusterCollectionEndcap");
149  PFSuperClusterCollectionEndcap_ = iConfig.getParameter<string>("PFSuperClusterCollectionEndcap");
150 
151  PFBasicClusterCollectionPreshower_ = iConfig.getParameter<string>("PFBasicClusterCollectionPreshower");
152  PFSuperClusterCollectionEndcapWithPreshower_ = iConfig.getParameter<string>("PFSuperClusterCollectionEndcapWithPreshower");
153 
154  PFClusterAssociationEBEE_ = "PFClusterAssociationEBEE";
155  PFClusterAssociationES_ = "PFClusterAssociationES";
156 
157  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionBarrel_);
158  produces<reco::SuperClusterCollection>(PFSuperClusterCollectionEndcapWithPreshower_);
159  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionBarrel_);
160  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionEndcap_);
161  produces<reco::CaloClusterCollection>(PFBasicClusterCollectionPreshower_);
162  produces<edm::ValueMap<reco::CaloClusterPtr> >(PFClusterAssociationEBEE_);
163  produces<edm::ValueMap<reco::CaloClusterPtr> >(PFClusterAssociationES_);
164 }
165 
166 
167 
169 
172  superClusterAlgo_.update(iE);
173 }
174 
175 
177  const edm::EventSetup& iSetup) {
178 
179  // do clustering
180  superClusterAlgo_.loadAndSortPFClusters(iEvent);
181  superClusterAlgo_.run();
182 
183  //build collections of output CaloClusters from the used PFClusters
184  std::auto_ptr<reco::CaloClusterCollection> caloClustersEB(new reco::CaloClusterCollection);
185  std::auto_ptr<reco::CaloClusterCollection> caloClustersEE(new reco::CaloClusterCollection);
186  std::auto_ptr<reco::CaloClusterCollection> caloClustersES(new reco::CaloClusterCollection);
187 
188  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEB; //maps of pfclusters to caloclusters
189  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEE;
190  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapES;
191 
192  //fill calocluster collections and maps
193  for( const auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection()) ) {
194  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus!=ebsc.clustersEnd(); ++pfclus) {
195  if (!pfClusterMapEB.count(*pfclus)) {
196  reco::CaloCluster caloclus(**pfclus);
197  caloClustersEB->push_back(caloclus);
198  pfClusterMapEB[*pfclus] = caloClustersEB->size() - 1;
199  }
200  else {
201  throw cms::Exception("PFECALSuperClusterProducer::produce")
202  << "Found an EB pfcluster matched to more than one EB supercluster!"
203  << std::dec << std::endl;
204  }
205  }
206  }
207  for( const auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection()) ) {
208  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus!=eesc.clustersEnd(); ++pfclus) {
209  if (!pfClusterMapEE.count(*pfclus)) {
210  reco::CaloCluster caloclus(**pfclus);
211  caloClustersEE->push_back(caloclus);
212  pfClusterMapEE[*pfclus] = caloClustersEE->size() - 1;
213  }
214  else {
215  throw cms::Exception("PFECALSuperClusterProducer::produce")
216  << "Found an EE pfcluster matched to more than one EE supercluster!"
217  << std::dec << std::endl;
218  }
219  }
220  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus!=eesc.preshowerClustersEnd(); ++pfclus) {
221  if (!pfClusterMapES.count(*pfclus)) {
222  reco::CaloCluster caloclus(**pfclus);
223  caloClustersES->push_back(caloclus);
224  pfClusterMapES[*pfclus] = caloClustersES->size() - 1;
225  }
226  else {
227  throw cms::Exception("PFECALSuperClusterProducer::produce")
228  << "Found an ES pfcluster matched to more than one EE supercluster!"
229  << std::dec << std::endl;
230  }
231  }
232  }
233 
234  //create ValueMaps from output CaloClusters back to original PFClusters
235  std::auto_ptr<edm::ValueMap<reco::CaloClusterPtr> > pfClusterAssociationEBEE(new edm::ValueMap<reco::CaloClusterPtr>);
236  std::auto_ptr<edm::ValueMap<reco::CaloClusterPtr> > pfClusterAssociationES(new edm::ValueMap<reco::CaloClusterPtr>);
237 
238  //vectors to fill ValueMaps
239  std::vector<reco::CaloClusterPtr> clusptrsEB(caloClustersEB->size());
240  std::vector<reco::CaloClusterPtr> clusptrsEE(caloClustersEE->size());
241  std::vector<reco::CaloClusterPtr> clusptrsES(caloClustersES->size());
242 
243  //put calocluster output collections in event and get orphan handles to create ptrs
244  const edm::OrphanHandle<reco::CaloClusterCollection> &caloClusHandleEB = iEvent.put(caloClustersEB,PFBasicClusterCollectionBarrel_);
245  const edm::OrphanHandle<reco::CaloClusterCollection> &caloClusHandleEE = iEvent.put(caloClustersEE,PFBasicClusterCollectionEndcap_);
246  const edm::OrphanHandle<reco::CaloClusterCollection> &caloClusHandleES = iEvent.put(caloClustersES,PFBasicClusterCollectionPreshower_);
247 
248  //relink superclusters to output caloclusters and fill vectors for ValueMaps
249  for( auto& ebsc : *(superClusterAlgo_.getEBOutputSCCollection()) ) {
250  reco::CaloClusterPtr seedptr(caloClusHandleEB,pfClusterMapEB[ebsc.seed()]);
251  ebsc.setSeed(seedptr);
252 
254  for (reco::CaloCluster_iterator pfclus = ebsc.clustersBegin(); pfclus!=ebsc.clustersEnd(); ++pfclus) {
255  int caloclusidx = pfClusterMapEB[*pfclus];
256  reco::CaloClusterPtr clusptr(caloClusHandleEB,caloclusidx);
257  clusters.push_back(clusptr);
258  clusptrsEB[caloclusidx] = *pfclus;
259  }
260  ebsc.setClusters(clusters);
261  }
262  for( auto& eesc : *(superClusterAlgo_.getEEOutputSCCollection()) ) {
263  reco::CaloClusterPtr seedptr(caloClusHandleEE,pfClusterMapEE[eesc.seed()]);
264  eesc.setSeed(seedptr);
265 
267  for (reco::CaloCluster_iterator pfclus = eesc.clustersBegin(); pfclus!=eesc.clustersEnd(); ++pfclus) {
268  int caloclusidx = pfClusterMapEE[*pfclus];
269  reco::CaloClusterPtr clusptr(caloClusHandleEE,caloclusidx);
270  clusters.push_back(clusptr);
271  clusptrsEE[caloclusidx] = *pfclus;
272  }
273  eesc.setClusters(clusters);
274 
275  reco::CaloClusterPtrVector psclusters;
276  for (reco::CaloCluster_iterator pfclus = eesc.preshowerClustersBegin(); pfclus!=eesc.preshowerClustersEnd(); ++pfclus) {
277  int caloclusidx = pfClusterMapES[*pfclus];
278  reco::CaloClusterPtr clusptr(caloClusHandleES,caloclusidx);
279  psclusters.push_back(clusptr);
280  clusptrsES[caloclusidx] = *pfclus;
281  }
282  eesc.setPreshowerClusters(psclusters);
283  }
284 
285  //fill association maps from output CaloClusters back to original PFClusters
286  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerEBEE(*pfClusterAssociationEBEE);
287  fillerEBEE.insert(caloClusHandleEB, clusptrsEB.begin(), clusptrsEB.end());
288  fillerEBEE.insert(caloClusHandleEE, clusptrsEE.begin(), clusptrsEE.end());
289  fillerEBEE.fill();
290 
291  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerES(*pfClusterAssociationES);
292  fillerES.insert(caloClusHandleES, clusptrsES.begin(), clusptrsES.end());
293  fillerES.fill();
294 
295  //store in the event
296  iEvent.put(pfClusterAssociationEBEE,PFClusterAssociationEBEE_);
297  iEvent.put(pfClusterAssociationES,PFClusterAssociationES_);
298  iEvent.put(superClusterAlgo_.getEBOutputSCCollection(),
299  PFSuperClusterCollectionBarrel_);
300  iEvent.put(superClusterAlgo_.getEEOutputSCCollection(),
301  PFSuperClusterCollectionEndcapWithPreshower_);
302 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void produce(edm::Event &, const edm::EventSetup &)
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:138
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
int iEvent
Definition: GenABIO.cc:230
PFECALSuperClusterProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
std::vector< CaloCluster > CaloClusterCollection
collection of CaloCluster objects
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)