// ----------------------------------------------------------------------------
// $Id: sio_EventDisp.C,v 1.8 2002/01/17 23:35:12 masako Exp $
// ----------------------------------------------------------------------------
//
//  Example file to run Event Display
//  
//  In this file, 1) read sio event (output from GISMO)
//                2) make event display
//
//                                   Feb. 2001   M. Iwasaki
//
// :: How to run ::
// 
// 1) to call the root, type   
//    
//     root
//
// 2)
//     root [0]  .x sio_EventDisp.C
// 
// .. that's it.
//
// For example, if you like to run 3 events, type like
//     root [0]  .x sio_EventDisp.C(3)
//

#include <stdlib.h>

int sio_EventDisp(int nEvent=5) {
  gROOT->Reset();

  TString parfile_dir;
  parfile_dir += gSystem->Getenv("LCDROOT")   ;parfile_dir += "/";
  parfile_dir += "ParFiles/";

  // In order to refer to shareable libraries in this simple form,
  // include their paths in a .rootrc file.
  gSystem->Load("libLCDEvent");
  gSystem->Load("libLCDRootAppsUtil");
  gSystem->Load("libLCDFastMC");
  gSystem->Load("libLCDFullRecon");
  gSystem->Load("libLCDPhUtil");
  if (strcmp(gSystem->GetName(),"WinNT")) {
    gSystem->Load("libSIO2root");
  }
  gSystem->Load("libLCDSIOUtil");

  LCDEvent event;

  // Input generated stdhep file
  Char_t* sioFile  = "test.sio";
  LCDreadSIOFile source(sioFile,&event);

  // Must use the same detector name as Full simulation
  Char_t* geomFile = 
    "SDMar01.par"; // SD
  //"LDMar01.par"; // LD
  TString s_geomFile(parfile_dir);
  s_geomFile += geomFile;
  FILE* m_geomfile =  fopen(s_geomFile.Data(),"r");
  LCDGetParameters gp(m_geomfile);
  fclose(m_geomfile);

  Char_t* smearFile = 
    "lookup_silicon.nobmcon";
  //"lookup_large.nobmcon";
  TString s_smearFile(parfile_dir);
  s_smearFile += smearFile;

  // Setup FullRecon
  LCDFullRecon *frec = 
  //new LCDFullRecon(&gp, s_smearFile.Data(), &event);   // For GEANT4
    new LCDFullRecon(&gp, s_smearFile.Data(), &event, 1);// For GISMO

  // Setup Event Display
  LCDEventDisplay evdisp(&gp);

  //Select Black-White option, if you like
  //evdisp->SetBlackWhite(); 

  evdisp.SetGismo(); // For GISMO only 
  evdisp.SetEMCALHit();
  //evdisp.SetHDCALHit();
  //evdisp.SetMUCALHit();
  //evdisp.SetTRKHit();
  //evdisp.SetVXD();
  evdisp.SetNoTRK();
  //evdisp.SetENDCAL();
  //evdisp.SetNoTRKHit();
  evdisp.SetNoLMCAL(); //Do not display LUM CAL part
  //evdisp.SetNoEMCAL(); //Do not display EM CAL part
  evdisp.SetNoHDCAL(); // Do not display HAD CAL part
  evdisp.SetNoCOIL();   // Do not display COIL part
  evdisp.SetNoMUCAL();  // Do not display MU CAL part
  //evdisp.SetTheta(90.);
  //evdisp.SetPhi(30.);

  // Event loop
  Int_t iEvent;
  for (iEvent = 0; iEvent < nEvent; iEvent++) {

    if (!source.GetEvent()) break;

    frec->Doit();

    printf("# of Clusters=%d\n",event.ClusterLst()->GetEntries());
    printf("# of McParts =%d\n",event.MCparticles()->GetEntries());

    evdisp.Draw(&event);

    Int_t a;
    printf("To get the next event, enter any number (<0 Exit Event loop)\n");
    scanf("%d",&a);
    if (a < 0) break;

  }
  return iEvent;
}
