Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:36

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file persistency/gdml/G01/load_gdml.cc
0027 /// \brief Main program of the persistency/gdml/G01 example
0028 //
0029 //
0030 //
0031 //
0032 // --------------------------------------------------------------
0033 //      GEANT 4 - load_gdml
0034 //
0035 // --------------------------------------------------------------
0036 
0037 #include "FTFP_BERT.hh"
0038 #include "G01ActionInitialization.hh"
0039 #include "G01DetectorConstruction.hh"
0040 #include "G01PrimaryGeneratorAction.hh"
0041 
0042 #include "G4GDMLParser.hh"
0043 #include "G4LogicalVolumeStore.hh"
0044 #include "G4RunManagerFactory.hh"
0045 #include "G4TransportationManager.hh"
0046 #include "G4Types.hh"
0047 #include "G4UIExecutive.hh"
0048 #include "G4UImanager.hh"
0049 #include "G4VisExecutive.hh"
0050 
0051 #include <vector>
0052 
0053 void print_aux(const G4GDMLAuxListType* auxInfoList, G4String prepend = "|")
0054 {
0055   for (std::vector<G4GDMLAuxStructType>::const_iterator iaux = auxInfoList->begin();
0056        iaux != auxInfoList->end(); iaux++)
0057   {
0058     G4String str = iaux->type;
0059     G4String val = iaux->value;
0060     G4String unit = iaux->unit;
0061 
0062     G4cout << prepend << str << " : " << val << " " << unit << G4endl;
0063 
0064     if (iaux->auxList) print_aux(iaux->auxList, prepend + "|");
0065   }
0066   return;
0067 }
0068 
0069 // --------------------------------------------------------------
0070 
0071 int main(int argc, char** argv)
0072 {
0073   G4cout << G4endl;
0074   G4cout << "Usage: load_gdml <intput_gdml_file:mandatory>"
0075          << " <output_gdml_file:optional>" << G4endl;
0076   G4cout << G4endl;
0077 
0078   if (argc < 2) {
0079     G4cout << "Error! Mandatory input file is not specified!" << G4endl;
0080     G4cout << G4endl;
0081     return -1;
0082   }
0083 
0084   G4GDMLParser parser;
0085 
0086   // Uncomment the following if wish to avoid names stripping
0087   // parser.SetStripFlag(false);
0088 
0089   // Uncomment the following and set a string with proper absolute path and
0090   // schema filename if wishing to use alternative schema for parsing validation
0091   // parser.SetImportSchema("");
0092 
0093   parser.SetOverlapCheck(true);
0094   parser.Read(argv[1]);
0095 
0096   if (argc > 4) {
0097     G4cout << "Error! Too many arguments!" << G4endl;
0098     G4cout << G4endl;
0099     return -1;
0100   }
0101 
0102   auto* runManager = G4RunManagerFactory::CreateRunManager();
0103 
0104   runManager->SetUserInitialization(new G01DetectorConstruction(parser.GetWorldVolume()));
0105   runManager->SetUserInitialization(new FTFP_BERT);
0106   runManager->SetUserInitialization(new G01ActionInitialization());
0107 
0108   runManager->Initialize();
0109 
0110   // Initialize visualization
0111   G4VisManager* visManager = new G4VisExecutive;
0112   visManager->Initialize();
0113 
0114   // Get the pointer to the User Interface manager
0115   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0116 
0117   ///////////////////////////////////////////////////////////////////////
0118   //
0119   // Example how to retrieve Auxiliary Information
0120   //
0121 
0122   G4cout << std::endl;
0123 
0124   const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
0125   std::vector<G4LogicalVolume*>::const_iterator lvciter;
0126   for (lvciter = lvs->begin(); lvciter != lvs->end(); lvciter++) {
0127     G4GDMLAuxListType auxInfo = parser.GetVolumeAuxiliaryInformation(*lvciter);
0128 
0129     if (auxInfo.size() > 0)
0130       G4cout << "Auxiliary Information is found for Logical Volume :  " << (*lvciter)->GetName()
0131              << G4endl;
0132 
0133     print_aux(&auxInfo);
0134   }
0135 
0136   // now the 'global' auxiliary info
0137   G4cout << std::endl;
0138   G4cout << "Global auxiliary info:" << std::endl;
0139   G4cout << std::endl;
0140 
0141   print_aux(parser.GetAuxList());
0142 
0143   G4cout << std::endl;
0144 
0145   //
0146   // End of Auxiliary Information block
0147   //
0148   ////////////////////////////////////////////////////////////////////////
0149 
0150   runManager->BeamOn(0);
0151 
0152   // example of writing out
0153 
0154   if (argc >= 3) {
0155     /*
0156          G4GDMLAuxStructType mysubaux = {"mysubtype", "mysubvalue", "mysubunit", 0};
0157          G4GDMLAuxListType* myauxlist = new G4GDMLAuxListType();
0158          myauxlist->push_back(mysubaux);
0159 
0160          G4GDMLAuxStructType myaux = {"mytype", "myvalue", "myunit", myauxlist};
0161          parser.AddAuxiliary(myaux);
0162 
0163 
0164          // example of setting auxiliary info for world volume
0165          // (can be set for any volume)
0166 
0167          G4GDMLAuxStructType mylocalaux = {"sometype", "somevalue", "someunit", 0};
0168 
0169          parser.AddVolumeAuxiliary(mylocalaux,
0170            G4TransportationManager::GetTransportationManager()
0171            ->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume());
0172     */
0173 
0174     parser.SetRegionExport(true);
0175     //     parser.SetEnergyCutsExport(true);
0176     //     parser.SetOutputFileOverwrite(true);
0177     parser.Write(argv[2], G4TransportationManager::GetTransportationManager()
0178                             ->GetNavigatorForTracking()
0179                             ->GetWorldVolume()
0180                             ->GetLogicalVolume());
0181   }
0182 
0183   if (argc == 4)  // batch mode
0184   {
0185     G4String command = "/control/execute ";
0186     G4String fileName = argv[3];
0187     UImanager->ApplyCommand(command + fileName);
0188   }
0189   else  // interactive mode
0190   {
0191     G4UIExecutive* ui = new G4UIExecutive(argc, argv);
0192     UImanager->ApplyCommand("/control/execute vis.mac");
0193     ui->SessionStart();
0194     delete ui;
0195   }
0196 
0197   delete visManager;
0198   delete runManager;
0199 
0200   return 0;
0201 }