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