]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTPCSector3D.cxx
Coverity
[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.07),
45   fZStep     (250.0/900),
46   fCutOnEta  (kFALSE),
47   fEtaMin    (-1.5),
48   fEtaMax    (1.5)
49
50 {
51   // Constructor.
52
53   fRnrFrame = kTRUE;
54   ComputeBBox();
55 }
56
57 /******************************************************************************/
58
59 void AliEveTPCSector3D::SetRnrFrame(Bool_t rf)
60 {
61   // Setter for fRnrFrame.
62
63   if(fRnrFrame != rf) {
64     fRnrFrame = rf;
65     IncRTS();
66   }
67 }
68
69 /******************************************************************************/
70
71 void AliEveTPCSector3D::ComputeBBox()
72 {
73   // Compute bounding box containing whole sector.
74
75   const AliEveTPCSectorData::SegmentInfo&  iSeg = AliEveTPCSectorData::GetInnSeg();
76   const AliEveTPCSectorData::SegmentInfo& o2Seg = AliEveTPCSectorData::GetOut2Seg();
77
78   BBoxInit();
79
80   Float_t w = 0.5*o2Seg.GetNMaxPads()*o2Seg.GetPadWidth();
81   fBBox[0] = -w;
82   fBBox[1] =  w;
83   fBBox[2] =  iSeg.GetRLow();
84   fBBox[3] =  o2Seg.GetRLow() + o2Seg.GetNRows()*o2Seg.GetPadHeight();
85   fBBox[4] =  0;
86   fBBox[5] =  AliEveTPCSectorData::GetZLength();
87   Float_t* b = fBoxSet.AssertBBox();
88   for (Int_t i=0; i<6; ++i) { b[i] = fBBox[i]; }
89 }
90
91 void AliEveTPCSector3D::Paint(Option_t* /*option*/)
92 {
93   // Paint object.
94
95   if(fRnrSelf == kFALSE)
96     return;
97
98   TBuffer3D buffer(TBuffer3DTypes::kGeneric);
99
100   SetMainColor(36);
101   SetMainTransparency(100);
102
103   // Section kCore
104   buffer.fID           = this;
105   buffer.fColor        = GetMainColor();
106   buffer.fTransparency = GetMainTransparency();
107   if (HasMainTrans()) RefMainTrans().SetBuffer3D(buffer);
108   buffer.SetSectionsValid(TBuffer3D::kCore);
109
110   Int_t reqSections = gPad->GetViewer3D()->AddObject(buffer);
111   if (reqSections == TBuffer3D::kNone) {
112     return;
113   }
114
115   Error("AliEveTPCSector3D::Paint", "only direct OpenGL rendering supported.");
116   return;
117 }
118
119 /******************************************************************************/
120
121 void AliEveTPCSector3D::LoadPadrow(AliEveTPCSectorData::RowIterator& iter,
122                                    Float_t xs, Float_t ys,
123                                    Float_t pw, Float_t ph)
124 {
125   // Load data of one padrow. Fill internal boxset and pointset objects.
126
127   Short_t pad, time, val;
128   Float_t x0, z0;
129   Float_t ym = ys + 0.5*ph;
130   Float_t zs = fZStep/fDriftVel;
131   Float_t eta, x1, y1, z1, x, y, z, c, s, zL;
132
133   while (iter.NextPad())
134   {
135     pad = iter.TEvePad();
136     while (iter.Next())
137     {
138       time = iter.Time();
139       val  = iter.Signal();
140
141       if (val <= fThreshold || time < fMinTime || time > fMaxTime)
142         continue;
143
144       if (fCutOnEta)
145       {
146
147         x1 = xs + (pad+0.5)*pw;
148         y1 = ym;
149         z1 = (time+0.5)*zs;
150
151         c = TMath::Cos((fSectorID + 0.5)*20*TMath::Pi()/180 - TMath::PiOver2());
152         s = TMath::Sin((fSectorID + 0.5)*20*TMath::Pi()/180 - TMath::PiOver2());
153         zL = AliEveTPCSectorData::GetZLength();
154
155         if (fSectorID < 18)
156         {
157           x = -c*x1-s*y1;
158           y = -s*x1+c*y1;
159           z = -z1+zL;
160         } 
161         else
162         {
163           x = c*x1+s*y1;
164           y = -s*x1+c*y1;
165           z = z1-zL;
166         }
167
168         eta = -TMath::Log(TMath::Tan(0.5*TMath::ACos(z/TMath::Sqrt(x*x + y*y + z*z))));
169
170         if(!(eta < fEtaMax && eta > fEtaMin) && !(-eta < fEtaMax && -eta > fEtaMin))
171           continue;
172
173       }
174
175       if (fPointSetOn && val <= fPointSetMaxVal)
176       {
177         fPointSetArray.Fill(xs + (pad+0.5)*pw, ym, (time+0.5)*zs, val);
178       }
179       else
180       {
181         x0 = xs + pad*pw;
182         z0 = time*zs;
183         fBoxSet.AddBox(x0, ys, z0, pw, ph, zs);
184         fBoxSet.DigitColor(ColorFromArray(val));
185       }
186     }
187   }
188 }
189
190 void AliEveTPCSector3D::UpdateBoxesAndPoints()
191 {
192   // Populate BoxSet and PointSet with digit information.
193
194   // printf("AliEveTPCSector3D update boxes\n");
195
196   fBoxSet.Reset(TEveBoxSet::kBT_AABox, kTRUE, 16384);
197   // Brutally delete sub-pointsets so that destruction via TEveManager is
198   // avoided. This only works because fPointSetArray is never published.
199   for (Int_t i = 0; i < fPointSetArray.GetNBins(); ++i)
200     delete fPointSetArray.GetBin(i);
201   fPointSetArray.RemoveElementsLocal();
202
203   AliEveTPCSectorData* data = GetSectorData();
204   if (data != 0) {
205     Bool_t isOn[3];
206     isOn[0] = fRnrInn;
207     isOn[1] = fRnrOut1;
208     isOn[2] = fRnrOut2;
209
210     SetupColorArray();
211     SetupPointSetArray();
212
213     // Loop over 3 main segments
214     for (Int_t sId = 0; sId <= 2; ++sId)
215     {
216       if (isOn[sId] == kFALSE)
217         continue;
218       const AliEveTPCSectorData::SegmentInfo& sInfo = AliEveTPCSectorData::GetSeg(sId);
219       Float_t sy = sInfo.GetRLow();
220       for (Int_t row=sInfo.GetFirstRow(); row<=sInfo.GetLastRow(); ++row)
221       {
222         AliEveTPCSectorData::RowIterator i = data->MakeRowIterator(row);
223         Float_t sx = -0.5*AliEveTPCSectorData::GetNPadsInRow(row)*sInfo.GetPadWidth();
224         LoadPadrow(i, sx, sy, sInfo.GetPadWidth(), sInfo.GetPadHeight());
225         sy += sInfo.GetPadHeight();
226       }
227     }
228
229     fBoxSet.RefitPlex();
230     if (fPointSetOn)
231       fPointSetArray.CloseBins();
232   }
233 }
234
235 void AliEveTPCSector3D::SetupPointSetArray()
236 {
237   // Setup fPointSetArray for current settings.
238
239   Int_t nBins = (Int_t) TMath::Nint(fPointFrac*gStyle->GetNumberOfColors());
240   if (nBins > 0) {
241     fPointSetOn = kTRUE;
242     fPointSetMaxVal = fThreshold + (Int_t) TMath::Nint(fPointFrac*(fMaxVal - fThreshold));
243     // printf("SetupPointSetArray frac=%f nbins=%d psmv=%d (%d,%d)\n", fPointFrac, nBins, fPointSetMaxVal, fThreshold, fMaxVal);
244     fPointSetArray.InitBins("", nBins, fThreshold, fPointSetMaxVal);
245     for (Int_t b=0; b<nBins; ++b) {
246       fPointSetArray.GetBin(b)->SetMarkerColor(gStyle->GetColorPalette(b));
247     }
248   } else {
249     fPointSetOn = kFALSE;
250   }
251 }