CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
EGRefinedSCFixer Class Reference
Inheritance diagram for EGRefinedSCFixer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 EGRefinedSCFixer (const edm::ParameterSet &)
 
reco::SuperCluster makeFixedRefinedSC (const reco::SuperCluster &orgRefinedSC, const reco::SuperCluster &orgSC, const reco::SuperCluster &fixedSC)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
virtual ~EGRefinedSCFixer ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

static std::vector< edm::Ptr
< reco::PFCluster > > 
getClustersFromSeedIds (const std::unordered_set< unsigned > &seedIds, const edm::Handle< reco::PFClusterCollection > &inClusters)
 
static std::unordered_set
< unsigned > 
getListOfClusterSeedIdsForNewSC (const reco::SuperCluster &orgRefinedSC, const reco::SuperCluster &orgSC, const reco::SuperCluster &fixedSC, const std::vector< edm::Ptr< reco::CaloCluster > > &clustersAddedToAnySC)
 
static std::vector< edm::Ptr
< reco::CaloCluster > > 
getSubClustersMissing (const reco::SuperCluster &lhs, const reco::SuperCluster &rhs)
 
static reco::SuperCluster makeFixedRefinedBarrelSC (const reco::SuperCluster &orgRefinedSC, const reco::SuperCluster &orgSC, const reco::SuperCluster &fixedSC, const edm::Handle< reco::PFClusterCollection > &fixedClusters, const std::vector< edm::Ptr< reco::CaloCluster > > &clustersAddedToAnySC)
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Types

typedef edm::ValueMap
< reco::ConversionRef
ConvRefMap
 
typedef edm::ValueMap
< reco::SuperClusterRef
SCRefMap
 

Private Member Functions

template<typename T >
void getToken (edm::EDGetTokenT< T > &token, const edm::ParameterSet &pset, const std::string &label, const std::string &instance="")
 

Private Attributes

const std::string ebeeClustersCollection_
 
const std::string esClustersCollection_
 
edm::EDGetTokenT
< reco::PFClusterCollection
fixedPFClustersToken_
 
edm::EDGetTokenT
< reco::SuperClusterCollection
fixedSCToken_ [2]
 
edm::EDGetTokenT
< reco::CaloClusterCollection
orgBCToken_
 
edm::EDGetTokenT
< reco::ConversionCollection
orgConvToken_
 
edm::EDGetTokenT
< reco::CaloClusterCollection
orgESToken_
 
edm::EDGetTokenT
< reco::SuperClusterCollection
orgRefinedSCToken_
 
edm::EDGetTokenT
< reco::SuperClusterCollection
orgSCToken_ [2]
 
const bool throwOnDupECALClustersInEvent_
 
const bool throwOnDupESClustersInEvent_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T...> CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T...> HasAbility
 
typedef
CacheTypes::LuminosityBlockCache 
LuminosityBlockCache
 
typedef
LuminosityBlockContextT
< LuminosityBlockCache,
RunCache, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 49 of file EGRefinedSCFixer.cc.

Member Typedef Documentation

Definition at line 85 of file EGRefinedSCFixer.cc.

Definition at line 84 of file EGRefinedSCFixer.cc.

Constructor & Destructor Documentation

EGRefinedSCFixer::EGRefinedSCFixer ( const edm::ParameterSet iConfig)
explicit

Definition at line 120 of file EGRefinedSCFixer.cc.

References ebeeClustersCollection_, esClustersCollection_, fixedPFClustersToken_, fixedSCToken_, getToken(), orgBCToken_, orgConvToken_, orgESToken_, orgRefinedSCToken_, and orgSCToken_.

120  :
121  ebeeClustersCollection_("EBEEClusters"),
122  esClustersCollection_("ESClusters"),
123  throwOnDupECALClustersInEvent_(iConfig.getParameter<bool>("throwOnDupECALClustersInEvent")),
124  throwOnDupESClustersInEvent_(iConfig.getParameter<bool>("throwOnDupESClustersInEvent"))
125 
126 {
127  getToken(orgRefinedSCToken_, iConfig, "orgRefinedSC");
128  getToken(orgBCToken_, iConfig, "orgRefinedSC", "EBEEClusters");
129  getToken(orgESToken_, iConfig, "orgRefinedSC", "ESClusters");
130  getToken(orgConvToken_, iConfig, "orgRefinedSC");
131  getToken(orgSCToken_[0], iConfig, "orgSC", "particleFlowSuperClusterECALBarrel");
132  getToken(orgSCToken_[1], iConfig, "orgSC", "particleFlowSuperClusterECALEndcapWithPreshower");
133  getToken(fixedSCToken_[0], iConfig, "fixedSC", "particleFlowSuperClusterECALBarrel");
134  getToken(fixedSCToken_[1], iConfig, "fixedSC", "particleFlowSuperClusterECALEndcapWithPreshower");
135  getToken(fixedPFClustersToken_, iConfig, "fixedPFClusters");
136 
137  produces<reco::SuperClusterCollection>();
138  produces<reco::CaloClusterCollection>(ebeeClustersCollection_);
139  produces<reco::CaloClusterCollection>(esClustersCollection_);
140  produces<reco::ConversionCollection>();
141 
142  // products not in PFEGammaProducer; provide mapping from new to old objects
143  produces<SCRefMap>();
144  produces<SCRefMap>("parentSCsEB");
145  produces<SCRefMap>("parentSCsEE");
146  //flags to tell us if we have duplicate clusters
147  produces<bool>("dupECALClusters");
148  produces<bool>("dupESClusters");
149 }
const bool throwOnDupECALClustersInEvent_
T getParameter(std::string const &) const
const std::string esClustersCollection_
const bool throwOnDupESClustersInEvent_
edm::EDGetTokenT< reco::PFClusterCollection > fixedPFClustersToken_
const std::string ebeeClustersCollection_
edm::EDGetTokenT< reco::ConversionCollection > orgConvToken_
edm::EDGetTokenT< reco::CaloClusterCollection > orgESToken_
edm::EDGetTokenT< reco::SuperClusterCollection > fixedSCToken_[2]
edm::EDGetTokenT< reco::SuperClusterCollection > orgRefinedSCToken_
edm::EDGetTokenT< reco::SuperClusterCollection > orgSCToken_[2]
void getToken(edm::EDGetTokenT< T > &token, const edm::ParameterSet &pset, const std::string &label, const std::string &instance="")
edm::EDGetTokenT< reco::CaloClusterCollection > orgBCToken_
virtual EGRefinedSCFixer::~EGRefinedSCFixer ( )
inlinevirtual

Definition at line 52 of file EGRefinedSCFixer.cc.

52 {}

Member Function Documentation

std::vector< edm::Ptr< reco::PFCluster > > EGRefinedSCFixer::getClustersFromSeedIds ( const std::unordered_set< unsigned > &  seedIds,
const edm::Handle< reco::PFClusterCollection > &  inClusters 
)
static

Definition at line 394 of file EGRefinedSCFixer.cc.

Referenced by makeFixedRefinedBarrelSC().

395 {
396  std::vector<edm::Ptr<reco::PFCluster> > outClusters;
397  for(size_t clusNr=0;clusNr<inClusters->size();clusNr++){
398  edm::Ptr<reco::PFCluster> clusPtr(inClusters,clusNr);
399  if(seedIds.count(clusPtr->seed().rawId())>0){
400  outClusters.push_back(clusPtr);
401  }
402  }
403  std::sort(outClusters.begin(),outClusters.end(),[](auto& lhs,auto& rhs){return lhs->energy()>rhs->energy();});
404  return outClusters;
405 }
std::unordered_set< unsigned > EGRefinedSCFixer::getListOfClusterSeedIdsForNewSC ( const reco::SuperCluster orgRefinedSC,
const reco::SuperCluster orgSC,
const reco::SuperCluster fixedSC,
const std::vector< edm::Ptr< reco::CaloCluster > > &  clustersAddedToAnySC 
)
static

Definition at line 358 of file EGRefinedSCFixer.cc.

References reco::SuperCluster::clusters(), and getSubClustersMissing().

Referenced by makeFixedRefinedBarrelSC().

363 {
364  auto const& clusAdded = getSubClustersMissing(orgRefinedSC,orgSC);
365  auto const& clusRemoved = getSubClustersMissing(orgSC,orgRefinedSC);
366 
367 
368  std::unordered_set<unsigned> detIdsOfClustersForNewSC;
369  for(auto& clus : fixedSC.clusters()){
370  auto compFunc=[&clus](auto& rhs){return rhs->seed().rawId()==clus->seed().rawId();};
371 
372  //first check if the cluster was removed by the refining process
373  bool notRemoved = std::find_if(clusRemoved.begin(),clusRemoved.end(),compFunc)==clusRemoved.end();
374 
375  //now check if it was assigned to another supercluster (it wont be picked up by the previous
376  //check if the parent supercluster picked it up during reclustering)
377  //if its a cluster which is added to any supercluster it wont add it
378  //its okay if it was added to this supercluster as we will add it in below
379  bool notAddedToASuperCluster = std::find_if(clustersAddedToAnySC.begin(),
380  clustersAddedToAnySC.end(),compFunc)==clustersAddedToAnySC.end();
381 
382  if(notRemoved && notAddedToASuperCluster){
383  detIdsOfClustersForNewSC.insert(clus->seed().rawId());
384  }
385  }
386  for(auto clus : clusAdded){
387  detIdsOfClustersForNewSC.insert(clus->seed().rawId());
388  }
389 
390  return detIdsOfClustersForNewSC;
391 }
static std::vector< edm::Ptr< reco::CaloCluster > > getSubClustersMissing(const reco::SuperCluster &lhs, const reco::SuperCluster &rhs)
const CaloClusterPtrVector & clusters() const
const access to the cluster list itself
Definition: SuperCluster.h:69
std::vector< edm::Ptr< reco::CaloCluster > > EGRefinedSCFixer::getSubClustersMissing ( const reco::SuperCluster lhs,
const reco::SuperCluster rhs 
)
static

Definition at line 344 of file EGRefinedSCFixer.cc.

References edm::PtrVector< T >::begin(), reco::SuperCluster::clusters(), edm::PtrVector< T >::end(), and reco::SuperCluster::seed().

Referenced by getListOfClusterSeedIdsForNewSC(), and produce().

346 {
347  std::vector<edm::Ptr<reco::CaloCluster> > missingSubClusters;
348  for(auto& subClus : lhs.clusters()){
349  auto compFunc=[&subClus](const auto& rhs){return subClus->seed()==rhs->seed();};
350  if(std::find_if(rhs.clusters().begin(),rhs.clusters().end(),compFunc)==rhs.clusters().end()){
351  missingSubClusters.push_back(subClus);
352  }
353  }
354  return missingSubClusters;
355 }
const CaloClusterPtrVector & clusters() const
const access to the cluster list itself
Definition: SuperCluster.h:69
const_iterator begin() const
Definition: PtrVector.h:130
const_iterator end() const
Definition: PtrVector.h:135
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
template<typename T >
void EGRefinedSCFixer::getToken ( edm::EDGetTokenT< T > &  token,
const edm::ParameterSet pset,
const std::string &  label,
const std::string &  instance = "" 
)
inlineprivate

Definition at line 88 of file EGRefinedSCFixer.cc.

References edm::ParameterSet::getParameter(), instance, and GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by EGRefinedSCFixer().

88  {
89  auto tag(pset.getParameter<edm::InputTag>(label));
90  if (!instance.empty())
91  tag = edm::InputTag(tag.label(), instance, tag.process());
92 
93  token = consumes<T>(tag);
94  }
T getParameter(std::string const &) const
static PFTauRenderPlugin instance
reco::SuperCluster EGRefinedSCFixer::makeFixedRefinedBarrelSC ( const reco::SuperCluster orgRefinedSC,
const reco::SuperCluster orgSC,
const reco::SuperCluster fixedSC,
const edm::Handle< reco::PFClusterCollection > &  fixedClusters,
const std::vector< edm::Ptr< reco::CaloCluster > > &  clustersAddedToAnySC 
)
static

Definition at line 411 of file EGRefinedSCFixer.cc.

References reco::SuperCluster::addCluster(), reco::CaloCluster::addHitAndFraction(), HLT_25ns10e33_v2_cff::clusters, getClustersFromSeedIds(), getListOfClusterSeedIdsForNewSC(), PFClusterWidthAlgo::pflowEtaWidth(), PFClusterWidthAlgo::pflowPhiWidth(), reco::SuperCluster::rawEnergy(), reco::SuperCluster::seed(), reco::CaloCluster::setCorrectedEnergy(), reco::SuperCluster::setEtaWidth(), reco::SuperCluster::setPhiWidth(), reco::SuperCluster::setPreshowerEnergy(), reco::SuperCluster::setPreshowerEnergyPlane1(), reco::SuperCluster::setPreshowerEnergyPlane2(), and reco::SuperCluster::setSeed().

Referenced by produce().

416 {
417  auto listOfSeedIds = getListOfClusterSeedIdsForNewSC(orgRefinedSC,orgSC,fixedSC,clustersAddedToAnySC);
418 
419  // make sure the seed cluster is in the listOfSeedIds
420  unsigned seedSeedId(fixedSC.seed()->seed().rawId());
421  listOfSeedIds.insert(seedSeedId);
422 
423  std::vector<edm::Ptr<reco::PFCluster> > clusters = getClustersFromSeedIds(listOfSeedIds,fixedClusters);
424 
425  // fixedSC.seed() is from a different BasicCluster collection
426  edm::Ptr<reco::PFCluster> seedCluster;
427  for (auto& ptr : clusters) {
428  if (ptr->seed().rawId() == seedSeedId) {
429  seedCluster = ptr;
430  break;
431  }
432  }
433 
434  std::vector<const reco::PFCluster*> clustersBarePtrs;
435 
436  double posX(0),posY(0),posZ(0);
437  double scNrgy(0),scCorrNrgy(0);
438  for(auto & clus : clusters){
439  clustersBarePtrs.push_back(&*clus);
440 
441  const double clusNrgy = clus->energy();
442  double clusCorrNrgy = clus->correctedEnergy();
443  const math::XYZPoint& clusPos = clus->position();
444  posX += clusNrgy * clusPos.X();
445  posY += clusNrgy * clusPos.Y();
446  posZ += clusNrgy * clusPos.Z();
447 
448  scNrgy += clusNrgy;
449  scCorrNrgy += clusCorrNrgy;
450 
451  }
452  posX /= scNrgy;
453  posY /= scNrgy;
454  posZ /= scNrgy;
455 
456  //intentionally passing in scCorrNrgy its not supposed to be scNrgy
457  reco::SuperCluster newSC(scCorrNrgy,math::XYZPoint(posX,posY,posZ));
458 
459  newSC.setCorrectedEnergy(scCorrNrgy);
460  newSC.setSeed(seedCluster); //the seed is the same as the non-refined SC
461  newSC.setPreshowerEnergyPlane1(0.);
462  newSC.setPreshowerEnergyPlane2(0.);
463  newSC.setPreshowerEnergy(0.);
464  for(const auto& clus : clusters ) {
465  newSC.addCluster(clus);
466  for(auto& hitAndFrac: clus->hitsAndFractions() ) {
467  newSC.addHitAndFraction(hitAndFrac.first,hitAndFrac.second);
468  }
469  }
470 
471  // calculate linearly weighted cluster widths
472  PFClusterWidthAlgo pfwidth(clustersBarePtrs);
473  newSC.setEtaWidth(pfwidth.pflowEtaWidth());
474  newSC.setPhiWidth(pfwidth.pflowPhiWidth());
475 
476  // cache the value of the raw energy
477  newSC.rawEnergy();
478 
479  return newSC;
480 }
static std::unordered_set< unsigned > getListOfClusterSeedIdsForNewSC(const reco::SuperCluster &orgRefinedSC, const reco::SuperCluster &orgSC, const reco::SuperCluster &fixedSC, const std::vector< edm::Ptr< reco::CaloCluster > > &clustersAddedToAnySC)
static std::vector< edm::Ptr< reco::PFCluster > > getClustersFromSeedIds(const std::unordered_set< unsigned > &seedIds, const edm::Handle< reco::PFClusterCollection > &inClusters)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
reco::SuperCluster EGRefinedSCFixer::makeFixedRefinedSC ( const reco::SuperCluster orgRefinedSC,
const reco::SuperCluster orgSC,
const reco::SuperCluster fixedSC 
)
void EGRefinedSCFixer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::stream::EDProducerBase.

Definition at line 162 of file EGRefinedSCFixer.cc.

References HLT_25ns10e33_v2_cff::clusters, conv, ebeeClustersCollection_, EcalBarrel, esClustersCollection_, Exception, edm::helper::Filler< Map >::fill(), fixedPFClustersToken_, fixedSCToken_, getSubClustersMissing(), edm::helper::Filler< Map >::insert(), edm::Ref< C, T, F >::isNonnull(), makeFixedRefinedBarrelSC(), GainSwitchTools::matchSCBySeedCrys(), eostools::move(), orgBCToken_, orgConvToken_, orgESToken_, orgRefinedSCToken_, orgSCToken_, edm::PtrVector< T >::push_back(), edm::Event::put(), throwOnDupECALClustersInEvent_, and throwOnDupESClustersInEvent_.

163 {
164  auto const& orgRefinedSCs = getHandle(iEvent, orgRefinedSCToken_);
165  auto const& orgBCs = getHandle(iEvent, orgBCToken_);
166  auto const& orgESs = getHandle(iEvent, orgESToken_);
167  auto const& orgConvs = getHandle(iEvent, orgConvToken_);
168  auto const& orgEBSCs = getHandle(iEvent,orgSCToken_[0]);
169  auto const& orgEESCs = getHandle(iEvent,orgSCToken_[1]);
170  auto const& fixedEBSCs = getHandle(iEvent,fixedSCToken_[0]);
171  auto const& fixedEESCs = getHandle(iEvent,fixedSCToken_[1]);
172  auto const& fixedPFClusters = getHandle(iEvent,fixedPFClustersToken_);
173 
174  auto fixedRefinedSCs = std::make_unique<reco::SuperClusterCollection>();
175  // EB clusters are fixed, EE are direct translation from the original
176  auto fixedBCs = std::make_unique<reco::CaloClusterCollection>();
177  // direct translation of the original ES collection - there is nothing "fixed" about this
178  // however they may be slightly different as we are reclustering from reduced rec-hit collections
179  // this will mainly effect non-photon or non-electron superclusters as those superclusters
180  // save less rec-hits surrounding them
181  auto fixedESs = std::make_unique<reco::CaloClusterCollection>();
182  auto fixedConvs = std::make_unique<reco::ConversionCollection>();
183 
184  std::vector<reco::SuperClusterRef> mappedRefinedSCs;
185  std::vector<reco::SuperClusterRef> mappedSCsEB(fixedEBSCs->size());
186  std::vector<reco::SuperClusterRef> mappedSCsEE(fixedEESCs->size());
187 
188  std::vector<edm::Ptr<reco::CaloCluster> > clusterAddedToAnyEBSC;
189  for(auto& refinedSC : *orgRefinedSCs){
190  if(refinedSC.seed()->seed().subdetId() == EcalBarrel) {
191  reco::SuperClusterRef parentSC = GainSwitchTools::matchSCBySeedCrys(refinedSC,orgEBSCs);
192  if(parentSC.isNonnull()) {
193  auto const& clusAdded = getSubClustersMissing(refinedSC,*parentSC);
194  for(auto clusPtr : clusAdded) clusterAddedToAnyEBSC.push_back(clusPtr);
195  }else{ //no parent supercluster, all superclusters in this supercluster are addded
196  for(auto clusPtr : refinedSC.clusters()) clusterAddedToAnyEBSC.push_back(clusPtr);
197  }
198  }
199  }
200 
201  for (unsigned iO(0); iO != orgRefinedSCs->size(); ++iO) {
202  auto& orgRefinedSC(orgRefinedSCs->at(iO));
203  mappedRefinedSCs.emplace_back(orgRefinedSCs, iO);
204 
205  // find the PFSuperCluster for this refined SC
206  if (orgRefinedSC.seed()->seed().subdetId() == EcalBarrel) {
207  auto orgEBSC(GainSwitchTools::matchSCBySeedCrys(orgRefinedSC, orgEBSCs));
208 
209  // particleFlowEGamma can create superclusters directly out of PFClusters too
210  // -> there is not always a matching EB SC
211  if (orgEBSC.isNonnull()) {
212  auto fixedEBSC(GainSwitchTools::matchSCBySeedCrys(*orgEBSC, fixedEBSCs, 1, 1));
213  if (fixedEBSC.isNonnull()) {
214  mappedSCsEB[fixedEBSC.key()] = orgEBSC;
215 
216  auto fixedRefinedSC(makeFixedRefinedBarrelSC(orgRefinedSC, *orgEBSC, *fixedEBSC, fixedPFClusters,clusterAddedToAnyEBSC));
217  fixedRefinedSCs->push_back(fixedRefinedSC);
218 
219  continue;
220  }
221  }
222  }
223  else {
224  auto orgEESC(GainSwitchTools::matchSCBySeedCrys(orgRefinedSC, orgEESCs));
225  if (orgEESC.isNonnull()) {
226  //there is nothing "fixed" here - two clusters are in theory identical but
227  //there could be mild differences given we are clustering from the
228  //reduced rec-hit collecitons
229  //for example this can lead to small energy changes leading a cluster to be
230  //now below the 4 GeV Et threshold to make a supercluster and therefore disappear
231  auto fixedEESC(GainSwitchTools::matchSCBySeedCrys(*orgEESC, fixedEESCs));
232  if(fixedEESC.isNonnull()) mappedSCsEE[fixedEESC.key()] = orgEESC;
233  }
234  }
235 
236  // if EE or no PFSuperCluster match
237  fixedRefinedSCs->push_back(orgRefinedSC);
238  }
239 
240 
241  // Put the PF SC maps in Event
242  std::auto_ptr<SCRefMap> pEBSCRefMap(new SCRefMap);
243  SCRefMap::Filler ebSCMapFiller(*pEBSCRefMap);
244  ebSCMapFiller.insert(fixedEBSCs, mappedSCsEB.begin(), mappedSCsEB.end());
245  ebSCMapFiller.fill();
246  iEvent.put(pEBSCRefMap, "parentSCsEB");
247 
248  std::auto_ptr<SCRefMap> pEESCRefMap(new SCRefMap);
249  SCRefMap::Filler eeSCMapFiller(*pEESCRefMap);
250  eeSCMapFiller.insert(fixedEESCs, mappedSCsEE.begin(), mappedSCsEE.end());
251  eeSCMapFiller.fill();
252  iEvent.put(pEESCRefMap, "parentSCsEE");
253 
254  // Copy basic clusters
255  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapEBEE; //maps of pfclusters to caloclusters
256  std::map<reco::CaloClusterPtr, unsigned int> pfClusterMapES;
257 
258  bool duplicateECALClusters=false;
259  bool duplicateESClusters=false;
260  for (auto& sc : *fixedRefinedSCs) {
261  // The cluster ref in fixed EB and the other superclusters point to different collections (former to gs-fixed, latter to original)
262  // but we are copying the basic clusters by value and remaking yet another collection here -> no need to distinguish
263  for (auto&& cItr(sc.clustersBegin()); cItr != sc.clustersEnd(); ++cItr) {
264  auto& ptr(*cItr);
265  if (pfClusterMapEBEE.count(ptr) == 0) {
266  pfClusterMapEBEE[ptr] = fixedBCs->size();
267  fixedBCs->emplace_back(*ptr);
268  }
269  else{
270  duplicateECALClusters=true;
272  throw cms::Exception("EGRefinedSCFixer::produce")
273  << "Found an EB/EE pfcluster matched to more than one supercluster!";
274  }
275  }
276  }
277 
278  for (auto&& cItr = sc.preshowerClustersBegin(); cItr!=sc.preshowerClustersEnd(); ++cItr) {
279  auto& ptr(*cItr);
280  if (pfClusterMapES.count(ptr) == 0) {
281  pfClusterMapES[ptr] = fixedESs->size();
282  fixedESs->emplace_back(*ptr);
283  }
284  else{
285  duplicateESClusters=true;
287  throw cms::Exception("PFEgammaProducer::produce")
288  << "Found an ES pfcluster matched to more than one supercluster!";
289  }
290  }
291  }
292  }
293  iEvent.put(std::make_unique<bool>(duplicateECALClusters),"dupECALClusters");
294  iEvent.put(std::make_unique<bool>(duplicateESClusters),"dupESClusters");
295 
296  //put calocluster output collections in event and get orphan handles to create ptrs
297  auto caloClusHandleEBEE(iEvent.put(std::move(fixedBCs), ebeeClustersCollection_));
298  auto caloClusHandleES(iEvent.put(std::move(fixedESs), esClustersCollection_));
299 
300  //relink superclusters to output caloclusters
301  for (auto& sc : *fixedRefinedSCs) {
302  edm::Ptr<reco::CaloCluster> seedptr(caloClusHandleEBEE, pfClusterMapEBEE[sc.seed()]);
303  sc.setSeed(seedptr);
304 
306  for (auto&& cItr(sc.clustersBegin()); cItr!=sc.clustersEnd(); ++cItr)
307  clusters.push_back(reco::CaloClusterPtr(caloClusHandleEBEE, pfClusterMapEBEE[*cItr]));
308  sc.setClusters(clusters);
309 
310  reco::CaloClusterPtrVector psclusters;
311  for (auto&& cItr(sc.preshowerClustersBegin()); cItr!=sc.preshowerClustersEnd(); ++cItr)
312  psclusters.push_back(reco::CaloClusterPtr(caloClusHandleES, pfClusterMapES[*cItr]));
313  sc.setPreshowerClusters(psclusters);
314  }
315 
316  auto scHandle(iEvent.put(std::move(fixedRefinedSCs)));
317 
318  // Put the new to old refined SC map
319  std::auto_ptr<SCRefMap> pRefinedSCRefMap(new SCRefMap);
320  SCRefMap::Filler refinedSCMapFiller(*pRefinedSCRefMap);
321  refinedSCMapFiller.insert(scHandle, mappedRefinedSCs.begin(), mappedRefinedSCs.end());
322  refinedSCMapFiller.fill();
323  iEvent.put(pRefinedSCRefMap);
324 
325  // copy and relink conversions
326  for (auto& conv : *orgConvs) {
327  // copy Ctor is not defined for reco::Conversion but there is a clone() method
328  // that uses a copy Ctor. I suppose this object can be trivially copied..
329  fixedConvs->emplace_back(conv);
330  auto& newConv(fixedConvs->back());
331  // conversion keeps a PtrVector, but according to PFEGammaProducer, single-leg conversions
332  // always have only one SC ptr.
334  // we create the new refined SC collection in the same order as the old one
335  scPtrVec.push_back(reco::CaloClusterPtr(scHandle, conv.caloCluster()[0].key()));
336  newConv.setMatchingSuperCluster(scPtrVec);
337  }
338 
339  iEvent.put(std::move(fixedConvs));
340 }
const bool throwOnDupECALClustersInEvent_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
const std::string esClustersCollection_
static std::vector< edm::Ptr< reco::CaloCluster > > getSubClustersMissing(const reco::SuperCluster &lhs, const reco::SuperCluster &rhs)
static HepMC::IO_HEPEVT conv
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:141
const bool throwOnDupESClustersInEvent_
edm::EDGetTokenT< reco::PFClusterCollection > fixedPFClustersToken_
static reco::SuperClusterRef matchSCBySeedCrys(const reco::SuperCluster &, HANDLE const &)
const std::string ebeeClustersCollection_
edm::EDGetTokenT< reco::ConversionCollection > orgConvToken_
edm::EDGetTokenT< reco::CaloClusterCollection > orgESToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
def move
Definition: eostools.py:510
edm::EDGetTokenT< reco::SuperClusterCollection > fixedSCToken_[2]
helper::Filler< ValueMap< reco::SuperClusterRef > > Filler
Definition: ValueMap.h:168
static reco::SuperCluster makeFixedRefinedBarrelSC(const reco::SuperCluster &orgRefinedSC, const reco::SuperCluster &orgSC, const reco::SuperCluster &fixedSC, const edm::Handle< reco::PFClusterCollection > &fixedClusters, const std::vector< edm::Ptr< reco::CaloCluster > > &clustersAddedToAnySC)
edm::EDGetTokenT< reco::SuperClusterCollection > orgRefinedSCToken_
edm::EDGetTokenT< reco::SuperClusterCollection > orgSCToken_[2]
edm::ValueMap< reco::SuperClusterRef > SCRefMap
edm::EDGetTokenT< reco::CaloClusterCollection > orgBCToken_

Member Data Documentation

const std::string EGRefinedSCFixer::ebeeClustersCollection_
private

Definition at line 109 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

const std::string EGRefinedSCFixer::esClustersCollection_
private

Definition at line 111 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

edm::EDGetTokenT<reco::PFClusterCollection> EGRefinedSCFixer::fixedPFClustersToken_
private

Definition at line 106 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

edm::EDGetTokenT<reco::SuperClusterCollection> EGRefinedSCFixer::fixedSCToken_[2]
private

Definition at line 104 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

edm::EDGetTokenT<reco::CaloClusterCollection> EGRefinedSCFixer::orgBCToken_
private

Definition at line 98 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

edm::EDGetTokenT<reco::ConversionCollection> EGRefinedSCFixer::orgConvToken_
private

Definition at line 100 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

edm::EDGetTokenT<reco::CaloClusterCollection> EGRefinedSCFixer::orgESToken_
private

Definition at line 99 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

edm::EDGetTokenT<reco::SuperClusterCollection> EGRefinedSCFixer::orgRefinedSCToken_
private

Definition at line 97 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

edm::EDGetTokenT<reco::SuperClusterCollection> EGRefinedSCFixer::orgSCToken_[2]
private

Definition at line 102 of file EGRefinedSCFixer.cc.

Referenced by EGRefinedSCFixer(), and produce().

const bool EGRefinedSCFixer::throwOnDupECALClustersInEvent_
private

Definition at line 115 of file EGRefinedSCFixer.cc.

Referenced by produce().

const bool EGRefinedSCFixer::throwOnDupESClustersInEvent_
private

Definition at line 116 of file EGRefinedSCFixer.cc.

Referenced by produce().