Back to home page

EIC code displayed by LXR

 
 

    


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

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: CCalG4Ecal.cc
0028 // Description: CCalG4Ecal Factory class to construct the G4 geometry of the
0029 //              electromagnetic calorimeter
0030 ///////////////////////////////////////////////////////////////////////////////
0031 
0032 #include <cmath>
0033 
0034 #include "CCalG4Ecal.hh"
0035 
0036 #include "CCalMaterialFactory.hh"
0037 #include "CCalRotationMatrixFactory.hh"
0038 #include "CCalSensitiveDetectors.hh"
0039 
0040 #include "CCalutils.hh"
0041 
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4ThreeVector.hh"
0044 #include "G4Box.hh"
0045 #include "G4Trd.hh"
0046 
0047 #include "G4LogicalVolume.hh"
0048 #include "G4PVPlacement.hh"
0049 
0050 //#define debug
0051 //#define ddebug
0052 //#define pdebug
0053 //#define sdebug
0054 
0055 //Initialize static logical volumes
0056 G4LogicalVolume* CCalG4Ecal::crystalmatrixLog = 0;
0057 
0058 //Initialize static prefix name
0059 G4String CCalG4Ecal::idName = "CrystalMatrix";
0060 
0061 
0062 CCalG4Ecal::CCalG4Ecal(const G4String &name) : CCalEcal(name), CCalG4Able(name), type(module1) {}
0063 
0064 
0065 CCalG4Ecal::~CCalG4Ecal() {}
0066 
0067 
0068 G4VPhysicalVolume* CCalG4Ecal::constructIn( G4VPhysicalVolume* mother ) {
0069   G4cout << "==>> Constructing CCalG4Ecal..." << G4endl;
0070 
0071   // Construction of global volume as a Box
0072 
0073   if (!crystalmatrixLog) {
0074     crystalmatrixLog = constructGlobal();
0075   }
0076   CCalRotationMatrixFactory* rotfact = CCalRotationMatrixFactory::getInstance();
0077 
0078   G4double x, y, z;
0079   if (mother != 0) {
0080     x = getXpos()*mm;
0081     y = getYpos()*mm;
0082     z = getZpos()*mm;
0083   } else {
0084     x = y = z = 0;
0085   }
0086     
0087   int num;
0088   if (type == module2) {
0089     num = 2;
0090   } else {
0091     num = 1;
0092   }
0093 #ifdef pdebug
0094   G4String name("Null");
0095   if (mother != 0) name = mother->GetName();
0096   G4cout << crystalmatrixLog->GetName() << " Number " << num << " positioned in "
0097        << name << " at (" << x << ", " << y << ", " << z << ")";
0098 #endif
0099 
0100   G4RotationMatrix* cmrot = 0;
0101   if (mother != 0) {
0102     G4String rotstr = idName + num;
0103     cmrot  = rotfact->findMatrix(rotstr);
0104     if (!cmrot) {
0105 #ifdef ddebug
0106       G4cout << "Creating a new rotation: " << rotstr << tab 
0107            << getThetaX()*deg << "," << getPhiX()*deg << "," 
0108            << getThetaY()*deg << "," << getPhiY()*deg << "," 
0109            << getThetaZ()*deg << "," << getPhiZ()*deg << G4endl;
0110 #endif
0111       cmrot = rotfact->AddMatrix(rotstr, getThetaX()*deg, getPhiX()*deg, 
0112                                  getThetaY()*deg, getPhiY()*deg,
0113                                  getThetaZ()*deg, getPhiZ()*deg);
0114     } // if !cmrot
0115 #ifdef pdebug
0116     G4cout << " rotation by (" <<  getThetaX() << ", " << getPhiX() << ", " 
0117          << getThetaY() << "," << getPhiY() << ", "  << getThetaZ() << ", " 
0118          << getPhiZ() << ")" << G4endl;
0119 #endif
0120   } else {
0121 #ifdef pdebug
0122     G4cout << " without rotation..." << G4endl;
0123 #endif
0124   }
0125 
0126   G4PVPlacement* crystalmatrix;
0127   if (mother != 0) {
0128     crystalmatrix = new G4PVPlacement(cmrot, G4ThreeVector(x,y,z),
0129                                       crystalmatrixLog, idName,
0130                                       mother->GetLogicalVolume(), false, num);
0131   } else {
0132     crystalmatrix = new G4PVPlacement(cmrot, G4ThreeVector(x,y,z),
0133                                       idName, crystalmatrixLog,
0134                                       mother, false, num);
0135   }
0136   G4cout << "<<== End of CCalG4Ecal construction ..." << G4endl;
0137 
0138   return crystalmatrix;
0139 }
0140 
0141 
0142 G4LogicalVolume* CCalG4Ecal::constructGlobal() {
0143 
0144   //Pointers to the Materials and Rotation Matrix factory
0145   CCalMaterialFactory* matfact       = CCalMaterialFactory::getInstance();
0146   CCalRotationMatrixFactory* rotfact = CCalRotationMatrixFactory::getInstance();
0147   
0148   G4Material* matter = matfact->findMaterial(getGenMat());
0149   G4VSolid* solid = new G4Box (idName, 0.5*getWidBox()*mm, 0.5*getWidBox()*mm,
0150                                0.5*getLengBox()*mm);
0151 #ifdef debug
0152   G4cout << tab << idName << " Box made of " << getGenMat() << " of dimension " 
0153        << 0.5*getWidBox()*mm << ", " << 0.5*getWidBox()*mm << ", "
0154        << 0.5*getLengBox()*mm << G4endl;
0155 #endif
0156   G4LogicalVolume* glog = new G4LogicalVolume (solid, matter, idName);
0157   setVisType(CCalVisualisable::PseudoVolumes,glog);
0158 
0159   //Now the layers
0160   G4String name = idName + "Layer";
0161   matter = matfact->findMaterial(getLayMat());
0162   solid  = new G4Trd(name, getLayPar(0)*mm, getLayPar(1)*mm, getLayPar(2)*mm, 
0163                      getLayPar(3)*mm, getLayPar(4)*mm);
0164 #ifdef debug
0165   G4cout << tab << name << " Trd made of " << getLayMat() << " of dimension " 
0166        << getLayPar(0)*mm << ", " << getLayPar(1)*mm << ", " << getLayPar(2)*mm
0167        << ", " << getLayPar(3)*mm << ", " << getLayPar(4)*mm << G4endl;
0168 #endif
0169   G4LogicalVolume* laylog = new G4LogicalVolume (solid, matter, name);
0170   setVisType(CCalVisualisable::OtherServices,laylog);
0171 
0172   G4int i = 0;
0173   G4String rotstr;
0174   G4double xp, yp, zp, angle;
0175   G4double zshift = -0.5 * (getLengBox() - getCrystLength()) + getLengFront();
0176   G4RotationMatrix* rot = 0;
0177   for (i = 0; i < getLayNum(); i++) {
0178     angle  = 0.5 * getLayAngle() * (2*i + 1 - getLayNum());
0179     xp     = angle * (getLayPar(4) + getLayRadius()) * mm;
0180     zp     = (zshift + getLayPar(0)*std::abs(std::sin(angle))) * mm;
0181     rotstr = idName + "Layer" + i;
0182     rot    = rotfact->findMatrix(rotstr);
0183     if (!rot) {
0184 #ifdef ddebug
0185       G4cout << "Creating a new rotation: " << rotstr << tab 
0186            << (90.0*deg+angle) << "," << 0.0*deg << "," << 90.0*deg << "," 
0187            << 90.0*deg << "," << angle << "," << 0.0*deg << G4endl;
0188 #endif
0189       rot = rotfact->AddMatrix(rotstr, (90.0*deg+angle), 0.0*deg, 90.0*deg,
0190                                90.0*deg, angle, 0.0*deg);
0191     }
0192     new G4PVPlacement(rot, G4ThreeVector(xp,0.,zp), laylog, name, glog,
0193                       false, i+1);
0194 #ifdef pdebug
0195     G4cout << laylog->GetName() << " number " << i+1 << " positioned in " 
0196          << glog->GetName()  << " at (" << xp << ", 0," << zp
0197          << ") with rotation angle " << angle/deg << G4endl;
0198 #endif
0199   }
0200 
0201   //Now the crystals
0202   name   = idName + "Crystal";
0203   matter = matfact->findMaterial(getCrystMat());
0204   solid  = new G4Trd(name, getCrystPar(0)*mm, getCrystPar(1)*mm, 
0205                      getCrystPar(2)*mm, getCrystPar(3)*mm, getCrystPar(4)*mm);
0206 #ifdef debug
0207   G4cout << tab << name << " Trd made of " << getCrystMat() << " of dimension " 
0208        << getCrystPar(0)*mm << ", " << getCrystPar(1)*mm << ", " 
0209        << getCrystPar(2)*mm << ", " << getCrystPar(3)*mm << ", " 
0210        << getCrystPar(4)*mm << G4endl;
0211 #endif
0212 
0213   G4LogicalVolume* detLog = new G4LogicalVolume (solid, matter, name);
0214   setVisType(CCalVisualisable::Sensitive,detLog);
0215   sensitiveLogs.push_back(detLog);
0216   for (i = 0; i < getCrystNum(); i++) {
0217     angle  = 0.5 * getLayAngle() * (2*i + 1 - getCrystNum());
0218     yp     = angle * (getCrystPar(4) + getLayRadius()) * mm;
0219     zp     = (getCrystPar(0)*std::abs(std::sin(angle)) - getCrystTol()) * mm;
0220     rotstr = idName + "Crystal" + i;
0221     rot    = rotfact->findMatrix(rotstr);
0222     if (!rot) {
0223 #ifdef ddebug
0224       G4cout << "Creating a new rotation: " << rotstr << tab << 90.0*deg << ","
0225            << 0.0*deg << "," << (90.0*deg+angle) << "," << 0.0*deg << "," 
0226            << angle << "," << 90.0*deg << G4endl;
0227 #endif
0228       rot = rotfact->AddMatrix(rotstr, 90.0*deg, 0.0*deg, (90.0*deg+angle),
0229                                90.0*deg, angle, 90.0*deg);
0230     }
0231     new G4PVPlacement(rot, G4ThreeVector(0,yp,zp), detLog, name, laylog,
0232                       false, i+1);
0233 #ifdef pdebug
0234     G4cout << detLog->GetName() << " number " << i+1 << " positioned in " 
0235          << laylog->GetName()  << " at (0," << yp << "," << zp
0236          << ") with rotation angle " << angle/deg << G4endl;
0237 #endif
0238   }
0239 
0240   //Support boxes
0241   name   = idName + "Support";
0242   matter = matfact->findMaterial(getSuppMat());
0243   solid  = new G4Box (name, 0.5*getDxSupp()*mm, 0.5*getDySupp()*mm, 
0244                       0.5*getDzSupp()*mm);
0245 #ifdef debug
0246   G4cout << tab << name << " Box made of " << getSuppMat() << " of dimension " 
0247        << 0.5*getDxSupp()*mm << ", " << 0.5*getDySupp()*mm << ", "
0248        << 0.5*getDzSupp()*mm << G4endl;
0249 #endif
0250   G4LogicalVolume* slog = new G4LogicalVolume (solid, matter, name);
0251   setVisType(CCalVisualisable::Support,slog);
0252 
0253   zp   = (-0.5 * getLengBox() + getCrystLength() + getLengFront() +
0254           0.5 * getDzSupp() + getDistSupp()) * mm;
0255   for (i = 0; i < getCrystNum(); i++) {
0256     yp   = getLayPar(1) * (2*i + 1 - getCrystNum()) * mm;
0257     new G4PVPlacement(0, G4ThreeVector(0,yp,zp), slog, name, glog,
0258                       false, i+1);
0259 #ifdef pdebug
0260     G4cout << slog->GetName() << " number " << i+1 << " positioned in " 
0261          << glog->GetName()  << " at (0," << yp << "," << zp
0262          << ") with no rotation" << G4endl;
0263 #endif
0264   }
0265 
0266   return glog;
0267 }
0268 
0269 
0270 void CCalG4Ecal::constructSensitive() {
0271 #ifdef debug
0272   G4cout << "Now registering CrystalMatrix LogicalVolume's to SD's:" << G4endl;
0273 #endif
0274   if (sensitiveLogs.size()>0) {
0275     CCalSensitiveDetectors* sensDets = CCalSensitiveDetectors::getInstance();
0276     G4String SDname = idName;
0277     for(std::vector<ptrG4Log>::iterator iter=sensitiveLogs.begin(); 
0278                                    iter<sensitiveLogs.end(); iter++) {
0279       sensDets->registerVolume(SDname, (*iter));
0280 #ifdef sdebug
0281       G4cout << "Register volume " << (*iter)->GetName() << " for" << SDname 
0282            << G4endl;
0283 #endif
0284     }
0285   }
0286 }