]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTRDModuleImp.cxx
Modified naming conventions in the geometry
[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   for(int iclus=0; iclus<clusters->GetEntriesFast(); iclus++){
268     c = (AliTRDcluster*)clusters->UncheckedAt(iclus);
269     c->GetGlobalXYZ(g); 
270     q = c->GetQ();
271     Int_t id = fRecPoints->SetNextPoint(g[0], g[1], g[2]);    
272     fRecPoints->SetPointId(id, new AliTRDcluster(*c));
273   }
274   fLoadRecPoints = kTRUE;
275 }
276
277 //______________________________________________________________________________
278 void AliEveTRDChamber::LoadDigits(AliTRDdigitsManager *digits)
279 {
280   //
281   // Draw digits
282   //
283   if(!fGeo){
284     AliError(Form("Geometry not set for chamber %d. Please call first AliEveTRDChamber::SetGeometry().", fDet));
285     return;
286   }
287   // Info("LoadDigits()", Form("digits =0x%x", digits));
288
289   if(!fDigits) AddElement(fDigits = new AliEveTRDDigits(this));
290
291   fDigits->Reset();
292   fDigits->SetData(digits);
293   fLoadDigits = kTRUE;
294 }
295
296 //______________________________________________________________________________
297 void AliEveTRDChamber::LoadHits(TClonesArray *hits, Int_t &idx)
298 {
299   //
300   // Draw hits
301   //
302   //Info("AddHit()", Form("%s", GetName()));
303
304   if(!fHits){ 
305     AddElement(fHits = new AliEveTRDHits());
306     fHits->SetTitle(Form("Hits for Det %d", GetID()));
307   }
308   fLoadHits = kTRUE;
309   Int_t nhits = hits->GetEntriesFast();
310
311   AliTRDhit *hit = 0x0;
312   while(idx<nhits){
313     hit = (AliTRDhit*)hits->UncheckedAt(idx);
314     if(hit->GetDetector() != fDet) return;
315
316     Int_t id = fHits->SetNextPoint(hit->X(), hit->Y(), hit->Z());
317     fHits->SetPointId(id, new AliTRDhit(*hit));
318     idx++;
319   }
320   return;
321 }
322
323 //______________________________________________________________________________
324 void AliEveTRDChamber::LoadTracklets(TObjArray *tracks)
325 {
326   //
327   // Draw tracks
328   //
329   if(!fGeo){
330     Error("LoadTracklets()", Form("Geometry not set for chamber %d. Please call first AliEveTRDChamber::SetGeometry().", fDet));
331     return;
332   }
333   // Info("LoadTracklets()", Form("tracks = 0x%x", tracks));
334
335   if(!fTracklets){
336     fTracklets = new std::vector<TEveTrack*>;
337   } else fTracklets->clear();
338
339
340   AliTRDmcmTracklet *trk = 0x0;
341   Double_t cloc[3], cglo[3];
342   for(int itrk=0; itrk<tracks->GetEntries();itrk++){
343     trk = (AliTRDmcmTracklet*)tracks->At(itrk);
344     trk->MakeTrackletGraph(fGeo,.5);
345     fTracklets->push_back(new TEveTrack());
346     fTracklets->back()->SetLineColor(4);
347
348     cloc[0] = trk->GetTime0(); // x0
349     cloc[1] = trk->GetOffset(); // y0
350     cloc[2] = trk->GetRowz(); // z
351     fGeo->RotateBack(fDet,cloc,cglo);
352     fTracklets->back()->SetNextPoint(cglo[0], cglo[1], cglo[2]);
353
354     cloc[0] += 3.7; // x1
355     cloc[1] += TMath::Tan(trk->GetSlope()*TMath::Pi()/180.) * 3.7; // y1
356     fGeo->RotateBack(fDet,cloc,cglo);
357     fTracklets->back()->SetNextPoint(cglo[0], cglo[1], cglo[2]);
358   }
359   fLoadTracklets = kTRUE;
360 }
361
362 //____________________________________________________
363 void AliEveTRDChamber::Paint(Option_t* option)
364 {
365   // Paint object.
366
367   //AliInfo(GetName());
368   if(!fRnrSelf) return;
369   if(fDigits && fRnrDigits){
370     if(fDigitsNeedRecompute){
371       fDigits->ComputeRepresentation();
372       fDigitsNeedRecompute = kFALSE;
373     }
374     fDigits->Paint(option);
375   }
376
377   if(fRecPoints && fRnrRecPoints) fRecPoints->GetObject()->Paint(option);
378
379   if(fHits && fRnrHits) fHits->GetObject()->Paint(option);
380
381   if(fTracklets && fRnrTracklets){
382     for(std::vector<TEveTrack*>::iterator i=fTracklets->begin(); i != fTracklets->end(); ++i) (*i)->Paint(option);
383   }
384 }
385
386 //______________________________________________________________________________
387 void AliEveTRDChamber::Reset()
388 {
389   // Reset.
390
391   if(fHits){
392     fHits->Reset();
393     fLoadHits = kFALSE;
394   }
395   if(fDigits){
396     fDigits->Reset();
397     fLoadDigits = kFALSE;
398     fDigitsNeedRecompute = kTRUE;
399   }
400   if(fRecPoints){
401     fRecPoints->Reset();
402     fLoadRecPoints = kFALSE;
403   }
404   if(fTracklets){
405     fTracklets->clear();
406     fLoadTracklets = kFALSE;
407   }
408 }
409
410 //______________________________________________________________________________
411 void AliEveTRDChamber::SetGeometry(AliTRDgeometry *geo)
412 {
413   // Set geometry.
414
415   fGeo = geo;
416
417   Int_t  ism  = geo->GetSector(fDet);
418   Int_t  istk = geo->GetStack(fDet);
419   Int_t  ilyr = geo->GetLayer(fDet);
420   Int_t  icha = istk*6+ilyr;
421
422   // define pad plane size in pads
423   AliTRDpadPlane *pp = fGeo->GetPadPlane(ilyr, istk);
424   fNrows   = pp->GetNrows();
425   fNcols   = pp->GetNcols();
426
427 // this version for setting the rendarable object is not working very nice
428 // Int_t shape_offset = TEveGeoShape::Class()->GetDataMemberOffset("fShape");
429 // TEveGeoShape* eg_shape = new TEveGeoShape("geometry");
430 // eg_shape->RefMainTrans().SetFrom(* gGeoManager->GetCurrentMatrix());
431 // * (TGeoShape**) (((char*)eg_shape) + shape_offset) = gGeoManager->GetCurrentVolume()->GetShape();
432 // 
433 // eg_shape->StampColorSelection();
434
435   // define rendarable volumes
436   gGeoManager->cd(Form("/B077_1/BSEGMO%d_1/BTRD%d_1/UTR1_1/UTS1_1/UTI1_1/UT%02d_1", ism, ism, icha));
437   fShape = new TEveGeoTopNode(gGeoManager, gGeoManager->GetCurrentNode());
438   fShape->RefMainTrans().SetFrom(*gGeoManager->GetCurrentMatrix());
439   fShape->DisableListElements();
440   fShape->SetRnrSelf(kFALSE);
441 // try to set the properties but it is crashing !!
442 //   TEveGeoNode *node = 0x0; 
443 //   if((node = (TEveGeoNode*)fShape->FindChild(Form("UA%02d_1", icha)))) node->SetRnrState(kTRUE);
444 //   else AliWarning(Form("Can not retrieve geo node UA%02d_1", icha));
445
446   AddElement(fShape);
447 }
448