Skip to content

Commit

Permalink
Define PSimHit offset and propagate to MTD hit categories, add except…
Browse files Browse the repository at this point in the history
…ion for track Ids exceeding it
  • Loading branch information
fabiocos committed Aug 8, 2023
1 parent 4a98a53 commit 7c3287f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
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) ? theTrackId % k_tidOffset : theTrackId; }

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

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
3 changes: 2 additions & 1 deletion SimG4Core/Application/test/SimHitCaloHitDumper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ 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()
<< " 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

0 comments on commit 7c3287f

Please sign in to comment.