47 #include "fastjet/ClusterSequence.hh" 48 #include "fastjet/JetDefinition.hh" 49 #include "fastjet/PseudoJet.hh" 73 using JetDefPtr = std::shared_ptr<fastjet::JetDefinition>;
142 std::map<int, std::array<double, 4>>
eTop4_;
144 typedef std::pair<double, double>
EtaPhi;
149 : dropZeroTowers_(iConfig.getParameter<
bool>(
"dropZeroTowers")),
150 medianWindowWidth_(iConfig.getParameter<
int>(
"medianWindowWidth")),
151 minimumTowersFraction_(iConfig.getParameter<double>(
"minimumTowersFraction")),
152 nSigmaPU_(iConfig.getParameter<double>(
"nSigmaPU")),
153 puPtMin_(iConfig.getParameter<double>(
"puPtMin")),
154 radiusPU_(iConfig.getParameter<double>(
"radiusPU")),
155 rParam_(iConfig.getParameter<double>(
"rParam")),
156 towSigmaCut_(iConfig.getParameter<double>(
"towSigmaCut")),
160 produces<std::vector<double>>(
"mapEtaEdges");
161 produces<std::vector<double>>(
"mapToRho");
162 produces<std::vector<double>>(
"mapToRhoMedian");
163 produces<std::vector<double>>(
"mapToRhoExtra");
164 produces<std::vector<double>>(
"mapToRhoM");
165 produces<std::vector<int>>(
"mapToNTow");
166 produces<std::vector<double>>(
"mapToTowExcludePt");
167 produces<std::vector<double>>(
"mapToTowExcludePhi");
168 produces<std::vector<double>>(
"mapToTowExcludeEta");
180 inputs_.reserve(inputView.size());
181 for (
auto const&
input : inputView)
209 std::vector<fastjet::PseudoJet> orphanInput;
235 LogDebug(
"PileUpSubtractor") <<
"The subtractor setting up geometry...\n";
239 int ietaold = -10000;
244 for (
auto const& did : alldid) {
248 if (hid.
ieta() != ietaold) {
249 ietaold = hid.
ieta();
274 LogDebug(
"PileUpSubtractor") <<
"The subtractor calculating pedestals...\n";
276 std::map<int, double> emean2;
277 std::map<int, int> ntowers;
279 int ietaold = -10000;
282 for (
int vi = 0; vi <
nEtaTow_; ++vi) {
301 eTop4_[
i] = {{0., 0., 0., 0.}};
304 for (
auto const& input_object : coll) {
306 double original_Et = originalTower->
et();
307 int ieta0 = originalTower->
ieta();
309 if (original_Et >
eTop4_[ieta0][0]) {
313 eTop4_[ieta0][0] = original_Et;
314 }
else if (original_Et >
eTop4_[ieta0][1]) {
317 eTop4_[ieta0][1] = original_Et;
318 }
else if (original_Et >
eTop4_[ieta0][2]) {
320 eTop4_[ieta0][2] = original_Et;
321 }
else if (original_Et >
eTop4_[ieta0][3]) {
322 eTop4_[ieta0][3] = original_Et;
326 emean2[ieta0] = emean2[ieta0] + original_Et * original_Et;
327 if (ieta0 - ietaold != 0) {
344 double e2 = emean2[it];
351 LogDebug(
"PileUpSubtractor") <<
" ieta: " << it <<
" number of towers: " <<
nt <<
" e1: " <<
e1 <<
" e2: " << e2
358 double eee = e2 / (double)
nt -
e1 *
e1 / (
double)(
nt *
nt);
365 for (
unsigned int lI = 0; lI < numToCheck; ++lI) {
386 int sign = (it < 0) ? -1 : 1;
414 LogDebug(
"PileUpSubtractor") <<
" ieta: " << it <<
" Pedestals: " <<
emean_[it] <<
" " <<
esigma_[it] <<
"\n";
421 LogDebug(
"PileUpSubtractor") <<
"The subtractor subtracting pedestals...\n";
423 std::vector<fastjet::PseudoJet> newcoll;
424 for (
auto& input_object : coll) {
425 int index = input_object.user_index();
427 int it = itow->
ieta();
429 double original_Et = itow->
et();
431 float mScale = etnew / input_object.Et();
436 input_object.px() * mScale, input_object.py() * mScale, input_object.pz() * mScale, input_object.e() * mScale);
438 input_object.reset_momentum(towP4.px(), towP4.py(), towP4.pz(), towP4.energy());
439 input_object.set_user_index(
index);
442 newcoll.push_back(input_object);
450 LogDebug(
"PileUpSubtractor") <<
"The subtractor calculating orphan input...\n";
454 std::vector<int> jettowers;
455 std::map<std::pair<int, int>,
int> excludedTowers;
456 for (
auto const& pseudojetTMP :
fjJets_) {
457 EtaPhi jet_etaphi(pseudojetTMP.eta(), pseudojetTMP.phi());
463 double dr2 =
reco::deltaR2(im.eta, im.phi, jet_etaphi.first, jet_etaphi.second);
467 excludedTowers[std::pair(im.ieta, im.iphi)] = 1;
474 int ie = originalTower->
ieta();
475 int ip = originalTower->
iphi();
477 if (excludedTowers[std::pair<int, int>(ie, ip)]) {
478 jettowers.push_back(
index);
486 auto itjet =
std::find(jettowers.begin(), jettowers.end(),
index);
487 if (itjet == jettowers.end()) {
488 orphanInput.emplace_back(originalTower->
px(), originalTower->
py(), originalTower->
pz(), originalTower->
energy());
489 orphanInput.back().set_user_index(
index);
503 std::vector<std::pair<std::size_t, double>>
order;
504 for (std::size_t
i = 0;
i <
size; ++
i) {
509 order.begin(),
order.end(), [](
auto const& pair0,
auto const& pair1) {
return pair0.second < pair1.second; });
511 std::vector<double> sortedEtaEdgeLow(
size);
512 std::vector<double> sortedEtaEdgeHigh(
size);
514 auto mapToRhoOut = std::make_unique<std::vector<double>>(
size);
515 auto mapToRhoExtraOut = std::make_unique<std::vector<double>>(
size);
516 auto mapToRhoMOut = std::make_unique<std::vector<double>>(
size);
517 auto mapToNTowOut = std::make_unique<std::vector<int>>(
size);
519 for (std::size_t
i = 0;
i <
size; ++
i) {
531 auto mapToRhoMedianOut = std::make_unique<std::vector<double>>(
size);
534 auto centre = mapToRhoOut->begin() +
index;
536 std::nth_element(rhoRange.begin(), rhoRange.begin() +
medianWindowWidth_, rhoRange.end());
540 auto mapEtaRangesOut = std::make_unique<std::vector<double>>();
542 mapEtaRangesOut->assign(sortedEtaEdgeLow.begin(), sortedEtaEdgeLow.end());
543 mapEtaRangesOut->push_back(sortedEtaEdgeHigh.back());
564 desc.add<
int>(
"medianWindowWidth", 2);
565 desc.add<
double>(
"towSigmaCut", 5.0);
566 desc.add<
double>(
"puPtMin", 15.0);
567 desc.add<
double>(
"rParam", 0.3);
568 desc.add<
double>(
"nSigmaPU", 1.0);
569 desc.add<
double>(
"radiusPU", 0.5);
570 desc.add<
double>(
"minimumTowersFraction", 0.7);
571 desc.add<
bool>(
"dropZeroTowers",
true);
572 descriptions.
add(
"hiPuRhoProducer",
desc);
std::vector< double > towExcludePt_
double pz() const final
z coordinate of momentum vector
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
void produce(edm::Event &, const edm::EventSetup &) override
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
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_
Geom::Phi< T > phi() const
std::vector< double > towExcludeEta_
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_
std::array< float, nEtaTow_ > vmean1_
static constexpr int nEtaTow_
double et(double vtxZ) const
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_
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
const double towSigmaCut_
constexpr int ieta() const
get the cell ieta
std::array< int, nEtaTow_ > vngeom_
Abs< T >::type abs(const T &t)
CaloGeometry const * geo_
#define DEFINE_FWK_MODULE(type)
virtual void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput)
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::pair< double, double > EtaPhi
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
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::map< int, double > emean_
std::vector< fastjet::PseudoJet > fjOriginalInputs_
std::vector< double > rhoM_
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_
constexpr int iphi() const
get the cell iphi
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