]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveITSScaledModule.cxx
Get selected digit via method, not direct member access (changed in root trunk).
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSScaledModule.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 "AliEveITSScaledModule.h"
11
12 #include <AliITSsegmentationSPD.h>
13 #include <AliITSsegmentationSDD.h>
14 #include <AliITSsegmentationSSD.h>
15
16 #include <AliITSdigitSPD.h>
17 #include <AliITSdigitSDD.h>
18 #include <AliITSdigitSSD.h>
19
20 #include <TMath.h>
21 #include <TClonesArray.h>
22
23 //==============================================================================
24 //==============================================================================
25 // AliEveDigitScaleInfo
26 //==============================================================================
27
28 //______________________________________________________________________________
29 //
30 // Encapsulates current state of scaling and agglomeration.
31
32 ClassImp(AliEveDigitScaleInfo)
33
34 AliEveDigitScaleInfo::AliEveDigitScaleInfo():
35   fScale(1),
36   fStatType (kSTAverage),
37   fSyncPalette(kFALSE)
38 {
39 }
40
41 void AliEveDigitScaleInfo::ScaleChanged(Int_t s)
42 {
43   fScale = s;
44
45   AliEveITSScaledModule* sm;
46   std::list<TEveElement*>::iterator i = fBackRefs.begin();
47   while (i != fBackRefs.end())
48   {
49     sm = dynamic_cast<AliEveITSScaledModule*>(*i);
50     if(sm) sm->LoadQuads();
51     ++i;
52   }
53 }
54
55 void AliEveDigitScaleInfo::StatTypeChanged(Int_t t)
56 {
57   fStatType = t;
58   fSyncPalette = kTRUE;
59
60   AliEveITSScaledModule* sm;
61   std::list<TEveElement*>::iterator i = fBackRefs.begin();
62   while (i != fBackRefs.end())
63   {
64     sm = dynamic_cast<AliEveITSScaledModule*>(*i);
65     if (sm) sm->SetQuadValues();
66     ++i;
67   }
68 }
69
70 //______________________________________________________________________________
71 // ScaledDigit_t
72 //
73
74 AliEveITSScaledModule::ScaledDigit_t::ScaledDigit_t() :
75   TObject(),
76   fN(0),
77   fSum(0), fSqrSum(0),
78   fMinI(-1), fMinJ(-1), fMaxI(-1), fMaxJ(-1)
79 {
80 }
81
82 AliEveITSScaledModule::ScaledDigit_t::ScaledDigit_t(Int_t di, Int_t dj) :
83   TObject(),
84   fN(0),
85   fSum(0), fSqrSum(0),
86   fMinI(di), fMinJ(dj), fMaxI(di), fMaxJ(dj)
87 {
88 }
89
90 void AliEveITSScaledModule::ScaledDigit_t::Dump() const
91 {
92   printf("N %d, sum %f, sqr_sum %f", fN, fSum, fSqrSum);
93 }
94
95
96 //==============================================================================
97 //==============================================================================
98 // AliEveITSScaledModule
99 //==============================================================================
100
101 //______________________________________________________________________________
102 //
103 // Visualization of an ITS module with digits aggregated
104 // on a grid of pre-defined size.
105
106 ClassImp(AliEveITSScaledModule)
107
108 AliEveITSScaledModule::AliEveITSScaledModule(Int_t gid, AliEveITSDigitsInfo* info, AliEveDigitScaleInfo* si):
109   AliEveITSModule("AliEveITSScaledModule", "AliEveITSScaledModule"),
110   fNx(-1),
111   fNz(-1),
112   fNCx(-1),
113   fNCz(-1),
114   fScaleInfo(si),
115   fDigitsMap()
116 {
117   SetOwnIds(kTRUE);
118
119   SetDigitsInfo(info);
120   SetID(gid);
121   fScaleInfo->IncRefCount(this);
122 }
123
124 AliEveITSScaledModule::~AliEveITSScaledModule()
125 {
126   fScaleInfo->DecRefCount(this);
127 }
128
129 /******************************************************************************/
130
131 void AliEveITSScaledModule::LoadQuads()
132 {
133   // Here we still use 'z' for the name of axial coordinates.
134   // The transforamtion matrix aplied rotates y -> z.
135   // We need this as TEveQuadSet offers optimized treatment for
136   // quads in the x-y plane.
137
138   TClonesArray *digits = fInfo->GetDigits(fID, fDetID);
139   if (!digits) return;
140
141   Int_t ndigits = digits->GetEntriesFast();
142
143   Float_t       x, z, zo, dpx, dpz; // orig cells size, pos
144   Int_t         i, j;               // orig cells idx
145   Int_t         c1, c2;             // original coordinates
146
147   Int_t id;
148   std::map<Int_t, Int_t> dmap;
149   std::map<Int_t, Int_t>::iterator miter;
150
151   Int_t scale = fScaleInfo->GetScale() -1;
152   switch(fDetID)
153   {
154     case 0:
155     {
156       // SPD
157       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
158
159       fNCz = fInfo->fSPDScaleZ[scale];
160       fNCx = fInfo->fSPDScaleX[scale];
161       fNz  = Int_t(fInfo->fSegSPD->Npz()/fNCz);
162       fNx  = Int_t(fInfo->fSegSPD->Npx()/fNCx);
163       dpz = 2*fDz/fNz;
164       dpx = 2*fDx/fNx;
165       //printf("SPD orig cells (%d, %d) (%d, %d)\n", fInfo->fSegSPD->Npx(), fInfo->fSegSPD->Npz(), Nx, Nz);
166
167       AliITSdigitSPD *od ;
168       for (Int_t k=0; k<ndigits; ++k)
169       {
170         od = (AliITSdigitSPD*) digits->UncheckedAt(k);
171
172         fInfo->GetSPDLocalZ(od->GetCoord1(),zo);
173         c1 = od->GetCoord1(); c2 = od->GetCoord2();
174         i  = Int_t((zo+fDz)/dpz);
175         j  = Int_t((od->GetCoord2()*fNx)/fInfo->fSegSPD->Npx());
176         id = j*fNx + i;
177
178         ScaledDigit_t* sd = 0;
179         miter = dmap.find(id);
180         if(miter == dmap.end())
181         {
182           dmap[id] = fPlex.Size();
183           z = dpz*(i) - fDz;
184           x = dpx*(j) - fDx;
185           AddQuad(x, z, dpx, dpz);
186           sd = new ScaledDigit_t(c1, c2);
187           QuadId(sd);
188         }
189         else
190         {
191           sd = dynamic_cast<ScaledDigit_t*>(GetId(miter->second));
192           if(c1 < sd->fMinI)
193             sd->fMinI = c1;
194           else if( c1 > sd->fMaxI)
195             sd->fMaxI = c1;
196
197           if(c2 < sd->fMinJ)
198             sd->fMinJ = c2;
199           else if( c2 > sd->fMaxJ)
200             sd->fMaxJ = c2;
201         }
202
203         sd->fN++;
204         sd->fSum  += od->GetSignal();
205         sd->fSqrSum += od->GetSignal()*od->GetSignal();
206       }
207       break;
208     }
209     case 1:
210     {
211       // SDD
212       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
213
214       fNCz = fInfo->fSDDScaleZ[scale];
215       fNCx = fInfo->fSDDScaleX[scale];
216       fNz  = Int_t(fInfo->fSegSDD->Npz()/fNCz);
217       fNx  = Int_t(fInfo->fSegSDD->Npx()/fNCx);
218       dpz  = 2*fDz/fNz;
219       dpx  = 2*fDx/fNx;
220
221       AliITSdigitSDD *od = 0;
222       for (Int_t k = 0; k < ndigits; ++k)
223       {
224         od = (AliITSdigitSDD*)digits->UncheckedAt(k);
225         fInfo->fSegSDD->DetToLocal(od->GetCoord2(), od->GetCoord1(),x,z);
226         z += fDz;
227         x += fDx;
228         i  = Int_t(z/dpz);
229         j  = Int_t(x/dpx);
230         //printf("Mod %d coord %d,%d out of %d,%d :: ORIG coord %d,%d out of %d,%d \n",fID,
231         //       i,j,Nz,Nx,od->GetCoord1(),od->GetCoord2(),fInfo->fSegSDD->Npz(),fInfo->fSegSDD->Npx());
232
233         id = j*fNx + i;
234         c1 = od->GetCoord1(); c2 = od->GetCoord2();
235
236         ScaledDigit_t* sd = 0;
237         miter = dmap.find(id);
238         if(miter == dmap.end())
239         {
240           dmap[id] = fPlex.Size();
241           z = dpz*(i) - fDz;
242           x = dpx*(j) - fDx;
243           AddQuad(x, z, dpx, dpz);
244           sd = new ScaledDigit_t(od->GetCoord1(),od->GetCoord2());
245           QuadId(sd);
246         }
247         else
248         {
249           sd = dynamic_cast<ScaledDigit_t*>(GetId(miter->second));
250           if(c1 < sd->fMinI)
251             sd->fMinI = c1;
252           else if( c1 > sd->fMaxI)
253             sd->fMaxI = c1;
254
255           if(c2 < sd->fMinJ)
256             sd->fMinJ = c2;
257           else if( c2 > sd->fMaxJ)
258             sd->fMaxJ = c2;
259         }
260         sd->fN++;
261         sd->fSum  += od->GetSignal();
262         sd->fSqrSum += od->GetSignal()*od->GetSignal();
263       }
264       break;
265     }
266     case 2:
267     {
268       // SSD
269       Reset(kQT_LineXZFixedY, kFALSE, 32);
270
271       AliITSsegmentationSSD* seg = fInfo->fSegSSD;
272       Float_t ap, an; // positive/negative angles -> offsets
273       seg->Angles(ap, an);
274       ap =   TMath::Tan(ap) * fDz;
275       an = - TMath::Tan(an) * fDz;
276
277       fNCx  = fInfo->fSSDScale[scale];
278       fNz  = 1;
279       fNx  = Int_t(fInfo->fSegSSD->Npx()/fNCx);
280       dpz = 2*fDz/fNz;
281       dpx = 2*fDx/fNx;
282
283       AliITSdigitSSD *od = 0;
284       for (Int_t k=0; k<ndigits; k++) {
285         od=(AliITSdigitSSD*)digits->UncheckedAt(k);
286         if(od->GetCoord1() == 1)
287           i = 1; // p side
288         else
289           i= -1; // n side
290         j = Int_t(od->GetCoord2()/fNCx);
291         c1 = od->GetCoord1(); c2 = od->GetCoord2();
292         id = j*i;
293
294         ScaledDigit_t* sd = 0;
295         miter = dmap.find(id);
296         if(miter == dmap.end())
297         {
298           // printf("orig digit %d,%d scaled %d,%d \n",od->GetCoord1(),od->GetCoord2(),i,j);
299           dmap[id] = fPlex.Size();
300           z = dpz*(i) - fDz;
301           x = dpx*(j) - fDx;
302           Float_t a = ( od->GetCoord1() == 1) ? ap : an;
303           AddLine(x-a, -fDz, 2*a, 2*fDz);
304
305           sd = new ScaledDigit_t(c1, c2);
306           QuadId(sd);
307         }
308         else
309         {
310           sd = dynamic_cast<ScaledDigit_t*>(GetId(miter->second));
311           if(c1 < sd->fMinI)
312             sd->fMinI = c1;
313           else if( c1 > sd->fMaxI)
314             sd->fMaxI = c1;
315
316           if(c2 < sd->fMinJ)
317             sd->fMinJ = c2;
318           else if( c2 > sd->fMaxJ)
319             sd->fMaxJ = c2;
320         }
321         sd->fN++;
322         sd->fSum  += od->GetSignal();
323         sd->fSqrSum += od->GetSignal()*od->GetSignal();
324       } // for digits
325       break;
326     } // end case 2
327   } // end switch
328
329   SetQuadValues();
330   RefitPlex();
331 }
332
333 /******************************************************************************/
334
335 void AliEveITSScaledModule::SetQuadValues()
336 {
337   if(fScaleInfo->GetSyncPalette()) SyncPalette();
338
339   Int_t num = fPlex.Size();
340   for (Int_t i = 0 ; i < num; i++)
341   {
342     ScaledDigit_t* sd = dynamic_cast<ScaledDigit_t*>(GetId(i));
343     Int_t v = 0;
344     switch(fScaleInfo->GetStatType())
345     {
346       using namespace TMath;
347
348       case AliEveDigitScaleInfo::kSTOccup:
349         v = Nint((100.0*sd->fN) / (fNCx*fNCz));
350         break;
351       case AliEveDigitScaleInfo::kSTAverage:
352         v = Nint((Double_t) sd->fSum / sd->fN);
353         break;
354       case AliEveDigitScaleInfo::kSTRms:
355         v = Nint(Sqrt(sd->fSqrSum) / sd->fN);
356         break;
357     }
358     DigitBase_t* qb = GetDigit(i);
359     qb->fValue = v;
360   }
361 }
362
363 /******************************************************************************/
364
365 void AliEveITSScaledModule::SyncPalette()
366 {
367   // printf("AliEveITSScaledModule::SyncPalette()\n");
368   if(fScaleInfo->GetStatType() == AliEveDigitScaleInfo::kSTOccup)
369   {
370     // SPD
371     AliEveITSModule::fgSPDPalette->SetLimits(0, 100);
372     AliEveITSModule::fgSPDPalette->SetMinMax(0, 100);
373
374     // SDD
375     AliEveITSModule::fgSDDPalette->SetLimits(0, 100);
376     AliEveITSModule::fgSDDPalette->SetMinMax(0, 100);
377
378     // SSD
379     AliEveITSModule::fgSSDPalette->SetLimits(0, 100);
380     AliEveITSModule::fgSDDPalette->SetMinMax(0, 100);
381   }
382   else
383   {
384     AliEveITSDigitsInfo& di = *fInfo;
385     // SPD
386     AliEveITSModule::fgSPDPalette->SetLimits(0, di.fSPDHighLim);
387     AliEveITSModule::fgSPDPalette->SetMinMax(di.fSPDMinVal, di.fSPDMaxVal);
388
389     // SDD
390     AliEveITSModule::fgSDDPalette->SetLimits(0, di.fSDDHighLim);
391     AliEveITSModule::fgSDDPalette->SetMinMax(di.fSDDMinVal, di.fSDDMaxVal);
392
393     // SSD
394     AliEveITSModule::fgSSDPalette->SetLimits(0, di.fSSDHighLim);
395     AliEveITSModule::fgSSDPalette->SetMinMax(di.fSSDMinVal, di.fSSDMaxVal);
396   }
397
398   fScaleInfo->SetSyncPalette(kFALSE);
399 }
400
401 /******************************************************************************/
402
403 void AliEveITSScaledModule::GetScaleData(Int_t& cnx, Int_t& cnz, Int_t& total) const
404 {
405   cnx   = fNx;
406   cnz   = fNz;
407   total = cnx*cnz;
408 }
409
410 /******************************************************************************/
411
412 void  AliEveITSScaledModule::DigitSelected(Int_t idx)
413 {
414   // Override control-click from TEveQuadSet
415   printf("AliEveITSScaledModule::DigitSelected "); Print();
416
417   // DigitBase_t *qb  = GetDigit(idx);
418   TObject     *obj = GetId(idx);
419   ScaledDigit_t *sd = dynamic_cast<ScaledDigit_t*>(obj);
420   TClonesArray *digits = fInfo->GetDigits(fID, fDetID);
421   Int_t ndigits = digits->GetEntriesFast();
422
423   printf("%d digits in cell scaleX = %d,  scaleZ = %d \n", sd->fN, fNCx, fNCz);
424
425   Int_t il = 0;
426   for(Int_t k=0; k<ndigits; k++)
427   {
428     AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
429
430     if(d->GetCoord1()>=sd->fMinI && d->GetCoord1()<=sd->fMaxI &&
431        d->GetCoord2()>=sd->fMinJ && d->GetCoord2()<=sd->fMaxJ)
432     {
433       printf("%3d, %3d: %3d", d->GetCoord1(), d->GetCoord2(), d->GetSignal());
434       printf(" | ");
435       il++;
436       if(il>5) {
437         printf("\n");
438         il = 0;
439       }
440     }
441   }
442   if(il) printf("\n");
443 }