Skip to content

Commit 869f312

Browse files
fgrosaalcaliva
authored andcommitted
Add possibility to apply signal filtering for MC with embedding (#14698)
* Add possibility to apply signal filtering for MC with embedding * Add protection for signal filtering to be enabled only with emdedding
1 parent 2626074 commit 869f312

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

Detectors/AOD/include/AODProducerWorkflow/AODProducerWorkflowSpec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class AODProducerWorkflowDPL : public Task
253253

254254
int mNThreads = 1;
255255
bool mUseMC = true;
256+
bool mUseSigFiltMC = false; // enable signal filtering for MC with embedding
256257
bool mEnableSV = true; // enable secondary vertices
257258
bool mEnableFITextra = false;
258259
bool mFieldON = false;

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -931,13 +931,17 @@ void clearMCKeepStore(std::vector<std::vector<std::unordered_map<int, int>>>& st
931931
}
932932

933933
// helper function to add a particle/track to the MC keep store
934-
void keepMCParticle(std::vector<std::vector<std::unordered_map<int, int>>>& store, int source, int event, int track, int value = 1)
934+
void keepMCParticle(std::vector<std::vector<std::unordered_map<int, int>>>& store, int source, int event, int track, int value = 1, bool useSigFilt = false)
935935
{
936936
if (track < 0) {
937937
LOG(warn) << "trackID is smaller than 0. Neglecting";
938938
return;
939939
}
940-
store[source][event][track] = value;
940+
if (useSigFilt && source == 0) {
941+
store[source][event][track] = -1;
942+
} else {
943+
store[source][event][track] = value;
944+
}
941945
}
942946

943947
void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader& mcReader,
@@ -966,7 +970,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
966970
if (!mcLabel.isValid()) {
967971
return;
968972
}
969-
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID());
973+
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID(), 1, mUseSigFiltMC);
970974
};
971975

972976
// mark reconstructed MC particles to store them into the table
@@ -981,7 +985,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
981985
if (!mcTruth.isValid()) {
982986
continue;
983987
}
984-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
988+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
985989
// treating contributors of global tracks
986990
auto contributorsGID = data.getSingleDetectorRefs(trackIndex);
987991
if (contributorsGID[GIndex::Source::TPC].isIndexSet()) {
@@ -996,7 +1000,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
9961000
if (!mcLabel.isValid()) {
9971001
continue;
9981002
}
999-
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID());
1003+
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID(), 1, mUseSigFiltMC);
10001004
}
10011005
}
10021006
}
@@ -1010,7 +1014,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
10101014
if (!mcTruth.isValid()) {
10111015
continue;
10121016
}
1013-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
1017+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
10141018
}
10151019
}
10161020
if (mInputSources[GIndex::PHS]) {
@@ -1019,7 +1023,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
10191023
if (!mcTruth.isValid()) {
10201024
continue;
10211025
}
1022-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
1026+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
10231027
}
10241028
}
10251029
using namespace aodmchelpers;
@@ -1707,6 +1711,8 @@ void AODProducerWorkflowDPL::init(InitContext& ic)
17071711
LOG(info) << "The Run number will be obtained from DPL headers";
17081712
}
17091713

1714+
mUseSigFiltMC = ic.options().get<bool>("mc-signal-filt");
1715+
17101716
// set no truncation if selected by user
17111717
if (mTruncate != 1) {
17121718
LOG(info) << "Truncation is not used!";
@@ -1993,6 +1999,24 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
19931999
int totalNParts = 0;
19942000
for (int iCol = 0; iCol < nMCCollisions; iCol++) {
19952001
totalNParts += mcParts[iCol].size();
2002+
2003+
// if signal filtering enabled, let's check if there are more than one source; otherwise fatalise
2004+
if (mUseSigFiltMC) {
2005+
std::vector<int> sourceIDs{};
2006+
auto& colParts = mcParts[iCol];
2007+
for (auto colPart : colParts) {
2008+
int sourceID = colPart.sourceID;
2009+
if (std::find(sourceIDs.begin(), sourceIDs.end(), sourceID) == sourceIDs.end()) {
2010+
sourceIDs.push_back(sourceID);
2011+
}
2012+
if (sourceIDs.size() > 1) { // we found more than one, exit
2013+
break;
2014+
}
2015+
}
2016+
if (sourceIDs.size() <= 1) {
2017+
LOGP(fatal, "Signal filtering cannot be enabled without embedding. Please fix the configuration either enabling the embedding, or turning off the signal filtering.");
2018+
}
2019+
}
19962020
}
19972021
mcCollisionsCursor.reserve(totalNParts);
19982022

@@ -2030,7 +2054,9 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
20302054
0,
20312055
sourceID);
20322056
}
2033-
mcColToEvSrc.emplace_back(std::vector<int>{iCol, sourceID, eventID}); // point background and injected signal events to one collision
2057+
if (sourceID != 0 || !mUseSigFiltMC) {
2058+
mcColToEvSrc.emplace_back(std::vector<int>{iCol, sourceID, eventID}); // point background and injected signal events to one collision
2059+
}
20342060
}
20352061
}
20362062
}
@@ -3239,7 +3265,7 @@ DataProcessorSpec getAODProducerWorkflowSpec(GID::mask_t src, bool enableSV, boo
32393265
ConfigParamSpec{"trackqc-NTrCut", VariantType::Int64, 4L, {"Minimal length of the track - in amount of tracklets"}},
32403266
ConfigParamSpec{"with-streamers", VariantType::String, "", {"Bit-mask to steer writing of intermediate streamer files"}},
32413267
ConfigParamSpec{"seed", VariantType::Int, 0, {"Set seed for random generator used for sampling (0 (default) means using a random_device)"}},
3242-
}};
3268+
ConfigParamSpec{"mc-signal-filt", VariantType::Bool, false, {"Enable usage of signal filtering (only for MC with embedding)"}}}};
32433269
}
32443270

32453271
} // namespace o2::aodproducer

0 commit comments

Comments
 (0)