]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTPCSectorViz.cxx
Fix signature of AliEveTPCSectorViz::CopyVizParams() to match the one in TEveElement...
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTPCSectorViz.cxx
1 // $Id$
2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4 /**************************************************************************
5  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #include "AliEveTPCSectorViz.h"
11
12 #include <EveDet/AliEveTPCData.h>
13 #include <EveDet/AliEveTPCSectorData.h>
14
15 #include <TEveTrans.h>
16 #include <TStyle.h>
17 #include <TMath.h>
18
19 //==============================================================================
20 //==============================================================================
21 // AliEveTPCSectorViz
22 //==============================================================================
23
24 //______________________________________________________________________________
25 //
26 // Base class for TPC raw-data visualization.
27 // See AliEveTPCSector2D and AliEveTPCSector3D for concrete implementations.
28
29 ClassImp(AliEveTPCSectorViz)
30
31 /******************************************************************************/
32
33 AliEveTPCSectorViz::AliEveTPCSectorViz(const Text_t* n, const Text_t* t) :
34   TEveElement(fFrameColor),
35   TNamed(n, t),
36
37   fTPCData  (0),
38   fSectorID (0),
39
40   fMinTime   (0),
41   fMaxTime   (450),
42   fThreshold (5),
43   fMaxVal    (128),
44
45   fRnrInn   (kTRUE),
46   fRnrOut1  (kTRUE),
47   fRnrOut2  (kTRUE),
48
49   fFrameColor ((Color_t) 4),
50   fRnrFrame   (kTRUE),
51   fAutoTrans  (kFALSE),
52   fRTS        (1),
53
54   fColorArray (0)
55 {
56   // Constructor.
57
58    InitMainTrans();
59 }
60
61 AliEveTPCSectorViz::~AliEveTPCSectorViz()
62 {
63   // Destructor.
64
65   if (fTPCData) fTPCData->DecRefCount();
66   delete [] fColorArray;
67 }
68
69 void AliEveTPCSectorViz::CopyVizParams(const TEveElement* el)
70 {
71   // Copy basic viualization parameters from another TPCSectorViz.
72
73   const AliEveTPCSectorViz* v = dynamic_cast<const AliEveTPCSectorViz*>(el);
74   if (v) {
75     fMinTime   = v->fMinTime;
76     fMaxTime   = v->fMaxTime;
77     fThreshold = v->fThreshold;
78     fMaxVal    = v->fMaxVal;
79
80     fRnrInn    = v->fRnrInn;
81     fRnrOut1   = v->fRnrOut1;
82     fRnrOut2   = v->fRnrOut2;
83   }
84 }
85
86 /******************************************************************************/
87
88 void AliEveTPCSectorViz::SetDataSource(AliEveTPCData* data)
89 {
90   // Set the data source.
91
92   if (data == fTPCData) return;
93   if (fTPCData) fTPCData->DecRefCount();
94   fTPCData = data;
95   if (fTPCData) fTPCData->IncRefCount();
96   IncRTS();
97 }
98
99 void AliEveTPCSectorViz::SetSectorID(Int_t id)
100 {
101   // Set sector id.
102
103   if (id < 0)  id = 0;
104   if (id > 35) id = 35;
105   fSectorID = id;
106   if (fAutoTrans)
107     SetAutoTrans(kTRUE); // Force repositioning.
108   IncRTS();
109 }
110
111 AliEveTPCSectorData* AliEveTPCSectorViz::GetSectorData() const
112 {
113   // Get sector-data.
114
115   return fTPCData ? fTPCData->GetSectorData(fSectorID) : 0;
116 }
117
118 /******************************************************************************/
119
120 void AliEveTPCSectorViz::SetThreshold(Short_t t)
121 {
122   // Set visualization threshold.
123
124   fThreshold = TMath::Min(t, (Short_t)(fMaxVal - 1));
125   ClearColorArray();
126   IncRTS();
127 }
128
129 void AliEveTPCSectorViz::SetMaxVal(Int_t mv)
130 {
131   // Set visualization max signal value.
132   // Signals above this will have the same color.
133
134   fMaxVal = TMath::Max(mv, (Int_t)(fThreshold + 1));
135   ClearColorArray();
136   IncRTS();
137 }
138
139 /******************************************************************************/
140
141 void AliEveTPCSectorViz::SetAutoTrans(Bool_t trans)
142 {
143   // Set automatic update of transformation matrix.
144   // The position is calculated immediately.
145
146   fAutoTrans = trans;
147   if (fAutoTrans)
148   {
149     using namespace TMath;
150     Float_t c = Cos((fSectorID + 0.5)*20*Pi()/180 - PiOver2());
151     Float_t s = Sin((fSectorID + 0.5)*20*Pi()/180 - PiOver2());
152     Float_t z = AliEveTPCSectorData::GetZLength();
153     Float_t d = -1;
154     if (fSectorID >= 18) {
155       z = -z;
156       d = -d;
157     }
158
159     // column major
160     InitMainTrans();
161     TEveTrans& t = RefMainTrans();
162     t[0]  = -c;  t[1]  = -s;
163     t[4]  = -s;  t[5]  =  c;
164     t[10] =  d;  t[14] =  z;
165   }
166 }
167 void AliEveTPCSectorViz::SetUseTrans(Bool_t t)
168 {
169   // Set flag spcifying if transformation matrix should be applied.
170
171   RefMainTrans().SetUseTrans(t);
172 }
173
174 /******************************************************************************/
175
176 void AliEveTPCSectorViz::SetupColor(Int_t val, UChar_t* pixel) const
177 {
178   // Set pixel color to represent signal val from the current palette.
179
180   using namespace TMath;
181   Float_t div  = Max(1, fMaxVal - fThreshold);
182   Int_t   nCol = gStyle->GetNumberOfColors();
183   Int_t   cBin = (Int_t) Nint(nCol*(val - fThreshold)/div);
184
185   TEveUtil::ColorFromIdx(gStyle->GetColorPalette(Min(nCol - 1, cBin)), pixel);
186 }
187
188 void AliEveTPCSectorViz::ClearColorArray()
189 {
190   // Clear cached color array.
191
192   if (fColorArray) {
193     delete [] fColorArray;
194     fColorArray = 0;
195   }
196 }
197
198 void AliEveTPCSectorViz::SetupColorArray() const
199 {
200   // Initialize cached color array.
201
202   if (fColorArray)
203     return;
204
205   fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)];
206   UChar_t* p = fColorArray;
207   for (Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4)
208     SetupColor(v, p);
209 }