Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:19:38

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 ///////////////////////////////////////////////////////////////////////////////
0027 // File: CCalG4Able.cc
0028 // Description: CCalG4Able is the base class of a Geant4 geometry factory
0029 ///////////////////////////////////////////////////////////////////////////////
0030 //Comment/Uncomment next line to unset/set debug information printing
0031 //#define debug
0032 //#define ddebug
0033 
0034 #ifdef ddebug
0035   #include "G4Timer.hh"
0036 #endif
0037 #ifdef debug
0038   #include "CCalutils.hh"
0039 #endif
0040 
0041 #include "CCalGeometryConfiguration.hh"
0042 #include "CCalG4Able.hh"
0043 #include "CCalSensitiveConfiguration.hh"
0044 
0045 #include "G4Color.hh"
0046 #include "G4VisAttributes.hh"
0047 
0048 
0049 CCalG4Able::CCalG4Able( G4String name ) :
0050   detPhysicalVolume(0), g4ableName(name), sensitivity(false),
0051   visProperties(CCalSensitiveConfiguration::getInstance()->getFileName(name)+".vis") {
0052   //Initialize g4VisAtt pointers
0053   for (G4int i=0; i<CCalVisualisable::TotalVisTypes; ++i) g4VisAtt[i]=0;
0054   sensitivity = CCalSensitiveConfiguration::getInstance()->getSensitiveFlag(name);
0055 }
0056 
0057 
0058 CCalG4Able::~CCalG4Able() {
0059   if (detPhysicalVolume) delete[] detPhysicalVolume;
0060 }
0061 
0062 
0063 G4VPhysicalVolume* CCalG4Able::PhysicalVolume( G4VPhysicalVolume* pv ) {
0064   //If detPhysicalVolume is not null the volume has already been built
0065   //so return it. In other case, construct it and its daughters.
0066 #ifdef ddebug
0067   G4Timer timer;
0068   timer.Start();
0069 #endif
0070   if (CCalGeometryConfiguration::getInstance()->getConstructFlag(G4Name())!=0){
0071     if (!detPhysicalVolume) {
0072       detPhysicalVolume = constructIn(pv);
0073       for (unsigned int i = 0; i < theG4DetectorsInside.size(); i++) {
0074         theG4DetectorsInside[i]->PhysicalVolume(detPhysicalVolume);
0075       }
0076     }
0077   }
0078   else {
0079     G4cout << "NOTE: You decided to skip the construction of " << G4Name() << G4endl;
0080   }
0081 #ifdef ddebug
0082   timer.Stop();
0083   G4cout << tab << "CCalG4Able::PhysicalVolume(...) --> time spent: " << timer << G4endl;
0084 #endif
0085   return detPhysicalVolume;
0086 }
0087 
0088 
0089 void CCalG4Able::sensitiveHandling() {
0090   if ( CCalGeometryConfiguration::getInstance()->getConstructFlag( G4Name() ) != 0  &&
0091        sensitivity ) {
0092     for (unsigned int i = 0; i < theG4DetectorsInside.size(); i++) {
0093 #ifdef debug
0094       G4cout << "==> Making " << detPhysicalVolume->GetName() << " sensitive..." << G4endl;
0095 #endif      
0096       theG4DetectorsInside[i]->constructSensitive();
0097     }
0098   }
0099 }
0100 
0101 
0102 void CCalG4Able::AddCCalG4Able( CCalG4Able* det ) {
0103   theG4DetectorsInside.push_back(det);
0104 }
0105 
0106 
0107 void CCalG4Able::setVisType( CCalVisualisable::visType vt, G4LogicalVolume* log ) {
0108   if (!g4VisAtt[vt]) {
0109 #ifdef debug
0110     G4cout << "CCalG4Able::setVisType: Constructing G4VisAttributes for " 
0111            << log->GetName() << " as " << vt << G4endl;
0112 #endif
0113     G4Color col( visProperties.colorRed(vt), visProperties.colorGreen(vt),
0114          visProperties.colorBlue(vt) );
0115     G4bool wf      = visProperties.isWireFrame(vt);
0116     G4bool visible = visProperties.isVisible(vt);
0117 #ifdef debug
0118     G4cout << "Color: " << visProperties.colorRed(vt)   << ", " << visProperties.colorGreen(vt)
0119        << ", " << visProperties.colorBlue(vt)  << tab << "Wireframe: " << wf << tab
0120            << "Visible: " << visible << G4endl;
0121 #endif
0122     g4VisAtt[vt] = new G4VisAttributes(col);
0123     g4VisAtt[vt]->SetForceWireframe(wf);
0124     g4VisAtt[vt]->SetVisibility(visible);
0125   }
0126   log->SetVisAttributes(g4VisAtt[vt]);
0127 }
0128 
0129 
0130 G4bool CCalG4Able::operator==( const CCalG4Able& right ) const {
0131   return detPhysicalVolume==right.detPhysicalVolume;
0132 }
0133 
0134 
0135 std::ostream& operator<<( std::ostream& os, const CCalG4Able& det ) {
0136   if (det.detPhysicalVolume) os << "Physical volume already constructed." << G4endl;
0137   else                       os << "Physical volume still not constructed." << G4endl;
0138   if (det.isSensitive()) os << "and it is Sensitive" << G4endl;
0139   else                   os << "and it is not Sensitive" << G4endl;  
0140   return os;
0141 }