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
25
26/** \class TGeoOverlap
27\ingroup Geometry_painter
28
29Base class describing geometry overlaps. Overlaps apply
30to the nodes contained inside a volume. These should not overlap to
31each other nor extrude the shape of their mother volume.
32*/
33
34////////////////////////////////////////////////////////////////////////////////
35/// Default ctor.
36
38{
39 fOverlap = 0;
40 fVolume1 = nullptr;
41 fVolume2 = nullptr;
42 fMatrix1 = nullptr;
43 fMatrix2 = nullptr;
44 fMarker = nullptr;
45}
46
47////////////////////////////////////////////////////////////////////////////////
48/// Creates a named overlap belonging to volume VOL and having the size OVLP.
49
52 : TNamed("", name)
53{
54 fOverlap = ovlp;
55 fVolume1 = vol1;
56 fVolume2 = vol2;
57 fMatrix1 = new TGeoHMatrix();
59 fMatrix2 = new TGeoHMatrix();
61 fMarker = new TPolyMarker3D();
65 // fMarker->SetMarkerSize(0.5);
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Destructor.
70
72{
73 if (fMarker)
74 delete fMarker;
75 if (fMatrix1)
76 delete fMatrix1;
77 if (fMatrix2)
78 delete fMatrix2;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Define double-click action
83
85{
86 if (!b)
87 return;
88 Draw();
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Method to compare this overlap with another. Returns :
93/// -1 - this is smaller than OBJ
94/// 0 - equal
95/// 1 - greater
96
98{
99 TGeoOverlap *other = nullptr;
100 other = (TGeoOverlap *)obj;
101 if (!other) {
102 Error("Compare", "other object is not TGeoOverlap");
103 return 0;
104 }
105 if (IsExtrusion()) {
106 if (other->IsExtrusion())
107 return (fOverlap <= other->GetOverlap()) ? 1 : -1;
108 return -1;
109 } else {
110 if (other->IsExtrusion())
111 return 1;
112 return (fOverlap <= other->GetOverlap()) ? 1 : -1;
113 }
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Distance to primitive for an overlap.
118
123
124////////////////////////////////////////////////////////////////////////////////
125/// Draw the overlap. One daughter will be blue, the other green,
126/// extruding points red.
127
133
134////////////////////////////////////////////////////////////////////////////////
135/// Event interception.
136
141
142////////////////////////////////////////////////////////////////////////////////
143/// Paint the overlap.
144
149
150////////////////////////////////////////////////////////////////////////////////
151/// Print detailed info.
152
154{
155 PrintInfo();
156 printf(" - first volume: %s at position:\n", fVolume1->GetName());
157 fMatrix1->Print();
159 printf(" - second volume: %s at position:\n", fVolume2->GetName());
160 fMatrix2->Print();
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Print some info.
166
168{
169 printf(" = Overlap %s: %s ovlp=%g\n", GetName(), GetTitle(), fOverlap);
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Set next overlapping point.
174
179
180////////////////////////////////////////////////////////////////////////////////
181/// Draw overlap and sample with random points the overlapping region.
182
184{
185 Draw();
186 // Select bounding box of the second volume (may extrude first)
187 TPolyMarker3D *marker = nullptr;
189 Double_t dx = box->GetDX();
190 Double_t dy = box->GetDY();
191 Double_t dz = box->GetDZ();
192 Double_t pt[3];
193 Double_t master[3];
194 const Double_t *orig = box->GetOrigin();
195 Int_t ipoint = 0;
196 Int_t itry = 0;
197 Int_t iovlp = 0;
198 while (ipoint < npoints) {
199 // Shoot randomly in the bounding box.
200 pt[0] = orig[0] - dx + 2. * dx * gRandom->Rndm();
201 pt[1] = orig[1] - dy + 2. * dy * gRandom->Rndm();
202 pt[2] = orig[2] - dz + 2. * dz * gRandom->Rndm();
203 if (!fVolume2->Contains(pt)) {
204 itry++;
205 if (itry > 10000 && !ipoint) {
206 Error("SampleOverlap", "No point inside volume!!! - aborting");
207 break;
208 }
209 continue;
210 }
211 ipoint++;
212 // Check if the point is inside the first volume
216 if (IsOverlap() && !in)
217 continue;
218 if (!IsOverlap() && in)
219 continue;
220 // The point is in the overlapping region.
221 iovlp++;
222 if (!marker) {
223 marker = new TPolyMarker3D();
224 marker->SetMarkerColor(kRed);
225 }
226 marker->SetNextPoint(master[0], master[1], master[2]);
227 }
228 if (!iovlp)
229 return;
230 marker->Draw("SAME");
231 gPad->Modified();
232 gPad->Update();
233 Double_t capacity = fVolume1->GetShape()->Capacity();
234 capacity *= Double_t(iovlp) / Double_t(npoints);
235 Double_t err = 1. / TMath::Sqrt(Double_t(iovlp));
236 Info("SampleOverlap", "#Overlap %s has %g +/- %g [cm3]", GetName(), capacity, err * capacity);
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Get 3D size of this.
241
243{
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Validate this overlap.
250
252{
253 Double_t point[3];
254 Double_t local[3];
257 for (Int_t i = 0; i < npoints; i++) {
258 fMarker->GetPoint(i, point[0], point[1], point[2]);
259 if (IsExtrusion()) {
262 printf("point %d: safe1=%f\n", i, safe1);
263 } else {
268 printf("point %d: safe1=%f safe2=%f\n", i, safe1, safe2);
269 }
270 }
271}
#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
@ 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:1071
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
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:558
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:673
th1 Draw()