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