diff --git a/inc/MCStepInfo.hh b/inc/MCStepInfo.hh index 10bcb54..97c6c89 100644 --- a/inc/MCStepInfo.hh +++ b/inc/MCStepInfo.hh @@ -20,7 +20,8 @@ namespace mu2e { XYZVectorF pos; // particle position at the start of this step void reset() {*this = MCStepInfo(); } bool valid() { return vid>=0; } - int simid = -1; // SimParticle id + int simid = -1; // SimParticle id (the simulation-stage piece that made this step) + int originid = -1; // id of the first simulation-stage piece of this SimParticle, matching mcsim id; equals simid unless the particle crossed a simulation stage boundary int pdg = -1; // true PDG code int startCode = -1; // creation process code int stopCode = -1; // stop process code diff --git a/inc/SimInfo.hh b/inc/SimInfo.hh index 775a912..00c504a 100644 --- a/inc/SimInfo.hh +++ b/inc/SimInfo.hh @@ -13,20 +13,21 @@ namespace mu2e // general info about the SimParticle which was simulated struct SimInfo { bool valid = false; // true/false as to whether the data is valid - int id = -1; // id number for SimParticle + int id = -1; // id number for SimParticle; for a particle split across simulation stages, the first stage, where the start values come from + int endid = -1; // id number of the SimParticle that stopCode, endpos and endmom come from; equals id unless the particle crossed a simulation stage boundary int nhits = -1; // number of matched hits in the track generated by this particle int nactive = -1; // number of active matched hits in the track generated by this particle int rank = -1; // rank of this particle, by # of associated hits int pdg = -1; // true PDG code int startCode = -1; // creation process code - int stopCode = -1; // stop process code + int stopCode = -1; // stop process code (of the endid SimParticle) int gen = -1; // generator code float time = -1.0; // Origin time of the SimParticle [ns] int index = -1; // index into the SimInfo vector XYZVectorF mom = XYZVectorF(); // origin momentumof the SimParticle [MeV/c] XYZVectorF pos = XYZVectorF(); // origin position of the SimParticle [mm, in detector coords] - XYZVectorF endmom = XYZVectorF(); // end momentumof the SimParticle [MeV/c] - XYZVectorF endpos = XYZVectorF(); // end position of the SimParticle [mm, in detector coords] + XYZVectorF endmom = XYZVectorF(); // end momentum of the endid SimParticle [MeV/c] + XYZVectorF endpos = XYZVectorF(); // end position of the endid SimParticle [mm, in detector coords] MCRelationship prirel = MCRelationship(); // relationship to the event primary particles MCRelationship trkrel = MCRelationship(); // relationship to the particle that created hits in the track void reset() { *this = SimInfo(); } diff --git a/src/InfoMCStructHelper.cc b/src/InfoMCStructHelper.cc index ea53db8..afee11b 100644 --- a/src/InfoMCStructHelper.cc +++ b/src/InfoMCStructHelper.cc @@ -29,6 +29,18 @@ namespace mu2e { + namespace { + // id of the first simulation-stage piece of this particle, as in + // SimParticle::originParticle(), but stopping at a parent piece that was not kept + int originId(SimParticle const& sp) { + SimParticle const* piece = &sp; + while (piece->selfParent() && piece->parent().isAvailable()) { + piece = piece->parent().get(); + } + return piece->id().asInt(); + } + } + InfoMCStructHelper::InfoMCStructHelper(const Config& conf) : _spctag(conf.spctag()), _mingood(conf.mingood()), _maxdt(conf.maxvddt()), @@ -291,17 +303,16 @@ namespace mu2e { siminfo.id = sp.id().asInt(); if(sp.genParticle().isNonnull()) { siminfo.gen = sp.genParticle()->generatorId().id(); } siminfo.startCode = sp.creationCode(); - siminfo.stopCode = sp.stoppingCode(); siminfo.pdg = sp.pdgId(); siminfo.time = sp.startGlobalTime(); siminfo.mom = XYZVectorF(sp.startMomentum()); siminfo.pos = XYZVectorF(det->toDetector(sp.startPosition())); - siminfo.endpos = XYZVectorF(det->toDetector(sp.endPosition())); - siminfo.endmom = XYZVectorF(sp.endMomentum()); + fillSimInfoEnd(sp, siminfo); } void InfoMCStructHelper::fillSimInfoEnd(const SimParticle& sp, SimInfo& siminfo) { GeomHandle det; + siminfo.endid = sp.id().asInt(); siminfo.stopCode = sp.stoppingCode(); siminfo.endpos = XYZVectorF(det->toDetector(sp.endPosition())); siminfo.endmom = XYZVectorF(sp.endMomentum()); @@ -577,6 +588,7 @@ namespace mu2e { mcsi.mom = mcstep.momentum(); mcsi.pos = spos; mcsi.simid = mcstep.simParticle()->id().asInt(); + mcsi.originid = originId(*mcstep.simParticle()); mcsi.pdg = mcstep.simParticle()->pdgId(); mcsi.startCode = mcstep.simParticle()->creationCode(); mcsi.stopCode = mcstep.simParticle()->stoppingCode(); @@ -618,6 +630,7 @@ namespace mu2e { mcstepinfo.pos = XYZVectorF(det->toDetector(mcstep.position())); const auto& simParticle = mcstep.simParticle(); mcstepinfo.simid = simParticle->id().asInt(); + mcstepinfo.originid = originId(*simParticle); mcstepinfo.pdg = simParticle->pdgId(); mcstepinfo.startCode = simParticle->creationCode(); mcstepinfo.stopCode = simParticle->stoppingCode(); diff --git a/validation/create_val_file_rooutil.C b/validation/create_val_file_rooutil.C index 7bf8209..614ee8f 100644 --- a/validation/create_val_file_rooutil.C +++ b/validation/create_val_file_rooutil.C @@ -176,6 +176,7 @@ void create_val_file_rooutil(std::string filename, std::string outfilename) { TH1F* h_trkmcsim_valid = new TH1F("h_trkmcsim_valid", "", 100,0,100); TH1F* h_trkmcsim_id = new TH1F("h_trkmcsim_id", "", 100,0,100); + TH1F* h_trkmcsim_endid = new TH1F("h_trkmcsim_endid", "", 100,0,100); TH1F* h_trkmcsim_nhits = new TH1F("h_trkmcsim_nhits", "", 100,0,100); TH1F* h_trkmcsim_nactive = new TH1F("h_trkmcsim_nactive", "", 100,0,100); TH1F* h_trkmcsim_rank = new TH1F("h_trkmcsim_rank", "", 100,0,100); @@ -636,6 +637,7 @@ void create_val_file_rooutil(std::string filename, std::string outfilename) { TH1F* h_mcsteps_virtualdetector_pos_y = new TH1F("h_mcsteps_virtualdetector_pos_y", "", 100,-1000,1000); TH1F* h_mcsteps_virtualdetector_pos_z = new TH1F("h_mcsteps_virtualdetector_pos_z", "", 320,-1600,1600); TH1F* h_mcsteps_virtualdetector_simid = new TH1F("h_mcsteps_virtualdetector_simid", "", 100,0,100); + TH1F* h_mcsteps_virtualdetector_originid = new TH1F("h_mcsteps_virtualdetector_originid", "", 100,0,100); TH1F* h_mcsteps_virtualdetector_pdg = new TH1F("h_mcsteps_virtualdetector_pdg", "", 100,0,100); TH1F* h_mcsteps_virtualdetector_startCode = new TH1F("h_mcsteps_virtualdetector_startCode", "", 100,0,100); TH1F* h_mcsteps_virtualdetector_stopCode = new TH1F("h_mcsteps_virtualdetector_stopCode", "", 100,0,100); @@ -847,6 +849,7 @@ void create_val_file_rooutil(std::string filename, std::string outfilename) { for (const auto& trkmcsim : trkmcsims) { h_trkmcsim_valid->Fill(trkmcsim.valid); h_trkmcsim_id->Fill(trkmcsim.id); + h_trkmcsim_endid->Fill(trkmcsim.endid); h_trkmcsim_nhits->Fill(trkmcsim.nhits); h_trkmcsim_nactive->Fill(trkmcsim.nactive); h_trkmcsim_rank->Fill(trkmcsim.rank); @@ -1422,6 +1425,7 @@ void create_val_file_rooutil(std::string filename, std::string outfilename) { h_mcsteps_virtualdetector_pos_y->Fill(vdstep.pos.y()); h_mcsteps_virtualdetector_pos_z->Fill(vdstep.pos.z()); h_mcsteps_virtualdetector_simid->Fill(vdstep.simid); + h_mcsteps_virtualdetector_originid->Fill(vdstep.originid); h_mcsteps_virtualdetector_pdg->Fill(vdstep.pdg); h_mcsteps_virtualdetector_startCode->Fill(vdstep.startCode); h_mcsteps_virtualdetector_stopCode->Fill(vdstep.stopCode);