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 "TGeoManager.h"
16#include "TGeoVolume.h"
17#include "TGeoNode.h"
18#include "TGeoBBox.h"
19#include "TRandom3.h"
20#include "TPolyMarker3D.h"
21#include "TVirtualGeoPainter.h"
22
23#include "TGeoOverlap.h"
24
26
27/** \class TGeoOverlap
28\ingroup Geometry_painter
29
30Base class describing geometry overlaps. Overlaps apply
31to the nodes contained inside a volume. These should not overlap to
32each other nor extrude the shape of their mother volume.
33*/
34
35////////////////////////////////////////////////////////////////////////////////
36/// Default ctor.
37
39{
40 fOverlap = 0;
41 fVolume1 = nullptr;
42 fVolume2 = nullptr;
43 fMatrix1 = nullptr;
44 fMatrix2 = nullptr;
45 fMarker = nullptr;
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Creates a named overlap belonging to volume VOL and having the size OVLP.
50
53 : TNamed("", name)
54{
55 fOverlap = ovlp;
56 fVolume1 = vol1;
57 fVolume2 = vol2;
58 fMatrix1 = new TGeoHMatrix();
60 fMatrix2 = new TGeoHMatrix();
62 fMarker = new TPolyMarker3D();
66 // fMarker->SetMarkerSize(0.5);
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Destructor.
71
73{
74 if (fMarker)
75 delete fMarker;
76 if (fMatrix1)
77 delete fMatrix1;
78 if (fMatrix2)
79 delete fMatrix2;
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Define double-click action
84
86{
87 if (!b)
88 return;
89 Draw();
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Method to compare this overlap with another. Returns :
94/// -1 - this is smaller than OBJ
95/// 0 - equal
96/// 1 - greater
97
99{
100 TGeoOverlap *other = nullptr;
101 other = (TGeoOverlap *)obj;
102 if (!other) {
103 Error("Compare", "other object is not TGeoOverlap");
104 return 0;
105 }
106 if (IsExtrusion()) {
107 if (other->IsExtrusion())
108 return (fOverlap <= other->GetOverlap()) ? 1 : -1;
109 return -1;
110 } else {
111 if (other->IsExtrusion())
112 return 1;
113 return (fOverlap <= other->GetOverlap()) ? 1 : -1;
114 }
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Distance to primitive for an overlap.
119
124
125////////////////////////////////////////////////////////////////////////////////
126/// Draw the overlap. One daughter will be blue, the other green,
127/// extruding points red.
128
134
135////////////////////////////////////////////////////////////////////////////////
136/// Event interception.
137
142
143////////////////////////////////////////////////////////////////////////////////
144/// Paint the overlap.
145
150
151////////////////////////////////////////////////////////////////////////////////
152/// Print detailed info.
153
155{
156 PrintInfo();
157 printf(" - first volume: %s at position:\n", fVolume1->GetName());
158 fMatrix1->Print();
160 printf(" - second volume: %s at position:\n", fVolume2->GetName());
161 fMatrix2->Print();
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Print some info.
167
169{
170 printf(" = Overlap %s: %s ovlp=%g\n", GetName(), GetTitle(), fOverlap);
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Set next overlapping point.
175
180
181////////////////////////////////////////////////////////////////////////////////
182/// Draw overlap and sample with random points the overlapping region.
183
185{
186 Draw();
187 // Select bounding box of the second volume (may extrude first)
188 TPolyMarker3D *marker = nullptr;
190 Double_t dx = box->GetDX();
191 Double_t dy = box->GetDY();
192 Double_t dz = box->GetDZ();
193 Double_t pt[3];
194 Double_t master[3];
195 const Double_t *orig = box->GetOrigin();
196 Int_t ipoint = 0;
197 Int_t itry = 0;
198 Int_t iovlp = 0;
199 while (ipoint < npoints) {
200 // Shoot randomly in the bounding box.
201 pt[0] = orig[0] - dx + 2. * dx * gRandom->Rndm();
202 pt[1] = orig[1] - dy + 2. * dy * gRandom->Rndm();
203 pt[2] = orig[2] - dz + 2. * dz * gRandom->Rndm();
204 if (!fVolume2->Contains(pt)) {
205 itry++;
206 if (itry > 10000 && !ipoint) {
207 Error("SampleOverlap", "No point inside volume!!! - aborting");
208 break;
209 }
210 continue;
211 }
212 ipoint++;
213 // Check if the point is inside the first volume
216 Bool_t in = fVolume1->Contains(pt);
217 if (IsOverlap() && !in)
218 continue;
219 if (!IsOverlap() && in)
220 continue;
221 // The point is in the overlapping region.
222 iovlp++;
223 if (!marker) {
224 marker = new TPolyMarker3D();
225 marker->SetMarkerColor(kRed);
226 }
227 marker->SetNextPoint(master[0], master[1], master[2]);
228 }
229 if (!iovlp)
230 return;
231 marker->Draw("SAME");
232 gPad->Modified();
233 gPad->Update();
234 Double_t capacity = fVolume1->GetShape()->Capacity();
235 capacity *= Double_t(iovlp) / Double_t(npoints);
236 Double_t err = 1. / TMath::Sqrt(Double_t(iovlp));
237 Info("SampleOverlap", "#Overlap %s has %g +/- %g [cm3]", GetName(), capacity, err * capacity);
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// Get 3D size of this.
242
244{
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Validate this overlap.
251
253{
254 Double_t point[3];
255 Double_t local[3];
258 for (Int_t i = 0; i < npoints; i++) {
259 fMarker->GetPoint(i, point[0], point[1], point[2]);
260 if (IsExtrusion()) {
263 printf("point %d: safe1=%f\n", i, safe1);
264 } else {
269 printf("point %d: safe1=%f safe2=%f\n", i, safe1, safe2);
270 }
271 }
272}
#define b(i)
Definition RSha256.hxx:100
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassImp(name)
Definition Rtypes.h:376
@ kRed
Definition Rtypes.h:67
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:39
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:41
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:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
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:1072
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1046
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:668
th1 Draw()