1414#include < CCDB/BasicCCDBManager.h>
1515#include < TList.h>
1616#include < vector>
17+ #include < bitset>
1718#include < string>
1819#include < iomanip>
1920#include < iostream>
@@ -106,6 +107,33 @@ enum TriggerSelectionType {
106107 knEventSelection // /< number of triggers for event selection
107108};
108109
110+ // / \enum OccupancyEstimationType
111+ // / \brief The type of occupancy estimation
112+ enum OccupancyEstimationType {
113+ kNOOCC = 0 , // /< do not use occupancy estimation
114+ kTRACKSOCC , // /< occupancy estimated using tracks
115+ kFT0COCC , // /< occupancy estimated using the FT0C
116+ knOccupancyEstimators // /< the number of occupancy estimators
117+ };
118+
119+ // / \enum CollisionSelectionFlags
120+ // / \brief The different criteria for selecting/rejecting collisions
121+ enum CollisionSelectionFlags {
122+ kMBBIT = 0 , // /< minimum bias
123+ kINT7BIT , // /< INT7 Run 1/2
124+ kSEL7BIT , // /< Sel7 Run 1/2
125+ kSEL8BIT , // /< Sel8
126+ kNOSAMEBUNCHPUPBIT , // /< no same bunch pile up
127+ kISGOODZVTXFT0VSPVBIT , // /< good zvtx FT0 vs PV
128+ kISVERTEXITSTPCBIT , // /< is vertex TPC and ITS
129+ kISVERTEXTOFMATCHEDBIT , // /< vertex contributor with TOF matched
130+ kISVERTEXTRDMATCHEDBIT , // /< vertex contributor with TRD matche
131+ kOCCUPANCYBIT , // /< occupancy within limits
132+ kCENTRALITYBIT , // /< centrality cut passed
133+ kZVERTEXBIT , // /< zvtx cut passed
134+ knCollisionSelectionFlags // /< number of flags
135+ };
136+
109137// / \enum StrongDebugging
110138// / \brief Enable a per track information debugging. Only for local analyses
111139enum StrongDebugging {
@@ -123,6 +151,11 @@ std::ofstream debugstream;
123151// ============================================================================================
124152float overallminp = 0 .0f ;
125153
154+ // ============================================================================================
155+ // The collision selection flags and configuration objects
156+ // ============================================================================================
157+ std::bitset<32 > collisionFlags;
158+
126159// ============================================================================================
127160// The DptDptFilter configuration objects
128161// ============================================================================================
@@ -302,6 +335,8 @@ SystemType fSystem = kNoSystem;
302335DataType fDataType = kData ;
303336CentMultEstimatorType fCentMultEstimator = kV0M ;
304337TriggerSelectionType fTriggerSelection = kMB ;
338+ OccupancyEstimationType fOccupancyEstimation = kNOOCC ; /* the occupancy estimator to use */
339+ float fMaxOccupancy = 1e6f; /* the maximum allowed occupancy */
305340
306341/* adaptations for the pp nightly checks */
307342analysis::CheckRangeCfg traceDCAOutliers;
@@ -449,6 +484,20 @@ inline std::string getCentMultEstimatorName(CentMultEstimatorType est)
449484 }
450485}
451486
487+ inline OccupancyEstimationType getOccupancyEstimator (const std::string& estimator)
488+ {
489+ if (estimator == " None" ) {
490+ return kNOOCC ;
491+ } else if (estimator == " Tracks" ) {
492+ return kTRACKSOCC ;
493+ } else if (estimator == " FT0C" ) {
494+ return kFT0COCC ;
495+ } else {
496+ LOGF (fatal, " Occupancy estimator %s not supported yet" , estimator.c_str ());
497+ return kNOOCC ;
498+ }
499+ }
500+
452501// ////////////////////////////////////////////////////////////////////////////////
453502// / Trigger selection
454503// ////////////////////////////////////////////////////////////////////////////////
@@ -469,17 +518,21 @@ inline bool triggerSelectionReco(CollisionObject const& collision)
469518 switch (fDataType ) {
470519 case kData :
471520 if (collision.alias_bit (kINT7 )) {
521+ collisionFlags.set (kINT7BIT );
472522 if (collision.sel7 ()) {
473523 trigsel = true ;
524+ collisionFlags.set (kSEL7BIT );
474525 }
475526 }
476527 break ;
477528 case kMC :
478529 if (collision.sel7 ()) {
479530 trigsel = true ;
531+ collisionFlags.set (kSEL7BIT );
480532 }
481533 break ;
482534 default :
535+ collisionFlags.set (kMBBIT );
483536 trigsel = true ;
484537 break ;
485538 }
@@ -502,6 +555,14 @@ inline bool triggerSelectionReco(CollisionObject const& collision)
502555 coll.selection_bit (aod::evsel::kIsGoodZvtxFT0vsPV ) &&
503556 coll.selection_bit (aod::evsel::kIsVertexITSTPC );
504557 };
558+ auto setCollisionFlags = [](auto & flags, auto const & coll) {
559+ flags.set (kSEL8BIT , coll.sel8 () != 0 );
560+ flags.set (kNOSAMEBUNCHPUPBIT , coll.selection_bit (aod::evsel::kNoSameBunchPileup ));
561+ flags.set (kISGOODZVTXFT0VSPVBIT , coll.selection_bit (aod::evsel::kIsGoodZvtxFT0vsPV ));
562+ flags.set (kISVERTEXITSTPCBIT , coll.selection_bit (aod::evsel::kIsVertexITSTPC ));
563+ flags.set (kISVERTEXTOFMATCHEDBIT , coll.selection_bit (aod::evsel::kIsVertexTOFmatched ));
564+ flags.set (kISVERTEXTRDMATCHEDBIT , coll.selection_bit (aod::evsel::kIsVertexTRDmatched ));
565+ };
505566 switch (fTriggerSelection ) {
506567 case kMB :
507568 if (run3Accepted (collision)) {
@@ -549,6 +610,7 @@ inline bool triggerSelectionReco(CollisionObject const& collision)
549610 default :
550611 break ;
551612 }
613+ setCollisionFlags (collisionFlags, collision);
552614 } break ;
553615 default :
554616 break ;
@@ -704,6 +766,7 @@ inline bool centralitySelectionMult(CollisionObject collision, float& centmult)
704766 float mult = getCentMultPercentile (collision);
705767 if (mult < 100 && 0 < mult) {
706768 centmult = mult;
769+ collisionFlags.set (kCENTRALITYBIT );
707770 return true ;
708771 }
709772 return false ;
@@ -718,6 +781,7 @@ inline bool centralitySelectionNoMult(CollisionObject const&, float& centmult)
718781 case kNOCM :
719782 centmult = 50.0 ;
720783 centmultsel = true ;
784+ collisionFlags.set (kCENTRALITYBIT );
721785 break ;
722786 default :
723787 break ;
@@ -786,31 +850,125 @@ inline bool centralitySelection<aod::McCollision>(aod::McCollision const&, float
786850 }
787851}
788852
853+ // ////////////////////////////////////////////////////////////////////////////////
854+ // / Occupancy selection
855+ // ////////////////////////////////////////////////////////////////////////////////
856+
857+ // / \brief get the collision occupancy
858+ template <typename CollisionObject>
859+ inline bool selectOnOccupancy (CollisionObject collision)
860+ {
861+ switch (fOccupancyEstimation ) {
862+ case kNOOCC :
863+ collisionFlags.set (kOCCUPANCYBIT );
864+ return true ;
865+ case kTRACKSOCC :
866+ if (collision.trackOccupancyInTimeRange () < fMaxOccupancy ) {
867+ collisionFlags.set (kOCCUPANCYBIT );
868+ return true ;
869+ } else {
870+ return false ;
871+ }
872+ case kFT0COCC :
873+ if (collision.ft0cOccupancyInTimeRange () < fMaxOccupancy ) {
874+ collisionFlags.set (kOCCUPANCYBIT );
875+ return true ;
876+ } else {
877+ return false ;
878+ }
879+ default :
880+ return false ;
881+ }
882+ }
883+
884+ // / \brief Occupancy selection by default: unknown subscribed collision table
885+ template <typename CollisionObject>
886+ inline bool occupancySelection (CollisionObject const &)
887+ {
888+ LOGF (fatal, " Occupancy selection not implemented for this kind of collisions" );
889+ return false ;
890+ }
891+
892+ // / \brief Occupancy selection for reconstructed and detector level collision tables with centrality/multiplicity information
893+ template <>
894+ inline bool occupancySelection<aod::CollisionEvSelCent>(aod::CollisionEvSelCent const & collision)
895+ {
896+ return selectOnOccupancy (collision);
897+ }
898+
899+ // / \brief Occupancy selection for reconstructed and detector level collision tables with Run 2 centrality/multiplicity information
900+ template <>
901+ inline bool occupancySelection<aod::CollisionEvSelRun2Cent>(aod::CollisionEvSelRun2Cent const & collision)
902+ {
903+ return selectOnOccupancy (collision);
904+ }
905+
906+ // / \brief Occupancy selection for reconstructed and detector level collision tables without centrality/multiplicity information
907+ template <>
908+ inline bool occupancySelection<aod::CollisionEvSel>(aod::CollisionEvSel const & collision)
909+ {
910+ return selectOnOccupancy (collision);
911+ }
912+
913+ // / \brief Occupancy selection for detector level collision tables without centrality/multiplicity
914+ template <>
915+ inline bool occupancySelection<soa::Join<aod::CollisionsEvSel, aod::McCollisionLabels>::iterator>(soa::Join<aod::CollisionsEvSel, aod::McCollisionLabels>::iterator const & collision)
916+ {
917+ return selectOnOccupancy (collision);
918+ }
919+
920+ // / \brief Occupancy selection for detector level collision tables with centrality/multiplicity
921+ template <>
922+ inline bool occupancySelection<soa::Join<aod::CollisionsEvSelCent, aod::McCollisionLabels>::iterator>(soa::Join<aod::CollisionsEvSelCent, aod::McCollisionLabels>::iterator const & collision)
923+ {
924+ return selectOnOccupancy (collision);
925+ }
926+
927+ // / \brief Occupancy selection for detector level collision tables with Run 2 centrality/multiplicity
928+ template <>
929+ inline bool occupancySelection<soa::Join<aod::CollisionsEvSelRun2Cent, aod::McCollisionLabels>::iterator>(soa::Join<aod::CollisionsEvSelRun2Cent, aod::McCollisionLabels>::iterator const & collision)
930+ {
931+ return selectOnOccupancy (collision);
932+ }
933+
934+ // / \brief Occupancy selection for generator level collision table
935+ template <>
936+ inline bool occupancySelection<aod::McCollision>(aod::McCollision const &)
937+ {
938+ return true ;
939+ }
940+
789941// ////////////////////////////////////////////////////////////////////////////////
790942// / Event selection
791943// ////////////////////////////////////////////////////////////////////////////////
792944
793945template <typename CollisionObject>
794946inline bool IsEvtSelected (CollisionObject const & collision, float & centormult)
795947{
948+ collisionFlags.reset ();
949+
796950 bool trigsel = triggerSelection (collision);
797951
952+ bool occupancysel = occupancySelection (collision);
953+
798954 bool zvtxsel = false ;
799955 /* TODO: vertex quality checks */
800956 if (zvtxlow < collision.posZ () && collision.posZ () < zvtxup) {
801957 if (onlyInOneSide) {
802958 if (collision.posZ () != 0.0 ) {
803959 /* if only one side, we accept collisions which have zvtx different than zero */
804960 zvtxsel = true ;
961+ collisionFlags.set (kZVERTEXBIT );
805962 }
806963 } else {
807964 zvtxsel = true ;
965+ collisionFlags.set (kZVERTEXBIT );
808966 }
809967 }
810968
811969 bool centmultsel = centralitySelection (collision, centormult);
812970
813- return trigsel && zvtxsel && centmultsel;
971+ return trigsel && occupancysel && zvtxsel && centmultsel;
814972}
815973
816974// ////////////////////////////////////////////////////////////////////////////////
0 commit comments