From Philippe & Laurent: new variant of MUON visualization.
[u/mrichter/AliRoot.git] / EVE / alice-macros / esd_muon_tracks.C
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
5  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
6  * full copyright notice.                                                 *
7  **************************************************************************/
8
9 // Macro to visualise ESD tracks from MUON spectrometer 
10 // (both tracker and trigger).
11 //
12 // Use esd_muon_tracks(Bool_t showClusters, Bool_t showDigits) in order to run it
13 //
14 // Needs that alieve_init() is already called
15
16 #if !defined(__CINT__) || defined(__MAKECINT__)
17
18 #include "AliMUONESDInterface.h"
19 #include "AliMUONTrack.h"
20 #include "AliMUONTrackExtrap.h"
21 #include "AliMUONTrackParam.h"
22 #include "AliMUONConstants.h"
23 #include "AliMUONCDB.h"
24 #include "AliMUONGeometryTransformer.h"
25 #include "AliMUONTriggerCircuit.h"
26
27 #include "AliMpCDB.h"
28
29 #include "AliESDEvent.h"
30 #include "AliESDMuonTrack.h"
31
32 #include "EveBase/AliEveMagField.h"
33 #include "EveBase/AliEveTrack.h"
34 #include "EveBase/AliEveEventManager.h"
35
36 #include <TEveManager.h>
37 #include <TEveUtil.h>
38 #include <TEveTrack.h>
39 #include <TEvePointSet.h>
40 #include <TEveQuadSet.h>
41 #include <TEveTrackPropagator.h>
42 #include <TEveVSDStructs.h>
43
44 #include <TStyle.h>
45 #include <TROOT.h>
46
47 #endif
48
49 AliMUONGeometryTransformer* gMUONGeometryTransformer(0x0);
50 AliMUONTriggerCircuit* gTriggerCircuit(0x0);
51
52 //______________________________________________________________________________
53 void esd_muon_track_propagator_setup(TEveTrackPropagator* trkProp, Bool_t tracker, Bool_t trigger)
54 {
55   // set magnetic field
56   if (AliMUONTrackExtrap::IsFieldON())
57   {
58     trkProp->SetMagFieldObj(new AliEveMagField);
59   }
60   else
61   {
62     trkProp->SetMagField(0.0);
63   }
64   trkProp->SetStepper(TEveTrackPropagator::kRungeKutta);
65   
66   // set propagation range
67   trkProp->SetMaxR(1000);
68   if (trigger) trkProp->SetMaxZ(-AliMUONConstants::DefaultChamberZ(13)+10.);
69   else trkProp->SetMaxZ(-AliMUONConstants::MuonFilterZBeg());
70   
71   // go through pathmarks
72   trkProp->SetFitDaughters(kFALSE);
73   trkProp->SetFitReferences(kTRUE);
74   trkProp->SetFitDecay(kFALSE);
75   trkProp->SetFitCluster2Ds(kFALSE);
76   
77   // Render the ref pathmarks
78   trkProp->SetRnrReferences(kTRUE);
79   trkProp->RefPMAtt().SetMarkerSize(0.5);
80   if (trigger) trkProp->RefPMAtt().SetMarkerColor(kGreen);
81   else trkProp->RefPMAtt().SetMarkerColor(kAzure);
82   
83   // Render first vertex
84   if (tracker)
85   {
86     trkProp->SetRnrFV(kTRUE);
87     if (trigger) trkProp->RefFVAtt().SetMarkerColor(kGreen);
88     else trkProp->RefFVAtt().SetMarkerColor(kAzure);
89   }
90 }
91
92 //______________________________________________________________________________
93 void add_esd_muon_tracks(AliESDEvent* esd, AliMUONESDInterface* data,
94                          TEveTrackList* match, TEveTrackList* nomatch, TEveTrackList* ghost)
95 {
96   Int_t nTrack(esd->GetNumberOfMuonTracks());
97   TEveRecTrack recTrack;
98   TEveTrack* track;
99   
100   // add ESD tracks to the proper list
101   for (Int_t n = 0; n < nTrack; ++n)
102   {
103     AliESDMuonTrack* emt = esd->GetMuonTrack(n);
104     
105     // fill general info
106     UInt_t trackId = emt->GetUniqueID();
107     recTrack.fLabel = emt->GetLabel();
108     recTrack.fIndex = (Int_t)trackId;
109     
110     // fill tracker track specific info
111     if ( emt->ContainTrackerData() )
112     {
113       recTrack.fStatus = emt->GetMatchTrigger();
114       recTrack.fSign = emt->Charge();
115       recTrack.fV.Set(emt->GetNonBendingCoorAtDCA(),emt->GetBendingCoorAtDCA(),emt->GetZ());
116       recTrack.fP.Set(emt->PxAtDCA(),emt->PyAtDCA(),emt->PzAtDCA());
117       recTrack.fBeta = ( emt->E() > 0 ) ? emt->P()/emt->E() : 0;
118       
119       // get proper track list
120       TEveTrackList* trackList = nomatch;
121       if ( emt->GetMatchTrigger() > 0 ) trackList = match;
122       
123       // produce eve track
124       track = new AliEveTrack(&recTrack,trackList->GetPropagator());
125       track->SetName(Form("%cmu",emt->Charge()>0 ? '+':'-'));
126       track->SetStdTitle();
127       track->SetSourceObject(emt); // WARNING: Change the UniqueID of the object!!
128       
129       // add path mark
130       TIter next(data->FindTrack(trackId)->GetTrackParamAtCluster());
131       AliMUONTrackParam* param;
132       while ( ( param = static_cast<AliMUONTrackParam*>(next()) ) )
133       {
134         TEveVector v(param->GetNonBendingCoor(),param->GetBendingCoor(),param->GetZ());
135         TEveVector p(param->Px(),param->Py(),param->Pz());
136         track->AddPathMark(TEvePathMark(TEvePathMark::kReference,v,p));
137       }
138       
139       // add trigger track if any
140       if (emt->ContainTriggerData())
141       {
142         Double_t x11 = gTriggerCircuit->GetX11Pos(emt->LoCircuit(), emt->LoStripY());
143         Double_t y11 = gTriggerCircuit->GetY11Pos(emt->LoCircuit(), emt->LoStripX());
144         Double_t z11 = AliMUONConstants::DefaultChamberZ(10);
145         Double_t y21 = gTriggerCircuit->GetY21Pos(emt->LoCircuit(), emt->LoStripX()+emt->LoDev()+1);
146         Double_t z21 = AliMUONConstants::DefaultChamberZ(12);
147         Double_t pz  = -emt->PUncorrected(); // max value
148         TEveVector v(x11, y11, z11);
149         TEveVector p(pz*x11/z11, pz*(y21-y11)/(z21-z11), pz);
150         track->AddPathMark(TEvePathMark(TEvePathMark::kReference,v,p));
151       }
152       
153       // add the track to proper list
154       track->SetAttLineAttMarker(trackList);
155       trackList->AddElement(track);
156     }
157     else // fill ghost track specific info
158     {
159       recTrack.fStatus = 0;
160       recTrack.fSign = emt->Charge();
161       recTrack.fV.Set(emt->GetNonBendingCoorUncorrected(),emt->GetBendingCoorUncorrected(),(Double_t)AliMUONConstants::DefaultChamberZ(10));
162       recTrack.fP.Set(-TMath::Tan(emt->GetThetaXUncorrected()),-TMath::Tan(emt->GetThetaYUncorrected()),-1.);
163       
164       // produce eve track
165       track = new AliEveTrack(&recTrack,ghost->GetPropagator());
166       track->SetName("mu");
167       track->SetTitle("Trigger only");
168       track->SetSourceObject(emt);
169       
170       // add the track to proper list
171       track->SetAttLineAttMarker(ghost);
172       ghost->AddElement(track);
173     }
174     
175   }
176   
177 }
178
179 //______________________________________________________________________________
180 void esd_muon_tracks(Bool_t showClusters, Bool_t showDigits)
181 {
182   // load ESD
183   AliESDEvent* esd = AliEveEventManager::AssertESD();
184   if (esd->GetNumberOfMuonTracks() == 0 && !gEve->GetKeepEmptyCont()) return;
185   
186   // load field
187   AliEveEventManager::AssertMagField();
188   if (!AliMUONESDInterface::GetTracker()) AliMUONESDInterface::ResetTracker(AliMUONCDB::LoadRecoParam());
189   
190   // load mapping
191   AliMpCDB::LoadAll(kFALSE);
192   
193   // load geometry
194   if (gMUONGeometryTransformer == 0) 
195   {
196     AliEveEventManager::AssertGeometry();
197     gMUONGeometryTransformer = new AliMUONGeometryTransformer();
198     gMUONGeometryTransformer->LoadGeometryData();
199     gTriggerCircuit = new AliMUONTriggerCircuit(gMUONGeometryTransformer);
200   }
201   
202   // convert ESD objects to MUON objects
203   AliMUONESDInterface data;
204   data.LoadEvent(*esd);
205   
206   // track containers
207   TEveElementList* trackCont = new TEveElementList("ESD MUON Tracks");
208   trackCont->SetTitle(Form("N=%d", esd->GetNumberOfMuonTracks()));
209   
210   TEveTrackList* match = new TEveTrackList("Matched");
211   match->SetRnrPoints(kFALSE);
212   match->SetRnrLine(kTRUE);
213   match->SetLineColor(kGreen);
214   esd_muon_track_propagator_setup(match->GetPropagator(), kTRUE, kTRUE);
215   trackCont->AddElement(match);
216   
217   TEveTrackList* nomatch = new TEveTrackList("Not matched");
218   nomatch->SetRnrPoints(kFALSE);
219   nomatch->SetRnrLine(kTRUE);
220   nomatch->SetLineColor(kAzure);
221   esd_muon_track_propagator_setup(nomatch->GetPropagator(), kTRUE, kFALSE);
222   trackCont->AddElement(nomatch);
223   
224   TEveTrackList* ghost = new TEveTrackList("Ghost");
225   ghost->SetRnrPoints(kFALSE);
226   ghost->SetRnrLine(kTRUE);
227   ghost->SetLineColor(kAzure);
228   esd_muon_track_propagator_setup(ghost->GetPropagator(), kFALSE, kTRUE);
229   trackCont->AddElement(ghost);
230   
231   // cluster container
232   TEvePointSet* clusterList = 0x0;
233   if (showClusters && (data.GetNClusters() > 0 || gEve->GetKeepEmptyCont()))
234   {
235     clusterList = new TEvePointSet(10000);
236     clusterList->SetName("ESD MUON Clusters");
237     clusterList->SetTitle(Form("N=%d",data.GetNClusters()));
238     clusterList->SetPickable(kFALSE);
239     clusterList->SetMarkerStyle(5);
240     clusterList->SetMarkerColor(kYellow);
241     clusterList->SetMarkerSize(2.5);
242   }
243
244   // digit containers
245   TEveElementList* digitCont = 0x0;
246   TEveQuadSet* bending = 0x0;
247   TEveQuadSet* nonBending = 0x0;
248   if (showDigits && (data.GetNDigits() > 0 || gEve->GetKeepEmptyCont()))
249   {
250     digitCont = new TEveElementList("ESD MUON Digits");
251     digitCont->SetTitle(Form("N=%d",data.GetNDigits()));
252     
253     bending = new TEveQuadSet(TEveQuadSet::kQT_RectangleXY, kFALSE, 32);
254     bending->SetName("Bending");
255     bending->SetRenderMode(TEveDigitSet::kRM_Fill);
256     bending->SetPickable(kFALSE);
257     digitCont->AddElement(bending);
258     
259     nonBending = new TEveQuadSet(TEveQuadSet::kQT_RectangleXY, kFALSE, 32);
260     nonBending->SetName("Non bending");
261     nonBending->SetRenderMode(TEveDigitSet::kRM_Line);
262     nonBending->SetPickable(kFALSE);
263     digitCont->AddElement(nonBending);
264   }
265   
266   // add tracks to the proper list and propagate them
267   add_esd_muon_tracks(esd, &data, match, nomatch, ghost);
268   match->SetTitle(Form("N=%d",match->NumChildren()));
269   nomatch->SetTitle(Form("N=%d",nomatch->NumChildren()));
270   ghost->SetTitle(Form("N=%d",ghost->NumChildren()));
271   match->MakeTracks();
272   nomatch->MakeTracks();
273   ghost->MakeTracks();
274   
275   // add cluster to the container
276   if (clusterList)
277   {
278     TEveUtil::LoadMacro("muon_clusters.C+");
279     TIter next(data.CreateClusterIterator());
280     gROOT->ProcessLine(Form("add_muon_clusters((TIter*)%p, (TEvePointSet*)%p);",&next, clusterList));
281   }
282   
283   // add digits to the containers
284   if (digitCont)
285   {
286     TEveUtil::LoadMacro("muon_digits.C+");
287     TIter next(data.CreateDigitIterator());
288     gROOT->ProcessLine(Form("add_muon_digits((TIter*)%p, (TEveQuadSet*)%p, (TEveQuadSet*)%p, kFALSE);",
289                             &next, bending, nonBending));
290     
291     // set containers' title
292     bending->SetTitle(Form("N=%d",bending->GetPlex()->Size()));
293     nonBending->SetTitle(Form("N=%d",nonBending->GetPlex()->Size()));
294     
295     // automatic scaling
296     gStyle->SetPalette(1);
297     bending->AssertPalette();
298     nonBending->AssertPalette();
299   }
300   
301   // add graphic containers
302   gEve->DisableRedraw();
303   gEve->AddElement(trackCont);
304   if (clusterList) gEve->AddElement(clusterList);
305   if (digitCont) gEve->AddElement(digitCont);
306   gEve->EnableRedraw();
307   gEve->Redraw3D();
308 }