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