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/** \class TGeoOverlap
26\ingroup Geometry_painter
27
28Base class describing geometry overlaps. Overlaps apply
29to the nodes contained inside a volume. These should not overlap to
30each other nor extrude the shape of their mother volume.
31*/
32
33////////////////////////////////////////////////////////////////////////////////
34/// Default ctor.
35
37{
38 fOverlap = 0;
39 fVolume1 = nullptr;
40 fVolume2 = nullptr;
41 fMatrix1 = nullptr;
42 fMatrix2 = nullptr;
43 fMarker = nullptr;
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Creates a named overlap belonging to volume VOL and having the size OVLP.
48
51 : TNamed("", name)
52{
53 fOverlap = ovlp;
54 fVolume1 = vol1;
55 fVolume2 = vol2;
56 fMatrix1 = new TGeoHMatrix();
58 fMatrix2 = new TGeoHMatrix();
60 fMarker = new TPolyMarker3D();
64 // fMarker->SetMarkerSize(0.5);
65}
66
67////////////////////////////////////////////////////////////////////////////////
68/// Destructor.
69
71{
72 if (fMarker)
73 delete fMarker;
74 if (fMatrix1)
75 delete fMatrix1;
76 if (fMatrix2)
77 delete fMatrix2;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Define double-click action
82
84{
85 if (!b)
86 return;
87 Draw();
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Method to compare this overlap with another. Returns :
92/// -1 - this is smaller than OBJ
93/// 0 - equal
94/// 1 - greater
95
97{
98 TGeoOverlap *other = nullptr;
99 other = (TGeoOverlap *)obj;
100 if (!other) {
101 Error("Compare", "other object is not TGeoOverlap");
102 return 0;
103 }
104 if (IsExtrusion()) {
105 if (other->IsExtrusion())
106 return (fOverlap <= other->GetOverlap()) ? 1 : -1;
107 return -1;
108 } else {
109 if (other->IsExtrusion())
110 return 1;
111 return (fOverlap <= other->GetOverlap()) ? 1 : -1;
112 }
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Distance to primitive for an overlap.
117
122
123////////////////////////////////////////////////////////////////////////////////
124/// Draw the overlap. One daughter will be blue, the other green,
125/// extruding points red.
126
132
133////////////////////////////////////////////////////////////////////////////////
134/// Event interception.
135
140
141////////////////////////////////////////////////////////////////////////////////
142/// Paint the overlap.
143
148
149////////////////////////////////////////////////////////////////////////////////
150/// Print detailed info.
151
153{
154 PrintInfo();
155 printf(" - first volume: %s at position:\n", fVolume1->GetName());
156 fMatrix1->Print();
158 printf(" - second volume: %s at position:\n", fVolume2->GetName());
159 fMatrix2->Print();
161 TString opt(option);
162 opt.ToUpper();
163 if (opt.Contains("P")) {
164 // print the first 10 points of the marker
165 if (fMarker && (fMarker->Size() > 0)) {
167 printf(" - first %d points in the overlapping region :\n", nshow);
168 Float_t x, y, z;
169 for (auto i = 0; i < nshow; ++i) {
170 fMarker->GetPoint(i, x, y, z);
171 printf(" {%g, %g, %g}\n", x, y, z);
172 }
173 }
174 }
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Print some info.
179
181{
182 printf(" = Overlap %s: %s ovlp=%g\n", GetName(), GetTitle(), fOverlap);
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Set next overlapping point.
187
192
193////////////////////////////////////////////////////////////////////////////////
194/// Draw overlap and sample with random points the overlapping region.
195
197{
198 Draw();
199 // Select bounding box of the second volume (may extrude first)
200 TPolyMarker3D *marker = nullptr;
202 Double_t dx = box->GetDX();
203 Double_t dy = box->GetDY();
204 Double_t dz = box->GetDZ();
205 Double_t pt[3];
206 Double_t master[3];
207 const Double_t *orig = box->GetOrigin();
208 Int_t ipoint = 0;
209 Int_t itry = 0;
210 Int_t iovlp = 0;
211 while (ipoint < npoints) {
212 // Shoot randomly in the bounding box.
213 pt[0] = orig[0] - dx + 2. * dx * gRandom->Rndm();
214 pt[1] = orig[1] - dy + 2. * dy * gRandom->Rndm();
215 pt[2] = orig[2] - dz + 2. * dz * gRandom->Rndm();
216 if (!fVolume2->Contains(pt)) {
217 itry++;
218 if (itry > 10000 && !ipoint) {
219 Error("SampleOverlap", "No point inside volume!!! - aborting");
220 break;
221 }
222 continue;
223 }
224 ipoint++;
225 // Check if the point is inside the first volume
229 if (IsOverlap() && !in)
230 continue;
231 if (!IsOverlap() && in)
232 continue;
233 // The point is in the overlapping region.
234 iovlp++;
235 if (!marker) {
236 marker = new TPolyMarker3D();
237 marker->SetMarkerColor(kRed);
238 }
239 marker->SetNextPoint(master[0], master[1], master[2]);
240 }
241 if (!iovlp)
242 return;
243 marker->Draw("SAME");
244 gPad->Modified();
245 gPad->Update();
246 Double_t capacity = fVolume1->GetShape()->Capacity();
247 capacity *= Double_t(iovlp) / Double_t(npoints);
248 Double_t err = 1. / TMath::Sqrt(Double_t(iovlp));
249 Info("SampleOverlap", "#Overlap %s has %g +/- %g [cm3]", GetName(), capacity, err * capacity);
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Get 3D size of this.
254
256{
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Validate this overlap.
263
265{
266 Double_t point[3];
267 Double_t local[3];
270 for (Int_t i = 0; i < npoints; i++) {
271 fMarker->GetPoint(i, point[0], point[1], point[2]);
272 if (IsExtrusion()) {
275 printf("point %d: safe1=%f\n", i, safe1);
276 } else {
281 printf("point %d: safe1=%f safe2=%f\n", i, safe1, safe2);
282 }
283 }
284}
#define b(i)
Definition RSha256.hxx:100
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
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:18
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition TGeoMatrix.h:459
TVirtualGeoPainter * GetGeomPainter()
Make a default painter if none present. Returns pointer to it.
Geometrical transformation package.
Definition TGeoMatrix.h:39
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:174
Bool_t Contains(const Double_t *point) const
Definition TGeoVolume.h:105
TGeoShape * GetShape() const
Definition TGeoVolume.h:191
void InspectShape() const
Definition TGeoVolume.h:196
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:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1088
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1062
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 Size() const
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
Basic string class.
Definition TString.h:138
void ToUpper()
Change string to upper case.
Definition TString.cxx:1202
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
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
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
th1 Draw()