//
// Pibero Djawotho <pibero@indiana.edu>
// Indiana University
// 4 October 2006
//

void RunUpsilonTreeMakersimulate(const char* file = "testups2ndfile.list", int nevents = 30000)
{
  // Load shared libraries
  gROOT->Macro("loadMuDst.C");
  gROOT->Macro("LoadLogger.C");
  gSystem->Load("StTpcDb");
  gSystem->Load("StDetectorDbMaker");
  gSystem->Load("StDbUtilities");
  gSystem->Load("StDaqLib");
  gSystem->Load("StEmcRawMaker");
  gSystem->Load("StEmcADCtoEMaker");
  gSystem->Load("StPreEclMaker");
  gSystem->Load("StEpcMaker");
  gSystem->Load("StDbBroker");
  gSystem->Load("St_db_Maker");
  gSystem->Load("StEEmcUtil");
  gSystem->Load("StBEMCPlots");
  gSystem->Load("StHeavyTrigger");
  gSystem->Load("StHeavyTriggerMaker");  
  gSystem->Load("StUpsilonTreeMaker");

  // Create chain
  StChain* chain = new StChain;

  // Instantiate MuDst maker
  StMuDstMaker* muDstMaker = new StMuDstMaker(0,0,"",file,".",1000,"MuDst");
  StMuDbReader* muDB = StMuDbReader::instance();

  // Database
cout<<"start to define dbMaker"<<endl;
  St_db_Maker* dbMaker = new St_db_Maker("StarDb", "MySQL:StarDb");

  // StEmcADCtoEMaker
cout<<"start to define adc"<<endl;
  StEmcADCtoEMaker* adc = new StEmcADCtoEMaker;
  adc->saveAllStEvent(true);
  adc->setPrint(false);

  // Clustering
cout<<"start to define ecl"<<endl;
  StPreEclMaker* ecl = new StPreEclMaker;
  ecl->setPrint(false);

cout<<"start to define trigMaker"<<endl;
  StHeavyTriggerMaker* trigMaker = new StHeavyTriggerMaker;
 cout<<"set setTriggerId"<<endl;
 trigMaker->setTriggerId(210601);  //  L2 Upsilon
// trigMaker->setTriggerId(210521);    // 	BEMC-HT2
  // Instantiate my maker
cout<<"start to define upsilonTreeMaker"<<endl;
  StUpsilonTreeMaker* upsilonTreeMaker = new StUpsilonTreeMaker;

cout<<"start chain->Init()"<<endl;
  // Initialize chain
  chain->Init();

  // Event loop
  gMessMgr->SwitchOff("Q");
  gMessMgr->SwitchOff("I");
cout<<"start chain->EventLoop(1, nevents)"<<endl;
  chain->EventLoop(nevents);
}
