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

gem geometry to DB writer #21307

Merged
merged 6 commits into from Nov 25, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion CondTools/Geometry/test/me0geometrywriter.py
Expand Up @@ -2,7 +2,7 @@

process = cms.Process("ME0GeometryWriter")
process.load('CondCore.CondDB.CondDB_cfi')
process.load('Configuration.Geometry.GeometryExtended2023D3_cff')
process.load('Configuration.Geometry.GeometryExtended2023D20_cff')
process.load('Geometry.MuonNumbering.muonNumberingInitialization_cfi')

process.source = cms.Source("EmptyIOVSource",
Expand Down
229 changes: 159 additions & 70 deletions Geometry/GEMGeometryBuilder/src/GEMGeometryParsFromDD.cc
Expand Up @@ -5,10 +5,10 @@
#include "Geometry/GEMGeometryBuilder/src/GEMGeometryParsFromDD.h"
#include "DataFormats/MuonDetId/interface/GEMDetId.h"

#include <CondFormats/GeometryObjects/interface/RecoIdealGeometry.h>
#include <DetectorDescription/Core/interface/DDFilter.h>
#include <DetectorDescription/Core/interface/DDFilteredView.h>
#include <DetectorDescription/Core/interface/DDSolid.h>
#include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
#include "DetectorDescription/Core/interface/DDFilter.h"
#include "DetectorDescription/Core/interface/DDFilteredView.h"
#include "DetectorDescription/Core/interface/DDSolid.h"

#include "Geometry/MuonNumbering/interface/MuonDDDNumbering.h"
#include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
Expand All @@ -29,86 +29,175 @@ GEMGeometryParsFromDD::~GEMGeometryParsFromDD()

void
GEMGeometryParsFromDD::build(const DDCompactView* cview,
const MuonDDDConstants& muonConstants, RecoIdealGeometry& rgeo )
const MuonDDDConstants& muonConstants, RecoIdealGeometry& rgeo )
{
std::string attribute = "ReadOutName"; // could come from .orcarc
std::string value = "MuonGEMHits"; // could come from .orcarc
std::string attribute = "MuStructure";
std::string value = "MuonEndCapGEM";

// Asking only for the MuonGEM's
DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
DDFilteredView fview(*cview,filter);
DDFilteredView fv(*cview,filter);

this->buildGeometry(fv, muonConstants, rgeo);
}

this->buildGeometry(fview, muonConstants, rgeo);
void
GEMGeometryParsFromDD::buildGeometry(DDFilteredView& fv,
const MuonDDDConstants& muonConstants,
RecoIdealGeometry& rgeo)
{
LogDebug("GEMGeometryParsFromDD") <<"Building the geometry service";
LogDebug("GEMGeometryParsFromDD") << "About to run through the GEM structure\n"
<<" First logical part "
<<fv.logicalPart().name().name();

MuonDDDNumbering muonDDDNumbering(muonConstants);
GEMNumberingScheme gemNumbering(muonConstants);

bool doSuper = fv.firstChild();
LogDebug("GEMGeometryParsFromDD") << "doSuperChamber = " << doSuper;
// loop over superchambers
while (doSuper){

// getting chamber id from eta partitions
fv.firstChild();fv.firstChild();
GEMDetId detIdCh = GEMDetId(gemNumbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
// back to chambers
fv.parent();fv.parent();

// currently there is no superchamber in the geometry
// only 2 chambers are present separated by a gap.
// making superchamber out of the first chamber layer including the gap between chambers
if (detIdCh.layer() == 1){// only make superChambers when doing layer 1
buildSuperChamber(fv, detIdCh, rgeo);
}
buildChamber(fv, detIdCh, rgeo);

// loop over chambers
// only 1 chamber
bool doChambers = fv.firstChild();
while (doChambers){

// loop over GEMEtaPartitions
bool doEtaPart = fv.firstChild();
while (doEtaPart){

GEMDetId detId = GEMDetId(gemNumbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
buildEtaPartition(fv, detId, rgeo);

doEtaPart = fv.nextSibling();
}
fv.parent();
doChambers = fv.nextSibling();
}
fv.parent();
doSuper = fv.nextSibling();
}
}

void
GEMGeometryParsFromDD::buildGeometry(DDFilteredView& fview, const MuonDDDConstants& muonConstants, RecoIdealGeometry& rgeo)
GEMGeometryParsFromDD::buildSuperChamber(DDFilteredView& fv, GEMDetId detId, RecoIdealGeometry& rgeo)
{
LogDebug("GEMGeometryParsFromDD") << "buildSuperChamber "<<fv.logicalPart().name().name()
<<" "<< detId <<std::endl;

DDBooleanSolid solid = (DDBooleanSolid)(fv.logicalPart().solid());
std::vector<double> dpar = solid.solidA().parameters();

double dy = dpar[0]/cm;//length is along local Y
double dz = dpar[3]/cm;// thickness is long local Z
double dx1= dpar[4]/cm;// bottom width is along local X
double dx2= dpar[8]/cm;// top width is along local X
dpar = solid.solidB().parameters();
dz += dpar[3]/cm;// chamber thickness
dz *=2; // 2 chambers in superchamber
dz += 2.105;// gap between chambers

GEMDetId gemid = detId.superChamberId();

std::vector<double> pars{dx1, dx2, dy, dz};
std::vector<double> vtra = getTranslation(fv);
std::vector<double> vrot = getRotation(fv);

bool doSubDets = fview.firstChild();
LogDebug("GEMGeometryParsFromDD") << "dimension dx1 "<< dx1 << ", dx2 "<< dx2 << ", dy "<< dy << ", dz "<< dz;
rgeo.insert(gemid.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
}

while (doSubDets){
void
GEMGeometryParsFromDD::buildChamber(DDFilteredView& fv, GEMDetId detId, RecoIdealGeometry& rgeo)
{
LogDebug("GEMGeometryParsFromDD") << "buildChamber "<<fv.logicalPart().name().name()
<<" "<< detId <<std::endl;

DDBooleanSolid solid = (DDBooleanSolid)(fv.logicalPart().solid());
std::vector<double> dpar = solid.solidA().parameters();

double dy = dpar[0]/cm;//length is along local Y
double dz = dpar[3]/cm;// thickness is long local Z
double dx1= dpar[4]/cm;// bottom width is along local X
double dx2= dpar[8]/cm;// top width is along local X
dpar = solid.solidB().parameters();
dz += dpar[3]/cm;// chamber thickness

GEMDetId gemid = detId.chamberId();

std::vector<double> pars{dx1, dx2, dy, dz};
std::vector<double> vtra = getTranslation(fv);
std::vector<double> vrot = getRotation(fv);

LogDebug("GEMGeometryParsFromDD") << "dimension dx1 "<< dx1 << ", dx2 "<< dx2 << ", dy "<< dy << ", dz "<< dz;
rgeo.insert(gemid.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
}

// Get the Base Muon Number
MuonDDDNumbering mdddnum(muonConstants);
MuonBaseNumber mbn = mdddnum.geoHistoryToBaseNumber(fview.geoHistory());
void
GEMGeometryParsFromDD::buildEtaPartition(DDFilteredView& fv, GEMDetId detId, RecoIdealGeometry& rgeo)
{
LogDebug("GEMGeometryParsFromDD") << "buildEtaPartition "<<fv.logicalPart().name().name()
<<" "<< detId <<std::endl;

// EtaPartition specific parameter (nstrips and npads)
DDValue numbOfStrips("nStrips");
DDValue numbOfPads("nPads");
std::vector<const DDsvalues_type* > specs(fv.specifics());
std::vector<const DDsvalues_type* >::iterator is = specs.begin();
double nStrips = 0., nPads = 0.;
for (;is != specs.end(); is++){
if (DDfetch( *is, numbOfStrips)) nStrips = numbOfStrips.doubles()[0];
if (DDfetch( *is, numbOfPads)) nPads = numbOfPads.doubles()[0];
}
LogDebug("GEMGeometryParsFromDD")
<< ((nStrips == 0. ) ? ("No nStrips found!!") : ("Number of strips: " + std::to_string(nStrips)));
LogDebug("GEMGeometryParsFromDD")
<< ((nPads == 0. ) ? ("No nPads found!!") : ("Number of pads: " + std::to_string(nPads)));

// EtaPartition specific parameter (size)
std::vector<double> dpar = fv.logicalPart().solid().parameters();

// Get the The GEM det Id
GEMNumberingScheme gemnum(muonConstants);
int detid = 0;
double dy = dpar[0]/cm;//length is along local Y
double dz = dpar[3]/cm;//0.4/cm;// thickness is long local Z
double dx1= dpar[4]/cm;// bottom width is along local X
double dx2= dpar[8]/cm;// top width is along local X

detid = gemnum.baseNumberToUnitNumber(mbn);
GEMDetId gemid(detid);
std::vector<double> pars{dx1, dx2, dy, dz, nStrips, nPads};
std::vector<double> vtra = getTranslation(fv);
std::vector<double> vrot = getRotation(fv);

LogDebug("GEMGeometryParsFromDD") << "dimension dx1 "<< dx1 << ", dx2 "<< dx2 << ", dy "<< dy << ", dz "<< dz;
rgeo.insert(detId.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
}

DDValue numbOfStrips("nStrips");
DDValue numbOfPads("nPads");
std::vector<double> GEMGeometryParsFromDD::getTranslation(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.

this and getRotation should return a std::array (or an actual vector/matrix object that would probably be more appropriate..)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RecoIdealGeometry wants std::vectors. If I make this into std::array, I would need to do an std::array to std::vector conversion.

{
const DDTranslation& tran = fv.translation();
return {tran.x(), tran.y(), tran.z()};
}

std::vector<const DDsvalues_type* > specs(fview.specifics());
std::vector<const DDsvalues_type* >::iterator is = specs.begin();
double nStrips = 0., nPads = 0.;
for (;is!=specs.end(); is++)
{
if (DDfetch( *is, numbOfStrips)) nStrips = numbOfStrips.doubles()[0];
if (DDfetch( *is, numbOfPads)) nPads = numbOfPads.doubles()[0];
}
LogDebug("GEMGeometryBuilderFromDDD") << ((nStrips == 0. ) ? ("No nStrips found!!") : (""));
LogDebug("GEMGeometryBuilderFromDDD") << ((nPads == 0. ) ? ("No nPads found!!") : (""));
//std::cout <<"# strips, pads: "<< nStrips<<", "<<nPads<<std::endl;

std::vector<double> dpar = fview.logicalPart().solid().parameters();

std::vector<std::string> strpars;
std::string name = fview.logicalPart().name().name();
strpars.emplace_back(name);
DDTranslation tran = fview.translation();

DDRotationMatrix rota = fview.rotation();//.Inverse();
DD3Vector x, y, z;
rota.GetComponents(x,y,z);
std::vector<double> pars;
pars.emplace_back(dpar[4]); //b/2;
pars.emplace_back(dpar[8]); //B/2;
pars.emplace_back(dpar[0]); //h/2;
pars.emplace_back(0.4); // XXX: what is that? hardcoded thickness?
pars.emplace_back(nStrips);
pars.emplace_back(nPads);

std::vector<double> vtra(3);
std::vector<double> vrot(9);
vtra[0]=(float) 1.0 * (tran.x());
vtra[1]=(float) 1.0 * (tran.y());
vtra[2]=(float) 1.0 * (tran.z());
vrot[0]=(float) 1.0 * x.X();
vrot[1]=(float) 1.0 * x.Y();
vrot[2]=(float) 1.0 * x.Z();
vrot[3]=(float) 1.0 * y.X();
vrot[4]=(float) 1.0 * y.Y();
vrot[5]=(float) 1.0 * y.Z();
vrot[6]=(float) 1.0 * z.X();
vrot[7]=(float) 1.0 * z.Y();
vrot[8]=(float) 1.0 * z.Z();
rgeo.insert(gemid.rawId(), vtra, vrot, pars, strpars);
doSubDets = fview.nextSibling(); // go to next layer
}

std::vector<double> GEMGeometryParsFromDD::getRotation(DDFilteredView& fv)
{
const DDRotationMatrix& rota = fv.rotation();//.Inverse();
DD3Vector x, y, z;
rota.GetComponents(x,y,z);
return { x.X(), x.Y(), x.Z(),
y.X(), y.Y(), y.Z(),
z.X(), z.Y(), z.Z() };
}
11 changes: 9 additions & 2 deletions Geometry/GEMGeometryBuilder/src/GEMGeometryParsFromDD.h
Expand Up @@ -9,13 +9,16 @@
*/

#include <string>
#include <vector>
#include <map>
#include <list>

class DDCompactView;
class DDFilteredView;
class MuonDDDConstants;
class RecoIdealGeometry;
class GEMDetId;

class GEMGeometryParsFromDD
{
public:
Expand All @@ -28,13 +31,17 @@ class GEMGeometryParsFromDD
const MuonDDDConstants& muonConstants,
RecoIdealGeometry& rgeo);


private:
void buildGeometry(DDFilteredView& fview,
const MuonDDDConstants& muonConstants,
RecoIdealGeometry& rgeo);

void buildSuperChamber(DDFilteredView& fv, GEMDetId detId, RecoIdealGeometry& rgeo);
void buildChamber(DDFilteredView& fv, GEMDetId detId, RecoIdealGeometry& rgeo);
void buildEtaPartition(DDFilteredView& fv, GEMDetId detId, RecoIdealGeometry& rgeo);

std::vector<double> getTranslation(DDFilteredView& fv);
std::vector<double> getRotation(DDFilteredView& fv);

};

#endif