Skip to content

Commit

Permalink
compressed finecalo changes - saving sim clusters per boundary-crossi…
Browse files Browse the repository at this point in the history
…ng particle
  • Loading branch information
Thomas Klijnsma authored and kdlong committed Sep 17, 2020
1 parent 15661fd commit 057c4fa
Show file tree
Hide file tree
Showing 27 changed files with 595 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void EcalSimpleProducer::produce(edm::Event &evt, const edm::EventSetup &) {
double em = simHitFormula_->Eval(iEta0, iPhi0, ievt - 1);
double eh = 0.;
double t = 0.;
const PCaloHit hit(EBDetId(iEta1, iPhi).rawId(), em, eh, t, 0);
const PCaloHit hit(EBDetId(iEta1, iPhi).rawId(), em, eh, t, 0, 0, 0);
hits->push_back(hit);
}
}
Expand Down
3 changes: 3 additions & 0 deletions SimDataFormats/CaloHit/interface/PCaloHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PCaloHit {
: myEnergy(e), myEMFraction(emFraction), myTime(t), myItra(i), detId(id), myDepth(d) {}
PCaloHit(float eEM, float eHad, float t, int i = 0, uint16_t d = 0);
PCaloHit(unsigned int id, float eEM, float eHad, float t, int i = 0, uint16_t d = 0);
PCaloHit(unsigned int id, float eEM, float eHad, float t, int i = 0, int iFine = 0, uint16_t d = 0);

//Names
static const char *name() { return "Hit"; }
Expand All @@ -31,6 +32,7 @@ class PCaloHit {

//Geant track number
int geantTrackId() const { return myItra; }
int geantFineTrackId() const { return myFineItra; }

//DetId where the Hit is recorded
void setID(unsigned int id) { detId = id; }
Expand Down Expand Up @@ -67,6 +69,7 @@ class PCaloHit {
float myEMFraction;
float myTime;
int myItra;
int myFineItra;
unsigned int detId;
uint16_t myDepth;
EncodedEventId theEventId;
Expand Down
6 changes: 6 additions & 0 deletions SimDataFormats/CaloHit/src/PCaloHit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ PCaloHit::PCaloHit(unsigned int id, float eEM, float eHad, float t, int i, uint1
myEMFraction = (myEnergy <= 0. ? 1. : eEM / myEnergy);
}

PCaloHit::PCaloHit(unsigned int id, float eEM, float eHad, float t, int i, int iFine, uint16_t d)
: myTime(t), myItra(i), myFineItra(iFine), detId(id), myDepth(d) {
myEnergy = eEM + eHad;
myEMFraction = (myEnergy <= 0. ? 1. : eEM / myEnergy);
}

std::ostream& operator<<(std::ostream& o, const PCaloHit& hit) {
o << "0x" << std::hex << hit.id() << std::dec << ": Energy (EM) " << hit.energyEM() << " GeV "
<< ": Energy (Had) " << hit.energyHad() << " GeV "
Expand Down
3 changes: 2 additions & 1 deletion SimDataFormats/CaloHit/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<lcgdict>
<class name="PCaloHit" ClassVersion="10">
<class name="PCaloHit" ClassVersion="11">
<version ClassVersion="11" checksum="2195704462"/>
<version ClassVersion="10" checksum="682759659"/>
</class>
<class name="std::vector<PCaloHit>"/>
Expand Down
1 change: 1 addition & 0 deletions SimDataFormats/SimHitMaker/interface/CaloSlaveSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CaloSlaveSD {
virtual void Initialize();
std::string name() const { return name_; }
virtual bool processHits(uint32_t, double, double, double, int, uint16_t depth = 0);
virtual bool processHits(uint32_t, double, double, double, int, int, uint16_t depth = 0);
virtual bool format();
Collection &hits() { return hits_; }
std::string type() { return "calo"; }
Expand Down
7 changes: 7 additions & 0 deletions SimDataFormats/SimHitMaker/src/CaloSlaveSD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ bool CaloSlaveSD::processHits(uint32_t unitID, double eDepEM, double eDepHad, do
return true;
}

bool CaloSlaveSD::processHits(uint32_t unitID, double eDepEM, double eDepHad, double tSlice, int tkID, int fineTkId, uint16_t depth) {
PCaloHit aCal = PCaloHit(unitID, eDepEM, eDepHad, tSlice, tkID, fineTkId, depth);
LogDebug("HitBuildInfo") << " Sent Hit " << aCal << " to ROU " << name_;
hits_.push_back(aCal);
return true;
}

void CaloSlaveSD::Clean() {
LogDebug("HitBuildIndo") << "CaloSlaveSD " << name_ << " cleaning the collection";
Collection().swap(hits_);
Expand Down
35 changes: 35 additions & 0 deletions SimDataFormats/Track/interface/SimTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define SimTrack_H

#include "SimDataFormats/Track/interface/CoreSimTrack.h"
#include "DataFormats/Math/interface/Vector3D.h"
#include "DataFormats/Math/interface/LorentzVector.h"
#include "FWCore/Utilities/interface/Exception.h"

class SimTrack : public CoreSimTrack {
public:
Expand Down Expand Up @@ -44,12 +47,44 @@ class SimTrack : public CoreSimTrack {

inline void setVertexIndex(const int v) { ivert = v; }

// Boundary crossing variables
void setCrossedBoundaryPosMom(int id, const math::XYZVectorD position, const math::XYZTLorentzVectorD momentum){
crossedBoundary_ = true;
idAtBoundary_ = id;
positionAtBoundary_ = position;
momentumAtBoundary_ = momentum;
}
bool crossedBoundary() const { return crossedBoundary_; }
math::XYZVectorD getPositionAtBoundary() const {
assertCrossedBoundary();
return positionAtBoundary_;
}
math::XYZTLorentzVectorD getMomentumAtBoundary() const {
assertCrossedBoundary();
return momentumAtBoundary_;
}
int getIDAtBoundary() const {
assertCrossedBoundary();
return idAtBoundary_;
}

private:
int ivert;
int igenpart;

math::XYZVectorD tkposition;
math::XYZTLorentzVectorD tkmomentum;

bool crossedBoundary_;
int idAtBoundary_;
math::XYZVectorD positionAtBoundary_;
math::XYZTLorentzVectorD momentumAtBoundary_;
void assertCrossedBoundary() const {
if (!crossedBoundary_){
throw cms::Exception("Unknown", "SimTrack")
<< "Assert crossed boundary failed for track " << trackId();
}
}
};

#include <iosfwd>
Expand Down
10 changes: 5 additions & 5 deletions SimDataFormats/Track/src/SimTrack.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#include "SimDataFormats/Track/interface/SimTrack.h"

SimTrack::SimTrack() : ivert(-1), igenpart(-1) {}
SimTrack::SimTrack() : ivert(-1), igenpart(-1), crossedBoundary_(false) {}

SimTrack::SimTrack(int ipart, const math::XYZTLorentzVectorD& p) : Core(ipart, p), ivert(-1), igenpart(-1) {}
SimTrack::SimTrack(int ipart, const math::XYZTLorentzVectorD& p) : Core(ipart, p), ivert(-1), igenpart(-1), crossedBoundary_(false) {}

SimTrack::SimTrack(int ipart, const math::XYZTLorentzVectorD& p, int iv, int ig)
: Core(ipart, p), ivert(iv), igenpart(ig) {}
: Core(ipart, p), ivert(iv), igenpart(ig), crossedBoundary_(false) {}

SimTrack::SimTrack(int ipart,
const math::XYZTLorentzVectorD& p,
int iv,
int ig,
const math::XYZVectorD& tkp,
const math::XYZTLorentzVectorD& tkm)
: Core(ipart, p), ivert(iv), igenpart(ig), tkposition(tkp), tkmomentum(tkm) {}
: Core(ipart, p), ivert(iv), igenpart(ig), tkposition(tkp), tkmomentum(tkm), crossedBoundary_(false) {}

SimTrack::SimTrack(const CoreSimTrack& t, int iv, int ig) : Core(t), ivert(iv), igenpart(ig) {}
SimTrack::SimTrack(const CoreSimTrack& t, int iv, int ig) : Core(t), ivert(iv), igenpart(ig), crossedBoundary_(false) {}

std::ostream& operator<<(std::ostream& o, const SimTrack& t) {
return o << (SimTrack::Core)(t) << ", " << t.vertIndex() << ", " << t.genpartIndex();
Expand Down
3 changes: 2 additions & 1 deletion SimDataFormats/Track/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<class name="CoreSimTrack" ClassVersion="10">
<version ClassVersion="10" checksum="3936841839"/>
</class>
<class name="SimTrack" ClassVersion="11">
<class name="SimTrack" ClassVersion="12">
<version ClassVersion="12" checksum="392307072"/>
<version ClassVersion="11" checksum="1785575744"/>
<version ClassVersion="10" checksum="1430205451"/>
</class>
Expand Down
5 changes: 4 additions & 1 deletion SimG4CMS/Calo/interface/CaloG4Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CaloG4Hit : public G4VHit {
void setIncidentEnergy(double e) { theIncidentEnergy = e; }

int getTrackID() const { return hitID.trackID(); }

uint32_t getUnitID() const { return hitID.unitID(); }
double getTimeSlice() const { return hitID.timeSlice(); }
int getTimeSliceID() const { return hitID.timeSliceID(); }
Expand Down Expand Up @@ -97,6 +98,8 @@ class CaloG4HitLess {
return (a->getUnitID() < b->getUnitID());
} else if (a->getDepth() != b->getDepth()) {
return (a->getDepth() < b->getDepth());
} else if (a->getID().getFineTrackID() != b->getID().getFineTrackID()) {
return (a->getID().getFineTrackID() < b->getID().getFineTrackID());
} else {
return (a->getTimeSliceID() < b->getTimeSliceID());
}
Expand All @@ -107,7 +110,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->getTimeSliceID() == b->getTimeSliceID() && a->getID().getFineTrackID() == b->getID().getFineTrackID());
}
};

Expand Down
9 changes: 9 additions & 0 deletions SimG4CMS/Calo/interface/CaloHitID.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class CaloHitID {
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth = 0);
void reset();

bool hasFineTrackID() const { return hasFineTrackID_; }
void setFineTrackID(int fineTrackID){
theFineTrackID = fineTrackID;
hasFineTrackID_ = true;
}
int getFineTrackID() const { return hasFineTrackID_ ? theFineTrackID : theTrackID; }

bool operator==(const CaloHitID&) const;
bool operator<(const CaloHitID&) const;
bool operator>(const CaloHitID&) const;
Expand All @@ -37,6 +44,8 @@ class CaloHitID {
uint16_t theDepth;
float timeSliceUnit;
bool ignoreTrackID;
bool hasFineTrackID_;
int theFineTrackID;
};

std::ostream& operator<<(std::ostream&, const CaloHitID&);
Expand Down
3 changes: 2 additions & 1 deletion SimG4CMS/Calo/interface/CaloSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ class CaloSD : public SensitiveCaloDetector,
float timeSlice;
double eminHitD;
double correctT;
bool useFineCaloID_;
bool doFineCalo_;
double eMinFine_;

std::map<CaloHitID, CaloG4Hit*> hitMap;
std::map<int, TrackWithHistory*> tkMap;
Expand Down
2 changes: 1 addition & 1 deletion SimG4CMS/Calo/interface/CaloTrkProcessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CaloTrkProcessing : public SensitiveCaloDetector,
G4LogicalVolume* detLV(const G4VTouchable*, int) const;
void detectorLevel(const G4VTouchable*, int&, int*, G4String*) const;

bool testBeam_, putHistory_, doFineCalo_, storeHGCBoundaryCross_;
bool testBeam_, putHistory_, doFineCalo_, storeAllTracksCalo_;
double eMin_, eMinFine_, eMinFinePhoton_;
int lastTrackID_;
std::vector<Detector> detectors_, fineDetectors_;
Expand Down
1 change: 0 additions & 1 deletion SimG4CMS/Calo/src/CaloG4Hit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const CaloG4Hit& CaloG4Hit::operator=(const CaloG4Hit& right) {
hadr = right.hadr;
theIncidentEnergy = right.theIncidentEnergy;
hitID = right.hitID;

return *this;
}

Expand Down
14 changes: 12 additions & 2 deletions SimG4CMS/Calo/src/CaloHitID.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ CaloHitID::CaloHitID(const CaloHitID& id) {
theDepth = id.theDepth;
timeSliceUnit = id.timeSliceUnit;
ignoreTrackID = id.ignoreTrackID;
hasFineTrackID_ = id.hasFineTrackID_;
theFineTrackID = id.theFineTrackID;
}

const CaloHitID& CaloHitID::operator=(const CaloHitID& id) {
Expand All @@ -31,7 +33,8 @@ const CaloHitID& CaloHitID::operator=(const CaloHitID& id) {
theDepth = id.theDepth;
timeSliceUnit = id.timeSliceUnit;
ignoreTrackID = id.ignoreTrackID;

hasFineTrackID_ = id.hasFineTrackID_;
theFineTrackID = id.theFineTrackID;
return *this;
}

Expand All @@ -51,18 +54,22 @@ void CaloHitID::reset() {
theTrackID = -2;
theTimeSliceID = (int)(theTimeSlice / timeSliceUnit);
theDepth = 0;
theFineTrackID = -3;
hasFineTrackID_ = false;
}

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

bool CaloHitID::operator<(const CaloHitID& id) const {
if (theTrackID != id.trackID()) {
return (theTrackID > id.trackID());
} else if (getFineTrackID() != id.getFineTrackID()) {
return (getFineTrackID() > id.getFineTrackID());
} else if (theUnitID != id.unitID()) {
return (theUnitID > id.unitID());
} else if (theDepth != id.depth()) {
Expand All @@ -75,6 +82,8 @@ bool CaloHitID::operator<(const CaloHitID& id) const {
bool CaloHitID::operator>(const CaloHitID& id) const {
if (theTrackID != id.trackID()) {
return (theTrackID < id.trackID());
} else if (getFineTrackID() != id.getFineTrackID()) {
return (getFineTrackID() < id.getFineTrackID());
} else if (theUnitID != id.unitID()) {
return (theUnitID < id.unitID());
} else if (theDepth != id.depth()) {
Expand All @@ -87,5 +96,6 @@ 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.getFineTrackID();
return os;
}
Loading

0 comments on commit 057c4fa

Please sign in to comment.