]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveITSModule.cxx
Fix compilation warning.
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSModule.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 "AliEveITSModule.h"
11
12 #include <AliITSgeomTGeo.h>
13 #include <AliITSsegmentationSPD.h>
14 #include <AliITSsegmentationSDD.h>
15 #include <AliITSsegmentationSSD.h>
16
17 #include <AliITSdigitSPD.h>
18 #include <AliITSdigitSDD.h>
19 #include <AliITSdigitSSD.h>
20
21 #include <TEveTrans.h>
22 #include <TClonesArray.h>
23 #include <TStyle.h>
24
25
26 //______________________________________________________________________________
27 //
28 // Visualization of an ITS module.
29
30 ClassImp(AliEveITSModule)
31
32 Bool_t AliEveITSModule::fgStaticInitDone = kFALSE;
33
34 TEveFrameBox*    AliEveITSModule::fgSPDFrameBox     = 0;
35 TEveFrameBox*    AliEveITSModule::fgSPDFrameBoxDead = 0;
36 TEveFrameBox*    AliEveITSModule::fgSDDFrameBox     = 0;
37 TEveFrameBox*    AliEveITSModule::fgSDDFrameBoxDead = 0;
38 TEveFrameBox*    AliEveITSModule::fgSSDFrameBox     = 0;
39 TEveFrameBox*    AliEveITSModule::fgSSDFrameBoxDead = 0;
40
41 TEveRGBAPalette* AliEveITSModule::fgSPDPalette  = 0;
42 TEveRGBAPalette* AliEveITSModule::fgSDDPalette  = 0;
43 TEveRGBAPalette* AliEveITSModule::fgSSDPalette  = 0;
44
45 /******************************************************************************/
46
47 AliEveITSModule::AliEveITSModule(const Text_t* n, const Text_t* t) :
48   TEveQuadSet(n, t),
49   fInfo(0),
50   fID(-1), fDetID(-1),
51   fLayer(-1), fLadder(-1), fDet(-1),
52   fDx(0), fDz(0), fDy(0)
53 {
54   // Constructor.
55 }
56
57 AliEveITSModule::AliEveITSModule(Int_t gid, AliEveITSDigitsInfo* info) :
58   TEveQuadSet(Form("ITS module %d", gid)),
59   fInfo  (0),
60   fID(-1), fDetID(-1),
61   fLayer(-1), fLadder(-1), fDet(-1),
62   fDx(0), fDz(0), fDy(0)
63 {
64   // Constructor with module id and data-source.
65
66   SetDigitsInfo(info);
67   SetID(gid);
68 }
69
70 AliEveITSModule::~AliEveITSModule()
71 {
72   // Destructor.
73
74   if (fInfo) fInfo->DecRefCount();
75 }
76
77 /******************************************************************************/
78
79 void AliEveITSModule::InitStatics(AliEveITSDigitsInfo* info)
80 {
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.
85
86   if (fgStaticInitDone) return;
87   fgStaticInitDone = kTRUE;
88
89   {
90     Float_t dx = info->fSegSPD->Dx()*0.00005;
91     Float_t dz = info->fSegSPD->Dz()*0.00005;
92
93     fgSPDFrameBox = new TEveFrameBox();
94     fgSPDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
95     fgSPDFrameBox->SetFrameColor(Color_t(31));
96     fgSPDFrameBox->SetFrameFill(kTRUE);
97     fgSPDFrameBox->IncRefCount();
98     fgSPDPalette  = new TEveRGBAPalette(info->fSPDMinVal,info->fSPDMaxVal);
99     fgSPDPalette->IncRefCount();
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();
106   }
107
108   {
109     Float_t dx = info->fSegSDD->Dx()*0.0001;
110     Float_t dz = info->fSegSDD->Dz()*0.00005;
111
112     fgSDDFrameBox = new TEveFrameBox();
113     fgSDDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
114     fgSDDFrameBox->SetFrameColor(Color_t(32));
115     fgSDDFrameBox->SetFrameFill(kTRUE);
116     fgSDDFrameBox->IncRefCount();
117     fgSDDPalette  = new TEveRGBAPalette(info->fSDDMinVal,info->fSDDMaxVal);
118     fgSDDPalette->SetLimits(0, info->fSDDHighLim); // Set proper ADC range.
119     fgSDDPalette->IncRefCount();
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();
126   }
127
128   {
129     Float_t dx = info->fSegSSD->Dx()*0.00005;
130     Float_t dz = info->fSegSSD->Dz()*0.00005;
131
132     fgSSDFrameBox = new TEveFrameBox();
133     fgSSDFrameBox->SetAAQuadXZ(-dx, 0, -dz, 2*dx, 2*dz);
134     fgSSDFrameBox->SetFrameColor(Color_t(33));
135     fgSSDFrameBox->SetFrameFill(kTRUE);
136     fgSSDFrameBox->IncRefCount();
137     fgSSDPalette  = new TEveRGBAPalette(info->fSSDMinVal,info->fSSDMaxVal);
138     fgSSDPalette->SetLimits(0, info->fSSDHighLim); // Set proper ADC range.
139     fgSSDPalette->IncRefCount();
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();
146   }
147
148 }
149
150 /******************************************************************************/
151
152 void AliEveITSModule::SetDigitsInfo(AliEveITSDigitsInfo* info)
153 {
154   // Set data and geometry source.
155
156   if (fInfo == info) return;
157   if (fInfo) fInfo->DecRefCount();
158   fInfo = info;
159   if (fInfo) fInfo->IncRefCount();
160 }
161
162 /******************************************************************************/
163
164 void AliEveITSModule::SetID(Int_t gid, Bool_t trans)
165 {
166   // Set detector id.
167
168   static const TEveException kEH("AliEveITSModule::SetID ");
169
170   if (fInfo == 0)
171     throw(kEH + "AliEveITSDigitsInfo not set.");
172
173   Int_t firstSPD = AliITSgeomTGeo::GetModuleIndex(1,1,1);
174   Int_t lastSSD  = AliITSgeomTGeo::GetNModules() - 1;
175   if (gid < firstSPD || gid > lastSSD)
176   {
177     throw(kEH + Form("%d is not valid. ID range from %d to %d", gid,
178                     firstSPD, lastSSD ));
179   }
180
181   fID = gid;
182
183   if (!fgStaticInitDone)
184   {
185     InitStatics(fInfo);
186   }
187
188   AliITSgeomTGeo::GetModuleId(fID, fLayer, fLadder, fDet);
189   TString strLadder = "Ladder";
190   TString strSensor = "Sensor";
191   TString symname;
192   Int_t   id, nsector, nstave, nladder, rest;
193
194   if (fID <= (AliITSgeomTGeo::GetModuleIndex(3,1,1) - 1))
195   {
196     // SPD
197
198     fDetID = 0;
199
200     SetFrame(fInfo->IsDead(fID, fDetID) ? fgSPDFrameBoxDead : fgSPDFrameBox);
201     SetPalette(fgSPDPalette);
202
203     symname += strLadder;
204     if (fID < 80)
205     {
206       nsector = fID/8;
207       rest    = fID - 8*nsector;
208       nstave  = 1;
209     }
210     else
211     {
212       id      = fID - 80;
213       nsector = id/8;
214       rest    = id - 8*nsector;
215       nstave  = 1;
216     }
217     if (rest < 4) nstave = 0;
218     rest    -= 4*nstave;
219     symname += rest;
220     SetName(symname);
221     fDx = fInfo->fSegSPD->Dx()*0.00005;
222     fDz = 3.50;
223     fDy = fInfo->fSegSPD->Dy()*0.00005;
224   }
225   else if (fID <= (AliITSgeomTGeo::GetModuleIndex(5,1,1) - 1))
226   {
227     // SDD
228
229     fDetID = 1;
230
231     SetFrame(fInfo->IsDead(fID, fDetID) ? fgSDDFrameBoxDead : fgSDDFrameBox);
232     SetPalette(fgSDDPalette);
233
234     symname += strSensor;
235     if (fID < 324)
236     {
237       id      = fID - 240;
238       nladder = id/6;
239       rest    = id - 6*nladder;
240     }
241     else
242     {
243       id      = fID - 324;
244       nladder = id/8;
245       rest    = id - 8*nladder;
246     }
247     symname += rest;
248     SetName(symname);
249     fDx = fInfo->fSegSDD->Dx()*0.0001;
250     fDz = fInfo->fSegSDD->Dz()*0.00005;
251     fDy = fInfo->fSegSDD->Dy()*0.00005;
252   }
253   else
254   {
255     // SSD
256
257     fDetID = 2;
258
259     SetFrame(fInfo->IsDead(fID, fDetID) ? fgSSDFrameBoxDead : fgSSDFrameBox);
260     SetPalette(fgSSDPalette);
261
262     symname += strSensor;
263     if (fID < 1248)
264     {
265       id      = fID - 500;
266       nladder = id/22;
267       rest    = id - nladder*22;
268     }
269     else
270     {
271       id      = fID - 1248;
272       nladder = id/25;
273       rest    = id - nladder*25;
274     }
275     symname += rest;
276     SetName(symname);
277     fInfo->fSegSSD->SetLayer(fLayer);
278     fDx = fInfo->fSegSSD->Dx()*0.00005;
279     fDz = fInfo->fSegSSD->Dz()*0.00005;
280     fDy = fInfo->fSegSSD->Dy()*0.00005;
281   }
282
283   LoadQuads();
284   RefitPlex();
285   ComputeBBox();
286   InitMainTrans();
287   if (trans)
288     SetTrans();
289
290 }
291
292 void AliEveITSModule::LoadQuads()
293 {
294   // Read module data from source and create low-level objects for
295   // visualization - called quads.
296
297   TClonesArray *digits  = fInfo->GetDigits(fID, fDetID);
298   Int_t         ndigits = digits ? digits->GetEntriesFast() : 0;
299
300   Float_t       x, z, dpx, dpz;
301   Int_t         i, j;
302
303   switch(fDetID)
304   {
305     case 0:
306     {
307       AliITSsegmentationSPD* seg =  fInfo->fSegSPD;
308
309       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
310
311       for (Int_t k=0; k<ndigits; ++k)
312       {
313         AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
314         j = d->GetCoord1();
315         i = d->GetCoord2();
316         x  = -0.5*seg->Dx() + i*seg->Dpx(0);
317         x *=  0.0001;
318         fInfo->GetSPDLocalZ(j, z);
319         dpx = seg->Dpx(i)*0.0001;
320         dpz = seg->Dpz(j)*0.0001;
321
322         AddQuad(x, z, dpx, dpz);
323         QuadValue(1); // In principle could have color based on number of neigbours
324         QuadId(d);
325       }
326       break;
327     }
328
329     case 1:
330     {
331       AliITSsegmentationSDD *seg =  fInfo->fSegSDD;
332
333       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
334
335       for (Int_t k=0; k<ndigits; ++k)
336       {
337         AliITSdigit* d = (AliITSdigit*) digits->UncheckedAt(k);
338
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);
348       }
349       break;
350     }
351
352     case 2:
353     {
354       AliITSsegmentationSSD* seg = fInfo->fSegSSD;
355
356       Reset(kQT_LineXZFixedY, kFALSE, 32);
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       {
365         AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
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);
379       }
380       break;
381     }
382
383   } // end switch
384 }
385
386 /******************************************************************************/
387
388 void AliEveITSModule::SetTrans()
389 {
390   // Set transformation matrix based on module id (use geometry to
391   // retrieve this information).
392
393   fMainTrans->SetFrom(*AliITSgeomTGeo::GetMatrix(fID));
394 }
395
396 /******************************************************************************/
397
398 void AliEveITSModule::DigitSelected(Int_t idx)
399 {
400   // Override secondary select (alt-click) from TEveQuadSet.
401
402   DigitBase_t *qb  = GetDigit(idx);
403   TObject     *obj = GetId(idx);
404   AliITSdigit *d   = dynamic_cast<AliITSdigit*>(obj);
405   printf("AliEveITSModule::QuadSelected "); Print();
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
414 /******************************************************************************/
415
416 void AliEveITSModule::Print(Option_t* ) const
417 {
418   // Print object summary information.
419
420   printf("AliEveITSModule: ID %d, layer %d, ladder %d, det %d\n",
421          fID, fLayer, fLadder, fDetID);
422 }