Added support to display the HLT ESD Tree. See the comment in visscan_local.C for How
[u/mrichter/AliRoot.git] / EVE / alice-macros / MUON_displaySimu.C
CommitLineData
20dae051 1// $Id$
d810d0de 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 *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
f6ee486c 9
25b4bdb2 10/// \ingroup evemacros
11/// \file MUON_displaySimu.C
12///
13/// \author B. Vulpescu, LPC
14
ba978640 15#if !defined(__CINT__) || defined(__MAKECINT__)
16#include <Riostream.h>
17#include <Rtypes.h>
18#include <TTree.h>
19#include <TStyle.h>
20#include <TString.h>
21#include <TSystem.h>
22#include <TEveManager.h>
23#include <TEveElement.h>
24#include <TEveTrack.h>
25
cd8436d1 26#include <AliLog.h>
6c49a8e1 27#include <AliMpSegmentation.h>
28#include <AliMpDDLStore.h>
29#include <AliMpCDB.h>
30#include <AliMUONRecoCheck.h>
31#include <AliMUONTrack.h>
32#include <AliMUONTrackExtrap.h>
33#include <AliMUONVTrackStore.h>
34#include <AliStack.h>
35#include <AliRunLoader.h>
36#include <AliESDEvent.h>
37#include <AliESDMuonTrack.h>
38#include <AliEveEventManager.h>
39#include <AliEveMUONData.h>
40#include <AliEveMUONChamber.h>
41#include <AliEveMUONTrack.h>
ba978640 42#else
d810d0de 43class AliEveMUONData;
44class AliEveEventManager;
ba978640 45#endif
f6ee486c 46
cb4245bb 47AliEveMUONData *g_muon_data = 0;
cb4245bb 48
49Int_t g_currentEvent = -1;
50Bool_t g_fromRaw = kFALSE;
f6ee486c 51
ba978640 52void MUON_ESD_tracks();
53void MUON_Ref_tracks();
54void MUON_MC_tracks();
f6ee486c 55
af2d8a68 56void MUON_displaySimu(Bool_t fromRaw = kFALSE, Bool_t showTracks = kTRUE, Bool_t clustersFromESD = kTRUE)
f6ee486c 57{
58e15fc1 58 //
59 // display from simulated digits (or produced raw data)
60 // tracks: ESD, Refs, MC
61 //
62
51346b82 63 if (!AliMpSegmentation::Instance()) AliMpCDB::LoadMpSegmentation();
832dd5c9 64 if (!AliMpDDLStore::Instance()) AliMpCDB::LoadDDLStore();
65
f7a1cc68 66 // set the magnetic field for track extrapolations
e383efce 67 AliEveEventManager::AssertMagField();
f7a1cc68 68 AliMUONTrackExtrap::SetField();
83eb8a9e 69
f6ee486c 70 TTree* dt = 0;
71 TTree* ct = 0;
eadce74d 72 TTree* ht = 0;
f6ee486c 73
4d62585e 74 if (AliEveEventManager::GetMaster() == 0) {
f6ee486c 75 printf("No alieve event: use alieve_init(...) \n");
76 return;
77 }
78
4d62585e 79 if (g_currentEvent == AliEveEventManager::GetMaster()->GetEventId()) {
f6ee486c 80 if (g_fromRaw == fromRaw) {
81 printf("Same event... \n");
82 return;
83 } else {
84 if (g_fromRaw) {
85 printf("Same event with digits.\n");
4d62585e 86 AliEveEventManager::GetMaster()->GotoEvent(g_currentEvent);
f6ee486c 87 } else {
88 printf("Same event with raw.\n");
4d62585e 89 AliEveEventManager::GetMaster()->GotoEvent(g_currentEvent);
f6ee486c 90 }
91 }
92 }
93
94 g_fromRaw = fromRaw;
95
4d62585e 96 TString dataPath = TString(AliEveEventManager::GetMaster()->GetTitle());
20dae051 97 dataPath.Append("/raw.root");
f6ee486c 98
d810d0de 99 AliRunLoader* rl = AliEveEventManager::AssertRunLoader();
100 g_muon_data = new AliEveMUONData;
51346b82 101
f6ee486c 102 if (!fromRaw) {
103 rl->LoadDigits("MUON");
104 dt = rl->GetTreeD("MUON", false);
105 if (dt == 0) {
cd8436d1 106 AliInfoGeneral("MUON_displaySimu.C", "No digits produced!");
f6ee486c 107 } else {
cd8436d1 108 AliInfoGeneral("MUON_displaySimu.C", "With aliroot digits!");
f6ee486c 109 g_muon_data->LoadDigits(dt);
110 }
111 } else {
112 if (gSystem->AccessPathName(dataPath.Data(),kFileExists)) {
cd8436d1 113 AliInfoGeneral("MUON_displaySimu.C", "No raw data produced!");
f6ee486c 114 } else {
cd8436d1 115 AliInfoGeneral("MUON_displaySimu.C", "With raw digits!");
f6ee486c 116 g_muon_data->LoadRaw(dataPath.Data());
117 }
118 }
51346b82 119
4d62585e 120 TString esdDataPath = TString(AliEveEventManager::GetMaster()->GetTitle());
83eb8a9e 121 esdDataPath.Append("/AliESDs.root");
af2d8a68 122 if (clustersFromESD) {
123 g_muon_data->LoadRecPointsFromESD(esdDataPath.Data());
124 } else {
125 rl->LoadRecPoints("MUON");
126 ct = rl->GetTreeR("MUON", false);
127 g_muon_data->LoadRecPoints(ct);
128 }
58e15fc1 129
eadce74d 130 rl->LoadHits("MUON");
131 ht = rl->GetTreeH("MUON", false);
132 g_muon_data->LoadHits(ht);
58e15fc1 133
4d62585e 134 g_currentEvent = AliEveEventManager::GetMaster()->GetEventId();
51346b82 135
f6ee486c 136 gStyle->SetPalette(1, 0);
137
84aff7a4 138 gEve->DisableRedraw();
51346b82 139
84aff7a4 140 TEveElementList* l = new TEveElementList("MUONChambers");
f6ee486c 141 l->SetTitle("MUON chambers");
fbc350a3 142 l->SetMainColor(2);
84aff7a4 143 gEve->AddElement(l);
51346b82 144
cb4245bb 145 for (Int_t ic = 0; ic < 14; ic++)
146 {
d810d0de 147 AliEveMUONChamber* mucha = new AliEveMUONChamber(ic);
51346b82 148
f6ee486c 149 mucha->SetFrameColor(2);
150 mucha->SetChamberID(ic);
51346b82 151
f6ee486c 152 mucha->SetDataSource(g_muon_data);
153
84aff7a4 154 gEve->AddElement(mucha, l);
f6ee486c 155 }
156
eadce74d 157 if (showTracks) {
eadce74d 158 MUON_ESD_tracks();
159 MUON_Ref_tracks();
160 MUON_MC_tracks();
161 }
f6ee486c 162
84aff7a4 163 gEve->Redraw3D(kTRUE);
cb4245bb 164 gEve->EnableRedraw();
f6ee486c 165}
166
57ffa5fb 167//______________________________________________________________________________
cb4245bb 168void MUON_ESD_tracks()
169{
d810d0de 170 AliESDEvent* esd = AliEveEventManager::AssertESD();
f6ee486c 171
51346b82 172 TEveTrackList* lt = new TEveTrackList("ESD-Tracks");
fbc350a3 173 lt->SetMainColor(6);
eadce74d 174 //lt->SetMUON();
f6ee486c 175
84aff7a4 176 gEve->AddElement(lt);
eadce74d 177
178 AliESDMuonTrack *mt;
84aff7a4 179 TEveRecTrack rt;
eadce74d 180 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
58e15fc1 181 Int_t nTrack = 0;
cb4245bb 182 for (Int_t n = 0; n < nMuonTracks; n++)
183 {
eadce74d 184 mt = esd->GetMuonTrack(n);
185
58e15fc1 186 if (mt->GetNHit() == 0) continue;
187 nTrack++;
188
83eb8a9e 189 rt.fLabel = n;
eadce74d 190
d810d0de 191 AliEveMUONTrack* track = new AliEveMUONTrack(&rt, lt->GetPropagator());
eadce74d 192
193 track->MakeESDTrack(mt);
194
84aff7a4 195 gEve->AddElement(track, lt);
eadce74d 196 }
197
198}
199
57ffa5fb 200//______________________________________________________________________________
cb4245bb 201void MUON_Ref_tracks()
202{
4d62585e 203 TString dataPathESD = TString(AliEveEventManager::GetMaster()->GetTitle());
83eb8a9e 204 dataPathESD.Append("/AliESDs.root");
4d62585e 205 TString dataPathSIM = TString(AliEveEventManager::GetMaster()->GetTitle());
83eb8a9e 206 dataPathSIM.Append("/");
eadce74d 207
83eb8a9e 208 AliMUONRecoCheck recoCheck(dataPathESD.Data(),dataPathSIM.Data());
4d62585e 209 AliMUONVTrackStore* trackRefStore = recoCheck.ReconstructibleTracks(AliEveEventManager::GetMaster()->GetEventId());
832dd5c9 210 TIter next(trackRefStore->CreateIterator());
211 AliMUONTrack* trackRef;
51346b82 212
213 TEveTrackList* lt = new TEveTrackList("Ref-Tracks");
fbc350a3 214 lt->SetMainColor(6);
eadce74d 215
84aff7a4 216 gEve->AddElement(lt);
eadce74d 217
84aff7a4 218 TEveRecTrack rt;
51346b82 219 Int_t i = 0;
cb4245bb 220 while ( ( trackRef = static_cast<AliMUONTrack*>(next()) ) )
221 {
83eb8a9e 222 rt.fLabel = i++;
eadce74d 223
d810d0de 224 AliEveMUONTrack* track = new AliEveMUONTrack(&rt, lt->GetPropagator());
eadce74d 225
832dd5c9 226 track->MakeRefTrack(trackRef);
eadce74d 227
84aff7a4 228 gEve->AddElement(track, lt);
eadce74d 229 }
230
231}
232
57ffa5fb 233//______________________________________________________________________________
cb4245bb 234void MUON_MC_tracks()
235{
d810d0de 236 AliRunLoader* rl = AliEveEventManager::AssertRunLoader();
eadce74d 237 rl->LoadKinematics();
238 AliStack* stack = rl->Stack();
239
eadce74d 240 Int_t nTracks = stack->GetNtrack();
241
51346b82 242 TEveTrackList* lt = new TEveTrackList("MC-Tracks");
fbc350a3 243 lt->SetMainColor(6);
eadce74d 244 //lt->SetMUON();
245
84aff7a4 246 gEve->AddElement(lt);
eadce74d 247
eadce74d 248 TParticle *part;
84aff7a4 249 TEveRecTrack rt;
eadce74d 250
251 Int_t nHitTracks = g_muon_data->GetNTrackList();
252 Int_t index;
cb4245bb 253 for (Int_t i = 0; i < nHitTracks; i++)
254 {
eadce74d 255 index = g_muon_data->GetTrack(i);
256 if (index >= nTracks) {
cd8436d1 257 AliInfoGeneral("MUON_displaySimu.C", "TEveHit track index larger than number in stack!");
eadce74d 258 continue;
259 }
260
261 part = stack->Particle(index);
262 if (part->P() < 0.001) continue; // skip momenta < 1.0 MeV/c
83eb8a9e 263 rt.fLabel = i;
eadce74d 264
d810d0de 265 AliEveMUONTrack* track = new AliEveMUONTrack(&rt, lt->GetPropagator());
eadce74d 266
267 track->MakeMCTrack(part);
268
84aff7a4 269 gEve->AddElement(track, lt);
eadce74d 270 }
f6ee486c 271
832dd5c9 272 rl->UnloadKinematics();
f6ee486c 273}
274