@@ -34,6 +34,7 @@ class BasePairCleaner
3434 if constexpr (modes::isFlagSet (mode, modes::Mode::kMc )) {
3535 mMixPairsWithCommonAncestor = pairCuts.mixOnlyCommonAncestor .value ;
3636 mMixPairsWithNonCommonAncestor = pairCuts.mixOnlyNonCommonAncestor .value ;
37+ mUseMotherAsAncestor = pairCuts.useMotherAsAncestor .value ;
3738 if (mMixPairsWithCommonAncestor && mMixPairsWithNonCommonAncestor ) {
3839 LOG (fatal) << " Both mixing with common and non-common ancestor is activated. Breaking..." ;
3940 }
@@ -48,34 +49,31 @@ class BasePairCleaner
4849 };
4950
5051 // mc only
52+ // ancestry is checked either with the partonic mother or with the first ancestor (i.e. the direct mother), depending on mUseMotherAsAncestor
5153 template <typename T1 , typename T2 , typename T3 >
52- bool mcPairHasCommonAncestor (T1 const & particle1, T2 const & particle2, T3 const & /* partonicMothers*/ ) const
54+ bool mcPairHasCommonAncestor (T1 const & particle1, T2 const & particle2, T3 const & partonicMothers) const
5355 {
54- // if one of the two particles has no associated partonic mother, we cannot know if they have a common anchestor, so we break out with false
55- if (!particle1.has_fMcPartMoth () || !particle2.has_fMcPartMoth ()) {
56- return false ;
56+ if (mUseMotherAsAncestor ) {
57+ return this ->mcPairHasCommonMother (particle1, particle2);
5758 }
58-
59- // get partonic mothers
60- auto partonicMother1 = particle1.template fMcPartMoth_as <T3 >();
61- auto partonicMother2 = particle2.template fMcPartMoth_as <T3 >();
62-
63- return partonicMother1.globalIndex () == partonicMother2.globalIndex ();
59+ return this ->mcPairHasCommonPartonicMother (particle1, particle2, partonicMothers);
6460 };
6561
6662 template <typename T1 , typename T2 , typename T3 >
67- bool mcPairHasNonCommonAncestor (T1 const & particle1, T2 const & particle2, T3 const & /* partonicMothers*/ ) const
63+ bool mcPairHasNonCommonAncestor (T1 const & particle1, T2 const & particle2, T3 const & partonicMothers) const
6864 {
65+ if (mUseMotherAsAncestor ) {
66+ // if one of the two particles has no associated mother, we cannot know if they have a common anchestor, so we break out with false
67+ if (!particle1.has_fMcMother () || !particle2.has_fMcMother ()) {
68+ return false ;
69+ }
70+ return !this ->mcPairHasCommonMother (particle1, particle2);
71+ }
6972 // if one of the two particles has no associated partonic mother, we cannot know if they have a common anchestor, so we break out with false
7073 if (!particle1.has_fMcPartMoth () || !particle2.has_fMcPartMoth ()) {
7174 return false ;
7275 }
73-
74- // get partonic mothers
75- auto partonicMother1 = particle1.template fMcPartMoth_as <T3 >();
76- auto partonicMother2 = particle2.template fMcPartMoth_as <T3 >();
77-
78- return partonicMother1.globalIndex () != partonicMother2.globalIndex ();
76+ return !this ->mcPairHasCommonPartonicMother (particle1, particle2, partonicMothers);
7977 };
8078
8179 // reco + mc
@@ -111,6 +109,38 @@ class BasePairCleaner
111109
112110 bool mMixPairsWithCommonAncestor = false ;
113111 bool mMixPairsWithNonCommonAncestor = false ;
112+
113+ private:
114+ // require both particles to originate from the same partonic mother
115+ template <typename T1 , typename T2 , typename T3 >
116+ bool mcPairHasCommonPartonicMother (T1 const & particle1, T2 const & particle2, T3 const & /* partonicMothers*/ ) const
117+ {
118+ // if one of the two particles has no associated partonic mother, we cannot know if they have a common anchestor, so we break out with false
119+ if (!particle1.has_fMcPartMoth () || !particle2.has_fMcPartMoth ()) {
120+ return false ;
121+ }
122+
123+ // get partonic mothers
124+ auto partonicMother1 = particle1.template fMcPartMoth_as <T3 >();
125+ auto partonicMother2 = particle2.template fMcPartMoth_as <T3 >();
126+
127+ return partonicMother1.globalIndex () == partonicMother2.globalIndex ();
128+ };
129+
130+ // require both particles to have the same first ancestor, i.e. the same direct mother
131+ // there is exactly one row in the mother table per generated mother, so comparing the indices is sufficient
132+ template <typename T1 , typename T2 >
133+ bool mcPairHasCommonMother (T1 const & particle1, T2 const & particle2) const
134+ {
135+ // if one of the two particles has no associated mother, we cannot know if they have a common anchestor, so we break out with false
136+ if (!particle1.has_fMcMother () || !particle2.has_fMcMother ()) {
137+ return false ;
138+ }
139+
140+ return particle1.fMcMotherId () == particle2.fMcMotherId ();
141+ };
142+
143+ bool mUseMotherAsAncestor = false ;
114144};
115145
116146class TrackTrackPairCleaner : public BasePairCleaner
0 commit comments