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