]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveITSScaledModule.cxx
Update of the class ESDMuonFilter. New marcros for creating AOD with muon information...
[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   fDigitsMap(),
111   fNx(-1),
112   fNz(-1),
113   fNCx(-1),
114   fNCz(-1),
115   fScaleInfo(si)
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;
139   Float_t       x, z, zo, dpx, dpz; // orig cells size, pos
140   Int_t         i, j, ndigits;   // orig cells idx
141   Int_t         c1, c2;          // original coordinates
142
143   Int_t id;
144   std::map<Int_t, Int_t> dmap;
145   std::map<Int_t, Int_t>::iterator miter;
146   digits  = fInfo->GetDigits(fID, fDetID);
147   ndigits = digits->GetEntriesFast();
148
149   ScaledDigit_t* sd;
150   Int_t scale = fScaleInfo->GetScale() -1;
151   switch(fDetID)
152   {
153     case 0:
154     {
155       // SPD
156       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
157
158       fNCz = fInfo->fSPDScaleZ[scale];
159       fNCx = fInfo->fSPDScaleX[scale];
160       fNz  = Int_t(fInfo->fSegSPD->Npz()/fNCz);
161       fNx  = Int_t(fInfo->fSegSPD->Npx()/fNCx);
162       dpz = 2*fDz/fNz;
163       dpx = 2*fDx/fNx;
164       //printf("SPD orig cells (%d, %d) (%d, %d)\n", fInfo->fSegSPD->Npx(), fInfo->fSegSPD->Npz(), Nx, Nz);
165
166       AliITSdigitSPD *od ;
167       for (Int_t k=0; k<ndigits; ++k)
168       {
169         od = (AliITSdigitSPD*) digits->UncheckedAt(k);
170
171         fInfo->GetSPDLocalZ(od->GetCoord1(),zo);
172         c1 = od->GetCoord1(); c2 = od->GetCoord2();
173         i = Int_t((zo+fDz)/dpz);
174         j = Int_t((od->GetCoord2()*fNx)/fInfo->fSegSPD->Npx());
175         id = j*fNx + i;
176
177         miter = dmap.find(id);
178         if(miter == dmap.end())
179         {
180           dmap[id] = fPlex.Size();
181           z = dpz*(i) - fDz;
182           x = dpx*(j) - fDx;
183           AddQuad(x, z, dpx, dpz);
184           sd = new ScaledDigit_t(c1, c2);
185           QuadId(sd);
186         }
187         else
188         {
189           sd = dynamic_cast<ScaledDigit_t*>(GetId(miter->second));
190           if(c1 < sd->fMinI)
191             sd->fMinI = c1;
192           else if( c1 > sd->fMaxI)
193             sd->fMaxI = c1;
194
195           if(c2 < sd->fMinJ)
196             sd->fMinJ = c2;
197           else if( c2 > sd->fMaxJ)
198             sd->fMaxJ = c2;
199         }
200
201         sd->fN++;
202         sd->fSum  += od->GetSignal();
203         sd->fSqrSum += od->GetSignal()*od->GetSignal();
204       }
205       break;
206     }
207     case 1:
208     {
209       // SDD
210       Reset(kQT_RectangleXZFixedY, kFALSE, 32);
211
212       fNCz = fInfo->fSDDScaleZ[scale];
213       fNCx = fInfo->fSDDScaleX[scale];
214       fNz  = Int_t(fInfo->fSegSDD->Npz()/fNCz);
215       fNx  = Int_t(fInfo->fSegSDD->Npx()/fNCx);
216       dpz = 2*fDz/fNz;
217       dpx = 2*fDx/fNx;
218
219       AliITSdigitSDD *od=0;
220       for (Int_t k=0; k<ndigits; k++) {
221         od=(AliITSdigitSDD*)digits->UncheckedAt(k);
222         fInfo->fSegSDD->DetToLocal(od->GetCoord2(), od->GetCoord1(),x,z);
223         z+= fDz;
224         x+= fDx;
225         i = Int_t(z/dpz);
226         j = Int_t(x/dpx);
227         //printf("Mod %d coord %d,%d out of %d,%d :: ORIG coord %d,%d out of %d,%d \n",fID,
228         //       i,j,Nz,Nx,od->GetCoord1(),od->GetCoord2(),fInfo->fSegSDD->Npz(),fInfo->fSegSDD->Npx());
229
230         id = j*fNx + i;
231         c1 = od->GetCoord1(); c2 = od->GetCoord2();
232
233         miter = dmap.find(id);
234         if(miter == dmap.end())
235         {
236           dmap[id] = fPlex.Size();
237           z = dpz*(i) - fDz;
238           x = dpx*(j) - fDx;
239           AddQuad(x, z, dpx, dpz);
240           sd = new ScaledDigit_t(od->GetCoord1(),od->GetCoord2());
241           QuadId(sd);
242         }
243         else
244         {
245           sd = dynamic_cast<ScaledDigit_t*>(GetId(miter->second));
246           if(c1 < sd->fMinI)
247             sd->fMinI = c1;
248           else if( c1 > sd->fMaxI)
249             sd->fMaxI = c1;
250
251           if(c2 < sd->fMinJ)
252             sd->fMinJ = c2;
253           else if( c2 > sd->fMaxJ)
254             sd->fMaxJ = c2;
255         }
256         sd->fN++;
257         sd->fSum  += od->GetSignal();
258         sd->fSqrSum += od->GetSignal()*od->GetSignal();
259       }
260       break;
261     }
262     case 2:
263     {
264       // SSD
265       Reset(kQT_LineXZFixedY, kFALSE, 32);
266
267       AliITSsegmentationSSD* seg = fInfo->fSegSSD;
268       Float_t ap, an; // positive/negative angles -> offsets
269       seg->Angles(ap, an);
270       ap =   TMath::Tan(ap) * fDz;
271       an = - TMath::Tan(an) * fDz;
272
273       fNCx  = fInfo->fSSDScale[scale];
274       fNz  = 1;
275       fNx  = Int_t(fInfo->fSegSSD->Npx()/fNCx);
276       dpz = 2*fDz/fNz;
277       dpx = 2*fDx/fNx;
278
279       AliITSdigitSSD *od=0;
280       for (Int_t k=0; k<ndigits; k++) {
281         od=(AliITSdigitSSD*)digits->UncheckedAt(k);
282         if(od->GetCoord1() == 1)
283           i = 1; // p side
284         else
285           i= -1; // n side
286         j = Int_t(od->GetCoord2()/fNCx);
287         c1 = od->GetCoord1(); c2 = od->GetCoord2();
288         id = j*i;
289
290         miter = dmap.find(id);
291         ScaledDigit_t* sd;
292         if(miter == dmap.end())
293         {
294           // printf("orig digit %d,%d scaled %d,%d \n",od->GetCoord1(),od->GetCoord2(),i,j);
295           dmap[id] = fPlex.Size();
296           z = dpz*(i) - fDz;
297           x = dpx*(j) - fDx;
298           Float_t a = ( od->GetCoord1() == 1) ? ap : an;
299           AddLine(x-a, -fDz, 2*a, 2*fDz);
300
301           sd = new ScaledDigit_t(c1, c2);
302           QuadId(sd);
303         }
304         else
305         {
306           sd = dynamic_cast<ScaledDigit_t*>(GetId(miter->second));
307           if(c1 < sd->fMinI)
308             sd->fMinI = c1;
309           else if( c1 > sd->fMaxI)
310             sd->fMaxI = c1;
311
312           if(c2 < sd->fMinJ)
313             sd->fMinJ = c2;
314           else if( c2 > sd->fMaxJ)
315             sd->fMaxJ = c2;
316         }
317         sd->fN++;
318         sd->fSum  += od->GetSignal();
319         sd->fSqrSum += od->GetSignal()*od->GetSignal();
320       } // for digits
321       break;
322     } // end case 2
323   } // end switch
324
325   SetQuadValues();
326   RefitPlex();
327 }
328
329 /******************************************************************************/
330
331 void AliEveITSScaledModule::SetQuadValues()
332 {
333   if(fScaleInfo->GetSyncPalette()) SyncPalette();
334
335   Int_t num = fPlex.Size();
336   for (Int_t i = 0 ; i < num; i++)
337   {
338     ScaledDigit_t* sd = dynamic_cast<ScaledDigit_t*>(GetId(i));
339     Int_t v = 0;
340     switch(fScaleInfo->GetStatType())
341     {
342       using namespace TMath;
343
344       case AliEveDigitScaleInfo::kSTOccup:
345         v = Nint((100.0*sd->fN) / (fNCx*fNCz));
346         break;
347       case AliEveDigitScaleInfo::kSTAverage:
348         v = Nint((Double_t) sd->fSum / sd->fN);
349         break;
350       case AliEveDigitScaleInfo::kSTRms:
351         v = Nint(Sqrt(sd->fSqrSum) / sd->fN);
352         break;
353     }
354     DigitBase_t* qb = GetDigit(i);
355     qb->fValue = v;
356   }
357 }
358
359 /******************************************************************************/
360
361 void AliEveITSScaledModule::SyncPalette()
362 {
363   // printf("AliEveITSScaledModule::SyncPalette()\n");
364   if(fScaleInfo->GetStatType() == AliEveDigitScaleInfo::kSTOccup)
365   {
366     // SPD
367     AliEveITSModule::fgSPDPalette->SetLimits(0, 100);
368     AliEveITSModule::fgSPDPalette->SetMinMax(0, 100);
369
370     // SDD
371     AliEveITSModule::fgSDDPalette->SetLimits(0, 100);
372     AliEveITSModule::fgSDDPalette->SetMinMax(0, 100);
373
374     // SSD
375     AliEveITSModule::fgSSDPalette->SetLimits(0, 100);
376     AliEveITSModule::fgSDDPalette->SetMinMax(0, 100);
377   }
378   else
379   {
380     AliEveITSDigitsInfo& di = *fInfo;
381     // SPD
382     AliEveITSModule::fgSPDPalette->SetLimits(0, di.fSPDHighLim);
383     AliEveITSModule::fgSPDPalette->SetMinMax(di.fSPDMinVal, di.fSPDMaxVal);
384
385     // SDD
386     AliEveITSModule::fgSDDPalette->SetLimits(0, di.fSDDHighLim);
387     AliEveITSModule::fgSDDPalette->SetMinMax(di.fSDDMinVal, di.fSDDMaxVal);
388
389     // SSD
390     AliEveITSModule::fgSSDPalette->SetLimits(0, di.fSSDHighLim);
391     AliEveITSModule::fgSSDPalette->SetMinMax(di.fSSDMinVal, di.fSSDMaxVal);
392   }
393
394   fScaleInfo->SetSyncPalette(kFALSE);
395 }
396
397 /******************************************************************************/
398
399 void AliEveITSScaledModule::GetScaleData(Int_t& cnx, Int_t& cnz, Int_t& total) const
400 {
401   cnx   = fNx;
402   cnz   = fNz;
403   total = cnx*cnz;
404 }
405
406 /******************************************************************************/
407
408 void  AliEveITSScaledModule::DigitSelected(Int_t idx)
409 {
410   // Override control-click from TEveQuadSet
411   printf("AliEveITSScaledModule::DigitSelected "); Print();
412
413   DigitBase_t* qb  = GetDigit(idx);
414   TObject* obj  = qb->fId.GetObject();
415   ScaledDigit_t* sd = dynamic_cast<ScaledDigit_t*>(obj);
416   TClonesArray *digits = fInfo->GetDigits(fID, fDetID);
417   Int_t ndigits = digits->GetEntriesFast();
418
419   printf("%d digits in cell scaleX = %d,  scaleZ = %d \n", sd->fN, fNCx, fNCz);
420
421   Int_t il = 0;
422   for(Int_t k=0; k<ndigits; k++)
423   {
424     AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
425
426     if(d->GetCoord1()>=sd->fMinI && d->GetCoord1()<=sd->fMaxI &&
427        d->GetCoord2()>=sd->fMinJ && d->GetCoord2()<=sd->fMaxJ)
428     {
429       printf("%3d, %3d: %3d", d->GetCoord1(), d->GetCoord2(), d->GetSignal());
430       printf(" | ");
431       il++;
432       if(il>5) {
433         printf("\n");
434         il = 0;
435       }
436     }
437   }
438   if(il) printf("\n");
439 }