ROOT logo
//-*- Mode: C++ -*-

// ** USED macros :
// ***************************************************
// - hlt_alieve_init.C
// - VizDB_scan.C
// - geom_gentle_hlt.C
// - geom_gentle_muon.C
// ***************************************************

#if !defined(__CINT__) || defined(__MAKECINT__)

//****************** ROOT ******************************************
#include "TRandom.h"
#include "TVirtualPad.h"
#include "TGLViewer.h"
#include "TThread.h"
#include "TGFileBrowser.h"
#include "TStyle.h"
#include "TList.h"
#include "TDirectory.h"
#include "TFile.h"
#include "TH2.h"
#include "TCanvas.h"
#include "TColor.h"
#include "TVector3.h"

//****************** ROOT/EVE **************************************
#include "TEveManager.h"

#include "AliEveHOMERManager.h"
#include "AliEveHLTEventManagerOffline.h"
#include "geom_gentle_hlt.C"

//***************************************************************
#include "HLT/rec/AliHLTReconstructor.h"



#endif



// -----------------------------------------------------------------
// --                       Geometry / Scenes                     --
// -----------------------------------------------------------------

TEveGeoShape *gGeomGentle     = 0;
TEveGeoShape *gGeomGentleRPhi = 0;
TEveGeoShape *gGeomGentleRhoZ = 0;
TEveGeoShape *gGeomGentleTRD  = 0;
TEveGeoShape *gGeomGentleMUON = 0;

TEveScene *gRPhiGeomScene  = 0;
TEveScene *gRhoZGeomScene  = 0;
TEveScene *gRPhiEventScene = 0;
TEveScene *gRhoZEventScene = 0;

TEveProjectionManager *gRPhiMgr = 0;
TEveProjectionManager *gRhoZMgr = 0;

TEveViewer *g3DView   = 0;
TEveViewer *gRPhiView = 0;
TEveViewer *gRhoZView = 0;

// -----------------------------------------------------------------
// --                Geometry / Scenes Parameters                 --
// -----------------------------------------------------------------

// -- Parameters to show different geometries
Bool_t gShowMUON     = kTRUE;
Bool_t gShowMUONRPhi = kFALSE;
Bool_t gShowMUONRhoZ = kTRUE;
Bool_t gShowTRD      = kFALSE;


// -----------------------------------------------------------------
// --                         Members                            --
// -----------------------------------------------------------------

// -- Timer for automatic event loop
TTimer                                    eventTimer;
TTimer                                    eventTimerFast;

// -- HOMERManager
AliEveHLTEventManagerOffline*                       geventManager      = 0;

// -- Geometry Manager 
TGeoManager*                              gGeoManager        = 0;
AliPHOSGeometry*                          gPHOSGeom          = 0;

// -- Cluster members
TEvePointSet*                             gSPDClusters       = 0;
TEvePointSet*                             gSSDClusters       = 0;
TEvePointSet*                             gSDDClusters       = 0;
TEvePointSet*                             gTRDClusters       = 0;
TEvePointSetArray*                        gTRDColClusters    = 0;
TEvePointSet*                             gTPCClusters       = 0;
TEvePointSet*                             gTPCTestClusters       = 0;
TEvePointSetArray*                        gTPCColClusters    = 0;
TEveBoxSet*                               gPHOSBoxSet[5]     = {0, 0, 0, 0, 0}; 
TEveBoxSet*                               gEMCALBoxSet[13]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
TEvePointSet*                             gMUONClusters      = 0;
TEveStraightLineSet*                      gMUONTracks        = 0;

// -- Text output members
TEveText*                                 gHLTText           = 0;

// -- Tracks members
TEveTrackList*                            gTPCTrack          = 0;

// -- Canvas for histograms
TCanvas*                                  gTRDCanvas         = 0;
TCanvas*                                  gTPCCanvas         = 0;
TCanvas*                                  gTPCClustCanvas          = 0;
TCanvas*                                  gTRDCalibCanvas    = 0;
TCanvas*                                  gTRDEORCanvas      = 0;
TCanvas*                                  gPrimVertexCanvas  = 0;
TCanvas*                                  gSPDVertexCanvas   = 0;
TCanvas*                                  gITSCanvas         = 0;
TCanvas*                                  gSSDCanvas0        = 0;
TCanvas*                                  gSSDCanvas1        = 0;
TCanvas*                                  gV0Canvas          = 0;
TCanvas*                                  gPHOSCanvas          = NULL;
TCanvas*                                  gEMCALCanvas          = 0;

// -- vertex --
Int_t                                     gSPDVertexHistoCount  = 0;



// -- TRD --
Int_t                                     gTRDHistoCount     = 0;
Int_t                                     gTRDEvents         = 0;
Int_t                                     gTRDBins           = 12;

// -- TPC --
Int_t                                     gTPCBins           = 15;
TH1F*                                     gTPCCharge         = 0;
TH1F*                                     gTPCQMax           = 0;
TH1F*                                     gTPCQMaxOverCharge = 0;

TH1F*                                     gTPCPt        = 0; // KK
TH1F*                                     gTPCEta       = 0; 
TH1F*                                     gTPCPsi       = 0; 
TH1F*                                     gTPCnClusters = 0; 
TH1F*                                     gTPCMult      = 0;

// -- PHOS --
TEveElementList*                          gPHOSElementList   = 0;
Int_t                                     gPHOSHistoCount    =0;
// -- EMCAL
TEveElementList*                          gEMCALElementList  = 0;
TGeoNode*                                 gEMCALNode         = 0;
Int_t                                     gEMCALHistoCount    =0;

// --- Flag if eventloop is running
Bool_t                                    gEventLoopStarted = kFALSE;



//Container for gGeoManager till it is broken
TGeoManager *fGeoManager = 0;
// -----------------------------------------------------------------
// --                          Methods                            --
// -----------------------------------------------------------------

Int_t initializeEveViewer( Bool_t showBarrel, Bool_t showMuon );

void writeToFile();


// #################################################################
// #################################################################
// #################################################################

// -----------------------------------------------------------------
void off ( Bool_t showBarrel = kTRUE, Bool_t showMuon = kFALSE ) {

  // -- Loading Geometry
  // ---------------------
  Int_t run = 67179;
  AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
  AliCDBManager::Instance()->SetRun(run);
  AliGeomManager::LoadGeometry();
  // The default in the simulation is the following line
  // TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", -1., -1, AliMagF::k5kG));
  // However for the current setting of +ve L3 and +ve Dipole magnetic field
  // the following setting creates the field close to real field with currect polarity
  if(showMuon)
    TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", 1., 1, AliMagF::k5kG));

  // Get the pointer to gGeoManager before it's broken (bug in alieve)
  fGeoManager = gGeoManager;

    // -- Initialize pointsets and add macros
  // ----------------------------------------
  //TEveUtil::LoadMacro("hlt_alieve_init.C");
  //hlt_alieve_init(".", -1);

  // -- Initialize Eve
  // -------------------
  initializeEveViewer( showBarrel, showMuon );

  // -- Reset gGeoManager to the original pointer
  // ----------------------------------------------

  // -- Finalize Eve
  // -----------------
  gSystem->ProcessEvents();
  gEve->Redraw3D(kTRUE);

  // -- Create new hM object
  // -------------------------
 
  gEventManager = new AliEveHLTEventManagerOffline("/home/slindal/alice/data/PbPb/AliESDs.root");

  gEventManager->SetEveManager(gEve);
  gEventManager->SetGeoManager(gGeoManager);
  gEventManager->SetRPhiManager(gRPhiMgr);
  gEventManager->SetRPhiEventScene(gRPhiEventScene);
  gEventManager->SetRPhiViewer(gRPhiView);
  gEventManager->SetRhoZManager(gRhoZMgr);
  gEventManager->SetRhoZEventScene(gRhoZEventScene);
  gEventManager->SetRhoZViewer(gRhoZView);
  //gEventManager->SetBarrelFlag(showBarrel);
  //gEventManager->SetMuonFlag(showMuon);


  // -- Add hM to EveTree
  // ----------------------
  gEve->AddToListTree(gEventManager, kTRUE);

  // -- Create SourceList
  // ----------------------



  gGeoManager = fGeoManager;
  

}

// -------------------------------------------------------------------------
Int_t initializeEveViewer( Bool_t showBarrel, Bool_t showMuon ) {
  
  //=============================================================================
  // Visualization database
  //============================================================================

  TEveUtil::AssertMacro("VizDB_scan.C");
  
  //  alieve_vizdb();
  


  //==============================================================================
  // -- Geometry, scenes, projections and viewers
  //==============================================================================

  TEveBrowser         *browser = gEve->GetBrowser();
  browser->ShowCloseTab(kFALSE);
  
  // -- Disable extra geometry
  // ---------------------------
  if (!showMuon)
    gShowMUON = gShowMUONRPhi = gShowMUONRhoZ = kFALSE;
  
  // -- Load Geometry
  // ------------------
  TEveUtil::LoadMacro("geom_gentle_hlt.C");
  gGeomGentle = geom_gentle_hlt();
  gGeomGentleRPhi = geom_gentle_rphi(); gGeomGentleRPhi->IncDenyDestroy();
  gGeomGentleRhoZ = geom_gentle_rhoz(); gGeomGentleRhoZ->IncDenyDestroy();
  gGeomGentleTRD  = geom_gentle_trd();

  gGeoManager = fGeoManager;

  gEMCALNode = gGeoManager->GetTopVolume()->FindNode("XEN1_1");

  TEveGeoTopNode* emcal_re = new TEveGeoTopNode(gGeoManager, gEMCALNode);
  gEve->AddGlobalElement(emcal_re);
  gEve->Redraw3D();

  if (gShowMUON) 
    gGeomGentleMUON = geom_gentle_muon(kFALSE);
  
  // -- Scenes
  // -----------
  gRPhiGeomScene  = gEve->SpawnNewScene("RPhi Geometry",
                    "Scene holding projected geometry for the RPhi view.");
  gRhoZGeomScene  = gEve->SpawnNewScene("RhoZ Geometry",
		    "Scene holding projected geometry for the RhoZ view.");
  gRPhiEventScene = gEve->SpawnNewScene("RPhi Event Data",
		    "Scene holding projected geometry for the RPhi view.");
  gRhoZEventScene = gEve->SpawnNewScene("RhoZ Event Data",
		    "Scene holding projected geometry for the RhoZ view.");

  // -- Projection managers
  // ------------------------

  gRPhiMgr = new TEveProjectionManager();
  gRPhiMgr->SetProjection(TEveProjection::kPT_RPhi);
  gEve->AddToListTree(gRPhiMgr, kFALSE);
  {
    TEveProjectionAxes* a = new TEveProjectionAxes(gRPhiMgr);
    a->SetMainColor(kWhite);
    a->SetTitle("R-Phi");
    a->SetTitleSize(0.05);
    a->SetTitleFont(102);
    a->SetLabelSize(0.025);
    a->SetLabelFont(102);
    gRPhiGeomScene->AddElement(a);
  }
  gRPhiMgr->SetCurrentDepth(-10);
  gRPhiMgr->ImportElements(gGeomGentleRPhi, gRPhiGeomScene);
  gRPhiMgr->SetCurrentDepth(0);
  gRPhiMgr->ImportElements(gGeomGentleTRD, gRPhiGeomScene);
  if (gShowMUONRPhi) gRPhiMgr->ImportElements(gGeomGentleMUON, gRPhiGeomScene);

  gRhoZMgr = new TEveProjectionManager();
  gRhoZMgr->SetProjection(TEveProjection::kPT_RhoZ);
  gEve->AddToListTree(gRhoZMgr, kFALSE);
  {
    TEveProjectionAxes* a = new TEveProjectionAxes(gRhoZMgr);
    a->SetMainColor(kWhite);
    a->SetTitle("Rho-Z");
    a->SetTitleSize(0.05);
    a->SetTitleFont(102);
    a->SetLabelSize(0.025);
    a->SetLabelFont(102);
    gRhoZGeomScene->AddElement(a);
  }
  gRhoZMgr->SetCurrentDepth(-10);
  gRhoZMgr->ImportElements(gGeomGentleRhoZ, gRhoZGeomScene);
  gRhoZMgr->SetCurrentDepth(0);
  gRhoZMgr->ImportElements(gGeomGentleTRD, gRhoZGeomScene);
  
  if (gShowMUONRhoZ) gRhoZMgr->ImportElements(gGeomGentleMUON, gRhoZGeomScene);

  // -- Viewers
  // ------------

  TEveWindowSlot *slot = TEveWindow::CreateWindowInTab(browser->GetTabRight());
  TEveWindowPack *pack = slot->MakePack();
  pack->SetElementName("Multi View");
  pack->SetHorizontal();
  pack->SetShowTitleBar(kFALSE);
  pack->NewSlot()->MakeCurrent();
  g3DView = gEve->SpawnNewViewer("3D View", "");
  g3DView->AddScene(gEve->GetGlobalScene());
  g3DView->AddScene(gEve->GetEventScene());


  pack = pack->NewSlot()->MakePack();
  pack->SetShowTitleBar(kFALSE);
  pack->NewSlot()->MakeCurrent();
  gRPhiView = gEve->SpawnNewViewer("RPhi View", "");
  gRPhiView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
  gRPhiView->AddScene(gRPhiGeomScene);
  gRPhiView->AddScene(gRPhiEventScene);

  pack->NewSlot()->MakeCurrent();
  gRhoZView = gEve->SpawnNewViewer("RhoZ View", "");
  gRhoZView->GetGLViewer()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
  gRhoZView->AddScene(gRhoZGeomScene);
  gRhoZView->AddScene(gRhoZEventScene);


   
  //Add HLT Text to windows
 
  TGLOverlayButton *ob1 = new TGLOverlayButton(g3DView->GetGLViewer(),  "HLT", 0, 20, 110, 60);
  ob1->SetAlphaValues(0.8, 0.8);
  //  cout << "color" << ob1->GetBackColor() << endl;
  //ob1->SetBackColor(8421631);
  //ob1->SetBackColor(10492431);
  TGLOverlayButton *ob2 = new TGLOverlayButton(g3DView->GetGLViewer(),  "ALICE", 0, 0, 110, 20);
  ob2->SetAlphaValues(0.8, 0.8);
  //ob2->SetBackColor(0.2);
  TGLOverlayButton *ob3 = new TGLOverlayButton(gEve->GetDefaultGLViewer(),  "HLT", 0, 20, 110, 60);
  ob3->SetAlphaValues(0.8, 0.8);
  TGLOverlayButton *ob4 = new TGLOverlayButton(gEve->GetDefaultGLViewer(),  "ALICE", 0, 0, 110, 20);
  ob4->SetAlphaValues(0.8, 0.8);


  TGLOverlayButton *ne = new TGLOverlayButton(gEve->GetDefaultGLViewer(),  "Next Event", 110, 0, 210, 20);
  ne->SetAlphaValues(0.0, 0.8);

  // -- List of Viewers
  // --------------------

  TEveViewerList *viewerlist = new TEveViewerList();
  viewerlist->AddElement(gEve->GetDefaultViewer());
  
  viewerlist->AddElement(g3DView);
  viewerlist->AddElement(gRhoZView);
  viewerlist->AddElement(gRPhiView);
  viewerlist->SwitchColorSet();

  //==============================================================================
  // -- Macros / QA histograms
  //==============================================================================

  // -- Registration of per-event macros
  // -------------------------------------

  AliEveMacroExecutor *exec    = new AliEveMacroExecutor();



  gStyle->SetPalette(1, 0);

  gStyle->SetOptFit(1);


  
  return 0;
}






        
 off.C:1
 off.C:2
 off.C:3
 off.C:4
 off.C:5
 off.C:6
 off.C:7
 off.C:8
 off.C:9
 off.C:10
 off.C:11
 off.C:12
 off.C:13
 off.C:14
 off.C:15
 off.C:16
 off.C:17
 off.C:18
 off.C:19
 off.C:20
 off.C:21
 off.C:22
 off.C:23
 off.C:24
 off.C:25
 off.C:26
 off.C:27
 off.C:28
 off.C:29
 off.C:30
 off.C:31
 off.C:32
 off.C:33
 off.C:34
 off.C:35
 off.C:36
 off.C:37
 off.C:38
 off.C:39
 off.C:40
 off.C:41
 off.C:42
 off.C:43
 off.C:44
 off.C:45
 off.C:46
 off.C:47
 off.C:48
 off.C:49
 off.C:50
 off.C:51
 off.C:52
 off.C:53
 off.C:54
 off.C:55
 off.C:56
 off.C:57
 off.C:58
 off.C:59
 off.C:60
 off.C:61
 off.C:62
 off.C:63
 off.C:64
 off.C:65
 off.C:66
 off.C:67
 off.C:68
 off.C:69
 off.C:70
 off.C:71
 off.C:72
 off.C:73
 off.C:74
 off.C:75
 off.C:76
 off.C:77
 off.C:78
 off.C:79
 off.C:80
 off.C:81
 off.C:82
 off.C:83
 off.C:84
 off.C:85
 off.C:86
 off.C:87
 off.C:88
 off.C:89
 off.C:90
 off.C:91
 off.C:92
 off.C:93
 off.C:94
 off.C:95
 off.C:96
 off.C:97
 off.C:98
 off.C:99
 off.C:100
 off.C:101
 off.C:102
 off.C:103
 off.C:104
 off.C:105
 off.C:106
 off.C:107
 off.C:108
 off.C:109
 off.C:110
 off.C:111
 off.C:112
 off.C:113
 off.C:114
 off.C:115
 off.C:116
 off.C:117
 off.C:118
 off.C:119
 off.C:120
 off.C:121
 off.C:122
 off.C:123
 off.C:124
 off.C:125
 off.C:126
 off.C:127
 off.C:128
 off.C:129
 off.C:130
 off.C:131
 off.C:132
 off.C:133
 off.C:134
 off.C:135
 off.C:136
 off.C:137
 off.C:138
 off.C:139
 off.C:140
 off.C:141
 off.C:142
 off.C:143
 off.C:144
 off.C:145
 off.C:146
 off.C:147
 off.C:148
 off.C:149
 off.C:150
 off.C:151
 off.C:152
 off.C:153
 off.C:154
 off.C:155
 off.C:156
 off.C:157
 off.C:158
 off.C:159
 off.C:160
 off.C:161
 off.C:162
 off.C:163
 off.C:164
 off.C:165
 off.C:166
 off.C:167
 off.C:168
 off.C:169
 off.C:170
 off.C:171
 off.C:172
 off.C:173
 off.C:174
 off.C:175
 off.C:176
 off.C:177
 off.C:178
 off.C:179
 off.C:180
 off.C:181
 off.C:182
 off.C:183
 off.C:184
 off.C:185
 off.C:186
 off.C:187
 off.C:188
 off.C:189
 off.C:190
 off.C:191
 off.C:192
 off.C:193
 off.C:194
 off.C:195
 off.C:196
 off.C:197
 off.C:198
 off.C:199
 off.C:200
 off.C:201
 off.C:202
 off.C:203
 off.C:204
 off.C:205
 off.C:206
 off.C:207
 off.C:208
 off.C:209
 off.C:210
 off.C:211
 off.C:212
 off.C:213
 off.C:214
 off.C:215
 off.C:216
 off.C:217
 off.C:218
 off.C:219
 off.C:220
 off.C:221
 off.C:222
 off.C:223
 off.C:224
 off.C:225
 off.C:226
 off.C:227
 off.C:228
 off.C:229
 off.C:230
 off.C:231
 off.C:232
 off.C:233
 off.C:234
 off.C:235
 off.C:236
 off.C:237
 off.C:238
 off.C:239
 off.C:240
 off.C:241
 off.C:242
 off.C:243
 off.C:244
 off.C:245
 off.C:246
 off.C:247
 off.C:248
 off.C:249
 off.C:250
 off.C:251
 off.C:252
 off.C:253
 off.C:254
 off.C:255
 off.C:256
 off.C:257
 off.C:258
 off.C:259
 off.C:260
 off.C:261
 off.C:262
 off.C:263
 off.C:264
 off.C:265
 off.C:266
 off.C:267
 off.C:268
 off.C:269
 off.C:270
 off.C:271
 off.C:272
 off.C:273
 off.C:274
 off.C:275
 off.C:276
 off.C:277
 off.C:278
 off.C:279
 off.C:280
 off.C:281
 off.C:282
 off.C:283
 off.C:284
 off.C:285
 off.C:286
 off.C:287
 off.C:288
 off.C:289
 off.C:290
 off.C:291
 off.C:292
 off.C:293
 off.C:294
 off.C:295
 off.C:296
 off.C:297
 off.C:298
 off.C:299
 off.C:300
 off.C:301
 off.C:302
 off.C:303
 off.C:304
 off.C:305
 off.C:306
 off.C:307
 off.C:308
 off.C:309
 off.C:310
 off.C:311
 off.C:312
 off.C:313
 off.C:314
 off.C:315
 off.C:316
 off.C:317
 off.C:318
 off.C:319
 off.C:320
 off.C:321
 off.C:322
 off.C:323
 off.C:324
 off.C:325
 off.C:326
 off.C:327
 off.C:328
 off.C:329
 off.C:330
 off.C:331
 off.C:332
 off.C:333
 off.C:334
 off.C:335
 off.C:336
 off.C:337
 off.C:338
 off.C:339
 off.C:340
 off.C:341
 off.C:342
 off.C:343
 off.C:344
 off.C:345
 off.C:346
 off.C:347
 off.C:348
 off.C:349
 off.C:350
 off.C:351
 off.C:352
 off.C:353
 off.C:354
 off.C:355
 off.C:356
 off.C:357
 off.C:358
 off.C:359
 off.C:360
 off.C:361
 off.C:362
 off.C:363
 off.C:364
 off.C:365
 off.C:366
 off.C:367
 off.C:368
 off.C:369
 off.C:370
 off.C:371
 off.C:372
 off.C:373
 off.C:374
 off.C:375
 off.C:376
 off.C:377
 off.C:378
 off.C:379
 off.C:380
 off.C:381
 off.C:382
 off.C:383
 off.C:384
 off.C:385
 off.C:386
 off.C:387
 off.C:388
 off.C:389
 off.C:390
 off.C:391
 off.C:392
 off.C:393
 off.C:394
 off.C:395
 off.C:396
 off.C:397
 off.C:398
 off.C:399
 off.C:400
 off.C:401
 off.C:402
 off.C:403
 off.C:404
 off.C:405
 off.C:406
 off.C:407
 off.C:408
 off.C:409
 off.C:410
 off.C:411
 off.C:412
 off.C:413
 off.C:414
 off.C:415
 off.C:416
 off.C:417
 off.C:418
 off.C:419
 off.C:420
 off.C:421
 off.C:422
 off.C:423
 off.C:424
 off.C:425
 off.C:426
 off.C:427