]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveITSDigitsInfo.cxx
From Massimo: remove usage of AliITSgeom, use AliITSgeomTGeo instead.
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveITSDigitsInfo.cxx
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  **************************************************************************/
9
10 #include "AliEveITSDigitsInfo.h"
11 #include <EveBase/AliEveEventManager.h>
12
13 #include <TEveTreeTools.h>
14 #include <TEveTrans.h>
15
16 #include <AliITS.h>
17 #include <AliITSInitGeometry.h>
18 #include <AliITSgeomTGeo.h>
19 #include <AliITSsegmentationSPD.h>
20 #include <AliITSsegmentationSDD.h>
21 #include <AliITSsegmentationSSD.h>
22 #include <AliITSDDLModuleMapSDD.h>
23
24 #include <AliITSCalibrationSDD.h>
25 #include <AliITSdigit.h>
26 #include <AliITSdigitSPD.h>
27
28 #include <AliCDBEntry.h>
29 #include <AliCDBManager.h>
30
31 #include <AliRawReader.h>
32 #include <AliITSRawStreamSPD.h>
33 #include <AliITSRawStreamSDD.h>
34 #include <AliITSRawStreamSSD.h>
35
36 #include <TGeoMatrix.h>
37 #include <TMath.h>
38 #include <TVector3.h>
39
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().
44
45 ClassImp(AliEveITSModuleSelection)
46
47 AliEveITSModuleSelection::AliEveITSModuleSelection():
48   fType(-1),
49   fLayer(-1),
50   fMinPhi(-TMath::Pi()),
51   fMaxPhi(TMath::Pi()),
52   fMinTheta(-TMath::Pi()),
53   fMaxTheta(TMath::Pi())
54 {
55   // Constructor.
56 }
57
58
59 //______________________________________________________________________________
60 //
61 // Stores ITS geometry information and event-data in format suitable
62 // for visualization.
63
64 ClassImp(AliEveITSDigitsInfo)
65
66 /******************************************************************************/
67
68 AliEveITSDigitsInfo::AliEveITSDigitsInfo() :
69   TObject(),
70   TEveRefCnt(),
71   fSPDmap(), fSDDmap(), fSSDmap(),
72   fTree (0),
73   fSegSPD     (0), fSegSDD     (0), fSegSSD     (0),
74   fDDLMapSDD  (0),
75   fSPDMinVal  (0), fSSDMinVal  (0), fSDDMinVal  (0),
76   fSPDMaxVal  (0), fSSDMaxVal  (0), fSDDMaxVal  (0),
77   fSPDHighLim (0), fSDDHighLim (0), fSSDHighLim (0)
78 {
79   // Default constructor.
80
81   InitInternals();
82 }
83
84 void AliEveITSDigitsInfo::InitInternals()
85 {
86   // Initialize internal geometry structures, in particular the
87   // module-id to transformation-matrix mapping and segmentation
88   // classes and data-structures.
89
90   static const TEveException eH("AliEveITSDigitsInfo::InitInternals ");
91
92   AliEveEventManager::AssertGeometry();
93
94   SetITSSegmentation();
95
96   // create tables for scaling
97   fSPDMinVal = 0;
98   fSDDMinVal = 5;
99   fSSDMinVal = 2;
100
101   fSPDMaxVal = 1;
102   fSDDMaxVal = 80;
103   fSSDMaxVal = 100;
104
105   fSPDHighLim = 1;
106   fSDDHighLim = 512;
107   fSSDHighLim = 1024;
108
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;
115
116   // spd lowest resolution
117   Int_t nx = 8; // fSegSPD->Npx()/8; // 32
118   Int_t nz = 6; // fSegSPD->Npz()/2; // 128
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);
127
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;
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;
157 }
158
159 /******************************************************************************/
160
161 AliEveITSDigitsInfo:: ~AliEveITSDigitsInfo()
162 {
163   // Destructor.
164   // Deletes the data-maps and the tree.
165
166   std::map<Int_t, TClonesArray*>::iterator j;
167   for (j = fSPDmap.begin(); j != fSPDmap.end(); ++j)
168     delete j->second;
169   for (j = fSDDmap.begin(); j != fSDDmap.end(); ++j)
170     delete j->second;
171   for (j = fSSDmap.begin(); j != fSSDmap.end(); ++j)
172     delete j->second;
173   delete fDDLMapSDD;
174   delete fSegSPD; delete fSegSDD; delete fSegSSD;
175   delete fTree;
176 }
177
178 /******************************************************************************/
179
180 void AliEveITSDigitsInfo::SetTree(TTree* tree)
181 {
182   // Set digit-tree to be used for digit retrieval. Data is loaded on
183   // demand.
184
185   fTree = tree;
186 }
187
188 void AliEveITSDigitsInfo::ReadRaw(AliRawReader* raw, Int_t mode)
189 {
190   // Read raw-data into internal structures. AliITSdigit is used to
191   // store raw-adata for all sub-detectors.
192
193   if ((mode & 1) || (mode & 2))
194   {
195     AliITSRawStreamSPD inputSPD(raw);
196     TClonesArray* digits = 0;
197     while (inputSPD.Next())
198     {
199       Int_t module = inputSPD.GetModuleID();
200       Int_t column = inputSPD.GetColumn();
201       Int_t row    = inputSPD.GetRow();
202
203       if (inputSPD.IsNewModule())
204       {
205         digits = fSPDmap[module];
206         if (digits == 0)
207           fSPDmap[module] = digits = new TClonesArray("AliITSdigit", 16);
208       }
209
210       AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
211       d->SetCoord1(column);
212       d->SetCoord2(row);
213       d->SetSignal(1);
214
215       // printf("SPD: %d %d %d\n",module,column,row);
216     }
217     raw->Reset();
218   }
219
220   if ((mode & 4) || (mode & 8))
221   {
222     AliITSRawStreamSDD input(raw);
223     input.SetDDLModuleMap(fDDLMapSDD);
224     TClonesArray* digits = 0;
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       {
234         digits = fSDDmap[module];
235         if (digits == 0)
236           fSDDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
237       }
238
239       AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
240       d->SetCoord1(anode);
241       d->SetCoord2(time);
242       d->SetSignal(signal);
243
244       // printf("SDD: %d %d %d %d\n",module,anode,time,signal);
245     }
246     raw->Reset();
247   }
248
249   if ((mode & 16) || (mode & 32))
250   {
251     AliITSRawStreamSSD input(raw);
252     TClonesArray* digits = 0;
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
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)
263       {
264         digits = fSSDmap[module];
265         if (digits == 0)
266           fSSDmap[module] = digits = new TClonesArray("AliITSdigit", 0);
267       }
268
269       AliITSdigit* d = new ((*digits)[digits->GetEntriesFast()]) AliITSdigit();
270       d->SetCoord1(side);
271       d->SetCoord2(strip);
272       d->SetSignal(signal);
273
274       // printf("SSD: %d %d %d %d\n",module,side,strip,signal);
275     }
276     raw->Reset();
277   }
278 }
279
280 /******************************************************************************/
281
282 void AliEveITSDigitsInfo::SetITSSegmentation()
283 {
284   // Create the segmentation objects and fill internal
285   // data-structures.
286
287   // SPD
288   fSegSPD = new AliITSsegmentationSPD();
289
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;
298     if (m==31 || m==32 || m==63  || m==64  || m==95 || m==96 ||
299         m==127 || m==128) dz=fZ2pitchSPD;
300     fSPDZCoord[m]=fSPDZCoord[m-1]+dz;
301   }
302
303   for (m=0; m<fNzSPD; m++) {
304     Double_t dz=1.*fZ1pitchSPD;
305     if (m==31 || m==32 || m==63  || m==64  || m==95 || m==96 ||
306         m==127 || m==128) dz=1.*fZ2pitchSPD;
307     fSPDZCoord[m]-=dz;
308   }
309
310   // SDD
311   fSegSDD = new AliITSsegmentationSDD();
312   // !!!! Set default drift speed, eventually need to get it from CDB.
313   fSegSDD->SetDriftSpeed(7.3);
314
315   // SSD
316   fSegSSD = new AliITSsegmentationSSD();
317 }
318
319 /******************************************************************************/
320
321 TClonesArray* AliEveITSDigitsInfo::GetDigits(Int_t mod, Int_t subdet)
322 {
323   // Return TClonesArray of digits for specified module and sub-detector-id.
324
325   switch(subdet)
326   {
327     case 0:
328     {
329       TClonesArray* digitsSPD = 0;
330       std::map<Int_t, TClonesArray*>::iterator i = fSPDmap.find(mod);
331       if (i == fSPDmap.end()) {
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;
341       } else {
342         return i->second;
343       }
344       break;
345     }
346     case 1:
347     {
348       TClonesArray* digitsSDD = 0;
349       std::map<Int_t, TClonesArray*>::iterator i = fSDDmap.find(mod);
350       if (i == fSDDmap.end()) {
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 {
361         return i->second;
362       }
363       break;
364     }
365     case 2:
366     {
367       TClonesArray* digitsSSD = 0;
368       std::map<Int_t, TClonesArray*>::iterator i = fSSDmap.find(mod);
369       if (i == fSSDmap.end()) {
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 {
381         return i->second;
382       }
383       break;
384     }
385     default:
386       return 0;
387   }
388   return 0;
389 }
390
391 /******************************************************************************/
392
393 void AliEveITSDigitsInfo::GetModuleIDs(AliEveITSModuleSelection* sel,
394                                        std::vector<UInt_t>& ids)
395 {
396   // Fill the id-vector with ids of modules that satisfy conditions
397   // given by the AliEveITSModuleSelection object.
398
399   Int_t idx0 = 0, idx1 = 0;
400   switch(sel->GetType())
401   {
402     case 0:
403       idx0 = 0;
404       idx1 = AliITSgeomTGeo::GetModuleIndex(3, 1, 1) - 1;
405       break;
406     case 1:
407       idx0 = AliITSgeomTGeo::GetModuleIndex(3, 1, 1);
408       idx1 = AliITSgeomTGeo::GetModuleIndex(5, 1, 1) - 1;
409       break;
410     case 2:
411       idx0 = AliITSgeomTGeo::GetModuleIndex(5, 1, 1);
412       idx1 = AliITSgeomTGeo::GetNModules() - 1;
413       break;
414     default:
415       idx1 = 0;
416       idx1 = AliITSgeomTGeo::GetNModules() - 1;
417       break;
418   }
419
420   TVector3  v;
421   TEveTrans mx;
422   Int_t     lay, lad, det;
423   for (Int_t id = idx0; id < idx1; ++id)
424   {
425     AliITSgeomTGeo::GetModuleId(id, lay, lad, det);
426     if (sel->GetLayer() == lay || sel->GetLayer() == -1)
427     {
428       // check data from matrix
429       mx.SetFrom(*AliITSgeomTGeo::GetMatrix(id));
430       mx.GetPos(v);
431       if (v.Phi()   <= sel->GetMaxPhi()   && v.Phi()   >= sel->GetMinPhi()   &&
432           v.Theta() <= sel->GetMaxTheta() && v.Theta() >= sel->GetMinTheta())
433       {
434         ids.push_back(id);
435       }
436     }
437   }
438 }
439
440 /******************************************************************************/
441
442 void AliEveITSDigitsInfo::Print(Option_t* ) const
443 {
444   // Print information about stored geometry and segmentation.
445
446   printf("*********************************************************\n");
447   printf("SPD module dimension (%f,%f)\n",           fSegSPD->Dx()*0.0001, fSegSPD->Dz()*0.0001);
448   printf("SPD first,last module: %d, %d\n",
449          AliITSgeomTGeo::GetModuleIndex(1,1,1), 
450          AliITSgeomTGeo::GetModuleIndex(3,1,1) - 1);
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));
454   iz = 32;
455   printf("SPD dimesion of pixel (%d,%d) are (%f,%f)\n", ix, iz, fSegSPD->Dpx(ix)*0.001, fSegSPD->Dpz(iz)*0.001);
456
457   printf("*********************************************************\n");
458   printf("SDD module dimension (%f,%f)\n",           fSegSDD->Dx()*0.0001, fSegSDD->Dz()*0.0001);
459   printf("SDD first,last module: %d, %d\n",
460          AliITSgeomTGeo::GetModuleIndex(3,1,1),
461          AliITSgeomTGeo::GetModuleIndex(5,1,1) - 1);
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;
466   printf("*********************************************************\n");
467   printf("SSD module dimension (%f,%f)\n",  fSegSSD->Dx()*0.0001, fSegSSD->Dz()*0.0001);
468   printf("SSD first, last module: %d, %d\n",
469          AliITSgeomTGeo::GetModuleIndex(5,1,1),
470          AliITSgeomTGeo::GetNModules() - 1);
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);
474   printf("SSD layer 5 stereoP %f stereoN %f angle\n", ap, an);
475   fSegSSD->SetLayer(6);  fSegSSD->Angles(ap,an);
476   printf("SSD layer 6 stereoP %f stereoN %f angle\n", ap, an);
477 }
478
479
480 /*
481   printf("num cells %d,%d scaled %d,%d \n",fSegSPD->Npz(),fSegSPD->Npx(),Nz,Nx);
482   printf("%d digits in AliEveITSModule %d\n",ne, module);
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 );
491 */