5353#include < array>
5454#include < cmath>
5555#include < cstdint>
56+ #include < random>
5657#include < string>
5758#include < string_view>
5859#include < utility>
@@ -80,6 +81,7 @@ struct studyDCAFitter {
8081 Configurable<std::string> grpmagPath{" grpmagPath" , " GLO/Config/GRPMagField" , " CCDB path of the GRPMagField object" };
8182 Configurable<std::string> lutPath{" lutPath" , " GLO/Param/MatLUT" , " Path of the Lut parametrization" };
8283 // Configurable<std::string> mVtxPath{"mVtxPath", "GLO/Calib/MeanVertex", "Path of the mean vertex file"};
84+ Configurable<float > cfgDownSampling{" cfgDownSampling" , 1.1 , " down sampling for wrongly found SV" };
8385
8486 struct : ConfigurableGroup {
8587 std::string prefix = " electronCut" ;
@@ -153,6 +155,10 @@ struct studyDCAFitter {
153155 mRunNumber = 0 ;
154156 d_bz = 0 ;
155157
158+ std::random_device seed_gen;
159+ engine = std::mt19937 (seed_gen ());
160+ dist01 = std::uniform_real_distribution<float >(0 .0f , 1 .0f );
161+
156162 addHistograms ();
157163 }
158164
@@ -167,6 +173,9 @@ struct studyDCAFitter {
167173 o2::dataformats::DCA mDcaInfoCov ;
168174 o2::dataformats::VertexBase mVtx ;
169175
176+ std::mt19937 engine;
177+ std::uniform_real_distribution<float > dist01;
178+
170179 template <typename TBC >
171180 void initCCDB (TBC const & bc)
172181 {
@@ -411,11 +420,11 @@ struct studyDCAFitter {
411420 auto t1mc = t1.template mcParticle_as <aod::McParticles>();
412421 auto t2mc = t2.template mcParticle_as <aod::McParticles>();
413422
414- int mcCommonMotherid = FindCommonMother (t1mc, t2mc, mcParticles);
423+ int mcCommonMotherId = FindCommonMother (t1mc, t2mc, mcParticles);
415424 int hfee_type = IsHF (t1mc, t2mc, mcParticles);
416425
417- if (mcCommonMotherid > -1 ) {
418- auto cmp = mcParticles.rawIteratorAt (mcCommonMotherid );
426+ if (mcCommonMotherId > -1 ) {
427+ auto cmp = mcParticles.rawIteratorAt (mcCommonMotherId );
419428 switch (std::abs (cmp.pdgCode ())) {
420429 case 23 :
421430 if constexpr (signType == 0 ) { // ULS
@@ -495,7 +504,6 @@ struct studyDCAFitter {
495504 fRegistry .fill (HIST (" Pair/PV/b2c2e_b2e_diffb/lsmm/hs" ), v12.M (), v12.Pt (), pair_dca);
496505 }
497506 break ;
498-
499507 default :
500508 break ;
501509 } // end of switch for HFee
@@ -583,19 +591,22 @@ struct studyDCAFitter {
583591 float pteeAtSV = RecoDecay::sqrtSumOfSquares (pvecSum[0 ], pvecSum[1 ]);
584592 float yeeAtSV = RecoDecay::y (pvecSum, meeAtSV);
585593
586- int pdgCodeCM = 0 ;
587-
588- auto t1mc = t1.template mcParticle_as <aod::McParticles>();
589- auto t2mc = t2.template mcParticle_as <aod::McParticles>();
594+ auto t1mc = t1.template mcParticle_as <aod::McParticles>(); // true lepton
595+ auto t2mc = t2.template mcParticle_as <aod::McParticles>(); // true lepton
596+ bool isCorrectCollision1 = t1mc.mcCollisionId () == collision.mcCollisionId ();
597+ bool isCorrectCollision2 = t2mc.mcCollisionId () == collision.mcCollisionId ();
598+ int pdgCodeMother1 = 0 ;
599+ int pdgCodeMother2 = 0 ;
590600
591- int mcCommonMotherid = FindCommonMother (t1mc, t2mc, mcParticles);
601+ int mcCommonMotherId = FindCommonMother (t1mc, t2mc, mcParticles);
592602 int hfee_type = IsHF (t1mc, t2mc, mcParticles);
593603 bool keepSignal = false ;
594604 uint8_t dileptonType = 0 ;
595605
596- if (mcCommonMotherid > -1 ) {
597- auto cmp = mcParticles.rawIteratorAt (mcCommonMotherid);
598- pdgCodeCM = cmp.pdgCode ();
606+ if (mcCommonMotherId > -1 ) {
607+ auto cmp = mcParticles.rawIteratorAt (mcCommonMotherId);
608+ pdgCodeMother1 = cmp.pdgCode ();
609+ pdgCodeMother2 = cmp.pdgCode ();
599610 switch (std::abs (cmp.pdgCode ())) {
600611 case 23 :
601612 keepSignal = true ;
@@ -678,6 +689,10 @@ struct studyDCAFitter {
678689 } // end of switch for LF
679690 } else if (hfee_type > -1 ) {
680691 keepSignal = true ;
692+ auto t1mcMother = t1mc.template mothers_first_as <aod::McParticles>();
693+ auto t2mcMother = t2mc.template mothers_first_as <aod::McParticles>();
694+ pdgCodeMother1 = t1mcMother.pdgCode ();
695+ pdgCodeMother2 = t2mcMother.pdgCode ();
681696 switch (hfee_type) {
682697 case static_cast <int >(EM_HFeeType::kCe_Ce ):
683698 dileptonType = 3 ;
@@ -765,18 +780,26 @@ struct studyDCAFitter {
765780 } else {
766781 keepSignal = true ;
767782 dileptonType = 0 ; // bkg
783+ auto t1mcMother = t1mc.template mothers_first_as <aod::McParticles>();
784+ auto t2mcMother = t2mc.template mothers_first_as <aod::McParticles>();
785+ pdgCodeMother1 = t1mcMother.pdgCode ();
786+ pdgCodeMother2 = t2mcMother.pdgCode ();
768787 }
769788
770789 if (keepSignal) {
790+ if (dileptonType == 0 && dist01 (engine) > cfgDownSampling) { // random sampling, if necessary
791+ return ;
792+ }
793+
771794 dileptonTable (eventTable.lastIndex () + 1 ,
772- signed1Pt1, eta1, dcaXY1, dcaZ1, CYY1 , CZY1 , CZZ1 ,
773- signed1Pt2, eta2, dcaXY2, dcaZ2, CYY2 , CZY2 , CZZ2 ,
795+ signed1Pt1, eta1, dcaXY1, dcaZ1, CYY1 , CZY1 , CZZ1 , isCorrectCollision1, pdgCodeMother1,
796+ signed1Pt2, eta2, dcaXY2, dcaZ2, CYY2 , CZY2 , CZZ2 , isCorrectCollision2, pdgCodeMother2,
774797 meeAtSV, pteeAtSV, yeeAtSV,
775798 chi2PCA,
776799 cpa, cpaXY, cpaRZ,
777800 lxy, lz, lxyz,
778801 lxyErr, lzErr, lxyzErr,
779- dileptonType, pdgCodeCM );
802+ dileptonType);
780803 }
781804 }
782805
@@ -825,6 +848,11 @@ struct studyDCAFitter {
825848 if (std::abs (mctrack.pdgCode ()) != 11 ) {
826849 continue ;
827850 }
851+
852+ auto mcMother = mctrack.template mothers_first_as <aod::McParticles>();
853+ if (std::abs (mcMother.pdgCode ()) > 1e+9 ) {
854+ continue ;
855+ }
828856 if (!(mctrack.isPhysicalPrimary () || mctrack.producedByGenerator ())) {
829857 continue ;
830858 }
0 commit comments