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