BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Mdc2DWire.cxx
Go to the documentation of this file.
1#include "BesVisLib/Mdc2DWire.h"
2#include "BesVisLib/BesCursor.h"
3#include "BesVisLib/BesView.h"
4#include "TMath.h"
5#include "math.h"
6#include <TColor.h>
7#include <TString.h>
8#include <iostream>
9
10using namespace std;
11
12#ifndef __CINT__
14#endif
15
16 //_____________________________________________________
17
19}
20
21//_____________________________________________________
22
23Mdc2DWire::Mdc2DWire( const char* name, const char* title, Double_t rmin, Double_t rmax,
24 Double_t dz, Double_t phi, Double_t* center ) {
25
26 SetName( name );
27 SetTitle( title );
28 fTip = 0;
29 fTube = 0; // Long Peixun's update: Add fTube initialization
30 fHighlighted = false;
31 fFired = false;
32 fColorfulWire = false;
33 fWireType = 1; // axial wire
34 evTime = 0;
35
36 Double_t r = 0.25 * ( rmax - rmin );
37 fWireCircle = new BesCircle2D( name, title, 0.0, r, &center[0] );
38
39 Double_t dx = fabs( r * cos( phi ) );
40 Double_t dy = fabs( r * sin( phi ) );
41 Double_t P[12] = { center[0] - dx, center[1] - dy, center[2] - dz, center[0] + dx,
42 center[1] + dy, center[2] - dz, center[0] - dx, center[1] - dy,
43 center[2] + dz, center[0] + dx, center[1] + dy, center[2] + dz };
44
45 fWireCone = new BesPolygon2D( name, title, 4, P );
46
47 Init();
48}
49
50//_____________________________________________________
51
52Mdc2DWire::Mdc2DWire( const char* name, const char* title, Int_t N, Double_t* P ) {
53 SetName( name );
54 SetTitle( title );
55 fTip = 0;
56 fHighlighted = false;
57 fFired = false;
58 fColorfulWire = false;
59 fWireType = 2; // stereo wire
60
61 Double_t* tubeP = &P[3 * N / 2]; // east four points, P4~P7
62 fTube = new BesPolygon2D( name, title, N / 2, tubeP );
63 fWireCircle = 0;
64 fWireCone = 0;
65
66 for ( Int_t i = 0; i < 3; i++ )
67 {
68 fWestHole[i] = ( P[i] + P[3 + i] + P[6 + i] + P[9 + i] ) / 4.0; // (P0+P1+P2+P3)/4
69 fEastHole[i] = ( P[12 + i] + P[15 + i] + P[18 + i] + P[21 + i] ) / 4.0; // (P4+P5+P6+P7)/4
70 }
71 TVector3 westVec( fWestHole[0], fWestHole[1], fWestHole[2] );
72 TVector3 eastVec( fEastHole[0], fEastHole[1], fEastHole[2] );
73 fWestPhi = westVec.Phi() * TMath::RadToDeg();
74 fEastPhi = eastVec.Phi() * TMath::RadToDeg();
75 if ( fWestPhi < 0.0 ) fWestPhi += 360.0;
76 if ( fEastPhi < 0.0 ) fEastPhi += 360.0;
77
78 // ------XY------
79 Double_t rMax = sqrt( ( P[4 * 3] - P[7 * 3] ) * ( P[4 * 3] - P[7 * 3] ) +
80 ( P[4 * 3 + 1] - P[7 * 3 + 1] ) * ( P[4 * 3 + 1] - P[7 * 3 + 1] ) +
81 ( P[4 * 3 + 2] - P[7 * 3 + 2] ) * ( P[4 * 3 + 2] - P[7 * 3 + 2] ) ) /
82 2.0;
83
84 Double_t rMinRatio = 0.0001; // min bubble radius = rMinRatio * rMax;
85 Double_t rMaxRatio = 0.8; // 0.6; // 0.4//yzhang
86
87 Double_t newP[12];
88 Double_t edge = rMaxRatio * 0.0001; //*0.85
89 for ( Int_t i = 0; i < 3; i++ )
90 {
91 newP[i] =
92 ( 0.5 + edge * rMinRatio ) * ( P[i] + P[3 + i] ) * 0.5 +
93 ( 0.5 - edge * rMinRatio ) * ( P[6 + i] + P[9 + i] ) * 0.5; // near center of P0+P1
94 newP[3 + i] =
95 ( 0.5 - edge * rMinRatio ) * ( P[i] + P[3 + i] ) * 0.5 +
96 ( 0.5 + edge * rMinRatio ) * ( P[6 + i] + P[9 + i] ) * 0.5; // near center of P2+P3
97 newP[6 + i] =
98 ( 0.5 + edge * rMaxRatio ) * ( P[12 + i] + P[15 + i] ) * 0.5 +
99 ( 0.5 - edge * rMaxRatio ) * ( P[18 + i] + P[21 + i] ) * 0.5; // near center of P4+P5
100 newP[9 + i] =
101 ( 0.5 - edge * rMaxRatio ) * ( P[12 + i] + P[15 + i] ) * 0.5 +
102 ( 0.5 + edge * rMaxRatio ) * ( P[18 + i] + P[21 + i] ) * 0.5; // near center of P6+P7
103 }
104 fWireCone = new BesPolygon2D( "WireCone", "WireCone", 4, &newP[0] );
105
106 fWireCircle =
107 new BesCircle2D( "WireBubble", "WireBubble", 0.0, rMaxRatio * rMax, &fEastHole[0] );
108
109 // ------ZR------
110 fZRPosMarker2D =
111 new BesMarker2D( "MdcZRPos", "MdcZRPos", fEastHole[0], fEastHole[1], fEastHole[2] );
112
113 Init();
114}
115
116//_____________________________________________________
117
119
120 // Long Peixun's update: remove "if"
121 delete fTube;
122 delete fWireCircle;
123 delete fWireCone;
124 delete fZRPosMarker2D;
125 delete fTip;
126}
127
128//_____________________________________________________
129
131
132 SetStyle();
133
134 fTip = new BesPaveText( 0, 0, 0.1, 0.1 );
135 CloseInfo();
136}
137
138//_____________________________________________________
139
141 lcTube = kBlack; // grey;
142 lwTube = 1;
143 fcTube = kBlack; // grey 15;
144 fsTube = 4000;
145
146 lcWire = 15;
147 if ( fWireType == 1 ) lcWire = kGreen;
148 if ( fWireType == 2 ) lcWire = kBlue;
149 lwCircle = 1;
150 lwCone = 1;
151 fcCircle = kWhite;
152 fcCone = 0;
153 fsCircle = 1001;
154 fsCone = 0;
155
156 lcWireFired = kRed;
157 lwCircleFired = 2; // yzhang 2;
158 lwConeFired = 2;
159 fcCircleFired = 9004; // kBlack;
160 fcConeFired = kBlack;
161 fsCircleFired = 1001; // solid
162 fsConeFired = 3001;
163
164 lcWireHL = kMagenta; // yzhang lcWire;
165 lwCircleHL = 2;
166 lwConeHL = 2;
167 fcCircleHL = kMagenta; // yzhang kBlack;
168 fcConeHL = kRed;
169 fsCircleHL = 1001;
170 fsConeHL = 4000;
171
172 sizeMarker = 4;
173 cMarker = kBlue;
174 cMarkerFired = kRed; // color of fired marker
175 cMarkerHL = cMarker; // cMarkerFired;
176 sMarker = 24;
177 sMarkerFired = 20; // style of fired marker
178 sMarkerHL = 25; // style of highlighted marker
179}
180
182 fInfoCon.clear();
183 fTip->DeleteText();
184}
185
187 if ( fTip )
188 {
189 fTip->Clear();
190
191 if ( fInfoCon.size() == 0 ) fInfoCon.push_back( GetTitle() );
192 fTip->SetText( fInfoCon );
193 }
194 else cout << "Mdc2DWire::CloseInfo, not initialized" << endl;
195}
196
197//_____________________________________________________
198
199Int_t Mdc2DWire::DistancetoPrimitive( Int_t px, Int_t py ) {
200 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
201 if ( view->GetViewType() & kXYView ) { return fWireCircle->DistancetoPrimitive( px, py ); }
202 else if ( view->GetViewType() & kZRView )
203 {
204 if ( fZRPosMarker2D )
205 {
206 // Long Peixun's update: Remove duplicate code
207
208 // We need to research what damage fZRPoseMarker2D pointers
209 // This bug can be avoid by changing the initialize order of subdetectors
210 // if ((unsigned long long)(fZRPosMarker2D) & 0xFFFFFFFF00000000)
211 // {
212 // cout << this << " " << fZRPosMarker2D << endl;
213 // }
214
215 // Mingrun Li's answer:
216 // Because fZRPoseMarker2D is not initialized with `nullptr`.
217 // I initialized it with `nullptr` and the bug seems to be gone.
218
219 return fZRPosMarker2D->DistancetoPrimitive( px, py );
220 }
221 }
222
223 return 999;
224}
225
226//_____________________________________________________
227
228void Mdc2DWire::ExecuteEvent( Int_t event, Int_t px, Int_t py ) {
229
230 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
231
232 if ( gBesCursor->GetType() == kBesHand )
233 {
234 if ( view ) view->ExecuteEvent( event, px, py );
235 }
236 else if ( gBesCursor->GetType() == kBesPick )
237 {
238
239 if ( gPad ) gPad->SetCursor( kPointer );
240
241 Int_t origColor = 1;
242
243 switch ( event )
244 {
245
246 case kMouseEnter:
247
248 if ( fWireCircle ) origColor = fWireCircle->GetFillColor();
249 if ( fZRPosMarker2D ) origColor = fZRPosMarker2D->GetMarkerColor();
250 this->SetHighlighted( true );
251
252 if ( this->IsFired() || view->GetVisMdcWires() )
253 {
254 Draw( "WIRE,SAME" );
255
256 fTip->SetPos( px, py );
257 view->UpdateView( 0 );
258
259 // Long Peixun's update: If ShowInfo is not checked, don't show tip text.
260 if ( gBesCursor->GetShowInfo() ) fTip->Draw( "BR,SAME" ); // "BR,ARC,SAME"
261 gPad->Modified();
262 gPad->Update();
263 }
264 break;
265
266 case kMouseLeave:
267
268 if ( this->IsHighlighted() )
269 {
270 this->SetHighlighted( false );
271 if ( view->GetVisMdcWires() ) Draw( "WIRE,SAME" );
272
273 view->UpdateView( 0 );
274 gPad->Modified();
275 gPad->Update();
276 }
277 break;
278 }
279 }
280}
281
282//_____________________________________________________
283
284void Mdc2DWire::Draw( Option_t* option ) {
285 //
286 // Mdc2DWire draw function
287 TString opt = option;
288 opt.ToUpper();
289
290 AppendPad( option );
291}
292
293//_____________________________________________________
294
295void Mdc2DWire::Paint( Option_t* option ) {
296
297 TString opt = option;
298 opt.ToUpper();
299
300 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
301
302 // gStyle->SetPalette(1);
303 if ( view->GetViewType() & kXYView )
304 {
305
306 Double_t wcCenter[3], ncCenter[3];
307 fWireCircle->GetCenter( &wcCenter[0] );
308 view->WCtoNDC( wcCenter, &ncCenter[0] );
309 Double_t x1, y1, x2, y2;
310 Double_t d = 0.05;
311 gPad->GetRange( x1, y1, x2, y2 );
312
313 // Only draw wire in pad range
314 if ( ncCenter[0] > x1 - d && ncCenter[0] < x2 + d && ncCenter[1] > y1 - d &&
315 ncCenter[1] < y2 + d )
316 {
317 if ( opt.Contains( "TUBE" ) && fTube )
318 {
319 fTube->SetLineColor( lcTube );
320 fTube->SetLineWidth( lwTube );
321 fTube->SetFillColor( fcTube );
322 fTube->SetFillStyle( fsTube );
323
324 fTube->Paint();
325 }
326
327 if ( this->IsFired() )
328 {
329 if ( fWireCircle )
330 {
331 fWireCircle->SetLineColor( lcWireFired );
332 fWireCircle->SetLineWidth( lwCircleFired );
333 fWireCircle->SetFillColor( fcCircleFired );
334 fWireCircle->SetFillStyle( fsCircleFired );
335 }
336 if ( fWireCone )
337 {
338 fWireCone->SetLineColor( lcWireFired );
339 fWireCone->SetLineWidth( lwConeFired );
340 fWireCone->SetFillColor( fcConeFired );
341 fWireCone->SetFillStyle( fsConeFired );
342 }
343 }
344 else
345 {
346 if ( fWireCone )
347 {
348 fWireCone->SetLineColor( lcWire );
349 fWireCone->SetLineWidth( lwCone );
350 fWireCone->SetFillColor( fcCone );
351 fWireCone->SetFillStyle( fsCone );
352 }
353 if ( fWireCircle )
354 {
355 fWireCircle->SetLineColor( lcWire );
356 fWireCircle->SetLineWidth( lwCircle );
357 fWireCircle->SetFillColor( fcCircle );
358 fWireCircle->SetFillStyle( fsCircle );
359 }
360 }
361
362 if ( this->IsHighlighted() )
363 {
364 if ( fWireCircle )
365 {
366 fWireCircle->SetLineColor( lcWireHL );
367 fWireCircle->SetLineWidth( lwCircleHL );
368 fWireCircle->SetFillColor( fcCircleHL );
369 fWireCircle->SetFillStyle( fsCircleHL );
370 }
371 if ( fWireCone )
372 {
373 fWireCone->SetLineColor( lcWireHL );
374 fWireCone->SetLineWidth( lwConeHL );
375 fWireCone->SetFillColor( fcConeHL );
376 fWireCone->SetFillStyle( fsConeHL );
377 }
378 }
379 if ( opt.Contains( "WIRE" ) )
380 {
381 // Long Peixun's update: Only draw fired wires' cone
382 if ( IsFired() ) fWireCone->Paint(); // Long Peixun's update: Draw colorful wires' cone
383 if ( fWireCircle ) fWireCircle->Paint();
384 }
385 }
386 }
387
388 if ( view->GetViewType() & kZRView )
389 {
390 if ( HasZRSection() )
391 {
392 fZRPosMarker2D->SetWCX( fZRSectionPos[0] );
393 fZRPosMarker2D->SetWCY( fZRSectionPos[1] );
394 fZRPosMarker2D->SetWCZ( fZRSectionPos[2] );
395 fZRPosMarker2D->SetMarkerColor( cMarker );
396 fZRPosMarker2D->SetMarkerStyle( sMarker );
397 fZRPosMarker2D->SetMarkerSizeMultiple( sizeMarker );
398
399 if ( this->IsFired() )
400 {
401 if ( fZRPosMarker2D )
402 {
403 fZRPosMarker2D->SetMarkerColor( cMarkerFired );
404 fZRPosMarker2D->SetMarkerStyle( sMarkerFired );
405 }
406 }
407 else
408 {
409 if ( fZRPosMarker2D )
410 {
411 fZRPosMarker2D->SetMarkerColor( cMarker );
412 fZRPosMarker2D->SetMarkerStyle( sMarker );
413 }
414 }
415
416 if ( this->IsHighlighted() )
417 {
418 if ( fZRPosMarker2D )
419 {
420 fZRPosMarker2D->SetMarkerColor( cMarkerHL );
421 fZRPosMarker2D->SetMarkerStyle( sMarkerHL );
422 }
423 }
424
425 if ( opt.Contains( "WIRE" ) )
426 {
427 if ( fZRPosMarker2D ) fZRPosMarker2D->Paint();
428 }
429 }
430 }
431}
432
433//_____________________________________________________
434
435char* Mdc2DWire::GetObjectInfo( Int_t px, Int_t py ) const {
436
437 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
438 if ( view ) return view->GetObjectInfo( px, py );
439 else return TObject::GetObjectInfo( px, py );
440}
441
442//_____________________________________________________
443
445 if ( fWireType != 2 ) return false;
446
447 bool flag = false;
448 BesView* view = dynamic_cast<BesView*>( gPad->GetView() );
449 Double_t viewPhi = view->GetLongitude();
450 viewPhi = Range360( viewPhi );
451 // if (GetName() == TString("Layer0Wire0")) cout << "view " << viewPhi << endl;
452
453 Double_t zrPhi = viewPhi - 90.0;
454 zrPhi = Range360( zrPhi );
455 // if (GetName() == TString("Layer0Wire0")) cout << zrPhi << endl;
456
457 for ( Int_t i = 0; i < 2; i++ )
458 {
459 if ( i == 1 )
460 {
461 zrPhi += 180.0;
462 zrPhi = Range360( zrPhi );
463 }
464
465 if ( fabs( fEastPhi - fWestPhi ) < 180.0 )
466 { // no cross phi=0.0
467 if ( ( fEastPhi - zrPhi ) * ( fWestPhi - zrPhi ) > 0.0 ) flag = false;
468 else
469 {
470 Double_t factor = fabs( ( fEastPhi - zrPhi ) / ( fEastPhi - fWestPhi ) );
471 for ( Int_t i = 0; i < 3; i++ )
472 { fZRSectionPos[i] = factor * fWestHole[i] + ( 1.0 - factor ) * fEastHole[i]; }
473 flag = true;
474 break;
475 }
476 }
477 else
478 { // cross phi=0.0
479 if ( ( fEastPhi - zrPhi ) * ( fWestPhi - zrPhi ) < 0.0 ) flag = false;
480 else
481 { // range 0~360 -> -180~180
482 Double_t tempEastPhi = fEastPhi;
483 if ( tempEastPhi >= 180.0 ) tempEastPhi -= 360.0;
484 Double_t tempWestPhi = fWestPhi;
485 if ( tempWestPhi >= 180.0 ) tempWestPhi -= 360.0;
486 Double_t tempZRPhi = zrPhi;
487 if ( tempZRPhi >= 180.0 ) tempZRPhi -= 360.0;
488
489 Double_t factor = fabs( ( tempEastPhi - tempZRPhi ) / ( tempEastPhi - tempWestPhi ) );
490 for ( Int_t i = 0; i < 3; i++ )
491 { fZRSectionPos[i] = factor * fWestHole[i] + ( 1.0 - factor ) * fEastHole[i]; }
492 flag = true;
493 break;
494 }
495 }
496 }
497
498 return flag;
499}
500
501//_____________________________________________________
502
503Double_t Mdc2DWire::Range360( Double_t input ) {
504 if ( input >= 360.0 )
505 {
506 do {
507 input -= 360.0;
508 } while ( input >= 360.0 );
509 }
510 else if ( input < 0.0 )
511 {
512 do {
513 input += 360.0;
514 } while ( input < 0.0 );
515 }
516
517 return input;
518}
519
520//_____________________________________________________
521
522void Mdc2DWire::SetTime( Double_t time ) { mdcTime = time; }
523
524//_____________________________________________________
525
526void Mdc2DWire::SetCharge( Double_t charge ) { mdcCharge = charge; }
527
528//_____________________________________________________
529
530void Mdc2DWire::SetQOverflow( Bool_t qOvfl ) { qOverflow = qOvfl; }
531
532//_____________________________________________________
533
534void Mdc2DWire::SetEvTime( Double_t time ) { evTime = time; }
535
536//_____________________________________________________
537// Long Peixun's update: raw channel data for mdc hits display
538void Mdc2DWire::SetTimeChannel( UInt_t tc ) { timeChannel = tc; }
539void Mdc2DWire::SetChargeChannel( UInt_t cc ) { chargeChannel = cc; }
540
541//_____________________________________________________
542
543void Mdc2DWire::SetColorfulWire( Bool_t colorfulWire, Bool_t subEvTime ) {
544 fColorfulWire = colorfulWire;
545 if ( fColorfulWire )
546 {
547 // yzhang change LINE COLOR of fired mdc wires
548 // n color bin = 50, time of max bin is 2000
549 // time max value = 1943.8125 ~ 2000 ns
550 // no time info color is kGray
551 // time > 2000 && time <=10000, color is kBlack
552 int tempColor;
553 if ( subEvTime )
554 {
555 // raw time - event start time
556 double tempMdcTime = mdcTime - evTime;
557 if ( fabs( evTime ) > 0.0001 ) tempMdcTime += 230;
558 if ( tempMdcTime > 10000 ) { tempColor = kGray; }
559 else if ( tempMdcTime > 2000 && tempMdcTime <= 10000 ) { tempColor = kRed; }
560 else if ( tempMdcTime < -10 ) { tempColor = kWhite; }
561 else { tempColor = 51 + (int)( tempMdcTime / 40 ); }
562 }
563 else
564 {
565 // raw time
566 if ( mdcTime > 10000 ) { tempColor = kGray; }
567 else if ( mdcTime > 2000 && mdcTime <= 10000 ) { tempColor = kRed; }
568 else { tempColor = 51 + (int)( mdcTime / 40 ); }
569 }
570 lcWireFired = tempColor;
571 // std::cout<< " mdcTime "<<mdcTime <<" evTime "<< evTime << " t-t0 "<< mdcTime - evTime
572 // +230<< " lcWireFired " << lcWireFired <<std::endl;
573
574 // yzhang change FILL COLOR of fired mdc wires
575 // n color bin = 50, charge of max bin is 2000
576 // charge max value = 29783 ~ 30000
577 // adc> 2000&&<=30000 color is kBlack
578 // no adc color is kGray
579 if ( mdcCharge > 30000 ) { tempColor = kGray; }
580 else if ( mdcCharge > 2000 && mdcCharge <= 30000 ) { tempColor = kRed; }
581 else { tempColor = 51 + (int)( mdcCharge / 40 ); }
582 if ( qOverflow ) { tempColor = kBlack; }
583 fcCircleFired = tempColor;
584 // std::cout<< " mdcCharge "<<mdcCharge<<" ovfl "<<qOverflow<<" fcCircleFired " <<
585 // fcCircleFired<< std::endl;
586 }
587 else
588 {
589 lcWireFired = kRed;
590 fcCircleFired = 9004;
591 }
592}
double P(RecMdcKalTrack *trk)
legend Draw()
cout<< "end eff5"<< endl;TGraph *gr1=new TGraphErrors(15, x, eff_ep, errx, err_ep);TGraph *gr2=new TGraphErrors(15, x, eff_em, errx, err_em);TGraph *gr3=new TGraphErrors(15, x, eff_ep2, errx, err_ep2);TGraph *gr4=new TGraphErrors(15, x, eff_em2, errx, err_em2);TGraph *gr5=new TGraphErrors(15, x, eff_ep3, errx, err_ep3);TGraph *gr6=new TGraphErrors(15, x, eff_em3, errx, err_em3);TGraph *gr7=new TGraphErrors(15, x, eff_ep4, errx, err_ep4);TGraph *gr8=new TGraphErrors(15, x, eff_em4, errx, err_em4);TGraph *gr9=new TGraphErrors(15, x, eff_ep5, errx, err_ep5);TGraph *gr10=new TGraphErrors(15, x, eff_em5, errx, err_em5);TCanvas *c1=new TCanvas("c1", "bhabha_eff", 100, 10, 600, 400);TMultiGraph *mg=new TMultiGraph();mg-> SetTitle("bhabha_eff")
Double_t time
titledef title[20]
ClassImp(Mdc2DWire) Mdc2DWire
Definition Mdc2DWire.cxx:13
virtual void WCtoNDC(const Float_t *pw, Float_t *pn)
Definition BesView.cxx:716
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
void SetChargeChannel(UInt_t cc)
virtual void ClearInfo()
void SetQOverflow(Bool_t qOvfl)
virtual void CloseInfo()
virtual void SetHighlighted(bool status=true)
virtual char * GetObjectInfo(Int_t px, Int_t py) const
virtual bool HasZRSection()
void SetTime(Double_t time)
void SetColorfulWire(Bool_t colorfulWire, Bool_t subEvTime)
Double_t Range360(Double_t input)
void SetEvTime(Double_t time)
virtual void Paint(Option_t *option="")
virtual void Init()
virtual void SetStyle()
void SetTimeChannel(UInt_t tc)
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
virtual void Draw(Option_t *option="")
void SetCharge(Double_t charge)
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)