BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
BesGeoTrack.cxx
Go to the documentation of this file.
1#include <TPad.h>
2#include <TVector3.h>
3#include <TGeoManager.h>
4#include "math.h"
5#include <TMath.h>
6
7#include <iostream>
8
10#include "BesVisLib/BesView.h"
12#include "BesVisLib/Mdc2DWire.h"
14#include "BesVisLib/BesCursor.h"
15
16using namespace std;
17
18#ifndef __CINT__
20#endif
21//int BesGeoTrack::count = 0;
23 : TGeoTrack()
24{
25// std::cout << "co BesGeoTrack: " << ++count << std::endl;
26 Init();
27}
28
29BesGeoTrack::BesGeoTrack(Int_t id, Int_t pdgcode, TVirtualGeoTrack *parent, TObject *particle)
30 : TGeoTrack(id, pdgcode, parent, particle)
31{
32// std::cout << "co BesGeoTrack: " << ++count << std::endl;
33 Init();
34}
35
37{
38// std::cout << "de BesGeoTrack: " << --count << std::endl;
39 if (fTip) delete fTip;
40 if (fPolyLine3D) delete fPolyLine3D;
41 if (fMarker) delete fMarker;
42}
43
45{
46 fTip = new BesPaveText(0, 0, 0.1, 0.1, "TL");
47
48 fMarker = 0;
49
50 //fHits.Clear("C");
51}
52
54{
55 if (fTip) {
56 fTip->SetText(fInfoCon);
57 }
58 else
59 cout << "BesGeoTrack::CloseInfo, not initialized" << endl;
60}
61
62void BesGeoTrack::AddPoint(Double_t x, Double_t y, Double_t z, Double_t t)
63{
64 TGeoTrack::AddPoint(x,y,z,t);
65}
66
67void BesGeoTrack::SetMarker(Double_t x, Double_t y, Double_t z)
68{
69 fMarker = new BesMarker2D("RecMarker", "RecMarker", x, y, z);
70
71 if (fType == 1) { // tof
72 fMarker->SetMarkerSizeMultiple(20);
73 fMarker->SetMarkerStyle(5);
74 fMarker->SetMarkerColor(kBlack);
75 }
76 else if (fType == 2) { // emc
77 fMarker->SetMarkerSizeMultiple(20);
78 fMarker->SetMarkerStyle(2);
79 fMarker->SetMarkerColor(kBlack);
80 }
81}
82
83Int_t BesGeoTrack::DistancetoPrimitive(Int_t px, Int_t py)
84{
85 Int_t dist = 9999;
86 Int_t cx, cy;
87 Double_t edge = 4.0; // edge width of track
88 Double_t markSizeRatio = 4.0; // 4.0 is approximate size.
89
90 if (fType == 1 || fType == 2) { // tof or emc
91 if (!fMarker) return dist;
92 fMarker->GetCenterPixel(cx, cy);
93 if (fType == 1) { // tof
94 Double_t r = sqrt( Double_t((px-cx)*(px-cx) + (py-cy)*(py-cy)) );
95 Double_t markerR = markSizeRatio*fMarker->GetMarkerSize();
96 if (markerR > 50) markerR = 50;
97 // if the size of a marker with type of circle is too large > 50 pixel, it could not be enlarged.
98 if ( fabs(r-markerR) < edge ) dist = 0;
99 }
100 else if (fType == 2) { // emc
101 Double_t dx = abs(px-cx), dy = abs(py-cy);
102 if ( fabs(dx) < edge && fabs(dy) < markSizeRatio*fMarker->GetMarkerSize() ||
103 fabs(dy) < edge && fabs(dx) < markSizeRatio*fMarker->GetMarkerSize() )
104 dist = 0;
105 }
106
107 return dist;
108 }
109 else return TGeoTrack::DistancetoPrimitive(px, py);
110}
111
112void BesGeoTrack::ExecuteEvent(Int_t event, Int_t px, Int_t py)
113{
114 BesView *view = (BesView*)gPad->GetView();
115
116 if (gBesCursor->GetType() == kBesHand) {
117 if (view) view->ExecuteEvent(event, px, py);
118 }
119 else if (gBesCursor->GetType() == kBesPick){
120
121 if (gPad) gPad->SetCursor(kPointer);
122
123 Int_t width, color;
124 Int_t normalWidth = 1, hlWidth = 2;
125
126 switch (event) {
127 case kMouseEnter:
128 if (fType == 0) {
129 if (view->GetVisMdcHitsGlobal()) {
130 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
131 Mdc2DWire *aHit = (Mdc2DWire*)fHits.At(i);
132 if (aHit != 0) {
133 if (view->GetVisMdcHits()) {
134 aHit->SetHighlighted(true);
135 }
136 }
137 }
138 }
139 }
140 else if (fType == 1) {
141 if (view->GetVisTofHitsGlobal()) {
142 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
143 Tof2DScin *aHit = (Tof2DScin*)fHits.At(i);
144 if (aHit != 0) {
145 if ( aHit->GetPart() == 0 && view->GetVisTofHitsEast() ||
146 aHit->GetPart() == 1 && view->GetVisTofHitsBarrel() ||
147 aHit->GetPart() == 2 && view->GetVisTofHitsWest() ) {
148 aHit->SetHighlighted(true);
149 }
150 }
151 }
152 }
153 }
154 else if (fType == 2) {
155 if (view->GetVisEmcHitsGlobal()) {
156 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
157 Emc2DCrystal *aHit = (Emc2DCrystal*)fHits.At(i);
158 if (aHit != 0) {
159 if ( aHit->GetPart() == 0 && view->GetVisEmcHitsEast() ||
160 aHit->GetPart() == 1 && view->GetVisEmcHitsBarrel() ||
161 aHit->GetPart() == 2 && view->GetVisEmcHitsWest() ) {
162 aHit->SetHighlighted(true);
163 }
164 }
165 }
166 }
167 }
168 else if (fType == 3) {
169 if (view->GetVisMucHitsGlobal()) {
170 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
171 Muc2DStrip *aHit = (Muc2DStrip*)fHits.At(i);
172 if (aHit != 0) {
173 if (view->GetVisMucHitsGlobal()) {
174 aHit->SetHighlighted(true);
175 }
176 }
177 }
178 }
179 }
180
181
182 if (fType == 0) {
183 width = this->GetLineWidth();
184 color = this->GetLineColor();
185 this->SetLineWidth(hlWidth);
186 this->SetLineColor(kRed);
187 }
188 else if (fType == 1) {
189 fMarker->SetMarkerColor(kMagenta);
190 }
191 else if (fType == 2) {
192 fMarker->SetMarkerColor(kMagenta);
193 }
194 else if (fType == 3) {
195 width = this->GetLineWidth();
196 color = this->GetLineColor();
197 this->SetLineWidth(hlWidth);
198 this->SetLineColor(kRed);
199 }
200 else if (fType == 4) {
201 this->SetLineWidth(hlWidth);
202 this->SetLineColor(kBlue);
203 }
204
205 fTip->SetPos(px, py);
206 view->UpdateView(0);
207
208 //yzhang 2011-11-15 TEMP
209 //drawHeader(fTip->GetText);
210 if (gBesCursor->GetShowInfo()) fTip->Draw("TL,SAME"); // "BR,ARC,SAME"
211 gPad->Modified();
212 gPad->Update();
213 break;
214
215 case kMouseLeave:
216 if (fType == 0) {
217 for (Int_t i = 0; i < (Int_t)fHits.GetEntries(); i++) {
218 Mdc2DWire *aHit = (Mdc2DWire*)fHits.At(i);
219 if (aHit != 0 && aHit->IsHighlighted()) {
220 aHit->SetHighlighted(false);
221 }
222 }
223 }
224 else if (fType == 1) {
225 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
226 Tof2DScin *aHit = (Tof2DScin*)fHits.At(i);
227 if (aHit != 0 && aHit->IsHighlighted()) {
228 aHit->SetHighlighted(false);
229 }
230 }
231 }
232 else if (fType == 2) {
233 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
234 Emc2DCrystal *aHit = (Emc2DCrystal*)fHits.At(i);
235 if (aHit != 0 && aHit->IsHighlighted()) {
236 aHit->SetHighlighted(false);
237 }
238 }
239 }
240 else if (fType == 3) {
241 for (Int_t i = 0; i < (Int_t)fHits.GetEntries(); i++) {
242 Muc2DStrip *aHit = (Muc2DStrip*)fHits.At(i);
243 if (aHit != 0 && aHit->IsHighlighted()) {
244 aHit->SetHighlighted(false);
245 }
246 }
247 }
248
249
250 if (fType == 0) {
251 this->SetLineWidth(normalWidth);
252 this->SetLineColor(kBlack);
253 }
254 else if (fType == 1) {
255 fMarker->SetMarkerColor(kBlack);
256 }
257 else if (fType == 2) {
258 fMarker->SetMarkerColor(kBlack);
259 }
260 else if (fType == 3) {
261 this->SetLineWidth(normalWidth);
262 this->SetLineColor(kBlack);
263 }
264 else if (fType == 4) {
265 this->SetLineWidth(normalWidth);
266 this->SetLineColor(kBlack);
267 }
268
269 view->UpdateView(0);
270 gPad->Modified();
271 gPad->Update();
272 break;
273 }
274
275 TGeoTrack::ExecuteEvent(event, px, py);
276 }
277}
278
279void BesGeoTrack::Draw(Option_t *option)
280{
281 // Draw Polyline3D for OpenGL and X3d
282 BesView *view = (BesView*)gPad->GetView();
283 if (view && view->GetViewType() & k3DView) {
284 Double_t x,y,z,t;
285 fPolyLine3D = new TPolyLine3D(GetNpoints());
286 for (Int_t i = 0; i < GetNpoints(); i++) {
287 GetPoint(i,x,y,z,t);
288 fPolyLine3D->SetPoint(i,x,y,z);
289 }
290 fPolyLine3D->SetBit(kCanDelete);
291
292 fPolyLine3D->SetLineWidth(5);
293 fPolyLine3D->SetLineColor(kRed);
294 fPolyLine3D->Draw(option);
295 }
296
297 if (!gPad) gGeoManager->GetMasterVolume()->Draw();
298 char *opt1 = Compress(option); // we will have to delete this ?
299 TString opt(opt1);
300 Bool_t is_default = kTRUE;
301 Bool_t is_onelevel = kFALSE;
302 Bool_t is_all = kFALSE;
303 Bool_t is_type = kFALSE;
304 if (opt.Contains("/D")) {
305 is_onelevel = kTRUE;
306 is_default = kFALSE;
307 }
308 if (opt.Contains("/*")) {
309 is_all = kTRUE;
310 is_default = kFALSE;
311 }
312 if (opt.Contains("/N")) {
313 is_type = kTRUE;
314 Int_t ist = opt.Index("/N")+2;
315 Int_t ilast = opt.Index("/",ist);
316 if (ilast<0) ilast=opt.Length();
317 TString type = opt(ist, ilast-ist);
318 gGeoManager->SetParticleName(type.Data());
319 }
320 SetBits(is_default, is_onelevel, is_all, is_type);
321 AppendPad("SAME");
322
323 delete [] opt1;
324 return;
325}
326
327void BesGeoTrack::Paint(Option_t *option)
328{
329 BesView *view = (BesView*)gPad->GetView();
330 Double_t viewPhi = view->GetLongitude();
331 TVector3 viewVec(cos(viewPhi*TMath::DegToRad()), sin(viewPhi*TMath::DegToRad()), 0);
332 Double_t x, y, z, t;
333 Double_t x1=0.0, y1=0.0, z1=0.0;
334 Double_t dot, dotMin = 1e+20, dotTolerance = 0.01;
335 for (Int_t i = 1; i < GetNpoints(); i++) {
336 GetPoint(i, x, y, z, t);
337 TVector3 vec(x,y,0);
338 if (vec.Mag() > 5.0) {
339 vec.SetMag(1.0);
340 dot = fabs(vec.Dot(viewVec));
341 if ( dot < dotTolerance && dot < dotMin ) {
342 x1 = x;
343 y1 = y;
344 z1 = z;
345 dotMin = dot;
346 }
347 }
348 }
349
350 if (dotMin < 1e+20) {
351 BesMarker2D sectionPhi("trackPhi", "trackPhi", x1, y1, z1);
352 sectionPhi.SetMarkerStyle(28);
353 sectionPhi.SetMarkerColor(1);
354 sectionPhi.SetMarkerSize(2);
355 sectionPhi.Paint();
356 //sectionPhi paint the marker in origin point of MdcTrack!!!
357 }
358
359 if (fMarker) fMarker->Paint(option);
360 TGeoTrack::Paint(option);
361}
362
363//_____________________________________________________
364
365char *BesGeoTrack::GetObjectInfo(Int_t px, Int_t py) const {
366
367 BesView *view = (BesView*)gPad->GetView();
368 if (view) return view->GetObjectInfo(px, py);
369 else return TObject::GetObjectInfo(px, py);
370}
371
372void BesGeoTrack::SetCharge(Int_t charge)
373{
374 fCharge = charge;
375 if (fCharge > 0) this->SetLineColor(kBlack); // +
376 else if (fCharge < 0) this->SetLineColor(kBlack); // -
377 else this->SetLineColor(kGreen); // 0
378}
379
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
@ kBesHand
Definition: BesCursor.h:15
@ kBesPick
Definition: BesCursor.h:14
R__EXTERN BesCursor * gBesCursor
Definition: BesCursor.h:40
ClassImp(BesGeoTrack) BesGeoTrack
Definition: BesGeoTrack.cxx:19
@ k3DView
Definition: BesStatus.h:14
g1 SetLineColor(2)
Double_t x[10]
gr SetLineWidth(2)
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
Bool_t GetShowInfo()
Definition: BesCursor.h:35
EBESCursorType GetType()
Definition: BesCursor.h:32
virtual void CloseInfo()
Definition: BesGeoTrack.cxx:53
virtual void Draw(Option_t *option="")
virtual void AddPoint(Double_t x, Double_t y, Double_t z, Double_t t)
Definition: BesGeoTrack.cxx:62
virtual char * GetObjectInfo(Int_t px, Int_t py) const
virtual void SetMarker(Double_t x, Double_t y, Double_t z)
Definition: BesGeoTrack.cxx:67
virtual void Paint(Option_t *option="")
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual void Init()
Definition: BesGeoTrack.cxx:44
virtual ~BesGeoTrack()
Definition: BesGeoTrack.cxx:36
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Definition: BesGeoTrack.cxx:83
virtual void SetCharge(Int_t charge)
virtual void GetCenterPixel(Int_t &px, Int_t &py)
Definition: BesMarker2D.cxx:81
virtual void SetMarkerSizeMultiple(Int_t input)
Definition: BesMarker2D.h:34
virtual void Paint(Option_t *option="")
virtual void SetText(std::vector< TString > infoCon)
Definition: BesPaveText.cxx:35
virtual void SetPos(Int_t px, Int_t py)
Definition: BesPaveText.cxx:76
Double_t GetLongitude()
Definition: BesTView.h:95
Bool_t GetVisMucHitsGlobal()
Definition: BesView.h:193
Bool_t GetVisMdcHitsGlobal()
Definition: BesView.h:162
Bool_t GetVisEmcHitsBarrel()
Definition: BesView.h:182
Bool_t GetVisEmcHitsGlobal()
Definition: BesView.h:180
virtual void UpdateView(Bool_t resetview=kFALSE)
Definition: BesView.cxx:598
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition: BesView.cxx:800
Bool_t GetVisMdcHits()
Definition: BesView.h:163
Bool_t GetVisEmcHitsWest()
Definition: BesView.h:183
EBESViewType GetViewType()
Definition: BesView.h:65
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: BesView.cxx:365
Bool_t GetVisTofHitsWest()
Definition: BesView.h:172
Bool_t GetVisTofHitsGlobal()
Definition: BesView.h:169
Bool_t GetVisEmcHitsEast()
Definition: BesView.h:181
Bool_t GetVisTofHitsBarrel()
Definition: BesView.h:171
Bool_t GetVisTofHitsEast()
Definition: BesView.h:170
virtual void SetHighlighted(bool status=true)
Definition: Emc2DCrystal.h:30
virtual Int_t GetPart()
Definition: Emc2DCrystal.h:49
virtual bool IsHighlighted()
Definition: Emc2DCrystal.h:32
virtual void SetHighlighted(bool status=true)
Definition: Mdc2DWire.h:32
virtual bool IsHighlighted()
Definition: Mdc2DWire.h:34
virtual void SetHighlighted(bool status=true)
Definition: Muc2DStrip.h:30
virtual bool IsHighlighted()
Definition: Muc2DStrip.h:32
virtual Int_t GetPart()
Definition: Tof2DScin.h:49
virtual void SetHighlighted(bool status=true)
Definition: Tof2DScin.h:30
virtual bool IsHighlighted()
Definition: Tof2DScin.h:32
dble_vec_t vec[12]
Definition: ranlxd.c:372
int t()
Definition: t.c:1