]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/TPCSector3D.cxx
Adapt to new QuadSet implementation.
[u/mrichter/AliRoot.git] / EVE / Alieve / TPCSector3D.cxx
1 // $Header$
2
3 #include "TPCSector3D.h"
4 #include <Alieve/TPCSectorData.h>
5
6 #include <TBuffer3D.h>
7 #include <TBuffer3DTypes.h>
8 #include <TVirtualPad.h>
9 #include <TVirtualViewer3D.h>
10
11 #include <TStyle.h>
12 #include <TColor.h>
13
14 using namespace Reve;
15 using namespace Alieve;
16
17 //______________________________________________________________________
18 // TPCSector3D
19 //
20
21 ClassImp(TPCSector3D)
22
23 TPCSector3D::TPCSector3D(const Text_t* n, const Text_t* t) :
24   TPCSectorViz(n, t),
25
26   fBoxSet       (n, t),
27   fPointSetArray(n, t),
28   fPointFrac    (0.25),
29   fPointSize    (3),
30
31   fPointSetOn     (0),
32   fPointSetMaxVal (0),
33
34   fDriftVel  (1),
35   fZStep     (250.0/450)
36 {
37   fRnrFrame = kFALSE;
38   ComputeBBox();
39 }
40
41 TPCSector3D::~TPCSector3D()
42 {}
43
44 /**************************************************************************/
45
46 void TPCSector3D::SetRnrFrame(Bool_t rf)
47 {
48   if(fRnrFrame != rf) {
49     fRnrFrame = rf;
50     IncRTS();
51   }
52 }
53
54 /**************************************************************************/
55
56 void TPCSector3D::ComputeBBox()
57 {
58   const TPCSectorData::SegmentInfo&  iSeg = TPCSectorData::GetInnSeg();
59   const TPCSectorData::SegmentInfo& o2Seg = TPCSectorData::GetOut2Seg();
60
61 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,11,2)
62   bbox_init();
63 #else
64   BBoxInit();
65 #endif
66   Float_t w = 0.5*o2Seg.GetNMaxPads()*o2Seg.GetPadWidth();
67   fBBox[0] = -w;
68   fBBox[1] =  w;
69   fBBox[2] =  iSeg.GetRLow();
70   fBBox[3] =  o2Seg.GetRLow() + o2Seg.GetNRows()*o2Seg.GetPadHeight();
71   fBBox[4] =  0;
72   fBBox[5] =  TPCSectorData::GetZLength();
73   Float_t* b = fBoxSet.AssertBBox();
74   for(Int_t i=0; i<6; ++i) { b[i] = fBBox[i]; }
75
76 }
77
78 void TPCSector3D::Paint(Option_t* /*option*/)
79 {
80   if(fRnrElement == kFALSE)
81     return;
82
83   TBuffer3D buffer(TBuffer3DTypes::kGeneric);
84
85   // Section kCore
86   buffer.fID           = this;
87   buffer.fColor        = 1;
88   buffer.fTransparency = 0;
89   fHMTrans.SetBuffer3D(buffer);
90   buffer.SetSectionsValid(TBuffer3D::kCore);
91    
92   Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer);
93   if (reqSections == TBuffer3D::kNone) {
94     return;
95   }
96
97   Error("TPCSector3D::Paint", "only direct OpenGL rendering supported.");
98   return;
99 }
100
101 /**************************************************************************/
102
103 void TPCSector3D::LoadPadrow(TPCSectorData::RowIterator& iter,
104                              Float_t xs, Float_t ys, Float_t pw, Float_t ph) 
105 {
106   Short_t pad, time, val;
107   Float_t x0, x1, z0, z1;
108   Float_t ym = ys + 0.5*ph;
109   Float_t ye = ys + ph;
110   Float_t zs = fZStep/fDriftVel;
111
112   while (iter.NextPad()) {
113     pad = iter.Pad();
114     while (iter.Next()) {
115       time = iter.Time();
116       val  = iter.Signal();
117
118       if(val <= fThreshold || time < fMinTime || time > fMaxTime)
119         continue;
120
121       if(fPointSetOn && val <= fPointSetMaxVal) {
122         fPointSetArray.Fill(xs + (pad+0.5)*pw, ym, (time+0.5)*zs, val);
123       } else {
124         fBoxSet.fBoxes.push_back(Reve::Box());
125         ColorFromArray(val, fBoxSet.fBoxes.back().color);
126         x0 = xs + pad*pw;
127         x1 = x0 + pw;
128         z0 = time*zs;
129         z1 = z0 + zs;
130         Float_t* p = fBoxSet.fBoxes.back().vertices; 
131         // front
132         p[0] = x0;  p[1] = ys;  p[2] = z0;  p += 3;
133         p[0] = x1;  p[1] = ys;  p[2] = z0;  p += 3;
134         p[0] = x1;  p[1] = ye;  p[2] = z0;  p += 3;
135         p[0] = x0;  p[1] = ye;  p[2] = z0;  p += 3;
136         // back
137         p[0] = x0;  p[1] = ys;  p[2] = z1;  p += 3;
138         p[0] = x1;  p[1] = ys;  p[2] = z1;  p += 3;
139         p[0] = x1;  p[1] = ye;  p[2] = z1;  p += 3;
140         p[0] = x0;  p[1] = ye;  p[2] = z1;
141       }
142     }
143   }
144 }
145
146 void TPCSector3D::UpdateBoxes()
147 {
148   // Populate parent class Reve::BoxSet with digit information.
149
150   // printf("TPCSector3D update boxes\n");
151
152   fBoxSet.ClearSet();
153   fPointSetArray.RemoveElements();
154
155   TPCSectorData* data = GetSectorData();
156   if (data != 0) {
157     Bool_t isOn[3];
158     isOn[0] = fRnrInn;
159     isOn[1] = fRnrOut1;
160     isOn[2] = fRnrOut2;
161
162     SetupColorArray();
163     SetupPointSetArray();
164
165     // Loop over 3 main segments
166     for (Int_t sId = 0; sId <= 2; ++sId) {
167       if(isOn[sId] == kFALSE)
168         continue;
169       const TPCSectorData::SegmentInfo& sInfo = TPCSectorData::GetSeg(sId);
170       Float_t sy = sInfo.GetRLow();
171       for (Int_t row=sInfo.GetFirstRow(); row<=sInfo.GetLastRow(); ++row) {
172         TPCSectorData::RowIterator i = data->MakeRowIterator(row);
173         Float_t sx = -0.5*TPCSectorData::GetNPadsInRow(row)*sInfo.GetPadWidth();
174         LoadPadrow(i, sx, sy, sInfo.GetPadWidth(), sInfo.GetPadHeight());
175         sy += sInfo.GetPadHeight();
176       }
177     }
178
179     if(fPointSetOn)
180       fPointSetArray.CloseBins();
181   }
182 }
183
184 void TPCSector3D::SetupPointSetArray()
185 {
186   Int_t   nBins = (Int_t) TMath::Nint(fPointFrac*gStyle->GetNumberOfColors());
187   if(nBins > 0) {
188     fPointSetOn = kTRUE;
189     fPointSetMaxVal = fThreshold + (Int_t) TMath::Nint(fPointFrac*(fMaxVal - fThreshold));
190     // printf("SetupPointSetArray frac=%f nbins=%d psmv=%d (%d,%d)\n", fPointFrac, nBins, fPointSetMaxVal, fThreshold, fMaxVal);
191     fPointSetArray.InitBins("", nBins, fThreshold, fPointSetMaxVal, kFALSE);
192     for(Int_t b=0; b<nBins; ++b) {
193       fPointSetArray.GetBin(b)->SetMarkerColor(gStyle->GetColorPalette(b));
194     }
195   } else {
196     fPointSetOn = kFALSE;
197   }
198 }