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