Coverity
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSModule.cxx
CommitLineData
d810d0de 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 *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
0879c50b 9
d810d0de 10#include "AliEveITSModule.h"
5a5a1232 11
12f6a2f3 12#include <AliITSgeomTGeo.h>
0879c50b 13#include <AliITSsegmentationSPD.h>
14#include <AliITSsegmentationSDD.h>
15#include <AliITSsegmentationSSD.h>
16
5a5a1232 17#include <AliITSdigitSPD.h>
18#include <AliITSdigitSDD.h>
19#include <AliITSdigitSSD.h>
20
a15e6d7d 21#include <TEveTrans.h>
22#include <TClonesArray.h>
5a5a1232 23#include <TStyle.h>
5a5a1232 24
9efc978d 25
698e2c9b 26//______________________________________________________________________________
27//
28// Visualization of an ITS module.
29
30ClassImp(AliEveITSModule)
31
0879c50b 32Bool_t AliEveITSModule::fgStaticInitDone = kFALSE;
d810d0de 33
105fb267 34TEveFrameBox* AliEveITSModule::fgSPDFrameBox = 0;
fe6798e0 35TEveFrameBox* AliEveITSModule::fgSPDFrameBoxDead = 0;
105fb267 36TEveFrameBox* AliEveITSModule::fgSDDFrameBox = 0;
37TEveFrameBox* AliEveITSModule::fgSDDFrameBoxDead = 0;
38TEveFrameBox* AliEveITSModule::fgSSDFrameBox = 0;
39TEveFrameBox* AliEveITSModule::fgSSDFrameBoxDead = 0;
9efc978d 40
d810d0de 41TEveRGBAPalette* AliEveITSModule::fgSPDPalette = 0;
42TEveRGBAPalette* AliEveITSModule::fgSDDPalette = 0;
43TEveRGBAPalette* AliEveITSModule::fgSSDPalette = 0;
9efc978d 44
57ffa5fb 45/******************************************************************************/
5a5a1232 46
d810d0de 47AliEveITSModule::AliEveITSModule(const Text_t* n, const Text_t* t) :
84aff7a4 48 TEveQuadSet(n, t),
265ecb21 49 fInfo(0),
50 fID(-1), fDetID(-1),
51 fLayer(-1), fLadder(-1), fDet(-1),
9efc978d 52 fDx(0), fDz(0), fDy(0)
698e2c9b 53{
54 // Constructor.
55}
5a5a1232 56
d810d0de 57AliEveITSModule::AliEveITSModule(Int_t gid, AliEveITSDigitsInfo* info) :
84aff7a4 58 TEveQuadSet(Form("ITS module %d", gid)),
27db2029 59 fInfo (0),
265ecb21 60 fID(-1), fDetID(-1),
61 fLayer(-1), fLadder(-1), fDet(-1),
9efc978d 62 fDx(0), fDz(0), fDy(0)
5a5a1232 63{
698e2c9b 64 // Constructor with module id and data-source.
65
27db2029 66 SetDigitsInfo(info);
9c8221e9 67 SetID(gid);
5a5a1232 68}
69
d810d0de 70AliEveITSModule::~AliEveITSModule()
5a5a1232 71{
698e2c9b 72 // Destructor.
73
4516a822 74 if (fInfo) fInfo->DecRefCount();
5a5a1232 75}
76
57ffa5fb 77/******************************************************************************/
5a5a1232 78
d810d0de 79void AliEveITSModule::InitStatics(AliEveITSDigitsInfo* info)
9efc978d 80{
c93f2d9b 81 // Initialize static variables.
82 //
83 // Warning all sensor sizes are in microns, here we transform them
84 // to cm. In Eve half-lengths/widths are used, hence another 1/2.
698e2c9b 85
9efc978d 86 if (fgStaticInitDone) return;
9c8221e9 87 fgStaticInitDone = kTRUE;
9efc978d 88
89 {
90 Float_t dx = info->fSegSPD->Dx()*0.00005;
c93f2d9b 91 Float_t dz = info->fSegSPD->Dz()*0.00005;
9efc978d 92
84aff7a4 93 fgSPDFrameBox = new TEveFrameBox();
9efc978d 94 fgSPDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
ab73f3eb 95 fgSPDFrameBox->SetFrameColor(Color_t(31));
32e219c2 96 fgSPDFrameBox->SetFrameFill(kTRUE);
97 fgSPDFrameBox->IncRefCount();
84aff7a4 98 fgSPDPalette = new TEveRGBAPalette(info->fSPDMinVal,info->fSPDMaxVal);
32e219c2 99 fgSPDPalette->IncRefCount();
fe6798e0 100
101 fgSPDFrameBoxDead = new TEveFrameBox();
102 fgSPDFrameBoxDead->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
103 fgSPDFrameBoxDead->SetFrameColor(kRed);
104 fgSPDFrameBoxDead->SetFrameFill(kTRUE);
105 fgSPDFrameBoxDead->IncRefCount();
9efc978d 106 }
107
108 {
109 Float_t dx = info->fSegSDD->Dx()*0.0001;
110 Float_t dz = info->fSegSDD->Dz()*0.00005;
111
84aff7a4 112 fgSDDFrameBox = new TEveFrameBox();
9efc978d 113 fgSDDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
ab73f3eb 114 fgSDDFrameBox->SetFrameColor(Color_t(32));
32e219c2 115 fgSDDFrameBox->SetFrameFill(kTRUE);
116 fgSDDFrameBox->IncRefCount();
84aff7a4 117 fgSDDPalette = new TEveRGBAPalette(info->fSDDMinVal,info->fSDDMaxVal);
32e219c2 118 fgSDDPalette->SetLimits(0, info->fSDDHighLim); // Set proper ADC range.
119 fgSDDPalette->IncRefCount();
105fb267 120
121 fgSDDFrameBoxDead = new TEveFrameBox();
122 fgSDDFrameBoxDead->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
123 fgSDDFrameBoxDead->SetFrameColor(kRed);
124 fgSDDFrameBoxDead->SetFrameFill(kTRUE);
125 fgSDDFrameBoxDead->IncRefCount();
9efc978d 126 }
127
128 {
129 Float_t dx = info->fSegSSD->Dx()*0.00005;
130 Float_t dz = info->fSegSSD->Dz()*0.00005;
131
84aff7a4 132 fgSSDFrameBox = new TEveFrameBox();
9efc978d 133 fgSSDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
ab73f3eb 134 fgSSDFrameBox->SetFrameColor(Color_t(33));
32e219c2 135 fgSSDFrameBox->SetFrameFill(kTRUE);
136 fgSSDFrameBox->IncRefCount();
84aff7a4 137 fgSSDPalette = new TEveRGBAPalette(info->fSSDMinVal,info->fSSDMaxVal);
32e219c2 138 fgSSDPalette->SetLimits(0, info->fSSDHighLim); // Set proper ADC range.
139 fgSSDPalette->IncRefCount();
105fb267 140
141 fgSSDFrameBoxDead = new TEveFrameBox();
142 fgSSDFrameBoxDead->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
143 fgSSDFrameBoxDead->SetFrameColor(kRed);
144 fgSSDFrameBoxDead->SetFrameFill(kTRUE);
145 fgSSDFrameBoxDead->IncRefCount();
9efc978d 146 }
147
148}
149
57ffa5fb 150/******************************************************************************/
9efc978d 151
d810d0de 152void AliEveITSModule::SetDigitsInfo(AliEveITSDigitsInfo* info)
5a5a1232 153{
698e2c9b 154 // Set data and geometry source.
155
9c8221e9 156 if (fInfo == info) return;
157 if (fInfo) fInfo->DecRefCount();
158 fInfo = info;
159 if (fInfo) fInfo->IncRefCount();
160}
161
57ffa5fb 162/******************************************************************************/
9c8221e9 163
d810d0de 164void AliEveITSModule::SetID(Int_t gid, Bool_t trans)
9c8221e9 165{
698e2c9b 166 // Set detector id.
167
a15e6d7d 168 static const TEveException kEH("AliEveITSModule::SetID ");
9efc978d 169
12f6a2f3 170 if (fInfo == 0)
a15e6d7d 171 throw(kEH + "AliEveITSDigitsInfo not set.");
9c8221e9 172
ff67a00a 173 Int_t firstSPD = AliITSgeomTGeo::GetModuleIndex(1,1,1);
174 Int_t lastSSD = AliITSgeomTGeo::GetNModules() - 1;
175 if (gid < firstSPD || gid > lastSSD)
12f6a2f3 176 {
a15e6d7d 177 throw(kEH + Form("%d is not valid. ID range from %d to %d", gid,
12f6a2f3 178 firstSPD, lastSSD ));
179 }
9c8221e9 180
181 fID = gid;
182
4516a822 183 if (!fgStaticInitDone)
184 {
1d3c2b09 185 InitStatics(fInfo);
1d3c2b09 186 }
9c8221e9 187
12f6a2f3 188 AliITSgeomTGeo::GetModuleId(fID, fLayer, fLadder, fDet);
ba6cfb13 189 TString strLadder = "Ladder";
190 TString strSensor = "Sensor";
191 TString symname;
9c8221e9 192 Int_t id, nsector, nstave, nladder, rest;
51346b82 193
12f6a2f3 194 if (fID <= (AliITSgeomTGeo::GetModuleIndex(3,1,1) - 1))
9efc978d 195 {
196 // SPD
197
fe6798e0 198 fDetID = 0;
199
200 SetFrame(fInfo->IsDead(fID, fDetID) ? fgSPDFrameBoxDead : fgSPDFrameBox);
9c8221e9 201 SetPalette(fgSPDPalette);
51346b82 202
9efc978d 203 symname += strLadder;
204 if (fID < 80)
205 {
ba6cfb13 206 nsector = fID/8;
9efc978d 207 rest = fID - 8*nsector;
208 nstave = 1;
209 }
210 else
211 {
212 id = fID - 80;
ba6cfb13 213 nsector = id/8;
9efc978d 214 rest = id - 8*nsector;
215 nstave = 1;
ba6cfb13 216 }
9efc978d 217 if (rest < 4) nstave = 0;
218 rest -= 4*nstave;
219 symname += rest;
220 SetName(symname);
9efc978d 221 fDx = fInfo->fSegSPD->Dx()*0.00005;
51346b82 222 fDz = 3.50;
9efc978d 223 fDy = fInfo->fSegSPD->Dy()*0.00005;
5a5a1232 224 }
12f6a2f3 225 else if (fID <= (AliITSgeomTGeo::GetModuleIndex(5,1,1) - 1))
9efc978d 226 {
227 // SDD
228
fe6798e0 229 fDetID = 1;
230
105fb267 231 SetFrame(fInfo->IsDead(fID, fDetID) ? fgSDDFrameBoxDead : fgSDDFrameBox);
9c8221e9 232 SetPalette(fgSDDPalette);
51346b82 233
9efc978d 234 symname += strSensor;
235 if (fID < 324)
236 {
237 id = fID - 240;
ba6cfb13 238 nladder = id/6;
9efc978d 239 rest = id - 6*nladder;
240 }
241 else
242 {
243 id = fID - 324;
ba6cfb13 244 nladder = id/8;
9efc978d 245 rest = id - 8*nladder;
ba6cfb13 246 }
9efc978d 247 symname += rest;
248 SetName(symname);
9efc978d 249 fDx = fInfo->fSegSDD->Dx()*0.0001;
250 fDz = fInfo->fSegSDD->Dz()*0.00005;
251 fDy = fInfo->fSegSDD->Dy()*0.00005;
5a5a1232 252 }
9efc978d 253 else
254 {
255 // SSD
256
fe6798e0 257 fDetID = 2;
258
105fb267 259 SetFrame(fInfo->IsDead(fID, fDetID) ? fgSSDFrameBoxDead : fgSSDFrameBox);
9c8221e9 260 SetPalette(fgSSDPalette);
261
9efc978d 262 symname += strSensor;
263 if (fID < 1248)
264 {
265 id = fID - 500;
ba6cfb13 266 nladder = id/22;
9efc978d 267 rest = id - nladder*22;
268 }
269 else
270 {
271 id = fID - 1248;
ba6cfb13 272 nladder = id/25;
9efc978d 273 rest = id - nladder*25;
ba6cfb13 274 }
9efc978d 275 symname += rest;
276 SetName(symname);
51346b82 277 fInfo->fSegSSD->SetLayer(fLayer);
9efc978d 278 fDx = fInfo->fSegSSD->Dx()*0.00005;
279 fDz = fInfo->fSegSSD->Dz()*0.00005;
280 fDy = fInfo->fSegSSD->Dy()*0.00005;
5a5a1232 281 }
282
51346b82 283 LoadQuads();
fe6798e0 284 RefitPlex();
5a5a1232 285 ComputeBBox();
a15e6d7d 286 InitMainTrans();
97e1e1bc 287 if (trans)
288 SetTrans();
fe6798e0 289
5a5a1232 290}
291
d810d0de 292void AliEveITSModule::LoadQuads()
5a5a1232 293{
698e2c9b 294 // Read module data from source and create low-level objects for
295 // visualization - called quads.
9efc978d 296
b3bc5327 297 TClonesArray *digits = fInfo->GetDigits(fID, fDetID);
298 Int_t ndigits = digits ? digits->GetEntriesFast() : 0;
299
51346b82 300 Float_t x, z, dpx, dpz;
b3bc5327 301 Int_t i, j;
5a5a1232 302
9efc978d 303 switch(fDetID)
304 {
4516a822 305 case 0:
306 {
51346b82 307 AliITSsegmentationSPD* seg = fInfo->fSegSPD;
9efc978d 308
84aff7a4 309 Reset(kQT_RectangleXZFixedY, kFALSE, 32);
5a5a1232 310
9efc978d 311 for (Int_t k=0; k<ndigits; ++k)
312 {
b3bc5327 313 AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
5a5a1232 314 j = d->GetCoord1();
315 i = d->GetCoord2();
9efc978d 316 x = -0.5*seg->Dx() + i*seg->Dpx(0);
317 x *= 0.0001;
318 fInfo->GetSPDLocalZ(j, z);
5a5a1232 319 dpx = seg->Dpx(i)*0.0001;
320 dpz = seg->Dpz(j)*0.0001;
321
9efc978d 322 AddQuad(x, z, dpx, dpz);
323 QuadValue(1); // In principle could have color based on number of neigbours
ffa36681 324 QuadId(d);
5a5a1232 325 }
9efc978d 326 break;
5a5a1232 327 }
5a5a1232 328
4516a822 329 case 1:
330 {
51346b82 331 AliITSsegmentationSDD *seg = fInfo->fSegSDD;
5a5a1232 332
84aff7a4 333 Reset(kQT_RectangleXZFixedY, kFALSE, 32);
9efc978d 334
335 for (Int_t k=0; k<ndigits; ++k)
336 {
b3bc5327 337 AliITSdigit* d = (AliITSdigit*) digits->UncheckedAt(k);
9efc978d 338
4516a822 339 j = d->GetCoord1();
340 i = d->GetCoord2();
341 seg->DetToLocal(i, j, x, z);
342 dpx = seg->Dpx(i)*0.0001;
343 dpz = seg->Dpz(j)*0.0001;
344
345 AddQuad(x-2*dpx, z - dpz*0.5, 4*dpx, dpz);
346 QuadValue(d->GetSignal());
347 QuadId(d);
9efc978d 348 }
349 break;
350 }
351
4516a822 352 case 2:
353 {
51346b82 354 AliITSsegmentationSSD* seg = fInfo->fSegSSD;
9efc978d 355
84aff7a4 356 Reset(kQT_LineXZFixedY, kFALSE, 32);
9efc978d 357
358 Float_t ap, an; // positive/negative angles -> offsets
359 seg->Angles(ap, an);
360 ap = TMath::Tan(ap) * fDz;
361 an = - TMath::Tan(an) * fDz;
362
363 for (Int_t k=0; k<ndigits; ++k)
364 {
b3bc5327 365 AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
4516a822 366
367 j = d->GetCoord1();
368 i = d->GetCoord2();
369 // !!!! The following function complains about not being verified.
370 // !!!! Experts should check.
371 seg->DetToLocal(i,j,x,z);
372
373 Float_t a = (d->GetCoord1() == 1) ? ap : an;
374
375 AddLine(x-a, -fDz, 2*a, 2*fDz);
376 QuadValue(d->GetSignal());
377 QuadId(d);
378 // printf("%3d -> %3d -> %8x\n", d->GetSignal(), ci, fQuads.back().color);
5a5a1232 379 }
9efc978d 380 break;
5a5a1232 381 }
5a5a1232 382
9efc978d 383 } // end switch
5a5a1232 384}
385
57ffa5fb 386/******************************************************************************/
5a5a1232 387
d810d0de 388void AliEveITSModule::SetTrans()
5a5a1232 389{
4852ff6f 390 // Set transformation matrix based on module id (use geometry to
391 // retrieve this information).
392
a15e6d7d 393 fMainTrans->SetFrom(*AliITSgeomTGeo::GetMatrix(fID));
5a5a1232 394}
395
57ffa5fb 396/******************************************************************************/
5a5a1232 397
d810d0de 398void AliEveITSModule::DigitSelected(Int_t idx)
ffa36681 399{
12f6a2f3 400 // Override secondary select (alt-click) from TEveQuadSet.
ffa36681 401
12f6a2f3 402 DigitBase_t *qb = GetDigit(idx);
d794819f 403 TObject *obj = GetId(idx);
12f6a2f3 404 AliITSdigit *d = dynamic_cast<AliITSdigit*>(obj);
d810d0de 405 printf("AliEveITSModule::QuadSelected "); Print();
ffa36681 406 printf(" idx=%d, value=%d, obj=0x%lx, digit=0x%lx\n",
407 idx, qb->fValue, (ULong_t)obj, (ULong_t)d);
408 if (d)
409 printf(" coord1=%3d coord2=%3d signal=%d\n",
410 d->GetCoord1(), d->GetCoord2(), d->GetSignal());
411
412}
413
57ffa5fb 414/******************************************************************************/
ffa36681 415
d810d0de 416void AliEveITSModule::Print(Option_t* ) const
5a5a1232 417{
698e2c9b 418 // Print object summary information.
419
420 printf("AliEveITSModule: ID %d, layer %d, ladder %d, det %d\n",
421 fID, fLayer, fLadder, fDetID);
5a5a1232 422}