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