ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 //______________________________________________________________________________
29 // TGeoOverlap - base class describing geometry overlaps. Overlaps apply
30 // to the nodes contained inside a volume. These should not overlap to
31 // each other nor extrude the shape of their mother volume.
32 //______________________________________________________________________________
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Default ctor.
36 
38 {
39  fOverlap = 0;
40  fVolume1 = 0;
41  fVolume2 = 0;
42  fMatrix1 = 0;
43  fMatrix2 = 0;
44  fMarker = 0;
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Creates a named overlap belonging to volume VOL and having the size OVLP.
49 
51  const TGeoMatrix *matrix1, const TGeoMatrix *matrix2,
52  Bool_t isovlp, Double_t ovlp)
53  :TNamed("",name)
54 {
55  fOverlap = ovlp;
56  fVolume1 = vol1;
57  fVolume2 = vol2;
58  fMatrix1 = new TGeoHMatrix();
59  *fMatrix1 = matrix1;
60  fMatrix2 = new TGeoHMatrix();
61  *fMatrix2 = matrix2;
62  fMarker = new TPolyMarker3D();
64  SetIsOverlap(isovlp);
66 // fMarker->SetMarkerSize(0.5);
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Destructor.
71 
73 {
74  if (fMarker) delete fMarker;
75  if (fMatrix1) delete fMatrix1;
76  if (fMatrix2) delete fMatrix2;
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// Define double-click action
81 
83 {
84  if (!b) return;
85  Draw();
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Method to compare this overlap with another. Returns :
90 /// -1 - this is smaller than OBJ
91 /// 0 - equal
92 /// 1 - greater
93 
95 {
96  TGeoOverlap *other = 0;
97  other = (TGeoOverlap*)obj;
98  if (!other) {
99  Error("Compare", "other object is not TGeoOverlap");
100  return 0;
101  }
102  if (IsExtrusion()) {
103  if (other->IsExtrusion()) return (fOverlap<=other->GetOverlap())?1:-1;
104  return -1;
105  } else {
106  if (other->IsExtrusion()) return 1;
107  return (fOverlap<=other->GetOverlap())?1:-1;
108  }
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Distance to primitive for an overlap.
113 
115 {
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Draw the overlap. One daughter will be blue, the other green,
121 /// extruding points red.
122 
124 {
125  fVolume1->GetGeoManager()->GetGeomPainter()->DrawOverlap(this, option);
126  PrintInfo();
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Event interception.
131 
133 {
135 }
136 
137 ////////////////////////////////////////////////////////////////////////////////
138 /// Paint the overlap.
139 
141 {
142  fVolume1->GetGeoManager()->GetGeomPainter()->PaintOverlap(this, option);
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Print detailed info.
147 
149 {
150  PrintInfo();
151  printf(" - first volume: %s at position:\n", fVolume1->GetName());
152  fMatrix1->Print();
154  printf(" - second volume: %s at position:\n", fVolume2->GetName());
155  fMatrix2->Print();
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Print some info.
161 
163 {
164  printf(" = Overlap %s: %s ovlp=%g\n", GetName(), GetTitle(),fOverlap);
165 }
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// Set next overlapping point.
169 
171 {
172  fMarker->SetNextPoint(x,y,z);
173 }
174 
175 ////////////////////////////////////////////////////////////////////////////////
176 /// Draw overlap and sample with random points the overlapping region.
177 
179 {
180  Draw();
181  // Select bounding box of the second volume (may extrude first)
182  TPolyMarker3D *marker = 0;
184  Double_t dx = box->GetDX();
185  Double_t dy = box->GetDY();
186  Double_t dz = box->GetDZ();
187  Double_t pt[3];
188  Double_t master[3];
189  const Double_t *orig = box->GetOrigin();
190  Int_t ipoint = 0;
191  Int_t itry = 0;
192  Int_t iovlp = 0;
193  while (ipoint < npoints) {
194  // Shoot randomly in the bounding box.
195  pt[0] = orig[0] - dx + 2.*dx*gRandom->Rndm();
196  pt[1] = orig[1] - dy + 2.*dy*gRandom->Rndm();
197  pt[2] = orig[2] - dz + 2.*dz*gRandom->Rndm();
198  if (!fVolume2->Contains(pt)) {
199  itry++;
200  if (itry>10000 && !ipoint) {
201  Error("SampleOverlap", "No point inside volume!!! - aborting");
202  break;
203  }
204  continue;
205  }
206  ipoint++;
207  // Check if the point is inside the first volume
208  fMatrix2->LocalToMaster(pt, master);
209  fMatrix1->MasterToLocal(master, pt);
210  Bool_t in = fVolume1->Contains(pt);
211  if (IsOverlap() && !in) continue;
212  if (!IsOverlap() && in) continue;
213  // The point is in the overlapping region.
214  iovlp++;
215  if (!marker) {
216  marker = new TPolyMarker3D();
217  marker->SetMarkerColor(kRed);
218  }
219  marker->SetNextPoint(master[0], master[1], master[2]);
220  }
221  if (!iovlp) return;
222  marker->Draw("SAME");
223  gPad->Modified();
224  gPad->Update();
225  Double_t capacity = fVolume1->GetShape()->Capacity();
226  capacity *= Double_t(iovlp)/Double_t(npoints);
227  Double_t err = 1./TMath::Sqrt(Double_t(iovlp));
228  Info("SampleOverlap", "#Overlap %s has %g +/- %g [cm3]",
229  GetName(), capacity, err*capacity);
230 }
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// Get 3D size of this.
234 
236 {
237  fVolume1->GetShape()->Sizeof3D();
238  fVolume2->GetShape()->Sizeof3D();
239 }
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Validate this overlap.
243 
245 {
246  Double_t point[3];
247  Double_t local[3];
248  Double_t safe1,safe2;
249  Int_t npoints = fMarker->GetN();
250  for (Int_t i=0; i<npoints; i++) {
251  fMarker->GetPoint(i, point[0], point[1], point[2]);
252  if (IsExtrusion()) {
253  fMatrix1->MasterToLocal(point,local);
254  safe1 = fVolume1->GetShape()->Safety(local, kFALSE);
255  printf("point %d: safe1=%f\n", i, safe1);
256  } else {
257  fMatrix1->MasterToLocal(point,local);
258  safe1 = fVolume1->GetShape()->Safety(local, kTRUE);
259  fMatrix2->MasterToLocal(point,local);
260  safe2 = fVolume2->GetShape()->Safety(local, kTRUE);
261  printf("point %d: safe1=%f safe2=%f\n", i, safe1,safe2);
262  }
263  }
264 }
265 
266 
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual void Sizeof3D() const =0
Double_t fOverlap
Definition: TGeoOverlap.h:63
virtual void ExecuteVolumeEvent(TGeoVolume *volume, Int_t event, Int_t px, Int_t py)=0
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom.cxx:512
const char Option_t
Definition: RtypesCore.h:62
Definition: Rtypes.h:61
void InspectShape() const
Definition: TGeoVolume.h:209
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Event interception.
void Browse(TBrowser *b)
Define double-click action.
Definition: TGeoOverlap.cxx:82
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Int_t Compare(const TObject *obj) const
Method to compare this overlap with another.
Definition: TGeoOverlap.cxx:94
virtual Double_t GetDY() const
Definition: TGeoBBox.h:83
Float_t py
Definition: hprod.C:33
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
virtual Double_t GetDZ() const
Definition: TGeoBBox.h:84
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 void DrawOverlap(void *ovlp, Option_t *option="")=0
ClassImp(TGeoOverlap) TGeoOverlap
Default ctor.
Definition: TGeoOverlap.cxx:26
Double_t x[n]
Definition: legend1.C:17
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
Bool_t IsExtrusion() const
Definition: TGeoOverlap.h:88
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:413
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Distance to primitive for an overlap.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
Float_t z[5]
Definition: Ifit.C:16
virtual Int_t DistanceToPrimitiveVol(TGeoVolume *vol, Int_t px, Int_t py)=0
virtual const Double_t * GetOrigin() const
Definition: TGeoBBox.h:85
void SetIsOverlap(Bool_t flag=kTRUE)
Definition: TGeoOverlap.h:98
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
void SampleOverlap(Int_t npoints=1000000)
Draw overlap and sample with random points the overlapping region.
virtual Double_t GetDX() const
Definition: TGeoBBox.h:82
Bool_t Contains(const Double_t *point) const
Definition: TGeoVolume.h:125
virtual void Sizeof3D() const
Get 3D size of this.
TPaveText * pt
void SetNextPoint(Double_t x, Double_t y, Double_t z)
Set next overlapping point.
Bool_t IsOverlap() const
Definition: TGeoOverlap.h:89
virtual ~TGeoOverlap()
Destructor.
Definition: TGeoOverlap.cxx:72
virtual Double_t Safety(const Double_t *point, Bool_t in=kTRUE) const =0
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:346
TGeoManager * GetGeoManager() const
Definition: TGeoVolume.h:187
TGeoVolume * fVolume2
Definition: TGeoOverlap.h:65
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
Double_t GetOverlap() const
Definition: TGeoOverlap.h:87
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual void Draw(Option_t *option="")
Draws 3-D polymarker with its current attributes.
TGeoVolume * fVolume1
Definition: TGeoOverlap.h:64
virtual Int_t SetNextPoint(Double_t x, Double_t y, Double_t z)
Set point following LastPoint to x, y, z.
TGeoShape * GetShape() const
Definition: TGeoVolume.h:204
virtual void Paint(Option_t *option="")
Paint the overlap.
double Double_t
Definition: RtypesCore.h:55
void Validate() const
Validate this overlap.
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Double_t y[n]
Definition: legend1.C:17
void Print(Option_t *option="") const
print the matrix in 4x4 format
Definition: TGeoMatrix.cxx:493
virtual Double_t Capacity() const =0
#define name(a, b)
Definition: linkTestLib0.cpp:5
TGeoHMatrix * fMatrix2
Definition: TGeoOverlap.h:67
Mother of all ROOT objects.
Definition: TObject.h:58
Float_t px
Definition: hprod.C:33
A 3D polymarker.
Definition: TPolyMarker3D.h:40
virtual void Draw(Option_t *option="")
Draw the overlap.
virtual void PrintInfo() const
Print some info.
#define gPad
Definition: TVirtualPad.h:288
virtual Int_t GetN() const
Definition: TPolyMarker3D.h:66
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
TPolyMarker3D * fMarker
Definition: TGeoOverlap.h:68
virtual void Print(Option_t *option="") const
Print detailed info.
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
virtual void PaintOverlap(void *ovlp, Option_t *option="")=0
TVirtualGeoPainter * GetGeomPainter()
Make a default painter if none present. Returns pointer to it.
TGeoHMatrix * fMatrix1
Definition: TGeoOverlap.h:66