Skip to content

Commit 51da6c0

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 fb0d7e3 commit 51da6c0

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

244244
int mNThreads = 1;
245245
bool mUseMC = true;
246+
bool mUseSigFiltMC = false; // enable signal filtering for MC with embedding
246247
bool mEnableSV = true; // enable secondary vertices
247248
bool mFieldON = false;
248249
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
@@ -892,13 +892,17 @@ void clearMCKeepStore(std::vector<std::vector<std::unordered_map<int, int>>>& st
892892
}
893893

894894
// helper function to add a particle/track to the MC keep store
895-
void keepMCParticle(std::vector<std::vector<std::unordered_map<int, int>>>& store, int source, int event, int track, int value = 1)
895+
void keepMCParticle(std::vector<std::vector<std::unordered_map<int, int>>>& store, int source, int event, int track, int value = 1, bool useSigFilt = false)
896896
{
897897
if (track < 0) {
898898
LOG(warn) << "trackID is smaller than 0. Neglecting";
899899
return;
900900
}
901-
store[source][event][track] = value;
901+
if (useSigFilt && source == 0) {
902+
store[source][event][track] = -1;
903+
} else {
904+
store[source][event][track] = value;
905+
}
902906
}
903907

904908
void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader& mcReader,
@@ -927,7 +931,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
927931
if (!mcLabel.isValid()) {
928932
return;
929933
}
930-
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID());
934+
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID(), 1, mUseSigFiltMC);
931935
};
932936

933937
// mark reconstructed MC particles to store them into the table
@@ -942,7 +946,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
942946
if (!mcTruth.isValid()) {
943947
continue;
944948
}
945-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
949+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
946950
// treating contributors of global tracks
947951
auto contributorsGID = data.getSingleDetectorRefs(trackIndex);
948952
if (contributorsGID[GIndex::Source::TPC].isIndexSet()) {
@@ -957,7 +961,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
957961
if (!mcLabel.isValid()) {
958962
continue;
959963
}
960-
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID());
964+
keepMCParticle(mToStore, mcLabel.getSourceID(), mcLabel.getEventID(), mcLabel.getTrackID(), 1, mUseSigFiltMC);
961965
}
962966
}
963967
}
@@ -971,7 +975,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
971975
if (!mcTruth.isValid()) {
972976
continue;
973977
}
974-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
978+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
975979
}
976980
}
977981
if (mInputSources[GIndex::PHS]) {
@@ -980,7 +984,7 @@ void AODProducerWorkflowDPL::fillMCParticlesTable(o2::steer::MCKinematicsReader&
980984
if (!mcTruth.isValid()) {
981985
continue;
982986
}
983-
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID());
987+
keepMCParticle(mToStore, mcTruth.getSourceID(), mcTruth.getEventID(), mcTruth.getTrackID(), 1, mUseSigFiltMC);
984988
}
985989
}
986990
using namespace aodmchelpers;
@@ -1688,6 +1692,8 @@ void AODProducerWorkflowDPL::init(InitContext& ic)
16881692
LOG(info) << "The Run number will be obtained from DPL headers";
16891693
}
16901694

1695+
mUseSigFiltMC = ic.options().get<bool>("mc-signal-filt");
1696+
16911697
// set no truncation if selected by user
16921698
if (mTruncate != 1) {
16931699
LOG(info) << "Truncation is not used!";
@@ -1941,6 +1947,24 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
19411947
int totalNParts = 0;
19421948
for (int iCol = 0; iCol < nMCCollisions; iCol++) {
19431949
totalNParts += mcParts[iCol].size();
1950+
1951+
// if signal filtering enabled, let's check if there are more than one source; otherwise fatalise
1952+
if (mUseSigFiltMC) {
1953+
std::vector<int> sourceIDs{};
1954+
auto& colParts = mcParts[iCol];
1955+
for (auto colPart : colParts) {
1956+
int sourceID = colPart.sourceID;
1957+
if (std::find(sourceIDs.begin(), sourceIDs.end(), sourceID) == sourceIDs.end()) {
1958+
sourceIDs.push_back(sourceID);
1959+
}
1960+
if (sourceIDs.size() > 1) { // we found more than one, exit
1961+
break;
1962+
}
1963+
}
1964+
if (sourceIDs.size() <= 1) {
1965+
LOGP(fatal, "Signal filtering cannot be enabled without embedding. Please fix the configuration either enabling the embedding, or turning off the signal filtering.");
1966+
}
1967+
}
19441968
}
19451969
mcCollisionsCursor.reserve(totalNParts);
19461970

@@ -1978,7 +2002,9 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
19782002
0,
19792003
sourceID);
19802004
}
1981-
mcColToEvSrc.emplace_back(std::vector<int>{iCol, sourceID, eventID}); // point background and injected signal events to one collision
2005+
if (sourceID != 0 || !mUseSigFiltMC) {
2006+
mcColToEvSrc.emplace_back(std::vector<int>{iCol, sourceID, eventID}); // point background and injected signal events to one collision
2007+
}
19822008
}
19832009
}
19842010
}
@@ -3055,7 +3081,7 @@ DataProcessorSpec getAODProducerWorkflowSpec(GID::mask_t src, bool enableSV, boo
30553081
ConfigParamSpec{"trackqc-fraction", VariantType::Float, float(0.1), {"Fraction of tracks to QC"}},
30563082
ConfigParamSpec{"trackqc-NTrCut", VariantType::Int64, 4L, {"Minimal length of the track - in amount of tracklets"}},
30573083
ConfigParamSpec{"seed", VariantType::Int, 0, {"Set seed for random generator used for sampling (0 (default) means using a random_device)"}},
3058-
}};
3084+
ConfigParamSpec{"mc-signal-filt", VariantType::Bool, false, {"Enable usage of signal filtering (only for MC with embedding)"}}}};
30593085
}
30603086

30613087
} // namespace o2::aodproducer

0 commit comments

Comments
 (0)