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