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