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