Skip to content

Commit

Permalink
Fix and simplify logic for offset/original tid retrival, add test for…
Browse files Browse the repository at this point in the history
… new methods in SimHitCaloHitDumper
  • Loading branch information
fabiocos committed Aug 9, 2023
1 parent 7c3287f commit 49cd3e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions SimDataFormats/TrackingHit/interface/PSimHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class PSimHit {
/** 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 originalTrackId() const { return theTrackId % k_tidOffset; }

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

This comment has been minimized.

Copy link
@perrotta

perrotta Aug 9, 2023

Contributor

This won't work in case the original trackId is 0: I don't know if it is a case you want to take into account

This comment has been minimized.

Copy link
@fabiocos

fabiocos Aug 9, 2023

Author Contributor

@perrotta I doubt that a track id = 0 is a valid use case, I would consider it as a bug, @civanch please correct me in case. Anyway I am not sure I see your point. My trivial test:

#include <iostream>
#include <climits>

int main() {

  std::cout << "UINT_MAX = " << UINT_MAX << std::endl;

  unsigned int base = 200000000;

  std::cout << "base as int= " << static_cast<int>(base) << std::endl;

  unsigned int a = base*1+27;
  unsigned int b = base*2+27;
  unsigned int c = base*3+100000027;
  unsigned int aa = 27;
  unsigned int bb = 0;
  unsigned int cc = base;

  std::cout << "base= " << base << " a= " << a << " a/base= " << a/base << " original= " << a%base << std::endl;
  std::cout << "base= " << base << " b= " << b << " b/base= " << b/base << " original= " << b%base << std::endl;
  std::cout << "base= " << base << " c= " << c << " c/base= " << c/base << " original= " << c%base << std::endl;
  std::cout << "base= " << base << " aa= " << aa << " aa/base= " << aa/base << " original= " << aa%base << std::endl;
  std::cout << "base= " << base << " bb= " << bb << " bb/base= " << bb/base << " original= " << bb%base << std::endl;
  std::cout << "base= " << base << " cc= " << cc << " cc/base= " << cc/base << " original= " << cc%base << std::endl;

  return 0;

}

gives as output:

UINT_MAX = 4294967295
base as int= 200000000
base= 200000000 a= 200000027 a/base= 1 original= 27
base= 200000000 b= 400000027 b/base= 2 original= 27
base= 200000000 c= 700000027 c/base= 3 original= 100000027
base= 200000000 aa= 27 aa/base= 0 original= 27
base= 200000000 bb= 0 bb/base= 0 original= 0
base= 200000000 cc= 200000000 cc/base= 1 original= 0

What am I missing?

This comment has been minimized.

Copy link
@perrotta

perrotta Aug 9, 2023

Contributor

Indeed, I was thinking too fast...


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

Expand Down
6 changes: 4 additions & 2 deletions SimG4Core/Application/test/SimHitCaloHitDumper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +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] << " Energy = " << theMTDHits[nhit].energyLoss()
<< " 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

0 comments on commit 49cd3e2

Please sign in to comment.