]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTPCSectorViz.cxx
fix user histogram management and style (Ben)
[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   (1000),
42   fThreshold (5),
43   fMaxVal    (128),
44
45   fRnrInn   (kTRUE),
46   fRnrOut1  (kTRUE),
47   fRnrOut2  (kTRUE),
48
49   fFrameColor (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
154     InitMainTrans();
155     TEveTrans& t = RefMainTrans();
156
157     if (fSectorID < 18) {
158       // column major
159       t[0]  = -c;  t[1]  = -s;
160       t[4]  = -s;  t[5]  =  c;
161       t[10] = -1;
162       t[14] =  z;
163     } else {
164       t[0]  =  c;  t[1]  =  s;
165       t[4]  = -s;  t[5]  =  c;
166       t[10] =  1;
167       t[14] = -z;
168     }
169   }
170 }
171 void AliEveTPCSectorViz::SetUseTrans(Bool_t t)
172 {
173   // Set flag spcifying if transformation matrix should be applied.
174
175   RefMainTrans().SetUseTrans(t);
176 }
177
178 /******************************************************************************/
179
180 void AliEveTPCSectorViz::SetupColor(Int_t val, UChar_t* pixel) const
181 {
182   // Set pixel color to represent signal val from the current palette.
183
184   Float_t div  = TMath::Max(1, fMaxVal - fThreshold);
185   Int_t   nCol = gStyle->GetNumberOfColors();
186   Int_t   cBin = TMath::Nint(nCol*(val - fThreshold)/div);
187
188   TEveUtil::ColorFromIdx(gStyle->GetColorPalette(TMath::Min(nCol - 1, cBin)), pixel);
189 }
190
191 void AliEveTPCSectorViz::ClearColorArray()
192 {
193   // Clear cached color array.
194
195   if (fColorArray) {
196     delete [] fColorArray;
197     fColorArray = 0;
198   }
199 }
200
201 void AliEveTPCSectorViz::SetupColorArray() const
202 {
203   // Initialize cached color array.
204
205   if (fColorArray)
206     return;
207
208   fColorArray = new UChar_t [4 * (fMaxVal - fThreshold + 1)];
209   UChar_t* p = fColorArray;
210   for (Int_t v=fThreshold; v<=fMaxVal; ++v, p+=4)
211     SetupColor(v, p);
212 }