CMS 3D CMS Logo

PFClusterProducer.cc
Go to the documentation of this file.
11 #include <memory>
12 
18 
19 public:
21  ~PFClusterProducer() override = default;
22 
23  void beginRun(const edm::Run&, const edm::EventSetup&) override;
24  void produce(edm::Event&, const edm::EventSetup&) override;
25 
26 private:
27  // inputs
30  bool cutsFromDB;
31  HcalPFCuts const* paramPF = nullptr;
32 
33  // options
34  const bool _prodInitClusters;
35  // the actual algorithm
36  std::vector<std::unique_ptr<RecHitTopologicalCleanerBase> > _cleaners;
37  std::vector<std::unique_ptr<RecHitTopologicalCleanerBase> > _seedcleaners;
38  std::unique_ptr<SeedFinderBase> _seedFinder;
39  std::unique_ptr<InitialClusteringStepBase> _initialClustering;
40  std::unique_ptr<PFClusterBuilderBase> _pfClusterBuilder;
41  std::unique_ptr<PFCPositionCalculatorBase> _positionReCalc;
42  std::unique_ptr<PFClusterEnergyCorrectorBase> _energyCorrector;
43 };
44 
47 
48 #ifdef PFLOW_DEBUG
49 #define LOGVERB(x) edm::LogVerbatim(x)
50 #define LOGWARN(x) edm::LogWarning(x)
51 #define LOGERR(x) edm::LogError(x)
52 #define LOGDRESSED(x) edm::LogInfo(x)
53 #else
54 #define LOGVERB(x) LogTrace(x)
55 #define LOGWARN(x) edm::LogWarning(x)
56 #define LOGERR(x) edm::LogError(x)
57 #define LOGDRESSED(x) LogDebug(x)
58 #endif
59 
61  : _prodInitClusters(conf.getUntrackedParameter<bool>("prodInitialClusters", false)) {
62  _rechitsLabel = consumes<reco::PFRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsSource"));
63  cutsFromDB = conf.getParameter<bool>("usePFThresholdsFromDB");
64  edm::ConsumesCollector cc = consumesCollector();
65 
66  if (cutsFromDB) {
67  hcalCutsToken_ = esConsumes<HcalPFCuts, HcalPFCutsRcd, edm::Transition::BeginRun>(edm::ESInputTag("", "withTopo"));
68  }
69 
70  //setup rechit cleaners
71  const edm::VParameterSet& cleanerConfs = conf.getParameterSetVector("recHitCleaners");
72  for (const auto& conf : cleanerConfs) {
73  const std::string& cleanerName = conf.getParameter<std::string>("algoName");
74  _cleaners.emplace_back(RecHitTopologicalCleanerFactory::get()->create(cleanerName, conf, cc));
75  }
76 
77  if (conf.exists("seedCleaners")) {
78  const edm::VParameterSet& seedcleanerConfs = conf.getParameterSetVector("seedCleaners");
79 
80  for (const auto& conf : seedcleanerConfs) {
81  const std::string& seedcleanerName = conf.getParameter<std::string>("algoName");
82  _seedcleaners.emplace_back(RecHitTopologicalCleanerFactory::get()->create(seedcleanerName, conf, cc));
83  }
84  }
85 
86  // setup seed finding
87  const edm::ParameterSet& sfConf = conf.getParameterSet("seedFinder");
88  const std::string& sfName = sfConf.getParameter<std::string>("algoName");
89  _seedFinder = SeedFinderFactory::get()->create(sfName, sfConf);
90  //setup topo cluster builder
91  const edm::ParameterSet& initConf = conf.getParameterSet("initialClusteringStep");
92  const std::string& initName = initConf.getParameter<std::string>("algoName");
93  _initialClustering = InitialClusteringStepFactory::get()->create(initName, initConf, cc);
94  //setup pf cluster builder if requested
95  const edm::ParameterSet& pfcConf = conf.getParameterSet("pfClusterBuilder");
96  if (!pfcConf.empty()) {
97  const std::string& pfcName = pfcConf.getParameter<std::string>("algoName");
98  _pfClusterBuilder = PFClusterBuilderFactory::get()->create(pfcName, pfcConf, cc);
99  }
100  //setup (possible) recalcuation of positions
101  const edm::ParameterSet& pConf = conf.getParameterSet("positionReCalc");
102  if (!pConf.empty()) {
103  const std::string& pName = pConf.getParameter<std::string>("algoName");
104  _positionReCalc = PFCPositionCalculatorFactory::get()->create(pName, pConf, cc);
105  }
106  // see if new need to apply corrections, setup if there.
107  const edm::ParameterSet& cConf = conf.getParameterSet("energyCorrector");
108  if (!cConf.empty()) {
109  const std::string& cName = cConf.getParameter<std::string>("algoName");
110  _energyCorrector = PFClusterEnergyCorrectorFactory::get()->create(cName, cConf);
111  }
112 
113  if (_prodInitClusters) {
114  produces<reco::PFClusterCollection>("initialClusters");
115  }
116  produces<reco::PFClusterCollection>();
117 }
118 
120  if (cutsFromDB) {
122  }
123  _initialClustering->update(es);
124  if (_pfClusterBuilder)
125  _pfClusterBuilder->update(es);
126  if (_positionReCalc)
127  _positionReCalc->update(es);
128  for (const auto& cleaner : _cleaners)
129  cleaner->update(es);
130  for (const auto& cleaner : _seedcleaners)
131  cleaner->update(es);
132 }
133 
135  _initialClustering->reset();
136  if (_pfClusterBuilder)
137  _pfClusterBuilder->reset();
138 
140  e.getByToken(_rechitsLabel, rechits);
141 
142  _initialClustering->updateEvent(e);
143 
144  std::vector<bool> mask(rechits->size(), true);
145  for (const auto& cleaner : _cleaners) {
146  cleaner->clean(rechits, mask);
147  }
148 
149  // no seeding on these hits
150  std::vector<bool> seedmask = mask;
151  for (const auto& cleaner : _seedcleaners) {
152  cleaner->clean(rechits, seedmask);
153  }
154 
155  std::vector<bool> seedable(rechits->size(), false);
156  _seedFinder->findSeeds(rechits, seedmask, seedable, paramPF);
157 
158  auto initialClusters = std::make_unique<reco::PFClusterCollection>();
159  _initialClustering->buildClusters(rechits, mask, seedable, *initialClusters, paramPF);
160  LOGVERB("PFClusterProducer::produce()") << *_initialClustering;
161 
162  auto pfClusters = std::make_unique<reco::PFClusterCollection>();
163  pfClusters = std::make_unique<reco::PFClusterCollection>();
164  if (_pfClusterBuilder) { // if we've defined a re-clustering step execute it
165  _pfClusterBuilder->buildClusters(*initialClusters, seedable, *pfClusters, paramPF);
166  LOGVERB("PFClusterProducer::produce()") << *_pfClusterBuilder;
167  } else {
168  pfClusters->insert(pfClusters->end(), initialClusters->begin(), initialClusters->end());
169  }
170 
171  if (_positionReCalc) {
172  _positionReCalc->calculateAndSetPositions(*pfClusters, paramPF);
173  }
174 
175  if (_energyCorrector) {
176  _energyCorrector->correctEnergies(*pfClusters);
177  }
178 
179  if (_prodInitClusters)
180  e.put(std::move(initialClusters), "initialClusters");
181  e.put(std::move(pfClusters));
182 }
std::unique_ptr< SeedFinderBase > _seedFinder
std::unique_ptr< PFClusterEnergyCorrectorBase > _energyCorrector
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
def create(alignables, pedeDump, additionalData, outputFile, config)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:35
std::unique_ptr< PFClusterBuilderBase > _pfClusterBuilder
void beginRun(const edm::Run &, const edm::EventSetup &) override
bool exists(std::string const &parameterName) const
checks if a parameter exists
RecHitTopologicalCleanerBase RHCB
ParameterSet const & getParameterSet(std::string const &) const
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
bool empty() const
Definition: ParameterSet.h:202
edm::EDGetTokenT< reco::PFRecHitCollection > _rechitsLabel
std::unique_ptr< InitialClusteringStepBase > _initialClustering
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, const edm::EventSetup &) override
HcalPFCuts const * paramPF
InitialClusteringStepBase ICSB
VParameterSet const & getParameterSetVector(std::string const &name) const
PFClusterProducer(const edm::ParameterSet &)
#define get
edm::ESGetToken< HcalPFCuts, HcalPFCutsRcd > hcalCutsToken_
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45