31 #include "TGeoManager.h" 32 #include "TGeoMatrix.h" 33 #include "TGeoCompositeShape.h" 37 #include "TGeoBoolNode.h" 43 #include "Math/GenVector/RotationX.h" 45 #include "CLHEP/Units/GlobalSystemOfUnits.h" 59 : m_level(pset.getUntrackedParameter<
int>(
"level", 10)),
60 m_verbose(pset.getUntrackedParameter<
bool>(
"verbose",
false)),
78 printf(
"TGeoFromDddService::postBeginRun\n");
84 printf(
"TGeoFromDddService::postEndRun\n");
100 edm::LogError(
"TGeoFromDddService") <<
"getGeoManager() -- EventSetup not present.\n";
104 edm::LogError(
"TGeoFromDddService") <<
"getGeoManager() -- creation failed.\n";
119 iRot.GetComponents(elements);
121 r.SetMatrix(elements);
123 TGeoTranslation
t(iTrans.x() / cm, iTrans.y() / cm, iTrans.z() / cm);
125 return new TGeoCombiTrans(
t, r);
143 TGeoManager* geo_mgr =
new TGeoManager(
"cmsGeo",
"CMS Detector");
145 if (gGeoIdentity ==
nullptr) {
146 gGeoIdentity =
new TGeoIdentity(
"Identity");
149 std::cout <<
"about to initialize the DDCompactView walker" << std::endl;
151 auto info = walker.current();
157 TGeoVolume* top =
createVolume(info.first.name().fullname(), info.first.solid(), info.first.material());
158 if (top ==
nullptr) {
162 geo_mgr->SetTopVolume(top);
164 top->SetVisibility(kFALSE);
165 top->SetLineColor(kBlue);
167 std::vector<TGeoVolume*> parentStack;
168 parentStack.push_back(top);
170 if (!walker.firstChild()) {
178 for (
unsigned int i = 0;
i < parentStack.size(); ++
i) {
181 std::cout << info.first.name() <<
" " << info.second->copyno() <<
" " 185 bool childAlreadyExists = (
nullptr !=
nameToVolume_[info.first.name().fullname()]);
186 TGeoVolume*
child =
createVolume(info.first.name().fullname(), info.first.solid(), info.first.material());
187 if (
nullptr != child && info.second !=
nullptr) {
188 parentStack.back()->AddNode(
189 child, info.second->copyno(),
createPlacement(info.second->rotation(), info.second->translation()));
190 child->SetLineColor(kBlue);
192 if (info.second ==
nullptr) {
196 if (
nullptr == child || childAlreadyExists || level ==
int(parentStack.size())) {
197 if (
nullptr != child) {
198 child->SetLineColor(kRed);
201 if (!walker.nextSibling()) {
202 while (walker.parent()) {
203 parentStack.pop_back();
204 if (walker.nextSibling()) {
210 if (walker.firstChild()) {
211 parentStack.push_back(child);
213 if (!walker.nextSibling()) {
214 while (walker.parent()) {
215 parentStack.pop_back();
216 if (walker.nextSibling()) {
223 }
while (!parentStack.empty());
225 geo_mgr->CloseGeometry();
227 geo_mgr->DefaultColors();
239 if (rSolid ==
nullptr) {
242 switch (iSolid.
shape()) {
244 rSolid =
new TGeoBBox(iName.c_str(), params[0] / cm, params[1] / cm, params[2] / cm);
247 rSolid =
new TGeoConeSeg(iName.c_str(),
254 params[6] / deg + params[5] / deg);
258 rSolid =
new TGeoTubeSeg(iName.c_str(),
263 params[3] / deg + params[4] / deg);
267 rSolid =
new TGeoCtub(iName.c_str(),
272 params[3] / deg + params[4] / deg,
281 rSolid =
new TGeoTrap(iName.c_str(),
295 rSolid =
new TGeoPcon(iName.c_str(), params[0] / deg, params[1] / deg, (params.size() - 2) / 3);
297 std::vector<double>
temp(params.size() + 1);
298 temp.reserve(params.size() + 1);
299 temp[0] = params[0] / deg;
300 temp[1] = params[1] / deg;
301 temp[2] = (params.size() - 2) / 3;
302 std::copy(params.begin() + 2, params.end(),
temp.begin() + 3);
303 for (std::vector<double>::iterator it =
temp.begin() + 3; it !=
temp.end(); ++it) {
306 rSolid->SetDimensions(&(*(
temp.begin())));
310 rSolid =
new TGeoPgon(
311 iName.c_str(), params[1] / deg, params[2] / deg,
static_cast<int>(params[0]), (params.size() - 3) / 3);
313 std::vector<double>
temp(params.size() + 1);
314 temp[0] = params[1] / deg;
315 temp[1] = params[2] / deg;
317 temp[3] = (params.size() - 3) / 3;
318 std::copy(params.begin() + 3, params.end(), temp.begin() + 4);
319 for (std::vector<double>::iterator it = temp.begin() + 4; it != temp.end(); ++it) {
322 rSolid->SetDimensions(&(*(temp.begin())));
327 std::vector<double>
x = extrPgon.
xVec();
328 std::transform(x.begin(), x.end(), x.begin(), [](
double d) {
return d / cm; });
329 std::vector<double>
y = extrPgon.
yVec();
330 std::transform(y.begin(), y.end(), y.begin(), [](
double d) {
return d / cm; });
331 std::vector<double>
z = extrPgon.
zVec();
332 std::vector<double> zx = extrPgon.
zxVec();
333 std::vector<double> zy = extrPgon.
zyVec();
334 std::vector<double> zscale = extrPgon.
zscaleVec();
336 TGeoXtru* mySolid =
new TGeoXtru(z.size());
337 mySolid->DefinePolygon(x.size(), &(*x.begin()), &(*y.begin()));
338 for (
size_t i = 0;
i < params[0]; ++
i) {
339 mySolid->DefineSection(
i, z[
i] / cm, zx[
i] / cm, zy[
i] / cm, zscale[
i]);
356 double openingAngle = 2.0 * asin(x / r);
357 double h = pt.
y1() < pt.
y2() ? pt.
y2() : pt.
y1();
359 double displacement = 0;
364 startPhi = 270. - openingAngle / deg / 2.0;
367 startPhi = 90. - openingAngle / deg / 2.;
369 std::unique_ptr<TGeoShape> trap(
new TGeoTrd2(
371 std::unique_ptr<TGeoShape> tubs(
372 new TGeoTubeSeg(pt.
name().
name().c_str(), 0., r / cm, h / cm, startPhi, openingAngle));
373 TGeoSubtraction* sub =
new TGeoSubtraction(
375 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
382 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
387 if (
nullptr != left.get() &&
nullptr != right.get()) {
388 TGeoSubtraction* sub =
389 new TGeoSubtraction(left.release(),
393 rSolid =
new TGeoCompositeShape(iName.c_str(), sub);
400 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
407 if (
nullptr != left.get() &&
nullptr != right.get()) {
408 TGeoUnion* boolS =
new TGeoUnion(left.release(),
412 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
419 throw cms::Exception(
"GeomConvert") <<
"conversion to DDBooleanSolid failed";
424 if (
nullptr != left.get() &&
nullptr != right.get()) {
425 TGeoIntersection* boolS =
426 new TGeoIntersection(left.release(),
430 rSolid =
new TGeoCompositeShape(iName.c_str(), boolS);
439 if (rSolid ==
nullptr) {
440 std::cerr <<
"COULD NOT MAKE " << iName << std::endl;
453 if (geo_med ==
nullptr) {
455 geo_med =
new TGeoMedium(mat_name.c_str(), 0, geo_mat);
459 v =
new TGeoVolume(iName.c_str(), solid, geo_med);
470 if (mat ==
nullptr) {
478 mat =
new TGeoMaterial(mat_name.c_str(), iMaterial.
a() * mole /
g, iMaterial.
z(), iMaterial.
density() * cm3 /
g);
void watchPostBeginRun(PostBeginRun::slot_type const &iSlot)
std::map< std::string, TGeoMaterial * > nameToMaterial_
double a() const
returns the atomic mass
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
TGeoManager * m_geoManager
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
double y2(void) const
half length along y on +z
const edm::EventSetup * m_eventSetup
DDMaterial is used to define and access material information.
TGeoVolume * createVolume(const std::string &iName, const DDSolid &iSolid, const DDMaterial &iMaterial)
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
std::vector< double > yVec(void) const
std::vector< double > zyVec(void) const
DDTranslation translation(void) const
TGeoCombiTrans * createPlacement(const Rotation3D &iRot, const Position &iTrans)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
A DDSolid represents the shape of a part.
double y1(void) const
half length along y on -z
std::map< std::string, TGeoVolume * > nameToVolume_
DDSolid solidB(void) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
std::vector< double > xVec(void) const
double z() const
retruns the atomic number
static const char *const name(DDSolidShape s)
DDRotation rotation(void) const
bool atMinusZ(void) const
true, if cut-out or rounding is on the -z side
double halfZ(void) const
half of the z-Axis
const std::string fullname() const
FractionV::value_type constituent(int i) const
returns the i-th compound material and its fraction-mass
DDSolidShape shape(void) const
The type of the solid.
std::map< std::string, TGeoMedium * > nameToMedium_
void postBeginRun(const edm::Run &, const edm::EventSetup &)
DDSolid solidA(void) const
TGeoFromDddService(const edm::ParameterSet &, edm::ActivityRegistry &)
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
std::vector< double > zVec(void) const
std::vector< double > zxVec(void) const
double density() const
returns the density
virtual ~TGeoFromDddService()
TGeoMaterial * createMaterial(const DDMaterial &iMaterial)
int noOfConstituents() const
returns the number of compound materials or 0 for elementary materials
TGeoManager * createManager(int level)
std::map< std::string, TGeoShape * > nameToShape_
const DDLogicalPart & root() const
returns the DDLogicalPart representing the root of the geometrical hierarchy
void watchPostEndRun(PostEndRun::slot_type const &iSlot)
double x2(void) const
half length along x on +z
std::vector< double > zscaleVec(void) const
value_type current() const
const std::string & name() const
Returns the name.
TGeoManager * getGeoManager()
void postEndRun(const edm::Run &, const edm::EventSetup &)
TGeoShape * createShape(const std::string &iName, const DDSolid &iSolid)
double x1(void) const
half length along x on -z
DDRotationMatrix & matrix()
double radius(void) const
radius of the cut-out (neg.) or rounding (pos.)