CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
MultipleAlgoIterator Class Reference

#include <MultipleAlgoIterator.h>

Inheritance diagram for MultipleAlgoIterator:
PileUpSubtractor

Public Member Functions

void calculateOrphanInput (std::vector< fastjet::PseudoJet > &orphanInput) override
 
void calculatePedestal (std::vector< fastjet::PseudoJet > const &coll) override
 
double getEt (const reco::CandidatePtr &in) const
 
double getEta (const reco::CandidatePtr &in) const
 
 MultipleAlgoIterator (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
 
void offsetCorrectJets () override
 
void rescaleRMS (double s)
 
void subtractPedestal (std::vector< fastjet::PseudoJet > &coll) override
 
- Public Member Functions inherited from PileUpSubtractor
virtual double getCone (double cone, double eta, double phi, double &et, double &pu)
 
virtual double getMeanAtTower (const reco::CandidatePtr &in) const
 
int getN (const reco::CandidatePtr &in) const
 
int getNwithJets (const reco::CandidatePtr &in) const
 
virtual double getPileUpAtTower (const reco::CandidatePtr &in) const
 
virtual double getPileUpEnergy (int ijet) const
 
virtual double getSigmaAtTower (const reco::CandidatePtr &in) const
 
int ieta (const reco::CandidatePtr &in) const
 
int iphi (const reco::CandidatePtr &in) const
 
 PileUpSubtractor (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
 
virtual void reset (std::vector< edm::Ptr< reco::Candidate > > &input, std::vector< fastjet::PseudoJet > &towers, std::vector< fastjet::PseudoJet > &output)
 
virtual void setDefinition (JetDefPtr const &jetDef)
 
virtual void setupGeometryMap (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
virtual ~PileUpSubtractor ()
 

Private Attributes

bool dropZeroTowers_
 
double minimumTowersFraction_
 
bool sumRecHits_
 

Additional Inherited Members

- Public Types inherited from PileUpSubtractor
typedef std::shared_ptr< fastjet::GhostedAreaSpec > ActiveAreaSpecPtr
 
typedef std::shared_ptr< fastjet::ClusterSequence > ClusterSequencePtr
 
typedef std::shared_ptr< fastjet::JetDefinition > JetDefPtr
 
typedef std::shared_ptr< fastjet::RangeDefinition > RangeDefPtr
 
- Protected Attributes inherited from PileUpSubtractor
int activeAreaRepeats
 
std::vector< HcalDetIdallgeomid_
 
bool doAreaFastjet_
 
bool doRhoFastjet_
 
std::map< int, double > emean_
 
std::map< int, double > esigma_
 
ActiveAreaSpecPtr fjActiveArea_
 
ClusterSequencePtr fjClusterSeq_
 
std::vector< fastjet::PseudoJet > * fjInputs_
 
JetDefPtr fjJetDefinition_
 
std::vector< fastjet::PseudoJet > * fjJets_
 
std::vector< fastjet::PseudoJet > fjOriginalInputs_
 
CaloGeometry const * geo_
 
std::map< int, int > geomtowers_
 
edm::ESGetToken< CaloGeometry, CaloGeometryRecordgeoToken_
 
double ghostArea
 
double ghostEtaMax
 
int ietamax_
 
int ietamin_
 
std::vector< edm::Ptr< reco::Candidate > > * inputs_
 
std::vector< double > jetOffset_
 
double jetPtMin_
 
double nSigmaPU_
 
std::map< int, int > ntowersWithJets_
 
double puPtMin_
 
double radiusPU_
 
bool reRunAlgo_
 

Detailed Description

Definition at line 6 of file MultipleAlgoIterator.h.

Constructor & Destructor Documentation

◆ MultipleAlgoIterator()

MultipleAlgoIterator::MultipleAlgoIterator ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  iC 
)

Definition at line 11 of file MultipleAlgoIterator.cc.

References LogDebug, and minimumTowersFraction_.

12  : PileUpSubtractor(iConfig, std::move(iC)),
13  minimumTowersFraction_(iConfig.getParameter<double>("minimumTowersFraction")),
14  sumRecHits_(iConfig.getParameter<bool>("sumRecHits")),
15  dropZeroTowers_(iConfig.getUntrackedParameter<bool>("dropZeroTowers", true)) {
16  LogDebug("PileUpSubtractor") << "LIMITING THE MINIMUM TOWERS FRACTION TO : " << minimumTowersFraction_ << endl;
17 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T getUntrackedParameter(std::string const &, T const &) const
PileUpSubtractor(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)

Member Function Documentation

◆ calculateOrphanInput()

void MultipleAlgoIterator::calculateOrphanInput ( std::vector< fastjet::PseudoJet > &  orphanInput)
overridevirtual

Reimplemented from PileUpSubtractor.

Definition at line 172 of file MultipleAlgoIterator.cc.

References PileUpSubtractor::allgeomid_, reco::deltaR(), l1ctLayer1_cff::dr, reco::Candidate::energy(), spr::find(), PileUpSubtractor::fjInputs_, PileUpSubtractor::fjJets_, PileUpSubtractor::fjOriginalInputs_, PileUpSubtractor::geo_, PileUpSubtractor::geomtowers_, CaloGeometry::getPosition(), PileUpSubtractor::ieta(), PileUpSubtractor::inputs_, PileUpSubtractor::iphi(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, LogDebug, minimumTowersFraction_, PileUpSubtractor::ntowersWithJets_, PileUpSubtractor::puPtMin_, reco::Candidate::px(), reco::Candidate::py(), reco::Candidate::pz(), and PileUpSubtractor::radiusPU_.

172  {
173  LogDebug("PileUpSubtractor") << "The subtractor calculating orphan input...\n";
174 
175  (*fjInputs_) = fjOriginalInputs_;
176 
177  vector<int> jettowers; // vector of towers indexed by "user_index"
178  vector<pair<int, int> > excludedTowers; // vector of excluded ieta, iphi values
179 
180  for (auto const& pseudojetTMP : *fjJets_) {
181  if (pseudojetTMP.perp() < puPtMin_)
182  continue;
183 
184  // find towers within radiusPU_ of this jet
185  for (auto const im : allgeomid_) {
186  double dr = reco::deltaR(geo_->getPosition(im), pseudojetTMP);
187  auto exclude = find(excludedTowers.begin(), excludedTowers.end(), pair<int, int>(im.ieta(), im.iphi()));
188  if (dr < radiusPU_ && exclude == excludedTowers.end() &&
189  (geomtowers_[im.ieta()] - ntowersWithJets_[im.ieta()]) > minimumTowersFraction_ * (geomtowers_[im.ieta()])) {
190  ntowersWithJets_[im.ieta()]++;
191 
192  excludedTowers.push_back(pair<int, int>(im.ieta(), im.iphi()));
193  }
194  }
195 
196  for (auto const& it : *fjInputs_) {
197  int index = it.user_index();
198  int ie = ieta((*inputs_)[index]);
199  int ip = iphi((*inputs_)[index]);
200  auto exclude = find(excludedTowers.begin(), excludedTowers.end(), pair<int, int>(ie, ip));
201  if (exclude != excludedTowers.end()) {
202  jettowers.push_back(index);
203  }
204  } // initial input collection
205 
206  } // pseudojets
207 
208  //
209  // Create a new collections from the towers not included in jets
210  //
211 
212  for (auto const& it : *fjInputs_) {
213  int index = it.user_index();
214  vector<int>::const_iterator itjet = find(jettowers.begin(), jettowers.end(), index);
215  if (itjet == jettowers.end()) {
216  const reco::CandidatePtr& originalTower = (*inputs_)[index];
217  fastjet::PseudoJet orphan(originalTower->px(), originalTower->py(), originalTower->pz(), originalTower->energy());
218  orphan.set_user_index(index);
219 
220  orphanInput.push_back(orphan);
221  }
222  }
223 }
virtual double energy() const =0
energy
std::vector< fastjet::PseudoJet > * fjJets_
std::vector< fastjet::PseudoJet > fjOriginalInputs_
virtual double pz() const =0
z coordinate of momentum vector
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::map< int, int > geomtowers_
std::vector< fastjet::PseudoJet > * fjInputs_
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
std::map< int, int > ntowersWithJets_
virtual double py() const =0
y coordinate of momentum vector
int iphi(const reco::CandidatePtr &in) const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
virtual double px() const =0
x coordinate of momentum vector
int ieta(const reco::CandidatePtr &in) const
CaloGeometry const * geo_
std::vector< HcalDetId > allgeomid_
std::vector< edm::Ptr< reco::Candidate > > * inputs_
#define LogDebug(id)

◆ calculatePedestal()

void MultipleAlgoIterator::calculatePedestal ( std::vector< fastjet::PseudoJet > const &  coll)
overridevirtual

Reimplemented from PileUpSubtractor.

Definition at line 108 of file MultipleAlgoIterator.cc.

References StorageManager_cfg::e1, PileUpSubtractor::emean_, PileUpSubtractor::esigma_, reco::Candidate::et(), PileUpSubtractor::geomtowers_, getEt(), submitPVValidationJobs::gt, mps_fire::i, PileUpSubtractor::ieta(), PileUpSubtractor::ietamax_, PileUpSubtractor::ietamin_, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, LogDebug, PileUpSubtractor::nSigmaPU_, nt, PileUpSubtractor::ntowersWithJets_, edm::second(), mathSSE::sqrt(), and sumRecHits_.

108  {
109  LogDebug("PileUpSubtractor") << "The subtractor calculating pedestals...\n";
110 
111  map<int, double> emean2;
112  map<int, int> ntowers;
113 
114  int ietaold = -10000;
115  int ieta0 = -100;
116 
117  // Initial values for emean_, emean2, esigma_, ntowers
118 
119  for (int i = ietamin_; i < ietamax_ + 1; i++) {
120  emean_[i] = 0.;
121  emean2[i] = 0.;
122  esigma_[i] = 0.;
123  ntowers[i] = 0;
124  }
125 
126  for (vector<fastjet::PseudoJet>::const_iterator input_object = coll.begin(), fjInputsEnd = coll.end();
127  input_object != fjInputsEnd;
128  ++input_object) {
129  const reco::CandidatePtr& originalTower = (*inputs_)[input_object->user_index()];
130  ieta0 = ieta(originalTower);
131  double Original_Et = originalTower->et();
132  if (sumRecHits_) {
133  Original_Et = getEt(originalTower);
134  }
135 
136  if (ieta0 - ietaold != 0) {
137  emean_[ieta0] = emean_[ieta0] + Original_Et;
138  emean2[ieta0] = emean2[ieta0] + Original_Et * Original_Et;
139  ntowers[ieta0] = 1;
140  ietaold = ieta0;
141  } else {
142  emean_[ieta0] = emean_[ieta0] + Original_Et;
143  emean2[ieta0] = emean2[ieta0] + Original_Et * Original_Et;
144  ntowers[ieta0]++;
145  }
146  }
147 
148  for (map<int, int>::const_iterator gt = geomtowers_.begin(); gt != geomtowers_.end(); gt++) {
149  int it = (*gt).first;
150 
151  double e1 = (*(emean_.find(it))).second;
152  double e2 = (*emean2.find(it)).second;
153  int nt = (*gt).second - (*(ntowersWithJets_.find(it))).second;
154 
155  LogDebug("PileUpSubtractor") << " ieta : " << it << " number of towers : " << nt << " e1 : " << e1 << " e2 : " << e2
156  << "\n";
157 
158  if (nt > 0) {
159  emean_[it] = e1 / nt;
160  double eee = e2 / nt - e1 * e1 / (nt * nt);
161  if (eee < 0.)
162  eee = 0.;
163  esigma_[it] = nSigmaPU_ * sqrt(eee);
164  } else {
165  emean_[it] = 0.;
166  esigma_[it] = 0.;
167  }
168  LogDebug("PileUpSubtractor") << " ieta : " << it << " Pedestals : " << emean_[it] << " " << esigma_[it] << "\n";
169  }
170 }
std::map< int, double > esigma_
virtual double et() const =0
transverse energy
std::map< int, int > geomtowers_
U second(std::pair< T, U > const &p)
std::map< int, double > emean_
std::map< int, int > ntowersWithJets_
T sqrt(T t)
Definition: SSEVec.h:19
int nt
Definition: AMPTWrapper.h:42
int ieta(const reco::CandidatePtr &in) const
double getEt(const reco::CandidatePtr &in) const
#define LogDebug(id)

◆ getEt()

double MultipleAlgoIterator::getEt ( const reco::CandidatePtr in) const

Definition at line 225 of file MultipleAlgoIterator.cc.

References CaloTower::emEnergy(), hcalRecHitTable_cff::energy, EgHLTOffHistBins_cfi::et, PileUpSubtractor::geo_, CaloGeometry::getPosition(), CaloTower::hadEnergy(), CaloTower::id(), recoMuon::in, and funct::sin().

Referenced by calculatePedestal(), and subtractPedestal().

225  {
226  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
227  const GlobalPoint& pos = geo_->getPosition(ctc->id());
228  double energy = ctc->emEnergy() + ctc->hadEnergy();
229  double et = energy * sin(pos.theta());
230  return et;
231 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
double emEnergy() const
Definition: CaloTower.h:130
double hadEnergy() const
Definition: CaloTower.h:131
CaloGeometry const * geo_
CaloTowerDetId id() const
Definition: CaloTower.h:123

◆ getEta()

double MultipleAlgoIterator::getEta ( const reco::CandidatePtr in) const

Definition at line 233 of file MultipleAlgoIterator.cc.

References PVValHelper::eta, PileUpSubtractor::geo_, CaloGeometry::getPosition(), CaloTower::id(), and recoMuon::in.

233  {
234  const CaloTower* ctc = dynamic_cast<const CaloTower*>(in.get());
235  const GlobalPoint& pos = geo_->getPosition(ctc->id());
236  double eta = pos.eta();
237  return eta;
238 }
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
CaloGeometry const * geo_
CaloTowerDetId id() const
Definition: CaloTower.h:123

◆ offsetCorrectJets()

void MultipleAlgoIterator::offsetCorrectJets ( )
overridevirtual

Reimplemented from PileUpSubtractor.

Definition at line 25 of file MultipleAlgoIterator.cc.

References spu::def(), PileUpSubtractor::doAreaFastjet_, PileUpSubtractor::doRhoFastjet_, PileUpSubtractor::emean_, PileUpSubtractor::esigma_, reco::Candidate::et(), PileUpSubtractor::fjActiveArea_, PileUpSubtractor::fjClusterSeq_, PileUpSubtractor::fjInputs_, PileUpSubtractor::fjJetDefinition_, PileUpSubtractor::fjJets_, PileUpSubtractor::fjOriginalInputs_, PileUpSubtractor::ieta(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, PileUpSubtractor::jetOffset_, PileUpSubtractor::jetPtMin_, LogDebug, PileUpSubtractor::nSigmaPU_, rescaleRMS(), edm::second(), subtractPedestal(), and HLT_2024v12_cff::towers.

25  {
26  LogDebug("PileUpSubtractor") << "The subtractor correcting jets...\n";
27  jetOffset_.clear();
28 
29  using namespace reco;
30 
31  (*fjInputs_) = fjOriginalInputs_;
34  const fastjet::JetDefinition& def = *fjJetDefinition_;
35  if (!doAreaFastjet_ && !doRhoFastjet_) {
36  fjClusterSeq_ = std::make_shared<fastjet::ClusterSequence>(*fjInputs_, def);
37  } else {
38  fjClusterSeq_ = ClusterSequencePtr(new fastjet::ClusterSequenceArea(*fjInputs_, def, *fjActiveArea_));
39  }
40 
41  (*fjJets_) = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(jetPtMin_));
42 
43  jetOffset_.reserve(fjJets_->size());
44 
45  vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin(), jetsEnd = fjJets_->end();
46  for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
47  int ijet = pseudojetTMP - fjJets_->begin();
48  jetOffset_[ijet] = 0;
49 
50  std::vector<fastjet::PseudoJet> towers = sorted_by_pt(pseudojetTMP->constituents());
51 
52  double newjetet = 0.;
53  for (vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(), towEnd = towers.end(); ito != towEnd; ++ito) {
54  const reco::CandidatePtr& originalTower = (*inputs_)[ito->user_index()];
55  int it = ieta(originalTower);
56  double Original_Et = originalTower->et();
57  double etnew = Original_Et - (*emean_.find(it)).second - (*esigma_.find(it)).second;
58  if (etnew < 0.)
59  etnew = 0;
60  newjetet = newjetet + etnew;
61  jetOffset_[ijet] += Original_Et - etnew;
62  }
63  }
64 }
int def(FILE *, FILE *, int)
std::vector< double > jetOffset_
std::map< int, double > esigma_
virtual double et() const =0
transverse energy
std::vector< fastjet::PseudoJet > * fjJets_
std::vector< fastjet::PseudoJet > fjOriginalInputs_
U second(std::pair< T, U > const &p)
std::vector< fastjet::PseudoJet > * fjInputs_
std::map< int, double > emean_
void subtractPedestal(std::vector< fastjet::PseudoJet > &coll) override
ActiveAreaSpecPtr fjActiveArea_
ClusterSequencePtr fjClusterSeq_
std::shared_ptr< fastjet::ClusterSequence > ClusterSequencePtr
int ieta(const reco::CandidatePtr &in) const
fixed size matrix
JetDefPtr fjJetDefinition_
#define LogDebug(id)

◆ rescaleRMS()

void MultipleAlgoIterator::rescaleRMS ( double  s)

Definition at line 19 of file MultipleAlgoIterator.cc.

References PileUpSubtractor::esigma_, and alignCSCRings::s.

Referenced by offsetCorrectJets().

19  {
20  for (std::map<int, double>::iterator iter = esigma_.begin(); iter != esigma_.end(); ++iter) {
21  iter->second = s * (iter->second);
22  }
23 }
std::map< int, double > esigma_

◆ subtractPedestal()

void MultipleAlgoIterator::subtractPedestal ( std::vector< fastjet::PseudoJet > &  coll)
overridevirtual

Reimplemented from PileUpSubtractor.

Definition at line 66 of file MultipleAlgoIterator.cc.

References dropZeroTowers_, PileUpSubtractor::emean_, PileUpSubtractor::esigma_, reco::Candidate::et(), getEt(), PileUpSubtractor::ieta(), PileUpSubtractor::iphi(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, LogDebug, and sumRecHits_.

Referenced by offsetCorrectJets().

66  {
67  LogDebug("PileUpSubtractor") << "The subtractor subtracting pedestals...\n";
68 
69  int it = -100;
70 
71  vector<fastjet::PseudoJet> newcoll;
72 
73  for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin(), fjInputsEnd = coll.end();
74  input_object != fjInputsEnd;
75  ++input_object) {
76  reco::CandidatePtr const& itow = (*inputs_)[input_object->user_index()];
77 
78  it = ieta(itow);
79  iphi(itow);
80 
81  double Original_Et = itow->et();
82  if (sumRecHits_) {
83  Original_Et = getEt(itow);
84  }
85 
86  double etnew = Original_Et - (*(emean_.find(it))).second - (*(esigma_.find(it))).second;
87  float mScale = etnew / input_object->Et();
88  if (etnew < 0.)
89  mScale = 0.;
90 
91  math::XYZTLorentzVectorD towP4(input_object->px() * mScale,
92  input_object->py() * mScale,
93  input_object->pz() * mScale,
94  input_object->e() * mScale);
95 
96  int index = input_object->user_index();
97  input_object->reset_momentum(towP4.px(), towP4.py(), towP4.pz(), towP4.energy());
98  input_object->set_user_index(index);
99 
100  if (etnew > 0. && dropZeroTowers_)
101  newcoll.push_back(*input_object);
102  }
103 
104  if (dropZeroTowers_)
105  coll = newcoll;
106 }
std::map< int, double > esigma_
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
virtual double et() const =0
transverse energy
std::map< int, double > emean_
int iphi(const reco::CandidatePtr &in) const
int ieta(const reco::CandidatePtr &in) const
double getEt(const reco::CandidatePtr &in) const
#define LogDebug(id)

Member Data Documentation

◆ dropZeroTowers_

bool MultipleAlgoIterator::dropZeroTowers_
private

Definition at line 20 of file MultipleAlgoIterator.h.

Referenced by subtractPedestal().

◆ minimumTowersFraction_

double MultipleAlgoIterator::minimumTowersFraction_
private

Definition at line 18 of file MultipleAlgoIterator.h.

Referenced by calculateOrphanInput(), and MultipleAlgoIterator().

◆ sumRecHits_

bool MultipleAlgoIterator::sumRecHits_
private

Definition at line 19 of file MultipleAlgoIterator.h.

Referenced by calculatePedestal(), and subtractPedestal().