void create_neuland_geo(const char* geoTag)
{

  fGlobalTrans->SetTranslation(0.0,0.0,0.0);

  Double_t neuLAND_paddle_dimx   = 125.;   // half of the length [cm]
  Double_t neuLAND_paddle_dimy   = 2.4;    // half of the width [cm]
  Double_t neuLAND_paddle_dimz   = 2.4;    // half of the depth [cm]
  Double_t neuLAND_depth_dim     = 20.;   // half detector depth [cm]
  Double_t neuLAND_gap_dim       = 0.03;   // total detector depth [cm]
  Double_t neuLAND_wrapping1_dim = 0.02;   // thickness of wrapping material [cm]
  Double_t neuLAND_wrapping2_dim = 0.05;   // thickness of wrapping material [cm]
  

  // -------   Load media from media file   -----------------------------------
  FairGeoLoader*    geoLoad = new FairGeoLoader("TGeo","FairGeoLoader");
  FairGeoInterface* geoFace = geoLoad->getGeoInterface();
  TString geoPath = gSystem->Getenv("VMCWORKDIR");
  TString medFile = geoPath + "/geometry/media_r3b.geo";
  geoFace->setMediaFile(medFile);
  geoFace->readMedia();
  gGeoMan = gGeoManager;
  // --------------------------------------------------------------------------



  // -------   Geometry file name (output)   ----------------------------------
  TString geoFileName = geoPath + "/geometry/neuland_";
  geoFileName = geoFileName + geoTag + ".geo.root";
  // --------------------------------------------------------------------------



  // -----------------   Get and create the required media    -----------------
  FairGeoMedia*   geoMedia = geoFace->getMedia();
  FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();

  FairGeoMedium* mBC408      = geoMedia->getMedium("BC408");
  if ( ! mBC408 ) Fatal("Main", "FairMedium BC408 not found");
  geoBuild->createMedium(mBC408);
  TGeoMedium* pMed37 = gGeoMan->GetMedium("BC408");
  if ( ! pMed37 ) Fatal("Main", "Medium BC408 not found");

  FairGeoMedium* mCH2      = geoMedia->getMedium("CH2");
  if ( ! mCH2 ) Fatal("Main", "FairMedium CH2 not found");
  geoBuild->createMedium(mCH2);
  TGeoMedium* pMed38 = gGeoMan->GetMedium("CH2");
  if ( ! pMed38 ) Fatal("Main", "Medium CH2 not found");

  FairGeoMedium* mAl      = geoMedia->getMedium("aluminium");
  if ( ! mAl ) Fatal("Main", "FairMedium aluminium not found");
  geoBuild->createMedium(mAl);
  TGeoMedium* pMedAl = gGeoMan->GetMedium("aluminium");
  if ( ! pMedAl ) Fatal("Main", "Medium aluminium not found");
  // --------------------------------------------------------------------------



  // --------------   Create geometry and top volume  -------------------------
  gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
  gGeoMan->SetName("NEULANDgeom");
  TGeoVolume* top = new TGeoVolumeAssembly("TOP");
  gGeoMan->SetTopVolume(top);
  // --------------------------------------------------------------------------



  Double_t tx,ty,tz;
  //------------------ BC408 paddles -----------------------------------------
  TGeoVolume *padle_h_box5 = gGeoManager->MakeBox("padle_h_box5", pMed37,
						  neuLAND_paddle_dimx,
						  neuLAND_paddle_dimy,
						  neuLAND_paddle_dimz);

  //------------------ wrapping Alu------------------------------------------
  TGeoShape* padle_h_box1 = new TGeoBBox("padle_h_box1",
					 neuLAND_paddle_dimx, 
					 neuLAND_paddle_dimy + neuLAND_wrapping1_dim, 
					 neuLAND_paddle_dimz + neuLAND_wrapping1_dim);
  TGeoShape* padle_h_box2 = new TGeoBBox("padle_h_box2",
					 neuLAND_paddle_dimx, 
					 neuLAND_paddle_dimy, 
					 neuLAND_paddle_dimz);
  
  // Create a composite shape
  TGeoCompositeShape *wrapping1 = new TGeoCompositeShape("diffbox", "padle_h_box1 - padle_h_box2");
  TGeoVolume *bvol1 = new TGeoVolume("wrapping1", wrapping1, pMedAl);

  //------------------ wrapping Tape------------------------------------------
  TGeoShape* padle_h_box3 = new TGeoBBox("padle_h_box3",
					 neuLAND_paddle_dimx,
					 neuLAND_paddle_dimy + neuLAND_wrapping1_dim + neuLAND_wrapping2_dim, 
					 neuLAND_paddle_dimz + neuLAND_wrapping1_dim + neuLAND_wrapping2_dim);
  TGeoShape* padle_h_box4 = new TGeoBBox("padle_h_box4",
					 neuLAND_paddle_dimx, 
					 neuLAND_paddle_dimy + neuLAND_wrapping1_dim, 
					 neuLAND_paddle_dimz + neuLAND_wrapping1_dim);

  // Create a composite shape
  TGeoCompositeShape *wrapping2 = new TGeoCompositeShape("diffbox", "padle_h_box3 - padle_h_box4");
  TGeoVolume *bvol2 = new TGeoVolume("wrapping2", wrapping2, pMed38);



  // Make the elementary assembly of the whole structure
  TGeoVolume *aLand = new TGeoVolumeAssembly("ALAND");

  Double_t total_dimx = neuLAND_paddle_dimx;
  Double_t total_dimy = neuLAND_paddle_dimy +
    neuLAND_wrapping1_dim + 
    neuLAND_wrapping2_dim + 
    neuLAND_gap_dim;
  Double_t total_dimz = neuLAND_paddle_dimz +
    neuLAND_wrapping1_dim +
    neuLAND_wrapping2_dim +
    neuLAND_gap_dim;
  
  //paddles
  TGeoRotation *zeroRotation = new TGeoRotation();
  zeroRotation->RotateX(0.);
  zeroRotation->RotateY(0.);
  zeroRotation->RotateZ(0.);

  TGeoRotation *rot1 = new TGeoRotation();
  rot1->RotateX(0.);
  rot1->RotateY(0.);
  rot1->RotateZ(90.);

  Double_t xx = 0.;
  Double_t yy = 0.;
  Double_t zz = 0.;
  
  aLand->AddNode(padle_h_box5, 1, new TGeoCombiTrans(xx, yy, zz, zeroRotation));
  aLand->AddNode(bvol1, 1, new TGeoCombiTrans(xx, yy, zz, zeroRotation));
  aLand->AddNode(bvol2, 1, new TGeoCombiTrans(xx, yy, zz, zeroRotation));

  TGeoVolume *cell = new TGeoVolumeAssembly("CELL");

  Int_t nindex = 0, i = 0;
  tx = 0.;
  tz = -neuLAND_depth_dim + total_dimz;
  for(tz = -neuLAND_depth_dim + total_dimz; tz < neuLAND_depth_dim; tz += total_dimz*2) {
    i += 1;
    for (ty = -total_dimx + total_dimy; ty < total_dimx; ty += total_dimy*2) {
      nindex++;
      if (i % 2 == 1) {
        cell->AddNode(aLand, nindex, new TGeoCombiTrans(tx, ty, tz, zeroRotation));
      } else {
        cell->AddNode(aLand, nindex, new TGeoCombiTrans(ty, tx, tz, rot1));
      }
    }
  }

  tx = 0.0;
  ty = 0.0;
  tz = fZ;
  TGeoCombiTrans *t0 = new TGeoCombiTrans(tx, ty, tz, zeroRotation);

  top->AddNode(cell, 1, /*GetGlobalPosition(t0)*/t0);



  // ---------------   Finish   -----------------------------------------------
  gGeoMan->CloseGeometry();
  gGeoMan->CheckOverlaps(0.001);
  gGeoMan->PrintOverlaps();
  gGeoMan->Test();

  TFile* geoFile = new TFile(geoFileName, "RECREATE");
  top->Write();
  geoFile->Close();
  // --------------------------------------------------------------------------
}
void create_dch_geo(const char* geoTag)
{

  fGlobalTrans->SetTranslation(0.0,0.0,0.0);

  // -------   Load media from media file   -----------------------------------
  FairGeoLoader*    geoLoad = new FairGeoLoader("TGeo","FairGeoLoader");
  FairGeoInterface* geoFace = geoLoad->getGeoInterface();
  TString geoPath = gSystem->Getenv("VMCWORKDIR");
  TString medFile = geoPath + "/geometry/media_r3b.geo";
  geoFace->setMediaFile(medFile);
  geoFace->readMedia();
  gGeoMan = gGeoManager;
  // --------------------------------------------------------------------------



  // -------   Geometry file name (output)   ----------------------------------
  TString geoFileName = geoPath + "/geometry/dch_";
  geoFileName = geoFileName + geoTag + ".geo.root";
  // --------------------------------------------------------------------------



  // -----------------   Get and create the required media    -----------------
  FairGeoMedia*   geoMedia = geoFace->getMedia();
  FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();

  FairGeoMedium* mAir      = geoMedia->getMedium("Air");
  if ( ! mAir ) Fatal("Main", "FairMedium Air not found");
  geoBuild->createMedium(mAir);
  TGeoMedium* pMed2 = gGeoMan->GetMedium("Air");
  if ( ! pMed2 ) Fatal("Main", "Medium Air not found");

  FairGeoMedium* mAl      = geoMedia->getMedium("aluminium");
  if ( ! mAl ) Fatal("Main", "FairMedium aluminium not found");
  geoBuild->createMedium(mAl);
  TGeoMedium* pMed21 = gGeoMan->GetMedium("aluminium");
  if ( ! pMed21 ) Fatal("Main", "Medium aluminium not found");

  FairGeoMedium* mMylar      = geoMedia->getMedium("mylar");
  if ( ! mMylar ) Fatal("Main", "FairMedium mylar not found");
  geoBuild->createMedium(mMylar);
  TGeoMedium* pMed15 = gGeoMan->GetMedium("mylar");
  if ( ! pMed15 ) Fatal("Main", "Medium mylar not found");

  FairGeoMedium* mHe      = geoMedia->getMedium("helium");
  if ( ! mHe ) Fatal("Main", "FairMedium helium not found");
  geoBuild->createMedium(mHe);
  TGeoMedium* pMed4 = gGeoMan->GetMedium("helium");
  if ( ! pMed4 ) Fatal("Main", "Medium helium not found");

  FairGeoMedium* mDCH      = geoMedia->getMedium("DCHgas");
  if ( ! mDCH ) Fatal("Main", "FairMedium DCHgas not found");
  geoBuild->createMedium(mDCH);
  TGeoMedium* pMed33 = gGeoMan->GetMedium("DCHgas");
  if ( ! pMed33 ) Fatal("Main", "Medium DCHgas not found");
  // --------------------------------------------------------------------------



  // --------------   Create geometry and top volume  -------------------------
  gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
  gGeoMan->SetName("DCHgeom");
  TGeoVolume* top = new TGeoVolumeAssembly("TOP");
  gGeoMan->SetTopVolume(top);
  // --------------------------------------------------------------------------



  Double_t dx,dy,dz;
  Double_t theta, phi;
  Double_t thx, phx, thy, phy, thz, phz;
  Double_t alpha;



  // Define DCH Geometry
  TGeoVolume* topDCH = new TGeoVolumeAssembly("DCH");


  //Active volume	(envelope box enclosing the sense wires)	
  Double_t actGasDx = 99.07/2.; // [cm]	//99.07326
  Double_t actGasDy = 77.60/2.;  // [cm]	//77.59584
  Double_t actGasDz = 5.20/2.;     // [cm]
  //distance of x and y planes centres is 4 cm. Distance between the first x halfplane and the second y halfplane is 4cm + 2*0.69*cos30 cm.

  TGeoShape* pActGasBox = new TGeoBBox("ActGasBox",
				       actGasDx,
				       actGasDy,
				       actGasDz);
  TGeoVolume*
    pActGasDchLog = new TGeoVolume("ActGASBoxLog",pActGasBox, pMed33);
  pActGasDchLog->SetVisLeaves(kTRUE);
  pActGasDchLog->SetVisContainers(kTRUE);


  // Gas box
  Double_t gasDx = 106.4/2.; // [cm]
  Double_t gasDy = 83.4/2.;  // [cm]
  Double_t gasDz = 7.50;     // [cm]	

  TGeoShape* pGasBox = new TGeoBBox("GasBox",
				    gasDx,
				    gasDy,
				    gasDz);
  TGeoVolume*
    pGasDchLog = new TGeoVolume("GASBoxLog",pGasBox, pMed33);
  pGasDchLog->SetVisLeaves(kTRUE);
  pGasDchLog->SetVisContainers(kTRUE);


  // Al Frame
  Double_t alDx = 125.8/2.; // [cm]
  Double_t alDy = 103.4/2.; // [cm]
  //Double_t alDz = 4.06;     // [cm]
  Double_t alDz = 7.50;     // [cm]	//modified

  TGeoShape* pAlBox = new TGeoBBox("AlBox",
				   alDx,
				   alDy,
				   alDz);

  TGeoVolume*
    pAlDchLog = new TGeoVolume("ALBoxLog",pAlBox, pMed21);
  pAlDchLog->SetVisLeaves(kTRUE);



  // Mylar Entrance exit windows
  Double_t mylDx= gasDx; //[cm]
  Double_t mylDy= gasDy; //[cm]
  Double_t mylDz= 0.0006; //[cm]
  TGeoShape* pMylarBox = new TGeoBBox("MylarBox",
				      mylDx,
				      mylDy,
				      mylDz);

  TGeoVolume*
    pMylDchLog = new TGeoVolume("MYLBoxLog",pMylarBox, pMed15);
  pMylDchLog->SetVisLeaves(kTRUE);



  // First assembly
  TGeoVolume *dch1 = new TGeoVolumeAssembly("DCH1");

  TGeoRotation *rot = new TGeoRotation();
  rot->RotateX(0.);
  rot->RotateY(0.);
  rot->RotateZ(0.);
  //Double_t tx = -3.5;	//correct values? active-area vs Al frame offsets?
  //Double_t ty = -5.;
  Double_t tx = +3.5;	//corrected values, active-area vs Al frame offsets. F.Wamers.
  Double_t ty = -3.5;
  Double_t tz = 0.;

  TGeoCombiTrans*
    pTransfo1 = new TGeoCombiTrans("", 0.,0.,0.,rot);
  TGeoCombiTrans*
    pTransfo2 = new TGeoCombiTrans("", tx,ty,tz,rot);
  TGeoCombiTrans*
    pTransfo3 = new TGeoCombiTrans("", -tx,-ty,-tz,rot); //new, in order to compensate Al vs Gas

  dch1->AddNode(pAlDchLog,0,pTransfo3);	//1->3
  pAlDchLog->AddNode(pGasDchLog,0,pTransfo2);	//place gas in aluminum, shifted
  pGasDchLog->AddNode(pActGasDchLog, 0,pTransfo1);	//place active in gas, centrally
  // Mylar Windows front+back
  //dch1->AddNode(pMylDchLog,0,new TGeoCombiTrans("", tx,ty,-alDz-mylDz,rot));
  //dch1->AddNode(pMylDchLog,1,new TGeoCombiTrans("", tx,ty, alDz+mylDz,rot));
  dch1->AddNode(pMylDchLog,0,new TGeoCombiTrans("", 0.,0.,-alDz-mylDz,rot));
  dch1->AddNode(pMylDchLog,1,new TGeoCombiTrans("", 0.,0., alDz+mylDz,rot));



  // Global Positioning
  //in agreement with the s318 tracker, those are supposed to be the centres of the active volumes!!!
  //Double_t pDch1x = -123.22 ; //Justyna 
  //Double_t pDch1y = 3.6 ;     //Justyna
  //Double_t pDch1z = 444.13 ;  //Justyna

  //Double_t pDch2x = -167.0 ;  //Justyna
  //Double_t pDch2y = 1.02 ;    //Justyna
  //Double_t pDch2z = 535.1 ;   //Justyna

  //use identical values as for the tracker config and the digitizer. F. Wamers. 
  Double_t pDch1x = -123.219446 ; //Felix 
  Double_t pDch1y = 3.597104 ;     //Felix
  Double_t pDch1z = 444.126271 ;  //Felix

  Double_t pDch2x = -167.015888 ;  //Felix
  Double_t pDch2y = 1.016917 ;    //Felix
  Double_t pDch2z = 535.093884 ;   //Felix
   
  //   Double_t pDch1x = -132.233355 ; //Christoph  
  //   Double_t pDch1y = 1.037475 ;     //Christoph 
  //   Double_t pDch1z = 438.710168 ;  //Christoph

  //   Double_t pDch2x = -170.8653 ;  //Christoph
  //   Double_t pDch2y = 2.075139 ;    //Christoph
  //   Double_t pDch2z = 538.614091 ;   //Christoph
   

  //The order of rotation matters!!! Rotate first z, and then y! Felix

  Double_t aDch1 = -31.0 ; 
  Double_t aDch2 = -31.0 ; 

  TGeoRotation *gRot1 = new TGeoRotation();
  gRot1->RotateX(0.);
  gRot1->RotateZ(-8.880000); //Justyna
  //gRot1->RotateZ(+8.880000); //Felix
  //   gRot1->RotateZ(-2.5); //Christoph
  gRot1->RotateY(aDch1);
   
  TGeoRotation *gRot2 = new TGeoRotation();
  gRot2->RotateX(0.);
  gRot2->RotateZ(9.350000); //Justyna
  //gRot2->RotateZ(-9.350000); //Felix
  //   gRot2->RotateZ(8.4); //Christoph
  gRot2->RotateY(aDch2);


  // Helium Bag definition
  Double_t heDx= alDx ; //[cm]
  Double_t heDy= alDy ; //[cm]
  Double_t heDz=(pDch2z-pDch1z)*0.953874/2.; //[cm]
  alpha=0.;     //[degre]
  Double_t beta =0.;     //[degre]
  phi  =15.20; //[degre]

  TGeoShape* pHePara = new TGeoPara("HePara", heDx, heDy, heDz,
				    alpha,beta,phi);

  TGeoVolume*
    pHeDchLog = new TGeoVolume("HeParaLog",pHePara, pMed4);
  pHeDchLog->SetVisLeaves(kTRUE);




  topDCH->AddNode(dch1,0,new TGeoCombiTrans("",pDch1x,pDch1y,pDch1z,gRot1) );
  topDCH->AddNode(dch1,1,new TGeoCombiTrans("",pDch2x,pDch2y,pDch2z,gRot2) );
  topDCH->AddNode(pHeDchLog,0,new TGeoCombiTrans("",(pDch1x+pDch2x)/2.,
						 pDch2y,
						 (pDch1z+pDch2z)/2.,
						 gRot1) );


  TGeoCombiTrans *temp1 = new TGeoCombiTrans();
  top->AddNode(topDCH, 0, GetGlobalPosition(temp1));
  
   
   
  // ---------------   Finish   -----------------------------------------------
  gGeoMan->CloseGeometry();
  gGeoMan->CheckOverlaps(0.001);
  gGeoMan->PrintOverlaps();
  gGeoMan->Test();

  TFile* geoFile = new TFile(geoFileName, "RECREATE");
  top->Write();
  geoFile->Close();
  // --------------------------------------------------------------------------
}
예제 #3
0
void create_tof_geo(const char* geoTag)
{

    fGlobalTrans->SetTranslation(0.0,0.0,0.0);

    // -------   Load media from media file   -----------------------------------
    FairGeoLoader*    geoLoad = new FairGeoLoader("TGeo","FairGeoLoader");
    FairGeoInterface* geoFace = geoLoad->getGeoInterface();
    TString geoPath = gSystem->Getenv("VMCWORKDIR");
    TString medFile = geoPath + "/geometry/media_r3b.geo";
    geoFace->setMediaFile(medFile);
    geoFace->readMedia();
    gGeoMan = gGeoManager;
    // --------------------------------------------------------------------------



    // -------   Geometry file name (output)   ----------------------------------
    TString geoFileName = geoPath + "/geometry/tof_";
    geoFileName = geoFileName + geoTag + ".geo.root";
    // --------------------------------------------------------------------------



    // -----------------   Get and create the required media    -----------------
    FairGeoMedia*   geoMedia = geoFace->getMedia();
    FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();

    FairGeoMedium* mAir      = geoMedia->getMedium("Air");
    if ( ! mAir ) Fatal("Main", "FairMedium Air not found");
    geoBuild->createMedium(mAir);
    TGeoMedium* pMed2 = gGeoMan->GetMedium("Air");
    if ( ! pMed2 ) Fatal("Main", "Medium Air not found");

    FairGeoMedium* mTof      = geoMedia->getMedium("plasticForTOF");
    if ( ! mTof ) Fatal("Main", "FairMedium plasticForTOF not found");
    geoBuild->createMedium(mTof);
    TGeoMedium* pMed34 = gGeoMan->GetMedium("plasticForTOF");
    if ( ! pMed34 ) Fatal("Main", "Medium plasticForTOF not found");
    // --------------------------------------------------------------------------



    // --------------   Create geometry and top volume  -------------------------
    gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
    gGeoMan->SetName("TOFgeom");
    TGeoVolume* top = new TGeoVolumeAssembly("TOP");
    gGeoMan->SetTopVolume(top);
    // --------------------------------------------------------------------------



    // out-of-file geometry definition
    Double_t dx,dy,dz;
    Double_t a;
    //   Double_t thx, phx, thy, phy, thz, phz;
    Double_t z, density, w;
    Int_t nel, numed;



    // TRANSFORMATION MATRICES
    // Combi transformation:
    dx = -417.359574; //Justyna
    dy = 2.400000;    //Justyna
    dz = 960.777114;  //Justyna

    //    dx = -421.33683; //Christoph
    //    dy = 2.12;    //Christoph
    //    dz = 958.387337;  //Christoph

    /*    dx = -171.1;  //position directrly (15cm) after DCH2
     dy = 2.400000;
     dz = 548.95;*/
    // dz = 0.;
    /*   // Rotation:
     thx = -121.000000;    phx = 0.000000;
     thy = 90.000000;    phy = 90.000000;
     thz = -31.000000;    phz = 0.000000;*/  //this

    //   TGeoRotation *pMatrix3 = new TGeoRotation("",thx,phx,thy,phy,thz,phz);  //this
    TGeoRotation *gRot = new TGeoRotation();
    gRot->RotateX(0.);
    gRot->RotateY(-31.000000);
    gRot->RotateZ(0.);

    TGeoCombiTrans*
    //   pMatrix2 = new TGeoCombiTrans("", dx,dy,dz,pMatrix3);  //this
    pMatrix2 = new TGeoCombiTrans("", dx,dy,dz,gRot);  //this







    /* PREVIOUS!!!
     // TRANSFORMATION MATRICES
     // Combi transformation:
     dx = 419.700000;
     dy = 0.000000;
     dz = 952.400000;
     // dz = 0.;
     // Rotation:
     thx = 121.000000;    phx = 0.000000;
     thy = 90.000000;    phy = 90.000000;
     thz = 31.000000;    phz = 0.000000;
     TGeoRotation *pMatrix3 = new TGeoRotation("",thx,phx,thy,phy,thz,phz);
     TGeoCombiTrans*
     pMatrix2 = new TGeoCombiTrans("", dx,dy,dz,pMatrix3);
     */

    //Top Volume
    TGeoVolume* pWorld = gGeoManager->GetTopVolume();
    pWorld->SetVisLeaves(kTRUE);


    TGeoVolumeAssembly *ptof = new TGeoVolumeAssembly("TOF");


    // SHAPES, VOLUMES AND GEOMETRICAL HIERARCHY
    // Shape: TOFBox type: TGeoBBox
    dx = 94.450000;
    dy = 73.450000;
    dz = 0.500000;
    TGeoShape *pTOFBox = new TGeoBBox("TOFBox", dx,dy,dz);
    // Volume: TOFLog
    TGeoVolume*
    pTOFLog = new TGeoVolume("TOFLog",pTOFBox, pMed34);
    pTOFLog->SetVisLeaves(kTRUE);

    TGeoCombiTrans *t0 = new TGeoCombiTrans("t0");
    ptof->AddNode(pTOFLog, 0, t0);

    TGeoCombiTrans *pGlobal = GetGlobalPosition(pMatrix2);
    if (pGlobal) {
        pWorld->AddNode(ptof, 0, pGlobal);
    } else {
        pWorld->AddNode(ptof, 0, pMatrix2);
    }

//  AddSensitiveVolume(pTOFLog);
//  fNbOfSensitiveVol+=1;



    // ---------------   Finish   -----------------------------------------------
    gGeoMan->CloseGeometry();
    gGeoMan->CheckOverlaps(0.001);
    gGeoMan->PrintOverlaps();
    gGeoMan->Test();

    TFile* geoFile = new TFile(geoFileName, "RECREATE");
    top->Write();
    geoFile->Close();
    // --------------------------------------------------------------------------
}
void EUTelGeometryTelescopeGeoDescription::translateSiPlane2TGeo(TGeoVolume* pvolumeWorld, int SensorId ) {
	double xc, yc, zc;   // volume center position 
	double alpha, beta, gamma;
	double rotRef1, rotRef2, rotRef3, rotRef4;

	std::stringstream strId;
	strId << SensorId;

	// Get sensor center position
	xc = siPlaneXPosition( SensorId );
	yc = siPlaneYPosition( SensorId );
	zc = siPlaneZPosition( SensorId );

	// Get sensor orientation
	alpha = siPlaneXRotation( SensorId ); //  in degrees !
	beta  = siPlaneYRotation( SensorId ); // 
	gamma = siPlaneZRotation( SensorId ); // 

	rotRef1 = siPlaneRotation1( SensorId );
	rotRef2 = siPlaneRotation2( SensorId );
	rotRef3 = siPlaneRotation3( SensorId );
	rotRef4 = siPlaneRotation4( SensorId );

	//We must check that the input is correct. Since this is a combination of initial rotations and reflections the determinate must be 1 or -1
	float determinant = rotRef1*rotRef4 - rotRef2*rotRef3  ;
	if(determinant==1 or determinant==-1) { 
		streamlog_out(DEBUG5) << "SensorID: " << SensorId << ". Determinant =  " <<determinant <<"  This is the correct determinate for this transformation." << std::endl;   
	} else {
		streamlog_out(ERROR5) << "SensorID: " << SensorId << ". Determinant =  " <<determinant << std::endl;   
		throw(lcio::Exception("The initial rotation and reflection matrix does not have determinant of 1 or -1. Gear file input must be wrong.")); 	
	}
	//Create spatial TGeoTranslation object.
	std::string stTranslationName = "matrixTranslationSensor";
	stTranslationName.append( strId.str() );
	TGeoTranslation* pMatrixTrans = new TGeoTranslation( stTranslationName.c_str(), xc, yc, zc );
	//ALL clsses deriving from TGeoMatrix are not owned by the ROOT geometry manager, invoking RegisterYourself() transfers
	//ownership and thus ROOT will clean up
	pMatrixTrans->RegisterYourself();      

	//Create TGeoRotation object. 
	//Translations are of course just positional changes in the global frame.
	//Note that each subsequent rotation is using the new coordinate system of the last transformation all the way back to the global frame.
	//The way to think about this is that each rotation is the multiplication of the last rotation matrix by a new one.
	//The order is:
	//Integer Z rotation and reflections.
	//Z rotations specified by in degrees.
	//X rotations 
	//Y rotations
	TGeoRotation* pMatrixRotRefCombined = new TGeoRotation();
	//We have to ensure that we retain a right handed coordinate system, i.e. if we only flip the x or y axis, we have to also flip the z-axis. If we flip both we have to flip twice.	
	double integerRotationsAndReflections[9]={rotRef1,rotRef2,0,rotRef3,rotRef4,0,0,0, determinant};
	pMatrixRotRefCombined->SetMatrix(integerRotationsAndReflections);
	std::cout << "Rotating plane " << SensorId << " to gamma: " << gamma << std::endl;
	pMatrixRotRefCombined->RotateZ(gamma);//Z Rotation (degrees)//This will again rotate a vector around z axis usign the right hand rule.  
	pMatrixRotRefCombined->RotateX(alpha);//X Rotations (degrees)//This will rotate a vector usign the right hand rule round the x-axis
	pMatrixRotRefCombined->RotateY(beta);//Y Rotations (degrees)//Same again for Y axis
	pMatrixRotRefCombined->RegisterYourself();//We must allow the matrix to be used by the TGeo manager.
	// Combined translation and orientation
	TGeoCombiTrans* combi = new TGeoCombiTrans( *pMatrixTrans, *pMatrixRotRefCombined );
	//This is to print to screen the rotation and translation matrices used to transform from local to global frame.
	streamlog_out(MESSAGE9) << "THESE MATRICES ARE USED TO TAKE A POINT IN THE LOCAL FRAME AND MOVE IT TO THE GLOBAL FRAME."  << std::endl;   
	streamlog_out(MESSAGE9) << "SensorID: " << SensorId << " Rotation/Reflection matrix for this object."  << std::endl;   
	const double* rotationMatrix =  combi->GetRotationMatrix();	
	streamlog_out(MESSAGE9) << std::setw(10) <<rotationMatrix[0]<<"  "<<rotationMatrix[1]<<"   "<<rotationMatrix[2]<< std::endl;
	streamlog_out(MESSAGE9) << std::setw(10) <<rotationMatrix[3]<<"  "<<rotationMatrix[4]<<"   "<<rotationMatrix[5]<< std::endl;
	streamlog_out(MESSAGE9) << std::setw(10) <<rotationMatrix[6]<<"  "<<rotationMatrix[7]<<"   "<<rotationMatrix[8]<< std::endl;

	//streamlog_out(MESSAGE9) << std::setw(10) <<rotationMatrix[0] << std::setw(10) <<rotationMatrix[1]<< std::setw(10) <<rotationMatrix[2]<< std::setw(10)<< std::endl<< std::endl; 
	//streamlog_out(MESSAGE9) << std::setw(10) <<rotationMatrix[3] << std::setw(10) <<rotationMatrix[4]<< std::setw(10) <<rotationMatrix[5]<< std::setw(10)<< std::endl<< std::endl; 
	//streamlog_out(MESSAGE9) << std::setw(10) <<rotationMatrix[6] << std::setw(10) <<rotationMatrix[7]<< std::setw(10) <<rotationMatrix[8]<< std::setw(10)<< std::endl<< std::endl; 
	const double* translationMatrix =  combi->GetTranslation();	
	streamlog_out(MESSAGE9) << "SensorID: " << SensorId << " Translation vector for this object."  << std::endl;   
	streamlog_out(MESSAGE9) << std::setw(10) <<translationMatrix[0] << std::setw(10) <<translationMatrix[1]<< std::setw(10) <<translationMatrix[2]<< std::setw(10)<< std::endl; 

	combi->RegisterYourself();   
	
	// Construct object medium. Required for radiation length determination
	// assume SILICON, though all information except of radiation length is ignored
	double a       = 28.085500;     
	double z       = 14.000000;
	double density = 2.330000;
	double radl    = siPlaneRadLength( SensorId );
	double absl    = 45.753206;
	std::string stMatName = "materialSensor";
	stMatName.append( strId.str() );
	TGeoMaterial* pMat = new TGeoMaterial( stMatName.c_str(), a, z, density, -radl, absl );
	pMat->SetIndex( 1 );
	// Medium: medium_Sensor_SILICON
	int numed   = 0;  // medium number
	double par[8];
	par[0]  = 0.000000; // isvol
	par[1]  = 0.000000; // ifield
	par[2]  = 0.000000; // fieldm
	par[3]  = 0.000000; // tmaxfd
	par[4]  = 0.000000; // stemax
	par[5]  = 0.000000; // deemax
	par[6]  = 0.000000; // epsil
	par[7]  = 0.000000; // stmin
	std::string stMedName = "mediumSensor";
	stMedName.append( strId.str() );
	TGeoMedium* pMed = new TGeoMedium( stMedName.c_str(), numed, pMat, par );

	// Construct object shape
	// Shape: Box type: TGeoBBox
	// TGeo requires half-width of box side
	Double_t dx = siPlaneXSize( SensorId ) / 2.;
	Double_t dy = siPlaneYSize( SensorId ) / 2.;
	Double_t dz = siPlaneZSize( SensorId ) / 2.;
	TGeoShape *pBoxSensor = new TGeoBBox( "BoxSensor", dx, dy, dz );

	std::cout << "Box for sensor: " << SensorId << " is: " << dx << "|" << dy  << "|" << dz << '\n';

	// Geometry navigation package requires following names for objects that have an ID  name:ID
	std::string stVolName = "volume_SensorID:";
	stVolName.append( strId.str() );

	_planePath.insert( std::make_pair(SensorId, "/volume_World_1/"+stVolName+"_1") );

	TGeoVolume* pvolumeSensor = new TGeoVolume( stVolName.c_str(), pBoxSensor, pMed );
	pvolumeSensor->SetVisLeaves( kTRUE );
	pvolumeWorld->AddNode(pvolumeSensor, 1/*(SensorId)*/, combi);

	//this line tells the pixel geometry manager to load the pixel geometry into the plane			
	streamlog_out(DEBUG1) << " sensorID: " << SensorId << " " << stVolName << std::endl;   
	std::string name = geoLibName(SensorId);

	if( name == "CAST" ) {
		_pixGeoMgr->addCastedPlane( SensorId, siPlaneXNpixels(SensorId), siPlaneYNpixels(SensorId), siPlaneXSize(SensorId), siPlaneYSize(SensorId), siPlaneZSize(SensorId), siPlaneRadLength(SensorId), stVolName);
	} else {
		_pixGeoMgr->addPlane( SensorId, name, stVolName);
		updatePlaneInfo(SensorId);
	}
}