Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 ////////////////////////////////////////////// 26 /////////////////////////////////////////////////////////////////////////////// 27 // File: CCalG4Ecal.cc 27 // File: CCalG4Ecal.cc 28 // Description: CCalG4Ecal Factory class to co 28 // Description: CCalG4Ecal Factory class to construct the G4 geometry of the 29 // electromagnetic calorimeter 29 // electromagnetic calorimeter 30 ////////////////////////////////////////////// 30 /////////////////////////////////////////////////////////////////////////////// 31 31 32 #include <cmath> << 33 << 34 #include "CCalG4Ecal.hh" 32 #include "CCalG4Ecal.hh" 35 33 36 #include "CCalMaterialFactory.hh" 34 #include "CCalMaterialFactory.hh" 37 #include "CCalRotationMatrixFactory.hh" 35 #include "CCalRotationMatrixFactory.hh" 38 #include "CCalSensitiveDetectors.hh" 36 #include "CCalSensitiveDetectors.hh" 39 37 40 #include "CCalutils.hh" 38 #include "CCalutils.hh" >> 39 #include <cmath> 41 40 42 #include "G4SystemOfUnits.hh" << 43 #include "G4ThreeVector.hh" 41 #include "G4ThreeVector.hh" 44 #include "G4Box.hh" 42 #include "G4Box.hh" 45 #include "G4Trd.hh" 43 #include "G4Trd.hh" 46 44 47 #include "G4LogicalVolume.hh" 45 #include "G4LogicalVolume.hh" 48 #include "G4PVPlacement.hh" 46 #include "G4PVPlacement.hh" 49 47 50 //#define debug 48 //#define debug 51 //#define ddebug 49 //#define ddebug 52 //#define pdebug 50 //#define pdebug 53 //#define sdebug 51 //#define sdebug 54 52 55 //Initialize static logical volumes 53 //Initialize static logical volumes 56 G4LogicalVolume* CCalG4Ecal::crystalmatrixLog 54 G4LogicalVolume* CCalG4Ecal::crystalmatrixLog = 0; 57 55 58 //Initialize static prefix name 56 //Initialize static prefix name 59 G4String CCalG4Ecal::idName = "CrystalMatrix"; 57 G4String CCalG4Ecal::idName = "CrystalMatrix"; 60 58 >> 59 //////////////////////////////////////////////////////////////////// >> 60 // CCalG4Ecal constructor & destructor... >> 61 //////////////////////////////////////////////////////////////////// 61 62 62 CCalG4Ecal::CCalG4Ecal(const G4String &name) : << 63 CCalG4Ecal::CCalG4Ecal(const G4String &name): 63 << 64 CCalEcal(name), CCalG4Able(name), type(module1) {} 64 65 65 CCalG4Ecal::~CCalG4Ecal() {} 66 CCalG4Ecal::~CCalG4Ecal() {} 66 67 >> 68 //////////////////////////////////////////////////////////////////// >> 69 // CCalG4Ecal methods... >> 70 //////////////////////////////////////////////////////////////////// 67 71 68 G4VPhysicalVolume* CCalG4Ecal::constructIn( G4 << 72 G4VPhysicalVolume* CCalG4Ecal::constructIn(G4VPhysicalVolume* mother) { 69 G4cout << "==>> Constructing CCalG4Ecal..." 73 G4cout << "==>> Constructing CCalG4Ecal..." << G4endl; 70 74 >> 75 /////////////////////////////////////////////////////////////// 71 // Construction of global volume as a Box 76 // Construction of global volume as a Box 72 77 73 if (!crystalmatrixLog) { 78 if (!crystalmatrixLog) { 74 crystalmatrixLog = constructGlobal(); 79 crystalmatrixLog = constructGlobal(); 75 } 80 } 76 CCalRotationMatrixFactory* rotfact = CCalRot 81 CCalRotationMatrixFactory* rotfact = CCalRotationMatrixFactory::getInstance(); 77 82 78 G4double x, y, z; 83 G4double x, y, z; 79 if (mother != 0) { 84 if (mother != 0) { 80 x = getXpos()*mm; 85 x = getXpos()*mm; 81 y = getYpos()*mm; 86 y = getYpos()*mm; 82 z = getZpos()*mm; 87 z = getZpos()*mm; 83 } else { 88 } else { 84 x = y = z = 0; 89 x = y = z = 0; 85 } 90 } 86 91 87 int num; 92 int num; 88 if (type == module2) { 93 if (type == module2) { 89 num = 2; 94 num = 2; 90 } else { 95 } else { 91 num = 1; 96 num = 1; 92 } 97 } 93 #ifdef pdebug 98 #ifdef pdebug 94 G4String name("Null"); 99 G4String name("Null"); 95 if (mother != 0) name = mother->GetName(); 100 if (mother != 0) name = mother->GetName(); 96 G4cout << crystalmatrixLog->GetName() << " N 101 G4cout << crystalmatrixLog->GetName() << " Number " << num << " positioned in " 97 << name << " at (" << x << ", " << y << 102 << name << " at (" << x << ", " << y << ", " << z << ")"; 98 #endif 103 #endif 99 104 100 G4RotationMatrix* cmrot = 0; 105 G4RotationMatrix* cmrot = 0; 101 if (mother != 0) { 106 if (mother != 0) { 102 G4String rotstr = idName + num; 107 G4String rotstr = idName + num; 103 cmrot = rotfact->findMatrix(rotstr); 108 cmrot = rotfact->findMatrix(rotstr); 104 if (!cmrot) { 109 if (!cmrot) { 105 #ifdef ddebug 110 #ifdef ddebug 106 G4cout << "Creating a new rotation: " << 111 G4cout << "Creating a new rotation: " << rotstr << tab 107 << getThetaX()*deg << "," << getPhi << 112 << getThetaX()*deg << "," << getPhiX()*deg << "," 108 << getThetaY()*deg << "," << getPhi << 113 << getThetaY()*deg << "," << getPhiY()*deg << "," 109 << getThetaZ()*deg << "," << getPhi << 114 << getThetaZ()*deg << "," << getPhiZ()*deg << G4endl; 110 #endif 115 #endif 111 cmrot = rotfact->AddMatrix(rotstr, getTh 116 cmrot = rotfact->AddMatrix(rotstr, getThetaX()*deg, getPhiX()*deg, 112 getThetaY()*d << 117 getThetaY()*deg, getPhiY()*deg, 113 getThetaZ()*d << 118 getThetaZ()*deg, getPhiZ()*deg); 114 } // if !cmrot 119 } // if !cmrot 115 #ifdef pdebug 120 #ifdef pdebug 116 G4cout << " rotation by (" << getThetaX() 121 G4cout << " rotation by (" << getThetaX() << ", " << getPhiX() << ", " 117 << getThetaY() << "," << getPhiY() << << 122 << getThetaY() << "," << getPhiY() << ", " << getThetaZ() << ", " 118 << getPhiZ() << ")" << G4endl; << 123 << getPhiZ() << ")" << G4endl; 119 #endif 124 #endif 120 } else { 125 } else { 121 #ifdef pdebug 126 #ifdef pdebug 122 G4cout << " without rotation..." << G4endl 127 G4cout << " without rotation..." << G4endl; 123 #endif 128 #endif 124 } 129 } 125 130 126 G4PVPlacement* crystalmatrix; 131 G4PVPlacement* crystalmatrix; 127 if (mother != 0) { 132 if (mother != 0) { 128 crystalmatrix = new G4PVPlacement(cmrot, G 133 crystalmatrix = new G4PVPlacement(cmrot, G4ThreeVector(x,y,z), 129 crystalm << 134 crystalmatrixLog, idName, 130 mother-> << 135 mother->GetLogicalVolume(), false, num); 131 } else { 136 } else { 132 crystalmatrix = new G4PVPlacement(cmrot, G 137 crystalmatrix = new G4PVPlacement(cmrot, G4ThreeVector(x,y,z), 133 idName, << 138 idName, crystalmatrixLog, 134 mother, << 139 mother, false, num); 135 } 140 } 136 G4cout << "<<== End of CCalG4Ecal constructi 141 G4cout << "<<== End of CCalG4Ecal construction ..." << G4endl; 137 142 138 return crystalmatrix; 143 return crystalmatrix; 139 } 144 } 140 145 141 146 142 G4LogicalVolume* CCalG4Ecal::constructGlobal() 147 G4LogicalVolume* CCalG4Ecal::constructGlobal() { 143 148 144 //Pointers to the Materials and Rotation Mat 149 //Pointers to the Materials and Rotation Matrix factory 145 CCalMaterialFactory* matfact = CCalMat 150 CCalMaterialFactory* matfact = CCalMaterialFactory::getInstance(); 146 CCalRotationMatrixFactory* rotfact = CCalRot 151 CCalRotationMatrixFactory* rotfact = CCalRotationMatrixFactory::getInstance(); 147 152 148 G4Material* matter = matfact->findMaterial(g 153 G4Material* matter = matfact->findMaterial(getGenMat()); 149 G4VSolid* solid = new G4Box (idName, 0.5*get 154 G4VSolid* solid = new G4Box (idName, 0.5*getWidBox()*mm, 0.5*getWidBox()*mm, 150 0.5*getLengBox( << 155 0.5*getLengBox()*mm); 151 #ifdef debug 156 #ifdef debug 152 G4cout << tab << idName << " Box made of " < 157 G4cout << tab << idName << " Box made of " << getGenMat() << " of dimension " 153 << 0.5*getWidBox()*mm << ", " << 0.5*ge 158 << 0.5*getWidBox()*mm << ", " << 0.5*getWidBox()*mm << ", " 154 << 0.5*getLengBox()*mm << G4endl; 159 << 0.5*getLengBox()*mm << G4endl; 155 #endif 160 #endif 156 G4LogicalVolume* glog = new G4LogicalVolume 161 G4LogicalVolume* glog = new G4LogicalVolume (solid, matter, idName); 157 setVisType(CCalVisualisable::PseudoVolumes,g 162 setVisType(CCalVisualisable::PseudoVolumes,glog); 158 163 159 //Now the layers 164 //Now the layers 160 G4String name = idName + "Layer"; 165 G4String name = idName + "Layer"; 161 matter = matfact->findMaterial(getLayMat()); 166 matter = matfact->findMaterial(getLayMat()); 162 solid = new G4Trd(name, getLayPar(0)*mm, ge 167 solid = new G4Trd(name, getLayPar(0)*mm, getLayPar(1)*mm, getLayPar(2)*mm, 163 getLayPar(3)*mm, getLayPa << 168 getLayPar(3)*mm, getLayPar(4)*mm); 164 #ifdef debug 169 #ifdef debug 165 G4cout << tab << name << " Trd made of " << 170 G4cout << tab << name << " Trd made of " << getLayMat() << " of dimension " 166 << getLayPar(0)*mm << ", " << getLayPar 171 << getLayPar(0)*mm << ", " << getLayPar(1)*mm << ", " << getLayPar(2)*mm 167 << ", " << getLayPar(3)*mm << ", " << g 172 << ", " << getLayPar(3)*mm << ", " << getLayPar(4)*mm << G4endl; 168 #endif 173 #endif 169 G4LogicalVolume* laylog = new G4LogicalVolum 174 G4LogicalVolume* laylog = new G4LogicalVolume (solid, matter, name); 170 setVisType(CCalVisualisable::OtherServices,l 175 setVisType(CCalVisualisable::OtherServices,laylog); 171 176 172 G4int i = 0; 177 G4int i = 0; 173 G4String rotstr; 178 G4String rotstr; 174 G4double xp, yp, zp, angle; 179 G4double xp, yp, zp, angle; 175 G4double zshift = -0.5 * (getLengBox() - get 180 G4double zshift = -0.5 * (getLengBox() - getCrystLength()) + getLengFront(); 176 G4RotationMatrix* rot = 0; 181 G4RotationMatrix* rot = 0; 177 for (i = 0; i < getLayNum(); i++) { 182 for (i = 0; i < getLayNum(); i++) { 178 angle = 0.5 * getLayAngle() * (2*i + 1 - 183 angle = 0.5 * getLayAngle() * (2*i + 1 - getLayNum()); 179 xp = angle * (getLayPar(4) + getLayRad 184 xp = angle * (getLayPar(4) + getLayRadius()) * mm; 180 zp = (zshift + getLayPar(0)*std::abs(s 185 zp = (zshift + getLayPar(0)*std::abs(std::sin(angle))) * mm; 181 rotstr = idName + "Layer" + i; 186 rotstr = idName + "Layer" + i; 182 rot = rotfact->findMatrix(rotstr); 187 rot = rotfact->findMatrix(rotstr); 183 if (!rot) { 188 if (!rot) { 184 #ifdef ddebug 189 #ifdef ddebug 185 G4cout << "Creating a new rotation: " << 190 G4cout << "Creating a new rotation: " << rotstr << tab 186 << (90.0*deg+angle) << "," << 0.0*d << 191 << (90.0*deg+angle) << "," << 0.0*deg << "," << 90.0*deg << "," 187 << 90.0*deg << "," << angle << "," << 192 << 90.0*deg << "," << angle << "," << 0.0*deg << G4endl; 188 #endif 193 #endif 189 rot = rotfact->AddMatrix(rotstr, (90.0*d 194 rot = rotfact->AddMatrix(rotstr, (90.0*deg+angle), 0.0*deg, 90.0*deg, 190 90.0*deg, angle << 195 90.0*deg, angle, 0.0*deg); 191 } 196 } 192 new G4PVPlacement(rot, G4ThreeVector(xp,0. 197 new G4PVPlacement(rot, G4ThreeVector(xp,0.,zp), laylog, name, glog, 193 false, i+1); << 198 false, i+1); 194 #ifdef pdebug 199 #ifdef pdebug 195 G4cout << laylog->GetName() << " number " 200 G4cout << laylog->GetName() << " number " << i+1 << " positioned in " 196 << glog->GetName() << " at (" << xp 201 << glog->GetName() << " at (" << xp << ", 0," << zp 197 << ") with rotation angle " << angle/ << 202 << ") with rotation angle " << angle/deg << G4endl; 198 #endif 203 #endif 199 } 204 } 200 205 201 //Now the crystals 206 //Now the crystals 202 name = idName + "Crystal"; 207 name = idName + "Crystal"; 203 matter = matfact->findMaterial(getCrystMat() 208 matter = matfact->findMaterial(getCrystMat()); 204 solid = new G4Trd(name, getCrystPar(0)*mm, 209 solid = new G4Trd(name, getCrystPar(0)*mm, getCrystPar(1)*mm, 205 getCrystPar(2)*mm, getCry << 210 getCrystPar(2)*mm, getCrystPar(3)*mm, getCrystPar(4)*mm); 206 #ifdef debug 211 #ifdef debug 207 G4cout << tab << name << " Trd made of " << 212 G4cout << tab << name << " Trd made of " << getCrystMat() << " of dimension " 208 << getCrystPar(0)*mm << ", " << getCrys 213 << getCrystPar(0)*mm << ", " << getCrystPar(1)*mm << ", " 209 << getCrystPar(2)*mm << ", " << getCrys 214 << getCrystPar(2)*mm << ", " << getCrystPar(3)*mm << ", " 210 << getCrystPar(4)*mm << G4endl; 215 << getCrystPar(4)*mm << G4endl; 211 #endif 216 #endif 212 217 213 G4LogicalVolume* detLog = new G4LogicalVolum 218 G4LogicalVolume* detLog = new G4LogicalVolume (solid, matter, name); 214 setVisType(CCalVisualisable::Sensitive,detLo 219 setVisType(CCalVisualisable::Sensitive,detLog); 215 sensitiveLogs.push_back(detLog); 220 sensitiveLogs.push_back(detLog); 216 for (i = 0; i < getCrystNum(); i++) { 221 for (i = 0; i < getCrystNum(); i++) { 217 angle = 0.5 * getLayAngle() * (2*i + 1 - 222 angle = 0.5 * getLayAngle() * (2*i + 1 - getCrystNum()); 218 yp = angle * (getCrystPar(4) + getLayR 223 yp = angle * (getCrystPar(4) + getLayRadius()) * mm; 219 zp = (getCrystPar(0)*std::abs(std::sin 224 zp = (getCrystPar(0)*std::abs(std::sin(angle)) - getCrystTol()) * mm; 220 rotstr = idName + "Crystal" + i; 225 rotstr = idName + "Crystal" + i; 221 rot = rotfact->findMatrix(rotstr); 226 rot = rotfact->findMatrix(rotstr); 222 if (!rot) { 227 if (!rot) { 223 #ifdef ddebug 228 #ifdef ddebug 224 G4cout << "Creating a new rotation: " << 229 G4cout << "Creating a new rotation: " << rotstr << tab << 90.0*deg << "," 225 << 0.0*deg << "," << (90.0*deg+angl << 230 << 0.0*deg << "," << (90.0*deg+angle) << "," << 0.0*deg << "," 226 << angle << "," << 90.0*deg << G4en << 231 << angle << "," << 90.0*deg << G4endl; 227 #endif 232 #endif 228 rot = rotfact->AddMatrix(rotstr, 90.0*de 233 rot = rotfact->AddMatrix(rotstr, 90.0*deg, 0.0*deg, (90.0*deg+angle), 229 90.0*deg, angle << 234 90.0*deg, angle, 90.0*deg); 230 } 235 } 231 new G4PVPlacement(rot, G4ThreeVector(0,yp, 236 new G4PVPlacement(rot, G4ThreeVector(0,yp,zp), detLog, name, laylog, 232 false, i+1); << 237 false, i+1); 233 #ifdef pdebug 238 #ifdef pdebug 234 G4cout << detLog->GetName() << " number " 239 G4cout << detLog->GetName() << " number " << i+1 << " positioned in " 235 << laylog->GetName() << " at (0," << 240 << laylog->GetName() << " at (0," << yp << "," << zp 236 << ") with rotation angle " << angle/ << 241 << ") with rotation angle " << angle/deg << G4endl; 237 #endif 242 #endif 238 } 243 } 239 244 240 //Support boxes 245 //Support boxes 241 name = idName + "Support"; 246 name = idName + "Support"; 242 matter = matfact->findMaterial(getSuppMat()) 247 matter = matfact->findMaterial(getSuppMat()); 243 solid = new G4Box (name, 0.5*getDxSupp()*mm 248 solid = new G4Box (name, 0.5*getDxSupp()*mm, 0.5*getDySupp()*mm, 244 0.5*getDzSupp()*mm); << 249 0.5*getDzSupp()*mm); 245 #ifdef debug 250 #ifdef debug 246 G4cout << tab << name << " Box made of " << 251 G4cout << tab << name << " Box made of " << getSuppMat() << " of dimension " 247 << 0.5*getDxSupp()*mm << ", " << 0.5*ge 252 << 0.5*getDxSupp()*mm << ", " << 0.5*getDySupp()*mm << ", " 248 << 0.5*getDzSupp()*mm << G4endl; 253 << 0.5*getDzSupp()*mm << G4endl; 249 #endif 254 #endif 250 G4LogicalVolume* slog = new G4LogicalVolume 255 G4LogicalVolume* slog = new G4LogicalVolume (solid, matter, name); 251 setVisType(CCalVisualisable::Support,slog); 256 setVisType(CCalVisualisable::Support,slog); 252 257 253 zp = (-0.5 * getLengBox() + getCrystLength 258 zp = (-0.5 * getLengBox() + getCrystLength() + getLengFront() + 254 0.5 * getDzSupp() + getDistSupp()) * << 259 0.5 * getDzSupp() + getDistSupp()) * mm; 255 for (i = 0; i < getCrystNum(); i++) { 260 for (i = 0; i < getCrystNum(); i++) { 256 yp = getLayPar(1) * (2*i + 1 - getCrystN 261 yp = getLayPar(1) * (2*i + 1 - getCrystNum()) * mm; 257 new G4PVPlacement(0, G4ThreeVector(0,yp,zp 262 new G4PVPlacement(0, G4ThreeVector(0,yp,zp), slog, name, glog, 258 false, i+1); << 263 false, i+1); 259 #ifdef pdebug 264 #ifdef pdebug 260 G4cout << slog->GetName() << " number " << 265 G4cout << slog->GetName() << " number " << i+1 << " positioned in " 261 << glog->GetName() << " at (0," << y 266 << glog->GetName() << " at (0," << yp << "," << zp 262 << ") with no rotation" << G4endl; << 267 << ") with no rotation" << G4endl; 263 #endif 268 #endif 264 } 269 } 265 270 266 return glog; 271 return glog; 267 } 272 } 268 273 269 << 270 void CCalG4Ecal::constructSensitive() { 274 void CCalG4Ecal::constructSensitive() { >> 275 271 #ifdef debug 276 #ifdef debug 272 G4cout << "Now registering CrystalMatrix Log 277 G4cout << "Now registering CrystalMatrix LogicalVolume's to SD's:" << G4endl; 273 #endif 278 #endif 274 if (sensitiveLogs.size()>0) { 279 if (sensitiveLogs.size()>0) { 275 CCalSensitiveDetectors* sensDets = CCalSen 280 CCalSensitiveDetectors* sensDets = CCalSensitiveDetectors::getInstance(); 276 G4String SDname = idName; 281 G4String SDname = idName; 277 for(std::vector<ptrG4Log>::iterator iter=s 282 for(std::vector<ptrG4Log>::iterator iter=sensitiveLogs.begin(); 278 iter<sensit << 283 iter<sensitiveLogs.end(); iter++) { 279 sensDets->registerVolume(SDname, (*iter) 284 sensDets->registerVolume(SDname, (*iter)); 280 #ifdef sdebug 285 #ifdef sdebug 281 G4cout << "Register volume " << (*iter)- 286 G4cout << "Register volume " << (*iter)->GetName() << " for" << SDname 282 << G4endl; << 287 << G4endl; 283 #endif 288 #endif 284 } 289 } 285 } 290 } >> 291 286 } 292 } >> 293 >> 294 287 295