]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/TPCSectorViz.cxx
Added optimised color lookup function/cache; do not alow threshold to overrun maxval...
[u/mrichter/AliRoot.git] / EVE / Alieve / TPCSectorViz.cxx
1 // $Header$
2
3 #include "TPCSectorViz.h"
4
5 #include <Alieve/TPCData.h>
6 #include <Alieve/TPCSectorData.h>
7 #include <AliTPCParam.h>
8
9 #include <TStyle.h>
10 #include <TColor.h>
11
12 using namespace Reve;
13 using namespace Alieve;
14
15 //______________________________________________________________________
16 // TPCSectorViz
17 //
18 // Base class for TPC raw-data visualization.
19 // See TPCSector2D and TPCSector3D for concrete implementations.
20
21 ClassImp(TPCSectorViz)
22
23 /**************************************************************************/
24
25 TPCSectorViz::TPCSectorViz(const Text_t* n, const Text_t* t) :
26   TNamed(n, t),
27   Reve::RenderElement(fFrameColor),
28
29   fTPCData  (0),
30   fSectorID (0),
31
32   fMinTime   (0),
33   fMaxTime   (450),
34   fThreshold (5),
35   fMaxVal    (80),
36
37   fRnrInn   (kTRUE),
38   fRnrOut1  (kTRUE),
39   fRnrOut2  (kTRUE),
40
41   fFrameColor ((Color_t) 4),
42   fRnrFrame (kTRUE),
43   fTrans    (kFALSE),
44   fRTS      (1),
45
46   fColorArray (0)
47 {}
48
49 TPCSectorViz::~TPCSectorViz()
50 {
51   if(fTPCData) fTPCData->DecRefCount();
52   delete [] fColorArray;
53 }
54
55 void TPCSectorViz::CopyVizParams(const TPCSectorViz& v)
56 {
57   fMinTime   = v.fMinTime;
58   fMaxTime   = v.fMaxTime;
59   fThreshold = v.fThreshold;
60   fMaxVal    = v.fMaxVal;
61
62   fRnrInn    = v.fRnrInn;
63   fRnrOut1   = v.fRnrOut1;
64   fRnrOut2   = v.fRnrOut2;
65 }
66
67 /**************************************************************************/
68
69 void TPCSectorViz::SetDataSource(TPCData* data)
70 {
71   if(data == fTPCData) return;
72   if(fTPCData) fTPCData->DecRefCount();
73   fTPCData = data;
74   if(fTPCData) fTPCData->IncRefCount();
75   IncRTS();
76 }
77
78 void TPCSectorViz::SetSectorID(Int_t id)
79 {
80   if(id < 0)  id = 0;
81   if(id > 35) id = 35;
82   fSectorID = id;
83   if(fTrans)
84     SetTrans(kTRUE); // Force repositioning.
85   IncRTS();
86 }
87
88 TPCSectorData* TPCSectorViz::GetSectorData() const
89 {
90   return fTPCData ? fTPCData->GetSectorData(fSectorID) : 0;
91 }
92
93 /**************************************************************************/
94
95 void TPCSectorViz::SetThreshold(Short_t t)
96 {
97   fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
98   ClearColorArray();
99   IncRTS();
100 }
101
102 void TPCSectorViz::SetMaxVal(Int_t mv)
103 {
104   fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
105   ClearColorArray();
106   IncRTS();
107 }
108
109 /**************************************************************************/
110
111 void TPCSectorViz::SetTrans(Bool_t trans) 
112 {
113   fTrans = trans;
114   if(fTrans) {
115     for (Int_t k=0; k<16; ++k)
116       fMatrix[k] = 0.;
117
118     using namespace TMath;
119     Float_t c = Cos((fSectorID + 0.5)*20*Pi()/180 - PiOver2());
120     Float_t s = Sin((fSectorID + 0.5)*20*Pi()/180 - PiOver2());
121     Float_t z = TPCSectorData::GetParam().GetZLength();
122     if(fSectorID >= 18) z = -z;
123   
124     // column major
125     fMatrix[0]  = -c;
126     fMatrix[1]  = -s;
127     fMatrix[4]  = -s;
128     fMatrix[5]  =  c;
129     fMatrix[10] = -1;
130     fMatrix[14] =  z;
131     fMatrix[15] =  1;
132   }
133 }
134
135 /**************************************************************************/
136
137 void TPCSectorViz::SetupColor(Int_t val, UChar_t* pixel) const
138 {
139   using namespace TMath;
140   Float_t div  = Max(1, fMaxVal - fThreshold);
141   Int_t   nCol = gStyle->GetNumberOfColors();
142   Int_t   cBin = (Int_t) Nint(nCol*(val - fThreshold)/div);
143
144   ColorFromIdx(gStyle->GetColorPalette(Min(nCol - 1, cBin)), pixel);
145 }
146
147 void TPCSectorViz::ClearColorArray()
148 {
149   if(fColorArray) {
150     delete [] fColorArray;
151     fColorArray = 0;
152   }
153 }
154
155 void TPCSectorViz::SetupColorArray() const
156 {
157   if(fColorArray)
158     return;
159
160   fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)];
161   UChar_t* p = fColorArray;
162   for(Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4)
163     SetupColor(v, p);
164 }