00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TVirtualPad.h"
00013 #include "TMath.h"
00014 #include "TNamed.h"
00015 #include "TBrowser.h"
00016 #include "TGeoManager.h"
00017 #include "TGeoVolume.h"
00018 #include "TGeoNode.h"
00019 #include "TGeoBBox.h"
00020 #include "TRandom3.h"
00021 #include "TPolyMarker3D.h"
00022 #include "TVirtualGeoPainter.h"
00023
00024 #include "TGeoOverlap.h"
00025
00026 ClassImp(TGeoOverlap)
00027
00028
00029
00030
00031
00032
00033
00034
00035 TGeoOverlap::TGeoOverlap()
00036 {
00037
00038 fOverlap = 0;
00039 fVolume1 = 0;
00040 fVolume2 = 0;
00041 fMatrix1 = 0;
00042 fMatrix2 = 0;
00043 fMarker = 0;
00044 }
00045
00046
00047 TGeoOverlap::TGeoOverlap(const char *name, TGeoVolume *vol1, TGeoVolume *vol2,
00048 const TGeoMatrix *matrix1, const TGeoMatrix *matrix2,
00049 Bool_t isovlp, Double_t ovlp)
00050 :TNamed("",name)
00051 {
00052
00053 fOverlap = ovlp;
00054 fVolume1 = vol1;
00055 fVolume2 = vol2;
00056 fMatrix1 = new TGeoHMatrix();
00057 *fMatrix1 = matrix1;
00058 fMatrix2 = new TGeoHMatrix();
00059 *fMatrix2 = matrix2;
00060 fMarker = new TPolyMarker3D();
00061 fMarker->SetMarkerColor(2);
00062 SetIsOverlap(isovlp);
00063 fMarker->SetMarkerStyle(6);
00064
00065 }
00066
00067
00068 TGeoOverlap::~TGeoOverlap()
00069 {
00070
00071 if (fMarker) delete fMarker;
00072 if (fMatrix1) delete fMatrix1;
00073 if (fMatrix2) delete fMatrix2;
00074 }
00075
00076
00077 void TGeoOverlap::Browse(TBrowser *b)
00078 {
00079
00080 if (!b) return;
00081 Draw();
00082 }
00083
00084
00085 Int_t TGeoOverlap::Compare(const TObject *obj) const
00086 {
00087
00088
00089
00090
00091 TGeoOverlap *other = 0;
00092 other = (TGeoOverlap*)obj;
00093 if (!other) {
00094 Error("Compare", "other object is not TGeoOverlap");
00095 return 0;
00096 }
00097 if (IsExtrusion()) {
00098 if (other->IsExtrusion()) return (fOverlap<=other->GetOverlap())?1:-1;
00099 return -1;
00100 } else {
00101 if (other->IsExtrusion()) return 1;
00102 return (fOverlap<=other->GetOverlap())?1:-1;
00103 }
00104 }
00105
00106
00107 Int_t TGeoOverlap::DistancetoPrimitive(Int_t px, Int_t py)
00108 {
00109
00110 return fVolume1->GetGeoManager()->GetGeomPainter()->DistanceToPrimitiveVol(fVolume1, px, py);
00111 }
00112
00113
00114 void TGeoOverlap::Draw(Option_t *option)
00115 {
00116
00117
00118 fVolume1->GetGeoManager()->GetGeomPainter()->DrawOverlap(this, option);
00119 PrintInfo();
00120 }
00121
00122
00123 void TGeoOverlap::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00124 {
00125
00126 fVolume1->GetGeoManager()->GetGeomPainter()->ExecuteVolumeEvent(fVolume1, event, px, py);
00127 }
00128
00129
00130 void TGeoOverlap::Paint(Option_t *option)
00131 {
00132
00133 fVolume1->GetGeoManager()->GetGeomPainter()->PaintOverlap(this, option);
00134 }
00135
00136
00137 void TGeoOverlap::Print(Option_t *) const
00138 {
00139
00140 PrintInfo();
00141 printf(" - first volume: %s at position:\n", fVolume1->GetName());
00142 fMatrix1->Print();
00143 fVolume1->InspectShape();
00144 printf(" - second volume: %s at position:\n", fVolume2->GetName());
00145 fMatrix2->Print();
00146 fVolume2->InspectShape();
00147 }
00148
00149
00150 void TGeoOverlap::PrintInfo() const
00151 {
00152
00153 printf(" = Overlap %s: %s ovlp=%g\n", GetName(), GetTitle(),fOverlap);
00154 }
00155
00156
00157 void TGeoOverlap::SetNextPoint(Double_t x, Double_t y, Double_t z)
00158 {
00159
00160 fMarker->SetNextPoint(x,y,z);
00161 }
00162
00163
00164 void TGeoOverlap::SampleOverlap(Int_t npoints)
00165 {
00166
00167 Draw();
00168
00169 TPolyMarker3D *marker = 0;
00170 TGeoBBox *box = (TGeoBBox*)fVolume2->GetShape();
00171 Double_t dx = box->GetDX();
00172 Double_t dy = box->GetDY();
00173 Double_t dz = box->GetDZ();
00174 Double_t pt[3];
00175 Double_t master[3];
00176 const Double_t *orig = box->GetOrigin();
00177 Int_t ipoint = 0;
00178 Int_t itry = 0;
00179 Int_t iovlp = 0;
00180 while (ipoint < npoints) {
00181
00182 pt[0] = orig[0] - dx + 2.*dx*gRandom->Rndm();
00183 pt[1] = orig[1] - dy + 2.*dy*gRandom->Rndm();
00184 pt[2] = orig[2] - dz + 2.*dz*gRandom->Rndm();
00185 if (!fVolume2->Contains(pt)) {
00186 itry++;
00187 if (itry>10000 && !ipoint) {
00188 Error("SampleOverlap", "No point inside volume!!! - aborting");
00189 break;
00190 }
00191 continue;
00192 }
00193 ipoint++;
00194
00195 fMatrix2->LocalToMaster(pt, master);
00196 fMatrix1->MasterToLocal(master, pt);
00197 Bool_t in = fVolume1->Contains(pt);
00198 if (IsOverlap() && !in) continue;
00199 if (!IsOverlap() && in) continue;
00200
00201 iovlp++;
00202 if (!marker) {
00203 marker = new TPolyMarker3D();
00204 marker->SetMarkerColor(kRed);
00205 }
00206 marker->SetNextPoint(master[0], master[1], master[2]);
00207 }
00208 if (!iovlp) return;
00209 marker->Draw("SAME");
00210 gPad->Modified();
00211 gPad->Update();
00212 Double_t capacity = fVolume1->GetShape()->Capacity();
00213 capacity *= Double_t(iovlp)/Double_t(npoints);
00214 Double_t err = 1./TMath::Sqrt(Double_t(iovlp));
00215 Info("SampleOverlap", "#Overlap %s has %g +/- %g [cm3]",
00216 GetName(), capacity, err*capacity);
00217 }
00218
00219
00220 void TGeoOverlap::Sizeof3D() const
00221 {
00222
00223 fVolume1->GetShape()->Sizeof3D();
00224 fVolume2->GetShape()->Sizeof3D();
00225 }
00226
00227
00228 void TGeoOverlap::Validate() const
00229 {
00230
00231 Double_t point[3];
00232 Double_t local[3];
00233 Double_t safe1,safe2;
00234 Int_t npoints = fMarker->GetN();
00235 for (Int_t i=0; i<npoints; i++) {
00236 fMarker->GetPoint(i, point[0], point[1], point[2]);
00237 if (IsExtrusion()) {
00238 fMatrix1->MasterToLocal(point,local);
00239 safe1 = fVolume1->GetShape()->Safety(local, kFALSE);
00240 printf("point %d: safe1=%f\n", i, safe1);
00241 } else {
00242 fMatrix1->MasterToLocal(point,local);
00243 safe1 = fVolume1->GetShape()->Safety(local, kTRUE);
00244 fMatrix2->MasterToLocal(point,local);
00245 safe2 = fVolume2->GetShape()->Safety(local, kTRUE);
00246 printf("point %d: safe1=%f safe2=%f\n", i, safe1,safe2);
00247 }
00248 }
00249 }
00250
00251