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