47 #include "fastjet/ClusterSequence.hh"
48 #include "fastjet/JetDefinition.hh"
49 #include "fastjet/PseudoJet.hh"
73 using JetDefPtr = std::shared_ptr<fastjet::JetDefinition>;
143 std::map<int, std::array<double, 4>>
eTop4_;
145 typedef std::pair<double, double>
EtaPhi;
150 : dropZeroTowers_(iConfig.getParameter<
bool>(
"dropZeroTowers")),
151 medianWindowWidth_(iConfig.getParameter<
int>(
"medianWindowWidth")),
152 minimumTowersFraction_(iConfig.getParameter<double>(
"minimumTowersFraction")),
153 nSigmaPU_(iConfig.getParameter<double>(
"nSigmaPU")),
154 puPtMin_(iConfig.getParameter<double>(
"puPtMin")),
155 radiusPU_(iConfig.getParameter<double>(
"radiusPU")),
156 rParam_(iConfig.getParameter<double>(
"rParam")),
157 towSigmaCut_(iConfig.getParameter<double>(
"towSigmaCut")),
161 produces<std::vector<double>>(
"mapEtaEdges");
162 produces<std::vector<double>>(
"mapToRho");
163 produces<std::vector<double>>(
"mapToRhoMedian");
164 produces<std::vector<double>>(
"mapToRhoExtra");
165 produces<std::vector<double>>(
"mapToRhoM");
166 produces<std::vector<int>>(
"mapToNTow");
167 produces<std::vector<double>>(
"mapToTowExcludePt");
168 produces<std::vector<double>>(
"mapToTowExcludePhi");
169 produces<std::vector<double>>(
"mapToTowExcludeEta");
181 inputs_.reserve(inputView.size());
182 for (
auto const&
input : inputView)
210 std::vector<fastjet::PseudoJet> orphanInput;
236 LogDebug(
"PileUpSubtractor") <<
"The subtractor setting up geometry...\n";
240 int ietaold = -10000;
245 for (
auto const& did : alldid) {
250 if (hid.
ieta() != ietaold) {
251 ietaold = hid.
ieta();
276 LogDebug(
"PileUpSubtractor") <<
"The subtractor calculating pedestals...\n";
278 std::map<int, double> emean2;
279 std::map<int, int> ntowers;
281 int ietaold = -10000;
284 for (
int vi = 0; vi <
nEtaTow_; ++vi) {
303 eTop4_[
i] = {{0., 0., 0., 0.}};
306 for (
auto const& input_object : coll) {
308 double original_Et = originalTower->
et();
309 int ieta0 = originalTower->
ieta();
311 if (original_Et >
eTop4_[ieta0][0]) {
315 eTop4_[ieta0][0] = original_Et;
316 }
else if (original_Et >
eTop4_[ieta0][1]) {
319 eTop4_[ieta0][1] = original_Et;
320 }
else if (original_Et >
eTop4_[ieta0][2]) {
322 eTop4_[ieta0][2] = original_Et;
323 }
else if (original_Et >
eTop4_[ieta0][3]) {
324 eTop4_[ieta0][3] = original_Et;
328 emean2[ieta0] = emean2[ieta0] + original_Et * original_Et;
329 if (ieta0 - ietaold != 0) {
346 double e2 = emean2[it];
353 LogDebug(
"PileUpSubtractor") <<
" ieta: " << it <<
" number of towers: " <<
nt <<
" e1: " <<
e1 <<
" e2: " << e2
360 double eee = e2 / (double)
nt -
e1 *
e1 / (
double)(
nt *
nt);
367 for (
unsigned int lI = 0; lI < numToCheck; ++lI) {
388 int sign = (it < 0) ? -1 : 1;
416 LogDebug(
"PileUpSubtractor") <<
" ieta: " << it <<
" Pedestals: " <<
emean_[it] <<
" " <<
esigma_[it] <<
"\n";
423 LogDebug(
"PileUpSubtractor") <<
"The subtractor subtracting pedestals...\n";
425 std::vector<fastjet::PseudoJet> newcoll;
426 for (
auto& input_object : coll) {
427 int index = input_object.user_index();
429 int it = itow->
ieta();
431 double original_Et = itow->
et();
433 float mScale = etnew / input_object.Et();
438 input_object.px() * mScale, input_object.py() * mScale, input_object.pz() * mScale, input_object.e() * mScale);
440 input_object.reset_momentum(towP4.px(), towP4.py(), towP4.pz(), towP4.energy());
441 input_object.set_user_index(
index);
444 newcoll.push_back(input_object);
452 LogDebug(
"PileUpSubtractor") <<
"The subtractor calculating orphan input...\n";
456 std::vector<int> jettowers;
457 std::map<std::pair<int, int>,
int> excludedTowers;
458 for (
auto const& pseudojetTMP :
fjJets_) {
459 EtaPhi jet_etaphi(pseudojetTMP.eta(), pseudojetTMP.phi());
465 double dr2 =
reco::deltaR2(im.eta, im.phi, jet_etaphi.first, jet_etaphi.second);
469 excludedTowers[std::pair(im.ieta, im.iphi)] = 1;
476 int ie = originalTower->
ieta();
477 int ip = originalTower->
iphi();
479 if (excludedTowers[std::pair<int, int>(ie, ip)]) {
480 jettowers.push_back(
index);
488 auto itjet =
std::find(jettowers.begin(), jettowers.end(),
index);
489 if (itjet == jettowers.end()) {
490 orphanInput.emplace_back(originalTower->
px(), originalTower->
py(), originalTower->
pz(), originalTower->
energy());
491 orphanInput.back().set_user_index(
index);
505 std::vector<std::pair<std::size_t, double>>
order;
506 for (std::size_t
i = 0;
i <
size; ++
i) {
511 order.begin(),
order.end(), [](
auto const& pair0,
auto const& pair1) {
return pair0.second < pair1.second; });
513 std::vector<double> sortedEtaEdgeLow(
size);
514 std::vector<double> sortedEtaEdgeHigh(
size);
516 auto mapToRhoOut = std::make_unique<std::vector<double>>(
size);
517 auto mapToRhoExtraOut = std::make_unique<std::vector<double>>(
size);
518 auto mapToRhoMOut = std::make_unique<std::vector<double>>(
size);
519 auto mapToNTowOut = std::make_unique<std::vector<int>>(
size);
521 for (std::size_t
i = 0;
i <
size; ++
i) {
533 auto mapToRhoMedianOut = std::make_unique<std::vector<double>>(
size);
536 auto centre = mapToRhoOut->begin() +
index;
538 std::nth_element(rhoRange.begin(), rhoRange.begin() +
medianWindowWidth_, rhoRange.end());
542 auto mapEtaRangesOut = std::make_unique<std::vector<double>>();
544 mapEtaRangesOut->assign(sortedEtaEdgeLow.begin(), sortedEtaEdgeLow.end());
545 mapEtaRangesOut->push_back(sortedEtaEdgeHigh.back());
566 desc.add<
int>(
"medianWindowWidth", 2);
567 desc.add<
double>(
"towSigmaCut", 5.0);
568 desc.add<
double>(
"puPtMin", 15.0);
569 desc.add<
double>(
"rParam", 0.3);
570 desc.add<
double>(
"nSigmaPU", 1.0);
571 desc.add<
double>(
"radiusPU", 0.5);
572 desc.add<
double>(
"minimumTowersFraction", 0.7);
573 desc.add<
bool>(
"dropZeroTowers",
true);
574 descriptions.
add(
"hiPuRhoProducer",
desc);