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> 32 #include <cmath> 33 33 34 #include "CCalG4Ecal.hh" 34 #include "CCalG4Ecal.hh" 35 35 36 #include "CCalMaterialFactory.hh" 36 #include "CCalMaterialFactory.hh" 37 #include "CCalRotationMatrixFactory.hh" 37 #include "CCalRotationMatrixFactory.hh" 38 #include "CCalSensitiveDetectors.hh" 38 #include "CCalSensitiveDetectors.hh" 39 39 40 #include "CCalutils.hh" 40 #include "CCalutils.hh" 41 41 42 #include "G4SystemOfUnits.hh" 42 #include "G4SystemOfUnits.hh" 43 #include "G4ThreeVector.hh" 43 #include "G4ThreeVector.hh" 44 #include "G4Box.hh" 44 #include "G4Box.hh" 45 #include "G4Trd.hh" 45 #include "G4Trd.hh" 46 46 47 #include "G4LogicalVolume.hh" 47 #include "G4LogicalVolume.hh" 48 #include "G4PVPlacement.hh" 48 #include "G4PVPlacement.hh" 49 49 50 //#define debug 50 //#define debug 51 //#define ddebug 51 //#define ddebug 52 //#define pdebug 52 //#define pdebug 53 //#define sdebug 53 //#define sdebug 54 54 55 //Initialize static logical volumes 55 //Initialize static logical volumes 56 G4LogicalVolume* CCalG4Ecal::crystalmatrixLog 56 G4LogicalVolume* CCalG4Ecal::crystalmatrixLog = 0; 57 57 58 //Initialize static prefix name 58 //Initialize static prefix name 59 G4String CCalG4Ecal::idName = "CrystalMatrix"; 59 G4String CCalG4Ecal::idName = "CrystalMatrix"; 60 60 >> 61 //////////////////////////////////////////////////////////////////// >> 62 // CCalG4Ecal constructor & destructor... >> 63 //////////////////////////////////////////////////////////////////// 61 64 62 CCalG4Ecal::CCalG4Ecal(const G4String &name) : << 65 CCalG4Ecal::CCalG4Ecal(const G4String &name): 63 << 66 CCalEcal(name), CCalG4Able(name), type(module1) {} 64 67 65 CCalG4Ecal::~CCalG4Ecal() {} 68 CCalG4Ecal::~CCalG4Ecal() {} 66 69 >> 70 //////////////////////////////////////////////////////////////////// >> 71 // CCalG4Ecal methods... >> 72 //////////////////////////////////////////////////////////////////// 67 73 68 G4VPhysicalVolume* CCalG4Ecal::constructIn( G4 << 74 G4VPhysicalVolume* CCalG4Ecal::constructIn(G4VPhysicalVolume* mother) { 69 G4cout << "==>> Constructing CCalG4Ecal..." 75 G4cout << "==>> Constructing CCalG4Ecal..." << G4endl; 70 76 >> 77 /////////////////////////////////////////////////////////////// 71 // Construction of global volume as a Box 78 // Construction of global volume as a Box 72 79 73 if (!crystalmatrixLog) { 80 if (!crystalmatrixLog) { 74 crystalmatrixLog = constructGlobal(); 81 crystalmatrixLog = constructGlobal(); 75 } 82 } 76 CCalRotationMatrixFactory* rotfact = CCalRot 83 CCalRotationMatrixFactory* rotfact = CCalRotationMatrixFactory::getInstance(); 77 84 78 G4double x, y, z; 85 G4double x, y, z; 79 if (mother != 0) { 86 if (mother != 0) { 80 x = getXpos()*mm; 87 x = getXpos()*mm; 81 y = getYpos()*mm; 88 y = getYpos()*mm; 82 z = getZpos()*mm; 89 z = getZpos()*mm; 83 } else { 90 } else { 84 x = y = z = 0; 91 x = y = z = 0; 85 } 92 } 86 93 87 int num; 94 int num; 88 if (type == module2) { 95 if (type == module2) { 89 num = 2; 96 num = 2; 90 } else { 97 } else { 91 num = 1; 98 num = 1; 92 } 99 } 93 #ifdef pdebug 100 #ifdef pdebug 94 G4String name("Null"); 101 G4String name("Null"); 95 if (mother != 0) name = mother->GetName(); 102 if (mother != 0) name = mother->GetName(); 96 G4cout << crystalmatrixLog->GetName() << " N 103 G4cout << crystalmatrixLog->GetName() << " Number " << num << " positioned in " 97 << name << " at (" << x << ", " << y << 104 << name << " at (" << x << ", " << y << ", " << z << ")"; 98 #endif 105 #endif 99 106 100 G4RotationMatrix* cmrot = 0; 107 G4RotationMatrix* cmrot = 0; 101 if (mother != 0) { 108 if (mother != 0) { 102 G4String rotstr = idName + num; 109 G4String rotstr = idName + num; 103 cmrot = rotfact->findMatrix(rotstr); 110 cmrot = rotfact->findMatrix(rotstr); 104 if (!cmrot) { 111 if (!cmrot) { 105 #ifdef ddebug 112 #ifdef ddebug 106 G4cout << "Creating a new rotation: " << 113 G4cout << "Creating a new rotation: " << rotstr << tab 107 << getThetaX()*deg << "," << getPhi << 114 << getThetaX()*deg << "," << getPhiX()*deg << "," 108 << getThetaY()*deg << "," << getPhi << 115 << getThetaY()*deg << "," << getPhiY()*deg << "," 109 << getThetaZ()*deg << "," << getPhi << 116 << getThetaZ()*deg << "," << getPhiZ()*deg << G4endl; 110 #endif 117 #endif 111 cmrot = rotfact->AddMatrix(rotstr, getTh 118 cmrot = rotfact->AddMatrix(rotstr, getThetaX()*deg, getPhiX()*deg, 112 getThetaY()*d << 119 getThetaY()*deg, getPhiY()*deg, 113 getThetaZ()*d << 120 getThetaZ()*deg, getPhiZ()*deg); 114 } // if !cmrot 121 } // if !cmrot 115 #ifdef pdebug 122 #ifdef pdebug 116 G4cout << " rotation by (" << getThetaX() 123 G4cout << " rotation by (" << getThetaX() << ", " << getPhiX() << ", " 117 << getThetaY() << "," << getPhiY() << << 124 << getThetaY() << "," << getPhiY() << ", " << getThetaZ() << ", " 118 << getPhiZ() << ")" << G4endl; << 125 << getPhiZ() << ")" << G4endl; 119 #endif 126 #endif 120 } else { 127 } else { 121 #ifdef pdebug 128 #ifdef pdebug 122 G4cout << " without rotation..." << G4endl 129 G4cout << " without rotation..." << G4endl; 123 #endif 130 #endif 124 } 131 } 125 132 126 G4PVPlacement* crystalmatrix; 133 G4PVPlacement* crystalmatrix; 127 if (mother != 0) { 134 if (mother != 0) { 128 crystalmatrix = new G4PVPlacement(cmrot, G 135 crystalmatrix = new G4PVPlacement(cmrot, G4ThreeVector(x,y,z), 129 crystalm << 136 crystalmatrixLog, idName, 130 mother-> << 137 mother->GetLogicalVolume(), false, num); 131 } else { 138 } else { 132 crystalmatrix = new G4PVPlacement(cmrot, G 139 crystalmatrix = new G4PVPlacement(cmrot, G4ThreeVector(x,y,z), 133 idName, << 140 idName, crystalmatrixLog, 134 mother, << 141 mother, false, num); 135 } 142 } 136 G4cout << "<<== End of CCalG4Ecal constructi 143 G4cout << "<<== End of CCalG4Ecal construction ..." << G4endl; 137 144 138 return crystalmatrix; 145 return crystalmatrix; 139 } 146 } 140 147 141 148 142 G4LogicalVolume* CCalG4Ecal::constructGlobal() 149 G4LogicalVolume* CCalG4Ecal::constructGlobal() { 143 150 144 //Pointers to the Materials and Rotation Mat 151 //Pointers to the Materials and Rotation Matrix factory 145 CCalMaterialFactory* matfact = CCalMat 152 CCalMaterialFactory* matfact = CCalMaterialFactory::getInstance(); 146 CCalRotationMatrixFactory* rotfact = CCalRot 153 CCalRotationMatrixFactory* rotfact = CCalRotationMatrixFactory::getInstance(); 147 154 148 G4Material* matter = matfact->findMaterial(g 155 G4Material* matter = matfact->findMaterial(getGenMat()); 149 G4VSolid* solid = new G4Box (idName, 0.5*get 156 G4VSolid* solid = new G4Box (idName, 0.5*getWidBox()*mm, 0.5*getWidBox()*mm, 150 0.5*getLengBox( << 157 0.5*getLengBox()*mm); 151 #ifdef debug 158 #ifdef debug 152 G4cout << tab << idName << " Box made of " < 159 G4cout << tab << idName << " Box made of " << getGenMat() << " of dimension " 153 << 0.5*getWidBox()*mm << ", " << 0.5*ge 160 << 0.5*getWidBox()*mm << ", " << 0.5*getWidBox()*mm << ", " 154 << 0.5*getLengBox()*mm << G4endl; 161 << 0.5*getLengBox()*mm << G4endl; 155 #endif 162 #endif 156 G4LogicalVolume* glog = new G4LogicalVolume 163 G4LogicalVolume* glog = new G4LogicalVolume (solid, matter, idName); 157 setVisType(CCalVisualisable::PseudoVolumes,g 164 setVisType(CCalVisualisable::PseudoVolumes,glog); 158 165 159 //Now the layers 166 //Now the layers 160 G4String name = idName + "Layer"; 167 G4String name = idName + "Layer"; 161 matter = matfact->findMaterial(getLayMat()); 168 matter = matfact->findMaterial(getLayMat()); 162 solid = new G4Trd(name, getLayPar(0)*mm, ge 169 solid = new G4Trd(name, getLayPar(0)*mm, getLayPar(1)*mm, getLayPar(2)*mm, 163 getLayPar(3)*mm, getLayPa << 170 getLayPar(3)*mm, getLayPar(4)*mm); 164 #ifdef debug 171 #ifdef debug 165 G4cout << tab << name << " Trd made of " << 172 G4cout << tab << name << " Trd made of " << getLayMat() << " of dimension " 166 << getLayPar(0)*mm << ", " << getLayPar 173 << getLayPar(0)*mm << ", " << getLayPar(1)*mm << ", " << getLayPar(2)*mm 167 << ", " << getLayPar(3)*mm << ", " << g 174 << ", " << getLayPar(3)*mm << ", " << getLayPar(4)*mm << G4endl; 168 #endif 175 #endif 169 G4LogicalVolume* laylog = new G4LogicalVolum 176 G4LogicalVolume* laylog = new G4LogicalVolume (solid, matter, name); 170 setVisType(CCalVisualisable::OtherServices,l 177 setVisType(CCalVisualisable::OtherServices,laylog); 171 178 172 G4int i = 0; 179 G4int i = 0; 173 G4String rotstr; 180 G4String rotstr; 174 G4double xp, yp, zp, angle; 181 G4double xp, yp, zp, angle; 175 G4double zshift = -0.5 * (getLengBox() - get 182 G4double zshift = -0.5 * (getLengBox() - getCrystLength()) + getLengFront(); 176 G4RotationMatrix* rot = 0; 183 G4RotationMatrix* rot = 0; 177 for (i = 0; i < getLayNum(); i++) { 184 for (i = 0; i < getLayNum(); i++) { 178 angle = 0.5 * getLayAngle() * (2*i + 1 - 185 angle = 0.5 * getLayAngle() * (2*i + 1 - getLayNum()); 179 xp = angle * (getLayPar(4) + getLayRad 186 xp = angle * (getLayPar(4) + getLayRadius()) * mm; 180 zp = (zshift + getLayPar(0)*std::abs(s 187 zp = (zshift + getLayPar(0)*std::abs(std::sin(angle))) * mm; 181 rotstr = idName + "Layer" + i; 188 rotstr = idName + "Layer" + i; 182 rot = rotfact->findMatrix(rotstr); 189 rot = rotfact->findMatrix(rotstr); 183 if (!rot) { 190 if (!rot) { 184 #ifdef ddebug 191 #ifdef ddebug 185 G4cout << "Creating a new rotation: " << 192 G4cout << "Creating a new rotation: " << rotstr << tab 186 << (90.0*deg+angle) << "," << 0.0*d << 193 << (90.0*deg+angle) << "," << 0.0*deg << "," << 90.0*deg << "," 187 << 90.0*deg << "," << angle << "," << 194 << 90.0*deg << "," << angle << "," << 0.0*deg << G4endl; 188 #endif 195 #endif 189 rot = rotfact->AddMatrix(rotstr, (90.0*d 196 rot = rotfact->AddMatrix(rotstr, (90.0*deg+angle), 0.0*deg, 90.0*deg, 190 90.0*deg, angle << 197 90.0*deg, angle, 0.0*deg); 191 } 198 } 192 new G4PVPlacement(rot, G4ThreeVector(xp,0. 199 new G4PVPlacement(rot, G4ThreeVector(xp,0.,zp), laylog, name, glog, 193 false, i+1); << 200 false, i+1); 194 #ifdef pdebug 201 #ifdef pdebug 195 G4cout << laylog->GetName() << " number " 202 G4cout << laylog->GetName() << " number " << i+1 << " positioned in " 196 << glog->GetName() << " at (" << xp 203 << glog->GetName() << " at (" << xp << ", 0," << zp 197 << ") with rotation angle " << angle/ << 204 << ") with rotation angle " << angle/deg << G4endl; 198 #endif 205 #endif 199 } 206 } 200 207 201 //Now the crystals 208 //Now the crystals 202 name = idName + "Crystal"; 209 name = idName + "Crystal"; 203 matter = matfact->findMaterial(getCrystMat() 210 matter = matfact->findMaterial(getCrystMat()); 204 solid = new G4Trd(name, getCrystPar(0)*mm, 211 solid = new G4Trd(name, getCrystPar(0)*mm, getCrystPar(1)*mm, 205 getCrystPar(2)*mm, getCry << 212 getCrystPar(2)*mm, getCrystPar(3)*mm, getCrystPar(4)*mm); 206 #ifdef debug 213 #ifdef debug 207 G4cout << tab << name << " Trd made of " << 214 G4cout << tab << name << " Trd made of " << getCrystMat() << " of dimension " 208 << getCrystPar(0)*mm << ", " << getCrys 215 << getCrystPar(0)*mm << ", " << getCrystPar(1)*mm << ", " 209 << getCrystPar(2)*mm << ", " << getCrys 216 << getCrystPar(2)*mm << ", " << getCrystPar(3)*mm << ", " 210 << getCrystPar(4)*mm << G4endl; 217 << getCrystPar(4)*mm << G4endl; 211 #endif 218 #endif 212 219 213 G4LogicalVolume* detLog = new G4LogicalVolum 220 G4LogicalVolume* detLog = new G4LogicalVolume (solid, matter, name); 214 setVisType(CCalVisualisable::Sensitive,detLo 221 setVisType(CCalVisualisable::Sensitive,detLog); 215 sensitiveLogs.push_back(detLog); 222 sensitiveLogs.push_back(detLog); 216 for (i = 0; i < getCrystNum(); i++) { 223 for (i = 0; i < getCrystNum(); i++) { 217 angle = 0.5 * getLayAngle() * (2*i + 1 - 224 angle = 0.5 * getLayAngle() * (2*i + 1 - getCrystNum()); 218 yp = angle * (getCrystPar(4) + getLayR 225 yp = angle * (getCrystPar(4) + getLayRadius()) * mm; 219 zp = (getCrystPar(0)*std::abs(std::sin 226 zp = (getCrystPar(0)*std::abs(std::sin(angle)) - getCrystTol()) * mm; 220 rotstr = idName + "Crystal" + i; 227 rotstr = idName + "Crystal" + i; 221 rot = rotfact->findMatrix(rotstr); 228 rot = rotfact->findMatrix(rotstr); 222 if (!rot) { 229 if (!rot) { 223 #ifdef ddebug 230 #ifdef ddebug 224 G4cout << "Creating a new rotation: " << 231 G4cout << "Creating a new rotation: " << rotstr << tab << 90.0*deg << "," 225 << 0.0*deg << "," << (90.0*deg+angl << 232 << 0.0*deg << "," << (90.0*deg+angle) << "," << 0.0*deg << "," 226 << angle << "," << 90.0*deg << G4en << 233 << angle << "," << 90.0*deg << G4endl; 227 #endif 234 #endif 228 rot = rotfact->AddMatrix(rotstr, 90.0*de 235 rot = rotfact->AddMatrix(rotstr, 90.0*deg, 0.0*deg, (90.0*deg+angle), 229 90.0*deg, angle << 236 90.0*deg, angle, 90.0*deg); 230 } 237 } 231 new G4PVPlacement(rot, G4ThreeVector(0,yp, 238 new G4PVPlacement(rot, G4ThreeVector(0,yp,zp), detLog, name, laylog, 232 false, i+1); << 239 false, i+1); 233 #ifdef pdebug 240 #ifdef pdebug 234 G4cout << detLog->GetName() << " number " 241 G4cout << detLog->GetName() << " number " << i+1 << " positioned in " 235 << laylog->GetName() << " at (0," << 242 << laylog->GetName() << " at (0," << yp << "," << zp 236 << ") with rotation angle " << angle/ << 243 << ") with rotation angle " << angle/deg << G4endl; 237 #endif 244 #endif 238 } 245 } 239 246 240 //Support boxes 247 //Support boxes 241 name = idName + "Support"; 248 name = idName + "Support"; 242 matter = matfact->findMaterial(getSuppMat()) 249 matter = matfact->findMaterial(getSuppMat()); 243 solid = new G4Box (name, 0.5*getDxSupp()*mm 250 solid = new G4Box (name, 0.5*getDxSupp()*mm, 0.5*getDySupp()*mm, 244 0.5*getDzSupp()*mm); << 251 0.5*getDzSupp()*mm); 245 #ifdef debug 252 #ifdef debug 246 G4cout << tab << name << " Box made of " << 253 G4cout << tab << name << " Box made of " << getSuppMat() << " of dimension " 247 << 0.5*getDxSupp()*mm << ", " << 0.5*ge 254 << 0.5*getDxSupp()*mm << ", " << 0.5*getDySupp()*mm << ", " 248 << 0.5*getDzSupp()*mm << G4endl; 255 << 0.5*getDzSupp()*mm << G4endl; 249 #endif 256 #endif 250 G4LogicalVolume* slog = new G4LogicalVolume 257 G4LogicalVolume* slog = new G4LogicalVolume (solid, matter, name); 251 setVisType(CCalVisualisable::Support,slog); 258 setVisType(CCalVisualisable::Support,slog); 252 259 253 zp = (-0.5 * getLengBox() + getCrystLength 260 zp = (-0.5 * getLengBox() + getCrystLength() + getLengFront() + 254 0.5 * getDzSupp() + getDistSupp()) * << 261 0.5 * getDzSupp() + getDistSupp()) * mm; 255 for (i = 0; i < getCrystNum(); i++) { 262 for (i = 0; i < getCrystNum(); i++) { 256 yp = getLayPar(1) * (2*i + 1 - getCrystN 263 yp = getLayPar(1) * (2*i + 1 - getCrystNum()) * mm; 257 new G4PVPlacement(0, G4ThreeVector(0,yp,zp 264 new G4PVPlacement(0, G4ThreeVector(0,yp,zp), slog, name, glog, 258 false, i+1); << 265 false, i+1); 259 #ifdef pdebug 266 #ifdef pdebug 260 G4cout << slog->GetName() << " number " << 267 G4cout << slog->GetName() << " number " << i+1 << " positioned in " 261 << glog->GetName() << " at (0," << y 268 << glog->GetName() << " at (0," << yp << "," << zp 262 << ") with no rotation" << G4endl; << 269 << ") with no rotation" << G4endl; 263 #endif 270 #endif 264 } 271 } 265 272 266 return glog; 273 return glog; 267 } 274 } 268 275 269 << 270 void CCalG4Ecal::constructSensitive() { 276 void CCalG4Ecal::constructSensitive() { >> 277 271 #ifdef debug 278 #ifdef debug 272 G4cout << "Now registering CrystalMatrix Log 279 G4cout << "Now registering CrystalMatrix LogicalVolume's to SD's:" << G4endl; 273 #endif 280 #endif 274 if (sensitiveLogs.size()>0) { 281 if (sensitiveLogs.size()>0) { 275 CCalSensitiveDetectors* sensDets = CCalSen 282 CCalSensitiveDetectors* sensDets = CCalSensitiveDetectors::getInstance(); 276 G4String SDname = idName; 283 G4String SDname = idName; 277 for(std::vector<ptrG4Log>::iterator iter=s 284 for(std::vector<ptrG4Log>::iterator iter=sensitiveLogs.begin(); 278 iter<sensit << 285 iter<sensitiveLogs.end(); iter++) { 279 sensDets->registerVolume(SDname, (*iter) 286 sensDets->registerVolume(SDname, (*iter)); 280 #ifdef sdebug 287 #ifdef sdebug 281 G4cout << "Register volume " << (*iter)- 288 G4cout << "Register volume " << (*iter)->GetName() << " for" << SDname 282 << G4endl; << 289 << G4endl; 283 #endif 290 #endif 284 } 291 } 285 } 292 } >> 293 286 } 294 } >> 295 >> 296 287 297