00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00040 #include <stdio.h>
00041 #include <map>
00042 #include <exception>
00043 using namespace std;
00044 #include <stdexcept>
00045 #include "StMessMgr.h"
00046 #include "StThreeVectorD.hh"
00047
00048
00049 #include "Sti/Base/Factory.h"
00050 #include "Sti/StiPlanarShape.h"
00051 #include "Sti/StiCylindricalShape.h"
00052 #include "Sti/StiMaterial.h"
00053 #include "Sti/StiPlacement.h"
00054 #include "Sti/StiDetector.h"
00055 #include "Sti/StiToolkit.h"
00056 #include "Sti/StiIsActiveFunctor.h"
00057 #include "Sti/StiNeverActiveFunctor.h"
00058 #include "StiRnD/Ist/StiIstIsActiveFunctor.h"
00059 #include "StiRnD/Ist/StiIstDetectorBuilder.h"
00060 #include "Sti/StiElossCalculator.h"
00061 #include "StiRnD/Ist/StiIstDetectorBuilder.h"
00062 #include "StDetectorDbMaker/StiIst1HitErrorCalculator.h"
00063
00064
00065
00066
00067
00068
00069 StiIstDetectorBuilder::StiIstDetectorBuilder(bool active, const string & inputFile)
00070 : StiDetectorBuilder("Ist",active,inputFile), _siMat(0), _hybridMat(0)
00071 {
00072
00073
00074
00075
00076 }
00077
00078 StiIstDetectorBuilder::~StiIstDetectorBuilder()
00079 {}
00080
00081 void StiIstDetectorBuilder::loadDS(TDataSet& ds){
00082 cout<<"StiIstDetectorBuilder::loadDS(TDataSet& ds) -I- started: "<<endl;
00083
00084
00085
00086 }
00087
00088
00089 void StiIstDetectorBuilder::buildDetectors(StMaker & source)
00090 {
00091 int nRows = 1 ;
00092 gMessMgr->Info() << "StiIstDetectorBuilder::buildDetectors() - I - Started "<<endm;
00093
00094
00095 setNRows(nRows);
00096 if (StiVMCToolKit::GetVMC()) {useVMCGeometry();}
00097 }
00098
00099
00100 void StiIstDetectorBuilder::useVMCGeometry() {
00101 cout << "StiIstDetectorBuilder::buildDetectors() -I- Use VMC geometry" << endl;
00102 SetCurrentDetectorBuilder(this);
00103
00104
00105 struct Material_t {
00106 const Char_t *name;
00107 StiMaterial **p;
00108 };
00109 Material_t map[] = {
00110 {"AIR", &_gasMat},
00111 {"SILICON", &_siMat},
00112 {"SILICON", &_hybridMat}
00113 };
00114 Int_t M = sizeof(map)/sizeof(Material_t);
00115 for (Int_t i = 0; i < M; i++) {
00116 const TGeoMaterial *mat = gGeoManager->GetMaterial(map[i].name);
00117 if (! mat) continue;
00118 Double_t PotI = StiVMCToolKit::GetPotI(mat);
00119 *map[i].p = add(new StiMaterial(mat->GetName(),
00120 mat->GetZ(),
00121 mat->GetA(),
00122 mat->GetDensity(),
00123 mat->GetDensity()*mat->GetRadLen(),
00124 PotI));
00125 }
00126
00127
00128 const VolumeMap_t IstVolumes[] =
00129 {
00130 {"IBSS", "active silicon", "HALL_1/CAVE_1/IBMO_1","",""},
00131 {"IBSP", "inactive silicon","HALL_1/CAVE_1/IBMO_1","",""}
00132 };
00133 Int_t NoIstVols = sizeof(IstVolumes)/sizeof(VolumeMap_t);
00134 gGeoManager->RestoreMasterVolume();
00135 gGeoManager->CdTop();
00136 for (Int_t i = 0; i < NoIstVols; i++) {
00137 gGeoManager->cd(IstVolumes[i].path);
00138 TGeoNode *nodeT = gGeoManager->GetCurrentNode();
00139 if (! nodeT) continue;;
00140 StiVMCToolKit::LoopOverNodes(nodeT, IstVolumes[i].path, IstVolumes[i].name, MakeAverageVolume);
00141 }
00142 }
00143
00144 void StiIstDetectorBuilder::AverageVolume(TGeoPhysicalNode *nodeP) {
00145
00146 LOG_DEBUG << "StiDetectorBuilder::AverageVolume -I TGeoPhysicalNode\t" << nodeP->GetName() << endm;
00147
00148
00149
00150 const Int_t NWAFERS = 12;
00151
00152 TString nameP(nodeP->GetName());
00153
00154
00155 nameP.ReplaceAll("HALL_1/CAVE_1/","");
00156 TString temp=nameP;
00157 temp.ReplaceAll("/IBMO_1/IBMY","");
00158 int q=temp.Index("_");
00159 temp.Replace(0,q+1,"");
00160 TString num0=temp(0,1);
00161 int layer=num0.Atoi();
00162 q=temp.Index("_");
00163 temp.Replace(0,q+1,"");
00164 TString num1=temp(0,2);
00165 if(!num1.IsDigit()) num1=temp(0,1);
00166 int ladder=num1.Atoi();
00167 q=temp.Index("_");
00168 temp.Replace(0,q+1,"");
00169 TString num2=temp(0,2);
00170 if(!num2.IsDigit()) num2=temp(0,1);
00171 int wafer=num2.Atoi();
00172 q=temp.Index("_");
00173 temp.Replace(0,q+1,"");
00174 TString num3=temp(0,1);
00175
00176 if(wafer!=1) return;
00177
00178
00179 Bool_t ActiveVolume = kFALSE;
00180 if (nodeP->GetVolume()->GetMedium()->GetParam(0) == 1) {
00181 ActiveVolume = kTRUE;
00182 }
00183
00184
00185 TGeoMaterial *matP = nodeP->GetVolume()->GetMaterial();
00186 Double_t PotI = StiVMCToolKit::GetPotI(matP);
00187 static StiMaterial *matS = 0;
00188 if (! matS) matS = add(new StiMaterial(matP->GetName(),
00189 matP->GetZ(),
00190 matP->GetA(),
00191 matP->GetDensity(),
00192 matP->GetDensity()*matP->GetRadLen(),
00193 PotI));
00194 Double_t ionization = matS->getIonization();
00195 StiElossCalculator *ElossCalculator = new StiElossCalculator(matS->getZOverA(),
00196 ionization*ionization,
00197 matS->getA(),
00198 matS->getZ(),
00199 matS->getDensity());
00200
00201 TGeoBBox *box = (TGeoBBox *) nodeP->GetShape();
00202 StiShape *sh = new StiPlanarShape(nodeP->GetVolume()->GetName(),
00203 NWAFERS*box->GetDZ(),
00204 box->GetDY(),
00205 box->GetDX());
00206 add(sh);
00207
00208
00209 TGeoHMatrix *hmat = nodeP->GetMatrix();
00210 Double_t *xyz = hmat->GetTranslation();
00211 Double_t *rot = hmat->GetRotationMatrix();
00212 StThreeVectorD centerVector(xyz[0],xyz[1],xyz[2]);
00213 StThreeVectorD normalVector(rot[1],rot[4],rot[7]);
00214
00215
00216
00217
00218 normalVector /= normalVector.magnitude();
00219
00220
00221 StiPlacement *pPlacement = new StiPlacement;
00222 Double_t phi = centerVector.phi();
00223 Double_t phiD = normalVector.phi();
00224 Double_t r = centerVector.perp();
00225 pPlacement->setZcenter(0);
00226 pPlacement->setLayerRadius(r);
00227
00228
00229
00230
00231
00232
00233
00234 if(nameP.Contains("IBSS")) pPlacement->setLayerAngle(phi);
00235 if(nameP.Contains("IBSP")) pPlacement->setLayerAngle(phi-.05);
00236 pPlacement->setRegion(StiPlacement::kMidRapidity);
00237 pPlacement->setNormalRep(phiD, r*TMath::Cos(phi-phiD), r*TMath::Sin(phi-phiD));
00238 assert(pPlacement);
00239
00240
00241
00242 StiDetector *pDetector = getDetectorFactory()->getInstance();
00243 pDetector->setName(nameP.Data());
00244 pDetector->setIsOn(false);
00245 if (ActiveVolume) {
00246 pDetector->setIsActive(new StiIstIsActiveFunctor);
00247 cout<<"active volume: "<<nameP<<endl;
00248 }
00249 else {
00250 pDetector->setIsActive(new StiNeverActiveFunctor);
00251 cout<<"inactive volume: "<<nameP<<endl;
00252 layer++;
00253 }
00254 pDetector->setIsContinuousMedium(false);
00255 pDetector->setIsDiscreteScatterer(true);
00256 pDetector->setShape(sh);
00257 pDetector->setPlacement(pPlacement);
00258 pDetector->setGas(GetCurrentDetectorBuilder()->getGasMat());
00259 pDetector->setMaterial(matS);
00260 pDetector->setElossCalculator(ElossCalculator);
00261 pDetector->setHitErrorCalculator(StiIst1HitErrorCalculator::instance());
00262
00263
00264
00265 add(layer,ladder,pDetector);
00266
00267 LOG_INFO << "StiIstDetectorBuilder: Added detector -I- " << pDetector->getName() << endm;
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 }
00290