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