Initialized sum variables
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSDigitsInfo.cxx
CommitLineData
d810d0de 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 *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
5a5a1232 9
3d598e88 10#include <TMath.h>
11#include <TVector3.h>
5a5a1232 12
84aff7a4 13#include <TEveTreeTools.h>
14#include <TEveTrans.h>
5a5a1232 15
d810d0de 16#include "AliEveITSDigitsInfo.h"
5a5a1232 17#include <AliITSCalibrationSDD.h>
18#include <AliITSdigit.h>
19#include <AliITSdigitSPD.h>
20
b3bc5327 21#include <AliRawReader.h>
22#include <AliITSRawStreamSPD.h>
23#include <AliITSRawStreamSDD.h>
24#include <AliITSRawStreamSSD.h>
d810d0de 25
54f770b4 26//______________________________________________________________________________
27//
28// Helper for selecting a range of ITS modules by type, layer, phi and
29// theta. Taken as an argument to AliEveITSDigitsInfo::GetModuleIDs().
3d598e88 30
d810d0de 31ClassImp(AliEveITSModuleSelection)
3d598e88 32
d810d0de 33AliEveITSModuleSelection::AliEveITSModuleSelection():
3d598e88 34 fType(-1),
35 fLayer(-1),
32e219c2 36 fMinPhi(-TMath::Pi()),
37 fMaxPhi(TMath::Pi()),
38 fMinTheta(-TMath::Pi()),
39 fMaxTheta(TMath::Pi())
54f770b4 40{
41 // Constructor.
42}
43
b3bc5327 44
54f770b4 45//______________________________________________________________________________
46//
47// Stores ITS geometry information and event-data in format suitable
48// for visualization.
3d598e88 49
d810d0de 50ClassImp(AliEveITSDigitsInfo)
5a5a1232 51
57ffa5fb 52/******************************************************************************/
5a5a1232 53
d810d0de 54AliEveITSDigitsInfo::AliEveITSDigitsInfo() :
265ecb21 55 TObject(),
84aff7a4 56 TEveRefCnt(),
265ecb21 57 fSPDmap(), fSDDmap(), fSSDmap(),
58 fTree (0),
59 fGeom (0),
fd31e9de 60 fSegSPD (0), fSegSDD (0), fSegSSD (0),
c76ea574 61 fSPDMinVal (0), fSSDMinVal (0), fSDDMinVal (0),
62 fSPDMaxVal (0), fSSDMaxVal (0), fSDDMaxVal (0),
fd31e9de 63 fSPDHighLim (0), fSDDHighLim (0), fSSDHighLim (0)
5a5a1232 64{
54f770b4 65 // Default constructor.
66
b3bc5327 67 InitInternals();
5a5a1232 68}
69
d810d0de 70void AliEveITSDigitsInfo::InitInternals()
5a5a1232 71{
54f770b4 72 // Initialize internal geometry structures, in particular the
73 // module-id to transformation-matrix mapping and segmentation
74 // classes and data-structures.
75
d810d0de 76 static const TEveException eH("AliEveITSDigitsInfo::InitInternals ");
5a5a1232 77
b3bc5327 78 fGeom = new AliITSgeom();
79 fGeom->ReadNewFile("$REVESYS/alice-data/ITSgeometry.det");
54f770b4 80 if (fGeom == 0)
b3bc5327 81 throw(eH + "can not load ITS geometry \n");
5a5a1232 82
83 SetITSSegmentation();
d4b6a94c 84
5a5a1232 85 // create tables for scaling
d4b6a94c 86 fSPDMinVal = 0;
87 fSDDMinVal = 5;
88 fSSDMinVal = 2;
89
90 fSPDMaxVal = 1;
91 fSDDMaxVal = 80;
92 fSSDMaxVal = 100;
93
32e219c2 94 fSPDHighLim = 1;
95 fSDDHighLim = 512;
96 fSSDHighLim = 1024;
d4b6a94c 97
d54c094e 98 // lowest scale factor refers to unscaled ITS module
99 fSPDScaleX[0] = 1;
100 fSPDScaleZ[0] = 1;
101 fSDDScaleX[0] = 1;
102 fSDDScaleZ[0] = 1;
103 fSSDScale [0] = 1;
d4b6a94c 104
b3bc5327 105 // spd lowest resolution
5a5a1232 106 Int_t nx = 8; // fSegSPD->Npx()/8; // 32
107 Int_t nz = 6; // fSegSPD->Npz()/2; // 128
51346b82 108 fSPDScaleX[1] = Int_t(nx);
109 fSPDScaleZ[1] = Int_t(nz);
110 fSPDScaleX[2] = Int_t(nx*2);
111 fSPDScaleZ[2] = Int_t(nz*2);
112 fSPDScaleX[3] = Int_t(nx*3);
113 fSPDScaleZ[3] = Int_t(nz*3);
114 fSPDScaleX[4] = Int_t(nx*4);
115 fSPDScaleZ[4] = Int_t(nz*4);
5a5a1232 116
5a5a1232 117 fSDDScaleX[1] = 2;
118 fSDDScaleZ[1] = 2;
119 fSDDScaleX[2] = 8;
120 fSDDScaleZ[2] = 8;
121 fSDDScaleX[3] = 16;
122 fSDDScaleZ[3] = 16;
123 fSDDScaleX[4] = 25;
124 fSDDScaleZ[4] = 25;
125
126 fSSDScale[1] = 3;
127 fSSDScale[2] = 9;
128 fSSDScale[3] = 20;
129 fSSDScale[4] = 30;
5a5a1232 130}
131
57ffa5fb 132/******************************************************************************/
5a5a1232 133
51346b82 134AliEveITSDigitsInfo:: ~AliEveITSDigitsInfo()
b3bc5327 135{
54f770b4 136 // Destructor.
137 // Deletes the data-maps and the tree.
138
fd31e9de 139 std::map<Int_t, TClonesArray*>::iterator j;
b3bc5327 140 for(j = fSPDmap.begin(); j != fSPDmap.end(); ++j)
141 delete j->second;
142 for(j = fSDDmap.begin(); j != fSDDmap.end(); ++j)
143 delete j->second;
144 for(j = fSSDmap.begin(); j != fSSDmap.end(); ++j)
145 delete j->second;
146
51346b82 147 delete fSegSPD; delete fSegSDD; delete fSegSSD;
b3bc5327 148 delete fGeom;
149 delete fTree;
150}
151
57ffa5fb 152/******************************************************************************/
b3bc5327 153
d810d0de 154void AliEveITSDigitsInfo::SetTree(TTree* tree)
b3bc5327 155{
156 // Set digit-tree to be used for digit retrieval. Data is loaded on
157 // demand.
158
159 fTree = tree;
160}
161
d810d0de 162void AliEveITSDigitsInfo::ReadRaw(AliRawReader* raw, Int_t mode)
b3bc5327 163{
164 // Read raw-data into internal structures. AliITSdigit is used to
165 // store raw-adata for all sub-detectors.
166
540e156e 167 if ((mode & 1) || (mode & 2)){
b3bc5327 168 AliITSRawStreamSPD inputSPD(raw);
169 TClonesArray* digits = 0;
b3bc5327 170 while (inputSPD.Next())
171 {
172 Int_t module = inputSPD.GetModuleID();
173 Int_t column = inputSPD.GetColumn();
174 Int_t row = inputSPD.GetRow();
51346b82 175
b3bc5327 176 if (inputSPD.IsNewModule())
177 {
f8495fba 178 digits = fSPDmap[module];
179 if (digits == 0)
180 fSPDmap[module] = digits = new TClonesArray("AliITSdigit", 16);
b3bc5327 181 }
182
f8495fba 183 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
b3bc5327 184 d->SetCoord1(column);
185 d->SetCoord2(row);
186 d->SetSignal(1);
b3bc5327 187
188 // printf("SPD: %d %d %d\n",module,column,row);
189 }
b3bc5327 190 raw->Reset();
191 }
192
540e156e 193 if ((mode & 4) || (mode & 8)){
b3bc5327 194 AliITSRawStreamSDD input(raw);
195 TClonesArray* digits = 0;
b3bc5327 196 while (input.Next())
197 {
198 Int_t module = input.GetModuleID();
199 Int_t anode = input.GetAnode();
200 Int_t time = input.GetTime();
201 Int_t signal = input.GetSignal();
202
203 if (input.IsNewModule())
204 {
f8495fba 205 digits = fSDDmap[module];
206 if (digits == 0)
207 fSDDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
b3bc5327 208 }
209
f8495fba 210 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
b3bc5327 211 d->SetCoord1(anode);
212 d->SetCoord2(time);
213 d->SetSignal(signal);
b3bc5327 214
215 // printf("SDD: %d %d %d %d\n",module,anode,time,signal);
216 }
b3bc5327 217 raw->Reset();
218 }
219
540e156e 220 if ((mode & 16) || (mode & 32)){
b3bc5327 221 AliITSRawStreamSSD input(raw);
222 TClonesArray* digits = 0;
b3bc5327 223 while (input.Next())
224 {
225 Int_t module = input.GetModuleID();
226 Int_t side = input.GetSideFlag();
227 Int_t strip = input.GetStrip();
228 Int_t signal = input.GetSignal();
229
230 if (input.IsNewModule())
231 {
f8495fba 232 digits = fSSDmap[module];
233 if (digits == 0)
234 fSSDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
b3bc5327 235 }
236
f8495fba 237 AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
b3bc5327 238 d->SetCoord1(side);
239 d->SetCoord2(strip);
240 d->SetSignal(signal);
b3bc5327 241
242 // printf("SSD: %d %d %d %d\n",module,side,strip,signal);
243 }
b3bc5327 244 raw->Reset();
245 }
246}
247
57ffa5fb 248/******************************************************************************/
b3bc5327 249
d810d0de 250void AliEveITSDigitsInfo::SetITSSegmentation()
5a5a1232 251{
54f770b4 252 // Create the segmentation objects and fill internal
253 // data-structures.
254
5a5a1232 255 // SPD
256 fSegSPD = new AliITSsegmentationSPD(fGeom);
54f770b4 257
5a5a1232 258 Int_t m;
259 Float_t fNzSPD=160;
260 Float_t fZ1pitchSPD=0.0425; Float_t fZ2pitchSPD=0.0625;
261 Float_t fHlSPD=3.48;
262
263 fSPDZCoord[0]=fZ1pitchSPD -fHlSPD;
264 for (m=1; m<fNzSPD; m++) {
265 Double_t dz=fZ1pitchSPD;
51346b82 266 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
267 m==127 || m==128) dz=fZ2pitchSPD;
5a5a1232 268 fSPDZCoord[m]=fSPDZCoord[m-1]+dz;
269 }
51346b82 270
5a5a1232 271 for (m=0; m<fNzSPD; m++) {
272 Double_t dz=1.*fZ1pitchSPD;
51346b82 273 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
274 m==127 || m==128) dz=1.*fZ2pitchSPD;
5a5a1232 275 fSPDZCoord[m]-=dz;
276 }
51346b82 277
5a5a1232 278 // SDD
b85e8cbd 279 fSegSDD = new AliITSsegmentationSDD(fGeom);
5a5a1232 280
281 // SSD
282 fSegSSD = new AliITSsegmentationSSD(fGeom);
283}
284
57ffa5fb 285/******************************************************************************/
5a5a1232 286
d810d0de 287TClonesArray* AliEveITSDigitsInfo::GetDigits(Int_t mod, Int_t subdet)
5a5a1232 288{
54f770b4 289 // Return TClonesArray of digits for specified module and sub-detector-id.
290
291 switch(subdet)
292 {
293 case 0:
294 {
6ddaaee3 295 TClonesArray* digitsSPD = 0;
fd31e9de 296 std::map<Int_t, TClonesArray*>::iterator i = fSPDmap.find(mod);
54f770b4 297 if (i == fSPDmap.end()) {
540e156e 298 if (fTree) {
299 TBranch* br = fTree->GetBranch("ITSDigitsSPD");
300 br->SetAddress(&digitsSPD);
301 br->GetEntry(mod);
302 fSPDmap[mod] = digitsSPD;
303 return digitsSPD;
304 }
305 else
306 return NULL;
6ddaaee3 307 } else {
308 return i->second;
309 }
310 break;
5a5a1232 311 }
54f770b4 312 case 1:
313 {
6ddaaee3 314 TClonesArray* digitsSDD = 0;
fd31e9de 315 std::map<Int_t, TClonesArray*>::iterator i = fSDDmap.find(mod);
54f770b4 316 if (i == fSDDmap.end()) {
540e156e 317 if (fTree) {
318 TBranch* br = fTree->GetBranch("ITSDigitsSDD");
319 br->SetAddress(&digitsSDD);
320 br->GetEntry(mod);
321 fSDDmap[mod] = digitsSDD;
322 return digitsSDD;
323 }
324 else
325 return NULL;
326 } else {
6ddaaee3 327 return i->second;
328 }
329 break;
5a5a1232 330 }
54f770b4 331 case 2:
332 {
6ddaaee3 333 TClonesArray* digitsSSD = 0;
fd31e9de 334 std::map<Int_t, TClonesArray*>::iterator i = fSSDmap.find(mod);
54f770b4 335 if (i == fSSDmap.end()) {
540e156e 336 if (fTree) {
337 TBranch* br = fTree->GetBranch("ITSDigitsSSD");
338 br->SetAddress(&digitsSSD);
339 br->GetEntry(mod);
340
341 fSSDmap[mod] = digitsSSD;
342 return digitsSSD;
343 }
344 else
345 return NULL;
346 } else {
6ddaaee3 347 return i->second;
348 }
349 break;
5a5a1232 350 }
6ddaaee3 351 default:
352 return 0;
54f770b4 353 }
03ecfe88 354 return 0;
5a5a1232 355}
356
57ffa5fb 357/******************************************************************************/
54f770b4 358
359void AliEveITSDigitsInfo::GetModuleIDs(AliEveITSModuleSelection* sel,
360 std::vector<UInt_t>& ids)
3d598e88 361{
54f770b4 362 // Fill the id-vector with ids of modules that satisfy conditions
363 // given by the AliEveITSModuleSelection object.
364
3d598e88 365 Int_t idx0 = 0, idx1 = 0;
51346b82 366 switch(sel->GetType())
3d598e88 367 {
368 case 0:
369 idx0 = 0;
370 idx1 = fGeom->GetLastSPD();
371 break;
372 case 1:
32e219c2 373 idx0 = fGeom->GetLastSPD()+1;
3d598e88 374 idx1 = fGeom->GetLastSDD();
375 break;
376 case 2:
32e219c2 377 idx0 = fGeom->GetLastSDD()+1;
3d598e88 378 idx1 = fGeom->GetLastSSD();
379 break;
380 default:
381 idx1 = 0;
382 idx1 = fGeom->GetLastSSD();
54f770b4 383 break;
3d598e88 384 }
385
386 TVector3 v;
387 Double_t x[9];
388 Int_t lay, lad, det;
84aff7a4 389 TEveTrans mx;
54f770b4 390 for (Int_t id = idx0; id<idx1; ++id)
391 {
3d598e88 392 fGeom->GetModuleId(id, lay, lad, det);
51346b82 393 if (sel->GetLayer() == lay || sel->GetLayer() == -1)
3d598e88 394 {
395 // check data from matrix
396 mx.UnitTrans();
397 fGeom->GetRotMatrix(id, x);
398 mx.SetBaseVec(1, x[0], x[3], x[6]);
399 mx.SetBaseVec(2, x[1], x[4], x[7]);
400 mx.SetBaseVec(3, x[2], x[5], x[8]);
51346b82 401 fGeom->GetTrans(id, x);
3d598e88 402 mx.SetBaseVec(4, x);
403 mx.GetPos(v);
51346b82 404 if (v.Phi() <= sel->GetMaxPhi() && v.Phi() >= sel->GetMinPhi() &&
405 v.Theta() <= sel->GetMaxTheta() && v.Theta() >= sel->GetMinTheta())
54f770b4 406 {
3d598e88 407 ids.push_back(id);
54f770b4 408 }
3d598e88 409 }
410 }
411}
5a5a1232 412
57ffa5fb 413/******************************************************************************/
5a5a1232 414
d810d0de 415void AliEveITSDigitsInfo::Print(Option_t* ) const
5a5a1232 416{
54f770b4 417 // Print information about stored geometry and segmentation.
418
5a5a1232 419 printf("*********************************************************\n");
54f770b4 420 printf("SPD module dimension (%f,%f)\n", fSegSPD->Dx()*0.0001, fSegSPD->Dz()*0.0001);
421 printf("SPD first,last module:: %d,%d\n", fGeom->GetStartSPD(), fGeom->GetLastSPD() );
422 printf("SPD num cells per module (x::%d,z::%d)\n", fSegSPD->Npx(), fSegSPD->Npz());
423 Int_t iz = 0, ix = 0;
424 printf("SPD dimesion of (%d,%d) in pixel(%f,%f)\n", ix, iz, fSegSPD->Dpx(ix), fSegSPD->Dpz(iz));
5a5a1232 425 iz = 32;
54f770b4 426 printf("SPD dimesion of pixel (%d,%d) are (%f,%f)\n", ix, iz, fSegSPD->Dpx(ix)*0.001, fSegSPD->Dpz(iz)*0.001);
51346b82 427
5a5a1232 428 printf("*********************************************************\n");
54f770b4 429 printf("SDD module dimension (%f,%f)\n", fSegSDD->Dx()*0.0001, fSegSDD->Dz()*0.0001);
430 printf("SDD first,last module:: %d,%d\n", fGeom->GetStartSDD(), fGeom->GetLastSDD());
431 printf("SDD num cells per module (x::%d,z::%d)\n", fSegSDD->Npx(), fSegSDD->Npz());
432 printf("SDD dimesion of pixel are (%f,%f)\n", fSegSDD->Dpx(1)*0.001, fSegSDD->Dpz(1)*0.001);
433
434 Float_t ap, an;
5a5a1232 435 printf("*********************************************************\n");
54f770b4 436 printf("SSD module dimension (%f,%f)\n", fSegSSD->Dx()*0.0001, fSegSSD->Dz()*0.0001);
437 printf("SSD first,last module:: %d,%d\n", fGeom->GetStartSSD(), fGeom->GetLastSSD() );
438 printf("SSD strips in module %d\n", fSegSSD->Npx());
439 printf("SSD strip sizes are (%f,%f)\n", fSegSSD->Dpx(1), fSegSSD->Dpz(1));
440 fSegSSD->SetLayer(5); fSegSSD->Angles(ap,an);
51346b82 441 printf("SSD layer 5 stereoP %f stereoN %f angle\n", ap, an);
5a5a1232 442 fSegSSD->SetLayer(6); fSegSSD->Angles(ap,an);
51346b82 443 printf("SSD layer 6 stereoP %f stereoN %f angle\n", ap, an);
5a5a1232 444}
445
446
447/*
448 printf("num cells %d,%d scaled %d,%d \n",fSegSPD->Npz(),fSegSPD->Npx(),Nz,Nx);
d810d0de 449 printf("%d digits in AliEveITSModule %d\n",ne, module);
5a5a1232 450 Float_t zn = i*(3.48*2)/Nz - 3.48 ;
451 Float_t xo = -fSegSPD->Dx()*0.00005 + fSegSPD->Dpx(0)*od->GetCoord2()*0.0001;
452 Float_t xn = -fSegSPD->Dx()*0.00005 + j*0.0001*fSegSPD->Dx()/Nx;
453 Float_t dpx = 0.0001*fSegSPD->Dx()/Nx;
454 Float_t dpz = 3.48*2/Nz;
455 printf("Z::original (%3f) scaled (%3f, %3f) \n", zo, zn-dpz/2, zn+dpz/2);
456 printf("X::original (%3f) scaled (%3f, %3f) \n", xo, xn-dpx/2, xn+dpx/2);
457 printf("%d,%d maped to %d,%d \n", od->GetCoord1(), od->GetCoord2(), i,j );
51346b82 458*/