Skip to content

Commit 0b91842

Browse files
authored
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 774014b commit 0b91842

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 mEnableFITextra = false;
261262
bool mFieldON = false;

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

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

949949
// helper function to add a particle/track to the MC keep store
950-
void keepMCParticle(std::vector<std::vector<std::unordered_map<int, int>>>& store, int source, int event, int track, int value = 1)
950+
void keepMCParticle(std::vector<std::vector<std::unordered_map<int, int>>>& store, int source, int event, int track, int value = 1, bool useSigFilt = false)
951951
{
952952
if (track < 0) {
953953
LOG(warn) << "trackID is smaller than 0. Neglecting";
954954
return;
955955
}
956-
store[source][event][track] = value;
956+
if (useSigFilt && source == 0) {
957+
store[source][event][track] = -1;
958+
} else {
959+
store[source][event][track] = value;
960+
}
957961
}
958962

959963
void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader& mcReader,
@@ -982,7 +986,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
982986
if (!mcLabel.isValid()) {
983987
return;
984988
}
985-
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID());
989+
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID(), 1, mUseSigFiltMC);
986990
};
987991

988992
// mark reconstructed MC particles to store them into the table
@@ -997,7 +1001,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
9971001
if (!mcTruth.isValid()) {
9981002
continue;
9991003
}
1000-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
1004+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
10011005
// treating contributors of global tracks
10021006
auto contributorsGID = data.getSingleDetectorRefs(trackIndex);
10031007
if (contributorsGID[GIndex::Source::TPC].isIndexSet()) {
@@ -1012,7 +1016,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
10121016
if (!mcLabel.isValid()) {
10131017
continue;
10141018
}
1015-
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID());
1019+
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID(), 1, mUseSigFiltMC);
10161020
}
10171021
}
10181022
}
@@ -1026,7 +1030,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
10261030
if (!mcTruth.isValid()) {
10271031
continue;
10281032
}
1029-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
1033+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
10301034
}
10311035
}
10321036
if (mInputSources[GIndex::PHS]) {
@@ -1035,7 +1039,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
10351039
if (!mcTruth.isValid()) {
10361040
continue;
10371041
}
1038-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
1042+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
10391043
}
10401044
}
10411045
using namespace aodmchelpers;
@@ -1743,6 +1747,8 @@ void AODProducerWorkflowDPL::init(InitContext& ic)
17431747
LOG(info) << "The Run number will be obtained from DPL headers";
17441748
}
17451749

1750+
mUseSigFiltMC = ic.options().get<bool>("mc-signal-filt");
1751+
17461752
// set no truncation if selected by user
17471753
if (mTruncate != 1) {
17481754
LOG(info) << "Truncation is not used!";
@@ -2061,6 +2067,24 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
20612067
int totalNParts = 0;
20622068
for (int iCol = 0; iCol < nMCCollisions; iCol++) {
20632069
totalNParts += mcParts[iCol].size();
2070+
2071+
// if signal filtering enabled, let's check if there are more than one source; otherwise fatalise
2072+
if (mUseSigFiltMC) {
2073+
std::vector<int> sourceIDs{};
2074+
auto& colParts = mcParts[iCol];
2075+
for (auto colPart : colParts) {
2076+
int sourceID = colPart.sourceID;
2077+
if (std::find(sourceIDs.begin(), sourceIDs.end(), sourceID) == sourceIDs.end()) {
2078+
sourceIDs.push_back(sourceID);
2079+
}
2080+
if (sourceIDs.size() > 1) { // we found more than one, exit
2081+
break;
2082+
}
2083+
}
2084+
if (sourceIDs.size() <= 1) {
2085+
LOGP(fatal, "Signal filtering cannot be enabled without embedding. Please fix the configuration either enabling the embedding, or turning off the signal filtering.");
2086+
}
2087+
}
20642088
}
20652089
mcCollisionsCursor.reserve(totalNParts);
20662090

@@ -2098,7 +2122,9 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
20982122
0,
20992123
sourceID);
21002124
}
2101-
mcColToEvSrc.emplace_back(std::vector<int>{iCol, sourceID, eventID}); // point background and injected signal events to one collision
2125+
if (sourceID != 0 || !mUseSigFiltMC) {
2126+
mcColToEvSrc.emplace_back(std::vector<int>{iCol, sourceID, eventID}); // point background and injected signal events to one collision
2127+
}
21022128
}
21032129
}
21042130
}
@@ -3326,7 +3352,7 @@ DataProcessorSpec getAODProducerWorkflowSpec(GID::mask_t src, bool enableSV, boo
33263352
ConfigParamSpec{"trackqc-tpc-pt", VariantType::Float, 0.2f, {"Keep TPC standalone track with this pt"}},
33273353
ConfigParamSpec{"with-streamers", VariantType::String, "", {"Bit-mask to steer writing of intermediate streamer files"}},
33283354
ConfigParamSpec{"seed", VariantType::Int, 0, {"Set seed for random generator used for sampling (0 (default) means using a random_device)"}},
3329-
}};
3355+
ConfigParamSpec{"mc-signal-filt", VariantType::Bool, false, {"Enable usage of signal filtering (only for MC with embedding)"}}}};
33303356
}
33313357

33323358
} // namespace o2::aodproducer

0 commit comments

Comments
 (0)