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