diff --git a/Filters/src/CompressDigiMCsCheck_module.cc b/Filters/src/CompressDigiMCsCheck_module.cc index bdd9cb76e4..9c4bd51f6e 100644 --- a/Filters/src/CompressDigiMCsCheck_module.cc +++ b/Filters/src/CompressDigiMCsCheck_module.cc @@ -133,8 +133,17 @@ namespace mu2e { throw cet::exception("CompressDigiMCsCheck") << "Old and new StepPointMC times with offsets applied do not match (StrawDigiMC)" << std::endl; } - // Loop through all the StepPointMCs in the waveform and check that the trigger step points are the same Ptr + // Check for tracker duplicate steps, there are two different cases. What should be happening is something like the following: + // We have five StepPointMCs: A, B, C, D, E + // StrawDigiMC has seven StepPtrs: HVStepPtr-->A CalStepPtr-->A WaveformStepPtrs-->A, B, C, D, E if (_checkTrackerDuplicateSteps) { + // Case 1. In this case we have accidentally treated the HVStepPtr and CalStepPtr as separate and duplicated step A (A' and A'') + // so we end up with seven StepPointsMCs: A, B, C, D, E, A', A'' + // and the StepPtrs all point to different: HVStepPtr-->A' CalStepPtr-->A'' WaveformStepPtrs-->A, B, C, D, E + // This will not trigger the exception in Case 2 + // If we only access steps through digis then you will get the correct information + // You cannot loop over the StepPointMCCollection however + // Here we check that the HV and Cal StepPtrs also exist in the WaveformStepPtrs const auto& i_newStepPointMCCal = i_newStrawDigiMC.stepPointMC(StrawEnd::cal); bool identical_cal_ptr = false; bool identical_hv_ptr = false; @@ -149,6 +158,27 @@ namespace mu2e { if (! (identical_hv_ptr && identical_cal_ptr) ) { throw cet::exception("CompressDigiMCsCheck") << "Trigger StepPointMCs in StrawDigiMCs are not identical to any StepPointMC in the waveform. This could indicate a duplication of StepPointMCs" << std::endl; } + + // Case 2: In this case, we have looped over an StepPointMCCollection with duplicated steps + // (and have not duplicated things further) + // StepPointMCs: A, B, C, D, E, A', A'' + // and the waveform will now include the duplicated steps: + // StrawDigiMC: HVStepPtr-->A', CalStepPtr-->A'', WaveformStepPtrs-->A, B, C, D, E, A', A'' + // This will not trigger the exception in Case 1 + // Here we check that there are no identical waveform steps + for (const auto& i_stepPointPtr : i_newStrawDigiMC.stepPointMCs()) { + for (const auto& j_stepPointPtr : i_newStrawDigiMC.stepPointMCs()) { + if (i_stepPointPtr == j_stepPointPtr) { + continue; // these will obviously match + } + + if ( (i_stepPointPtr->volumeId() == j_stepPointPtr->volumeId()) && + (i_stepPointPtr->totalEDep() == j_stepPointPtr->totalEDep()) + ) { + throw cet::exception("CompressDigiMCsCheck") << "Two StepPointMCs in StrawDigiMC waveform are identical" << std::endl; + } + } + } } } }