1 #ifndef TtFullLepKinSolutionProducer_h
2 #define TtFullLepKinSolutionProducer_h
10 #include "TLorentzVector.h"
40 bool operator()(std::pair<double, int>
a, std::pair<double, int>
b){
41 return a.first > b.first;
61 return (l1->
pt() > l2->
pt());
94 produces<std::vector<std::vector<int> > > ();
95 produces<std::vector<reco::LeafCandidate> >(
"fullLepNeutrinos");
96 produces<std::vector<reco::LeafCandidate> >(
"fullLepNeutrinoBars");
97 produces<std::vector<double> >(
"solWeight");
98 produces<bool>(
"isWrongCharge");
118 std::vector<std::vector<int> > idcsV;
119 std::vector<reco::LeafCandidate> nusV;
120 std::vector<reco::LeafCandidate> nuBarsV;
121 std::vector<std::pair<double, int> > weightsV;
124 std::auto_ptr<std::vector<std::vector<int> > > pIdcs(
new std::vector<std::vector<int> >);
125 std::auto_ptr<std::vector<reco::LeafCandidate> > pNus(
new std::vector<reco::LeafCandidate>);
126 std::auto_ptr<std::vector<reco::LeafCandidate> > pNuBars(
new std::vector<reco::LeafCandidate>);
127 std::auto_ptr<std::vector<double> > pWeight(
new std::vector<double>);
128 std::auto_ptr<bool> pWrongCharge(
new bool);
139 int selMuon1 = -1, selMuon2 = -1;
140 int selElectron1 = -1, selElectron2 = -1;
144 bool isWrongCharge =
false;
145 bool jetsFound =
false;
146 bool METFound =
false;
147 bool electronsFound =
false;
148 bool electronMuonFound =
false;
149 bool muonsFound =
false;
152 if(jets->size()>=2) { jetsFound =
true; }
155 if(mets->size()>=1) { METFound =
true; }
159 if(muons->size() + electrons->size() >=2) {
161 if(electrons->size() == 0) mumu =
true;
162 else if(muons->size() == 0) ee =
true;
163 else if(electrons->size() == 1) {
164 if(muons->size() == 1) emu =
true;
165 else if(
PTComp(&(*electrons)[0], &(*muons)[1])) emu =
true;
168 else if(electrons->size() > 1) {
169 if(
PTComp(&(*electrons)[1], &(*muons)[0])) ee =
true;
170 else if(muons->size() == 1) emu =
true;
171 else if(
PTComp(&(*electrons)[0], &(*muons)[1])) emu =
true;
184 electronsFound =
true;
185 if(!
LepDiffCharge(&(*electrons)[0], &(*electrons)[1])) isWrongCharge =
true;
192 electronMuonFound =
true;
193 if(!
LepDiffCharge(&(*electrons)[0], &(*muons)[0])) isWrongCharge =
true;
207 if(!
LepDiffCharge(&(*muons)[0], &(*muons)[1])) isWrongCharge =
true;
212 *pWrongCharge = isWrongCharge;
215 if(
int(ee)+int(emu)+int(mumu)>1) {
216 edm::LogWarning(
"TtFullLepKinSolutionProducer") <<
"Lepton selection criteria uncorrectly defined";
224 if(correctLeptons && METFound && jetsFound) {
230 if(jets->size()<
static_cast<unsigned int>(stop) || stop<0) stop=jets->size();
236 for (
int ib = 0; ib<stop; ib++) {
238 for (
int ibbar = 0; ibbar<stop; ibbar++) {
240 if(ib==ibbar)
continue;
242 std::vector<int> idcs;
246 idcs.push_back(ibbar);
248 TLorentzVector LV_l1;
249 TLorentzVector LV_l2;
250 TLorentzVector LV_b = TLorentzVector((*jets)[ib].correctedJet(
jetCorrLevel_,
"bottom").px(),
254 TLorentzVector LV_bbar = TLorentzVector((*jets)[ibbar].correctedJet(
jetCorrLevel_,
"bottom").px(),
259 double xconstraint = 0, yconstraint = 0;
262 idcs.push_back(selElectron1);
263 LV_l1.SetXYZT((*electrons)[selElectron1].px(),
264 (*electrons)[selElectron1].py(),
265 (*electrons)[selElectron1].pz(),
266 (*electrons)[selElectron1].
energy());
267 xconstraint += (*electrons)[selElectron1].px();
268 yconstraint += (*electrons)[selElectron1].py();
270 idcs.push_back(selElectron2);
271 LV_l2.SetXYZT((*electrons)[selElectron2].px(),
272 (*electrons)[selElectron2].py(),
273 (*electrons)[selElectron2].pz(),
274 (*electrons)[selElectron2].
energy());
275 xconstraint += (*electrons)[selElectron2].px();
276 yconstraint += (*electrons)[selElectron2].py();
285 idcs.push_back(selElectron1);
286 LV_l1.SetXYZT((*electrons)[selElectron1].px(),
287 (*electrons)[selElectron1].py(),
288 (*electrons)[selElectron1].pz(),
289 (*electrons)[selElectron1].
energy());
290 xconstraint += (*electrons)[selElectron1].px();
291 yconstraint += (*electrons)[selElectron1].py();
296 idcs.push_back(selMuon1);
297 LV_l2.SetXYZT((*muons)[selMuon1].px(),
298 (*muons)[selMuon1].py(),
299 (*muons)[selMuon1].pz(),
300 (*muons)[selMuon1].
energy());
301 xconstraint += (*muons)[selMuon1].px();
302 yconstraint += (*muons)[selMuon1].py();
307 idcs.push_back(selMuon1);
308 LV_l1.SetXYZT((*muons)[selMuon1].px(),
309 (*muons)[selMuon1].py(),
310 (*muons)[selMuon1].pz(),
311 (*muons)[selMuon1].
energy());
312 xconstraint += (*muons)[selMuon1].px();
313 yconstraint += (*muons)[selMuon1].py();
315 idcs.push_back(selElectron1);
316 LV_l2.SetXYZT((*electrons)[selElectron1].px(),
317 (*electrons)[selElectron1].py(),
318 (*electrons)[selElectron1].pz(),
319 (*electrons)[selElectron1].
energy());
320 xconstraint += (*electrons)[selElectron1].px();
321 yconstraint += (*electrons)[selElectron1].py();
328 idcs.push_back(selElectron1);
329 LV_l1.SetXYZT((*electrons)[selElectron1].px(),
330 (*electrons)[selElectron1].py(),
331 (*electrons)[selElectron1].pz(),
332 (*electrons)[selElectron1].
energy());
333 xconstraint += (*electrons)[selElectron1].px();
334 yconstraint += (*electrons)[selElectron1].py();
338 idcs.push_back(selMuon1);
339 LV_l2.SetXYZT((*muons)[selMuon1].px(),
340 (*muons)[selMuon1].py(),
341 (*muons)[selMuon1].pz(),
342 (*muons)[selMuon1].
energy());
343 xconstraint += (*muons)[selMuon1].px();
344 yconstraint += (*muons)[selMuon1].py();
351 idcs.push_back(selElectron1);
352 LV_l2.SetXYZT((*electrons)[selElectron1].px(),
353 (*electrons)[selElectron1].py(),
354 (*electrons)[selElectron1].pz(),
355 (*electrons)[selElectron1].
energy());
356 xconstraint += (*electrons)[selElectron1].px();
357 yconstraint += (*electrons)[selElectron1].py();
361 idcs.push_back(selMuon1);
362 LV_l1.SetXYZT((*muons)[selMuon1].px(),
363 (*muons)[selMuon1].py(),
364 (*muons)[selMuon1].pz(),
365 (*muons)[selMuon1].
energy());
366 xconstraint += (*muons)[selMuon1].px();
367 yconstraint += (*muons)[selMuon1].py();
376 idcs.push_back(selMuon1);
377 LV_l1.SetXYZT((*muons)[selMuon1].px(),
378 (*muons)[selMuon1].py(),
379 (*muons)[selMuon1].pz(),
380 (*muons)[selMuon1].
energy());
381 xconstraint += (*muons)[selMuon1].px();
382 yconstraint += (*muons)[selMuon1].py();
384 idcs.push_back(selMuon2);
385 LV_l2.SetXYZT((*muons)[selMuon2].px(),
386 (*muons)[selMuon2].py(),
387 (*muons)[selMuon2].pz(),
388 (*muons)[selMuon2].
energy());
389 xconstraint += (*muons)[selMuon2].px();
390 yconstraint += (*muons)[selMuon2].py();
393 xconstraint += (*jets)[ib].px() + (*jets)[ibbar].px() + (*mets)[0].px();
394 yconstraint += (*jets)[ib].py() + (*jets)[ibbar].py() + (*mets)[0].py();
403 idcsV.push_back(idcs);
410 weightsV.push_back(std::make_pair(nuSol.
weight, nSol));
418 if(weightsV.size()==0){
420 std::vector<int> idcs;
421 for(
int i=0;
i<6; ++
i)
424 idcsV.push_back(idcs);
425 weightsV.push_back(std::make_pair(-1,0));
429 nuBarsV.push_back(nuBar);
433 int weightL = weightsV.
size();
434 int nuL = nusV.size();
435 int nuBarL = nuBarsV.size();
436 int idxL = idcsV.size();
438 if(weightL!=nuL || weightL!=nuBarL || weightL!=idxL){
439 edm::LogWarning(
"TtFullLepKinSolutionProducer") <<
"Output vectors are of different length:"
440 <<
"\n weight: " << weightL
442 <<
"\n nubar: " << nuBarL
443 <<
"\n idcs: " << idxL;
447 if(weightsV.size()>1){
455 for(
int i=0;
i<stop; ++
i){
456 pWeight->push_back(weightsV[
i].
first);
457 pNus ->push_back(nusV[weightsV[
i].
second]);
458 pNuBars->push_back(nuBarsV[weightsV[
i].second]);
459 pIdcs ->push_back(idcsV[weightsV[
i].second]);
464 evt.
put(pNus,
"fullLepNeutrinos");
465 evt.
put(pNuBars,
"fullLepNeutrinoBars");
466 evt.
put(pWeight,
"solWeight");
467 evt.
put(pWrongCharge,
"isWrongCharge");
T getParameter(std::string const &) const
bool operator()(std::pair< double, int > a, std::pair< double, int > b)
bool LepDiffCharge(const reco::Candidate *, const reco::Candidate *) const
virtual double pt() const =0
transverse momentum
bool HasPositiveCharge(const reco::Candidate *) const
std::vector< double > nupars_
void SetConstraints(double xx=0, double yy=0)
~TtFullLepKinSolutionProducer()
U second(std::pair< T, U > const &p)
bool PTComp(const reco::Candidate *, const reco::Candidate *) const
NeutrinoSolution getNuSolution(TLorentzVector LV_l, TLorentzVector LV_l_, TLorentzVector LV_b, TLorentzVector LV_b_)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
reco::LeafCandidate neutrino
virtual int charge() const =0
electric charge
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::string jetCorrLevel_
TtFullLepKinSolutionProducer(const edm::ParameterSet &iConfig)
virtual void produce(edm::Event &evt, const edm::EventSetup &iSetup)
reco::LeafCandidate neutrinoBar
TtFullLepKinSolver * solver