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