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