Skip to content
Snippets Groups Projects
Geant4Converter.cpp 42.9 KiB
Newer Older
//==========================================================================
//  AIDA Detector description implementation for LCD
//--------------------------------------------------------------------------
Markus Frank's avatar
Markus Frank committed
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
// Author     : M.Frank
//
//==========================================================================
#include "DD4hep/LCDD.h"
#include "DD4hep/Plugins.h"
#include "DD4hep/Volumes.h"
#include "DD4hep/DD4hepUnits.h"
Markus Frank's avatar
Markus Frank committed
#include "DD4hep/objects/ObjectsInterna.h"
#include "DD4hep/objects/DetectorInterna.h"

#include "DDG4/Geant4Field.h"
#include "DDG4/Geant4Converter.h"
Markus Frank's avatar
Markus Frank committed
#include "DDG4/Geant4SensitiveDetector.h"
// ROOT includes
#include "TROOT.h"
#include "TColor.h"
#include "TGeoShape.h"
#include "TGeoCone.h"
#include "TGeoHype.h"
#include "TGeoPcon.h"
#include "TGeoPgon.h"
#include "TGeoSphere.h"
#include "TGeoTorus.h"
#include "TGeoTrd1.h"
#include "TGeoTrd2.h"
#include "TGeoTube.h"
#include "TGeoArb8.h"
#include "TGeoMatrix.h"
#include "TGeoBoolNode.h"
#include "TGeoCompositeShape.h"
Markus Frank's avatar
Markus Frank committed
#include "TGeoScaledShape.h"
#include "TClass.h"
#include "TMath.h"

// Geant4 include files
#include "G4VSensitiveDetector.hh"
#include "G4VisAttributes.hh"
#include "G4ProductionCuts.hh"
#include "G4VUserRegionInformation.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4Element.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4SDManager.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4Box.hh"
#include "G4Trd.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4Tubs.hh"
#include "G4Trap.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4Cons.hh"
#include "G4Hype.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4Torus.hh"
#include "G4Sphere.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4Polycone.hh"
#include "G4Polyhedra.hh"
#include "G4UnionSolid.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4Paraboloid.hh"
#include "G4Ellipsoid.hh"
#include "G4EllipticalTube.hh"
Markus Frank's avatar
Markus Frank committed
#include "G4SubtractionSolid.hh"
#include "G4IntersectionSolid.hh"
#include "G4Region.hh"
#include "G4UserLimits.hh"
#include "G4LogicalVolume.hh"
#include "G4Material.hh"
#include "G4Element.hh"
#include "G4Isotope.hh"
#include "G4Transform3D.hh"
#include "G4ThreeVector.hh"
#include "G4PVPlacement.hh"
#include "G4ElectroMagneticField.hh"
#include "G4FieldManager.hh"
#include "G4ReflectionFactory.hh"
#include "CLHEP/Units/SystemOfUnits.h"
#include <iostream>
#include <iomanip>
#include <sstream>

using namespace DD4hep::Simulation;
using namespace DD4hep::Simulation::Geant4GeometryMaps;
using namespace DD4hep::Geometry;
using namespace DD4hep;
Markus Frank's avatar
Markus Frank committed
using namespace CLHEP;
using namespace std;

#include "DDG4/Geant4AssemblyVolume.h"
#include "DD4hep/DetectorTools.h"
#include "G4RotationMatrix.hh"
#include "G4AffineTransform.hh"
#include "G4LogicalVolume.hh"
#include "G4VPhysicalVolume.hh"
#include "G4ReflectionFactory.hh"
void Geant4AssemblyVolume::imprint(Geant4GeometryInfo& info,
                                   const TGeoNode*   parent,
                                   Chain chain,
                                   Geant4AssemblyVolume* pAssembly,
                                   G4LogicalVolume*  pMotherLV,
                                   G4Transform3D&    transformation,
                                   G4int copyNumBase,
                                   G4bool surfCheck )
  TGeoVolume* vol = parent->GetVolume();
  static int level=0;
  ++level;
  unsigned int  numberOfDaughters;

  if( copyNumBase == 0 )
    {
      numberOfDaughters = pMotherLV->GetNoDaughters();
    }
  // We start from the first available index
  std::vector<G4AssemblyTriplet> triplets = pAssembly->fTriplets;
  //cout << " Assembly:" << DetectorTools::placementPath(chain) << endl;

  for( unsigned int i = 0; i < triplets.size(); i++ )  {
    const TGeoNode* node = pAssembly->m_entries[i];
    Chain new_chain = chain;
    new_chain.push_back(node);
    //cout << " Assembly: Entry: " << DetectorTools::placementPath(new_chain) << endl;
    G4Transform3D Ta( *(triplets[i].GetRotation()),
                      triplets[i].GetTranslation() );
    if ( triplets[i].IsReflection() )  { Ta = Ta * G4ReflectZ3D(); }

    G4Transform3D Tfinal = transformation * Ta;
    if ( triplets[i].GetVolume() )
      {
        // Generate the unique name for the next PV instance
        // The name has format:
        //
        // av_WWW_impr_XXX_YYY_ZZZ
        // where the fields mean:
        // WWW - assembly volume instance number
        // XXX - assembly volume imprint number
        // YYY - the name of a log. volume we want to make a placement of
        // ZZZ - the log. volume index inside the assembly volume
        //
        std::stringstream pvName;
        pvName << "av_"
               << GetAssemblyID()
               << "_impr_"
               << GetImprintsCount()
               << "_"
               << triplets[i].GetVolume()->GetName().c_str()
               << "_pv_"
               << i
               << std::ends;

        // Generate a new physical volume instance inside a mother
        // (as we allow 3D transformation use G4ReflectionFactory to
        //  take into account eventual reflection)
        //
        G4PhysicalVolumesPair pvPlaced
          = G4ReflectionFactory::Instance()->Place( Tfinal,
                                                    pvName.str().c_str(),
                                                    triplets[i].GetVolume(),
                                                    pMotherLV,
                                                    false,
                                                    numberOfDaughters + i,
                                                    surfCheck );

        // Register the physical volume created by us so we can delete it later
        //
        fPVStore.push_back( pvPlaced.first );
        info.g4VolumeImprints[vol].push_back(make_pair(new_chain,pvPlaced.first));
        cout << " Assembly:Parent:" << parent->GetName() << " " << node->GetName()
             << " " <<  (void*)node << " G4:" << pvName.str() << " Daughter:"
Loading
Loading full blame...