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 
35 
37 public:
39  : pfClusterSoAToken_(consumes(config.getParameter<edm::InputTag>("src"))),
40  pfRecHitFractionSoAToken_(consumes(config.getParameter<edm::InputTag>("src"))),
41  InputPFRecHitSoA_Token_{consumes(config.getParameter<edm::InputTag>("PFRecHitsLabelIn"))},
42  legacyPfClustersToken_(produces()),
43  recHitsLabel_(consumes(config.getParameter<edm::InputTag>("recHitsSource"))),
44  hcalCutsToken_(esConsumes<HcalPFCuts, HcalPFCutsRcd>(edm::ESInputTag("", "withTopo"))),
45  cutsFromDB_(config.getParameter<bool>("usePFThresholdsFromDB")) {
46  edm::ConsumesCollector cc = consumesCollector();
47 
48  //setup pf cluster builder if requested
49  const edm::ParameterSet& pfcConf = config.getParameterSet("pfClusterBuilder");
50  if (!pfcConf.empty()) {
51  if (pfcConf.exists("positionCalc")) {
52  const edm::ParameterSet& acConf = pfcConf.getParameterSet("positionCalc");
53  const std::string& algoac = acConf.getParameter<std::string>("algoName");
54  positionCalc_ = PFCPositionCalculatorFactory::get()->create(algoac, acConf, cc);
55  }
56 
57  if (pfcConf.exists("allCellsPositionCalc")) {
58  const edm::ParameterSet& acConf = pfcConf.getParameterSet("allCellsPositionCalc");
59  const std::string& algoac = acConf.getParameter<std::string>("algoName");
60  allCellsPositionCalc_ = PFCPositionCalculatorFactory::get()->create(algoac, acConf, cc);
61  }
62  }
63  }
64 
65  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
67  desc.add<edm::InputTag>("src", edm::InputTag("pfClusterSoAProducer"));
68  desc.add<edm::InputTag>("PFRecHitsLabelIn", edm::InputTag("pfRecHitSoAProducerHCAL"));
69  desc.add<edm::InputTag>("recHitsSource", edm::InputTag("legacyPFRecHitProducer"));
70  desc.add<bool>("usePFThresholdsFromDB", true);
71  {
73  pfClusterBuilder.add<unsigned int>("maxIterations", 5);
74  pfClusterBuilder.add<double>("minFracTot", 1e-20);
75  pfClusterBuilder.add<double>("minFractionToKeep", 1e-7);
76  pfClusterBuilder.add<bool>("excludeOtherSeeds", true);
77  pfClusterBuilder.add<double>("showerSigma", 10.);
78  pfClusterBuilder.add<double>("stoppingTolerance", 1e-8);
79  pfClusterBuilder.add<double>("timeSigmaEB", 10.);
80  pfClusterBuilder.add<double>("timeSigmaEE", 10.);
81  pfClusterBuilder.add<double>("maxNSigmaTime", 10.);
82  pfClusterBuilder.add<double>("minChi2Prob", 0.);
83  pfClusterBuilder.add<bool>("clusterTimeResFromSeed", false);
84  pfClusterBuilder.add<std::string>("algoName", "");
85  {
87  validator.add<std::string>("detector", "");
88  validator.add<std::vector<int>>("depths", {});
89  validator.add<std::vector<double>>("recHitEnergyNorm", {});
90  std::vector<edm::ParameterSet> vDefaults(2);
91  vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
92  vDefaults[0].addParameter<std::vector<int>>("depths", {1, 2, 3, 4});
93  vDefaults[0].addParameter<std::vector<double>>("recHitEnergyNorm", {0.1, 0.2, 0.3, 0.3});
94  vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
95  vDefaults[1].addParameter<std::vector<int>>("depths", {1, 2, 3, 4, 5, 6, 7});
96  vDefaults[1].addParameter<std::vector<double>>("recHitEnergyNorm", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
97  pfClusterBuilder.addVPSet("recHitEnergyNorms", validator, vDefaults);
98  }
99  {
101  bar.add<std::string>("algoName", "Basic2DGenericPFlowPositionCalc");
102  bar.add<double>("minFractionInCalc", 1e-9);
103  bar.add<int>("posCalcNCrystals", 5);
104  {
106  validator.add<std::string>("detector", "");
107  validator.add<std::vector<int>>("depths", {});
108  validator.add<std::vector<double>>("logWeightDenominator", {});
109  std::vector<edm::ParameterSet> vDefaults(2);
110  vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
111  vDefaults[0].addParameter<std::vector<int>>("depths", {1, 2, 3, 4});
112  vDefaults[0].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.3, 0.3});
113  vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
114  vDefaults[1].addParameter<std::vector<int>>("depths", {1, 2, 3, 4, 5, 6, 7});
115  vDefaults[1].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
116  bar.addVPSet("logWeightDenominatorByDetector", validator, vDefaults);
117  }
118  bar.add<double>("minAllowedNormalization", 1e-9);
119  pfClusterBuilder.add("positionCalc", bar);
120  }
121  {
123  bar.add<std::string>("algoName", "Basic2DGenericPFlowPositionCalc");
124  bar.add<double>("minFractionInCalc", 1e-9);
125  bar.add<int>("posCalcNCrystals", -1);
126  {
128  validator.add<std::string>("detector", "");
129  validator.add<std::vector<int>>("depths", {});
130  validator.add<std::vector<double>>("logWeightDenominator", {});
131  std::vector<edm::ParameterSet> vDefaults(2);
132  vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
133  vDefaults[0].addParameter<std::vector<int>>("depths", {1, 2, 3, 4});
134  vDefaults[0].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.3, 0.3});
135  vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
136  vDefaults[1].addParameter<std::vector<int>>("depths", {1, 2, 3, 4, 5, 6, 7});
137  vDefaults[1].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
138  bar.addVPSet("logWeightDenominatorByDetector", validator, vDefaults);
139  }
140  bar.add<double>("minAllowedNormalization", 1e-9);
141  pfClusterBuilder.add("allCellsPositionCalc", bar);
142  }
143  {
145  bar.add<double>("corrTermLowE", 0.);
146  bar.add<double>("threshLowE", 6.);
147  bar.add<double>("noiseTerm", 21.86);
148  bar.add<double>("constantTermLowE", 4.24);
149  bar.add<double>("noiseTermLowE", 8.);
150  bar.add<double>("threshHighE", 15.);
151  bar.add<double>("constantTerm", 2.82);
152  pfClusterBuilder.add("timeResolutionCalcBarrel", bar);
153  }
154  {
156  bar.add<double>("corrTermLowE", 0.);
157  bar.add<double>("threshLowE", 6.);
158  bar.add<double>("noiseTerm", 21.86);
159  bar.add<double>("constantTermLowE", 4.24);
160  bar.add<double>("noiseTermLowE", 8.);
161  bar.add<double>("threshHighE", 15.);
162  bar.add<double>("constantTerm", 2.82);
163  pfClusterBuilder.add("timeResolutionCalcEndcap", bar);
164  }
165  {
167  pfClusterBuilder.add("positionReCalc", bar);
168  }
169  {
171  pfClusterBuilder.add("energyCorrector", bar);
172  }
173  desc.add("pfClusterBuilder", pfClusterBuilder);
174  }
175  descriptions.addWithDefaultLabel(desc);
176  }
177 
178 private:
179  void produce(edm::Event&, const edm::EventSetup&) override;
186  const bool cutsFromDB_;
187  // the actual algorithm
188  std::unique_ptr<PFCPositionCalculatorBase> positionCalc_;
189  std::unique_ptr<PFCPositionCalculatorBase> allCellsPositionCalc_;
190 };
191 
194 
195  HcalPFCuts const* paramPF = cutsFromDB_ ? &setup.getData(hcalCutsToken_) : nullptr;
196 
197  auto const& pfClusterSoA = event.get(pfClusterSoAToken_).const_view();
198  auto const& pfRecHitFractionSoA = event.get(pfRecHitFractionSoAToken_).const_view();
199 
200  int nRH = 0;
201  if (pfRecHits->metadata().size() != 0)
202  nRH = pfRecHits.view().size();
204  out.reserve(nRH);
205 
206  auto const rechitsHandle = event.getHandle(recHitsLabel_);
207 
208  if (nRH != 0) {
209  // Build PFClusters in legacy format
210  std::vector<int> nTopoSeeds(nRH, 0);
211 
212  for (int i = 0; i < pfClusterSoA.nSeeds(); i++) {
213  nTopoSeeds[pfClusterSoA[i].topoId()]++;
214  }
215 
216  // Looping over SoA PFClusters to produce legacy PFCluster collection
217  for (int i = 0; i < pfClusterSoA.nSeeds(); i++) {
218  unsigned int n = pfClusterSoA[i].seedRHIdx();
220  temp.setSeed((*rechitsHandle)[n].detId()); // Pulling the detId of this PFRecHit from the legacy format input
221  int offset = pfClusterSoA[i].rhfracOffset();
222  for (int k = offset; k < (offset + pfClusterSoA[i].rhfracSize()) && k >= 0;
223  k++) { // Looping over PFRecHits in the same topo cluster
224  if (pfRecHitFractionSoA[k].pfrhIdx() < nRH && pfRecHitFractionSoA[k].pfrhIdx() > -1 &&
225  pfRecHitFractionSoA[k].frac() > 0.0) {
226  const reco::PFRecHitRef& refhit = reco::PFRecHitRef(rechitsHandle, pfRecHitFractionSoA[k].pfrhIdx());
227  temp.addRecHitFraction(reco::PFRecHitFraction(refhit, pfRecHitFractionSoA[k].frac()));
228  }
229  }
230 
231  // Now PFRecHitFraction of this PFCluster is set. Now compute calculateAndSetPosition (energy, position etc)
232  if (nTopoSeeds[pfClusterSoA[i].topoId()] == 1 && allCellsPositionCalc_) {
233  allCellsPositionCalc_->calculateAndSetPosition(temp, paramPF);
234  } else {
235  positionCalc_->calculateAndSetPosition(temp, paramPF);
236  }
237  out.emplace_back(std::move(temp));
238  }
239  }
240 
241  event.emplace(legacyPfClustersToken_, std::move(out));
242 }
243 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::unique_ptr< PFCPositionCalculatorBase > positionCalc_
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
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