File indexing completed on 2025-02-26 09:19:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 #include "G4RunManager.hh"
0044 #include "G4PhysicalVolumeStore.hh"
0045 #include "G4LogicalVolumeStore.hh"
0046 #include "G4VisAttributes.hh"
0047 #include "G4UserLimits.hh"
0048 #include "G4ios.hh"
0049 #include "G4SDManager.hh"
0050 #include "G4GDMLParser.hh"
0051
0052 #include "ConfigurationManager.hh"
0053 #include "DetectorConstruction.hh"
0054 #include "TrackerSD.hh"
0055 #include "MscSD.hh"
0056 #include "lArTPCSD.hh"
0057 #include "CalorimeterSD.hh"
0058 #include "DRCalorimeterSD.hh"
0059 #include "RadiatorSD.hh"
0060 #include "PhotonSD.hh"
0061 #include "InteractionSD.hh"
0062 #include "ColorReader.hh"
0063
0064 #include <iostream>
0065
0066 DetectorConstruction::DetectorConstruction(G4String fname)
0067 : G4VUserDetectorConstruction()
0068 , gdmlFile(fname)
0069 {}
0070
0071 DetectorConstruction::~DetectorConstruction() {}
0072 G4VPhysicalVolume* DetectorConstruction::Construct()
0073 {
0074 verbose = ConfigurationManager::getInstance()->isEnable_verbose();
0075 ReadGDML();
0076 const G4GDMLAuxMapType* auxmap = parser->GetAuxMap();
0077 if(verbose)
0078 {
0079 G4cout << "Found " << auxmap->size()
0080 << " volume(s) with auxiliary information." << G4endl << G4endl;
0081 }
0082 for(G4GDMLAuxMapType::const_iterator iter = auxmap->begin();
0083 iter != auxmap->end(); iter++)
0084 {
0085 if(verbose)
0086 {
0087 G4cout << "Volume " << ((*iter).first)->GetName()
0088 << " has the following list of auxiliary information: " << G4endl;
0089 }
0090 for(G4GDMLAuxListType::const_iterator vit = (*iter).second.begin();
0091 vit != (*iter).second.end(); vit++)
0092 {
0093 if(verbose)
0094 {
0095 G4cout << "--> Type: " << (*vit).type << " Value: " << (*vit).value
0096 << G4endl;
0097 }
0098 if((*vit).type == "StepLimit")
0099 {
0100 G4UserLimits* fStepLimit = new G4UserLimits(atof((*vit).value));
0101 ((*iter).first)->SetUserLimits(fStepLimit);
0102 }
0103 }
0104 }
0105 G4VPhysicalVolume* worldPhysVol = parser->GetWorldVolume();
0106 if(ConfigurationManager::getInstance()->isDumpgdml())
0107 {
0108 std::ifstream ifile;
0109 ifile.open(ConfigurationManager::getInstance()->getGDMLFileName());
0110 if(ifile)
0111 {
0112 G4cout << "****************************************************"
0113 << G4endl;
0114 G4cout << ConfigurationManager::getInstance()->getGDMLFileName()
0115 << " already exists!!!" << G4endl;
0116 G4cout << "No new gdml dump created!!!" << G4endl;
0117 G4cout << "****************************************************"
0118 << G4endl;
0119 }
0120 else
0121 {
0122 G4cout << "Writing: "
0123 << ConfigurationManager::getInstance()->getGDMLFileName()
0124 << G4endl;
0125 parser->Write(ConfigurationManager::getInstance()->getGDMLFileName(),
0126 worldPhysVol);
0127 }
0128 }
0129 return worldPhysVol;
0130 }
0131 void DetectorConstruction::ConstructSDandField()
0132 {
0133 G4SDManager* SDman = G4SDManager::GetSDMpointer();
0134 const G4GDMLAuxMapType* auxmap = parser->GetAuxMap();
0135 if(verbose)
0136 {
0137 G4cout << "Found " << auxmap->size()
0138 << " volume(s) with auxiliary information." << G4endl << G4endl;
0139 }
0140 for(G4GDMLAuxMapType::const_iterator iter = auxmap->begin();
0141 iter != auxmap->end(); iter++)
0142 {
0143 if(verbose)
0144 {
0145 G4cout << "Volume " << ((*iter).first)->GetName()
0146 << " has the following list of auxiliary information: " << G4endl;
0147 }
0148 for(G4GDMLAuxListType::const_iterator vit = (*iter).second.begin();
0149 vit != (*iter).second.end(); vit++)
0150 {
0151 if(verbose)
0152 {
0153 G4cout << "--> Type: " << (*vit).type << " Value: " << (*vit).value
0154 << G4endl;
0155 }
0156 if((*vit).type == "SensDet")
0157 {
0158 if(verbose)
0159 {
0160 G4cout << "Found sensitive Detector: " << (*vit).value << G4endl;
0161 }
0162 if((*vit).value == "PhotonDetector")
0163 {
0164 G4String name = ((*iter).first)->GetName() + "_Photondetector";
0165 PhotonSD* aPhotonSD = new PhotonSD(name);
0166 SDman->AddNewDetector(aPhotonSD);
0167 ((*iter).first)->SetSensitiveDetector(aPhotonSD);
0168 if(verbose)
0169 {
0170 G4cout << "Attaching sensitive Detector: " << (*vit).value
0171 << " to Volume: " << ((*iter).first)->GetName() << G4endl;
0172 }
0173 }
0174 else if((*vit).value == "Target")
0175 {
0176 G4String name = ((*iter).first)->GetName() + "_Target";
0177 InteractionSD* aInteractionSD = new InteractionSD(name);
0178 SDman->AddNewDetector(aInteractionSD);
0179 ((*iter).first)->SetSensitiveDetector(aInteractionSD);
0180 if(verbose)
0181 {
0182 G4cout << "Attaching sensitive Detector: " << (*vit).value
0183 << " to Volume: " << ((*iter).first)->GetName() << G4endl;
0184 }
0185 }
0186 else if((*vit).value == "Tracker")
0187 {
0188 G4String name = ((*iter).first)->GetName() + "_Tracker";
0189 TrackerSD* aTrackerSD = new TrackerSD(name);
0190 SDman->AddNewDetector(aTrackerSD);
0191 ((*iter).first)->SetSensitiveDetector(aTrackerSD);
0192 if(verbose)
0193 {
0194 G4cout << "Attaching sensitive Detector: " << (*vit).value
0195 << " to Volume: " << ((*iter).first)->GetName() << G4endl;
0196 }
0197 }
0198 else if((*vit).value == "Msc")
0199 {
0200 G4String name = ((*iter).first)->GetName() + "_Msc";
0201 MscSD* aMscSD = new MscSD(name);
0202 SDman->AddNewDetector(aMscSD);
0203 ((*iter).first)->SetSensitiveDetector(aMscSD);
0204 if(verbose)
0205 {
0206 G4cout << "Attaching sensitive Detector: " << (*vit).value
0207 << " to Volume: " << ((*iter).first)->GetName() << G4endl;
0208 }
0209 }
0210 else if((*vit).value == "lArTPC")
0211 {
0212 G4String name = ((*iter).first)->GetName() + "_lArTPC";
0213 lArTPCSD* alArTPCSD = new lArTPCSD(name);
0214 SDman->AddNewDetector(alArTPCSD);
0215 ((*iter).first)->SetSensitiveDetector(alArTPCSD);
0216 if(verbose)
0217 {
0218 G4cout << "Attaching sensitive Detector: " << (*vit).value
0219 << " to Volume: " << ((*iter).first)->GetName() << G4endl;
0220 }
0221 }
0222 else if((*vit).value == "Radiator")
0223 {
0224 G4String name = ((*iter).first)->GetName() + "_Radiator";
0225 RadiatorSD* aRadiatorSD = new RadiatorSD(name);
0226 SDman->AddNewDetector(aRadiatorSD);
0227 ((*iter).first)->SetSensitiveDetector(aRadiatorSD);
0228 if(verbose)
0229 {
0230 G4cout << "Attaching sensitive Detector: " << (*vit).value
0231 << " to Volume: " << ((*iter).first)->GetName() << G4endl;
0232 }
0233 }
0234 else if((*vit).value == "Calorimeter")
0235 {
0236 G4String name = ((*iter).first)->GetName() + "_Calorimeter";
0237 CalorimeterSD* aCalorimeterSD = new CalorimeterSD(name);
0238 SDman->AddNewDetector(aCalorimeterSD);
0239 ((*iter).first)->SetSensitiveDetector(aCalorimeterSD);
0240 if(verbose)
0241 {
0242 G4cout << "Attaching sensitive Detector: " << (*vit).value
0243 << " to Volume: " << ((*iter).first)->GetName() << G4endl;
0244 }
0245 }
0246 else if((*vit).value == "DRCalorimeter")
0247 {
0248 G4String name = ((*iter).first)->GetName() + "_DRCalorimeter";
0249 DRCalorimeterSD* aDRCalorimeterSD = new DRCalorimeterSD(name);
0250 SDman->AddNewDetector(aDRCalorimeterSD);
0251 ((*iter).first)->SetSensitiveDetector(aDRCalorimeterSD);
0252 if(verbose)
0253 {
0254 G4cout << "Attaching sensitive Detector: " << (*vit).value
0255 << " to Volume: " << ((*iter).first)->GetName() << G4endl;
0256 }
0257 }
0258 }
0259 else if((*vit).type == "Solid")
0260 {
0261 if((*vit).value == "True")
0262 {
0263 G4VisAttributes* visibility = new G4VisAttributes();
0264 visibility->SetForceSolid(true);
0265 G4VisAttributes* visatt = new G4VisAttributes(
0266 ((*iter).first)->GetVisAttributes()->GetColour());
0267 visatt->SetVisibility(true);
0268 visatt->SetForceSolid(true);
0269 visatt->SetForceAuxEdgeVisible(true);
0270 ((*iter).first)->SetVisAttributes(visatt);
0271 }
0272 }
0273 }
0274 }
0275 }
0276 void DetectorConstruction::ReadGDML()
0277 {
0278 fReader = new ColorReader;
0279 parser = new G4GDMLParser(fReader);
0280 parser->Read(gdmlFile, false);
0281 G4VPhysicalVolume* World = parser->GetWorldVolume();
0282
0283
0284 G4LogicalVolume* pWorldLogical = World->GetLogicalVolume();
0285 pWorldLogical->SetVisAttributes(0);
0286 G4cout << World->GetTranslation() << G4endl << G4endl;
0287 if(verbose)
0288 {
0289 G4cout << "Found World: " << World->GetName() << G4endl;
0290 G4cout << "World LV: " << World->GetLogicalVolume()->GetName() << G4endl;
0291 }
0292 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
0293 if(verbose)
0294 {
0295 G4cout << "Found " << pLVStore->size() << " logical volumes." << G4endl
0296 << G4endl;
0297 }
0298 G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
0299 if(verbose)
0300 {
0301 G4cout << "Found " << pPVStore->size() << " physical volumes." << G4endl
0302 << G4endl;
0303 }
0304 }
0305
0306 void DetectorConstruction::UpdateGeometry()
0307 {
0308 G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
0309 }