BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
Emc2DCrystal.cxx
Go to the documentation of this file.
1#include <TString.h>
2#include <TColor.h>
3#include <iostream>
4#include "TMath.h"
5#include "math.h"
6
7#include "BesVisLib/Emc2DCrystal.h"
8#include "BesVisLib/BesView.h"
9#include "BesVisLib/BesCursor.h"
10
11using namespace std;
12
13#ifndef __CINT__
15#endif
16
17//_____________________________________________________
18
20
21}
22
23//_____________________________________________________
24
25Emc2DCrystal::Emc2DCrystal(const char* name, const char* title, Int_t N, Double_t *P, Int_t part, Int_t theta)
26{
27 SetName(name);
29 fTip = 0;
30 fHighlighted = false;
31 fFired = false;
32 fPart = part;
33 fTheta = theta;
34
35 fTime = 0.0;
36 fCharge = 0.0;
37
38 fZRSectionTolerance[1] = 0.1; // degree
39 fZRSectionTolerance[2] = fZRSectionTolerance[0] = 1.2; // degree
40
41 // ------XY------
42
43 Double_t Pxy[3*5]; // 4 side and 5 side shape in Emc End crystal
44 if (N == 8) { // 4 side
45 Int_t iXYSeq[4] = {0,2,6,4};
46 for (Int_t i = 0; i < 4; i++) {
47 if (part == 1) {
48 for (Int_t j = 0; j < 3; j++) {
49 Pxy[3*i+j] = ( P[3*iXYSeq[i]+j] + P[3*(iXYSeq[i]+1)+j] )/2.0;
50 }
51 }
52 else if (part == 0) {
53 SetXYPoint(&P[3*i], &P[3*(i+4)], &Pxy[3*i], ecXYPointZ);
54 //for (Int_t j = 0; j < 3; j++) Pxy[3*i+j] = P[3*i+j];
55 }
56 else if (part == 2) {
57 SetXYPoint(&P[3*i], &P[3*(i+4)], &Pxy[3*i], -ecXYPointZ);
58 //for (Int_t j = 0; j < 3; j++) Pxy[3*i+j] = P[3*i+j];
59 }
60 //cout << GetName() << endl;
61 //if (GetName() == TString("EastEcTheta5Phi0")) cout << Pxy[3*i] << " " << Pxy[3*i+1] << " " << Pxy[3*i+2] << endl;
62 }
63
64 fCrystalXY = new BesPolygon2D(name, title, 4, &Pxy[0]);
65 fCrystalXYFired = new BesPolygon2D(name, title, 4, &Pxy[0]);
66 }
67 if (N == 16) { // 5 side
68 Int_t iXYSeq[5] = {8,9,1,2,3}; // 9 10,1 2
69 for (Int_t i = 0; i < 5; i++) { // 8 11,0 3
70 if (part == 0) {
71 SetXYPoint(&P[3*iXYSeq[i]], &P[3*(iXYSeq[i]+4)], &Pxy[3*i], ecXYPointZ);
72 }
73 else if (part == 2) {
74 SetXYPoint(&P[3*iXYSeq[i]], &P[3*(iXYSeq[i]+4)], &Pxy[3*i], -ecXYPointZ);
75 }
76 //for (Int_t j = 0; j < 3; j++) Pxy[3*i+j] = P[3*iXYSeq[i]+j];
77 }
78
79 fCrystalXY = new BesPolygon2D(name, title, 5, &Pxy[0]);
80 fCrystalXYFired = new BesPolygon2D(name, title, 5, &Pxy[0]);
81 }
82
83 // ------ZR------
84
85 Double_t Pzr[3*4];
86 Int_t iSeq[8] = {0,3,1,2,5,6,4,7}; // center of 0+3, 1+2, 5+6, 4+7
87 for (Int_t i = 0; i < 4; i++) {
88 for (Int_t j = 0; j < 3; j++) {
89 Pzr[3*i+j] = (P[3*iSeq[2*i]+j] + P[3*iSeq[2*i+1]+j])/2.0;
90 }
91 //if (GetName() == TString("EastEcCrystal0")) cout << Pxy[i] << endl;
92 }
93
94
95 fCrystalZR = new BesPolygon2D(TString(name)+TString("zr"), title, 4, &Pzr[0]);
96 fCrystalZRFired = new BesPolygon2D(TString(name)+TString("zr"), title, 4, &Pzr[0]);
97
98 if (N == 8) {
99 if (GetPart() == 1) {
100 fPhiMin = GetAngle( P[3*0], P[3*0+1] );
101 fPhiMax = GetAngle( P[3*3], P[3*3+1] );
102 }
103 else {
104 fPhiMin = GetAngle( P[3*3], P[3*3+1] );
105 fPhiMax = GetAngle( P[3*0], P[3*0+1] );
106 }
107 }
108 else if (N == 16) {
109 fPhiMin = GetAngle( P[3*3], P[3*3+1] );
110 fPhiMax = GetAngle( P[3*8], P[3*8+1] );
111 }
112
113 if (fPhiMin > fPhiMax && fabs(fPhiMax-fPhiMin) < 180.0) { // not cross 0 degree
114 Double_t phiTemp = fPhiMin;
115 fPhiMin = fPhiMax;
116 fPhiMax = phiTemp;
117 }
118 //cout << GetName() << " min "<< fPhiMin << " max " << fPhiMax << endl;
119
120 // ------Side------
121
122 Double_t Pside[3*5]; // 4 side and 5 side shape in Emc End crystal
123 if (N == 8) { // 4 side
124 //Int_t iSideSeq[4] = {0,1,2,3};
125 for (Int_t i = 0; i < 4; i++) {
126 if (part == 1) {
127 SetZRPoint(&P[3*i], &P[3*(i+4)], &Pside[3*i], brZRPointR);
128 }
129 else {
130 ProjectECToSide(&Pxy[3*i], &Pside[3*i]);
131 }
132 }
133
134 fCrystalSide = new BesPolygon2D(name, title, 4, &Pside[0]);
135 fCrystalSideFired = new BesPolygon2D(name, title, 4, &Pside[0]);
136 }
137 if (N == 16) { // 5 side
138 for (Int_t i = 0; i < 5; i++) {
139 ProjectECToSide(&Pxy[3*i], &Pside[3*i]);
140 }
141
142 fCrystalSide = new BesPolygon2D(name, title, 5, &Pside[0]);
143 fCrystalSideFired = new BesPolygon2D(name, title, 5, &Pside[0]);
144 }
145
146 // Init
147
148 SetStyle();
149
150 fTip = new BesPaveText(0, 0, 0.45, 0.08);
151 CloseInfo();
152}
153
154//_____________________________________________________
155
157
158 if (fCrystalXY) delete fCrystalXY;
159 if (fCrystalZR) delete fCrystalZR;
160 if (fCrystalXYFired) delete fCrystalXYFired;
161 if (fCrystalZRFired) delete fCrystalZRFired;
162}
163
165{
166 lcCrystal = 15;
167 lwCrystal = 1;
168 fcCrystal = 1005; // lightBlue
169 fsCrystal = 1001;
170 fsCrystalTrans = 4000;
171
172 lcCrystalFired = kRed;
173 lwCrystalFired = 1;
174 fcCrystalFired = kRed;
175 fsCrystalFired = 1001;
176
177 lcCrystalHL = lcCrystal;
178 lwCrystalHL = 1;
179 fcCrystalHL = kBlue;
180 fsCrystalHL = 1001;
181
182 lcCrystalFiredHL = kRed;
183 lwCrystalFiredHL = 2;
184 fcCrystalFiredHL = kWhite;
185 fsCrystalFiredHL = 4000;
186}
187
189{
190 fInfoCon.clear();
191 fTip->DeleteText();
192}
193
195{
196 if (fTip) {
197 fTip->Clear();
198
199 if (fInfoCon.size() == 0) fInfoCon.push_back(GetTitle());
200 fTip->SetText(fInfoCon);
201 }
202 else
203 cout << "Emc2DCrystal::CloseInfo, not initialized" << endl;
204}
205
206//_____________________________________________________
207
208Int_t Emc2DCrystal::DistancetoPrimitive(Int_t px, Int_t py) {
209
210 BesView *view = (BesView*)gPad->GetView();
211 if ( view->GetViewType() & kXYView ) {
212 if ( fCrystalXY && IsXYVisible() ) {
213 return fCrystalXY->DistancetoPrimitive(px, py);
214 }
215 }
216 else if ( view->GetViewType() & kZRView && fCrystalZR && fCrystalSide ) {
217 if (HasZRSection())
218 return fCrystalZR->DistancetoPrimitive(px, py);
219 else if ( IsSideVisible() &&
220 (view->GetVisEmcSide() || (view->GetVisEmcHitsSide() && IsFired())) )
221 return fCrystalSide->DistancetoPrimitive(px, py);
222 }
223
224 return 9999;
225}
226
227//_____________________________________________________
228
229void Emc2DCrystal::ExecuteEvent(Int_t event, Int_t px, Int_t py) {
230
231 //if (fWireType == 2 && fWireBubble[0] ) {
232 //if (fWireCone->GetLineWidth() > 1) // FIRED
233 //cout << GetName() << endl;
234
235 BesView *view = (BesView*)gPad->GetView();
236
237 if (gBesCursor->GetType() == kBesHand) {
238 if (view) view->ExecuteEvent(event, px, py);
239 }
240 else if (gBesCursor->GetType() == kBesPick){
241
242 if (gPad) gPad->SetCursor(kPointer);
243
244 switch (event) {
245
246 case kMouseEnter :
247 this->SetHighlighted(true);
248
249 //if (this->IsFired() || view->GetVisEmcHitsGlobal()) {
250 Draw();
251
252 fTip->SetPos(px, py);
253 view->UpdateView(0);
254
255 fTip->Draw("BR,SAME"); // "BR,ARC,SAME"
256 gPad->Modified();
257 gPad->Update();
258 break;
259
260 case kMouseLeave:
261 if (this->IsHighlighted()) {
262 this->SetHighlighted(false);
263 //if (view->GetVisEmcHitsGlobal())
264 Draw();
265
266 /*
267 if (fTip) {
268 delete fTip;
269 fTip = 0;
270 }
271 */
272
273 view->UpdateView(0);
274 gPad->Modified();
275 gPad->Update();
276 break;
277 }
278 }
279 }
280}
281
282//_____________________________________________________
283
284void Emc2DCrystal::Draw(Option_t *option) {
285 //
286 // Emc2DCrystal draw function
287 TString opt = option;
288 opt.ToUpper();
289
290 AppendPad(option);
291}
292
293//_____________________________________________________
294
295void Emc2DCrystal::Paint(Option_t *option) {
296
297 TString opt = option;
298 opt.ToUpper();
299
300 BesView *view = (BesView*)gPad->GetView();
301 if (view->GetViewType() & kXYView) {
302
303 if (fCrystalXY) {
304 fCrystalXY->SetLineColor(lcCrystal);
305 fCrystalXY->SetLineWidth(lwCrystal);
306 fCrystalXY->SetFillColor(fcCrystal);
307 fCrystalXY->SetFillStyle(fsCrystal);
308 }
309
310 if (this->IsFired()) {
311 if (fCrystalXY) {
312 fCrystalXY->SetFillStyle(fsCrystalTrans);
313 }
314 if (fCrystalXYFired) {
315 fCrystalXYFired->SetLineColor(lcCrystalFired);
316 fCrystalXYFired->SetLineWidth(lwCrystalFired);
317 fCrystalXYFired->SetFillColor(fcCrystalFired);
318 fCrystalXYFired->SetFillStyle(fsCrystalFired);
319 }
320 }
321
322 if (this->IsHighlighted()) {
323 if (fCrystalXY) {
324 fCrystalXY->SetLineColor(lcCrystalHL);
325 fCrystalXY->SetLineWidth(lwCrystalHL);
326 fCrystalXY->SetFillColor(fcCrystalHL);
327 fCrystalXY->SetFillStyle(fsCrystalHL);
328 }
329 if (fCrystalXYFired) {
330 fCrystalXYFired->SetLineColor(lcCrystalFiredHL);
331 fCrystalXYFired->SetLineWidth(lwCrystalFiredHL);
332 fCrystalXYFired->SetFillColor(fcCrystalFiredHL);
333 fCrystalXYFired->SetFillStyle(fsCrystalFiredHL);
334 }
335 }
336
337 if ( fCrystalXY && IsXYVisible() ) fCrystalXY->Paint();
338 if (this->IsFired()) {
339 if (view->GetVisEmcHitsGlobal() &&
340 ( (fPart == 0 && view->GetVisEmcHitsEast()) ||
341 (fPart == 1 && view->GetVisEmcHitsBarrel()) ||
342 (fPart == 2 && view->GetVisEmcHitsWest()) )) {
343 if (fCrystalXYFired) {
344 fCrystalXY->Paint();
345 //if (this->IsHighlighted()) cout << GetName() << " is highlighted " << endl;
346 //cout << "Emc fired Crystal size " << fCharge/fChargeMax << endl;
347 fCrystalXYFired->Restore(); // restore default size
348 fCrystalXYFired->SetSize(fCharge/fChargeMax);
349 fCrystalXYFired->Paint();
350 }
351 }
352 }
353 }
354
355 if (view->GetViewType() & kZRView) {
356 if (HasZRSection()) {
357 if (this->IsFired()) {
358 if (fCrystalZRFired) {
359 fCrystalZRFired->SetLineColor(lcCrystalFired);
360 fCrystalZRFired->SetLineWidth(lwCrystalFired);
361 fCrystalZRFired->SetFillColor(fcCrystalFired);
362 fCrystalZRFired->SetFillStyle(fsCrystalFired);
363 }
364 }
365
366 if (fCrystalZR) {
367 fCrystalZR->SetLineColor(lcCrystal);
368 fCrystalZR->SetLineWidth(lwCrystal);
369 fCrystalZR->SetFillColor(fcCrystal);
370 fCrystalZR->SetFillStyle(fsCrystal);
371 }
372
373 if (this->IsHighlighted()) {
374 if (fCrystalZR) {
375 fCrystalZR->SetLineColor(lcCrystalHL);
376 fCrystalZR->SetLineWidth(lwCrystalHL);
377 fCrystalZR->SetFillColor(fcCrystalHL);
378 fCrystalZR->SetFillStyle(fsCrystalHL);
379 }
380 if (fCrystalZRFired) {
381 fCrystalZRFired->SetLineColor(lcCrystalFiredHL);
382 fCrystalZRFired->SetLineWidth(lwCrystalFiredHL);
383 fCrystalZRFired->SetFillColor(fcCrystalFiredHL);
384 fCrystalZRFired->SetFillStyle(fsCrystalFiredHL);
385 }
386 }
387
388 if ( fCrystalZR ) fCrystalZR->Paint();
389 if (this->IsFired()) {
390 if (view->GetVisEmcHitsGlobal() &&
391 ( (fPart == 0 && view->GetVisEmcHitsEast()) ||
392 (fPart == 1 && view->GetVisEmcHitsBarrel()) ||
393 (fPart == 2 && view->GetVisEmcHitsWest()) )) {
394 if (fCrystalZRFired) {
395 //cout << "Emc fired Crystal size " << fCharge/fChargeMax << endl;
396 fCrystalZRFired->Restore(); // restore default size
397 fCrystalZRFired->SetSize(fCharge/fChargeMax);
398 fCrystalZRFired->Paint();
399 }
400 }
401 }
402 }
403
404 // side
405 if (this->IsFired()) {
406 if (fCrystalSideFired) {
407 fCrystalSideFired->SetLineColor(lcCrystalFired);
408 fCrystalSideFired->SetLineWidth(lwCrystalFired);
409 fCrystalSideFired->SetFillColor(fcCrystalFired);
410 fCrystalSideFired->SetFillStyle(fsCrystalFired);
411 }
412 }
413
414 if (fCrystalSide) {
415 fCrystalSide->SetLineColor(lcCrystal);
416 fCrystalSide->SetLineWidth(lwCrystal);
417 fCrystalSide->SetFillColor(fcCrystal);
418 fCrystalSide->SetFillStyle(fsCrystal);
419 }
420
421 if (this->IsHighlighted()) {
422 if (fCrystalSide) {
423 fCrystalSide->SetLineColor(lcCrystalHL);
424 fCrystalSide->SetLineWidth(lwCrystalHL);
425 fCrystalSide->SetFillColor(fcCrystalHL);
426 fCrystalSide->SetFillStyle(fsCrystalHL);
427 }
428 if (fCrystalSideFired) {
429 fCrystalSideFired->SetLineColor(lcCrystalFiredHL);
430 fCrystalSideFired->SetLineWidth(lwCrystalFiredHL);
431 fCrystalSideFired->SetFillColor(fcCrystalFiredHL);
432 fCrystalSideFired->SetFillStyle(fsCrystalFiredHL);
433 }
434 }
435
436 if ( IsSideVisible() ) {
437 if ( (view->GetVisEmcSide() || view->GetVisEmcHitsSide() && this->IsFired()) && fCrystalSide ) fCrystalSide->Paint();
438 if ( this->IsFired() ) {
439 if (view->GetVisEmcHitsGlobal() && view->GetVisEmcHitsSide()) {
440 if (fCrystalSideFired) {
441 //cout << "Emc fired Crystal size " << fCharge/fChargeMax << endl;
442 fCrystalSideFired->Restore(); // restore default size
443 fCrystalSideFired->SetSize(fCharge/fChargeMax);
444 fCrystalSideFired->Paint();
445 }
446 }
447 }
448 }
449 }
450}
451
452//_____________________________________________________
453
454char *Emc2DCrystal::GetObjectInfo(Int_t px, Int_t py) const {
455
456 BesView *view = (BesView*)gPad->GetView();
457 if (view) return view->GetObjectInfo(px, py);
458 else return TObject::GetObjectInfo(px, py);
459}
460
461//_____________________________________________________
462
464{
465 bool flag = false;
466 BesView *view = (BesView*)gPad->GetView();
467 Double_t viewPhi = view->GetLongitude();
468 viewPhi = Range360(viewPhi);
469 //if (GetName() == TString("Layer0Wire0")) cout << "view " << viewPhi << endl;
470
471 Double_t zrPhi = viewPhi-90.0;
472 zrPhi = Range360(zrPhi);
473 //if (GetName() == TString("Layer0Wire0")) cout << zrPhi << endl;
474
475 for (Int_t i = 0; i < 2; i++) {
476 if (i==1) {
477 zrPhi += 180.0;
478 zrPhi = Range360(zrPhi);
479 }
480
481 if (zrPhi >= fPhiMin-fZRSectionTolerance[GetPart()] &&
482 zrPhi <= fPhiMax+fZRSectionTolerance[GetPart()]) {
483 flag = true;
484 break;
485 }
486 else if (fPhiMin > fPhiMax) { // cross 0 degree
487 //cout << GetName() << " zrPhi " << zrPhi << " min " << fPhiMin << " max " << fPhiMax << endl;
488 if (zrPhi >= fPhiMin-fZRSectionTolerance[GetPart()] ||
489 zrPhi <= fPhiMax+fZRSectionTolerance[GetPart()]) {
490 flag = true;
491 break;
492 }
493 }
494 }
495
496 return flag;
497}
498
499//_____________________________________________________
500
501Double_t Emc2DCrystal::GetAngle(Double_t x, Double_t y) //degree
502{
503 Double_t angle = TMath::ACos( x/TMath::Sqrt(x*x+y*y) ) * TMath::RadToDeg();
504 if ( y<0.0 ) angle *= -1;
505 angle = Range360(angle);
506
507 return angle;
508}
509
510//_____________________________________________________
511
512Double_t Emc2DCrystal::Range360(Double_t input)
513{
514 if (input >= 360.0) {
515 do {
516 input -= 360.0;
517 }
518 while (input >= 360.0);
519 }
520 else if (input < 0.0) {
521 do {
522 input += 360.0;
523 }
524 while (input < 0.0);
525 }
526
527 return input;
528}
529
531{
532 if ( GetPart() != 1 || GetTheta() == 0 || IsFired() )
533 return true;
534 else
535 return false;
536}
537
539{
540 BesView *view = (BesView*)gPad->GetView();
541 Double_t viewPhi = view->GetLongitude();
542 Double_t viewPhiMin = viewPhi - sideDeltaPhi;
543 Double_t viewPhiMax = viewPhi + sideDeltaPhi;
544
545 viewPhi = Range360(viewPhi);
546 viewPhiMin = Range360(viewPhiMin);
547 viewPhiMax = Range360(viewPhiMax);
548 //if (GetName() == TString("Layer0Wire0")) cout << "view " << viewPhi << endl;
549
550 if (viewPhiMin < viewPhiMax) { // not cross 0 degree
551 if (fPhiMax > viewPhiMin && fPhiMax < viewPhiMax) return true;
552 }
553 else { // cross 0 degree
554 if (fPhiMax > viewPhiMin || fPhiMax < viewPhiMax) return true;
555 }
556
557 return false;
558}
559
560// the point newP is on the line connecting p1 and p2, cut point by the plane Z=z
561
562void Emc2DCrystal::SetXYPoint(Double_t *p1, Double_t *p2, Double_t *newP, Double_t z)
563{
564 Double_t ratio = fabs( (z-p1[2]) / (p2[2]-p1[2]) );
565 for (Int_t i = 0; i < 3; i++) {
566 newP[i] = p1[i] * (1.0-ratio) + p2[i] * ratio;
567 }
568}
569
570// the point newP is on the line connecting p1 and p2, cut point by the plane R=r
571
572void Emc2DCrystal::SetZRPoint(Double_t *p1, Double_t *p2, Double_t *newP, Double_t r)
573{
574 Double_t r1 = sqrt(p1[0]*p1[0] + p1[1]*p1[1]);
575 Double_t r2 = sqrt(p2[0]*p2[0] + p2[1]*p2[1]);
576
577 Double_t ratio = fabs( (r-r1) / (r2-r1) );
578 for (Int_t i = 0; i < 3; i++) {
579 newP[i] = p1[i] * (1.0-ratio) + p2[i] * ratio;
580 }
581}
582
583void Emc2DCrystal::ProjectECToSide(Double_t *p1, Double_t *newP)
584{
585 // ------ R ---------
586 // | --> |
587 // | r |
588
589 Double_t r1 = sqrt(p1[0]*p1[0] + p1[1]*p1[1]);
590 newP[0] = p1[0] * (brZRPointR/r1);
591 newP[1] = p1[1] * (brZRPointR/r1);
592
593 Double_t drToR = brZRPointR - r1;
594 newP[2] = fabs(ecXYPointZ + drToR) * (p1[2]/fabs(p1[2]));
595
596
597 //if (GetName() == TString("EastEcTheta0Phi0")) {
598 //cout << p1[0] << " " << p1[1] << " " << p1[2] << endl;
599 //cout << newP[0] << " " << newP[1] << " " << newP[2] << endl;
600 //}
601
602}
double P(RecMdcKalTrack *trk)
gr SetTitle("BbLum_000XXXX")
Double_t x[10]
ClassImp(Emc2DCrystal) Emc2DCrystal
titledef title[20]
virtual void SetText(std::vector< TString > infoCon)
virtual void SetPos(Int_t px, Int_t py)
Definition: BesPaveText.cxx:76
virtual void SetSize(Double_t size)
virtual void Paint(Option_t *option="")
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
virtual void Restore()
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 ProjectECToSide(Double_t *p1, Double_t *newP)
virtual void SetZRPoint(Double_t *p1, Double_t *p2, Double_t *newP, Double_t r)
virtual void SetStyle()
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual bool IsSideVisible()
virtual void CloseInfo()
Double_t GetAngle(Double_t x, Double_t y)
virtual char * GetObjectInfo(Int_t px, Int_t py) const
virtual void Draw(Option_t *option="")
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
virtual bool HasZRSection()
Double_t Range360(Double_t input)
virtual bool IsXYVisible()
virtual void Paint(Option_t *option="")
virtual void ClearInfo()
virtual void SetXYPoint(Double_t *p1, Double_t *p2, Double_t *newP, Double_t z)