ROOT logo
/**************************************************************************
 * This file is property of and copyright by the ALICE HLT Project        *
 * All rights reserved.                                                   *
 *                                                                        *
 * Primary Authors:                                                       *
 *   Artur Szostak <artursz@iafrica.com>                                  *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

// $Id: DisplaydHLTData.C 37070 2009-11-20 13:53:08Z aszostak $

/**
 * \ingroup macros
 * \file DisplaydHLTData.C
 * \brief Macro for displaying rootified dHLT data generated with RunChain.C
 *
 * This macro is used to display the dHLT data generated by the RunChain.C macro
 * with the "root" option for making the output data. Optionally the dHLTRawData.root
 * file which is generated during a AliRoot offline reconstruction can also be
 * displayed using this macro.
 * After having generated the dHLT raw data file (called <i>output.root</i> for example)
 * the following command can be executed in an alieve session to display both
 * MUON and dHLT data:
 * \code
 *   > gSystem->Load("libAliHLTMUON.so");
 *   > .L $ALICE_ROOT/EVE/macros/alieve_init.C
 *   > .L $ALICE_ROOT/EVE/alice-macros/event_goto.C
 *   > .L $ALICE_ROOT/EVE/alice-macros/MUON_displayData.C
 *   > .L $ALICE_ROOT/HLT/MUON/macros/DisplaydHLTData.C
 *   > alieve_init("OCDBpath","DataPath",EventNumber);
 *   > MUON_displayData(1,1,1);
 *   > DisplaydHLTData("output.root");
 * \endcode
 * Where <i>OCDBpath</i> should be replaced by the path to the OCDB database,
 * <i>DataPath</i> should be the directory of the raw data or raw data root file and
 * <i>EventNumber</i> is the event number to load.
 *
 * \author Artur Szostak <artursz@iafrica.com>
 */

#if !defined(__CINT__) || defined(__MAKECINT__)
#include "AliEveEventManager.h"
#include "AliHLTMUONTriggerRecord.h"
#include "AliHLTMUONRecHit.h"
#include "AliHLTMUONMansoTrack.h"
#include "AliHLTMUONEvent.h"
#include "TEveManager.h"
#include "TEveElement.h"
#include "TEvePointSet.h"
#include "TEveStraightLineSet.h"
#include "TArrayD.h"
#include "TFile.h"
#include "TString.h"
#include "TClassTable.h"
#include "TSystem.h"
#include <iostream>
using std::cerr;
using std::endl;
#endif


TFile* gDHLTFile = NULL;

void FillData(Int_t eventId);


void DisplaydHLTData(const char* dHLTfilename = "output.root")
{
	// Display dHLT data.
	
	if (gClassTable->GetID("AliHLTMUONEvent") < 0)
	{
		gSystem->Load("libAliHLTMUON.so");
	}
	
	if (AliEveEventManager::GetMaster() == NULL)
	{
		cerr << "ERROR: alieve event not initialised, use alieve_init(...)" << endl;
		return;
	}
	
	gEve->DisableRedraw();
	
	TString filename = dHLTfilename;
	TString tmpfilename = filename;
	if (gSystem->FindFile("", tmpfilename) == NULL)
	{
		tmpfilename = filename;
		if (gSystem->FindFile(".", tmpfilename) == NULL)
		{
			TString filename = TString(AliEveEventManager::GetMaster()->GetTitle());
			filename += "/";
			filename += dHLTfilename;
		}
	}
	if (gDHLTFile == NULL)
	{
		gDHLTFile = new TFile(filename.Data(), "READ");
	}
	else if (filename != gDHLTFile->GetName())
	{
		delete gDHLTFile;
		gDHLTFile = new TFile(filename.Data(), "READ");
	}
	
	FillData(AliEveEventManager::GetMaster()->GetEventId());
	
	gEve->Redraw3D(kTRUE);
	gEve->EnableRedraw();
}


void FillData(TEveElementList* list, const AliHLTMUONTriggerRecord* trigrec)
{
	// Count the number of points in the trigger record.
	Int_t pointCount = 0;
	for (int i = 11; i <= 14; ++i)
	{
		if (trigrec->Hit(i) != TVector3(0,0,0)) ++pointCount;
	}
	
	// Create and fill the point set for the trigger record.
	TEvePointSet* pointset = new TEvePointSet(pointCount);
	pointset->SetName(Form("TriggerRecord%d", trigrec->Id()));
	pointset->SetTitle(Form("dHLT trigger record ID = %d", trigrec->Id()));
	pointset->SetMarkerStyle(28);
	pointset->SetMarkerColor(kYellow);
	pointset->SetMarkerSize(3);
	Int_t ipnt = 0;
	for (int i = 11; i <= 14; ++i)
	{
		if (trigrec->Hit(i) == TVector3(0,0,0)) continue;
		pointset->SetPoint(ipnt, trigrec->Hit(i).X(), trigrec->Hit(i).Y(), trigrec->Hit(i).Z());
		++ipnt;
	}
	
	list->AddElement(pointset);
}


void FillData(TEveElementList* list, const AliHLTMUONMansoTrack* track)
{
	// Count the points in the track.
	Int_t pointCount = 0;
	for (int i = 7; i <= 10; ++i)
	{
		const AliHLTMUONRecHit* hit = track->Hit(i);
		if (hit != NULL) ++pointCount;
	}
	const AliHLTMUONTriggerRecord* trigrec = track->TriggerRecord();
	if (trigrec != NULL)
	{
		for (int i = 11; i <= 14; ++i)
		{
			if (trigrec->Hit(i) != TVector3(0,0,0)) ++pointCount;
		}
	}
	
	// Create and fill the point set for the track.
	TEvePointSet* pointset = new TEvePointSet(pointCount);
	pointset->SetName(Form("Track%d", track->Id()));
	pointset->SetTitle(Form("dHLT track ID = %d", track->Id()));
	if (track->Id() != -1)
	{
		pointset->SetMarkerStyle(20);
		pointset->SetMarkerColor(kGreen);
		pointset->SetMarkerSize(1.5);
	}
	else
	{
		pointset->SetMarkerStyle(28);
		pointset->SetMarkerColor(kYellow);
		pointset->SetMarkerSize(3);
	}
	Int_t ipnt = 0;
	if (trigrec != NULL)
	{
		for (int i = 11; i <= 14; ++i)
		{
			if (trigrec->Hit(i) == TVector3(0,0,0)) continue;
			pointset->SetPoint(ipnt, trigrec->Hit(i).X(), trigrec->Hit(i).Y(), trigrec->Hit(i).Z());
			++ipnt;
		}
	}
	for (int j = 7; j <= 10; ++j)
	{
		const AliHLTMUONRecHit* hit = track->Hit(j);
		if (hit == NULL) continue;
		pointset->SetPoint(ipnt, hit->X(), hit->Y(), hit->Z());
		++ipnt;
	}
	
	for (int j = 7; j <= 10; ++j)
	{
		if (track->RoIRadius(j) == -1) continue;
		TEveStraightLineSet* roi = new TEveStraightLineSet(
				Form("RoI%d", j),
				Form("Region of interest for chamber %d", j)
			);
		Float_t p0x = track->RoICentre(j).X() + track->RoIRadius(j);
		Float_t p0y = track->RoICentre(j).Y();
		Float_t p0z = track->RoICentre(j).Z();
		Float_t p1x = p0x;
		Float_t p1y = p0y;
		Float_t p1z = p0z;
		for (int i = 0; i < 32; ++i)
		{
			Double_t t = Double_t(i) / 32. * 2. * TMath::Pi();
			Float_t p2x = track->RoICentre(j).X() + track->RoIRadius(j)*cos(t);
			Float_t p2y = track->RoICentre(j).Y() + track->RoIRadius(j)*sin(t);
			Float_t p2z = track->RoICentre(j).Z();
			roi->AddLine(p1x, p1y, p1z, p2x, p2y, p2z);
			p1x = p2x;
			p1y = p2y;
			p1z = p2z;
		}
		roi->AddLine(p1x, p1y, p1z, p0x, p0y, p0z);
		pointset->AddElement(roi);
	}
	
	list->AddElement(pointset);
}


void FillData(Int_t eventId)
{
	AliHLTMUONEvent* dhltEvent = dynamic_cast<AliHLTMUONEvent*>( gDHLTFile->Get(Form("AliHLTMUONEvent;%d", eventId+1)) );
	if (dhltEvent == NULL)
	{
		cerr << "ERROR: Could not find dHLT data for event " << eventId << endl;
		return;
	}
	
	TEveElementList* list = new TEveElementList("dHLTData", "dHLT data");
	gEve->AddElement(list);
	
	TArrayD px, py, pz;
	for (int i = 0; i < dhltEvent->DataObjects().GetEntriesFast(); i++)
	{
		if (dhltEvent->DataObjects()[i]->IsA() == AliHLTMUONRecHit::Class())
		{
			const AliHLTMUONRecHit* hit = dynamic_cast<const AliHLTMUONRecHit*>( dhltEvent->DataObjects()[i] );
			px.Set(px.GetSize()+1);
			py.Set(py.GetSize()+1);
			pz.Set(pz.GetSize()+1);
			px[px.GetSize()-1] = hit->X();
			py[py.GetSize()-1] = hit->Y();
			pz[pz.GetSize()-1] = hit->Z();
			continue;
		}
		else if (dhltEvent->DataObjects()[i]->IsA() == AliHLTMUONTriggerRecord::Class())
		{
			const AliHLTMUONTriggerRecord* trigrec = dynamic_cast<const AliHLTMUONTriggerRecord*>( dhltEvent->DataObjects()[i] );
			FillData(list, trigrec);
		}
		else if (dhltEvent->DataObjects()[i]->IsA() == AliHLTMUONMansoTrack::Class())
		{
			const AliHLTMUONMansoTrack* track = dynamic_cast<const AliHLTMUONMansoTrack*>( dhltEvent->DataObjects()[i] );
			FillData(list, track);
		}
	}
	
	TEvePointSet* mps = new TEvePointSet(px.GetSize());
	mps->SetName("RecHits");
	mps->SetTitle("dHLT reconstructed hits");
	mps->SetMarkerStyle(28);
	mps->SetMarkerColor(kYellow);
	mps->SetMarkerSize(3);
	for (int i = 0; i < px.GetSize(); ++i)
	{
		mps->SetPoint(i, px[i], py[i], pz[i]);
	}
	list->AddElement(mps);
}
 DisplaydHLTData.C:1
 DisplaydHLTData.C:2
 DisplaydHLTData.C:3
 DisplaydHLTData.C:4
 DisplaydHLTData.C:5
 DisplaydHLTData.C:6
 DisplaydHLTData.C:7
 DisplaydHLTData.C:8
 DisplaydHLTData.C:9
 DisplaydHLTData.C:10
 DisplaydHLTData.C:11
 DisplaydHLTData.C:12
 DisplaydHLTData.C:13
 DisplaydHLTData.C:14
 DisplaydHLTData.C:15
 DisplaydHLTData.C:16
 DisplaydHLTData.C:17
 DisplaydHLTData.C:18
 DisplaydHLTData.C:19
 DisplaydHLTData.C:20
 DisplaydHLTData.C:21
 DisplaydHLTData.C:22
 DisplaydHLTData.C:23
 DisplaydHLTData.C:24
 DisplaydHLTData.C:25
 DisplaydHLTData.C:26
 DisplaydHLTData.C:27
 DisplaydHLTData.C:28
 DisplaydHLTData.C:29
 DisplaydHLTData.C:30
 DisplaydHLTData.C:31
 DisplaydHLTData.C:32
 DisplaydHLTData.C:33
 DisplaydHLTData.C:34
 DisplaydHLTData.C:35
 DisplaydHLTData.C:36
 DisplaydHLTData.C:37
 DisplaydHLTData.C:38
 DisplaydHLTData.C:39
 DisplaydHLTData.C:40
 DisplaydHLTData.C:41
 DisplaydHLTData.C:42
 DisplaydHLTData.C:43
 DisplaydHLTData.C:44
 DisplaydHLTData.C:45
 DisplaydHLTData.C:46
 DisplaydHLTData.C:47
 DisplaydHLTData.C:48
 DisplaydHLTData.C:49
 DisplaydHLTData.C:50
 DisplaydHLTData.C:51
 DisplaydHLTData.C:52
 DisplaydHLTData.C:53
 DisplaydHLTData.C:54
 DisplaydHLTData.C:55
 DisplaydHLTData.C:56
 DisplaydHLTData.C:57
 DisplaydHLTData.C:58
 DisplaydHLTData.C:59
 DisplaydHLTData.C:60
 DisplaydHLTData.C:61
 DisplaydHLTData.C:62
 DisplaydHLTData.C:63
 DisplaydHLTData.C:64
 DisplaydHLTData.C:65
 DisplaydHLTData.C:66
 DisplaydHLTData.C:67
 DisplaydHLTData.C:68
 DisplaydHLTData.C:69
 DisplaydHLTData.C:70
 DisplaydHLTData.C:71
 DisplaydHLTData.C:72
 DisplaydHLTData.C:73
 DisplaydHLTData.C:74
 DisplaydHLTData.C:75
 DisplaydHLTData.C:76
 DisplaydHLTData.C:77
 DisplaydHLTData.C:78
 DisplaydHLTData.C:79
 DisplaydHLTData.C:80
 DisplaydHLTData.C:81
 DisplaydHLTData.C:82
 DisplaydHLTData.C:83
 DisplaydHLTData.C:84
 DisplaydHLTData.C:85
 DisplaydHLTData.C:86
 DisplaydHLTData.C:87
 DisplaydHLTData.C:88
 DisplaydHLTData.C:89
 DisplaydHLTData.C:90
 DisplaydHLTData.C:91
 DisplaydHLTData.C:92
 DisplaydHLTData.C:93
 DisplaydHLTData.C:94
 DisplaydHLTData.C:95
 DisplaydHLTData.C:96
 DisplaydHLTData.C:97
 DisplaydHLTData.C:98
 DisplaydHLTData.C:99
 DisplaydHLTData.C:100
 DisplaydHLTData.C:101
 DisplaydHLTData.C:102
 DisplaydHLTData.C:103
 DisplaydHLTData.C:104
 DisplaydHLTData.C:105
 DisplaydHLTData.C:106
 DisplaydHLTData.C:107
 DisplaydHLTData.C:108
 DisplaydHLTData.C:109
 DisplaydHLTData.C:110
 DisplaydHLTData.C:111
 DisplaydHLTData.C:112
 DisplaydHLTData.C:113
 DisplaydHLTData.C:114
 DisplaydHLTData.C:115
 DisplaydHLTData.C:116
 DisplaydHLTData.C:117
 DisplaydHLTData.C:118
 DisplaydHLTData.C:119
 DisplaydHLTData.C:120
 DisplaydHLTData.C:121
 DisplaydHLTData.C:122
 DisplaydHLTData.C:123
 DisplaydHLTData.C:124
 DisplaydHLTData.C:125
 DisplaydHLTData.C:126
 DisplaydHLTData.C:127
 DisplaydHLTData.C:128
 DisplaydHLTData.C:129
 DisplaydHLTData.C:130
 DisplaydHLTData.C:131
 DisplaydHLTData.C:132
 DisplaydHLTData.C:133
 DisplaydHLTData.C:134
 DisplaydHLTData.C:135
 DisplaydHLTData.C:136
 DisplaydHLTData.C:137
 DisplaydHLTData.C:138
 DisplaydHLTData.C:139
 DisplaydHLTData.C:140
 DisplaydHLTData.C:141
 DisplaydHLTData.C:142
 DisplaydHLTData.C:143
 DisplaydHLTData.C:144
 DisplaydHLTData.C:145
 DisplaydHLTData.C:146
 DisplaydHLTData.C:147
 DisplaydHLTData.C:148
 DisplaydHLTData.C:149
 DisplaydHLTData.C:150
 DisplaydHLTData.C:151
 DisplaydHLTData.C:152
 DisplaydHLTData.C:153
 DisplaydHLTData.C:154
 DisplaydHLTData.C:155
 DisplaydHLTData.C:156
 DisplaydHLTData.C:157
 DisplaydHLTData.C:158
 DisplaydHLTData.C:159
 DisplaydHLTData.C:160
 DisplaydHLTData.C:161
 DisplaydHLTData.C:162
 DisplaydHLTData.C:163
 DisplaydHLTData.C:164
 DisplaydHLTData.C:165
 DisplaydHLTData.C:166
 DisplaydHLTData.C:167
 DisplaydHLTData.C:168
 DisplaydHLTData.C:169
 DisplaydHLTData.C:170
 DisplaydHLTData.C:171
 DisplaydHLTData.C:172
 DisplaydHLTData.C:173
 DisplaydHLTData.C:174
 DisplaydHLTData.C:175
 DisplaydHLTData.C:176
 DisplaydHLTData.C:177
 DisplaydHLTData.C:178
 DisplaydHLTData.C:179
 DisplaydHLTData.C:180
 DisplaydHLTData.C:181
 DisplaydHLTData.C:182
 DisplaydHLTData.C:183
 DisplaydHLTData.C:184
 DisplaydHLTData.C:185
 DisplaydHLTData.C:186
 DisplaydHLTData.C:187
 DisplaydHLTData.C:188
 DisplaydHLTData.C:189
 DisplaydHLTData.C:190
 DisplaydHLTData.C:191
 DisplaydHLTData.C:192
 DisplaydHLTData.C:193
 DisplaydHLTData.C:194
 DisplaydHLTData.C:195
 DisplaydHLTData.C:196
 DisplaydHLTData.C:197
 DisplaydHLTData.C:198
 DisplaydHLTData.C:199
 DisplaydHLTData.C:200
 DisplaydHLTData.C:201
 DisplaydHLTData.C:202
 DisplaydHLTData.C:203
 DisplaydHLTData.C:204
 DisplaydHLTData.C:205
 DisplaydHLTData.C:206
 DisplaydHLTData.C:207
 DisplaydHLTData.C:208
 DisplaydHLTData.C:209
 DisplaydHLTData.C:210
 DisplaydHLTData.C:211
 DisplaydHLTData.C:212
 DisplaydHLTData.C:213
 DisplaydHLTData.C:214
 DisplaydHLTData.C:215
 DisplaydHLTData.C:216
 DisplaydHLTData.C:217
 DisplaydHLTData.C:218
 DisplaydHLTData.C:219
 DisplaydHLTData.C:220
 DisplaydHLTData.C:221
 DisplaydHLTData.C:222
 DisplaydHLTData.C:223
 DisplaydHLTData.C:224
 DisplaydHLTData.C:225
 DisplaydHLTData.C:226
 DisplaydHLTData.C:227
 DisplaydHLTData.C:228
 DisplaydHLTData.C:229
 DisplaydHLTData.C:230
 DisplaydHLTData.C:231
 DisplaydHLTData.C:232
 DisplaydHLTData.C:233
 DisplaydHLTData.C:234
 DisplaydHLTData.C:235
 DisplaydHLTData.C:236
 DisplaydHLTData.C:237
 DisplaydHLTData.C:238
 DisplaydHLTData.C:239
 DisplaydHLTData.C:240
 DisplaydHLTData.C:241
 DisplaydHLTData.C:242
 DisplaydHLTData.C:243
 DisplaydHLTData.C:244
 DisplaydHLTData.C:245
 DisplaydHLTData.C:246
 DisplaydHLTData.C:247
 DisplaydHLTData.C:248
 DisplaydHLTData.C:249
 DisplaydHLTData.C:250
 DisplaydHLTData.C:251
 DisplaydHLTData.C:252
 DisplaydHLTData.C:253
 DisplaydHLTData.C:254
 DisplaydHLTData.C:255
 DisplaydHLTData.C:256
 DisplaydHLTData.C:257
 DisplaydHLTData.C:258
 DisplaydHLTData.C:259
 DisplaydHLTData.C:260
 DisplaydHLTData.C:261
 DisplaydHLTData.C:262
 DisplaydHLTData.C:263
 DisplaydHLTData.C:264
 DisplaydHLTData.C:265
 DisplaydHLTData.C:266
 DisplaydHLTData.C:267
 DisplaydHLTData.C:268
 DisplaydHLTData.C:269
 DisplaydHLTData.C:270
 DisplaydHLTData.C:271
 DisplaydHLTData.C:272
 DisplaydHLTData.C:273
 DisplaydHLTData.C:274
 DisplaydHLTData.C:275
 DisplaydHLTData.C:276
 DisplaydHLTData.C:277
 DisplaydHLTData.C:278
 DisplaydHLTData.C:279
 DisplaydHLTData.C:280
 DisplaydHLTData.C:281
 DisplaydHLTData.C:282