Logo ROOT   6.16/01
Reference Guide
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_classes
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 = 0;
43 fVolume2 = 0;
44 fMatrix1 = 0;
45 fMatrix2 = 0;
46 fMarker = 0;
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Creates a named overlap belonging to volume VOL and having the size OVLP.
51
53 const TGeoMatrix *matrix1, const TGeoMatrix *matrix2,
54 Bool_t isovlp, Double_t ovlp)
55 :TNamed("",name)
56{
57 fOverlap = ovlp;
58 fVolume1 = vol1;
59 fVolume2 = vol2;
60 fMatrix1 = new TGeoHMatrix();
61 *fMatrix1 = matrix1;
62 fMatrix2 = new TGeoHMatrix();
63 *fMatrix2 = matrix2;
64 fMarker = new TPolyMarker3D();
66 SetIsOverlap(isovlp);
68// fMarker->SetMarkerSize(0.5);
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Destructor.
73
75{
76 if (fMarker) delete fMarker;
77 if (fMatrix1) delete fMatrix1;
78 if (fMatrix2) delete fMatrix2;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Define double-click action
83
85{
86 if (!b) 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 = 0;
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()) return (fOverlap<=other->GetOverlap())?1:-1;
106 return -1;
107 } else {
108 if (other->IsExtrusion()) return 1;
109 return (fOverlap<=other->GetOverlap())?1:-1;
110 }
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Distance to primitive for an overlap.
115
117{
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Draw the overlap. One daughter will be blue, the other green,
123/// extruding points red.
124
126{
128 PrintInfo();
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Event interception.
133
135{
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Paint the overlap.
141
143{
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Print detailed info.
149
151{
152 PrintInfo();
153 printf(" - first volume: %s at position:\n", fVolume1->GetName());
154 fMatrix1->Print();
156 printf(" - second volume: %s at position:\n", fVolume2->GetName());
157 fMatrix2->Print();
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Print some info.
163
165{
166 printf(" = Overlap %s: %s ovlp=%g\n", GetName(), GetTitle(),fOverlap);
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Set next overlapping point.
171
173{
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Draw overlap and sample with random points the overlapping region.
179
181{
182 Draw();
183 // Select bounding box of the second volume (may extrude first)
184 TPolyMarker3D *marker = 0;
186 Double_t dx = box->GetDX();
187 Double_t dy = box->GetDY();
188 Double_t dz = box->GetDZ();
189 Double_t pt[3];
190 Double_t master[3];
191 const Double_t *orig = box->GetOrigin();
192 Int_t ipoint = 0;
193 Int_t itry = 0;
194 Int_t iovlp = 0;
195 while (ipoint < npoints) {
196 // Shoot randomly in the bounding box.
197 pt[0] = orig[0] - dx + 2.*dx*gRandom->Rndm();
198 pt[1] = orig[1] - dy + 2.*dy*gRandom->Rndm();
199 pt[2] = orig[2] - dz + 2.*dz*gRandom->Rndm();
200 if (!fVolume2->Contains(pt)) {
201 itry++;
202 if (itry>10000 && !ipoint) {
203 Error("SampleOverlap", "No point inside volume!!! - aborting");
204 break;
205 }
206 continue;
207 }
208 ipoint++;
209 // Check if the point is inside the first volume
210 fMatrix2->LocalToMaster(pt, master);
211 fMatrix1->MasterToLocal(master, pt);
212 Bool_t in = fVolume1->Contains(pt);
213 if (IsOverlap() && !in) continue;
214 if (!IsOverlap() && in) continue;
215 // The point is in the overlapping region.
216 iovlp++;
217 if (!marker) {
218 marker = new TPolyMarker3D();
219 marker->SetMarkerColor(kRed);
220 }
221 marker->SetNextPoint(master[0], master[1], master[2]);
222 }
223 if (!iovlp) return;
224 marker->Draw("SAME");
225 gPad->Modified();
226 gPad->Update();
227 Double_t capacity = fVolume1->GetShape()->Capacity();
228 capacity *= Double_t(iovlp)/Double_t(npoints);
229 Double_t err = 1./TMath::Sqrt(Double_t(iovlp));
230 Info("SampleOverlap", "#Overlap %s has %g +/- %g [cm3]",
231 GetName(), capacity, err*capacity);
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Get 3D size of this.
236
238{
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Validate this overlap.
245
247{
248 Double_t point[3];
249 Double_t local[3];
250 Double_t safe1,safe2;
251 Int_t npoints = fMarker->GetN();
252 for (Int_t i=0; i<npoints; i++) {
253 fMarker->GetPoint(i, point[0], point[1], point[2]);
254 if (IsExtrusion()) {
255 fMatrix1->MasterToLocal(point,local);
256 safe1 = fVolume1->GetShape()->Safety(local, kFALSE);
257 printf("point %d: safe1=%f\n", i, safe1);
258 } else {
259 fMatrix1->MasterToLocal(point,local);
260 safe1 = fVolume1->GetShape()->Safety(local, kTRUE);
261 fMatrix2->MasterToLocal(point,local);
262 safe2 = fVolume2->GetShape()->Safety(local, kTRUE);
263 printf("point %d: safe1=%f safe2=%f\n", i, safe1,safe2);
264 }
265 }
266}
267
268
#define b(i)
Definition: RSha256.hxx:100
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:363
@ kRed
Definition: Rtypes.h:63
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
#define gPad
Definition: TVirtualPad.h:286
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:18
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition: TGeoMatrix.h:421
TVirtualGeoPainter * GetGeomPainter()
Make a default painter if none present. Returns pointer to it.
Geometrical transformation package.
Definition: TGeoMatrix.h:41
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
Definition: TGeoMatrix.cxx:406
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
Definition: TGeoMatrix.cxx:339
void Print(Option_t *option="") const
print the matrix in 4x4 format
Definition: TGeoMatrix.cxx:486
Base class describing geometry overlaps.
Definition: TGeoOverlap.h:41
TGeoHMatrix * fMatrix1
Definition: TGeoOverlap.h:56
void SetIsOverlap(Bool_t flag=kTRUE)
Definition: TGeoOverlap.h:88
void Browse(TBrowser *b)
Define double-click action.
Definition: TGeoOverlap.cxx:84
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:54
virtual void Sizeof3D() const
Get 3D size of this.
Bool_t IsOverlap() const
Definition: TGeoOverlap.h:79
void SampleOverlap(Int_t npoints=1000000)
Draw overlap and sample with random points the overlapping region.
TPolyMarker3D * fMarker
Definition: TGeoOverlap.h:58
Double_t fOverlap
Definition: TGeoOverlap.h:53
TGeoHMatrix * fMatrix2
Definition: TGeoOverlap.h:57
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Event interception.
virtual void Print(Option_t *option="") const
Print detailed info.
TGeoVolume * fVolume2
Definition: TGeoOverlap.h:55
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Distance to primitive for an overlap.
virtual Int_t Compare(const TObject *obj) const
Method to compare this overlap with another.
Definition: TGeoOverlap.cxx:96
virtual void PrintInfo() const
Print some info.
virtual void Paint(Option_t *option="")
Paint the overlap.
Bool_t IsExtrusion() const
Definition: TGeoOverlap.h:78
virtual void Draw(Option_t *option="")
Draw the overlap.
Double_t GetOverlap() const
Definition: TGeoOverlap.h:77
virtual ~TGeoOverlap()
Destructor.
Definition: TGeoOverlap.cxx:74
TGeoOverlap()
Default ctor.
Definition: TGeoOverlap.cxx:39
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:53
TGeoManager * GetGeoManager() const
Definition: TGeoVolume.h:174
Bool_t Contains(const Double_t *point) const
Definition: TGeoVolume.h:112
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
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
A 3D polymarker.
Definition: TPolyMarker3D.h:33
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
Definition: TPolyMarker3D.h:58
virtual Int_t SetNextPoint(Double_t x, Double_t y, Double_t z)
Set point following LastPoint to x, y, z.
virtual void Draw(Option_t *option="")
Draws 3-D polymarker with its current attributes.
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:533
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)
Definition: TMath.h:679