Skip to content

Commit 92a2669

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 73044db commit 92a2669

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
@@ -256,6 +256,7 @@ class AODProducerWorkflowDPL : public Task
256256

257257
int mNThreads = 1;
258258
bool mUseMC = true;
259+
bool mUseSigFiltMC = false; // enable signal filtering for MC with embedding
259260
bool mEnableSV = true; // enable secondary vertices
260261
bool mFieldON = false;
261262
const float cSpeed = 0.029979246f; // speed of light in TOF units

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

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

906906
// helper function to add a particle/track to the MC keep store
907-
void keepMCParticle(std::vector<std::vector<std::unordered_map<int, int>>>& store, int source, int event, int track, int value = 1)
907+
void keepMCParticle(std::vector<std::vector<std::unordered_map<int, int>>>& store, int source, int event, int track, int value = 1, bool useSigFilt = false)
908908
{
909909
if (track < 0) {
910910
LOG(warn) << "trackID is smaller than 0. Neglecting";
911911
return;
912912
}
913-
store[source][event][track] = value;
913+
if (useSigFilt && source == 0) {
914+
store[source][event][track] = -1;
915+
} else {
916+
store[source][event][track] = value;
917+
}
914918
}
915919

916920
void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader& mcReader,
@@ -939,7 +943,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
939943
if (!mcLabel.isValid()) {
940944
return;
941945
}
942-
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID());
946+
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID(), 1, mUseSigFiltMC);
943947
};
944948

945949
// mark reconstructed MC particles to store them into the table
@@ -954,7 +958,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
954958
if (!mcTruth.isValid()) {
955959
continue;
956960
}
957-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
961+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
958962
// treating contributors of global tracks
959963
auto contributorsGID = data.getSingleDetectorRefs(trackIndex);
960964
if (contributorsGID[GIndex::Source::TPC].isIndexSet()) {
@@ -969,7 +973,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
969973
if (!mcLabel.isValid()) {
970974
continue;
971975
}
972-
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID());
976+
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID(), 1, mUseSigFiltMC);
973977
}
974978
}
975979
}
@@ -983,7 +987,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
983987
if (!mcTruth.isValid()) {
984988
continue;
985989
}
986-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
990+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
987991
}
988992
}
989993
if (mInputSources[GIndex::PHS]) {
@@ -992,7 +996,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
992996
if (!mcTruth.isValid()) {
993997
continue;
994998
}
995-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
999+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
9961000
}
9971001
}
9981002
using namespace aodmchelpers;
@@ -1708,6 +1712,8 @@ void AODProducerWorkflowDPL::init(InitContext& ic)
17081712
LOG(info) << "The Run number will be obtained from DPL headers";
17091713
}
17101714

1715+
mUseSigFiltMC = ic.options().get<bool>("mc-signal-filt");
1716+
17111717
// set no truncation if selected by user
17121718
if (mTruncate != 1) {
17131719
LOG(info) << "Truncation is not used!";
@@ -1980,6 +1986,24 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
19801986
int totalNParts = 0;
19811987
for (int iCol = 0; iCol < nMCCollisions; iCol++) {
19821988
totalNParts += mcParts[iCol].size();
1989+
1990+
// if signal filtering enabled, let's check if there are more than one source; otherwise fatalise
1991+
if (mUseSigFiltMC) {
1992+
std::vector<int> sourceIDs{};
1993+
auto& colParts = mcParts[iCol];
1994+
for (auto colPart : colParts) {
1995+
int sourceID = colPart.sourceID;
1996+
if (std::find(sourceIDs.begin(), sourceIDs.end(), sourceID) == sourceIDs.end()) {
1997+
sourceIDs.push_back(sourceID);
1998+
}
1999+
if (sourceIDs.size() > 1) { // we found more than one, exit
2000+
break;
2001+
}
2002+
}
2003+
if (sourceIDs.size() <= 1) {
2004+
LOGP(fatal, "Signal filtering cannot be enabled without embedding. Please fix the configuration either enabling the embedding, or turning off the signal filtering.");
2005+
}
2006+
}
19832007
}
19842008
mcCollisionsCursor.reserve(totalNParts);
19852009

@@ -2017,7 +2041,9 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
20172041
0,
20182042
sourceID);
20192043
}
2020-
mcColToEvSrc.emplace_back(std::vector<int>{iCol, sourceID, eventID}); // point background and injected signal events to one collision
2044+
if (sourceID != 0 || !mUseSigFiltMC) {
2045+
mcColToEvSrc.emplace_back(std::vector<int>{iCol, sourceID, eventID}); // point background and injected signal events to one collision
2046+
}
20212047
}
20222048
}
20232049
}
@@ -3205,7 +3231,7 @@ DataProcessorSpec getAODProducerWorkflowSpec(GID::mask_t src, bool enableSV, boo
32053231
ConfigParamSpec{"trackqc-NTrCut", VariantType::Int64, 4L, {"Minimal length of the track - in amount of tracklets"}},
32063232
ConfigParamSpec{"with-streamers", VariantType::String, "", {"Bit-mask to steer writing of intermediate streamer files"}},
32073233
ConfigParamSpec{"seed", VariantType::Int, 0, {"Set seed for random generator used for sampling (0 (default) means using a random_device)"}},
3208-
}};
3234+
ConfigParamSpec{"mc-signal-filt", VariantType::Bool, false, {"Enable usage of signal filtering (only for MC with embedding)"}}}};
32093235
}
32103236

32113237
} // namespace o2::aodproducer

0 commit comments

Comments
 (0)