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

Fixed finecalo performance #34597

Merged
merged 2 commits into from
Aug 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions SimG4CMS/Calo/interface/CaloG4Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CaloG4Hit : public G4VHit {
double getTimeSlice() const { return hitID.timeSlice(); }
int getTimeSliceID() const { return hitID.timeSliceID(); }
uint16_t getDepth() const { return hitID.depth(); }
bool isFinecaloTrackID() const { return hitID.isFinecaloTrackID(); }

CaloHitID getID() const { return hitID; }
void setID(uint32_t i, double d, int j, uint16_t k = 0) { hitID.setID(i, d, j, k); }
Expand Down Expand Up @@ -98,8 +99,6 @@ class CaloG4HitLess {
return (a->getUnitID() < b->getUnitID());
} else if (a->getDepth() != b->getDepth()) {
return (a->getDepth() < b->getDepth());
} else if (a->getID().fineTrackID() != b->getID().fineTrackID()) {
return (a->getID().fineTrackID() < b->getID().fineTrackID());
} else {
return (a->getTimeSliceID() < b->getTimeSliceID());
}
Expand All @@ -110,7 +109,7 @@ class CaloG4HitEqual {
public:
bool operator()(const CaloG4Hit* a, const CaloG4Hit* b) {
return (a->getTrackID() == b->getTrackID() && a->getUnitID() == b->getUnitID() && a->getDepth() == b->getDepth() &&
a->getTimeSliceID() == b->getTimeSliceID() && a->getID().fineTrackID() == b->getID().fineTrackID());
a->getTimeSliceID() == b->getTimeSliceID());
}
};

Expand Down
7 changes: 3 additions & 4 deletions SimG4CMS/Calo/interface/CaloHitID.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ class CaloHitID {
void reset();

void setTrackID(int trackID) { theTrackID = trackID; }
bool hasFineTrackID() const { return theFineTrackID != -1; }
void setFineTrackID(int fineTrackID) { theFineTrackID = fineTrackID; }
int fineTrackID() const { return hasFineTrackID() ? theFineTrackID : theTrackID; }
void markAsFinecaloTrackID(bool flag = true) { isFinecaloTrackID_ = flag; }
bool isFinecaloTrackID() const { return isFinecaloTrackID_; }

bool operator==(const CaloHitID&) const;
bool operator<(const CaloHitID&) const;
Expand All @@ -42,7 +41,7 @@ class CaloHitID {
uint16_t theDepth;
float timeSliceUnit;
bool ignoreTrackID;
int theFineTrackID;
bool isFinecaloTrackID_;
};

std::ostream& operator<<(std::ostream&, const CaloHitID&);
Expand Down
7 changes: 6 additions & 1 deletion SimG4CMS/Calo/interface/CaloSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <vector>
#include <map>
#include <unordered_map>
#include <memory>

class G4Step;
Expand Down Expand Up @@ -85,7 +86,9 @@ class CaloSD : public SensitiveCaloDetector,
double getAttenuation(const G4Step* aStep, double birk1, double birk2, double birk3) const;

static std::string printableDecayChain(const std::vector<unsigned int>& decayChain);
void hitBookkeepingFineCalo(const G4Step* step, const G4Track* currentTrack, CaloG4Hit* hit);
std::string shortreprID(const CaloHitID& ID);
std::string shortreprID(const CaloG4Hit* hit);
unsigned int findBoundaryCrossingParent(const G4Track* track, bool markParentAsSaveable = true);

void update(const BeginOfRun*) override;
void update(const BeginOfEvent*) override;
Expand Down Expand Up @@ -183,8 +186,10 @@ class CaloSD : public SensitiveCaloDetector,

std::map<CaloHitID, CaloG4Hit*> hitMap;
std::map<int, TrackWithHistory*> tkMap;
std::unordered_map<unsigned int, unsigned int> boundaryCrossingParentMap_;
std::vector<std::unique_ptr<CaloG4Hit>> reusehit;
std::vector<Detector> fineDetectors_;
bool doFineCaloThisStep_;
};

#endif // SimG4CMS_CaloSD_h
16 changes: 5 additions & 11 deletions SimG4CMS/Calo/src/CaloHitID.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <iomanip>

CaloHitID::CaloHitID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth, float tSlice, bool ignoreTkID)
: timeSliceUnit(tSlice), ignoreTrackID(ignoreTkID), theFineTrackID(-1) {
: timeSliceUnit(tSlice), ignoreTrackID(ignoreTkID), isFinecaloTrackID_(false) {
setID(unitID, timeSlice, trackID, depth);
}

Expand All @@ -21,7 +21,7 @@ CaloHitID::CaloHitID(const CaloHitID& id) {
theDepth = id.theDepth;
timeSliceUnit = id.timeSliceUnit;
ignoreTrackID = id.ignoreTrackID;
theFineTrackID = id.theFineTrackID;
isFinecaloTrackID_ = id.isFinecaloTrackID_;
}

const CaloHitID& CaloHitID::operator=(const CaloHitID& id) {
Expand All @@ -32,7 +32,7 @@ const CaloHitID& CaloHitID::operator=(const CaloHitID& id) {
theDepth = id.theDepth;
timeSliceUnit = id.timeSliceUnit;
ignoreTrackID = id.ignoreTrackID;
theFineTrackID = id.theFineTrackID;
isFinecaloTrackID_ = id.isFinecaloTrackID_;
return *this;
}

Expand All @@ -52,21 +52,19 @@ void CaloHitID::reset() {
theTrackID = -2;
theTimeSliceID = (int)(theTimeSlice / timeSliceUnit);
theDepth = 0;
theFineTrackID = -1;
isFinecaloTrackID_ = false;
}

bool CaloHitID::operator==(const CaloHitID& id) const {
return ((theUnitID == id.unitID()) && (theTrackID == id.trackID() || ignoreTrackID) &&
(theTimeSliceID == id.timeSliceID()) && (theDepth == id.depth()) && (fineTrackID() == id.fineTrackID()))
(theTimeSliceID == id.timeSliceID()) && (theDepth == id.depth()))
? true
: false;
}

bool CaloHitID::operator<(const CaloHitID& id) const {
if (theTrackID != id.trackID()) {
return (theTrackID > id.trackID());
} else if (fineTrackID() != id.fineTrackID()) {
return (fineTrackID() > id.fineTrackID());
} else if (theUnitID != id.unitID()) {
return (theUnitID > id.unitID());
} else if (theDepth != id.depth()) {
Expand All @@ -79,8 +77,6 @@ bool CaloHitID::operator<(const CaloHitID& id) const {
bool CaloHitID::operator>(const CaloHitID& id) const {
if (theTrackID != id.trackID()) {
return (theTrackID < id.trackID());
} else if (fineTrackID() != id.fineTrackID()) {
return (fineTrackID() < id.fineTrackID());
} else if (theUnitID != id.unitID()) {
return (theUnitID < id.unitID());
} else if (theDepth != id.depth()) {
Expand All @@ -93,7 +89,5 @@ bool CaloHitID::operator>(const CaloHitID& id) const {
std::ostream& operator<<(std::ostream& os, const CaloHitID& id) {
os << "UnitID 0x" << std::hex << id.unitID() << std::dec << " Depth " << std::setw(6) << id.depth() << " Time "
<< std::setw(6) << id.timeSlice() << " TrackID " << std::setw(8) << id.trackID();
if (id.hasFineTrackID())
os << " fineTrackID " << id.fineTrackID();
return os;
}