]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveITSModule.cxx
Merge changes from branches/dev/EVE. This branch was following development in ROOT...
[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     InitStatics(fInfo);
164
165     fgSPDFrameBox->IncRefCount(this);
166     fgSPDPalette->IncRefCount();
167
168     fgSDDFrameBox->IncRefCount(this);
169     fgSDDPalette->IncRefCount();
170
171     fgSSDFrameBox->IncRefCount(this);
172     fgSSDPalette->IncRefCount();
173   }
174
175   AliITSgeomTGeo::GetModuleId(fID, fLayer, fLadder, fDet);
176   TString strLadder = "Ladder";
177   TString strSensor = "Sensor";
178   TString symname;
179   Int_t   id, nsector, nstave, nladder, rest;
180
181   if (fID <= (AliITSgeomTGeo::GetModuleIndex(3,1,1) - 1))
182   {
183     // SPD
184
185     SetFrame(fgSPDFrameBox);
186     SetPalette(fgSPDPalette);
187
188     symname += strLadder;
189     if (fID < 80)
190     {
191       nsector = fID/8;
192       rest    = fID - 8*nsector;
193       nstave  = 1;
194     }
195     else
196     {
197       id      = fID - 80;
198       nsector = id/8;
199       rest    = id - 8*nsector;
200       nstave  = 1;
201     }
202     if (rest < 4) nstave = 0;
203     rest    -= 4*nstave;
204     symname += rest;
205     SetName(symname);
206     fDetID = 0;
207     fDx = fInfo->fSegSPD->Dx()*0.00005;
208     fDz = 3.50;
209     fDy = fInfo->fSegSPD->Dy()*0.00005;
210
211   }
212   else if (fID <= (AliITSgeomTGeo::GetModuleIndex(5,1,1) - 1))
213   {
214     // SDD
215
216     SetFrame(fgSDDFrameBox);
217     SetPalette(fgSDDPalette);
218
219     symname += strSensor;
220     if (fID < 324)
221     {
222       id      = fID - 240;
223       nladder = id/6;
224       rest    = id - 6*nladder;
225     }
226     else
227     {
228       id      = fID - 324;
229       nladder = id/8;
230       rest    = id - 8*nladder;
231     }
232     symname += rest;
233     SetName(symname);
234     fDetID = 1;
235     fDx = fInfo->fSegSDD->Dx()*0.0001;
236     fDz = fInfo->fSegSDD->Dz()*0.00005;
237     fDy = fInfo->fSegSDD->Dy()*0.00005;
238
239   }
240   else
241   {
242     // SSD
243
244     SetFrame(fgSSDFrameBox);
245     SetPalette(fgSSDPalette);
246
247     symname += strSensor;
248     if (fID < 1248)
249     {
250       id      = fID - 500;
251       nladder = id/22;
252       rest    = id - nladder*22;
253     }
254     else
255     {
256       id      = fID - 1248;
257       nladder = id/25;
258       rest    = id - nladder*25;
259     }
260     symname += rest;
261     SetName(symname);
262     fDetID = 2;
263     fInfo->fSegSSD->SetLayer(fLayer);
264     fDx = fInfo->fSegSSD->Dx()*0.00005;
265     fDz = fInfo->fSegSSD->Dz()*0.00005;
266     fDy = fInfo->fSegSSD->Dy()*0.00005;
267
268   }
269
270   LoadQuads();
271   ComputeBBox();
272   InitMainTrans();
273   if (trans)
274     SetTrans();
275 }
276
277 void AliEveITSModule::LoadQuads()
278 {
279   // Read module data from source and create low-level objects for
280   // visualization - called quads.
281
282   TClonesArray *digits  = fInfo->GetDigits(fID, fDetID);
283   Int_t         ndigits = digits ? digits->GetEntriesFast() : 0;
284
285   Float_t       x, z, dpx, dpz;
286   Int_t         i, j;
287
288   switch(fDetID)
289   {
290
291     case 0: { // SPD
292       AliITSsegmentationSPD* seg =  fInfo->fSegSPD;
293
294       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
295
296       for (Int_t k=0; k<ndigits; ++k)
297       {
298         AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
299         j = d->GetCoord1();
300         i = d->GetCoord2();
301         x  = -0.5*seg->Dx() + i*seg->Dpx(0);
302         x *=  0.0001;
303         fInfo->GetSPDLocalZ(j, z);
304         dpx = seg->Dpx(i)*0.0001;
305         dpz = seg->Dpz(j)*0.0001;
306
307         AddQuad(x, z, dpx, dpz);
308         QuadValue(1); // In principle could have color based on number of neigbours
309         QuadId(d);
310       }
311       break;
312     }
313
314     case 1: { // SDD
315       AliITSsegmentationSDD *seg =  fInfo->fSegSDD;
316
317       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
318
319       for (Int_t k=0; k<ndigits; ++k)
320       {
321         AliITSdigit* d = (AliITSdigit*) digits->UncheckedAt(k);
322
323         // if (d->GetSignal() > fgSDDThreshold)
324         {
325           j = d->GetCoord1();
326           i = d->GetCoord2();
327           seg->DetToLocal(i, j, x, z);
328           dpx = seg->Dpx(i)*0.0001;
329           dpz = seg->Dpz(j)*0.0001;
330
331           AddQuad(x-2*dpx, z - dpz*0.5, 4*dpx, dpz);
332           QuadValue(d->GetSignal());
333           QuadId(d);
334         }
335       }
336       break;
337     }
338
339     case 2: { // SSD
340       AliITSsegmentationSSD* seg = fInfo->fSegSSD;
341
342       Reset(kQT_LineXZFixedY, kFALSE, 32);
343
344       Float_t ap, an; // positive/negative angles -> offsets
345       seg->Angles(ap, an);
346       ap =   TMath::Tan(ap) * fDz;
347       an = - TMath::Tan(an) * fDz;
348
349       for (Int_t k=0; k<ndigits; ++k)
350       {
351         AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
352         // if(d->GetSignal() > fgSSDThreshold)
353         {
354           j = d->GetCoord1();
355           i = d->GetCoord2();
356           seg->DetToLocal(i,j,x,z);
357
358           Float_t a = ( d->GetCoord1() == 1) ? ap : an;
359
360           AddLine(x-a, -fDz, 2*a, 2*fDz);
361           QuadValue(d->GetSignal());
362           QuadId(d);
363           // printf("%3d -> %3d -> %8x\n", d->GetSignal(), ci, fQuads.back().color);
364         }
365       }
366       break;
367     }
368
369   } // end switch
370
371   RefitPlex();
372 }
373
374 /******************************************************************************/
375
376 void AliEveITSModule::SetTrans()
377 {
378   // Set transformation matrix based on module id (use geometry to
379   // retrieve this information).
380
381   fMainTrans->SetFrom(*AliITSgeomTGeo::GetMatrix(fID));
382 }
383
384 /******************************************************************************/
385
386 void AliEveITSModule::DigitSelected(Int_t idx)
387 {
388   // Override secondary select (alt-click) from TEveQuadSet.
389
390   DigitBase_t *qb  = GetDigit(idx);
391   TObject     *obj = qb->fId.GetObject();
392   AliITSdigit *d   = dynamic_cast<AliITSdigit*>(obj);
393   printf("AliEveITSModule::QuadSelected "); Print();
394   printf("  idx=%d, value=%d, obj=0x%lx, digit=0x%lx\n",
395          idx, qb->fValue, (ULong_t)obj, (ULong_t)d);
396   if (d)
397     printf("  coord1=%3d coord2=%3d signal=%d\n",
398            d->GetCoord1(), d->GetCoord2(), d->GetSignal());
399
400 }
401
402 /******************************************************************************/
403
404 void AliEveITSModule::Print(Option_t* ) const
405 {
406   // Print object summary information.
407
408   printf("AliEveITSModule: ID %d, layer %d, ladder %d, det %d\n",
409          fID, fLayer, fLadder, fDetID);
410 }