Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TrkStrawHitMC provenance and guard against empty StrawDigiMCs #1291

Merged
merged 13 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions CommonMC/src/SelectRecoMC_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,17 @@ namespace mu2e {
// find the referenced sim particle
int spref(-1);
auto const& sdmc = sdmcc.at(hit.index()); // bounds-check for security;
for(size_t isp=0;isp < spcc.size(); isp++){
auto const& spc = spcc[isp];
if(sdmc.earlyStrawGasStep()->simParticle() == spc._spp){
spref = isp;
break;
// if mc info is not meaningful, do not try to inspect any SimParticles
if (sdmc.provenance() != StrawDigiProvenance::External){
for(size_t isp=0;isp < spcc.size(); isp++){
auto const& spc = spcc[isp];
if(sdmc.earlyStrawGasStep()->simParticle() == spc._spp){
spref = isp;
break;
}
}
if(spref < 0)throw cet::exception("Reco")<<"mu2e::SelectRecoMC: missing index"<< std::endl;
}
if(spref < 0)throw cet::exception("Reco")<<"mu2e::SelectRecoMC: missing index"<< std::endl;
TrkStrawHitMC tshmc;
fillTSHMC(tshmc,hit.index(),spref,sdmc,tracker,srep);
mcseed._tshmcs.push_back(tshmc);
Expand All @@ -250,12 +253,21 @@ namespace mu2e {
void SelectRecoMC::fillUnusedTSHMC( SPCC const& spcc, StrawDigiMCCollection const& sdmcc,
Tracker const& tracker, std::shared_ptr<const StrawResponse>const& srep,
KalSeedMC& mcseed) {
// either keep hits only from the primary or from all contributing
size_t ispmax = _saveallunused? spcc.size() : 1;
// either keep hits only from the primary or all contributing particles,
// assuming any exist. if they do not, then there is no primary.
size_t limit = 0;
if (0 < spcc.size()){
kutschke marked this conversation as resolved.
Show resolved Hide resolved
limit = 1;
}
size_t ispmax = _saveallunused? spcc.size() : limit;
for(size_t isp=0; isp < ispmax; ++isp){
auto const& spc = spcc[isp];
for (size_t isdmc=0; isdmc < sdmcc.size(); isdmc++){
auto const& sdmc = sdmcc[isdmc];
// if this contains no MC information, then we cannot inspect it further
if (sdmc.provenance() == StrawDigiProvenance::External){
continue;
kutschke marked this conversation as resolved.
Show resolved Hide resolved
}
auto const& sgs = *(sdmc.earlyStrawGasStep());
if(sgs.simParticle() == spc._spp){
// search to see if the associated digi is already on the track
Expand All @@ -278,7 +290,20 @@ namespace mu2e {

void SelectRecoMC::fillTSHMC(TrkStrawHitMC& tshmc, size_t isdmc, size_t isp,StrawDigiMC const& sdmc,
Tracker const& tracker, std::shared_ptr<const StrawResponse>const& srep ) {
// always record the index, to avoid downstream corruptions
tshmc._sdmcindex = isdmc;
// propagate interpretability of StrawDigiMC to TrkStrawHitMC
if (sdmc.provenance() == StrawDigiProvenance::External){
kutschke marked this conversation as resolved.
Show resolved Hide resolved
tshmc._provenance = TrkStrawHitProvenance::External;
// if there is no MC information at all, leave TrkStrawHitMC empty
return;
}
else if (sdmc.provenance() == StrawDigiProvenance::Mixed){
tshmc._provenance = TrkStrawHitProvenance::Mixed;
}
else if (sdmc.provenance() == StrawDigiProvenance::Simulation){
tshmc._provenance = TrkStrawHitProvenance::Simulation;
}
tshmc._spindex = isp;
tshmc._energySum = sdmc.triggerEnergySum(sdmc.earlyEnd());
const auto& sgs = *(sdmc.earlyStrawGasStep());
Expand Down
10 changes: 10 additions & 0 deletions MCDataProducts/inc/KalSeedMC.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Offline/DataProducts/inc/GenVector.hh"
#include "Offline/DataProducts/inc/StrawEnd.hh"
#include "Offline/DataProducts/inc/VirtualDetectorId.hh"
#include <Offline/GeneralUtilities/inc/EnumToStringSparse.hh>
#include "Offline/RecoDataProducts/inc/KalSeed.hh"
#include "Offline/MCDataProducts/inc/SimParticle.hh"
#include "Offline/MCDataProducts/inc/ProcessCode.hh"
Expand Down Expand Up @@ -69,6 +70,14 @@ namespace mu2e {
};
//
// MC information for TrackStrawHits on this fit
// enum equipped with std::string descriptions
class TrkStrawHitProvenanceDetail{
public:
enum enum_type {unknown=0, Simulation, Mixed, External};
static std::string const& typeName();
static std::map<enum_type, std::string> const& names();
};
using TrkStrawHitProvenance = EnumToStringSparse<TrkStrawHitProvenanceDetail>;
struct TrkStrawHitMC {
StrawHitIndex strawDigiMCIndex() const { return _sdmcindex; }
StrawHitIndex simPartStubIndex() const { return _spindex; }
Expand All @@ -95,6 +104,7 @@ namespace mu2e {
float _wireTau; // threshold cluster distance to the wire along the perpedicular particle path
float _strawDOCA; // signed doca to straw
float _strawPhi; // cylindrical phi from -pi to pi with 0 in Z direction
TrkStrawHitProvenance _provenance; // TODO default read value == Sim?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support a default value, perhaps 'unknown' to flag errors downstream

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EnumToStringSparse class template requires that the detail class contain an enumerator named "unknown" and it default constructs it's objects to have a value of "unknown".

You will also add the implementation for the two functions declared in the detail class.

I suggest you moved the TrkStrawHitProvenance to be it's own .hh and .cc . Then use them in KalSeedMC .
If you prefer to keep them in KalSeedMC, then create KalSeedMC.cc to hold the missing implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, making the initialization manifest does make the code more readable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... or add a comment that it defaults to unknown.

Copy link
Contributor Author

@edcallaghan edcallaghan Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A default constructor is now explicitly defined for the TrkStrawHitMC struct, which initializes the provenance to unknown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default provenance has been updated to Simulation, so that existing simulation will be deserialized correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kutschke The common DigiProvenance now inhabits a standalone src/inc pair.

Re default values: maybe I misunderstand your commentary, but the discussion here is about how to correctly initialize the provenance data member of TrkStrawHitMC when deserializing preexisting simulation in which the provenance field did not exist. Since the default value for the actual provenance enum will be unknown, as you asy, this needs to be explicitly overridden in the TrkStrawHitMC constructor to mark the preexisting simulation as having been produced as such.

};

struct KalSeedMC {
Expand Down
6 changes: 6 additions & 0 deletions TrkDiag/src/TrkMCTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ namespace mu2e {
// loop over the hits and find the associated steppoints
bool isactive = tshs.flag().hasAllProperties(active);
StrawDigiMC const& mcdigi = mcdigis.at(tshs.index());
// if mc info is not meaningful, then skip this digi.
// this looks sketchy, but nowhere is an implicit association
// between the sct and mcdigis collection actually assumed
if (mcdigi.provenance() == StrawDigiProvenance::External){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restructure logic to avoid 'continue'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

continue;
}
art::Ptr<SimParticle> spp = mcdigi.earlyStrawGasStep()->simParticle();
// see if this particle has already been found; if so, increment, if not, add it
bool found(false);
Expand Down