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