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;
83 Prob->SetUseTauProbability(
true);
84 Prob->SetUseMnuProbability(
false);
85 Prob->SetUseDphiLL(
false);
134 float hEmax = 3000.0;
144 m_fMfit_all = std::make_shared<TH1F>(
"MMC_h1",
"M", hNbins, 0.0,
151 std::make_shared<TH1F>(
"MMC_h1NoW",
"M no weight", hNbins, 0.0, hEmax);
153 m_fPXfit1 = std::make_shared<TH1F>(
"MMC_h2",
"Px1", 4 * hNbins, -hEmax,
155 m_fPYfit1 = std::make_shared<TH1F>(
"MMC_h3",
"Py1", 4 * hNbins, -hEmax,
157 m_fPZfit1 = std::make_shared<TH1F>(
"MMC_h4",
"Pz1", 4 * hNbins, -hEmax,
159 m_fPXfit2 = std::make_shared<TH1F>(
"MMC_h5",
"Px2", 4 * hNbins, -hEmax,
161 m_fPYfit2 = std::make_shared<TH1F>(
"MMC_h6",
"Py2", 4 * hNbins, -hEmax,
163 m_fPZfit2 = std::make_shared<TH1F>(
"MMC_h7",
"Pz2", 4 * hNbins, -hEmax,
180 m_fFitting->SetParNames(
"Max",
"Mean",
"InvWidth2");
205 Info(
"DiTauMassTools",
"------------- Raw Input for MissingMassCalculator --------------");
210 Info(
"DiTauMassTools",
"------------- Prepared Input for MissingMassCalculator--------------");
229 double dummy_METres =
232 dummy_METres * std::abs(cos(dummy_met.Phi() -
preparedInput.m_MetVec.Phi()));
234 dummy_METres * std::abs(sin(dummy_met.Phi() -
preparedInput.m_MetVec.Phi()));
250 Info(
"DiTauMassTools",
"Calling DitauMassCalculatorV9lfv");
256 TFile *outFile = TFile::Open(
"MMC_likelihoods.root",
"UPDATE");
259 if (!outFile->GetDirectory(path.c_str()))
260 outFile->mkdir(path.c_str());
261 outFile->cd(path.c_str());
271 TH1D *nosol =
new TH1D(
"nosol",
"nosol", 7, 0, 7);
279 nosol->Write(nosol->GetName(), TObject::kOverwrite);
294 fStuff.
nutau1 = PtEtaPhiMVector(0., 0., 0., 0.);
295 fStuff.
nutau2 = PtEtaPhiMVector(0., 0., 0., 0.);
296 fStuff.
vistau1 = PtEtaPhiMVector(0., 0., 0., 0.);
297 fStuff.
vistau2 = PtEtaPhiMVector(0., 0., 0., 0.);
309 Info(
"DiTauMassTools",
"Retrieving output from fDitauStuffFit");
314 double q1 = (1. - 0.68) / 2.;
341 PtEtaPhiMVector tlvdummy(0., 0., 0., 0.);
342 XYVector metdummy(0., 0.);
383 PtEtaPhiMVector dummy_vec1(0.0, 0.0, 0.0, 0.0);
384 PtEtaPhiMVector dummy_vec2(0.0, 0.0, 0.0, 0.0);
385 for (
int i = 0; i < 3; i++) {
407 Info(
"DiTauMassTools",
408 ".........................Other input.....................................");
409 Info(
"DiTauMassTools",
"%s",
410 (
"Beam energy =" + std::to_string(
preparedInput.m_beamEnergy) +
411 " sqrt(S) for collisions =" + std::to_string(2.0 *
preparedInput.m_beamEnergy))
413 Info(
"DiTauMassTools",
"%s",
416 Info(
"DiTauMassTools",
"%s",
417 (
"LFV mode " + std::to_string(
preparedInput.m_LFVmode) +
" seed=" + std::to_string(
m_seed))
419 Info(
"DiTauMassTools",
"%s", (
"usetauProbability=" + std::to_string(
Prob->GetUseTauProbability()) +
420 " useTailCleanup=" + std::to_string(
preparedInput.m_fUseTailCleanup))
424 Info(
"DiTauMassTools",
425 "tau1 and tau2 were internally swapped (visible on prepared input printout)");
427 Info(
"DiTauMassTools",
"tau1 and tau2 were NOT internally swapped");
430 Info(
"DiTauMassTools",
"%s",
431 (
" MEtLMin=" + std::to_string(
m_MEtLMin) +
" MEtLMax=" + std::to_string(
m_MEtLMax)).c_str());
432 Info(
"DiTauMassTools",
"%s",
433 (
" MEtPMin=" + std::to_string(
m_MEtPMin) +
" MEtPMax=" + std::to_string(
m_MEtPMax)).c_str());
434 Info(
"DiTauMassTools",
"%s",
435 (
" Phi1Min=" + std::to_string(
m_Phi1Min) +
" Phi1Max=" + std::to_string(
m_Phi1Max)).c_str());
436 Info(
"DiTauMassTools",
"%s",
437 (
" Phi2Min=" + std::to_string(
m_Phi2Min) +
" Phi2Max=" + std::to_string(
m_Phi2Max)).c_str());
438 Info(
"DiTauMassTools",
"%s",
439 (
" Mnu1Min=" + std::to_string(
m_Mnu1Min) +
" Mnu1Max=" + std::to_string(
m_Mnu1Max)).c_str());
440 Info(
"DiTauMassTools",
"%s",
441 (
" Mnu2Min=" + std::to_string(
m_Mnu2Min) +
" Mnu2Max=" + std::to_string(
m_Mnu2Max)).c_str());
450 const PtEtaPhiMVector *origVisTau1 = 0;
451 const PtEtaPhiMVector *origVisTau2 = 0;
464 Info(
"DiTauMassTools",
465 "------------- Printing Final Results for MissingMassCalculator --------------");
466 Info(
"DiTauMassTools",
467 ".............................................................................");
468 Info(
"DiTauMassTools",
"%s", (
"Fit status=" + std::to_string(
OutputInfo.m_FitStatus)).c_str());
471 Info(
"DiTauMassTools",
"%s",
474 Info(
"DiTauMassTools",
"%s",
475 (
" signif=" + std::to_string(
OutputInfo.m_FitSignificance[imeth])).c_str());
476 Info(
"DiTauMassTools",
"%s", (
" mass=" + std::to_string(
OutputInfo.m_FittedMass[imeth])).c_str());
477 Info(
"DiTauMassTools",
"%s", (
" rms/mpv=" + std::to_string(
OutputInfo.m_RMS2MPV)).c_str());
480 Info(
"DiTauMassTools",
" no 4-momentum or MET from this method ");
485 Info(
"DiTauMassTools",
" fit failed ");
488 const PtEtaPhiMVector &tlvnu1 =
OutputInfo.m_nuvec1[imeth];
489 const PtEtaPhiMVector &tlvnu2 =
OutputInfo.m_nuvec2[imeth];
490 const PtEtaPhiMVector &tlvo1 =
OutputInfo.m_objvec1[imeth];
491 const PtEtaPhiMVector &tlvo2 =
OutputInfo.m_objvec2[imeth];
492 const XYVector &tvmet =
OutputInfo.m_FittedMetVec[imeth];
494 Info(
"DiTauMassTools",
"%s",
495 (
" Neutrino-1: P=" + std::to_string(tlvnu1.P()) +
" Pt=" + std::to_string(tlvnu1.Pt()) +
496 " Eta=" + std::to_string(tlvnu1.Eta()) +
" Phi=" + std::to_string(tlvnu1.Phi()) +
497 " M=" + std::to_string(tlvnu1.M()) +
" Px=" + std::to_string(tlvnu1.Px()) +
498 " Py=" + std::to_string(tlvnu1.Py()) +
" Pz=" + std::to_string(tlvnu1.Pz()))
500 Info(
"DiTauMassTools",
"%s",
501 (
" Neutrino-2: P=" + std::to_string(tlvnu2.P()) +
" Pt=" + std::to_string(tlvnu2.Pt()) +
502 " Eta=" + std::to_string(tlvnu2.Eta()) +
" Phi=" + std::to_string(tlvnu2.Phi()) +
503 " M=" + std::to_string(tlvnu2.M()) +
" Px=" + std::to_string(tlvnu2.Px()) +
504 " Py=" + std::to_string(tlvnu2.Py()) +
" Pz=" + std::to_string(tlvnu2.Pz()))
506 Info(
"DiTauMassTools",
"%s",
507 (
" Tau-1: P=" + std::to_string(tlvo1.P()) +
" Pt=" + std::to_string(tlvo1.Pt()) +
508 " Eta=" + std::to_string(tlvo1.Eta()) +
" Phi=" + std::to_string(tlvo1.Phi()) +
509 " M=" + std::to_string(tlvo1.M()) +
" Px=" + std::to_string(tlvo1.Px()) +
510 " Py=" + std::to_string(tlvo1.Py()) +
" Pz=" + std::to_string(tlvo1.Pz()))
512 Info(
"DiTauMassTools",
"%s",
513 (
" Tau-2: P=" + std::to_string(tlvo2.P()) +
" Pt=" + std::to_string(tlvo2.Pt()) +
514 " Eta=" + std::to_string(tlvo2.Eta()) +
" Phi=" + std::to_string(tlvo2.Phi()) +
515 " M=" + std::to_string(tlvo2.M()) +
" Px=" + std::to_string(tlvo2.Px()) +
516 " Py=" + std::to_string(tlvo2.Py()) +
" Pz=" + std::to_string(tlvo2.Pz()))
519 Info(
"DiTauMassTools",
"%s",
520 (
" dR(nu1-visTau1)=" + std::to_string(DeltaR(tlvnu1,*origVisTau1))).c_str());
521 Info(
"DiTauMassTools",
"%s",
522 (
" dR(nu2-visTau2)=" + std::to_string(DeltaR(tlvnu2,*origVisTau2))).c_str());
524 Info(
"DiTauMassTools",
"%s",
525 (
" Fitted MET =" + std::to_string(tvmet.R()) +
" Phi=" + std::to_string(tlvnu1.Phi()) +
526 " Px=" + std::to_string(tvmet.X()) +
" Py=" + std::to_string(tvmet.Y()))
529 Info(
"DiTauMassTools",
"%s", (
" Resonance: P=" + std::to_string(
OutputInfo.m_totalvec[imeth].P()) +
530 " Pt=" + std::to_string(
OutputInfo.m_totalvec[imeth].Pt()) +
531 " Eta=" + std::to_string(
OutputInfo.m_totalvec[imeth].Eta()) +
532 " Phi=" + std::to_string(
OutputInfo.m_totalvec[imeth].Phi()) +
533 " M=" + std::to_string(
OutputInfo.m_totalvec[imeth].M()) +
534 " Px=" + std::to_string(
OutputInfo.m_totalvec[imeth].Px()) +
535 " Py=" + std::to_string(
OutputInfo.m_totalvec[imeth].Py()) +
536 " Pz=" + std::to_string(
OutputInfo.m_totalvec[imeth].Pz()))
551 const double &phi1,
const double &phi2,
552 int &nsol1,
int &nsol2) {
573 int solution_code = 0;
591 if (pTmiss2 * dPhiSign < 0) {
593 return solution_code;
599 if (pTmiss1 * (-dPhiSign) < 0) {
601 return solution_code;
610 double m4noma1 = m2noma1 * m2noma1;
612 double p2v1proj = std::pow(pv1proj, 2);
614 double pTmiss2CscDPhi = pTmiss2 / sinDPhi2;
615 double &pTn1 = pTmiss2CscDPhi;
616 double pT2miss2CscDPhi = pTmiss2CscDPhi * pTmiss2CscDPhi;
619 const double discri1 = m4noma1 + 4 * m2noma1 * pTmiss2CscDPhi * pv1proj -
620 4 * (
m_ET2v1 * (
m_m2Nu1 + pT2miss2CscDPhi) - (pT2miss2CscDPhi * p2v1proj));
625 return solution_code;
633 double m4noma2 = m2noma2 * m2noma2;
635 double p2v2proj = std::pow(pv2proj, 2);
636 double sinDPhi1 = -sinDPhi2;
637 double pTmiss1CscDPhi = pTmiss1 / sinDPhi1;
638 double &pTn2 = pTmiss1CscDPhi;
639 double pT2miss1CscDPhi = pTmiss1CscDPhi * pTmiss1CscDPhi;
641 const double discri2 = m4noma2 + 4 * m2noma2 * pTmiss1CscDPhi * pv2proj -
642 4 * (
m_ET2v2 * (
m_m2Nu2 + pT2miss1CscDPhi) - (pT2miss1CscDPhi * p2v2proj));
647 return solution_code;
653 double sqdiscri1 = sqrt(discri1);
659 double pn1Z = first1 + second1;
661 if (m2noma1 + 2 * pTmiss2CscDPhi * pv1proj + 2 * pn1Z *
m_tauVec1Pz >
665 sqrt(std::pow(pTn1, 2) + std::pow(pn1Z, 2) +
m_m2Nu1));
670 pn1Z = first1 - second1;
672 if (m2noma1 + 2 * pTmiss2CscDPhi * pv1proj + 2 * pn1Z *
m_tauVec1Pz >
677 sqrt(std::pow(pTn1, 2) + std::pow(pn1Z, 2) +
m_m2Nu1));
684 return solution_code;
689 double sqdiscri2 = sqrt(discri2);
695 double pn2Z = first2 + second2;
697 if (m2noma2 + 2 * pTmiss1CscDPhi * pv2proj + 2 * pn2Z *
m_tauVec2Pz >
701 sqrt(std::pow(pTn2, 2) + std::pow(pn2Z, 2) +
m_m2Nu2));
706 pn2Z = first2 - second2;
709 if (m2noma2 + 2 * pTmiss1CscDPhi * pv2proj + 2 * pn2Z *
m_tauVec2Pz >
713 sqrt(std::pow(pTn2, 2) + std::pow(pn2Z, 2) +
m_m2Nu2));
720 return solution_code;
736 if (std::abs(pnux - pTmissx) > 0.001 || std::abs(pnuy - pTmissy) > 0.001) {
737 Info(
"DiTauMassTools",
"%s", (
"NuPsolutionV3 ERROR Pnux-Met.X or Pnuy-Met.Y > 0.001 : " +
738 std::to_string(pnux - pTmissx) +
" and " +
739 std::to_string(pnuy - pTmissx) +
" " +
"Invalid solutions")
742 if (std::abs(mtau1plus -
m_mTau) > 0.001 || std::abs(mtau1moins -
m_mTau) > 0.001 ||
743 std::abs(mtau2plus -
m_mTau) > 0.001 || std::abs(mtau2moins -
m_mTau) > 0.001) {
744 Info(
"DiTauMassTools",
"%s", (
"NuPsolutionV3 ERROR tau mass not recovered : " +
745 std::to_string(mtau1plus) +
" " + std::to_string(mtau1moins) +
" " +
746 std::to_string(mtau2plus) +
" " + std::to_string(mtau2moins))
751 return solution_code;
756 const PtEtaPhiMVector &tau,
const double &l_nu,
757 std::vector<PtEtaPhiMVector> &nu_vec) {
758 int solution_code = 0;
761 PxPyPzMVector nu(met_vec.X(), met_vec.Y(), 0.0, l_nu);
762 PxPyPzMVector nu2(met_vec.X(), met_vec.Y(), 0.0, l_nu);
766 double msq = (Mtau * Mtau - tau.M() * tau.M() - l_nu * l_nu) /
768 double gamma = nu.Px() * nu.Px() + nu.Py() * nu.Py();
769 double beta = tau.Px() * nu.Px() + tau.Py() * nu.Py() + msq;
770 double a = tau.E() * tau.E() - tau.Pz() * tau.Pz();
771 double b = -2 * tau.Pz() * beta;
772 double c = tau.E() * tau.E() * gamma - beta * beta;
773 if ((b * b - 4 *
a * c) < 0)
774 return solution_code;
777 double pvz1 = (-b + sqrt(b * b - 4 *
a * c)) / (2 *
a);
778 double pvz2 = (-b - sqrt(b * b - 4 *
a * c)) / (2 *
a);
780 nu.SetCoordinates(met_vec.X(), met_vec.Y(), pvz1, l_nu);
781 nu2.SetCoordinates(met_vec.X(), met_vec.Y(), pvz2, l_nu);
783 PtEtaPhiMVector return_nu(nu.Pt(), nu.Eta(), nu.Phi(), nu.M());
784 PtEtaPhiMVector return_nu2(nu2.Pt(), nu2.Eta(), nu2.Phi(), nu2.M());
785 nu_vec.push_back(return_nu);
786 nu_vec.push_back(return_nu2);
787 return solution_code;
850 bool paramInsideRange =
false;
869 if (paramInsideRange)
893 if (nsuccesses > 0) {
899 double Px1, Py1, Pz1;
900 double Px2, Py2, Pz2;
901 if (nsuccesses > 0) {
922 if (prob_hist != 0.0)
946 PxPyPzMVector fulltau1, fulltau2;
968 Info(
"DiTauMassTools",
"Scanning ");
969 Info(
"DiTauMassTools",
" Markov ");
970 Info(
"DiTauMassTools",
"%s",
971 (
" V9W niters=" + std::to_string(
m_iter0) +
" " + std::to_string(
m_iter1)).c_str());
972 Info(
"DiTauMassTools",
"%s", (
" nFullScan " + std::to_string(
m_markovNFullScan)).c_str());
973 Info(
"DiTauMassTools",
"%s", (
" nRejectNoSol " + std::to_string(
m_markovNRejectNoSol)).c_str());
975 Info(
"DiTauMassTools",
"%s", (
" nAccept " + std::to_string(
m_markovNAccept)).c_str());
976 Info(
"DiTauMassTools",
"%s",
983 Info(
"DiTauMassTools",
"%s", (
"!!!----> Warning-3 in "
984 "MissingMassCalculator::DitauMassCalculatorV9Walk() : fit status=" +
985 std::to_string(fit_code))
987 Info(
"DiTauMassTools",
"%s",
"....... No solution is found. Printing input info .......");
989 Info(
"DiTauMassTools",
"%s", (
" vis Tau-1: Pt=" + std::to_string(
preparedInput.m_vistau1.Pt()) +
995 Info(
"DiTauMassTools",
"%s", (
" vis Tau-2: Pt=" + std::to_string(
preparedInput.m_vistau2.Pt()) +
1001 Info(
"DiTauMassTools",
"%s", (
" MET=" + std::to_string(
preparedInput.m_MetVec.R()) +
1005 Info(
"DiTauMassTools",
" ---------------------------------------------------------- ");
1047 double METresX_binSize = 2 * N_METsigma * METresX / NiterMET;
1048 double METresY_binSize = 2 * N_METsigma * METresY / NiterMET;
1052 std::vector<PtEtaPhiMVector> nu_vec;
1057 double metprob = 1.0;
1058 double sign_tmp = 0.0;
1059 double tauprob = 1.0;
1060 double totalProb = 0.0;
1064 double met_smear_x = 0.0;
1065 double met_smear_y = 0.0;
1066 double met_smearL = 0.0;
1067 double met_smearP = 0.0;
1069 double angle1 = 0.0;
1093 const double met_coscovphi = cos(
preparedInput.m_METcovphi);
1094 const double met_sincovphi = sin(
preparedInput.m_METcovphi);
1109 Info(
"DiTauMassTools",
"Running in dilepton mode");
1114 PtEtaPhiMVector tau_tmp(0.0, 0.0, 0.0, 0.0);
1115 PtEtaPhiMVector lep_tmp(0.0, 0.0, 0.0, 0.0);
1155 double Mlep = tau_tmp.M();
1162 double MnuProb = 1.0;
1164 for (
int i3 = 0; i3 < NiterMnu; i3++)
1166 M_nu = Mnu_binSize * i3;
1167 if (M_nu >= (Mtau - Mlep))
1173 for (
int i4 = 0; i4 < NiterMET + 1; i4++)
1175 met_smearL = METresX_binSize * i4 - N_METsigma * METresX;
1176 for (
int i5 = 0; i5 < NiterMET + 1; i5++)
1178 met_smearP = METresY_binSize * i5 - N_METsigma * METresY;
1179 if (
pow(met_smearL / METresX, 2) +
pow(met_smearP / METresY, 2) >
pow(N_METsigma, 2))
1181 met_smear_x = met_smearL * met_coscovphi - met_smearP * met_sincovphi;
1182 met_smear_y = met_smearL * met_sincovphi + met_smearP * met_coscovphi;
1183 metvec_tmp.SetXY(input_metX + met_smear_x, input_metY + met_smear_y);
1198 metprob =
Prob->MetProbability(
preparedInput, met_smearL, met_smearP, METresX, METresY);
1201 for (
unsigned int j1 = 0; j1 < nu_vec.size(); j1++) {
1202 if (tau_tmp.E() + nu_vec[j1].E() >=
preparedInput.m_beamEnergy)
1204 const double tau1_tmpp = (tau_tmp + nu_vec[j1]).
P();
1205 angle1 =
Angle(nu_vec[j1], tau_tmp);
1215 double tauvecprob1j =
1217 if (tauvecprob1j == 0.)
1219 tauprob =
Prob->TauProbabilityLFV(
preparedInput, tau_type_tmp, tau_tmp, nu_vec[j1]);
1220 totalProb = tauvecprob1j * metprob * MnuProb * tauprob;
1237 m_fPXfit1->Fill((tau_tmp + nu_vec[j1]).Px(), totalProb);
1238 m_fPYfit1->Fill((tau_tmp + nu_vec[j1]).Py(), totalProb);
1239 m_fPZfit1->Fill((tau_tmp + nu_vec[j1]).Pz(), totalProb);
1243 sign_tmp = -log10(totalProb);
1267 Info(
"DiTauMassTools",
"Running in lepton+tau mode");
1293 PtEtaPhiMVector tau_tmp(0.0, 0.0, 0.0, 0.0);
1294 PtEtaPhiMVector lep_tmp(0.0, 0.0, 0.0, 0.0);
1308 for (
int i4 = 0; i4 < NiterMET + 1; i4++)
1310 met_smearL = METresX_binSize * i4 - N_METsigma * METresX;
1311 for (
int i5 = 0; i5 < NiterMET + 1; i5++)
1313 met_smearP = METresY_binSize * i5 - N_METsigma * METresY;
1314 if (
pow(met_smearL / METresX, 2) +
pow(met_smearP / METresY, 2) >
pow(N_METsigma, 2))
1318 metvec_tmp.SetXY(input_metX + met_smear_x, input_metY + met_smear_y);
1333 metprob =
Prob->MetProbability(
preparedInput, met_smearL, met_smearP, METresX, METresY);
1336 for (
unsigned int j1 = 0; j1 < nu_vec.size(); j1++) {
1337 if (tau_tmp.E() + nu_vec[j1].E() >=
preparedInput.m_beamEnergy)
1339 const double tau1_tmpp = (tau_tmp + nu_vec[j1]).
P();
1340 angle1 =
Angle(nu_vec[j1], tau_tmp);
1350 double tauvecprob1j =
1352 if (tauvecprob1j == 0.)
1354 tauprob =
Prob->TauProbabilityLFV(
preparedInput, tau_type_tmp, tau_tmp, nu_vec[j1]);
1355 totalProb = tauvecprob1j * metprob * tauprob;
1378 sign_tmp = -log10(totalProb);
1404 Info(
"DiTauMassTools",
"Running in an unknown mode?!?!");
1411 Info(
"DiTauMassTools",
"%s",
1412 (
"SpeedUp niters=" + std::to_string(iter0) +
" " + std::to_string(
m_iter1) +
" " +
1433 if (prob_hist != 0.0)
1451 PxPyPzMVector nu1_tmp(0.0, 0.0, 0.0, 0.0);
1452 PxPyPzMVector nu2_tmp(0.0, 0.0, 0.0, 0.0);
1472 if (fit_code == 0) {
1474 "DiTauMassTools",
"%s",
1475 (
"!!!----> Warning-3 in MissingMassCalculator::DitauMassCalculatorV9lfv() : fit status=" +
1476 std::to_string(fit_code))
1478 Info(
"DiTauMassTools",
"....... No solution is found. Printing input info .......");
1480 Info(
"DiTauMassTools",
"%s", (
" vis Tau-1: Pt="+std::to_string(
preparedInput.m_vistau1.Pt())
1483 +
" type="+std::to_string(
preparedInput.m_type_visTau1)).c_str());
1484 Info(
"DiTauMassTools",
"%s", (
" vis Tau-2: Pt="+std::to_string(
preparedInput.m_vistau2.Pt())
1487 +
" type="+std::to_string(
preparedInput.m_type_visTau2)).c_str());
1488 Info(
"DiTauMassTools",
"%s", (
" MET="+std::to_string(
preparedInput.m_MetVec.R())+
" Met_X="+std::to_string(
preparedInput.m_MetVec.X())
1489 +
" Met_Y="+std::to_string(
preparedInput.m_MetVec.Y())).c_str());
1490 Info(
"DiTauMassTools",
" ---------------------------------------------------------- ");
1501 const double mM =
x[0];
1502 const double mMax = par[0];
1503 const double mMean = par[1];
1504 const double mInvWidth2 = par[2];
1506 const double fitval = mMax * (1 - 4 * mInvWidth2 * std::pow(mM - mMean, 2));
1519 const int winHalfWidth,
bool debug) {
1527 for (std::vector<double>::iterator itr = histInfo.begin(); itr != histInfo.end(); ++itr) {
1536 winHalfWidth == 0)) {
1540 int max_bin = theHist->GetMaximumBin();
1541 maxPos = theHist->GetBinCenter(max_bin);
1544 prob = theHist->GetBinContent(max_bin) / double(theHist->GetEntries());
1551 int hNbins = theHist->GetNbinsX();
1556 int max_bin = theHist->GetMaximumBin();
1557 int iBinMin = max_bin - winHalfWidth;
1560 int iBinMax = max_bin + winHalfWidth;
1561 if (iBinMax > hNbins)
1562 iBinMax = hNbins - 1;
1565 for (
int iBin = iBinMin; iBin <= iBinMax; ++iBin) {
1566 const double weight = theHist->GetBinContent(iBin);
1568 sumx += weight * theHist->GetBinCenter(iBin);
1570 maxPos = sumx / sumw;
1573 prob = sumw / theHist->GetEntries();
1583 Error(
"DiTauMassTools",
"%s",
1584 (
"ERROR undefined maxHistStrategy:" + std::to_string(maxHistStrategy)).c_str());
1590 int lastNonZeroBin = -1;
1591 int firstNonZeroBin = -1;
1592 double totalSumw = 0.;
1593 bool firstNullPart =
true;
1594 for (
int iBin = 0; iBin < hNbins; ++iBin) {
1595 const double weight = theHist->GetBinContent(iBin);
1597 totalSumw += weight;
1598 lastNonZeroBin = iBin;
1599 if (firstNullPart) {
1600 firstNullPart =
false;
1601 firstNonZeroBin = iBin;
1608 firstNonZeroBin = std::max(0, firstNonZeroBin - winHalfWidth - 1);
1609 lastNonZeroBin = std::min(hNbins - 1, lastNonZeroBin + winHalfWidth + 1);
1618 const int nwidth = 2 * winHalfWidth + 1;
1621 for (
int ibin = 0; ibin < nwidth; ++ibin) {
1622 winsum += theHist->GetBinContent(ibin);
1624 double winmax = winsum;
1627 int iBinL = firstNonZeroBin;
1628 int iBinR = iBinL + 2 * winHalfWidth;
1629 bool goingUp =
true;
1634 const double deltawin = theHist->GetBinContent(iBinR) - theHist->GetBinContent(iBinL - 1);
1640 if (winsum > winmax) {
1643 max_bin = (iBinR + iBinL) / 2 - 1;
1654 }
while (iBinR < lastNonZeroBin);
1657 int iBinMin = max_bin - winHalfWidth;
1660 int iBinMax = max_bin + winHalfWidth;
1661 if (iBinMax >= hNbins)
1662 iBinMax = hNbins - 1;
1665 for (
int iBin = iBinMin; iBin <= iBinMax; ++iBin) {
1666 const double weight = theHist->GetBinContent(iBin);
1668 sumx += weight * theHist->GetBinCenter(iBin);
1671 double maxPosWin = -1.;
1674 maxPosWin = sumx / sumw;
1677 prob = sumw / totalSumw;
1681 const double h_rms = theHist->GetRMS(1);
1685 double numerator = 0;
1686 double denominator = 0;
1687 bool nullBin =
false;
1689 for (
int i = iBinMin; i < iBinMax; ++i) {
1690 double binError = theHist->GetBinError(i);
1691 if (binError < 1e-10) {
1694 double binErrorSquare = std::pow(binError, 2);
1695 num = theHist->GetBinContent(i) / (binErrorSquare);
1696 numerator = numerator + num;
1697 denominator = denominator + (1 / (binErrorSquare));
1699 if (numerator < 1e-10 || denominator < 1e-10 || nullBin ==
true) {
1702 histInfo[
HistInfo::MEANBIN] = sqrt(1 / denominator) / (numerator / denominator);
1715 const double binWidth = theHist->GetBinCenter(2) - theHist->GetBinCenter(1);
1716 double fitWidth = (winHalfWidth + 0.5) *
binWidth;
1729 TString fitOption =
debug ?
"QS" :
"QNS";
1732 m_fFitting->SetParameters(sumw / winHalfWidth, maxPos, 0.0025);
1735 TFitResultPtr fitRes =
1736 theHist->Fit(
m_fFitting, fitOption,
"", maxPos - fitWidth, maxPos + fitWidth);
1738 double maxPosFit = -1.;
1740 if (
int(fitRes) == 0) {
1743 const double mMax = fitRes->Parameter(0);
1744 const double mMean = fitRes->Parameter(1);
1745 const double mInvWidth2 = fitRes->Parameter(2);
1746 double mMaxError = fitRes->ParError(0);
1748 double mMeanError = fitRes->ParError(1);
1750 double mInvWidth2Error = fitRes->ParError(2);
1753 mInvWidth2Error = 0.;
1754 const double c = mMax * (1 - 4 * mMean * mMean * mInvWidth2);
1755 const double b = 8 * mMax * mMean * mInvWidth2;
1756 const double a = -4 * mMax * mInvWidth2;
1762 const double h_discri = b * b - 4 *
a * c;
1764 const double sqrth_discri = sqrt(h_discri);
1765 const double h_fitLength = sqrth_discri /
a;
1772 maxPosFit = -b / (2 *
a);
1776 if (maxPosFit >= 0. and std::abs(maxPosFit - maxPosWin) < 0.8 * fitWidth) {
1794 const double &M_nu1,
1795 const double &M_nu2) {
1801 const int solution =
NuPsolutionV3(M_nu1, M_nu2, phi1, phi2, nsol1, nsol2);
1820 const int nsol1,
const int nsol2,
1821 const double &Mvis,
const double &Meff)
1827 Error(
"DiTauMassTools",
"%s",
1828 (
"refineSolutions ERROR probFinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1831 Error(
"DiTauMassTools",
"%s",
1832 (
"refineSolutions ERROR mtautauSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1835 Error(
"DiTauMassTools",
"%s",
1836 (
"refineSolutions ERROR nu1FinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1839 Error(
"DiTauMassTools",
"%s",
1840 (
"refineSolutions ERROR nu2FinalSolVec.size() should be " + std::to_string(
m_nsolfinalmax))
1843 Error(
"DiTauMassTools",
"%s", (
"refineSolutions ERROR nsol1 " + std::to_string(nsol1) +
1844 " > nsolmax !" + std::to_string(
m_nsolmax))
1847 Error(
"DiTauMassTools",
"%s", (
"refineSolutions ERROR nsol1 " + std::to_string(nsol2) +
1848 " > nsolmax !" + std::to_string(
m_nsolmax))
1854 Prob->apply(
preparedInput, -99, -99, PtEtaPhiMVector(0, 0, 0, 0), PtEtaPhiMVector(0, 0, 0, 0),
1855 PtEtaPhiMVector(0, 0, 0, 0), PtEtaPhiMVector(0, 0, 0, 0),
true,
false,
false);
1857 for (
int j1 = 0; j1 < nsol1; ++j1) {
1867 const int pickInt = std::abs(10000 *
m_Phi1);
1868 const int pickDigit = pickInt - 10 * (pickInt / 10);
1876 nuvec1_tmpj.SetCoordinates(nuvec1_tmpj.Pt(), nuvec1_tmpj.Eta(), nuvec1_tmpj.Phi(), M_nu1);
1877 tauvecsol1j.SetPxPyPzE(0., 0., 0., 0.);
1878 tauvecsol1j += nuvec1_tmpj;
1883 PtEtaPhiMVector(0, 0, 0, 0), nuvec1_tmpj,
1884 PtEtaPhiMVector(0, 0, 0, 0),
false,
true,
false);
1888 for (
int j2 = 0; j2 < nsol2; ++j2) {
1899 const int pickInt = std::abs(10000 *
m_Phi2);
1900 const int pickDigit = pickInt - 10 * int(pickInt / 10);
1908 nuvec2_tmpj.SetCoordinates(nuvec2_tmpj.Pt(), nuvec2_tmpj.Eta(), nuvec2_tmpj.Phi(), M_nu2);
1909 tauvecsol2j.SetPxPyPzE(0., 0., 0., 0.);
1910 tauvecsol2j += nuvec2_tmpj;
1916 PtEtaPhiMVector(0, 0, 0, 0), nuvec2_tmpj,
false,
true,
false);
1920 if (tauvecprob1j == 0.)
1922 if (tauvecprob2j == 0.)
1925 double totalProb = 1.;
1938 (constProb * tauvecprob1j * tauvecprob2j *
1942 if (totalProb <= 0) {
1944 Warning(
"DiTauMassTools",
"%s",
1945 (
"null proba solution, rejected "+std::to_string(totalProb)).c_str());
1952 Error(
"DiTauMassTools",
"%s",
1953 (
"refineSolutions ERROR nsol getting larger than nsolfinalmax!!! " +
1956 Error(
"DiTauMassTools",
"%s",
1957 (
" j1 " + std::to_string(j1) +
" j2 " + std::to_string(j2) +
" nsol1 " +
1958 std::to_string(nsol1) +
" nsol2 " + std::to_string(nsol2))
1972 nu1Final.SetPxPyPzE(nuvec1_tmpj.Px(), nuvec1_tmpj.Py(), nuvec1_tmpj.Pz(), nuvec1_tmpj.E());
1973 nu2Final.SetPxPyPzE(nuvec2_tmpj.Px(), nuvec2_tmpj.Py(), nuvec2_tmpj.Pz(), nuvec2_tmpj.E());
1981 if (ngoodsol1 == 0) {
1984 if (ngoodsol2 == 0) {
1991 const PtEtaPhiMVector &nu1,
1992 const PtEtaPhiMVector &vis2,
1993 const PtEtaPhiMVector &nu2,
const double &mmc_mass,
1994 const double &vis_mass,
const double &eff_mass,
1995 const double &dphiTT) {
2006 const double MrecoMvis = mmc_mass / vis_mass;
2007 if (MrecoMvis > 2.6)
2009 const double MrecoMeff = mmc_mass / eff_mass;
2010 if (MrecoMeff > 1.9)
2012 const double e1p1 = nu1.E() / vis1.P();
2013 const double e2p2 = nu2.E() / vis2.P();
2014 if ((e1p1 + e2p2) > 4.5)
2033 if (
Prob->GetUseHT()) {
2034 const double MrecoMvis = mmc_mass / vis_mass;
2035 const double MrecoMeff = mmc_mass / eff_mass;
2036 const double x = dphiTT > 1.5 ? dphiTT : 1.5;
2037 if ((MrecoMeff + MrecoMvis) > 5.908 - 1.881 *
x + 0.2995 *
x *
x)
2050 double totalProbSumSol = 0.;
2051 double totalProbSumSolOld = 0.;
2052 bool firstPointWithSol =
false;
2054 for (
int isol = 0; isol <
m_nsol; ++isol) {
2059 bool notSureToKeep =
true;
2063 notSureToKeep =
false;
2070 firstPointWithSol =
true;
2082 if (notSureToKeep) {
2085 for (
int isol = 0; isol <
m_nsolOld; ++isol) {
2091 if (!firstPointWithSol && totalProbSumSolOld <= 0.) {
2092 Error(
"DiTauMassTools",
"%s",
2093 (
" ERROR null old probability !!! " + std::to_string(totalProbSumSolOld) +
" nsolOld " +
2097 }
else if (totalProbSumSol > totalProbSumSolOld) {
2102 }
else if (totalProbSumSol < totalProbSumSolOld * 1E-6) {
2106 }
else if (
m_nsol <= 0) {
2113 reject = (uMC > totalProbSumSol / totalProbSumSolOld);
2138 bool fillSolution =
true;
2139 bool oldToBeUsed =
false;
2147 fillSolution =
false;
2161 if (!firstPointWithSol) {
2162 fillSolution =
true;
2165 fillSolution =
false;
2172 if (!fillSolution) {
2173 if (firstPointWithSol) {
2176 for (
int isol = 0; isol <
m_nsol; ++isol) {
2188 double solSum2 = 0.;
2190 for (
int isol = 0; isol <
m_nsol; ++isol) {
2194 const PtEtaPhiMVector *pnuvec1_tmpj;
2195 const PtEtaPhiMVector *pnuvec2_tmpj;
2208 const PtEtaPhiMVector &nuvec1_tmpj = *pnuvec1_tmpj;
2209 const PtEtaPhiMVector &nuvec2_tmpj = *pnuvec2_tmpj;
2212 solSum2 += mtautau * mtautau;
2234 if (mtautau != 0. && weight != 0.)
2299 for (
int isol = 0; isol <
m_nsol; ++isol) {
2308 const double solRMS = sqrt(solSum2 /
m_nsol - std::pow(solSum /
m_nsol, 2));
2501 Info(
"DiTauMassTools",
" in m_meanbinToBeEvaluated && m_iterNsuc==500 ");
2516 double stopdouble = 500 * std::pow((meanbin /
m_meanbinStop), 2);
2517 int stopint = stopdouble;
2648 PtEtaPhiMVector Met4vec;
2721 const double &P_tau) {
2723#ifndef WITHDTHETA3DLIM
2725 if (limit_code == 0)
2727 if (limit_code == 1)
2729 if (limit_code == 2)
2734 if (limit_code == 0)
2736 double par[3] = {0.0, 0.0, 0.0};
2738 if (tau_type == 8) {
2739 if (limit_code == 0)
2745 if (limit_code == 1)
2751 if (limit_code == 2)
2759 if (tau_type >= 0 && tau_type <= 2) {
2760 if (limit_code == 0)
2764 par[2] = -0.0004859;
2766 if (limit_code == 1)
2772 if (limit_code == 2)
2780 if (tau_type >= 3 && tau_type <= 5) {
2781 if (limit_code == 0)
2785 par[2] = -0.0009458;
2787 if (limit_code == 1)
2793 if (limit_code == 2)
2801 if (std::abs(P_tau + par[1]) > 0.0)
2802 limit = par[0] / (P_tau + par[1]) + par[2];
2803 if (limit_code == 0) {
2806 }
else if (limit > 0.03) {
2810 if (limit < 0.0 || limit > 0.5 * TMath::Pi()) {
2811 limit = 0.5 * TMath::Pi();
2812 }
else if (limit < 0.05 && limit > 0.0) {
2841 if (LFVMode == -1) {
2843 }
else if (LFVMode != -2) {
2855 PtEtaPhiMVector fixedtau1;
2856 fixedtau1.SetCoordinates(tlvTau1.Pt() /
GEV, tlvTau1.Eta(), tlvTau1.Phi(), tlvTau1.M() /
GEV);
2857 PtEtaPhiMVector fixedtau2;
2858 fixedtau2.SetCoordinates(tlvTau2.Pt() /
GEV, tlvTau2.Eta(), tlvTau2.Phi(), tlvTau2.M() /
GEV);
2865 if (mmcType1 == 8 && mmcType2 == 8) {
2867 }
else if (mmcType1 >= 0 && mmcType1 <= 5 && mmcType2 >= 0 && mmcType2 <= 5) {
2873 Info(
"DiTauMassTools",
"%s", (
"running for tau types "+std::to_string(
preparedInput.m_type_visTau1)+
" "+std::to_string(
preparedInput.m_type_visTau2)).c_str());
2877 Info(
"DiTauMassTools",
"%s", (
"passing SumEt="+std::to_string(
met->sumet() /
GEV)).c_str());
2883 Error(
"DiTauMassTools",
"MMCCalibrationSet has not been set !. Please use "
2884 "fMMC.SetCalibrationSet(MMCCalibrationSet::MMC2019) or fMMC.SetCalibrationSet(MMCCalibrationSet::MMC2024)"
2919 for (
unsigned int i = 0; i <
preparedInput.m_jet4vecs.size(); i++) {
2926 Info(
"DiTauMassTools",
"correcting sumET");
3023 Info(
"DiTauMassTools",
"Substracting pt1 from sumEt");
3030 Info(
"DiTauMassTools",
"Substracting pt2 from sumEt");
3042 Prob->SetUseTauProbability(
true);
3045 Prob->SetUseTauProbability(
false);
3062 Prob->SetUseTauProbability(
false);
3064 Prob->SetUseTauProbability(
true);
3065 Prob->SetUseMnuProbability(
false);
3070 if (
Prob->GetUseHT())
3073 double HtOffset = 0.;
3078 HtOffset = 87.5 - 27.0 *
x;
3097 float hEmax = 3000.0;
3099 m_fMEtP_all = std::make_shared<TH1F>(
"MEtP_h1",
"M", hNbins, -100.0,
3101 m_fMEtL_all = std::make_shared<TH1F>(
"MEtL_h1",
"M", hNbins, -100.0,
3103 m_fMnu1_all = std::make_shared<TH1F>(
"Mnu1_h1",
"M", hNbins, 0.0,
3105 m_fMnu2_all = std::make_shared<TH1F>(
"Mnu2_h1",
"M", hNbins, 0.0,
3107 m_fPhi1_all = std::make_shared<TH1F>(
"Phi1_h1",
"M", hNbins, -10.0,
3109 m_fPhi2_all = std::make_shared<TH1F>(
"Phi2_h1",
"M", hNbins, -10.0,
3132 float hEmax = 3000.0;
3134 m_fMmass_split1 = std::make_shared<TH1F>(
"mass_h1_1",
"M", hNbins, 0.0, hEmax);
3135 m_fMEtP_split1 = std::make_shared<TH1F>(
"MEtP_h1_1",
"M", hNbins, -100.0, 100.0);
3136 m_fMEtL_split1 = std::make_shared<TH1F>(
"MEtL_h1_1",
"M", hNbins, -100.0, 100.0);
3137 m_fMnu1_split1 = std::make_shared<TH1F>(
"Mnu1_h1_1",
"M", hNbins, 0.0, hEmax);
3138 m_fMnu2_split1 = std::make_shared<TH1F>(
"Mnu2_h1_1",
"M", hNbins, 0.0, hEmax);
3139 m_fPhi1_split1 = std::make_shared<TH1F>(
"Phi1_h1_1",
"M", hNbins, -10.0, 10.0);
3140 m_fPhi2_split1 = std::make_shared<TH1F>(
"Phi2_h1_1",
"M", hNbins, -10.0, 10.0);
3141 m_fMmass_split2 = std::make_shared<TH1F>(
"mass_h1_2",
"M", hNbins, 0.0, hEmax);
3142 m_fMEtP_split2 = std::make_shared<TH1F>(
"MEtP_h1_2",
"M", hNbins, -100.0, 100.0);
3143 m_fMEtL_split2 = std::make_shared<TH1F>(
"MEtL_h1_2",
"M", hNbins, -100.0, 100.0);
3144 m_fMnu1_split2 = std::make_shared<TH1F>(
"Mnu1_h1_2",
"M", hNbins, 0.0, hEmax);
3145 m_fMnu2_split2 = std::make_shared<TH1F>(
"Mnu2_h1_2",
"M", hNbins, 0.0, hEmax);
3146 m_fPhi1_split2 = std::make_shared<TH1F>(
"Phi1_h1_2",
"M", hNbins, -10.0, 10.0);
3147 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.
constexpr int pow(int base, int exp) noexcept
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.