2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
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 **************************************************************************/
11 #include "TLinearFitter.h"
13 #include "TEveTrans.h"
14 #include "TEveManager.h"
16 #include "EveBase/AliEveEventManager.h"
18 #include "AliEveTRDData.h"
19 #include "AliEveTRDModuleImp.h"
20 #include "AliEveTRDLoader.h"
21 #include "AliEveTRDLoaderImp.h"
25 #include "AliTrackPointArray.h"
26 #include "AliRieman.h"
28 #include "AliTRDhit.h"
29 #include "AliTRDcluster.h"
30 #include "AliTRDseedV1.h"
31 #include "AliTRDtrackV1.h"
32 #include "AliTRDtrackerV1.h"
33 #include "AliTRDpadPlane.h"
34 #include "AliTRDdigitsManager.h"
35 #include "AliTRDdataArrayDigits.h"
36 #include "AliTRDarrayADC.h"
37 #include "AliTRDSignalIndex.h"
38 #include "AliTRDgeometry.h"
39 #include "AliTRDtransform.h"
40 #include "AliTRDReconstructor.h"
41 #include "AliTRDrecoParam.h"
43 ClassImp(AliEveTRDHits)
44 ClassImp(AliEveTRDDigits)
45 ClassImp(AliEveTRDClusters)
46 ClassImp(AliEveTRDTracklet)
47 ClassImp(AliEveTRDTrack)
49 ///////////////////////////////////////////////////////////
50 ///////////// AliEveTRDDigits /////////////////////
51 ///////////////////////////////////////////////////////////
53 //______________________________________________________________________________
54 AliEveTRDDigits::AliEveTRDDigits(AliEveTRDChamber *p) :
55 TEveQuadSet("digits", ""), fParent(p), fBoxes(), fData()
60 //______________________________________________________________________________
61 AliEveTRDDigits::~AliEveTRDDigits()
63 // AliInfo(GetTitle());
66 //______________________________________________________________________________
67 void AliEveTRDDigits::ComputeRepresentation()
69 // Calculate digits representation according to user settings. The
70 // user can set the following parameters:
71 // - digits scale (log/lin)
73 // - digits apparence (quads/boxes)
79 TEveQuadSet::Reset(TEveQuadSet::kQT_RectangleYZ, kTRUE, 64);
81 Double_t scale, dy, dz;
83 Int_t nrows = fData.GetNrow(),
84 ncols = fData.GetNcol(),
85 ntbs = fData.GetNtime(),
86 det = fParent->GetID();
87 Float_t threshold = fParent->GetDigitsThreshold();
89 AliTRDtransform transform(det);
90 AliTRDgeometry *geo = fParent->fGeo;
91 AliTRDpadPlane *pp = geo->GetPadPlane(geo->GetLayer(det), geo->GetStack(det));
93 // express position in tracking coordinates
95 for (Int_t ir = 0; ir < nrows; ir++) {
96 dz = pp->GetRowSize(ir);
97 for (Int_t ic = 0; ic < ncols; ic++) {
98 dy = pp->GetColSize(ic);
99 for (Int_t it = 0; it < ntbs; it++) {
100 q = fData.GetDataUnchecked(ir, ic, it);
101 if (q < threshold) continue;
103 Double_t x[6] = {0., 0., Double_t(q), 0., 0., 0.};
104 Int_t roc[3] = {ir, ic, 0};
106 transform.Transform(&x[0], &roc[0], UInt_t(it), out, 0);
108 scale = q < 512 ? q/512. : 1.;
109 color = 50+int(scale*50.);
111 AddQuad(x[1]-.45*dy, x[2]-.5*dz*scale, x[0], .9*dy, dz*scale);
114 QuadId(new TNamed(Form("Charge%d", q), "dummy title"));
120 // rotate to global coordinates
122 TEveTrans& t = RefMainTrans();
123 t.SetRotByAngles((geo->GetSector(det)+.5)*AliTRDgeometry::GetAlpha(), 0.,0.);
126 //______________________________________________________________________________
127 void AliEveTRDDigits::SetData(AliTRDdigitsManager *digits)
131 Int_t det = fParent->GetID();
132 AliTRDarrayADC *data = digits->GetDigits(det);
133 if(!data->GetDim()) return;
136 AliTRDSignalIndex *indexes = digits->GetIndexes(det);
137 if(!indexes->IsAllocated()) digits->BuildIndexes(det);
139 if(!fData.HasData()) fData.Allocate(data->GetNrow(), data->GetNcol(), data->GetNtime());
142 Int_t row, col, time, adc;
143 indexes->ResetCounters();
144 while (indexes->NextRCIndex(row, col)){
145 indexes->ResetTbinCounter();
146 while (indexes->NextTbinIndex(time)){
147 if(data->IsPadCorrupted(row, col, time)){
148 // we should mark this position
151 adc = data->GetData(row, col, time);
152 if(adc <= 1) continue;
153 fData.SetDataUnchecked(row, col, time, adc);
154 //fIndex->AddIndexTBin(row,col,time);
155 //printf("\tr[%d] c[%d] t[%d] ADC[%d]\n", row, col, time, adc);
162 //______________________________________________________________________________
163 void AliEveTRDDigits::Paint(Option_t *option)
167 if(fParent->GetDigitsBox()) fBoxes.Paint(option);
168 else TEveQuadSet::Paint(option);
171 //______________________________________________________________________________
172 void AliEveTRDDigits::Reset()
174 // Reset raw and visual data.
176 TEveQuadSet::Reset(TEveQuadSet::kQT_RectangleYZ, kTRUE, 64);
177 // MT fBoxes.fBoxes.clear();
181 ///////////////////////////////////////////////////////////
182 ///////////// AliEveTRDHits /////////////////////
183 ///////////////////////////////////////////////////////////
185 //______________________________________________________________________________
186 AliEveTRDHits::AliEveTRDHits() : TEvePointSet("hits", 20)
190 SetMarkerColor(kGreen);
194 //______________________________________________________________________________
195 AliEveTRDHits::~AliEveTRDHits()
197 //AliInfo(GetTitle());
200 //______________________________________________________________________________
201 void AliEveTRDHits::PointSelected(Int_t n)
203 // Handle an individual point selection from GL.
206 if(!(h = dynamic_cast<AliTRDhit*>(GetPointId(n)))) return;
207 printf("Id[%3d] Det[%3d] Reg[%c] TR[%c] Q[%3d] MC[%d] t[%f]\n",
209 h->FromAmplification() ? 'A' : 'D',
210 h->FromTRphoton() ? 'y' : 'n',
211 h->GetCharge(), h->GetTrack(), h->GetTime());
215 ///////////////////////////////////////////////////////////
216 ///////////// AliEveTRDClusters /////////////////////
217 ///////////////////////////////////////////////////////////
219 //______________________________________________________________________________
220 AliEveTRDClusters::AliEveTRDClusters():AliEveTRDHits()
227 SetMarkerColor(kGray);
231 //______________________________________________________________________________
232 void AliEveTRDClusters::PointSelected(Int_t n)
234 // Handle an individual point selection from GL.
236 AliTRDcluster *c = dynamic_cast<AliTRDcluster*>(GetPointId(n));
237 printf("\nDetector : %d\n", c->GetDetector());
238 printf("Charge : %f\n", c->GetQ());
239 printf("Sum S : %4.0f\n", c->GetSumS());
240 printf("Time bin : %d\n", c->GetLocalTimeBin());
241 printf("Signals : ");
242 Short_t *cSignals = c->GetSignals();
243 for(Int_t ipad=0; ipad<7; ipad++) printf("%d ", cSignals[ipad]); printf("\n");
244 printf("Central pad : %d\n", c->GetPadCol());
245 printf("MC track labels : ");
246 for(Int_t itrk=0; itrk<3; itrk++) printf("%d ", c->GetLabel(itrk)); printf("\n");
247 // Bool_t AliCluster::GetGlobalCov(Float_t* cov) const
248 // Bool_t AliCluster::GetGlobalXYZ(Float_t* xyz) const
249 // Float_t AliCluster::GetSigmaY2() const
250 // Float_t AliCluster::GetSigmaYZ() const
251 // Float_t AliCluster::GetSigmaZ2() const
254 //______________________________________________________________________________
255 void AliEveTRDClusters::Print(Option_t *o) const
257 AliTRDcluster *c = 0x0;
259 for(Int_t n = GetN(); n--;){
260 if(!(c = dynamic_cast<AliTRDcluster*>(GetPointId(n)))) continue;
265 //______________________________________________________________________________
266 void AliEveTRDClusters::Load(Char_t *w, Bool_t stk) const
269 if(strcmp(w, "hit")==0) typ = 0;
270 else if(strcmp(w, "dig")==0) typ = 1;
271 else if(strcmp(w, "cls")==0) typ = 2;
272 else if(strcmp(w, "all")==0) typ = 3;
274 AliInfo("The following arguments are accepted:");
275 AliInfo(" \"hit\" : loading of MC hits");
276 AliInfo(" \"dig\" : loading of digits");
277 AliInfo(" \"cls\" : loading of reconstructed clusters");
278 AliInfo(" \"all\" : loading of MC hits+digits+clusters");
282 AliTRDcluster *c = 0x0;
284 while((n = GetN() && !(c = dynamic_cast<AliTRDcluster*>(GetPointId(n))))) n++;
287 Int_t det = c->GetDetector();
288 AliEveTRDLoader *loader = 0x0;
291 loader = new AliEveTRDLoader("Hits");
292 if(!loader->Open("TRD.Hits.root")){
296 loader->SetDataType(AliEveTRDLoader::kTRDHits);
299 loader = new AliEveTRDLoader("Digits");
300 if(!loader->Open("TRD.Digits.root")){
304 loader->SetDataType(AliEveTRDLoader::kTRDDigits);
307 loader = new AliEveTRDLoader("Clusters");
308 if(!loader->Open("TRD.RecPoints.root")){
312 loader->SetDataType(AliEveTRDLoader::kTRDClusters);
315 loader = new AliEveTRDLoaderSim("MC");
316 if(!loader->Open("galice.root")){
320 loader->SetDataType(AliEveTRDLoader::kTRDHits | AliEveTRDLoader::kTRDDigits | AliEveTRDLoader::kTRDClusters);
325 loader->AddChambers(AliTRDgeometry::GetSector(det),AliTRDgeometry::GetStack(det), stk ? -1 : AliTRDgeometry::GetLayer(det));
327 loader->GoToEvent(AliEveEventManager::GetCurrent()->GetEventId());
329 // register loader with alieve
330 gEve->AddElement(loader);
331 //loader->SpawnEditor();
335 ///////////////////////////////////////////////////////////
336 ///////////// AliEveTRDTracklet /////////////////////
337 ///////////////////////////////////////////////////////////
339 //______________________________________________________________________________
340 AliEveTRDTracklet::AliEveTRDTracklet(AliTRDseedV1 *trklt):TEveLine()
348 Float_t x0 = trklt->GetX0();
349 Float_t y0 = trklt->GetYref(0);
350 Float_t z0 = trklt->GetZref(0);
351 Float_t dydx = trklt->GetYref(1);
352 Float_t dzdx = trklt->GetZref(1);
353 Float_t tilt = trklt->GetTilt();
355 AliTRDcluster *c = 0x0;
356 for(Int_t ic=0; ic<AliTRDseed::knTimebins; ic++){
357 if(!(c = trklt->GetClusters(ic))) continue;
358 if(!fClusters) AddElement(fClusters = new AliEveTRDClusters());
360 //Float_t yt = y0 - dx*dydx;
361 Float_t zt = z0 - dx*dzdx;
362 // backup yc - for testing purposes
363 Float_t yc = c->GetY();
364 c->SetY(yc-tilt*(c->GetZ()-zt));
366 Int_t id = fClusters->SetNextPoint(g[0], g[1], g[2]);
367 //Int_t id = fClusters->SetNextPoint(c->GetX(), c->GetY(), c->GetZ());
369 fClusters->SetPointId(id, new AliTRDcluster(*c));
372 fClusters->SetTitle(Form("N[%d]", trklt->GetN2()));
373 fClusters->SetMarkerColor(kMagenta);
376 SetTitle(Form("Det[%d] Plane[%d] P[%7.3f]", trklt->GetDetector(), trklt->GetPlane(), trklt->GetMomentum()));
380 // init tracklet line
381 Int_t sec = AliTRDgeometry::GetSector(trklt->GetDetector());
382 Double_t alpha = AliTRDgeometry::GetAlpha() * (sec<9 ? sec + .5 : sec - 17.5);
385 y0 = trklt->GetYfit(0);
386 dydx = trklt->GetYfit(1);
387 Double_t xg = x0 * TMath::Cos(alpha) - y0 * TMath::Sin(alpha);
388 Double_t yg = x0 * TMath::Sin(alpha) + y0 * TMath::Cos(alpha);
389 SetPoint(0, xg, yg, z0);
390 //SetPoint(0, x0, y0, z0);
393 dx = .5*AliTRDgeometry::CamHght()+AliTRDgeometry::CdrHght();
397 xg = x0 * TMath::Cos(alpha) - y0 * TMath::Sin(alpha);
398 yg = x0 * TMath::Sin(alpha) + y0 * TMath::Cos(alpha);
399 SetPoint(1, xg, yg, z0);
400 //SetPoint(1, x0, y0, z0);
403 //______________________________________________________________________________
404 void AliEveTRDTracklet::Print(Option_t *o) const
406 AliTRDseedV1 *tracklet = (AliTRDseedV1*)GetUserData();
407 if(!tracklet) return;
411 ///////////////////////////////////////////////////////////
412 ///////////// AliEveTRDTrack /////////////////////
413 ///////////////////////////////////////////////////////////
415 //______________________________________________________________________________
416 AliEveTRDTrack::AliEveTRDTrack(AliTRDtrackV1 *trk)
428 AliTRDtrackerV1::SetNTimeBins(24);
431 fRim = new AliRieman(trk->GetNumberOfClusters());
432 AliTRDseedV1 *tracklet = 0x0;
433 for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
434 if(!(tracklet = trk->GetTracklet(il))) continue;
435 if(!tracklet->IsOK()) continue;
436 AddElement(new AliEveTRDTracklet(tracklet));
438 AliTRDcluster *c = 0x0;
439 tracklet->ResetClusterIter(kFALSE);
440 while((c = tracklet->PrevCluster())){
441 Float_t xc = c->GetX();
442 Float_t yc = c->GetY();
443 Float_t zc = c->GetZ();
444 Float_t zt = tracklet->GetZref(0) - (tracklet->GetX0()-xc)*tracklet->GetZref(1);
445 yc -= tracklet->GetTilt()*(zc-zt);
446 fRim->AddPoint(xc, yc, zc, 1, 10);
450 SetStatus(fTrackState);
453 //______________________________________________________________________________
454 AliEveTRDTrack::~AliEveTRDTrack()
456 if(fPoints) delete [] fPoints; fPoints = 0x0;
457 //delete dynamic_cast<AliTRDtrackV1*>(GetUserData());
460 //______________________________________________________________________________
461 void AliEveTRDTrack::Print(Option_t *o) const
463 AliTRDtrackV1 *track = (AliTRDtrackV1*)GetUserData();
468 //______________________________________________________________________________
469 void AliEveTRDTrack::SetStatus(UChar_t s)
471 // nothing to be done
472 if(fPoints && fTrackState == s) return;
474 const Int_t nc = AliTRDtrackV1::kMAXCLUSTERSPERTRACK;
475 AliTRDtrackV1 *trk = (AliTRDtrackV1*)GetUserData();
477 Bool_t BUILD = kFALSE;
479 fPoints = new AliTrackPoint[nc];
481 AliTRDcluster *c = trk->GetCluster(0);
482 Double_t x = c->GetX();
483 Int_t sec = c->GetDetector()/30;
484 fAlpha = AliTRDgeometry::GetAlpha() * (sec<9 ? sec + .5 : sec - 17.5);
486 Double_t dx = (trk->GetCluster(trk->GetNumberOfClusters()-1)->GetX()-x)/nc;
487 for(Int_t ip=0; ip<nc; ip++){
488 fPoints[ip].SetXYZ(x, 0., 0.);
494 // select track model
495 if(BUILD || ((s&12) != (fTrackState&12))){
496 if(TESTBIT(s, kTrackCosmics)){
497 //printf("Straight track\n");
498 AliTRDtrackerV1::FitLine(trk, 0x0, kFALSE, nc, fPoints);
500 if(TESTBIT(s, kTrackModel)){
501 //printf("Kalman track\n");
502 if(trk->GetNumberOfTracklets() >=4) AliTRDtrackerV1::FitKalman(trk, 0x0, kFALSE, nc, fPoints);
504 //printf("Rieman track\n");
505 // if(trk->GetNumberOfTracklets() >=4) AliTRDtrackerV1::FitRiemanTilt(trk, 0x0, kTRUE, nc, fPoints);
507 for(Int_t ip = nc; ip--;){
508 x = fPoints[ip].GetX();
509 fPoints[ip].SetXYZ(x, fRim->GetYat(x), fRim->GetZat(x));
515 for(Int_t ip=0; ip<nc; ip++){
516 fPoints[ip].Rotate(-fAlpha).GetXYZ(global);
517 SetPoint(ip, global[0], global[1], global[2]);
523 if(BUILD || ((s&3) != (fTrackState&3))){
524 if(TESTBIT(s, kSource)){
525 //printf("Source color\n");
526 if(fESDStatus&AliESDtrack::kTRDin){
527 SetMarkerColor(kGreen);
528 SetLineColor(kGreen);
530 SetMarkerColor(kMagenta);
531 SetLineColor(kMagenta);
534 if(TESTBIT(s, kPID) == AliTRDReconstructor::kLQPID){
535 //printf("PID color kLQPID\n");
536 //trk->GetReconstructor()->SetOption("!nn");
538 //printf("PID color kNNPID\n");
539 //trk->GetReconstructor()->SetOption("nn");
543 Int_t species = 0; Float_t pid = 0.;
544 for(Int_t is=0; is<AliPID::kSPECIES; is++)
545 if(trk->GetPID(is) > pid){
546 pid = trk->GetPID(is);
550 case AliPID::kElectron:
551 SetMarkerColor(kRed);
555 SetMarkerColor(kBlue);
563 const Char_t *model = "line";
564 if(!TESTBIT(s, kTrackCosmics)){
565 if(TESTBIT(s, kTrackModel)) model = "kalman";
566 else model = "rieman";
568 Int_t species = 0; Float_t pid = 0.;
569 for(Int_t is=0; is<AliPID::kSPECIES; is++)
570 if(trk->GetPID(is) > pid){
571 pid = trk->GetPID(is);
576 "Tracklets[%d] Clusters[%d]\n"
577 "Reconstruction Source[%s]\n"
578 "PID[%4.1f %4.1f %4.1f %4.1f %4.1f]\n"
579 "MC[%d]", trk->GetNumberOfTracklets(), trk->GetNumberOfClusters(), fESDStatus&AliESDtrack::kTRDin ? "barrel" : "sa",
580 1.E2*trk->GetPID(0), 1.E2*trk->GetPID(1),
581 1.E2*trk->GetPID(2), 1.E2*trk->GetPID(3), 1.E2*trk->GetPID(4), trk->GetLabel()));
584 char id[6]; strncpy(id, GetName(), 6);
585 SetName(Form("%s %s", id, AliPID::ParticleName(species)));