]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTRDData.cxx
fix broken compilation in EVE-TRD
[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 "TVector.h"
11 #include "TLinearFitter.h"
12 #include "TEveTrans.h"
13
14 #include "AliEveTRDData.h"
15 #include "AliEveTRDModuleImp.h"
16
17 #include "AliLog.h"
18 #include "AliPID.h"
19 #include "AliTrackPointArray.h"
20
21 #include "AliTRDhit.h"
22 #include "AliTRDcluster.h"
23 #include "AliTRDseedV1.h"
24 #include "AliTRDtrackV1.h"
25 #include "AliTRDtrackerV1.h"
26 #include "AliTRDpadPlane.h"
27 #include "AliTRDdigitsManager.h"
28 #include "AliTRDdataArrayDigits.h"
29 #include "AliTRDSignalIndex.h"
30 #include "AliTRDgeometry.h"
31 #include "AliTRDtransform.h"
32 #include "AliTRDReconstructor.h"
33 #include "AliTRDrecoParam.h"
34
35 ClassImp(AliEveTRDHits)
36 ClassImp(AliEveTRDDigits)
37 ClassImp(AliEveTRDClusters)
38 ClassImp(AliEveTRDTracklet)
39 ClassImp(AliEveTRDTrack)
40
41 ///////////////////////////////////////////////////////////
42 /////////////   AliEveTRDDigits       /////////////////////
43 ///////////////////////////////////////////////////////////
44
45 //______________________________________________________________________________
46 AliEveTRDDigits::AliEveTRDDigits(AliEveTRDChamber *p) :
47   TEveQuadSet("digits", ""), fParent(p), fBoxes(), fData()
48 {
49   // Constructor.
50 }
51
52 //______________________________________________________________________________
53 AliEveTRDDigits::~AliEveTRDDigits()
54 {
55 //  AliInfo(GetTitle());
56 }
57
58 //______________________________________________________________________________
59 void AliEveTRDDigits::ComputeRepresentation()
60 {
61   // Calculate digits representation according to user settings. The
62   // user can set the following parameters:
63   // - digits scale (log/lin)
64   // - digits threshold
65   // - digits apparence (quads/boxes)
66
67   if(!fData.HasData()){
68     return;
69   }
70
71   TEveQuadSet::Reset(TEveQuadSet::kQT_RectangleYZ, kTRUE, 64);
72
73   Double_t scale, dy, dz;
74   Int_t q, color;
75   Int_t nrows = fData.GetNrow(),
76         ncols = fData.GetNcol(),
77         ntbs  = fData.GetNtime(),
78         det   = fParent->GetID();
79   Float_t threshold = fParent->GetDigitsThreshold();
80
81   AliTRDtransform transform(det);
82   AliTRDgeometry *geo = fParent->fGeo;
83   AliTRDpadPlane *pp = geo->GetPadPlane(geo->GetLayer(det), geo->GetStack(det));
84
85   // express position in tracking coordinates
86   fData.Expand();
87   for (Int_t ir = 0; ir < nrows; ir++) {
88     dz = pp->GetRowSize(ir);
89     for (Int_t ic = 0; ic < ncols; ic++) {
90       dy = pp->GetColSize(ic);
91       for (Int_t it = 0; it < ntbs; it++) {
92         q = fData.GetDataUnchecked(ir, ic, it);
93         if (q < threshold) continue;
94
95         Double_t x[6] = {0., 0., Double_t(q), 0., 0., 0.}; 
96         Int_t  roc[3] = {ir, ic, 0}; 
97         Bool_t    out = kTRUE;
98         transform.Transform(&x[0], &roc[0], UInt_t(it), out, 0);
99
100         scale = q < 512 ? q/512. : 1.;
101         color  = 50+int(scale*50.);
102     
103         AddQuad(x[1]-.45*dy, x[2]-.5*dz*scale, x[0], .9*dy, dz*scale);
104         QuadValue(q);
105         QuadColor(color);
106         QuadId(new TNamed(Form("Charge%d", q), "dummy title"));
107       }  // end time loop
108     }  // end col loop
109   }  // end row loop
110   fData.Compress(1);
111   
112   // rotate to global coordinates
113   //RefitPlex();
114   TEveTrans& t = RefMainTrans();
115   t.SetRotByAngles((geo->GetSector(det)+.5)*AliTRDgeometry::GetAlpha(), 0.,0.);
116 }
117
118 //______________________________________________________________________________
119 void AliEveTRDDigits::SetData(AliTRDdigitsManager *digits)
120 {
121   // Set data source.
122
123   Int_t det = fParent->GetID();
124   AliTRDdataArrayDigits *data = digits->GetDigits(det);
125   if(!data->HasData()) return;
126   data->Expand();
127
128   AliTRDSignalIndex *indexes = digits->GetIndexes(det);
129   if(!indexes->IsAllocated()) digits->BuildIndexes(det);
130
131   if(!fData.HasData()) fData.Allocate(data->GetNrow(), data->GetNcol(), data->GetNtime());
132   fData.Expand();
133
134   Int_t row, col, time, adc;
135   indexes->ResetCounters();
136   while (indexes->NextRCIndex(row, col)){
137     indexes->ResetTbinCounter();
138     while (indexes->NextTbinIndex(time)){
139       if(data->IsPadCorrupted(row, col, time)){
140         // we should mark this position
141         break;
142       }
143       adc = data->GetData(row, col, time);
144       if(adc <= 1) continue;
145       fData.SetDataUnchecked(row, col, time, adc);
146       //fIndex->AddIndexTBin(row,col,time);
147       //printf("\tr[%d] c[%d] t[%d] ADC[%d]\n", row, col, time, adc);
148     } 
149   }
150   fData.Compress(1);
151 }
152
153
154 //______________________________________________________________________________
155 void AliEveTRDDigits::Paint(Option_t *option)
156 {
157   // Paint the object.
158
159   if(fParent->GetDigitsBox()) fBoxes.Paint(option);
160   else TEveQuadSet::Paint(option);
161 }
162
163 //______________________________________________________________________________
164 void AliEveTRDDigits::Reset()
165 {
166   // Reset raw and visual data.
167
168   TEveQuadSet::Reset(TEveQuadSet::kQT_RectangleYZ, kTRUE, 64);
169   // MT fBoxes.fBoxes.clear();
170   fData.Reset();
171 }
172
173 ///////////////////////////////////////////////////////////
174 /////////////   AliEveTRDHits         /////////////////////
175 ///////////////////////////////////////////////////////////
176
177 //______________________________________________________________________________
178 AliEveTRDHits::AliEveTRDHits() : TEvePointSet("hits", 20)
179 {
180   // Constructor.
181   SetMarkerSize(.1);
182   SetMarkerColor(2);
183   SetOwnIds(kTRUE);
184 }
185
186 //______________________________________________________________________________
187 AliEveTRDHits::~AliEveTRDHits()
188 {
189   //AliInfo(GetTitle());
190 }
191
192 //______________________________________________________________________________
193 void AliEveTRDHits::PointSelected(Int_t n)
194 {
195   // Handle an individual point selection from GL.
196
197   AliTRDhit *h = dynamic_cast<AliTRDhit*>(GetPointId(n));
198   printf("\nDetector             : %d\n", h->GetDetector());
199   printf("Region of production : %c\n", h->FromAmplification() ? 'A' : 'D');
200   printf("TR photon            : %s\n", h->FromTRphoton() ? "Yes" : "No");
201   printf("Charge               : %d\n", h->GetCharge());
202   printf("MC track label       : %d\n", h->GetTrack());
203   printf("Time from collision  : %f\n", h->GetTime());
204 }
205
206
207 ///////////////////////////////////////////////////////////
208 /////////////   AliEveTRDClusters         /////////////////////
209 ///////////////////////////////////////////////////////////
210
211 //______________________________________________________________________________
212 AliEveTRDClusters::AliEveTRDClusters():AliEveTRDHits()
213 {
214   // Constructor.
215   SetName("clusters");
216
217   SetMarkerSize(.4);
218   SetMarkerStyle(24);
219   SetMarkerColor(kGray);
220   SetOwnIds(kTRUE);
221 }
222
223 //______________________________________________________________________________
224 void AliEveTRDClusters::PointSelected(Int_t n)
225 {
226   // Handle an individual point selection from GL.
227
228   AliTRDcluster *c = dynamic_cast<AliTRDcluster*>(GetPointId(n));
229   printf("\nDetector             : %d\n", c->GetDetector());
230   printf("Charge               : %f\n", c->GetQ());
231   printf("Sum S                : %4.0f\n", c->GetSumS());
232   printf("Time bin             : %d\n", c->GetLocalTimeBin());
233   printf("Signals              : ");
234   Short_t *cSignals = c->GetSignals();
235   for(Int_t ipad=0; ipad<7; ipad++) printf("%d ", cSignals[ipad]); printf("\n");
236   printf("Central pad          : %d\n", c->GetPadCol());
237   printf("MC track labels      : ");
238   for(Int_t itrk=0; itrk<3; itrk++) printf("%d ", c->GetLabel(itrk)); printf("\n");
239   // Bool_t     AliCluster::GetGlobalCov(Float_t* cov) const
240   // Bool_t     AliCluster::GetGlobalXYZ(Float_t* xyz) const
241   // Float_t    AliCluster::GetSigmaY2() const
242   // Float_t    AliCluster::GetSigmaYZ() const
243   // Float_t    AliCluster::GetSigmaZ2() const
244 }
245
246 ///////////////////////////////////////////////////////////
247 /////////////   AliEveTRDTracklet         /////////////////////
248 ///////////////////////////////////////////////////////////
249
250 //______________________________________________________________________________
251 AliEveTRDTracklet::AliEveTRDTracklet(AliTRDseedV1 *trklt):TEveLine()
252   ,fClusters(0x0)
253 {
254   // Constructor.
255   SetName("tracklet");
256   
257   SetUserData(trklt);
258   Int_t det = -1, sec;
259   Float_t g[3];
260   AliTRDcluster *c = 0x0;
261   AddElement(fClusters = new AliEveTRDClusters());
262   for(Int_t ic=0; ic<35; ic++){
263     if(!(c = trklt->GetClusters(ic))) continue;
264     det = c->GetDetector();
265     c->GetGlobalXYZ(g); 
266     Int_t id = fClusters->SetNextPoint(g[0], g[1], g[2]);    
267     fClusters->SetPointId(id, new AliTRDcluster(*c));
268   } 
269
270   SetTitle(Form("Det[%d] Plane[%d] P[%7.3f]", det, trklt->GetPlane(), trklt->GetMomentum()));
271   SetLineColor(kRed);
272   //SetOwnIds(kTRUE);
273   
274   sec = det/30;
275   Double_t alpha = AliTRDgeometry::GetAlpha() * (sec<9 ? sec + .5 : sec - 17.5); 
276   Double_t x0 = trklt->GetX0(), 
277     y0f = trklt->GetYfit(0), 
278     ysf = trklt->GetYfit(1),
279     z0r = trklt->GetZref(0), 
280     zsr = trklt->GetZref(1);
281   Double_t xg =  x0 * TMath::Cos(alpha) - y0f * TMath::Sin(alpha); 
282   Double_t yg = x0 * TMath::Sin(alpha) + y0f * TMath::Cos(alpha);
283   SetPoint(0, xg, yg, z0r);
284   //SetPointId(0, new AliTRDseedV1(*trackletObj));
285   Double_t x1 = x0-3.5, 
286     y1f = y0f - ysf*3.5,
287     z1r = z0r - zsr*3.5; 
288   xg =  x1 * TMath::Cos(alpha) - y1f * TMath::Sin(alpha); 
289   yg = x1 * TMath::Sin(alpha) + y1f * TMath::Cos(alpha);
290   SetPoint(1, xg, yg, z1r);
291 }
292
293 //______________________________________________________________________________
294 void AliEveTRDTracklet::ProcessData()
295 {
296   AliTRDseedV1 *tracklet = (AliTRDseedV1*)GetUserData();
297   tracklet->Print();
298 }
299
300 ///////////////////////////////////////////////////////////
301 /////////////   AliEveTRDTrack         /////////////////////
302 ///////////////////////////////////////////////////////////
303
304 //______________________________________________________________________________
305 AliEveTRDTrack::AliEveTRDTrack(AliTRDtrackV1 *trk) 
306   :TEveLine()
307   ,fTrackState(0)
308   ,fESDStatus(0)
309   ,fAlpha(0.)
310   ,fPoints(0x0)
311 {
312   // Constructor.
313   SetName("track");
314
315   SetUserData(trk);
316   
317   AliTRDtrackerV1::SetNTimeBins(24);
318
319   AliTRDseedV1 *tracklet = 0x0;
320   for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
321     if(!(tracklet = trk->GetTracklet(il))) continue;
322     if(!tracklet->IsOK()) continue;
323     AddElement(new AliEveTRDTracklet(tracklet));
324   }
325
326   SetStatus(fTrackState);
327 }
328
329 //______________________________________________________________________________
330 AliEveTRDTrack::~AliEveTRDTrack()
331 {
332   if(fPoints) delete [] fPoints; fPoints = 0x0;
333   //delete dynamic_cast<AliTRDtrackV1*>(GetUserData());
334 }
335
336
337 //______________________________________________________________________________
338 void AliEveTRDTrack::SetStatus(UChar_t s)
339 {
340   // nothing to be done
341   if(fPoints && fTrackState == s) return;
342
343   const Int_t nc = AliTRDtrackV1::kMAXCLUSTERSPERTRACK;
344   AliTRDtrackV1 *trk = (AliTRDtrackV1*)GetUserData();
345
346   Bool_t BUILD = kFALSE;
347   if(!fPoints){ 
348     fPoints = new AliTrackPoint[nc];
349
350     AliTRDcluster *c = trk->GetCluster(0);
351     Double_t x = c->GetX();
352     Int_t sec = c->GetDetector()/30;
353     fAlpha = AliTRDgeometry::GetAlpha() * (sec<9 ? sec + .5 : sec - 17.5); 
354
355     Double_t dx = (trk->GetCluster(trk->GetNumberOfClusters()-1)->GetX()-x)/nc;
356     for(Int_t ip=0; ip<nc; ip++){
357       fPoints[ip].SetXYZ(x, 0., 0.);
358       x+=dx;
359     }
360     BUILD = kTRUE;
361   }
362
363   // select track model
364   if(BUILD || ((s&12) != (fTrackState&12))){
365     if(TESTBIT(s, kTrackCosmics)){
366       //printf("Straight track\n");
367       AliTRDtrackerV1::FitLine(trk, 0x0, kFALSE, nc, fPoints);
368     } else {
369       if(TESTBIT(s, kTrackModel)){
370         //printf("Kalman track\n");
371         //AliTRDtrackerV1::FitKalman(trk, 0x0, kFALSE, nc, fPoints);
372       } else { 
373         //printf("Rieman track\n");
374         if(trk->GetNumberOfTracklets() >=4) AliTRDtrackerV1::FitRiemanTilt(trk, 0x0, kTRUE, nc, fPoints);
375       }
376     }
377   
378     Float_t global[3];
379     for(Int_t ip=0; ip<nc; ip++){
380       fPoints[ip].Rotate(-fAlpha).GetXYZ(global);
381       SetPoint(ip, global[0], global[1], global[2]);
382     }
383     SetSmooth(kTRUE);
384   }
385
386   // set color
387   if(BUILD || ((s&3) != (fTrackState&3))){
388     if(TESTBIT(s, kSource)){
389       //printf("Source color\n");
390       if(fESDStatus&AliESDtrack::kTRDin){
391         SetMarkerColor(kGreen);
392         SetLineColor(kGreen);
393       } else {
394         SetMarkerColor(kMagenta);
395         SetLineColor(kMagenta);
396       }
397     } else {
398       if(TESTBIT(s, kPID) == AliTRDReconstructor::kLQPID){
399         //printf("PID color kLQPID\n");
400         //trk->GetReconstructor()->SetOption("!nn");
401       } else {
402         //printf("PID color kNNPID\n");
403         //trk->GetReconstructor()->SetOption("nn");
404       }
405       trk->CookPID();
406   
407       Int_t species = 0; Float_t pid = 0.;
408       for(Int_t is=0; is<AliPID::kSPECIES; is++) 
409         if(trk->GetPID(is) > pid){
410           pid = trk->GetPID(is);
411           species = is;
412         }
413       switch(species){
414       case AliPID::kElectron:
415         SetMarkerColor(kRed);
416         SetLineColor(kRed);
417         break;
418       default:
419         SetMarkerColor(kBlue);
420         SetLineColor(kBlue);
421         break;
422       }
423     }
424     SetLineWidth(2);
425   }
426   
427   Char_t *model = "line";
428   if(!TESTBIT(s, kTrackCosmics)){
429     if(TESTBIT(s, kTrackModel)) model = "kalman";
430     else model = "rieman";
431   }
432   Int_t species = 0; Float_t pid = 0.;
433   for(Int_t is=0; is<AliPID::kSPECIES; is++) 
434     if(trk->GetPID(is) > pid){
435       pid = trk->GetPID(is);
436       species = is;
437     }
438
439   SetTitle(Form("Nc[%d] Nt[%d] Model[%s] Source[%s]", trk->GetNumberOfClusters(), trk->GetNumberOfTracklets(), model, fESDStatus&AliESDtrack::kTRDin ? "barrel" : "sa"));
440   SetName(AliPID::ParticleName(species));
441
442   // save track status
443   fTrackState = s;
444 }