]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/macros/DisplaydHLTData.C
fixing HLT re-initialization
[u/mrichter/AliRoot.git] / HLT / MUON / macros / DisplaydHLTData.C
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors:                                                       *
6  *   Artur Szostak <artursz@iafrica.com>                                  *
7  *                                                                        *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  **************************************************************************/
16
17 // $Id: DisplaydHLTData.C 37070 2009-11-20 13:53:08Z aszostak $
18
19 /**
20  * \ingroup macros
21  * \file DisplaydHLTData.C
22  * \brief Macro for displaying rootified dHLT data generated with RunChain.C
23  *
24  * This macro is used to display the dHLT data generated by the RunChain.C macro
25  * with the "root" option for making the output data. Optionally the dHLTRawData.root
26  * file which is generated during a AliRoot offline reconstruction can also be
27  * displayed using this macro.
28  * After having generated the dHLT raw data file (called <i>output.root</i> for example)
29  * the following command can be executed in an alieve session to display both
30  * MUON and dHLT data:
31  * \code
32  *   > gSystem->Load("libAliHLTMUON.so");
33  *   > .L $ALICE_ROOT/EVE/macros/alieve_init.C
34  *   > .L $ALICE_ROOT/EVE/alice-macros/event_goto.C
35  *   > .L $ALICE_ROOT/EVE/alice-macros/MUON_displayData.C
36  *   > .L $ALICE_ROOT/HLT/MUON/macros/DisplaydHLTData.C
37  *   > alieve_init("OCDBpath","DataPath",EventNumber);
38  *   > MUON_displayData(1,1,1);
39  *   > DisplaydHLTData("output.root");
40  * \endcode
41  * Where <i>OCDBpath</i> should be replaced by the path to the OCDB database,
42  * <i>DataPath</i> should be the directory of the raw data or raw data root file and
43  * <i>EventNumber</i> is the event number to load.
44  *
45  * \author Artur Szostak <artursz@iafrica.com>
46  */
47
48 #if !defined(__CINT__) || defined(__MAKECINT__)
49 #include "AliEveEventManager.h"
50 #include "AliHLTMUONTriggerRecord.h"
51 #include "AliHLTMUONRecHit.h"
52 #include "AliHLTMUONMansoTrack.h"
53 #include "AliHLTMUONEvent.h"
54 #include "TEveManager.h"
55 #include "TEveElement.h"
56 #include "TEvePointSet.h"
57 #include "TEveStraightLineSet.h"
58 #include "TArrayD.h"
59 #include "TFile.h"
60 #include "TString.h"
61 #include "TClassTable.h"
62 #include "TSystem.h"
63 #include <iostream>
64 using std::cerr;
65 using std::endl;
66 #endif
67
68
69 TFile* gDHLTFile = NULL;
70
71 void FillData(Int_t eventId);
72
73
74 void DisplaydHLTData(const char* dHLTfilename = "output.root")
75 {
76         // Display dHLT data.
77         
78         if (gClassTable->GetID("AliHLTMUONEvent") < 0)
79         {
80                 gSystem->Load("libAliHLTMUON.so");
81         }
82         
83         if (AliEveEventManager::GetMaster() == NULL)
84         {
85                 cerr << "ERROR: alieve event not initialised, use alieve_init(...)" << endl;
86                 return;
87         }
88         
89         gEve->DisableRedraw();
90         
91         TString filename = dHLTfilename;
92         TString tmpfilename = filename;
93         if (gSystem->FindFile("", tmpfilename) == NULL)
94         {
95                 tmpfilename = filename;
96                 if (gSystem->FindFile(".", tmpfilename) == NULL)
97                 {
98                         TString filename = TString(AliEveEventManager::GetMaster()->GetTitle());
99                         filename += "/";
100                         filename += dHLTfilename;
101                 }
102         }
103         if (gDHLTFile == NULL)
104         {
105                 gDHLTFile = new TFile(filename.Data(), "READ");
106         }
107         else if (filename != gDHLTFile->GetName())
108         {
109                 delete gDHLTFile;
110                 gDHLTFile = new TFile(filename.Data(), "READ");
111         }
112         
113         FillData(AliEveEventManager::GetMaster()->GetEventId());
114         
115         gEve->Redraw3D(kTRUE);
116         gEve->EnableRedraw();
117 }
118
119
120 void FillData(TEveElementList* list, const AliHLTMUONTriggerRecord* trigrec)
121 {
122         // Count the number of points in the trigger record.
123         Int_t pointCount = 0;
124         for (int i = 11; i <= 14; ++i)
125         {
126                 if (trigrec->Hit(i) != TVector3(0,0,0)) ++pointCount;
127         }
128         
129         // Create and fill the point set for the trigger record.
130         TEvePointSet* pointset = new TEvePointSet(pointCount);
131         pointset->SetName(Form("TriggerRecord%d", trigrec->Id()));
132         pointset->SetTitle(Form("dHLT trigger record ID = %d", trigrec->Id()));
133         pointset->SetMarkerStyle(28);
134         pointset->SetMarkerColor(kYellow);
135         pointset->SetMarkerSize(3);
136         Int_t ipnt = 0;
137         for (int i = 11; i <= 14; ++i)
138         {
139                 if (trigrec->Hit(i) == TVector3(0,0,0)) continue;
140                 pointset->SetPoint(ipnt, trigrec->Hit(i).X(), trigrec->Hit(i).Y(), trigrec->Hit(i).Z());
141                 ++ipnt;
142         }
143         
144         list->AddElement(pointset);
145 }
146
147
148 void FillData(TEveElementList* list, const AliHLTMUONMansoTrack* track)
149 {
150         // Count the points in the track.
151         Int_t pointCount = 0;
152         for (int i = 7; i <= 10; ++i)
153         {
154                 const AliHLTMUONRecHit* hit = track->Hit(i);
155                 if (hit != NULL) ++pointCount;
156         }
157         const AliHLTMUONTriggerRecord* trigrec = track->TriggerRecord();
158         if (trigrec != NULL)
159         {
160                 for (int i = 11; i <= 14; ++i)
161                 {
162                         if (trigrec->Hit(i) != TVector3(0,0,0)) ++pointCount;
163                 }
164         }
165         
166         // Create and fill the point set for the track.
167         TEvePointSet* pointset = new TEvePointSet(pointCount);
168         pointset->SetName(Form("Track%d", track->Id()));
169         pointset->SetTitle(Form("dHLT track ID = %d", track->Id()));
170         if (track->Id() != -1)
171         {
172                 pointset->SetMarkerStyle(20);
173                 pointset->SetMarkerColor(kGreen);
174                 pointset->SetMarkerSize(1.5);
175         }
176         else
177         {
178                 pointset->SetMarkerStyle(28);
179                 pointset->SetMarkerColor(kYellow);
180                 pointset->SetMarkerSize(3);
181         }
182         Int_t ipnt = 0;
183         if (trigrec != NULL)
184         {
185                 for (int i = 11; i <= 14; ++i)
186                 {
187                         if (trigrec->Hit(i) == TVector3(0,0,0)) continue;
188                         pointset->SetPoint(ipnt, trigrec->Hit(i).X(), trigrec->Hit(i).Y(), trigrec->Hit(i).Z());
189                         ++ipnt;
190                 }
191         }
192         for (int j = 7; j <= 10; ++j)
193         {
194                 const AliHLTMUONRecHit* hit = track->Hit(j);
195                 if (hit == NULL) continue;
196                 pointset->SetPoint(ipnt, hit->X(), hit->Y(), hit->Z());
197                 ++ipnt;
198         }
199         
200         for (int j = 7; j <= 10; ++j)
201         {
202                 if (track->RoIRadius(j) == -1) continue;
203                 TEveStraightLineSet* roi = new TEveStraightLineSet(
204                                 Form("RoI%d", j),
205                                 Form("Region of interest for chamber %d", j)
206                         );
207                 Float_t p0x = track->RoICentre(j).X() + track->RoIRadius(j);
208                 Float_t p0y = track->RoICentre(j).Y();
209                 Float_t p0z = track->RoICentre(j).Z();
210                 Float_t p1x = p0x;
211                 Float_t p1y = p0y;
212                 Float_t p1z = p0z;
213                 for (int i = 0; i < 32; ++i)
214                 {
215                         Double_t t = Double_t(i) / 32. * 2. * TMath::Pi();
216                         Float_t p2x = track->RoICentre(j).X() + track->RoIRadius(j)*cos(t);
217                         Float_t p2y = track->RoICentre(j).Y() + track->RoIRadius(j)*sin(t);
218                         Float_t p2z = track->RoICentre(j).Z();
219                         roi->AddLine(p1x, p1y, p1z, p2x, p2y, p2z);
220                         p1x = p2x;
221                         p1y = p2y;
222                         p1z = p2z;
223                 }
224                 roi->AddLine(p1x, p1y, p1z, p0x, p0y, p0z);
225                 pointset->AddElement(roi);
226         }
227         
228         list->AddElement(pointset);
229 }
230
231
232 void FillData(Int_t eventId)
233 {
234         AliHLTMUONEvent* dhltEvent = dynamic_cast<AliHLTMUONEvent*>( gDHLTFile->Get(Form("AliHLTMUONEvent;%d", eventId+1)) );
235         if (dhltEvent == NULL)
236         {
237                 cerr << "ERROR: Could not find dHLT data for event " << eventId << endl;
238                 return;
239         }
240         
241         TEveElementList* list = new TEveElementList("dHLTData", "dHLT data");
242         gEve->AddElement(list);
243         
244         TArrayD px, py, pz;
245         for (int i = 0; i < dhltEvent->DataObjects().GetEntriesFast(); i++)
246         {
247                 if (dhltEvent->DataObjects()[i]->IsA() == AliHLTMUONRecHit::Class())
248                 {
249                         const AliHLTMUONRecHit* hit = dynamic_cast<const AliHLTMUONRecHit*>( dhltEvent->DataObjects()[i] );
250                         px.Set(px.GetSize()+1);
251                         py.Set(py.GetSize()+1);
252                         pz.Set(pz.GetSize()+1);
253                         px[px.GetSize()-1] = hit->X();
254                         py[py.GetSize()-1] = hit->Y();
255                         pz[pz.GetSize()-1] = hit->Z();
256                         continue;
257                 }
258                 else if (dhltEvent->DataObjects()[i]->IsA() == AliHLTMUONTriggerRecord::Class())
259                 {
260                         const AliHLTMUONTriggerRecord* trigrec = dynamic_cast<const AliHLTMUONTriggerRecord*>( dhltEvent->DataObjects()[i] );
261                         FillData(list, trigrec);
262                 }
263                 else if (dhltEvent->DataObjects()[i]->IsA() == AliHLTMUONMansoTrack::Class())
264                 {
265                         const AliHLTMUONMansoTrack* track = dynamic_cast<const AliHLTMUONMansoTrack*>( dhltEvent->DataObjects()[i] );
266                         FillData(list, track);
267                 }
268         }
269         
270         TEvePointSet* mps = new TEvePointSet(px.GetSize());
271         mps->SetName("RecHits");
272         mps->SetTitle("dHLT reconstructed hits");
273         mps->SetMarkerStyle(28);
274         mps->SetMarkerColor(kYellow);
275         mps->SetMarkerSize(3);
276         for (int i = 0; i < px.GetSize(); ++i)
277         {
278                 mps->SetPoint(i, px[i], py[i], pz[i]);
279         }
280         list->AddElement(mps);
281 }