22 doAreaFastjet_ = iConfig.
getParameter<
bool>(
"doAreaFastjet");
23 doRhoFastjet_ = iConfig.
getParameter<
bool>(
"doRhoFastjet");
28 ghostEtaMax = iConfig.
getParameter<
double>(
"Ghost_EtaMax");
29 activeAreaRepeats = iConfig.
getParameter<
int>(
"Active_Area_Repeats");
32 if (doAreaFastjet_ || doRhoFastjet_) {
33 fjActiveArea_ = std::make_shared<fastjet::ActiveAreaSpec>(ghostEtaMax, activeAreaRepeats, ghostArea);
34 if ((ghostEtaMax < 0) || (activeAreaRepeats < 0) || (ghostArea < 0))
36 <<
"Parameters ghostEtaMax, activeAreaRepeats or ghostArea for doAreaFastjet/doRhoFastjet are not defined."
42 std::vector<fastjet::PseudoJet>&
towers,
43 std::vector<fastjet::PseudoJet>&
output) {
47 fjOriginalInputs_ = (*fjInputs_);
48 for (
unsigned int i = 0;
i < fjInputs_->size(); ++
i) {
49 fjOriginalInputs_[
i].set_user_index((*fjInputs_)[
i].user_index());
54 fjJetDefinition_ = std::make_shared<fastjet::JetDefinition>(*jetDef);
58 LogDebug(
"PileUpSubtractor") <<
"The subtractor setting up geometry...\n";
60 if (geo_ ==
nullptr) {
69 for (std::vector<DetId>::const_iterator did = alldid.begin(); did != alldid.end(); did++) {
72 allgeomid_.push_back(*did);
74 if (hid.
ieta() != ietaold) {
76 geomtowers_[hid.
ieta()] = 1;
77 if (hid.
ieta() > ietamax_)
78 ietamax_ = hid.
ieta();
79 if (hid.
ieta() < ietamin_)
80 ietamin_ = hid.
ieta();
82 geomtowers_[hid.
ieta()]++;
88 for (
int i = ietamin_;
i < ietamax_ + 1;
i++) {
89 ntowersWithJets_[
i] = 0;
97 LogDebug(
"PileUpSubtractor") <<
"The subtractor calculating pedestals...\n";
98 map<int, double> emean2;
99 map<int, int> ntowers;
101 int ietaold = -10000;
106 for (
int i = ietamin_;
i < ietamax_ + 1;
i++) {
113 for (vector<fastjet::PseudoJet>::const_iterator input_object = coll.begin(), fjInputsEnd = coll.end();
114 input_object != fjInputsEnd;
117 ieta0 =
ieta(originalTower);
118 double Original_Et = originalTower->et();
119 if (ieta0 - ietaold != 0) {
120 emean_[ieta0] = emean_[ieta0] + Original_Et;
121 emean2[ieta0] = emean2[ieta0] + Original_Et * Original_Et;
125 emean_[ieta0] = emean_[ieta0] + Original_Et;
126 emean2[ieta0] = emean2[ieta0] + Original_Et * Original_Et;
131 for (map<int, int>::const_iterator
gt = geomtowers_.begin();
gt != geomtowers_.end();
gt++) {
132 int it = (*gt).first;
134 double e1 = (*(emean_.find(it))).second;
135 double e2 = (*emean2.find(it)).
second;
136 int nt = (*gt).second - (*(ntowersWithJets_.find(it))).second;
138 LogDebug(
"PileUpSubtractor") <<
" ieta : " << it <<
" number of towers : " <<
nt <<
" e1 : " <<
e1 <<
" e2 : " << e2
141 emean_[it] =
e1 /
nt;
145 esigma_[it] = nSigmaPU_ *
sqrt(eee);
150 LogDebug(
"PileUpSubtractor") <<
" ieta : " << it <<
" Pedestals : " << emean_[it] <<
" " << esigma_[it] <<
"\n";
158 LogDebug(
"PileUpSubtractor") <<
"The subtractor subtracting pedestals...\n";
161 for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin(), fjInputsEnd = coll.end();
162 input_object != fjInputsEnd;
168 double etnew = itow->et() - (*(emean_.find(it))).second - (*(esigma_.find(it))).second;
169 float mScale = etnew / input_object->Et();
174 input_object->py() * mScale,
175 input_object->pz() * mScale,
176 input_object->e() * mScale);
178 int index = input_object->user_index();
179 input_object->reset_momentum(towP4.px(), towP4.py(), towP4.pz(), towP4.energy());
180 input_object->set_user_index(
index);
185 LogDebug(
"PileUpSubtractor") <<
"The subtractor calculating orphan input...\n";
187 (*fjInputs_) = fjOriginalInputs_;
189 vector<int> jettowers;
190 vector<pair<int, int> > excludedTowers;
192 vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin(), fjJetsEnd = fjJets_->end();
193 for (; pseudojetTMP != fjJetsEnd; ++pseudojetTMP) {
194 if (pseudojetTMP->perp() < puPtMin_)
198 for (vector<HcalDetId>::const_iterator im = allgeomid_.begin(); im != allgeomid_.end(); im++) {
200 vector<pair<int, int> >::const_iterator exclude =
201 find(excludedTowers.begin(), excludedTowers.end(), pair<int, int>(im->ieta(), im->iphi()));
202 if (
dr < radiusPU_ && exclude == excludedTowers.end()) {
203 ntowersWithJets_[(*im).ieta()]++;
204 excludedTowers.push_back(pair<int, int>(im->ieta(), im->iphi()));
207 vector<fastjet::PseudoJet>::const_iterator it = fjInputs_->begin(), fjInputsEnd = fjInputs_->end();
209 for (; it != fjInputsEnd; ++it) {
210 int index = it->user_index();
213 vector<pair<int, int> >::const_iterator exclude =
214 find(excludedTowers.begin(), excludedTowers.end(), pair<int, int>(ie, ip));
215 if (exclude != excludedTowers.end()) {
216 jettowers.push_back(
index);
224 for (vector<fastjet::PseudoJet>::const_iterator it = fjInputs_->begin(), fjInputsEnd = fjInputs_->end();
227 int index = it->user_index();
228 vector<int>::const_iterator itjet =
find(jettowers.begin(), jettowers.end(),
index);
229 if (itjet == jettowers.end()) {
231 fastjet::PseudoJet orphan(originalTower->px(), originalTower->py(), originalTower->pz(), originalTower->energy());
232 orphan.set_user_index(
index);
234 orphanInput.push_back(orphan);
240 LogDebug(
"PileUpSubtractor") <<
"The subtractor correcting jets...\n";
242 using namespace reco;
247 jetOffset_.reserve(fjJets_->size());
248 vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin(), jetsEnd = fjJets_->end();
249 for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
250 int ijet = pseudojetTMP - fjJets_->begin();
251 jetOffset_[ijet] = 0;
253 std::vector<fastjet::PseudoJet>
towers = fastjet::sorted_by_pt(pseudojetTMP->constituents());
254 double newjetet = 0.;
255 for (vector<fastjet::PseudoJet>::const_iterator ito =
towers.begin(), towEnd =
towers.end(); ito != towEnd; ++ito) {
257 int it =
ieta(originalTower);
258 double Original_Et = originalTower->et();
259 double etnew = Original_Et - (*emean_.find(it)).
second - (*esigma_.find(it)).
second;
262 newjetet = newjetet + etnew;
263 jetOffset_[ijet] += Original_Et - etnew;
265 double mScale = newjetet / pseudojetTMP->Et();
266 LogDebug(
"PileUpSubtractor") <<
"pseudojetTMP->Et() : " << pseudojetTMP->Et() <<
'\n';
267 LogDebug(
"PileUpSubtractor") <<
"newjetet : " << newjetet <<
'\n';
268 LogDebug(
"PileUpSubtractor") <<
"jetOffset_[ijet] : " << jetOffset_[ijet] <<
'\n';
269 LogDebug(
"PileUpSubtractor") <<
"pseudojetTMP->Et() - jetOffset_[ijet] : " << pseudojetTMP->Et() - jetOffset_[ijet]
271 LogDebug(
"PileUpSubtractor") <<
"Scale is : " << mScale <<
'\n';
272 int cshist = pseudojetTMP->cluster_hist_index();
273 pseudojetTMP->reset_momentum(pseudojetTMP->px() * mScale,
274 pseudojetTMP->py() * mScale,
275 pseudojetTMP->pz() * mScale,
276 pseudojetTMP->e() * mScale);
277 pseudojetTMP->set_cluster_hist_index(cshist);
284 for (vector<HcalDetId>::const_iterator im = allgeomid_.begin(); im != allgeomid_.end(); im++) {
285 if (im->depth() != 1)
290 pu += (*emean_.find(im->ieta())).second + (*esigma_.find(im->ieta())).second;
299 return (*emean_.find(it)).
second;
304 return (*esigma_.find(it)).
second;
309 return (*emean_.find(it)).
second + (*esigma_.find(it)).
second;
315 int n = (*(geomtowers_.find(it))).second - (*(ntowersWithJets_.find(it))).second;
321 int n = (*(ntowersWithJets_.find(it))).second;
327 const CaloTower* ctc = dynamic_cast<const CaloTower*>(
in.get());
331 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
338 const CaloTower* ctc = dynamic_cast<const CaloTower*>(
in.get());
342 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";