fix coverity
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDData.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
a879a24a 10#include "TROOT.h"
5998b164 11#include "TStyle.h"
a4197d2e 12#include "TVector.h"
13#include "TLinearFitter.h"
a879a24a 14#include "TCanvas.h"
a1d14acd 15#include "TGeoMatrix.h"
5998b164 16#include "TGeoManager.h"
b3d20a1c 17
6983e87a 18#include "TEveTrans.h"
b3d20a1c 19#include "TEveManager.h"
20
21#include "EveBase/AliEveEventManager.h"
6983e87a 22
d810d0de 23#include "AliEveTRDData.h"
24#include "AliEveTRDModuleImp.h"
b3d20a1c 25#include "AliEveTRDLoader.h"
26#include "AliEveTRDLoaderImp.h"
a282bf09 27
c742ee6b 28#include "AliGeomManager.h"
1fbca246 29#include "AliESDtrack.h"
6983e87a 30#include "AliLog.h"
a4197d2e 31#include "AliPID.h"
32#include "AliTrackPointArray.h"
57ce0047 33#include "AliRieman.h"
6983e87a 34
edf0c4a0 35#include "AliTRDhit.h"
36#include "AliTRDcluster.h"
6983e87a 37#include "AliTRDseedV1.h"
98b9b8b2 38#include "AliTRDtrackletMCM.h"
a879a24a 39#include "AliTRDtrackletWord.h"
98b9b8b2 40#include "AliTRDmcmSim.h"
6983e87a 41#include "AliTRDtrackV1.h"
a4197d2e 42#include "AliTRDtrackerV1.h"
a282bf09 43#include "AliTRDpadPlane.h"
a4197d2e 44#include "AliTRDdigitsManager.h"
a879a24a 45#include "AliTRDmcmSim.h"
20301585 46#include "AliTRDarrayADC.h"
0d9ef37b 47#include "AliTRDSignalIndex.h"
a282bf09 48#include "AliTRDgeometry.h"
6983e87a 49#include "AliTRDtransform.h"
a4197d2e 50#include "AliTRDReconstructor.h"
51#include "AliTRDrecoParam.h"
a282bf09 52
d810d0de 53ClassImp(AliEveTRDHits)
54ClassImp(AliEveTRDDigits)
55ClassImp(AliEveTRDClusters)
6983e87a 56ClassImp(AliEveTRDTracklet)
57ClassImp(AliEveTRDTrack)
a879a24a 58ClassImp(AliEveTRDTrackletOnline)
59ClassImp(AliEveTRDmcm)
a282bf09 60
61///////////////////////////////////////////////////////////
fd31e9de 62///////////// AliEveTRDDigits /////////////////////
a282bf09 63///////////////////////////////////////////////////////////
64
fd31e9de 65//______________________________________________________________________________
5998b164 66AliEveTRDDigits::AliEveTRDDigits(AliEveTRDChamber *p)
67 :TEveQuadSet("digits", "")
68 ,fParent(p)
a15e6d7d 69{
a9063c0d 70 // Constructor.
5998b164 71 SetOwnIds(kTRUE);
72 gStyle->SetPalette(1, 0);
73 SetPalette(new TEveRGBAPalette(0, 512));
527ceac3 74 Reset(TEveQuadSet::kQT_RectangleYZ, kFALSE, 32);
a15e6d7d 75}
a282bf09 76
fd31e9de 77//______________________________________________________________________________
6983e87a 78AliEveTRDDigits::~AliEveTRDDigits()
a282bf09 79{
6983e87a 80// AliInfo(GetTitle());
a282bf09 81}
82
fd31e9de 83//______________________________________________________________________________
6983e87a 84void AliEveTRDDigits::SetData(AliTRDdigitsManager *digits)
85{
86 // Set data source.
87
c742ee6b 88 Int_t det(fParent->GetID());
20301585 89 AliTRDarrayADC *data = digits->GetDigits(det);
90 if(!data->GetDim()) return;
0d9ef37b 91 data->Expand();
92
93 AliTRDSignalIndex *indexes = digits->GetIndexes(det);
94 if(!indexes->IsAllocated()) digits->BuildIndexes(det);
95
5998b164 96 Double_t scale, dy, dz;
527ceac3 97 Int_t ly = AliTRDgeometry::GetLayer(det),
5998b164 98 stk = AliTRDgeometry::GetStack(det),
99 sec = AliTRDgeometry::GetSector(det),
100 vid = AliGeomManager::LayerToVolUID(AliGeomManager::kTRD1 + ly, stk + AliTRDgeometry::Nstack() * sec);
7e2dd929 101 SetNameTitle(Form("digits%03d", det), Form("D-%03d [%02d_%d_%d]", det, sec, stk, ly));
5998b164 102 Short_t sig[7]={0,0,0,10,0,0,0};
103
104 AliTRDtransform transform(det);
105 AliTRDpadPlane *pp(fParent->fGeo->GetPadPlane(ly, stk));
0d9ef37b 106
527ceac3 107 Int_t row, col;
5998b164 108 AliTRDcluster c;
0d9ef37b 109 indexes->ResetCounters();
110 while (indexes->NextRCIndex(row, col)){
5998b164 111 dz = pp->GetRowSize(row);
112 dy = pp->GetColSize(col);
527ceac3 113 Short_t *const adc = data->GetDataAddress(row,col);
114 for (Int_t time(0); time<30; time++){
115 if(data->IsPadCorrupted(row, col, time)) break;
116 if(adc[time] <= 1) continue;
5998b164 117 new (&c) AliTRDcluster(det, col, row, time, sig, vid);
118 transform.Transform(&c);
119
527ceac3 120 scale = adc[time] < 512 ? adc[time]/512. : 1.;
121 AddQuad(c.GetY()-0.5*dy, c.GetZ()-0.5*dz*scale, c.GetX(), dy*0.95, dz*scale);
36f3e126 122 QuadValue(Int_t(adc[time]));
7e2dd929 123 QuadId(new TNamed(Form("ADC %d", adc[time]), Form("det[%3d(%02d_%d_%d)] col[%3d] row[%2d] tb[%2d]", det, sec, stk, ly, col, row, time)));
0d9ef37b 124 }
125 }
5998b164 126
127 // rotate to global coordinates
128 RefitPlex();
129 TEveTrans& t = RefMainTrans();
527ceac3 130 t.SetRotByAngles((sec+.5)*AliTRDgeometry::GetAlpha(), 0.,0.);
6983e87a 131}
132
133
c742ee6b 134// //______________________________________________________________________________
135// void AliEveTRDDigits::Paint(Option_t *option)
136// {
137// // Paint the object.
138//
139// if(fParent->GetDigitsBox()) fBoxes.Paint(option);
140// else TEveQuadSet::Paint(option);
141// }
a282bf09 142
5998b164 143// //______________________________________________________________________________
144// void AliEveTRDDigits::Reset()
145// {
146// // Reset raw and visual data.
147//
148// TEveQuadSet::Reset(TEveQuadSet::kQT_RectangleYZ, kTRUE, 64);
149// // MT fBoxes.fBoxes.clear();
150// fData.Reset();
151// }
a282bf09 152
153///////////////////////////////////////////////////////////
fd31e9de 154///////////// AliEveTRDHits /////////////////////
a282bf09 155///////////////////////////////////////////////////////////
156
fd31e9de 157//______________________________________________________________________________
a4197d2e 158AliEveTRDHits::AliEveTRDHits() : TEvePointSet("hits", 20)
a15e6d7d 159{
160 // Constructor.
a4197d2e 161 SetMarkerSize(.1);
b3d20a1c 162 SetMarkerColor(kGreen);
a4197d2e 163 SetOwnIds(kTRUE);
6983e87a 164}
165
166//______________________________________________________________________________
167AliEveTRDHits::~AliEveTRDHits()
168{
169 //AliInfo(GetTitle());
a15e6d7d 170}
a282bf09 171
fd31e9de 172//______________________________________________________________________________
d810d0de 173void AliEveTRDHits::PointSelected(Int_t n)
edf0c4a0 174{
a15e6d7d 175 // Handle an individual point selection from GL.
176
004e0620 177 AliTRDhit *h = NULL;
a969af30 178 if(!(h = dynamic_cast<AliTRDhit*>(GetPointId(n)))) return;
179 printf("Id[%3d] Det[%3d] Reg[%c] TR[%c] Q[%3d] MC[%d] t[%f]\n",
180 n, h->GetDetector(),
181 h->FromAmplification() ? 'A' : 'D',
182 h->FromTRphoton() ? 'y' : 'n',
183 h->GetCharge(), h->GetTrack(), h->GetTime());
a282bf09 184}
185
edf0c4a0 186
187///////////////////////////////////////////////////////////
6983e87a 188///////////// AliEveTRDClusters /////////////////////
edf0c4a0 189///////////////////////////////////////////////////////////
190
fd31e9de 191//______________________________________________________________________________
a4197d2e 192AliEveTRDClusters::AliEveTRDClusters():AliEveTRDHits()
a15e6d7d 193{
194 // Constructor.
6983e87a 195 SetName("clusters");
a4197d2e 196
5524a724 197 SetMarkerSize(.4);
a4197d2e 198 SetMarkerStyle(24);
5524a724 199 SetMarkerColor(kGray);
a4197d2e 200 SetOwnIds(kTRUE);
a15e6d7d 201}
edf0c4a0 202
fd31e9de 203//______________________________________________________________________________
d810d0de 204void AliEveTRDClusters::PointSelected(Int_t n)
edf0c4a0 205{
a15e6d7d 206 // Handle an individual point selection from GL.
207
fd31e9de 208 AliTRDcluster *c = dynamic_cast<AliTRDcluster*>(GetPointId(n));
ce239ca6 209 if(!c) return;
210 c->Print();
211 Emit("PointSelected(Int_t)", n);
fd31e9de 212 // Bool_t AliCluster::GetGlobalCov(Float_t* cov) const
213 // Bool_t AliCluster::GetGlobalXYZ(Float_t* xyz) const
214 // Float_t AliCluster::GetSigmaY2() const
215 // Float_t AliCluster::GetSigmaYZ() const
216 // Float_t AliCluster::GetSigmaZ2() const
edf0c4a0 217}
218
57d55fae 219//______________________________________________________________________________
220void AliEveTRDClusters::Print(Option_t *o) const
221{
004e0620 222 AliTRDcluster *c = NULL;
57d55fae 223
224 for(Int_t n = GetN(); n--;){
225 if(!(c = dynamic_cast<AliTRDcluster*>(GetPointId(n)))) continue;
226 c->Print(o);
227 }
228}
229
b3d20a1c 230//______________________________________________________________________________
ea41d018 231void AliEveTRDClusters::Load(const Char_t *w) const
b3d20a1c 232{
233 Int_t typ = -1;
234 if(strcmp(w, "hit")==0) typ = 0;
235 else if(strcmp(w, "dig")==0) typ = 1;
236 else if(strcmp(w, "cls")==0) typ = 2;
883dc828 237 else if(strcmp(w, "tlt")==0) typ = 3;
238 else if(strcmp(w, "all")==0) typ = 4;
b3d20a1c 239 else{
240 AliInfo("The following arguments are accepted:");
241 AliInfo(" \"hit\" : loading of MC hits");
242 AliInfo(" \"dig\" : loading of digits");
243 AliInfo(" \"cls\" : loading of reconstructed clusters");
883dc828 244 AliInfo(" \"tlt\" : loading of online tracklets");
245 AliInfo(" \"all\" : loading everything available");
b3d20a1c 246 return;
247 }
248
004e0620 249 AliTRDcluster *c = NULL;
b3d20a1c 250 Int_t n = 0;
251 while((n = GetN() && !(c = dynamic_cast<AliTRDcluster*>(GetPointId(n))))) n++;
252 if(!c) return;
253
254 Int_t det = c->GetDetector();
09487f16 255 AliEveTRDLoader *loader(NULL);
b3d20a1c 256 switch(typ){
883dc828 257 case 4:
09487f16 258 loader = new AliEveTRDLoaderSim("MC");
662326b0 259 if(loader){
260 if(!loader->Open("galice.root")){delete loader; loader=NULL;}
261 else{
262 loader->SetDataType(AliEveTRDLoader::kTRDHits | AliEveTRDLoader::kTRDDigits | AliEveTRDLoader::kTRDClusters);
263 break;
264 }
09487f16 265 }
b3d20a1c 266 case 0:
267 loader = new AliEveTRDLoader("Hits");
662326b0 268 if(loader){
269 if(!loader->Open("TRD.Hits.root")){delete loader; loader=NULL;}
270 else{
271 if(typ!=4) break;
272 }
b3d20a1c 273 }
b3d20a1c 274 case 1:
09487f16 275 if(!loader) loader = new AliEveTRDLoader("Digits");
662326b0 276 if(loader){
277 if(!loader->Open("TRD.Digits.root")){
278 if(typ==1){delete loader; loader=NULL;}
279 } else {
280 if(typ!=4) break;
281 }
b3d20a1c 282 }
b3d20a1c 283 case 2:
09487f16 284 if(!loader) loader = new AliEveTRDLoader("Clusters");
662326b0 285 if(loader){
286 if(!loader->Open("TRD.RecPoints.root")){
287 if(typ ==2){delete loader; loader=NULL;}
288 } else {
289 if(typ!=4) break;
290 }
883dc828 291 }
292 case 3:
293 if(!loader) loader = new AliEveTRDLoader("Tracklets");
662326b0 294 if(loader){
295 if(!loader->Open("TRD.Tracklets.root")){
296 if(typ ==3) {delete loader; loader=NULL;}
297 } else break;
b3d20a1c 298 }
b3d20a1c 299 default: return;
300 }
09487f16 301 if(!loader) return;
b3d20a1c 302
527ceac3 303 loader->AddChambers(AliTRDgeometry::GetSector(det),AliTRDgeometry::GetStack(det), AliTRDgeometry::GetLayer(det));
b3d20a1c 304 // load first event
883dc828 305 if(!loader->GoToEvent(AliEveEventManager::GetCurrent()->GetEventId())) AliWarning(Form("No data loaded for event %d", AliEveEventManager::GetCurrent()->GetEventId()));
b3d20a1c 306 // register loader with alieve
527ceac3 307 gEve->AddElement(loader->GetChamber(det), *(BeginParents()));
b3d20a1c 308 //loader->SpawnEditor();
309 gEve->Redraw3D();
310}
311
edf0c4a0 312///////////////////////////////////////////////////////////
6983e87a 313///////////// AliEveTRDTracklet /////////////////////
edf0c4a0 314///////////////////////////////////////////////////////////
edf0c4a0 315
6983e87a 316//______________________________________________________________________________
a4197d2e 317AliEveTRDTracklet::AliEveTRDTracklet(AliTRDseedV1 *trklt):TEveLine()
004e0620 318 ,fClusters(NULL)
a282bf09 319{
6983e87a 320 // Constructor.
321 SetName("tracklet");
a4197d2e 322
883dc828 323 if(!gGeoManager) AliEveEventManager::AssertGeometry();
a4197d2e 324 SetUserData(trklt);
4f7bd6c9 325 // init tracklet line
326 Int_t sec = AliTRDgeometry::GetSector(trklt->GetDetector());
327 Float_t alpha((0.5+sec)*AliTRDgeometry::GetAlpha()),
328 cphi(TMath::Cos(alpha)),
329 sphi(TMath::Sin(alpha));
a7cc0364 330 Float_t dx;
331 Float_t x0 = trklt->GetX0();
332 Float_t y0 = trklt->GetYref(0);
333 Float_t z0 = trklt->GetZref(0);
334 Float_t dydx = trklt->GetYref(1);
335 Float_t dzdx = trklt->GetZref(1);
5998b164 336 Float_t tilt = trklt->GetTilt();
a4197d2e 337 Float_t g[3];
004e0620 338 AliTRDcluster *c = NULL;
c624c106 339 for(Int_t ic=0; ic<AliTRDseedV1::kNclusters; ic++){
a4197d2e 340 if(!(c = trklt->GetClusters(ic))) continue;
57d55fae 341 if(!fClusters) AddElement(fClusters = new AliEveTRDClusters());
a7cc0364 342 dx = x0 - c->GetX();
343 //Float_t yt = y0 - dx*dydx;
344 Float_t zt = z0 - dx*dzdx;
57ce0047 345 // backup yc - for testing purposes
346 Float_t yc = c->GetY();
347 c->SetY(yc-tilt*(c->GetZ()-zt));
4f7bd6c9 348
349 // Ben: Temporary(?) fix -> Issue with wrongly set flag "fIsMisaligned" of AliCluster
350 // Changes can be undone ofter the issue with the flag has been solved
351 //c->GetGlobalXYZ(g);
352
353 // The following code for the trasformation local-to-global is just adapted from
354 // AliTRDgeometry::RotateBack(...)
355
356 // tracking to global coordinates transformation
357 Float_t loc[3] = { c->GetX(), c->GetY(), c->GetZ() };
358 g[0] = loc[0] * cphi - loc[1] * sphi;
359 g[1] = loc[0] * sphi + loc[1] * cphi;
360 g[2] = loc[2];
361 // Ben: End of fix
527ceac3 362 Int_t id = fClusters->SetNextPoint(g[0], g[1], g[2]);
57ce0047 363 c->SetY(yc);
a4197d2e 364 fClusters->SetPointId(id, new AliTRDcluster(*c));
365 }
a7cc0364 366 if(fClusters){
527ceac3 367 fClusters->SetName("TC clusters");
368 fClusters->SetTitle(Form("N[%d]", trklt->GetN()));
a7cc0364 369 fClusters->SetMarkerColor(kMagenta);
370 }
a4197d2e 371
527ceac3 372 SetTitle(Form("Det[%d] RC[%c] Layer[%d] P[%7.3f]", trklt->GetDetector(), trklt->IsRowCross()?'y':'n', trklt->GetPlane(), trklt->GetMomentum()));
5524a724 373 SetLineColor(kRed);
a4197d2e 374 //SetOwnIds(kTRUE);
375
aecbd636 376 //trklt->Fit(kTRUE);
a7cc0364 377 y0 = trklt->GetYfit(0);
378 dydx = trklt->GetYfit(1);
4f7bd6c9 379 Double_t xg(x0 * cphi - y0 * sphi),
380 yg(x0 * sphi + y0 * cphi);
57ce0047 381 SetPoint(0, xg, yg, z0);
382 //SetPoint(0, x0, y0, z0);
57d55fae 383
384
a7cc0364 385 dx = .5*AliTRDgeometry::CamHght()+AliTRDgeometry::CdrHght();
386 x0 -= dx;
387 y0 -= dydx*dx,
388 z0 -= dzdx*dx;
4f7bd6c9 389 xg = x0 * cphi - y0 * sphi;
390 yg = x0 * sphi + y0 * cphi;
a7cc0364 391 SetPoint(1, xg, yg, z0);
57ce0047 392 //SetPoint(1, x0, y0, z0);
a4197d2e 393}
394
98b9b8b2 395
396AliEveTRDTracklet::~AliEveTRDTracklet()
397{
98b9b8b2 398
98b9b8b2 399}
400
a4197d2e 401//______________________________________________________________________________
57d55fae 402void AliEveTRDTracklet::Print(Option_t *o) const
a4197d2e 403{
404 AliTRDseedV1 *tracklet = (AliTRDseedV1*)GetUserData();
57d55fae 405 if(!tracklet) return;
406 tracklet->Print(o);
a282bf09 407}
408
edf0c4a0 409///////////////////////////////////////////////////////////
6983e87a 410///////////// AliEveTRDTrack /////////////////////
edf0c4a0 411///////////////////////////////////////////////////////////
6983e87a 412
413//______________________________________________________________________________
baee73d3 414AliEveTRDTrack::AliEveTRDTrack(AliTRDtrackV1 *trk)
415 :TEveLine()
416 ,fTrackState(0)
417 ,fESDStatus(0)
418 ,fAlpha(0.)
004e0620 419 ,fPoints(NULL)
420 ,fRim(NULL)
edf0c4a0 421{
a15e6d7d 422 // Constructor.
a4197d2e 423 SetUserData(trk);
57d55fae 424 SetName("");
425
5998b164 426// AliTRDtrackerV1::SetNTimeBins(24);
baee73d3 427
57ce0047 428 fRim = new AliRieman(trk->GetNumberOfClusters());
004e0620 429 AliTRDseedV1 *tracklet = NULL;
7bc3159a 430 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
431 if(!(tracklet = trk->GetTracklet(il))) continue;
a4197d2e 432 if(!tracklet->IsOK()) continue;
baee73d3 433 AddElement(new AliEveTRDTracklet(tracklet));
a4197d2e 434
0495887f 435// tracklet->ResetClusterIter(kFALSE);
436// while((c = tracklet->PrevCluster())){
527ceac3 437// AliTRDcluster *c(NULL);
5998b164 438/* for(Int_t ic=AliTRDseedV1::kNtb; ic--;){
0495887f 439 if(!(c=tracklet->GetClusters(ic))) continue;
57ce0047 440 Float_t xc = c->GetX();
441 Float_t yc = c->GetY();
442 Float_t zc = c->GetZ();
443 Float_t zt = tracklet->GetZref(0) - (tracklet->GetX0()-xc)*tracklet->GetZref(1);
444 yc -= tracklet->GetTilt()*(zc-zt);
0495887f 445 fRim->AddPoint(xc, yc, zc, .05, 2.3);
5998b164 446 }*/
57ce0047 447 }
0495887f 448 if(trk->GetNumberOfTracklets()>1) fRim->Update();
baee73d3 449 SetStatus(fTrackState);
450}
a4197d2e 451
baee73d3 452//______________________________________________________________________________
453AliEveTRDTrack::~AliEveTRDTrack()
454{
004e0620 455 if(fPoints) delete [] fPoints; fPoints = NULL;
baee73d3 456 //delete dynamic_cast<AliTRDtrackV1*>(GetUserData());
a4197d2e 457}
458
14eef4aa 459//______________________________________________________________________________
460void AliEveTRDTrack::Print(Option_t *o) const
461{
462 AliTRDtrackV1 *track = (AliTRDtrackV1*)GetUserData();
463 if(!track) return;
464 track->Print(o);
465}
baee73d3 466
a4197d2e 467//______________________________________________________________________________
baee73d3 468void AliEveTRDTrack::SetStatus(UChar_t s)
a4197d2e 469{
baee73d3 470 // nothing to be done
471 if(fPoints && fTrackState == s) return;
5998b164 472 //return;
baee73d3 473 const Int_t nc = AliTRDtrackV1::kMAXCLUSTERSPERTRACK;
ce239ca6 474 AliTRDtrackV1 *trk(NULL);
475 if(!(trk=static_cast<AliTRDtrackV1*>(GetUserData()))) {
476 AliError("Failed casting data to TRD track.");
477 return;
478 }
baee73d3 479
480 Bool_t BUILD = kFALSE;
481 if(!fPoints){
482 fPoints = new AliTrackPoint[nc];
483
b0042d44 484 // define the radial span of the track in the TRD
485 Double_t xmin = -1., xmax = -1.;
486 Int_t det = 0;
004e0620 487 AliTRDseedV1 *trklt = NULL;
488 for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
b0042d44 489 if(!(trklt = trk->GetTracklet(ily))) continue;
490 if(xmin<0.) xmin = trklt->GetX0() - AliTRDgeometry::CamHght() - AliTRDgeometry::CdrHght();
004e0620 491 if(trklt->GetX0()>xmax) xmax = trklt->GetX0();
b0042d44 492 det = trklt->GetDetector();
493 }
494 Int_t sec = det/AliTRDgeometry::kNdets;
495 fAlpha = AliTRDgeometry::GetAlpha() * (sec<9 ? sec + .5 : sec - 17.5); //trk->GetAlpha()
baee73d3 496
b0042d44 497 Double_t dx =(xmax - xmin)/nc;
baee73d3 498 for(Int_t ip=0; ip<nc; ip++){
b0042d44 499 fPoints[ip].SetXYZ(xmin, 0., 0.);
500 xmin+=dx;
baee73d3 501 }
502 BUILD = kTRUE;
503 }
504
505 // select track model
506 if(BUILD || ((s&12) != (fTrackState&12))){
507 if(TESTBIT(s, kTrackCosmics)){
508 //printf("Straight track\n");
004e0620 509 AliTRDtrackerV1::FitLine(trk, NULL, kFALSE, nc, fPoints);
baee73d3 510 } else {
511 if(TESTBIT(s, kTrackModel)){
512 //printf("Kalman track\n");
004e0620 513 if(trk->GetNumberOfTracklets() >=4) AliTRDtrackerV1::FitKalman(trk, NULL, kFALSE, nc, fPoints);
baee73d3 514 } else {
5998b164 515 //printf("Rieman track rim[%p] nc[%d]\n", (void*)fRim, nc);
516 //if(trk->GetNumberOfTracklets() >=4) AliTRDtrackerV1::FitRiemanTilt(trk, NULL, kTRUE, nc, fPoints);
004e0620 517 Float_t x = 0.;
57ce0047 518 for(Int_t ip = nc; ip--;){
519 x = fPoints[ip].GetX();
5998b164 520 //printf("%2d x[%f] y[%f] z[%f]\n", ip, x, fRim->GetYat(x), fRim->GetZat(x));
57ce0047 521 fPoints[ip].SetXYZ(x, fRim->GetYat(x), fRim->GetZat(x));
004e0620 522 }
baee73d3 523 }
524 }
a4197d2e 525
baee73d3 526 Float_t global[3];
004e0620 527 for(Int_t ip=0; ip<nc; ip++){
baee73d3 528 fPoints[ip].Rotate(-fAlpha).GetXYZ(global);
529 SetPoint(ip, global[0], global[1], global[2]);
5998b164 530 //printf("*** %2d x[%f] y[%f] z[%f]\n", ip, global[0], global[1], global[2]);
531
baee73d3 532 }
533 SetSmooth(kTRUE);
534 }
535
536 // set color
537 if(BUILD || ((s&3) != (fTrackState&3))){
538 if(TESTBIT(s, kSource)){
539 //printf("Source color\n");
540 if(fESDStatus&AliESDtrack::kTRDin){
541 SetMarkerColor(kGreen);
542 SetLineColor(kGreen);
543 } else {
544 SetMarkerColor(kMagenta);
545 SetLineColor(kMagenta);
546 }
547 } else {
9443fb9d 548 if(TESTBIT(s, kPID) == AliTRDpidUtil::kLQ){
baee73d3 549 //printf("PID color kLQPID\n");
550 //trk->GetReconstructor()->SetOption("!nn");
551 } else {
552 //printf("PID color kNNPID\n");
553 //trk->GetReconstructor()->SetOption("nn");
554 }
ce239ca6 555 //trk->CookPID();
baee73d3 556
557 Int_t species = 0; Float_t pid = 0.;
377ec156 558 for(Int_t is=0; is<AliPID::kSPECIES; ++is)
baee73d3 559 if(trk->GetPID(is) > pid){
560 pid = trk->GetPID(is);
377ec156 561 species = (AliPID::EParticleType) is;
baee73d3 562 }
563 switch(species){
564 case AliPID::kElectron:
565 SetMarkerColor(kRed);
566 SetLineColor(kRed);
567 break;
568 default:
569 SetMarkerColor(kBlue);
570 SetLineColor(kBlue);
571 break;
572 }
573 }
574 SetLineWidth(2);
575 }
576
a6e0ebfe 577 const Char_t *model = "line";
baee73d3 578 if(!TESTBIT(s, kTrackCosmics)){
579 if(TESTBIT(s, kTrackModel)) model = "kalman";
580 else model = "rieman";
581 }
582 Int_t species = 0; Float_t pid = 0.;
583 for(Int_t is=0; is<AliPID::kSPECIES; is++)
584 if(trk->GetPID(is) > pid){
585 pid = trk->GetPID(is);
586 species = is;
587 }
edf0c4a0 588
57d55fae 589 SetTitle(Form(
590 "Tracklets[%d] Clusters[%d]\n"
591 "Reconstruction Source[%s]\n"
592 "PID[%4.1f %4.1f %4.1f %4.1f %4.1f]\n"
593 "MC[%d]", trk->GetNumberOfTracklets(), trk->GetNumberOfClusters(), fESDStatus&AliESDtrack::kTRDin ? "barrel" : "sa",
594 1.E2*trk->GetPID(0), 1.E2*trk->GetPID(1),
595 1.E2*trk->GetPID(2), 1.E2*trk->GetPID(3), 1.E2*trk->GetPID(4), trk->GetLabel()));
596
597 if(GetName()){
90ae0503 598 char id[6]; snprintf(id, 6, "%s", GetName());
57d55fae 599 SetName(Form("%s %s", id, AliPID::ParticleName(species)));
600 }
baee73d3 601
602 // save track status
603 fTrackState = s;
604}
a879a24a 605
527ceac3 606//______________________________________________________________________________
ea41d018 607void AliEveTRDTrack::Load(const Char_t *what) const
527ceac3 608{
90ae0503 609// Spread downwards to tracklets the command "what"
610
611 const AliEveTRDTracklet* trklt(NULL);
612 TEveElement::List_ci itrklt=BeginChildren();
527ceac3 613 while(itrklt!=EndChildren()){
90ae0503 614 if((trklt = dynamic_cast<const AliEveTRDTracklet*>(*itrklt))) trklt->Load(what);
527ceac3 615 itrklt++;
616 }
617}
618
90ae0503 619//______________________________________________________________________________
a879a24a 620AliEveTRDTrackletOnline::AliEveTRDTrackletOnline(AliTRDtrackletMCM *tracklet) :
621 TEveLine(),
622 fDetector(-1),
623 fROB(-1),
624 fMCM(-1)
625{
626 AliTRDtrackletMCM *trkl = new AliTRDtrackletMCM(*tracklet);
627 SetUserData(trkl);
628
629 fDetector = trkl->GetDetector();
630 fROB = trkl->GetROB();
631 fMCM = trkl->GetMCM();
632
a1d14acd 633 SetName("sim. tracklet");
a879a24a 634 SetTitle(Form("Det: %i, ROB: %i, MCM: %i, Label: %i\n0x%08x",
635 trkl->GetDetector(), trkl->GetROB(), trkl->GetMCM(), trkl->GetLabel(),
636 trkl->GetTrackletWord()));
a428533a 637 SetLineColor(kGreen);
a1d14acd 638 SetLineWidth(3);
a879a24a 639
a1d14acd 640 AliTRDgeometry geo;
641 TGeoHMatrix *matrix = geo.GetClusterMatrix(trkl->GetDetector());
a879a24a 642
a1d14acd 643 fDetector = trkl->GetDetector();
644 fROB = trkl->GetROB();
645 fMCM = trkl->GetMCM();
646
a879a24a 647 Float_t length = 3.;
648 Double_t x[3];
649 Double_t p[3];
a1d14acd 650 Double_t p2[3];
651 x[0] = AliTRDgeometry::AnodePos();
a879a24a 652 x[1] = trkl->GetY();
a1d14acd 653 x[2] = trkl->GetLocalZ();
a879a24a 654
a1d14acd 655 matrix->LocalToMaster(x, p);
656 geo.RotateBack(trkl->GetDetector(), p, p2);
657 SetPoint(0, p2[0], p2[1], p2[2]);
a879a24a 658
659 x[0] -= length;
a428533a 660 x[1] -= length * trkl->GetdYdX();
a1d14acd 661 matrix->LocalToMaster(x, p);
662 p[2] *= p[0] / (p[0] + length);
663 geo.RotateBack(trkl->GetDetector(), p, p2);
664 SetPoint(1, p2[0], p2[1], p2[2]);
a879a24a 665}
666
667AliEveTRDTrackletOnline::AliEveTRDTrackletOnline(AliTRDtrackletWord *tracklet) :
668 TEveLine(),
669 fDetector(-1),
670 fROB(-1),
671 fMCM(-1)
672{
673 AliTRDtrackletWord *trkl = new AliTRDtrackletWord(*tracklet);
674 SetUserData(trkl);
675
a879a24a 676 fDetector = trkl->GetDetector();
a1d14acd 677 fROB = trkl->GetROB();
678 fMCM = trkl->GetMCM();
a879a24a 679
a1d14acd 680 SetName("raw tracklet");
a879a24a 681 SetTitle(Form("Det: %i, ROB: %i, MCM: %i, Label: %i\n0x%08x",
682 trkl->GetDetector(), fROB, fMCM, -1,
683 trkl->GetTrackletWord()));
684 SetLineColor(kRed);
a1d14acd 685 SetLineWidth(3);
a879a24a 686
a1d14acd 687 AliTRDgeometry geo;
688 TGeoHMatrix *matrix = geo.GetClusterMatrix(trkl->GetDetector());
a879a24a 689
690 Float_t length = 3.;
691 Double_t x[3];
692 Double_t p[3];
a1d14acd 693 Double_t p2[3];
694 x[0] = AliTRDgeometry::AnodePos();
a879a24a 695 x[1] = trkl->GetY();
a1d14acd 696 x[2] = trkl->GetLocalZ();
a879a24a 697
a1d14acd 698 matrix->LocalToMaster(x, p);
699 geo.RotateBack(trkl->GetDetector(), p, p2);
700 SetPoint(0, p2[0], p2[1], p2[2]);
a879a24a 701
702 x[0] -= length;
a428533a 703 x[1] -= length * trkl->GetdYdX();
a1d14acd 704 matrix->LocalToMaster(x, p);
705 p[2] *= p[0] / (p[0] + length);
706 geo.RotateBack(trkl->GetDetector(), p, p2);
707 SetPoint(1, p2[0], p2[1], p2[2]);
a879a24a 708}
709
710AliEveTRDTrackletOnline::~AliEveTRDTrackletOnline()
711{
a1d14acd 712 delete ((AliTRDtrackletBase*) GetUserData());
713 SetUserData(0x0);
a879a24a 714}
715
716void AliEveTRDTrackletOnline::ShowMCM(Option_t *opt) const
717{
718 if (fDetector < 0 || fROB < 0 || fMCM < 0)
719 return;
720
721 AliEveTRDmcm *evemcm = new AliEveTRDmcm();
722 evemcm->Init(fDetector, fROB, fMCM);
723 evemcm->LoadDigits();
724 evemcm->Draw(opt);
725
004e0620 726 TEveElementList *mcmlist = NULL;
a879a24a 727 if (gEve->GetCurrentEvent())
728 mcmlist = (TEveElementList*) gEve->GetCurrentEvent()->FindChild("TRD MCMs");
729 if (!mcmlist) {
730 mcmlist = new TEveElementList("TRD MCMs");
731 gEve->AddElement(mcmlist);
732 }
733 gEve->AddElement(evemcm, mcmlist);
734}
735
736
737AliEveTRDmcm::AliEveTRDmcm() :
738 TEveElement(),
739 TNamed(),
740 fMCM(new AliTRDmcmSim())
741{
742 SetName("MCM");
743 SetTitle("Unknown MCM");
744}
745
746AliEveTRDmcm::~AliEveTRDmcm()
747{
748 delete fMCM;
749}
750
751Bool_t AliEveTRDmcm::Init(Int_t det, Int_t rob, Int_t mcm)
752{
753 SetName(Form("MCM: Det. %i, ROB %i, MCM %i", det, rob, mcm));
754 SetTitle(Form("MCM: Det. %i, ROB %i, MCM %i", det, rob, mcm));
755 fMCM->Init(det, rob, mcm);
756 fMCM->Reset();
757 return kTRUE;
758}
759
760Bool_t AliEveTRDmcm::LoadDigits()
761{
762 AliRunLoader *rl = AliEveEventManager::AssertRunLoader();
763 return fMCM->LoadMCM(rl, fMCM->GetDetector(),
764 fMCM->GetRobPos(), fMCM->GetMcmPos());
765}
766
767Bool_t AliEveTRDmcm::Filter()
768{
769 fMCM->Filter();
770 return kTRUE;
771}
772
773Bool_t AliEveTRDmcm::Tracklet()
774{
775 fMCM->Tracklet();
776 return kTRUE;
777}
778
779void AliEveTRDmcm::Draw(Option_t* option)
780{
781 const char *mcmname = Form("mcm_%i_%i_%i", fMCM->GetDetector(),
782 fMCM->GetRobPos(), fMCM->GetMcmPos());
783
784 TCanvas *c = dynamic_cast<TCanvas*> (gROOT->FindObject(mcmname));
785 if (!c)
786 c = gEve->AddCanvasTab("TRD MCM");
787 c->SetTitle(Form("MCM %i on ROB %i of det. %i",
788 fMCM->GetMcmPos(), fMCM->GetRobPos(), fMCM->GetDetector()));
789 c->SetName(mcmname);
790 c->cd();
791 fMCM->Draw(option);
792}
793
794Bool_t AliEveTRDmcm::AssignPointer(const char* ptrname)
795{
c51e9ba0 796 gROOT->ProcessLine(Form("AliTRDmcmSim* %s = (AliTRDmcmSim *)%p", ptrname, (void*)fMCM));
a879a24a 797 return kTRUE;
798}