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