CMS 3D CMS Logo

PFClusterProducer.cc
Go to the documentation of this file.
1 #include "PFClusterProducer.h"
2 
3 #ifdef PFLOW_DEBUG
4 #define LOGVERB(x) edm::LogVerbatim(x)
5 #define LOGWARN(x) edm::LogWarning(x)
6 #define LOGERR(x) edm::LogError(x)
7 #define LOGDRESSED(x) edm::LogInfo(x)
8 #else
9 #define LOGVERB(x) LogTrace(x)
10 #define LOGWARN(x) edm::LogWarning(x)
11 #define LOGERR(x) edm::LogError(x)
12 #define LOGDRESSED(x) LogDebug(x)
13 #endif
14 
16  _prodInitClusters(conf.getUntrackedParameter<bool>("prodInitialClusters",false))
17 {
18  _rechitsLabel = consumes<reco::PFRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsSource"));
19  //setup rechit cleaners
20  const edm::VParameterSet& cleanerConfs =
21  conf.getParameterSetVector("recHitCleaners");
22  for( const auto& conf : cleanerConfs ) {
23  const std::string& cleanerName =
24  conf.getParameter<std::string>("algoName");
25  RHCB* cleaner =
26  RecHitTopologicalCleanerFactory::get()->create(cleanerName,conf);
27  _cleaners.push_back(std::unique_ptr<RHCB>(cleaner));
28  }
30 
31  // setup seed finding
32  const edm::ParameterSet& sfConf =
33  conf.getParameterSet("seedFinder");
34  const std::string& sfName = sfConf.getParameter<std::string>("algoName");
35  SeedFinderBase* sfb = SeedFinderFactory::get()->create(sfName,sfConf);
36  _seedFinder.reset(sfb);
37  //setup topo cluster builder
38  const edm::ParameterSet& initConf =
39  conf.getParameterSet("initialClusteringStep");
40  const std::string& initName = initConf.getParameter<std::string>("algoName");
41  ICSB* initb = InitialClusteringStepFactory::get()->create(initName,initConf,sumes);
42  _initialClustering.reset(initb);
43  //setup pf cluster builder if requested
44  _pfClusterBuilder.reset(nullptr);
45  const edm::ParameterSet& pfcConf = conf.getParameterSet("pfClusterBuilder");
46  if( !pfcConf.empty() ) {
47  const std::string& pfcName = pfcConf.getParameter<std::string>("algoName");
48  PFCBB* pfcb = PFClusterBuilderFactory::get()->create(pfcName,pfcConf);
49  _pfClusterBuilder.reset(pfcb);
50  }
51  //setup (possible) recalcuation of positions
52  _positionReCalc.reset(nullptr);
53  const edm::ParameterSet& pConf = conf.getParameterSet("positionReCalc");
54  if( !pConf.empty() ) {
55  const std::string& pName = pConf.getParameter<std::string>("algoName");
56  PosCalc* pcalc = PFCPositionCalculatorFactory::get()->create(pName,pConf);
57  _positionReCalc.reset(pcalc);
58  }
59  // see if new need to apply corrections, setup if there.
60  const edm::ParameterSet& cConf = conf.getParameterSet("energyCorrector");
61  if( !cConf.empty() ) {
62  const std::string& cName = cConf.getParameter<std::string>("algoName");
64  PFClusterEnergyCorrectorFactory::get()->create(cName,cConf);
65  _energyCorrector.reset(eCorr);
66  }
67 
68 
69  if( _prodInitClusters ) {
70  produces<reco::PFClusterCollection>("initialClusters");
71  }
72  produces<reco::PFClusterCollection>();
73 }
74 
76  const edm::EventSetup& es) {
77  _initialClustering->update(es);
78  if( _pfClusterBuilder ) _pfClusterBuilder->update(es);
79  if( _positionReCalc ) _positionReCalc->update(es);
80 
81 }
82 
84  _initialClustering->reset();
85  if( _pfClusterBuilder ) _pfClusterBuilder->reset();
86 
88  e.getByToken(_rechitsLabel,rechits);
89 
90  _initialClustering->updateEvent(e);
91 
92  std::vector<bool> mask(rechits->size(),true);
93  for( const auto& cleaner : _cleaners ) {
94  cleaner->clean(rechits, mask);
95  }
96 
97 
98 
99  std::vector<bool> seedable(rechits->size(),false);
100  _seedFinder->findSeeds(rechits,mask,seedable);
101 
102 
103 
104  auto initialClusters = std::make_unique<reco::PFClusterCollection>();
105  _initialClustering->buildClusters(rechits, mask, seedable, *initialClusters);
106  LOGVERB("PFClusterProducer::produce()") << *_initialClustering;
107 
108 
109 
110 
111  auto pfClusters = std::make_unique<reco::PFClusterCollection>();
112  pfClusters.reset(new reco::PFClusterCollection);
113  if( _pfClusterBuilder ) { // if we've defined a re-clustering step execute it
114  _pfClusterBuilder->buildClusters(*initialClusters, seedable, *pfClusters);
115  LOGVERB("PFClusterProducer::produce()") << *_pfClusterBuilder;
116  } else {
117  pfClusters->insert(pfClusters->end(),
118  initialClusters->begin(),initialClusters->end());
119  }
120 
121 
122 
123 
124  if( _positionReCalc ) {
125  _positionReCalc->calculateAndSetPositions(*pfClusters);
126  }
127 
128  if( _energyCorrector ) {
129  _energyCorrector->correctEnergies(*pfClusters);
130  }
131 
132  if( _prodInitClusters ) e.put(std::move(initialClusters),"initialClusters");
133  e.put(std::move(pfClusters));
134 }
std::unique_ptr< SeedFinderBase > _seedFinder
T getParameter(std::string const &) const
std::unique_ptr< PFClusterEnergyCorrectorBase > _energyCorrector
bool empty() const
Definition: ParameterSet.h:218
VParameterSet const & getParameterSetVector(std::string const &name) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
std::unique_ptr< PFClusterBuilderBase > _pfClusterBuilder
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
#define LOGVERB(x)
std::unique_ptr< PFCPositionCalculatorBase > _positionReCalc
std::vector< std::unique_ptr< RecHitTopologicalCleanerBase > > _cleaners
const bool _prodInitClusters
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
edm::EDGetTokenT< reco::PFRecHitCollection > _rechitsLabel
std::unique_ptr< InitialClusteringStepBase > _initialClustering
void produce(edm::Event &, const edm::EventSetup &) override
ParameterSet const & getParameterSet(std::string const &) const
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
PFClusterProducer(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:510
T get(const Candidate &c)
Definition: component.h:55