[807] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // File name: RadmonTDetectorVolumesWithPadsDecorator.icc |
---|
| 28 | // Creation date: Sep 2005 |
---|
| 29 | // Main author: Riccardo Capra <capra@ge.infn.it> |
---|
| 30 | // |
---|
| 31 | // Id: $Id: RadmonTDetectorVolumesWithPadsDecorator.icc,v 1.1.2.2 2006/06/29 16:12:42 gunter Exp $ |
---|
| 32 | // Tag: $Name: geant4-09-01-patch-02 $ |
---|
| 33 | // |
---|
| 34 | |
---|
| 35 | #ifndef RADMONTDETECTORVOLUMESWITHPADSDECORATOR_HH |
---|
| 36 | #error "RadmonTDetectorVolumesWithPadsDecorator.icc cannot be included directly. Please use RadmonTDetectorVolumesWithPadsDecorator.hh" |
---|
| 37 | #else /* RADMONTDETECTORVOLUMESWITHPADSDECORATOR_HH */ |
---|
| 38 | // Include files |
---|
| 39 | #include "RadmonVDetectorLabelledEntityConstructor.hh" |
---|
| 40 | #include "RadmonDetectorLayerVolumesList.hh" |
---|
| 41 | #include "RadmonDetectorLayerVolumeItem.hh" |
---|
| 42 | #include "G4Box.hh" |
---|
| 43 | #include "G4UIcommand.hh" |
---|
| 44 | |
---|
| 45 | template <class LayerVolumesComponent> |
---|
| 46 | RadmonTDetectorVolumesWithPadsDecorator<LayerVolumesComponent> :: RadmonTDetectorVolumesWithPadsDecorator(const RadmonVDetectorLabelledEntityConstructor * constructor) |
---|
| 47 | : |
---|
| 48 | owner(constructor), |
---|
| 49 | component(constructor) |
---|
| 50 | { |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | template <class LayerVolumesComponent> |
---|
| 56 | RadmonTDetectorVolumesWithPadsDecorator<LayerVolumesComponent> :: ~RadmonTDetectorVolumesWithPadsDecorator() |
---|
| 57 | { |
---|
| 58 | while(!attributesStack.empty()) |
---|
| 59 | { |
---|
| 60 | delete attributesStack.top(); |
---|
| 61 | attributesStack.pop(); |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | template <class LayerVolumesComponent> |
---|
| 70 | RadmonDetectorLayerVolumesList * RadmonTDetectorVolumesWithPadsDecorator<LayerVolumesComponent> :: GenerateVolumesList(void) |
---|
| 71 | { |
---|
| 72 | G4double width(owner->GetWidth()); |
---|
| 73 | if (width<0) |
---|
| 74 | return 0; |
---|
| 75 | |
---|
| 76 | G4double height(owner->GetHeight()); |
---|
| 77 | if (height<0) |
---|
| 78 | return 0; |
---|
| 79 | |
---|
| 80 | G4double thickness(owner->GetThickness()); |
---|
| 81 | if (thickness<0) |
---|
| 82 | return 0; |
---|
| 83 | |
---|
| 84 | G4int padIndex(0); |
---|
| 85 | G4String padIndexStr; |
---|
| 86 | |
---|
| 87 | for(;;) |
---|
| 88 | { |
---|
| 89 | padIndex++; |
---|
| 90 | padIndexStr=G4UIcommand::ConvertToString(padIndex); |
---|
| 91 | |
---|
| 92 | if (!owner->ExistsAttribute("PadsPosition_"+padIndexStr)) |
---|
| 93 | break; |
---|
| 94 | |
---|
| 95 | padsDataList.push_back(RadmonDetectorPadsData()); |
---|
| 96 | RadmonDetectorPadsData & last(padsDataList.back()); |
---|
| 97 | |
---|
| 98 | if (!last.ReadPositionsAndRotationsFromString(owner->GetAttribute("PadsPosition_"+padIndexStr, "#"))) |
---|
| 99 | { |
---|
| 100 | G4cout << "RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: \"PadsPosition_" << padIndexStr << "\" has an invalid format" << G4endl; |
---|
| 101 | return 0; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | G4double var(owner->GetAttributeAsMeasure("PadsWidth_"+padIndexStr, "Length", -1.)); |
---|
| 105 | if (var<0) |
---|
| 106 | { |
---|
| 107 | G4cout << "RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: \"PadsWidth_" << padIndexStr << "\" not defined." << G4endl; |
---|
| 108 | return 0; |
---|
| 109 | } |
---|
| 110 | last.SetWidth(var); |
---|
| 111 | |
---|
| 112 | var=owner->GetAttributeAsMeasure("PadsHeight_"+padIndexStr, "Length", -1.); |
---|
| 113 | if (var<0) |
---|
| 114 | { |
---|
| 115 | G4cout << "RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: \"PadsHeight_" << padIndexStr << "\" not defined." << G4endl; |
---|
| 116 | return 0; |
---|
| 117 | } |
---|
| 118 | last.SetHeight(var); |
---|
| 119 | |
---|
| 120 | G4Material * material(owner->GetMaterial("PadsMaterial_"+padIndexStr)); |
---|
| 121 | if (!material) |
---|
| 122 | return 0; |
---|
| 123 | last.SetMaterial(material); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | if (padIndex<=1) |
---|
| 127 | { |
---|
| 128 | G4cout << "RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: No pads defined" << G4endl; |
---|
| 129 | return 0; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | RadmonDetectorLayerVolumesList * list(component.GenerateVolumesList()); |
---|
| 133 | |
---|
| 134 | if (list==0) |
---|
| 135 | return 0; |
---|
| 136 | |
---|
| 137 | G4int n(list->GetNItems()); |
---|
| 138 | |
---|
| 139 | if (n==0) |
---|
| 140 | { |
---|
| 141 | delete list; |
---|
| 142 | return 0; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | RadmonDetectorLayerVolumeItem * item; |
---|
| 146 | RadmonDetectorLayerVolumeItem * motherItem; |
---|
| 147 | |
---|
| 148 | while (n>0) |
---|
| 149 | { |
---|
| 150 | n--; |
---|
| 151 | |
---|
| 152 | item=list->GetItem(n); |
---|
| 153 | if (item->GetMotherVolumeItem()==0) |
---|
| 154 | { |
---|
| 155 | motherItem=item; |
---|
| 156 | break; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | if (!motherItem) |
---|
| 161 | G4Exception("RadmonTDetectorVolumesWithPadsDecorator::GenerateVolumesList: No mother volume found."); |
---|
| 162 | |
---|
| 163 | intersection.Initialize(motherItem); |
---|
| 164 | |
---|
| 165 | PadsDataList::const_iterator i(padsDataList.begin()); |
---|
| 166 | PadsDataList::const_iterator end(padsDataList.end()); |
---|
| 167 | G4VisAttributes * visAttributes; |
---|
| 168 | padIndex=0; |
---|
| 169 | |
---|
| 170 | G4int j; |
---|
| 171 | G4String jStr; |
---|
| 172 | G4VSolid * box; |
---|
| 173 | |
---|
| 174 | while (i!=end) |
---|
| 175 | { |
---|
| 176 | padIndex++; |
---|
| 177 | padIndexStr=G4UIcommand::ConvertToString(padIndex); |
---|
| 178 | |
---|
| 179 | visAttributes=owner->AllocateVisAttributes("PadsVisAttributes_"+padIndexStr, i->GetMaterial()); |
---|
| 180 | attributesStack.push(visAttributes); |
---|
| 181 | |
---|
| 182 | box=new G4Box("Pad_"+padIndexStr, i->GetWidth()/2., i->GetHeight()/2., thickness/2.); |
---|
| 183 | |
---|
| 184 | j=i->GetNPads(); |
---|
| 185 | |
---|
| 186 | while (j>0) |
---|
| 187 | { |
---|
| 188 | jStr=G4UIcommand::ConvertToString(j); |
---|
| 189 | j--; |
---|
| 190 | |
---|
| 191 | item=list->AppendItem(); |
---|
| 192 | item->SetSolid(intersection.ApplyTo(box, i->GetRotation(j), i->GetPosition(j), j==0, true)); |
---|
| 193 | item->SetAttributes(visAttributes); |
---|
| 194 | item->SetMaterial(i->GetMaterial()); |
---|
| 195 | item->SetName("Pad_"+padIndexStr+"_"+jStr); |
---|
| 196 | item->SetMotherVolumeItem(motherItem); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | i++; |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | return list; |
---|
| 203 | } |
---|
| 204 | #endif /* RADMONTDETECTORVOLUMESWITHPADSDECORATOR_HH */ |
---|