]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTPCSector3D.cxx
3b5cb59543d9733d1b0f3106a204548d4f734c6f
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTPCSector3D.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 "AliEveTPCSector3D.h"
11 #include <EveDet/AliEveTPCSectorData.h>
12
13 #include <TEveTrans.h>
14
15 #include <TBuffer3D.h>
16 #include <TBuffer3DTypes.h>
17 #include <TVirtualPad.h>
18 #include <TVirtualViewer3D.h>
19
20 #include <TStyle.h>
21
22 //==============================================================================
23 //==============================================================================
24 // AliEveTPCSector3D
25 //==============================================================================
26
27 //______________________________________________________________________________
28 //
29 // Visualization of TPC raw-data in 3D.
30
31 ClassImp(AliEveTPCSector3D)
32
33 AliEveTPCSector3D::AliEveTPCSector3D(const Text_t* n, const Text_t* t) :
34   AliEveTPCSectorViz(n, t),
35
36   fBoxSet       (n, t),
37   fPointSetArray(n, t),
38   fPointFrac    (0.25),
39   fPointSize    (3),
40
41   fPointSetOn     (0),
42   fPointSetMaxVal (0),
43
44   fDriftVel  (1),
45   fZStep     (250.0/450)
46 {
47   // Constructor.
48
49   fRnrFrame = kFALSE;
50   ComputeBBox();
51 }
52
53 /******************************************************************************/
54
55 void AliEveTPCSector3D::SetRnrFrame(Bool_t rf)
56 {
57   // Setter for fRnrFrame.
58
59   if(fRnrFrame != rf) {
60     fRnrFrame = rf;
61     IncRTS();
62   }
63 }
64
65 /******************************************************************************/
66
67 void AliEveTPCSector3D::ComputeBBox()
68 {
69   // Compute bounding box containing whole sector.
70
71   const AliEveTPCSectorData::SegmentInfo&  iSeg = AliEveTPCSectorData::GetInnSeg();
72   const AliEveTPCSectorData::SegmentInfo& o2Seg = AliEveTPCSectorData::GetOut2Seg();
73
74   BBoxInit();
75
76   Float_t w = 0.5*o2Seg.GetNMaxPads()*o2Seg.GetPadWidth();
77   fBBox[0] = -w;
78   fBBox[1] =  w;
79   fBBox[2] =  iSeg.GetRLow();
80   fBBox[3] =  o2Seg.GetRLow() + o2Seg.GetNRows()*o2Seg.GetPadHeight();
81   fBBox[4] =  0;
82   fBBox[5] =  AliEveTPCSectorData::GetZLength();
83   Float_t* b = fBoxSet.AssertBBox();
84   for(Int_t i=0; i<6; ++i) { b[i] = fBBox[i]; }
85
86 }
87
88 void AliEveTPCSector3D::Paint(Option_t* /*option*/)
89 {
90   // Paint object.
91
92   if(fRnrSelf == kFALSE)
93     return;
94
95   TBuffer3D buffer(TBuffer3DTypes::kGeneric);
96
97   // Section kCore
98   buffer.fID           = this;
99   buffer.fColor        = 1;
100   buffer.fTransparency = 0;
101   if (HasMainTrans()) RefMainTrans().SetBuffer3D(buffer);
102   buffer.SetSectionsValid(TBuffer3D::kCore);
103
104   Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer);
105   if (reqSections == TBuffer3D::kNone) {
106     return;
107   }
108
109   Error("AliEveTPCSector3D::Paint", "only direct OpenGL rendering supported.");
110   return;
111 }
112
113 /******************************************************************************/
114
115 void AliEveTPCSector3D::LoadPadrow(AliEveTPCSectorData::RowIterator& iter,
116                              Float_t xs, Float_t ys, Float_t pw, Float_t ph)
117 {
118   // Load data of one padrow. Fill internal boxset and pointset objects.
119
120   Short_t pad, time, val;
121   Float_t x0, z0;
122   Float_t ym = ys + 0.5*ph;
123   Float_t zs = fZStep/fDriftVel;
124
125   while (iter.NextPad())
126   {
127     pad = iter.TEvePad();
128     while (iter.Next())
129     {
130       time = iter.Time();
131       val  = iter.Signal();
132
133       if(val <= fThreshold || time < fMinTime || time > fMaxTime)
134         continue;
135
136       if(fPointSetOn && val <= fPointSetMaxVal)
137       {
138         fPointSetArray.Fill(xs + (pad+0.5)*pw, ym, (time+0.5)*zs, val);
139       }
140       else
141       {
142         x0 = xs + pad*pw;
143         z0 = time*zs;
144         fBoxSet.AddBox(x0, ys, z0, pw, ph, zs);
145         fBoxSet.DigitColor(ColorFromArray(val));
146       }
147     }
148   }
149 }
150
151 void AliEveTPCSector3D::UpdateBoxesAndPoints()
152 {
153   // Populate BoxSet and PointSet with digit information.
154
155   // printf("AliEveTPCSector3D update boxes\n");
156
157   fBoxSet.Reset(TEveBoxSet::kBT_AABox, kTRUE, 16384);
158   fPointSetArray.RemoveElements();
159
160   AliEveTPCSectorData* data = GetSectorData();
161   if (data != 0) {
162     Bool_t isOn[3];
163     isOn[0] = fRnrInn;
164     isOn[1] = fRnrOut1;
165     isOn[2] = fRnrOut2;
166
167     SetupColorArray();
168     SetupPointSetArray();
169
170     // Loop over 3 main segments
171     for (Int_t sId = 0; sId <= 2; ++sId) {
172       if(isOn[sId] == kFALSE)
173         continue;
174       const AliEveTPCSectorData::SegmentInfo& sInfo = AliEveTPCSectorData::GetSeg(sId);
175       Float_t sy = sInfo.GetRLow();
176       for (Int_t row=sInfo.GetFirstRow(); row<=sInfo.GetLastRow(); ++row) {
177         AliEveTPCSectorData::RowIterator i = data->MakeRowIterator(row);
178         Float_t sx = -0.5*AliEveTPCSectorData::GetNPadsInRow(row)*sInfo.GetPadWidth();
179         LoadPadrow(i, sx, sy, sInfo.GetPadWidth(), sInfo.GetPadHeight());
180         sy += sInfo.GetPadHeight();
181       }
182     }
183
184     fBoxSet.RefitPlex();
185     if (fPointSetOn)
186       fPointSetArray.CloseBins();
187   }
188 }
189
190 void AliEveTPCSector3D::SetupPointSetArray()
191 {
192   // Setup fPointSetArray for current settings.
193
194   Int_t nBins = (Int_t) TMath::Nint(fPointFrac*gStyle->GetNumberOfColors());
195   if (nBins > 0) {
196     fPointSetOn = kTRUE;
197     fPointSetMaxVal = fThreshold + (Int_t) TMath::Nint(fPointFrac*(fMaxVal - fThreshold));
198     // printf("SetupPointSetArray frac=%f nbins=%d psmv=%d (%d,%d)\n", fPointFrac, nBins, fPointSetMaxVal, fThreshold, fMaxVal);
199     fPointSetArray.InitBins("", nBins, fThreshold, fPointSetMaxVal);
200     for (Int_t b=0; b<nBins; ++b) {
201       fPointSetArray.GetBin(b)->SetMarkerColor(gStyle->GetColorPalette(b));
202     }
203   } else {
204     fPointSetOn = kFALSE;
205   }
206 }