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