Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:49:10

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 // This is the first version of Flash, a Geant4-based application
0027 //
0028 //
0029 //////////////////////////////////////////////////////////////////////////////////////////////
0030 
0031 #include "FlashMinibeamTemplate.hh"
0032 #include "G4Box.hh"
0033 #include "G4Colour.hh"
0034 #include "G4Cons.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4NistElementBuilder.hh"
0037 #include "G4NistManager.hh"
0038 #include "G4PVPlacement.hh"
0039 #include "G4RotationMatrix.hh"
0040 #include "G4RunManager.hh"
0041 #include "G4SubtractionSolid.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4MultiUnion.hh"
0044 #include "G4Tubs.hh"
0045 #include "G4VisAttributes.hh"
0046 #include "globals.hh"
0047 #include "G4UserLimits.hh"
0048 #include "G4Region.hh"
0049 #include <cmath>
0050 FlashMinibeamTemplate::FlashMinibeamTemplate(G4VPhysicalVolume *physicalTreatmentRoom, G4double x, G4double r)
0051   : hight(0.),motherPhys(physicalTreatmentRoom),X_center(x), y_center(0.),z_center(0.),d_between_holes(0.),hole_side(0.),radius(r),field_side(0)
0052        {
0053   ConstructCollimator();
0054 }
0055 
0056 FlashMinibeamTemplate::~FlashMinibeamTemplate() {}
0057 
0058 void FlashMinibeamTemplate::ConstructCollimator() {
0059   // Sets default geometry and materials
0060   SetMaterial();
0061   //ConstructColl_full(); //FULL
0062   // ConstructColl_template(); //GRID
0063   // Construct_hole();  //SINGLE HOLE
0064   ConstructColl_template_planar(); //PLANAR
0065 }
0066 
0067 void FlashMinibeamTemplate::SetMaterial() {
0068   //X_center = 0 *cm; 
0069   y_center = 0.*cm;
0070   z_center = 0.*cm;
0071   d_between_holes=2; //mm
0072   hole_side = 1; //mm
0073   maxStep = 0.1 * mm;
0074   field_side=10; //mm
0075   TemplateRegion = new G4Region("Template_region");
0076   fStepLimit = new G4UserLimits(maxStep);
0077   blue = new G4VisAttributes(G4Colour(0., 0., 1.));
0078   red = new G4VisAttributes(G4Colour(0., 1., 0.));
0079   blue->SetVisibility(true);
0080   red->SetVisibility(true);
0081   G4NistManager *man = G4NistManager::Instance();
0082   G4bool isotopes = false;
0083   TEFLON = man->FindOrBuildMaterial("G4_TEFLON", isotopes);
0084   TUNGSTEN = man->FindOrBuildMaterial("G4_W", isotopes);
0085 }
0086 
0087 void FlashMinibeamTemplate::ConstructColl_full() {
0088 G4double phi1 = 90. * deg;
0089   G4RotationMatrix rm1;
0090   rm1.rotateY(phi1);
0091   const G4double outerRad = radius;
0092   const G4double innRadius = 0. * mm;
0093     hight = 5 * cm;
0094   const G4double startAngle= 0. * deg;
0095   const G4double spanningAngle = 360. * deg;
0096   const G4double XPosition = X_center+hight;
0097   G4VSolid * solid =
0098       new G4Tubs("Solid_template", innRadius, outerRad, hight,
0099                  startAngle, spanningAngle);
0100   G4LogicalVolume *log = new G4LogicalVolume(
0101       solid, TUNGSTEN, "Log_template", 0, 0, 0);
0102    new G4PVPlacement(
0103       G4Transform3D(rm1, G4ThreeVector((XPosition), 0., 0.)), "physi_template",
0104       log, motherPhys, false, 0);
0105   log->SetVisAttributes(blue);
0106   log->SetRegion(TemplateRegion);
0107   TemplateRegion->AddRootLogicalVolume(log);
0108   log->SetUserLimits(fStepLimit);
0109 }
0110 
0111 void FlashMinibeamTemplate::ConstructColl_template() {  //GRID
0112 G4double phi2 = 90. * deg;
0113   G4RotationMatrix rm2;
0114   rm2.rotateY(phi2);
0115     hight = 0.25 * cm;
0116   const G4double XPosition = X_center+hight;
0117 G4Box *t1 = new G4Box("t1_", radius, radius, hight); 
0118 G4Box *Air_box = new G4Box("air_templ",hole_side/2,hole_side/2,hight+0.1*mm);
0119 G4MultiUnion* munion_solid = new G4MultiUnion("Boxes_Union");
0120 G4int n_holes = (G4int) round(field_side/(d_between_holes));
0121 G4RotationMatrix rotm = G4RotationMatrix();
0122 G4cout<< "NUMBER:"<<n_holes<<G4endl;
0123 for (G4int i= 0; i<n_holes;i++){
0124   for (G4int j=0;j<n_holes;j++){
0125     G4double xi = (-(n_holes -1)/2+ i)*(d_between_holes) ;
0126     G4double yi = ((n_holes -1)/2- j)*(d_between_holes) ;
0127 G4ThreeVector position = G4ThreeVector(xi*mm,yi*mm,0.);
0128 G4Transform3D tr = G4Transform3D(rotm,position);
0129 munion_solid->AddNode(*Air_box,tr);
0130 }
0131  }
0132 munion_solid->Voxelize();
0133 // Associate it to a logical volume as a normal solid
0134 //
0135 G4RotationMatrix rotm_t2 = G4RotationMatrix();
0136     rotm_t2.rotateX(0 * deg);
0137     G4ThreeVector zTrans(0, 0, 0);
0138     G4SubtractionSolid *hollowcover =
0139         new G4SubtractionSolid("template", t1, munion_solid, 0, zTrans);
0140 G4LogicalVolume *logic =
0141         new G4LogicalVolume(hollowcover, TUNGSTEN, "Log_template", 0, 0, 0);
0142  new G4PVPlacement(
0143       G4Transform3D(rm2, G4ThreeVector((XPosition), 0., 0.)), "cover1phys",
0144       logic, motherPhys, false, 0);
0145       logic->SetVisAttributes(blue);
0146       logic->SetRegion(TemplateRegion);
0147       TemplateRegion->AddRootLogicalVolume(logic);
0148       logic->SetUserLimits(fStepLimit);
0149 }
0150 void FlashMinibeamTemplate::Construct_hole(){ //Single hole
0151 G4double phi2 = 90. * deg;
0152   G4RotationMatrix rm2;
0153   rm2.rotateY(phi2);
0154   const G4double outerRad = radius;
0155   const G4double innRadius = 0. * mm;
0156     hight = 0.25 * cm;
0157   const G4double startAngle= 0. * deg;
0158   const G4double spanningAngle = 360. * deg;
0159   const G4double XPosition = X_center+hight;    
0160   G4VSolid *t1 = new G4Tubs("t1_", innRadius, outerRad, hight,
0161                  startAngle, spanningAngle);
0162 G4Box *Air_box = new G4Box("air_templ",0.5*cm,0.5*cm,hight+1*mm);
0163 G4RotationMatrix rotm_t2 = G4RotationMatrix();
0164     rotm_t2.rotateX(0 * deg);
0165     //G4ThreeVector zTrans(lato/2, -lato/2, 0);
0166     G4ThreeVector zTrans(0, 0, 0);
0167     G4SubtractionSolid *hollowcover =
0168         new G4SubtractionSolid("template", t1, Air_box, 0, zTrans);
0169 G4LogicalVolume *logic =
0170         new G4LogicalVolume(hollowcover, TUNGSTEN, "Log_template", 0, 0, 0);
0171     new G4PVPlacement(
0172       G4Transform3D(rm2, G4ThreeVector((XPosition), 0., 0.)), "cover1phys",
0173       logic, motherPhys, false, 0);
0174         logic->SetVisAttributes(blue);
0175   logic->SetRegion(TemplateRegion);
0176   TemplateRegion->AddRootLogicalVolume(logic);
0177   logic->SetUserLimits(fStepLimit);
0178 }
0179 
0180 void FlashMinibeamTemplate::ConstructColl_template_planar() {
0181 G4double phi2 = 90. * deg;
0182   G4RotationMatrix rm2;
0183   rm2.rotateY(phi2);
0184     hight = 0.25 * cm;
0185   const G4double XPosition = X_center+hight;
0186 G4Box *t1 = new G4Box("t1_", radius, radius, hight);
0187  G4Box *Air_box = new G4Box("air_templ",hole_side/2,field_side/2*mm,hight+0.1*mm);
0188 G4MultiUnion* munion_solid = new G4MultiUnion("Boxes_Union");
0189 G4int n_holes = (G4int) round(field_side/(d_between_holes))/2; //TOTAL HOLE NUMBERS=n_holes*2+1
0190 G4RotationMatrix rotm = G4RotationMatrix();
0191 G4ThreeVector position = G4ThreeVector(0.,0.,0.);
0192 G4Transform3D tr = G4Transform3D(rotm,position);
0193 munion_solid->AddNode(*Air_box,tr);
0194   for (G4int j=1;j<n_holes;j++){
0195 G4double xi = j*(d_between_holes) ;
0196 //G4double yi = ((n_holes -1)/2- j)*(d_between_holes) ;
0197  position = G4ThreeVector(xi*mm,0.,0.);
0198  tr = G4Transform3D(rotm,position);
0199 munion_solid->AddNode(*Air_box,tr);
0200  position = G4ThreeVector(-xi*mm,0.,0.);
0201  tr = G4Transform3D(rotm,position);
0202 munion_solid->AddNode(*Air_box,tr);
0203 }
0204 munion_solid->Voxelize();
0205 // Associate it to a logical volume as a normal solid
0206 //
0207 G4RotationMatrix rotm_t2 = G4RotationMatrix();
0208     rotm_t2.rotateX(0 * deg);
0209     //G4ThreeVector zTrans(lato/2, -lato/2, 0);
0210     G4ThreeVector zTrans(0, 0, 0);
0211     G4SubtractionSolid *hollowcover =
0212         new G4SubtractionSolid("template", t1, munion_solid, 0, zTrans);
0213 G4LogicalVolume *logic =
0214         new G4LogicalVolume(hollowcover, TUNGSTEN, "Log_template", 0, 0, 0);
0215     new G4PVPlacement(
0216       G4Transform3D(rm2, G4ThreeVector((XPosition), 0., 0.)), "cover1phys",
0217       logic, motherPhys, false, 0);
0218         logic->SetVisAttributes(blue);
0219   logic->SetRegion(TemplateRegion);
0220   TemplateRegion->AddRootLogicalVolume(logic);
0221   logic->SetUserLimits(fStepLimit);
0222 }
0223