]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/EVE/AliHLTEveHLT.cxx
Merge branch 'displayDevel'
[u/mrichter/AliRoot.git] / HLT / EVE / AliHLTEveHLT.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * ALICE Experiment at CERN, All rights reserved.                         *
4  *                                                                        *
5  * Primary Authors: Svein Lindal <slindal@fys.uio.no   >                  *
6  *                  for The ALICE HLT Project.                            *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 /// @file   AliHLTEvePhos.cxx
18 /// @author Svein Lindal <slindal@fys.uio.no>
19 /// @brief  HLT class for the HLT EVE display
20
21 #include "AliHLTEveHLT.h"
22 #include "AliHLTHOMERBlockDesc.h"
23 #include "AliHLTEveBase.h"
24 #include "AliEveHLTEventManager.h"
25 #include "TEveManager.h"
26 #include "TEvePointSet.h"
27 #include "TEveTrack.h"
28 #include "TCanvas.h"
29 #include "AliESDEvent.h"
30 #include "TEveTrackPropagator.h"
31 #include "AliEveTrack.h"
32 #include "TEveVSDStructs.h"
33 #include "TString.h"
34 #include "TPCLib/tracking-ca/AliHLTTPCCATrackParam.h"
35 #include "TPCLib/tracking-ca/AliHLTTPCCATrackConvertor.h"
36 #include "AliEveMagField.h"
37 #include "TH1F.h"
38 #include "TH2F.h"
39 #include "TThread.h"
40
41 ClassImp(AliHLTEveHLT)
42
43 AliHLTEveHLT::AliHLTEveHLT() : 
44   AliHLTEveBase("TPC tracks"), 
45   fTrueField(kFALSE),
46   fUseIpOnFailedITS(kFALSE),
47   fUseRkStepper(kFALSE),
48   fTrackList(NULL),
49   fOldTrackList(NULL),
50   fPointSetVertex(NULL),
51   fTrCanvas(NULL),
52   fHistPt(NULL), 
53   fHistP(NULL), 
54   fHistEta(NULL),
55   fHistTheta(NULL),
56   fHistPhi(NULL),
57   fHistnClusters(NULL),
58   fHistMult(NULL)
59 {
60   // Constructor.
61   //CreateHistograms();
62 }
63
64 AliHLTEveHLT::~AliHLTEveHLT()
65 {
66   //Destructor, not implemented
67   if(fTrackList)
68     delete fTrackList;
69   fTrackList = NULL;
70 }
71
72 void AliHLTEveHLT::ProcessEsdEvent( AliESDEvent * esd ) {
73   //See header file for documentation
74   if(!fTrackList) CreateTrackList();
75   if(!fPointSetVertex) CreateVertexPointSet();
76   ProcessEsdEvent(esd, fTrackList);
77     
78 }
79 ///_____________________________________________________________________
80 void AliHLTEveHLT::ProcessBlock(AliHLTHOMERBlockDesc * block) {
81   //See header file for documentation
82   if ( ! block->GetDataType().CompareTo("ALIESDV0") ) {
83     if(!fTrackList) CreateTrackList();
84     if(!fPointSetVertex) CreateVertexPointSet();
85     ProcessEsdBlock(block, fTrackList);
86   } 
87   
88   else if ( ! block->GetDataType().CompareTo("ROOTTOBJ") ) {
89     //processROOTTOBJ( block, gHLTText );
90   } 
91
92   else if ( ! block->GetDataType().CompareTo("HLTRDLST") ) {
93     //processHLTRDLST( block );
94   } 
95
96   else if ( !block->GetDataType().CompareTo("ROOTHIST") ) {      
97     if( !fCanvas ) { 
98       fCanvas = CreateCanvas("Primary Vertex", "Primary Vertex");
99       fCanvas->Divide(3, 2);
100     }
101     ProcessHistograms( block , fCanvas);
102   }  
103 }
104
105 ///____________________________________________________________________________
106 void AliHLTEveHLT::UpdateElements() {
107   //See header file for documentation
108   //if(fCanvas) fCanvas->Update();
109   //DrawHistograms();
110   if(fTrackList) fTrackList->ElementChanged();
111   if(fPointSetVertex) fPointSetVertex->ResetBBox();
112
113 }
114 ///_________________________________________________________________________________
115 void AliHLTEveHLT::ResetElements(){
116   //See header file for documentation
117   
118   cout << "destroy"<<endl;
119   if(fTrackList) {
120     RemoveElement(fTrackList);
121     fTrackList = NULL;
122   }
123   
124   if(fPointSetVertex) fPointSetVertex->Reset();
125   cout<< "reset done"<<endl;
126   fHistoCount = 0;
127
128 }
129
130 ///_____________________________________________________________________________________
131 void * AliHLTEveHLT::DestroyGarbage(void * arg) {
132   AliHLTEveHLT * hlt = reinterpret_cast<AliHLTEveHLT*>(arg);
133   if(hlt) hlt->DestroyOldTrackList();
134   return (void*)0;
135 }
136 ///_____________________________________________________________________________________
137 void AliHLTEveHLT::DestroyOldTrackList() {
138   cout << "Destroying the old tracklist's elements"<<endl;
139   fOldTrackList->DestroyElements();
140   cout << "Destroying the old tracklist itself"<<endl;
141   fOldTrackList->Destroy();
142 }
143
144 ///_____________________________________________________________________________________
145 void AliHLTEveHLT::ProcessHistograms(AliHLTHOMERBlockDesc * block, TCanvas * canvas) {
146   //See header file for documentation
147   if ( ! block->GetClassName().CompareTo("TH1F")) {
148     TH1F* histo = reinterpret_cast<TH1F*>(block->GetTObject());
149     if( histo ){
150       TString name(histo->GetName());
151       if( !name.CompareTo("primVertexZ") ){
152         canvas->cd(2);
153         histo->Draw();
154       }else if( !name.CompareTo("primVertexX") ){
155         canvas->cd(3);
156         histo->Draw();
157       }else if( !name.CompareTo("primVertexY") ){
158         canvas->cd(4);
159         histo->Draw();
160       }
161     }
162   }  else if ( ! block->GetClassName().CompareTo("TH2F")) {
163     TH2F *hista = reinterpret_cast<TH2F*>(block->GetTObject());
164     if (hista ){
165        TString name(hista->GetName());
166        if( !name.CompareTo("primVertexXY")) {      
167          canvas->cd(1);
168          hista->Draw();
169        }
170     }
171   }
172   canvas->cd();
173 }
174
175
176 void AliHLTEveHLT::CreateTrackList() {
177   //See header file for documentation
178   fTrackList = new TEveTrackList("ESD Tracks");
179   fTrackList->SetMainColor(6);
180   AddElement(fTrackList);
181 }
182
183
184 void AliHLTEveHLT::CreateVertexPointSet() {
185   //See header file for documentation
186   fPointSetVertex = new TEvePointSet("Primary Vertex");
187   fPointSetVertex->SetMainColor(6);
188   fPointSetVertex->SetMarkerStyle((Style_t)kFullStar);
189
190   AddElement(fPointSetVertex);
191 }
192
193
194 void AliHLTEveHLT::ProcessEsdBlock( AliHLTHOMERBlockDesc * block, TEveTrackList * cont ) {
195   //See header file for documentation
196
197   AliESDEvent* esd = (AliESDEvent *) (block->GetTObject());
198   if (!esd) return;
199   
200   ProcessEsdEvent(esd, cont);
201 }
202
203 void AliHLTEveHLT::ProcessEsdEvent(AliESDEvent * esd, TEveTrackList * cont) {
204
205   esd->GetStdContent();
206
207   cout << esd->GetEventNumberInFile() << "  " << esd->GetNumberOfCaloClusters() << endl;
208
209   //fEventManager->SetRunNumber(esd->GetRunNumber());
210
211   Double_t vertex[3];
212   const AliESDVertex * esdVertex = esd->GetPrimaryVertex();
213   
214   if(esdVertex) {
215     esdVertex->GetXYZ(vertex);
216     fPointSetVertex->SetNextPoint(vertex[0], vertex[1], vertex[2]);
217   }
218   
219   SetUpTrackPropagator(cont->GetPropagator(),-0.1*esd->GetMagneticField(), 520);
220
221   for (Int_t iter = 0; iter < esd->GetNumberOfTracks(); ++iter) {
222     AliEveTrack* track = dynamic_cast<AliEveTrack*>(MakeEsdTrack(esd->GetTrack(iter), cont));
223     cont->AddElement(track);
224    
225     // fHistPt->Fill(esd->GetTrack(iter)->Pt());   // KK
226     // fHistP->Fill(esd->GetTrack(iter)->P()*esd->GetTrack(iter)->Charge());
227     // fHistEta->Fill(esd->GetTrack(iter)->Eta());
228     // fHistTheta->Fill(esd->GetTrack(iter)->Theta()*TMath::RadToDeg());
229     // fHistPhi->Fill(esd->GetTrack(iter)->Phi()*TMath::RadToDeg());
230     // if(esd->GetTrack(iter)->GetStatus()&AliESDtrack::kTPCin || (esd->GetTrack(iter)->GetStatus()&AliESDtrack::kTPCin && esd->GetTrack(iter)->GetStatus()&AliESDtrack::kITSin)){
231     //    fHistnClusters->Fill(esd->GetTrack(iter)->GetTPCNcls());  
232     //}
233   }
234   
235 //fHistMult->Fill(esd->GetNumberOfTracks()); // KK
236   
237   
238   cont->SetTitle(Form("N=%d", esd->GetNumberOfTracks()) );
239   cont->MakeTracks();
240   
241 }
242
243
244
245 void AliHLTEveHLT::DrawHistograms(){
246   //See header file for documentation
247
248   if (!fTrCanvas) {
249     fTrCanvas = CreateCanvas("TPC Tr QA", "TPC Track QA");
250     fTrCanvas->Divide(4, 2);
251   }
252
253   Int_t icd = 1;
254   fTrCanvas->cd(icd++);
255   fHistPt->Draw();
256   fTrCanvas->cd(icd++);
257   fHistP->Draw();
258   fTrCanvas->cd(icd++);
259   fHistEta->Draw();
260   fTrCanvas->cd(icd++);
261   fHistTheta->Draw();
262   fTrCanvas->cd(icd++);
263   fHistPhi->Draw();
264   fTrCanvas->cd(icd++);
265   fHistnClusters->Draw();
266   fTrCanvas->cd(icd++);
267   fHistMult->Draw();
268   fTrCanvas->cd();
269
270   fTrCanvas->Update();
271
272 }
273
274 AliEveTrack* AliHLTEveHLT::MakeEsdTrack (AliESDtrack *at, TEveTrackList* cont) {
275   //See header file for documentation
276
277
278   const double kCLight = 0.000299792458;
279   double bz = - kCLight*10.*( cont->GetPropagator()->GetMagField(0,0,0).fZ);
280
281   Bool_t innerTaken = kFALSE;
282   if ( ! at->IsOn(AliESDtrack::kITSrefit) && fUseIpOnFailedITS)
283   {
284     //tp = at->GetInnerParam();
285     innerTaken = kTRUE;
286   }
287
288   // Add inner/outer track parameters as path-marks.
289
290   Double_t     pbuf[3], vbuf[3];
291
292   AliExternalTrackParam trackParam = *at;
293
294   // take parameters constrained to vertex (if they are)
295
296   if( at->GetConstrainedParam() ){
297     trackParam = *at->GetConstrainedParam();
298   }
299   else if( at->GetInnerParam() ){
300     trackParam = *(at->GetInnerParam());
301   }
302   if( at->GetStatus()&AliESDtrack::kTRDin ){
303     // transport to TRD in
304     trackParam = *at;
305     trackParam.PropagateTo( 290.45, -10.*( cont->GetPropagator()->GetMagField(0,0,0).fZ) );
306   }
307
308   TEveRecTrack rt;
309   {
310     rt.fLabel  = at->GetLabel();
311     rt.fIndex  = (Int_t) at->GetID();
312     rt.fStatus = (Int_t) at->GetStatus();
313     rt.fSign   = (Int_t) trackParam.GetSign();  
314     trackParam.GetXYZ(vbuf);
315     trackParam.GetPxPyPz(pbuf);    
316     rt.fV.Set(vbuf);
317     rt.fP.Set(pbuf);
318     Double_t ep = at->GetP(), mc = at->GetMass();
319     rt.fBeta = ep/TMath::Sqrt(ep*ep + mc*mc);
320   }
321
322   AliEveTrack* track = new AliEveTrack(&rt, cont->GetPropagator());
323   track->SetAttLineAttMarker(cont);
324   track->SetName(Form("AliEveTrack %d", at->GetID()));
325   track->SetElementTitle(CreateTrackTitle(at));
326   track->SetSourceObject(at);
327
328
329   // Set reference points along the trajectory
330   // and the last point
331
332   { 
333     TEvePathMark startPoint(TEvePathMark::kReference);
334     trackParam.GetXYZ(vbuf);
335     trackParam.GetPxPyPz(pbuf);    
336     startPoint.fV.Set(vbuf);
337     startPoint.fP.Set(pbuf);
338     rt.fV.Set(vbuf);
339     rt.fP.Set(pbuf);
340     Double_t ep = at->GetP(), mc = at->GetMass();
341     rt.fBeta = ep/TMath::Sqrt(ep*ep + mc*mc);
342
343     track->AddPathMark( startPoint );    
344   }
345
346
347   if( at->GetTPCPoints(2)>80 ){
348   
349     //
350     // use AliHLTTPCCATrackParam propagator 
351     // since AliExternalTrackParam:PropagateTo()
352     // has an offset at big distances
353     //
354     
355     AliHLTTPCCATrackParam t;
356     AliHLTTPCCATrackConvertor::SetExtParam( t, trackParam );
357     
358     Double_t x0 = trackParam.GetX();
359     Double_t dx = at->GetTPCPoints(2) - x0;
360     
361     //
362     // set a reference at the half of trajectory for better drawing
363     //
364     
365     for( double dxx=dx/2; TMath::Abs(dxx)>=1.; dxx*=.9 ){
366       if( !t.TransportToX(x0+dxx, bz, .999 ) ) continue;
367       AliHLTTPCCATrackConvertor::GetExtParam( t, trackParam, trackParam.GetAlpha() ); 
368       trackParam.GetXYZ(vbuf);
369       trackParam.GetPxPyPz(pbuf);
370       TEvePathMark midPoint(TEvePathMark::kReference);
371       midPoint.fV.Set(vbuf);
372       midPoint.fP.Set(pbuf);    
373       track->AddPathMark( midPoint );
374       break;
375     }
376     
377     //
378     // Set a reference at the end of the trajectory
379     // and a "decay point", to let the event display know where the track ends
380     //
381     
382     for( ; TMath::Abs(dx)>=1.; dx*=.9 ){
383       if( !t.TransportToX(x0+dx, bz, .999 ) ) continue;
384       AliHLTTPCCATrackConvertor::GetExtParam( t, trackParam, trackParam.GetAlpha() ); 
385       trackParam.GetXYZ(vbuf);
386       trackParam.GetPxPyPz(pbuf);
387       TEvePathMark endPoint(TEvePathMark::kReference);
388       TEvePathMark decPoint(TEvePathMark::kDecay);
389       endPoint.fV.Set(vbuf);
390       endPoint.fP.Set(pbuf);
391       decPoint.fV.Set(vbuf);
392       decPoint.fP.Set(pbuf);
393       track->AddPathMark( endPoint );
394       track->AddPathMark( decPoint );
395       break;
396     }  
397   }
398
399   if (at->IsOn(AliESDtrack::kTPCrefit))
400   {
401     if ( ! innerTaken)
402     {
403       AddTrackParamToTrack(track, at->GetInnerParam());
404     }
405     AddTrackParamToTrack(track, at->GetOuterParam());
406   }
407   return track;
408 }
409
410 void AliHLTEveHLT::SetUpTrackPropagator(TEveTrackPropagator* trkProp, Float_t magF, Float_t maxR) {
411   //See header file for documentation
412
413   if (fTrueField) {
414     trkProp->SetMagFieldObj(new AliEveMagField);
415   
416   } else {
417     trkProp->SetMagField(magF);
418   }
419  
420   if (fUseRkStepper) {
421     trkProp->SetStepper(TEveTrackPropagator::kRungeKutta);
422   }
423
424   trkProp->SetMaxR(maxR);
425 }
426
427
428 void AliHLTEveHLT::AddTrackParamToTrack(AliEveTrack* track, const AliExternalTrackParam* tp) {
429   //See header file for documentation
430
431   if (tp == 0)
432     return;
433
434   Double_t pbuf[3], vbuf[3];
435   tp->GetXYZ(vbuf);
436   tp->GetPxPyPz(pbuf);
437
438   TEvePathMark pm(TEvePathMark::kReference);
439   pm.fV.Set(vbuf);
440   pm.fP.Set(pbuf);
441   track->AddPathMark(pm);
442 }
443
444
445
446 TString AliHLTEveHLT::CreateTrackTitle(AliESDtrack* t) {
447   // Add additional track parameters as a path-mark to track.
448
449   TString s;
450
451   Int_t label = t->GetLabel(), index = t->GetID();
452   TString idx(index == kMinInt ? "<undef>" : Form("%d", index));
453   TString lbl(label == kMinInt ? "<undef>" : Form("%d", label));
454
455   Double_t p[3], v[3];
456   t->GetXYZ(v);
457   t->GetPxPyPz(p);
458   Double_t pt    = t->Pt();
459   Double_t ptsig = TMath::Sqrt(t->GetSigma1Pt2());
460   Double_t ptsq  = pt*pt;
461   Double_t ptm   = pt / (1.0 + pt*ptsig);
462   Double_t ptM   = pt / (1.0 - pt*ptsig);
463
464   s = Form("Index=%s, Label=%s\nChg=%d, Pdg=%d\n"
465            "pT = %.3f + %.3f - %.3f [%.3f]\n"
466            "P  = (%.3f, %.3f, %.3f)\n"
467            "V  = (%.3f, %.3f, %.3f)\n",
468            idx.Data(), lbl.Data(), t->Charge(), 0,
469            pt, ptM - pt, pt - ptm, ptsig*ptsq,
470            p[0], p[1], p[2],
471            v[0], v[1], v[2]);
472
473   Int_t   o;
474   s += "Det (in,out,refit,pid):\n";
475   o  = AliESDtrack::kITSin;
476   s += Form("ITS (%d,%d,%d,%d)  ",  t->IsOn(o), t->IsOn(o<<1), t->IsOn(o<<2), t->IsOn(o<<3));
477   o  = AliESDtrack::kTPCin;
478   s += Form("TPC(%d,%d,%d,%d)\n",   t->IsOn(o), t->IsOn(o<<1), t->IsOn(o<<2), t->IsOn(o<<3));
479   o  = AliESDtrack::kTRDin;
480   s += Form("TRD(%d,%d,%d,%d) ",    t->IsOn(o), t->IsOn(o<<1), t->IsOn(o<<2), t->IsOn(o<<3));
481   o  = AliESDtrack::kTOFin;
482   s += Form("TOF(%d,%d,%d,%d)\n",   t->IsOn(o), t->IsOn(o<<1), t->IsOn(o<<2), t->IsOn(o<<3));
483   o  = AliESDtrack::kHMPIDout;
484   s += Form("HMPID(out=%d,pid=%d)\n", t->IsOn(o), t->IsOn(o<<1));
485   s += Form("ESD pid=%d", t->IsOn(AliESDtrack::kESDpid));
486
487   if (t->IsOn(AliESDtrack::kESDpid))
488   {
489     Double_t pid[5];
490     t->GetESDpid(pid);
491     s += Form("\n[%.2f %.2f %.2f %.2f %.2f]", pid[0], pid[1], pid[2], pid[3], pid[4]);
492   }
493
494   return s;
495 }
496
497