#include "PamVMCDetCard.h"

ClassImp(PamVMCDetCard)

void  PamVMCDetCard::DefineGeometry(){

  TGeoMaterial *m=0;
  TGeoMixture *x=0;
  TString s = "ALUMINIUM"; 
  m = GetMat(s);
  if(!m){
    m = new TGeoMaterial(s,26.98,13,2.7);
    m->SetUniqueID( 9);
  }

  s = "IRON";
  m = GetMat(s);
  if(!m){
    m = new TGeoMaterial(s,55.85,26,7.87);
    m->SetUniqueID( 10);    
  }

  s = "SCINT";
  x = (TGeoMixture*)GetMat(s);  
  if(!x){
    x = new TGeoMixture(s,2,   1.03200    );
    x->SetUniqueID( 17);
    x->DefineElement(0,12.01,6,0.922427);
    x->DefineElement(1,1.01,1,0.7757296E-01);
  }

  s = "N2GAS";
  m = GetMat(s);
  if (!m){
    m = new TGeoMaterial(s,14.01,7,0.1250000E-02);
    m->SetUniqueID( 19);
  }

  s = "PLAST";
  x = (TGeoMixture*)GetMat(s);
   if(!x){
     x = new TGeoMixture(s,2,   1.03200    );
     x->SetUniqueID( 28);
     x->DefineElement(0,12.01,6,0.9929774);
     x->DefineElement(1,1.01,1,0.7022570E-02);
   }

   TGeoMedium *n =0;

  s="ALUMINIUM";
  n = (GetMed(s))?GetMed(s): new TGeoMedium(s,1,9,-1,1,40,1,100,0.5000000E-01,0.136283,0.5000000E-03);

  s = "N2 GAS";
  n = (GetMed(s))?GetMed(s): new TGeoMedium(s,3,19,-1,1,40,1,0.5000000E-01,0.5000000E-01,0.1000000E-02,0.5000000E-03);

  s = "SCINTILLATOR";
  n = (GetMed(s))?GetMed(s): new TGeoMedium(s,10,17,1,1,40,1,0.5000000E-01,0.5000000E-01,0.1000000E-01,0.5000000E-03);

  s = "PLASTIC";
  n = (GetMed(s))?GetMed(s): new TGeoMedium(s,18,28,-1,1,40,1,100,0.5000000E-01,0.1000000E-01,0.5000000E-03);

  s = "IRON";
  n = (GetMed(s))?GetMed(s): new TGeoMedium(s,27,10,-1,1,40,1,100,0.5000000E-01,0.2491200E-02,0.5000000E-03);


  TGeoVolume *v = 0;

  s = "C1D1";
  v = (GetVol(s))?GetVol(s): gGeoManager->MakeTrap(s,GetMed("SCINTILLATOR"),9.075,17.37456,180.,0.4,17.1515,17.1515,0.,0.4,15.99778,15.99778,0.);
  s = "C2D1";
  v = (GetVol(s))?GetVol(s):gGeoManager->MakeTrap(s,GetMed("SCINTILLATOR"),9.075,14.89904,180.,0.4,14.5515,14.5515,0.,0.4,14.24778,14.24778,0.);
  s = "CAR1";
  v = (GetVol(s))?GetVol(s):gGeoManager->MakeTrap(s,GetMed("ALUMINIUM"),10.175,17.37456,180.,0.55,18.37594,18.37594,0.,0.55,17.08238,17.08238,0.);
  s = "CR1P";
  v = (GetVol(s))?GetVol(s):gGeoManager->MakeTrap(s,GetMed("PLASTIC"),9.975,17.37456,180.,0.4,18.15331,18.15331,0.,0.4,16.88518,16.88518,0.);
  s = "CAR2";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("ALUMINIUM"),10.175,14.89904,180.,0.55,15.70831,15.70831,0.,0.55,15.36778,15.36778,0.);
  s = "CR2P";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("PLASTIC"),9.974999,14.89904,180.,0.4,15.49798,15.49798,0.,0.4,15.16415,15.16415,0.);
  s = "VSN1";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("N2 GAS"),3.3,14.05436,0.,0.4,0.,0.,0.,0.4,3.297782,3.297782,0.);
  s = "VSN2";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("PLASTIC"),0.9,63.27491,0.,0.4,0.,0.,0.,0.4,2.225,2.225,0.);
  s = "VPN2";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("ALUMINIUM"),0.7358874,63.27491,0.,0.55,0.,0.,0.,0.55,1.819277,1.819277,0.);
  s = "VPN1";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("N2 GAS"),4.214088,14.05436,0.,0.4,0.,0.,0.,0.4,4.211256,4.211256,0.);
  s = "VAN1";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("N2 GAS"),4.417219,14.05436,0.,0.55,0.,0.,0.,0.55,4.41425,4.41425,0.);
  s = "VAN2";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("N2 GAS"),0.6994181,63.27491,0.,0.55,0.,0.,0.,0.55,1.729117,1.729117,0.);
  s = "CARD";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),27.,22.8,12.35);
  s = "LEGB";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("ALUMINIUM"),2.15,3.575,11.85);
  s = "LEG1";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("N2 GAS"),0.65,0.,0.,0.15,6.85,6.85,0.,0.15,10.85,10.85,0.);
  s = "LEG2";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),0.65,1.65,11.35);
  s = "LEG3";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),0.1,1.3,0.325);
  s = "LEG4";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),0.65,1.625,11.85);
  s = "LEG5";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),1.125,2.575,11.85);
  s = "LEG6";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),0.1,0.55,11.2);
  s = "LEG7";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),1.1,0.75,3.25);
  s = "LEG8";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),1.1,0.75,4.35);
  s = "LEG9";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),1.1,0.75,3.25);
  s = "TPLT";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("ALUMINIUM"),27.,22.8,0.5);
  s = "TOPC";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),20.4,16.,0.5);
  s = "TH11";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),2.8,3.2,0.5);
  s = "TH12";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),2.8,5.3,0.5);
  s = "TH21";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),1.7,3.,0.5);
  s = "TH22";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),4.9,3.,0.5);
  s = "TOPT";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTrap(s,GetMed("N2 GAS"),0.5,0.,0.,2.25,2.25,0.,-26.565,2.25,2.25,0.,-26.565);
  s = "TOHO";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeTube(s,GetMed("N2 GAS"),0.,0.7,0.5);
  s = "MGSC";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("IRON"),16.,15.4,0.12456);
  s = "MGSH";
  v = (GetVol(s))?GetVol(s):  gGeoManager->MakeBox(s,GetMed("N2 GAS"),9.8,8.,0.12456);




  GetVol("CARD")->AddNode(GetVol("CAR1"),1,new TGeoCombiTrans(-3.91289,-13.17068,0.1509358,GetRot("rot11")));
    GetVol("CAR1")->AddNode(GetVol("VAN1"),1,new TGeoTranslation(-16.95761,0.,5.757782));
    GetVol("CAR1")->AddNode(GetVol("VAN2"),1,new TGeoTranslation(-11.09758,0.,9.475582));
    GetVol("CAR1")->AddNodeOverlap(GetVol("CR1P"),1,new TGeoTranslation(0.379E-02,0.,0.));
      GetVol("CR1P")->AddNode(GetVol("VPN1"),1,new TGeoTranslation(-16.84998,0.,5.760911));
      GetVol("CR1P")->AddNode(GetVol("VPN2"),1,new TGeoTranslation(-11.22606,0.,9.239112));
      GetVol("CR1P")->AddNodeOverlap(GetVol("C1D1"),1,new TGeoTranslation(0.17055E-01,0.,0.));
        GetVol("C1D1")->AddNode(GetVol("VSN1"),1,new TGeoTranslation(-16.36562,0.,5.775));
        GetVol("C1D1")->AddNode(GetVol("VSN2"),1,new TGeoTranslation(-11.80423,0.,8.175));
  GetVol("CARD")->AddNode(GetVol("CAR1"),2,new TGeoCombiTrans(3.91289,13.17068,0.1509358,GetRot("rot12")));
  GetVol("CARD")->AddNode(GetVol("CAR2"),1,new TGeoCombiTrans(15.79685,-4.187448,0.9491571E-02,GetRot("rot14")));
    GetVol("CAR2")->AddNode(GetVol("VAN1"),2,new TGeoTranslation(-14.7665,0.,5.757782));
    GetVol("CAR2")->AddNode(GetVol("VAN2"),2,new TGeoTranslation(-8.906463,0.,9.475582));
    GetVol("CAR2")->AddNodeOverlap(GetVol("CR2P"),1,new TGeoTranslation(0.8603846E-03,0.,0.));
      GetVol("CR2P")->AddNode(GetVol("VPN1"),2,new TGeoTranslation(-14.66179,0.,5.760911));
      GetVol("CR2P")->AddNode(GetVol("VPN2"),2,new TGeoTranslation(-9.037874,0.,9.239112));
      GetVol("CR2P")->AddNodeOverlap(GetVol("C2D1"),1,new TGeoTranslation(0.3871730E-02,0.,0.));
        GetVol("C2D1")->AddNode(GetVol("VSN1"),2,new TGeoTranslation(-14.19062,0.,5.775));
        GetVol("C2D1")->AddNode(GetVol("VSN2"),2,new TGeoTranslation(-9.629226,0.,8.175));
  GetVol("CARD")->AddNode(GetVol("CAR2"),2,new TGeoCombiTrans(-15.79685,4.187448,0.9491571E-02,GetRot("rot13")));
  GetVol("CARD")->AddNodeOverlap(GetVol("LEGB"),1,new TGeoTranslation(-21.05,-18.525,-0.5)); //many
    GetVol("LEGB")->AddNode(GetVol("LEG1"),1,new TGeoCombiTrans(-1.5,-3.425,0.,GetRot("rot7")));
    GetVol("LEGB")->AddNode(GetVol("LEG1"),2,new TGeoCombiTrans(-1.5,0.175,0.,GetRot("rot7")));
    GetVol("LEGB")->AddNode(GetVol("LEG2"),1,new TGeoTranslation(-1.5,-1.625,0.));
    GetVol("LEGB")->AddNode(GetVol("LEG3"),1,new TGeoTranslation(-0.55,2.275,11.525));
    GetVol("LEGB")->AddNode(GetVol("LEG3"),2,new TGeoTranslation(-0.55,2.275,-11.525));
    GetVol("LEGB")->AddNode(GetVol("LEG4"),1,new TGeoTranslation(-1.5,1.95,0.));
    GetVol("LEGB")->AddNode(GetVol("LEG5"),1,new TGeoTranslation(1.025,1.,0.));
    GetVol("LEGB")->AddNode(GetVol("LEG6"),1,new TGeoTranslation(-0.75,3.025,0.));
    GetVol("LEGB")->AddNode(GetVol("LEG7"),1,new TGeoTranslation(0.65,-2.825,8.));
    GetVol("LEGB")->AddNode(GetVol("LEG8"),1,new TGeoTranslation(0.65,-2.825,0.));
    GetVol("LEGB")->AddNode(GetVol("LEG9"),1,new TGeoTranslation(0.65,-2.825,-8.));
    GetVol("CARD")->AddNodeOverlap(GetVol("LEGB"),2,new TGeoCombiTrans(-21.05,18.525,-0.5,GetRot("rot10"))); //many
    GetVol("CARD")->AddNodeOverlap(GetVol("LEGB"),3,new TGeoCombiTrans(21.05,18.525,-0.5,GetRot("rot4"))); //many
    GetVol("CARD")->AddNodeOverlap(GetVol("LEGB"),4,new TGeoCombiTrans(21.05,-18.525,-0.5,GetRot("rot9")));//many
    GetVol("CARD")->AddNode(GetVol("TPLT"),1,new TGeoTranslation(0.,0.,11.85));
      GetVol("TPLT")->AddNode(GetVol("TOPC"),1,gGeoIdentity);
      GetVol("TPLT")->AddNode(GetVol("TH11"),1,new TGeoTranslation(-23.6,14.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH11"),2,new TGeoTranslation(-23.6,-14.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH11"),3,new TGeoTranslation(23.6,14.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH11"),4,new TGeoTranslation(23.6,-14.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH12"),1,new TGeoTranslation(-23.6,5.5,0.));
      GetVol("TPLT")->AddNode(GetVol("TH12"),2,new TGeoTranslation(-23.6,-5.5,0.));
      GetVol("TPLT")->AddNode(GetVol("TH12"),3,new TGeoTranslation(23.6,5.5,0.));
      GetVol("TPLT")->AddNode(GetVol("TH12"),4,new TGeoTranslation(23.6,-5.5,0.));
      GetVol("TPLT")->AddNode(GetVol("TH21"),1,new TGeoTranslation(-17.2,19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH21"),2,new TGeoTranslation(-17.2,-19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH21"),3,new TGeoTranslation(17.2,19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH21"),4,new TGeoTranslation(17.2,-19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH22"),1,new TGeoTranslation(-10.2,19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH22"),2,new TGeoTranslation(-10.2,-19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH22"),3,new TGeoTranslation(10.2,19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH22"),4,new TGeoTranslation(10.2,-19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH22"),5,new TGeoTranslation(0.,19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TH22"),6,new TGeoTranslation(0.,-19.4,0.));
      GetVol("TPLT")->AddNode(GetVol("TOPT"),1,new TGeoTranslation(-25.875,-20.55,0.));
      GetVol("TPLT")->AddNode(GetVol("TOPT"),2,new TGeoCombiTrans(-25.875,20.55,0.,GetRot("rot10")));
      GetVol("TPLT")->AddNode(GetVol("TOPT"),3,new TGeoCombiTrans(25.875,20.55,0.,GetRot("rot4")));
      GetVol("TPLT")->AddNode(GetVol("TOPT"),4,new TGeoCombiTrans(25.875,-20.55,0.,GetRot("rot9")));
      GetVol("TPLT")->AddNode(GetVol("TOHO"),1,new TGeoTranslation(20.1,18.,0.));
      GetVol("TPLT")->AddNode(GetVol("TOHO"),2,new TGeoTranslation(-20.1,18.,0.));
      GetVol("TPLT")->AddNode(GetVol("TOHO"),3,new TGeoTranslation(-20.1,-18.,0.));
      GetVol("TPLT")->AddNode(GetVol("TOHO"),4,new TGeoTranslation(20.1,-18.,0.));
  GetVol("CARD")->AddNode(GetVol("MGSC"),1,new TGeoTranslation(0.,0.,-12.22544));
    GetVol("MGSC")->AddNode(GetVol("MGSH"),1,gGeoIdentity);


  SetMotherProp(GetVol("CARD"),1,new TGeoTranslation(0.,0.,87.439));

};

void  PamVMCDetCard::DefineCuts(){

  TString  s ="ALUMINIUM"; // default GPAMELA parameters
  if (GetMed(s) && !GetCC(s))
  SetCC(s, new pCutControl(GetMedID(s), 0.0001, 0.001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001,
			     0.001, 0.01, 1., 1., 1., 0., 1., 1., 1., 4., 1., 1., 1., 1.));
  s ="N2 GAS";
  if (GetMed(s) && !GetCC(s))
    SetCC(s, new pCutControl(GetMedID(s), 0.0001, 0.001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001,
                             0.001, 0.01, 1., 1., 1., 0., 0., 1., 1., 4., 1., 1., 2., 1.));
  s ="SCINTILLATOR";// default GPAMELA parameters
  if (GetMed(s) && !GetCC(s))
    SetCC(s, new pCutControl(GetMedID(s), 0.0001, 0.001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001,
			     0.001, 0.01, 1., 1., 1., 0., 1., 1., 1., 4., 1., 1., 1., 1.));
  s = "PLASTIC";// default GPAMELA parameters
  if (GetMed(s) && !GetCC(s))
    SetCC(s, new pCutControl(GetMedID(s), 0.0001, 0.001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001,
			     0.001, 0.01, 1., 1., 1., 0., 1., 1., 1., 4., 1., 1., 1., 1.));   
  s = "IRON";  //default GPAMELA parameters
  if (GetMed(s) && !GetCC(s))
    SetCC(s, new pCutControl(GetMedID(s), 0.0001, 0.001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001,
			     0.001, 0.01, 1., 1., 1., 0., 1., 1., 1., 4., 1., 1., 1., 1.));   
}
