Skip to content

Commit 529ac7e

Browse files
committed
Implement option to check MCSignal in time and back in time
1 parent 04d8a9c commit 529ac7e

4 files changed

Lines changed: 98 additions & 36 deletions

File tree

PWGDQ/Core/MCProng.cxx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ClassImp(MCProng);
1818

1919
//________________________________________________________________________________________________________________
2020
MCProng::MCProng() : fNGenerations(0),
21+
fCheckGenerationsInTime(0),
2122
fPDGcodes({}),
2223
fCheckBothCharges({}),
2324
fExcludePDG({}),
@@ -28,7 +29,8 @@ MCProng::MCProng() : fNGenerations(0),
2829
}
2930

3031
//________________________________________________________________________________________________________________
31-
MCProng::MCProng(int n) : fNGenerations(n)
32+
MCProng::MCProng(int n) : fNGenerations(n),
33+
fCheckGenerationsInTime(0)
3234
{
3335
fPDGcodes.reserve(n);
3436
fCheckBothCharges.reserve(n);
@@ -49,13 +51,14 @@ MCProng::MCProng(int n) : fNGenerations(n)
4951
//________________________________________________________________________________________________________________
5052
MCProng::MCProng(int n, const std::vector<int> pdgs, const std::vector<bool> checkBothCharges, const std::vector<bool> excludePDG,
5153
const std::vector<uint64_t> sourceBits, const std::vector<uint64_t> excludeSource,
52-
const std::vector<bool> useANDonSourceBitMap) : fNGenerations(n),
53-
fPDGcodes(pdgs),
54-
fCheckBothCharges(checkBothCharges),
55-
fExcludePDG(excludePDG),
56-
fSourceBits(sourceBits),
57-
fExcludeSource(excludeSource),
58-
fUseANDonSourceBitMap(useANDonSourceBitMap){};
54+
const std::vector<bool> useANDonSourceBitMap, bool checkGenerationsInTime) : fNGenerations(n),
55+
fPDGcodes(pdgs),
56+
fCheckBothCharges(checkBothCharges),
57+
fExcludePDG(excludePDG),
58+
fSourceBits(sourceBits),
59+
fExcludeSource(excludeSource),
60+
fUseANDonSourceBitMap(useANDonSourceBitMap),
61+
fCheckGenerationsInTime(checkGenerationsInTime){};
5962

6063
//________________________________________________________________________________________________________________
6164
void MCProng::SetPDGcode(int generation, int code, bool checkBothCharges /*= false*/, bool exclude /*= false*/)
@@ -100,13 +103,22 @@ void MCProng::SetUseANDonSourceBits(int generation, bool option /*=true*/)
100103
fUseANDonSourceBitMap[generation] = option;
101104
}
102105

106+
//________________________________________________________________________________________________________________
107+
void MCProng::SetDirectionOfGeneration(int generation, bool intime /*=false*/)
108+
{
109+
if (generation < 0 || generation >= fNGenerations) {
110+
return;
111+
}
112+
fCheckGenerationsInTime = intime;
113+
}
114+
103115
//________________________________________________________________________________________________________________
104116
void MCProng::Print() const
105117
{
106118
for (int i = 0; i < fNGenerations; i++) {
107119
std::cout << "Generation #" << i << " PDGcode(" << fPDGcodes[i] << ") CheckBothCharges(" << fCheckBothCharges[i]
108120
<< ") ExcludePDG(" << fExcludePDG[i] << ") SourceBits(" << fSourceBits[i] << ") ExcludeSource(" << fExcludeSource[i]
109-
<< ") UseANDonSource(" << fUseANDonSourceBitMap[i] << ")" << std::endl;
121+
<< ") UseANDonSource(" << fUseANDonSourceBitMap[i] << ") CheckGenerationsInTime(" << fCheckGenerationsInTime << ")" << std::endl;
110122
}
111123
}
112124

PWGDQ/Core/MCProng.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,21 @@ class MCProng
7979
MCProng();
8080
MCProng(int n);
8181
MCProng(int n, std::vector<int> pdgs, std::vector<bool> checkBothCharges, std::vector<bool> excludePDG,
82-
std::vector<uint64_t> sourceBits, std::vector<uint64_t> excludeSource, std::vector<bool> useANDonSourceBitMap);
82+
std::vector<uint64_t> sourceBits, std::vector<uint64_t> excludeSource, std::vector<bool> useANDonSourceBitMap, bool fCheckGenerationsInTime = false);
8383
MCProng(const MCProng& c) = default;
8484
virtual ~MCProng() = default;
8585

8686
void SetPDGcode(int generation, int code, bool checkBothCharges = false, bool exclude = false);
8787
void SetSources(int generation, uint64_t bits, uint64_t exclude = 0, bool useANDonSourceBits = true);
8888
void SetSourceBit(int generation, int sourceBit, bool exclude = false);
8989
void SetUseANDonSourceBits(int generation, bool option = true);
90+
void SetDirectionOfGeneration(int generation, bool intime = false); // set variable to check generations in time or back in time (default)
9091
void Print() const;
9192
bool TestPDG(int i, int pdgCode) const;
9293
bool ComparePDG(int pdg, int prongPDG, bool checkBothCharges = false, bool exclude = false) const;
9394

9495
int fNGenerations;
96+
bool fCheckGenerationsInTime;
9597
std::vector<int> fPDGcodes;
9698
std::vector<bool> fCheckBothCharges;
9799
std::vector<bool> fExcludePDG;

PWGDQ/Core/MCSignal.h

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ bool MCSignal::CheckProng(int i, bool checkSources, const U& mcStack, const T& t
133133
auto currentMCParticle = track;
134134
// loop over the generations specified for this prong
135135
for (int j = 0; j < fProngs[i].fNGenerations; j++) {
136+
// if generations are checked in time (grandmother->mother->daughter) reverse order of MCProng variables to start at the end
137+
if (fProngs[i].fCheckGenerationsInTime) {
138+
std::reverse(fProngs[i].fPDGcodes.begin(), fProngs[i].fPDGcodes.end());
139+
std::reverse(fProngs[i].fCheckBothCharges.begin(), fProngs[i].fCheckBothCharges.end());
140+
std::reverse(fProngs[i].fExcludePDG.begin(), fProngs[i].fExcludePDG.end());
141+
std::reverse(fProngs[i].fSourceBits.begin(), fProngs[i].fSourceBits.end());
142+
std::reverse(fProngs[i].fExcludeSource.begin(), fProngs[i].fExcludeSource.end());
143+
std::reverse(fProngs[i].fUseANDonSourceBitMap.begin(), fProngs[i].fUseANDonSourceBitMap.end());
144+
}
136145
// check the PDG code
137146
if (!fProngs[i].TestPDG(j, currentMCParticle.pdgCode())) {
138147
return false;
@@ -147,23 +156,46 @@ bool MCSignal::CheckProng(int i, bool checkSources, const U& mcStack, const T& t
147156
}
148157
}
149158
}
150-
// make sure that a mother exists in the stack before moving one generation further in history
151-
if (!currentMCParticle.has_mothers() && j < fProngs[i].fNGenerations - 1) {
152-
return false;
153-
}
154-
if (currentMCParticle.has_mothers() && j < fProngs[i].fNGenerations - 1) {
155-
/*for (auto& m : mcParticle.mothers_as<aod::McParticles_001>()) {
156-
LOGF(debug, "M2 %d %d", mcParticle.globalIndex(), m.globalIndex());
157-
}*/
158-
currentMCParticle = currentMCParticle.template mothers_first_as<U>();
159-
// currentMCParticle = mcStack.iteratorAt(currentMCParticle.mothersIds()[0]);
160-
// currentMCParticle = currentMCParticle.template mother0_as<U>();
159+
160+
// if checking back in time: look for mother
161+
// else (checking in time): look for daughter
162+
if (!fProngs[i].fCheckGenerationsInTime) {
163+
// make sure that a mother exists in the stack before moving one generation further in history
164+
if (!currentMCParticle.has_mothers() && j < fProngs[i].fNGenerations - 1) {
165+
return false;
166+
}
167+
if (currentMCParticle.has_mothers() && j < fProngs[i].fNGenerations - 1) {
168+
/*for (auto& m : mcParticle.mothers_as<aod::McParticles_001>()) {
169+
LOGF(debug, "M2 %d %d", mcParticle.globalIndex(), m.globalIndex());
170+
}*/
171+
currentMCParticle = currentMCParticle.template mothers_first_as<U>();
172+
// currentMCParticle = mcStack.iteratorAt(currentMCParticle.mothersIds()[0]);
173+
// currentMCParticle = currentMCParticle.template mother0_as<U>();
174+
}
175+
} else {
176+
// make sure that a daughter exists in the stack before moving one generation younger
177+
if (!currentMCParticle.has_daughters() && j < fProngs[i].fNGenerations - 1) {
178+
return false;
179+
}
180+
if (currentMCParticle.has_daughters() && j < fProngs[i].fNGenerations - 1) {
181+
currentMCParticle = currentMCParticle.template mothers_first_as<U>();
182+
// currentMCParticle = mcStack.iteratorAt(currentMCParticle.mothersIds()[0]);
183+
}
161184
}
162185
}
163186

164187
if (checkSources) {
165188
currentMCParticle = track;
166189
for (int j = 0; j < fProngs[i].fNGenerations; j++) {
190+
// if generations are checked in time (grandmother->mother->daughter) reverse order of MCProng variables to start at the end
191+
if (fProngs[i].fCheckGenerationsInTime) {
192+
std::reverse(fProngs[i].fPDGcodes.begin(), fProngs[i].fPDGcodes.end());
193+
std::reverse(fProngs[i].fCheckBothCharges.begin(), fProngs[i].fCheckBothCharges.end());
194+
std::reverse(fProngs[i].fExcludePDG.begin(), fProngs[i].fExcludePDG.end());
195+
std::reverse(fProngs[i].fSourceBits.begin(), fProngs[i].fSourceBits.end());
196+
std::reverse(fProngs[i].fExcludeSource.begin(), fProngs[i].fExcludeSource.end());
197+
std::reverse(fProngs[i].fUseANDonSourceBitMap.begin(), fProngs[i].fUseANDonSourceBitMap.end());
198+
}
167199
if (!fProngs[i].fSourceBits[j]) {
168200
// no sources required for this generation
169201
continue;
@@ -202,23 +234,38 @@ bool MCSignal::CheckProng(int i, bool checkSources, const U& mcStack, const T& t
202234
if (fProngs[i].fUseANDonSourceBitMap[j] && (sourcesDecision != fProngs[i].fSourceBits[j])) {
203235
return false;
204236
}
205-
// move one generation back in history
206-
// make sure that a mother exists in the stack before moving one generation further in history
207-
if (!currentMCParticle.has_mothers() && j < fProngs[i].fNGenerations - 1) {
208-
return false;
209-
}
210-
if (currentMCParticle.has_mothers() && j < fProngs[i].fNGenerations - 1) {
211-
/*for (auto& m : mcParticle.mothers_as<aod::McParticles_001>()) {
212-
LOGF(debug, "M2 %d %d", mcParticle.globalIndex(), m.globalIndex());
237+
238+
// if checking back in time: look for mother
239+
// else (checking in time): look for daughter
240+
if (!fProngs[i].fCheckGenerationsInTime) {
241+
// move one generation back in history
242+
// make sure that a mother exists in the stack before moving one generation further in history
243+
if (!currentMCParticle.has_mothers() && j < fProngs[i].fNGenerations - 1) {
244+
return false;
245+
}
246+
if (currentMCParticle.has_mothers() && j < fProngs[i].fNGenerations - 1) {
247+
/*for (auto& m : mcParticle.mothers_as<aod::McParticles_001>()) {
248+
LOGF(debug, "M2 %d %d", mcParticle.globalIndex(), m.globalIndex());
249+
}*/
250+
currentMCParticle = currentMCParticle.template mothers_first_as<U>();
251+
// currentMCParticle = mcStack.iteratorAt(currentMCParticle.mothersIds()[0]);
252+
// currentMCParticle = currentMCParticle.template mother0_as<U>();
253+
}
254+
/*if (j < fProngs[i].fNGenerations - 1) {
255+
currentMCParticle = mcStack.iteratorAt(currentMCParticle.mother0Id());
256+
//currentMCParticle = currentMCParticle.template mother0_as<U>();
213257
}*/
214-
currentMCParticle = currentMCParticle.template mothers_first_as<U>();
215-
// currentMCParticle = mcStack.iteratorAt(currentMCParticle.mothersIds()[0]);
216-
// currentMCParticle = currentMCParticle.template mother0_as<U>();
258+
} else {
259+
// move one generation further in history
260+
// make sure that a daughter exists in the stack before moving one generation younger
261+
if (!currentMCParticle.has_daughters() && j < fProngs[i].fNGenerations - 1) {
262+
return false;
263+
}
264+
if (currentMCParticle.has_daughters() && j < fProngs[i].fNGenerations - 1) {
265+
currentMCParticle = currentMCParticle.template mothers_first_as<U>();
266+
// currentMCParticle = mcStack.iteratorAt(currentMCParticle.mothersIds()[0]);
267+
}
217268
}
218-
/*if (j < fProngs[i].fNGenerations - 1) {
219-
currentMCParticle = mcStack.iteratorAt(currentMCParticle.mother0Id());
220-
//currentMCParticle = currentMCParticle.template mother0_as<U>();
221-
}*/
222269
}
223270
}
224271

PWGDQ/Core/MCSignalLibrary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ MCSignal* o2::aod::dqmcsignals::GetMCSignal(const char* name)
284284
if (!nameStr.compare("eFromLMeeLFQ")) {
285285
MCProng prong(2, {11, 900}, {true, true}, {false, false}, {0, 0}, {0, 0}, {false, false});
286286
//prong.SetSourceBit(0, MCProng::kPhysicalPrimary, false); // set source to be ALICE primary particles
287+
prong.SetDirectionOfGeneration(0, true); // set direction to check generation in time (true) or back in time (false)
287288
signal = new MCSignal(name, "Electrons from LF meson + quarkonia decays", {prong}, {-1}); //pi0,eta,eta',rho,omega,phi,jpsi,psi2s mesons
288289
return signal;
289290
}

0 commit comments

Comments
 (0)