|
| 1 | +# Convert your first model |
| 2 | + |
| 3 | +Rather than start on your own detector, it is worth converting something small and known-good first, |
| 4 | +so that anything odd later is clearly your model and not your installation. A toy excavator arm is |
| 5 | +committed to the repository for exactly this purpose: |
| 6 | + |
| 7 | +```text |
| 8 | +$O2_ROOT/share/CADSupport/examples/ExcavatorArm.step # 13 leaf solids, ~500 kB |
| 9 | +``` |
| 10 | + |
| 11 | +It converts in seconds and is varied enough to be interesting: the hydraulic rams and pivot pins are |
| 12 | +plain cylinders, the boom and stick are machined bodies full of concave features, and the bucket has |
| 13 | +a torus in it. Run the converter over it, asking for all three representations at once — we come back |
| 14 | +to what those are in the next section: |
| 15 | + |
| 16 | +```bash |
| 17 | +mkdir -p cad_out/excavator |
| 18 | +o2-cad-to-tgeo \ |
| 19 | + $O2_ROOT/share/CADSupport/examples/ExcavatorArm.step \ |
| 20 | + --output-folder cad_out/excavator \ |
| 21 | + -o geom.C \ |
| 22 | + --step-unit auto \ |
| 23 | + --csg auto --exact-surfaces auto --mesh --mesh-prec 0.05 |
| 24 | +``` |
| 25 | + |
| 26 | +That takes about thirteen seconds. Along the way the converter prints three lines worth reading on |
| 27 | +*every* run, because each one catches a different common mistake: |
| 28 | + |
| 29 | +```text |
| 30 | +Detected STEP length unit: mm (scale to cm = 0.1) |
| 31 | +Placement check: 13 leaf placement(s), all at distinct world transforms. |
| 32 | +Emitting 13/13 logical volumes as exact O2BVHSurfaceSolid |
| 33 | +``` |
| 34 | + |
| 35 | +The unit line bites hardest. TGeo works in centimetres and most CAD systems export millimetres, so a |
| 36 | +silent unit error gives you a detector ten times too big and a simulation that still looks almost |
| 37 | +plausible. `--step-unit auto` reads the declaration in the file; pass `--step-unit mm` explicitly when |
| 38 | +the file declares something you do not believe. The placement line then tells you whether two leaves |
| 39 | +landed on the same world transform, which almost always means a duplicated part in the CAD model |
| 40 | +rather than a real coincidence. |
| 41 | + |
| 42 | +Finally the converter prints what it decided for each part, ending in a one-line summary: |
| 43 | + |
| 44 | +```text |
| 45 | +=== REPRESENTATION CASCADE (per leaf solid) === |
| 46 | + volume carried by evidence |
| 47 | + BasePin csg TGeoTube(rmin=0, rmax=1, dz=5) [tier1-tube], dV_sym=0 cm^3 |
| 48 | + Base surface declined CSG: 7 axis clusters: beyond the recogniser's scope ... |
| 49 | + BoomCylinderOuter csg TGeoTube(0.6,1,7.991) u TGeoTube(0.7,1.5,1.5), dV_sym=0 cm^3 |
| 50 | + ... |
| 51 | + tiers: CSG 7, exact surfaces 6, tessellated 0 (of 13 leaf solids) |
| 52 | +``` |
| 53 | + |
| 54 | +Seven parts came out as ordinary ROOT shapes, six as exact surface solids, and none had to fall back |
| 55 | +to an approximate mesh. The `dV_sym=0` is the reassuring part: it is the symmetric-difference volume |
| 56 | +between what was emitted and the original CAD solid, so zero means the conversion is exact rather |
| 57 | +than merely close. |
| 58 | + |
| 59 | +## Look at what you made |
| 60 | + |
| 61 | +Numbers in a terminal are no substitute for seeing the thing. The macro can build the geometry and |
| 62 | +write it out as an ordinary ROOT file: |
| 63 | + |
| 64 | +```bash |
| 65 | +cd cad_out/excavator |
| 66 | +root -l -b -q -e '.L geom.C' -e 'build_and_export("geom.root");' |
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +*The converted model, drawn by casting one ray per pixel through the TGeo navigator — so this is the |
| 72 | +geometry as the transport sees it, not a separate preview mesh.* |
| 73 | + |
| 74 | +The simplest interactive way to inspect the result is ROOT's own web display, which renders the |
| 75 | +geometry with JSROOT in your browser and lets you rotate it, hide volumes and click through the tree: |
| 76 | + |
| 77 | +```bash |
| 78 | +root --web geom.root |
| 79 | +``` |
| 80 | + |
| 81 | +If you are on a remote machine where opening a browser is awkward, export the geometry as a JSROOT |
| 82 | +document instead and open that file locally. It is a self-contained 32 kB for this model, and can be |
| 83 | +dragged straight onto [root.cern/js](https://root.cern/js/): |
| 84 | + |
| 85 | +```bash |
| 86 | +root -l -b -q -e 'TGeoManager::Import("geom.root");' \ |
| 87 | + -e 'TBufferJSON::ExportToFile("excavator.json.gz", gGeoManager);' |
| 88 | +``` |
| 89 | + |
| 90 | +Spend a minute here. Turning the model around is the fastest way to notice that a subassembly is |
| 91 | +missing, that something sits at the wrong scale, or that the part you care about was quietly filtered |
| 92 | +out. |
0 commit comments