19 m_ignoreInputChecks(false),
26 declareProperty(
"EgammaCalibAndSmearingTool",
m_energyRescaler = ToolHandle<CP::IEgammaCalibrationAndSmearingTool>(
"CP::EgammaCalibrationAndSmearingTool"));
27 declareProperty(
"MuonCalibrationAndSmearingTool",
m_mu_resolSFTool = ToolHandle<CP::IMuonCalibrationAndSmearingTool>(
"CP::MuonCalibrationAndSmearingTool"));
40 ATH_MSG_ERROR (
"initialize: unable to retrieve EgammaCalibrationAndSmearingTool");
41 return StatusCode::FAILURE;
45 ATH_MSG_ERROR (
"initialize: unable to retrieve MuonCalibrationAndSmearingTool");
46 return StatusCode::FAILURE;
50 return StatusCode::SUCCESS;
60 return StatusCode::FAILURE;
66 return StatusCode::SUCCESS;
84 const TLorentzVector& fsr4Vec,
88 ATH_MSG_DEBUG (
"addFSRParticle: *** 4vecFsr: " << fsr4Vec.Pt() <<
"/" << fsr4Vec.Eta() <<
"/" << fsr4Vec.Phi());
100 e_res =
m_energyRescaler->resolution( fsr4Vec.E(), fsr4Vec.Eta(), cl_etaCalo, phType)*fsr4Vec.E();
103 ATH_MSG_ERROR(
"addFSRParticle: - cannot find EgammaCalibrationAndSmearingTool. ");
104 ATH_MSG_ERROR(
"addFSRParticle: - please set property 'EgammaCalibAndSmearingToolName' with the name of your EgammaCalibrationAndSmearingTool - default is 'EgammaCalibrationAndSmearingTool'. ");
108 photonCovarianceMatrix.setZero();
109 photonCovarianceMatrix(
d0,
d0) = 0.000001;
110 photonCovarianceMatrix(
z0,
z0) = 0.000001;
111 photonCovarianceMatrix(
phi0,
phi0) = 0.000001;
112 photonCovarianceMatrix(
theta,
theta) = 0.000001;
114 photonCovarianceMatrix(
d0,
z0) = 0;
115 photonCovarianceMatrix(
d0,
phi0) = 0;
116 photonCovarianceMatrix(
d0,
theta) = 0;
117 photonCovarianceMatrix(
d0,
qOverP) = 0;
118 photonCovarianceMatrix(
z0,
phi0) = 0;
119 photonCovarianceMatrix(
z0,
theta) = 0;
120 photonCovarianceMatrix(
z0,
qOverP) = 0;
125 ATH_MSG_DEBUG (
"addFSRParticle: FSR calib type,e, e_res " << phType <<
" " << fsr4Vec.E() <<
" " << e_res);
128 for (
int ii = 0; ii < 5; ii++)
129 for (
int jj = ii + 1; jj < 5; jj++)
130 photonCovarianceMatrix(jj, ii) = photonCovarianceMatrix(ii, jj);
138 input.addConstituent_FourVector_d0z0PhiThetaP(fsr4Vec, photonCovarianceMatrix, covarXYZ, isOK);
154 TLorentzVector mu4vec;
163 bool set4vec =
false;
166 track =
mu.trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
168 ATH_MSG_ERROR(
"addParticle: - could not get muonSpectrometerPt from muon. Please applyCorrection with the MuonCalibAndSmearTool");
170 ATH_MSG_ERROR(
"addParticle: - Combined muon is missing MS track particle. Using combined track particle");
171 track =
mu.primaryTrackParticle();
173 mu4vec.SetPtEtaPhiM(muonSpectrometerPt(
mu),
track->eta(),
track->phi(),
mu.m());
178 track =
mu.trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
180 ATH_MSG_ERROR(
"addParticle: - could not get innerDetectorPt from muon. Please applyCorrection with the MuonCalibAndSmearTool");
181 mu4vec.SetPtEtaPhiM(innerDetectorPt(
mu),
track->eta(),
track->phi(),
mu.m());
187 if (!set4vec) mu4vec.SetPtEtaPhiM(
mu.pt(),
mu.eta(),
mu.phi(),
mu.m());
190 ATH_MSG_ERROR(
"addParticle: - could not get track particle for muon");
194 ATH_MSG_DEBUG (
"addParticle: *** 4vecMu: " << mu4vec.Pt() <<
"/" << mu4vec.Eta() <<
"/" << mu4vec.Phi());
243 covmatrix(
d0,
d0) =
track->definingParametersCovMatrix()(
d0,
d0);
244 covmatrix(
z0,
z0) =
track->definingParametersCovMatrix()(
z0,
z0);
248 covmatrix(
d0,
z0) =
track->definingParametersCovMatrix()(
d0,
z0);
261 <<
" " <<
track->definingParametersCovMatrix()(
d0,
d0)
262 <<
" " <<
track->definingParametersCovMatrix()(
z0,
z0)
266 <<
" " <<
track->definingParametersCovMatrix()(
d0,
z0)
267 <<
" " <<
track->definingParametersCovMatrix()(
d0,
phi0)
268 <<
" " <<
track->definingParametersCovMatrix()(
d0,
theta)
269 <<
" " <<
track->definingParametersCovMatrix()(
d0,
qOverP)*muSF
270 <<
" " <<
track->definingParametersCovMatrix()(
z0,
phi0)
271 <<
" " <<
track->definingParametersCovMatrix()(
z0,
theta)
272 <<
" " <<
track->definingParametersCovMatrix()(
z0,
qOverP)*muSF
277 for (
int ii = 0; ii < 5; ii++)
278 for (
int jj = ii+1; jj < 5; jj++)
279 covmatrix(jj,ii) = covmatrix(ii,jj);
284 double P = mu4vec.P();
291 jacobian0(4,4) = -
P*
P;
293 AmgMatrix(5,5) newmatrix = jacobian0.transpose() * covmatrix * jacobian0;
303 input.addConstituent_FourVector_d0z0PhiThetaP(mu4vec, newmatrix, covarXYZ, isOK);
314 float el_E_res = elEnergyRes;
325 ATH_MSG_ERROR(
"addParticle: - ERROR could not get track particle for electron");
329 ATH_MSG_DEBUG (
"addParticle: *** 4vecEl: " <<
el.pt() <<
"/" <<
el.eta() <<
"/" <<
el.phi());
333 covmatrix(
d0,
d0) =
track->definingParametersCovMatrix()(
d0,
d0);
334 covmatrix(
z0,
z0) =
track->definingParametersCovMatrix()(
z0,
z0);
338 covmatrix(
d0,
z0) =
track->definingParametersCovMatrix()(
d0,
z0);
350 <<
" " << el_E_res <<
" " <<
el.e()
351 <<
" " <<
track->definingParametersCovMatrix()(
d0,
d0)
352 <<
" " <<
track->definingParametersCovMatrix()(
z0,
z0)
355 <<
" " <<
track->definingParametersCovMatrix()(
d0,
z0)
356 <<
" " <<
track->definingParametersCovMatrix()(
d0,
phi0)
357 <<
" " <<
track->definingParametersCovMatrix()(
d0,
theta)
358 <<
" " <<
track->definingParametersCovMatrix()(
z0,
phi0)
359 <<
" " <<
track->definingParametersCovMatrix()(
z0,
theta)
364 for(
int ii=0;ii<5;ii++)
365 for(
int jj=ii+1;jj<5;jj++)
366 covmatrix(jj,ii) = covmatrix(ii,jj);
374 input.addConstituent_FourVector_d0z0PhiThetaP(
el.p4(), covmatrix, covarXYZ, isOK);
392 ATH_MSG_ERROR(
"massFitInterface: Found number of input particles less than 2");
410 for (
unsigned int iobj = 0; iobj <
m_nobj; iobj++)
419 m_covarianceInit(
i + 3*iobj, j + 3*iobj) = (theInput.getCovarianceCartesian(iobj))(
i + 2, j + 2);
422 for(
unsigned int i=0;
i<dimension;
i++)
425 for(
unsigned int j=0;j<dimension;j++)
439 p =
new double *[
rows] ;
440 for(
int i = 0 ;
i <
rows ;
i++ )
443 for(
unsigned int iobj=0; iobj<
m_nobj; iobj++)
449 p[3][iobj] +=
p[
i][iobj]*
p[
i][iobj];
451 p[3][iobj] = sqrt(
p[3][iobj]);
457 for(
unsigned int ij=0;ij<
m_nobj;ij++)
464 for(
int i = 0 ;
i <
rows ;
i++ )
468 double initMass = Etot * Etot - Xtot * Xtot - Ytot * Ytot - Ztot * Ztot;
469 initMass = sqrt(initMass);
471 double sig = MassResol;
472 double xLeft = initMass;
480 if (dLinitL * dLinitR < 0.) {
481 while (xRight - xLeft > 1.) {
482 double xM = (xRight + xLeft) / 2.;
484 if (dL * dLinitL < 0.) {
492 return (xLeft + xRight) / 2.;
494 if (dLinitL > dLinitR)
508 p =
new double *[
rows] ;
509 for(
int i = 0 ;
i <
rows ;
i++ )
512 for(
unsigned int iobj=0; iobj<
m_nobj; iobj++) {
514 for(
int i=0;
i<3;
i++) {
516 p[3][iobj] +=
p[
i][iobj]*
p[
i][iobj];
518 p[3][iobj] = sqrt(
p[3][iobj]);
524 for(
unsigned int ij=0;ij<
m_nobj;ij++) {
531 double initMass = etot * etot - xtot * xtot - ytot * ytot - ztot * ztot;
532 initMass = sqrt(initMass);
535 jacobianMass.setZero();
536 for(
unsigned int ii=0;ii<
m_nobj;ii++) {
537 jacobianMass(3*ii + 0, 0) = (2.*(etot) *
p[0][ii] /
p[3][ii] - 2.* xtot);
538 jacobianMass(3*ii + 1, 0) = (2.*(etot) *
p[1][ii] /
p[3][ii] - 2.* ytot);
539 jacobianMass(3*ii + 2, 0) = (2.*(etot) *
p[2][ii] /
p[3][ii] - 2.* ztot);
548 double sig = sigm(0, 0);
552 double MassResol =
sig;
553 double maxmass = initMass;
557 double max = -(maxmass - initMass) * (maxmass - initMass) / 2. / MassResol / MassResol
560 for (
int i = 1;
i < 401;
i++) {
561 double ytest = initMass + (
m_conMass - initMass) / 400 *
i;
563 double val = -(ytest - initMass) * (ytest - initMass) / 2. / MassResol / MassResol
574 for(
int i = 0 ;
i <
rows ;
i++ )
590 ATH_MSG_WARNING(
"ConstraintFit::massFitRun()(cont) Following H->4l group decision (Feb 1, 2013), this event will not be fit");
591 ATH_MSG_WARNING(
"ConstraintFit::massFitRun()(cont) To bypass this behaviour set the ingore flag");
593 std::vector<TLorentzVector> particleList;
606 for(
unsigned int iobj=0;iobj<
m_nobj;iobj++)
607 for(
int ii=0;ii<5;ii++)
608 for(
int jj=0;jj<5;jj++)
609 covOut(ii+5*iobj,jj+5*iobj) =
m_theInput.getCovarianceCartesian(iobj)(ii,jj);
615 covard0z0PhiThetaP.setZero();
618 output.setFitOutput(particleList, covOut, covard0z0PhiThetaP);
644 std::vector<TLorentzVector> particleList;
658 for(
unsigned int iobj=0;iobj<
m_nobj;iobj++)
659 for(
int ii=0;ii<2;ii++)
660 for(
int jj=0;jj<2;jj++)
661 covOut(ii+5*iobj,jj+5*iobj) =
m_theInput.getCovarianceCartesian(iobj)(ii,jj);
662 for(
unsigned int iobj=0;iobj<
m_nobj;iobj++)
663 for(
int ii=2;ii<5;ii++)
664 for(
int jj=2;jj<5;jj++)
672 for(
unsigned int iobj1=0;iobj1<
m_nobj;iobj1++) {
673 for(
unsigned int iobj2=0;iobj2<
m_nobj;iobj2++) {
674 if(iobj1 == iobj2)
continue;
675 for(
int ii=2;ii<5;ii++)
676 for(
int jj=2;jj<5;jj++)
686 covard0z0PhiThetaP.setZero();
689 output.setFitOutput(particleList, covOut, covard0z0PhiThetaP);
700 for(
unsigned int iobj = 0; iobj <
m_nobj; iobj++) {
703 double massInit =
aa.M();
711 for(
unsigned int iobj = 0; iobj <
m_nobj; iobj++) {
712 for(
int ii = 0; ii < 5; ii++) {
713 for(
int jj = 0; jj < 5; jj++) {
714 covOut(ii+5*iobj, jj+5*iobj) =
m_theInput.getCovarianceCartesian(iobj)(ii, jj);
725 std::vector<double> resolInit;
726 std::vector<double> resolFinal;
727 std::vector<double> resolFinalnew;
728 resolInit.reserve(
m_nobj);
729 resolFinal.reserve(
m_nobj);
730 resolFinalnew.reserve(
m_nobj);
731 double sumResolInit=0.;
733 for(
unsigned int iobj = 0; iobj <
m_nobj; iobj++) {
737 resolInit.push_back((
m_theInput.getConstituentCovariance(iobj))(4,4));
743 output.getConstituentCovarianced0z0PhiThetaP(iobj, tmpMtx);
744 resolFinal.push_back(tmpMtx(4,4));
749 sumResolInit += resolInit[iobj];
756 for(
unsigned int iobj=0;iobj<
m_nobj;iobj++) {
757 resolFinalnew.push_back( resolFinal[iobj] + constraintWidthSquare *
758 resolInit[iobj]*resolInit[iobj]
759 /sumResolInit/sumResolInit );
760 covOut(4+5*iobj,4+5*iobj) = covOut(4+5*iobj,4+5*iobj)*resolFinalnew[iobj]/resolFinal[iobj];
761 covOut(3+5*iobj,3+5*iobj) = covOut(3+5*iobj,3+5*iobj)*resolFinalnew[iobj]/resolFinal[iobj];
762 covOut(2+5*iobj,2+5*iobj) = covOut(2+5*iobj,2+5*iobj)*resolFinalnew[iobj]/resolFinal[iobj];
776 output.setFitOutput(particleList, covOut, covard0z0PhiThetaP);
792 p =
new double *[
rows] ;
793 for(
int i = 0 ;
i <
rows ;
i++ )
796 for(
unsigned int iobj=0; iobj<
m_nobj; iobj++) {
800 p[
i][iobj] =
p0(
i+3*iobj, 0);
801 p[3][iobj] +=
p[
i][iobj]*
p[
i][iobj];
803 p[3][iobj] = sqrt(
p[3][iobj]);
810 for(
unsigned int ij=0;ij<
m_nobj;ij++)
817 double XYZtot[3] = {Xtot, Ytot, Ztot};
818 std::vector<double> constraintD;
819 for(
unsigned int ij=0;ij<
m_nobj;ij++)
820 for(
int ik=0;ik<3;ik++)
821 constraintD.push_back((2.*(Etot) *
p[ik][ij] /
p[3][ij] - 2.* XYZtot[ik]));
823 double constraintd = Etot * Etot - Xtot * Xtot - Ytot * Ytot - Ztot * Ztot;
824 constraintd = constraintd -
mass *
mass;
827 for(
unsigned int ij=0;ij<3*
m_nobj;ij++)
828 D(0, ij) = constraintD.at(ij);
830 d(0, 0) = constraintd;
835 DVDinverse=DVD.inverse();
841 for(
unsigned int ij=0;ij<3*
m_nobj;ij++) {
844 for(
unsigned int jk = 0; jk < 3 *
m_nobj; jk++)
847 double constraintValue =
d(0, 0);
849 for(
int i = 0 ;
i <
rows ;
i++ )
852 return constraintValue;
862 int maxIterations = 20;
864 double constraintValue = -1.e10;
866 <<
" Iterations " << iIter
869 <<
" Iteration " << iIter);
877 double maxDiff = 5.e15;
881 if (maxDiff >
diff(
i, 0))
882 maxDiff =
diff(
i, 0);
884 if ((maxDiff < 1.
e-4 && fabs(constraintValue) < 5.
e-5) || maxIterations <= iIter)
887 <<
" Iterations " << iIter
890 <<
" \n Iteration " << iIter <<
" doIter " << doIter);
895 <<
" Iterations " << iIter
898 <<
" Iteration " << iIter);
910 unsigned int nPart = nPartFirst + nPartSecond;
911 std::vector<TLorentzVector>
particles(nPart);
912 std::vector<
AmgMatrix(3,3)> covariances(nPart);
913 for (
unsigned int iobj = 0; iobj < firstInput.
getNConstituents(); ++iobj) {
914 covariances[iobj].setZero();
918 for (
unsigned int iobj = 0; iobj < secondInput.
getNConstituents(); ++iobj) {
919 covariances[iobj + nPartFirst].setZero();
934 unsigned int nPart = nPartFirst + nPartSecond;
935 std::vector<TLorentzVector>
particles(nPart);
936 std::vector<
AmgMatrix(3,3)> covariances(nPart);
938 covariances[iobj].setZero();
942 for (
unsigned int iobj = 0; iobj < extraInput.
getNConstituents(); ++iobj) {
943 covariances[iobj + nPartFirst].setZero();
959 unsigned int nPart = nPartFirst + nPartSecond;
960 std::vector<TLorentzVector>
particles(nPart);
961 std::vector<
AmgMatrix(3,3)> covariances(nPart);
963 covariances[iobj].setZero();
967 for (
unsigned int iobj = 0; iobj < secondFitOutput.
getNConstituents(); ++iobj) {
968 covariances[iobj + nPartFirst].setZero();
977 const std::vector<
AmgMatrix(3,3)>& covariances)
981 if (
particles.size() != covariances.size()) {
982 ATH_MSG_ERROR(
"getMassError: Number of particles is not equal to the number of covariance matrices");
989 TLorentzVector combv;
991 double invmass = combv.M();
997 jacobianNPtoM.setZero();
998 jacobianNPtoM(0,0) = -1.*combv.Px()/invmass;
999 jacobianNPtoM(0,1) = -1.*combv.Py()/invmass;
1000 jacobianNPtoM(0,2) = -1.*combv.Pz()/invmass;
1001 jacobianNPtoM(0,3) = combv.E()/invmass;
1012 const AmgMatrix(3,3)& covPhiThetaP = covariances[iobj];
1014 ATH_MSG_VERBOSE (
"getMassError: 1.3 covPhiThetaP\n " << covPhiThetaP);
1016 double theta = lv.Theta();
1017 double phi = lv.Phi();
1022 ATH_MSG_VERBOSE (
"getMassError: 2.1 iobj " << iobj <<
"covPhiThetaP\n" << covPhiThetaP);
1026 jacobian1.setZero();
1027 jacobian1(0,0) = 1.;
1028 jacobian1(1,1) = -1*(1./
sin(
theta));
1029 jacobian1(2,2) = 1.;
1030 AmgMatrix(3,3) covPhiEtaP = jacobian1 * covPhiThetaP * jacobian1.transpose();
1038 covEEtaPhiM.setZero();
1039 for(
int i = 0;
i < 3;
i++) {
1040 for(
int j = 0; j < 3; j++) {
1041 covEEtaPhiM(
i,j) = covEEtaPhiM(j,
i) = covPhiEtaP(2-
i,2-j);
1049 jacobian2.setZero();
1066 AmgMatrix(4,4) covPxPyPzE = jacobian2 * covEEtaPhiM * jacobian2.transpose();
1073 Amg::MatrixX em = jacobianNPtoM * covPxPyPzE * jacobianNPtoM.transpose();
1074 masserror += em(0,0);
1081 if (masserror < 0.) {
1082 ATH_MSG_WARNING(
"getMassError: Mass covariance element less than zero! Returning 1E11 ...");
1085 return sqrt(masserror);
1096 ATH_MSG_WARNING(
"ZMassConstraint::ConstraintFit::doSanityChecksOnCovariance:: Fractional uncertainty on P = "
1097 << sqrt(covar(
qP,
qP))/
vector.P() <<
" is > 1 ...this is not ok...");
1103 ATH_MSG_WARNING(
"ZMassConstraint::ConstraintFit::doSanityChecksOnCovariance:: Uncertainty on Theta = "
1104 << covar(
theta,
theta) <<
" is > 10^-2 ...this is not ok");
1108 ATH_MSG_WARNING(
"ZMassConstraint::ConstraintFit::doSanityChecksOnCovariance:: Uncertainty on Phi = "
1109 << covar(
phi0,
phi0) <<
" is > 10^-2 ...this is not ok");
1112 for(
int i=0;
i<5;
i++) {
1113 for(
int j=0;j<5;j++) {
1115 if(fabs(covar(
i,j))/sqrt(covar(
i,
i))/sqrt(covar(j,j)) > 1.) {
1116 ATH_MSG_WARNING(
"ZMassConstraint::ConstraintFit::doSanityChecksOnCovariance:: Off-diagonal term "
1117 <<
i <<
" " << j <<
" is > 1 - doesn't look ok");
1128 const AmgMatrix(5,5)& covard0z0PhiThetaP,
1132 double phi = fourVec.Phi();
1133 double theta = fourVec.Theta();
1134 double P = fourVec.P();
1140 jacobian(2,2) = -
P * TMath::Sin(
theta) * TMath::Sin(phi);
1141 jacobian(2,3) =
P * TMath::Sin(
theta) * TMath::Cos(phi);
1142 jacobian(3,2) =
P * TMath::Cos(
theta) * TMath::Cos(phi);
1143 jacobian(3,3) =
P * TMath::Cos(
theta) * TMath::Sin(phi);
1144 jacobian(3,4) = -
P * TMath::Sin(
theta);
1145 jacobian(4,2) = TMath::Sin(
theta) * TMath::Cos(phi);
1146 jacobian(4,3) = TMath::Sin(
theta) * TMath::Sin(phi);
1147 jacobian(4,4) = TMath::Cos(
theta);
1149 covarXYZ = jacobian.transpose() * covard0z0PhiThetaP * jacobian;
1162 unsigned int matrixSize = 5 * particleList.size();
1166 for(
unsigned int ii = 0; ii < particleList.size(); ii++) {
1167 double phi = particleList.at(ii).Phi();
1168 double theta = particleList.at(ii).Theta();
1169 double P = particleList.at(ii).P();
1170 Jacobian( 5*ii, 5*ii) = 1.;
1171 Jacobian(1 + 5*ii, 1 + 5*ii) = 1.;
1173 Jacobian(2 + 5*ii, 2 + 5*ii) = -
P * TMath::Sin(
theta) * TMath::Sin(phi);
1174 Jacobian(2 + 5*ii, 3 + 5*ii) =
P * TMath::Sin(
theta) * TMath::Cos(phi);
1175 Jacobian(3 + 5*ii, 2 + 5*ii) =
P * TMath::Cos(
theta) * TMath::Cos(phi);
1176 Jacobian(3 + 5*ii, 3 + 5*ii) =
P * TMath::Cos(
theta) * TMath::Sin(phi);
1177 Jacobian(3 + 5*ii, 4 + 5*ii) = -
P * TMath::Sin(
theta);
1178 Jacobian(4 + 5*ii, 2 + 5*ii) = TMath::Sin(
theta) * TMath::Cos(phi);
1179 Jacobian(4 + 5*ii, 3 + 5*ii) = TMath::Sin(
theta) * TMath::Sin(phi);
1180 Jacobian(4 + 5*ii, 4 + 5*ii) = TMath::Cos(
theta);
1184 Jacobianinverse=Jacobian.inverse();
1185 covard0z0PhiThetaP = Jacobianinverse.transpose() * covarXYZ * Jacobianinverse;
1191 double eta_calo = 0;
1194 ATH_MSG_ERROR(
"retrieve_eta_calo - unable to cast to Egamma");
1202 eta_calo = etaCaloAcc(cluster);
1205 ATH_MSG_ERROR(
"retrieve_eta_calo - etaCalo not available as auxilliary variable");
1207 eta_calo = cluster.
eta();