CMS 3D CMS Logo

LegacyPFClusterProducer.cc
Go to the documentation of this file.
1 #include <Eigen/Core>
2 #include <Eigen/Dense>
3 #include <algorithm>
4 #include <array>
5 #include <cmath>
6 #include <iostream>
7 #include <memory>
8 #include <string>
9 #include <type_traits>
10 #include <unordered_map>
11 #include <utility>
12 #include <vector>
13 
24 
27 
36 
38 public:
40  : pfClusterSoAToken_(consumes(config.getParameter<edm::InputTag>("src"))),
41  pfRecHitFractionSoAToken_(consumes(config.getParameter<edm::InputTag>("src"))),
42  InputPFRecHitSoA_Token_{consumes(config.getParameter<edm::InputTag>("PFRecHitsLabelIn"))},
43  pfClusParamsToken_(esConsumes(config.getParameter<edm::ESInputTag>("pfClusterParams"))),
44  legacyPfClustersToken_(produces()),
45  recHitsLabel_(consumes(config.getParameter<edm::InputTag>("recHitsSource"))),
46  hcalCutsToken_(esConsumes<HcalPFCuts, HcalPFCutsRcd>(edm::ESInputTag("", "withTopo"))),
47  cutsFromDB_(config.getParameter<bool>("usePFThresholdsFromDB")) {
48  edm::ConsumesCollector cc = consumesCollector();
49 
50  //setup pf cluster builder if requested
51  const edm::ParameterSet& pfcConf = config.getParameterSet("pfClusterBuilder");
52  if (!pfcConf.empty()) {
53  if (pfcConf.exists("positionCalc")) {
54  const edm::ParameterSet& acConf = pfcConf.getParameterSet("positionCalc");
55  const std::string& algoac = acConf.getParameter<std::string>("algoName");
56  positionCalc_ = PFCPositionCalculatorFactory::get()->create(algoac, acConf, cc);
57  }
58 
59  if (pfcConf.exists("allCellsPositionCalc")) {
60  const edm::ParameterSet& acConf = pfcConf.getParameterSet("allCellsPositionCalc");
61  const std::string& algoac = acConf.getParameter<std::string>("algoName");
62  allCellsPositionCalc_ = PFCPositionCalculatorFactory::get()->create(algoac, acConf, cc);
63  }
64  }
65  }
66 
67  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
69  desc.add<edm::InputTag>("src");
70  desc.add<edm::InputTag>("PFRecHitsLabelIn");
71  desc.add<edm::ESInputTag>("pfClusterParams");
72  desc.add<edm::InputTag>("recHitsSource");
73  desc.add<bool>("usePFThresholdsFromDB", true);
74  {
76  pfClusterBuilder.add<unsigned int>("maxIterations", 5);
77  pfClusterBuilder.add<double>("minFracTot", 1e-20);
78  pfClusterBuilder.add<double>("minFractionToKeep", 1e-7);
79  pfClusterBuilder.add<bool>("excludeOtherSeeds", true);
80  pfClusterBuilder.add<double>("showerSigma", 10.);
81  pfClusterBuilder.add<double>("stoppingTolerance", 1e-8);
82  pfClusterBuilder.add<double>("timeSigmaEB", 10.);
83  pfClusterBuilder.add<double>("timeSigmaEE", 10.);
84  pfClusterBuilder.add<double>("maxNSigmaTime", 10.);
85  pfClusterBuilder.add<double>("minChi2Prob", 0.);
86  pfClusterBuilder.add<bool>("clusterTimeResFromSeed", false);
87  pfClusterBuilder.add<std::string>("algoName", "");
88  {
90  validator.add<std::string>("detector", "");
91  validator.add<std::vector<int>>("depths", {});
92  validator.add<std::vector<double>>("recHitEnergyNorm", {});
93  std::vector<edm::ParameterSet> vDefaults(2);
94  vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
95  vDefaults[0].addParameter<std::vector<int>>("depths", {1, 2, 3, 4});
96  vDefaults[0].addParameter<std::vector<double>>("recHitEnergyNorm", {0.1, 0.2, 0.3, 0.3});
97  vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
98  vDefaults[1].addParameter<std::vector<int>>("depths", {1, 2, 3, 4, 5, 6, 7});
99  vDefaults[1].addParameter<std::vector<double>>("recHitEnergyNorm", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
100  pfClusterBuilder.addVPSet("recHitEnergyNorms", validator, vDefaults);
101  }
102  {
104  bar.add<std::string>("algoName", "Basic2DGenericPFlowPositionCalc");
105  bar.add<double>("minFractionInCalc", 1e-9);
106  bar.add<int>("posCalcNCrystals", 5);
107  {
109  validator.add<std::string>("detector", "");
110  validator.add<std::vector<int>>("depths", {});
111  validator.add<std::vector<double>>("logWeightDenominator", {});
112  std::vector<edm::ParameterSet> vDefaults(2);
113  vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
114  vDefaults[0].addParameter<std::vector<int>>("depths", {1, 2, 3, 4});
115  vDefaults[0].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.3, 0.3});
116  vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
117  vDefaults[1].addParameter<std::vector<int>>("depths", {1, 2, 3, 4, 5, 6, 7});
118  vDefaults[1].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
119  bar.addVPSet("logWeightDenominatorByDetector", validator, vDefaults);
120  }
121  bar.add<double>("minAllowedNormalization", 1e-9);
122  pfClusterBuilder.add("positionCalc", bar);
123  }
124  {
126  bar.add<std::string>("algoName", "Basic2DGenericPFlowPositionCalc");
127  bar.add<double>("minFractionInCalc", 1e-9);
128  bar.add<int>("posCalcNCrystals", -1);
129  {
131  validator.add<std::string>("detector", "");
132  validator.add<std::vector<int>>("depths", {});
133  validator.add<std::vector<double>>("logWeightDenominator", {});
134  std::vector<edm::ParameterSet> vDefaults(2);
135  vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
136  vDefaults[0].addParameter<std::vector<int>>("depths", {1, 2, 3, 4});
137  vDefaults[0].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.3, 0.3});
138  vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
139  vDefaults[1].addParameter<std::vector<int>>("depths", {1, 2, 3, 4, 5, 6, 7});
140  vDefaults[1].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
141  bar.addVPSet("logWeightDenominatorByDetector", validator, vDefaults);
142  }
143  bar.add<double>("minAllowedNormalization", 1e-9);
144  pfClusterBuilder.add("allCellsPositionCalc", bar);
145  }
146  {
148  bar.add<double>("corrTermLowE", 0.);
149  bar.add<double>("threshLowE", 6.);
150  bar.add<double>("noiseTerm", 21.86);
151  bar.add<double>("constantTermLowE", 4.24);
152  bar.add<double>("noiseTermLowE", 8.);
153  bar.add<double>("threshHighE", 15.);
154  bar.add<double>("constantTerm", 2.82);
155  pfClusterBuilder.add("timeResolutionCalcBarrel", bar);
156  }
157  {
159  bar.add<double>("corrTermLowE", 0.);
160  bar.add<double>("threshLowE", 6.);
161  bar.add<double>("noiseTerm", 21.86);
162  bar.add<double>("constantTermLowE", 4.24);
163  bar.add<double>("noiseTermLowE", 8.);
164  bar.add<double>("threshHighE", 15.);
165  bar.add<double>("constantTerm", 2.82);
166  pfClusterBuilder.add("timeResolutionCalcEndcap", bar);
167  }
168  {
170  pfClusterBuilder.add("positionReCalc", bar);
171  }
172  {
174  pfClusterBuilder.add("energyCorrector", bar);
175  }
176  desc.add("pfClusterBuilder", pfClusterBuilder);
177  }
178  descriptions.addWithDefaultLabel(desc);
179  }
180 
181 private:
182  void produce(edm::Event&, const edm::EventSetup&) override;
190  const bool cutsFromDB_;
191  // the actual algorithm
192  std::unique_ptr<PFCPositionCalculatorBase> positionCalc_;
193  std::unique_ptr<PFCPositionCalculatorBase> allCellsPositionCalc_;
194 };
195 
198 
199  HcalPFCuts const* paramPF = cutsFromDB_ ? &setup.getData(hcalCutsToken_) : nullptr;
200 
201  auto const& pfClusterSoA = event.get(pfClusterSoAToken_).const_view();
202  auto const& pfRecHitFractionSoA = event.get(pfRecHitFractionSoAToken_).const_view();
203 
204  int nRH = pfRecHits.view().size();
206  out.reserve(nRH);
207 
208  auto const rechitsHandle = event.getHandle(recHitsLabel_);
209 
210  // Build PFClusters in legacy format
211  std::vector<int> nTopoSeeds(nRH, 0);
212 
213  for (int i = 0; i < pfClusterSoA.nSeeds(); i++) {
214  nTopoSeeds[pfClusterSoA[i].topoId()]++;
215  }
216 
217  // Looping over SoA PFClusters to produce legacy PFCluster collection
218  for (int i = 0; i < pfClusterSoA.nSeeds(); i++) {
219  unsigned int n = pfClusterSoA[i].seedRHIdx();
221  temp.setSeed((*rechitsHandle)[n].detId()); // Pulling the detId of this PFRecHit from the legacy format input
222  int offset = pfClusterSoA[i].rhfracOffset();
223  for (int k = offset; k < (offset + pfClusterSoA[i].rhfracSize()) && k >= 0;
224  k++) { // Looping over PFRecHits in the same topo cluster
225  if (pfRecHitFractionSoA[k].pfrhIdx() < nRH && pfRecHitFractionSoA[k].pfrhIdx() > -1 &&
226  pfRecHitFractionSoA[k].frac() > 0.0) {
227  const reco::PFRecHitRef& refhit = reco::PFRecHitRef(rechitsHandle, pfRecHitFractionSoA[k].pfrhIdx());
228  temp.addRecHitFraction(reco::PFRecHitFraction(refhit, pfRecHitFractionSoA[k].frac()));
229  }
230  }
231 
232  // Now PFRecHitFraction of this PFCluster is set. Now compute calculateAndSetPosition (energy, position etc)
233  if (nTopoSeeds[pfClusterSoA[i].topoId()] == 1 && allCellsPositionCalc_) {
234  allCellsPositionCalc_->calculateAndSetPosition(temp, paramPF);
235  } else {
236  positionCalc_->calculateAndSetPosition(temp, paramPF);
237  }
238  out.emplace_back(std::move(temp));
239  }
240 
241  event.emplace(legacyPfClustersToken_, std::move(out));
242 }
243 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::unique_ptr< PFCPositionCalculatorBase > positionCalc_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::EDGetTokenT< reco::PFClusterHostCollection > pfClusterSoAToken_
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
const edm::EDGetTokenT< reco::PFRecHitFractionHostCollection > pfRecHitFractionSoAToken_
const edm::EDGetTokenT< reco::PFRecHitHostCollection > InputPFRecHitSoA_Token_
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
const edm::ESGetToken< reco::PFClusterParamsHostCollection, JobConfigurationGPURecord > pfClusParamsToken_
bool exists(std::string const &parameterName) const
checks if a parameter exists
ParameterSet const & getParameterSet(std::string const &) const
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
Definition: config.py:1
const edm::EDPutTokenT< reco::PFClusterCollection > legacyPfClustersToken_
std::unique_ptr< PFCPositionCalculatorBase > allCellsPositionCalc_
bool empty() const
Definition: ParameterSet.h:202
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::Ref< PFRecHitCollection > PFRecHitRef
persistent reference to PFRecHit objects
Definition: PFRecHitFwd.h:15
LegacyPFClusterProducer(edm::ParameterSet const &config)
const edm::ESGetToken< HcalPFCuts, HcalPFCutsRcd > hcalCutsToken_
HLT enums.
const edm::EDGetTokenT< reco::PFRecHitCollection > recHitsLabel_
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
#define get
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1