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