Skip to content

Commit

Permalink
Fully resolve the issue of usinng dd4hep in CherenkovAnalysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunanda committed Aug 31, 2021
1 parent 60eb2fb commit 213cbdc
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 49 deletions.
1 change: 1 addition & 0 deletions SimG4CMS/CherenkovAnalysis/data/SingleDREAMDD4Hep.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<IncludeSection>
<Include ref='Geometry/CMSCommonData/data/materials/2021/v2/materials.xml'/>
<Include ref='SimG4CMS/CherenkovAnalysis/data/cms.xml'/>
<Include ref='SimG4CMS/CherenkovAnalysis/data/singleDREAM.xml'/>
</IncludeSection>
</DDDefinition>
Expand Down
35 changes: 35 additions & 0 deletions SimG4CMS/CherenkovAnalysis/data/cms.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<DDDefinition>

<SolidSection label="cms">
<Box name="DREAM" dx="2.0*m" dy="0.3*m" dz="2.0*m"/>
<Box name="Crystal" dx="9.0*cm" dy="1.1*cm" dz="1.1*cm"/>
</SolidSection>

<LogicalPartSection label="cms">
<LogicalPart name="OCMS" category="unspecified">
<rSolid name="DREAM"/>
<rMaterial name="materials:Air"/>
</LogicalPart>
<LogicalPart name="DREAM" category="unspecified">
<rSolid name="DREAM"/>
<rMaterial name="materials:Air"/>
</LogicalPart>
<LogicalPart name="Crystal" category="unspecified">
<rSolid name="Crystal"/>
<rMaterial name="materials:E_PbWO4"/>
</LogicalPart>
</LogicalPartSection>

<PosPartSection label="cms">
<PosPart copyNumber="1">
<rParent name="cms:OCMS"/>
<rChild name="cms:DREAM"/>
</PosPart>
<PosPart copyNumber="1">
<rParent name="cms:DREAM"/>
<rChild name="cms:Crystal"/>
</PosPart>
</PosPartSection>

</DDDefinition>
30 changes: 0 additions & 30 deletions SimG4CMS/CherenkovAnalysis/data/singleDREAM.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
<?xml version="1.0"?>
<DDDefinition>

<SolidSection label="singleDREAM">
<Box name="DREAM" dx="2.0*m" dy="0.3*m" dz="2.0*m"/>
<Box name="Crystal" dx="9.0*cm" dy="1.1*cm" dz="1.1*cm"/>
</SolidSection>

<LogicalPartSection label="singleDREAM">
<LogicalPart name="World" category="unspecified">
<rSolid name="DREAM"/>
<rMaterial name="materials:Air"/>
</LogicalPart>
<LogicalPart name="DREAM" category="unspecified">
<rSolid name="DREAM"/>
<rMaterial name="materials:Air"/>
</LogicalPart>
<LogicalPart name="Crystal" category="unspecified">
<rSolid name="Crystal"/>
<rMaterial name="materials:E_PbWO4"/>
</LogicalPart>
</LogicalPartSection>

<PosPartSection label="singleDREAM">
<PosPart copyNumber="1">
<rParent name="singleDREAM:World"/>
<rChild name="singleDREAM:DREAM"/>
</PosPart>
<PosPart copyNumber="1">
<rParent name="singleDREAM:DREAM"/>
<rChild name="singleDREAM:Crystal"/>
</PosPart>
</PosPartSection>

<SpecParSection label="singleDREAM" eval="true">
<SpecPar name="Crystal">
Expand Down
3 changes: 2 additions & 1 deletion SimG4CMS/CherenkovAnalysis/python/SingleDREAMXML_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
XMLIdealGeometryESSource = cms.ESSource("XMLIdealGeometryESSource",
geomXMLFiles = cms.vstring(
'Geometry/CMSCommonData/data/materials/2021/v2/materials.xml',
'SimG4CMS/CherenkovAnalysis/data/cms.xml',
'SimG4CMS/CherenkovAnalysis/data/singleDREAM.xml'),
rootNodeName = cms.string('singleDREAM:DREAM')
rootNodeName = cms.string('cms:OCMS')
)


23 changes: 6 additions & 17 deletions SimG4CMS/CherenkovAnalysis/src/DreamSD.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

#include <memory>

#include "DetectorDescription/Core/interface/DDCompactView.h"
#include "DetectorDescription/Core/interface/DDFilter.h"
#include "DetectorDescription/Core/interface/DDFilteredView.h"
Expand Down Expand Up @@ -142,11 +139,10 @@ void DreamSD::initMap(const std::string &sd) {
DDFilteredView fv((*cpvDDD_), filter);
fv.firstChild();
bool dodet = true;
const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
while (dodet) {
const DDSolid &sol = fv.logicalPart().solid();
std::vector<double> paras(sol.parameters());
G4String name = sol.name().name();
std::string name = static_cast<std::string>(sol.name().name());
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EcalSim") << "DreamSD::initMap (for " << sd << "): Solid " << name << " Shape " << sol.shape()
<< " Parameter 0 = " << paras[0];
Expand All @@ -155,16 +151,7 @@ void DreamSD::initMap(const std::string &sd) {
std::sort(paras.begin(), paras.end());
double length = 2.0 * k_ScaleFromDDDToG4 * paras.back();
double width = 2.0 * k_ScaleFromDDDToG4 * paras.front();
G4LogicalVolume *lv = nullptr;
for (auto lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
if ((*lvcite)->GetName() == name) {
lv = (*lvcite);
break;
}
xtalLMap_.insert(std::pair<G4LogicalVolume *, Doubles>(lv, Doubles(length, width)));
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("EcalSim") << "DreamSD " << name << ":" << lv << ":" << length << ":" << width;
#endif
fillMap(name, length, width);
dodet = fv.next();
}
}
Expand All @@ -191,7 +178,8 @@ void DreamSD::fillMap(const std::string &name, double length, double width) {
G4LogicalVolume *lv = nullptr;
for (auto lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
edm::LogVerbatim("EcalSim") << name << " vs " << (*lvcite)->GetName();
if ((*lvcite)->GetName() == static_cast<G4String>(name)) {
std::string namex = static_cast<std::string>((*lvcite)->GetName());
if (name == static_cast<std::string>(dd4hep::dd::noNamespace(namex))) {
lv = (*lvcite);
break;
}
Expand Down Expand Up @@ -432,7 +420,8 @@ double DreamSD::getAverageNumberOfPhotons_(const double charge,
// Values from Ts42 detector construction
bool DreamSD::setPbWO2MaterialProperties_(G4Material *aMaterial) {
std::string pbWO2Name("E_PbWO4");
if (pbWO2Name != aMaterial->GetName()) { // Wrong material!
std::string name = static_cast<std::string>(aMaterial->GetName());
if (static_cast<std::string>(dd4hep::dd::noNamespace(name)) != pbWO2Name) { // Wrong material!
edm::LogWarning("EcalSim") << "This is not the right material: "
<< "expecting " << pbWO2Name << ", got " << aMaterial->GetName();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
process.p1 = cms.Path(process.generator*process.VtxSmeared*process.generatorSmeared*process.g4SimHits*process.cherenkovAnalysis)

process.DDDetectorESProducer.confGeomXMLFiles = cms.FileInPath("SimG4CMS/CherenkovAnalysis/data/SingleDREAMDD4Hep.xml")
process.DDDetectorESProducer.rootDDName = 'singleDREAM:DREAM'
process.generator.PGunParameters.MinE = 10.0
process.generator.PGunParameters.MaxE = 10.0
process.g4SimHits.UseMagneticField = False
Expand Down

0 comments on commit 213cbdc

Please sign in to comment.