-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Expand file tree
/
Copy pathLegacyMultiDepthPFClusterProducer.cc
More file actions
201 lines (167 loc) · 8.9 KB
/
LegacyMultiDepthPFClusterProducer.cc
File metadata and controls
201 lines (167 loc) · 8.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <Eigen/Core>
#include <Eigen/Dense>
#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Utilities/interface/StreamID.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include "CondFormats/DataRecord/interface/HcalPFCutsRcd.h"
#include "CondTools/Hcal/interface/HcalPFCutsHandler.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHitHostCollection.h"
#include "DataFormats/ParticleFlowReco/interface/PFClusterHostCollection.h"
#include "DataFormats/ParticleFlowReco/interface/PFRecHitFractionHostCollection.h"
#include "RecoParticleFlow/PFClusterProducer/interface/PFCPositionCalculatorBase.h"
#include "RecoParticleFlow/PFClusterProducer/interface/PFClusterEnergyCorrectorBase.h"
class LegacyMultiDepthPFClusterProducer : public edm::stream::EDProducer<> {
public:
LegacyMultiDepthPFClusterProducer(edm::ParameterSet const& config)
: pfClusterSoAToken_(consumes(config.getParameter<edm::InputTag>("pfClusterSoA"))),
pfRecHitFractionSoAToken_(consumes(config.getParameter<edm::InputTag>("pfRecHitFractionSoA"))),
inputPFRecHitSoA_Token_{consumes(config.getParameter<edm::InputTag>("pfRecHitsSoA"))},
legacyPfClustersToken_(produces()),
recHitsLabel_(consumes(config.getParameter<edm::InputTag>("recHitsSource"))),
hcalCutsToken_(esConsumes<HcalPFCuts, HcalPFCutsRcd>(edm::ESInputTag("", "withTopo"))),
cutsFromDB_(config.getParameter<bool>("usePFThresholdsFromDB")) {
edm::ConsumesCollector cc = consumesCollector();
//setup pf cluster builder if requested
const edm::ParameterSet& pfcConf = config.getParameterSet("pfClusterBuilder");
if (!pfcConf.empty()) {
const auto& acConf = pfcConf.getParameterSet("positionCalc");
if (!acConf.empty()) {
const std::string& algoac = acConf.getParameter<std::string>("algoName");
if (!algoac.empty())
positionCalc_ = PFCPositionCalculatorFactory::get()->create(algoac, acConf, cc);
}
const auto& acConf2 = pfcConf.getParameterSet("allCellsPositionCalc");
if (!acConf2.empty()) {
const std::string& algoac = acConf2.getParameter<std::string>("algoName");
if (!algoac.empty())
allCellsPositionCalc_ = PFCPositionCalculatorFactory::get()->create(algoac, acConf2, cc);
}
// see if new need to apply corrections, setup if there.
const edm::ParameterSet& cConf = config.getParameterSet("energyCorrector");
if (!cConf.empty()) {
const std::string& cName = cConf.getParameter<std::string>("algoName");
if (!cName.empty())
energyCorrector_ = PFClusterEnergyCorrectorFactory::get()->create(cName, cConf);
}
}
}
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("pfClusterSoA", edm::InputTag("pfClusterSoAProducer"));
desc.add<edm::InputTag>("pfRecHitFractionSoA", edm::InputTag("pfClusterSoAProducer"));
desc.add<edm::InputTag>("pfRecHitsSoA", edm::InputTag("pfRecHitSoAProducerHCAL"));
desc.add<edm::InputTag>("recHitsSource", edm::InputTag("legacyPFRecHitProducer"));
desc.add<bool>("usePFThresholdsFromDB", true);
desc.add<edm::ParameterSetDescription>("energyCorrector", {});
{
edm::ParameterSetDescription pset0;
pset0.add<std::string>("algoName", "PFMultiDepthClusterizer");
{
edm::ParameterSetDescription pset1;
pset1.add<std::string>("algoName", "Basic2DGenericPFlowPositionCalc");
{
edm::ParameterSetDescription validator;
validator.add<std::string>("detector", "");
validator.add<std::vector<int>>("depths", {});
validator.add<std::vector<double>>("logWeightDenominator", {});
std::vector<edm::ParameterSet> vDefaults(2);
vDefaults[0].addParameter<std::string>("detector", "HCAL_BARREL1");
vDefaults[0].addParameter<std::vector<int>>("depths", {1, 2, 3, 4});
vDefaults[0].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.3, 0.3});
vDefaults[1].addParameter<std::string>("detector", "HCAL_ENDCAP");
vDefaults[1].addParameter<std::vector<int>>("depths", {1, 2, 3, 4, 5, 6, 7});
vDefaults[1].addParameter<std::vector<double>>("logWeightDenominator", {0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2});
pset1.addVPSet("logWeightDenominatorByDetector", validator, vDefaults);
}
pset1.add<double>("minAllowedNormalization", 1e-09);
pset1.add<double>("minFractionInCalc", 1e-09);
pset1.add<int>("posCalcNCrystals", -1);
pset1.add<edm::ParameterSetDescription>("timeResolutionCalcBarrel", {});
pset1.add<edm::ParameterSetDescription>("timeResolutionCalcEndcap", {});
pset0.add<edm::ParameterSetDescription>("allCellsPositionCalc", pset1);
}
pset0.add<edm::ParameterSetDescription>("positionCalc", {});
pset0.add<double>("minFractionToKeep", 1e-07);
desc.add<edm::ParameterSetDescription>("pfClusterBuilder", pset0);
}
desc.add<edm::ParameterSetDescription>("positionReCalc", {});
descriptions.addWithDefaultLabel(desc);
}
private:
void produce(edm::Event&, const edm::EventSetup&) override;
const edm::EDGetTokenT<reco::PFClusterHostCollection> pfClusterSoAToken_;
const edm::EDGetTokenT<reco::PFRecHitFractionHostCollection> pfRecHitFractionSoAToken_;
const edm::EDGetTokenT<reco::PFRecHitHostCollection> inputPFRecHitSoA_Token_;
const edm::EDPutTokenT<reco::PFClusterCollection> legacyPfClustersToken_;
const edm::EDGetTokenT<reco::PFRecHitCollection> recHitsLabel_;
const edm::ESGetToken<HcalPFCuts, HcalPFCutsRcd> hcalCutsToken_;
const bool cutsFromDB_;
// the actual algorithm
std::unique_ptr<PFCPositionCalculatorBase> positionCalc_;
std::unique_ptr<PFCPositionCalculatorBase> allCellsPositionCalc_;
std::unique_ptr<PFClusterEnergyCorrectorBase> energyCorrector_;
};
void LegacyMultiDepthPFClusterProducer::produce(edm::Event& event, const edm::EventSetup& setup) {
const reco::PFRecHitHostCollection& pfRecHits = event.get(inputPFRecHitSoA_Token_);
HcalPFCuts const* paramPF = cutsFromDB_ ? &setup.getData(hcalCutsToken_) : nullptr;
auto const& pfClusterSoA = event.get(pfClusterSoAToken_).const_view();
auto const& pfRecHitFractionSoA = event.get(pfRecHitFractionSoAToken_).const_view();
auto const nRoots = pfClusterSoA.nTopos();
int nRH = pfRecHits->metadata().size();
reco::PFClusterCollection out;
out.reserve(nRoots);
auto const rechitsHandle = event.getHandle(recHitsLabel_);
int sizePFC = pfClusterSoA.metadata().size();
if (sizePFC != 0) {
// Build PFClusters in legacy format
std::unordered_map<int, int> nTopoSeeds;
nTopoSeeds.reserve(pfClusterSoA.nSeeds());
for (int i = 0; i < pfClusterSoA.nSeeds(); ++i)
nTopoSeeds[pfClusterSoA[i].topoId()]++;
// Looping over SoA PFClusters to produce legacy PFCluster collection
auto const& recHits = *rechitsHandle;
for (int i = 0; i < pfClusterSoA.nSeeds(); i++) {
unsigned int seedIdx = pfClusterSoA[i].seedRHIdx();
if (seedIdx >= static_cast<unsigned>(nRH))
continue;
reco::PFCluster temp;
temp.setSeed(recHits[seedIdx].detId());
int const offset = pfClusterSoA[i].rhfracOffset();
int const size = pfClusterSoA[i].rhfracSize();
for (int k = offset; k < (offset + size); k++) { // Looping over PFRecHits in the same topo cluster
if (pfRecHitFractionSoA[k].pfrhIdx() < nRH && pfRecHitFractionSoA[k].pfrhIdx() > -1 &&
pfRecHitFractionSoA[k].frac() > 0.0f) {
const reco::PFRecHitRef& refhit = reco::PFRecHitRef(rechitsHandle, pfRecHitFractionSoA[k].pfrhIdx());
temp.addRecHitFraction(reco::PFRecHitFraction(refhit, pfRecHitFractionSoA[k].frac()));
}
}
// Now PFRecHitFraction of this PFCluster is set. Now compute calculateAndSetPosition (energy, position etc)
if (nTopoSeeds[pfClusterSoA[i].topoId()] == 1 && allCellsPositionCalc_) {
allCellsPositionCalc_->calculateAndSetPosition(temp, paramPF);
} else {
positionCalc_->calculateAndSetPosition(temp, paramPF);
}
out.emplace_back(std::move(temp));
}
}
event.emplace(legacyPfClustersToken_, std::move(out));
}
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(LegacyMultiDepthPFClusterProducer);