26#include <TFitResult.h>
27#include <TFitResultPtr.h>
28#include <TMatrixDSym.h>
31#include "Math/VectorUtil.h"
36 constexpr double GEV = 1000.0;
41using ROOT::Math::PtEtaPhiMVector;
42using ROOT::Math::PxPyPzMVector;
43using ROOT::Math::XYVector;
44using ROOT::Math::VectorUtil::DeltaR;
45using ROOT::Math::VectorUtil::Phi_mpi_pi;
81 Prob->SetUseTauProbability(
true);
82 Prob->SetUseMnuProbability(
false);
83 Prob->SetUseDphiLL(
false);
128 float hEmax = 3000.0;
138 m_fMfit_all = std::make_shared<TH1F>(
"MMC_h1",
"M", hNbins, 0.0,
145 std::make_shared<TH1F>(
"MMC_h1NoW",
"M no weight", hNbins, 0.0, hEmax);
147 m_fPXfit1 = std::make_shared<TH1F>(
"MMC_h2",
"Px1", 4 * hNbins, -hEmax,
149 m_fPYfit1 = std::make_shared<TH1F>(
"MMC_h3",
"Py1", 4 * hNbins, -hEmax,
151 m_fPZfit1 = std::make_shared<TH1F>(
"MMC_h4",
"Pz1", 4 * hNbins, -hEmax,
153 m_fPXfit2 = std::make_shared<TH1F>(
"MMC_h5",
"Px2", 4 * hNbins, -hEmax,
155 m_fPYfit2 = std::make_shared<TH1F>(
"MMC_h6",
"Py2", 4 * hNbins, -hEmax,
157 m_fPZfit2 = std::make_shared<TH1F>(
"MMC_h7",
"Pz2", 4 * hNbins, -hEmax,
174 m_fFitting->SetParNames(
"Max",
"Mean",
"InvWidth2");
198 Info(
"DiTauMassTools",
"------------- Raw Input for MissingMassCalculator --------------");
203 Info(
"DiTauMassTools",
"------------- Prepared Input for MissingMassCalculator--------------");
222 double dummy_METres =
225 dummy_METres * std::abs(cos(dummy_met.Phi() -
preparedInput.m_MetVec.Phi()));
227 dummy_METres * std::abs(sin(dummy_met.Phi() -
preparedInput.m_MetVec.Phi()));
243 Info(
"DiTauMassTools",
"Calling DitauMassCalculatorV9lfv");
249 TFile *outFile = TFile::Open(
"MMC_likelihoods.root",
"UPDATE");
252 if (!outFile->GetDirectory(path.c_str()))
253 outFile->mkdir(path.c_str());
254 outFile->cd(path.c_str());
264 TH1D *nosol =
new TH1D(
"nosol",
"nosol", 7, 0, 7);
272 nosol->Write(nosol->GetName(), TObject::kOverwrite);
287 fStuff.
nutau1 = PtEtaPhiMVector(0., 0., 0., 0.);
288 fStuff.
nutau2 = PtEtaPhiMVector(0., 0., 0., 0.);
289 fStuff.
vistau1 = PtEtaPhiMVector(0., 0., 0., 0.);
290 fStuff.
vistau2 = PtEtaPhiMVector(0., 0., 0., 0.);
302 Info(
"DiTauMassTools",
"Retrieving output from fDitauStuffFit");
307 double q1 = (1. - 0.68) / 2.;
334 PtEtaPhiMVector tlvdummy(0., 0., 0., 0.);
335 XYVector metdummy(0., 0.);
376 PtEtaPhiMVector dummy_vec1(0.0, 0.0, 0.0, 0.0);
377 PtEtaPhiMVector dummy_vec2(0.0, 0.0, 0.0, 0.0);
378 for (
int i = 0; i < 3; i++) {
400 Info(
"DiTauMassTools",
401 ".........................Other input.....................................");
402 Info(
"DiTauMassTools",
"%s",
403 (
"Beam energy =" + std::to_string(
preparedInput.m_beamEnergy) +
404 " sqrt(S) for collisions =" + std::to_string(2.0 *
preparedInput.m_beamEnergy))
406 Info(
"DiTauMassTools",
"%s",
409 Info(
"DiTauMassTools",
"%s",
410 (
"LFV mode " + std::to_string(
preparedInput.m_LFVmode) +
" seed=" + std::to_string(
m_seed))
412 Info(
"DiTauMassTools",
"%s", (
"usetauProbability=" + std::to_string(
Prob->GetUseTauProbability()) +
413 " useTailCleanup=" + std::to_string(
preparedInput.m_fUseTailCleanup))
417 Info(
"DiTauMassTools",
418 "tau1 and tau2 were internally swapped (visible on prepared input printout)");
420 Info(
"DiTauMassTools",
"tau1 and tau2 were NOT internally swapped");
423 Info(
"DiTauMassTools",
"%s",
424 (
" MEtLMin=" + std::to_string(
m_MEtLMin) +
" MEtLMax=" + std::to_string(
m_MEtLMax)).c_str());
425 Info(
"DiTauMassTools",
"%s",
426 (
" MEtPMin=" + std::to_string(
m_MEtPMin) +
" MEtPMax=" + std::to_string(
m_MEtPMax)).c_str());
427 Info(
"DiTauMassTools",
"%s",
428 (
" Phi1Min=" + std::to_string(
m_Phi1Min) +
" Phi1Max=" + std::to_string(
m_Phi1Max)).c_str());
429 Info(
"DiTauMassTools",
"%s",
430 (
" Phi2Min=" + std::to_string(
m_Phi2Min) +
" Phi2Max=" + std::to_string(
m_Phi2Max)).c_str());
431 Info(
"DiTauMassTools",
"%s",
432 (
" Mnu1Min=" + std::to_string(
m_Mnu1Min) +
" Mnu1Max=" + std::to_string(
m_Mnu1Max)).c_str());
433 Info(
"DiTauMassTools",
"%s",
434 (
" Mnu2Min=" + std::to_string(
m_Mnu2Min) +
" Mnu2Max=" + std::to_string(
m_Mnu2Max)).c_str());
443 const PtEtaPhiMVector *origVisTau1 = 0;
444 const PtEtaPhiMVector *origVisTau2 = 0;
457 Info(
"DiTauMassTools",
458 "------------- Printing Final Results for MissingMassCalculator --------------");
459 Info(
"DiTauMassTools",
460 ".............................................................................");
461 Info(
"DiTauMassTools",
"%s", (
"Fit status=" + std::to_string(
OutputInfo.m_FitStatus)).c_str());
464 Info(
"DiTauMassTools",
"%s",
467 Info(
"DiTauMassTools",
"%s",
468 (
" signif=" + std::to_string(
OutputInfo.m_FitSignificance[imeth])).c_str());
469 Info(
"DiTauMassTools",
"%s", (
" mass=" + std::to_string(
OutputInfo.m_FittedMass[imeth])).c_str());
470 Info(
"DiTauMassTools",
"%s", (
" rms/mpv=" + std::to_string(
OutputInfo.m_RMS2MPV)).c_str());
473 Info(
"DiTauMassTools",
" no 4-momentum or MET from this method ");
478 Info(
"DiTauMassTools",
" fit failed ");
481 const PtEtaPhiMVector &tlvnu1 =
OutputInfo.m_nuvec1[imeth];
482 const PtEtaPhiMVector &tlvnu2 =
OutputInfo.m_nuvec2[imeth];
483 const PtEtaPhiMVector &tlvo1 =
OutputInfo.m_objvec1[imeth];
484 const PtEtaPhiMVector &tlvo2 =
OutputInfo.m_objvec2[imeth];
485 const XYVector &tvmet =
OutputInfo.m_FittedMetVec[imeth];
487 Info(
"DiTauMassTools",
"%s",
488 (
" Neutrino-1: P=" + std::to_string(tlvnu1.P()) +
" Pt=" + std::to_string(tlvnu1.Pt()) +
489 " Eta=" + std::to_string(tlvnu1.Eta()) +
" Phi=" + std::to_string(tlvnu1.Phi()) +
490 " M=" + std::to_string(tlvnu1.M()) +
" Px=" + std::to_string(tlvnu1.Px()) +
491 " Py=" + std::to_string(tlvnu1.Py()) +
" Pz=" + std::to_string(tlvnu1.Pz()))
493 Info(
"DiTauMassTools",
"%s",
494 (
" Neutrino-2: P=" + std::to_string(tlvnu2.P()) +
" Pt=" + std::to_string(tlvnu2.Pt()) +
495 " Eta=" + std::to_string(tlvnu2.Eta()) +
" Phi=" + std::to_string(tlvnu2.Phi()) +
496 " M=" + std::to_string(tlvnu2.M()) +
" Px=" + std::to_string(tlvnu2.Px()) +
497 " Py=" + std::to_string(tlvnu2.Py()) +
" Pz=" + std::to_string(tlvnu2.Pz()))
499 Info(
"DiTauMassTools",
"%s",
500 (
" Tau-1: P=" + std::to_string(tlvo1.P()) +
" Pt=" + std::to_string(tlvo1.Pt()) +
501 " Eta=" + std::to_string(tlvo1.Eta()) +
" Phi=" + std::to_string(tlvo1.Phi()) +
502 " M=" + std::to_string(tlvo1.M()) +
" Px=" + std::to_string(tlvo1.Px()) +
503 " Py=" + std::to_string(tlvo1.Py()) +
" Pz=" + std::to_string(tlvo1.Pz()))
505 Info(
"DiTauMassTools",
"%s",
506 (
" Tau-2: P=" + std::to_string(tlvo2.P()) +
" Pt=" + std::to_string(tlvo2.Pt()) +
507 " Eta=" + std::to_string(tlvo2.Eta()) +
" Phi=" + std::to_string(tlvo2.Phi()) +
508 " M=" + std::to_string(tlvo2.M()) +
" Px=" + std::to_string(tlvo2.Px()) +
509 " Py=" + std::to_string(tlvo2.Py()) +
" Pz=" + std::to_string(tlvo2.Pz()))
512 Info(
"DiTauMassTools",
"%s",
513 (
" dR(nu1-visTau1)=" + std::to_string(DeltaR(tlvnu1,*origVisTau1))).c_str());
514 Info(
"DiTauMassTools",
"%s",
515 (
" dR(nu2-visTau2)=" + std::to_string(DeltaR(tlvnu2,*origVisTau2))).c_str());
517 Info(
"DiTauMassTools",
"%s",
518 (
" Fitted MET =" + std::to_string(tvmet.R()) +
" Phi=" + std::to_string(tlvnu1.Phi()) +
519 " Px=" + std::to_string(tvmet.X()) +
" Py=" + std::to_string(tvmet.Y()))
522 Info(
"DiTauMassTools",
"%s", (
" Resonance: P=" + std::to_string(
OutputInfo.m_totalvec[imeth].P()) +
523 " Pt=" + std::to_string(
OutputInfo.m_totalvec[imeth].Pt()) +
524 " Eta=" + std::to_string(
OutputInfo.m_totalvec[imeth].Eta()) +
525 " Phi=" + std::to_string(
OutputInfo.m_totalvec[imeth].Phi()) +
526 " M=" + std::to_string(
OutputInfo.m_totalvec[imeth].M()) +
527 " Px=" + std::to_string(
OutputInfo.m_totalvec[imeth].Px()) +
528 " Py=" + std::to_string(
OutputInfo.m_totalvec[imeth].Py()) +
529 " Pz=" + std::to_string(
OutputInfo.m_totalvec[imeth].Pz()))
544 const double &phi1,
const double &phi2,
545 int &nsol1,
int &nsol2) {
566 int solution_code = 0;
584 if (pTmiss2 * dPhiSign < 0) {
586 return solution_code;
592 if (pTmiss1 * (-dPhiSign) < 0) {
594 return solution_code;
603 double m4noma1 = m2noma1 * m2noma1;
605 double p2v1proj = std::pow(pv1proj, 2);
607 double pTmiss2CscDPhi = pTmiss2 / sinDPhi2;
608 double &pTn1 = pTmiss2CscDPhi;
609 double pT2miss2CscDPhi = pTmiss2CscDPhi * pTmiss2CscDPhi;
612 const double discri1 = m4noma1 + 4 * m2noma1 * pTmiss2CscDPhi * pv1proj -
613 4 * (
m_ET2v1 * (
m_m2Nu1 + pT2miss2CscDPhi) - (pT2miss2CscDPhi * p2v1proj));
618 return solution_code;
626 double m4noma2 = m2noma2 * m2noma2;
628 double p2v2proj = std::pow(pv2proj, 2);
629 double sinDPhi1 = -sinDPhi2;
630 double pTmiss1CscDPhi = pTmiss1 / sinDPhi1;
631 double &pTn2 = pTmiss1CscDPhi;
632 double pT2miss1CscDPhi = pTmiss1CscDPhi * pTmiss1CscDPhi;
634 const double discri2 = m4noma2 + 4 * m2noma2 * pTmiss1CscDPhi * pv2proj -
635 4 * (
m_ET2v2 * (
m_m2Nu2 + pT2miss1CscDPhi) - (pT2miss1CscDPhi * p2v2proj));
640 return solution_code;
646 double sqdiscri1 = sqrt(discri1);
652 double pn1Z = first1 + second1;
654 if (m2noma1 + 2 * pTmiss2CscDPhi * pv1proj + 2 * pn1Z *
m_tauVec1Pz >
658 sqrt(std::pow(pTn1, 2) + std::pow(pn1Z, 2) +
m_m2Nu1));
663 pn1Z = first1 - second1;
665 if (m2noma1 + 2 * pTmiss2CscDPhi * pv1proj + 2 * pn1Z *
m_tauVec1Pz >
670 sqrt(std::pow(pTn1, 2) + std::pow(pn1Z, 2) +
m_m2Nu1));
677 return solution_code;
682 double sqdiscri2 = sqrt(discri2);
688 double pn2Z = first2 + second2;
690 if (m2noma2 + 2 * pTmiss1CscDPhi * pv2proj + 2 * pn2Z *
m_tauVec2Pz >
694 sqrt(std::pow(pTn2, 2) + std::pow(pn2Z, 2) +
m_m2Nu2));
699 pn2Z = first2 - second2;
702 if (m2noma2 + 2 * pTmiss1CscDPhi * pv2proj + 2 * pn2Z *
m_tauVec2Pz >
706 sqrt(std::pow(pTn2, 2) + std::pow(pn2Z, 2) +
m_m2Nu2));
713 return solution_code;
729 if (std::abs(pnux - pTmissx) > 0.001 || std::abs(pnuy - pTmissy) > 0.001) {
730 Info(
"DiTauMassTools",
"%s", (
"NuPsolutionV3 ERROR Pnux-Met.X or Pnuy-Met.Y > 0.001 : " +
731 std::to_string(pnux - pTmissx) +
" and " +
732 std::to_string(pnuy - pTmissx) +
" " +
"Invalid solutions")
735 if (std::abs(mtau1plus -
m_mTau) > 0.001 || std::abs(mtau1moins -
m_mTau) > 0.001 ||
736 std::abs(mtau2plus -
m_mTau) > 0.001 || std::abs(mtau2moins -
m_mTau) > 0.001) {
737 Info(
"DiTauMassTools",
"%s", (
"NuPsolutionV3 ERROR tau mass not recovered : " +
738 std::to_string(mtau1plus) +
" " + std::to_string(mtau1moins) +
" " +
739 std::to_string(mtau2plus) +
" " + std::to_string(mtau2moins))
744 return solution_code;
749 const PtEtaPhiMVector &tau,
const double &l_nu,
750 std::vector<PtEtaPhiMVector> &nu_vec) {
751 int solution_code = 0;
754 PxPyPzMVector nu(met_vec.X(), met_vec.Y(), 0.0, l_nu);
755 PxPyPzMVector nu2(met_vec.X(), met_vec.Y(), 0.0, l_nu);
759 double msq = (Mtau * Mtau - tau.M() * tau.M() - l_nu * l_nu) /
761 double gamma = nu.Px() * nu.Px() + nu.Py() * nu.Py();
762 double beta = tau.Px() * nu.Px() + tau.Py() * nu.Py() + msq;
763 double a = tau.E() * tau.E() - tau.Pz() * tau.Pz();
764 double b = -2 * tau.Pz() * beta;
765 double c = tau.E() * tau.E() * gamma - beta * beta;
766 if ((b * b - 4 *
a * c) < 0)
767 return solution_code;
770 double pvz1 = (-b + sqrt(b * b - 4 *
a * c)) / (2 *
a);
771 double pvz2 = (-b - sqrt(b * b - 4 *
a * c)) / (2 *
a);
773 nu.SetCoordinates(met_vec.X(), met_vec.Y(), pvz1, l_nu);
774 nu2.SetCoordinates(met_vec.X(), met_vec.Y(), pvz2, l_nu);
776 PtEtaPhiMVector return_nu(nu.Pt(), nu.Eta(), nu.Phi(), nu.M());
777 PtEtaPhiMVector return_nu2(nu2.Pt(), nu2.Eta(), nu2.Phi(), nu2.M());
778 nu_vec.push_back(return_nu);
779 nu_vec.push_back(return_nu2);
780 return solution_code;
843 bool paramInsideRange =
false;
862 if (paramInsideRange)
886 if (nsuccesses > 0) {
892 double Px1, Py1, Pz1;
893 double Px2, Py2, Pz2;
894 if (nsuccesses > 0) {
915 if (prob_hist != 0.0)
939 PxPyPzMVector fulltau1, fulltau2;
961 Info(
"DiTauMassTools",
"Scanning ");
962 Info(
"DiTauMassTools",
" Markov ");
963 Info(
"DiTauMassTools",
"%s",
964 (
" V9W niters=" + std::to_string(
m_iter0) +
" " + std::to_string(
m_iter1)).c_str());
965 Info(
"DiTauMassTools",
"%s", (
" nFullScan " + std::to_string(
m_markovNFullScan)).c_str());
966 Info(
"DiTauMassTools",
"%s", (
" nRejectNoSol " + std::to_string(
m_markovNRejectNoSol)).c_str());
968 Info(
"DiTauMassTools",
"%s", (
" nAccept " + std::to_string(
m_markovNAccept)).c_str());
969 Info(
"DiTauMassTools",
"%s",
976 Info(
"DiTauMassTools",
"%s", (
"!!!----> Warning-3 in "
977 "MissingMassCalculator::DitauMassCalculatorV9Walk() : fit status=" +
978 std::to_string(fit_code))
980 Info(
"DiTauMassTools",
"%s",
"....... No solution is found. Printing input info .......");
982 Info(
"DiTauMassTools",
"%s", (
" vis Tau-1: Pt=" + std::to_string(
preparedInput.m_vistau1.Pt()) +
988 Info(
"DiTauMassTools",
"%s", (
" vis Tau-2: Pt=" + std::to_string(
preparedInput.m_vistau2.Pt()) +
994 Info(
"DiTauMassTools",
"%s", (
" MET=" + std::to_string(
preparedInput.m_MetVec.R()) +
998 Info(
"DiTauMassTools",
" ---------------------------------------------------------- ");
1040 double METresX_binSize = 2 * N_METsigma * METresX / NiterMET;
1041 double METresY_binSize = 2 * N_METsigma * METresY / NiterMET;
1045 std::vector<PtEtaPhiMVector> nu_vec;
1050 double metprob = 1.0;
1051 double sign_tmp = 0.0;
1052 double tauprob = 1.0;
1053 double totalProb = 0.0;
1057 double met_smear_x = 0.0;
1058 double met_smear_y = 0.0;
1059 double met_smearL = 0.0;
1060 double met_smearP = 0.0;
1062 double angle1 = 0.0;
1086 const double met_coscovphi = cos(
preparedInput.m_METcovphi);
1087 const double met_sincovphi = sin(
preparedInput.m_METcovphi);
1102 Info(
"DiTauMassTools",
"Running in dilepton mode");
1107 PtEtaPhiMVector tau_tmp(0.0, 0.0, 0.0, 0.0);
1108 PtEtaPhiMVector lep_tmp(0.0, 0.0, 0.0, 0.0);
1148 double Mlep = tau_tmp.M();
1155 double MnuProb = 1.0;
1157 for (
int i3 = 0; i3 < NiterMnu; i3++)
1159 M_nu = Mnu_binSize * i3;
1160 if (M_nu >= (Mtau - Mlep))
1166 for (
int i4 = 0; i4 < NiterMET + 1; i4++)
1168 met_smearL = METresX_binSize * i4 - N_METsigma * METresX;
1169 for (
int i5 = 0; i5 < NiterMET + 1; i5++)
1171 met_smearP = METresY_binSize * i5 - N_METsigma * METresY;
1172 if (pow(met_smearL / METresX, 2) + pow(met_smearP / METresY, 2) > pow(N_METsigma, 2))
1174 met_smear_x = met_smearL * met_coscovphi - met_smearP * met_sincovphi;
1175 met_smear_y = met_smearL * met_sincovphi + met_smearP * met_coscovphi;
1176 metvec_tmp.SetXY(input_metX + met_smear_x, input_metY + met_smear_y);
1191 metprob =
Prob->MetProbability(
preparedInput, met_smearL, met_smearP, METresX, METresY);
1194 for (
unsigned int j1 = 0; j1 < nu_vec.size(); j1++) {
1195 if (tau_tmp.E() + nu_vec[j1].E() >=
preparedInput.m_beamEnergy)
1197 const double tau1_tmpp = (tau_tmp + nu_vec[j1]).
P();
1198 angle1 =
Angle(nu_vec[j1], tau_tmp);
1208 double tauvecprob1j =
1210 if (tauvecprob1j == 0.)
1212 tauprob =
Prob->TauProbabilityLFV(
preparedInput, tau_type_tmp, tau_tmp, nu_vec[j1]);
1213 totalProb = tauvecprob1j * metprob * MnuProb * tauprob;
1230 m_fPXfit1->Fill((tau_tmp + nu_vec[j1]).Px(), totalProb);
1231 m_fPYfit1->Fill((tau_tmp + nu_vec[j1]).Py(), totalProb);
1232 m_fPZfit1->Fill((tau_tmp + nu_vec[j1]).Pz(), totalProb);
1236 sign_tmp = -log10(totalProb);
1260 Info(
"DiTauMassTools",
"Running in lepton+tau mode");
1286 PtEtaPhiMVector tau_tmp(0.0, 0.0, 0.0, 0.0);
1287 PtEtaPhiMVector lep_tmp(0.0, 0.0, 0.0, 0.0);
1301 for (
int i4 = 0; i4 < NiterMET + 1; i4++)
1303 met_smearL = METresX_binSize * i4 - N_METsigma * METresX;
1304 for (
int i5 = 0; i5 < NiterMET + 1; i5++)
1306 met_smearP = METresY_binSize * i5 - N_METsigma * METresY;
1307 if (pow(met_smearL / METresX, 2) + pow(met_smearP / METresY, 2) > pow(N_METsigma, 2))
1311 metvec_tmp.SetXY(input_metX + met_smear_x, input_metY + met_smear_y);
1326 metprob =
Prob->MetProbability(
preparedInput, met_smearL, met_smearP, METresX, METresY);
1329 for (
unsigned int j1 = 0; j1 < nu_vec.size(); j1++) {
1330 if (tau_tmp.E() + nu_vec[j1].E() >=
preparedInput.m_beamEnergy)
1332 const double tau1_tmpp = (tau_tmp + nu_vec[j1]).
P();
1333 angle1 =
Angle(nu_vec[j1], tau_tmp);
1343 double tauvecprob1j =
1345 if (tauvecprob1j == 0.)
1347 tauprob =
Prob->TauProbabilityLFV(
preparedInput, tau_type_tmp, tau_tmp, nu_vec[j1]);
1348 totalProb = tauvecprob1j * metprob * tauprob;
1371 sign_tmp = -log10(totalProb);
1397 Info(
"DiTauMassTools",
"Running in an unknown mode?!?!");
1404 Info(
"DiTauMassTools",
"%s",
1405 (
"SpeedUp niters=" + std::to_string(iter0) +
" " + std::to_string(
m_iter1) +
" " +
1426 if (prob_hist != 0.0)
1444 PxPyPzMVector nu1_tmp(0.0, 0.0, 0.0, 0.0);
1445 PxPyPzMVector nu2_tmp(0.0, 0.0, 0.0, 0.0);
1465 if (fit_code == 0) {
1467 "DiTauMassTools",
"%s",
1468 (
"!!!----> Warning-3 in MissingMassCalculator::DitauMassCalculatorV9lfv() : fit status=" +
1469 std::to_string(fit_code))
1471 Info(
"DiTauMassTools",
"....... No solution is found. Printing input info .......");
1473 Info(
"DiTauMassTools",
"%s", (
" vis Tau-1: Pt="+std::to_string(
preparedInput.m_vistau1.Pt())
1476 +
" type="+std::to_string(
preparedInput.m_type_visTau1)).c_str());
1477 Info(
"DiTauMassTools",
"%s", (
" vis Tau-2: Pt="+std::to_string(
preparedInput.m_vistau2.Pt())
1480 +
" type="+std::to_string(
preparedInput.m_type_visTau2)).c_str());
1481 Info(
"DiTauMassTools",
"%s", (
" MET="+std::to_string(
preparedInput.m_MetVec.R())+
" Met_X="+std::to_string(
preparedInput.m_MetVec.X())
1482 +
" Met_Y="+std::to_string(
preparedInput.m_MetVec.Y())).c_str());
1483 Info(
"DiTauMassTools",
" ---------------------------------------------------------- ");
1494 const double mM =
x[0];
1495 const double mMax = par[0];
1496 const double mMean = par[1];
1497 const double mInvWidth2 = par[2];
1499 const double fitval = mMax * (1 - 4 * mInvWidth2 * std::pow(mM - mMean, 2));
1512 const int winHalfWidth,
bool debug) {
1520 for (std::vector<double>::iterator itr = histInfo.begin(); itr != histInfo.end(); ++itr) {
1529 winHalfWidth == 0)) {
1533 int max_bin = theHist->GetMaximumBin();
1534 maxPos = theHist->GetBinCenter(max_bin);
1537 prob = theHist->GetBinContent(max_bin) / double(theHist->GetEntries());
1544 int hNbins = theHist->GetNbinsX();
1549 int max_bin = theHist->GetMaximumBin();
1550 int iBinMin = max_bin - winHalfWidth;
1553 int iBinMax = max_bin + winHalfWidth;
1554 if (iBinMax > hNbins)
1555 iBinMax = hNbins - 1;
1558 for (
int iBin = iBinMin; iBin <= iBinMax; ++iBin) {
1559 const double weight = theHist->GetBinContent(iBin);
1561 sumx += weight * theHist->GetBinCenter(iBin);
1563 maxPos = sumx / sumw;
1566 prob = sumw / theHist->GetEntries();
1576 Error(
"DiTauMassTools",
"%s",
1577 (
"ERROR undefined maxHistStrategy:" + std::to_string(maxHistStrategy)).c_str());
1583 int lastNonZeroBin = -1;
1584 int firstNonZeroBin = -1;
1585 double totalSumw = 0.;
1586 bool firstNullPart =
true;
1587 for (
int iBin = 0; iBin < hNbins; ++iBin) {
1588 const double weight = theHist->GetBinContent(iBin);
1590 totalSumw += weight;
1591 lastNonZeroBin = iBin;
1592 if (firstNullPart) {
1593 firstNullPart =
false;
1594 firstNonZeroBin = iBin;
1601 firstNonZeroBin = std::max(0, firstNonZeroBin - winHalfWidth - 1);
1602 lastNonZeroBin = std::min(hNbins - 1, lastNonZeroBin + winHalfWidth + 1);
1611 const int nwidth = 2 * winHalfWidth + 1;
1614 for (
int ibin = 0; ibin < nwidth; ++ibin) {
1615 winsum += theHist->GetBinContent(ibin);
1617 double winmax = winsum;
1620 int iBinL = firstNonZeroBin;
1621 int iBinR = iBinL + 2 * winHalfWidth;
1622 bool goingUp =
true;
1627 const double deltawin = theHist->GetBinContent(iBinR) - theHist->GetBinContent(iBinL - 1);
1633 if (winsum > winmax) {
1636 max_bin = (iBinR + iBinL) / 2 - 1;
1647 }
while (iBinR < lastNonZeroBin);
1650 int iBinMin = max_bin - winHalfWidth;
1653 int iBinMax = max_bin + winHalfWidth;
1654 if (iBinMax >= hNbins)
1655 iBinMax = hNbins - 1;
1658 for (
int iBin = iBinMin; iBin <= iBinMax; ++iBin) {
1659 const double weight = theHist->GetBinContent(iBin);
1661 sumx += weight * theHist->GetBinCenter(iBin);
1664 double maxPosWin = -1.;
1667 maxPosWin = sumx / sumw;
1670 prob = sumw / totalSumw;
1674 const double h_rms = theHist->GetRMS(1);
1678 double numerator = 0;
1679 double denominator = 0;
1680 bool nullBin =
false;
1682 for (
int i = iBinMin; i < iBinMax; ++i) {
1683 double binError = theHist->GetBinError(i);
1684 if (binError < 1e-10) {
1687 double binErrorSquare = std::pow(binError, 2);
1688 num = theHist->GetBinContent(i) / (binErrorSquare);
1689 numerator = numerator + num;
1690 denominator = denominator + (1 / (binErrorSquare));
1692 if (numerator < 1e-10 || denominator < 1e-10 || nullBin ==
true) {
1695 histInfo[
HistInfo::MEANBIN] = sqrt(1 / denominator) / (numerator / denominator);
1708 const double binWidth = theHist->GetBinCenter(2) - theHist->GetBinCenter(1);
1709 double fitWidth = (winHalfWidth + 0.5) *
binWidth;
1722 TString fitOption =
debug ?
"QS" :
"QNS";
1725 m_fFitting->SetParameters(sumw / winHalfWidth, maxPos, 0.0025);
1728 TFitResultPtr fitRes =
1729 theHist->Fit(
m_fFitting, fitOption,
"", maxPos - fitWidth, maxPos + fitWidth);
1731 double maxPosFit = -1.;
1733 if (
int(fitRes) == 0) {
1736 const double mMax = fitRes->Parameter(0);
1737 const double mMean = fitRes->Parameter(1);
1738 const double mInvWidth2 = fitRes->Parameter(2);
1739 double mMaxError = fitRes->ParError(0);
1741 double mMeanError = fitRes->ParError(1);
1743 double mInvWidth2Error = fitRes->ParError(2);
1746 mInvWidth2Error = 0.;
1747 const double c = mMax * (1 - 4 * mMean * mMean * mInvWidth2);
1748 const double b = 8 * mMax * mMean * mInvWidth2;
1749 const double a = -4 * mMax * mInvWidth2;
1755 const double h_discri = b * b - 4 *
a * c;
1757 const double sqrth_discri = sqrt(h_discri);
1758 const double h_fitLength = sqrth_discri /
a;
1765 maxPosFit = -b / (2 *
a);
1769 if (maxPosFit >= 0. and std::abs(maxPosFit - maxPosWin) < 0.8 * fitWidth) {
1787 const double &M_nu1,
1788 const double &M_nu2) {
1794 const int solution =
NuPsolutionV3(M_nu1, M_nu2, phi1, phi2, nsol1, nsol2);
1813 const int nsol1,
const int nsol2,
1814 const double &Mvis,
const double &Meff)
1820 Error(
"DiTauMassTools",
"%s",
1821 (
"refineSolutions ERROR probFinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1824 Error(
"DiTauMassTools",
"%s",
1825 (
"refineSolutions ERROR mtautauSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1828 Error(
"DiTauMassTools",
"%s",
1829 (
"refineSolutions ERROR nu1FinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1832 Error(
"DiTauMassTools",
"%s",
1833 (
"refineSolutions ERROR nu2FinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1836 Error(
"DiTauMassTools",
"%s", (
"refineSolutions ERROR nsol1 " + std::to_string(nsol1) +
1837 " > nsolmax !" + std::to_string(
m_nsolmax))
1840 Error(
"DiTauMassTools",
"%s", (
"refineSolutions ERROR nsol1 " + std::to_string(nsol2) +
1841 " > nsolmax !" + std::to_string(
m_nsolmax))
1847 Prob->apply(
preparedInput, -99, -99, PtEtaPhiMVector(0, 0, 0, 0), PtEtaPhiMVector(0, 0, 0, 0),
1848 PtEtaPhiMVector(0, 0, 0, 0), PtEtaPhiMVector(0, 0, 0, 0),
true,
false,
false);
1850 for (
int j1 = 0; j1 < nsol1; ++j1) {
1860 const int pickInt = std::abs(10000 *
m_Phi1);
1861 const int pickDigit = pickInt - 10 * (pickInt / 10);
1869 nuvec1_tmpj.SetCoordinates(nuvec1_tmpj.Pt(), nuvec1_tmpj.Eta(), nuvec1_tmpj.Phi(), M_nu1);
1870 tauvecsol1j.SetPxPyPzE(0., 0., 0., 0.);
1871 tauvecsol1j += nuvec1_tmpj;
1876 PtEtaPhiMVector(0, 0, 0, 0), nuvec1_tmpj,
1877 PtEtaPhiMVector(0, 0, 0, 0),
false,
true,
false);
1881 for (
int j2 = 0; j2 < nsol2; ++j2) {
1892 const int pickInt = std::abs(10000 *
m_Phi2);
1893 const int pickDigit = pickInt - 10 * int(pickInt / 10);
1901 nuvec2_tmpj.SetCoordinates(nuvec2_tmpj.Pt(), nuvec2_tmpj.Eta(), nuvec2_tmpj.Phi(), M_nu2);
1902 tauvecsol2j.SetPxPyPzE(0., 0., 0., 0.);
1903 tauvecsol2j += nuvec2_tmpj;
1909 PtEtaPhiMVector(0, 0, 0, 0), nuvec2_tmpj,
false,
true,
false);
1913 if (tauvecprob1j == 0.)
1915 if (tauvecprob2j == 0.)
1918 double totalProb = 1.;
1931 (constProb * tauvecprob1j * tauvecprob2j *
1935 if (totalProb <= 0) {
1937 Warning(
"DiTauMassTools",
"%s",
1938 (
"null proba solution, rejected "+std::to_string(totalProb)).c_str());
1945 Error(
"DiTauMassTools",
"%s",
1946 (
"refineSolutions ERROR nsol getting larger than nsolfinalmax!!! " +
1949 Error(
"DiTauMassTools",
"%s",
1950 (
" j1 " + std::to_string(j1) +
" j2 " + std::to_string(j2) +
" nsol1 " +
1951 std::to_string(nsol1) +
" nsol2 " + std::to_string(nsol2))
1965 nu1Final.SetPxPyPzE(nuvec1_tmpj.Px(), nuvec1_tmpj.Py(), nuvec1_tmpj.Pz(), nuvec1_tmpj.E());
1966 nu2Final.SetPxPyPzE(nuvec2_tmpj.Px(), nuvec2_tmpj.Py(), nuvec2_tmpj.Pz(), nuvec2_tmpj.E());
1974 if (ngoodsol1 == 0) {
1977 if (ngoodsol2 == 0) {
1984 const PtEtaPhiMVector &nu1,
1985 const PtEtaPhiMVector &vis2,
1986 const PtEtaPhiMVector &nu2,
const double &mmc_mass,
1987 const double &vis_mass,
const double &eff_mass,
1988 const double &dphiTT) {
1999 const double MrecoMvis = mmc_mass / vis_mass;
2000 if (MrecoMvis > 2.6)
2002 const double MrecoMeff = mmc_mass / eff_mass;
2003 if (MrecoMeff > 1.9)
2005 const double e1p1 = nu1.E() / vis1.P();
2006 const double e2p2 = nu2.E() / vis2.P();
2007 if ((e1p1 + e2p2) > 4.5)
2026 if (
Prob->GetUseHT()) {
2027 const double MrecoMvis = mmc_mass / vis_mass;
2028 const double MrecoMeff = mmc_mass / eff_mass;
2029 const double x = dphiTT > 1.5 ? dphiTT : 1.5;
2030 if ((MrecoMeff + MrecoMvis) > 5.908 - 1.881 *
x + 0.2995 *
x *
x)
2043 double totalProbSumSol = 0.;
2044 double totalProbSumSolOld = 0.;
2045 bool firstPointWithSol =
false;
2047 for (
int isol = 0; isol <
m_nsol; ++isol) {
2052 bool notSureToKeep =
true;
2056 notSureToKeep =
false;
2063 firstPointWithSol =
true;
2075 if (notSureToKeep) {
2078 for (
int isol = 0; isol <
m_nsolOld; ++isol) {
2084 if (!firstPointWithSol && totalProbSumSolOld <= 0.) {
2085 Error(
"DiTauMassTools",
"%s",
2086 (
" ERROR null old probability !!! " + std::to_string(totalProbSumSolOld) +
" nsolOld " +
2090 }
else if (totalProbSumSol > totalProbSumSolOld) {
2095 }
else if (totalProbSumSol < totalProbSumSolOld * 1E-6) {
2099 }
else if (
m_nsol <= 0) {
2106 reject = (uMC > totalProbSumSol / totalProbSumSolOld);
2131 bool fillSolution =
true;
2132 bool oldToBeUsed =
false;
2140 fillSolution =
false;
2154 if (!firstPointWithSol) {
2155 fillSolution =
true;
2158 fillSolution =
false;
2165 if (!fillSolution) {
2166 if (firstPointWithSol) {
2169 for (
int isol = 0; isol <
m_nsol; ++isol) {
2181 double solSum2 = 0.;
2183 for (
int isol = 0; isol <
m_nsol; ++isol) {
2187 const PtEtaPhiMVector *pnuvec1_tmpj;
2188 const PtEtaPhiMVector *pnuvec2_tmpj;
2201 const PtEtaPhiMVector &nuvec1_tmpj = *pnuvec1_tmpj;
2202 const PtEtaPhiMVector &nuvec2_tmpj = *pnuvec2_tmpj;
2205 solSum2 += mtautau * mtautau;
2227 if (mtautau != 0. && weight != 0.)
2292 for (
int isol = 0; isol <
m_nsol; ++isol) {
2301 const double solRMS = sqrt(solSum2 /
m_nsol - std::pow(solSum /
m_nsol, 2));
2494 Info(
"DiTauMassTools",
" in m_meanbinToBeEvaluated && m_iterNsuc==500 ");
2509 double stopdouble = 500 * std::pow((meanbin /
m_meanbinStop), 2);
2510 int stopint = stopdouble;
2641 PtEtaPhiMVector Met4vec;
2714 const double &P_tau) {
2716#ifndef WITHDTHETA3DLIM
2718 if (limit_code == 0)
2720 if (limit_code == 1)
2722 if (limit_code == 2)
2727 if (limit_code == 0)
2729 double par[3] = {0.0, 0.0, 0.0};
2731 if (tau_type == 8) {
2732 if (limit_code == 0)
2738 if (limit_code == 1)
2744 if (limit_code == 2)
2752 if (tau_type >= 0 && tau_type <= 2) {
2753 if (limit_code == 0)
2757 par[2] = -0.0004859;
2759 if (limit_code == 1)
2765 if (limit_code == 2)
2773 if (tau_type >= 3 && tau_type <= 5) {
2774 if (limit_code == 0)
2778 par[2] = -0.0009458;
2780 if (limit_code == 1)
2786 if (limit_code == 2)
2794 if (std::abs(P_tau + par[1]) > 0.0)
2795 limit = par[0] / (P_tau + par[1]) + par[2];
2796 if (limit_code == 0) {
2799 }
else if (limit > 0.03) {
2803 if (limit < 0.0 || limit > 0.5 * TMath::Pi()) {
2804 limit = 0.5 * TMath::Pi();
2805 }
else if (limit < 0.05 && limit > 0.0) {
2834 if (LFVMode == -1) {
2836 }
else if (LFVMode != -2) {
2848 PtEtaPhiMVector fixedtau1;
2849 fixedtau1.SetCoordinates(tlvTau1.Pt() /
GEV, tlvTau1.Eta(), tlvTau1.Phi(), tlvTau1.M() /
GEV);
2850 PtEtaPhiMVector fixedtau2;
2851 fixedtau2.SetCoordinates(tlvTau2.Pt() /
GEV, tlvTau2.Eta(), tlvTau2.Phi(), tlvTau2.M() /
GEV);
2858 if (mmcType1 == 8 && mmcType2 == 8) {
2860 }
else if (mmcType1 >= 0 && mmcType1 <= 5 && mmcType2 >= 0 && mmcType2 <= 5) {
2866 Info(
"DiTauMassTools",
"%s", (
"running for tau types "+std::to_string(
preparedInput.m_type_visTau1)+
" "+std::to_string(
preparedInput.m_type_visTau2)).c_str());
2870 Info(
"DiTauMassTools",
"%s", (
"passing SumEt="+std::to_string(
met->sumet() /
GEV)).c_str());
2876 Error(
"DiTauMassTools",
"MMCCalibrationSet has not been set !. Please use "
2877 "fMMC.SetCalibrationSet(MMCCalibrationSet::MMC2019) or fMMC.SetCalibrationSet(MMCCalibrationSet::MMC2024)"
2912 for (
unsigned int i = 0; i <
preparedInput.m_jet4vecs.size(); i++) {
2919 Info(
"DiTauMassTools",
"correcting sumET");
3016 Info(
"DiTauMassTools",
"Substracting pt1 from sumEt");
3023 Info(
"DiTauMassTools",
"Substracting pt2 from sumEt");
3035 Prob->SetUseTauProbability(
true);
3038 Prob->SetUseTauProbability(
false);
3055 Prob->SetUseTauProbability(
false);
3057 Prob->SetUseTauProbability(
true);
3058 Prob->SetUseMnuProbability(
false);
3063 if (
Prob->GetUseHT())
3066 double HtOffset = 0.;
3071 HtOffset = 87.5 - 27.0 *
x;
3090 float hEmax = 3000.0;
3092 m_fMEtP_all = std::make_shared<TH1F>(
"MEtP_h1",
"M", hNbins, -100.0,
3094 m_fMEtL_all = std::make_shared<TH1F>(
"MEtL_h1",
"M", hNbins, -100.0,
3096 m_fMnu1_all = std::make_shared<TH1F>(
"Mnu1_h1",
"M", hNbins, 0.0,
3098 m_fMnu2_all = std::make_shared<TH1F>(
"Mnu2_h1",
"M", hNbins, 0.0,
3100 m_fPhi1_all = std::make_shared<TH1F>(
"Phi1_h1",
"M", hNbins, -10.0,
3102 m_fPhi2_all = std::make_shared<TH1F>(
"Phi2_h1",
"M", hNbins, -10.0,
3125 float hEmax = 3000.0;
3127 m_fMmass_split1 = std::make_shared<TH1F>(
"mass_h1_1",
"M", hNbins, 0.0, hEmax);
3128 m_fMEtP_split1 = std::make_shared<TH1F>(
"MEtP_h1_1",
"M", hNbins, -100.0, 100.0);
3129 m_fMEtL_split1 = std::make_shared<TH1F>(
"MEtL_h1_1",
"M", hNbins, -100.0, 100.0);
3130 m_fMnu1_split1 = std::make_shared<TH1F>(
"Mnu1_h1_1",
"M", hNbins, 0.0, hEmax);
3131 m_fMnu2_split1 = std::make_shared<TH1F>(
"Mnu2_h1_1",
"M", hNbins, 0.0, hEmax);
3132 m_fPhi1_split1 = std::make_shared<TH1F>(
"Phi1_h1_1",
"M", hNbins, -10.0, 10.0);
3133 m_fPhi2_split1 = std::make_shared<TH1F>(
"Phi2_h1_1",
"M", hNbins, -10.0, 10.0);
3134 m_fMmass_split2 = std::make_shared<TH1F>(
"mass_h1_2",
"M", hNbins, 0.0, hEmax);
3135 m_fMEtP_split2 = std::make_shared<TH1F>(
"MEtP_h1_2",
"M", hNbins, -100.0, 100.0);
3136 m_fMEtL_split2 = std::make_shared<TH1F>(
"MEtL_h1_2",
"M", hNbins, -100.0, 100.0);
3137 m_fMnu1_split2 = std::make_shared<TH1F>(
"Mnu1_h1_2",
"M", hNbins, 0.0, hEmax);
3138 m_fMnu2_split2 = std::make_shared<TH1F>(
"Mnu2_h1_2",
"M", hNbins, 0.0, hEmax);
3139 m_fPhi1_split2 = std::make_shared<TH1F>(
"Phi1_h1_2",
"M", hNbins, -10.0, 10.0);
3140 m_fPhi2_split2 = std::make_shared<TH1F>(
"Phi2_h1_2",
"M", hNbins, -10.0, 10.0);
__HOSTDEV__ double Phi_mpi_pi(double)
A number of constexpr particle constants to avoid hardcoding them directly in various places.
Class providing the definition of the 4-vector interface.
constexpr double tauMassInMeV
the mass of the tau (in MeV)
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
MissingET_v1 MissingET
Version control by type defintion.