505 {
506
507
508
509
510 float detectorEta = jet.
getAttribute<
float>(
"DetectorEta");
511 double absdetectorEta = fabs(detectorEta);
512
515 jetStartP4 = jet.
jetP4();
516
518
519 float mass_corr = jetStartP4.mass();
520 double pT_corr = jetStartP4.pt();
521
522 TLorentzVector caloCalibJet;
523 float mass_ta = 0;
524
526
527 int etabin=-99;
529 ATH_MSG_FATAL(
"Please check that the mass correction eta binning is properly set in your config file");
530 return StatusCode::FAILURE;
531 }
533 {
534 ATH_MSG_FATAL(
"Please check that the mass correction 3D histogram is provided");
535 return StatusCode::FAILURE;
536 }
537
538
539
540
541
542
543
544
547 ) && jetStartP4.mass() != 0 ) {
549 {
552 }
553 if (etabin< 0){
554 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the mass correction");
555 return StatusCode::FAILURE;
556 }
557 }
558
559
560 double massFactor = 1;
562 {
566 else
568 break;
570 if (jetStartP4.mass() / jetStartP4.e() > 0)
571 {
573 massFactor =
getMassCorr3D( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.e()), absdetectorEta);
574 else
575 massFactor =
getMassCorr( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.e()), etabin);
576 }
577 else
578 massFactor = 1;
579 break;
581 if (jetStartP4.mass() / jetStartP4.Et() > 0)
582 {
584 massFactor =
getMassCorr3D( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.Et()), absdetectorEta);
585 else
586 massFactor =
getMassCorr( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.Et()), etabin);
587 }
588 else
589 massFactor = 1;
590 break;
592 if (jetStartP4.mass() / jetStartP4.pt() > 0)
593 {
595 massFactor =
getMassCorr3D( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.pt()), absdetectorEta);
596 else
597 massFactor =
getMassCorr( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.pt()), etabin);
598 }
599 else
600 massFactor = 1;
601 break;
603 if (jetStartP4.mass() / jetStartP4.Et() > 0)
604 {
606 massFactor =
getMassCorr3D( jetStartP4.Et()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.Et()), absdetectorEta);
607 else
608 massFactor =
getMassCorr( jetStartP4.Et()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.Et()), etabin);
609 }
610 else
611 massFactor = 1;
612 break;
613 default:
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;
616 break;
617 }
618
619 mass_corr = jetStartP4.mass() / massFactor;
620 if (mass_corr > jetStartP4.e()) {
621 mass_corr = jetStartP4.mass();
622 }
623
624 if(!
m_pTfixed) pT_corr = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_corr*mass_corr)/std::cosh( jetStartP4.eta() );
625 }
626
627 caloCalibJet.SetPtEtaPhiM(pT_corr, jetStartP4.eta(), jetStartP4.phi(), mass_corr);
628
630 calibP4.SetPxPyPzE( caloCalibJet.Px(), caloCalibJet.Py(), caloCalibJet.Pz(), caloCalibJet.E() );
631
632
635 }
636
637
639
640 double E_corr = jetStartP4.e();
641
642
644 {
645 etabin=-99;
647 ATH_MSG_FATAL(
"Please check that the mass correction eta binning is properly set in your config file");
649 }
650 }
652 {
653 ATH_MSG_FATAL(
"Please check that the track assisted mass correction 3D histogram is provided");
654 return StatusCode::FAILURE;
655 }
656
657 float trackSumMass;
658 std::string TrackSumMassStr = "TrackSumMass";
659 if(
m_jetAlgo==
"AntiKt4EMTopo" ||
m_jetAlgo==
"AntiKt4LCTopo") TrackSumMassStr =
"DFCommonJets_TrackSumMass";
660 std::string TrackSumPtStr = "TrackSumPt";
661 if(
m_jetAlgo==
"AntiKt4EMTopo" ||
m_jetAlgo==
"AntiKt4LCTopo") TrackSumPtStr =
"DFCommonJets_TrackSumPt";
662 if( !jet.
getAttribute<
float>(TrackSumMassStr,trackSumMass) ) {
664
665 [[maybe_unused]] static const bool warnedOnce = [&] {
666 ATH_MSG_WARNING(
"Failed to retrieve TrackSumMass! Track Assisted Mass Correction will NOT be applied");
667 return true;
668 }();
669 return StatusCode::SUCCESS;
670 } else{
671 ATH_MSG_FATAL(
"Failed to retrieve TrackSumMass! Mass Combination can NOT be performed. Aborting.");
672 return StatusCode::FAILURE;
673 }
674 }
675 float trackSumPt;
676 if( !jet.
getAttribute<
float>(TrackSumPtStr,trackSumPt) ) {
678
679 [[maybe_unused]] static const bool warnedOnce = [&] {
680 ATH_MSG_WARNING(
"Failed to retrieve TrackSumPt! Track Assisted Mass Correction will NOT be applied");
681 return true;
682 }();
683 return StatusCode::SUCCESS;
684 } else{
685 ATH_MSG_FATAL(
"Failed to retrieve TrackSumPt! Mass Combination can NOT be performed. Aborting.");
686 return StatusCode::FAILURE;
687 }
688 }
689 pT_corr = jetStartP4.pt();
691 if(trackSumPt==0)
mTA = 0;
692 else{
mTA = (jetStartP4.pt()/trackSumPt)*trackSumMass;}
695
698 ) && jetStartP4.mass() != 0 ) {
700 {
703 }
704 if (etabin< 0){
705 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the track assisted mass correction");
706 return StatusCode::FAILURE;
707 }
708 }
709
710 double mTAFactor = 1;
711
713
715 {
719 else
721 break;
723 if (
mTA / jetStartP4.e() > 0)
724 {
727 else
729 }
730 else
731 mTAFactor = 1;
732 break;
734 if (
mTA / jetStartP4.Et() > 0)
735 {
738 else
740 }
741 else
742 mTAFactor = 1;
743 break;
745 if (
mTA / jetStartP4.pt() > 0)
746 {
749 else
751 }
752 else
753 mTAFactor = 1;
754 break;
756 if (
mTA / jetStartP4.Et() > 0)
757 {
760 else
762 }
763 else
764 mTAFactor = 1;
765 break;
766 default:
767 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.");
768 return StatusCode::FAILURE;
769 break;
770 }
771 }
772
773 if(mTAFactor!=0) mass_corr =
mTA/mTAFactor;
774 else{
775 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. ");
776 return StatusCode::FAILURE;
777 }
778
779 if(!
m_pTfixed) pT_corr = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_corr*mass_corr)/std::cosh( jetStartP4.eta() );
780 else{E_corr = std::sqrt(jetStartP4.P()*jetStartP4.P()+mass_corr*mass_corr);}
781 }
782 else{
784 mass_corr = 0;
785 if(!
m_pTfixed) pT_corr = jetStartP4.e()/std::cosh( jetStartP4.eta() );
786 else{E_corr = jetStartP4.P();}
787 }
788
789 TLorentzVector TACalibJet;
792 TACalibJet.SetPtEtaPhiM(pT_corr, jetStartP4.eta(), jetStartP4.phi(), mass_corr);
793 }else{
794 TACalibJet_pTfixed.SetPxPyPzE( jetStartP4.Px(), jetStartP4.Py(), jetStartP4.Pz(), E_corr );}
795
796
798 jet.
setAttribute<
float>(
"JetTrackAssistedMassCalibrated",mass_corr);
800 else{jet.
setAttribute<
float>(
"JetECorrByCalibratedTAMass",E_corr);}
801
802
803 mass_ta = mass_corr;
804
805
806
808 calibP4_calo.SetCoordinates( caloCalibJet.Pt(), jetStartP4.eta(), jetStartP4.phi(), caloCalibJet.M() );
810
811
814 calibP4_ta.SetCoordinates( TACalibJet.Pt(), jetStartP4.eta(), jetStartP4.phi(), TACalibJet.M() );
815 }else{
816 calibP4_ta.SetPxPyPzE( TACalibJet_pTfixed.Px(), TACalibJet_pTfixed.Py(), TACalibJet_pTfixed.Pz(), TACalibJet_pTfixed.E() );}
817
819 }
820 }
821
823 float mass_calo;
824 float Mass_comb = 0.;
825 double pT_calo;
826 double E_calo;
827 double Et_calo;
828
830
831
835 calibP4Insitu_calo=jetInsituP4_calo;
836 }else{
837 ATH_MSG_FATAL(
"Cannot retrieve JetInsituScaleMomentumCalo jets" );
838 return StatusCode::FAILURE;
839 }
840 TLorentzVector TLVCaloInsituCalib;
841 TLVCaloInsituCalib.SetPtEtaPhiM(calibP4Insitu_calo.pt(), calibP4Insitu_calo.eta(), calibP4Insitu_calo.phi(), calibP4Insitu_calo.mass());
842 mass_calo = TLVCaloInsituCalib.M();
843 pT_calo = TLVCaloInsituCalib.Pt();
844 E_calo = TLVCaloInsituCalib.E();
845 Et_calo = TLVCaloInsituCalib.Et();
846
850 calibP4Insitu_ta=jetInsituP4_ta;
851 }else{
852 ATH_MSG_FATAL(
"Cannot retrieve JetInsituScaleMomentumTA jets" );
853 return StatusCode::FAILURE;
854 }
855 TLorentzVector TLVTAInsituCalib;
856 TLVTAInsituCalib.SetPtEtaPhiM(calibP4Insitu_ta.pt(), calibP4Insitu_ta.eta(), calibP4Insitu_ta.phi(), calibP4Insitu_ta.mass());
857 mass_ta = TLVTAInsituCalib.M();
858 }else{
859 mass_calo = caloCalibJet.M();
860 pT_calo = caloCalibJet.Pt();
861 E_calo = caloCalibJet.E();
862 Et_calo = caloCalibJet.Et();
863
864 }
865
866
867 if( (mass_calo==0) || (mass_ta==0) ) {
868 Mass_comb = mass_ta+mass_calo;
869 }
870 else {
871
872 int etabin=-99;
874 {
876 ATH_MSG_FATAL(
"Please check that the mass combination eta binning is properly set in your config file");
877 return StatusCode::FAILURE;
878 }
880 ATH_MSG_FATAL(
"Please check that the mass combination eta binning is properly set in your config file");
881 return StatusCode::FAILURE;
882 }
883 }
885 {
886 ATH_MSG_FATAL(
"Please check that the mass resolution 3D histogram is provided");
887 return StatusCode::FAILURE;
888 }
890 {
891 ATH_MSG_FATAL(
"Please check that the track assisted mass resolution 3D histogram is provided");
892 return StatusCode::FAILURE;
893 }
894
897
899 {
902 }
903 if (etabin< 0){
904 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the mass combination");
905 return StatusCode::FAILURE;
906 }
907 }
908
909
910 double relCalo = 0;
911 double relTA = 0;
914 {
917 {
922 }
923 else
924 {
929 }
930 break;
933 {
934 relCalo = mass_calo/E_calo > 0 ?
getRelCalo3D( E_calo/
m_GeV, std::log(mass_calo/E_calo), absdetectorEta ) : 0;
935 relTA = mass_ta/E_calo > 0 ?
getRelTA3D( E_calo/
m_GeV, std::log(mass_ta/E_calo), absdetectorEta ) : 0;
937 rho = mass_calo/E_calo > 0 ?
getRho3D( E_calo/
m_GeV, std::log(mass_calo/E_calo), absdetectorEta ) : 0;
938 }
939 else
940 {
941 relCalo = mass_calo/E_calo > 0 ?
getRelCalo( E_calo/
m_GeV, std::log(mass_calo/E_calo), etabin ) : 0;
942 relTA = mass_ta/E_calo > 0 ?
getRelTA( E_calo/
m_GeV, std::log(mass_ta/E_calo), etabin ) : 0;
944 rho = mass_calo/E_calo > 0 ?
getRho( E_calo/
m_GeV, std::log(mass_calo/E_calo), etabin ) : 0;
945 }
946 break;
949 {
950 relCalo = mass_calo/Et_calo > 0 ?
getRelCalo3D( E_calo/
m_GeV, std::log(mass_calo/Et_calo), absdetectorEta ) : 0;
951 relTA = mass_ta/Et_calo > 0 ?
getRelTA3D( E_calo/
m_GeV, std::log(mass_ta/Et_calo), absdetectorEta ) : 0;
953 rho = mass_calo/Et_calo > 0 ?
getRho3D( E_calo/
m_GeV, std::log(mass_calo/Et_calo), absdetectorEta ) : 0;
954 }
955 else
956 {
957 relCalo = mass_calo/Et_calo > 0 ?
getRelCalo( E_calo/
m_GeV, std::log(mass_calo/Et_calo), etabin ) : 0;
958 relTA = mass_ta/Et_calo > 0 ?
getRelTA( E_calo/
m_GeV, std::log(mass_ta/Et_calo), etabin ) : 0;
960 rho = mass_calo/Et_calo > 0 ?
getRho( E_calo/
m_GeV, std::log(mass_calo/Et_calo), etabin ) : 0;
961 }
962 break;
965 {
966 relCalo = mass_calo/pT_calo > 0 ?
getRelCalo3D( E_calo/
m_GeV, std::log(mass_calo/pT_calo), absdetectorEta ) : 0;
967 relTA = mass_ta/pT_calo > 0 ?
getRelTA3D( E_calo/
m_GeV, std::log(mass_ta/pT_calo), absdetectorEta ) : 0;
969 rho = mass_calo/pT_calo > 0 ?
getRho3D( E_calo/
m_GeV, std::log(mass_calo/pT_calo), absdetectorEta ) : 0;
970 }
971 else
972 {
973 relCalo = mass_calo/pT_calo > 0 ?
getRelCalo( E_calo/
m_GeV, std::log(mass_calo/pT_calo), etabin ) : 0;
974 relTA = mass_ta/pT_calo > 0 ?
getRelTA( E_calo/
m_GeV, std::log(mass_ta/pT_calo), etabin ) : 0;
976 rho = mass_calo/pT_calo > 0 ?
getRho( E_calo/
m_GeV, std::log(mass_calo/pT_calo), etabin ) : 0;
977 }
978 break;
981 {
982 relCalo = mass_calo/Et_calo > 0 ?
getRelCalo3D( Et_calo/
m_GeV, std::log(mass_calo/Et_calo), absdetectorEta ) : 0;
983 relTA = mass_ta/Et_calo > 0 ?
getRelTA3D( Et_calo/
m_GeV, std::log(mass_ta/Et_calo), absdetectorEta ) : 0;
985 rho = mass_calo/Et_calo > 0 ?
getRho3D( Et_calo/
m_GeV, std::log(mass_calo/Et_calo), absdetectorEta ) : 0;
986 }
987 else
988 {
989 relCalo = mass_calo/Et_calo > 0 ?
getRelCalo( Et_calo/
m_GeV, std::log(mass_calo/Et_calo), etabin ) : 0;
990 relTA = mass_ta/Et_calo > 0 ?
getRelTA( Et_calo/
m_GeV, std::log(mass_ta/Et_calo), etabin ) : 0;
992 rho = mass_calo/Et_calo > 0 ?
getRho( Et_calo/
m_GeV, std::log(mass_calo/Et_calo), etabin ) : 0;
993 }
994 break;
995 default:
996 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.");
997 return StatusCode::FAILURE;
998 break;
999 }
1000
1001
1003 ATH_MSG_ERROR(
"Encountered division by zero when calculating mass combination weight using correlated weights");
1004 return StatusCode::FAILURE;
1005 }
1006 const double Weight = ( relTA*relTA -
rho *relCalo*relTA ) / ( relCalo*relCalo + relTA*relTA - 2 * rho* relCalo * relTA );
1007
1008
1009 if(relCalo == 0 && relTA == 0)
1010 Mass_comb = 0;
1011 else if(relCalo == 0)
1012 Mass_comb = mass_ta;
1013 else if(relTA == 0)
1014 Mass_comb = mass_calo;
1015 else
1016 Mass_comb = ( mass_calo * Weight ) + ( mass_ta * ( 1 - Weight) );
1017
1018 if(Mass_comb>jetStartP4.e()) Mass_comb = mass_calo;
1019 else if(!
m_pTfixed) pT_calo = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_calo*mass_calo)/std::cosh( jetStartP4.eta() );
1020 }
1021 }
1022
1023 TLorentzVector TLVjet;
1024 TLVjet.SetPtEtaPhiM( pT_calo, jetStartP4.eta(), jetStartP4.phi(), Mass_comb );
1025 calibP4.SetPxPyPzE( TLVjet.Px(), TLVjet.Py(), TLVjet.Pz(), TLVjet.E() );
1026
1027
1030
1031 }
1032
1033 return StatusCode::SUCCESS;
1034
1035}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
bool m_useCorrelatedWeights
float getRelTA(double pT_uncorr, double mass_over_pt_uncorr, int etabin) const
float getMassCorr3D(double pT_uncorr, double mass_uncorr, double eta) const
float getRelTA3D(double pT_uncorr, double mass_over_pt_uncorr, double eta) const
float getRelCalo3D(double pT_uncorr, double mass_over_pt_uncorr, double eta) const
float getMassCorr(double pT_uncorr, double mass_uncorr, int etabin) const
VecTH2 m_caloResolutionMassCombination
float getRelCalo(double pT_uncorr, double mass_over_pt_uncorr, int etabin) const
VecD m_massCombinationEtaBins
VecTH2 m_respFactorsTrackAssistedMass
std::unique_ptr< const TH3 > m_caloResolutionMassCombination3D
float getTrackAssistedMassCorr(double pT_uncorr, double mass_uncorr, int etabin) const
std::unique_ptr< const TH3 > m_respFactorTrackAssistedMass3D
float getTrackAssistedMassCorr3D(double pT_uncorr, double mass_uncorr, double eta) const
std::unique_ptr< const TH3 > m_respFactorMass3D
VecTH2 m_taResolutionMassCombination
std::unique_ptr< const TH3 > m_taResolutionMassCombination3D
bool m_trackAssistedJetMassCorr
float getRho(double pT_uncorr, double mass_over_pt_uncorr, int etabin) const
float getRho3D(double pT_uncorr, double mass_over_pt_uncorr, double eta) const
virtual StatusCode setStartP4(xAOD::Jet &jet) const
void setAttribute(const std::string &name, const T &v)
void setJetP4(const JetFourMom_t &p4)
bool getAttribute(AttributeID type, T &value) const
Retrieve attribute moment by enum.
JetFourMom_t jetP4() const
The full 4-momentum of the particle : internal jet type.
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.