]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTRDModuleImp.cxx
With Rossella. Add more configurability to ITS raw/digit visualization: a) select...
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDModuleImp.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 "AliEveTRDModuleImp.h"
11 #include "AliEveTRDData.h"
12
13 #include "TGListTree.h"
14 #include "TClonesArray.h"
15 #include "TGeoManager.h"
16 #include "TGeoMatrix.h"
17
18 #include "TEveManager.h"
19 #include "TEveTrack.h"
20 #include "TEveGeoNode.h"
21 #include "TEveTrans.h"
22
23
24 #include "AliLog.h"
25 #include "AliTRDgeometry.h"
26 #include "AliTRDCommonParam.h"
27 #include "AliTRDpadPlane.h"
28 #include "AliTRDhit.h"
29 #include "AliTRDcluster.h"
30 #include "AliTRDmcmTracklet.h"
31
32 ClassImp(AliEveTRDChamber)
33 ClassImp(AliEveTRDNode)
34
35 //______________________________________________________________________________
36 AliEveTRDNode::AliEveTRDNode(const char *typ, Int_t det) :
37   TEveElement(), AliEveTRDModule(typ, det)
38 {
39   // Xonstructor.
40 }
41
42 //______________________________________________________________________________
43 void AliEveTRDNode::Paint(Option_t* option)
44 {
45   // Paint object.
46
47   List_i iter = fChildren.begin();
48   while(iter != fChildren.end()){
49     (dynamic_cast<AliEveTRDModule*>(*iter))->Paint(option);
50     iter++;
51   }
52 }
53
54 //______________________________________________________________________________
55 void AliEveTRDNode::Reset()
56 {
57   // Reset.
58
59   List_i iter = fChildren.begin();
60   while(iter != fChildren.end()){
61     (dynamic_cast<AliEveTRDModule*>(*iter))->Reset();
62     iter++;
63   }
64 }
65
66 //______________________________________________________________________________
67 void AliEveTRDNode::Collapse()
68 {
69   // Collapse.
70
71   TGListTree *list = gEve->GetListTree();
72   AliEveTRDNode *node = 0x0;
73   List_i iter = fChildren.begin();
74   while(iter != fChildren.end()){
75     if((node = dynamic_cast<AliEveTRDNode*>(*iter))) node->Collapse();
76     list->CloseItem(FindListTreeItem(list));
77     iter++;
78   }
79 }
80
81 //______________________________________________________________________________
82 void AliEveTRDNode::Expand()
83 {
84   // Expand.
85
86   TGListTree *list = gEve->GetListTree();
87   AliEveTRDNode *node = 0x0;
88   List_i iter = fChildren.begin();
89   while(iter != fChildren.end()){
90     if((node = dynamic_cast<AliEveTRDNode*>(*iter))) node->Expand();
91     list->OpenItem(FindListTreeItem(list));
92     iter++;
93   }
94 }
95
96 //______________________________________________________________________________
97 void AliEveTRDNode::EnableListElements()
98 {
99   // Enable list elements.
100
101   SetRnrSelf(kTRUE);
102   AliEveTRDNode *node = 0x0;
103   AliEveTRDChamber *chmb = 0x0;
104   List_i iter = fChildren.begin();
105   while(iter != fChildren.end()){
106     if((node = dynamic_cast<AliEveTRDNode*>(*iter))){
107       node->SetRnrSelf(kTRUE);
108       node->EnableListElements();
109     }
110     if((chmb = dynamic_cast<AliEveTRDChamber*>(*iter))) chmb->SetRnrSelf(kTRUE);
111     iter++;
112   }
113   gEve->Redraw3D();
114 }
115
116 //______________________________________________________________________________
117 void AliEveTRDNode::DisableListElements()
118 {
119   // Disable list elements.
120
121   SetRnrSelf(kFALSE);
122   AliEveTRDNode *node = 0x0;
123   AliEveTRDChamber *chmb = 0x0;
124   List_i iter = fChildren.begin();
125   while(iter != fChildren.end()){
126     if((node = dynamic_cast<AliEveTRDNode*>(*iter))){
127       node->SetRnrSelf(kFALSE);
128       node->DisableListElements();
129     }
130     if((chmb = dynamic_cast<AliEveTRDChamber*>(*iter))) chmb->SetRnrSelf(kFALSE);
131     iter++;
132   }
133   gEve->Redraw3D();
134 }
135
136 //______________________________________________________________________________
137 void AliEveTRDNode::UpdateLeaves()
138 {
139   // Update leaves.
140
141   AliEveTRDModule *module;
142   List_i iter = fChildren.begin();
143   while(iter != fChildren.end()){
144     module = dynamic_cast<AliEveTRDModule*>(*iter);
145     if(!module) continue;
146
147     module->fRnrHits = fRnrHits;
148     module->fRnrDigits = fRnrDigits;
149     module->fDigitsLog = fDigitsLog;
150     module->fDigitsBox = fDigitsBox;
151     module->fDigitsThreshold = fDigitsThreshold;
152     module->fDigitsNeedRecompute = fDigitsNeedRecompute;
153     module->fRnrRecPoints = fRnrRecPoints;
154     module->fRnrTracklets = fRnrTracklets;
155     iter++;
156   }
157
158   AliEveTRDNode *node = 0x0;
159   iter = fChildren.begin();
160   while(iter != fChildren.end()){
161     if((node = dynamic_cast<AliEveTRDNode*>(*iter))) node->UpdateLeaves();
162     iter++;
163   }
164 }
165
166
167 //______________________________________________________________________________
168 void AliEveTRDNode::UpdateNode()
169 {
170   // Update node.
171
172   // Info("UpdateNode()", Form("%s", GetName()));
173   AliEveTRDNode *node = 0x0;
174   List_i iter = fChildren.begin();
175   while(iter != fChildren.end()){
176     if((node = dynamic_cast<AliEveTRDNode*>(*iter))) node->UpdateNode();
177     iter++;
178   }
179
180   Int_t score[11];
181   for(int i=0; i<11; i++) score[i] = 0;
182   AliEveTRDModule *module;
183   iter = fChildren.begin();
184   while(iter != fChildren.end()){
185     module = dynamic_cast<AliEveTRDModule*>(*iter);
186     if(!module) continue;
187     score[0] += (module->fLoadHits) ? 1 : 0;
188     score[1] += (module->fRnrHits) ? 1 : 0;
189
190     score[2] += (module->fLoadDigits) ? 1 : 0;
191     score[3] += (module->fRnrDigits) ? 1 : 0;
192     score[4] += (module->fDigitsLog) ? 1 : 0;
193     score[5] += (module->fDigitsBox) ? 1 : 0;
194     score[6] += (module->fDigitsNeedRecompute) ? 1 : 0;
195
196     score[7] += (module->fLoadRecPoints) ? 1 : 0;
197     score[8] += (module->fRnrRecPoints) ? 1 : 0;
198
199     score[9] += (module->fLoadTracklets) ? 1 : 0;
200     score[10] += (module->fRnrTracklets) ? 1 : 0;
201     iter++;
202   }
203
204   Int_t size = fChildren.size();
205   fLoadHits      = (score[0] > 0) ? kTRUE : kFALSE;
206   fRnrHits       = (score[1] == size) ? kTRUE : kFALSE;
207
208   fLoadDigits    = (score[2] > 0) ? kTRUE : kFALSE;
209   fRnrDigits     = (score[3] == size) ? kTRUE : kFALSE;
210   fDigitsLog     = (score[4] == size) ? kTRUE : kFALSE;
211   fDigitsBox     = (score[5] == size) ? kTRUE : kFALSE;
212   fDigitsNeedRecompute = (score[6] == size) ? kTRUE : kFALSE;
213
214   fLoadRecPoints = (score[7] > 0) ? kTRUE : kFALSE;
215   fRnrRecPoints  = (score[8] == size) ? kTRUE : kFALSE;
216
217   fLoadTracklets = (score[9] > 0) ? kTRUE : kFALSE;
218   fRnrTracklets  = (score[10] == size) ? kTRUE : kFALSE;
219 }
220
221
222 ///////////////////////////////////////////////////////////
223 ////////////      AliEveTRDChamber     ////////////////////
224 ///////////////////////////////////////////////////////////
225
226 //______________________________________________________________________________
227 AliEveTRDChamber::AliEveTRDChamber(Int_t det) :
228   TEveElement()
229   ,AliEveTRDModule("Chmb", det)
230   ,fDigits(0x0)
231   ,fHits(0x0)
232   ,fRecPoints(0x0)
233   ,fTracklets(0x0)
234   ,fGeo(0x0)
235   ,fShape(0x0)
236   ,fNrows(-1)
237   ,fNcols(-1)
238   ,fNtime(22)
239 {
240   //
241   // Constructor
242   //
243 }
244
245
246 //______________________________________________________________________________
247 void AliEveTRDChamber::LoadClusters(TObjArray *clusters)
248 {
249   //
250   // Draw clusters
251   //
252
253   if(!fGeo){
254     AliError(Form("Geometry not set for chamber %d. Please call first AliEveTRDChamber::SetGeometry().", fDet));
255     return;
256   }
257
258   if(!fRecPoints){ 
259     AddElement(fRecPoints = new AliEveTRDClusters());
260     fRecPoints->SetTitle(Form("Clusters for Det %d", GetID()));
261   }
262   fRecPoints->Reset();
263
264   Float_t q;
265   Float_t g[3]; //global coordinates
266   AliTRDcluster *c=0x0;
267   Int_t nc = clusters->GetEntriesFast();
268   for(int iclus=0; iclus<nc; iclus++){
269     c = (AliTRDcluster*)clusters->UncheckedAt(iclus);
270     c->GetGlobalXYZ(g); 
271     q = c->GetQ();
272     Int_t id = fRecPoints->SetNextPoint(g[0], g[1], g[2]);    
273     fRecPoints->SetPointId(id, new AliTRDcluster(*c));
274   }
275   fRecPoints->StampObjProps();
276   fLoadRecPoints = kTRUE;
277 }
278
279 //______________________________________________________________________________
280 void AliEveTRDChamber::LoadDigits(AliTRDdigitsManager *digits)
281 {
282   //
283   // Draw digits
284   //
285   if(!fGeo){
286     AliError(Form("Geometry not set for chamber %d. Please call first AliEveTRDChamber::SetGeometry().", fDet));
287     return;
288   }
289
290   if(!fDigits) AddElement(fDigits = new AliEveTRDDigits(this));
291
292   fDigits->Reset();
293   fDigits->SetData(digits);
294   fDigits->StampObjProps();
295   fDigitsNeedRecompute = kTRUE;  
296   fLoadDigits = kTRUE;
297 }
298
299 //______________________________________________________________________________
300 void AliEveTRDChamber::LoadHits(TClonesArray *hits, Int_t &idx)
301 {
302   //
303   // Draw hits
304   //
305
306   if(!fHits){ 
307     AddElement(fHits = new AliEveTRDHits());
308     fHits->SetTitle(Form("Hits for Det %d", GetID()));
309   }
310   fLoadHits = kTRUE;
311   Int_t nhits = hits->GetEntriesFast();
312
313   AliTRDhit *hit = 0x0;
314   while(idx<nhits){
315     hit = (AliTRDhit*)hits->UncheckedAt(idx);
316     if(hit->GetDetector() != fDet) return;
317
318     Int_t id = fHits->SetNextPoint(hit->X(), hit->Y(), hit->Z());
319     fHits->SetPointId(id, new AliTRDhit(*hit));
320     fHits->StampObjProps();
321     idx++;
322   }
323   return;
324 }
325
326 //______________________________________________________________________________
327 void AliEveTRDChamber::LoadTracklets(TObjArray *tracks)
328 {
329   //
330   // Draw tracks
331   //
332   if(!fGeo){
333     Error("LoadTracklets()", Form("Geometry not set for chamber %d. Please call first AliEveTRDChamber::SetGeometry().", fDet));
334     return;
335   }
336
337   if(!fTracklets){
338     fTracklets = new std::vector<TEveTrack*>;
339   } else fTracklets->clear();
340
341
342   AliTRDmcmTracklet *trk = 0x0;
343   Double_t cloc[3], cglo[3];
344   for(int itrk=0; itrk<tracks->GetEntries();itrk++){
345     trk = (AliTRDmcmTracklet*)tracks->At(itrk);
346     trk->MakeTrackletGraph(fGeo,.5);
347     fTracklets->push_back(new TEveTrack());
348     fTracklets->back()->SetLineColor(4);
349
350     cloc[0] = trk->GetTime0(); // x0
351     cloc[1] = trk->GetOffset(); // y0
352     cloc[2] = trk->GetRowz(); // z
353     fGeo->RotateBack(fDet,cloc,cglo);
354     fTracklets->back()->SetNextPoint(cglo[0], cglo[1], cglo[2]);
355
356     cloc[0] += 3.7; // x1
357     cloc[1] += TMath::Tan(trk->GetSlope()*TMath::Pi()/180.) * 3.7; // y1
358     fGeo->RotateBack(fDet,cloc,cglo);
359     fTracklets->back()->SetNextPoint(cglo[0], cglo[1], cglo[2]);
360   }
361   fLoadTracklets = kTRUE;
362 }
363
364 //____________________________________________________
365 void AliEveTRDChamber::Paint(Option_t* option)
366 {
367   // Paint object.
368
369   if(!fRnrSelf) return;
370   if(fDigits && fRnrDigits){
371     if(fDigitsNeedRecompute){
372       fDigits->ComputeRepresentation();
373       fDigitsNeedRecompute = kFALSE;
374     }
375     fDigits->Paint(option);
376   }
377
378   if(fRecPoints && fRnrRecPoints) fRecPoints->GetObject()->Paint(option);
379
380   if(fHits && fRnrHits) fHits->GetObject()->Paint(option);
381
382   if(fTracklets && fRnrTracklets){
383     for(std::vector<TEveTrack*>::iterator i=fTracklets->begin(); i != fTracklets->end(); ++i) (*i)->Paint(option);
384   }
385 }
386
387 //______________________________________________________________________________
388 void AliEveTRDChamber::Reset()
389 {
390   // Reset.
391
392   if(fHits){
393     fHits->Reset();
394     fLoadHits = kFALSE;
395   }
396   if(fDigits){
397     fDigits->Reset();
398     fLoadDigits = kFALSE;
399     fDigitsNeedRecompute = kTRUE;
400   }
401   if(fRecPoints){
402     fRecPoints->Reset();
403     fLoadRecPoints = kFALSE;
404   }
405   if(fTracklets){
406     fTracklets->clear();
407     fLoadTracklets = kFALSE;
408   }
409 }
410
411 //______________________________________________________________________________
412 void AliEveTRDChamber::SetGeometry(AliTRDgeometry *geo)
413 {
414   // Set geometry.
415
416   fGeo = geo;
417
418   Int_t  ism  = geo->GetSector(fDet);
419   Int_t  istk = geo->GetStack(fDet);
420   Int_t  ilyr = geo->GetLayer(fDet);
421   Int_t  icha = istk*6+ilyr;
422
423   // define pad plane size in pads
424   AliTRDpadPlane *pp = fGeo->GetPadPlane(ilyr, istk);
425   fNrows   = pp->GetNrows();
426   fNcols   = pp->GetNcols();
427
428 // this version for setting the rendarable object is not working very nice
429 // Int_t shape_offset = TEveGeoShape::Class()->GetDataMemberOffset("fShape");
430 // TEveGeoShape* eg_shape = new TEveGeoShape("geometry");
431 // eg_shape->RefMainTrans().SetFrom(* gGeoManager->GetCurrentMatrix());
432 // * (TGeoShape**) (((char*)eg_shape) + shape_offset) = gGeoManager->GetCurrentVolume()->GetShape();
433 // 
434 // eg_shape->StampColorSelection();
435
436   // define rendarable volumes
437   gGeoManager->cd(Form("/B077_1/BSEGMO%d_1/BTRD%d_1/UTR1_1/UTS1_1/UTI1_1/UT%02d_1", ism, ism, icha));
438   fShape = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
439   fShape->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
440   fShape->DisableListElements();
441   fShape->SetRnrSelf(kFALSE);
442 // try to set the properties but it is crashing !!
443 //   TEveGeoNode *node = 0x0; 
444 //   if((node = (TEveGeoNode*)fShape->FindChild(Form("UA%02d_1", icha)))) node->SetRnrState(kTRUE);
445 //   else AliWarning(Form("Can not retrieve geo node UA%02d_1", icha));
446
447   AddElement(fShape);
448 }
449