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 if ((hid).
depth() == 1) {
73 allgeomid_.push_back(*did);
75 if ((hid).
ieta() != ietaold) {
76 ietaold = (hid).
ieta();
77 geomtowers_[(hid).
ieta()] = 1;
78 if ((hid).ieta() > ietamax_)
79 ietamax_ = (hid).ieta();
80 if ((hid).
ieta() < ietamin_)
81 ietamin_ = (hid).
ieta();
83 geomtowers_[(hid).
ieta()]++;
90 for (
int i = ietamin_;
i < ietamax_ + 1;
i++) {
91 ntowersWithJets_[
i] = 0;
99 LogDebug(
"PileUpSubtractor") <<
"The subtractor calculating pedestals...\n";
100 map<int, double> emean2;
101 map<int, int> ntowers;
103 int ietaold = -10000;
108 for (
int i = ietamin_;
i < ietamax_ + 1;
i++) {
115 for (vector<fastjet::PseudoJet>::const_iterator input_object = coll.begin(), fjInputsEnd = coll.end();
116 input_object != fjInputsEnd;
119 ieta0 =
ieta(originalTower);
120 double Original_Et = originalTower->et();
121 if (ieta0 - ietaold != 0) {
122 emean_[ieta0] = emean_[ieta0] + Original_Et;
123 emean2[ieta0] = emean2[ieta0] + Original_Et * Original_Et;
127 emean_[ieta0] = emean_[ieta0] + Original_Et;
128 emean2[ieta0] = emean2[ieta0] + Original_Et * Original_Et;
133 for (map<int, int>::const_iterator gt = geomtowers_.begin(); gt != geomtowers_.end(); gt++) {
134 int it = (*gt).first;
136 double e1 = (*(emean_.find(it))).second;
137 double e2 = (*emean2.find(it)).
second;
138 int nt = (*gt).second - (*(ntowersWithJets_.find(it))).second;
140 LogDebug(
"PileUpSubtractor") <<
" ieta : " << it <<
" number of towers : " <<
nt <<
" e1 : " <<
e1 <<
" e2 : " << e2
143 emean_[it] =
e1 /
nt;
147 esigma_[it] = nSigmaPU_ *
sqrt(eee);
152 LogDebug(
"PileUpSubtractor") <<
" ieta : " << it <<
" Pedestals : " << emean_[it] <<
" " << esigma_[it] <<
"\n";
160 LogDebug(
"PileUpSubtractor") <<
"The subtractor subtracting pedestals...\n";
163 for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin(), fjInputsEnd = coll.end();
164 input_object != fjInputsEnd;
170 double etnew = itow->et() - (*(emean_.find(it))).second - (*(esigma_.find(it))).second;
171 float mScale = etnew / input_object->Et();
176 input_object->py() * mScale,
177 input_object->pz() * mScale,
178 input_object->e() * mScale);
180 int index = input_object->user_index();
181 input_object->reset_momentum(towP4.px(), towP4.py(), towP4.pz(), towP4.energy());
182 input_object->set_user_index(
index);
187 LogDebug(
"PileUpSubtractor") <<
"The subtractor calculating orphan input...\n";
189 (*fjInputs_) = fjOriginalInputs_;
191 vector<int> jettowers;
192 vector<pair<int, int> > excludedTowers;
194 vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin(), fjJetsEnd = fjJets_->end();
195 for (; pseudojetTMP != fjJetsEnd; ++pseudojetTMP) {
196 if (pseudojetTMP->perp() < puPtMin_)
200 for (vector<HcalDetId>::const_iterator im = allgeomid_.begin(); im != allgeomid_.end(); im++) {
202 vector<pair<int, int> >::const_iterator exclude =
203 find(excludedTowers.begin(), excludedTowers.end(), pair<int, int>(im->ieta(), im->iphi()));
204 if (
dr < radiusPU_ && exclude == excludedTowers.end()) {
205 ntowersWithJets_[(*im).ieta()]++;
206 excludedTowers.push_back(pair<int, int>(im->ieta(), im->iphi()));
209 vector<fastjet::PseudoJet>::const_iterator it = fjInputs_->begin(), fjInputsEnd = fjInputs_->end();
211 for (; it != fjInputsEnd; ++it) {
212 int index = it->user_index();
215 vector<pair<int, int> >::const_iterator exclude =
216 find(excludedTowers.begin(), excludedTowers.end(), pair<int, int>(ie, ip));
217 if (exclude != excludedTowers.end()) {
218 jettowers.push_back(
index);
226 for (vector<fastjet::PseudoJet>::const_iterator it = fjInputs_->begin(), fjInputsEnd = fjInputs_->end();
229 int index = it->user_index();
230 vector<int>::const_iterator itjet =
find(jettowers.begin(), jettowers.end(),
index);
231 if (itjet == jettowers.end()) {
233 fastjet::PseudoJet orphan(originalTower->px(), originalTower->py(), originalTower->pz(), originalTower->energy());
234 orphan.set_user_index(
index);
236 orphanInput.push_back(orphan);
242 LogDebug(
"PileUpSubtractor") <<
"The subtractor correcting jets...\n";
244 using namespace reco;
249 jetOffset_.reserve(fjJets_->size());
250 vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin(), jetsEnd = fjJets_->end();
251 for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
252 int ijet = pseudojetTMP - fjJets_->begin();
253 jetOffset_[ijet] = 0;
255 std::vector<fastjet::PseudoJet>
towers = fastjet::sorted_by_pt(pseudojetTMP->constituents());
256 double newjetet = 0.;
257 for (vector<fastjet::PseudoJet>::const_iterator ito =
towers.begin(), towEnd =
towers.end(); ito != towEnd; ++ito) {
259 int it =
ieta(originalTower);
260 double Original_Et = originalTower->et();
261 double etnew = Original_Et - (*emean_.find(it)).
second - (*esigma_.find(it)).
second;
264 newjetet = newjetet + etnew;
265 jetOffset_[ijet] += Original_Et - etnew;
267 double mScale = newjetet / pseudojetTMP->Et();
268 LogDebug(
"PileUpSubtractor") <<
"pseudojetTMP->Et() : " << pseudojetTMP->Et() <<
'\n';
269 LogDebug(
"PileUpSubtractor") <<
"newjetet : " << newjetet <<
'\n';
270 LogDebug(
"PileUpSubtractor") <<
"jetOffset_[ijet] : " << jetOffset_[ijet] <<
'\n';
271 LogDebug(
"PileUpSubtractor") <<
"pseudojetTMP->Et() - jetOffset_[ijet] : " << pseudojetTMP->Et() - jetOffset_[ijet]
273 LogDebug(
"PileUpSubtractor") <<
"Scale is : " << mScale <<
'\n';
274 int cshist = pseudojetTMP->cluster_hist_index();
275 pseudojetTMP->reset_momentum(pseudojetTMP->px() * mScale,
276 pseudojetTMP->py() * mScale,
277 pseudojetTMP->pz() * mScale,
278 pseudojetTMP->e() * mScale);
279 pseudojetTMP->set_cluster_hist_index(cshist);
286 for (vector<HcalDetId>::const_iterator im = allgeomid_.begin(); im != allgeomid_.end(); im++) {
287 if (im->depth() != 1)
292 pu += (*emean_.find(im->ieta())).second + (*esigma_.find(im->ieta())).second;
301 return (*emean_.find(it)).
second;
306 return (*esigma_.find(it)).
second;
311 return (*emean_.find(it)).
second + (*esigma_.find(it)).
second;
317 int n = (*(geomtowers_.find(it))).second - (*(ntowersWithJets_.find(it))).second;
323 int n = (*(ntowersWithJets_.find(it))).second;
329 const CaloTower* ctc = dynamic_cast<const CaloTower*>(
in.get());
333 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
340 const CaloTower* ctc = dynamic_cast<const CaloTower*>(
in.get());
344 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";