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