TGeoMedium* KVSpectroDetector::GetGeoMedium(const Char_t* mat_name){ // By default, return pointer to TGeoMedium corresponding to this KVMaterial. // If argument "mat_name" is given, a pointer to a medium is return for this material. // mat_name = "Vacuum" is a special case: if the "Vacuum" does not exist, we create it. // // Instance of geometry manager class TGeoManager must be created before calling this // method, otherwise 0x0 will be returned. // If the required TGeoMedium is not already available in the TGeoManager, we create // a new TGeoMedium corresponding to the material given in argument. if( !gGeoManager ) return NULL; TString medName, matName; if( !strcmp(mat_name,"") ){ // for gaseous materials, the TGeoMedium/Material name is of the form // gasname_pressure // e.g. C3F8_37.5 for C3F8 gas at 37.5 torr // each gas with different pressure has to have a separate TGeoMaterial/Medium matName = GetName(); KVIonRangeTableMaterial* irmat = KVMaterial::GetRangeTable()->GetMaterial(matName.Data()); if(irmat->IsGas()) medName.Form("%s_%f", matName.Data(), GetPressure()); else medName = GetName(); } else{ matName = mat_name; medName = mat_name; } TGeoMedium* gmed = gGeoManager->GetMedium( medName); if( gmed ) return gmed; TGeoMaterial *gmat = gGeoManager->GetMaterial( medName); if( !gmat ){ if( !strcmp(matName.Data(), "Vacuum") ){ // create material gmat = new TGeoMaterial("Vacuum",0,0,0 ); } else{ // create material gmat = GetRangeTable()->GetTGeoMaterial(matName.Data()); if(!gmat){ Error("GetGeoMedium","Material %s is nowhere to be found in %s" ,matName.Data(),GetRangeTable()->GetName()); return NULL; } gmat->SetPressure( GetPressure() ); gmat->SetTemperature( GetTemperature() ); gmat->SetTransparency(0); } } // For the moment the names of material and medium do not // depend on the temperature of the material. gmat->SetName(medName); gmat->SetTitle(matName); // create medium TGeoMedium* lastmed = (TGeoMedium*)gGeoManager->GetListOfMedia()->Last(); Int_t numed = (lastmed ? lastmed->GetId()+1 : 0); // static counter variable used to number media gmed = new TGeoMedium( medName, numed, gmat ); numed+=1; return gmed; }
TGeoMedium* KVMaterial::GetGeoMedium(const Char_t* med_name) { // By default, return pointer to TGeoMedium corresponding to this KVMaterial. // If argument "med_name" is given and corresponds to the name of an already existing // medium, we return a pointer to this medium, or 0x0 if it does not exist. // med_name = "Vacuum" is a special case: if the "Vacuum" does not exist, we create it. // // Instance of geometry manager class TGeoManager must be created before calling this // method, otherwise 0x0 will be returned. // If the required TGeoMedium is not already available in the TGeoManager, we create // a new TGeoMedium corresponding to the properties of this KVMaterial. // The name of the TGeoMedium (and associated TGeoMaterial) is the name of the KVMaterial. if (!gGeoManager) return NULL; if (strcmp(med_name, "")) { TGeoMedium* gmed = gGeoManager->GetMedium(med_name); if (gmed) return gmed; else if (!strcmp(med_name, "Vacuum")) { // create material TGeoMaterial* gmat = new TGeoMaterial("Vacuum", 0, 0, 0); gmat->SetTitle("Vacuum"); gmed = new TGeoMedium("Vacuum", 0, gmat); gmed->SetTitle("Vacuum"); return gmed; } return NULL; } // if object is a KVDetector, we return medium corresponding to the active layer if (GetActiveLayer()) return GetActiveLayer()->GetGeoMedium(); // for gaseous materials, the TGeoMedium/Material name is of the form // gasname_pressure // e.g. C3F8_37.5 for C3F8 gas at 37.5 torr // each gas with different pressure has to have a separate TGeoMaterial/Medium TString medName; if (IsGas()) medName.Form("%s_%f", GetName(), GetPressure()); else medName = GetName(); TGeoMedium* gmed = gGeoManager->GetMedium(medName); if (gmed) return gmed; TGeoMaterial* gmat = gGeoManager->GetMaterial(medName); if (!gmat) { // create material gmat = GetRangeTable()->GetTGeoMaterial(GetName()); gmat->SetPressure(GetPressure()); gmat->SetTemperature(GetTemperature()); gmat->SetTransparency(0); gmat->SetName(medName); gmat->SetTitle(GetName()); } // create medium static Int_t numed = 1; // static counter variable used to number media gmed = new TGeoMedium(medName, numed, gmat); numed += 1; return gmed; }