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