00001 #include <assert.h>
00002 #include <stdexcept>
00003 #include "Sti/Base/Factory.h"
00004 #include "Sti/StiPlanarShape.h"
00005 #include "Sti/StiCylindricalShape.h"
00006 #include "Sti/StiMaterial.h"
00007 #include "Sti/StiPlacement.h"
00008 #include "Sti/StiDetector.h"
00009 #include "Sti/StiIsActiveFunctor.h"
00010 #include "Sti/StiNeverActiveFunctor.h"
00011 #include "Sti/Star/StiStarDetectorBuilder.h"
00012 #include "Sti/StiElossCalculator.h"
00013 #include "TMath.h"
00014 #include "TError.h"
00015
00016 void StiStarDetectorBuilder::buildDetectors(StMaker&s) {
00017 if (! _gasMat)
00018 _gasMat = add(new StiMaterial("Air",7.3, 14.61, 0.001205, 30420.*0.001205, 7.3*12.e-9));
00019 TGeoManager *geo = StiVMCToolKit::GetVMC();
00020 assert(geo);
00021 useVMCGeometry();
00022 cout << "StiStarDetectorBuilder::buildDetectors() -I- Done" << endl;
00023 }
00024
00025 void StiStarDetectorBuilder::useVMCGeometry() {
00026 string name;
00027 setNRows(1);
00028 cout << "StiStarDetectorBuilder::buildDetectors() -I- Use VMC geometry" << endl;
00029 SetCurrentDetectorBuilder(this);
00030 const VolumeMap_t PipeVolumes[] = {
00031 {"PIPE","the STAR beam pipe mother volume","HALL_1/CAVE_1/PIPE_%d","",""},
00032 {"PIPC","the Central Beam PIPe Volume","HALL_1/CAVE_1/PIPE_%d/PIPC_1","",""},
00033 {"PVAC","the Vacuum Volume of Be section of pipe","HALL_1/CAVE_1/PIPE_%d/PIPC_1/PVAC_1","",""},
00034 {"PIPO","Steel pipe from Be to 1st flanges","HALL_1/CAVE_1/PIPE_%d/PIPO_1/PVAO_1","",""},
00035 {"PVAO","its cavity","HALL_1/CAVE_1/PIPE_%d/PIPO_1/PVAO_1","",""},
00036
00037 {"SROD", "Support rod","HALL_1/CAVE_1/SVTT_1/SROD_1-2","",""},
00038 {"SBSP", "Beampipe support mother","HALL_1/CAVE_1/SVTT_1/SBSP_1-2","",""}
00039 };
00040 setNSectors(0,1);
00041 Double_t dPhi = 2*TMath::Pi();
00042 _vacuumMaterial = add(new StiMaterial("Vaccum",0., 1., 0., 1e30, 0.) );
00043 for (Int_t i = 1; i < 5; i += 2) {
00044 TGeoVolume *pipe = gGeoManager->GetVolume(PipeVolumes[i].name);
00045 if (!pipe) {
00046 Warning("StiStarDetectorBuilder::useVMCGeometry","No %s volume\n",PipeVolumes[i].name);
00047 continue;
00048 }
00049 TGeoMaterial *pipeMaterial = pipe->GetMaterial();
00050 Double_t PotI = StiVMCToolKit::GetPotI(pipeMaterial);
00051 _pipeMaterial = add(new StiMaterial(pipeMaterial->GetName(),
00052 pipeMaterial->GetZ(),
00053 pipeMaterial->GetA(),
00054 pipeMaterial->GetDensity(),
00055 pipeMaterial->GetDensity()*pipeMaterial->GetRadLen(),
00056 PotI));
00057 Double_t ionization = _pipeMaterial->getIonization();
00058 StiElossCalculator * pipeElossCalculator = new StiElossCalculator(_pipeMaterial->getZOverA(), ionization*ionization, _pipeMaterial->getA(), _pipeMaterial->getZ(), _pipeMaterial->getDensity());
00059 TGeoTube *pipeShape = (TGeoTube *) pipe->GetShape();
00060 Double_t Rmax = pipeShape->GetRmax();
00061 Double_t dZ = pipeShape->GetDz();
00062 TGeoVolume *vac = gGeoManager->GetVolume(PipeVolumes[i+1].name);
00063 if (!vac) {
00064 Warning("StiStarDetectorBuilder::useVMCGeometry","No %s volume\n",PipeVolumes[i+1].name);
00065 continue;
00066 }
00067 TGeoTube *vacShape = (TGeoTube *) vac->GetShape();
00068 Double_t Rmin = vacShape->GetRmax();
00069 Double_t radius = (Rmin + Rmax)/2;
00070 _beamPipeShape = new StiCylindricalShape;
00071 _beamPipeShape->setName(PipeVolumes[i].comment);
00072 _beamPipeShape->setThickness(Rmax-Rmin);
00073 if (i == 1) _beamPipeShape->setHalfDepth( 2*dZ );
00074 else _beamPipeShape->setHalfDepth( dZ );
00075 _beamPipeShape->setOpeningAngle( dPhi );
00076 _beamPipeShape->setOuterRadius(Rmax);
00077 add(_beamPipeShape);
00078 for (Int_t j = 0; j < 2; j++) {
00079 if (i == 1 && j == 1) continue;
00080 StiPlacement *p = new StiPlacement;
00081 TString pathT = Form(PipeVolumes[i].path,j+1);
00082 if (i == 1) p->setZcenter(0);
00083 else {
00084 TGeoPhysicalNode *nodeP = gGeoManager->MakePhysicalNode(pathT);
00085 TGeoHMatrix *hmat = nodeP->GetMatrix();
00086 Double_t *xyz = hmat->GetTranslation();
00087 p->setZcenter(xyz[2]);
00088 }
00089 p->setLayerRadius(radius);
00090 p->setLayerAngle(0);
00091 p->setNormalRep(0, radius, 0.);
00092 p->setRegion(StiPlacement::kMidRapidity);
00093 StiDetector *pipeVolume = _detectorFactory->getInstance();
00094 TString nameP = pathT.Data();
00095 nameP.ReplaceAll("HALL_1/CAVE_1/","");
00096 nameP.Resize(30); nameP.Strip();
00097 pipeVolume->setName(nameP.Data());
00098 pipeVolume->setIsOn(true);
00099 pipeVolume->setIsActive(new StiNeverActiveFunctor);
00100 pipeVolume->setIsContinuousMedium(false);
00101 pipeVolume->setIsDiscreteScatterer(true);
00102 pipeVolume->setShape(_beamPipeShape);
00103 pipeVolume->setPlacement(p);
00104 pipeVolume->setGas(_vacuumMaterial);
00105 pipeVolume->setMaterial(_pipeMaterial);
00106 pipeVolume->setElossCalculator(pipeElossCalculator);
00107 Int_t layer = getNRows();
00108 add(layer+1,0,pipeVolume);
00109 }
00110 }
00111 Int_t NoExtraVols = sizeof(PipeVolumes)/sizeof(VolumeMap_t);
00112 TString pathT("HALL_1/CAVE_1");
00113 TString path("");
00114 for (Int_t i = 5; i < NoExtraVols; i++) {
00115 gGeoManager->RestoreMasterVolume();
00116 gGeoManager->CdTop();
00117 gGeoManager->cd(pathT); path = pathT;
00118 TGeoNode *nodeT = gGeoManager->GetCurrentNode();
00119 if (! nodeT) continue;
00120 StiVMCToolKit::LoopOverNodes(nodeT, path, PipeVolumes[i].name, MakeAverageVolume);
00121 }
00122 cout << "StiStarDetectorBuilder::buildDetectors() -I- Done" << endl;
00123 }