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

Phase2-hgx232 Further attempt to make dd4hep compliant #28869

Merged
merged 4 commits into from Feb 14, 2020
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
6 changes: 3 additions & 3 deletions Geometry/HGCalCommonData/data/hgcal/v9/hgcal.xml
Expand Up @@ -78,7 +78,7 @@
<Constant name="rMaxHEmixMax" value="[rMaxHGCal3]"/>
</ConstantsSection>

<SolidSection label="hgcal.xml">
<SolidSection label="hgcal.xml" eval="true">
<Polycone name="HGCal" startPhi="0*deg" deltaPhi="360*deg">
<ZSection z="[zHGCal1]" rMin="[rMinHGCal1]" rMax="[rMaxHGCal1]"/>
<ZSection z="[zHGCal2]" rMin="[rMinHGCal2]" rMax="[rMaxHGCal2]"/>
Expand All @@ -101,7 +101,7 @@
</Polycone>
</SolidSection>

<LogicalPartSection label="hgcal.xml">
<LogicalPartSection label="hgcal.xml" eval="true">
<LogicalPart name="HGCal" category="unspecified">
<rSolid name="HGCal"/>
<rMaterial name="materials:Air"/>
Expand All @@ -120,7 +120,7 @@
</LogicalPart>
</LogicalPartSection>

<PosPartSection label="hgcal.xml">
<PosPartSection label="hgcal.xml" eval="true">
<PosPart copyNumber="1">
<rParent name="caloBase:CALO"/>
<rChild name="hgcal:HGCal"/>
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/data/hgcalEE/v9/hgcalEE.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<DDDefinition xmlns="http://www.cern.ch/cms/DDL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cern.ch/cms/DDL ../../../../DetectorDescription/Schema/DDLSchema.xsd">

<PosPartSection label="hgcalHEsil.xml">
<PosPartSection label="hgcalHEsil.xml" eval="true">
<Algorithm name="hgcal:DDHGCalEEAlgo">
<rParent name="hgcal:HGCalEE"/>
<Vector name="WaferNames" type="string" nEntries="6">
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/data/hgcalHEmix/v9/hgcalHEmix.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<DDDefinition xmlns="http://www.cern.ch/cms/DDL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cern.ch/cms/DDL ../../../../DetectorDescription/Schema/DDLSchema.xsd">

<PosPartSection label="hgcalHEmix.xml">
<PosPartSection label="hgcalHEmix.xml" eval="true">
<Algorithm name="hgcal:DDHGCalHEAlgo">
<rParent name="hgcal:HGCalHEmix"/>
<Vector name="WaferNames" type="string" nEntries="6">
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/data/hgcalHEsil/v9/hgcalHEsil.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<DDDefinition xmlns="http://www.cern.ch/cms/DDL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cern.ch/cms/DDL ../../../../DetectorDescription/Schema/DDLSchema.xsd">

<PosPartSection label="hgcalHEsil.xml">
<PosPartSection label="hgcalHEsil.xml" eval="true">
<Algorithm name="hgcal:DDHGCalEEAlgo">
<rParent name="hgcal:HGCalHEsil"/>
<Vector name="WaferNames" type="string" nEntries="6">
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/data/hgcalcell/v9/hgcalcell.xml
Expand Up @@ -11,7 +11,7 @@
<Constant name="NumberOfCellsCoarse" value="[hgcal:NumberOfCellsCoarse]"/>
</ConstantsSection>

<PosPartSection label="hgcalcell.xml">
<PosPartSection label="hgcalcell.xml" eval="true">
<Algorithm name="hgcal:DDHGCalCell">
<rParent name="hgcalwafer:HGCalCell"/>
<Numeric name="WaferSize" value="[WaferSize]"/>
Expand Down
2 changes: 1 addition & 1 deletion Geometry/HGCalCommonData/data/hgcalwafer/v9/hgcalwafer.xml
Expand Up @@ -10,7 +10,7 @@
<Constant name="NumberOfCellsCoarse" value="[hgcal:NumberOfCellsCoarse]"/>
</ConstantsSection>

<PosPartSection label="hgcalcell.xml">
<PosPartSection label="hgcalcell.xml" eval="true">
<Algorithm name="hgcal:DDHGCalWafer8">
<rParent name="hgcalwafer:HGCalEEWafer0Fine"/>
<Numeric name="WaferSize" value="[WaferSize]"/>
Expand Down
73 changes: 42 additions & 31 deletions Geometry/HGCalCommonData/interface/HGCalGeomParameters.h
Expand Up @@ -30,39 +30,50 @@ class HGCalGeomParameters {
public:
HGCalGeomParameters();
~HGCalGeomParameters();
void loadGeometryHexagon(const DDFilteredView&,
HGCalParameters&,
const std::string&,
const DDCompactView*,
const std::string&,
const std::string&,
HGCalGeometryMode::WaferMode);
void loadGeometryHexagon(cms::DDFilteredView&,
HGCalParameters&,
const std::string&,
const cms::DDCompactView*,
const std::string&,
const std::string&,
HGCalGeometryMode::WaferMode);
void loadGeometryHexagon8(const DDFilteredView&, HGCalParameters&, int);
void loadGeometryHexagon8(cms::DDFilteredView&, HGCalParameters&, int);
void loadSpecParsHexagon(
const DDFilteredView&, HGCalParameters&, const DDCompactView*, const std::string&, const std::string&);
void loadSpecParsHexagon(const cms::DDFilteredView&,
HGCalParameters&,
const cms::DDCompactView*,
const std::string&,
const std::string&,
const std::string&,
const std::string&);
void loadSpecParsHexagon8(const DDFilteredView&, HGCalParameters&);
void loadSpecParsHexagon8(const cms::DDFilteredView&, const cms::DDVectorsMap&, HGCalParameters&, const std::string&);
void loadSpecParsTrapezoid(const DDFilteredView&, HGCalParameters&);
void loadSpecParsTrapezoid(const cms::DDFilteredView&, const cms::DDVectorsMap&, HGCalParameters&, const std::string&);

void loadGeometryHexagon(const DDFilteredView& _fv,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @bsunanda, I see you are loading DDFilteredView/CompactView both from Core and DDCMS. Do you have a list of missing methods (or compiler errors) that you get by using DDCMS instances only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vargasa The idea is that I would like to load geometry for either DDD or DD4Hep scenario. The difference is created by a run time flag which is under control of an ERA. So when this flag is set it loads geometry using DDCMS call, otherwise using call to Core. The 2 scenarios DDD vs DD4Hep need to coexist for a while. I do not want to have 2 libraries for core and DDCMS functionalities at this moment.

HGCalParameters& php,
const std::string& sdTag1,
const DDCompactView* cpv,
const std::string& sdTag2,
const std::string& sdTag3,
HGCalGeometryMode::WaferMode mode);
void loadGeometryHexagon(const cms::DDCompactView* cpv,
HGCalParameters& php,
const std::string& sdTag1,
const std::string& sdTag2,
const std::string& sdTag3,
HGCalGeometryMode::WaferMode mode);
void loadGeometryHexagon8(const DDFilteredView& _fv, HGCalParameters& php, int firstLayer);
void loadGeometryHexagon8(const cms::DDCompactView* cpv,
HGCalParameters& php,
const std::string& sdTag1,
int firstLayer);
void loadSpecParsHexagon(const DDFilteredView& fv,
HGCalParameters& php,
const DDCompactView* cpv,
const std::string& sdTag1,
const std::string& sdTag2);
void loadSpecParsHexagon(const cms::DDFilteredView& fv,
HGCalParameters& php,
const std::string& sdTag1,
const std::string& sdTag2,
const std::string& sdTag3,
const std::string& sdTag4);
void loadSpecParsHexagon8(const DDFilteredView& fv, HGCalParameters& php);
void loadSpecParsHexagon8(const cms::DDFilteredView& fv,
const cms::DDVectorsMap& vmap,
HGCalParameters& php,
const std::string& sdTag1);
void loadSpecParsTrapezoid(const DDFilteredView& fv, HGCalParameters& php);
void loadSpecParsTrapezoid(const cms::DDFilteredView& fv,
const cms::DDVectorsMap& vmap,
HGCalParameters& php,
const std::string& sdTag1);
void loadWaferHexagon(HGCalParameters& php);
void loadWaferHexagon8(HGCalParameters& php);
void loadCellParsHexagon(const DDCompactView* cpv, HGCalParameters& php);
void loadCellParsHexagon(const cms::DDVectorsMap&, HGCalParameters& php);
void loadCellParsHexagon(const cms::DDVectorsMap& vmap, HGCalParameters& php);
void loadCellParsHexagon(const HGCalParameters& php);
void loadCellTrapezoid(HGCalParameters& php);

Expand Down Expand Up @@ -97,7 +108,7 @@ class HGCalGeomParameters {
void loadSpecParsHexagon(const HGCalParameters& php);
void loadSpecParsHexagon8(const HGCalParameters& php);
void loadSpecParsTrapezoid(const HGCalParameters& php);
std::vector<double> getDDDArray(const std::string&, const DDsvalues_type&, const int);
std::vector<double> getDDDArray(const std::string& str, const DDsvalues_type& sv, const int nmin);
std::pair<double, double> cellPosition(const std::vector<cellParameters>& wafers,
std::vector<cellParameters>::const_iterator& itrf,
int wafer,
Expand Down
26 changes: 13 additions & 13 deletions Geometry/HGCalCommonData/interface/HGCalParametersFromDD.h
Expand Up @@ -14,19 +14,19 @@ class HGCalParametersFromDD {
HGCalParametersFromDD() {}
virtual ~HGCalParametersFromDD() {}

bool build(const DDCompactView*,
HGCalParameters&,
const std::string&,
const std::string&,
const std::string&,
const std::string&);
bool build(const cms::DDCompactView*,
HGCalParameters&,
const std::string&,
const std::string&,
const std::string&,
const std::string&,
const std::string&);
bool build(const DDCompactView* cpv,
HGCalParameters& php,
const std::string& name,
const std::string& namew,
const std::string& namec,
const std::string& namet);
bool build(const cms::DDCompactView* cpv,
HGCalParameters& php,
const std::string& name,
const std::string& namew,
const std::string& namec,
const std::string& namet,
const std::string& name2);

private:
void getCellPosition(HGCalParameters& php, int type);
Expand Down
62 changes: 36 additions & 26 deletions Geometry/HGCalCommonData/src/HGCalGeomParameters.cc
Expand Up @@ -263,22 +263,26 @@ void HGCalGeomParameters::loadGeometryHexagon(const DDFilteredView& _fv,
layers, trforms, trformUse, copies, copiesInLayers, wafer2copy, wafers, wafertype, cellsf, cellsc, php);
}

void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
void HGCalGeomParameters::loadGeometryHexagon(const cms::DDCompactView* cpv,
HGCalParameters& php,
const std::string& sdTag1,
const cms::DDCompactView* cpv,
const std::string& sdTag2,
const std::string& sdTag3,
HGCalGeometryMode::WaferMode mode) {
bool dodet(true);
cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume());
std::string attribute = "Volume";
cms::DDSpecParRefs refs;
const cms::DDSpecParRegistry& mypar = cpv->specpars();
mypar.filter(refs, attribute, sdTag1);
fv.mergedSpecifics(refs);
std::map<int, HGCalGeomParameters::layerParameters> layers;
std::vector<HGCalParameters::hgtrform> trforms;
std::vector<bool> trformUse;

while (dodet) {
while (fv.firstChild()) {
const std::vector<double>& pars = fv.parameters();
// Layers first
std::vector<int> copy = fv.history().copyNos;
std::vector<int> copy = fv.copyNos();
int nsiz = (int)(copy.size());
int lay = (nsiz > 0) ? copy[nsiz - 1] : 0;
int zp = (nsiz > 2) ? copy[nsiz - 3] : -1;
Expand All @@ -294,8 +298,8 @@ void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
if (itr == layers.end()) {
double rin(0), rout(0);
if (fv.isA<dd4hep::Polyhedra>()) {
rin = 0.5 * HGCalParameters::k_ScaleFromDD4Hep * (pars[5] + pars[8]);
rout = 0.5 * HGCalParameters::k_ScaleFromDD4Hep * (pars[6] + pars[9]);
rin = 0.5 * HGCalParameters::k_ScaleFromDD4Hep * (pars[4] + pars[7]);
rout = 0.5 * HGCalParameters::k_ScaleFromDD4Hep * (pars[5] + pars[8]);
} else if (fv.isATubeSeg()) {
cms::dd::DDTubs tubeSeg(fv);
rin = HGCalParameters::k_ScaleFromDD4Hep * tubeSeg.rIn();
Expand Down Expand Up @@ -325,7 +329,6 @@ void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
trforms.emplace_back(mytrf);
trformUse.emplace_back(false);
}
dodet = fv.nextSibling();
}

// Then wafers
Expand All @@ -337,7 +340,6 @@ void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
std::vector<int32_t> wafer2copy;
std::vector<HGCalGeomParameters::cellParameters> wafers;
cms::DDFilteredView fv1(cpv->detector(), cpv->detector()->worldVolume());
std::string attribute = "Volume";
cms::DDSpecParRefs ref1;
const cms::DDSpecParRegistry& mypar1 = cpv->specpars();
mypar1.filter(ref1, attribute, sdTag2);
Expand All @@ -347,11 +349,11 @@ void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
edm::LogError("HGCalGeom") << " Attribute " << sdTag2 << " not found but needed.";
throw cms::Exception("DDException") << "Attribute " << sdTag2 << " not found but needed.";
} else {
dodet = true;
bool dodet = true;
std::unordered_set<std::string> names;
while (dodet) {
const std::string name = static_cast<std::string>(fv1.name());
std::vector<int> copy = fv1.history().copyNos;
std::vector<int> copy = fv1.copyNos();
int nsiz = (int)(copy.size());
int wafer = (nsiz > 0) ? copy[nsiz - 1] : 0;
int layer = (nsiz > 1) ? copy[nsiz - 2] : 0;
Expand Down Expand Up @@ -384,13 +386,13 @@ void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
double zv[2], rv;
const std::vector<double>& pars = fv1.parameters();
if (mode == HGCalGeometryMode::Polyhedra) {
zv[0] = pars[4];
zv[1] = pars[7];
rv = pars[6];
zv[0] = pars[3];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These indices seem almost random. Some comments or more descriptive naming would be helpful to understand what is happening.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpedro88 It's on my task list to create a shape class for Polyhedra (and some other shapes) to hide these implementation details. Unfortunately, I probably won't get to it soon. In the interim, we have these details here. Some comments saying that this code will be revised might help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I talked to Ianna about this. May be we should discuss about this in some meeting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianna Please comment on this issue

zv[1] = pars[6];
rv = pars[5];
} else {
zv[0] = pars[4];
zv[1] = pars[7];
rv = pars[6];
zv[0] = pars[2];
zv[1] = pars[8];
rv = pars[3];
}
php.waferR_ = HGCalParameters::k_ScaleFromDD4HepToG4 * rv / std::cos(30._deg);
php.waferSize_ = HGCalParameters::k_ScaleFromDD4Hep * rv;
Expand All @@ -412,7 +414,7 @@ void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
}
}
}
dodet = fv1.nextSibling();
dodet = fv1.firstChild();
}
}

Expand All @@ -429,10 +431,10 @@ void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
edm::LogError("HGCalGeom") << " Attribute " << sdTag3 << " not found but needed.";
throw cms::Exception("DDException") << "Attribute " << sdTag3 << " not found but needed.";
} else {
dodet = true;
bool dodet = true;
while (dodet) {
const std::string name = static_cast<std::string>(fv2.name());
std::vector<int> copy = fv2.history().copyNos;
std::vector<int> copy = fv2.copyNos();
int nsiz = (int)(copy.size());
int cellx = (nsiz > 0) ? copy[nsiz - 1] : 0;
int wafer = (nsiz > 1) ? copy[nsiz - 2] : 0;
Expand Down Expand Up @@ -478,7 +480,7 @@ void HGCalGeomParameters::loadGeometryHexagon(cms::DDFilteredView& fv,
}
}
}
dodet = fv2.nextSibling();
dodet = fv2.firstChild();
}
}

Expand Down Expand Up @@ -736,14 +738,23 @@ void HGCalGeomParameters::loadGeometryHexagon8(const DDFilteredView& _fv, HGCalP
loadGeometryHexagon8(layers, trforms, firstLayer, php);
}

void HGCalGeomParameters::loadGeometryHexagon8(cms::DDFilteredView& fv, HGCalParameters& php, int firstLayer) {
bool dodet(true);
void HGCalGeomParameters::loadGeometryHexagon8(const cms::DDCompactView* cpv,
HGCalParameters& php,
const std::string& sdTag1,
int firstLayer) {
cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume());
std::string attribute = "Volume";
cms::DDSpecParRefs refs;
const cms::DDSpecParRegistry& mypar = cpv->specpars();
mypar.filter(refs, attribute, sdTag1);
fv.mergedSpecifics(refs);
bool dodet = fv.firstChild();
std::map<int, HGCalGeomParameters::layerParameters> layers;
std::map<std::pair<int, int>, HGCalParameters::hgtrform> trforms;
int levelTop = 3 + std::max(php.levelT_[0], php.levelT_[1]);
while (dodet) {
// Layers first
std::vector<int> copy = fv.history().copyNos;
std::vector<int> copy = fv.copyNos();
int nsiz = static_cast<int>(copy.size());
int lay = (nsiz > levelTop) ? copy[nsiz - 4] : copy[nsiz - 1];
int zside = (nsiz > php.levelZSide_) ? copy[php.levelZSide_] : -1;
Expand Down Expand Up @@ -786,7 +797,7 @@ void HGCalGeomParameters::loadGeometryHexagon8(cms::DDFilteredView& fv, HGCalPar
trforms[std::make_pair(lay, zside)] = mytrf;
}
}
dodet = fv.nextSibling();
dodet = fv.firstChild();
}

loadGeometryHexagon8(layers, trforms, firstLayer, php);
Expand Down Expand Up @@ -894,7 +905,6 @@ void HGCalGeomParameters::loadSpecParsHexagon(const DDFilteredView& fv,

void HGCalGeomParameters::loadSpecParsHexagon(const cms::DDFilteredView& fv,
HGCalParameters& php,
const cms::DDCompactView* cpv,
const std::string& sdTag1,
const std::string& sdTag2,
const std::string& sdTag3,
Expand Down