void KVGeoNavigator::FormatDetectorName(const Char_t* basename, KVString& name) { // If a format for naming detectors has been defined by a call // to SetDetectorNameFormat(const Char_t *), we use it to // format the name in the TString. // If no format was given we prefix the names of the parent structures // to the basename in order to generate the full name of the detector: // [struc1-name]_[struc2-name]_..._[detector-basename] // If SetNameCorrespondanceList(const Char_t *) was used, we use it to translate // any names resulting from this formatting to their final value. name = ""; if (!fCurStrucNumber) { // no parent structures name = basename; } else { if (fDetNameFmt == "") { for (int i = 0; i < fCurStrucNumber; i++) { KVGeoStrucElement* el = (KVGeoStrucElement*)fCurrentStructures[i]; name += Form("%s_", el->GetName()); } name += basename; } else { // $det:name$ - will be replaced by the detector basename // $struc:[type]:name$ - will be replaced by the name of the parent structure of given type // $struc:[type]:type$ - will be replaced by the type of the parent structure of given type // $struc:[type]:number$ - will be replaced by the number of the parent structure of given type fDetNameFmt.Begin("$"); while (!fDetNameFmt.End()) { KVString bit = fDetNameFmt.Next(); if (bit.Contains(":")) { bit.Begin(":"); KVString itbit = bit.Next(); if (itbit == "det") { itbit = bit.Next(); if (itbit.BeginsWith("name")) { Ssiz_t ind = itbit.Index("%"); if (ind > -1) { itbit.Remove(0, ind); name += Form(itbit.Data(), basename); } else name += basename; } } else if (itbit == "struc") { KVString struc_typ = bit.Next(); KVGeoStrucElement* el = 0; for (int i = 0; i < fCurStrucNumber; i++) { el = (KVGeoStrucElement*)fCurrentStructures[i]; if (el->IsType(struc_typ)) break; } if (el) { itbit = bit.Next(); if (itbit.BeginsWith("name")) { Ssiz_t ind = itbit.Index("%"); if (ind > -1) { itbit.Remove(0, ind); name += Form(itbit.Data(), el->GetName()); } else name += el->GetName(); } else if (itbit.BeginsWith("type")) { Ssiz_t ind = itbit.Index("%"); if (ind > -1) { itbit.Remove(0, ind); name += Form(itbit.Data(), el->GetType()); } else name += el->GetType(); } else if (itbit.BeginsWith("number")) { Ssiz_t ind = itbit.Index("%"); if (ind > -1) { itbit.Remove(0, ind); name += Form(itbit.Data(), el->GetNumber()); } else name += el->GetNumber(); } } } } else name += bit; } } } TString tmp; GetNameCorrespondance(name.Data(), tmp); name = tmp; }
KVDetector* KVGeoImport::GetCurrentDetector() { // Returns pointer to KVDetector corresponding to current location // in geometry. Detector is created and added to array if needed. // We also set up any geometry structure elements (from nodes beginning with "STRUCT_") KVString detector_name; Bool_t multilay; TGeoVolume* detector_volume = GetCurrentDetectorNameAndVolume(detector_name,multilay); // failed to identify current volume as part of a detector if(!detector_volume) return 0; // has detector already been built ? if not, do it now KVDetector* det = fArray->GetDetector(detector_name); if(!fCreateArray){ if(det){ // set matrix & shape for entrance window if not done yet if(!det->GetEntranceWindowMatrix()){ det->SetEntranceWindowMatrix(GetCurrentMatrix()); det->SetEntranceWindowShape((TGeoBBox*)GetCurrentVolume()->GetShape()); } TString vol_name(GetCurrentVolume()->GetName()); if(!multilay || vol_name.BeginsWith("ACTIVE_")){ // set matrix & shape for active layer det->SetActiveLayerMatrix(GetCurrentMatrix()); det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape()); } } } else { if(!det) { det = BuildDetector(detector_name, detector_volume); if(det) { // Setting the entrance window shape and matrix // ============================================ // for consistency, the matrix and shape MUST correspond // i.e. we cannot have the matrix corresponding to the entrance window // of a multilayer detector and the shape corresponding to the // whole detector (all layers) - otherwise, calculation of points // on detector entrance window will be false! // Info("GetCurrentDetector","Setting EW matrix to current matrix:"); // GetCurrentMatrix()->Print(); det->SetEntranceWindowMatrix(GetCurrentMatrix()); det->SetEntranceWindowShape((TGeoBBox*)GetCurrentVolume()->GetShape()); TString vol_name(GetCurrentVolume()->GetName()); if(!multilay || vol_name.BeginsWith("ACTIVE_")){ // first layer of detector (or only layer) is also active layer // Info("GetCurrentDetector","and also setting active layer matrix to current matrix:"); // GetCurrentMatrix()->Print(); det->SetActiveLayerMatrix(GetCurrentMatrix()); det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape()); } fArray->Add(det); Int_t nstruc = CurrentStructures().GetEntries(); if(nstruc){ // Build and add geometry structure elements KVGeoStrucElement* ELEM = fArray; for(register int i=0;i<nstruc;i++){ KVGeoStrucElement* elem = (KVGeoStrucElement*)CurrentStructures()[i]; KVGeoStrucElement* nextELEM = ELEM->GetStructure(elem->GetName()); if(!nextELEM){ // make new structure nextELEM = new KVGeoStrucElement(elem->GetName(), elem->GetType()); nextELEM->SetNumber(elem->GetNumber()); ELEM->Add(nextELEM); } ELEM=nextELEM; } // add detector to last structure ELEM->Add(det); } } } else { // Detector already built, are we now in its active layer ? TString vol_name(GetCurrentVolume()->GetName()); if(!multilay || vol_name.BeginsWith("ACTIVE_")){ // Info("GetCurrentDetector","Setting active layer matrix to current matrix:"); // GetCurrentMatrix()->Print(); det->SetActiveLayerMatrix(GetCurrentMatrix()); det->SetActiveLayerShape((TGeoBBox*)GetCurrentVolume()->GetShape()); } } } return det; }