BOSS 7.1.0
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 //Long Peixun's update: remove "if"
40 delete fTip;
41 delete fPolyLine3D;
42 delete fMarker;
43}
44
46{
47 fTip = new BesPaveText(0, 0, 0.1, 0.1, "TL");
48 fPolyLine3D = 0; //Long Peixun's update
49 fMarker = 0;
50
51 //fHits.Clear("C");
52}
53
55{
56 if (fTip) {
57 fTip->SetText(fInfoCon);
58 }
59 else
60 cout << "BesGeoTrack::CloseInfo, not initialized" << endl;
61}
62
63void BesGeoTrack::AddPoint(Double_t x, Double_t y, Double_t z, Double_t t)
64{
65 TGeoTrack::AddPoint(x,y,z,t);
66}
67
68void BesGeoTrack::SetMarker(Double_t x, Double_t y, Double_t z)
69{
70 fMarker = new BesMarker2D("RecMarker", "RecMarker", x, y, z);
71
72 if (fType == 1) { // tof
73 fMarker->SetMarkerSizeMultiple(15); //Long Peixun's update: 20 -> 15
74 fMarker->SetMarkerStyle(5);
75 fMarker->SetMarkerColor(kBlack);
76 }
77 else if (fType == 2) { // emc
78 fMarker->SetMarkerSizeMultiple(15); //Long Peixun's update: 20 -> 15
79 fMarker->SetMarkerStyle(2);
80 fMarker->SetMarkerColor(kBlack);
81 }
82 else if (fType == 6) //Long Peixun's update: cluster in CGEM view
83 {
84 fMarker->SetMarkerSizeMultiple(1.1);
85 fMarker->SetMarkerStyle(4);
86 fMarker->SetMarkerColor(kBlack);
87 }
88 else if (fType == 7) //Long Peixun's update: cluster in CGEM UF view
89 {
90 fMarker->SetMarkerSizeMultiple(1.2);
91 fMarker->SetMarkerStyle(4);
92 fMarker->SetMarkerColor(kBlack);
93 }
94}
95
96Int_t BesGeoTrack::DistancetoPrimitive(Int_t px, Int_t py)
97{
98 Int_t dist = 9999;
99 Int_t cx, cy;
100 Double_t edge = 4.0; // edge width of track
101 Double_t markSizeRatio = 4.0; // 4.0 is approximate size.
102
103 if (fType == 1 || fType == 2 || fType == 6 || fType == 7) { // tof or emc or cgem
104 if (!fMarker) return dist;
105 fMarker->GetCenterPixel(cx, cy);
106 if (fType == 1) { // tof
107 Double_t r = sqrt( Double_t((px-cx)*(px-cx) + (py-cy)*(py-cy)) );
108 Double_t markerR = markSizeRatio*fMarker->GetMarkerSize();
109 if (markerR > 50) markerR = 50;
110 // if the size of a marker with type of circle is too large > 50 pixel, it could not be enlarged.
111 if ( fabs(r-markerR) < edge ) dist = 0;
112 }
113 //Long Peixun's update: consider cluster in CGEM view
114 else if (fType == 2 || fType == 6 || fType == 7) { // emc
115 Double_t dx = abs(px-cx), dy = abs(py-cy);
116 if ( fabs(dx) < edge && fabs(dy) < markSizeRatio*fMarker->GetMarkerSize() ||
117 fabs(dy) < edge && fabs(dx) < markSizeRatio*fMarker->GetMarkerSize() )
118 dist = 0;
119 }
120
121 return dist;
122 }
123 else return TGeoTrack::DistancetoPrimitive(px, py);
124}
125
126void BesGeoTrack::ExecuteEvent(Int_t event, Int_t px, Int_t py)
127{
128 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
129
130 if (gBesCursor->GetType() == kBesHand) {
131 if (view) view->ExecuteEvent(event, px, py);
132 }
133 else if (gBesCursor->GetType() == kBesPick){
134
135 if (gPad) gPad->SetCursor(kPointer);
136
137 Int_t width, color;
138 Int_t normalWidth = 1, hlWidth = 2;
139
140 switch (event) {
141 case kMouseEnter:
142 if (fType == 0) {
143 if (view->GetVisMdcHitsGlobal()) {
144 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
145 Mdc2DWire *aHit = (Mdc2DWire*)fHits.At(i);
146 if (aHit != 0) {
147 if (view->GetVisMdcHits()) {
148 aHit->SetHighlighted(true);
149 }
150 }
151 }
152 }
153 }
154 else if (fType == 1) {
155 if (view->GetVisTofHitsGlobal()) {
156 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
157 Tof2DScin *aHit = (Tof2DScin*)fHits.At(i);
158 if (aHit != 0) {
159 if ( aHit->GetPart() == 0 && view->GetVisTofHitsEast() ||
160 aHit->GetPart() == 1 && view->GetVisTofHitsBarrel() ||
161 aHit->GetPart() == 2 && view->GetVisTofHitsWest() ) {
162 aHit->SetHighlighted(true);
163 }
164 }
165 }
166 }
167 }
168 else if (fType == 2) {
169 if (view->GetVisEmcHitsGlobal()) {
170 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
171 Emc2DCrystal *aHit = (Emc2DCrystal*)fHits.At(i);
172 if (aHit != 0) {
173 if ( aHit->GetPart() == 0 && view->GetVisEmcHitsEast() ||
174 aHit->GetPart() == 1 && view->GetVisEmcHitsBarrel() ||
175 aHit->GetPart() == 2 && view->GetVisEmcHitsWest() ) {
176 aHit->SetHighlighted(true);
177 }
178 }
179 }
180 }
181 }
182 else if (fType == 3) {
183 if (view->GetVisMucHitsGlobal()) {
184 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
185 Muc2DStrip *aHit = (Muc2DStrip*)fHits.At(i);
186 if (aHit != 0) {
187 if (view->GetVisMucHitsGlobal()) {
188 aHit->SetHighlighted(true);
189 }
190 }
191 }
192 }
193 }
194
195
196 if (fType == 0) {
197 width = this->GetLineWidth();
198 color = this->GetLineColor();
199 this->SetLineWidth(hlWidth);
200 this->SetLineColor(kRed);
201 }
202 else if (fType == 1) {
203 fMarker->SetMarkerColor(kMagenta);
204 }
205 else if (fType == 2) {
206 fMarker->SetMarkerColor(kMagenta);
207 }
208 else if (fType == 3) {
209 width = this->GetLineWidth();
210 color = this->GetLineColor();
211 this->SetLineWidth(hlWidth);
212 this->SetLineColor(kRed);
213 }
214 else if (fType == 4) {
215 this->SetLineWidth(hlWidth);
216 this->SetLineColor(kBlue);
217 }
218 else if (fType == 6 || fType == 7) //Long Peixun's update: for clusters in CGEM
219 {
220 fMarker->SetMarkerColor(kViolet);
221 fMarker->SetMarkerStyle(8);
222 }
223
224 fTip->SetPos(px, py);
225 view->UpdateView(0);
226
227 //yzhang 2011-11-15 TEMP
228 //drawHeader(fTip->GetText);
229 if (gBesCursor->GetShowInfo()) fTip->Draw("TL,SAME"); // "BR,ARC,SAME"
230 gPad->Modified();
231 gPad->Update();
232 break;
233
234 case kMouseLeave:
235 if (fType == 0) {
236 for (Int_t i = 0; i < (Int_t)fHits.GetEntries(); i++) {
237 Mdc2DWire *aHit = (Mdc2DWire*)fHits.At(i);
238 if (aHit != 0 && aHit->IsHighlighted()) {
239 aHit->SetHighlighted(false);
240 }
241 }
242 }
243 else if (fType == 1) {
244 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
245 Tof2DScin *aHit = (Tof2DScin*)fHits.At(i);
246 if (aHit != 0 && aHit->IsHighlighted()) {
247 aHit->SetHighlighted(false);
248 }
249 }
250 }
251 else if (fType == 2) {
252 for (Int_t i = 0; i < fHits.GetEntries(); i++) {
253 Emc2DCrystal *aHit = (Emc2DCrystal*)fHits.At(i);
254 if (aHit != 0 && aHit->IsHighlighted()) {
255 aHit->SetHighlighted(false);
256 }
257 }
258 }
259 else if (fType == 3) {
260 for (Int_t i = 0; i < (Int_t)fHits.GetEntries(); i++) {
261 Muc2DStrip *aHit = (Muc2DStrip*)fHits.At(i);
262 if (aHit != 0 && aHit->IsHighlighted()) {
263 aHit->SetHighlighted(false);
264 }
265 }
266 }
267
268
269 if (fType == 0) {
270 this->SetLineWidth(normalWidth);
271 this->SetLineColor(kBlack);
272 }
273 else if (fType == 1) {
274 fMarker->SetMarkerColor(kBlack);
275 }
276 else if (fType == 2) {
277 fMarker->SetMarkerColor(kBlack);
278 }
279 else if (fType == 3) {
280 this->SetLineWidth(normalWidth);
281 this->SetLineColor(kBlack);
282 }
283 else if (fType == 4) {
284 this->SetLineWidth(normalWidth);
285 this->SetLineColor(kBlack);
286 }
287 else if (fType == 6 || fType == 7) //Long Peixun's update: for clusters in CGEM
288 {
289 fMarker->SetMarkerColor(kBlack);
290 fMarker->SetMarkerStyle(4);
291 }
292
293 view->UpdateView(0);
294 gPad->Modified();
295 gPad->Update();
296 break;
297 }
298
299 TGeoTrack::ExecuteEvent(event, px, py);
300 }
301}
302
303//Long Peixun's update: Construct 3D line before draw it
305{
306 Double_t x,y,z,t;
307 fPolyLine3D = new TPolyLine3D(GetNpoints());
308 fPolyLine3D->SetBit(kCanDelete);
309 for (Int_t i = 0; i < GetNpoints(); i++)
310 {
311 GetPoint(i,x,y,z,t);
312 fPolyLine3D->SetPoint(i,x,y,z);
313 }
314 fPolyLine3D->SetLineWidth(5);
315 fPolyLine3D->SetLineColor(897); //Long Peixun's update: Red -> Red with a bit purple
316}
317
318void BesGeoTrack::Draw(Option_t *option)
319{
320 // Draw Polyline3D for OpenGL and X3d
321 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
322 if (view && view->GetViewType() & k3DView) {
323 //Long Peixun's update: Move these code to Construct3DLine()
325 fPolyLine3D->Draw(option);
326 }
327
328 //Long Peixun's update: The color of components in the track should be Red
329 for (Int_t i = 0; i < f3DHits.GetEntries(); ++i)
330 {
331 TGeoPhysicalNode* pHit = (TGeoPhysicalNode*)f3DHits.At(i);
332 if (pHit) pHit->SetLineColor(kRed);
333
334 }
335
336 if (!gPad) gGeoManager->GetMasterVolume()->Draw();
337 char *opt1 = Compress(option); // we will have to delete this ?
338 TString opt(opt1);
339 Bool_t is_default = kTRUE;
340 Bool_t is_onelevel = kFALSE;
341 Bool_t is_all = kFALSE;
342 Bool_t is_type = kFALSE;
343 if (opt.Contains("/D")) {
344 is_onelevel = kTRUE;
345 is_default = kFALSE;
346 }
347 if (opt.Contains("/*")) {
348 is_all = kTRUE;
349 is_default = kFALSE;
350 }
351 if (opt.Contains("/N")) {
352 is_type = kTRUE;
353 Int_t ist = opt.Index("/N")+2;
354 Int_t ilast = opt.Index("/",ist);
355 if (ilast<0) ilast=opt.Length();
356 TString type = opt(ist, ilast-ist);
357 gGeoManager->SetParticleName(type.Data());
358 }
359 SetBits(is_default, is_onelevel, is_all, is_type);
360 AppendPad("SAME");
361
362 delete [] opt1;
363 return;
364}
365
366void BesGeoTrack::Paint(Option_t *option)
367{
368 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
369 Double_t viewPhi = view->GetLongitude();
370 TVector3 viewVec(cos(viewPhi*TMath::DegToRad()), sin(viewPhi*TMath::DegToRad()), 0);
371 Double_t x, y, z, t;
372 Double_t x1=0.0, y1=0.0, z1=0.0;
373 Double_t dot, dotMin = 1e+20, dotTolerance = 0.01;
374 for (Int_t i = 1; i < GetNpoints(); i++) {
375 GetPoint(i, x, y, z, t);
376 TVector3 vec(x,y,0);
377 if (vec.Mag() > 5.0) {
378 vec.SetMag(1.0);
379 dot = fabs(vec.Dot(viewVec));
380 if ( dot < dotTolerance && dot < dotMin ) {
381 x1 = x;
382 y1 = y;
383 z1 = z;
384 dotMin = dot;
385 }
386 }
387 }
388
389 if (dotMin < 1e+20) {
390 BesMarker2D sectionPhi("trackPhi", "trackPhi", x1, y1, z1);
391 sectionPhi.SetMarkerStyle(28);
392 sectionPhi.SetMarkerColor(1);
393 sectionPhi.SetMarkerSize(2);
394 sectionPhi.Paint();
395 //sectionPhi paint the marker in origin point of MdcTrack!!!
396 }
397
398 if (fMarker) fMarker->Paint(option);
399 TGeoTrack::Paint(option);
400}
401
402//_____________________________________________________
403
404char *BesGeoTrack::GetObjectInfo(Int_t px, Int_t py) const {
405
406 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
407 if (view) return view->GetObjectInfo(px, py);
408 else return TObject::GetObjectInfo(px, py);
409}
410
412{
413 fCharge = charge;
414 if (fCharge > 0) this->SetLineColor(kBlack); // +
415 else if (fCharge < 0) this->SetLineColor(kBlack); // -
416 else this->SetLineColor(kGreen); // 0
417}
418
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:17
gr1 SetLineColor(1)
Double_t x[10]
gr SetLineWidth(2)
TTree * t
Definition: binning.cxx:23
Bool_t GetShowInfo()
Definition: BesCursor.h:35
EBESCursorType GetType()
Definition: BesCursor.h:32
virtual void CloseInfo()
Definition: BesGeoTrack.cxx:54
virtual void Draw(Option_t *option="")
virtual void AddPoint(Double_t x, Double_t y, Double_t z, Double_t t)
Definition: BesGeoTrack.cxx:63
virtual char * GetObjectInfo(Int_t px, Int_t py) const
virtual void Construct3DLine()
virtual void SetMarker(Double_t x, Double_t y, Double_t z)
Definition: BesGeoTrack.cxx:68
virtual void Paint(Option_t *option="")
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual void Init()
Definition: BesGeoTrack.cxx:45
virtual ~BesGeoTrack()
Definition: BesGeoTrack.cxx:36
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Definition: BesGeoTrack.cxx:96
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:86
Double_t GetLongitude()
Definition: BesTView.h:95
Bool_t GetVisMucHitsGlobal()
Definition: BesView.h:224
Bool_t GetVisMdcHitsGlobal()
Definition: BesView.h:193
Bool_t GetVisEmcHitsBarrel()
Definition: BesView.h:213
Bool_t GetVisEmcHitsGlobal()
Definition: BesView.h:211
virtual void UpdateView(Bool_t resetview=kFALSE)
Definition: BesView.cxx:657
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Definition: BesView.cxx:869
Bool_t GetVisMdcHits()
Definition: BesView.h:194
Bool_t GetVisEmcHitsWest()
Definition: BesView.h:214
EBESViewType GetViewType()
Definition: BesView.h:71
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: BesView.cxx:366
Bool_t GetVisTofHitsWest()
Definition: BesView.h:203
Bool_t GetVisTofHitsGlobal()
Definition: BesView.h:200
Bool_t GetVisEmcHitsEast()
Definition: BesView.h:212
Bool_t GetVisTofHitsBarrel()
Definition: BesView.h:202
Bool_t GetVisTofHitsEast()
Definition: BesView.h:201
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
double y[1000]
float charge