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