1 | #include "EDetectorPhotonsPainter.hh" |
---|
2 | #include "EDetPhoton.hh" |
---|
3 | #include "Etypes.hh" |
---|
4 | |
---|
5 | #include "TMath.h" |
---|
6 | #include "TPad.h" |
---|
7 | #include "TView.h" |
---|
8 | #include "TPolyMarker3D.h" |
---|
9 | #include "TAxis3D.h" |
---|
10 | #include "TStyle.h" |
---|
11 | #include "Riostream.h" |
---|
12 | |
---|
13 | #include <TBuffer3D.h> |
---|
14 | #include <TCanvas.h> |
---|
15 | #include <TPaveText.h> |
---|
16 | #include <map> |
---|
17 | #include <vector> |
---|
18 | #include <TROOT.h> |
---|
19 | using namespace TMath; |
---|
20 | |
---|
21 | ClassImp(EDetectorPhotonsPainter) |
---|
22 | |
---|
23 | //_____________________________________________________________________________ |
---|
24 | EDetectorPhotonsPainter::EDetectorPhotonsPainter( EDetector *detector ) : fDetector(detector),fXmin(0),fXmax(0),fYmin(0),fYmax(0),fZmin(0),fZmax(0) { |
---|
25 | // |
---|
26 | // Constructor |
---|
27 | // |
---|
28 | |
---|
29 | BuildPoints(); |
---|
30 | } |
---|
31 | |
---|
32 | //_____________________________________________________________________________ |
---|
33 | EDetectorPhotonsPainter::~EDetectorPhotonsPainter() { |
---|
34 | // |
---|
35 | // Destructor |
---|
36 | // |
---|
37 | |
---|
38 | } |
---|
39 | |
---|
40 | //______________________________________________________________________________ |
---|
41 | void EDetectorPhotonsPainter::BuildPoints() { |
---|
42 | // |
---|
43 | // Show photons in detector |
---|
44 | // |
---|
45 | |
---|
46 | if (fDetector->GetNumPhotons() < 1) { |
---|
47 | Info("DrawOptics()","No photons loaded."); |
---|
48 | return; |
---|
49 | } |
---|
50 | |
---|
51 | map < Int_t, vector<Int_t> > histories; |
---|
52 | |
---|
53 | EPhoton *ph = fDetector->GetPhoton(0); |
---|
54 | fXmin = fXmax = ph->GetPos().X(); |
---|
55 | fYmin = fYmax = ph->GetPos().Y(); |
---|
56 | fZmin = fZmax = ph->GetPos().Z(); |
---|
57 | |
---|
58 | for (Int_t k = 0; k < fDetector->GetNumPhotons(); k++) { |
---|
59 | EDetPhoton *ph = fDetector->GetPhoton(k); |
---|
60 | histories[ph->GetHistory()].push_back(k); |
---|
61 | fXmin = Min(fXmin,ph->GetPos().X()); |
---|
62 | fXmax = Max(fXmax,ph->GetPos().X()); |
---|
63 | fYmin = Min(fYmin,ph->GetPos().Y()); |
---|
64 | fYmax = Max(fYmax,ph->GetPos().Y()); |
---|
65 | fZmin = Min(fZmin,ph->GetPos().Z()); |
---|
66 | fZmax = Max(fZmax,ph->GetPos().Z()); |
---|
67 | } |
---|
68 | |
---|
69 | Int_t ncolor = 0; |
---|
70 | Int_t hsize = histories.size() < 2 ? 1 : histories.size()-1; |
---|
71 | |
---|
72 | map < Int_t, vector<Int_t> >::const_iterator i; |
---|
73 | for (i = histories.begin(); i != histories.end(); i++){ |
---|
74 | Int_t color = 51+(Int_t)(ncolor++*49/(hsize)); |
---|
75 | fPoints[i->first] = new TPolyMarker3D(i->second.size()*3,fMarkerStyle,""); |
---|
76 | |
---|
77 | for ( UInt_t k(0); k < i->second.size(); k++) { |
---|
78 | EPhoton *ph = fDetector->GetPhoton(i->second[k]); |
---|
79 | |
---|
80 | fPoints[i->first]->SetPoint(k,ph->GetPos().X(),ph->GetPos().Y(),ph->GetPos().Z()); |
---|
81 | } |
---|
82 | |
---|
83 | fPoints[i->first]->SetMarkerColor(color); |
---|
84 | } |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | //______________________________________________________________________________ |
---|
89 | void EDetectorPhotonsPainter::Draw( Option_t* option ) { |
---|
90 | // |
---|
91 | // |
---|
92 | // |
---|
93 | |
---|
94 | Bool_t has_pad = (gPad==0)?kFALSE:kTRUE; |
---|
95 | if (!gPad) { |
---|
96 | #if ( ROOT_VERSION_CODE <= ROOT_VERSION(5,16,00) ) |
---|
97 | if (!gROOT->GetMakeDefCanvas()) return; |
---|
98 | (gROOT->GetMakeDefCanvas()); |
---|
99 | #else |
---|
100 | if (!gROOT->MakeDefCanvas()) return; |
---|
101 | (gROOT->MakeDefCanvas()); |
---|
102 | #endif |
---|
103 | } |
---|
104 | |
---|
105 | AppendPad(option); |
---|
106 | |
---|
107 | // Create a 3-D view |
---|
108 | TView *view = gPad->GetView(); |
---|
109 | if (!view) { |
---|
110 | #if ( ROOT_VERSION_CODE <= ROOT_VERSION(5,16,00) ) |
---|
111 | view = new TView(11); |
---|
112 | #else |
---|
113 | view =TView::CreateView(1); |
---|
114 | #endif |
---|
115 | |
---|
116 | #if ( ROOT_VERSION_CODE <= ROOT_VERSION(4,03,02) ) |
---|
117 | view->SetAutoRange(kTRUE); |
---|
118 | TBuffer3D *buff = gPad->GetBuffer3D(); |
---|
119 | buff->fOption = TBuffer3D::kRANGE; |
---|
120 | Paint("range"); |
---|
121 | buff->fOption = TBuffer3D::kPAD; |
---|
122 | view->SetAutoRange(kFALSE); |
---|
123 | #else |
---|
124 | view->SetAutoRange(kTRUE); |
---|
125 | Paint("range"); |
---|
126 | view->SetAutoRange(kFALSE); |
---|
127 | #endif // ROOT_VERSION_CODE <= ROOT_VERSION(4,03,02) |
---|
128 | if (has_pad) gPad->Update(); |
---|
129 | } |
---|
130 | |
---|
131 | if (!view->IsPerspective()) view->SetPerspective(); |
---|
132 | |
---|
133 | TAxis3D::ToggleRulers(); |
---|
134 | |
---|
135 | } |
---|
136 | |
---|
137 | //______________________________________________________________________________ |
---|
138 | void EDetectorPhotonsPainter::Paint( Option_t* option ) { |
---|
139 | // |
---|
140 | // |
---|
141 | // |
---|
142 | |
---|
143 | map < Int_t, TPolyMarker3D* >::const_iterator j; |
---|
144 | for ( j=fPoints.begin(); j != fPoints.end(); j++ ) { |
---|
145 | j->second->Paint( option ); |
---|
146 | } |
---|
147 | |
---|
148 | } |
---|