// ---------------------------------------------------------------------------
// $Id: root_EventDispFullRecon.C,v 1.6 2001/06/23 16:06:07 toshi Exp $
// ---------------------------------------------------------------------------
// $Log: root_EventDispFullRecon.C,v $
// Revision 1.6  2001/06/23 16:06:07  toshi
// LCDFullRecon frec(...) -> LCDFullRecon *frec=new LCDFullRecon(...) .
//
// Revision 1.5  2001/06/23 02:59:51  toshi
// Input file and parameter files are inconsistent.
//
// Revision 1.4  2001/06/23 02:43:47  toshi
// Fix file format bug...(Never copy files written on windows...)
//
// Revision 1.3  2001/06/22 20:06:49  toshi
// Change input file name.
//
// Revision 1.2  2001/06/22 18:00:02  toshi
// Add event->Clear().
//
// Revision 1.1  2001/06/21 21:26:42  toshi
// This file is to display full simulation data written in ROOT file format.
//
//
//  Example file to run Event Display.
//  
//  In this file, 1) read root event (output from GISMO and coverted to root)
//                2) make event display
//
//                                   June 2001   T. Abe
//
// :: How to run ::
// 
// 1) to call the root, type   
//    
//     root
//
// 2)
//     root [0]  .x root_EventDispFullRecon.C
// 
// .. that's it.
//
// For example, if you like to run 3 events, type like
//     root [0]  .x root_EventDispFullRecon.C(3)
//
/*
#include "TFile.h"
#include "TTree.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TSystem.h"
#include "TString.h"

#include "LCDEvent.h"
#include "LCDTrack.h"
#include "LCDFullRecon.h"
#include "LCDreadRootFile.h"
#include "LCDEventDisplay.h"

TSystem *gSystem=new TSystem();

#include <stdlib.h>
*/
int root_EventDispFullRecon(int nEvent=5) {
  gROOT->Reset();

  // 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");

  LCDEvent* event=new LCDEvent();

  // Input generated stdhep file
  Char_t* rootFile  = "test_L2_pi0.root";
  LCDreadRootFile source(rootFile,event);

  // Parameter file directory
  TString parfile_dir;
  parfile_dir += gSystem->Getenv("LCDROOT")   ;parfile_dir += "/";
  parfile_dir += gSystem->Getenv("LCDVERSION");parfile_dir += "/";
  parfile_dir += "ParFiles/";

  // Must use the same detector name as Full simulation
  Char_t* geomFile = 
    // "Silicon.par"; //Silicon
    "Large.par";   // Large
  // "Small.par";   // Small
  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";
  // "lookup_small.nobmcon";
  TString s_smearFile(parfile_dir);
  s_smearFile += smearFile;

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

  // Setup Event Display
  LCDEventDisplay *evdisp=new LCDEventDisplay(&gp);

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

  evdisp->SetGismo();
  evdisp->SetEMCALHit();
  evdisp->SetHDCALHit();
  evdisp->SetTRKHit();
  evdisp->SetNoTRK();
  evdisp->SetVXD();
  evdisp->SetNoLMCAL(); //Do not display LUM CAL part
  evdisp->SetNoMUCAL();  // Do not display MU CAL part

  // 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;
}
