Fix for #76933: Fix access operator
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSScaledModule.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3b868b75 3
d810d0de 4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
9
10#include "AliEveITSScaledModule.h"
3b868b75 11
0879c50b 12#include <AliITSsegmentationSPD.h>
13#include <AliITSsegmentationSDD.h>
14#include <AliITSsegmentationSSD.h>
15
3b868b75 16#include <AliITSdigitSPD.h>
17#include <AliITSdigitSDD.h>
18#include <AliITSdigitSSD.h>
d810d0de 19
0879c50b 20#include <TMath.h>
a15e6d7d 21#include <TClonesArray.h>
3b868b75 22
a15e6d7d 23//==============================================================================
24//==============================================================================
d810d0de 25// AliEveDigitScaleInfo
a15e6d7d 26//==============================================================================
27
28//______________________________________________________________________________
3b868b75 29//
a15e6d7d 30// Encapsulates current state of scaling and agglomeration.
698e2c9b 31
d810d0de 32ClassImp(AliEveDigitScaleInfo)
3b868b75 33
d810d0de 34AliEveDigitScaleInfo::AliEveDigitScaleInfo():
3b868b75 35 fScale(1),
a15e6d7d 36 fStatType (kSTAverage),
32e219c2 37 fSyncPalette(kFALSE)
3b868b75 38{
39}
40
d810d0de 41void AliEveDigitScaleInfo::ScaleChanged(Int_t s)
3b868b75 42{
32e219c2 43 fScale = s;
51346b82 44
d810d0de 45 AliEveITSScaledModule* sm;
22828c05 46 RefMap_i i = fBackRefs.begin();
972e1e68 47 // #endif
32e219c2 48 while (i != fBackRefs.end())
49 {
972e1e68 50 sm = dynamic_cast<AliEveITSScaledModule*>(i->first);
51 // #endif
32e219c2 52 if(sm) sm->LoadQuads();
53 ++i;
54 }
3b868b75 55}
56
d810d0de 57void AliEveDigitScaleInfo::StatTypeChanged(Int_t t)
3b868b75 58{
32e219c2 59 fStatType = t;
60 fSyncPalette = kTRUE;
51346b82 61
d810d0de 62 AliEveITSScaledModule* sm;
22828c05 63 RefMap_i i = fBackRefs.begin();
972e1e68 64 // #endif
32e219c2 65 while (i != fBackRefs.end())
66 {
972e1e68 67 sm = dynamic_cast<AliEveITSScaledModule*>(i->first);
68 // #endif
a15e6d7d 69 if (sm) sm->SetQuadValues();
32e219c2 70 ++i;
71 }
3b868b75 72}
73
57ffa5fb 74//______________________________________________________________________________
a15e6d7d 75// ScaledDigit_t
3b868b75 76//
c76ea574 77
a15e6d7d 78AliEveITSScaledModule::ScaledDigit_t::ScaledDigit_t() :
3b868b75 79 TObject(),
a15e6d7d 80 fN(0),
81 fSum(0), fSqrSum(0),
82 fMinI(-1), fMinJ(-1), fMaxI(-1), fMaxJ(-1)
3b868b75 83{
84}
85
a15e6d7d 86AliEveITSScaledModule::ScaledDigit_t::ScaledDigit_t(Int_t di, Int_t dj) :
3b868b75 87 TObject(),
a15e6d7d 88 fN(0),
89 fSum(0), fSqrSum(0),
90 fMinI(di), fMinJ(dj), fMaxI(di), fMaxJ(dj)
3b868b75 91{
92}
93
a15e6d7d 94void AliEveITSScaledModule::ScaledDigit_t::Dump() const
3b868b75 95{
a15e6d7d 96 printf("N %d, sum %f, sqr_sum %f", fN, fSum, fSqrSum);
3b868b75 97}
98
698e2c9b 99
a15e6d7d 100//==============================================================================
101//==============================================================================
d810d0de 102// AliEveITSScaledModule
a15e6d7d 103//==============================================================================
698e2c9b 104
105//______________________________________________________________________________
3b868b75 106//
698e2c9b 107// Visualization of an ITS module with digits aggregated
108// on a grid of pre-defined size.
3b868b75 109
d810d0de 110ClassImp(AliEveITSScaledModule)
3b868b75 111
d810d0de 112AliEveITSScaledModule::AliEveITSScaledModule(Int_t gid, AliEveITSDigitsInfo* info, AliEveDigitScaleInfo* si):
113 AliEveITSModule("AliEveITSScaledModule", "AliEveITSScaledModule"),
3b868b75 114 fNx(-1),
115 fNz(-1),
116 fNCx(-1),
03dfc4a7 117 fNCz(-1),
9af86b69 118 fScaleInfo(si),
119 fDigitsMap()
3b868b75 120{
3b868b75 121 SetOwnIds(kTRUE);
122
123 SetDigitsInfo(info);
51346b82 124 SetID(gid);
32e219c2 125 fScaleInfo->IncRefCount(this);
3b868b75 126}
127
d810d0de 128AliEveITSScaledModule::~AliEveITSScaledModule()
3b868b75 129{
32e219c2 130 fScaleInfo->DecRefCount(this);
3b868b75 131}
132
57ffa5fb 133/******************************************************************************/
3b868b75 134
d810d0de 135void AliEveITSScaledModule::LoadQuads()
3b868b75 136{
137 // Here we still use 'z' for the name of axial coordinates.
138 // The transforamtion matrix aplied rotates y -> z.
84aff7a4 139 // We need this as TEveQuadSet offers optimized treatment for
3b868b75 140 // quads in the x-y plane.
141
a4135a45 142 TClonesArray *digits = fInfo->GetDigits(fID, fDetID);
143 if (!digits) return;
144
145 Int_t ndigits = digits->GetEntriesFast();
146
3b868b75 147 Float_t x, z, zo, dpx, dpz; // orig cells size, pos
a4135a45 148 Int_t i, j; // orig cells idx
149 Int_t c1, c2; // original coordinates
3b868b75 150
151 Int_t id;
fd31e9de 152 std::map<Int_t, Int_t> dmap;
153 std::map<Int_t, Int_t>::iterator miter;
3b868b75 154
03dfc4a7 155 Int_t scale = fScaleInfo->GetScale() -1;
3b868b75 156 switch(fDetID)
157 {
51346b82 158 case 0:
159 {
3b868b75 160 // SPD
84aff7a4 161 Reset(kQT_RectangleXZFixedY, kFALSE, 32);
3b868b75 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);
51346b82 167 dpz = 2*fDz/fNz;
3b868b75 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();
9af86b69 178 i = Int_t((zo+fDz)/dpz);
179 j = Int_t((od->GetCoord2()*fNx)/fInfo->fSegSPD->Npx());
3b868b75 180 id = j*fNx + i;
51346b82 181
9af86b69 182 ScaledDigit_t* sd = 0;
3b868b75 183 miter = dmap.find(id);
184 if(miter == dmap.end())
51346b82 185 {
3b868b75 186 dmap[id] = fPlex.Size();
187 z = dpz*(i) - fDz;
188 x = dpx*(j) - fDx;
189 AddQuad(x, z, dpx, dpz);
a15e6d7d 190 sd = new ScaledDigit_t(c1, c2);
3b868b75 191 QuadId(sd);
192 }
51346b82 193 else
3b868b75 194 {
01ff6975 195 sd = static_cast<ScaledDigit_t*>(GetId(miter->second));
a15e6d7d 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;
3b868b75 205 }
51346b82 206
a15e6d7d 207 sd->fN++;
208 sd->fSum += od->GetSignal();
209 sd->fSqrSum += od->GetSignal()*od->GetSignal();
3b868b75 210 }
211 break;
212 }
51346b82 213 case 1:
214 {
3b868b75 215 // SDD
84aff7a4 216 Reset(kQT_RectangleXZFixedY, kFALSE, 32);
3b868b75 217
218 fNCz = fInfo->fSDDScaleZ[scale];
51346b82 219 fNCx = fInfo->fSDDScaleX[scale];
3b868b75 220 fNz = Int_t(fInfo->fSegSDD->Npz()/fNCz);
221 fNx = Int_t(fInfo->fSegSDD->Npx()/fNCx);
9af86b69 222 dpz = 2*fDz/fNz;
223 dpx = 2*fDx/fNx;
3b868b75 224
9af86b69 225 AliITSdigitSDD *od = 0;
226 for (Int_t k = 0; k < ndigits; ++k)
227 {
228 od = (AliITSdigitSDD*)digits->UncheckedAt(k);
3b868b75 229 fInfo->fSegSDD->DetToLocal(od->GetCoord2(), od->GetCoord1(),x,z);
9af86b69 230 z += fDz;
231 x += fDx;
232 i = Int_t(z/dpz);
233 j = Int_t(x/dpx);
3b868b75 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();
51346b82 239
9af86b69 240 ScaledDigit_t* sd = 0;
3b868b75 241 miter = dmap.find(id);
242 if(miter == dmap.end())
51346b82 243 {
3b868b75 244 dmap[id] = fPlex.Size();
245 z = dpz*(i) - fDz;
246 x = dpx*(j) - fDx;
247 AddQuad(x, z, dpx, dpz);
a15e6d7d 248 sd = new ScaledDigit_t(od->GetCoord1(),od->GetCoord2());
3b868b75 249 QuadId(sd);
250 }
51346b82 251 else
3b868b75 252 {
377ec156 253 sd = static_cast<ScaledDigit_t*>(GetId(miter->second));
a15e6d7d 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;
3b868b75 263 }
a15e6d7d 264 sd->fN++;
265 sd->fSum += od->GetSignal();
266 sd->fSqrSum += od->GetSignal()*od->GetSignal();
3b868b75 267 }
268 break;
51346b82 269 }
270 case 2:
271 {
272 // SSD
84aff7a4 273 Reset(kQT_LineXZFixedY, kFALSE, 32);
3b868b75 274
51346b82 275 AliITSsegmentationSSD* seg = fInfo->fSegSSD;
3b868b75 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
51346b82 281 fNCx = fInfo->fSSDScale[scale];
3b868b75 282 fNz = 1;
283 fNx = Int_t(fInfo->fSegSSD->Npx()/fNCx);
284 dpz = 2*fDz/fNz;
285 dpx = 2*fDx/fNx;
286
9af86b69 287 AliITSdigitSSD *od = 0;
3b868b75 288 for (Int_t k=0; k<ndigits; k++) {
289 od=(AliITSdigitSSD*)digits->UncheckedAt(k);
51346b82 290 if(od->GetCoord1() == 1)
3b868b75 291 i = 1; // p side
51346b82 292 else
3b868b75 293 i= -1; // n side
294 j = Int_t(od->GetCoord2()/fNCx);
295 c1 = od->GetCoord1(); c2 = od->GetCoord2();
51346b82 296 id = j*i;
3b868b75 297
9af86b69 298 ScaledDigit_t* sd = 0;
3b868b75 299 miter = dmap.find(id);
3b868b75 300 if(miter == dmap.end())
51346b82 301 {
3b868b75 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
a15e6d7d 309 sd = new ScaledDigit_t(c1, c2);
3b868b75 310 QuadId(sd);
311 }
51346b82 312 else
3b868b75 313 {
04a6d27f 314 sd = static_cast<ScaledDigit_t*>(GetId(miter->second));
a15e6d7d 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;
3b868b75 324 }
a15e6d7d 325 sd->fN++;
326 sd->fSum += od->GetSignal();
327 sd->fSqrSum += od->GetSignal()*od->GetSignal();
3b868b75 328 } // for digits
329 break;
330 } // end case 2
331 } // end switch
332
333 SetQuadValues();
334 RefitPlex();
335}
336
57ffa5fb 337/******************************************************************************/
3b868b75 338
d810d0de 339void AliEveITSScaledModule::SetQuadValues()
3b868b75 340{
32e219c2 341 if(fScaleInfo->GetSyncPalette()) SyncPalette();
342
a15e6d7d 343 Int_t num = fPlex.Size();
344 for (Int_t i = 0 ; i < num; i++)
3b868b75 345 {
01ff6975 346 ScaledDigit_t* sd = static_cast<ScaledDigit_t*>(GetId(i));
3b868b75 347 Int_t v = 0;
32e219c2 348 switch(fScaleInfo->GetStatType())
349 {
350 using namespace TMath;
351
a15e6d7d 352 case AliEveDigitScaleInfo::kSTOccup:
353 v = Nint((100.0*sd->fN) / (fNCx*fNCz));
32e219c2 354 break;
a15e6d7d 355 case AliEveDigitScaleInfo::kSTAverage:
356 v = Nint((Double_t) sd->fSum / sd->fN);
32e219c2 357 break;
a15e6d7d 358 case AliEveDigitScaleInfo::kSTRms:
359 v = Nint(Sqrt(sd->fSqrSum) / sd->fN);
32e219c2 360 break;
3b868b75 361 }
84aff7a4 362 DigitBase_t* qb = GetDigit(i);
3b868b75 363 qb->fValue = v;
364 }
365}
366
57ffa5fb 367/******************************************************************************/
3b868b75 368
d810d0de 369void AliEveITSScaledModule::SyncPalette()
51346b82 370{
d810d0de 371 // printf("AliEveITSScaledModule::SyncPalette()\n");
a15e6d7d 372 if(fScaleInfo->GetStatType() == AliEveDigitScaleInfo::kSTOccup)
32e219c2 373 {
374 // SPD
d810d0de 375 AliEveITSModule::fgSPDPalette->SetLimits(0, 100);
376 AliEveITSModule::fgSPDPalette->SetMinMax(0, 100);
51346b82 377
32e219c2 378 // SDD
d810d0de 379 AliEveITSModule::fgSDDPalette->SetLimits(0, 100);
380 AliEveITSModule::fgSDDPalette->SetMinMax(0, 100);
32e219c2 381
382 // SSD
d810d0de 383 AliEveITSModule::fgSSDPalette->SetLimits(0, 100);
384 AliEveITSModule::fgSDDPalette->SetMinMax(0, 100);
32e219c2 385 }
386 else
387 {
a15e6d7d 388 AliEveITSDigitsInfo& di = *fInfo;
32e219c2 389 // SPD
a15e6d7d 390 AliEveITSModule::fgSPDPalette->SetLimits(0, di.fSPDHighLim);
391 AliEveITSModule::fgSPDPalette->SetMinMax(di.fSPDMinVal, di.fSPDMaxVal);
51346b82 392
32e219c2 393 // SDD
a15e6d7d 394 AliEveITSModule::fgSDDPalette->SetLimits(0, di.fSDDHighLim);
395 AliEveITSModule::fgSDDPalette->SetMinMax(di.fSDDMinVal, di.fSDDMaxVal);
32e219c2 396
397 // SSD
a15e6d7d 398 AliEveITSModule::fgSSDPalette->SetLimits(0, di.fSSDHighLim);
399 AliEveITSModule::fgSSDPalette->SetMinMax(di.fSSDMinVal, di.fSSDMaxVal);
32e219c2 400 }
401
402 fScaleInfo->SetSyncPalette(kFALSE);
403}
404
57ffa5fb 405/******************************************************************************/
32e219c2 406
a15e6d7d 407void AliEveITSScaledModule::GetScaleData(Int_t& cnx, Int_t& cnz, Int_t& total) const
32e219c2 408{
a15e6d7d 409 cnx = fNx;
410 cnz = fNz;
32e219c2 411 total = cnx*cnz;
412}
413
57ffa5fb 414/******************************************************************************/
32e219c2 415
d810d0de 416void AliEveITSScaledModule::DigitSelected(Int_t idx)
3b868b75 417{
84aff7a4 418 // Override control-click from TEveQuadSet
d810d0de 419 printf("AliEveITSScaledModule::DigitSelected "); Print();
3b868b75 420
d794819f 421 // DigitBase_t *qb = GetDigit(idx);
422 TObject *obj = GetId(idx);
01ff6975 423 ScaledDigit_t *sd = static_cast<ScaledDigit_t*>(obj);
3b868b75 424 TClonesArray *digits = fInfo->GetDigits(fID, fDetID);
425 Int_t ndigits = digits->GetEntriesFast();
426
a15e6d7d 427 printf("%d digits in cell scaleX = %d, scaleZ = %d \n", sd->fN, fNCx, fNCz);
3b868b75 428
429 Int_t il = 0;
51346b82 430 for(Int_t k=0; k<ndigits; k++)
3b868b75 431 {
432 AliITSdigit *d = (AliITSdigit*) digits->UncheckedAt(k);
433
a15e6d7d 434 if(d->GetCoord1()>=sd->fMinI && d->GetCoord1()<=sd->fMaxI &&
435 d->GetCoord2()>=sd->fMinJ && d->GetCoord2()<=sd->fMaxJ)
3b868b75 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}