Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoOverlap.cxx
Go to the documentation of this file.
1// @(#)root/geom:$Id$
2// Author: Andrei Gheata 09-02-03
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TVirtualPad.h"
13#include "TMath.h"
14#include "TNamed.h"
15#include "TBrowser.h"
16#include "TGeoManager.h"
17#include "TGeoVolume.h"
18#include "TGeoNode.h"
19#include "TGeoBBox.h"
20#include "TRandom3.h"
21#include "TPolyMarker3D.h"
22#include "TVirtualGeoPainter.h"
23
24#include "TGeoOverlap.h"
25
27
28/** \class TGeoOverlap
29\ingroup Geometry_painter
30
31Base class describing geometry overlaps. Overlaps apply
32to the nodes contained inside a volume. These should not overlap to
33each other nor extrude the shape of their mother volume.
34*/
35
36////////////////////////////////////////////////////////////////////////////////
37/// Default ctor.
38
40{
41 fOverlap = 0;
42 fVolume1 = nullptr;
43 fVolume2 = nullptr;
44 fMatrix1 = nullptr;
45 fMatrix2 = nullptr;
46 fMarker = nullptr;
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Creates a named overlap belonging to volume VOL and having the size OVLP.
51
52TGeoOverlap::TGeoOverlap(const char *name, TGeoVolume *vol1, TGeoVolume *vol2, const TGeoMatrix *matrix1,
53 const TGeoMatrix *matrix2, Bool_t isovlp, Double_t ovlp)
54 : TNamed("", name)
55{
56 fOverlap = ovlp;
57 fVolume1 = vol1;
58 fVolume2 = vol2;
59 fMatrix1 = new TGeoHMatrix();
60 *fMatrix1 = matrix1;
61 fMatrix2 = new TGeoHMatrix();
62 *fMatrix2 = matrix2;
63 fMarker = new TPolyMarker3D();
65 SetIsOverlap(isovlp);
67 // fMarker->SetMarkerSize(0.5);
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Destructor.
72
74{
75 if (fMarker)
76 delete fMarker;
77 if (fMatrix1)
78 delete fMatrix1;
79 if (fMatrix2)
80 delete fMatrix2;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Define double-click action
85
87{
88 if (!b)
89 return;
90 Draw();
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Method to compare this overlap with another. Returns :
95/// -1 - this is smaller than OBJ
96/// 0 - equal
97/// 1 - greater
98
100{
101 TGeoOverlap *other = nullptr;
102 other = (TGeoOverlap *)obj;
103 if (!other) {
104 Error("Compare", "other object is not TGeoOverlap");
105 return 0;
106 }
107 if (IsExtrusion()) {
108 if (other->IsExtrusion())
109 return (fOverlap <= other->GetOverlap()) ? 1 : -1;
110 return -1;
111 } else {
112 if (other->IsExtrusion())
113 return 1;
114 return (fOverlap <= other->GetOverlap()) ? 1 : -1;
115 }
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Distance to primitive for an overlap.
120
122{
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Draw the overlap. One daughter will be blue, the other green,
128/// extruding points red.
129
131{
133 PrintInfo();
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Event interception.
138
140{
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Paint the overlap.
146
148{
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Print detailed info.
154
156{
157 PrintInfo();
158 printf(" - first volume: %s at position:\n", fVolume1->GetName());
159 fMatrix1->Print();
161 printf(" - second volume: %s at position:\n", fVolume2->GetName());
162 fMatrix2->Print();
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Print some info.
168
170{
171 printf(" = Overlap %s: %s ovlp=%g\n", GetName(), GetTitle(), fOverlap);
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Set next overlapping point.
176
178{
179 fMarker->SetNextPoint(x, y, z);
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Draw overlap and sample with random points the overlapping region.
184
186{
187 Draw();
188 // Select bounding box of the second volume (may extrude first)
189 TPolyMarker3D *marker = nullptr;
191 Double_t dx = box->GetDX();
192 Double_t dy = box->GetDY();
193 Double_t dz = box->GetDZ();
194 Double_t pt[3];
195 Double_t master[3];
196 const Double_t *orig = box->GetOrigin();
197 Int_t ipoint = 0;
198 Int_t itry = 0;
199 Int_t iovlp = 0;
200 while (ipoint < npoints) {
201 // Shoot randomly in the bounding box.
202 pt[0] = orig[0] - dx + 2. * dx * gRandom->Rndm();
203 pt[1] = orig[1] - dy + 2. * dy * gRandom->Rndm();
204 pt[2] = orig[2] - dz + 2. * dz * gRandom->Rndm();
205 if (!fVolume2->Contains(pt)) {
206 itry++;
207 if (itry > 10000 && !ipoint) {
208 Error("SampleOverlap", "No point inside volume!!! - aborting");
209 break;
210 }
211 continue;
212 }
213 ipoint++;
214 // Check if the point is inside the first volume
215 fMatrix2->LocalToMaster(pt, master);
216 fMatrix1->MasterToLocal(master, pt);
217 Bool_t in = fVolume1->Contains(pt);
218 if (IsOverlap() && !in)
219 continue;
220 if (!IsOverlap() && in)
221 continue;
222 // The point is in the overlapping region.
223 iovlp++;
224 if (!marker) {
225 marker = new TPolyMarker3D();
226 marker->SetMarkerColor(kRed);
227 }
228 marker->SetNextPoint(master[0], master[1], master[2]);
229 }
230 if (!iovlp)
231 return;
232 marker->Draw("SAME");
233 gPad->Modified();
234 gPad->Update();
235 Double_t capacity = fVolume1->GetShape()->Capacity();
236 capacity *= Double_t(iovlp) / Double_t(npoints);
237 Double_t err = 1. / TMath::Sqrt(Double_t(iovlp));
238 Info("SampleOverlap", "#Overlap %s has %g +/- %g [cm3]", GetName(), capacity, err * capacity);
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Get 3D size of this.
243
245{
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Validate this overlap.
252
254{
255 Double_t point[3];
256 Double_t local[3];
257 Double_t safe1, safe2;
258 Int_t npoints = fMarker->GetN();
259 for (Int_t i = 0; i < npoints; i++) {
260 fMarker->GetPoint(i, point[0], point[1], point[2]);
261 if (IsExtrusion()) {
262 fMatrix1->MasterToLocal(point, local);
263 safe1 = fVolume1->GetShape()->Safety(local, kFALSE);
264 printf("point %d: safe1=%f\n", i, safe1);
265 } else {
266 fMatrix1->MasterToLocal(point, local);
267 safe1 = fVolume1->GetShape()->Safety(local, kTRUE);
268 fMatrix2->MasterToLocal(point, local);
269 safe2 = fVolume2->GetShape()->Safety(local, kTRUE);
270 printf("point %d: safe1=%f safe2=%f\n", i, safe1, safe2);
271 }
272 }
273}
#define b(i)
Definition RSha256.hxx:100
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
@ kRed
Definition Rtypes.h:66
Option_t Option_t option
char name[80]
Definition TGX11.cxx:110
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
#define gPad
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Box class.
Definition TGeoBBox.h:17
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition TGeoMatrix.h:458
TVirtualGeoPainter * GetGeomPainter()
Make a default painter if none present. Returns pointer to it.
Geometrical transformation package.
Definition TGeoMatrix.h:38
void Print(Option_t *option="") const override
print the matrix in 4x4 format
virtual void MasterToLocal(const Double_t *master, Double_t *local) const
convert a point by multiplying its column vector (x, y, z, 1) to matrix
virtual void LocalToMaster(const Double_t *local, Double_t *master) const
convert a point by multiplying its column vector (x, y, z, 1) to matrix inverse
Base class describing geometry overlaps.
Definition TGeoOverlap.h:37
TGeoHMatrix * fMatrix1
Definition TGeoOverlap.h:49
void SetIsOverlap(Bool_t flag=kTRUE)
Definition TGeoOverlap.h:84
void Paint(Option_t *option="") override
Paint the overlap.
void Validate() const
Validate this overlap.
void SetNextPoint(Double_t x, Double_t y, Double_t z)
Set next overlapping point.
TGeoVolume * fVolume1
Definition TGeoOverlap.h:47
Bool_t IsOverlap() const
Definition TGeoOverlap.h:71
void SampleOverlap(Int_t npoints=1000000)
Draw overlap and sample with random points the overlapping region.
Int_t Compare(const TObject *obj) const override
Method to compare this overlap with another.
void Draw(Option_t *option="") override
Draw the overlap.
TPolyMarker3D * fMarker
Definition TGeoOverlap.h:51
void Print(Option_t *option="") const override
Print detailed info.
~TGeoOverlap() override
Destructor.
Double_t fOverlap
Definition TGeoOverlap.h:46
TGeoHMatrix * fMatrix2
Definition TGeoOverlap.h:50
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Distance to primitive for an overlap.
TGeoVolume * fVolume2
Definition TGeoOverlap.h:48
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Event interception.
void Browse(TBrowser *b) override
Define double-click action.
virtual void PrintInfo() const
Print some info.
Bool_t IsExtrusion() const
Definition TGeoOverlap.h:70
Double_t GetOverlap() const
Definition TGeoOverlap.h:69
void Sizeof3D() const override
Get 3D size of this.
TGeoOverlap()
Default ctor.
virtual void Sizeof3D() const =0
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const =0
virtual Double_t Capacity() const =0
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
TGeoManager * GetGeoManager() const
Definition TGeoVolume.h:173
Bool_t Contains(const Double_t *point) const
Definition TGeoVolume.h:104
TGeoShape * GetShape() const
Definition TGeoVolume.h:190
void InspectShape() const
Definition TGeoVolume.h:195
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
A 3D polymarker.
virtual void GetPoint(Int_t n, Float_t &x, Float_t &y, Float_t &z) const
Fills the parameters x, y, z with the coordinate of the n-th point n must be between 0 and Size() - 1...
virtual Int_t GetN() const
virtual Int_t SetNextPoint(Double_t x, Double_t y, Double_t z)
Set point following LastPoint to x, y, z.
void Draw(Option_t *option="") override
Draws 3-D polymarker with its current attributes.
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
virtual void PaintOverlap(void *ovlp, Option_t *option="")=0
virtual void DrawOverlap(void *ovlp, Option_t *option="")=0
virtual Int_t DistanceToPrimitiveVol(TGeoVolume *vol, Int_t px, Int_t py)=0
virtual void ExecuteVolumeEvent(TGeoVolume *volume, Int_t event, Int_t px, Int_t py)=0
TPaveText * pt
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
th1 Draw()