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