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

Simulation: define PSimHit track Id offset and propagate to MTD hit categories #42506

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions SimDataFormats/TrackingHit/interface/PSimHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class TrackingSlaveSD; // for friend declaration only

class PSimHit {
public:
static constexpr unsigned int k_tidOffset = 200000000;

PSimHit() : theDetUnitId(0) {}

PSimHit(const Local3DPoint& entry,
Expand Down Expand Up @@ -105,6 +107,15 @@ class PSimHit {
*/
unsigned int trackId() const { return theTrackId; }

/** In case te SimTrack ID is incremented by the k_tidOffset for hit category definition, this
* methods returns the original theTrackId value directly.
*/
unsigned int originalTrackId() const { return theTrackId % k_tidOffset; }

unsigned int offsetTrackId() const { return theTrackId / k_tidOffset; }

static unsigned int addTrackIdOffset(unsigned int tId, unsigned int offset) { return offset * k_tidOffset + tId; }

EncodedEventId eventId() const { return theEventId; }

void setEventId(EncodedEventId e) { theEventId = e; }
Expand Down
1 change: 1 addition & 0 deletions SimG4CMS/Forward/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<use name="DataFormats/ForwardDetId"/>
<use name="DataFormats/Math"/>
<use name="SimDataFormats/SimHitMaker"/>
<use name="SimDataFormats/TrackingHit"/>
<use name="SimDataFormats/CaloHit"/>
<use name="Geometry/MTDCommonData"/>
<use name="boost"/>
Expand Down
6 changes: 3 additions & 3 deletions SimG4CMS/Forward/interface/MtdSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class MtdSD : public TimingSD {
int getTrackID(const G4Track *) override;

private:
static constexpr unsigned int k_idsecOffset = 100000000;
static constexpr unsigned int k_idloopOffset = 200000000;
static constexpr unsigned int k_idFromCaloOffset = 300000000;
static constexpr unsigned int k_idsecOffset = 1;
static constexpr unsigned int k_idloopOffset = 2;
static constexpr unsigned int k_idFromCaloOffset = 3;

double energyCut;
double energyHistoryCut;
Expand Down
7 changes: 4 additions & 3 deletions SimG4CMS/Forward/src/MtdSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Geometry/MTDCommonData/interface/BTLNumberingScheme.h"
#include "Geometry/MTDCommonData/interface/ETLNumberingScheme.h"
#include "DataFormats/ForwardDetId/interface/MTDDetId.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"

#include "G4Track.hh"
#include "G4Step.hh"
Expand Down Expand Up @@ -108,11 +109,11 @@ int MtdSD::getTrackID(const G4Track* aTrack) {
if (rname == "FastTimerRegionSensBTL") {
theID = trkInfo->mcTruthID();
if (trkInfo->isExtSecondary() && !trkInfo->isInTrkFromBackscattering()) {
theID += k_idsecOffset;
theID = PSimHit::addTrackIdOffset(theID, k_idsecOffset);
} else if (trkInfo->isInTrkFromBackscattering()) {
theID += k_idFromCaloOffset;
theID = PSimHit::addTrackIdOffset(theID, k_idFromCaloOffset);
} else if (trkInfo->isBTLlooper()) {
theID += k_idloopOffset;
theID = PSimHit::addTrackIdOffset(theID, k_idloopOffset);
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("MtdSim") << "MtdSD: Track ID: " << aTrack->GetTrackID()
Expand Down
5 changes: 4 additions & 1 deletion SimG4Core/Application/test/SimHitCaloHitDumper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ void SimHitCaloHitDumper::analyze(const edm::Event& iEvent, const edm::EventSetu
edm::LogPrint("SimHitCaloHitDumper") << (*icoll).second << " hits in the event = " << (*icoll).first;
edm::LogPrint("SimHitCaloHitDumper") << "\n";
for (int ihit = 0; ihit < (*icoll).first; ++ihit) {
edm::LogPrint("SimHitCaloHitDumper") << theMTDHits[nhit] << " Track Id = " << theMTDHits[nhit].trackId();
edm::LogPrint("SimHitCaloHitDumper")
<< theMTDHits[nhit] << " Energy = " << theMTDHits[nhit].energyLoss()
<< " tid orig/offset= " << theMTDHits[nhit].originalTrackId() << " " << theMTDHits[nhit].offsetTrackId()
<< " Track Id = " << theMTDHits[nhit].trackId();
nhit++;
}
}
Expand Down
1 change: 1 addition & 0 deletions SimG4Core/Notification/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<lib name="1"/>
</export>
<use name="SimDataFormats/Forward"/>
<use name="SimDataFormats/TrackingHit"/>
<use name="SimDataFormats/Track"/>
<use name="SimDataFormats/Vertex"/>
<use name="DataFormats/Math"/>
Expand Down
5 changes: 5 additions & 0 deletions SimG4Core/Notification/src/SimTrackManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "SimG4Core/Notification/interface/TmpSimVertex.h"
#include "SimG4Core/Notification/interface/TmpSimEvent.h"
#include "SimG4Core/Notification/interface/TrackInformation.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand Down Expand Up @@ -162,6 +163,10 @@ void SimTrackManager::reallyStoreTracks() {
}
}

if (id >= static_cast<int>(PSimHit::k_tidOffset)) {
throw cms::Exception("SimTrackManager::reallyStoreTracks")
<< " SimTrack ID " << id << " exceeds maximum allowed by PSimHit identifier" << PSimHit::k_tidOffset;
}
TmpSimTrack* g4simtrack =
new TmpSimTrack(id, trkH->particleID(), trkH->momentum(), trkH->totalEnergy(), ivertex, ig, pm, spos, smom);
g4simtrack->copyCrossedBoundaryVars(trkH);
Expand Down