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