36 #include "CLHEP/Units/GlobalPhysicalConstants.h"
37 #include "Math/GenVector/VectorUtil.h"
38 #include "Math/GenVector/PxPyPzE4D.h"
59 PileupJPTJetIdAlgo::~PileupJPTJetIdAlgo() {
63 void PileupJPTJetIdAlgo::bookMVAReader() {
72 std::cout <<
" TMVA method " << tmvaMethod_.c_str() <<
" " << tmvaWeights_.c_str() << std::endl;
73 reader_ =
new TMVA::Reader(
"!Color:!Silent");
75 reader_->AddVariable(
"Nvtx", &Nvtx);
76 reader_->AddVariable(
"PtJ", &PtJ);
77 reader_->AddVariable(
"EtaJ", &EtaJ);
78 reader_->AddVariable(
"Beta", &Beta);
79 reader_->AddVariable(
"MultCalo", &MultCalo);
80 reader_->AddVariable(
"dAxis1c", &dAxis1c);
81 reader_->AddVariable(
"dAxis2c", &dAxis2c);
82 reader_->AddVariable(
"MultTr", &MultTr);
83 reader_->AddVariable(
"dAxis1t", &dAxis1t);
84 reader_->AddVariable(
"dAxis2t", &dAxis2t);
90 readerF_ =
new TMVA::Reader(
"!Color:!Silent");
92 readerF_->AddVariable(
"Nvtx", &Nvtx);
93 readerF_->AddVariable(
"PtJ", &PtJ);
94 readerF_->AddVariable(
"EtaJ", &EtaJ);
95 readerF_->AddVariable(
"MultCalo", &MultCalo);
96 readerF_->AddVariable(
"dAxis1c", &dAxis1c);
97 readerF_->AddVariable(
"dAxis2c", &dAxis2c);
106 std::cout <<
"================================ JET LOOP ==================== " << std::endl;
107 std::cout <<
"================ jetPt = " << (*jet).pt() << std::endl;
108 std::cout <<
"================ jetEta = " << (*jet).eta() << std::endl;
114 int ncalotowers = 0.;
119 double dphideta = 0.;
126 std::vector<CaloTowerPtr> calotwrs = (*rawcalojet).getCaloConstituents();
129 std::cout <<
"======= CaloTowerPtr DONE == " << std::endl;
132 for (std::vector<CaloTowerPtr>::const_iterator icalot = calotwrs.begin(); icalot != calotwrs.end(); icalot++) {
135 double deta = (*jet).eta() - (*icalot)->eta();
136 double dphi = (*jet).phi() - (*icalot)->phi();
139 dphi = dphi - 2. *
M_PI;
140 if (dphi < -1. *
M_PI)
141 dphi = dphi + 2. *
M_PI;
144 std::cout <<
" CaloTower jet eta " << (*jet).eta() <<
" tower eta " << (*icalot)->eta() <<
" jet phi "
145 << (*jet).phi() <<
" tower phi " << (*icalot)->phi() <<
" dphi " << dphi <<
" " << (*icalot)->pt()
146 <<
" ieta " << (*icalot)->ieta() <<
" " <<
abs((*icalot)->ieta()) << std::endl;
148 if (
abs((*icalot)->ieta()) < 30)
149 EE = EE + (*icalot)->emEnergy();
150 if (
abs((*icalot)->ieta()) < 30)
151 HE = HE + (*icalot)->hadEnergy();
152 if (
abs((*icalot)->ieta()) > 29)
153 EELong = EELong + (*icalot)->emEnergy();
154 if (
abs((*icalot)->ieta()) > 29)
155 EEShort = EEShort + (*icalot)->hadEnergy();
157 sumpt = sumpt + (*icalot)->pt();
158 dphi2 = dphi2 + dphi * dphi * (*icalot)->pt();
159 deta2 = deta2 + deta * deta * (*icalot)->pt();
160 dphi1 = dphi1 + dphi * (*icalot)->pt();
161 deta1 = deta1 + deta * (*icalot)->pt();
162 dphideta = dphideta + dphi * deta * (*icalot)->pt();
167 deta1 = deta1 / sumpt;
168 dphi1 = dphi1 / sumpt;
169 deta2 = deta2 / sumpt;
170 dphi2 = dphi2 / sumpt;
171 dphideta = dphideta / sumpt;
176 double detavar = deta2 - deta1 * deta1;
177 double dphivar = dphi2 - dphi1 * dphi1;
178 double dphidetacov = dphideta - deta1 * dphi1;
180 double det = (detavar - dphivar) * (detavar - dphivar) + 4 * dphidetacov * dphidetacov;
182 double x1 = (detavar + dphivar + det) / 2.;
183 double x2 = (detavar + dphivar - det) / 2.;
186 std::cout <<
" ncalo " << ncalotowers <<
" deta2 " << deta2 <<
" dphi2 " << dphi2 <<
" deta1 " << deta1
187 <<
" dphi1 " << dphi1 <<
" detavar " << detavar <<
" dphivar " << dphivar <<
" dphidetacov "
188 << dphidetacov <<
" sqrt(det) " <<
sqrt(det) <<
" x1 " << x1 <<
" x2 " << x2 << std::endl;
197 double dphidetatr = 0.;
202 if ((*it)->pt() > 0.5 && ((*it)->ptError() / (*it)->pt()) < 0.05) {
204 sumpttr = sumpttr + (*it)->pt();
205 double deta = (*jet).eta() - (*it)->eta();
206 double dphi = (*jet).phi() - (*it)->phi();
209 dphi = dphi - 2. *
M_PI;
210 if (dphi < -1. *
M_PI)
211 dphi = dphi + 2. *
M_PI;
213 dphitr2 = dphitr2 + dphi * dphi * (*it)->pt();
214 detatr2 = detatr2 + deta * deta * (*it)->pt();
215 dphitr1 = dphitr1 + dphi * (*it)->pt();
216 detatr1 = detatr1 + deta * (*it)->pt();
217 dphidetatr = dphidetatr + dphi * deta * (*it)->pt();
219 std::cout <<
" Tracks-in-in " << (*it)->pt() <<
" " << (*it)->eta() <<
" " << (*it)->phi() <<
" in jet "
220 << (*jet).eta() <<
" " << (*jet).phi() <<
" jet pt " << (*jet).pt() << std::endl;
227 if ((*it)->pt() > 0.5 && ((*it)->ptError() / (*it)->pt()) < 0.05) {
229 sumpttr = sumpttr + (*it)->pt();
230 double deta = (*jet).eta() - (*it)->eta();
231 double dphi = (*jet).phi() - (*it)->phi();
234 dphi = dphi - 2. *
M_PI;
235 if (dphi < -1. *
M_PI)
236 dphi = dphi + 2. *
M_PI;
238 dphitr2 = dphitr2 + dphi * dphi * (*it)->pt();
239 detatr2 = detatr2 + deta * deta * (*it)->pt();
240 dphitr1 = dphitr1 + dphi * (*it)->pt();
241 detatr1 = detatr1 + deta * (*it)->pt();
242 dphidetatr = dphidetatr + dphi * deta * (*it)->pt();
244 std::cout <<
" Tracks-in-in " << (*it)->pt() <<
" " << (*it)->eta() <<
" " << (*it)->phi() <<
" in jet "
245 << (*jet).eta() <<
" " << (*jet).phi() <<
" jet pt " << (*jet).pt() << std::endl;
250 std::cout <<
" Number of tracks in-in and in-out " << pioninin.
size() <<
" " << pioninout.
size() << std::endl;
253 detatr1 = detatr1 / sumpttr;
254 dphitr1 = dphitr1 / sumpttr;
255 detatr2 = detatr2 / sumpttr;
256 dphitr2 = dphitr2 / sumpttr;
257 dphidetatr = dphidetatr / sumpttr;
262 double detavart = detatr2 - detatr1 * detatr1;
263 double dphivart = dphitr2 - dphitr1 * dphitr1;
264 double dphidetacovt = dphidetatr - detatr1 * dphitr1;
266 double dettr = (detavart - dphivart) * (detavart - dphivart) + 4 * dphidetacovt * dphidetacovt;
268 double x1tr = (detavart + dphivart + dettr) / 2.;
269 double x2tr = (detavart + dphivart - dettr) / 2.;
272 std::cout <<
" ntracks " << ntracks <<
" detatr2 " << detatr2 <<
" dphitr2 " << dphitr2 <<
" detatr1 " << detatr1
273 <<
" dphitr1 " << dphitr1 <<
" detavart " << detavart <<
" dphivart " << dphivart <<
" dphidetacovt "
274 << dphidetacovt <<
" sqrt(det) " <<
sqrt(dettr) <<
" x1tr " << x1tr <<
" x2tr " << x2tr << std::endl;
279 Beta = (*jet).getSpecific().Zch;
284 MultCalo = ncalotowers;
288 if (fabs(EtaJ) < 2.6) {
289 mva_ = reader_->EvaluateMVA(
"BDTG method");
292 mva_ = readerF_->EvaluateMVA(
"BDTG method");
296 std::cout <<
"======= Computed MVA = " << mva_ << std::endl;
Jets made from CaloTowers.
const edm::RefToBase< reco::Jet > & getCaloJetRef() const
const_iterator end() const
Termination of iteration.
const_iterator begin() const
Initialize an iterator over the RefVector.
Jets made from CaloJets corrected for ZSP and tracks.
Abs< T >::type abs(const T &t)
T getParameter(std::string const &) const
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
size_type size() const
Size of the RefVector.
std::string fullPath() const