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

Generated on Wed Mar 5 17:25:22 2008 for BDSIM by  doxygen 1.5.3