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  _rechitsLabel = consumes<reco::PFRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsSource"));
18  //setup rechit cleaners
19  const edm::VParameterSet& cleanerConfs = conf.getParameterSetVector("recHitCleaners");
20  for (const auto& conf : cleanerConfs) {
21  const std::string& cleanerName = conf.getParameter<std::string>("algoName");
22  _cleaners.emplace_back(RecHitTopologicalCleanerFactory::get()->create(cleanerName, conf));
23  }
24  edm::ConsumesCollector sumes = consumesCollector();
25 
26  // setup seed finding
27  const edm::ParameterSet& sfConf = conf.getParameterSet("seedFinder");
28  const std::string& sfName = sfConf.getParameter<std::string>("algoName");
29  _seedFinder = SeedFinderFactory::get()->create(sfName, sfConf);
30  //setup topo cluster builder
31  const edm::ParameterSet& initConf = conf.getParameterSet("initialClusteringStep");
32  const std::string& initName = initConf.getParameter<std::string>("algoName");
33  _initialClustering = InitialClusteringStepFactory::get()->create(initName, initConf, sumes);
34  //setup pf cluster builder if requested
35  const edm::ParameterSet& pfcConf = conf.getParameterSet("pfClusterBuilder");
36  if (!pfcConf.empty()) {
37  const std::string& pfcName = pfcConf.getParameter<std::string>("algoName");
38  _pfClusterBuilder = PFClusterBuilderFactory::get()->create(pfcName, pfcConf);
39  }
40  //setup (possible) recalcuation of positions
41  const edm::ParameterSet& pConf = conf.getParameterSet("positionReCalc");
42  if (!pConf.empty()) {
43  const std::string& pName = pConf.getParameter<std::string>("algoName");
44  _positionReCalc = PFCPositionCalculatorFactory::get()->create(pName, pConf);
45  }
46  // see if new need to apply corrections, setup if there.
47  const edm::ParameterSet& cConf = conf.getParameterSet("energyCorrector");
48  if (!cConf.empty()) {
49  const std::string& cName = cConf.getParameter<std::string>("algoName");
51  }
52 
53  if (_prodInitClusters) {
54  produces<reco::PFClusterCollection>("initialClusters");
55  }
56  produces<reco::PFClusterCollection>();
57 }
58 
60  _initialClustering->update(es);
62  _pfClusterBuilder->update(es);
63  if (_positionReCalc)
64  _positionReCalc->update(es);
65 }
66 
68  _initialClustering->reset();
70  _pfClusterBuilder->reset();
71 
73  e.getByToken(_rechitsLabel, rechits);
74 
75  _initialClustering->updateEvent(e);
76 
77  std::vector<bool> mask(rechits->size(), true);
78  for (const auto& cleaner : _cleaners) {
79  cleaner->clean(rechits, mask);
80  }
81 
82  std::vector<bool> seedable(rechits->size(), false);
83  _seedFinder->findSeeds(rechits, mask, seedable);
84 
85  auto initialClusters = std::make_unique<reco::PFClusterCollection>();
86  _initialClustering->buildClusters(rechits, mask, seedable, *initialClusters);
87  LOGVERB("PFClusterProducer::produce()") << *_initialClustering;
88 
89  auto pfClusters = std::make_unique<reco::PFClusterCollection>();
90  pfClusters.reset(new reco::PFClusterCollection);
91  if (_pfClusterBuilder) { // if we've defined a re-clustering step execute it
92  _pfClusterBuilder->buildClusters(*initialClusters, seedable, *pfClusters);
93  LOGVERB("PFClusterProducer::produce()") << *_pfClusterBuilder;
94  } else {
95  pfClusters->insert(pfClusters->end(), initialClusters->begin(), initialClusters->end());
96  }
97 
98  if (_positionReCalc) {
99  _positionReCalc->calculateAndSetPositions(*pfClusters);
100  }
101 
102  if (_energyCorrector) {
103  _energyCorrector->correctEnergies(*pfClusters);
104  }
105 
106  if (_prodInitClusters)
107  e.put(std::move(initialClusters), "initialClusters");
108  e.put(std::move(pfClusters));
109 }
std::unique_ptr< SeedFinderBase > _seedFinder
T getParameter(std::string const &) const
std::unique_ptr< PFClusterEnergyCorrectorBase > _energyCorrector
bool empty() const
Definition: ParameterSet.h:190
VParameterSet const & getParameterSetVector(std::string const &name) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
def create(alignables, pedeDump, additionalData, outputFile, config)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
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
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:511