src/BDSLWCalorimeter.cc

00001 /* BDSIM code for LW Calorimeter.    Version 1.0
00002    Author: John Carter, Royal Holloway, Univ. of London.
00003    Last modified 26.7.2004
00004    Copyright (c) 2004 by J.C.Carter.  ALL RIGHTS RESERVED. 
00005 */
00006 
00007 #include "BDSGlobalConstants.hh" 
00008 #include "BDSLWCalorimeter.hh"
00009 #include "BDSMaterials.hh"
00010 #include "G4Box.hh"
00011 #include "G4Tubs.hh"
00012 #include "G4VisAttributes.hh"
00013 #include "G4LogicalVolume.hh"
00014 #include "G4VPhysicalVolume.hh"
00015 #include "G4PVPlacement.hh"               
00016 #include "G4UserLimits.hh"
00017 
00018 #include "BDSAcceleratorComponent.hh"
00019 
00020 #include "BDSLWCalorimeterSD.hh"
00021 #include "G4SDManager.hh"
00022 
00023 
00024 //#include"MagFieldFunction.hh"
00025 #include <map>
00026 
00027 
00028 //============================================================
00029 
00030 typedef std::map<G4String,int> LogVolCountMap;
00031 extern LogVolCountMap* LogVolCount;
00032 
00033 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00034 extern LogVolMap* LogVol;
00035 
00036 extern G4RotationMatrix* RotY90;
00037 //============================================================
00038 
00039 BDSLWCalorimeter::BDSLWCalorimeter (G4String& aName,G4double aLength,
00040                                     G4double aBpRad, G4String aTunnelMaterial):
00041   BDSAcceleratorComponent(
00042                          aName,
00043                          aLength,aBpRad,0,0,
00044                          SetVisAttributes(),aTunnelMaterial),
00045   itsBPFieldMgr(NULL),
00046   itsVisAttributes(NULL)
00047 {
00048   LWCalorimeterLogicalVolume();
00049   BuildCal(aLength);
00050   BuildBeampipe(aLength);
00051 
00052   //G4int nLWCalorimeters=(*LogVolCount)[itsName];
00053   //BDSRoot->SetLWCalorimeterNumber(nLWCalorimeters);
00054 
00055 }
00056 
00057 
00058 void BDSLWCalorimeter::LWCalorimeterLogicalVolume()
00059 {
00060   if(!(*LogVolCount)[itsName])
00061     {
00062 
00063       G4double SampTransSize;
00064       SampTransSize=2.*BDSGlobalConstants::Instance()->GetTunnelRadius();
00065 
00066       itsMarkerLogicalVolume=
00067         new G4LogicalVolume(
00068                             new G4Box(itsName+"_solid",
00069                                       SampTransSize,
00070                                       SampTransSize,
00071                                       itsLength/2),
00072                             BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->GetVacuumMaterial()),
00073                             itsName);
00074 
00075       (*LogVolCount)[itsName]=1;
00076       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00077 #ifndef NOUSERLIMITS
00078       itsOuterUserLimits =new G4UserLimits();
00079       itsOuterUserLimits->SetMaxAllowedStep(itsLength);
00080       itsOuterUserLimits->SetUserMaxTime(BDSGlobalConstants::Instance()->GetMaxTime());
00081       itsMarkerLogicalVolume->SetUserLimits(itsOuterUserLimits);
00082 #endif
00083 
00084     }
00085   else
00086     {
00087       (*LogVolCount)[itsName]++;
00088       itsMarkerLogicalVolume=(*LogVol)[itsName];
00089     }
00090 }
00091 
00092 void BDSLWCalorimeter::BuildCal(G4double aLength)
00093 {
00094   // build the Calorimeter
00095    
00096   itsLWCal=new G4Box(itsName+"_LWCal",
00097                      BDSGlobalConstants::Instance()->GetLWCalWidth()/2,
00098                      BDSGlobalConstants::Instance()->GetLWCalWidth()/2,
00099                      aLength/2);
00100   itsLWCalLogicalVolume=new G4LogicalVolume(itsLWCal,
00101                                             BDSMaterials::Instance()->GetMaterial("LeadTungstate"),
00102                                             itsName+"_cal_logical");
00103   G4RotationMatrix* Rot=NULL;
00104   if(itsAngle!=0)Rot=RotY90;
00105  
00106   itsPhysiLWCal = new G4PVPlacement(
00107                     Rot,                     // rotation
00108                     G4ThreeVector(BDSGlobalConstants::Instance()->GetLWCalOffset(),0.,0.),
00109                     itsLWCalLogicalVolume,   // its logical volume
00110                     itsName+"_cal",          // its name
00111                     itsMarkerLogicalVolume,  // its mother  volume
00112                     false,                   // no boolean operation
00113                     0, BDSGlobalConstants::Instance()->GetCheckOverlaps()); // copy number
00114   
00115   // Sensitive Detector:
00116   G4SDManager* SDMan = G4SDManager::GetSDMpointer();
00117  
00118   BDSLWCalorimeterSD* SensDet=new BDSLWCalorimeterSD(itsName);
00119   SDMan->AddNewDetector(SensDet);
00120   
00121   itsLWCalLogicalVolume->SetSensitiveDetector(SensDet);    
00122 }
00123 void BDSLWCalorimeter::BuildBeampipe(G4double aLength)
00124 {
00125   // build beampipe
00126   itsBPTube=new G4Tubs(itsName+"_tube",
00127                        0.,itsBpRadius,
00128                        aLength/2,
00129                        0,twopi*radian);
00130   
00131   itsInnerBPTube=new G4Tubs(itsName+"_InnerTube",
00132                             0.,
00133                             itsBpRadius-BDSGlobalConstants::Instance()->GetBeampipeThickness(),
00134                             aLength/2,
00135                             0,twopi*radian);
00136   itsBeampipeLogicalVolume=     
00137     new G4LogicalVolume(itsBPTube,
00138                         //                      BDSMaterials::Instance()->("Iron"),
00139                         BDSMaterials::Instance()->GetMaterial("Aluminium"),
00140                         itsName+"_bmp_logical");
00141   
00142   itsInnerBPLogicalVolume=      
00143     new G4LogicalVolume(itsInnerBPTube,
00144                         BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->GetVacuumMaterial()),
00145                         itsName+"_bmp_Inner_log");
00146   
00147   itsPhysiInner = new G4PVPlacement(
00148                       (G4RotationMatrix*)0,     // rotation
00149                       (G4ThreeVector)0,         // at (0,0,0)
00150                       itsInnerBPLogicalVolume,  // its logical volume
00151                       itsName+"_InnerBmp",      // its name
00152                       itsBeampipeLogicalVolume, // its mother  volume
00153                       false,                   // no boolean operation
00154                                   0, BDSGlobalConstants::Instance()->GetCheckOverlaps());                      // copy number
00155   
00156   
00157    G4RotationMatrix* Rot=NULL;
00158    if(itsAngle!=0)Rot=RotY90;
00159   
00160    itsPhysiComp = new G4PVPlacement(
00161                        Rot,                       // rotation
00162                        (G4ThreeVector)0,          // at (0,0,0)
00163                        itsBeampipeLogicalVolume,  // its logical volume
00164                        itsName+"_bmp",            // its name
00165                        itsMarkerLogicalVolume,    // its mother  volume
00166                        false,                     // no boolean operation
00167                        0, BDSGlobalConstants::Instance()->GetCheckOverlaps()); // copy number
00168 #ifndef NOUSERLIMITS
00169    itsBeampipeUserLimits =
00170      new G4UserLimits("beampipe cuts",DBL_MAX,DBL_MAX,DBL_MAX,
00171                       BDSGlobalConstants::Instance()->GetThresholdCutCharged());
00172    
00173    itsInnerBeampipeUserLimits =
00174      new G4UserLimits("inner beamipe cuts",DBL_MAX,DBL_MAX,DBL_MAX,
00175                       BDSGlobalConstants::Instance()->GetThresholdCutCharged());
00176    
00177    itsBeampipeUserLimits->SetMaxAllowedStep(itsLength);
00178    itsBeampipeUserLimits->SetUserMaxTime(BDSGlobalConstants::Instance()->GetMaxTime());
00179    
00180    itsBeampipeLogicalVolume->SetUserLimits(itsBeampipeUserLimits);
00181    
00182    itsInnerBeampipeUserLimits->SetMaxAllowedStep(itsLength);
00183    itsInnerBeampipeUserLimits->SetUserMaxTime(BDSGlobalConstants::Instance()->GetMaxTime());
00184    
00185    itsInnerBPLogicalVolume->SetUserLimits(itsInnerBeampipeUserLimits);
00186 #endif
00187    itsInnerBPLogicalVolume->SetFieldManager(itsBPFieldMgr,false) ;
00188    
00189    // now protect the fields inside the marker volume by giving the
00190    // marker a null magnetic field (otherwise G4VPlacement can
00191    // over-ride the already-created fields, by calling 
00192    // G4LogicalVolume::AddDaughter, which calls 
00193    // pDaughterLogical->SetFieldManager(fFieldManager, true) - the
00194    // latter 'true' over-writes all the other fields
00195    
00196    itsMarkerLogicalVolume->
00197      SetFieldManager(BDSGlobalConstants::Instance()->GetZeroFieldManager(),false);
00198   
00199 }
00200 
00201 G4VisAttributes* BDSLWCalorimeter::SetVisAttributes()
00202 {
00203   itsVisAttributes=new G4VisAttributes(G4Colour(1,0.5,0.5));
00204   return itsVisAttributes;
00205 }
00206 
00207 BDSLWCalorimeter::~BDSLWCalorimeter()
00208 {
00209   delete itsVisAttributes;
00210 }

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7