]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveITSModule.cxx
Corrected SDD raw-data visualization code (Francesco). To be ported to the release...
[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   if (!digits) return;
284
285   Int_t         ndigits = digits ? digits->GetEntriesFast() : 0;
286
287   Float_t       x, z, dpx, dpz;
288   Int_t         i, j;
289
290   switch(fDetID)
291   {
292
293     case 0: { // SPD
294       AliITSsegmentationSPD* seg =  fInfo->fSegSPD;
295
296       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
297
298       for (Int_t k=0; k<ndigits; ++k)
299       {
300         AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
301         j = d->GetCoord1();
302         i = d->GetCoord2();
303         x  = -0.5*seg->Dx() + i*seg->Dpx(0);
304         x *=  0.0001;
305         fInfo->GetSPDLocalZ(j, z);
306         dpx = seg->Dpx(i)*0.0001;
307         dpz = seg->Dpz(j)*0.0001;
308
309         AddQuad(x, z, dpx, dpz);
310         QuadValue(1); // In principle could have color based on number of neigbours
311         QuadId(d);
312       }
313       break;
314     }
315
316     case 1: { // SDD
317       AliITSsegmentationSDD *seg =  fInfo->fSegSDD;
318
319       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
320
321       for (Int_t k=0; k<ndigits; ++k)
322       {
323         AliITSdigit* d = (AliITSdigit*) digits->UncheckedAt(k);
324
325         // if (d->GetSignal() > fgSDDThreshold)
326         {
327           j = d->GetCoord1();
328           i = d->GetCoord2();
329           seg->DetToLocal(i, j, x, z);
330           dpx = seg->Dpx(i)*0.0001;
331           dpz = seg->Dpz(j)*0.0001;
332
333           AddQuad(x-2*dpx, z - dpz*0.5, 4*dpx, dpz);
334           QuadValue(d->GetSignal());
335           QuadId(d);
336         }
337       }
338       break;
339     }
340
341     case 2: { // SSD
342       AliITSsegmentationSSD* seg = fInfo->fSegSSD;
343
344       Reset(kQT_LineXZFixedY, kFALSE, 32);
345
346       Float_t ap, an; // positive/negative angles -> offsets
347       seg->Angles(ap, an);
348       ap =   TMath::Tan(ap) * fDz;
349       an = - TMath::Tan(an) * fDz;
350
351       for (Int_t k=0; k<ndigits; ++k)
352       {
353         AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
354         // if(d->GetSignal() > fgSSDThreshold)
355         {
356           j = d->GetCoord1();
357           i = d->GetCoord2();
358           seg->DetToLocal(i,j,x,z);
359
360           Float_t a = ( d->GetCoord1() == 1) ? ap : an;
361
362           AddLine(x-a, -fDz, 2*a, 2*fDz);
363           QuadValue(d->GetSignal());
364           QuadId(d);
365           // printf("%3d -> %3d -> %8x\n", d->GetSignal(), ci, fQuads.back().color);
366         }
367       }
368       break;
369     }
370
371   } // end switch
372
373   RefitPlex();
374 }
375
376 /******************************************************************************/
377
378 void AliEveITSModule::SetTrans()
379 {
380   // Set transformation matrix based on module id (use geometry to
381   // retrieve this information).
382
383   fMainTrans->SetFrom(*AliITSgeomTGeo::GetMatrix(fID));
384 }
385
386 /******************************************************************************/
387
388 void AliEveITSModule::DigitSelected(Int_t idx)
389 {
390   // Override secondary select (alt-click) from TEveQuadSet.
391
392   DigitBase_t *qb  = GetDigit(idx);
393   TObject     *obj = qb->fId.GetObject();
394   AliITSdigit *d   = dynamic_cast<AliITSdigit*>(obj);
395   printf("AliEveITSModule::QuadSelected "); Print();
396   printf("  idx=%d, value=%d, obj=0x%lx, digit=0x%lx\n",
397          idx, qb->fValue, (ULong_t)obj, (ULong_t)d);
398   if (d)
399     printf("  coord1=%3d coord2=%3d signal=%d\n",
400            d->GetCoord1(), d->GetCoord2(), d->GetSignal());
401
402 }
403
404 /******************************************************************************/
405
406 void AliEveITSModule::Print(Option_t* ) const
407 {
408   // Print object summary information.
409
410   printf("AliEveITSModule: ID %d, layer %d, ladder %d, det %d\n",
411          fID, fLayer, fLadder, fDetID);
412 }