Skip to content

Commit 8c22488

Browse files
iarseneIonut Cristian Arsene
andauthored
[PWGDQ] Adding protections to the prefiltering task; fix problem with exclusive MCSignals (#8831)
Co-authored-by: Ionut Cristian Arsene <iarsene@cern.ch>
1 parent 91d52aa commit 8c22488

File tree

5 files changed

+119
-68
lines changed

5 files changed

+119
-68
lines changed

PWGDQ/Core/MCSignal.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ MCSignal::MCSignal() : TNamed("", ""),
2727
fExcludeCommonAncestor(false),
2828
fTempAncestorLabel(-1),
2929
fDecayChannelIsExclusive(false),
30-
fDecayChannelIsNotExclusive(false)
30+
fDecayChannelIsNotExclusive(false),
31+
fNAncestorDirectProngs(0)
3132
{
3233
}
3334

@@ -39,7 +40,8 @@ MCSignal::MCSignal(int nProngs, const char* name /*= ""*/, const char* title /*=
3940
fExcludeCommonAncestor(false),
4041
fTempAncestorLabel(-1),
4142
fDecayChannelIsExclusive(false),
42-
fDecayChannelIsNotExclusive(false)
43+
fDecayChannelIsNotExclusive(false),
44+
fNAncestorDirectProngs(0)
4345
{
4446
fProngs.reserve(nProngs);
4547
}
@@ -52,7 +54,8 @@ MCSignal::MCSignal(const char* name, const char* title, std::vector<MCProng> pro
5254
fExcludeCommonAncestor(excludeCommonAncestor),
5355
fTempAncestorLabel(-1),
5456
fDecayChannelIsExclusive(false),
55-
fDecayChannelIsNotExclusive(false)
57+
fDecayChannelIsNotExclusive(false),
58+
fNAncestorDirectProngs(0)
5659
{
5760
}
5861

@@ -82,6 +85,7 @@ void MCSignal::PrintConfig()
8285
cout << "Exclude common ancestor combinations: " << fExcludeCommonAncestor << endl;
8386
cout << "Decay channel is exclusive: " << fDecayChannelIsExclusive << endl;
8487
cout << "Decay channel is not exclusive: " << fDecayChannelIsNotExclusive << endl;
88+
cout << "Decay channel direct prongs for the common ancestor: " << fNAncestorDirectProngs << endl;
8589
cout << "Printing " << fNProngs << "/" << fProngs.size() << " prongs:" << endl;
8690
int i = 0;
8791
for (auto& pr : fProngs) {

PWGDQ/Core/MCSignal.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ class MCSignal : public TNamed
7373

7474
void SetProngs(std::vector<MCProng> prongs, std::vector<int8_t> commonAncestors);
7575
void AddProng(MCProng prong, int8_t commonAncestor = -1);
76-
void SetDecayChannelIsExclusive(bool option = true)
76+
void SetDecayChannelIsExclusive(int nProngs, bool option = true)
7777
{
7878
fDecayChannelIsExclusive = option;
79+
fNAncestorDirectProngs = nProngs;
7980
}
80-
void SetDecayChannelIsNotExclusive(bool option = true)
81+
void SetDecayChannelIsNotExclusive(int nProngs, bool option = true)
8182
{
8283
fDecayChannelIsNotExclusive = option;
84+
fNAncestorDirectProngs = nProngs;
8385
}
8486

8587
int GetNProngs() const
@@ -98,6 +100,10 @@ class MCSignal : public TNamed
98100
{
99101
return fDecayChannelIsNotExclusive;
100102
}
103+
int GetNAncestorDirectProngs() const
104+
{
105+
return fNAncestorDirectProngs;
106+
}
101107

102108
template <typename... T>
103109
bool CheckSignal(bool checkSources, const T&... args)
@@ -117,8 +123,9 @@ class MCSignal : public TNamed
117123
unsigned int fNProngs; // number of prongs
118124
std::vector<int8_t> fCommonAncestorIdxs; // index of the most recent ancestor, relative to each prong's history
119125
bool fExcludeCommonAncestor; // explicitly request that there is no common ancestor
120-
bool fDecayChannelIsExclusive; // if true, then the indicated mother particle has a number of daughters which is equal to the number of prongs defined in this MC signal
121-
bool fDecayChannelIsNotExclusive; // if true, then the indicated mother particle has a number of daughters which is larger than the number of prongs defined in this MC signal
126+
bool fDecayChannelIsExclusive; // if true, then the indicated mother particle has a number of daughters which is equal to the number of direct prongs defined in this MC signal
127+
bool fDecayChannelIsNotExclusive; // if true, then the indicated mother particle has a number of daughters which is larger than the number of direct prongs defined in this MC signal
128+
int fNAncestorDirectProngs; // number of direct prongs belonging to the common ancestor specified by this signal
122129
int fTempAncestorLabel;
123130

124131
template <typename T>
@@ -162,10 +169,10 @@ bool MCSignal::CheckProng(int i, bool checkSources, const T& track)
162169
// If these numbers are equal, it means this decay MCSignal match is exclusive (there are no additional prongs for this mother besides the
163170
// prongs defined here).
164171
if (currentMCParticle.has_daughters()) {
165-
if (fDecayChannelIsExclusive && currentMCParticle.daughtersIds()[1] - currentMCParticle.daughtersIds()[0] + 1 != fNProngs) {
172+
if (fDecayChannelIsExclusive && currentMCParticle.daughtersIds()[1] - currentMCParticle.daughtersIds()[0] + 1 != fNAncestorDirectProngs) {
166173
return false;
167174
}
168-
if (fDecayChannelIsNotExclusive && currentMCParticle.daughtersIds()[1] - currentMCParticle.daughtersIds()[0] + 1 == fNProngs) {
175+
if (fDecayChannelIsNotExclusive && currentMCParticle.daughtersIds()[1] - currentMCParticle.daughtersIds()[0] + 1 == fNAncestorDirectProngs) {
169176
return false;
170177
}
171178
}

PWGDQ/Core/MCSignalLibrary.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,14 +712,14 @@ MCSignal* o2::aod::dqmcsignals::GetMCSignal(const char* name)
712712
MCProng prong(2, {11, 443}, {true, true}, {false, false}, {0, 0}, {0, 0}, {false, false});
713713
prong.SetSourceBit(0, MCProng::kPhysicalPrimary);
714714
signal = new MCSignal(name, "ee pairs from j/psi decays", {prong, prong}, {1, 1}); // signal at pair level
715-
signal->SetDecayChannelIsExclusive(true);
715+
signal->SetDecayChannelIsExclusive(2, true);
716716
return signal;
717717
}
718718
if (!nameStr.compare("eeFromJpsiNotExclusive")) {
719719
MCProng prong(2, {11, 443}, {true, true}, {false, false}, {0, 0}, {0, 0}, {false, false});
720720
prong.SetSourceBit(0, MCProng::kPhysicalPrimary);
721721
signal = new MCSignal(name, "ee pairs from j/psi decays", {prong, prong}, {1, 1}); // signal at pair level
722-
signal->SetDecayChannelIsNotExclusive(true);
722+
signal->SetDecayChannelIsNotExclusive(2, true);
723723
return signal;
724724
}
725725
if (!nameStr.compare("eePrimaryFromPromptJPsi")) {
@@ -1145,15 +1145,15 @@ MCSignal* o2::aod::dqmcsignals::GetMCSignal(const char* name)
11451145
MCProng pronge(3, {11, 443, 521}, {true, true, true}, {false, false, false}, {0, 0, 0}, {0, 0, 0}, {false, false, false});
11461146
MCProng prongKaon(2, {321, 521}, {true, true}, {false, false}, {0, 0}, {0, 0}, {false, false});
11471147
signal = new MCSignal(name, "Kaon and electron pair from B+", {pronge, pronge, prongKaon}, {2, 2, 1});
1148-
signal->SetDecayChannelIsExclusive(true);
1148+
signal->SetDecayChannelIsExclusive(2, true);
11491149
return signal;
11501150
}
11511151

11521152
if (!nameStr.compare("eeKaonFromBplusNotExclusive")) {
11531153
MCProng pronge(3, {11, 443, 521}, {true, true, true}, {false, false, false}, {0, 0, 0}, {0, 0, 0}, {false, false, false});
11541154
MCProng prongKaon(2, {321, 521}, {true, true}, {false, false}, {0, 0}, {0, 0}, {false, false});
11551155
signal = new MCSignal(name, "Kaon and electron pair from B+", {pronge, pronge, prongKaon}, {2, 2, 1});
1156-
signal->SetDecayChannelIsNotExclusive(true);
1156+
signal->SetDecayChannelIsNotExclusive(2, true);
11571157
return signal;
11581158
}
11591159

PWGDQ/Tasks/dqEfficiency_withAssoc.cxx

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ struct AnalysisPrefilterSelection {
919919
Configurable<std::string> fConfigPrefilterPairCut{"cfgPrefilterPairCut", "", "Prefilter pair cut"};
920920
Configurable<std::string> fConfigTrackCuts{"cfgTrackCuts", "", "Track cuts for which to run the prefilter"};
921921
// Track related options
922-
Configurable<bool> fPropTrack{"cfgPropTrack", true, "Propgate tracks to associated collision to recalculate DCA and momentum vector"};
922+
Configurable<bool> fPropTrack{"cfgPropTrack", false, "Propgate tracks to associated collision to recalculate DCA and momentum vector"};
923923

924924
std::map<uint32_t, uint32_t> fPrefilterMap;
925925
AnalysisCompositeCut* fPairCut;
@@ -934,23 +934,39 @@ struct AnalysisPrefilterSelection {
934934
return;
935935
}
936936

937+
bool runPrefilter = true;
937938
// get the list of track cuts to be prefiltered
938939
TString trackCutsStr = fConfigTrackCuts.value;
939940
TObjArray* objArrayTrackCuts = nullptr;
940941
if (!trackCutsStr.IsNull()) {
941942
objArrayTrackCuts = trackCutsStr.Tokenize(",");
943+
if (objArrayTrackCuts == nullptr) {
944+
runPrefilter = false;
945+
}
946+
} else {
947+
LOG(warn) << " No track cuts to prefilter! Prefilter will not be run";
948+
runPrefilter = false;
949+
}
950+
// get the cut to be used as loose selection
951+
TString prefilterTrackCutStr = fConfigPrefilterTrackCut.value;
952+
if (prefilterTrackCutStr.IsNull()) {
953+
LOG(warn) << " No prefilter loose selection specified! Prefilter will not be run";
954+
runPrefilter = false;
942955
}
943956

944-
// get the list of cuts that were computed in the barrel track-selection task and create a bit mask
945-
// to mark just the ones we want to apply a prefilter on
946957
fPrefilterMask = 0;
947958
fPrefilterCutBit = -1;
948-
string trackCuts;
949-
getTaskOptionValue<string>(context, "analysis-track-selection", "cfgTrackCuts", trackCuts, false);
950-
TString allTrackCutsStr = trackCuts;
951-
TString prefilterTrackCutStr = fConfigPrefilterTrackCut.value;
952-
if (!trackCutsStr.IsNull()) {
959+
if (runPrefilter) {
960+
// get the list of cuts that were computed in the barrel track-selection task and create a bit mask
961+
// to mark just the ones we want to apply a prefilter on
962+
string trackCuts;
963+
getTaskOptionValue<string>(context, "analysis-track-selection", "cfgTrackCuts", trackCuts, false);
964+
TString allTrackCutsStr = trackCuts;
965+
953966
std::unique_ptr<TObjArray> objArray(allTrackCutsStr.Tokenize(","));
967+
if (objArray == nullptr) {
968+
LOG(fatal) << " Not getting any track cuts from the barrel-track-selection ";
969+
}
954970
if (objArray->FindObject(prefilterTrackCutStr.Data()) == nullptr) {
955971
LOG(fatal) << " Prefilter track cut not among the cuts calculated by the track-selection task! ";
956972
}
@@ -963,18 +979,15 @@ struct AnalysisPrefilterSelection {
963979
fPrefilterCutBit = icut;
964980
}
965981
}
982+
// setup the prefilter pair cut
983+
fPairCut = new AnalysisCompositeCut(true);
984+
TString pairCutStr = fConfigPrefilterPairCut.value;
985+
if (!pairCutStr.IsNull()) {
986+
fPairCut = dqcuts::GetCompositeCut(pairCutStr.Data());
987+
}
966988
}
967-
// NOTE: If no prefilter loose cut is specified to be "prefiltered" or no track cuts are asked to be prefiltered,
968-
// then make a warning. In the processing, the produced table will just lead to a neutral behaviour (no prefilter applied)
969989
if (fPrefilterMask == static_cast<uint32_t>(0) || fPrefilterCutBit < 0) {
970-
LOG(warn) << "No loose cut or track cuts for prefiltering are specified. This task will do nothing.";
971-
}
972-
973-
// setup the prefilter pair cut
974-
fPairCut = new AnalysisCompositeCut(true);
975-
TString pairCutStr = fConfigPrefilterPairCut.value;
976-
if (!pairCutStr.IsNull()) {
977-
fPairCut = dqcuts::GetCompositeCut(pairCutStr.Data());
990+
LOG(warn) << "No specified loose cut or track cuts for prefiltering. This task will do nothing.";
978991
}
979992

980993
VarManager::SetUseVars(AnalysisCut::fgUsedVars); // provide the list of required variables so that VarManager knows what to fill
@@ -1039,18 +1052,26 @@ struct AnalysisPrefilterSelection {
10391052
runPrefilter<gkTrackFillMap>(event, groupedAssocs, tracks);
10401053
}
10411054
}
1055+
10421056
uint32_t mymap = -1;
1043-
for (auto& assoc : assocs) {
1044-
auto track = assoc.template reducedtrack_as<MyBarrelTracks>();
1045-
mymap = -1;
1046-
// If cuts were not configured, then produce a map with all 1's
1047-
if (fPrefilterCutBit < 0 || fPrefilterMask == 0) {
1048-
prefilter(mymap);
1049-
} else if (fPrefilterMap.find(track.globalIndex()) != fPrefilterMap.end()) {
1050-
// NOTE: publish the bitwise negated bits (~), so there will be zeroes for cuts that failed the prefiltering and 1 everywhere else
1051-
mymap = ~fPrefilterMap[track.globalIndex()];
1057+
// If cuts were not configured, then produce a map with all 1's and publish it for all associations
1058+
if (fPrefilterCutBit < 0 || fPrefilterMask == 0) {
1059+
for (int i = 0; i < assocs.size(); ++i) {
10521060
prefilter(mymap);
10531061
}
1062+
} else {
1063+
for (auto& assoc : assocs) {
1064+
// TODO: just use the index from the assoc (no need to cast the whole track)
1065+
auto track = assoc.template reducedtrack_as<MyBarrelTracks>();
1066+
mymap = -1;
1067+
if (fPrefilterMap.find(track.globalIndex()) != fPrefilterMap.end()) {
1068+
// NOTE: publish the bitwise negated bits (~), so there will be zeroes for cuts that failed the prefiltering and 1 everywhere else
1069+
mymap = ~fPrefilterMap[track.globalIndex()];
1070+
prefilter(mymap);
1071+
} else {
1072+
prefilter(mymap); // track did not pass the prefilter selections, so publish just 1's
1073+
}
1074+
}
10541075
}
10551076
}
10561077

PWGDQ/Tasks/tableReader_withAssoc.cxx

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -856,32 +856,47 @@ struct AnalysisPrefilterSelection {
856856
uint32_t fPrefilterMask;
857857
int fPrefilterCutBit;
858858

859+
Preslice<aod::ReducedTracksAssoc> trackAssocsPerCollision = aod::reducedtrack_association::reducedeventId;
860+
859861
void init(o2::framework::InitContext& context)
860862
{
861863
if (context.mOptions.get<bool>("processDummy")) {
862864
return;
863865
}
864866

867+
bool runPrefilter = true;
865868
// get the list of track cuts to be prefiltered
866869
TString trackCutsStr = fConfigTrackCuts.value;
867870
TObjArray* objArrayTrackCuts = nullptr;
868871
if (!trackCutsStr.IsNull()) {
869872
objArrayTrackCuts = trackCutsStr.Tokenize(",");
873+
if (objArrayTrackCuts == nullptr) {
874+
runPrefilter = false;
875+
}
876+
} else {
877+
LOG(warn) << " No track cuts to prefilter! Prefilter will not be run";
878+
runPrefilter = false;
870879
}
871-
if (objArrayTrackCuts->GetEntries() == 0) {
872-
LOG(fatal) << " No track cuts to prefilter!";
880+
// get the cut to be used as loose selection
881+
TString prefilterTrackCutStr = fConfigPrefilterTrackCut.value;
882+
if (prefilterTrackCutStr.IsNull()) {
883+
LOG(warn) << " No prefilter loose selection specified! Prefilter will not be run";
884+
runPrefilter = false;
873885
}
874886

875-
// get the list of cuts that were computed in the barrel track-selection task and create a bit mask
876-
// to mark just the ones we want to apply a prefilter on
877887
fPrefilterMask = static_cast<uint32_t>(0);
878888
fPrefilterCutBit = -1;
879-
string trackCuts;
880-
getTaskOptionValue<string>(context, "analysis-track-selection", "cfgTrackCuts", trackCuts, false);
881-
TString allTrackCutsStr = trackCuts;
882-
TString prefilterTrackCutStr = fConfigPrefilterTrackCut.value;
883-
if (!trackCutsStr.IsNull()) {
889+
if (runPrefilter) {
890+
// get the list of cuts that were computed in the barrel track-selection task and create a bit mask
891+
// to mark just the ones we want to apply a prefilter on
892+
string trackCuts;
893+
getTaskOptionValue<string>(context, "analysis-track-selection", "cfgTrackCuts", trackCuts, false);
894+
TString allTrackCutsStr = trackCuts;
895+
884896
std::unique_ptr<TObjArray> objArray(allTrackCutsStr.Tokenize(","));
897+
if (objArray == nullptr) {
898+
LOG(fatal) << " Not getting any track cuts from the barrel-track-selection ";
899+
}
885900
if (objArray->FindObject(prefilterTrackCutStr.Data()) == nullptr) {
886901
LOG(fatal) << " Prefilter track cut not among the cuts calculated by the track-selection task! ";
887902
}
@@ -894,18 +909,17 @@ struct AnalysisPrefilterSelection {
894909
fPrefilterCutBit = icut;
895910
}
896911
}
912+
// setup the prefilter pair cut
913+
fPairCut = new AnalysisCompositeCut(true);
914+
TString pairCutStr = fConfigPrefilterPairCut.value;
915+
if (!pairCutStr.IsNull()) {
916+
fPairCut = dqcuts::GetCompositeCut(pairCutStr.Data());
917+
}
897918
}
898919
if (fPrefilterMask == static_cast<uint32_t>(0) || fPrefilterCutBit < 0) {
899920
LOG(warn) << "No specified loose cut or track cuts for prefiltering. This task will do nothing.";
900921
}
901922

902-
// setup the prefilter pair cut
903-
fPairCut = new AnalysisCompositeCut(true);
904-
TString pairCutStr = fConfigPrefilterPairCut.value;
905-
if (!pairCutStr.IsNull()) {
906-
fPairCut = dqcuts::GetCompositeCut(pairCutStr.Data());
907-
}
908-
909923
VarManager::SetUseVars(AnalysisCut::fgUsedVars); // provide the list of required variables so that VarManager knows what to fill
910924
VarManager::SetDefaultVarNames();
911925

@@ -955,11 +969,8 @@ struct AnalysisPrefilterSelection {
955969
} // end loop over combinations
956970
}
957971

958-
Preslice<aod::ReducedTracksAssoc> trackAssocsPerCollision = aod::reducedtrack_association::reducedeventId;
959-
960972
void processBarrelSkimmed(MyEvents const& events, soa::Join<aod::ReducedTracksAssoc, aod::BarrelTrackCuts> const& assocs, MyBarrelTracks const& tracks)
961973
{
962-
963974
fPrefilterMap.clear();
964975

965976
for (auto& event : events) {
@@ -968,18 +979,26 @@ struct AnalysisPrefilterSelection {
968979
runPrefilter<gkTrackFillMap>(groupedAssocs, tracks);
969980
}
970981
}
982+
971983
uint32_t mymap = -1;
972-
for (auto& assoc : assocs) {
973-
auto track = assoc.template reducedtrack_as<MyBarrelTracks>();
974-
mymap = -1;
975-
// If cuts were not configured, then produce a map with all 1's
976-
if (fPrefilterCutBit < 0 || fPrefilterMask == 0) {
977-
prefilter(mymap);
978-
} else if (fPrefilterMap.find(track.globalIndex()) != fPrefilterMap.end()) {
979-
// NOTE: publish the bitwise negated bits (~), so there will be zeroes for cuts that failed the prefiltering and 1 everywhere else
980-
mymap = ~fPrefilterMap[track.globalIndex()];
984+
// If cuts were not configured, then produce a map with all 1's and publish it for all associations
985+
if (fPrefilterCutBit < 0 || fPrefilterMask == 0) {
986+
for (int i = 0; i < assocs.size(); ++i) {
981987
prefilter(mymap);
982988
}
989+
} else {
990+
for (auto& assoc : assocs) {
991+
// TODO: just use the index from the assoc (no need to cast the whole track)
992+
auto track = assoc.template reducedtrack_as<MyBarrelTracks>();
993+
mymap = -1;
994+
if (fPrefilterMap.find(track.globalIndex()) != fPrefilterMap.end()) {
995+
// NOTE: publish the bitwise negated bits (~), so there will be zeroes for cuts that failed the prefiltering and 1 everywhere else
996+
mymap = ~fPrefilterMap[track.globalIndex()];
997+
prefilter(mymap);
998+
} else {
999+
prefilter(mymap); // track did not pass the prefilter selections, so publish just 1's
1000+
}
1001+
}
9831002
}
9841003
}
9851004

0 commit comments

Comments
 (0)