1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
#include <stdlib.h>
#include "../benchmark/ArgParser.h"
#include "ShapeTester.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TView.h"
#include "TPolyMarker3D.h"
#include "TPolyLine3D.h"
#include "VecGeom/management/RootGeoManager.h"
#include "VecGeom/volumes/LogicalVolume.h"
#include "VecGeom/management/GeoManager.h"
#include "TGeoManager.h"
#include "TGeoVolume.h"
using namespace vecgeom;
// debugging any available shape (logical volume) found in a ROOT file
// usage: shape_debugFromROOTFile detector.root logicalvolumename x y z vx vy vz
// logicalvolumename should not contain trailing pointer information
Precision runTester(VPlacedVolume const *shape, Vector3D<Precision> const &point, Vector3D<Precision> const &dir)
{
const char *sInside[3] = {"kInside", "kSurface", "kOutside"};
Precision distance;
auto inside = shape->Inside(point);
std::cout << "Inside = " << sInside[inside - 1] << std::endl;
distance = shape->SafetyToIn(point);
if (distance < kHalfTolerance) distance = 0.0;
std::cout << "SafetyFromOutside = " << distance << std::endl;
distance = shape->SafetyToOut(point);
if (distance < kHalfTolerance) distance = 0.0;
std::cout << "SafetyFromInside = " << distance << std::endl;
distance = shape->DistanceToIn(point, dir);
if (distance < kHalfTolerance) distance = 0.0;
std::cout << "DistanceToIn = " << distance << std::endl;
distance = shape->DistanceToOut(point, dir);
if (distance < kHalfTolerance) distance = 0.0;
std::cout << "DistanceToOut = " << distance << std::endl;
if (shape) delete shape;
return distance;
}
void DrawArrow(Vector3D<Precision> const &point, Vector3D<Precision> const &dir, Precision size, Precision dout,
short color)
{
TPolyLine3D *pl = new TPolyLine3D(2);
pl->SetLineColor(color);
pl->SetNextPoint(point[0], point[1], point[2]);
pl->SetNextPoint(point[0] + size * dir[0], point[1] + size * dir[1], point[2] + size * dir[2]);
TPolyMarker3D *pm1 = new TPolyMarker3D(2);
TPolyMarker3D *pm2 = new TPolyMarker3D(1);
pm1->SetNextPoint(point[0], point[1], point[2]);
pm1->SetNextPoint(point[0] + dout * dir[0], point[1] + dout * dir[1], point[2] + dout * dir[2]);
pm2->SetNextPoint(point[0] + size * dir[0], point[1] + size * dir[1], point[2] + size * dir[2]);
pm1->SetMarkerColor(2);
pm2->SetMarkerColor(color);
pm1->SetMarkerStyle(6);
pm2->SetMarkerStyle(26);
pm2->SetMarkerSize(0.4);
pl->Draw();
pm1->Draw();
pm2->Draw();
}
TGeoNode *FindDaughter(TGeoVolume *vol, std::string &name, int &index)
{
int nd = vol->GetNdaughters();
TGeoNode *found = nullptr;
for (int i = 0; i < nd; ++i) {
TGeoNode *node = vol->GetNode(i);
if (name == node->GetVolume()->GetName()) {
found = node;
index = i;
found->GetVolume()->SetVisibility(true);
found->GetVolume()->SetTransparency(0);
found->GetVolume()->SetLineColor(kRed);
break;
}
}
if (found) {
for (int i = 0; i < nd; ++i) {
if (vol->GetNode(i) != found) vol->GetNode(i)->GetVolume()->SetVisibility(false);
}
}
return found;
}
int main(int argc, char *argv[])
{
if (argc < 9) {
std::cerr << "***** Error: need to give root geometry file, logical volume name. point and direction coordinates\n";
std::cerr << "Ex: ./shape_testFromROOTFile ExN03.root mother daughter 1.3 2.5 3.6 0 0 1\n";
exit(1);
}
TGeoManager::Import(argv[1]);
if (!gGeoManager) return 1;
std::string testvolume(argv[2]);
std::string testdaughter(argv[3]);
// Local point/direction (mm)
double point[3];
point[0] = 0.1 * atof(argv[4]);
point[1] = 0.1 * atof(argv[5]);
point[2] = 0.1 * atof(argv[6]);
double lpoint[3];
memcpy(lpoint, point, 3 * sizeof(double));
double direction[3];
direction[0] = atof(argv[7]);
direction[1] = atof(argv[8]);
direction[2] = atof(argv[9]);
double ldir[3];
memcpy(ldir, direction, 3 * sizeof(double));
bool daughter = false;
if (testdaughter != "void") daughter = true;
int found = 0;
TGeoVolume *foundvolume = NULL;
TGeoVolume *founddaughter = NULL;
// now try to find shape with logical volume name given on the command line
TObjArray *vlist = gGeoManager->GetListOfVolumes();
for (auto i = 0; i < vlist->GetEntries(); ++i) {
TGeoVolume *vol = reinterpret_cast<TGeoVolume *>(vlist->At(i));
std::string fullname(vol->GetName());
std::size_t founds = fullname.compare(testvolume);
if (founds == 0) {
found++;
foundvolume = vol;
std::cerr << "found matching volume " << fullname << " of type " << vol->GetShape()->ClassName() << "\n";
}
}
std::cerr << "volume found " << found << " times \n";
if (!foundvolume) {
std::cerr << "Cannot find volume: " << testvolume << std::endl;
return 1;
}
foundvolume->GetShape()->InspectShape();
int index = -1;
if (daughter) {
TGeoNode *dnode = FindDaughter(foundvolume, testdaughter, index);
if (!dnode) {
std::cerr << "Cannot find daughter " << testdaughter << " of volume " << testvolume << std::endl;
return 1;
}
founddaughter = dnode->GetVolume();
std::cerr << "daughter found\n" << std::endl;
founddaughter->GetShape()->InspectShape();
dnode->GetMatrix()->MasterToLocal(point, lpoint);
dnode->GetMatrix()->MasterToLocalVect(direction, ldir);
}
/*
Precision master[3] = {-70.37002915950117,-193.7782403798211,-382.7815168187679};
Precision masterdir[3] = {0.9910804931325202, 0.06730730580739153, 0.1150181842890534};
TGeoNode *node = gGeoManager->FindNode(master[0], master[1], master[2]);
if (node && (node->GetVolume() == foundvolume)) {
std::cout << " == Path is correct\n";
if (daughter) gGeoManager->CdDown(index);
std::cout << "touchable: " << gGeoManager->GetPath() << std::endl;
gGeoManager->GetCurrentMatrix()->MasterToLocal(master, lpoint);
gGeoManager->GetCurrentMatrix()->MasterToLocalVect(masterdir, ldir);
}
*/
LogicalVolume *converted =
(daughter) ? RootGeoManager::Instance().Convert(founddaughter) : RootGeoManager::Instance().Convert(foundvolume);
VPlacedVolume *shape = converted->Place(); // VPlacedVolume
std::cerr << "\n=========Using VecGeom=========\n\n";
shape->Print();
Vector3D<Precision> amin, amax;
shape->Extent(amin, amax);
Precision size = 0.2 * (amax - amin).Mag();
Vector3D<Precision> lp(lpoint[0], lpoint[1], lpoint[2]);
Vector3D<Precision> ld(ldir[0], ldir[1], ldir[2]);
printf("local point: %.16f %.16f %.16f local dir: %.16f %.16f %.16f\n", lp[0], lp[1], lp[2], ld[0], ld[1], ld[2]);
Precision dout = runTester(shape, lp, ld);
TApplication *app = new TApplication("VecGeom Visualizer", nullptr, nullptr);
TCanvas *c = new TCanvas(foundvolume->GetName(), "", 1200, 800);
gGeoManager->SetTopVisible();
gGeoManager->SetVisLevel(1);
foundvolume->SetTransparency(40);
foundvolume->SetVisContainers();
foundvolume->SetLineColor(kBlue);
if (!daughter)
foundvolume->DrawOnly();
else
foundvolume->Draw();
DrawArrow(lp, ld, size, dout, kMagenta);
c->GetView()->ShowAxis();
app->Run();
return 0;
}
|