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)
194 fjJets_ = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(
puPtMin_));
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
359 emean_[it] = e1 / (double)nt;
360 double eee = e2 / (double)nt - e1 * e1 / (
double)(nt *
nt);
367 for (
unsigned int lI = 0; lI < numToCheck; ++lI) {
380 emean_[it] = e1 / (double)nt;
381 double eee = e2 / nt - e1 * e1 / (nt *
nt);
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) {
522 auto const&
index = order[
i].first;
533 auto mapToRhoMedianOut = std::make_unique<std::vector<double>>(
size);
536 auto centre = mapToRhoOut->begin() +
index;
537 std::vector<float> rhoRange(centre - medianWindowWidth_, centre + medianWindowWidth_);
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());
553 iEvent.
put(
std::move(mapToRhoMedianOut),
"mapToRhoMedian");
554 iEvent.
put(
std::move(mapToRhoExtraOut),
"mapToRhoExtra");
557 iEvent.
put(
std::move(mapToTowExcludePtOut),
"mapToTowExcludePt");
558 iEvent.
put(
std::move(mapToTowExcludePhiOut),
"mapToTowExcludePhi");
559 iEvent.
put(
std::move(mapToTowExcludeEtaOut),
"mapToTowExcludeEta");
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);
std::vector< double > towExcludePt_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
double pz() const final
z coordinate of momentum vector
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
void produce(edm::Event &, const edm::EventSetup &) override
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
double pt() const final
transverse momentum
std::vector< double > etaEdges_
std::vector< double > rhoExtra_
std::array< float, nEtaTow_ > vrms0_
virtual void inputTowers()
constexpr bool isNotFinite(T x)
std::vector< EtaPhiTower > towermap_
#define DEFINE_FWK_MODULE(type)
std::vector< double > towExcludeEta_
Geom::Phi< T > phi() const
const edm::EDGetTokenT< CaloTowerCollection > caloTowerToken_
std::array< float, nEtaTow_ > vrho1_
std::vector< double > etaEdgeHi_
std::vector< fastjet::PseudoJet > fjInputs_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< double > rho_
std::vector< double > towExcludePhi_
std::map< int, std::array< double, 4 > > eTop4_
static std::string const input
std::array< float, nEtaTow_ > vmean0_
bool getData(T &iHolder) const
std::array< float, nEtaTow_ > vmean1_
static constexpr int nEtaTow_
std::vector< double > etaEdgeLow_
virtual void subtractPedestal(std::vector< fastjet::PseudoJet > &coll)
double px() const final
x coordinate of momentum vector
std::array< float, nEtaTow_ > vrms1_
std::vector< const CaloTower * > inputs_
const double towSigmaCut_
constexpr int iphi() const
get the cell iphi
std::array< int, nEtaTow_ > vngeom_
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Abs< T >::type abs(const T &t)
constexpr int ieta() const
get the cell ieta
bool get(ProductID const &oid, Handle< PROD > &result) const
CaloGeometry const * geo_
virtual void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double py() const final
y coordinate of momentum vector
HiPuRhoProducer(const edm::ParameterSet &)
virtual void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual void putRho(edm::Event &iEvent, const edm::EventSetup &iSetup)
std::shared_ptr< fastjet::JetDefinition > JetDefPtr
std::vector< HcalDetId > allgeomid_
std::pair< double, double > EtaPhi
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
ClusterSequencePtr fjClusterSeq_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::array< int, nEtaTow_ > vntow_
std::vector< fastjet::PseudoJet > fjJets_
const bool dropZeroTowers_
std::map< int, int > geomtowers_
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
std::map< int, double > emean_
std::vector< fastjet::PseudoJet > fjOriginalInputs_
std::vector< double > rhoM_
double et(double vtxZ) const
std::map< int, double > esigma_
const int medianWindowWidth_
std::shared_ptr< fastjet::ClusterSequence > ClusterSequencePtr
double phi() const final
momentum azimuthal angle
JetDefPtr fjJetDefinition_
std::map< int, int > ntowersWithJets_
tuple size
Write out results.
constexpr std::array< double, 42 > etaedge
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const double minimumTowersFraction_
virtual void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll)
std::array< float, nEtaTow_ > vrho0_
double energy() const final
energy
double eta() const final
momentum pseudorapidity