26#include <TFitResult.h>
27#include <TFitResultPtr.h>
28#include <TMatrixDSym.h>
32#include "Math/VectorUtil.h"
37 constexpr double GEV = 1000.0;
42using ROOT::Math::PtEtaPhiMVector;
43using ROOT::Math::PxPyPzMVector;
44using ROOT::Math::XYVector;
45using ROOT::Math::VectorUtil::DeltaR;
46using ROOT::Math::VectorUtil::Phi_mpi_pi;
82 Prob->SetUseTauProbability(
true);
83 Prob->SetUseMnuProbability(
false);
84 Prob->SetUseDphiLL(
false);
129 float hEmax = 3000.0;
139 m_fMfit_all = std::make_shared<TH1F>(
"MMC_h1",
"M", hNbins, 0.0,
146 std::make_shared<TH1F>(
"MMC_h1NoW",
"M no weight", hNbins, 0.0, hEmax);
148 m_fPXfit1 = std::make_shared<TH1F>(
"MMC_h2",
"Px1", 4 * hNbins, -hEmax,
150 m_fPYfit1 = std::make_shared<TH1F>(
"MMC_h3",
"Py1", 4 * hNbins, -hEmax,
152 m_fPZfit1 = std::make_shared<TH1F>(
"MMC_h4",
"Pz1", 4 * hNbins, -hEmax,
154 m_fPXfit2 = std::make_shared<TH1F>(
"MMC_h5",
"Px2", 4 * hNbins, -hEmax,
156 m_fPYfit2 = std::make_shared<TH1F>(
"MMC_h6",
"Py2", 4 * hNbins, -hEmax,
158 m_fPZfit2 = std::make_shared<TH1F>(
"MMC_h7",
"Pz2", 4 * hNbins, -hEmax,
175 m_fFitting->SetParNames(
"Max",
"Mean",
"InvWidth2");
199 Info(
"DiTauMassTools",
"------------- Raw Input for MissingMassCalculator --------------");
204 Info(
"DiTauMassTools",
"------------- Prepared Input for MissingMassCalculator--------------");
223 double dummy_METres =
226 dummy_METres * std::abs(cos(dummy_met.Phi() -
preparedInput.m_MetVec.Phi()));
228 dummy_METres * std::abs(sin(dummy_met.Phi() -
preparedInput.m_MetVec.Phi()));
244 Info(
"DiTauMassTools",
"Calling DitauMassCalculatorV9lfv");
250 TFile *outFile = TFile::Open(
"MMC_likelihoods.root",
"UPDATE");
253 if (!outFile->GetDirectory(path.c_str()))
254 outFile->mkdir(path.c_str());
255 outFile->cd(path.c_str());
265 TH1D *nosol =
new TH1D(
"nosol",
"nosol", 7, 0, 7);
273 nosol->Write(nosol->GetName(), TObject::kOverwrite);
288 fStuff.
nutau1 = PtEtaPhiMVector(0., 0., 0., 0.);
289 fStuff.
nutau2 = PtEtaPhiMVector(0., 0., 0., 0.);
290 fStuff.
vistau1 = PtEtaPhiMVector(0., 0., 0., 0.);
291 fStuff.
vistau2 = PtEtaPhiMVector(0., 0., 0., 0.);
303 Info(
"DiTauMassTools",
"Retrieving output from fDitauStuffFit");
308 double q1 = (1. - 0.68) / 2.;
335 PtEtaPhiMVector tlvdummy(0., 0., 0., 0.);
336 XYVector metdummy(0., 0.);
377 PtEtaPhiMVector dummy_vec1(0.0, 0.0, 0.0, 0.0);
378 PtEtaPhiMVector dummy_vec2(0.0, 0.0, 0.0, 0.0);
379 for (
int i = 0; i < 3; i++) {
401 Info(
"DiTauMassTools",
402 ".........................Other input.....................................");
403 Info(
"DiTauMassTools",
"%s",
404 (
"Beam energy =" + std::to_string(
preparedInput.m_beamEnergy) +
405 " sqrt(S) for collisions =" + std::to_string(2.0 *
preparedInput.m_beamEnergy))
407 Info(
"DiTauMassTools",
"%s",
410 Info(
"DiTauMassTools",
"%s",
411 (
"LFV mode " + std::to_string(
preparedInput.m_LFVmode) +
" seed=" + std::to_string(
m_seed))
413 Info(
"DiTauMassTools",
"%s", (
"usetauProbability=" + std::to_string(
Prob->GetUseTauProbability()) +
414 " useTailCleanup=" + std::to_string(
preparedInput.m_fUseTailCleanup))
418 Info(
"DiTauMassTools",
419 "tau1 and tau2 were internally swapped (visible on prepared input printout)");
421 Info(
"DiTauMassTools",
"tau1 and tau2 were NOT internally swapped");
424 Info(
"DiTauMassTools",
"%s",
425 (
" MEtLMin=" + std::to_string(
m_MEtLMin) +
" MEtLMax=" + std::to_string(
m_MEtLMax)).c_str());
426 Info(
"DiTauMassTools",
"%s",
427 (
" MEtPMin=" + std::to_string(
m_MEtPMin) +
" MEtPMax=" + std::to_string(
m_MEtPMax)).c_str());
428 Info(
"DiTauMassTools",
"%s",
429 (
" Phi1Min=" + std::to_string(
m_Phi1Min) +
" Phi1Max=" + std::to_string(
m_Phi1Max)).c_str());
430 Info(
"DiTauMassTools",
"%s",
431 (
" Phi2Min=" + std::to_string(
m_Phi2Min) +
" Phi2Max=" + std::to_string(
m_Phi2Max)).c_str());
432 Info(
"DiTauMassTools",
"%s",
433 (
" Mnu1Min=" + std::to_string(
m_Mnu1Min) +
" Mnu1Max=" + std::to_string(
m_Mnu1Max)).c_str());
434 Info(
"DiTauMassTools",
"%s",
435 (
" Mnu2Min=" + std::to_string(
m_Mnu2Min) +
" Mnu2Max=" + std::to_string(
m_Mnu2Max)).c_str());
444 const PtEtaPhiMVector *origVisTau1 = 0;
445 const PtEtaPhiMVector *origVisTau2 = 0;
458 Info(
"DiTauMassTools",
459 "------------- Printing Final Results for MissingMassCalculator --------------");
460 Info(
"DiTauMassTools",
461 ".............................................................................");
462 Info(
"DiTauMassTools",
"%s", (
"Fit status=" + std::to_string(
OutputInfo.m_FitStatus)).c_str());
465 Info(
"DiTauMassTools",
"%s",
468 Info(
"DiTauMassTools",
"%s",
469 (
" signif=" + std::to_string(
OutputInfo.m_FitSignificance[imeth])).c_str());
470 Info(
"DiTauMassTools",
"%s", (
" mass=" + std::to_string(
OutputInfo.m_FittedMass[imeth])).c_str());
471 Info(
"DiTauMassTools",
"%s", (
" rms/mpv=" + std::to_string(
OutputInfo.m_RMS2MPV)).c_str());
474 Info(
"DiTauMassTools",
" no 4-momentum or MET from this method ");
479 Info(
"DiTauMassTools",
" fit failed ");
482 const PtEtaPhiMVector &tlvnu1 =
OutputInfo.m_nuvec1[imeth];
483 const PtEtaPhiMVector &tlvnu2 =
OutputInfo.m_nuvec2[imeth];
484 const PtEtaPhiMVector &tlvo1 =
OutputInfo.m_objvec1[imeth];
485 const PtEtaPhiMVector &tlvo2 =
OutputInfo.m_objvec2[imeth];
486 const XYVector &tvmet =
OutputInfo.m_FittedMetVec[imeth];
488 Info(
"DiTauMassTools",
"%s",
489 (
" Neutrino-1: P=" + std::to_string(tlvnu1.P()) +
" Pt=" + std::to_string(tlvnu1.Pt()) +
490 " Eta=" + std::to_string(tlvnu1.Eta()) +
" Phi=" + std::to_string(tlvnu1.Phi()) +
491 " M=" + std::to_string(tlvnu1.M()) +
" Px=" + std::to_string(tlvnu1.Px()) +
492 " Py=" + std::to_string(tlvnu1.Py()) +
" Pz=" + std::to_string(tlvnu1.Pz()))
494 Info(
"DiTauMassTools",
"%s",
495 (
" Neutrino-2: P=" + std::to_string(tlvnu2.P()) +
" Pt=" + std::to_string(tlvnu2.Pt()) +
496 " Eta=" + std::to_string(tlvnu2.Eta()) +
" Phi=" + std::to_string(tlvnu2.Phi()) +
497 " M=" + std::to_string(tlvnu2.M()) +
" Px=" + std::to_string(tlvnu2.Px()) +
498 " Py=" + std::to_string(tlvnu2.Py()) +
" Pz=" + std::to_string(tlvnu2.Pz()))
500 Info(
"DiTauMassTools",
"%s",
501 (
" Tau-1: P=" + std::to_string(tlvo1.P()) +
" Pt=" + std::to_string(tlvo1.Pt()) +
502 " Eta=" + std::to_string(tlvo1.Eta()) +
" Phi=" + std::to_string(tlvo1.Phi()) +
503 " M=" + std::to_string(tlvo1.M()) +
" Px=" + std::to_string(tlvo1.Px()) +
504 " Py=" + std::to_string(tlvo1.Py()) +
" Pz=" + std::to_string(tlvo1.Pz()))
506 Info(
"DiTauMassTools",
"%s",
507 (
" Tau-2: P=" + std::to_string(tlvo2.P()) +
" Pt=" + std::to_string(tlvo2.Pt()) +
508 " Eta=" + std::to_string(tlvo2.Eta()) +
" Phi=" + std::to_string(tlvo2.Phi()) +
509 " M=" + std::to_string(tlvo2.M()) +
" Px=" + std::to_string(tlvo2.Px()) +
510 " Py=" + std::to_string(tlvo2.Py()) +
" Pz=" + std::to_string(tlvo2.Pz()))
513 Info(
"DiTauMassTools",
"%s",
514 (
" dR(nu1-visTau1)=" + std::to_string(DeltaR(tlvnu1,*origVisTau1))).c_str());
515 Info(
"DiTauMassTools",
"%s",
516 (
" dR(nu2-visTau2)=" + std::to_string(DeltaR(tlvnu2,*origVisTau2))).c_str());
518 Info(
"DiTauMassTools",
"%s",
519 (
" Fitted MET =" + std::to_string(tvmet.R()) +
" Phi=" + std::to_string(tlvnu1.Phi()) +
520 " Px=" + std::to_string(tvmet.X()) +
" Py=" + std::to_string(tvmet.Y()))
523 Info(
"DiTauMassTools",
"%s", (
" Resonance: P=" + std::to_string(
OutputInfo.m_totalvec[imeth].P()) +
524 " Pt=" + std::to_string(
OutputInfo.m_totalvec[imeth].Pt()) +
525 " Eta=" + std::to_string(
OutputInfo.m_totalvec[imeth].Eta()) +
526 " Phi=" + std::to_string(
OutputInfo.m_totalvec[imeth].Phi()) +
527 " M=" + std::to_string(
OutputInfo.m_totalvec[imeth].M()) +
528 " Px=" + std::to_string(
OutputInfo.m_totalvec[imeth].Px()) +
529 " Py=" + std::to_string(
OutputInfo.m_totalvec[imeth].Py()) +
530 " Pz=" + std::to_string(
OutputInfo.m_totalvec[imeth].Pz()))
545 const double &phi1,
const double &phi2,
546 int &nsol1,
int &nsol2) {
567 int solution_code = 0;
585 if (pTmiss2 * dPhiSign < 0) {
587 return solution_code;
593 if (pTmiss1 * (-dPhiSign) < 0) {
595 return solution_code;
604 double m4noma1 = m2noma1 * m2noma1;
606 double p2v1proj = std::pow(pv1proj, 2);
608 double pTmiss2CscDPhi = pTmiss2 / sinDPhi2;
609 double &pTn1 = pTmiss2CscDPhi;
610 double pT2miss2CscDPhi = pTmiss2CscDPhi * pTmiss2CscDPhi;
613 const double discri1 = m4noma1 + 4 * m2noma1 * pTmiss2CscDPhi * pv1proj -
614 4 * (
m_ET2v1 * (
m_m2Nu1 + pT2miss2CscDPhi) - (pT2miss2CscDPhi * p2v1proj));
619 return solution_code;
627 double m4noma2 = m2noma2 * m2noma2;
629 double p2v2proj = std::pow(pv2proj, 2);
630 double sinDPhi1 = -sinDPhi2;
631 double pTmiss1CscDPhi = pTmiss1 / sinDPhi1;
632 double &pTn2 = pTmiss1CscDPhi;
633 double pT2miss1CscDPhi = pTmiss1CscDPhi * pTmiss1CscDPhi;
635 const double discri2 = m4noma2 + 4 * m2noma2 * pTmiss1CscDPhi * pv2proj -
636 4 * (
m_ET2v2 * (
m_m2Nu2 + pT2miss1CscDPhi) - (pT2miss1CscDPhi * p2v2proj));
641 return solution_code;
647 double sqdiscri1 = sqrt(discri1);
653 double pn1Z = first1 + second1;
655 if (m2noma1 + 2 * pTmiss2CscDPhi * pv1proj + 2 * pn1Z *
m_tauVec1Pz >
659 sqrt(std::pow(pTn1, 2) + std::pow(pn1Z, 2) +
m_m2Nu1));
664 pn1Z = first1 - second1;
666 if (m2noma1 + 2 * pTmiss2CscDPhi * pv1proj + 2 * pn1Z *
m_tauVec1Pz >
671 sqrt(std::pow(pTn1, 2) + std::pow(pn1Z, 2) +
m_m2Nu1));
678 return solution_code;
683 double sqdiscri2 = sqrt(discri2);
689 double pn2Z = first2 + second2;
691 if (m2noma2 + 2 * pTmiss1CscDPhi * pv2proj + 2 * pn2Z *
m_tauVec2Pz >
695 sqrt(std::pow(pTn2, 2) + std::pow(pn2Z, 2) +
m_m2Nu2));
700 pn2Z = first2 - second2;
703 if (m2noma2 + 2 * pTmiss1CscDPhi * pv2proj + 2 * pn2Z *
m_tauVec2Pz >
707 sqrt(std::pow(pTn2, 2) + std::pow(pn2Z, 2) +
m_m2Nu2));
714 return solution_code;
730 if (std::abs(pnux - pTmissx) > 0.001 || std::abs(pnuy - pTmissy) > 0.001) {
731 Info(
"DiTauMassTools",
"%s", (
"NuPsolutionV3 ERROR Pnux-Met.X or Pnuy-Met.Y > 0.001 : " +
732 std::to_string(pnux - pTmissx) +
" and " +
733 std::to_string(pnuy - pTmissx) +
" " +
"Invalid solutions")
736 if (std::abs(mtau1plus -
m_mTau) > 0.001 || std::abs(mtau1moins -
m_mTau) > 0.001 ||
737 std::abs(mtau2plus -
m_mTau) > 0.001 || std::abs(mtau2moins -
m_mTau) > 0.001) {
738 Info(
"DiTauMassTools",
"%s", (
"NuPsolutionV3 ERROR tau mass not recovered : " +
739 std::to_string(mtau1plus) +
" " + std::to_string(mtau1moins) +
" " +
740 std::to_string(mtau2plus) +
" " + std::to_string(mtau2moins))
745 return solution_code;
750 const PtEtaPhiMVector &tau,
const double &l_nu,
751 std::vector<PtEtaPhiMVector> &nu_vec) {
752 int solution_code = 0;
755 PxPyPzMVector nu(met_vec.X(), met_vec.Y(), 0.0, l_nu);
756 PxPyPzMVector nu2(met_vec.X(), met_vec.Y(), 0.0, l_nu);
760 double msq = (Mtau * Mtau - tau.M() * tau.M() - l_nu * l_nu) /
762 double gamma = nu.Px() * nu.Px() + nu.Py() * nu.Py();
763 double beta = tau.Px() * nu.Px() + tau.Py() * nu.Py() + msq;
764 double a = tau.E() * tau.E() - tau.Pz() * tau.Pz();
765 double b = -2 * tau.Pz() * beta;
766 double c = tau.E() * tau.E() * gamma - beta * beta;
767 if ((b * b - 4 *
a * c) < 0)
768 return solution_code;
771 double pvz1 = (-b + sqrt(b * b - 4 *
a * c)) / (2 *
a);
772 double pvz2 = (-b - sqrt(b * b - 4 *
a * c)) / (2 *
a);
774 nu.SetCoordinates(met_vec.X(), met_vec.Y(), pvz1, l_nu);
775 nu2.SetCoordinates(met_vec.X(), met_vec.Y(), pvz2, l_nu);
777 PtEtaPhiMVector return_nu(nu.Pt(), nu.Eta(), nu.Phi(), nu.M());
778 PtEtaPhiMVector return_nu2(nu2.Pt(), nu2.Eta(), nu2.Phi(), nu2.M());
779 nu_vec.push_back(return_nu);
780 nu_vec.push_back(return_nu2);
781 return solution_code;
844 bool paramInsideRange =
false;
863 if (paramInsideRange)
887 if (nsuccesses > 0) {
893 double Px1, Py1, Pz1;
894 double Px2, Py2, Pz2;
895 if (nsuccesses > 0) {
916 if (prob_hist != 0.0)
940 PxPyPzMVector fulltau1, fulltau2;
962 Info(
"DiTauMassTools",
"Scanning ");
963 Info(
"DiTauMassTools",
" Markov ");
964 Info(
"DiTauMassTools",
"%s",
965 (
" V9W niters=" + std::to_string(
m_iter0) +
" " + std::to_string(
m_iter1)).c_str());
966 Info(
"DiTauMassTools",
"%s", (
" nFullScan " + std::to_string(
m_markovNFullScan)).c_str());
967 Info(
"DiTauMassTools",
"%s", (
" nRejectNoSol " + std::to_string(
m_markovNRejectNoSol)).c_str());
969 Info(
"DiTauMassTools",
"%s", (
" nAccept " + std::to_string(
m_markovNAccept)).c_str());
970 Info(
"DiTauMassTools",
"%s",
977 Info(
"DiTauMassTools",
"%s", (
"!!!----> Warning-3 in "
978 "MissingMassCalculator::DitauMassCalculatorV9Walk() : fit status=" +
979 std::to_string(fit_code))
981 Info(
"DiTauMassTools",
"%s",
"....... No solution is found. Printing input info .......");
983 Info(
"DiTauMassTools",
"%s", (
" vis Tau-1: Pt=" + std::to_string(
preparedInput.m_vistau1.Pt()) +
989 Info(
"DiTauMassTools",
"%s", (
" vis Tau-2: Pt=" + std::to_string(
preparedInput.m_vistau2.Pt()) +
995 Info(
"DiTauMassTools",
"%s", (
" MET=" + std::to_string(
preparedInput.m_MetVec.R()) +
999 Info(
"DiTauMassTools",
" ---------------------------------------------------------- ");
1041 double METresX_binSize = 2 * N_METsigma * METresX / NiterMET;
1042 double METresY_binSize = 2 * N_METsigma * METresY / NiterMET;
1046 std::vector<PtEtaPhiMVector> nu_vec;
1051 double metprob = 1.0;
1052 double sign_tmp = 0.0;
1053 double tauprob = 1.0;
1054 double totalProb = 0.0;
1058 double met_smear_x = 0.0;
1059 double met_smear_y = 0.0;
1060 double met_smearL = 0.0;
1061 double met_smearP = 0.0;
1063 double angle1 = 0.0;
1087 const double met_coscovphi = cos(
preparedInput.m_METcovphi);
1088 const double met_sincovphi = sin(
preparedInput.m_METcovphi);
1103 Info(
"DiTauMassTools",
"Running in dilepton mode");
1108 PtEtaPhiMVector tau_tmp(0.0, 0.0, 0.0, 0.0);
1109 PtEtaPhiMVector lep_tmp(0.0, 0.0, 0.0, 0.0);
1149 double Mlep = tau_tmp.M();
1156 double MnuProb = 1.0;
1158 for (
int i3 = 0; i3 < NiterMnu; i3++)
1160 M_nu = Mnu_binSize * i3;
1161 if (M_nu >= (Mtau - Mlep))
1167 for (
int i4 = 0; i4 < NiterMET + 1; i4++)
1169 met_smearL = METresX_binSize * i4 - N_METsigma * METresX;
1170 for (
int i5 = 0; i5 < NiterMET + 1; i5++)
1172 met_smearP = METresY_binSize * i5 - N_METsigma * METresY;
1173 if (pow(met_smearL / METresX, 2) + pow(met_smearP / METresY, 2) > pow(N_METsigma, 2))
1175 met_smear_x = met_smearL * met_coscovphi - met_smearP * met_sincovphi;
1176 met_smear_y = met_smearL * met_sincovphi + met_smearP * met_coscovphi;
1177 metvec_tmp.SetXY(input_metX + met_smear_x, input_metY + met_smear_y);
1192 metprob =
Prob->MetProbability(
preparedInput, met_smearL, met_smearP, METresX, METresY);
1195 for (
unsigned int j1 = 0; j1 < nu_vec.size(); j1++) {
1196 if (tau_tmp.E() + nu_vec[j1].E() >=
preparedInput.m_beamEnergy)
1198 const double tau1_tmpp = (tau_tmp + nu_vec[j1]).
P();
1199 angle1 =
Angle(nu_vec[j1], tau_tmp);
1209 double tauvecprob1j =
1211 if (tauvecprob1j == 0.)
1213 tauprob =
Prob->TauProbabilityLFV(
preparedInput, tau_type_tmp, tau_tmp, nu_vec[j1]);
1214 totalProb = tauvecprob1j * metprob * MnuProb * tauprob;
1231 m_fPXfit1->Fill((tau_tmp + nu_vec[j1]).Px(), totalProb);
1232 m_fPYfit1->Fill((tau_tmp + nu_vec[j1]).Py(), totalProb);
1233 m_fPZfit1->Fill((tau_tmp + nu_vec[j1]).Pz(), totalProb);
1237 sign_tmp = -log10(totalProb);
1261 Info(
"DiTauMassTools",
"Running in lepton+tau mode");
1287 PtEtaPhiMVector tau_tmp(0.0, 0.0, 0.0, 0.0);
1288 PtEtaPhiMVector lep_tmp(0.0, 0.0, 0.0, 0.0);
1302 for (
int i4 = 0; i4 < NiterMET + 1; i4++)
1304 met_smearL = METresX_binSize * i4 - N_METsigma * METresX;
1305 for (
int i5 = 0; i5 < NiterMET + 1; i5++)
1307 met_smearP = METresY_binSize * i5 - N_METsigma * METresY;
1308 if (pow(met_smearL / METresX, 2) + pow(met_smearP / METresY, 2) > pow(N_METsigma, 2))
1312 metvec_tmp.SetXY(input_metX + met_smear_x, input_metY + met_smear_y);
1327 metprob =
Prob->MetProbability(
preparedInput, met_smearL, met_smearP, METresX, METresY);
1330 for (
unsigned int j1 = 0; j1 < nu_vec.size(); j1++) {
1331 if (tau_tmp.E() + nu_vec[j1].E() >=
preparedInput.m_beamEnergy)
1333 const double tau1_tmpp = (tau_tmp + nu_vec[j1]).
P();
1334 angle1 =
Angle(nu_vec[j1], tau_tmp);
1344 double tauvecprob1j =
1346 if (tauvecprob1j == 0.)
1348 tauprob =
Prob->TauProbabilityLFV(
preparedInput, tau_type_tmp, tau_tmp, nu_vec[j1]);
1349 totalProb = tauvecprob1j * metprob * tauprob;
1372 sign_tmp = -log10(totalProb);
1398 Info(
"DiTauMassTools",
"Running in an unknown mode?!?!");
1405 Info(
"DiTauMassTools",
"%s",
1406 (
"SpeedUp niters=" + std::to_string(iter0) +
" " + std::to_string(
m_iter1) +
" " +
1427 if (prob_hist != 0.0)
1445 PxPyPzMVector nu1_tmp(0.0, 0.0, 0.0, 0.0);
1446 PxPyPzMVector nu2_tmp(0.0, 0.0, 0.0, 0.0);
1466 if (fit_code == 0) {
1468 "DiTauMassTools",
"%s",
1469 (
"!!!----> Warning-3 in MissingMassCalculator::DitauMassCalculatorV9lfv() : fit status=" +
1470 std::to_string(fit_code))
1472 Info(
"DiTauMassTools",
"....... No solution is found. Printing input info .......");
1474 Info(
"DiTauMassTools",
"%s", (
" vis Tau-1: Pt="+std::to_string(
preparedInput.m_vistau1.Pt())
1477 +
" type="+std::to_string(
preparedInput.m_type_visTau1)).c_str());
1478 Info(
"DiTauMassTools",
"%s", (
" vis Tau-2: Pt="+std::to_string(
preparedInput.m_vistau2.Pt())
1481 +
" type="+std::to_string(
preparedInput.m_type_visTau2)).c_str());
1482 Info(
"DiTauMassTools",
"%s", (
" MET="+std::to_string(
preparedInput.m_MetVec.R())+
" Met_X="+std::to_string(
preparedInput.m_MetVec.X())
1483 +
" Met_Y="+std::to_string(
preparedInput.m_MetVec.Y())).c_str());
1484 Info(
"DiTauMassTools",
" ---------------------------------------------------------- ");
1495 const double mM =
x[0];
1496 const double mMax = par[0];
1497 const double mMean = par[1];
1498 const double mInvWidth2 = par[2];
1500 const double fitval = mMax * (1 - 4 * mInvWidth2 * std::pow(mM - mMean, 2));
1513 const int winHalfWidth,
bool debug) {
1521 for (std::vector<double>::iterator itr = histInfo.begin(); itr != histInfo.end(); ++itr) {
1530 winHalfWidth == 0)) {
1534 int max_bin = theHist->GetMaximumBin();
1535 maxPos = theHist->GetBinCenter(max_bin);
1538 prob = theHist->GetBinContent(max_bin) / double(theHist->GetEntries());
1545 int hNbins = theHist->GetNbinsX();
1550 int max_bin = theHist->GetMaximumBin();
1551 int iBinMin = max_bin - winHalfWidth;
1554 int iBinMax = max_bin + winHalfWidth;
1555 if (iBinMax > hNbins)
1556 iBinMax = hNbins - 1;
1559 for (
int iBin = iBinMin; iBin <= iBinMax; ++iBin) {
1560 const double weight = theHist->GetBinContent(iBin);
1562 sumx += weight * theHist->GetBinCenter(iBin);
1564 maxPos = sumx / sumw;
1567 prob = sumw / theHist->GetEntries();
1577 Error(
"DiTauMassTools",
"%s",
1578 (
"ERROR undefined maxHistStrategy:" + std::to_string(maxHistStrategy)).c_str());
1584 int lastNonZeroBin = -1;
1585 int firstNonZeroBin = -1;
1586 double totalSumw = 0.;
1587 bool firstNullPart =
true;
1588 for (
int iBin = 0; iBin < hNbins; ++iBin) {
1589 const double weight = theHist->GetBinContent(iBin);
1591 totalSumw += weight;
1592 lastNonZeroBin = iBin;
1593 if (firstNullPart) {
1594 firstNullPart =
false;
1595 firstNonZeroBin = iBin;
1602 firstNonZeroBin = std::max(0, firstNonZeroBin - winHalfWidth - 1);
1603 lastNonZeroBin = std::min(hNbins - 1, lastNonZeroBin + winHalfWidth + 1);
1612 const int nwidth = 2 * winHalfWidth + 1;
1615 for (
int ibin = 0; ibin < nwidth; ++ibin) {
1616 winsum += theHist->GetBinContent(ibin);
1618 double winmax = winsum;
1621 int iBinL = firstNonZeroBin;
1622 int iBinR = iBinL + 2 * winHalfWidth;
1623 bool goingUp =
true;
1628 const double deltawin = theHist->GetBinContent(iBinR) - theHist->GetBinContent(iBinL - 1);
1634 if (winsum > winmax) {
1637 max_bin = (iBinR + iBinL) / 2 - 1;
1648 }
while (iBinR < lastNonZeroBin);
1651 int iBinMin = max_bin - winHalfWidth;
1654 int iBinMax = max_bin + winHalfWidth;
1655 if (iBinMax >= hNbins)
1656 iBinMax = hNbins - 1;
1659 for (
int iBin = iBinMin; iBin <= iBinMax; ++iBin) {
1660 const double weight = theHist->GetBinContent(iBin);
1662 sumx += weight * theHist->GetBinCenter(iBin);
1665 double maxPosWin = -1.;
1668 maxPosWin = sumx / sumw;
1671 prob = sumw / totalSumw;
1675 const double h_rms = theHist->GetRMS(1);
1679 double numerator = 0;
1680 double denominator = 0;
1681 bool nullBin =
false;
1683 for (
int i = iBinMin; i < iBinMax; ++i) {
1684 double binError = theHist->GetBinError(i);
1685 if (binError < 1e-10) {
1688 double binErrorSquare = std::pow(binError, 2);
1689 num = theHist->GetBinContent(i) / (binErrorSquare);
1690 numerator = numerator + num;
1691 denominator = denominator + (1 / (binErrorSquare));
1693 if (numerator < 1e-10 || denominator < 1e-10 || nullBin ==
true) {
1696 histInfo[
HistInfo::MEANBIN] = sqrt(1 / denominator) / (numerator / denominator);
1709 const double binWidth = theHist->GetBinCenter(2) - theHist->GetBinCenter(1);
1710 double fitWidth = (winHalfWidth + 0.5) *
binWidth;
1723 TString fitOption =
debug ?
"QS" :
"QNS";
1726 m_fFitting->SetParameters(sumw / winHalfWidth, maxPos, 0.0025);
1729 TFitResultPtr fitRes =
1730 theHist->Fit(
m_fFitting, fitOption,
"", maxPos - fitWidth, maxPos + fitWidth);
1732 double maxPosFit = -1.;
1734 if (
int(fitRes) == 0) {
1737 const double mMax = fitRes->Parameter(0);
1738 const double mMean = fitRes->Parameter(1);
1739 const double mInvWidth2 = fitRes->Parameter(2);
1740 double mMaxError = fitRes->ParError(0);
1742 double mMeanError = fitRes->ParError(1);
1744 double mInvWidth2Error = fitRes->ParError(2);
1747 mInvWidth2Error = 0.;
1748 const double c = mMax * (1 - 4 * mMean * mMean * mInvWidth2);
1749 const double b = 8 * mMax * mMean * mInvWidth2;
1750 const double a = -4 * mMax * mInvWidth2;
1756 const double h_discri = b * b - 4 *
a * c;
1758 const double sqrth_discri = sqrt(h_discri);
1759 const double h_fitLength = sqrth_discri /
a;
1766 maxPosFit = -b / (2 *
a);
1770 if (maxPosFit >= 0. and std::abs(maxPosFit - maxPosWin) < 0.8 * fitWidth) {
1788 const double &M_nu1,
1789 const double &M_nu2) {
1795 const int solution =
NuPsolutionV3(M_nu1, M_nu2, phi1, phi2, nsol1, nsol2);
1814 const int nsol1,
const int nsol2,
1815 const double &Mvis,
const double &Meff)
1821 Error(
"DiTauMassTools",
"%s",
1822 (
"refineSolutions ERROR probFinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1825 Error(
"DiTauMassTools",
"%s",
1826 (
"refineSolutions ERROR mtautauSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1829 Error(
"DiTauMassTools",
"%s",
1830 (
"refineSolutions ERROR nu1FinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1833 Error(
"DiTauMassTools",
"%s",
1834 (
"refineSolutions ERROR nu2FinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1837 Error(
"DiTauMassTools",
"%s", (
"refineSolutions ERROR nsol1 " + std::to_string(nsol1) +
1838 " > nsolmax !" + std::to_string(
m_nsolmax))
1841 Error(
"DiTauMassTools",
"%s", (
"refineSolutions ERROR nsol1 " + std::to_string(nsol2) +
1842 " > nsolmax !" + std::to_string(
m_nsolmax))
1848 Prob->apply(
preparedInput, -99, -99, PtEtaPhiMVector(0, 0, 0, 0), PtEtaPhiMVector(0, 0, 0, 0),
1849 PtEtaPhiMVector(0, 0, 0, 0), PtEtaPhiMVector(0, 0, 0, 0),
true,
false,
false);
1851 for (
int j1 = 0; j1 < nsol1; ++j1) {
1861 const int pickInt = std::abs(10000 *
m_Phi1);
1862 const int pickDigit = pickInt - 10 * (pickInt / 10);
1870 nuvec1_tmpj.SetCoordinates(nuvec1_tmpj.Pt(), nuvec1_tmpj.Eta(), nuvec1_tmpj.Phi(), M_nu1);
1871 tauvecsol1j.SetPxPyPzE(0., 0., 0., 0.);
1872 tauvecsol1j += nuvec1_tmpj;
1877 PtEtaPhiMVector(0, 0, 0, 0), nuvec1_tmpj,
1878 PtEtaPhiMVector(0, 0, 0, 0),
false,
true,
false);
1882 for (
int j2 = 0; j2 < nsol2; ++j2) {
1893 const int pickInt = std::abs(10000 *
m_Phi2);
1894 const int pickDigit = pickInt - 10 * int(pickInt / 10);
1902 nuvec2_tmpj.SetCoordinates(nuvec2_tmpj.Pt(), nuvec2_tmpj.Eta(), nuvec2_tmpj.Phi(), M_nu2);
1903 tauvecsol2j.SetPxPyPzE(0., 0., 0., 0.);
1904 tauvecsol2j += nuvec2_tmpj;
1910 PtEtaPhiMVector(0, 0, 0, 0), nuvec2_tmpj,
false,
true,
false);
1914 if (tauvecprob1j == 0.)
1916 if (tauvecprob2j == 0.)
1919 double totalProb = 1.;
1932 (constProb * tauvecprob1j * tauvecprob2j *
1936 if (totalProb <= 0) {
1938 Warning(
"DiTauMassTools",
"%s",
1939 (
"null proba solution, rejected "+std::to_string(totalProb)).c_str());
1946 Error(
"DiTauMassTools",
"%s",
1947 (
"refineSolutions ERROR nsol getting larger than nsolfinalmax!!! " +
1950 Error(
"DiTauMassTools",
"%s",
1951 (
" j1 " + std::to_string(j1) +
" j2 " + std::to_string(j2) +
" nsol1 " +
1952 std::to_string(nsol1) +
" nsol2 " + std::to_string(nsol2))
1966 nu1Final.SetPxPyPzE(nuvec1_tmpj.Px(), nuvec1_tmpj.Py(), nuvec1_tmpj.Pz(), nuvec1_tmpj.E());
1967 nu2Final.SetPxPyPzE(nuvec2_tmpj.Px(), nuvec2_tmpj.Py(), nuvec2_tmpj.Pz(), nuvec2_tmpj.E());
1975 if (ngoodsol1 == 0) {
1978 if (ngoodsol2 == 0) {
1985 const PtEtaPhiMVector &nu1,
1986 const PtEtaPhiMVector &vis2,
1987 const PtEtaPhiMVector &nu2,
const double &mmc_mass,
1988 const double &vis_mass,
const double &eff_mass,
1989 const double &dphiTT) {
2000 const double MrecoMvis = mmc_mass / vis_mass;
2001 if (MrecoMvis > 2.6)
2003 const double MrecoMeff = mmc_mass / eff_mass;
2004 if (MrecoMeff > 1.9)
2006 const double e1p1 = nu1.E() / vis1.P();
2007 const double e2p2 = nu2.E() / vis2.P();
2008 if ((e1p1 + e2p2) > 4.5)
2027 if (
Prob->GetUseHT()) {
2028 const double MrecoMvis = mmc_mass / vis_mass;
2029 const double MrecoMeff = mmc_mass / eff_mass;
2030 const double x = dphiTT > 1.5 ? dphiTT : 1.5;
2031 if ((MrecoMeff + MrecoMvis) > 5.908 - 1.881 *
x + 0.2995 *
x *
x)
2044 double totalProbSumSol = 0.;
2045 double totalProbSumSolOld = 0.;
2046 bool firstPointWithSol =
false;
2048 for (
int isol = 0; isol <
m_nsol; ++isol) {
2053 bool notSureToKeep =
true;
2057 notSureToKeep =
false;
2064 firstPointWithSol =
true;
2076 if (notSureToKeep) {
2079 for (
int isol = 0; isol <
m_nsolOld; ++isol) {
2085 if (!firstPointWithSol && totalProbSumSolOld <= 0.) {
2086 Error(
"DiTauMassTools",
"%s",
2087 (
" ERROR null old probability !!! " + std::to_string(totalProbSumSolOld) +
" nsolOld " +
2091 }
else if (totalProbSumSol > totalProbSumSolOld) {
2096 }
else if (totalProbSumSol < totalProbSumSolOld * 1E-6) {
2100 }
else if (
m_nsol <= 0) {
2107 reject = (uMC > totalProbSumSol / totalProbSumSolOld);
2132 bool fillSolution =
true;
2133 bool oldToBeUsed =
false;
2141 fillSolution =
false;
2155 if (!firstPointWithSol) {
2156 fillSolution =
true;
2159 fillSolution =
false;
2166 if (!fillSolution) {
2167 if (firstPointWithSol) {
2170 for (
int isol = 0; isol <
m_nsol; ++isol) {
2182 double solSum2 = 0.;
2184 for (
int isol = 0; isol <
m_nsol; ++isol) {
2188 const PtEtaPhiMVector *pnuvec1_tmpj;
2189 const PtEtaPhiMVector *pnuvec2_tmpj;
2202 const PtEtaPhiMVector &nuvec1_tmpj = *pnuvec1_tmpj;
2203 const PtEtaPhiMVector &nuvec2_tmpj = *pnuvec2_tmpj;
2206 solSum2 += mtautau * mtautau;
2228 if (mtautau != 0. && weight != 0.)
2293 for (
int isol = 0; isol <
m_nsol; ++isol) {
2302 const double solRMS = sqrt(solSum2 /
m_nsol - std::pow(solSum /
m_nsol, 2));
2495 Info(
"DiTauMassTools",
" in m_meanbinToBeEvaluated && m_iterNsuc==500 ");
2510 double stopdouble = 500 * std::pow((meanbin /
m_meanbinStop), 2);
2511 int stopint = stopdouble;
2642 PtEtaPhiMVector Met4vec;
2715 const double &P_tau) {
2717#ifndef WITHDTHETA3DLIM
2719 if (limit_code == 0)
2721 if (limit_code == 1)
2723 if (limit_code == 2)
2729 if (limit_code == 0)
2731 double par[3] = {0.0, 0.0, 0.0};
2733 if (tau_type == 8) {
2734 if (limit_code == 0)
2740 if (limit_code == 1)
2746 if (limit_code == 2)
2754 if (tau_type >= 0 && tau_type <= 2) {
2755 if (limit_code == 0)
2759 par[2] = -0.0004859;
2761 if (limit_code == 1)
2767 if (limit_code == 2)
2775 if (tau_type >= 3 && tau_type <= 5) {
2776 if (limit_code == 0)
2780 par[2] = -0.0009458;
2782 if (limit_code == 1)
2788 if (limit_code == 2)
2796 if (std::abs(P_tau + par[1]) > 0.0)
2797 limit = par[0] / (P_tau + par[1]) + par[2];
2798 if (limit_code == 0) {
2801 }
else if (limit > 0.03) {
2805 if (limit < 0.0 || limit > 0.5 * TMath::Pi()) {
2806 limit = 0.5 * TMath::Pi();
2807 }
else if (limit < 0.05 && limit > 0.0) {
2836 if (LFVMode == -1) {
2838 }
else if (LFVMode != -2) {
2850 PtEtaPhiMVector fixedtau1;
2851 fixedtau1.SetCoordinates(tlvTau1.Pt() /
GEV, tlvTau1.Eta(), tlvTau1.Phi(), tlvTau1.M() /
GEV);
2852 PtEtaPhiMVector fixedtau2;
2853 fixedtau2.SetCoordinates(tlvTau2.Pt() /
GEV, tlvTau2.Eta(), tlvTau2.Phi(), tlvTau2.M() /
GEV);
2860 if (mmcType1 == 8 && mmcType2 == 8) {
2862 }
else if (mmcType1 >= 0 && mmcType1 <= 5 && mmcType2 >= 0 && mmcType2 <= 5) {
2868 Info(
"DiTauMassTools",
"%s", (
"running for tau types "+std::to_string(
preparedInput.m_type_visTau1)+
" "+std::to_string(
preparedInput.m_type_visTau2)).c_str());
2872 Info(
"DiTauMassTools",
"%s", (
"passing SumEt="+std::to_string(
met->sumet() /
GEV)).c_str());
2878 Error(
"DiTauMassTools",
"MMCCalibrationSet has not been set !. Please use "
2879 "fMMC.SetCalibrationSet(MMCCalibrationSet::MMC2019) or fMMC.SetCalibrationSet(MMCCalibrationSet::MMC2024)"
2914 for (
unsigned int i = 0; i <
preparedInput.m_jet4vecs.size(); i++) {
2921 Info(
"DiTauMassTools",
"correcting sumET");
3018 Info(
"DiTauMassTools",
"Substracting pt1 from sumEt");
3025 Info(
"DiTauMassTools",
"Substracting pt2 from sumEt");
3037 Prob->SetUseTauProbability(
true);
3040 Prob->SetUseTauProbability(
false);
3057 Prob->SetUseTauProbability(
false);
3059 Prob->SetUseTauProbability(
true);
3060 Prob->SetUseMnuProbability(
false);
3065 if (
Prob->GetUseHT())
3068 double HtOffset = 0.;
3073 HtOffset = 87.5 - 27.0 *
x;
3092 float hEmax = 3000.0;
3094 m_fMEtP_all = std::make_shared<TH1F>(
"MEtP_h1",
"M", hNbins, -100.0,
3096 m_fMEtL_all = std::make_shared<TH1F>(
"MEtL_h1",
"M", hNbins, -100.0,
3098 m_fMnu1_all = std::make_shared<TH1F>(
"Mnu1_h1",
"M", hNbins, 0.0,
3100 m_fMnu2_all = std::make_shared<TH1F>(
"Mnu2_h1",
"M", hNbins, 0.0,
3102 m_fPhi1_all = std::make_shared<TH1F>(
"Phi1_h1",
"M", hNbins, -10.0,
3104 m_fPhi2_all = std::make_shared<TH1F>(
"Phi2_h1",
"M", hNbins, -10.0,
3127 float hEmax = 3000.0;
3129 m_fMmass_split1 = std::make_shared<TH1F>(
"mass_h1_1",
"M", hNbins, 0.0, hEmax);
3130 m_fMEtP_split1 = std::make_shared<TH1F>(
"MEtP_h1_1",
"M", hNbins, -100.0, 100.0);
3131 m_fMEtL_split1 = std::make_shared<TH1F>(
"MEtL_h1_1",
"M", hNbins, -100.0, 100.0);
3132 m_fMnu1_split1 = std::make_shared<TH1F>(
"Mnu1_h1_1",
"M", hNbins, 0.0, hEmax);
3133 m_fMnu2_split1 = std::make_shared<TH1F>(
"Mnu2_h1_1",
"M", hNbins, 0.0, hEmax);
3134 m_fPhi1_split1 = std::make_shared<TH1F>(
"Phi1_h1_1",
"M", hNbins, -10.0, 10.0);
3135 m_fPhi2_split1 = std::make_shared<TH1F>(
"Phi2_h1_1",
"M", hNbins, -10.0, 10.0);
3136 m_fMmass_split2 = std::make_shared<TH1F>(
"mass_h1_2",
"M", hNbins, 0.0, hEmax);
3137 m_fMEtP_split2 = std::make_shared<TH1F>(
"MEtP_h1_2",
"M", hNbins, -100.0, 100.0);
3138 m_fMEtL_split2 = std::make_shared<TH1F>(
"MEtL_h1_2",
"M", hNbins, -100.0, 100.0);
3139 m_fMnu1_split2 = std::make_shared<TH1F>(
"Mnu1_h1_2",
"M", hNbins, 0.0, hEmax);
3140 m_fMnu2_split2 = std::make_shared<TH1F>(
"Mnu2_h1_2",
"M", hNbins, 0.0, hEmax);
3141 m_fPhi1_split2 = std::make_shared<TH1F>(
"Phi1_h1_2",
"M", hNbins, -10.0, 10.0);
3142 m_fPhi2_split2 = std::make_shared<TH1F>(
"Phi2_h1_2",
"M", hNbins, -10.0, 10.0);
3178 const bool kMMCsynchronize,
3179 double &mass,
double &xp1,
double &xp2) {
3181 TLorentzVector k1 = p0->p4();
3182 TLorentzVector k2 = p1->p4();
3185 if (kMMCsynchronize) {
3188 k1.SetPtEtaPhiM(k1.Pt(), k1.Eta(), k1.Phi(),
3189 tau0->nTracks() < 3 ? 800. : 1200.);
3194 k2.SetPtEtaPhiM(k2.Pt(), k2.Eta(), k2.Phi(),
3195 tau1->
nTracks() < 3 ? 800. : 1200.);
3205 if (K.Determinant() == 0)
3209 M(0, 0) =
met->mpx();
3210 M(1, 0) =
met->mpy();
3212 TMatrixD Kinv = K.Invert();
3217 double X1 = X(0, 0);
3218 double X2 = X(1, 0);
3219 double x1 = 1. / (1. + X1);
3220 double x2 = 1. / (1. + X2);
3222 TLorentzVector par1 = k1 * (1 / x1);
3223 TLorentzVector par2 = k2 * (1 / x2);
3225 double m = (par1 + par2).M();
3230 if (k1.Pt() > k2.Pt()) {
__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.
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
constexpr double tauMassInMeV
the mass of the tau (in MeV)
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
@ Tau
The object is a tau (jet).
MissingET_v1 MissingET
Version control by type defintion.
TauJet_v3 TauJet
Definition of the current "tau version".