CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PFClusterProducer.cc
Go to the documentation of this file.
9 
10 #include <memory>
11 
17 
18 public:
20  ~PFClusterProducer() override = default;
21 
22  void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override;
23  void produce(edm::Event&, const edm::EventSetup&) override;
24 
25 private:
26  // inputs
28  // options
29  const bool _prodInitClusters;
30  // the actual algorithm
31  std::vector<std::unique_ptr<RecHitTopologicalCleanerBase> > _cleaners;
32  std::vector<std::unique_ptr<RecHitTopologicalCleanerBase> > _seedcleaners;
33  std::unique_ptr<SeedFinderBase> _seedFinder;
34  std::unique_ptr<InitialClusteringStepBase> _initialClustering;
35  std::unique_ptr<PFClusterBuilderBase> _pfClusterBuilder;
36  std::unique_ptr<PFCPositionCalculatorBase> _positionReCalc;
37  std::unique_ptr<PFClusterEnergyCorrectorBase> _energyCorrector;
38 };
39 
42 
43 #ifdef PFLOW_DEBUG
44 #define LOGVERB(x) edm::LogVerbatim(x)
45 #define LOGWARN(x) edm::LogWarning(x)
46 #define LOGERR(x) edm::LogError(x)
47 #define LOGDRESSED(x) edm::LogInfo(x)
48 #else
49 #define LOGVERB(x) LogTrace(x)
50 #define LOGWARN(x) edm::LogWarning(x)
51 #define LOGERR(x) edm::LogError(x)
52 #define LOGDRESSED(x) LogDebug(x)
53 #endif
54 
56  : _prodInitClusters(conf.getUntrackedParameter<bool>("prodInitialClusters", false)) {
57  _rechitsLabel = consumes<reco::PFRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsSource"));
58  edm::ConsumesCollector cc = consumesCollector();
59 
60  //setup rechit cleaners
61  const edm::VParameterSet& cleanerConfs = conf.getParameterSetVector("recHitCleaners");
62  for (const auto& conf : cleanerConfs) {
63  const std::string& cleanerName = conf.getParameter<std::string>("algoName");
64  _cleaners.emplace_back(RecHitTopologicalCleanerFactory::get()->create(cleanerName, conf, cc));
65  }
66 
67  if (conf.exists("seedCleaners")) {
68  const edm::VParameterSet& seedcleanerConfs = conf.getParameterSetVector("seedCleaners");
69 
70  for (const auto& conf : seedcleanerConfs) {
71  const std::string& seedcleanerName = conf.getParameter<std::string>("algoName");
72  _seedcleaners.emplace_back(RecHitTopologicalCleanerFactory::get()->create(seedcleanerName, conf, cc));
73  }
74  }
75 
76  // setup seed finding
77  const edm::ParameterSet& sfConf = conf.getParameterSet("seedFinder");
78  const std::string& sfName = sfConf.getParameter<std::string>("algoName");
79  _seedFinder = SeedFinderFactory::get()->create(sfName, sfConf);
80  //setup topo cluster builder
81  const edm::ParameterSet& initConf = conf.getParameterSet("initialClusteringStep");
82  const std::string& initName = initConf.getParameter<std::string>("algoName");
83  _initialClustering = InitialClusteringStepFactory::get()->create(initName, initConf, cc);
84  //setup pf cluster builder if requested
85  const edm::ParameterSet& pfcConf = conf.getParameterSet("pfClusterBuilder");
86  if (!pfcConf.empty()) {
87  const std::string& pfcName = pfcConf.getParameter<std::string>("algoName");
88  _pfClusterBuilder = PFClusterBuilderFactory::get()->create(pfcName, pfcConf, cc);
89  }
90  //setup (possible) recalcuation of positions
91  const edm::ParameterSet& pConf = conf.getParameterSet("positionReCalc");
92  if (!pConf.empty()) {
93  const std::string& pName = pConf.getParameter<std::string>("algoName");
94  _positionReCalc = PFCPositionCalculatorFactory::get()->create(pName, pConf, cc);
95  }
96  // see if new need to apply corrections, setup if there.
97  const edm::ParameterSet& cConf = conf.getParameterSet("energyCorrector");
98  if (!cConf.empty()) {
99  const std::string& cName = cConf.getParameter<std::string>("algoName");
100  _energyCorrector = PFClusterEnergyCorrectorFactory::get()->create(cName, cConf);
101  }
102 
103  if (_prodInitClusters) {
104  produces<reco::PFClusterCollection>("initialClusters");
105  }
106  produces<reco::PFClusterCollection>();
107 }
108 
110  _initialClustering->update(es);
111  if (_pfClusterBuilder)
112  _pfClusterBuilder->update(es);
113  if (_positionReCalc)
114  _positionReCalc->update(es);
115  for (const auto& cleaner : _cleaners)
116  cleaner->update(es);
117  for (const auto& cleaner : _seedcleaners)
118  cleaner->update(es);
119 }
120 
122  _initialClustering->reset();
123  if (_pfClusterBuilder)
124  _pfClusterBuilder->reset();
125 
127  e.getByToken(_rechitsLabel, rechits);
128 
129  _initialClustering->updateEvent(e);
130 
131  std::vector<bool> mask(rechits->size(), true);
132  for (const auto& cleaner : _cleaners) {
133  cleaner->clean(rechits, mask);
134  }
135 
136  // no seeding on these hits
137  std::vector<bool> seedmask = mask;
138  for (const auto& cleaner : _seedcleaners) {
139  cleaner->clean(rechits, seedmask);
140  }
141 
142  std::vector<bool> seedable(rechits->size(), false);
143  _seedFinder->findSeeds(rechits, seedmask, seedable);
144 
145  auto initialClusters = std::make_unique<reco::PFClusterCollection>();
146  _initialClustering->buildClusters(rechits, mask, seedable, *initialClusters);
147  LOGVERB("PFClusterProducer::produce()") << *_initialClustering;
148 
149  auto pfClusters = std::make_unique<reco::PFClusterCollection>();
150  pfClusters = std::make_unique<reco::PFClusterCollection>();
151  if (_pfClusterBuilder) { // if we've defined a re-clustering step execute it
152  _pfClusterBuilder->buildClusters(*initialClusters, seedable, *pfClusters);
153  LOGVERB("PFClusterProducer::produce()") << *_pfClusterBuilder;
154  } else {
155  pfClusters->insert(pfClusters->end(), initialClusters->begin(), initialClusters->end());
156  }
157 
158  if (_positionReCalc) {
159  _positionReCalc->calculateAndSetPositions(*pfClusters);
160  }
161 
162  if (_energyCorrector) {
163  _energyCorrector->correctEnergies(*pfClusters);
164  }
165 
166  if (_prodInitClusters)
167  e.put(std::move(initialClusters), "initialClusters");
168  e.put(std::move(pfClusters));
169 }
std::unique_ptr< SeedFinderBase > _seedFinder
std::unique_ptr< PFClusterEnergyCorrectorBase > _energyCorrector
bool empty() const
Definition: ParameterSet.h:201
VParameterSet const & getParameterSetVector(std::string const &name) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
std::unique_ptr< PFClusterBuilderBase > _pfClusterBuilder
RecHitTopologicalCleanerBase RHCB
bool exists(std::string const &parameterName) const
checks if a parameter exists
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
std::vector< std::unique_ptr< RecHitTopologicalCleanerBase > > _seedcleaners
~PFClusterProducer() override=default
#define LOGVERB(x)
PFCPositionCalculatorBase PosCalc
std::unique_ptr< PFCPositionCalculatorBase > _positionReCalc
PFClusterBuilderBase PFCBB
std::vector< std::unique_ptr< RecHitTopologicalCleanerBase > > _cleaners
const bool _prodInitClusters
edm::EDGetTokenT< reco::PFRecHitCollection > _rechitsLabel
def move
Definition: eostools.py:511
std::unique_ptr< InitialClusteringStepBase > _initialClustering
list lumi
Definition: dqmdumpme.py:53
void produce(edm::Event &, const edm::EventSetup &) override
ParameterSet const & getParameterSet(std::string const &) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
InitialClusteringStepBase ICSB
PFClusterProducer(const edm::ParameterSet &)
#define get