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  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
26 
27 private:
28  // inputs
31  bool cutsFromDB;
32  HcalPFCuts const* paramPF = nullptr;
33 
34  // options
35  const bool _prodInitClusters;
36  // the actual algorithm
37  std::vector<std::unique_ptr<RecHitTopologicalCleanerBase>> _cleaners;
38  std::vector<std::unique_ptr<RecHitTopologicalCleanerBase>> _seedcleaners;
39  std::unique_ptr<SeedFinderBase> _seedFinder;
40  std::unique_ptr<InitialClusteringStepBase> _initialClustering;
41  std::unique_ptr<PFClusterBuilderBase> _pfClusterBuilder;
42  std::unique_ptr<PFCPositionCalculatorBase> _positionReCalc;
43  std::unique_ptr<PFClusterEnergyCorrectorBase> _energyCorrector;
44 };
45 
48 
51  desc.add<edm::InputTag>("recHitsSource", {});
52  desc.add<bool>("usePFThresholdsFromDB", false);
53  {
55  psd.add<std::string>("algoName", "");
56  desc.addVPSet("recHitCleaners", psd, {});
57  }
58  {
60  psd.add<std::string>("algoName", "");
61  psd.add<std::vector<std::string>>("RecHitFlagsToBeExcluded", {});
62  desc.addVPSet("seedCleaners", psd, {});
63  }
64  {
66  pset.add<std::string>("algoName", "");
67  pset.add<int>("nNeighbours", 0);
68  {
70  psd.add<std::string>("detector", "");
71  psd.addNode((edm::ParameterDescription<double>("seedingThreshold", 0, true) and
72  edm::ParameterDescription<double>("seedingThresholdPt", 0, true)) xor
73  (edm::ParameterDescription<std::vector<int>>("depths", {}, true) and
74  edm::ParameterDescription<std::vector<double>>("seedingThreshold", {}, true) and
75  edm::ParameterDescription<std::vector<double>>("seedingThresholdPt", {}, true)));
76  pset.addVPSet("thresholdsByDetector", psd, {});
77  }
78  desc.add<edm::ParameterSetDescription>("seedFinder", pset);
79  }
80  {
82  pset.add<std::string>("algoName", "");
83  {
85  psd.add<std::string>("detector", "");
86  psd.addNode((edm::ParameterDescription<double>("gatheringThreshold", 0, true) and
87  edm::ParameterDescription<double>("gatheringThresholdPt", 0, true)) xor
88  (edm::ParameterDescription<std::vector<int>>("depths", {}, true) and
89  edm::ParameterDescription<std::vector<double>>("gatheringThreshold", {}, true) and
90  edm::ParameterDescription<std::vector<double>>("gatheringThresholdPt", {}, true)));
91  pset.addVPSet("thresholdsByDetector", psd, {});
92  }
93  pset.add<bool>("useCornerCells", false);
94  pset.add<edm::InputTag>("clusterSrc", {});
95  pset.add<bool>("filterByTracksterIteration", false);
96  pset.add<bool>("filterByTracksterPID", false);
97  pset.add<std::vector<int>>("filter_on_categories", {});
98  pset.add<std::vector<int>>("filter_on_iterations", {});
99  pset.add<double>("pid_threshold", 0);
100  pset.add<edm::InputTag>("tracksterSrc", {});
101  pset.add<double>("exclusiveFraction", 0);
102  pset.add<double>("invisibleFraction", 0);
103  pset.add<bool>("maxDistanceFilter", false);
104  pset.add<double>("maxDistance", 0);
105  pset.add<double>("maxDforTimingSquared", 0);
106  pset.add<double>("timeOffset", 0);
107  pset.add<uint32_t>("minNHitsforTiming", 0);
108  pset.add<bool>("useMCFractionsForExclEnergy", false);
109  pset.add<std::vector<double>>("hadronCalib", {});
110  pset.add<std::vector<double>>("egammaCalib", {});
111  pset.add<double>("calibMinEta", 0);
112  pset.add<double>("calibMaxEta", 0);
113  pset.add<edm::InputTag>("simClusterSrc", {});
114  desc.add<edm::ParameterSetDescription>("initialClusteringStep", pset);
115  }
116  {
118  pset.add<std::string>("algoName", "");
119  {
121  pset2.add<std::string>("algoName", "");
122  pset2.add<double>("minFractionInCalc", 0);
123  pset2.add<int>("posCalcNCrystals", -1);
124  {
126  psd.add<std::string>("detector", "");
127  psd.add<std::vector<int>>("depths", {});
128  psd.add<std::vector<double>>("logWeightDenominator", {});
129  pset2.addVPSet("logWeightDenominatorByDetector", psd, {});
130  }
131  pset2.add<double>("logWeightDenominator", 0);
132  pset2.add<double>("minAllowedNormalization", 0);
133  {
135  pset3.add<double>("constantTerm", 0);
136  pset3.add<double>("constantTermLowE", 0);
137  pset3.add<double>("corrTermLowE", 0);
138  pset3.add<double>("noiseTerm", 0);
139  pset3.add<double>("noiseTermLowE", 0);
140  pset3.add<double>("threshHighE", -1.);
141  pset3.add<double>("threshLowE", -1.);
142  pset2.add<edm::ParameterSetDescription>("timeResolutionCalcBarrel", pset3);
143  pset2.add<edm::ParameterSetDescription>("timeResolutionCalcEndcap", pset3);
144  }
145  pset.add<edm::ParameterSetDescription>("allCellsPositionCalc", pset2);
146  pset.add<edm::ParameterSetDescription>("positionCalc", pset2);
147  }
148  pset.add<double>("minFractionToKeep", 0);
149  pset.add<double>("nSigmaEta", 0);
150  pset.add<double>("nSigmaPhi", 0);
151  pset.add<bool>("excludeOtherSeeds", false);
152  pset.add<uint32_t>("maxIterations", 0);
153  pset.add<double>("minFracTot", 0);
154  {
156  pset2.add<std::string>("algoName", "");
157  pset2.add<double>("minFractionInCalc", 0);
158  pset2.add<double>("T0_EB", 0);
159  pset2.add<double>("T0_EE", 0);
160  pset2.add<double>("T0_ES", 0);
161  pset2.add<double>("W0", 0);
162  pset2.add<double>("X0", 0);
163  pset2.add<double>("minAllowedNormalization", 0);
164  pset2.add<edm::ParameterSetDescription>("timeResolutionCalc", {});
165  pset.add<edm::ParameterSetDescription>("positionCalcForConvergence", pset2);
166  }
167  {
169  psd.add<std::string>("detector", "");
170  psd.addNode(edm::ParameterDescription<double>("recHitEnergyNorm", 0, true) xor
171  (edm::ParameterDescription<std::vector<int>>("depths", {}, true) and
172  edm::ParameterDescription<std::vector<double>>("recHitEnergyNorm", {}, true)));
173  pset.addVPSet("recHitEnergyNorms", psd, {});
174  }
175  pset.add<double>("showerSigma", 1.5);
176  pset.add<double>("stoppingTolerance", 1e-08);
177  pset.add<bool>("clusterTimeResFromSeed", false);
178  pset.add<double>("maxNSigmaTime", 10.0);
179  pset.add<double>("minChi2Prob", 0);
180  {
182  pset2.add<double>("constantTerm", 0);
183  pset2.add<double>("constantTermLowE", 0);
184  pset2.add<double>("corrTermLowE", 0);
185  pset2.add<double>("noiseTerm", 0);
186  pset2.add<double>("noiseTermLowE", 0);
187  pset2.add<double>("threshHighE", -1.);
188  pset2.add<double>("threshLowE", -1.);
189  pset.add<edm::ParameterSetDescription>("timeResolutionCalcBarrel", pset2);
190  pset.add<edm::ParameterSetDescription>("timeResolutionCalcEndcap", pset2);
191  }
192  pset.add<double>("timeSigmaEB", 10.0);
193  pset.add<double>("timeSigmaEE", 10.0);
194  desc.add<edm::ParameterSetDescription>("pfClusterBuilder", pset);
195  }
196  {
198  pset.add<std::string>("algoName", "");
199  pset.add<double>("minFractionInCalc", 0);
200  pset.add<bool>("updateTiming", false);
201  pset.add<double>("T0_EB", 0);
202  pset.add<double>("T0_EE", 0);
203  pset.add<double>("T0_ES", 0);
204  pset.add<double>("W0", 0);
205  pset.add<double>("X0", 0);
206  pset.add<double>("minAllowedNormalization", 0);
207  pset.add<edm::ParameterSetDescription>("timeResolutionCalc", {});
208  desc.add<edm::ParameterSetDescription>("positionReCalc", pset);
209  }
210  desc.add<edm::ParameterSetDescription>("energyCorrector", {});
211  descriptions.addWithDefaultLabel(desc);
212 }
213 
214 #ifdef PFLOW_DEBUG
215 #define LOGVERB(x) edm::LogVerbatim(x)
216 #define LOGWARN(x) edm::LogWarning(x)
217 #define LOGERR(x) edm::LogError(x)
218 #define LOGDRESSED(x) edm::LogInfo(x)
219 #else
220 #define LOGVERB(x) LogTrace(x)
221 #define LOGWARN(x) edm::LogWarning(x)
222 #define LOGERR(x) edm::LogError(x)
223 #define LOGDRESSED(x) LogDebug(x)
224 #endif
225 
227  : _prodInitClusters(conf.getUntrackedParameter<bool>("prodInitialClusters", false)) {
228  _rechitsLabel = consumes<reco::PFRecHitCollection>(conf.getParameter<edm::InputTag>("recHitsSource"));
229  cutsFromDB = conf.getParameter<bool>("usePFThresholdsFromDB");
230  edm::ConsumesCollector cc = consumesCollector();
231 
232  if (cutsFromDB) {
233  hcalCutsToken_ = esConsumes<HcalPFCuts, HcalPFCutsRcd, edm::Transition::BeginRun>(edm::ESInputTag("", "withTopo"));
234  }
235 
236  //setup rechit cleaners
237  const edm::VParameterSet& cleanerConfs = conf.getParameterSetVector("recHitCleaners");
238  for (const auto& conf : cleanerConfs) {
239  const std::string& cleanerName = conf.getParameter<std::string>("algoName");
240  _cleaners.emplace_back(RecHitTopologicalCleanerFactory::get()->create(cleanerName, conf, cc));
241  }
242 
243  const auto& seedcleanerConfs = conf.getParameterSetVector("seedCleaners");
244  if (!seedcleanerConfs.empty()) {
245  for (const auto& conf : seedcleanerConfs) {
246  const std::string& seedcleanerName = conf.getParameter<std::string>("algoName");
247  _seedcleaners.emplace_back(RecHitTopologicalCleanerFactory::get()->create(seedcleanerName, conf, cc));
248  }
249  }
250 
251  // setup seed finding
252  const edm::ParameterSet& sfConf = conf.getParameterSet("seedFinder");
253  const std::string& sfName = sfConf.getParameter<std::string>("algoName");
254  _seedFinder = SeedFinderFactory::get()->create(sfName, sfConf);
255  //setup topo cluster builder
256  const edm::ParameterSet& initConf = conf.getParameterSet("initialClusteringStep");
257  const std::string& initName = initConf.getParameter<std::string>("algoName");
258  _initialClustering = InitialClusteringStepFactory::get()->create(initName, initConf, cc);
259  //setup pf cluster builder if requested
260  const edm::ParameterSet& pfcConf = conf.getParameterSet("pfClusterBuilder");
261  if (!pfcConf.empty()) {
262  const std::string& pfcName = pfcConf.getParameter<std::string>("algoName");
263  if (!pfcName.empty())
264  _pfClusterBuilder = PFClusterBuilderFactory::get()->create(pfcName, pfcConf, cc);
265  }
266  //setup (possible) recalcuation of positions
267  const edm::ParameterSet& pConf = conf.getParameterSet("positionReCalc");
268  if (!pConf.empty()) {
269  const std::string& pName = pConf.getParameter<std::string>("algoName");
270  if (!pName.empty())
271  _positionReCalc = PFCPositionCalculatorFactory::get()->create(pName, pConf, cc);
272  }
273  // see if new need to apply corrections, setup if there.
274  const edm::ParameterSet& cConf = conf.getParameterSet("energyCorrector");
275  if (!cConf.empty()) {
276  const std::string& cName = cConf.getParameter<std::string>("algoName");
277  if (!cName.empty())
278  _energyCorrector = PFClusterEnergyCorrectorFactory::get()->create(cName, cConf);
279  }
280 
281  if (_prodInitClusters) {
282  produces<reco::PFClusterCollection>("initialClusters");
283  }
284  produces<reco::PFClusterCollection>();
285 }
286 
288  if (cutsFromDB) {
290  }
291  _initialClustering->update(es);
292  if (_pfClusterBuilder)
293  _pfClusterBuilder->update(es);
294  if (_positionReCalc)
295  _positionReCalc->update(es);
296  for (const auto& cleaner : _cleaners)
297  cleaner->update(es);
298  for (const auto& cleaner : _seedcleaners)
299  cleaner->update(es);
300 }
301 
303  _initialClustering->reset();
304  if (_pfClusterBuilder)
305  _pfClusterBuilder->reset();
306 
308  e.getByToken(_rechitsLabel, rechits);
309 
310  _initialClustering->updateEvent(e);
311 
312  std::vector<bool> mask(rechits->size(), true);
313  for (const auto& cleaner : _cleaners) {
314  cleaner->clean(rechits, mask);
315  }
316 
317  // no seeding on these hits
318  std::vector<bool> seedmask = mask;
319  for (const auto& cleaner : _seedcleaners) {
320  cleaner->clean(rechits, seedmask);
321  }
322 
323  std::vector<bool> seedable(rechits->size(), false);
324  _seedFinder->findSeeds(rechits, seedmask, seedable, paramPF);
325 
326  auto initialClusters = std::make_unique<reco::PFClusterCollection>();
327  _initialClustering->buildClusters(rechits, mask, seedable, *initialClusters, paramPF);
328  LOGVERB("PFClusterProducer::produce()") << *_initialClustering;
329 
330  auto pfClusters = std::make_unique<reco::PFClusterCollection>();
331  pfClusters = std::make_unique<reco::PFClusterCollection>();
332  if (_pfClusterBuilder) { // if we've defined a re-clustering step execute it
333  _pfClusterBuilder->buildClusters(*initialClusters, seedable, *pfClusters, paramPF);
334  LOGVERB("PFClusterProducer::produce()") << *_pfClusterBuilder;
335  } else {
336  pfClusters->insert(pfClusters->end(), initialClusters->begin(), initialClusters->end());
337  }
338 
339  if (_positionReCalc) {
340  _positionReCalc->calculateAndSetPositions(*pfClusters, paramPF);
341  }
342 
343  if (_energyCorrector) {
344  _energyCorrector->correctEnergies(*pfClusters);
345  }
346 
347  if (_prodInitClusters)
348  e.put(std::move(initialClusters), "initialClusters");
349  e.put(std::move(pfClusters));
350 }
std::unique_ptr< SeedFinderBase > _seedFinder
std::unique_ptr< PFClusterEnergyCorrectorBase > _energyCorrector
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
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
RecHitTopologicalCleanerBase RHCB
ParameterSet const & getParameterSet(std::string const &) const
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
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
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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