// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // File name: RadmonTDetectorVolumesWithPadsDecorator.icc // Creation date: Sep 2005 // Main author: Riccardo Capra // // Id: $Id: RadmonTDetectorVolumesWithPadsDecorator.icc,v 1.1.2.2 2006/06/29 16:12:42 gunter Exp $ // Tag: $Name: geant4-09-01-patch-02 $ // #ifndef RADMONTDETECTORVOLUMESWITHPADSDECORATOR_HH #error "RadmonTDetectorVolumesWithPadsDecorator.icc cannot be included directly. Please use RadmonTDetectorVolumesWithPadsDecorator.hh" #else /* RADMONTDETECTORVOLUMESWITHPADSDECORATOR_HH */ // Include files #include "RadmonVDetectorLabelledEntityConstructor.hh" #include "RadmonDetectorLayerVolumesList.hh" #include "RadmonDetectorLayerVolumeItem.hh" #include "G4Box.hh" #include "G4UIcommand.hh" template RadmonTDetectorVolumesWithPadsDecorator :: RadmonTDetectorVolumesWithPadsDecorator(const RadmonVDetectorLabelledEntityConstructor * constructor) : owner(constructor), component(constructor) { } template RadmonTDetectorVolumesWithPadsDecorator :: ~RadmonTDetectorVolumesWithPadsDecorator() { while(!attributesStack.empty()) { delete attributesStack.top(); attributesStack.pop(); } } template RadmonDetectorLayerVolumesList * RadmonTDetectorVolumesWithPadsDecorator :: GenerateVolumesList(void) { G4double width(owner->GetWidth()); if (width<0) return 0; G4double height(owner->GetHeight()); if (height<0) return 0; G4double thickness(owner->GetThickness()); if (thickness<0) return 0; G4int padIndex(0); G4String padIndexStr; for(;;) { padIndex++; padIndexStr=G4UIcommand::ConvertToString(padIndex); if (!owner->ExistsAttribute("PadsPosition_"+padIndexStr)) break; padsDataList.push_back(RadmonDetectorPadsData()); RadmonDetectorPadsData & last(padsDataList.back()); if (!last.ReadPositionsAndRotationsFromString(owner->GetAttribute("PadsPosition_"+padIndexStr, "#"))) { G4cout << "RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: \"PadsPosition_" << padIndexStr << "\" has an invalid format" << G4endl; return 0; } G4double var(owner->GetAttributeAsMeasure("PadsWidth_"+padIndexStr, "Length", -1.)); if (var<0) { G4cout << "RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: \"PadsWidth_" << padIndexStr << "\" not defined." << G4endl; return 0; } last.SetWidth(var); var=owner->GetAttributeAsMeasure("PadsHeight_"+padIndexStr, "Length", -1.); if (var<0) { G4cout << "RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: \"PadsHeight_" << padIndexStr << "\" not defined." << G4endl; return 0; } last.SetHeight(var); G4Material * material(owner->GetMaterial("PadsMaterial_"+padIndexStr)); if (!material) return 0; last.SetMaterial(material); } if (padIndex<=1) { G4cout << "RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: No pads defined" << G4endl; return 0; } RadmonDetectorLayerVolumesList * list(component.GenerateVolumesList()); if (list==0) return 0; G4int n(list->GetNItems()); if (n==0) { delete list; return 0; } RadmonDetectorLayerVolumeItem * item; RadmonDetectorLayerVolumeItem * motherItem; while (n>0) { n--; item=list->GetItem(n); if (item->GetMotherVolumeItem()==0) { motherItem=item; break; } } if (!motherItem) G4Exception("RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: No mother volume found."); intersection.Initialize(motherItem); PadsDataList::const_iterator i(padsDataList.begin()); PadsDataList::const_iterator end(padsDataList.end()); G4VisAttributes * visAttributes; padIndex=0; G4int j; G4String jStr; G4VSolid * box; while (i!=end) { padIndex++; padIndexStr=G4UIcommand::ConvertToString(padIndex); visAttributes=owner->AllocateVisAttributes("PadsVisAttributes_"+padIndexStr, i->GetMaterial()); attributesStack.push(visAttributes); box=new G4Box("Pad_"+padIndexStr, i->GetWidth()/2., i->GetHeight()/2., thickness/2.); j=i->GetNPads(); while (j>0) { jStr=G4UIcommand::ConvertToString(j); j--; item=list->AppendItem(); item->SetSolid(intersection.ApplyTo(box, i->GetRotation(j), i->GetPosition(j), j==0, true)); item->SetAttributes(visAttributes); item->SetMaterial(i->GetMaterial()); item->SetName("Pad_"+padIndexStr+"_"+jStr); item->SetMotherVolumeItem(motherItem); } i++; } return list; } #endif /* RADMONTDETECTORVOLUMESWITHPADSDECORATOR_HH */