503 {
504
505
506
507
508 float detectorEta = jet.
getAttribute<
float>(
"DetectorEta");
509 double absdetectorEta = fabs(detectorEta);
510
513 jetStartP4 = jet.
jetP4();
514
516
517 float mass_corr = jetStartP4.mass();
518 double pT_corr = jetStartP4.pt();
519
520 TLorentzVector caloCalibJet;
521 float mass_ta = 0;
522
524
525 int etabin=-99;
527 ATH_MSG_FATAL(
"Please check that the mass correction eta binning is properly set in your config file");
528 return StatusCode::FAILURE;
529 }
531 {
532 ATH_MSG_FATAL(
"Please check that the mass correction 3D histogram is provided");
533 return StatusCode::FAILURE;
534 }
535
536
537
538
539
540
541
542
545 ) && jetStartP4.mass() != 0 ) {
547 {
550 }
551 if (etabin< 0){
552 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the mass correction");
553 return StatusCode::FAILURE;
554 }
555 }
556
557
558 double massFactor = 1;
560 {
564 else
566 break;
568 if (jetStartP4.mass() / jetStartP4.e() > 0)
569 {
571 massFactor =
getMassCorr3D( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.e()), absdetectorEta);
572 else
573 massFactor =
getMassCorr( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.e()), etabin);
574 }
575 else
576 massFactor = 1;
577 break;
579 if (jetStartP4.mass() / jetStartP4.Et() > 0)
580 {
582 massFactor =
getMassCorr3D( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.Et()), absdetectorEta);
583 else
584 massFactor =
getMassCorr( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.Et()), etabin);
585 }
586 else
587 massFactor = 1;
588 break;
590 if (jetStartP4.mass() / jetStartP4.pt() > 0)
591 {
593 massFactor =
getMassCorr3D( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.pt()), absdetectorEta);
594 else
595 massFactor =
getMassCorr( jetStartP4.e()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.pt()), etabin);
596 }
597 else
598 massFactor = 1;
599 break;
601 if (jetStartP4.mass() / jetStartP4.Et() > 0)
602 {
604 massFactor =
getMassCorr3D( jetStartP4.Et()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.Et()), absdetectorEta);
605 else
606 massFactor =
getMassCorr( jetStartP4.Et()/
m_GeV, std::log(jetStartP4.mass() / jetStartP4.Et()), etabin);
607 }
608 else
609 massFactor = 1;
610 break;
611 default:
612 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.");
613 return StatusCode::FAILURE;
614 break;
615 }
616 if (massFactor == 0.){
618 massFactor = 1.;
619 }
620 mass_corr = jetStartP4.mass() / massFactor;
621 if (mass_corr > jetStartP4.e()) {
622 mass_corr = jetStartP4.mass();
623 }
624
625 if(!
m_pTfixed) pT_corr = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_corr*mass_corr)/std::cosh( jetStartP4.eta() );
626 }
627
628 caloCalibJet.SetPtEtaPhiM(pT_corr, jetStartP4.eta(), jetStartP4.phi(), mass_corr);
629
631 calibP4.SetPxPyPzE( caloCalibJet.Px(), caloCalibJet.Py(), caloCalibJet.Pz(), caloCalibJet.E() );
632
633
636 }
637
638
640
641 double E_corr = jetStartP4.e();
642
643
645 {
646 etabin=-99;
648 ATH_MSG_FATAL(
"Please check that the mass correction eta binning is properly set in your config file");
650 }
651 }
653 {
654 ATH_MSG_FATAL(
"Please check that the track assisted mass correction 3D histogram is provided");
655 return StatusCode::FAILURE;
656 }
657
658 float trackSumMass;
659 std::string TrackSumMassStr = "TrackSumMass";
660 if(
m_jetAlgo==
"AntiKt4EMTopo" ||
m_jetAlgo==
"AntiKt4LCTopo") TrackSumMassStr =
"DFCommonJets_TrackSumMass";
661 std::string TrackSumPtStr = "TrackSumPt";
662 if(
m_jetAlgo==
"AntiKt4EMTopo" ||
m_jetAlgo==
"AntiKt4LCTopo") TrackSumPtStr =
"DFCommonJets_TrackSumPt";
663 if( !jet.
getAttribute<
float>(TrackSumMassStr,trackSumMass) ) {
665
666 [[maybe_unused]] static const bool warnedOnce = [&] {
667 ATH_MSG_WARNING(
"Failed to retrieve TrackSumMass! Track Assisted Mass Correction will NOT be applied");
668 return true;
669 }();
670 return StatusCode::SUCCESS;
671 } else{
672 ATH_MSG_FATAL(
"Failed to retrieve TrackSumMass! Mass Combination can NOT be performed. Aborting.");
673 return StatusCode::FAILURE;
674 }
675 }
676 float trackSumPt;
677 if( !jet.
getAttribute<
float>(TrackSumPtStr,trackSumPt) ) {
679
680 [[maybe_unused]] static const bool warnedOnce = [&] {
681 ATH_MSG_WARNING(
"Failed to retrieve TrackSumPt! Track Assisted Mass Correction will NOT be applied");
682 return true;
683 }();
684 return StatusCode::SUCCESS;
685 } else{
686 ATH_MSG_FATAL(
"Failed to retrieve TrackSumPt! Mass Combination can NOT be performed. Aborting.");
687 return StatusCode::FAILURE;
688 }
689 }
690 pT_corr = jetStartP4.pt();
692 if(trackSumPt==0)
mTA = 0;
693 else{
mTA = (jetStartP4.pt()/trackSumPt)*trackSumMass;}
696
699 ) && jetStartP4.mass() != 0 ) {
701 {
704 }
705 if (etabin< 0){
706 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the track assisted mass correction");
707 return StatusCode::FAILURE;
708 }
709 }
710
711 double mTAFactor = 1;
712
714
716 {
720 else
722 break;
724 if (
mTA / jetStartP4.e() > 0)
725 {
728 else
730 }
731 else
732 mTAFactor = 1;
733 break;
735 if (
mTA / jetStartP4.Et() > 0)
736 {
739 else
741 }
742 else
743 mTAFactor = 1;
744 break;
746 if (
mTA / jetStartP4.pt() > 0)
747 {
750 else
752 }
753 else
754 mTAFactor = 1;
755 break;
757 if (
mTA / jetStartP4.Et() > 0)
758 {
761 else
763 }
764 else
765 mTAFactor = 1;
766 break;
767 default:
768 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.");
769 return StatusCode::FAILURE;
770 break;
771 }
772 }
773
774 if(mTAFactor!=0) mass_corr =
mTA/mTAFactor;
775 else{
776 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. ");
777 return StatusCode::FAILURE;
778 }
779
780 if(!
m_pTfixed) pT_corr = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_corr*mass_corr)/std::cosh( jetStartP4.eta() );
781 else{E_corr = std::sqrt(jetStartP4.P()*jetStartP4.P()+mass_corr*mass_corr);}
782 }
783 else{
785 mass_corr = 0;
786 if(!
m_pTfixed) pT_corr = jetStartP4.e()/std::cosh( jetStartP4.eta() );
787 else{E_corr = jetStartP4.P();}
788 }
789
790 TLorentzVector TACalibJet;
793 TACalibJet.SetPtEtaPhiM(pT_corr, jetStartP4.eta(), jetStartP4.phi(), mass_corr);
794 }else{
795 TACalibJet_pTfixed.SetPxPyPzE( jetStartP4.Px(), jetStartP4.Py(), jetStartP4.Pz(), E_corr );}
796
797
799 jet.
setAttribute<
float>(
"JetTrackAssistedMassCalibrated",mass_corr);
801 else{jet.
setAttribute<
float>(
"JetECorrByCalibratedTAMass",E_corr);}
802
803
804 mass_ta = mass_corr;
805
806
807
809 calibP4_calo.SetCoordinates( caloCalibJet.Pt(), jetStartP4.eta(), jetStartP4.phi(), caloCalibJet.M() );
811
812
815 calibP4_ta.SetCoordinates( TACalibJet.Pt(), jetStartP4.eta(), jetStartP4.phi(), TACalibJet.M() );
816 }else{
817 calibP4_ta.SetPxPyPzE( TACalibJet_pTfixed.Px(), TACalibJet_pTfixed.Py(), TACalibJet_pTfixed.Pz(), TACalibJet_pTfixed.E() );}
818
820 }
821 }
822
824 float mass_calo;
825 float Mass_comb = 0.;
826 double pT_calo;
827 double E_calo;
828 double Et_calo;
829
831
832
836 calibP4Insitu_calo=jetInsituP4_calo;
837 }else{
838 ATH_MSG_FATAL(
"Cannot retrieve JetInsituScaleMomentumCalo jets" );
839 return StatusCode::FAILURE;
840 }
841 TLorentzVector TLVCaloInsituCalib;
842 TLVCaloInsituCalib.SetPtEtaPhiM(calibP4Insitu_calo.pt(), calibP4Insitu_calo.eta(), calibP4Insitu_calo.phi(), calibP4Insitu_calo.mass());
843 mass_calo = TLVCaloInsituCalib.M();
844 pT_calo = TLVCaloInsituCalib.Pt();
845 E_calo = TLVCaloInsituCalib.E();
846 Et_calo = TLVCaloInsituCalib.Et();
847
851 calibP4Insitu_ta=jetInsituP4_ta;
852 }else{
853 ATH_MSG_FATAL(
"Cannot retrieve JetInsituScaleMomentumTA jets" );
854 return StatusCode::FAILURE;
855 }
856 TLorentzVector TLVTAInsituCalib;
857 TLVTAInsituCalib.SetPtEtaPhiM(calibP4Insitu_ta.pt(), calibP4Insitu_ta.eta(), calibP4Insitu_ta.phi(), calibP4Insitu_ta.mass());
858 mass_ta = TLVTAInsituCalib.M();
859 }else{
860 mass_calo = caloCalibJet.M();
861 pT_calo = caloCalibJet.Pt();
862 E_calo = caloCalibJet.E();
863 Et_calo = caloCalibJet.Et();
864
865 }
866
867
868 if( (mass_calo==0) || (mass_ta==0) ) {
869 Mass_comb = mass_ta+mass_calo;
870 }
871 else {
872
873 int etabin=-99;
875 {
877 ATH_MSG_FATAL(
"Please check that the mass combination eta binning is properly set in your config file");
878 return StatusCode::FAILURE;
879 }
881 ATH_MSG_FATAL(
"Please check that the mass combination eta binning is properly set in your config file");
882 return StatusCode::FAILURE;
883 }
884 }
886 {
887 ATH_MSG_FATAL(
"Please check that the mass resolution 3D histogram is provided");
888 return StatusCode::FAILURE;
889 }
891 {
892 ATH_MSG_FATAL(
"Please check that the track assisted mass resolution 3D histogram is provided");
893 return StatusCode::FAILURE;
894 }
895
898
900 {
903 }
904 if (etabin< 0){
905 ATH_MSG_FATAL(
"There was a problem determining the eta bin to use for the mass combination");
906 return StatusCode::FAILURE;
907 }
908 }
909
910
911 double relCalo = 0;
912 double relTA = 0;
915 {
918 {
923 }
924 else
925 {
930 }
931 break;
934 {
935 relCalo = mass_calo/E_calo > 0 ?
getRelCalo3D( E_calo/
m_GeV, std::log(mass_calo/E_calo), absdetectorEta ) : 0;
936 relTA = mass_ta/E_calo > 0 ?
getRelTA3D( E_calo/
m_GeV, std::log(mass_ta/E_calo), absdetectorEta ) : 0;
938 rho = mass_calo/E_calo > 0 ?
getRho3D( E_calo/
m_GeV, std::log(mass_calo/E_calo), absdetectorEta ) : 0;
939 }
940 else
941 {
942 relCalo = mass_calo/E_calo > 0 ?
getRelCalo( E_calo/
m_GeV, std::log(mass_calo/E_calo), etabin ) : 0;
943 relTA = mass_ta/E_calo > 0 ?
getRelTA( E_calo/
m_GeV, std::log(mass_ta/E_calo), etabin ) : 0;
945 rho = mass_calo/E_calo > 0 ?
getRho( E_calo/
m_GeV, std::log(mass_calo/E_calo), etabin ) : 0;
946 }
947 break;
950 {
951 relCalo = mass_calo/Et_calo > 0 ?
getRelCalo3D( E_calo/
m_GeV, std::log(mass_calo/Et_calo), absdetectorEta ) : 0;
952 relTA = mass_ta/Et_calo > 0 ?
getRelTA3D( E_calo/
m_GeV, std::log(mass_ta/Et_calo), absdetectorEta ) : 0;
954 rho = mass_calo/Et_calo > 0 ?
getRho3D( E_calo/
m_GeV, std::log(mass_calo/Et_calo), absdetectorEta ) : 0;
955 }
956 else
957 {
958 relCalo = mass_calo/Et_calo > 0 ?
getRelCalo( E_calo/
m_GeV, std::log(mass_calo/Et_calo), etabin ) : 0;
959 relTA = mass_ta/Et_calo > 0 ?
getRelTA( E_calo/
m_GeV, std::log(mass_ta/Et_calo), etabin ) : 0;
961 rho = mass_calo/Et_calo > 0 ?
getRho( E_calo/
m_GeV, std::log(mass_calo/Et_calo), etabin ) : 0;
962 }
963 break;
966 {
967 relCalo = mass_calo/pT_calo > 0 ?
getRelCalo3D( E_calo/
m_GeV, std::log(mass_calo/pT_calo), absdetectorEta ) : 0;
968 relTA = mass_ta/pT_calo > 0 ?
getRelTA3D( E_calo/
m_GeV, std::log(mass_ta/pT_calo), absdetectorEta ) : 0;
970 rho = mass_calo/pT_calo > 0 ?
getRho3D( E_calo/
m_GeV, std::log(mass_calo/pT_calo), absdetectorEta ) : 0;
971 }
972 else
973 {
974 relCalo = mass_calo/pT_calo > 0 ?
getRelCalo( E_calo/
m_GeV, std::log(mass_calo/pT_calo), etabin ) : 0;
975 relTA = mass_ta/pT_calo > 0 ?
getRelTA( E_calo/
m_GeV, std::log(mass_ta/pT_calo), etabin ) : 0;
977 rho = mass_calo/pT_calo > 0 ?
getRho( E_calo/
m_GeV, std::log(mass_calo/pT_calo), etabin ) : 0;
978 }
979 break;
982 {
983 relCalo = mass_calo/Et_calo > 0 ?
getRelCalo3D( Et_calo/
m_GeV, std::log(mass_calo/Et_calo), absdetectorEta ) : 0;
984 relTA = mass_ta/Et_calo > 0 ?
getRelTA3D( Et_calo/
m_GeV, std::log(mass_ta/Et_calo), absdetectorEta ) : 0;
986 rho = mass_calo/Et_calo > 0 ?
getRho3D( Et_calo/
m_GeV, std::log(mass_calo/Et_calo), absdetectorEta ) : 0;
987 }
988 else
989 {
990 relCalo = mass_calo/Et_calo > 0 ?
getRelCalo( Et_calo/
m_GeV, std::log(mass_calo/Et_calo), etabin ) : 0;
991 relTA = mass_ta/Et_calo > 0 ?
getRelTA( Et_calo/
m_GeV, std::log(mass_ta/Et_calo), etabin ) : 0;
993 rho = mass_calo/Et_calo > 0 ?
getRho( Et_calo/
m_GeV, std::log(mass_calo/Et_calo), etabin ) : 0;
994 }
995 break;
996 default:
997 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.");
998 return StatusCode::FAILURE;
999 break;
1000 }
1001
1002
1003 if(relCalo*relCalo + relTA*relTA - 2 * rho* relCalo * relTA == 0.){
1004 ATH_MSG_ERROR(
"Encountered division by zero when calculating mass combination weight using correlated weights");
1005 return StatusCode::FAILURE;
1006 }
1007
1008 const double Weight = ( relTA*relTA -
rho *relCalo*relTA ) / ( relCalo*relCalo + relTA*relTA - 2 * rho* relCalo * relTA );
1009
1010
1011 if(relCalo == 0 && relTA == 0)
1012 Mass_comb = 0;
1013 else if(relCalo == 0)
1014 Mass_comb = mass_ta;
1015 else if(relTA == 0)
1016 Mass_comb = mass_calo;
1017 else
1018 Mass_comb = ( mass_calo * Weight ) + ( mass_ta * ( 1 - Weight) );
1019
1020 if(Mass_comb>jetStartP4.e()) Mass_comb = mass_calo;
1021 else if(!
m_pTfixed) pT_calo = std::sqrt(jetStartP4.e()*jetStartP4.e()-mass_calo*mass_calo)/std::cosh( jetStartP4.eta() );
1022 }
1023 }
1024
1025 TLorentzVector TLVjet;
1026 TLVjet.SetPtEtaPhiM( pT_calo, jetStartP4.eta(), jetStartP4.phi(), Mass_comb );
1027 calibP4.SetPxPyPzE( TLVjet.Px(), TLVjet.Py(), TLVjet.Pz(), TLVjet.E() );
1028
1029
1032
1033 }
1034
1035 return StatusCode::SUCCESS;
1036
1037}
#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.