@@ -216,41 +216,50 @@ bool MCSignal::CheckProng(int i, bool checkSources, const T& track)
216216 currentMCParticle = track;
217217 for (int j = 0 ; j < fProngs [i].fNGenerations ; j++) {
218218 // check whether sources are required for this generation
219- if (!fProngs [i].fSourceBits [j]) {
220- continue ;
219+ bool hasSources = false ;
220+ if (fProngs [i].fSourceBits [j]) {
221+ hasSources = true ;
221222 }
222223 // check each source
223224 uint64_t sourcesDecision = 0 ;
224- // Check kPhysicalPrimary
225- if (fProngs [i].fSourceBits [j] & (static_cast <uint64_t >(1 ) << MCProng::kPhysicalPrimary )) {
226- if ((fProngs [i].fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kPhysicalPrimary )) != currentMCParticle.isPhysicalPrimary ()) {
227- sourcesDecision |= (static_cast <uint64_t >(1 ) << MCProng::kPhysicalPrimary );
225+ if (hasSources) {
226+ // Check kPhysicalPrimary
227+ if (fProngs [i].fSourceBits [j] & (static_cast <uint64_t >(1 ) << MCProng::kPhysicalPrimary )) {
228+ if ((fProngs [i].fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kPhysicalPrimary )) != currentMCParticle.isPhysicalPrimary ()) {
229+ sourcesDecision |= (static_cast <uint64_t >(1 ) << MCProng::kPhysicalPrimary );
230+ }
228231 }
229- }
230- // Check kProducedInTransport
231- if (fProngs [i].fSourceBits [j] & (static_cast <uint64_t >(1 ) << MCProng::kProducedInTransport )) {
232- if (( fProngs [i]. fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kProducedInTransport )) != (!currentMCParticle. producedByGenerator ())) {
233- sourcesDecision |= ( static_cast < uint64_t >( 1 ) << MCProng:: kProducedInTransport );
232+ // Check kProducedInTransport
233+ if ( fProngs [i]. fSourceBits [j] & ( static_cast < uint64_t >( 1 ) << MCProng:: kProducedInTransport )) {
234+ if (( fProngs [i].fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kProducedInTransport )) != (!currentMCParticle. producedByGenerator () )) {
235+ sourcesDecision |= (static_cast <uint64_t >(1 ) << MCProng::kProducedInTransport );
236+ }
234237 }
235- }
236- // Check kProducedByGenerator
237- if (fProngs [i].fSourceBits [j] & (static_cast <uint64_t >(1 ) << MCProng::kProducedByGenerator )) {
238- if (( fProngs [i]. fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kProducedByGenerator )) != currentMCParticle. producedByGenerator ()) {
239- sourcesDecision |= ( static_cast < uint64_t >( 1 ) << MCProng:: kProducedByGenerator );
238+ // Check kProducedByGenerator
239+ if ( fProngs [i]. fSourceBits [j] & ( static_cast < uint64_t >( 1 ) << MCProng:: kProducedByGenerator )) {
240+ if (( fProngs [i].fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kProducedByGenerator )) != currentMCParticle. producedByGenerator ( )) {
241+ sourcesDecision |= (static_cast <uint64_t >(1 ) << MCProng::kProducedByGenerator );
242+ }
240243 }
241- }
242- // Check kFromBackgroundEvent
243- if (fProngs [i].fSourceBits [j] & (static_cast <uint64_t >(1 ) << MCProng::kFromBackgroundEvent )) {
244- if (( fProngs [i]. fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kFromBackgroundEvent )) != currentMCParticle. fromBackgroundEvent ()) {
245- sourcesDecision |= ( static_cast < uint64_t >( 1 ) << MCProng:: kFromBackgroundEvent );
244+ // Check kFromBackgroundEvent
245+ if ( fProngs [i]. fSourceBits [j] & ( static_cast < uint64_t >( 1 ) << MCProng:: kFromBackgroundEvent )) {
246+ if (( fProngs [i].fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kFromBackgroundEvent )) != currentMCParticle. fromBackgroundEvent ( )) {
247+ sourcesDecision |= (static_cast <uint64_t >(1 ) << MCProng::kFromBackgroundEvent );
248+ }
246249 }
247- }
250+ // Check HEPMC code 11 (final state)
251+ if (fProngs [i].fSourceBits [j] & (static_cast <uint64_t >(1 ) << MCProng::kHEPMCFinalState )) {
252+ if ((fProngs [i].fExcludeSource [j] & (static_cast <uint64_t >(1 ) << MCProng::kHEPMCFinalState )) != (currentMCParticle.getHepMCStatusCode () == 11 )) {
253+ sourcesDecision |= (static_cast <uint64_t >(1 ) << MCProng::kHEPMCFinalState );
254+ }
255+ }
256+ } // end if(hasSources)
248257 // no source bit is fulfilled
249- if (!sourcesDecision) {
258+ if (hasSources && !sourcesDecision) {
250259 return false ;
251260 }
252261 // if fUseANDonSourceBitMap is on, request all bits
253- if (fProngs [i].fUseANDonSourceBitMap [j] && (sourcesDecision != fProngs [i].fSourceBits [j])) {
262+ if (hasSources && ( fProngs [i].fUseANDonSourceBitMap [j] && (sourcesDecision != fProngs [i].fSourceBits [j]) )) {
254263 return false ;
255264 }
256265
@@ -280,8 +289,8 @@ bool MCSignal::CheckProng(int i, bool checkSources, const T& track)
280289 }
281290 }
282291 }
283- }
284- }
292+ } // end loop over generations
293+ } // end if(checkSources)
285294
286295 if (fProngs [i].fPDGInHistory .size () == 0 ) {
287296 return true ;
@@ -299,40 +308,41 @@ bool MCSignal::CheckProng(int i, bool checkSources, const T& track)
299308 // Note: Currently no need to check generation InTime, so disable if case and always check BackInTime (direction of mothers)
300309 // The option to check for daughter in decay chain is still implemented but commented out.
301310
302- // if (!fProngs[i].fCheckGenerationsInTime) { // check generation back in time
303- while (currentMCParticle.has_mothers ()) {
304- auto mother = currentMCParticle.template mothers_first_as <P>();
305- if (!fProngs [i].fExcludePDGInHistory [k] && fProngs [i].ComparePDG (mother.pdgCode (), fProngs [i].fPDGInHistory [k], true , fProngs [i].fExcludePDGInHistory [k])) {
306- pdgInHistory.emplace_back (mother.pdgCode ());
307- break ;
311+ if (!fProngs [i].fCheckGenerationsInTime ) { // check generation back in time
312+ while (currentMCParticle.has_mothers ()) {
313+ auto mother = currentMCParticle.template mothers_first_as <P>();
314+ if (!fProngs [i].fExcludePDGInHistory [k] && fProngs [i].ComparePDG (mother.pdgCode (), fProngs [i].fPDGInHistory [k], true , fProngs [i].fExcludePDGInHistory [k])) {
315+ pdgInHistory.emplace_back (mother.pdgCode ());
316+ break ;
317+ }
318+ if (fProngs [i].fExcludePDGInHistory [k] && !fProngs [i].ComparePDG (mother.pdgCode (), fProngs [i].fPDGInHistory [k], true , fProngs [i].fExcludePDGInHistory [k])) {
319+ return false ;
320+ }
321+ ith++;
322+ currentMCParticle = mother;
323+ if (ith > 10 ) { // need error message. Given pdg code was not found within 10 generations of the particles decay chain.
324+ break ;
325+ }
308326 }
309- if (fProngs [i].fExcludePDGInHistory [k] && !fProngs [i].ComparePDG (mother.pdgCode (), fProngs [i].fPDGInHistory [k], true , fProngs [i].fExcludePDGInHistory [k])) {
327+ } /* else { // check generation in time
328+ if (!currentMCParticle.has_daughters()) {
310329 return false;
311330 }
312- ith++;
313- currentMCParticle = mother;
314- if (ith > 10 ) { // need error message. Given pdg code was not found within 10 generations of the particles decay chain.
315- break ;
331+ const auto& daughtersSlice = currentMCParticle.template daughters_as<P>();
332+ for (auto& d : daughtersSlice) {
333+ if (!fProngs[i].fExcludePDGInHistory[k] && fProngs[i].ComparePDG(d.pdgCode(), fProngs[i].fPDGInHistory[k], true, fProngs[i].fExcludePDGInHistory[k])) {
334+ pdgInHistory.emplace_back(d.pdgCode());
335+ break;
336+ }
337+ if (fProngs[i].fExcludePDGInHistory[k] && !fProngs[i].ComparePDG(d.pdgCode(), fProngs[i].fPDGInHistory[k], true, fProngs[i].fExcludePDGInHistory[k])) {
338+ return false;
339+ }
340+ ith++;
341+ if (ith > 10) { // need error message. Given pdg code was not found within 10 generations of the particles decay chain.
342+ break;
343+ }
316344 }
317- }
318- // } else { // check generation in time
319- // if (!currentMCParticle.has_daughters())
320- // return false;
321- // const auto& daughtersSlice = currentMCParticle.template daughters_as<P>();
322- // for (auto& d : daughtersSlice) {
323- // if (!fProngs[i].fExcludePDGInHistory[k] && fProngs[i].ComparePDG(d.pdgCode(), fProngs[i].fPDGInHistory[k], true, fProngs[i].fExcludePDGInHistory[k])) {
324- // pdgInHistory.emplace_back(d.pdgCode());
325- // break;
326- // }
327- // if (fProngs[i].fExcludePDGInHistory[k] && !fProngs[i].ComparePDG(d.pdgCode(), fProngs[i].fPDGInHistory[k], true, fProngs[i].fExcludePDGInHistory[k])) {
328- // return false;
329- // }
330- // ith++;
331- // if (ith > 10) { // need error message. Given pdg code was not found within 10 generations of the particles decay chain.
332- // break;
333- // }
334- // }
335- // }
345+ }*/
336346 }
337347 if (pdgInHistory.size () != nIncludedPDG) { // vector has as many entries as mothers (daughters) defined for prong
338348 return false ;
0 commit comments