510 float detectorEta =
jet.getAttribute<
float>(
"DetectorEta");
511 double absdetectorEta = fabs(detectorEta);
515 jetStartP4 =
jet.jetP4();
519 float mass_corr = jetStartP4.mass();
520 double pT_corr = jetStartP4.pt();
522 TLorentzVector caloCalibJet;
529 ATH_MSG_FATAL(
"Please check that the mass correction eta binning is properly set in your config file");
530 return StatusCode::FAILURE;
534 ATH_MSG_FATAL(
"Please check that the mass correction 3D histogram is provided");
535 return StatusCode::FAILURE;
547 ) && jetStartP4.mass() != 0 ) {
554 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the mass correction");
555 return StatusCode::FAILURE;
560 double massFactor = 1;
570 if (jetStartP4.mass() / jetStartP4.e() > 0)
581 if (jetStartP4.mass() / jetStartP4.Et() > 0)
592 if (jetStartP4.mass() / jetStartP4.pt() > 0)
603 if (jetStartP4.mass() / jetStartP4.Et() > 0)
614 ATH_MSG_FATAL(
"This should never be reached - if it happens, it's because a new BinningParam enum option was added, but how to handle it for the calo mass was not. Please contact the tool developer(s) to fix this.");
615 return StatusCode::FAILURE;
619 mass_corr = jetStartP4.mass() / massFactor;
621 if(!
m_pTfixed) pT_corr = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_corr*mass_corr)/std::cosh( jetStartP4.eta() );
624 caloCalibJet.SetPtEtaPhiM(pT_corr, jetStartP4.eta(), jetStartP4.phi(), mass_corr);
627 calibP4.SetPxPyPzE( caloCalibJet.Px(), caloCalibJet.Py(), caloCalibJet.Pz(), caloCalibJet.E() );
631 jet.setJetP4( calibP4 );
637 double E_corr = jetStartP4.e();
644 ATH_MSG_FATAL(
"Please check that the mass correction eta binning is properly set in your config file");
650 ATH_MSG_FATAL(
"Please check that the track assisted mass correction 3D histogram is provided");
651 return StatusCode::FAILURE;
655 std::string TrackSumMassStr =
"TrackSumMass";
656 if(
m_jetAlgo==
"AntiKt4EMTopo" ||
m_jetAlgo==
"AntiKt4LCTopo") TrackSumMassStr =
"DFCommonJets_TrackSumMass";
657 std::string TrackSumPtStr =
"TrackSumPt";
658 if(
m_jetAlgo==
"AntiKt4EMTopo" ||
m_jetAlgo==
"AntiKt4LCTopo") TrackSumPtStr =
"DFCommonJets_TrackSumPt";
659 if( !
jet.getAttribute<
float>(TrackSumMassStr,trackSumMass) ) {
662 [[maybe_unused]]
static const bool warnedOnce = [&] {
663 ATH_MSG_WARNING(
"Failed to retrieve TrackSumMass! Track Assisted Mass Correction will NOT be applied");
666 return StatusCode::SUCCESS;
668 ATH_MSG_FATAL(
"Failed to retrieve TrackSumMass! Mass Combination can NOT be performed. Aborting.");
669 return StatusCode::FAILURE;
673 if( !
jet.getAttribute<
float>(TrackSumPtStr,trackSumPt) ) {
676 [[maybe_unused]]
static const bool warnedOnce = [&] {
677 ATH_MSG_WARNING(
"Failed to retrieve TrackSumPt! Track Assisted Mass Correction will NOT be applied");
680 return StatusCode::SUCCESS;
682 ATH_MSG_FATAL(
"Failed to retrieve TrackSumPt! Mass Combination can NOT be performed. Aborting.");
683 return StatusCode::FAILURE;
686 pT_corr = jetStartP4.pt();
688 if(trackSumPt==0)
mTA = 0;
689 else{
mTA = (jetStartP4.pt()/trackSumPt)*trackSumMass;}
690 if(mTA<0 || mTA > jetStartP4.e())
mTA = 0;
695 ) && jetStartP4.mass() != 0 ) {
702 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the track assisted mass correction");
703 return StatusCode::FAILURE;
707 double mTAFactor = 1;
720 if (
mTA / jetStartP4.e() > 0)
731 if (
mTA / jetStartP4.Et() > 0)
742 if (
mTA / jetStartP4.pt() > 0)
753 if (
mTA / jetStartP4.Et() > 0)
764 ATH_MSG_FATAL(
"This should never be reached - if it happens, it's because a new BinningParam enum option was added, but how to handle it for the TA mass was not. Please contact the tool developer(s) to fix this.");
765 return StatusCode::FAILURE;
770 if(mTAFactor!=0) mass_corr =
mTA/mTAFactor;
772 ATH_MSG_FATAL(
"The calibration histogram may have a bad filling bin that is causing mTAFactor to be zero. This value should be different from zero in order to take the ratio. Please contact the tool developer to fix this since the calibration histogram may be corrupted. ");
773 return StatusCode::FAILURE;
776 if(!
m_pTfixed) pT_corr = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_corr*mass_corr)/std::cosh( jetStartP4.eta() );
777 else{E_corr = std::sqrt(jetStartP4.P()*jetStartP4.P()+mass_corr*mass_corr);}
782 if(!
m_pTfixed) pT_corr = jetStartP4.e()/std::cosh( jetStartP4.eta() );
783 else{E_corr = jetStartP4.P();}
786 TLorentzVector TACalibJet;
789 TACalibJet.SetPtEtaPhiM(pT_corr, jetStartP4.eta(), jetStartP4.phi(), mass_corr);
791 TACalibJet_pTfixed.SetPxPyPzE( jetStartP4.Px(), jetStartP4.Py(), jetStartP4.Pz(), E_corr );}
794 jet.setAttribute<
float>(
"JetTrackAssistedMassUnCalibrated",
mTA);
795 jet.setAttribute<
float>(
"JetTrackAssistedMassCalibrated",mass_corr);
796 if(!
m_pTfixed)
jet.setAttribute<
float>(
"JetpTCorrByCalibratedTAMass",pT_corr);
797 else{
jet.setAttribute<
float>(
"JetECorrByCalibratedTAMass",E_corr);}
805 calibP4_calo.SetCoordinates( caloCalibJet.Pt(), jetStartP4.eta(), jetStartP4.phi(), caloCalibJet.M() );
811 calibP4_ta.SetCoordinates( TACalibJet.Pt(), jetStartP4.eta(), jetStartP4.phi(), TACalibJet.M() );
813 calibP4_ta.SetPxPyPzE( TACalibJet_pTfixed.Px(), TACalibJet_pTfixed.Py(), TACalibJet_pTfixed.Pz(), TACalibJet_pTfixed.E() );}
821 float Mass_comb = 0.;
832 calibP4Insitu_calo=jetInsituP4_calo;
834 ATH_MSG_FATAL(
"Cannot retrieve JetInsituScaleMomentumCalo jets" );
835 return StatusCode::FAILURE;
837 TLorentzVector TLVCaloInsituCalib;
838 TLVCaloInsituCalib.SetPtEtaPhiM(calibP4Insitu_calo.pt(), calibP4Insitu_calo.eta(), calibP4Insitu_calo.phi(), calibP4Insitu_calo.mass());
839 mass_calo = TLVCaloInsituCalib.M();
840 pT_calo = TLVCaloInsituCalib.Pt();
841 E_calo = TLVCaloInsituCalib.E();
842 Et_calo = TLVCaloInsituCalib.Et();
847 calibP4Insitu_ta=jetInsituP4_ta;
849 ATH_MSG_FATAL(
"Cannot retrieve JetInsituScaleMomentumTA jets" );
850 return StatusCode::FAILURE;
852 TLorentzVector TLVTAInsituCalib;
853 TLVTAInsituCalib.SetPtEtaPhiM(calibP4Insitu_ta.pt(), calibP4Insitu_ta.eta(), calibP4Insitu_ta.phi(), calibP4Insitu_ta.mass());
854 mass_ta = TLVTAInsituCalib.M();
856 mass_calo = caloCalibJet.M();
857 pT_calo = caloCalibJet.Pt();
858 E_calo = caloCalibJet.E();
859 Et_calo = caloCalibJet.Et();
864 if( (mass_calo==0) || (mass_ta==0) ) {
865 Mass_comb = mass_ta+mass_calo;
873 ATH_MSG_FATAL(
"Please check that the mass combination eta binning is properly set in your config file");
874 return StatusCode::FAILURE;
877 ATH_MSG_FATAL(
"Please check that the mass combination eta binning is properly set in your config file");
878 return StatusCode::FAILURE;
883 ATH_MSG_FATAL(
"Please check that the mass resolution 3D histogram is provided");
884 return StatusCode::FAILURE;
888 ATH_MSG_FATAL(
"Please check that the track assisted mass resolution 3D histogram is provided");
889 return StatusCode::FAILURE;
901 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the mass combination");
902 return StatusCode::FAILURE;
993 ATH_MSG_FATAL(
"This should never be reached - if it happens, it's because a new BinningParam enum option was added, but how to handle it for the TA mass was not. Please contact the tool developer(s) to fix this.");
994 return StatusCode::FAILURE;
1000 ATH_MSG_ERROR(
"Encountered division by zero when calculating mass combination weight using correlated weights");
1001 return StatusCode::FAILURE;
1003 const double Weight = ( relTA*relTA -
rho *relCalo*relTA ) / ( relCalo*relCalo + relTA*relTA - 2 *
rho* relCalo * relTA );
1006 if(relCalo == 0 && relTA == 0)
1008 else if(relCalo == 0)
1009 Mass_comb = mass_ta;
1011 Mass_comb = mass_calo;
1013 Mass_comb = ( mass_calo * Weight ) + ( mass_ta * ( 1 - Weight) );
1015 if(Mass_comb>jetStartP4.e()) Mass_comb = mass_calo;
1016 else if(!
m_pTfixed) pT_calo = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_calo*mass_calo)/std::cosh( jetStartP4.eta() );
1020 TLorentzVector TLVjet;
1021 TLVjet.SetPtEtaPhiM( pT_calo, jetStartP4.eta(), jetStartP4.phi(), Mass_comb );
1022 calibP4.SetPxPyPzE( TLVjet.Px(), TLVjet.Py(), TLVjet.Pz(), TLVjet.E() );
1026 jet.setJetP4( calibP4 );
1030 return StatusCode::SUCCESS;