CGEM BOSS 6.6.5.g
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: 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 || fType==9)
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 || fType==9) {
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 || fType==9) {
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 else if (fType == 9) { // Wang Liangliang for ideal tracking, Nov 2021
327 this->SetLineWidth(normalWidth);
328 this->SetLineColor(kOrange);
329 }
330
331 view->UpdateView(0);
332 gPad->Modified();
333 gPad->Update();
334 break;
335 }
336
337 TGeoTrack::ExecuteEvent(event, px, py);
338 }
339}
340
341//Long Peixun's update: Construct 3D line before draw it
343{
344 Double_t x,y,z,t;
345 fPolyLine3D = new TPolyLine3D(GetNpoints());
346 fPolyLine3D->SetBit(kCanDelete);
347 for (Int_t i = 0; i < GetNpoints(); i++)
348 {
349 GetPoint(i,x,y,z,t);
350 fPolyLine3D->SetPoint(i,x,y,z);
351 }
352 if (fType == 8) //Long Peixun's update: Change the color of MC truth tracks
353 {
354 fPolyLine3D->SetLineWidth(7);
355 fPolyLine3D->SetLineColor(kBlue);
356 }
357 else if(fType == 9)
358 {
359 fPolyLine3D->SetLineWidth(7);
360 fPolyLine3D->SetLineColor(kOrange);
361 }
362 else
363 {
364 fPolyLine3D->SetLineWidth(7); //Long Peixun's update: more wider
365 fPolyLine3D->SetLineColor(923); //Long Peixun's update: Red -> Black
366 }
367}
368
369void BesGeoTrack::Draw(Option_t *option)
370{
371 // Draw Polyline3D for OpenGL and X3d
372 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
373 if (view && view->GetViewType() & k3DView) {
374 //Long Peixun's update: Move these code to Construct3DLine()
376 fPolyLine3D->Draw(option);
377 }
378
379 //Long Peixun's update: The color of components in the track should be Red
380 for (Int_t i = 0; i < f3DHits.GetEntries(); ++i)
381 {
382 TGeoPhysicalNode* pHit = (TGeoPhysicalNode*)f3DHits.At(i);
383 if (pHit) pHit->SetLineColor(kRed);
384
385 }
386
387 if (!gPad) gGeoManager->GetMasterVolume()->Draw();
388 char *opt1 = Compress(option); // we will have to delete this ?
389 TString opt(opt1);
390 Bool_t is_default = kTRUE;
391 Bool_t is_onelevel = kFALSE;
392 Bool_t is_all = kFALSE;
393 Bool_t is_type = kFALSE;
394 if (opt.Contains("/D")) {
395 is_onelevel = kTRUE;
396 is_default = kFALSE;
397 }
398 if (opt.Contains("/*")) {
399 is_all = kTRUE;
400 is_default = kFALSE;
401 }
402 if (opt.Contains("/N")) {
403 is_type = kTRUE;
404 Int_t ist = opt.Index("/N")+2;
405 Int_t ilast = opt.Index("/",ist);
406 if (ilast<0) ilast=opt.Length();
407 TString type = opt(ist, ilast-ist);
408 gGeoManager->SetParticleName(type.Data());
409 }
410 SetBits(is_default, is_onelevel, is_all, is_type);
411 AppendPad("SAME");
412
413 delete [] opt1;
414 return;
415}
416
417void BesGeoTrack::Paint(Option_t *option)
418{
419 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
420 Double_t viewPhi = view->GetLongitude();
421 TVector3 viewVec(cos(viewPhi*TMath::DegToRad()), sin(viewPhi*TMath::DegToRad()), 0);
422 Double_t x, y, z, t;
423 Double_t x1=0.0, y1=0.0, z1=0.0;
424 Double_t dot, dotMin = 1e+20, dotTolerance = 0.01;
425 for (Int_t i = 1; i < GetNpoints(); i++) {
426 GetPoint(i, x, y, z, t);
427 TVector3 vec(x,y,0);
428 if (vec.Mag() > 5.0) {
429 vec.SetMag(1.0);
430 dot = fabs(vec.Dot(viewVec));
431 if ( dot < dotTolerance && dot < dotMin ) {
432 x1 = x;
433 y1 = y;
434 z1 = z;
435 dotMin = dot;
436 }
437 }
438 }
439
440 if (dotMin < 1e+20) {
441 BesMarker2D sectionPhi("trackPhi", "trackPhi", x1, y1, z1);
442 sectionPhi.SetMarkerStyle(28);
443 sectionPhi.SetMarkerColor(1);
444 sectionPhi.SetMarkerSize(2);
445 sectionPhi.Paint();
446 //sectionPhi paint the marker in origin point of MdcTrack!!!
447 }
448
449 if (fMarker) fMarker->Paint(option);
450 TGeoTrack::Paint(option);
451}
452
453//_____________________________________________________
454
455char *BesGeoTrack::GetObjectInfo(Int_t px, Int_t py) const {
456
457 BesView *view = dynamic_cast<BesView*>(gPad->GetView());
458 if (view) return view->GetObjectInfo(px, py);
459 else return TObject::GetObjectInfo(px, py);
460}
461
462void BesGeoTrack::SetCharge(Int_t charge)
463{
464 fCharge = charge;
465 if (fCharge > 0) this->SetLineColor(kBlack); // +
466 else if (fCharge < 0) this->SetLineColor(kBlack); // -
467 else this->SetLineColor(kGreen); // 0
468
469 if (fType == 9) // Wang Liangliang for ideal tracking, Nov 2021
470 this->SetLineColor(kOrange);
471}
472
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
Int_t fCharge
Definition: BesGeoTrack.h:51
TObjArray fHits
Definition: BesGeoTrack.h:45
virtual void CloseInfo()
Definition: BesGeoTrack.cxx:56
Int_t fType
Definition: BesGeoTrack.h:52
std::vector< TString > fInfoCon
Definition: BesGeoTrack.h:50
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
TObjArray f3DHits
Definition: BesGeoTrack.h:46
virtual void Construct3DLine()
virtual void SetMarker(Double_t x, Double_t y, Double_t z)
Definition: BesGeoTrack.cxx:70
TObjArray fClusters
Definition: BesGeoTrack.h:47
virtual void Paint(Option_t *option="")
BesMarker2D * fMarker
Definition: BesGeoTrack.h:59
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
TPolyLine3D * fPolyLine3D
Definition: BesGeoTrack.h:58
virtual void Init()
Definition: BesGeoTrack.cxx:45
BesPaveText * fTip
Definition: BesGeoTrack.h:57
virtual ~BesGeoTrack()
Definition: BesGeoTrack.cxx:36
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Definition: BesGeoTrack.cxx:98
Int_t fTrkID
Definition: BesGeoTrack.h:48
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:245
Bool_t GetVisMdcHitsGlobal()
Definition: BesView.h:214
Bool_t GetVisEmcHitsBarrel()
Definition: BesView.h:234
Bool_t GetVisEmcHitsGlobal()
Definition: BesView.h:232
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
Bool_t GetVisMdcHits()
Definition: BesView.h:215
Bool_t GetVisEmcHitsWest()
Definition: BesView.h:235
EBESViewType GetViewType()
Definition: BesView.h:74
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Definition: BesView.cxx:451
Bool_t GetVisTofHitsWest()
Definition: BesView.h:224
Bool_t GetVisTofHitsGlobal()
Definition: BesView.h:221
Bool_t GetVisCgemHitsClusters()
Definition: BesView.h:204
Bool_t GetVisEmcHitsEast()
Definition: BesView.h:233
Bool_t GetVisCgemHitsGlobal()
Definition: BesView.h:201
Bool_t GetVisTofHitsBarrel()
Definition: BesView.h:223
Bool_t GetVisTofHitsEast()
Definition: BesView.h:222
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