Skip to content

Commit

Permalink
Merge pull request #32667 from cvuosalo/pps-physvol-names
Browse files Browse the repository at this point in the history
[DD4hep] Fix PPS simulation so physical volume names are recognized
  • Loading branch information
cmsbuild committed Jan 14, 2021
2 parents b763360 + 7ef37ed commit 17e3389
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
14 changes: 9 additions & 5 deletions SimG4CMS/PPS/src/PPSDiamondOrganization.cc
Expand Up @@ -15,16 +15,17 @@
//******************************************************************** Constructor and destructor

PPSDiamondOrganization ::PPSDiamondOrganization()
: theArm_(-1), theStation_(-1), theRoman_pot_(-1), thePlane_(-1), theDetector_(-1) {}
: theArm_(0), theStation_(0), theRoman_pot_(0), thePlane_(0), theDetector_(0) {}

uint32_t PPSDiamondOrganization::unitID(const G4Step* aStep) {
G4VPhysicalVolume* physVol;
const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
bool foundVacuum = false;

for (int ii = 0; ii < touch->GetHistoryDepth(); ii++) {
physVol = touch->GetVolume(ii);

if (physVol->GetName() == "CTPPS_Diamond_Segment" || physVol->GetName() == "CTPPS_UFSD_Segment") {
if (physVol->GetName().contains("CTPPS_Diamond_Segment") || physVol->GetName().contains("CTPPS_UFSD_Segment")) {
theDetector_ = physVol->GetCopyNo() % 100;
thePlane_ = physVol->GetCopyNo() / 100;
LogDebug("PPSSimDiamond") << "\n---------------------CTPPS_Diamond_Segment-------------------------------------"
Expand All @@ -34,15 +35,18 @@ uint32_t PPSDiamondOrganization::unitID(const G4Step* aStep) {
LogDebug("PPSSimDiamond") << "\t\t\t\t\tdetector= " << theDetector_ << " plane= " << thePlane_ << " ii = " << ii;
}

else if (physVol->GetName() == "Primary_Vacuum") {
else if (physVol->GetName().contains("Primary_Vacuum")) {
int cpy_no = physVol->GetCopyNo();
theArm_ = (cpy_no / 100) % 10;
theStation_ = (cpy_no / 10) % 10;
theRoman_pot_ = cpy_no % 10;
foundVacuum = true;
}
LogDebug("PPSSimDiamond") << "Diamond"
<< "physVol =" << physVol->GetName() << ", level=" << ii
LogDebug("PPSSimDiamond") << "Diamond physVol =" << physVol->GetName() << ", level=" << ii
<< ", physVol->GetCopyNo()=" << physVol->GetCopyNo() << std::endl;
}
if (foundVacuum == false) {
edm::LogError("PPSSimDiamond") << "Physical volume Primary_Vacuum not found. Cannot determine CTPPSDiamondDetId.";
}
return CTPPSDiamondDetId(theArm_, theStation_, theRoman_pot_, thePlane_, theDetector_).rawId();
}
17 changes: 13 additions & 4 deletions SimG4CMS/PPS/src/PPSPixelOrganization.cc
Expand Up @@ -18,7 +18,7 @@
// constructors and destructor
//
PPSPixelOrganization ::PPSPixelOrganization()
: currentUnitID_(-1), currentArm_(-1), currentStation_(-1), currentRP_(-1), currentPlane_(-1) {
: currentUnitID_(0), currentArm_(0), currentStation_(0), currentRP_(0), currentPlane_(0) {
edm::LogInfo("PPSSim") << "Creating PPSPixelOrganization";
}

Expand All @@ -30,24 +30,33 @@ uint32_t PPSPixelOrganization ::unitID(const G4Step* aStep) {
const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
G4VPhysicalVolume* physVol;
int ii = 0;
bool foundEnvelop = false;
bool foundPhysVol = false;

for (ii = 0; ii < touch->GetHistoryDepth(); ii++) {
while (ii < touch->GetHistoryDepth() && (foundEnvelop == false || foundPhysVol == false)) {
physVol = touch->GetVolume(ii);

edm::LogInfo("PPSSim") << "physVol=" << physVol->GetName() << ", level=" << ii
<< ", physVol->GetCopyNo()=" << physVol->GetCopyNo();

if (physVol->GetName().contains("Envelop")) {
currentPlane_ = physVol->GetCopyNo() - 1;
} else if (physVol->GetName() == "RP_box_primary_vacuum") {
foundEnvelop = true;
} else if (physVol->GetName().contains("RP_box_primary_vacuum")) {
int cpy_no = physVol->GetCopyNo();
currentArm_ = (cpy_no / 100) % 10;
currentStation_ = (cpy_no / 10) % 10;
currentRP_ = cpy_no % 10;
foundPhysVol = true;
}
++ii;
}

edm::LogInfo("PPSSim") << currentArm_ << " " << currentRP_ << " " << currentPlane_;
if (foundPhysVol) {
edm::LogInfo("PPSSim") << "Arm, RP, plane = " << currentArm_ << " " << currentRP_ << " " << currentPlane_;
} else {
edm::LogError("PPSSim") << "Physical volume RP_box_primary_vacuum not found. Cannot determine CTPPSPixelDetId.";
}

CTPPSPixelDetId id(currentArm_, currentStation_, currentRP_, currentPlane_);
uint32_t kk = id.rawId();
Expand Down
4 changes: 2 additions & 2 deletions SimG4CMS/PPS/src/PPSStripOrganization.cc
Expand Up @@ -20,9 +20,9 @@ uint32_t PPSStripOrganization::unitID(const G4Step* aStep) {

for (int ii = 0; ii < touch->GetHistoryDepth(); ii++) {
physVol = touch->GetVolume(ii);
if (physVol->GetName() == "RP_Silicon_Detector") {
if (physVol->GetName().contains("RP_Silicon_Detector")) {
detector = physVol->GetCopyNo();
} else if (physVol->GetName() == "RP_box_primary_vacuum") {
} else if (physVol->GetName().contains("RP_box_primary_vacuum")) {
int cpy_no = physVol->GetCopyNo();
arm = (cpy_no / 100) % 10;
station = (cpy_no / 10) % 10;
Expand Down

0 comments on commit 17e3389

Please sign in to comment.