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