<commit_before>// One can use the configuration macro in compiled mode by
// root [0] gSystem->Load("libgeant321");
// root [0] gSystem->SetIncludePath("-I$ROOTSYS/include -I$ALICE_ROOT/include\
//                   -I$ALICE_ROOT -I$ALICE/geant3/TGeant3");
// root [0] .x grun.C(1,"Config.C++")

#if !defined(__CINT__) || defined(__MAKECINT__)
#include <Riostream.h>
#include <TPDGCode.h>
#include <TRandom.h>
#include <TSystem.h>
#include <TVirtualMC.h>
#include <TGeant3TGeo.h>
#include "STEER/AliRunLoader.h"
#include "STEER/AliRun.h"
#include "STEER/AliConfig.h"
#include "PYTHIA6/AliDecayerPythia.h"
#include "EVGEN/AliGenCocktail.h"
#include "EVGEN/AliGenHIJINGpara.h"
#include "STEER/AliMagF.h"
#include "STRUCT/AliBODY.h"
#include "STRUCT/AliMAG.h"
#include "STRUCT/AliABSOv3.h"
#include "STRUCT/AliDIPOv3.h"
#include "STRUCT/AliHALLv3.h"
#include "STRUCT/AliFRAMEv2.h"
#include "STRUCT/AliSHILv3.h"
#include "STRUCT/AliPIPEv3.h"
#include "ITS/AliITSv11.h"
#include "TPC/AliTPCv2.h"
#include "TOF/AliTOFv6T0.h"
#include "HMPID/AliHMPIDv3.h"
#include "ZDC/AliZDCv3.h"
#include "TRD/AliTRDv1.h"
#include "FMD/AliFMDv1.h"
#include "MUON/AliMUONv1.h"
#include "PHOS/AliPHOSv1.h"
#include "PMD/AliPMDv1.h"
#include "T0/AliT0v1.h"
#include "EMCAL/AliEMCALv2.h"
#include "ACORDE/AliACORDEv1.h"
#include "VZERO/AliVZEROv7.h"
#endif

Float_t EtaToTheta(Float_t arg);
void    LoadPythia();

void Config()
{
    // ThetaRange is (0., 180.). It was (0.28,179.72) 7/12/00 09:00
    // Theta range given through pseudorapidity limits 22/6/2001

    // Set Random Number seed
  //gRandom->SetSeed(123456); // Set 0 to use the current time

  AliLog::Message(AliLog::kInfo, Form("Seed for random number generation = %d",gRandom->GetSeed()), "Config.C", "Config.C", "Config()","Config.C", __LINE__);

  // Load Pythia libraries
  LoadPythia();
  // Libraries required by geant321
#if defined(__CINT__)
    gSystem->Load("libgeant321");
#endif

    new     TGeant3TGeo("C++ Interface to Geant3");

    AliRunLoader* rl=0x0;

    AliLog::Message(AliLog::kInfo, "Creating Run Loader", "Config.C", "Config.C", "Config()"," Config.C", __LINE__);

    rl = AliRunLoader::Open("galice.root",
			    AliConfig::GetDefaultEventFolderName(),
			    "recreate");
    if (rl == 0x0)
      {
	gAlice->Fatal("Config.C","Can not instatiate the Run Loader");
	return;
      }
    rl->SetCompressionLevel(2);
    rl->SetNumberOfEventsPerFile(3);
    gAlice->SetRunLoader(rl);

    // gAlice->SetGeometryFromFile("geometry.root");

    // Uncomment if you want to load geometry from OCDB!   >>>>
/*
    if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
	 cout << "#####################################################" << endl;
	 cout << "#                                                   #" << endl;
	 cout << "#     WARNING: CDB DEFAULT STORAGE NOT SET !!!      #" << endl;
	 cout << "#     SETTING IT TO local://$ALICE_ROOT/OCDB !!!         #" << endl;
	 cout << "#                                                   #" << endl;
	 cout << "#####################################################" << endl;

         AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
    }

    if(AliCDBManager::Instance()->GetRun() < 0){
	 cout << "#####################################################" << endl;
	 cout << "#                                                   #" << endl;
	 cout << "#     WARNING: RUN NUMBER NOT SET !!!               #" << endl;
	 cout << "#     SETTING IT TO 0 !!!                           #" << endl;
	 cout << "#                                                   #" << endl;
	 cout << "#####################################################" << endl;

         AliCDBManager::Instance()->SetRun(0);
    }
    gAlice->SetGeometryFromCDB();
*/
    // Uncomment if you want to load geometry from OCDB!   <<<<

    // Set the trigger configuration
    AliSimulation::Instance()->SetTriggerConfig("Pb-Pb");
    cout<<"Trigger configuration is set to  Pb-Pb"<<endl;

    //
    // Set External decayer
    TVirtualMCDecayer *decayer = new AliDecayerPythia();

    decayer->SetForceDecay(kAll);
    decayer->Init();
    gMC->SetExternalDecayer(decayer);
    //=======================================================================
    // ************* STEERING parameters FOR ALICE SIMULATION **************
    // --- Specify event type to be tracked through the ALICE setup
    // --- All positions are in cm, angles in degrees, and P and E in GeV

    gMC->SetProcess("DCAY",1);
    gMC->SetProcess("PAIR",1);
    gMC->SetProcess("COMP",1);
    gMC->SetProcess("PHOT",1);
    gMC->SetProcess("PFIS",0);
    gMC->SetProcess("DRAY",0);
    gMC->SetProcess("ANNI",1);
    gMC->SetProcess("BREM",1);
    gMC->SetProcess("MUNU",1);
    gMC->SetProcess("CKOV",1);
    gMC->SetProcess("HADR",1);
    gMC->SetProcess("LOSS",2);
    gMC->SetProcess("MULS",1);
    gMC->SetProcess("RAYL",1);

    Float_t cut = 1.e-3;        // 1MeV cut by default
    Float_t tofmax = 1.e10;

    gMC->SetCut("CUTGAM", cut);
    gMC->SetCut("CUTELE", cut);
    gMC->SetCut("CUTNEU", cut);
    gMC->SetCut("CUTHAD", cut);
    gMC->SetCut("CUTMUO", cut);
    gMC->SetCut("BCUTE",  cut);
    gMC->SetCut("BCUTM",  cut);
    gMC->SetCut("DCUTE",  cut);
    gMC->SetCut("DCUTM",  cut);
    gMC->SetCut("PPCUTM", cut);
    gMC->SetCut("TOFMAX", tofmax);

    int     nParticles = 100;
    if (gSystem->Getenv("CONFIG_NPARTICLES"))
    {
        nParticles = atoi(gSystem->Getenv("CONFIG_NPARTICLES"));
    }

    AliGenCocktail *gener = new AliGenCocktail();
    gener->SetPhiRange(0, 360);
    // Set pseudorapidity range from -8 to 8.
    Float_t thmin = EtaToTheta(8);   // theta min. <---> eta max
    Float_t thmax = EtaToTheta(-8);  // theta max. <---> eta min
    gener->SetThetaRange(thmin,thmax);
    gener->SetOrigin(0, 0, 0);  //vertex position
    gener->SetSigma(0, 0, 0);   //Sigma in (X,Y,Z) (cm) on IP position

    AliGenHIJINGpara *hijingparam = new AliGenHIJINGpara(nParticles);
    hijingparam->SetMomentumRange(0.2, 999);
    gener->AddGenerator(hijingparam,"HIJING PARAM",1);

//    AliGenBox *genbox = new AliGenBox(nParticles);
//    genbox->SetPart(kGamma);
//    genbox->SetPtRange(0.3, 10.00);
//    gener->AddGenerator(genbox,"GENBOX GAMMA for PHOS",1);
    gener->Init();

    //
    // Activate this line if you want the vertex smearing to happen
    // track by track
    //
    //gener->SetVertexSmear(perTrack);
    // Field (L3 0.4 T)
    TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", -1., -1., AliMagF::k5kG));

    Int_t   iABSO   = 1;
    Int_t   iDIPO   = 1;
    Int_t   iFMD    = 1;
    Int_t   iFRAME  = 1;
    Int_t   iHALL   = 1;
    Int_t   iITS    = 1;
    Int_t   iMAG    = 1;
    Int_t   iMUON   = 1;
    Int_t   iPHOS   = 1;
    Int_t   iPIPE   = 1;
    Int_t   iPMD    = 1;
    Int_t   iHMPID  = 1;
    Int_t   iSHIL   = 1;
    Int_t   iT0     = 1;
    Int_t   iTOF    = 1;
    Int_t   iTPC    = 1;
    Int_t   iTRD    = 1;
    Int_t   iZDC    = 1;
    Int_t   iEMCAL  = 1;
    Int_t   iACORDE = 1;
    Int_t   iVZERO  = 1;
    rl->CdGAFile();
    //=================== Alice BODY parameters =============================
    AliBODY *BODY = new AliBODY("BODY", "Alice envelop");

    if (iMAG)
    {
        //=================== MAG parameters ============================
        // --- Start with Magnet since detector layouts may be depending ---
        // --- on the selected Magnet dimensions ---
        AliMAG *MAG = new AliMAG("MAG", "Magnet");
    }

    if (iABSO)
    {
        //=================== ABSO parameters ============================
        AliABSO *ABSO = new AliABSOv3("ABSO", "Muon Absorber");
    }

    if (iDIPO)
    {
        //=================== DIPO parameters ============================

        AliDIPO *DIPO = new AliDIPOv3("DIPO", "Dipole version 3");
    }

    if (iHALL)
    {
        //=================== HALL parameters ============================

        AliHALL *HALL = new AliHALLv3("HALL", "Alice Hall");
    }

    if (iFRAME)
    {
        //=================== FRAME parameters ============================

        AliFRAMEv2 *FRAME = new AliFRAMEv2("FRAME", "Space Frame");
	FRAME->SetHoles(1);
    }

    if (iSHIL)
    {
        //=================== SHIL parameters ============================

        AliSHIL *SHIL = new AliSHILv3("SHIL", "Shielding Version 3");
    }

    if (iPIPE)
    {
        //=================== PIPE parameters ============================

        AliPIPE *PIPE = new AliPIPEv3("PIPE", "Beam Pipe");
    }

    if (iITS)
    {
        //=================== ITS parameters ============================

	AliITS *ITS  = new AliITSv11("ITS","ITS v11");
    }

    if (iTPC)
    {
        //============================ TPC parameters ===================
        AliTPC *TPC = new AliTPCv2("TPC", "Default");
    }

    if (iTOF) {
        //=================== TOF parameters ============================
	AliTOF *TOF = new AliTOFv6T0("TOF", "normal TOF");
    }

    if (iHMPID)
    {
        //=================== HMPID parameters ===========================
        AliHMPID *HMPID = new AliHMPIDv3("HMPID", "normal HMPID");

    }

    if (iZDC)
    {
        //=================== ZDC parameters ============================

        AliZDC *ZDC = new AliZDCv3("ZDC", "normal ZDC");
    }

    if (iTRD)
    {
        //=================== TRD parameters ============================

        AliTRD *TRD = new AliTRDv1("TRD", "TRD slow simulator");
    }

    if (iFMD)
    {
        //=================== FMD parameters ============================
	AliFMD *FMD = new AliFMDv1("FMD", "normal FMD");
   }

    if (iMUON)
    {
        //=================== MUON parameters ===========================
        // New MUONv1 version (geometry defined via builders)
        AliMUON *MUON = new AliMUONv1("MUON", "default");
    }
    //=================== PHOS parameters ===========================

    if (iPHOS)
    {
        AliPHOS *PHOS = new AliPHOSv1("PHOS", "IHEP");
    }

    if (iPMD)
    {
        //=================== PMD parameters ============================
        AliPMD *PMD = new AliPMDv1("PMD", "normal PMD");
    }

    if (iT0)
    {
        //=================== T0 parameters ============================
        AliT0 *T0 = new AliT0v1("T0", "T0 Detector");
    }

    if (iEMCAL)
    {
        //=================== EMCAL parameters ============================
        AliEMCAL *EMCAL = new AliEMCALv2("EMCAL", "EMCAL_COMPLETEV1");
    }

     if (iACORDE)
    {
        //=================== ACORDE parameters ============================
        AliACORDE *ACORDE = new AliACORDEv1("ACORDE", "normal ACORDE");
    }

     if (iVZERO)
    {
        //=================== VZERO parameters ============================
        AliVZERO *VZERO = new AliVZEROv7("VZERO", "normal VZERO");
    }

     AliLog::Message(AliLog::kInfo, "End of Config", "Config.C", "Config.C", "Config()"," Config.C", __LINE__);

}

Float_t EtaToTheta(Float_t arg){
  return (180./TMath::Pi())*2.*atan(exp(-arg));
}

void LoadPythia()
{
    // Load Pythia related libraries
    gSystem->Load("liblhapdf.so");      // Parton density functions
    gSystem->Load("libEGPythia6.so");   // TGenerator interface
    gSystem->Load("libpythia6.so");     // Pythia
    gSystem->Load("libAliPythia6.so");  // ALICE specific implementations
}
<commit_msg>Config.C with correct EMCAL geometry<commit_after>// One can use the configuration macro in compiled mode by
// root [0] gSystem->Load("libgeant321");
// root [0] gSystem->SetIncludePath("-I$ROOTSYS/include -I$ALICE_ROOT/include\
//                   -I$ALICE_ROOT -I$ALICE/geant3/TGeant3");
// root [0] .x grun.C(1,"Config.C++")

#if !defined(__CINT__) || defined(__MAKECINT__)
#include <Riostream.h>
#include <TPDGCode.h>
#include <TRandom.h>
#include <TSystem.h>
#include <TVirtualMC.h>
#include <TGeant3TGeo.h>
#include "STEER/AliRunLoader.h"
#include "STEER/AliRun.h"
#include "STEER/AliConfig.h"
#include "PYTHIA6/AliDecayerPythia.h"
#include "EVGEN/AliGenCocktail.h"
#include "EVGEN/AliGenHIJINGpara.h"
#include "STEER/AliMagF.h"
#include "STRUCT/AliBODY.h"
#include "STRUCT/AliMAG.h"
#include "STRUCT/AliABSOv3.h"
#include "STRUCT/AliDIPOv3.h"
#include "STRUCT/AliHALLv3.h"
#include "STRUCT/AliFRAMEv2.h"
#include "STRUCT/AliSHILv3.h"
#include "STRUCT/AliPIPEv3.h"
#include "ITS/AliITSv11.h"
#include "TPC/AliTPCv2.h"
#include "TOF/AliTOFv6T0.h"
#include "HMPID/AliHMPIDv3.h"
#include "ZDC/AliZDCv3.h"
#include "TRD/AliTRDv1.h"
#include "FMD/AliFMDv1.h"
#include "MUON/AliMUONv1.h"
#include "PHOS/AliPHOSv1.h"
#include "PMD/AliPMDv1.h"
#include "T0/AliT0v1.h"
#include "EMCAL/AliEMCALv2.h"
#include "ACORDE/AliACORDEv1.h"
#include "VZERO/AliVZEROv7.h"
#endif

Float_t EtaToTheta(Float_t arg);
void    LoadPythia();

void Config()
{
    // ThetaRange is (0., 180.). It was (0.28,179.72) 7/12/00 09:00
    // Theta range given through pseudorapidity limits 22/6/2001

    // Set Random Number seed
  //gRandom->SetSeed(123456); // Set 0 to use the current time

  AliLog::Message(AliLog::kInfo, Form("Seed for random number generation = %d",gRandom->GetSeed()), "Config.C", "Config.C", "Config()","Config.C", __LINE__);

  // Load Pythia libraries
  LoadPythia();
  // Libraries required by geant321
#if defined(__CINT__)
    gSystem->Load("libgeant321");
#endif

    new     TGeant3TGeo("C++ Interface to Geant3");

    AliRunLoader* rl=0x0;

    AliLog::Message(AliLog::kInfo, "Creating Run Loader", "Config.C", "Config.C", "Config()"," Config.C", __LINE__);

    rl = AliRunLoader::Open("galice.root",
			    AliConfig::GetDefaultEventFolderName(),
			    "recreate");
    if (rl == 0x0)
      {
	gAlice->Fatal("Config.C","Can not instatiate the Run Loader");
	return;
      }
    rl->SetCompressionLevel(2);
    rl->SetNumberOfEventsPerFile(3);
    gAlice->SetRunLoader(rl);

    // gAlice->SetGeometryFromFile("geometry.root");

    // Uncomment if you want to load geometry from OCDB!   >>>>
/*
    if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
	 cout << "#####################################################" << endl;
	 cout << "#                                                   #" << endl;
	 cout << "#     WARNING: CDB DEFAULT STORAGE NOT SET !!!      #" << endl;
	 cout << "#     SETTING IT TO local://$ALICE_ROOT/OCDB !!!         #" << endl;
	 cout << "#                                                   #" << endl;
	 cout << "#####################################################" << endl;

         AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
    }

    if(AliCDBManager::Instance()->GetRun() < 0){
	 cout << "#####################################################" << endl;
	 cout << "#                                                   #" << endl;
	 cout << "#     WARNING: RUN NUMBER NOT SET !!!               #" << endl;
	 cout << "#     SETTING IT TO 0 !!!                           #" << endl;
	 cout << "#                                                   #" << endl;
	 cout << "#####################################################" << endl;

         AliCDBManager::Instance()->SetRun(0);
    }
    gAlice->SetGeometryFromCDB();
*/
    // Uncomment if you want to load geometry from OCDB!   <<<<

    // Set the trigger configuration
    AliSimulation::Instance()->SetTriggerConfig("Pb-Pb");
    cout<<"Trigger configuration is set to  Pb-Pb"<<endl;

    //
    // Set External decayer
    TVirtualMCDecayer *decayer = new AliDecayerPythia();

    decayer->SetForceDecay(kAll);
    decayer->Init();
    gMC->SetExternalDecayer(decayer);
    //=======================================================================
    // ************* STEERING parameters FOR ALICE SIMULATION **************
    // --- Specify event type to be tracked through the ALICE setup
    // --- All positions are in cm, angles in degrees, and P and E in GeV

    gMC->SetProcess("DCAY",1);
    gMC->SetProcess("PAIR",1);
    gMC->SetProcess("COMP",1);
    gMC->SetProcess("PHOT",1);
    gMC->SetProcess("PFIS",0);
    gMC->SetProcess("DRAY",0);
    gMC->SetProcess("ANNI",1);
    gMC->SetProcess("BREM",1);
    gMC->SetProcess("MUNU",1);
    gMC->SetProcess("CKOV",1);
    gMC->SetProcess("HADR",1);
    gMC->SetProcess("LOSS",2);
    gMC->SetProcess("MULS",1);
    gMC->SetProcess("RAYL",1);

    Float_t cut = 1.e-3;        // 1MeV cut by default
    Float_t tofmax = 1.e10;

    gMC->SetCut("CUTGAM", cut);
    gMC->SetCut("CUTELE", cut);
    gMC->SetCut("CUTNEU", cut);
    gMC->SetCut("CUTHAD", cut);
    gMC->SetCut("CUTMUO", cut);
    gMC->SetCut("BCUTE",  cut);
    gMC->SetCut("BCUTM",  cut);
    gMC->SetCut("DCUTE",  cut);
    gMC->SetCut("DCUTM",  cut);
    gMC->SetCut("PPCUTM", cut);
    gMC->SetCut("TOFMAX", tofmax);

    int     nParticles = 100;
    if (gSystem->Getenv("CONFIG_NPARTICLES"))
    {
        nParticles = atoi(gSystem->Getenv("CONFIG_NPARTICLES"));
    }

    AliGenCocktail *gener = new AliGenCocktail();
    gener->SetPhiRange(0, 360);
    // Set pseudorapidity range from -8 to 8.
    Float_t thmin = EtaToTheta(8);   // theta min. <---> eta max
    Float_t thmax = EtaToTheta(-8);  // theta max. <---> eta min
    gener->SetThetaRange(thmin,thmax);
    gener->SetOrigin(0, 0, 0);  //vertex position
    gener->SetSigma(0, 0, 0);   //Sigma in (X,Y,Z) (cm) on IP position

    AliGenHIJINGpara *hijingparam = new AliGenHIJINGpara(nParticles);
    hijingparam->SetMomentumRange(0.2, 999);
    gener->AddGenerator(hijingparam,"HIJING PARAM",1);

//    AliGenBox *genbox = new AliGenBox(nParticles);
//    genbox->SetPart(kGamma);
//    genbox->SetPtRange(0.3, 10.00);
//    gener->AddGenerator(genbox,"GENBOX GAMMA for PHOS",1);
    gener->Init();

    //
    // Activate this line if you want the vertex smearing to happen
    // track by track
    //
    //gener->SetVertexSmear(perTrack);
    // Field (L3 0.4 T)
    TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", -1., -1., AliMagF::k5kG));

    Int_t   iABSO   = 1;
    Int_t   iDIPO   = 1;
    Int_t   iFMD    = 1;
    Int_t   iFRAME  = 1;
    Int_t   iHALL   = 1;
    Int_t   iITS    = 1;
    Int_t   iMAG    = 1;
    Int_t   iMUON   = 1;
    Int_t   iPHOS   = 1;
    Int_t   iPIPE   = 1;
    Int_t   iPMD    = 1;
    Int_t   iHMPID  = 1;
    Int_t   iSHIL   = 1;
    Int_t   iT0     = 1;
    Int_t   iTOF    = 1;
    Int_t   iTPC    = 1;
    Int_t   iTRD    = 1;
    Int_t   iZDC    = 1;
    Int_t   iEMCAL  = 1;
    Int_t   iACORDE = 1;
    Int_t   iVZERO  = 1;
    rl->CdGAFile();
    //=================== Alice BODY parameters =============================
    AliBODY *BODY = new AliBODY("BODY", "Alice envelop");

    if (iMAG)
    {
        //=================== MAG parameters ============================
        // --- Start with Magnet since detector layouts may be depending ---
        // --- on the selected Magnet dimensions ---
        AliMAG *MAG = new AliMAG("MAG", "Magnet");
    }

    if (iABSO)
    {
        //=================== ABSO parameters ============================
        AliABSO *ABSO = new AliABSOv3("ABSO", "Muon Absorber");
    }

    if (iDIPO)
    {
        //=================== DIPO parameters ============================

        AliDIPO *DIPO = new AliDIPOv3("DIPO", "Dipole version 3");
    }

    if (iHALL)
    {
        //=================== HALL parameters ============================

        AliHALL *HALL = new AliHALLv3("HALL", "Alice Hall");
    }

    if (iFRAME)
    {
        //=================== FRAME parameters ============================

        AliFRAMEv2 *FRAME = new AliFRAMEv2("FRAME", "Space Frame");
	FRAME->SetHoles(1);
    }

    if (iSHIL)
    {
        //=================== SHIL parameters ============================

        AliSHIL *SHIL = new AliSHILv3("SHIL", "Shielding Version 3");
    }

    if (iPIPE)
    {
        //=================== PIPE parameters ============================

        AliPIPE *PIPE = new AliPIPEv3("PIPE", "Beam Pipe");
    }

    if (iITS)
    {
        //=================== ITS parameters ============================

	AliITS *ITS  = new AliITSv11("ITS","ITS v11");
    }

    if (iTPC)
    {
        //============================ TPC parameters ===================
        AliTPC *TPC = new AliTPCv2("TPC", "Default");
    }

    if (iTOF) {
        //=================== TOF parameters ============================
	AliTOF *TOF = new AliTOFv6T0("TOF", "normal TOF");
    }

    if (iHMPID)
    {
        //=================== HMPID parameters ===========================
        AliHMPID *HMPID = new AliHMPIDv3("HMPID", "normal HMPID");

    }

    if (iZDC)
    {
        //=================== ZDC parameters ============================

        AliZDC *ZDC = new AliZDCv3("ZDC", "normal ZDC");
    }

    if (iTRD)
    {
        //=================== TRD parameters ============================

        AliTRD *TRD = new AliTRDv1("TRD", "TRD slow simulator");
    }

    if (iFMD)
    {
        //=================== FMD parameters ============================
	AliFMD *FMD = new AliFMDv1("FMD", "normal FMD");
   }

    if (iMUON)
    {
        //=================== MUON parameters ===========================
        // New MUONv1 version (geometry defined via builders)
        AliMUON *MUON = new AliMUONv1("MUON", "default");
    }
    //=================== PHOS parameters ===========================

    if (iPHOS)
    {
        AliPHOS *PHOS = new AliPHOSv1("PHOS", "IHEP");
    }

    if (iPMD)
    {
        //=================== PMD parameters ============================
        AliPMD *PMD = new AliPMDv1("PMD", "normal PMD");
    }

    if (iT0)
    {
        //=================== T0 parameters ============================
        AliT0 *T0 = new AliT0v1("T0", "T0 Detector");
    }

    if (iEMCAL)
    {
        //=================== EMCAL parameters ============================
        AliEMCAL *EMCAL = new AliEMCALv2("EMCAL", "EMCAL_COMPLETE12SMV1");
    }

     if (iACORDE)
    {
        //=================== ACORDE parameters ============================
        AliACORDE *ACORDE = new AliACORDEv1("ACORDE", "normal ACORDE");
    }

     if (iVZERO)
    {
        //=================== VZERO parameters ============================
        AliVZERO *VZERO = new AliVZEROv7("VZERO", "normal VZERO");
    }

     AliLog::Message(AliLog::kInfo, "End of Config", "Config.C", "Config.C", "Config()"," Config.C", __LINE__);

}

Float_t EtaToTheta(Float_t arg){
  return (180./TMath::Pi())*2.*atan(exp(-arg));
}

void LoadPythia()
{
    // Load Pythia related libraries
    gSystem->Load("liblhapdf.so");      // Parton density functions
    gSystem->Load("libEGPythia6.so");   // TGenerator interface
    gSystem->Load("libpythia6.so");     // Pythia
    gSystem->Load("libAliPythia6.so");  // ALICE specific implementations
}
<|endoftext|>


<commit_before>static Int_t    eventsPerRun = 100;
void Config()
{
    // 7-DEC-2000 09:00
    // Switch on Transition Radiation simulation. 6/12/00 18:00
    // iZDC=1  7/12/00 09:00
    // ThetaRange is (0., 180.). It was (0.28,179.72) 7/12/00 09:00
    // Theta range given through pseudorapidity limits 22/6/2001

    // Set Random Number seed
    // gRandom->SetSeed(12345);

    new     AliGeant3("C++ Interface to Geant3");

    if (!gSystem->Getenv("CONFIG_FILE"))
    {
        TFile  *rootfile = new TFile("galice.root", "recreate");

        rootfile->SetCompressionLevel(2);
    }

    TGeant3 *geant3 = (TGeant3 *) gMC;

    //
    // Set External decayer
    AliDecayer *decayer = new AliDecayerPythia();

    decayer->SetForceDecay(kAll);
    decayer->Init();
    gMC->SetExternalDecayer(decayer);
    //
    //
    //=======================================================================
    // ******* GEANT STEERING parameters FOR ALICE SIMULATION *******
    geant3->SetTRIG(1);         //Number of events to be processed
    geant3->SetSWIT(4, 10);
    geant3->SetDEBU(0, 0, 1);
    //geant3->SetSWIT(2,2);
    geant3->SetDCAY(1);
    geant3->SetPAIR(1);
    geant3->SetCOMP(1);
    geant3->SetPHOT(1);
    geant3->SetPFIS(0);
    geant3->SetDRAY(0);
    geant3->SetANNI(1);
    geant3->SetBREM(1);
    geant3->SetMUNU(1);
    geant3->SetCKOV(1);
    geant3->SetHADR(1);         //Select pure GEANH (HADR 1) or GEANH/NUCRIN (HADR 3)
    geant3->SetLOSS(2);
    geant3->SetMULS(1);
    geant3->SetRAYL(1);
    geant3->SetAUTO(1);         //Select automatic STMIN etc... calc. (AUTO 1) or manual (AUTO 0)
    geant3->SetABAN(0);         //Restore 3.16 behaviour for abandoned tracks
    geant3->SetOPTI(2);         //Select optimisation level for GEANT geometry searches (0,1,2)
    geant3->SetERAN(5.e-7);

    Float_t cut = 1.e-3;        // 1MeV cut by default
    Float_t tofmax = 1.e10;

    //             GAM ELEC NHAD CHAD MUON EBREM MUHAB EDEL MUDEL MUPA TOFMAX
    geant3->SetCUTS(cut, cut, cut, cut, cut, cut, cut, cut, cut, cut,
                    tofmax);
    //
    //=======================================================================
    // ************* STEERING parameters FOR ALICE SIMULATION **************
    // --- Specify event type to be tracked through the ALICE setup
    // --- All positions are in cm, angles in degrees, and P and E in GeV
    if (gSystem->Getenv("CONFIG_NPARTICLES"))
    {
        int     nParticles = atoi(gSystem->Getenv("CONFIG_NPARTICLES"));
    } else
    {
        int     nParticles = 50;
    }
    AliGenHIJINGpara *gener = new AliGenHIJINGpara(nParticles);

    gener->SetMomentumRange(0, 999);
    gener->SetPhiRange(0, 360);
    // Set pseudorapidity range from -8 to 8.
    Float_t thmin = EtaToTheta(8);   // theta min. <---> eta max
    Float_t thmax = EtaToTheta(-8);  // theta max. <---> eta min
    gener->SetThetaRange(thmin,thmax);
    gener->SetOrigin(0, 0, 0);  //vertex position
    gener->SetSigma(0, 0, 0);   //Sigma in (X,Y,Z) (cm) on IP position
    gener->Init();
    //
    // Activate this line if you want the vertex smearing to happen
    // track by track
    //
    //gener->SetVertexSmear(perTrack);

    gAlice->SetField(-999, 2);  //Specify maximum magnetic field in Tesla (neg. ==> default field)

    Int_t   iABSO = 1;
    Int_t   iCASTOR = 1;
    Int_t   iDIPO = 1;
    Int_t   iFMD = 1;
    Int_t   iFRAME = 1;
    Int_t   iHALL = 1;
    Int_t   iITS = 1;
    Int_t   iMAG = 1;
    Int_t   iMUON = 1;
    Int_t   iPHOS = 1;
    Int_t   iPIPE = 1;
    Int_t   iPMD = 1;
    Int_t   iRICH = 1;
    Int_t   iSHIL = 1;
    Int_t   iSTART = 1;
    Int_t   iTOF = 1;
    Int_t   iTPC = 1;
    Int_t   iTRD = 1;
    Int_t   iZDC = 1;
    Int_t   iEMCAL = 0;

    //=================== Alice BODY parameters =============================
    AliBODY *BODY = new AliBODY("BODY", "Alice envelop");

    if (iMAG)
    {
        //=================== MAG parameters ============================
        // --- Start with Magnet since detector layouts may be depending ---
        // --- on the selected Magnet dimensions ---
        AliMAG *MAG = new AliMAG("MAG", "Magnet");
    }

    if (iABSO)
    {
        //=================== ABSO parameters ============================
        AliABSO *ABSO = new AliABSOv0("ABSO", "Muon Absorber");
    }

    if (iDIPO)
    {
        //=================== DIPO parameters ============================

        AliDIPO *DIPO = new AliDIPOv2("DIPO", "Dipole version 2");
    }

    if (iHALL)
    {
        //=================== HALL parameters ============================

        AliHALL *HALL = new AliHALL("HALL", "Alice Hall");
    }

    if (iFRAME)
    {
        //=================== FRAME parameters ============================

        AliFRAME *FRAME = new AliFRAMEv2("FRAME", "Space Frame");

    }

    if (iSHIL)
    {
        //=================== SHIL parameters ============================

        AliSHIL *SHIL = new AliSHILvF("SHIL", "Shielding");
    }

    if (iPIPE)
    {
        //=================== PIPE parameters ============================

        AliPIPE *PIPE = new AliPIPEv0("PIPE", "Beam Pipe");
    }

  if(iITS) {

//=================== ITS parameters ============================
    //
    // As the innermost detector in ALICE, the Inner Tracking System "impacts" on
    // almost all other detectors. This involves the fact that the ITS geometry
    // still has several options to be followed in parallel in order to determine
    // the best set-up which minimizes the induced background. All the geometries
    // available to date are described in the following. Read carefully the comments
    // and use the default version (the only one uncommented) unless you are making
    // comparisons and you know what you are doing. In this case just uncomment the
    // ITS geometry you want to use and run Aliroot.
    //
    // Detailed geometries:
    //
    //
    //AliITS *ITS  = new AliITSv5symm("ITS","Updated ITS TDR detailed version with symmetric services");
    //
    //AliITS *ITS  = new AliITSv5asymm("ITS","Updates ITS TDR detailed version with asymmetric services");
    //
    AliITSvPPRasymm *ITS  = new AliITSvPPRasymm("ITS","New ITS PPR detailed version with asymmetric services");
    ITS->SetMinorVersion(2);					 // don't touch this parameter if you're not an ITS developer
    ITS->SetReadDet(kFALSE);					 // don't touch this parameter if you're not an ITS developer
    //    ITS->SetWriteDet("$ALICE_ROOT/ITS/ITSgeometry_vPPRasymm2.det");  // don't touch this parameter if you're not an ITS developer
    ITS->SetThicknessDet1(200.);   // detector thickness on layer 1 must be in the range [100,300]
    ITS->SetThicknessDet2(200.);   // detector thickness on layer 2 must be in the range [100,300]
    ITS->SetThicknessChip1(200.);  // chip thickness on layer 1 must be in the range [150,300]
    ITS->SetThicknessChip2(200.);  // chip thickness on layer 2 must be in the range [150,300]
    ITS->SetRails(1);	     // 1 --> rails in ; 0 --> rails out
    ITS->SetCoolingFluid(1);   // 1 --> water ; 0 --> freon
    //
    //AliITSvPPRsymm *ITS  = new AliITSvPPRsymm("ITS","New ITS PPR detailed version with symmetric services");
    //ITS->SetMinorVersion(2);                                       // don't touch this parameter if you're not an ITS developer
    //ITS->SetReadDet(kFALSE);                                       // don't touch this parameter if you're not an ITS developer
    //ITS->SetWriteDet("$ALICE_ROOT/ITS/ITSgeometry_vPPRsymm2.det"); // don't touch this parameter if you're not an ITS developer
    //ITS->SetThicknessDet1(200.);   // detector thickness on layer 1 must be in the range [100,300]
    //ITS->SetThicknessDet2(200.);   // detector thickness on layer 2 must be in the range [100,300]
    //ITS->SetThicknessChip1(200.);  // chip thickness on layer 1 must be in the range [150,300]
    //ITS->SetThicknessChip2(200.);  // chip thickness on layer 2 must be in the range [150,300]
    //ITS->SetRails(1);              // 1 --> rails in ; 0 --> rails out
    //ITS->SetCoolingFluid(1);       // 1 --> water ; 0 --> freon
    //
    //
    // Coarse geometries (warning: no hits are produced with these coarse geometries and they unuseful
    // for reconstruction !):
    //
    //
    //AliITSvPPRcoarseasymm *ITS  = new AliITSvPPRcoarseasymm("ITS","New ITS PPR coarse version with asymmetric services");
    //ITS->SetRails(1);                // 1 --> rails in ; 0 --> rails out
    //ITS->SetSupportMaterial(0);      // 0 --> Copper ; 1 --> Aluminum ; 2 --> Carbon
    //
    //AliITS *ITS  = new AliITSvPPRcoarsesymm("ITS","New ITS PPR coarse version with symmetric services");
    //ITS->SetRails(1);                // 1 --> rails in ; 0 --> rails out
    //ITS->SetSupportMaterial(0);      // 0 --> Copper ; 1 --> Aluminum ; 2 --> Carbon
    //
    //
    //
    // Geant3 <-> EUCLID conversion
    // ============================
    //
    // SetEUCLID is a flag to output (=1) or not to output (=0) both geometry and
    // media to two ASCII files (called by default ITSgeometry.euc and
    // ITSgeometry.tme) in a format understandable to the CAD system EUCLID.
    // The default (=0) means that you dont want to use this facility.
    //
    ITS->SetEUCLID(0);
  }

    if (iTPC)
    {
        //============================ TPC parameters ================================
        // --- This allows the user to specify sectors for the SLOW (TPC geometry 2)
        // --- Simulator. SecAL (SecAU) <0 means that ALL lower (upper)
        // --- sectors are specified, any value other than that requires at least one
        // --- sector (lower or upper)to be specified!
        // --- Reminder: sectors 1-24 are lower sectors (1-12 -> z>0, 13-24 -> z<0)
        // ---           sectors 25-72 are the upper ones (25-48 -> z>0, 49-72 -> z<0)
        // --- SecLows - number of lower sectors specified (up to 6)
        // --- SecUps - number of upper sectors specified (up to 12)
        // --- Sens - sensitive strips for the Slow Simulator !!!
        // --- This does NOT work if all S or L-sectors are specified, i.e.
        // --- if SecAL or SecAU < 0
        //
        //
        //-----------------------------------------------------------------------------

        //  gROOT->LoadMacro("SetTPCParam.C");
        //  AliTPCParam *param = SetTPCParam();
        AliTPC *TPC = new AliTPCv2("TPC", "Default");

        // All sectors included
        TPC->SetSecAL(-1);
        TPC->SetSecAU(-1);

    }

    if (iTOF)
    {
        //=================== TOF parameters ============================
        AliTOF *TOF = new AliTOFv2("TOF", "normal TOF");
    }

    if (iRICH)
    {
        //=================== RICH parameters ===========================
        AliRICH *RICH = new AliRICHv1("RICH", "normal RICH");

    }

    if (iZDC)
    {
        //=================== ZDC parameters ============================

        AliZDC *ZDC = new AliZDCv2("ZDC", "normal ZDC");
    }

    if (iCASTOR)
    {
        //=================== CASTOR parameters ============================

        AliCASTOR *CASTOR = new AliCASTORv1("CASTOR", "normal CASTOR");
    }

    if (iTRD)
    {
        //=================== TRD parameters ============================

        AliTRD *TRD = new AliTRDv1("TRD", "TRD slow simulator");

        // Select the gas mixture (0: 97% Xe + 3% isobutane, 1: 90% Xe + 10% CO2)
        TRD->SetGasMix(1);

        // With hole in front of PHOS
        TRD->SetPHOShole();
        // With hole in front of RICH
        TRD->SetRICHhole();
        // Switch on TR
        AliTRDsim *TRDsim = TRD->CreateTR();
    }

    if (iFMD)
    {
        //=================== FMD parameters ============================

        AliFMD *FMD = new AliFMDv1("FMD", "normal FMD");
        FMD->SetRingsSi1(256);
        FMD->SetRingsSi2(64);
        FMD->SetSectorsSi1(20);
        FMD->SetSectorsSi2(24);
   }

    if (iMUON)
    {
        //=================== MUON parameters ===========================

        AliMUON *MUON = new AliMUONv1("MUON", "default");
    }
    //=================== PHOS parameters ===========================

    if (iPHOS)
    {
        AliPHOS *PHOS = new AliPHOSv1("PHOS", "GPS2");
    }

    if (iPMD)
    {
        //=================== PMD parameters ============================

        AliPMD *PMD = new AliPMDv1("PMD", "normal PMD");

        PMD->SetPAR(1., 1., 0.8, 0.02);
        PMD->SetIN(6., 18., -580., 27., 27.);
        PMD->SetGEO(0.0, 0.2, 4.);
        PMD->SetPadSize(0.8, 1.0, 1.0, 1.5);

    }

    if (iEMCAL && !iRICH)
    {
        //=================== EMCAL parameters ============================
        AliEMCAL *EMCAL = new AliEMCALv1("EMCAL", "EMCALArch1a");
    }

    if (iSTART)
    {
        //=================== START parameters ============================
        AliSTART *START = new AliSTARTv1("START", "START Detector");
    }

}

Float_t EtaToTheta(Float_t arg){
  return (180./TMath::Pi())*2.*atan(exp(-arg));
}
<commit_msg>CASTOR deleted<commit_after>static Int_t    eventsPerRun = 100;
void Config()
{
    // 7-DEC-2000 09:00
    // Switch on Transition Radiation simulation. 6/12/00 18:00
    // iZDC=1  7/12/00 09:00
    // ThetaRange is (0., 180.). It was (0.28,179.72) 7/12/00 09:00
    // Theta range given through pseudorapidity limits 22/6/2001

    // Set Random Number seed
    // gRandom->SetSeed(12345);

    new     AliGeant3("C++ Interface to Geant3");

    if (!gSystem->Getenv("CONFIG_FILE"))
    {
        TFile  *rootfile = new TFile("galice.root", "recreate");

        rootfile->SetCompressionLevel(2);
    }

    TGeant3 *geant3 = (TGeant3 *) gMC;

    //
    // Set External decayer
    AliDecayer *decayer = new AliDecayerPythia();

    decayer->SetForceDecay(kAll);
    decayer->Init();
    gMC->SetExternalDecayer(decayer);
    //
    //
    //=======================================================================
    // ******* GEANT STEERING parameters FOR ALICE SIMULATION *******
    geant3->SetTRIG(1);         //Number of events to be processed
    geant3->SetSWIT(4, 10);
    geant3->SetDEBU(0, 0, 1);
    //geant3->SetSWIT(2,2);
    geant3->SetDCAY(1);
    geant3->SetPAIR(1);
    geant3->SetCOMP(1);
    geant3->SetPHOT(1);
    geant3->SetPFIS(0);
    geant3->SetDRAY(0);
    geant3->SetANNI(1);
    geant3->SetBREM(1);
    geant3->SetMUNU(1);
    geant3->SetCKOV(1);
    geant3->SetHADR(1);         //Select pure GEANH (HADR 1) or GEANH/NUCRIN (HADR 3)
    geant3->SetLOSS(2);
    geant3->SetMULS(1);
    geant3->SetRAYL(1);
    geant3->SetAUTO(1);         //Select automatic STMIN etc... calc. (AUTO 1) or manual (AUTO 0)
    geant3->SetABAN(0);         //Restore 3.16 behaviour for abandoned tracks
    geant3->SetOPTI(2);         //Select optimisation level for GEANT geometry searches (0,1,2)
    geant3->SetERAN(5.e-7);

    Float_t cut = 1.e-3;        // 1MeV cut by default
    Float_t tofmax = 1.e10;

    //             GAM ELEC NHAD CHAD MUON EBREM MUHAB EDEL MUDEL MUPA TOFMAX
    geant3->SetCUTS(cut, cut, cut, cut, cut, cut, cut, cut, cut, cut,
                    tofmax);
    //
    //=======================================================================
    // ************* STEERING parameters FOR ALICE SIMULATION **************
    // --- Specify event type to be tracked through the ALICE setup
    // --- All positions are in cm, angles in degrees, and P and E in GeV
    if (gSystem->Getenv("CONFIG_NPARTICLES"))
    {
        int     nParticles = atoi(gSystem->Getenv("CONFIG_NPARTICLES"));
    } else
    {
        int     nParticles = 50;
    }
    AliGenHIJINGpara *gener = new AliGenHIJINGpara(nParticles);

    gener->SetMomentumRange(0, 999);
    gener->SetPhiRange(0, 360);
    // Set pseudorapidity range from -8 to 8.
    Float_t thmin = EtaToTheta(8);   // theta min. <---> eta max
    Float_t thmax = EtaToTheta(-8);  // theta max. <---> eta min
    gener->SetThetaRange(thmin,thmax);
    gener->SetOrigin(0, 0, 0);  //vertex position
    gener->SetSigma(0, 0, 0);   //Sigma in (X,Y,Z) (cm) on IP position
    gener->Init();
    //
    // Activate this line if you want the vertex smearing to happen
    // track by track
    //
    //gener->SetVertexSmear(perTrack);

    gAlice->SetField(-999, 2);  //Specify maximum magnetic field in Tesla (neg. ==> default field)

    Int_t   iABSO = 1;
    Int_t   iDIPO = 1;
    Int_t   iFMD = 1;
    Int_t   iFRAME = 1;
    Int_t   iHALL = 1;
    Int_t   iITS = 1;
    Int_t   iMAG = 1;
    Int_t   iMUON = 1;
    Int_t   iPHOS = 1;
    Int_t   iPIPE = 1;
    Int_t   iPMD = 1;
    Int_t   iRICH = 1;
    Int_t   iSHIL = 1;
    Int_t   iSTART = 1;
    Int_t   iTOF = 1;
    Int_t   iTPC = 1;
    Int_t   iTRD = 1;
    Int_t   iZDC = 1;
    Int_t   iEMCAL = 0;

    //=================== Alice BODY parameters =============================
    AliBODY *BODY = new AliBODY("BODY", "Alice envelop");

    if (iMAG)
    {
        //=================== MAG parameters ============================
        // --- Start with Magnet since detector layouts may be depending ---
        // --- on the selected Magnet dimensions ---
        AliMAG *MAG = new AliMAG("MAG", "Magnet");
    }

    if (iABSO)
    {
        //=================== ABSO parameters ============================
        AliABSO *ABSO = new AliABSOv0("ABSO", "Muon Absorber");
    }

    if (iDIPO)
    {
        //=================== DIPO parameters ============================

        AliDIPO *DIPO = new AliDIPOv2("DIPO", "Dipole version 2");
    }

    if (iHALL)
    {
        //=================== HALL parameters ============================

        AliHALL *HALL = new AliHALL("HALL", "Alice Hall");
    }

    if (iFRAME)
    {
        //=================== FRAME parameters ============================

        AliFRAME *FRAME = new AliFRAMEv2("FRAME", "Space Frame");

    }

    if (iSHIL)
    {
        //=================== SHIL parameters ============================

        AliSHIL *SHIL = new AliSHILvF("SHIL", "Shielding");
    }

    if (iPIPE)
    {
        //=================== PIPE parameters ============================

        AliPIPE *PIPE = new AliPIPEv0("PIPE", "Beam Pipe");
    }

  if(iITS) {

//=================== ITS parameters ============================
    //
    // As the innermost detector in ALICE, the Inner Tracking System "impacts" on
    // almost all other detectors. This involves the fact that the ITS geometry
    // still has several options to be followed in parallel in order to determine
    // the best set-up which minimizes the induced background. All the geometries
    // available to date are described in the following. Read carefully the comments
    // and use the default version (the only one uncommented) unless you are making
    // comparisons and you know what you are doing. In this case just uncomment the
    // ITS geometry you want to use and run Aliroot.
    //
    // Detailed geometries:
    //
    //
    //AliITS *ITS  = new AliITSv5symm("ITS","Updated ITS TDR detailed version with symmetric services");
    //
    //AliITS *ITS  = new AliITSv5asymm("ITS","Updates ITS TDR detailed version with asymmetric services");
    //
    AliITSvPPRasymm *ITS  = new AliITSvPPRasymm("ITS","New ITS PPR detailed version with asymmetric services");
    ITS->SetMinorVersion(2);					 // don't touch this parameter if you're not an ITS developer
    ITS->SetReadDet(kFALSE);					 // don't touch this parameter if you're not an ITS developer
    //    ITS->SetWriteDet("$ALICE_ROOT/ITS/ITSgeometry_vPPRasymm2.det");  // don't touch this parameter if you're not an ITS developer
    ITS->SetThicknessDet1(200.);   // detector thickness on layer 1 must be in the range [100,300]
    ITS->SetThicknessDet2(200.);   // detector thickness on layer 2 must be in the range [100,300]
    ITS->SetThicknessChip1(200.);  // chip thickness on layer 1 must be in the range [150,300]
    ITS->SetThicknessChip2(200.);  // chip thickness on layer 2 must be in the range [150,300]
    ITS->SetRails(1);	     // 1 --> rails in ; 0 --> rails out
    ITS->SetCoolingFluid(1);   // 1 --> water ; 0 --> freon
    //
    //AliITSvPPRsymm *ITS  = new AliITSvPPRsymm("ITS","New ITS PPR detailed version with symmetric services");
    //ITS->SetMinorVersion(2);                                       // don't touch this parameter if you're not an ITS developer
    //ITS->SetReadDet(kFALSE);                                       // don't touch this parameter if you're not an ITS developer
    //ITS->SetWriteDet("$ALICE_ROOT/ITS/ITSgeometry_vPPRsymm2.det"); // don't touch this parameter if you're not an ITS developer
    //ITS->SetThicknessDet1(200.);   // detector thickness on layer 1 must be in the range [100,300]
    //ITS->SetThicknessDet2(200.);   // detector thickness on layer 2 must be in the range [100,300]
    //ITS->SetThicknessChip1(200.);  // chip thickness on layer 1 must be in the range [150,300]
    //ITS->SetThicknessChip2(200.);  // chip thickness on layer 2 must be in the range [150,300]
    //ITS->SetRails(1);              // 1 --> rails in ; 0 --> rails out
    //ITS->SetCoolingFluid(1);       // 1 --> water ; 0 --> freon
    //
    //
    // Coarse geometries (warning: no hits are produced with these coarse geometries and they unuseful
    // for reconstruction !):
    //
    //
    //AliITSvPPRcoarseasymm *ITS  = new AliITSvPPRcoarseasymm("ITS","New ITS PPR coarse version with asymmetric services");
    //ITS->SetRails(1);                // 1 --> rails in ; 0 --> rails out
    //ITS->SetSupportMaterial(0);      // 0 --> Copper ; 1 --> Aluminum ; 2 --> Carbon
    //
    //AliITS *ITS  = new AliITSvPPRcoarsesymm("ITS","New ITS PPR coarse version with symmetric services");
    //ITS->SetRails(1);                // 1 --> rails in ; 0 --> rails out
    //ITS->SetSupportMaterial(0);      // 0 --> Copper ; 1 --> Aluminum ; 2 --> Carbon
    //
    //
    //
    // Geant3 <-> EUCLID conversion
    // ============================
    //
    // SetEUCLID is a flag to output (=1) or not to output (=0) both geometry and
    // media to two ASCII files (called by default ITSgeometry.euc and
    // ITSgeometry.tme) in a format understandable to the CAD system EUCLID.
    // The default (=0) means that you dont want to use this facility.
    //
    ITS->SetEUCLID(0);
  }

    if (iTPC)
    {
        //============================ TPC parameters ================================
        // --- This allows the user to specify sectors for the SLOW (TPC geometry 2)
        // --- Simulator. SecAL (SecAU) <0 means that ALL lower (upper)
        // --- sectors are specified, any value other than that requires at least one
        // --- sector (lower or upper)to be specified!
        // --- Reminder: sectors 1-24 are lower sectors (1-12 -> z>0, 13-24 -> z<0)
        // ---           sectors 25-72 are the upper ones (25-48 -> z>0, 49-72 -> z<0)
        // --- SecLows - number of lower sectors specified (up to 6)
        // --- SecUps - number of upper sectors specified (up to 12)
        // --- Sens - sensitive strips for the Slow Simulator !!!
        // --- This does NOT work if all S or L-sectors are specified, i.e.
        // --- if SecAL or SecAU < 0
        //
        //
        //-----------------------------------------------------------------------------

        //  gROOT->LoadMacro("SetTPCParam.C");
        //  AliTPCParam *param = SetTPCParam();
        AliTPC *TPC = new AliTPCv2("TPC", "Default");

        // All sectors included
        TPC->SetSecAL(-1);
        TPC->SetSecAU(-1);

    }

    if (iTOF)
    {
        //=================== TOF parameters ============================
        AliTOF *TOF = new AliTOFv2("TOF", "normal TOF");
    }

    if (iRICH)
    {
        //=================== RICH parameters ===========================
        AliRICH *RICH = new AliRICHv1("RICH", "normal RICH");

    }

    if (iZDC)
    {
        //=================== ZDC parameters ============================

        AliZDC *ZDC = new AliZDCv2("ZDC", "normal ZDC");
    }

    if (iTRD)
    {
        //=================== TRD parameters ============================

        AliTRD *TRD = new AliTRDv1("TRD", "TRD slow simulator");

        // Select the gas mixture (0: 97% Xe + 3% isobutane, 1: 90% Xe + 10% CO2)
        TRD->SetGasMix(1);

        // With hole in front of PHOS
        TRD->SetPHOShole();
        // With hole in front of RICH
        TRD->SetRICHhole();
        // Switch on TR
        AliTRDsim *TRDsim = TRD->CreateTR();
    }

    if (iFMD)
    {
        //=================== FMD parameters ============================

        AliFMD *FMD = new AliFMDv1("FMD", "normal FMD");
        FMD->SetRingsSi1(256);
        FMD->SetRingsSi2(64);
        FMD->SetSectorsSi1(20);
        FMD->SetSectorsSi2(24);
   }

    if (iMUON)
    {
        //=================== MUON parameters ===========================

        AliMUON *MUON = new AliMUONv1("MUON", "default");
    }
    //=================== PHOS parameters ===========================

    if (iPHOS)
    {
        AliPHOS *PHOS = new AliPHOSv1("PHOS", "GPS2");
    }

    if (iPMD)
    {
        //=================== PMD parameters ============================

        AliPMD *PMD = new AliPMDv1("PMD", "normal PMD");

        PMD->SetPAR(1., 1., 0.8, 0.02);
        PMD->SetIN(6., 18., -580., 27., 27.);
        PMD->SetGEO(0.0, 0.2, 4.);
        PMD->SetPadSize(0.8, 1.0, 1.0, 1.5);

    }

    if (iEMCAL && !iRICH)
    {
        //=================== EMCAL parameters ============================
        AliEMCAL *EMCAL = new AliEMCALv1("EMCAL", "EMCALArch1a");
    }

    if (iSTART)
    {
        //=================== START parameters ============================
        AliSTART *START = new AliSTARTv1("START", "START Detector");
    }

}

Float_t EtaToTheta(Float_t arg){
  return (180./TMath::Pi())*2.*atan(exp(-arg));
}
<|endoftext|>


<commit_before>#include <iostream.h>

static Bool_t isGeant4 = false;
static Bool_t isSteer = false;
static Bool_t isDetector = false;

void g4libs()
{
  // g4libs_global();
  g4libs_granular();
}

void g4libs_global()
{
// Loads G4 global libraries,
// external packages: CLHEP, graphics drivers, .. used by G4
// and Alice G4 libraries: AliGeant4, TGeant4
// ---
  if (!isGeant4) {

    // CLHEP
    gSystem->Load("$(CLHEP_BASE_DIR)/lib/libCLHEP");

    // Geant4
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4global");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4graphics_reps");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4intercoms");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4materials");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4geometry");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4particles");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4track");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4processes");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4tracking");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4digits+hits");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4event");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4readout");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4run");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG3toG4");

    // Geant4 interfaces
    //gSystem->Load("/usr/X11R6/lib/libXt");
    //gSystem->Load("/usr/local/lib/libXm");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIcommon");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIbasic");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIGAG");

    // Geant4 visualization
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4vis_management");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4modeling");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4FR");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4OpenGL");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4VRML");

    // TGeant4, AliGeant4
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTGeant4");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libAliGeant4");

    isGeant4 = true;
    cout << "Geant4 global libraries have been loaded." << endl;
  }
}

void g4libs_granular()
{
// Loads G4 granular libraries,
// external packages: CLHEP, graphics drivers, .. used by G4
// and Alice G4 libraries: AliGeant4, TGeant4
// ---
  if (!isGeant4) {

    // CLHEP
    gSystem->Load("$(CLHEP_BASE_DIR)/lib/libCLHEP");

    // G4 categories

    // global
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4globman");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hepnumerics");

    // graphics_reps
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4graphics_reps");

    // intercoms
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4intercoms");

    // materials
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4materials");

    // geometry
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4magneticfield");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4volumes");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4geometrymng");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4geomBoolean");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4csg");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4step");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4brep");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4stepinterface");

    // particles
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4partman");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4bosons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4baryons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4ions");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4mesons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4leptons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4shortlived");

    // track
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4track");

    // processes
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4procman");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4parameterisation");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4decay");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4emutils");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4emstandard");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4emlowenergy");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4muons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4xrays");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_xsect");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_mgt");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_proc");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_stop");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_util");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_man_gen");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_deex");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_string_common");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_diffstring");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_stringfrag");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_HE_gen");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_kinetic");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_preequ");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_qgstring");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_util_gen");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_HE");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_LE");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_iso");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_neu");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4optical");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4photolepton_hadron");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4transportation");

    // tracking
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4tracking");

    // digits+hits
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hits");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4digits");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4detector");

    // event
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4event");

    // readout
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4readout");

    // run
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4run");

    // g3tog4
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG3toG4");

    // interfaces
    //gSystem->Load("/usr/X11R6/lib/libXt");
    //gSystem->Load("/usr/local/lib/libXm");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIcommon");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIbasic");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIGAG");

    // visualisation
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4vis_management");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4modeling");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4FR");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4OpenGL");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4VRML");

    // TGeant4, AliGeant4
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTGeant4");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libAliGeant4");

    isGeant4 = true;
    cout << "Geant4 granular libraries have been loaded." << endl;
  }
}

void steerlibs() {
// Loads AliRoot steer libraries
// ---
  if (!isSteer) {

    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libSTEER");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libdummypythia");
    gSystem->Load("$(ROOTSYS)/lib/libEGPythia");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libEVGEN");

    isSteer = true;
    cout << "AliRoot steer libraries have been loaded." << endl;
  }
}

void detlibs() {
// Load AliRoot modules libraries
// ---
  if (!isDetector) {

    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libminicern");
    // minicern required by MUON
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libSTRUCT");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libFMD");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libMUON");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libPHOS");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libPMD");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libRICH");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTOF");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTPC");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTRD");
    //gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libZDC");
       // requires symbols from geant3 lib
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libITS");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libCASTOR");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libSTART");

    isDetector = true;
    cout << "AliRoot detectors libraries have been loaded." << endl;
  }
}
<commit_msg>corrected ordering of libraries (required by HP)<commit_after>#include <iostream.h>

static Bool_t isGeant4 = false;
static Bool_t isSteer = false;
static Bool_t isDetector = false;

void g4libs()
{
  // g4libs_global();
  g4libs_granular();
}

void g4libs_global()
{
// Loads G4 global libraries,
// external packages: CLHEP, graphics drivers, .. used by G4
// and Alice G4 libraries: AliGeant4, TGeant4
// ---
  if (!isGeant4) {

    // CLHEP
    gSystem->Load("$(CLHEP_BASE_DIR)/lib/libCLHEP");

    // Geant4
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4global");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4graphics_reps");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4intercoms");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4materials");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4geometry");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4particles");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4track");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4processes");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4tracking");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4digits+hits");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4event");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4readout");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4run");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG3toG4");

    // Geant4 interfaces
    //gSystem->Load("/usr/X11R6/lib/libXt");
    //gSystem->Load("/usr/local/lib/libXm");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIcommon");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIbasic");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIGAG");

    // Geant4 visualization
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4vis_management");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4modeling");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4FR");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4OpenGL");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4VRML");

    // TGeant4, AliGeant4
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTGeant4");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libAliGeant4");

    isGeant4 = true;
    cout << "Geant4 global libraries have been loaded." << endl;
  }
}

void g4libs_granular()
{
// Loads G4 granular libraries,
// external packages: CLHEP, graphics drivers, .. used by G4
// and Alice G4 libraries: AliGeant4, TGeant4
// ---
  if (!isGeant4) {

    // CLHEP
    gSystem->Load("$(CLHEP_BASE_DIR)/lib/libCLHEP");

    // G4 categories

    // global
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4globman");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hepnumerics");

    // graphics_reps
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4graphics_reps");

    // intercoms
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4intercoms");

    // materials
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4materials");

    // geometry
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4magneticfield");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4volumes");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4geometrymng");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4geomBoolean");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4csg");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4step");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4brep");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4specsolids");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4stepinterface");

    // particles
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4partman");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4bosons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4baryons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4ions");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4mesons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4leptons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4shortlived");

    // track
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4track");

    // processes
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4procman");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4parameterisation");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4decay");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4emutils");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4emstandard");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4emlowenergy");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4muons");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4xrays");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_xsect");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_mgt");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_proc");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_util");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_man_gen");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_util_gen");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_string_common");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_diffstring");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_stringfrag");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_HE_gen");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_kinetic");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_preequ");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_qgstring");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_HE");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_LE");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_deex");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_stop");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_neu");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hadronic_iso");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4optical");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4photolepton_hadron");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4transportation");

    // tracking
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4tracking");

    // digits+hits
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4hits");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4digits");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4detector");

    // event
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4event");

    // readout
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4readout");

    // run
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4run");

    // g3tog4
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG3toG4");

    // interfaces
    //gSystem->Load("/usr/X11R6/lib/libXt");
    //gSystem->Load("/usr/local/lib/libXm");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIcommon");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIbasic");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4UIGAG");

    // visualisation
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4modeling");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4vis_management");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4FR");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4OpenGL");
    gSystem->Load("$(G4INSTALL)/lib/$(G4SYSTEM)/libG4VRML");

    // TGeant4, AliGeant4
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTGeant4");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libAliGeant4");

    isGeant4 = true;
    cout << "Geant4 granular libraries have been loaded." << endl;
  }
}

void steerlibs() {
// Loads AliRoot steer libraries
// ---
  if (!isSteer) {

    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libSTEER");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libdummypythia");
    gSystem->Load("$(ROOTSYS)/lib/libEGPythia");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libEVGEN");

    isSteer = true;
    cout << "AliRoot steer libraries have been loaded." << endl;
  }
}

void detlibs() {
// Load AliRoot modules libraries
// ---
  if (!isDetector) {

    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libminicern");
    // minicern required by MUON
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libSTRUCT");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libFMD");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libMUON");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libPHOS");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libPMD");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libRICH");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTOF");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTPC");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTRD");
    //gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libZDC");
       // requires symbols from geant3 lib
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libITS");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libCASTOR");
    gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libSTART");

    isDetector = true;
    cout << "AliRoot detectors libraries have been loaded." << endl;
  }
}
<|endoftext|>


<commit_before>// Copyright 2010-2012 RethinkDB, all rights reserved.
#ifndef CONCURRENCY_PUBSUB_HPP_
#define CONCURRENCY_PUBSUB_HPP_

#include "arch/runtime/runtime_utils.hpp"
#include "concurrency/mutex_assertion.hpp"
#include "containers/intrusive_list.hpp"
#include "utils.hpp"

/* Forward declaration */

template<class subscriber_t>
class publisher_controller_t;

/* `publisher_t` is used to implement small-scale pub/sub architectures. It's
useful whenever you need to broadcast notifications to some number of listeners.

Each publisher has zero or more subscriptions. Each subscription is associated
with a subscriber. A subscription is usually associated with one publisher, but
it is possible to unassociate a subscription or to move it from one publisher to
another.

The publisher handles concurrency issues for you. In particular, it won't let
you add or remove subscribers or destroy the publisher while in the middle of
delivering a notification. */

template<class subscriber_t>
class publisher_t {
public:
    class subscription_t : public intrusive_list_node_t<subscription_t> {
    public:
        /* Construct a `subscription_t` that is not subscribed to any publisher.
        */
        explicit subscription_t(subscriber_t sub) : subscriber(sub), publisher(NULL) { }

        /* Construct a `subscription_t` and subscribe to the given publisher. */
        subscription_t(subscriber_t sub, publisher_t *pub) : subscriber(sub), publisher(NULL) {
            reset(pub);
        }

        /* Cause us to be subscribed to the given publisher (if any) and not to
        any other publisher. */
        void reset(publisher_t *pub = NULL) {
            if (publisher) {
                DEBUG_VAR mutex_assertion_t::acq_t acq(&publisher->mutex);
                publisher->subscriptions.remove(this);
            }
            publisher = pub;
            if (publisher) {
                DEBUG_VAR mutex_assertion_t::acq_t acq(&publisher->mutex);
                publisher->subscriptions.push_back(this);
            }
        }

        /* Unsubscribe from the publisher you are subscribed to, if any. */
        ~subscription_t() {
            reset();
        }

        subscriber_t subscriber;

    private:
        friend class publisher_controller_t<subscriber_t>;

        publisher_t *publisher;

        DISABLE_COPYING(subscription_t);
    };

    void rethread(threadnum_t new_thread) {
        mutex.rethread(new_thread);
    }

private:
    friend class subscription_t;
    friend class publisher_controller_t<subscriber_t>;

    publisher_t() { }
    ~publisher_t() {
        rassert(subscriptions.empty());
    }

    intrusive_list_t<subscription_t> subscriptions;
    mutex_assertion_t mutex;

    DISABLE_COPYING(publisher_t);
};

/* To create a publisher, create a `publisher_controller_t` and call its
`get_publisher()` method. `publisher_t` is split from `publisher_controller_t`
so that you can pass a `publisher_t *` to things; they will be able to listen
for events, but not publish events themselves.

To publish things, call `publish()` on the `publisher_controller_t` you
created. `publish()` takes a function, which will be called once for each
subscription. The function must not block. */

template<class subscriber_t>
class publisher_controller_t : public home_thread_mixin_t {
public:
    publisher_controller_t() { }

    publisher_t<subscriber_t> *get_publisher() {
        return &publisher;
    }

    template<class callable_t>
    void publish(const callable_t &callable) {
        DEBUG_VAR mutex_assertion_t::acq_t acq(&publisher.mutex);
        for (typename publisher_t<subscriber_t>::subscription_t *sub = publisher.subscriptions.head();
             sub;
             sub = publisher.subscriptions.next(sub)) {
            /* `callable()` should not block */
            ASSERT_FINITE_CORO_WAITING;
            callable(sub->subscriber);
        }
    }

    void rethread(threadnum_t new_thread) {
        rassert(publisher.subscriptions.empty(),
                "Cannot rethread a `publisher_t` that has subscribers.");
        publisher.rethread(new_thread);
        real_home_thread = new_thread;
    }

private:
    publisher_t<subscriber_t> publisher;
    DISABLE_COPYING(publisher_controller_t);
};

#endif /* CONCURRENCY_PUBSUB_HPP_ */
<commit_msg>Removed unused home_thread_mixin_t base class of publisher_controller_t.<commit_after>// Copyright 2010-2012 RethinkDB, all rights reserved.
#ifndef CONCURRENCY_PUBSUB_HPP_
#define CONCURRENCY_PUBSUB_HPP_

#include "arch/runtime/runtime_utils.hpp"
#include "concurrency/mutex_assertion.hpp"
#include "containers/intrusive_list.hpp"
#include "utils.hpp"

/* Forward declaration */

template<class subscriber_t>
class publisher_controller_t;

/* `publisher_t` is used to implement small-scale pub/sub architectures. It's
useful whenever you need to broadcast notifications to some number of listeners.

Each publisher has zero or more subscriptions. Each subscription is associated
with a subscriber. A subscription is usually associated with one publisher, but
it is possible to unassociate a subscription or to move it from one publisher to
another.

The publisher handles concurrency issues for you. In particular, it won't let
you add or remove subscribers or destroy the publisher while in the middle of
delivering a notification. */

template<class subscriber_t>
class publisher_t {
public:
    class subscription_t : public intrusive_list_node_t<subscription_t> {
    public:
        /* Construct a `subscription_t` that is not subscribed to any publisher.
        */
        explicit subscription_t(subscriber_t sub) : subscriber(sub), publisher(NULL) { }

        /* Construct a `subscription_t` and subscribe to the given publisher. */
        subscription_t(subscriber_t sub, publisher_t *pub) : subscriber(sub), publisher(NULL) {
            reset(pub);
        }

        /* Cause us to be subscribed to the given publisher (if any) and not to
        any other publisher. */
        void reset(publisher_t *pub = NULL) {
            if (publisher) {
                DEBUG_VAR mutex_assertion_t::acq_t acq(&publisher->mutex);
                publisher->subscriptions.remove(this);
            }
            publisher = pub;
            if (publisher) {
                DEBUG_VAR mutex_assertion_t::acq_t acq(&publisher->mutex);
                publisher->subscriptions.push_back(this);
            }
        }

        /* Unsubscribe from the publisher you are subscribed to, if any. */
        ~subscription_t() {
            reset();
        }

        subscriber_t subscriber;

    private:
        friend class publisher_controller_t<subscriber_t>;

        publisher_t *publisher;

        DISABLE_COPYING(subscription_t);
    };

    void rethread(threadnum_t new_thread) {
        mutex.rethread(new_thread);
    }

private:
    friend class subscription_t;
    friend class publisher_controller_t<subscriber_t>;

    publisher_t() { }
    ~publisher_t() {
        rassert(subscriptions.empty());
    }

    intrusive_list_t<subscription_t> subscriptions;
    mutex_assertion_t mutex;

    DISABLE_COPYING(publisher_t);
};

/* To create a publisher, create a `publisher_controller_t` and call its
`get_publisher()` method. `publisher_t` is split from `publisher_controller_t`
so that you can pass a `publisher_t *` to things; they will be able to listen
for events, but not publish events themselves.

To publish things, call `publish()` on the `publisher_controller_t` you
created. `publish()` takes a function, which will be called once for each
subscription. The function must not block. */

template<class subscriber_t>
class publisher_controller_t {
public:
    publisher_controller_t() { }

    publisher_t<subscriber_t> *get_publisher() {
        return &publisher;
    }

    template<class callable_t>
    void publish(const callable_t &callable) {
        DEBUG_VAR mutex_assertion_t::acq_t acq(&publisher.mutex);
        for (typename publisher_t<subscriber_t>::subscription_t *sub = publisher.subscriptions.head();
             sub;
             sub = publisher.subscriptions.next(sub)) {
            /* `callable()` should not block */
            ASSERT_FINITE_CORO_WAITING;
            callable(sub->subscriber);
        }
    }

    void rethread(threadnum_t new_thread) {
        rassert(publisher.subscriptions.empty(),
                "Cannot rethread a `publisher_t` that has subscribers.");
        publisher.rethread(new_thread);
    }

private:
    publisher_t<subscriber_t> publisher;
    DISABLE_COPYING(publisher_controller_t);
};

#endif /* CONCURRENCY_PUBSUB_HPP_ */
<|endoftext|>


<commit_before>#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
#include <android/native_window.h> // requires ndk r5 or newer
#include <EGL/egl.h> // requires ndk r5 or newer
#include <GLES/gl.h>
#include <EGL/eglplatform.h>
#include <string>
#include <time.h>
#include "renderer.h"

#include <common/MapController.hpp>
#include <common/MapDisplay.hpp>
#include <common/Camera.hpp>

void DetachThreadFromVM(void);

Renderer::Renderer() {
    LOG_INFO("Renderer instance created");
    pthread_mutex_init(&_mutex, 0);
    _window = NULL;
    _display = EGL_NO_DISPLAY;
    _surface = EGL_NO_SURFACE;
    _context = EGL_NO_CONTEXT;

    _currentTimeSec = double(clock()) / double(CLOCKS_PER_SEC);
    _initialTimeSec = _currentTimeSec;

    _rotateX = 0.0f;
    _rotateY = 0.0f;
    _rotateZ = 0.0f;
    _zoom = 0.0f;

    // Lock the mutex to keep the thread from doing anything until we get resumed
    pthread_mutex_lock(&_mutex);
    _paused = true;

    // Create the rendering thread
    _done = false;
    pthread_create(&_threadId, 0, threadStartCallback, this);

    return;
}

Renderer::~Renderer() {
    LOG_INFO("Renderer instance destroyed");
    _done = true;
    if (_paused) {
        pthread_mutex_unlock(&_mutex);
    }
    pthread_join(_threadId, 0);
    destroy();
    pthread_mutex_destroy(&_mutex);
    return;
}

void Renderer::resume() {
    assert(_paused);
    _paused = false;
    pthread_mutex_unlock(&_mutex);
    return;
}

void Renderer::pause() {
    assert(!_paused);
    pthread_mutex_lock(&_mutex);
    _paused = true;
    return;
}

void Renderer::bufferedRotationX(float radiansX) {
    _rotateX += radiansX;
}

void Renderer::bufferedRotationY(float radiansY) {
    _rotateY += radiansY;
}

void Renderer::bufferedRotationZ(float radiansZ) {
    _rotateZ += radiansZ;
}

void Renderer::bufferedZoom(float zoom) {
    _zoom += zoom;
}

void Renderer::setWindow(ANativeWindow *window, float displayScale) {
    _displayScale = displayScale;

    // notify render thread that window has changed
    if (!_paused) {
        pthread_mutex_lock(&_mutex);
    }
    _window = window;
    if (!_paused) {
        pthread_mutex_unlock(&_mutex);
    }

    return;
}

void Renderer::renderLoop() {
    pthread_mutex_lock(&_mutex);

    while (!_done) {
        // TODO: do we need to handle the window changing after creation, don't think so, but not sure
        if ((_display == EGL_NO_DISPLAY) && _window) {
            initialize();
        }

        // Main thread might want to take this context current during the gap below, need to release it here
        if (_display != EGL_NO_DISPLAY) {
            if (!eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    EGL_NO_CONTEXT)) {
                LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
            }
        }

        // Let the main thread do any work that it is waiting on us for
        pthread_mutex_unlock(&_mutex);
        // sched_yield();
        //the scheduler is being flaky, force sleep long enough for the main thread to wake
        usleep(1000);
        pthread_mutex_lock(&_mutex);

        if(_rotateX != 0.0f) {
            _mapController->display->camera->rotateRadiansX(_rotateX);
        }

        if(_rotateY != 0.0f) {
            _mapController->display->camera->rotateRadiansY(_rotateY);
        }

        if(_rotateZ != 0.0f) {
            _mapController->display->camera->rotateRadiansZ(_rotateZ);
        }

        if(_zoom != 0.0f) {
            _mapController->display->camera->zoomByScale(_zoom);
        }

        _rotateX = 0.0f;
        _rotateY = 0.0f;
        _rotateZ = 0.0f;
        _zoom = 0.0f;

        if (_display != EGL_NO_DISPLAY) {
            // Take back control of GL context
            if (!eglMakeCurrent(_display, _surface, _surface, _context)) {
                LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
                // Hack: this fails when we rotate, delete the context to force a recreation
                // TODO: need to detect and handle this better
                destroy();
            }
        }

        if (_display != EGL_NO_DISPLAY) {
            drawFrame();

            if (!eglSwapBuffers(_display, _surface)) {
                LOG_ERROR("eglSwapBuffers() returned error %d", eglGetError());
            }
        }

    }

    pthread_mutex_unlock(&_mutex);

    DetachThreadFromVM();

    LOG_INFO("Render loop exits");

    return;
}

bool Renderer::initialize() {
    const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_BLUE_SIZE, 8,
            EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE };

    const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };

    EGLDisplay display;
    EGLConfig config;
    EGLint numConfigs;
    EGLint format;
    EGLSurface surface;
    EGLContext context;
    EGLint width;
    EGLint height;

    LOG_INFO("Initializing context");

    if ((display = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) {
        LOG_ERROR("eglGetDisplay() returned error %d", eglGetError());
        return false;
    }

    if (!eglInitialize(display, 0, 0)) {
        LOG_ERROR("eglInitialize() returned error %d", eglGetError());
        return false;
    }

    if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs)) {
        LOG_ERROR("eglChooseConfig() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) {
        LOG_ERROR("eglGetConfigAttrib() returned error %d", eglGetError());
        destroy();
        return false;
    }

    ANativeWindow_setBuffersGeometry(_window, 0, 0, format);

    if (!(surface = eglCreateWindowSurface(display, config, _window, 0))) {
        LOG_ERROR("eglCreateWindowSurface() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!(context = eglCreateContext(display, config, 0, contextAttribs))) {
        LOG_ERROR("eglCreateContext() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglMakeCurrent(display, surface, surface, context)) {
        LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglQuerySurface(display, surface, EGL_WIDTH, &width)
            || !eglQuerySurface(display, surface, EGL_HEIGHT, &height)) {
        LOG_ERROR("eglQuerySurface() returned error %d", eglGetError());
        destroy();
        return false;
    }

    LOG("display size: %d %d %.2f", width, height, _displayScale);
    _display = display;
    _surface = surface;
    _context = context;
    _width = width;
    _height = height;

    LOG("created GL context");

    _mapController = new MapController;
    _mapController->display->camera->setDisplaySize(width, height);

    _mapController->display->setDisplayScale(_displayScale);

    _mapController->data->updateDisplay(_mapController->display);

    _mapController->display->camera->setAllowIdleAnimation(true);

    LOG("created map controller");

    return true;
}

void Renderer::destroy() {
    LOG_INFO("Destroying context");

    delete _mapController;
    _mapController = NULL;

    eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    eglDestroyContext(_display, _context);
    eglDestroySurface(_display, _surface);
    eglTerminate(_display);

    _display = EGL_NO_DISPLAY;
    _surface = EGL_NO_SURFACE;
    _context = EGL_NO_CONTEXT;
    _width = 0;
    _height = 0;

    return;
}

MapController* Renderer::beginControllerModification(void) {
    // Wait for render thread to block
    if (!_paused) {
        pthread_mutex_lock(&_mutex);
    }

    // Make context current in this thread
    if (!eglMakeCurrent(_display, _surface, _surface, _context)) {
        LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
    }

    return _mapController;
}

void Renderer::endControllerModification(void) {
    // Release context so renderer can grab it
    if (!eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
            EGL_NO_CONTEXT)) {
        LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
    }

    if (!_paused) {
        // let the renderer go
        pthread_mutex_unlock(&_mutex);
    }
}

void Renderer::drawFrame() {
    _currentTimeSec = double(clock()) / double(CLOCKS_PER_SEC);
    _mapController->update(_currentTimeSec - _initialTimeSec);
    _mapController->display->draw();
}

void* Renderer::threadStartCallback(void *myself) {
    Renderer *renderer = (Renderer*) myself;

    renderer->renderLoop();
    pthread_exit(0);

    return 0;
}

// TODO
void cameraMoveFinishedCallback(void) {
}

void lostSelectedNodeCallback(void) {
}

<commit_msg>Fix Android build.<commit_after>#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
#include <android/native_window.h> // requires ndk r5 or newer
#include <EGL/egl.h> // requires ndk r5 or newer
#include <GLES/gl.h>
#include <EGL/eglplatform.h>
#include <string>
#include <time.h>
#include "renderer.h"

#include <common/MapController.hpp>
#include <common/MapDisplay.hpp>
#include <common/Camera.hpp>

void DetachThreadFromVM(void);

Renderer::Renderer() {
    LOG_INFO("Renderer instance created");
    pthread_mutex_init(&_mutex, 0);
    _window = NULL;
    _display = EGL_NO_DISPLAY;
    _surface = EGL_NO_SURFACE;
    _context = EGL_NO_CONTEXT;

    _currentTimeSec = double(clock()) / double(CLOCKS_PER_SEC);
    _initialTimeSec = _currentTimeSec;

    _rotateX = 0.0f;
    _rotateY = 0.0f;
    _rotateZ = 0.0f;
    _zoom = 0.0f;

    // Lock the mutex to keep the thread from doing anything until we get resumed
    pthread_mutex_lock(&_mutex);
    _paused = true;

    // Create the rendering thread
    _done = false;
    pthread_create(&_threadId, 0, threadStartCallback, this);

    return;
}

Renderer::~Renderer() {
    LOG_INFO("Renderer instance destroyed");
    _done = true;
    if (_paused) {
        pthread_mutex_unlock(&_mutex);
    }
    pthread_join(_threadId, 0);
    destroy();
    pthread_mutex_destroy(&_mutex);
    return;
}

void Renderer::resume() {
    assert(_paused);
    _paused = false;
    pthread_mutex_unlock(&_mutex);
    return;
}

void Renderer::pause() {
    assert(!_paused);
    pthread_mutex_lock(&_mutex);
    _paused = true;
    return;
}

void Renderer::bufferedRotationX(float radiansX) {
    _rotateX += radiansX;
}

void Renderer::bufferedRotationY(float radiansY) {
    _rotateY += radiansY;
}

void Renderer::bufferedRotationZ(float radiansZ) {
    _rotateZ += radiansZ;
}

void Renderer::bufferedZoom(float zoom) {
    _zoom += zoom;
}

void Renderer::setWindow(ANativeWindow *window, float displayScale) {
    _displayScale = displayScale;

    // notify render thread that window has changed
    if (!_paused) {
        pthread_mutex_lock(&_mutex);
    }
    _window = window;
    if (!_paused) {
        pthread_mutex_unlock(&_mutex);
    }

    return;
}

void Renderer::renderLoop() {
    pthread_mutex_lock(&_mutex);

    while (!_done) {
        // TODO: do we need to handle the window changing after creation, don't think so, but not sure
        if ((_display == EGL_NO_DISPLAY) && _window) {
            initialize();
        }

        // Main thread might want to take this context current during the gap below, need to release it here
        if (_display != EGL_NO_DISPLAY) {
            if (!eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    EGL_NO_CONTEXT)) {
                LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
            }
        }

        // Let the main thread do any work that it is waiting on us for
        pthread_mutex_unlock(&_mutex);
        // sched_yield();
        //the scheduler is being flaky, force sleep long enough for the main thread to wake
        usleep(1000);
        pthread_mutex_lock(&_mutex);

        if(_rotateX != 0.0f) {
            _mapController->display->camera->rotateRadiansX(_rotateX);
        }

        if(_rotateY != 0.0f) {
            _mapController->display->camera->rotateRadiansY(_rotateY);
        }

        if(_rotateZ != 0.0f) {
            _mapController->display->camera->rotateRadiansZ(_rotateZ);
        }

        if(_zoom != 0.0f) {
            _mapController->display->camera->zoomByScale(_zoom);
        }

        _rotateX = 0.0f;
        _rotateY = 0.0f;
        _rotateZ = 0.0f;
        _zoom = 0.0f;

        if (_display != EGL_NO_DISPLAY) {
            // Take back control of GL context
            if (!eglMakeCurrent(_display, _surface, _surface, _context)) {
                LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
                // Hack: this fails when we rotate, delete the context to force a recreation
                // TODO: need to detect and handle this better
                destroy();
            }
        }

        if (_display != EGL_NO_DISPLAY) {
            drawFrame();

            if (!eglSwapBuffers(_display, _surface)) {
                LOG_ERROR("eglSwapBuffers() returned error %d", eglGetError());
            }
        }

    }

    pthread_mutex_unlock(&_mutex);

    DetachThreadFromVM();

    LOG_INFO("Render loop exits");

    return;
}

bool Renderer::initialize() {
    const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_BLUE_SIZE, 8,
            EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE };

    const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };

    EGLDisplay display;
    EGLConfig config;
    EGLint numConfigs;
    EGLint format;
    EGLSurface surface;
    EGLContext context;
    EGLint width;
    EGLint height;

    LOG_INFO("Initializing context");

    if ((display = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) {
        LOG_ERROR("eglGetDisplay() returned error %d", eglGetError());
        return false;
    }

    if (!eglInitialize(display, 0, 0)) {
        LOG_ERROR("eglInitialize() returned error %d", eglGetError());
        return false;
    }

    if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs)) {
        LOG_ERROR("eglChooseConfig() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) {
        LOG_ERROR("eglGetConfigAttrib() returned error %d", eglGetError());
        destroy();
        return false;
    }

    ANativeWindow_setBuffersGeometry(_window, 0, 0, format);

    if (!(surface = eglCreateWindowSurface(display, config, _window, 0))) {
        LOG_ERROR("eglCreateWindowSurface() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!(context = eglCreateContext(display, config, 0, contextAttribs))) {
        LOG_ERROR("eglCreateContext() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglMakeCurrent(display, surface, surface, context)) {
        LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglQuerySurface(display, surface, EGL_WIDTH, &width)
            || !eglQuerySurface(display, surface, EGL_HEIGHT, &height)) {
        LOG_ERROR("eglQuerySurface() returned error %d", eglGetError());
        destroy();
        return false;
    }

    LOG("display size: %d %d %.2f", width, height, _displayScale);
    _display = display;
    _surface = surface;
    _context = context;
    _width = width;
    _height = height;

    LOG("created GL context");

    _mapController = new MapController;
    _mapController->display->camera->setDisplaySize(width, height);

    _mapController->display->setDisplayScale(_displayScale);

    _mapController->updateDisplay(false);

    _mapController->display->camera->setAllowIdleAnimation(true);

    LOG("created map controller");

    return true;
}

void Renderer::destroy() {
    LOG_INFO("Destroying context");

    delete _mapController;
    _mapController = NULL;

    eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    eglDestroyContext(_display, _context);
    eglDestroySurface(_display, _surface);
    eglTerminate(_display);

    _display = EGL_NO_DISPLAY;
    _surface = EGL_NO_SURFACE;
    _context = EGL_NO_CONTEXT;
    _width = 0;
    _height = 0;

    return;
}

MapController* Renderer::beginControllerModification(void) {
    // Wait for render thread to block
    if (!_paused) {
        pthread_mutex_lock(&_mutex);
    }

    // Make context current in this thread
    if (!eglMakeCurrent(_display, _surface, _surface, _context)) {
        LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
    }

    return _mapController;
}

void Renderer::endControllerModification(void) {
    // Release context so renderer can grab it
    if (!eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
            EGL_NO_CONTEXT)) {
        LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError());
    }

    if (!_paused) {
        // let the renderer go
        pthread_mutex_unlock(&_mutex);
    }
}

void Renderer::drawFrame() {
    _currentTimeSec = double(clock()) / double(CLOCKS_PER_SEC);
    _mapController->update(_currentTimeSec - _initialTimeSec);
    _mapController->display->draw();
}

void* Renderer::threadStartCallback(void *myself) {
    Renderer *renderer = (Renderer*) myself;

    renderer->renderLoop();
    pthread_exit(0);

    return 0;
}

// TODO
void cameraMoveFinishedCallback(void) {
}

void lostSelectedNodeCallback(void) {
}

<|endoftext|>


<commit_before>/*************************************************************************
 *                                                                       *
 *  I|*j^3Cl|a   "+!*%                  qt          Nd   gW              *
 *  l]{y+l?MM*  !#Wla\NNP               NW          MM   I|              *
 *        PW    ?E|    tWg              Wg  sC!     AW           ~@v~    *
 *       NC     ?M!    yN|  WW     MK   MW@K1Y%M@   RM   #Q    QP@tim    *
 *     CM|      |WQCljAE|   MD     Mg   RN     cM~  NM   WQ   MQ         *
 *    #M        aQ?         MW     M3   Mg      Q(  HQ   YR  IM|         *
 *   Dq         {Ql         MH    iMX   Mg     MM   QP   QM   Eg         *
 * !EWNaPRag2$  +M"          $WNaHaN%   MQE$%EXW    QQ   CM    %M%a$D    *
 *                                                                       *
 *               Website: https://github.com/zpublic/zpublic             *
 *                                                                       *
 ************************************************************************/

/**
 * @file
 * @brief а
 */

#pragma once
#include "win_utils_header.h"
#include <string.h>

namespace zl
{
namespace WinUtils
{
    /**
     * @brief а࣬üаݣȡа
     */
    class ZLClipboard
    {
    public:
        /**
         * @brief а
         * @param[in]   pszData BufferҪõа
         * @param[in]   nDataLen ݵĳ
         * @return ɹTRUEʧܷFALSE
         */
        static BOOL SetClipboard(const char* pszData, const int nDataLen)
        {
            if (::OpenClipboard(NULL))
            {
                ::EmptyClipboard();
                HGLOBAL hMem = ::GlobalAlloc(GMEM_DDESHARE, nDataLen + 1);
                if (hMem)
                {
                    char *buffer = (char *)::GlobalLock(hMem);
                    strcpy_s(buffer, nDataLen + 1, pszData);
                    ::GlobalUnlock(hMem);
                    ::SetClipboardData(CF_TEXT, hMem);
                }
                ::CloseClipboard();
                return TRUE;
            }
            return FALSE;
        }
        /**
         * @brief ȡа
         * @return ɹؼаеݣʧܷؿմ
         */
        static CStringA GetClipboard()
        {
            CStringA sText;
            if (::IsClipboardFormatAvailable(CF_TEXT) && ::OpenClipboard(NULL))
            {
                HGLOBAL hMem = ::GetClipboardData(CF_TEXT);
                if (hMem)
                {
                    LPSTR lpStr = (LPSTR)::GlobalLock(hMem);
                    if (lpStr)
                    {
                        sText = lpStr;
                        ::GlobalUnlock(hMem);
                    }
                }
                ::CloseClipboard();
            }
            return sText;
        }
    };

}
}
<commit_msg>* 修整注释内容<commit_after>/*************************************************************************
 *                                                                       *
 *  I|*j^3Cl|a   "+!*%                  qt          Nd   gW              *
 *  l]{y+l?MM*  !#Wla\NNP               NW          MM   I|              *
 *        PW    ?E|    tWg              Wg  sC!     AW           ~@v~    *
 *       NC     ?M!    yN|  WW     MK   MW@K1Y%M@   RM   #Q    QP@tim    *
 *     CM|      |WQCljAE|   MD     Mg   RN     cM~  NM   WQ   MQ         *
 *    #M        aQ?         MW     M3   Mg      Q(  HQ   YR  IM|         *
 *   Dq         {Ql         MH    iMX   Mg     MM   QP   QM   Eg         *
 * !EWNaPRag2$  +M"          $WNaHaN%   MQE$%EXW    QQ   CM    %M%a$D    *
 *                                                                       *
 *               Website: https://github.com/zpublic/zpublic             *
 *                                                                       *
 ************************************************************************/

/**
 * @file
 * @brief а
 */

#pragma once
#include "win_utils_header.h"
#include <string.h>

namespace zl
{
namespace WinUtils
{
    /**
     * @brief а
     */
    class ZLClipboard
    {
    public:
        /**
         * @brief üа
         * @param[in] pszData  ָ뻺ָ
         * @param[in] nDataLen
         * @return ɹTRUEʧܷFALSE
         */
        static BOOL SetClipboard(const char* pszData, const int nDataLen)
        {
            if (::OpenClipboard(NULL))
            {
                ::EmptyClipboard();
                HGLOBAL hMem = ::GlobalAlloc(GMEM_DDESHARE, nDataLen + 1);
                if (hMem)
                {
                    char *buffer = (char *)::GlobalLock(hMem);
                    strcpy_s(buffer, nDataLen + 1, pszData);
                    ::GlobalUnlock(hMem);
                    ::SetClipboardData(CF_TEXT, hMem);
                }
                ::CloseClipboard();
                return TRUE;
            }
            return FALSE;
        }

        /**
         * @brief ȡа
         * @return а,ʧΪ
         */
        static CStringA GetClipboard()
        {
            CStringA sText;
            if (::IsClipboardFormatAvailable(CF_TEXT) && ::OpenClipboard(NULL))
            {
                HGLOBAL hMem = ::GetClipboardData(CF_TEXT);
                if (hMem)
                {
                    LPSTR lpStr = (LPSTR)::GlobalLock(hMem);
                    if (lpStr)
                    {
                        sText = lpStr;
                        ::GlobalUnlock(hMem);
                    }
                }
                ::CloseClipboard();
            }
            return sText;
        }
    };

}
}
<|endoftext|>