1 | #include "EOpticsPhotonsPainter.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 | |
---|
19 | using namespace TMath; |
---|
20 | |
---|
21 | ClassImp(EOpticsPhotonsPainter) |
---|
22 | |
---|
23 | //_____________________________________________________________________________ |
---|
24 | EOpticsPhotonsPainter::EOpticsPhotonsPainter( 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 | EOpticsPhotonsPainter::~EOpticsPhotonsPainter() { |
---|
34 | // |
---|
35 | // Destructor |
---|
36 | // |
---|
37 | |
---|
38 | } |
---|
39 | |
---|
40 | //______________________________________________________________________________ |
---|
41 | void EOpticsPhotonsPainter::BuildPoints() { |
---|
42 | // |
---|
43 | // Show photons in optics |
---|
44 | // |
---|
45 | |
---|
46 | |
---|
47 | if (fDetector->GetNumPhotons() < 1) { |
---|
48 | Info("BuildPoints","No photons loaded."); |
---|
49 | return; |
---|
50 | } |
---|
51 | |
---|
52 | map < Int_t, vector<Int_t> > fates; |
---|
53 | |
---|
54 | for (Int_t k = 0; k < fDetector->GetNumPhotons(); k++) { |
---|
55 | EDetPhoton *ph = fDetector->GetPhoton(k); |
---|
56 | if(ph->GetHistory() != kOptics) continue; |
---|
57 | |
---|
58 | fates[ph->GetFate()].push_back(k); |
---|
59 | } |
---|
60 | |
---|
61 | Int_t ncolor = 0; |
---|
62 | |
---|
63 | map < Int_t, vector<Int_t> >::const_iterator i; |
---|
64 | for (i = fates.begin(); i != fates.end(); i++){ |
---|
65 | |
---|
66 | Int_t color; |
---|
67 | |
---|
68 | if ( fates.size() == 1 ) color = kWhite; |
---|
69 | else |
---|
70 | color = 51+(Int_t)(ncolor++*49/(fates.size()-1)); |
---|
71 | fPoints[i->first] = new TPolyMarker3D(i->second.size()*3,fMarkerStyle,""); |
---|
72 | |
---|
73 | for ( UInt_t k(0); k < i->second.size(); k++) { |
---|
74 | EPhoton *ph = fDetector->GetPhoton(i->second[k]); |
---|
75 | |
---|
76 | fPoints[i->first]->SetPoint(k,ph->GetPos().X(),ph->GetPos().Y(),ph->GetPos().Z()); |
---|
77 | } |
---|
78 | |
---|
79 | fPoints[i->first]->SetMarkerColor(color); |
---|
80 | } |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | //______________________________________________________________________________ |
---|
85 | void EOpticsPhotonsPainter::Draw( Option_t* option ) { |
---|
86 | // |
---|
87 | // |
---|
88 | // |
---|
89 | |
---|
90 | Bool_t has_pad = (gPad==0)?kFALSE:kTRUE; |
---|
91 | #if ( ROOT_VERSION_CODE <= ROOT_VERSION(5,16,00) ) |
---|
92 | if (!gROOT->GetMakeDefCanvas()) return; |
---|
93 | (gROOT->GetMakeDefCanvas()); |
---|
94 | #else |
---|
95 | if (!gROOT->MakeDefCanvas()) return; |
---|
96 | (gROOT->MakeDefCanvas()); |
---|
97 | #endif |
---|
98 | |
---|
99 | AppendPad(option); |
---|
100 | |
---|
101 | // Create a 3-D view |
---|
102 | TView *view = gPad->GetView(); |
---|
103 | if (!view) { |
---|
104 | #if ( ROOT_VERSION_CODE <= ROOT_VERSION(5,16,00) ) |
---|
105 | view = new TView(11); |
---|
106 | #else |
---|
107 | view =TView::CreateView(1); |
---|
108 | #endif |
---|
109 | #if ( ROOT_VERSION_CODE <= ROOT_VERSION(4,03,02) ) |
---|
110 | view->SetAutoRange(kTRUE); |
---|
111 | TBuffer3D *buff = gPad->GetBuffer3D(); |
---|
112 | buff->fOption = TBuffer3D::kRANGE; |
---|
113 | Paint("range"); |
---|
114 | buff->fOption = TBuffer3D::kPAD; |
---|
115 | view->SetAutoRange(kFALSE); |
---|
116 | #else |
---|
117 | view->SetAutoRange(kTRUE); |
---|
118 | Paint("range"); |
---|
119 | view->SetAutoRange(kFALSE); |
---|
120 | #endif // ROOT_VERSION_CODE <= ROOT_VERSION(4,03,02) |
---|
121 | if (has_pad) gPad->Update(); |
---|
122 | } |
---|
123 | |
---|
124 | if (!view->IsPerspective()) view->SetPerspective(); |
---|
125 | |
---|
126 | TAxis3D::ToggleRulers(); |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | //______________________________________________________________________________ |
---|
131 | void EOpticsPhotonsPainter::Paint( Option_t* option ) { |
---|
132 | // |
---|
133 | // |
---|
134 | // |
---|
135 | |
---|
136 | map < Int_t, TPolyMarker3D* >::const_iterator j; |
---|
137 | for ( j=fPoints.begin(); j != fPoints.end(); j++ ) { |
---|
138 | j->second->Paint( option ); |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|